1 /* dvb-usb-remote.c is part of the DVB USB library.
3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
6 * This file contains functions for initializing the input-device and for handling remote-control-queries.
8 #include "dvb-usb-common.h"
9 #include <linux/usb/input.h>
11 /* Remote-control poll function - called every dib->rc_query_interval ms to see
12 * whether the remote control has received anything.
14 * TODO: Fix the repeat rate of the input device.
16 static void dvb_usb_read_remote_control(struct work_struct
*work
)
18 struct dvb_usb_device
*d
=
19 container_of(work
, struct dvb_usb_device
, rc_query_work
.work
);
23 /* TODO: need a lock here. We can simply skip checking for the remote control
26 /* when the parameter has been set to 1 via sysfs while the driver was running */
27 if (dvb_usb_disable_rc_polling
)
30 if (d
->props
.rc_query(d
,&event
,&state
)) {
31 err("error while querying for an remote control event.");
37 case REMOTE_NO_KEY_PRESSED
:
39 case REMOTE_KEY_PRESSED
:
40 deb_rc("key pressed\n");
41 d
->last_event
= event
;
42 case REMOTE_KEY_REPEAT
:
43 deb_rc("key repeated\n");
44 input_event(d
->rc_input_dev
, EV_KEY
, event
, 1);
45 input_event(d
->rc_input_dev
, EV_KEY
, d
->last_event
, 0);
46 input_sync(d
->rc_input_dev
);
52 /* improved repeat handling ???
54 case REMOTE_NO_KEY_PRESSED:
55 deb_rc("NO KEY PRESSED\n");
56 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
57 deb_rc("releasing event %d\n",d->last_event);
58 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0);
59 input_sync(d->rc_input_dev);
61 d->last_state = REMOTE_NO_KEY_PRESSED;
64 case REMOTE_KEY_PRESSED:
65 deb_rc("KEY PRESSED\n");
66 deb_rc("pressing event %d\n",event);
68 input_event(d->rc_input_dev, EV_KEY, event, 1);
69 input_sync(d->rc_input_dev);
71 d->last_event = event;
72 d->last_state = REMOTE_KEY_PRESSED;
74 case REMOTE_KEY_REPEAT:
75 deb_rc("KEY_REPEAT\n");
76 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
77 deb_rc("repeating event %d\n",d->last_event);
78 input_event(d->rc_input_dev, EV_KEY, d->last_event, 2);
79 input_sync(d->rc_input_dev);
80 d->last_state = REMOTE_KEY_REPEAT;
88 schedule_delayed_work(&d
->rc_query_work
,msecs_to_jiffies(d
->props
.rc_interval
));
91 int dvb_usb_remote_init(struct dvb_usb_device
*d
)
93 struct input_dev
*input_dev
;
97 if (d
->props
.rc_key_map
== NULL
||
98 d
->props
.rc_query
== NULL
||
99 dvb_usb_disable_rc_polling
)
102 usb_make_path(d
->udev
, d
->rc_phys
, sizeof(d
->rc_phys
));
103 strlcat(d
->rc_phys
, "/ir0", sizeof(d
->rc_phys
));
105 input_dev
= input_allocate_device();
109 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
);
110 input_dev
->name
= "IR-receiver inside an USB DVB receiver";
111 input_dev
->phys
= d
->rc_phys
;
112 usb_to_input_id(d
->udev
, &input_dev
->id
);
113 input_dev
->dev
.parent
= &d
->udev
->dev
;
115 /* set the bits for the keys */
116 deb_rc("key map size: %d\n", d
->props
.rc_key_map_size
);
117 for (i
= 0; i
< d
->props
.rc_key_map_size
; i
++) {
118 deb_rc("setting bit for event %d item %d\n",
119 d
->props
.rc_key_map
[i
].event
, i
);
120 set_bit(d
->props
.rc_key_map
[i
].event
, input_dev
->keybit
);
123 /* Start the remote-control polling. */
124 if (d
->props
.rc_interval
< 40)
125 d
->props
.rc_interval
= 100; /* default */
127 /* setting these two values to non-zero, we have to manage key repeats */
128 input_dev
->rep
[REP_PERIOD
] = d
->props
.rc_interval
;
129 input_dev
->rep
[REP_DELAY
] = d
->props
.rc_interval
+ 150;
131 err
= input_register_device(input_dev
);
133 input_free_device(input_dev
);
137 d
->rc_input_dev
= input_dev
;
139 INIT_DELAYED_WORK(&d
->rc_query_work
, dvb_usb_read_remote_control
);
141 info("schedule remote query interval to %d msecs.", d
->props
.rc_interval
);
142 schedule_delayed_work(&d
->rc_query_work
,msecs_to_jiffies(d
->props
.rc_interval
));
144 d
->state
|= DVB_USB_STATE_REMOTE
;
149 int dvb_usb_remote_exit(struct dvb_usb_device
*d
)
151 if (d
->state
& DVB_USB_STATE_REMOTE
) {
152 cancel_rearming_delayed_work(&d
->rc_query_work
);
153 flush_scheduled_work();
154 input_unregister_device(d
->rc_input_dev
);
156 d
->state
&= ~DVB_USB_STATE_REMOTE
;
160 #define DVB_USB_RC_NEC_EMPTY 0x00
161 #define DVB_USB_RC_NEC_KEY_PRESSED 0x01
162 #define DVB_USB_RC_NEC_KEY_REPEATED 0x02
163 int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device
*d
,
164 u8 keybuf
[5], u32
*event
, int *state
)
167 struct dvb_usb_rc_key
*keymap
= d
->props
.rc_key_map
;
169 *state
= REMOTE_NO_KEY_PRESSED
;
171 case DVB_USB_RC_NEC_EMPTY
:
173 case DVB_USB_RC_NEC_KEY_PRESSED
:
174 if ((u8
) ~keybuf
[1] != keybuf
[2] ||
175 (u8
) ~keybuf
[3] != keybuf
[4]) {
176 deb_err("remote control checksum failed.\n");
179 /* See if we can match the raw key code. */
180 for (i
= 0; i
< d
->props
.rc_key_map_size
; i
++)
181 if (keymap
[i
].custom
== keybuf
[1] &&
182 keymap
[i
].data
== keybuf
[3]) {
183 *event
= keymap
[i
].event
;
184 *state
= REMOTE_KEY_PRESSED
;
187 deb_err("key mapping failed - no appropriate key found in keymapping\n");
189 case DVB_USB_RC_NEC_KEY_REPEATED
:
190 *state
= REMOTE_KEY_REPEAT
;
193 deb_err("unkown type of remote status: %d\n",keybuf
[0]);
198 EXPORT_SYMBOL(dvb_usb_nec_rc_key_to_event
);