diff options
Diffstat (limited to 'drivers/staging/lirc')
-rw-r--r-- | drivers/staging/lirc/TODO.lirc_zilog | 36 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_imon.c | 1 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_it87.c | 1 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_parallel.c | 19 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_sasem.c | 1 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_serial.c | 3 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_sir.c | 1 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_zilog.c | 650 |
8 files changed, 403 insertions, 309 deletions
diff --git a/drivers/staging/lirc/TODO.lirc_zilog b/drivers/staging/lirc/TODO.lirc_zilog index 6aa312df401..2d0263f0793 100644 --- a/drivers/staging/lirc/TODO.lirc_zilog +++ b/drivers/staging/lirc/TODO.lirc_zilog | |||
@@ -1,13 +1,37 @@ | |||
1 | The binding between hdpvr and lirc_zilog is currently disabled, | 1 | 1. Both ir-kbd-i2c and lirc_zilog provide support for RX events. |
2 | The 'tx_only' lirc_zilog module parameter will allow ir-kbd-i2c | ||
3 | and lirc_zilog to coexist in the kernel, if the user requires such a set-up. | ||
4 | However the IR unit will not work well without coordination between the | ||
5 | two modules. A shared mutex, for transceiver access locking, needs to be | ||
6 | supplied by bridge drivers, in struct IR_i2_init_data, to both ir-kbd-i2c | ||
7 | and lirc_zilog, before they will coexist usefully. This should be fixed | ||
8 | before moving out of staging. | ||
9 | |||
10 | 2. References and locking need careful examination. For cx18 and ivtv PCI | ||
11 | cards, which are not easily "hot unplugged", the imperfect state of reference | ||
12 | counting and locking is acceptable if not correct. For USB connected units | ||
13 | like HD PVR, PVR USB2, HVR-1900, and HVR1950, the likelyhood of an Ooops on | ||
14 | unplug is probably great. Proper reference counting and locking needs to be | ||
15 | implemented before this module is moved out of staging. | ||
16 | |||
17 | 3. The binding between hdpvr and lirc_zilog is currently disabled, | ||
2 | due to an OOPS reported a few years ago when both the hdpvr and cx18 | 18 | due to an OOPS reported a few years ago when both the hdpvr and cx18 |
3 | drivers were loaded in his system. More details can be seen at: | 19 | drivers were loaded in his system. More details can be seen at: |
4 | http://www.mail-archive.com/linux-media@vger.kernel.org/msg09163.html | 20 | http://www.mail-archive.com/linux-media@vger.kernel.org/msg09163.html |
5 | More tests need to be done, in order to fix the reported issue. | 21 | More tests need to be done, in order to fix the reported issue. |
6 | 22 | ||
7 | There's a conflict between ir-kbd-i2c: Both provide support for RX events. | 23 | 4. In addition to providing a shared mutex for transceiver access |
8 | Such conflict needs to be fixed, before moving it out of staging. | 24 | locking, bridge drivers, if able, should provide a chip reset() callback |
25 | to lirc_zilog via struct IR_i2c_init_data. cx18 and ivtv already have routines | ||
26 | to perform Z8 chip resets via GPIO manipulations. This will allow lirc_zilog | ||
27 | to bring the chip back to normal when it hangs, in the same places the | ||
28 | original lirc_pvr150 driver code does. This is not strictly needed, so it | ||
29 | is not required to move lirc_zilog out of staging. | ||
30 | |||
31 | 5. Both lirc_zilog and ir-kbd-i2c support the Zilog Z8 for IR, as programmed | ||
32 | and installed on Hauppauge products. When working on either module, developers | ||
33 | must consider at least the following bridge drivers which mention an IR Rx unit | ||
34 | at address 0x71 (indicative of a Z8): | ||
9 | 35 | ||
10 | The way I2C probe works, it will try to register the driver twice, one | 36 | ivtv cx18 hdpvr pvrusb2 bt8xx cx88 saa7134 |
11 | for RX and another for TX. The logic needs to be fixed to avoid such | ||
12 | issue. | ||
13 | 37 | ||
diff --git a/drivers/staging/lirc/lirc_imon.c b/drivers/staging/lirc/lirc_imon.c index 0da6b9518af..235cab0eb08 100644 --- a/drivers/staging/lirc/lirc_imon.c +++ b/drivers/staging/lirc/lirc_imon.c | |||
@@ -447,6 +447,7 @@ static ssize_t vfd_write(struct file *file, const char *buf, | |||
447 | 447 | ||
448 | exit: | 448 | exit: |
449 | mutex_unlock(&context->ctx_lock); | 449 | mutex_unlock(&context->ctx_lock); |
450 | kfree(data_buf); | ||
450 | 451 | ||
451 | return (!retval) ? n_bytes : retval; | 452 | return (!retval) ? n_bytes : retval; |
452 | } | 453 | } |
diff --git a/drivers/staging/lirc/lirc_it87.c b/drivers/staging/lirc/lirc_it87.c index 929ae579546..5938616f3e8 100644 --- a/drivers/staging/lirc/lirc_it87.c +++ b/drivers/staging/lirc/lirc_it87.c | |||
@@ -232,6 +232,7 @@ static ssize_t lirc_write(struct file *file, const char *buf, | |||
232 | i++; | 232 | i++; |
233 | } | 233 | } |
234 | terminate_send(tx_buf[i - 1]); | 234 | terminate_send(tx_buf[i - 1]); |
235 | kfree(tx_buf); | ||
235 | return n; | 236 | return n; |
236 | } | 237 | } |
237 | 238 | ||
diff --git a/drivers/staging/lirc/lirc_parallel.c b/drivers/staging/lirc/lirc_parallel.c index dfd2c447e67..3a9c09881b2 100644 --- a/drivers/staging/lirc/lirc_parallel.c +++ b/drivers/staging/lirc/lirc_parallel.c | |||
@@ -376,6 +376,7 @@ static ssize_t lirc_write(struct file *filep, const char *buf, size_t n, | |||
376 | unsigned long flags; | 376 | unsigned long flags; |
377 | int counttimer; | 377 | int counttimer; |
378 | int *wbuf; | 378 | int *wbuf; |
379 | ssize_t ret; | ||
379 | 380 | ||
380 | if (!is_claimed) | 381 | if (!is_claimed) |
381 | return -EBUSY; | 382 | return -EBUSY; |
@@ -393,8 +394,10 @@ static ssize_t lirc_write(struct file *filep, const char *buf, size_t n, | |||
393 | if (timer == 0) { | 394 | if (timer == 0) { |
394 | /* try again if device is ready */ | 395 | /* try again if device is ready */ |
395 | timer = init_lirc_timer(); | 396 | timer = init_lirc_timer(); |
396 | if (timer == 0) | 397 | if (timer == 0) { |
397 | return -EIO; | 398 | ret = -EIO; |
399 | goto out; | ||
400 | } | ||
398 | } | 401 | } |
399 | 402 | ||
400 | /* adjust values from usecs */ | 403 | /* adjust values from usecs */ |
@@ -420,7 +423,8 @@ static ssize_t lirc_write(struct file *filep, const char *buf, size_t n, | |||
420 | if (check_pselecd && (in(1) & LP_PSELECD)) { | 423 | if (check_pselecd && (in(1) & LP_PSELECD)) { |
421 | lirc_off(); | 424 | lirc_off(); |
422 | local_irq_restore(flags); | 425 | local_irq_restore(flags); |
423 | return -EIO; | 426 | ret = -EIO; |
427 | goto out; | ||
424 | } | 428 | } |
425 | } while (counttimer < wbuf[i]); | 429 | } while (counttimer < wbuf[i]); |
426 | i++; | 430 | i++; |
@@ -436,7 +440,8 @@ static ssize_t lirc_write(struct file *filep, const char *buf, size_t n, | |||
436 | level = newlevel; | 440 | level = newlevel; |
437 | if (check_pselecd && (in(1) & LP_PSELECD)) { | 441 | if (check_pselecd && (in(1) & LP_PSELECD)) { |
438 | local_irq_restore(flags); | 442 | local_irq_restore(flags); |
439 | return -EIO; | 443 | ret = -EIO; |
444 | goto out; | ||
440 | } | 445 | } |
441 | } while (counttimer < wbuf[i]); | 446 | } while (counttimer < wbuf[i]); |
442 | i++; | 447 | i++; |
@@ -445,7 +450,11 @@ static ssize_t lirc_write(struct file *filep, const char *buf, size_t n, | |||
445 | #else | 450 | #else |
446 | /* place code that handles write without external timer here */ | 451 | /* place code that handles write without external timer here */ |
447 | #endif | 452 | #endif |
448 | return n; | 453 | ret = n; |
454 | out: | ||
455 | kfree(wbuf); | ||
456 | |||
457 | return ret; | ||
449 | } | 458 | } |
450 | 459 | ||
451 | static unsigned int lirc_poll(struct file *file, poll_table *wait) | 460 | static unsigned int lirc_poll(struct file *file, poll_table *wait) |
diff --git a/drivers/staging/lirc/lirc_sasem.c b/drivers/staging/lirc/lirc_sasem.c index 998485ebdbc..925eabe1485 100644 --- a/drivers/staging/lirc/lirc_sasem.c +++ b/drivers/staging/lirc/lirc_sasem.c | |||
@@ -448,6 +448,7 @@ static ssize_t vfd_write(struct file *file, const char *buf, | |||
448 | exit: | 448 | exit: |
449 | 449 | ||
450 | mutex_unlock(&context->ctx_lock); | 450 | mutex_unlock(&context->ctx_lock); |
451 | kfree(data_buf); | ||
451 | 452 | ||
452 | return (!retval) ? n_bytes : retval; | 453 | return (!retval) ? n_bytes : retval; |
453 | } | 454 | } |
diff --git a/drivers/staging/lirc/lirc_serial.c b/drivers/staging/lirc/lirc_serial.c index 9bcf149c426..1c3099b388e 100644 --- a/drivers/staging/lirc/lirc_serial.c +++ b/drivers/staging/lirc/lirc_serial.c | |||
@@ -966,7 +966,7 @@ static ssize_t lirc_write(struct file *file, const char *buf, | |||
966 | if (n % sizeof(int) || count % 2 == 0) | 966 | if (n % sizeof(int) || count % 2 == 0) |
967 | return -EINVAL; | 967 | return -EINVAL; |
968 | wbuf = memdup_user(buf, n); | 968 | wbuf = memdup_user(buf, n); |
969 | if (PTR_ERR(wbuf)) | 969 | if (IS_ERR(wbuf)) |
970 | return PTR_ERR(wbuf); | 970 | return PTR_ERR(wbuf); |
971 | spin_lock_irqsave(&hardware[type].lock, flags); | 971 | spin_lock_irqsave(&hardware[type].lock, flags); |
972 | if (type == LIRC_IRDEO) { | 972 | if (type == LIRC_IRDEO) { |
@@ -981,6 +981,7 @@ static ssize_t lirc_write(struct file *file, const char *buf, | |||
981 | } | 981 | } |
982 | off(); | 982 | off(); |
983 | spin_unlock_irqrestore(&hardware[type].lock, flags); | 983 | spin_unlock_irqrestore(&hardware[type].lock, flags); |
984 | kfree(wbuf); | ||
984 | return n; | 985 | return n; |
985 | } | 986 | } |
986 | 987 | ||
diff --git a/drivers/staging/lirc/lirc_sir.c b/drivers/staging/lirc/lirc_sir.c index c553ab62623..76be7b8c620 100644 --- a/drivers/staging/lirc/lirc_sir.c +++ b/drivers/staging/lirc/lirc_sir.c | |||
@@ -330,6 +330,7 @@ static ssize_t lirc_write(struct file *file, const char *buf, size_t n, | |||
330 | /* enable receiver */ | 330 | /* enable receiver */ |
331 | Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE; | 331 | Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE; |
332 | #endif | 332 | #endif |
333 | kfree(tx_buf); | ||
333 | return count; | 334 | return count; |
334 | } | 335 | } |
335 | 336 | ||
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c index ad29bb1275a..3fe5f416019 100644 --- a/drivers/staging/lirc/lirc_zilog.c +++ b/drivers/staging/lirc/lirc_zilog.c | |||
@@ -20,6 +20,9 @@ | |||
20 | * | 20 | * |
21 | * parts are cut&pasted from the lirc_i2c.c driver | 21 | * parts are cut&pasted from the lirc_i2c.c driver |
22 | * | 22 | * |
23 | * Numerous changes updating lirc_zilog.c in kernel 2.6.38 and later are | ||
24 | * Copyright (C) 2011 Andy Walls <awalls@md.metrocast.net> | ||
25 | * | ||
23 | * This program is free software; you can redistribute it and/or modify | 26 | * This program is free software; you can redistribute it and/or modify |
24 | * it under the terms of the GNU General Public License as published by | 27 | * it under the terms of the GNU General Public License as published by |
25 | * the Free Software Foundation; either version 2 of the License, or | 28 | * the Free Software Foundation; either version 2 of the License, or |
@@ -60,38 +63,44 @@ | |||
60 | #include <media/lirc_dev.h> | 63 | #include <media/lirc_dev.h> |
61 | #include <media/lirc.h> | 64 | #include <media/lirc.h> |
62 | 65 | ||
63 | struct IR { | 66 | struct IR_rx { |
64 | struct lirc_driver l; | ||
65 | |||
66 | /* Device info */ | ||
67 | struct mutex ir_lock; | ||
68 | int open; | ||
69 | bool is_hdpvr; | ||
70 | |||
71 | /* RX device */ | 67 | /* RX device */ |
72 | struct i2c_client c_rx; | 68 | struct i2c_client *c; |
73 | int have_rx; | ||
74 | 69 | ||
75 | /* RX device buffer & lock */ | 70 | /* RX device buffer & lock */ |
76 | struct lirc_buffer buf; | 71 | struct lirc_buffer buf; |
77 | struct mutex buf_lock; | 72 | struct mutex buf_lock; |
78 | 73 | ||
79 | /* RX polling thread data */ | 74 | /* RX polling thread data */ |
80 | struct completion *t_notify; | ||
81 | struct completion *t_notify2; | ||
82 | int shutdown; | ||
83 | struct task_struct *task; | 75 | struct task_struct *task; |
84 | 76 | ||
85 | /* RX read data */ | 77 | /* RX read data */ |
86 | unsigned char b[3]; | 78 | unsigned char b[3]; |
79 | bool hdpvr_data_fmt; | ||
80 | }; | ||
87 | 81 | ||
82 | struct IR_tx { | ||
88 | /* TX device */ | 83 | /* TX device */ |
89 | struct i2c_client c_tx; | 84 | struct i2c_client *c; |
85 | |||
86 | /* TX additional actions needed */ | ||
90 | int need_boot; | 87 | int need_boot; |
91 | int have_tx; | 88 | bool post_tx_ready_poll; |
89 | }; | ||
90 | |||
91 | struct IR { | ||
92 | struct lirc_driver l; | ||
93 | |||
94 | struct mutex ir_lock; | ||
95 | int open; | ||
96 | |||
97 | struct i2c_adapter *adapter; | ||
98 | struct IR_rx *rx; | ||
99 | struct IR_tx *tx; | ||
92 | }; | 100 | }; |
93 | 101 | ||
94 | /* Minor -> data mapping */ | 102 | /* Minor -> data mapping */ |
103 | static struct mutex ir_devices_lock; | ||
95 | static struct IR *ir_devices[MAX_IRCTL_DEVICES]; | 104 | static struct IR *ir_devices[MAX_IRCTL_DEVICES]; |
96 | 105 | ||
97 | /* Block size for IR transmitter */ | 106 | /* Block size for IR transmitter */ |
@@ -124,14 +133,11 @@ static struct mutex tx_data_lock; | |||
124 | #define zilog_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, \ | 133 | #define zilog_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, \ |
125 | ## args) | 134 | ## args) |
126 | #define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) | 135 | #define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) |
127 | 136 | #define zilog_info(s, args...) printk(KERN_INFO KBUILD_MODNAME ": " s, ## args) | |
128 | #define ZILOG_HAUPPAUGE_IR_RX_NAME "Zilog/Hauppauge IR RX" | ||
129 | #define ZILOG_HAUPPAUGE_IR_TX_NAME "Zilog/Hauppauge IR TX" | ||
130 | 137 | ||
131 | /* module parameters */ | 138 | /* module parameters */ |
132 | static int debug; /* debug output */ | 139 | static int debug; /* debug output */ |
133 | static int disable_rx; /* disable RX device */ | 140 | static int tx_only; /* only handle the IR Tx function */ |
134 | static int disable_tx; /* disable TX device */ | ||
135 | static int minor = -1; /* minor number */ | 141 | static int minor = -1; /* minor number */ |
136 | 142 | ||
137 | #define dprintk(fmt, args...) \ | 143 | #define dprintk(fmt, args...) \ |
@@ -150,8 +156,12 @@ static int add_to_buf(struct IR *ir) | |||
150 | int ret; | 156 | int ret; |
151 | int failures = 0; | 157 | int failures = 0; |
152 | unsigned char sendbuf[1] = { 0 }; | 158 | unsigned char sendbuf[1] = { 0 }; |
159 | struct IR_rx *rx = ir->rx; | ||
153 | 160 | ||
154 | if (lirc_buffer_full(&ir->buf)) { | 161 | if (rx == NULL) |
162 | return -ENXIO; | ||
163 | |||
164 | if (lirc_buffer_full(&rx->buf)) { | ||
155 | dprintk("buffer overflow\n"); | 165 | dprintk("buffer overflow\n"); |
156 | return -EOVERFLOW; | 166 | return -EOVERFLOW; |
157 | } | 167 | } |
@@ -161,17 +171,25 @@ static int add_to_buf(struct IR *ir) | |||
161 | * data and we have space | 171 | * data and we have space |
162 | */ | 172 | */ |
163 | do { | 173 | do { |
174 | if (kthread_should_stop()) | ||
175 | return -ENODATA; | ||
176 | |||
164 | /* | 177 | /* |
165 | * Lock i2c bus for the duration. RX/TX chips interfere so | 178 | * Lock i2c bus for the duration. RX/TX chips interfere so |
166 | * this is worth it | 179 | * this is worth it |
167 | */ | 180 | */ |
168 | mutex_lock(&ir->ir_lock); | 181 | mutex_lock(&ir->ir_lock); |
169 | 182 | ||
183 | if (kthread_should_stop()) { | ||
184 | mutex_unlock(&ir->ir_lock); | ||
185 | return -ENODATA; | ||
186 | } | ||
187 | |||
170 | /* | 188 | /* |
171 | * Send random "poll command" (?) Windows driver does this | 189 | * Send random "poll command" (?) Windows driver does this |
172 | * and it is a good point to detect chip failure. | 190 | * and it is a good point to detect chip failure. |
173 | */ | 191 | */ |
174 | ret = i2c_master_send(&ir->c_rx, sendbuf, 1); | 192 | ret = i2c_master_send(rx->c, sendbuf, 1); |
175 | if (ret != 1) { | 193 | if (ret != 1) { |
176 | zilog_error("i2c_master_send failed with %d\n", ret); | 194 | zilog_error("i2c_master_send failed with %d\n", ret); |
177 | if (failures >= 3) { | 195 | if (failures >= 3) { |
@@ -186,45 +204,53 @@ static int add_to_buf(struct IR *ir) | |||
186 | "trying reset\n"); | 204 | "trying reset\n"); |
187 | 205 | ||
188 | set_current_state(TASK_UNINTERRUPTIBLE); | 206 | set_current_state(TASK_UNINTERRUPTIBLE); |
207 | if (kthread_should_stop()) { | ||
208 | mutex_unlock(&ir->ir_lock); | ||
209 | return -ENODATA; | ||
210 | } | ||
189 | schedule_timeout((100 * HZ + 999) / 1000); | 211 | schedule_timeout((100 * HZ + 999) / 1000); |
190 | ir->need_boot = 1; | 212 | ir->tx->need_boot = 1; |
191 | 213 | ||
192 | ++failures; | 214 | ++failures; |
193 | mutex_unlock(&ir->ir_lock); | 215 | mutex_unlock(&ir->ir_lock); |
194 | continue; | 216 | continue; |
195 | } | 217 | } |
196 | 218 | ||
197 | ret = i2c_master_recv(&ir->c_rx, keybuf, sizeof(keybuf)); | 219 | if (kthread_should_stop()) { |
220 | mutex_unlock(&ir->ir_lock); | ||
221 | return -ENODATA; | ||
222 | } | ||
223 | ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf)); | ||
198 | mutex_unlock(&ir->ir_lock); | 224 | mutex_unlock(&ir->ir_lock); |
199 | if (ret != sizeof(keybuf)) { | 225 | if (ret != sizeof(keybuf)) { |
200 | zilog_error("i2c_master_recv failed with %d -- " | 226 | zilog_error("i2c_master_recv failed with %d -- " |
201 | "keeping last read buffer\n", ret); | 227 | "keeping last read buffer\n", ret); |
202 | } else { | 228 | } else { |
203 | ir->b[0] = keybuf[3]; | 229 | rx->b[0] = keybuf[3]; |
204 | ir->b[1] = keybuf[4]; | 230 | rx->b[1] = keybuf[4]; |
205 | ir->b[2] = keybuf[5]; | 231 | rx->b[2] = keybuf[5]; |
206 | dprintk("key (0x%02x/0x%02x)\n", ir->b[0], ir->b[1]); | 232 | dprintk("key (0x%02x/0x%02x)\n", rx->b[0], rx->b[1]); |
207 | } | 233 | } |
208 | 234 | ||
209 | /* key pressed ? */ | 235 | /* key pressed ? */ |
210 | if (ir->is_hdpvr) { | 236 | if (rx->hdpvr_data_fmt) { |
211 | if (got_data && (keybuf[0] == 0x80)) | 237 | if (got_data && (keybuf[0] == 0x80)) |
212 | return 0; | 238 | return 0; |
213 | else if (got_data && (keybuf[0] == 0x00)) | 239 | else if (got_data && (keybuf[0] == 0x00)) |
214 | return -ENODATA; | 240 | return -ENODATA; |
215 | } else if ((ir->b[0] & 0x80) == 0) | 241 | } else if ((rx->b[0] & 0x80) == 0) |
216 | return got_data ? 0 : -ENODATA; | 242 | return got_data ? 0 : -ENODATA; |
217 | 243 | ||
218 | /* look what we have */ | 244 | /* look what we have */ |
219 | code = (((__u16)ir->b[0] & 0x7f) << 6) | (ir->b[1] >> 2); | 245 | code = (((__u16)rx->b[0] & 0x7f) << 6) | (rx->b[1] >> 2); |
220 | 246 | ||
221 | codes[0] = (code >> 8) & 0xff; | 247 | codes[0] = (code >> 8) & 0xff; |
222 | codes[1] = code & 0xff; | 248 | codes[1] = code & 0xff; |
223 | 249 | ||
224 | /* return it */ | 250 | /* return it */ |
225 | lirc_buffer_write(&ir->buf, codes); | 251 | lirc_buffer_write(&rx->buf, codes); |
226 | ++got_data; | 252 | ++got_data; |
227 | } while (!lirc_buffer_full(&ir->buf)); | 253 | } while (!lirc_buffer_full(&rx->buf)); |
228 | 254 | ||
229 | return 0; | 255 | return 0; |
230 | } | 256 | } |
@@ -242,46 +268,35 @@ static int add_to_buf(struct IR *ir) | |||
242 | static int lirc_thread(void *arg) | 268 | static int lirc_thread(void *arg) |
243 | { | 269 | { |
244 | struct IR *ir = arg; | 270 | struct IR *ir = arg; |
245 | 271 | struct IR_rx *rx = ir->rx; | |
246 | if (ir->t_notify != NULL) | ||
247 | complete(ir->t_notify); | ||
248 | 272 | ||
249 | dprintk("poll thread started\n"); | 273 | dprintk("poll thread started\n"); |
250 | 274 | ||
251 | do { | 275 | while (!kthread_should_stop()) { |
252 | if (ir->open) { | 276 | set_current_state(TASK_INTERRUPTIBLE); |
253 | set_current_state(TASK_INTERRUPTIBLE); | ||
254 | 277 | ||
255 | /* | 278 | /* if device not opened, we can sleep half a second */ |
256 | * This is ~113*2 + 24 + jitter (2*repeat gap + | 279 | if (!ir->open) { |
257 | * code length). We use this interval as the chip | ||
258 | * resets every time you poll it (bad!). This is | ||
259 | * therefore just sufficient to catch all of the | ||
260 | * button presses. It makes the remote much more | ||
261 | * responsive. You can see the difference by | ||
262 | * running irw and holding down a button. With | ||
263 | * 100ms, the old polling interval, you'll notice | ||
264 | * breaks in the repeat sequence corresponding to | ||
265 | * lost keypresses. | ||
266 | */ | ||
267 | schedule_timeout((260 * HZ) / 1000); | ||
268 | if (ir->shutdown) | ||
269 | break; | ||
270 | if (!add_to_buf(ir)) | ||
271 | wake_up_interruptible(&ir->buf.wait_poll); | ||
272 | } else { | ||
273 | /* if device not opened so we can sleep half a second */ | ||
274 | set_current_state(TASK_INTERRUPTIBLE); | ||
275 | schedule_timeout(HZ/2); | 280 | schedule_timeout(HZ/2); |
281 | continue; | ||
276 | } | 282 | } |
277 | } while (!ir->shutdown); | ||
278 | |||
279 | if (ir->t_notify2 != NULL) | ||
280 | wait_for_completion(ir->t_notify2); | ||
281 | 283 | ||
282 | ir->task = NULL; | 284 | /* |
283 | if (ir->t_notify != NULL) | 285 | * This is ~113*2 + 24 + jitter (2*repeat gap + code length). |
284 | complete(ir->t_notify); | 286 | * We use this interval as the chip resets every time you poll |
287 | * it (bad!). This is therefore just sufficient to catch all | ||
288 | * of the button presses. It makes the remote much more | ||
289 | * responsive. You can see the difference by running irw and | ||
290 | * holding down a button. With 100ms, the old polling | ||
291 | * interval, you'll notice breaks in the repeat sequence | ||
292 | * corresponding to lost keypresses. | ||
293 | */ | ||
294 | schedule_timeout((260 * HZ) / 1000); | ||
295 | if (kthread_should_stop()) | ||
296 | break; | ||
297 | if (!add_to_buf(ir)) | ||
298 | wake_up_interruptible(&rx->buf.wait_poll); | ||
299 | } | ||
285 | 300 | ||
286 | dprintk("poll thread ended\n"); | 301 | dprintk("poll thread ended\n"); |
287 | return 0; | 302 | return 0; |
@@ -299,10 +314,10 @@ static int set_use_inc(void *data) | |||
299 | * this is completely broken code. lirc_unregister_driver() | 314 | * this is completely broken code. lirc_unregister_driver() |
300 | * must be possible even when the device is open | 315 | * must be possible even when the device is open |
301 | */ | 316 | */ |
302 | if (ir->c_rx.addr) | 317 | if (ir->rx != NULL) |
303 | i2c_use_client(&ir->c_rx); | 318 | i2c_use_client(ir->rx->c); |
304 | if (ir->c_tx.addr) | 319 | if (ir->tx != NULL) |
305 | i2c_use_client(&ir->c_tx); | 320 | i2c_use_client(ir->tx->c); |
306 | 321 | ||
307 | return 0; | 322 | return 0; |
308 | } | 323 | } |
@@ -311,10 +326,10 @@ static void set_use_dec(void *data) | |||
311 | { | 326 | { |
312 | struct IR *ir = data; | 327 | struct IR *ir = data; |
313 | 328 | ||
314 | if (ir->c_rx.addr) | 329 | if (ir->rx) |
315 | i2c_release_client(&ir->c_rx); | 330 | i2c_release_client(ir->rx->c); |
316 | if (ir->c_tx.addr) | 331 | if (ir->tx) |
317 | i2c_release_client(&ir->c_tx); | 332 | i2c_release_client(ir->tx->c); |
318 | if (ir->l.owner != NULL) | 333 | if (ir->l.owner != NULL) |
319 | module_put(ir->l.owner); | 334 | module_put(ir->l.owner); |
320 | } | 335 | } |
@@ -453,7 +468,7 @@ corrupt: | |||
453 | } | 468 | } |
454 | 469 | ||
455 | /* send a block of data to the IR TX device */ | 470 | /* send a block of data to the IR TX device */ |
456 | static int send_data_block(struct IR *ir, unsigned char *data_block) | 471 | static int send_data_block(struct IR_tx *tx, unsigned char *data_block) |
457 | { | 472 | { |
458 | int i, j, ret; | 473 | int i, j, ret; |
459 | unsigned char buf[5]; | 474 | unsigned char buf[5]; |
@@ -467,7 +482,7 @@ static int send_data_block(struct IR *ir, unsigned char *data_block) | |||
467 | buf[1 + j] = data_block[i + j]; | 482 | buf[1 + j] = data_block[i + j]; |
468 | dprintk("%02x %02x %02x %02x %02x", | 483 | dprintk("%02x %02x %02x %02x %02x", |
469 | buf[0], buf[1], buf[2], buf[3], buf[4]); | 484 | buf[0], buf[1], buf[2], buf[3], buf[4]); |
470 | ret = i2c_master_send(&ir->c_tx, buf, tosend + 1); | 485 | ret = i2c_master_send(tx->c, buf, tosend + 1); |
471 | if (ret != tosend + 1) { | 486 | if (ret != tosend + 1) { |
472 | zilog_error("i2c_master_send failed with %d\n", ret); | 487 | zilog_error("i2c_master_send failed with %d\n", ret); |
473 | return ret < 0 ? ret : -EFAULT; | 488 | return ret < 0 ? ret : -EFAULT; |
@@ -478,32 +493,32 @@ static int send_data_block(struct IR *ir, unsigned char *data_block) | |||
478 | } | 493 | } |
479 | 494 | ||
480 | /* send boot data to the IR TX device */ | 495 | /* send boot data to the IR TX device */ |
481 | static int send_boot_data(struct IR *ir) | 496 | static int send_boot_data(struct IR_tx *tx) |
482 | { | 497 | { |
483 | int ret; | 498 | int ret; |
484 | unsigned char buf[4]; | 499 | unsigned char buf[4]; |
485 | 500 | ||
486 | /* send the boot block */ | 501 | /* send the boot block */ |
487 | ret = send_data_block(ir, tx_data->boot_data); | 502 | ret = send_data_block(tx, tx_data->boot_data); |
488 | if (ret != 0) | 503 | if (ret != 0) |
489 | return ret; | 504 | return ret; |
490 | 505 | ||
491 | /* kick it off? */ | 506 | /* kick it off? */ |
492 | buf[0] = 0x00; | 507 | buf[0] = 0x00; |
493 | buf[1] = 0x20; | 508 | buf[1] = 0x20; |
494 | ret = i2c_master_send(&ir->c_tx, buf, 2); | 509 | ret = i2c_master_send(tx->c, buf, 2); |
495 | if (ret != 2) { | 510 | if (ret != 2) { |
496 | zilog_error("i2c_master_send failed with %d\n", ret); | 511 | zilog_error("i2c_master_send failed with %d\n", ret); |
497 | return ret < 0 ? ret : -EFAULT; | 512 | return ret < 0 ? ret : -EFAULT; |
498 | } | 513 | } |
499 | ret = i2c_master_send(&ir->c_tx, buf, 1); | 514 | ret = i2c_master_send(tx->c, buf, 1); |
500 | if (ret != 1) { | 515 | if (ret != 1) { |
501 | zilog_error("i2c_master_send failed with %d\n", ret); | 516 | zilog_error("i2c_master_send failed with %d\n", ret); |
502 | return ret < 0 ? ret : -EFAULT; | 517 | return ret < 0 ? ret : -EFAULT; |
503 | } | 518 | } |
504 | 519 | ||
505 | /* Here comes the firmware version... (hopefully) */ | 520 | /* Here comes the firmware version... (hopefully) */ |
506 | ret = i2c_master_recv(&ir->c_tx, buf, 4); | 521 | ret = i2c_master_recv(tx->c, buf, 4); |
507 | if (ret != 4) { | 522 | if (ret != 4) { |
508 | zilog_error("i2c_master_recv failed with %d\n", ret); | 523 | zilog_error("i2c_master_recv failed with %d\n", ret); |
509 | return 0; | 524 | return 0; |
@@ -543,7 +558,7 @@ static void fw_unload(void) | |||
543 | } | 558 | } |
544 | 559 | ||
545 | /* load "firmware" for the IR TX device */ | 560 | /* load "firmware" for the IR TX device */ |
546 | static int fw_load(struct IR *ir) | 561 | static int fw_load(struct IR_tx *tx) |
547 | { | 562 | { |
548 | int ret; | 563 | int ret; |
549 | unsigned int i; | 564 | unsigned int i; |
@@ -558,7 +573,7 @@ static int fw_load(struct IR *ir) | |||
558 | } | 573 | } |
559 | 574 | ||
560 | /* Request codeset data file */ | 575 | /* Request codeset data file */ |
561 | ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &ir->c_tx.dev); | 576 | ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &tx->c->dev); |
562 | if (ret != 0) { | 577 | if (ret != 0) { |
563 | zilog_error("firmware haup-ir-blaster.bin not available " | 578 | zilog_error("firmware haup-ir-blaster.bin not available " |
564 | "(%d)\n", ret); | 579 | "(%d)\n", ret); |
@@ -685,20 +700,20 @@ out: | |||
685 | } | 700 | } |
686 | 701 | ||
687 | /* initialise the IR TX device */ | 702 | /* initialise the IR TX device */ |
688 | static int tx_init(struct IR *ir) | 703 | static int tx_init(struct IR_tx *tx) |
689 | { | 704 | { |
690 | int ret; | 705 | int ret; |
691 | 706 | ||
692 | /* Load 'firmware' */ | 707 | /* Load 'firmware' */ |
693 | ret = fw_load(ir); | 708 | ret = fw_load(tx); |
694 | if (ret != 0) | 709 | if (ret != 0) |
695 | return ret; | 710 | return ret; |
696 | 711 | ||
697 | /* Send boot block */ | 712 | /* Send boot block */ |
698 | ret = send_boot_data(ir); | 713 | ret = send_boot_data(tx); |
699 | if (ret != 0) | 714 | if (ret != 0) |
700 | return ret; | 715 | return ret; |
701 | ir->need_boot = 0; | 716 | tx->need_boot = 0; |
702 | 717 | ||
703 | /* Looks good */ | 718 | /* Looks good */ |
704 | return 0; | 719 | return 0; |
@@ -714,20 +729,20 @@ static loff_t lseek(struct file *filep, loff_t offset, int orig) | |||
714 | static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | 729 | static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) |
715 | { | 730 | { |
716 | struct IR *ir = filep->private_data; | 731 | struct IR *ir = filep->private_data; |
717 | unsigned char buf[ir->buf.chunk_size]; | 732 | struct IR_rx *rx = ir->rx; |
718 | int ret = 0, written = 0; | 733 | int ret = 0, written = 0; |
719 | DECLARE_WAITQUEUE(wait, current); | 734 | DECLARE_WAITQUEUE(wait, current); |
720 | 735 | ||
721 | dprintk("read called\n"); | 736 | dprintk("read called\n"); |
722 | if (ir->c_rx.addr == 0) | 737 | if (rx == NULL) |
723 | return -ENODEV; | 738 | return -ENODEV; |
724 | 739 | ||
725 | if (mutex_lock_interruptible(&ir->buf_lock)) | 740 | if (mutex_lock_interruptible(&rx->buf_lock)) |
726 | return -ERESTARTSYS; | 741 | return -ERESTARTSYS; |
727 | 742 | ||
728 | if (n % ir->buf.chunk_size) { | 743 | if (n % rx->buf.chunk_size) { |
729 | dprintk("read result = -EINVAL\n"); | 744 | dprintk("read result = -EINVAL\n"); |
730 | mutex_unlock(&ir->buf_lock); | 745 | mutex_unlock(&rx->buf_lock); |
731 | return -EINVAL; | 746 | return -EINVAL; |
732 | } | 747 | } |
733 | 748 | ||
@@ -736,7 +751,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
736 | * to avoid losing scan code (in case when queue is awaken somewhere | 751 | * to avoid losing scan code (in case when queue is awaken somewhere |
737 | * between while condition checking and scheduling) | 752 | * between while condition checking and scheduling) |
738 | */ | 753 | */ |
739 | add_wait_queue(&ir->buf.wait_poll, &wait); | 754 | add_wait_queue(&rx->buf.wait_poll, &wait); |
740 | set_current_state(TASK_INTERRUPTIBLE); | 755 | set_current_state(TASK_INTERRUPTIBLE); |
741 | 756 | ||
742 | /* | 757 | /* |
@@ -744,7 +759,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
744 | * mode and 'copy_to_user' is happy, wait for data. | 759 | * mode and 'copy_to_user' is happy, wait for data. |
745 | */ | 760 | */ |
746 | while (written < n && ret == 0) { | 761 | while (written < n && ret == 0) { |
747 | if (lirc_buffer_empty(&ir->buf)) { | 762 | if (lirc_buffer_empty(&rx->buf)) { |
748 | /* | 763 | /* |
749 | * According to the read(2) man page, 'written' can be | 764 | * According to the read(2) man page, 'written' can be |
750 | * returned as less than 'n', instead of blocking | 765 | * returned as less than 'n', instead of blocking |
@@ -764,16 +779,17 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
764 | schedule(); | 779 | schedule(); |
765 | set_current_state(TASK_INTERRUPTIBLE); | 780 | set_current_state(TASK_INTERRUPTIBLE); |
766 | } else { | 781 | } else { |
767 | lirc_buffer_read(&ir->buf, buf); | 782 | unsigned char buf[rx->buf.chunk_size]; |
783 | lirc_buffer_read(&rx->buf, buf); | ||
768 | ret = copy_to_user((void *)outbuf+written, buf, | 784 | ret = copy_to_user((void *)outbuf+written, buf, |
769 | ir->buf.chunk_size); | 785 | rx->buf.chunk_size); |
770 | written += ir->buf.chunk_size; | 786 | written += rx->buf.chunk_size; |
771 | } | 787 | } |
772 | } | 788 | } |
773 | 789 | ||
774 | remove_wait_queue(&ir->buf.wait_poll, &wait); | 790 | remove_wait_queue(&rx->buf.wait_poll, &wait); |
775 | set_current_state(TASK_RUNNING); | 791 | set_current_state(TASK_RUNNING); |
776 | mutex_unlock(&ir->buf_lock); | 792 | mutex_unlock(&rx->buf_lock); |
777 | 793 | ||
778 | dprintk("read result = %s (%d)\n", | 794 | dprintk("read result = %s (%d)\n", |
779 | ret ? "-EFAULT" : "OK", ret); | 795 | ret ? "-EFAULT" : "OK", ret); |
@@ -782,7 +798,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) | |||
782 | } | 798 | } |
783 | 799 | ||
784 | /* send a keypress to the IR TX device */ | 800 | /* send a keypress to the IR TX device */ |
785 | static int send_code(struct IR *ir, unsigned int code, unsigned int key) | 801 | static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key) |
786 | { | 802 | { |
787 | unsigned char data_block[TX_BLOCK_SIZE]; | 803 | unsigned char data_block[TX_BLOCK_SIZE]; |
788 | unsigned char buf[2]; | 804 | unsigned char buf[2]; |
@@ -799,26 +815,26 @@ static int send_code(struct IR *ir, unsigned int code, unsigned int key) | |||
799 | return ret; | 815 | return ret; |
800 | 816 | ||
801 | /* Send the data block */ | 817 | /* Send the data block */ |
802 | ret = send_data_block(ir, data_block); | 818 | ret = send_data_block(tx, data_block); |
803 | if (ret != 0) | 819 | if (ret != 0) |
804 | return ret; | 820 | return ret; |
805 | 821 | ||
806 | /* Send data block length? */ | 822 | /* Send data block length? */ |
807 | buf[0] = 0x00; | 823 | buf[0] = 0x00; |
808 | buf[1] = 0x40; | 824 | buf[1] = 0x40; |
809 | ret = i2c_master_send(&ir->c_tx, buf, 2); | 825 | ret = i2c_master_send(tx->c, buf, 2); |
810 | if (ret != 2) { | 826 | if (ret != 2) { |
811 | zilog_error("i2c_master_send failed with %d\n", ret); | 827 | zilog_error("i2c_master_send failed with %d\n", ret); |
812 | return ret < 0 ? ret : -EFAULT; | 828 | return ret < 0 ? ret : -EFAULT; |
813 | } | 829 | } |
814 | ret = i2c_master_send(&ir->c_tx, buf, 1); | 830 | ret = i2c_master_send(tx->c, buf, 1); |
815 | if (ret != 1) { | 831 | if (ret != 1) { |
816 | zilog_error("i2c_master_send failed with %d\n", ret); | 832 | zilog_error("i2c_master_send failed with %d\n", ret); |
817 | return ret < 0 ? ret : -EFAULT; | 833 | return ret < 0 ? ret : -EFAULT; |
818 | } | 834 | } |
819 | 835 | ||
820 | /* Send finished download? */ | 836 | /* Send finished download? */ |
821 | ret = i2c_master_recv(&ir->c_tx, buf, 1); | 837 | ret = i2c_master_recv(tx->c, buf, 1); |
822 | if (ret != 1) { | 838 | if (ret != 1) { |
823 | zilog_error("i2c_master_recv failed with %d\n", ret); | 839 | zilog_error("i2c_master_recv failed with %d\n", ret); |
824 | return ret < 0 ? ret : -EFAULT; | 840 | return ret < 0 ? ret : -EFAULT; |
@@ -832,7 +848,7 @@ static int send_code(struct IR *ir, unsigned int code, unsigned int key) | |||
832 | /* Send prepare command? */ | 848 | /* Send prepare command? */ |
833 | buf[0] = 0x00; | 849 | buf[0] = 0x00; |
834 | buf[1] = 0x80; | 850 | buf[1] = 0x80; |
835 | ret = i2c_master_send(&ir->c_tx, buf, 2); | 851 | ret = i2c_master_send(tx->c, buf, 2); |
836 | if (ret != 2) { | 852 | if (ret != 2) { |
837 | zilog_error("i2c_master_send failed with %d\n", ret); | 853 | zilog_error("i2c_master_send failed with %d\n", ret); |
838 | return ret < 0 ? ret : -EFAULT; | 854 | return ret < 0 ? ret : -EFAULT; |
@@ -843,7 +859,7 @@ static int send_code(struct IR *ir, unsigned int code, unsigned int key) | |||
843 | * last i2c_master_recv always fails with a -5, so for now, we're | 859 | * last i2c_master_recv always fails with a -5, so for now, we're |
844 | * going to skip this whole mess and say we're done on the HD PVR | 860 | * going to skip this whole mess and say we're done on the HD PVR |
845 | */ | 861 | */ |
846 | if (ir->is_hdpvr) { | 862 | if (!tx->post_tx_ready_poll) { |
847 | dprintk("sent code %u, key %u\n", code, key); | 863 | dprintk("sent code %u, key %u\n", code, key); |
848 | return 0; | 864 | return 0; |
849 | } | 865 | } |
@@ -857,7 +873,7 @@ static int send_code(struct IR *ir, unsigned int code, unsigned int key) | |||
857 | for (i = 0; i < 20; ++i) { | 873 | for (i = 0; i < 20; ++i) { |
858 | set_current_state(TASK_UNINTERRUPTIBLE); | 874 | set_current_state(TASK_UNINTERRUPTIBLE); |
859 | schedule_timeout((50 * HZ + 999) / 1000); | 875 | schedule_timeout((50 * HZ + 999) / 1000); |
860 | ret = i2c_master_send(&ir->c_tx, buf, 1); | 876 | ret = i2c_master_send(tx->c, buf, 1); |
861 | if (ret == 1) | 877 | if (ret == 1) |
862 | break; | 878 | break; |
863 | dprintk("NAK expected: i2c_master_send " | 879 | dprintk("NAK expected: i2c_master_send " |
@@ -870,7 +886,7 @@ static int send_code(struct IR *ir, unsigned int code, unsigned int key) | |||
870 | } | 886 | } |
871 | 887 | ||
872 | /* Seems to be an 'ok' response */ | 888 | /* Seems to be an 'ok' response */ |
873 | i = i2c_master_recv(&ir->c_tx, buf, 1); | 889 | i = i2c_master_recv(tx->c, buf, 1); |
874 | if (i != 1) { | 890 | if (i != 1) { |
875 | zilog_error("i2c_master_recv failed with %d\n", ret); | 891 | zilog_error("i2c_master_recv failed with %d\n", ret); |
876 | return -EFAULT; | 892 | return -EFAULT; |
@@ -895,10 +911,11 @@ static ssize_t write(struct file *filep, const char *buf, size_t n, | |||
895 | loff_t *ppos) | 911 | loff_t *ppos) |
896 | { | 912 | { |
897 | struct IR *ir = filep->private_data; | 913 | struct IR *ir = filep->private_data; |
914 | struct IR_tx *tx = ir->tx; | ||
898 | size_t i; | 915 | size_t i; |
899 | int failures = 0; | 916 | int failures = 0; |
900 | 917 | ||
901 | if (ir->c_tx.addr == 0) | 918 | if (tx == NULL) |
902 | return -ENODEV; | 919 | return -ENODEV; |
903 | 920 | ||
904 | /* Validate user parameters */ | 921 | /* Validate user parameters */ |
@@ -919,15 +936,15 @@ static ssize_t write(struct file *filep, const char *buf, size_t n, | |||
919 | } | 936 | } |
920 | 937 | ||
921 | /* Send boot data first if required */ | 938 | /* Send boot data first if required */ |
922 | if (ir->need_boot == 1) { | 939 | if (tx->need_boot == 1) { |
923 | ret = send_boot_data(ir); | 940 | ret = send_boot_data(tx); |
924 | if (ret == 0) | 941 | if (ret == 0) |
925 | ir->need_boot = 0; | 942 | tx->need_boot = 0; |
926 | } | 943 | } |
927 | 944 | ||
928 | /* Send the code */ | 945 | /* Send the code */ |
929 | if (ret == 0) { | 946 | if (ret == 0) { |
930 | ret = send_code(ir, (unsigned)command >> 16, | 947 | ret = send_code(tx, (unsigned)command >> 16, |
931 | (unsigned)command & 0xFFFF); | 948 | (unsigned)command & 0xFFFF); |
932 | if (ret == -EPROTO) { | 949 | if (ret == -EPROTO) { |
933 | mutex_unlock(&ir->ir_lock); | 950 | mutex_unlock(&ir->ir_lock); |
@@ -952,7 +969,7 @@ static ssize_t write(struct file *filep, const char *buf, size_t n, | |||
952 | } | 969 | } |
953 | set_current_state(TASK_UNINTERRUPTIBLE); | 970 | set_current_state(TASK_UNINTERRUPTIBLE); |
954 | schedule_timeout((100 * HZ + 999) / 1000); | 971 | schedule_timeout((100 * HZ + 999) / 1000); |
955 | ir->need_boot = 1; | 972 | tx->need_boot = 1; |
956 | ++failures; | 973 | ++failures; |
957 | } else | 974 | } else |
958 | i += sizeof(int); | 975 | i += sizeof(int); |
@@ -969,22 +986,23 @@ static ssize_t write(struct file *filep, const char *buf, size_t n, | |||
969 | static unsigned int poll(struct file *filep, poll_table *wait) | 986 | static unsigned int poll(struct file *filep, poll_table *wait) |
970 | { | 987 | { |
971 | struct IR *ir = filep->private_data; | 988 | struct IR *ir = filep->private_data; |
989 | struct IR_rx *rx = ir->rx; | ||
972 | unsigned int ret; | 990 | unsigned int ret; |
973 | 991 | ||
974 | dprintk("poll called\n"); | 992 | dprintk("poll called\n"); |
975 | if (ir->c_rx.addr == 0) | 993 | if (rx == NULL) |
976 | return -ENODEV; | 994 | return -ENODEV; |
977 | 995 | ||
978 | mutex_lock(&ir->buf_lock); | 996 | mutex_lock(&rx->buf_lock); |
979 | 997 | ||
980 | poll_wait(filep, &ir->buf.wait_poll, wait); | 998 | poll_wait(filep, &rx->buf.wait_poll, wait); |
981 | 999 | ||
982 | dprintk("poll result = %s\n", | 1000 | dprintk("poll result = %s\n", |
983 | lirc_buffer_empty(&ir->buf) ? "0" : "POLLIN|POLLRDNORM"); | 1001 | lirc_buffer_empty(&rx->buf) ? "0" : "POLLIN|POLLRDNORM"); |
984 | 1002 | ||
985 | ret = lirc_buffer_empty(&ir->buf) ? 0 : (POLLIN|POLLRDNORM); | 1003 | ret = lirc_buffer_empty(&rx->buf) ? 0 : (POLLIN|POLLRDNORM); |
986 | 1004 | ||
987 | mutex_unlock(&ir->buf_lock); | 1005 | mutex_unlock(&rx->buf_lock); |
988 | return ret; | 1006 | return ret; |
989 | } | 1007 | } |
990 | 1008 | ||
@@ -994,10 +1012,9 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg) | |||
994 | int result; | 1012 | int result; |
995 | unsigned long mode, features = 0; | 1013 | unsigned long mode, features = 0; |
996 | 1014 | ||
997 | if (ir->c_rx.addr != 0) | 1015 | features |= LIRC_CAN_SEND_PULSE; |
1016 | if (ir->rx != NULL) | ||
998 | features |= LIRC_CAN_REC_LIRCCODE; | 1017 | features |= LIRC_CAN_REC_LIRCCODE; |
999 | if (ir->c_tx.addr != 0) | ||
1000 | features |= LIRC_CAN_SEND_PULSE; | ||
1001 | 1018 | ||
1002 | switch (cmd) { | 1019 | switch (cmd) { |
1003 | case LIRC_GET_LENGTH: | 1020 | case LIRC_GET_LENGTH: |
@@ -1024,15 +1041,9 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg) | |||
1024 | result = -EINVAL; | 1041 | result = -EINVAL; |
1025 | break; | 1042 | break; |
1026 | case LIRC_GET_SEND_MODE: | 1043 | case LIRC_GET_SEND_MODE: |
1027 | if (!(features&LIRC_CAN_SEND_MASK)) | ||
1028 | return -ENOSYS; | ||
1029 | |||
1030 | result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg); | 1044 | result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg); |
1031 | break; | 1045 | break; |
1032 | case LIRC_SET_SEND_MODE: | 1046 | case LIRC_SET_SEND_MODE: |
1033 | if (!(features&LIRC_CAN_SEND_MASK)) | ||
1034 | return -ENOSYS; | ||
1035 | |||
1036 | result = get_user(mode, (unsigned long *) arg); | 1047 | result = get_user(mode, (unsigned long *) arg); |
1037 | if (!result && mode != LIRC_MODE_PULSE) | 1048 | if (!result && mode != LIRC_MODE_PULSE) |
1038 | return -EINVAL; | 1049 | return -EINVAL; |
@@ -1043,6 +1054,15 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg) | |||
1043 | return result; | 1054 | return result; |
1044 | } | 1055 | } |
1045 | 1056 | ||
1057 | /* ir_devices_lock must be held */ | ||
1058 | static struct IR *find_ir_device_by_minor(unsigned int minor) | ||
1059 | { | ||
1060 | if (minor >= MAX_IRCTL_DEVICES) | ||
1061 | return NULL; | ||
1062 | |||
1063 | return ir_devices[minor]; | ||
1064 | } | ||
1065 | |||
1046 | /* | 1066 | /* |
1047 | * Open the IR device. Get hold of our IR structure and | 1067 | * Open the IR device. Get hold of our IR structure and |
1048 | * stash it in private_data for the file | 1068 | * stash it in private_data for the file |
@@ -1051,15 +1071,15 @@ static int open(struct inode *node, struct file *filep) | |||
1051 | { | 1071 | { |
1052 | struct IR *ir; | 1072 | struct IR *ir; |
1053 | int ret; | 1073 | int ret; |
1074 | unsigned int minor = MINOR(node->i_rdev); | ||
1054 | 1075 | ||
1055 | /* find our IR struct */ | 1076 | /* find our IR struct */ |
1056 | unsigned minor = MINOR(node->i_rdev); | 1077 | mutex_lock(&ir_devices_lock); |
1057 | if (minor >= MAX_IRCTL_DEVICES) { | 1078 | ir = find_ir_device_by_minor(minor); |
1058 | dprintk("minor %d: open result = -ENODEV\n", | 1079 | mutex_unlock(&ir_devices_lock); |
1059 | minor); | 1080 | |
1081 | if (ir == NULL) | ||
1060 | return -ENODEV; | 1082 | return -ENODEV; |
1061 | } | ||
1062 | ir = ir_devices[minor]; | ||
1063 | 1083 | ||
1064 | /* increment in use count */ | 1084 | /* increment in use count */ |
1065 | mutex_lock(&ir->ir_lock); | 1085 | mutex_lock(&ir->ir_lock); |
@@ -1106,7 +1126,6 @@ static struct lirc_driver lirc_template = { | |||
1106 | 1126 | ||
1107 | static int ir_remove(struct i2c_client *client); | 1127 | static int ir_remove(struct i2c_client *client); |
1108 | static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id); | 1128 | static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id); |
1109 | static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg); | ||
1110 | 1129 | ||
1111 | #define ID_FLAG_TX 0x01 | 1130 | #define ID_FLAG_TX 0x01 |
1112 | #define ID_FLAG_HDPVR 0x02 | 1131 | #define ID_FLAG_HDPVR 0x02 |
@@ -1126,7 +1145,6 @@ static struct i2c_driver driver = { | |||
1126 | }, | 1145 | }, |
1127 | .probe = ir_probe, | 1146 | .probe = ir_probe, |
1128 | .remove = ir_remove, | 1147 | .remove = ir_remove, |
1129 | .command = ir_command, | ||
1130 | .id_table = ir_transceiver_id, | 1148 | .id_table = ir_transceiver_id, |
1131 | }; | 1149 | }; |
1132 | 1150 | ||
@@ -1144,214 +1162,253 @@ static const struct file_operations lirc_fops = { | |||
1144 | .release = close | 1162 | .release = close |
1145 | }; | 1163 | }; |
1146 | 1164 | ||
1147 | static int ir_remove(struct i2c_client *client) | 1165 | static void destroy_rx_kthread(struct IR_rx *rx) |
1148 | { | 1166 | { |
1149 | struct IR *ir = i2c_get_clientdata(client); | 1167 | /* end up polling thread */ |
1168 | if (rx != NULL && !IS_ERR_OR_NULL(rx->task)) { | ||
1169 | kthread_stop(rx->task); | ||
1170 | rx->task = NULL; | ||
1171 | } | ||
1172 | } | ||
1150 | 1173 | ||
1151 | mutex_lock(&ir->ir_lock); | 1174 | /* ir_devices_lock must be held */ |
1175 | static int add_ir_device(struct IR *ir) | ||
1176 | { | ||
1177 | int i; | ||
1152 | 1178 | ||
1153 | if (ir->have_rx || ir->have_tx) { | 1179 | for (i = 0; i < MAX_IRCTL_DEVICES; i++) |
1154 | DECLARE_COMPLETION(tn); | 1180 | if (ir_devices[i] == NULL) { |
1155 | DECLARE_COMPLETION(tn2); | 1181 | ir_devices[i] = ir; |
1156 | 1182 | break; | |
1157 | /* end up polling thread */ | ||
1158 | if (ir->task && !IS_ERR(ir->task)) { | ||
1159 | ir->t_notify = &tn; | ||
1160 | ir->t_notify2 = &tn2; | ||
1161 | ir->shutdown = 1; | ||
1162 | wake_up_process(ir->task); | ||
1163 | complete(&tn2); | ||
1164 | wait_for_completion(&tn); | ||
1165 | ir->t_notify = NULL; | ||
1166 | ir->t_notify2 = NULL; | ||
1167 | } | 1183 | } |
1168 | 1184 | ||
1169 | } else { | 1185 | return i == MAX_IRCTL_DEVICES ? -ENOMEM : i; |
1170 | mutex_unlock(&ir->ir_lock); | 1186 | } |
1171 | zilog_error("%s: detached from something we didn't " | 1187 | |
1172 | "attach to\n", __func__); | 1188 | /* ir_devices_lock must be held */ |
1173 | return -ENODEV; | 1189 | static void del_ir_device(struct IR *ir) |
1190 | { | ||
1191 | int i; | ||
1192 | |||
1193 | for (i = 0; i < MAX_IRCTL_DEVICES; i++) | ||
1194 | if (ir_devices[i] == ir) { | ||
1195 | ir_devices[i] = NULL; | ||
1196 | break; | ||
1197 | } | ||
1198 | } | ||
1199 | |||
1200 | static int ir_remove(struct i2c_client *client) | ||
1201 | { | ||
1202 | struct IR *ir = i2c_get_clientdata(client); | ||
1203 | |||
1204 | mutex_lock(&ir_devices_lock); | ||
1205 | |||
1206 | if (ir == NULL) { | ||
1207 | /* We destroyed everything when the first client came through */ | ||
1208 | mutex_unlock(&ir_devices_lock); | ||
1209 | return 0; | ||
1174 | } | 1210 | } |
1175 | 1211 | ||
1176 | /* unregister lirc driver */ | 1212 | /* Good-bye LIRC */ |
1177 | if (ir->l.minor >= 0 && ir->l.minor < MAX_IRCTL_DEVICES) { | 1213 | lirc_unregister_driver(ir->l.minor); |
1178 | lirc_unregister_driver(ir->l.minor); | 1214 | |
1179 | ir_devices[ir->l.minor] = NULL; | 1215 | /* Good-bye Rx */ |
1216 | destroy_rx_kthread(ir->rx); | ||
1217 | if (ir->rx != NULL) { | ||
1218 | if (ir->rx->buf.fifo_initialized) | ||
1219 | lirc_buffer_free(&ir->rx->buf); | ||
1220 | i2c_set_clientdata(ir->rx->c, NULL); | ||
1221 | kfree(ir->rx); | ||
1180 | } | 1222 | } |
1181 | 1223 | ||
1182 | /* free memory */ | 1224 | /* Good-bye Tx */ |
1183 | lirc_buffer_free(&ir->buf); | 1225 | i2c_set_clientdata(ir->tx->c, NULL); |
1184 | mutex_unlock(&ir->ir_lock); | 1226 | kfree(ir->tx); |
1227 | |||
1228 | /* Good-bye IR */ | ||
1229 | del_ir_device(ir); | ||
1185 | kfree(ir); | 1230 | kfree(ir); |
1186 | 1231 | ||
1232 | mutex_unlock(&ir_devices_lock); | ||
1187 | return 0; | 1233 | return 0; |
1188 | } | 1234 | } |
1189 | 1235 | ||
1190 | static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | 1236 | |
1237 | /* ir_devices_lock must be held */ | ||
1238 | static struct IR *find_ir_device_by_adapter(struct i2c_adapter *adapter) | ||
1191 | { | 1239 | { |
1240 | int i; | ||
1192 | struct IR *ir = NULL; | 1241 | struct IR *ir = NULL; |
1242 | |||
1243 | for (i = 0; i < MAX_IRCTL_DEVICES; i++) | ||
1244 | if (ir_devices[i] != NULL && | ||
1245 | ir_devices[i]->adapter == adapter) { | ||
1246 | ir = ir_devices[i]; | ||
1247 | break; | ||
1248 | } | ||
1249 | |||
1250 | return ir; | ||
1251 | } | ||
1252 | |||
1253 | static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
1254 | { | ||
1255 | struct IR *ir; | ||
1193 | struct i2c_adapter *adap = client->adapter; | 1256 | struct i2c_adapter *adap = client->adapter; |
1194 | char buf; | ||
1195 | int ret; | 1257 | int ret; |
1196 | int have_rx = 0, have_tx = 0; | 1258 | bool tx_probe = false; |
1197 | 1259 | ||
1198 | dprintk("%s: adapter name (%s) nr %d, i2c_device_id name (%s), " | 1260 | dprintk("%s: %s on i2c-%d (%s), client addr=0x%02x\n", |
1199 | "client addr=0x%02x\n", | 1261 | __func__, id->name, adap->nr, adap->name, client->addr); |
1200 | __func__, adap->name, adap->nr, id->name, client->addr); | ||
1201 | 1262 | ||
1202 | /* | 1263 | /* |
1203 | * FIXME - This probe function probes both the Tx and Rx | 1264 | * The IR receiver is at i2c address 0x71. |
1204 | * addresses of the IR microcontroller. | 1265 | * The IR transmitter is at i2c address 0x70. |
1205 | * | ||
1206 | * However, the I2C subsystem is passing along one I2C client at a | ||
1207 | * time, based on matches to the ir_transceiver_id[] table above. | ||
1208 | * The expectation is that each i2c_client address will be probed | ||
1209 | * individually by drivers so the I2C subsystem can mark all client | ||
1210 | * addresses as claimed or not. | ||
1211 | * | ||
1212 | * This probe routine causes only one of the client addresses, TX or RX, | ||
1213 | * to be claimed. This will cause a problem if the I2C subsystem is | ||
1214 | * subsequently triggered to probe unclaimed clients again. | ||
1215 | */ | 1266 | */ |
1216 | /* | ||
1217 | * The external IR receiver is at i2c address 0x71. | ||
1218 | * The IR transmitter is at 0x70. | ||
1219 | */ | ||
1220 | client->addr = 0x70; | ||
1221 | 1267 | ||
1222 | if (!disable_tx) { | 1268 | if (id->driver_data & ID_FLAG_TX) |
1223 | if (i2c_master_recv(client, &buf, 1) == 1) | 1269 | tx_probe = true; |
1224 | have_tx = 1; | 1270 | else if (tx_only) /* module option */ |
1225 | dprintk("probe 0x70 @ %s: %s\n", | 1271 | return -ENXIO; |
1226 | adap->name, have_tx ? "success" : "failed"); | ||
1227 | } | ||
1228 | 1272 | ||
1229 | if (!disable_rx) { | 1273 | zilog_info("probing IR %s on %s (i2c-%d)\n", |
1230 | client->addr = 0x71; | 1274 | tx_probe ? "Tx" : "Rx", adap->name, adap->nr); |
1231 | if (i2c_master_recv(client, &buf, 1) == 1) | ||
1232 | have_rx = 1; | ||
1233 | dprintk("probe 0x71 @ %s: %s\n", | ||
1234 | adap->name, have_rx ? "success" : "failed"); | ||
1235 | } | ||
1236 | 1275 | ||
1237 | if (!(have_rx || have_tx)) { | 1276 | mutex_lock(&ir_devices_lock); |
1238 | zilog_error("%s: no devices found\n", adap->name); | ||
1239 | goto out_nodev; | ||
1240 | } | ||
1241 | 1277 | ||
1242 | printk(KERN_INFO "lirc_zilog: chip found with %s\n", | 1278 | /* Use a single struct IR instance for both the Rx and Tx functions */ |
1243 | have_rx && have_tx ? "RX and TX" : | 1279 | ir = find_ir_device_by_adapter(adap); |
1244 | have_rx ? "RX only" : "TX only"); | 1280 | if (ir == NULL) { |
1281 | ir = kzalloc(sizeof(struct IR), GFP_KERNEL); | ||
1282 | if (ir == NULL) { | ||
1283 | ret = -ENOMEM; | ||
1284 | goto out_no_ir; | ||
1285 | } | ||
1286 | /* store for use in ir_probe() again, and open() later on */ | ||
1287 | ret = add_ir_device(ir); | ||
1288 | if (ret) | ||
1289 | goto out_free_ir; | ||
1290 | |||
1291 | ir->adapter = adap; | ||
1292 | mutex_init(&ir->ir_lock); | ||
1293 | |||
1294 | /* set lirc_dev stuff */ | ||
1295 | memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); | ||
1296 | ir->l.minor = minor; /* module option */ | ||
1297 | ir->l.code_length = 13; | ||
1298 | ir->l.rbuf = NULL; | ||
1299 | ir->l.fops = &lirc_fops; | ||
1300 | ir->l.data = ir; | ||
1301 | ir->l.dev = &adap->dev; | ||
1302 | ir->l.sample_rate = 0; | ||
1303 | } | ||
1245 | 1304 | ||
1246 | ir = kzalloc(sizeof(struct IR), GFP_KERNEL); | 1305 | if (tx_probe) { |
1306 | /* Set up a struct IR_tx instance */ | ||
1307 | ir->tx = kzalloc(sizeof(struct IR_tx), GFP_KERNEL); | ||
1308 | if (ir->tx == NULL) { | ||
1309 | ret = -ENOMEM; | ||
1310 | goto out_free_xx; | ||
1311 | } | ||
1247 | 1312 | ||
1248 | if (!ir) | 1313 | ir->tx->c = client; |
1249 | goto out_nomem; | 1314 | ir->tx->need_boot = 1; |
1315 | ir->tx->post_tx_ready_poll = | ||
1316 | (id->driver_data & ID_FLAG_HDPVR) ? false : true; | ||
1317 | } else { | ||
1318 | /* Set up a struct IR_rx instance */ | ||
1319 | ir->rx = kzalloc(sizeof(struct IR_rx), GFP_KERNEL); | ||
1320 | if (ir->rx == NULL) { | ||
1321 | ret = -ENOMEM; | ||
1322 | goto out_free_xx; | ||
1323 | } | ||
1250 | 1324 | ||
1251 | ret = lirc_buffer_init(&ir->buf, 2, BUFLEN / 2); | 1325 | ret = lirc_buffer_init(&ir->rx->buf, 2, BUFLEN / 2); |
1252 | if (ret) | 1326 | if (ret) |
1253 | goto out_nomem; | 1327 | goto out_free_xx; |
1254 | 1328 | ||
1255 | mutex_init(&ir->ir_lock); | 1329 | mutex_init(&ir->rx->buf_lock); |
1256 | mutex_init(&ir->buf_lock); | 1330 | ir->rx->c = client; |
1257 | ir->need_boot = 1; | 1331 | ir->rx->hdpvr_data_fmt = |
1258 | ir->is_hdpvr = (id->driver_data & ID_FLAG_HDPVR) ? true : false; | 1332 | (id->driver_data & ID_FLAG_HDPVR) ? true : false; |
1259 | 1333 | ||
1260 | memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); | 1334 | /* set lirc_dev stuff */ |
1261 | ir->l.minor = -1; | 1335 | ir->l.rbuf = &ir->rx->buf; |
1336 | } | ||
1262 | 1337 | ||
1263 | /* I2C attach to device */ | ||
1264 | i2c_set_clientdata(client, ir); | 1338 | i2c_set_clientdata(client, ir); |
1265 | 1339 | ||
1266 | /* initialise RX device */ | 1340 | /* Proceed only if we have the required Tx and Rx clients ready to go */ |
1267 | if (have_rx) { | 1341 | if (ir->tx == NULL || |
1268 | DECLARE_COMPLETION(tn); | 1342 | (ir->rx == NULL && !tx_only)) { |
1269 | memcpy(&ir->c_rx, client, sizeof(struct i2c_client)); | 1343 | zilog_info("probe of IR %s on %s (i2c-%d) done. Waiting on " |
1270 | 1344 | "IR %s.\n", tx_probe ? "Tx" : "Rx", adap->name, | |
1271 | ir->c_rx.addr = 0x71; | 1345 | adap->nr, tx_probe ? "Rx" : "Tx"); |
1272 | strlcpy(ir->c_rx.name, ZILOG_HAUPPAUGE_IR_RX_NAME, | 1346 | goto out_ok; |
1273 | I2C_NAME_SIZE); | 1347 | } |
1274 | 1348 | ||
1349 | /* initialise RX device */ | ||
1350 | if (ir->rx != NULL) { | ||
1275 | /* try to fire up polling thread */ | 1351 | /* try to fire up polling thread */ |
1276 | ir->t_notify = &tn; | 1352 | ir->rx->task = kthread_run(lirc_thread, ir, |
1277 | ir->task = kthread_run(lirc_thread, ir, "lirc_zilog"); | 1353 | "zilog-rx-i2c-%d", adap->nr); |
1278 | if (IS_ERR(ir->task)) { | 1354 | if (IS_ERR(ir->rx->task)) { |
1279 | ret = PTR_ERR(ir->task); | 1355 | ret = PTR_ERR(ir->rx->task); |
1280 | zilog_error("lirc_register_driver: cannot run " | 1356 | zilog_error("%s: could not start IR Rx polling thread" |
1281 | "poll thread %d\n", ret); | 1357 | "\n", __func__); |
1282 | goto err; | 1358 | goto out_free_xx; |
1283 | } | 1359 | } |
1284 | wait_for_completion(&tn); | ||
1285 | ir->t_notify = NULL; | ||
1286 | ir->have_rx = 1; | ||
1287 | } | ||
1288 | |||
1289 | /* initialise TX device */ | ||
1290 | if (have_tx) { | ||
1291 | memcpy(&ir->c_tx, client, sizeof(struct i2c_client)); | ||
1292 | ir->c_tx.addr = 0x70; | ||
1293 | strlcpy(ir->c_tx.name, ZILOG_HAUPPAUGE_IR_TX_NAME, | ||
1294 | I2C_NAME_SIZE); | ||
1295 | ir->have_tx = 1; | ||
1296 | } | 1360 | } |
1297 | 1361 | ||
1298 | /* set lirc_dev stuff */ | ||
1299 | ir->l.code_length = 13; | ||
1300 | ir->l.rbuf = &ir->buf; | ||
1301 | ir->l.fops = &lirc_fops; | ||
1302 | ir->l.data = ir; | ||
1303 | ir->l.minor = minor; | ||
1304 | ir->l.dev = &adap->dev; | ||
1305 | ir->l.sample_rate = 0; | ||
1306 | |||
1307 | /* register with lirc */ | 1362 | /* register with lirc */ |
1308 | ir->l.minor = lirc_register_driver(&ir->l); | 1363 | ir->l.minor = lirc_register_driver(&ir->l); |
1309 | if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) { | 1364 | if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) { |
1310 | zilog_error("ir_attach: \"minor\" must be between 0 and %d " | 1365 | zilog_error("%s: \"minor\" must be between 0 and %d (%d)!\n", |
1311 | "(%d)!\n", MAX_IRCTL_DEVICES-1, ir->l.minor); | 1366 | __func__, MAX_IRCTL_DEVICES-1, ir->l.minor); |
1312 | ret = -EBADRQC; | 1367 | ret = -EBADRQC; |
1313 | goto err; | 1368 | goto out_free_thread; |
1314 | } | 1369 | } |
1315 | 1370 | ||
1316 | /* store this for getting back in open() later on */ | ||
1317 | ir_devices[ir->l.minor] = ir; | ||
1318 | |||
1319 | /* | 1371 | /* |
1320 | * if we have the tx device, load the 'firmware'. We do this | 1372 | * if we have the tx device, load the 'firmware'. We do this |
1321 | * after registering with lirc as otherwise hotplug seems to take | 1373 | * after registering with lirc as otherwise hotplug seems to take |
1322 | * 10s to create the lirc device. | 1374 | * 10s to create the lirc device. |
1323 | */ | 1375 | */ |
1324 | if (have_tx) { | 1376 | ret = tx_init(ir->tx); |
1325 | /* Special TX init */ | 1377 | if (ret != 0) |
1326 | ret = tx_init(ir); | 1378 | goto out_unregister; |
1327 | if (ret != 0) | ||
1328 | goto err; | ||
1329 | } | ||
1330 | 1379 | ||
1380 | zilog_info("probe of IR %s on %s (i2c-%d) done. IR unit ready.\n", | ||
1381 | tx_probe ? "Tx" : "Rx", adap->name, adap->nr); | ||
1382 | out_ok: | ||
1383 | mutex_unlock(&ir_devices_lock); | ||
1331 | return 0; | 1384 | return 0; |
1332 | 1385 | ||
1333 | err: | 1386 | out_unregister: |
1334 | /* undo everything, hopefully... */ | 1387 | lirc_unregister_driver(ir->l.minor); |
1335 | if (ir->c_rx.addr) | 1388 | out_free_thread: |
1336 | ir_remove(&ir->c_rx); | 1389 | destroy_rx_kthread(ir->rx); |
1337 | if (ir->c_tx.addr) | 1390 | out_free_xx: |
1338 | ir_remove(&ir->c_tx); | 1391 | if (ir->rx != NULL) { |
1339 | return ret; | 1392 | if (ir->rx->buf.fifo_initialized) |
1340 | 1393 | lirc_buffer_free(&ir->rx->buf); | |
1341 | out_nodev: | 1394 | if (ir->rx->c != NULL) |
1342 | zilog_error("no device found\n"); | 1395 | i2c_set_clientdata(ir->rx->c, NULL); |
1343 | return -ENODEV; | 1396 | kfree(ir->rx); |
1344 | 1397 | } | |
1345 | out_nomem: | 1398 | if (ir->tx != NULL) { |
1346 | zilog_error("memory allocation failure\n"); | 1399 | if (ir->tx->c != NULL) |
1400 | i2c_set_clientdata(ir->tx->c, NULL); | ||
1401 | kfree(ir->tx); | ||
1402 | } | ||
1403 | out_free_ir: | ||
1404 | del_ir_device(ir); | ||
1347 | kfree(ir); | 1405 | kfree(ir); |
1348 | return -ENOMEM; | 1406 | out_no_ir: |
1349 | } | 1407 | zilog_error("%s: probing IR %s on %s (i2c-%d) failed with %d\n", |
1350 | 1408 | __func__, tx_probe ? "Tx" : "Rx", adap->name, adap->nr, | |
1351 | static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg) | 1409 | ret); |
1352 | { | 1410 | mutex_unlock(&ir_devices_lock); |
1353 | /* nothing */ | 1411 | return ret; |
1354 | return 0; | ||
1355 | } | 1412 | } |
1356 | 1413 | ||
1357 | static int __init zilog_init(void) | 1414 | static int __init zilog_init(void) |
@@ -1361,6 +1418,7 @@ static int __init zilog_init(void) | |||
1361 | zilog_notify("Zilog/Hauppauge IR driver initializing\n"); | 1418 | zilog_notify("Zilog/Hauppauge IR driver initializing\n"); |
1362 | 1419 | ||
1363 | mutex_init(&tx_data_lock); | 1420 | mutex_init(&tx_data_lock); |
1421 | mutex_init(&ir_devices_lock); | ||
1364 | 1422 | ||
1365 | request_module("firmware_class"); | 1423 | request_module("firmware_class"); |
1366 | 1424 | ||
@@ -1386,7 +1444,8 @@ module_exit(zilog_exit); | |||
1386 | 1444 | ||
1387 | MODULE_DESCRIPTION("Zilog/Hauppauge infrared transmitter driver (i2c stack)"); | 1445 | MODULE_DESCRIPTION("Zilog/Hauppauge infrared transmitter driver (i2c stack)"); |
1388 | MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, " | 1446 | MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, " |
1389 | "Ulrich Mueller, Stefan Jahn, Jerome Brock, Mark Weaver"); | 1447 | "Ulrich Mueller, Stefan Jahn, Jerome Brock, Mark Weaver, " |
1448 | "Andy Walls"); | ||
1390 | MODULE_LICENSE("GPL"); | 1449 | MODULE_LICENSE("GPL"); |
1391 | /* for compat with old name, which isn't all that accurate anymore */ | 1450 | /* for compat with old name, which isn't all that accurate anymore */ |
1392 | MODULE_ALIAS("lirc_pvr150"); | 1451 | MODULE_ALIAS("lirc_pvr150"); |
@@ -1397,8 +1456,5 @@ MODULE_PARM_DESC(minor, "Preferred minor device number"); | |||
1397 | module_param(debug, bool, 0644); | 1456 | module_param(debug, bool, 0644); |
1398 | MODULE_PARM_DESC(debug, "Enable debugging messages"); | 1457 | MODULE_PARM_DESC(debug, "Enable debugging messages"); |
1399 | 1458 | ||
1400 | module_param(disable_rx, bool, 0644); | 1459 | module_param(tx_only, bool, 0644); |
1401 | MODULE_PARM_DESC(disable_rx, "Disable the IR receiver device"); | 1460 | MODULE_PARM_DESC(tx_only, "Only handle the IR transmit function"); |
1402 | |||
1403 | module_param(disable_tx, bool, 0644); | ||
1404 | MODULE_PARM_DESC(disable_tx, "Disable the IR transmitter device"); | ||