1 /* ir-rc5-sz-decoder.c - handle RC5 Streamzap IR Pulse/Space protocol
3 * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 * Copyright (C) 2010 by Jarod Wilson <jarod@redhat.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 * This code handles the 15 bit RC5-ish protocol used by the Streamzap
19 * It considers a carrier of 36 kHz, with a total of 15 bits, where
20 * the first two bits are start bits, and a third one is a filing bit
23 #include "rc-core-priv.h"
25 #define RC5_SZ_NBITS 15
26 #define RC5_UNIT 888888 /* ns */
27 #define RC5_BIT_START (1 * RC5_UNIT)
28 #define RC5_BIT_END (1 * RC5_UNIT)
38 * ir_rc5_sz_decode() - Decode one RC-5 Streamzap pulse or space
39 * @dev: the struct rc_dev descriptor of the device
40 * @ev: the struct ir_raw_event descriptor of the pulse/space
42 * This function returns -EINVAL if the pulse violates the state machine
44 static int ir_rc5_sz_decode(struct rc_dev
*dev
, struct ir_raw_event ev
)
46 struct rc5_sz_dec
*data
= &dev
->raw
->rc5_sz
;
47 u8 toggle
, command
, system
;
50 if (!(dev
->raw
->enabled_protocols
& RC_TYPE_RC5_SZ
))
53 if (!is_timing_event(ev
)) {
55 data
->state
= STATE_INACTIVE
;
59 if (!geq_margin(ev
.duration
, RC5_UNIT
, RC5_UNIT
/ 2))
63 IR_dprintk(2, "RC5-sz decode started at state %i (%uus %s)\n",
64 data
->state
, TO_US(ev
.duration
), TO_STR(ev
.pulse
));
66 if (!geq_margin(ev
.duration
, RC5_UNIT
, RC5_UNIT
/ 2))
69 switch (data
->state
) {
75 data
->state
= STATE_BIT_START
;
77 data
->wanted_bits
= RC5_SZ_NBITS
;
78 decrease_duration(&ev
, RC5_BIT_START
);
82 if (!eq_margin(ev
.duration
, RC5_BIT_START
, RC5_UNIT
/ 2))
89 data
->state
= STATE_BIT_END
;
93 if (!is_transition(&ev
, &dev
->raw
->prev_ev
))
96 if (data
->count
== data
->wanted_bits
)
97 data
->state
= STATE_FINISHED
;
99 data
->state
= STATE_BIT_START
;
101 decrease_duration(&ev
, RC5_BIT_END
);
109 command
= (data
->bits
& 0x0003F) >> 0;
110 system
= (data
->bits
& 0x02FC0) >> 6;
111 toggle
= (data
->bits
& 0x01000) ? 1 : 0;
112 scancode
= system
<< 6 | command
;
114 IR_dprintk(1, "RC5-sz scancode 0x%04x (toggle: %u)\n",
117 rc_keydown(dev
, scancode
, toggle
);
118 data
->state
= STATE_INACTIVE
;
123 IR_dprintk(1, "RC5-sz decode failed at state %i (%uus %s)\n",
124 data
->state
, TO_US(ev
.duration
), TO_STR(ev
.pulse
));
125 data
->state
= STATE_INACTIVE
;
129 static struct ir_raw_handler rc5_sz_handler
= {
130 .protocols
= RC_TYPE_RC5_SZ
,
131 .decode
= ir_rc5_sz_decode
,
134 static int __init
ir_rc5_sz_decode_init(void)
136 ir_raw_handler_register(&rc5_sz_handler
);
138 printk(KERN_INFO
"IR RC5 (streamzap) protocol handler initialized\n");
142 static void __exit
ir_rc5_sz_decode_exit(void)
144 ir_raw_handler_unregister(&rc5_sz_handler
);
147 module_init(ir_rc5_sz_decode_init
);
148 module_exit(ir_rc5_sz_decode_exit
);
150 MODULE_LICENSE("GPL");
151 MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
152 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
153 MODULE_DESCRIPTION("RC5 (streamzap) IR protocol decoder");