aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c2
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c233
-rw-r--r--drivers/media/video/em28xx/em28xx-reg.h7
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c4
-rw-r--r--drivers/media/video/em28xx/em28xx.h6
5 files changed, 237 insertions, 15 deletions
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index e4251117cbe3..1d38bfaa3e7c 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -1843,4 +1843,6 @@ void em28xx_card_setup(struct em28xx *dev)
1843#endif 1843#endif
1844 1844
1845 em28xx_config_tuner(dev); 1845 em28xx_config_tuner(dev);
1846
1847 em28xx_ir_init(dev);
1846} 1848}
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index eab3d9511af3..afd67607c028 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -38,12 +38,42 @@ static unsigned int ir_debug;
38module_param(ir_debug, int, 0644); 38module_param(ir_debug, int, 0644);
39MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); 39MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
40 40
41#define dprintk(fmt, arg...) \ 41#define i2cdprintk(fmt, arg...) \
42 if (ir_debug) { \ 42 if (ir_debug) { \
43 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg); \ 43 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg); \
44 } 44 }
45 45
46/* ----------------------------------------------------------------------- */ 46#define dprintk(fmt, arg...) \
47 if (ir_debug) { \
48 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
49 }
50
51/**********************************************************
52 Polling structure used by em28xx IR's
53 **********************************************************/
54
55struct em28xx_IR {
56 struct em28xx *dev;
57 struct input_dev *input;
58 struct ir_input_state ir;
59 char name[32];
60 char phys[32];
61
62 /* poll external decoder */
63 int polling;
64 struct work_struct work;
65 struct timer_list timer;
66 u32 last_gpio;
67 u32 mask_keycode;
68 u32 mask_keydown;
69 u32 mask_keyup;
70
71 int (*get_key)(struct em28xx_IR *);
72};
73
74/**********************************************************
75 I2C IR based get keycodes - should be used with ir-kbd-i2c
76 **********************************************************/
47 77
48int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 78int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
49{ 79{
@@ -51,7 +81,7 @@ int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
51 81
52 /* poll IR chip */ 82 /* poll IR chip */
53 if (1 != i2c_master_recv(&ir->c, &b, 1)) { 83 if (1 != i2c_master_recv(&ir->c, &b, 1)) {
54 dprintk("read error\n"); 84 i2cdprintk("read error\n");
55 return -EIO; 85 return -EIO;
56 } 86 }
57 87
@@ -59,7 +89,7 @@ int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
59 down, while 0xff indicates that no button is hold 89 down, while 0xff indicates that no button is hold
60 down. 0xfe sequences are sometimes interrupted by 0xFF */ 90 down. 0xfe sequences are sometimes interrupted by 0xFF */
61 91
62 dprintk("key %02x\n", b); 92 i2cdprintk("key %02x\n", b);
63 93
64 if (b == 0xff) 94 if (b == 0xff)
65 return 0; 95 return 0;
@@ -73,7 +103,6 @@ int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
73 return 1; 103 return 1;
74} 104}
75 105
76
77int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 106int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
78{ 107{
79 unsigned char buf[2]; 108 unsigned char buf[2];
@@ -97,7 +126,7 @@ int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
97 ((buf[0]&0x10)>>3) | /* 0000 0010 */ 126 ((buf[0]&0x10)>>3) | /* 0000 0010 */
98 ((buf[0]&0x20)>>5); /* 0000 0001 */ 127 ((buf[0]&0x20)>>5); /* 0000 0001 */
99 128
100 dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n", 129 i2cdprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",
101 code, buf[0]); 130 code, buf[0]);
102 131
103 /* return key */ 132 /* return key */
@@ -114,11 +143,11 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
114 /* poll IR chip */ 143 /* poll IR chip */
115 144
116 if (3 != i2c_master_recv(&ir->c, buf, 3)) { 145 if (3 != i2c_master_recv(&ir->c, buf, 3)) {
117 dprintk("read error\n"); 146 i2cdprintk("read error\n");
118 return -EIO; 147 return -EIO;
119 } 148 }
120 149
121 dprintk("key %02x\n", buf[2]&0x3f); 150 i2cdprintk("key %02x\n", buf[2]&0x3f);
122 if (buf[0] != 0x00) 151 if (buf[0] != 0x00)
123 return 0; 152 return 0;
124 153
@@ -128,6 +157,188 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
128 return 1; 157 return 1;
129} 158}
130 159
160/**********************************************************
161 Poll based get keycode functions
162 **********************************************************/
163
164static int default_polling_getkey(struct em28xx_IR *ir)
165{
166 struct em28xx *dev = ir->dev;
167 int rc;
168 u32 msg;
169
170 /* Read key toggle, brand, and key code */
171 rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR,
172 (u8 *)&msg, sizeof(msg));
173 if (rc < 0)
174 return rc;
175
176 return (int)(msg & 0x7fffffffl);
177}
178
179/**********************************************************
180 Polling code for em28xx
181 **********************************************************/
182
183static void em28xx_ir_handle_key(struct em28xx_IR *ir)
184{
185 int gpio;
186 u32 data;
187
188 /* read gpio value */
189 gpio = ir->get_key(ir);
190 if (gpio < 0)
191 return;
192
193 if (gpio == ir->last_gpio)
194 return;
195 ir->last_gpio = gpio;
196
197 /* extract data */
198 data = ir_extract_bits(gpio, ir->mask_keycode);
199 dprintk("irq gpio=0x%x code=%d | poll%s%s\n",
200 gpio, data,
201 (gpio & ir->mask_keydown) ? " down" : "",
202 (gpio & ir->mask_keyup) ? " up" : "");
203
204 /* Generate keyup/keydown events */
205 if (ir->mask_keydown) {
206 /* bit set on keydown */
207 if (gpio & ir->mask_keydown)
208 ir_input_keydown(ir->input, &ir->ir, data, data);
209 else
210 ir_input_nokey(ir->input, &ir->ir);
211 } else if (ir->mask_keyup) {
212 /* bit cleared on keydown */
213 if (!(gpio & ir->mask_keyup))
214 ir_input_keydown(ir->input, &ir->ir, data, data);
215 else
216 ir_input_nokey(ir->input, &ir->ir);
217 } else {
218 /* can't distinguish keydown/up :-/ */
219 ir_input_keydown(ir->input, &ir->ir, data, data);
220 ir_input_nokey(ir->input, &ir->ir);
221 }
222}
223
224static void ir_timer(unsigned long data)
225{
226 struct em28xx_IR *ir = (struct em28xx_IR *)data;
227
228 schedule_work(&ir->work);
229}
230
231static void em28xx_ir_work(struct work_struct *work)
232{
233 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work);
234
235 em28xx_ir_handle_key(ir);
236 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
237}
238
239void em28xx_ir_start(struct em28xx_IR *ir)
240{
241 setup_timer(&ir->timer, ir_timer, (unsigned long)ir);
242 INIT_WORK(&ir->work, em28xx_ir_work);
243 schedule_work(&ir->work);
244}
245
246static void em28xx_ir_stop(struct em28xx_IR *ir)
247{
248 del_timer_sync(&ir->timer);
249 flush_scheduled_work();
250}
251
252int em28xx_ir_init(struct em28xx *dev)
253{
254 struct em28xx_IR *ir;
255 struct input_dev *input_dev;
256 IR_KEYTAB_TYPE *ir_codes = NULL;
257 int ir_type = IR_TYPE_OTHER;
258 int err = -ENOMEM;
259
260 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
261 input_dev = input_allocate_device();
262 if (!ir || !input_dev)
263 goto err_out_free;
264
265 ir->input = input_dev;
266
267 /* */
268 ir->get_key = default_polling_getkey;
269 ir->polling = 50; /* ms */
270
271 /* detect & configure */
272 switch (dev->model) {
273 }
274
275 if (NULL == ir_codes) {
276 err = -ENODEV;
277 goto err_out_free;
278 }
279
280 /* Get the current key status, to avoid adding an
281 unexistent key code */
282 ir->last_gpio = ir->get_key(ir);
283
284 /* init input device */
285 snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)",
286 dev->name);
287
288 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
289 strlcat(ir->phys, "/input0", sizeof(ir->phys));
290
291 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
292 input_dev->name = ir->name;
293 input_dev->phys = ir->phys;
294 input_dev->id.bustype = BUS_USB;
295 input_dev->id.version = 1;
296 input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
297 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
298
299 input_dev->dev.parent = &dev->udev->dev;
300 /* record handles to ourself */
301 ir->dev = dev;
302 dev->ir = ir;
303
304 em28xx_ir_start(ir);
305
306 /* all done */
307 err = input_register_device(ir->input);
308 if (err)
309 goto err_out_stop;
310
311 return 0;
312 err_out_stop:
313 em28xx_ir_stop(ir);
314 dev->ir = NULL;
315 err_out_free:
316 input_free_device(input_dev);
317 kfree(ir);
318 return err;
319}
320
321int em28xx_ir_fini(struct em28xx *dev)
322{
323 struct em28xx_IR *ir = dev->ir;
324
325 /* skip detach on non attached boards */
326 if (!ir)
327 return 0;
328
329 em28xx_ir_stop(ir);
330 input_unregister_device(ir->input);
331 kfree(ir);
332
333 /* done */
334 dev->ir = NULL;
335 return 0;
336}
337
338/**********************************************************
339 Handle Webcam snapshot button
340 **********************************************************/
341
131static void em28xx_query_sbutton(struct work_struct *work) 342static void em28xx_query_sbutton(struct work_struct *work)
132{ 343{
133 /* Poll the register and see if the button is depressed */ 344 /* Poll the register and see if the button is depressed */
@@ -210,9 +421,3 @@ void em28xx_deregister_snapshot_button(struct em28xx *dev)
210 } 421 }
211 return; 422 return;
212} 423}
213
214/* ----------------------------------------------------------------------
215 * Local variables:
216 * c-basic-offset: 8
217 * End:
218 */
diff --git a/drivers/media/video/em28xx/em28xx-reg.h b/drivers/media/video/em28xx/em28xx-reg.h
index 50d1790d84fc..f67955a1b818 100644
--- a/drivers/media/video/em28xx/em28xx-reg.h
+++ b/drivers/media/video/em28xx/em28xx-reg.h
@@ -71,6 +71,13 @@
71#define EM28XX_R42_AC97ADDR 0x42 71#define EM28XX_R42_AC97ADDR 0x42
72#define EM28XX_R43_AC97BUSY 0x43 72#define EM28XX_R43_AC97BUSY 0x43
73 73
74#define EM28XX_R45_IR 0x45
75 /* 0x45 bit 7 - parity bit
76 bits 6-0 - count
77 0x46 IR brand
78 0x47 IR data
79 */
80
74/* em202 registers */ 81/* em202 registers */
75#define EM28XX_R02_MASTER_AC97 0x02 82#define EM28XX_R02_MASTER_AC97 0x02
76#define EM28XX_R10_LINE_IN_AC97 0x10 83#define EM28XX_R10_LINE_IN_AC97 0x10
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 129bd06a2ea6..154a99c61ee6 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1603,6 +1603,10 @@ static void em28xx_release_resources(struct em28xx *dev)
1603 list_del(&dev->devlist); 1603 list_del(&dev->devlist);
1604 if (dev->sbutton_input_dev) 1604 if (dev->sbutton_input_dev)
1605 em28xx_deregister_snapshot_button(dev); 1605 em28xx_deregister_snapshot_button(dev);
1606
1607 if (dev->ir)
1608 em28xx_ir_fini(dev);
1609
1606 if (dev->radio_dev) { 1610 if (dev->radio_dev) {
1607 if (-1 != dev->radio_dev->minor) 1611 if (-1 != dev->radio_dev->minor)
1608 video_unregister_device(dev->radio_dev); 1612 video_unregister_device(dev->radio_dev);
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 1350a9cea7c5..73fd9e9e0403 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -384,6 +384,8 @@ struct em28xx {
384 unsigned int has_snapshot_button:1; 384 unsigned int has_snapshot_button:1;
385 unsigned int valid:1; /* report for validated boards */ 385 unsigned int valid:1; /* report for validated boards */
386 386
387 struct em28xx_IR *ir;
388
387 /* Some older em28xx chips needs a waiting time after writing */ 389 /* Some older em28xx chips needs a waiting time after writing */
388 unsigned int wait_after_write; 390 unsigned int wait_after_write;
389 391
@@ -544,7 +546,6 @@ void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir);
544int em28xx_tuner_callback(void *ptr, int component, int command, int arg); 546int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
545 547
546/* Provided by em28xx-input.c */ 548/* Provided by em28xx-input.c */
547/* TODO: Check if the standard get_key handlers on ir-common can be used */
548int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw); 549int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);
549int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw); 550int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);
550int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, 551int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
@@ -552,6 +553,9 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
552void em28xx_register_snapshot_button(struct em28xx *dev); 553void em28xx_register_snapshot_button(struct em28xx *dev);
553void em28xx_deregister_snapshot_button(struct em28xx *dev); 554void em28xx_deregister_snapshot_button(struct em28xx *dev);
554 555
556int em28xx_ir_init(struct em28xx *dev);
557int em28xx_ir_fini(struct em28xx *dev);
558
555/* printk macros */ 559/* printk macros */
556 560
557#define em28xx_err(fmt, arg...) do {\ 561#define em28xx_err(fmt, arg...) do {\