]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/lirc/lirc_zilog.c
[media] lirc_zilog: Remove useless struct i2c_driver.command function
[mv-sheeva.git] / drivers / staging / lirc / lirc_zilog.c
1 /*
2  * i2c IR lirc driver for devices with zilog IR processors
3  *
4  * Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
5  * modified for PixelView (BT878P+W/FM) by
6  *      Michal Kochanowicz <mkochano@pld.org.pl>
7  *      Christoph Bartelmus <lirc@bartelmus.de>
8  * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by
9  *      Ulrich Mueller <ulrich.mueller42@web.de>
10  * modified for Asus TV-Box and Creative/VisionTek BreakOut-Box by
11  *      Stefan Jahn <stefan@lkcc.org>
12  * modified for inclusion into kernel sources by
13  *      Jerome Brock <jbrock@users.sourceforge.net>
14  * modified for Leadtek Winfast PVR2000 by
15  *      Thomas Reitmayr (treitmayr@yahoo.com)
16  * modified for Hauppauge PVR-150 IR TX device by
17  *      Mark Weaver <mark@npsl.co.uk>
18  * changed name from lirc_pvr150 to lirc_zilog, works on more than pvr-150
19  *      Jarod Wilson <jarod@redhat.com>
20  *
21  * parts are cut&pasted from the lirc_i2c.c driver
22  *
23  *  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
25  *  the Free Software Foundation; either version 2 of the License, or
26  *  (at your option) any later version.
27  *
28  *  This program is distributed in the hope that it will be useful,
29  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
30  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  *  GNU General Public License for more details.
32  *
33  *  You should have received a copy of the GNU General Public License
34  *  along with this program; if not, write to the Free Software
35  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
36  *
37  */
38
39
40 #include <linux/version.h>
41 #include <linux/module.h>
42 #include <linux/kmod.h>
43 #include <linux/kernel.h>
44 #include <linux/sched.h>
45 #include <linux/fs.h>
46 #include <linux/poll.h>
47 #include <linux/string.h>
48 #include <linux/timer.h>
49 #include <linux/delay.h>
50 #include <linux/completion.h>
51 #include <linux/errno.h>
52 #include <linux/slab.h>
53 #include <linux/i2c.h>
54 #include <linux/firmware.h>
55 #include <linux/vmalloc.h>
56
57 #include <linux/mutex.h>
58 #include <linux/kthread.h>
59
60 #include <media/lirc_dev.h>
61 #include <media/lirc.h>
62
63 struct IR_rx {
64         /* RX device */
65         struct i2c_client *c;
66
67         /* RX device buffer & lock */
68         struct lirc_buffer buf;
69         struct mutex buf_lock;
70
71         /* RX polling thread data */
72         struct task_struct *task;
73
74         /* RX read data */
75         unsigned char b[3];
76         bool hdpvr_data_fmt;
77 };
78
79 struct IR_tx {
80         /* TX device */
81         struct i2c_client *c;
82
83         /* TX additional actions needed */
84         int need_boot;
85         bool post_tx_ready_poll;
86 };
87
88 struct IR {
89         struct lirc_driver l;
90
91         struct mutex ir_lock;
92         int open;
93
94         struct i2c_adapter *adapter;
95         struct IR_rx *rx;
96         struct IR_tx *tx;
97 };
98
99 /* Minor -> data mapping */
100 static struct mutex ir_devices_lock;
101 static struct IR *ir_devices[MAX_IRCTL_DEVICES];
102
103 /* Block size for IR transmitter */
104 #define TX_BLOCK_SIZE   99
105
106 /* Hauppauge IR transmitter data */
107 struct tx_data_struct {
108         /* Boot block */
109         unsigned char *boot_data;
110
111         /* Start of binary data block */
112         unsigned char *datap;
113
114         /* End of binary data block */
115         unsigned char *endp;
116
117         /* Number of installed codesets */
118         unsigned int num_code_sets;
119
120         /* Pointers to codesets */
121         unsigned char **code_sets;
122
123         /* Global fixed data template */
124         int fixed[TX_BLOCK_SIZE];
125 };
126
127 static struct tx_data_struct *tx_data;
128 static struct mutex tx_data_lock;
129
130 #define zilog_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, \
131                                         ## args)
132 #define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
133 #define zilog_info(s, args...) printk(KERN_INFO KBUILD_MODNAME ": " s, ## args)
134
135 /* module parameters */
136 static int debug;       /* debug output */
137 static int tx_only;     /* only handle the IR Tx function */
138 static int minor = -1;  /* minor number */
139
140 #define dprintk(fmt, args...)                                           \
141         do {                                                            \
142                 if (debug)                                              \
143                         printk(KERN_DEBUG KBUILD_MODNAME ": " fmt,      \
144                                  ## args);                              \
145         } while (0)
146
147 static int add_to_buf(struct IR *ir)
148 {
149         __u16 code;
150         unsigned char codes[2];
151         unsigned char keybuf[6];
152         int got_data = 0;
153         int ret;
154         int failures = 0;
155         unsigned char sendbuf[1] = { 0 };
156         struct IR_rx *rx = ir->rx;
157
158         if (rx == NULL)
159                 return -ENXIO;
160
161         if (lirc_buffer_full(&rx->buf)) {
162                 dprintk("buffer overflow\n");
163                 return -EOVERFLOW;
164         }
165
166         /*
167          * service the device as long as it is returning
168          * data and we have space
169          */
170         do {
171                 if (kthread_should_stop())
172                         return -ENODATA;
173
174                 /*
175                  * Lock i2c bus for the duration.  RX/TX chips interfere so
176                  * this is worth it
177                  */
178                 mutex_lock(&ir->ir_lock);
179
180                 if (kthread_should_stop()) {
181                         mutex_unlock(&ir->ir_lock);
182                         return -ENODATA;
183                 }
184
185                 /*
186                  * Send random "poll command" (?)  Windows driver does this
187                  * and it is a good point to detect chip failure.
188                  */
189                 ret = i2c_master_send(rx->c, sendbuf, 1);
190                 if (ret != 1) {
191                         zilog_error("i2c_master_send failed with %d\n", ret);
192                         if (failures >= 3) {
193                                 mutex_unlock(&ir->ir_lock);
194                                 zilog_error("unable to read from the IR chip "
195                                             "after 3 resets, giving up\n");
196                                 return ret;
197                         }
198
199                         /* Looks like the chip crashed, reset it */
200                         zilog_error("polling the IR receiver chip failed, "
201                                     "trying reset\n");
202
203                         set_current_state(TASK_UNINTERRUPTIBLE);
204                         if (kthread_should_stop()) {
205                                 mutex_unlock(&ir->ir_lock);
206                                 return -ENODATA;
207                         }
208                         schedule_timeout((100 * HZ + 999) / 1000);
209                         ir->tx->need_boot = 1;
210
211                         ++failures;
212                         mutex_unlock(&ir->ir_lock);
213                         continue;
214                 }
215
216                 if (kthread_should_stop()) {
217                         mutex_unlock(&ir->ir_lock);
218                         return -ENODATA;
219                 }
220                 ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf));
221                 mutex_unlock(&ir->ir_lock);
222                 if (ret != sizeof(keybuf)) {
223                         zilog_error("i2c_master_recv failed with %d -- "
224                                     "keeping last read buffer\n", ret);
225                 } else {
226                         rx->b[0] = keybuf[3];
227                         rx->b[1] = keybuf[4];
228                         rx->b[2] = keybuf[5];
229                         dprintk("key (0x%02x/0x%02x)\n", rx->b[0], rx->b[1]);
230                 }
231
232                 /* key pressed ? */
233                 if (rx->hdpvr_data_fmt) {
234                         if (got_data && (keybuf[0] == 0x80))
235                                 return 0;
236                         else if (got_data && (keybuf[0] == 0x00))
237                                 return -ENODATA;
238                 } else if ((rx->b[0] & 0x80) == 0)
239                         return got_data ? 0 : -ENODATA;
240
241                 /* look what we have */
242                 code = (((__u16)rx->b[0] & 0x7f) << 6) | (rx->b[1] >> 2);
243
244                 codes[0] = (code >> 8) & 0xff;
245                 codes[1] = code & 0xff;
246
247                 /* return it */
248                 lirc_buffer_write(&rx->buf, codes);
249                 ++got_data;
250         } while (!lirc_buffer_full(&rx->buf));
251
252         return 0;
253 }
254
255 /*
256  * Main function of the polling thread -- from lirc_dev.
257  * We don't fit the LIRC model at all anymore.  This is horrible, but
258  * basically we have a single RX/TX device with a nasty failure mode
259  * that needs to be accounted for across the pair.  lirc lets us provide
260  * fops, but prevents us from using the internal polling, etc. if we do
261  * so.  Hence the replication.  Might be neater to extend the LIRC model
262  * to account for this but I'd think it's a very special case of seriously
263  * messed up hardware.
264  */
265 static int lirc_thread(void *arg)
266 {
267         struct IR *ir = arg;
268         struct IR_rx *rx = ir->rx;
269
270         dprintk("poll thread started\n");
271
272         while (!kthread_should_stop()) {
273                 set_current_state(TASK_INTERRUPTIBLE);
274
275                 /* if device not opened, we can sleep half a second */
276                 if (!ir->open) {
277                         schedule_timeout(HZ/2);
278                         continue;
279                 }
280
281                 /*
282                  * This is ~113*2 + 24 + jitter (2*repeat gap + code length).
283                  * We use this interval as the chip resets every time you poll
284                  * it (bad!).  This is therefore just sufficient to catch all
285                  * of the button presses.  It makes the remote much more
286                  * responsive.  You can see the difference by running irw and
287                  * holding down a button.  With 100ms, the old polling
288                  * interval, you'll notice breaks in the repeat sequence
289                  * corresponding to lost keypresses.
290                  */
291                 schedule_timeout((260 * HZ) / 1000);
292                 if (kthread_should_stop())
293                         break;
294                 if (!add_to_buf(ir))
295                         wake_up_interruptible(&rx->buf.wait_poll);
296         }
297
298         dprintk("poll thread ended\n");
299         return 0;
300 }
301
302 static int set_use_inc(void *data)
303 {
304         struct IR *ir = data;
305
306         if (ir->l.owner == NULL || try_module_get(ir->l.owner) == 0)
307                 return -ENODEV;
308
309         /* lock bttv in memory while /dev/lirc is in use  */
310         /*
311          * this is completely broken code. lirc_unregister_driver()
312          * must be possible even when the device is open
313          */
314         if (ir->rx != NULL)
315                 i2c_use_client(ir->rx->c);
316         if (ir->tx != NULL)
317                 i2c_use_client(ir->tx->c);
318
319         return 0;
320 }
321
322 static void set_use_dec(void *data)
323 {
324         struct IR *ir = data;
325
326         if (ir->rx)
327                 i2c_release_client(ir->rx->c);
328         if (ir->tx)
329                 i2c_release_client(ir->tx->c);
330         if (ir->l.owner != NULL)
331                 module_put(ir->l.owner);
332 }
333
334 /* safe read of a uint32 (always network byte order) */
335 static int read_uint32(unsigned char **data,
336                                      unsigned char *endp, unsigned int *val)
337 {
338         if (*data + 4 > endp)
339                 return 0;
340         *val = ((*data)[0] << 24) | ((*data)[1] << 16) |
341                ((*data)[2] << 8) | (*data)[3];
342         *data += 4;
343         return 1;
344 }
345
346 /* safe read of a uint8 */
347 static int read_uint8(unsigned char **data,
348                                     unsigned char *endp, unsigned char *val)
349 {
350         if (*data + 1 > endp)
351                 return 0;
352         *val = *((*data)++);
353         return 1;
354 }
355
356 /* safe skipping of N bytes */
357 static int skip(unsigned char **data,
358                               unsigned char *endp, unsigned int distance)
359 {
360         if (*data + distance > endp)
361                 return 0;
362         *data += distance;
363         return 1;
364 }
365
366 /* decompress key data into the given buffer */
367 static int get_key_data(unsigned char *buf,
368                              unsigned int codeset, unsigned int key)
369 {
370         unsigned char *data, *endp, *diffs, *key_block;
371         unsigned char keys, ndiffs, id;
372         unsigned int base, lim, pos, i;
373
374         /* Binary search for the codeset */
375         for (base = 0, lim = tx_data->num_code_sets; lim; lim >>= 1) {
376                 pos = base + (lim >> 1);
377                 data = tx_data->code_sets[pos];
378
379                 if (!read_uint32(&data, tx_data->endp, &i))
380                         goto corrupt;
381
382                 if (i == codeset)
383                         break;
384                 else if (codeset > i) {
385                         base = pos + 1;
386                         --lim;
387                 }
388         }
389         /* Not found? */
390         if (!lim)
391                 return -EPROTO;
392
393         /* Set end of data block */
394         endp = pos < tx_data->num_code_sets - 1 ?
395                 tx_data->code_sets[pos + 1] : tx_data->endp;
396
397         /* Read the block header */
398         if (!read_uint8(&data, endp, &keys) ||
399             !read_uint8(&data, endp, &ndiffs) ||
400             ndiffs > TX_BLOCK_SIZE || keys == 0)
401                 goto corrupt;
402
403         /* Save diffs & skip */
404         diffs = data;
405         if (!skip(&data, endp, ndiffs))
406                 goto corrupt;
407
408         /* Read the id of the first key */
409         if (!read_uint8(&data, endp, &id))
410                 goto corrupt;
411
412         /* Unpack the first key's data */
413         for (i = 0; i < TX_BLOCK_SIZE; ++i) {
414                 if (tx_data->fixed[i] == -1) {
415                         if (!read_uint8(&data, endp, &buf[i]))
416                                 goto corrupt;
417                 } else {
418                         buf[i] = (unsigned char)tx_data->fixed[i];
419                 }
420         }
421
422         /* Early out key found/not found */
423         if (key == id)
424                 return 0;
425         if (keys == 1)
426                 return -EPROTO;
427
428         /* Sanity check */
429         key_block = data;
430         if (!skip(&data, endp, (keys - 1) * (ndiffs + 1)))
431                 goto corrupt;
432
433         /* Binary search for the key */
434         for (base = 0, lim = keys - 1; lim; lim >>= 1) {
435                 /* Seek to block */
436                 unsigned char *key_data;
437                 pos = base + (lim >> 1);
438                 key_data = key_block + (ndiffs + 1) * pos;
439
440                 if (*key_data == key) {
441                         /* skip key id */
442                         ++key_data;
443
444                         /* found, so unpack the diffs */
445                         for (i = 0; i < ndiffs; ++i) {
446                                 unsigned char val;
447                                 if (!read_uint8(&key_data, endp, &val) ||
448                                     diffs[i] >= TX_BLOCK_SIZE)
449                                         goto corrupt;
450                                 buf[diffs[i]] = val;
451                         }
452
453                         return 0;
454                 } else if (key > *key_data) {
455                         base = pos + 1;
456                         --lim;
457                 }
458         }
459         /* Key not found */
460         return -EPROTO;
461
462 corrupt:
463         zilog_error("firmware is corrupt\n");
464         return -EFAULT;
465 }
466
467 /* send a block of data to the IR TX device */
468 static int send_data_block(struct IR_tx *tx, unsigned char *data_block)
469 {
470         int i, j, ret;
471         unsigned char buf[5];
472
473         for (i = 0; i < TX_BLOCK_SIZE;) {
474                 int tosend = TX_BLOCK_SIZE - i;
475                 if (tosend > 4)
476                         tosend = 4;
477                 buf[0] = (unsigned char)(i + 1);
478                 for (j = 0; j < tosend; ++j)
479                         buf[1 + j] = data_block[i + j];
480                 dprintk("%02x %02x %02x %02x %02x",
481                         buf[0], buf[1], buf[2], buf[3], buf[4]);
482                 ret = i2c_master_send(tx->c, buf, tosend + 1);
483                 if (ret != tosend + 1) {
484                         zilog_error("i2c_master_send failed with %d\n", ret);
485                         return ret < 0 ? ret : -EFAULT;
486                 }
487                 i += tosend;
488         }
489         return 0;
490 }
491
492 /* send boot data to the IR TX device */
493 static int send_boot_data(struct IR_tx *tx)
494 {
495         int ret;
496         unsigned char buf[4];
497
498         /* send the boot block */
499         ret = send_data_block(tx, tx_data->boot_data);
500         if (ret != 0)
501                 return ret;
502
503         /* kick it off? */
504         buf[0] = 0x00;
505         buf[1] = 0x20;
506         ret = i2c_master_send(tx->c, buf, 2);
507         if (ret != 2) {
508                 zilog_error("i2c_master_send failed with %d\n", ret);
509                 return ret < 0 ? ret : -EFAULT;
510         }
511         ret = i2c_master_send(tx->c, buf, 1);
512         if (ret != 1) {
513                 zilog_error("i2c_master_send failed with %d\n", ret);
514                 return ret < 0 ? ret : -EFAULT;
515         }
516
517         /* Here comes the firmware version... (hopefully) */
518         ret = i2c_master_recv(tx->c, buf, 4);
519         if (ret != 4) {
520                 zilog_error("i2c_master_recv failed with %d\n", ret);
521                 return 0;
522         }
523         if (buf[0] != 0x80) {
524                 zilog_error("unexpected IR TX response: %02x\n", buf[0]);
525                 return 0;
526         }
527         zilog_notify("Zilog/Hauppauge IR blaster firmware version "
528                      "%d.%d.%d loaded\n", buf[1], buf[2], buf[3]);
529
530         return 0;
531 }
532
533 /* unload "firmware", lock held */
534 static void fw_unload_locked(void)
535 {
536         if (tx_data) {
537                 if (tx_data->code_sets)
538                         vfree(tx_data->code_sets);
539
540                 if (tx_data->datap)
541                         vfree(tx_data->datap);
542
543                 vfree(tx_data);
544                 tx_data = NULL;
545                 dprintk("successfully unloaded IR blaster firmware\n");
546         }
547 }
548
549 /* unload "firmware" for the IR TX device */
550 static void fw_unload(void)
551 {
552         mutex_lock(&tx_data_lock);
553         fw_unload_locked();
554         mutex_unlock(&tx_data_lock);
555 }
556
557 /* load "firmware" for the IR TX device */
558 static int fw_load(struct IR_tx *tx)
559 {
560         int ret;
561         unsigned int i;
562         unsigned char *data, version, num_global_fixed;
563         const struct firmware *fw_entry;
564
565         /* Already loaded? */
566         mutex_lock(&tx_data_lock);
567         if (tx_data) {
568                 ret = 0;
569                 goto out;
570         }
571
572         /* Request codeset data file */
573         ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &tx->c->dev);
574         if (ret != 0) {
575                 zilog_error("firmware haup-ir-blaster.bin not available "
576                             "(%d)\n", ret);
577                 ret = ret < 0 ? ret : -EFAULT;
578                 goto out;
579         }
580         dprintk("firmware of size %zu loaded\n", fw_entry->size);
581
582         /* Parse the file */
583         tx_data = vmalloc(sizeof(*tx_data));
584         if (tx_data == NULL) {
585                 zilog_error("out of memory\n");
586                 release_firmware(fw_entry);
587                 ret = -ENOMEM;
588                 goto out;
589         }
590         tx_data->code_sets = NULL;
591
592         /* Copy the data so hotplug doesn't get confused and timeout */
593         tx_data->datap = vmalloc(fw_entry->size);
594         if (tx_data->datap == NULL) {
595                 zilog_error("out of memory\n");
596                 release_firmware(fw_entry);
597                 vfree(tx_data);
598                 ret = -ENOMEM;
599                 goto out;
600         }
601         memcpy(tx_data->datap, fw_entry->data, fw_entry->size);
602         tx_data->endp = tx_data->datap + fw_entry->size;
603         release_firmware(fw_entry); fw_entry = NULL;
604
605         /* Check version */
606         data = tx_data->datap;
607         if (!read_uint8(&data, tx_data->endp, &version))
608                 goto corrupt;
609         if (version != 1) {
610                 zilog_error("unsupported code set file version (%u, expected"
611                             "1) -- please upgrade to a newer driver",
612                             version);
613                 fw_unload_locked();
614                 ret = -EFAULT;
615                 goto out;
616         }
617
618         /* Save boot block for later */
619         tx_data->boot_data = data;
620         if (!skip(&data, tx_data->endp, TX_BLOCK_SIZE))
621                 goto corrupt;
622
623         if (!read_uint32(&data, tx_data->endp,
624                               &tx_data->num_code_sets))
625                 goto corrupt;
626
627         dprintk("%u IR blaster codesets loaded\n", tx_data->num_code_sets);
628
629         tx_data->code_sets = vmalloc(
630                 tx_data->num_code_sets * sizeof(char *));
631         if (tx_data->code_sets == NULL) {
632                 fw_unload_locked();
633                 ret = -ENOMEM;
634                 goto out;
635         }
636
637         for (i = 0; i < TX_BLOCK_SIZE; ++i)
638                 tx_data->fixed[i] = -1;
639
640         /* Read global fixed data template */
641         if (!read_uint8(&data, tx_data->endp, &num_global_fixed) ||
642             num_global_fixed > TX_BLOCK_SIZE)
643                 goto corrupt;
644         for (i = 0; i < num_global_fixed; ++i) {
645                 unsigned char pos, val;
646                 if (!read_uint8(&data, tx_data->endp, &pos) ||
647                     !read_uint8(&data, tx_data->endp, &val) ||
648                     pos >= TX_BLOCK_SIZE)
649                         goto corrupt;
650                 tx_data->fixed[pos] = (int)val;
651         }
652
653         /* Filch out the position of each code set */
654         for (i = 0; i < tx_data->num_code_sets; ++i) {
655                 unsigned int id;
656                 unsigned char keys;
657                 unsigned char ndiffs;
658
659                 /* Save the codeset position */
660                 tx_data->code_sets[i] = data;
661
662                 /* Read header */
663                 if (!read_uint32(&data, tx_data->endp, &id) ||
664                     !read_uint8(&data, tx_data->endp, &keys) ||
665                     !read_uint8(&data, tx_data->endp, &ndiffs) ||
666                     ndiffs > TX_BLOCK_SIZE || keys == 0)
667                         goto corrupt;
668
669                 /* skip diff positions */
670                 if (!skip(&data, tx_data->endp, ndiffs))
671                         goto corrupt;
672
673                 /*
674                  * After the diffs we have the first key id + data -
675                  * global fixed
676                  */
677                 if (!skip(&data, tx_data->endp,
678                                1 + TX_BLOCK_SIZE - num_global_fixed))
679                         goto corrupt;
680
681                 /* Then we have keys-1 blocks of key id+diffs */
682                 if (!skip(&data, tx_data->endp,
683                                (ndiffs + 1) * (keys - 1)))
684                         goto corrupt;
685         }
686         ret = 0;
687         goto out;
688
689 corrupt:
690         zilog_error("firmware is corrupt\n");
691         fw_unload_locked();
692         ret = -EFAULT;
693
694 out:
695         mutex_unlock(&tx_data_lock);
696         return ret;
697 }
698
699 /* initialise the IR TX device */
700 static int tx_init(struct IR_tx *tx)
701 {
702         int ret;
703
704         /* Load 'firmware' */
705         ret = fw_load(tx);
706         if (ret != 0)
707                 return ret;
708
709         /* Send boot block */
710         ret = send_boot_data(tx);
711         if (ret != 0)
712                 return ret;
713         tx->need_boot = 0;
714
715         /* Looks good */
716         return 0;
717 }
718
719 /* do nothing stub to make LIRC happy */
720 static loff_t lseek(struct file *filep, loff_t offset, int orig)
721 {
722         return -ESPIPE;
723 }
724
725 /* copied from lirc_dev */
726 static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
727 {
728         struct IR *ir = filep->private_data;
729         struct IR_rx *rx = ir->rx;
730         int ret = 0, written = 0;
731         DECLARE_WAITQUEUE(wait, current);
732
733         dprintk("read called\n");
734         if (rx == NULL)
735                 return -ENODEV;
736
737         if (mutex_lock_interruptible(&rx->buf_lock))
738                 return -ERESTARTSYS;
739
740         if (n % rx->buf.chunk_size) {
741                 dprintk("read result = -EINVAL\n");
742                 mutex_unlock(&rx->buf_lock);
743                 return -EINVAL;
744         }
745
746         /*
747          * we add ourselves to the task queue before buffer check
748          * to avoid losing scan code (in case when queue is awaken somewhere
749          * between while condition checking and scheduling)
750          */
751         add_wait_queue(&rx->buf.wait_poll, &wait);
752         set_current_state(TASK_INTERRUPTIBLE);
753
754         /*
755          * while we didn't provide 'length' bytes, device is opened in blocking
756          * mode and 'copy_to_user' is happy, wait for data.
757          */
758         while (written < n && ret == 0) {
759                 if (lirc_buffer_empty(&rx->buf)) {
760                         /*
761                          * According to the read(2) man page, 'written' can be
762                          * returned as less than 'n', instead of blocking
763                          * again, returning -EWOULDBLOCK, or returning
764                          * -ERESTARTSYS
765                          */
766                         if (written)
767                                 break;
768                         if (filep->f_flags & O_NONBLOCK) {
769                                 ret = -EWOULDBLOCK;
770                                 break;
771                         }
772                         if (signal_pending(current)) {
773                                 ret = -ERESTARTSYS;
774                                 break;
775                         }
776                         schedule();
777                         set_current_state(TASK_INTERRUPTIBLE);
778                 } else {
779                         unsigned char buf[rx->buf.chunk_size];
780                         lirc_buffer_read(&rx->buf, buf);
781                         ret = copy_to_user((void *)outbuf+written, buf,
782                                            rx->buf.chunk_size);
783                         written += rx->buf.chunk_size;
784                 }
785         }
786
787         remove_wait_queue(&rx->buf.wait_poll, &wait);
788         set_current_state(TASK_RUNNING);
789         mutex_unlock(&rx->buf_lock);
790
791         dprintk("read result = %s (%d)\n",
792                 ret ? "-EFAULT" : "OK", ret);
793
794         return ret ? ret : written;
795 }
796
797 /* send a keypress to the IR TX device */
798 static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
799 {
800         unsigned char data_block[TX_BLOCK_SIZE];
801         unsigned char buf[2];
802         int i, ret;
803
804         /* Get data for the codeset/key */
805         ret = get_key_data(data_block, code, key);
806
807         if (ret == -EPROTO) {
808                 zilog_error("failed to get data for code %u, key %u -- check "
809                             "lircd.conf entries\n", code, key);
810                 return ret;
811         } else if (ret != 0)
812                 return ret;
813
814         /* Send the data block */
815         ret = send_data_block(tx, data_block);
816         if (ret != 0)
817                 return ret;
818
819         /* Send data block length? */
820         buf[0] = 0x00;
821         buf[1] = 0x40;
822         ret = i2c_master_send(tx->c, buf, 2);
823         if (ret != 2) {
824                 zilog_error("i2c_master_send failed with %d\n", ret);
825                 return ret < 0 ? ret : -EFAULT;
826         }
827         ret = i2c_master_send(tx->c, buf, 1);
828         if (ret != 1) {
829                 zilog_error("i2c_master_send failed with %d\n", ret);
830                 return ret < 0 ? ret : -EFAULT;
831         }
832
833         /* Send finished download? */
834         ret = i2c_master_recv(tx->c, buf, 1);
835         if (ret != 1) {
836                 zilog_error("i2c_master_recv failed with %d\n", ret);
837                 return ret < 0 ? ret : -EFAULT;
838         }
839         if (buf[0] != 0xA0) {
840                 zilog_error("unexpected IR TX response #1: %02x\n",
841                         buf[0]);
842                 return -EFAULT;
843         }
844
845         /* Send prepare command? */
846         buf[0] = 0x00;
847         buf[1] = 0x80;
848         ret = i2c_master_send(tx->c, buf, 2);
849         if (ret != 2) {
850                 zilog_error("i2c_master_send failed with %d\n", ret);
851                 return ret < 0 ? ret : -EFAULT;
852         }
853
854         /*
855          * The sleep bits aren't necessary on the HD PVR, and in fact, the
856          * last i2c_master_recv always fails with a -5, so for now, we're
857          * going to skip this whole mess and say we're done on the HD PVR
858          */
859         if (!tx->post_tx_ready_poll) {
860                 dprintk("sent code %u, key %u\n", code, key);
861                 return 0;
862         }
863
864         /*
865          * This bit NAKs until the device is ready, so we retry it
866          * sleeping a bit each time.  This seems to be what the windows
867          * driver does, approximately.
868          * Try for up to 1s.
869          */
870         for (i = 0; i < 20; ++i) {
871                 set_current_state(TASK_UNINTERRUPTIBLE);
872                 schedule_timeout((50 * HZ + 999) / 1000);
873                 ret = i2c_master_send(tx->c, buf, 1);
874                 if (ret == 1)
875                         break;
876                 dprintk("NAK expected: i2c_master_send "
877                         "failed with %d (try %d)\n", ret, i+1);
878         }
879         if (ret != 1) {
880                 zilog_error("IR TX chip never got ready: last i2c_master_send "
881                             "failed with %d\n", ret);
882                 return ret < 0 ? ret : -EFAULT;
883         }
884
885         /* Seems to be an 'ok' response */
886         i = i2c_master_recv(tx->c, buf, 1);
887         if (i != 1) {
888                 zilog_error("i2c_master_recv failed with %d\n", ret);
889                 return -EFAULT;
890         }
891         if (buf[0] != 0x80) {
892                 zilog_error("unexpected IR TX response #2: %02x\n", buf[0]);
893                 return -EFAULT;
894         }
895
896         /* Oh good, it worked */
897         dprintk("sent code %u, key %u\n", code, key);
898         return 0;
899 }
900
901 /*
902  * Write a code to the device.  We take in a 32-bit number (an int) and then
903  * decode this to a codeset/key index.  The key data is then decompressed and
904  * sent to the device.  We have a spin lock as per i2c documentation to prevent
905  * multiple concurrent sends which would probably cause the device to explode.
906  */
907 static ssize_t write(struct file *filep, const char *buf, size_t n,
908                           loff_t *ppos)
909 {
910         struct IR *ir = filep->private_data;
911         struct IR_tx *tx = ir->tx;
912         size_t i;
913         int failures = 0;
914
915         if (tx == NULL)
916                 return -ENODEV;
917
918         /* Validate user parameters */
919         if (n % sizeof(int))
920                 return -EINVAL;
921
922         /* Lock i2c bus for the duration */
923         mutex_lock(&ir->ir_lock);
924
925         /* Send each keypress */
926         for (i = 0; i < n;) {
927                 int ret = 0;
928                 int command;
929
930                 if (copy_from_user(&command, buf + i, sizeof(command))) {
931                         mutex_unlock(&ir->ir_lock);
932                         return -EFAULT;
933                 }
934
935                 /* Send boot data first if required */
936                 if (tx->need_boot == 1) {
937                         ret = send_boot_data(tx);
938                         if (ret == 0)
939                                 tx->need_boot = 0;
940                 }
941
942                 /* Send the code */
943                 if (ret == 0) {
944                         ret = send_code(tx, (unsigned)command >> 16,
945                                             (unsigned)command & 0xFFFF);
946                         if (ret == -EPROTO) {
947                                 mutex_unlock(&ir->ir_lock);
948                                 return ret;
949                         }
950                 }
951
952                 /*
953                  * Hmm, a failure.  If we've had a few then give up, otherwise
954                  * try a reset
955                  */
956                 if (ret != 0) {
957                         /* Looks like the chip crashed, reset it */
958                         zilog_error("sending to the IR transmitter chip "
959                                     "failed, trying reset\n");
960
961                         if (failures >= 3) {
962                                 zilog_error("unable to send to the IR chip "
963                                             "after 3 resets, giving up\n");
964                                 mutex_unlock(&ir->ir_lock);
965                                 return ret;
966                         }
967                         set_current_state(TASK_UNINTERRUPTIBLE);
968                         schedule_timeout((100 * HZ + 999) / 1000);
969                         tx->need_boot = 1;
970                         ++failures;
971                 } else
972                         i += sizeof(int);
973         }
974
975         /* Release i2c bus */
976         mutex_unlock(&ir->ir_lock);
977
978         /* All looks good */
979         return n;
980 }
981
982 /* copied from lirc_dev */
983 static unsigned int poll(struct file *filep, poll_table *wait)
984 {
985         struct IR *ir = filep->private_data;
986         struct IR_rx *rx = ir->rx;
987         unsigned int ret;
988
989         dprintk("poll called\n");
990         if (rx == NULL)
991                 return -ENODEV;
992
993         mutex_lock(&rx->buf_lock);
994
995         poll_wait(filep, &rx->buf.wait_poll, wait);
996
997         dprintk("poll result = %s\n",
998                 lirc_buffer_empty(&rx->buf) ? "0" : "POLLIN|POLLRDNORM");
999
1000         ret = lirc_buffer_empty(&rx->buf) ? 0 : (POLLIN|POLLRDNORM);
1001
1002         mutex_unlock(&rx->buf_lock);
1003         return ret;
1004 }
1005
1006 static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
1007 {
1008         struct IR *ir = filep->private_data;
1009         int result;
1010         unsigned long mode, features = 0;
1011
1012         features |= LIRC_CAN_SEND_PULSE;
1013         if (ir->rx != NULL)
1014                 features |= LIRC_CAN_REC_LIRCCODE;
1015
1016         switch (cmd) {
1017         case LIRC_GET_LENGTH:
1018                 result = put_user((unsigned long)13,
1019                                   (unsigned long *)arg);
1020                 break;
1021         case LIRC_GET_FEATURES:
1022                 result = put_user(features, (unsigned long *) arg);
1023                 break;
1024         case LIRC_GET_REC_MODE:
1025                 if (!(features&LIRC_CAN_REC_MASK))
1026                         return -ENOSYS;
1027
1028                 result = put_user(LIRC_REC2MODE
1029                                   (features&LIRC_CAN_REC_MASK),
1030                                   (unsigned long *)arg);
1031                 break;
1032         case LIRC_SET_REC_MODE:
1033                 if (!(features&LIRC_CAN_REC_MASK))
1034                         return -ENOSYS;
1035
1036                 result = get_user(mode, (unsigned long *)arg);
1037                 if (!result && !(LIRC_MODE2REC(mode) & features))
1038                         result = -EINVAL;
1039                 break;
1040         case LIRC_GET_SEND_MODE:
1041                 result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg);
1042                 break;
1043         case LIRC_SET_SEND_MODE:
1044                 result = get_user(mode, (unsigned long *) arg);
1045                 if (!result && mode != LIRC_MODE_PULSE)
1046                         return -EINVAL;
1047                 break;
1048         default:
1049                 return -EINVAL;
1050         }
1051         return result;
1052 }
1053
1054 /* ir_devices_lock must be held */
1055 static struct IR *find_ir_device_by_minor(unsigned int minor)
1056 {
1057         if (minor >= MAX_IRCTL_DEVICES)
1058                 return NULL;
1059
1060         return ir_devices[minor];
1061 }
1062
1063 /*
1064  * Open the IR device.  Get hold of our IR structure and
1065  * stash it in private_data for the file
1066  */
1067 static int open(struct inode *node, struct file *filep)
1068 {
1069         struct IR *ir;
1070         int ret;
1071         unsigned int minor = MINOR(node->i_rdev);
1072
1073         /* find our IR struct */
1074         mutex_lock(&ir_devices_lock);
1075         ir = find_ir_device_by_minor(minor);
1076         mutex_unlock(&ir_devices_lock);
1077
1078         if (ir == NULL)
1079                 return -ENODEV;
1080
1081         /* increment in use count */
1082         mutex_lock(&ir->ir_lock);
1083         ++ir->open;
1084         ret = set_use_inc(ir);
1085         if (ret != 0) {
1086                 --ir->open;
1087                 mutex_unlock(&ir->ir_lock);
1088                 return ret;
1089         }
1090         mutex_unlock(&ir->ir_lock);
1091
1092         /* stash our IR struct */
1093         filep->private_data = ir;
1094
1095         return 0;
1096 }
1097
1098 /* Close the IR device */
1099 static int close(struct inode *node, struct file *filep)
1100 {
1101         /* find our IR struct */
1102         struct IR *ir = filep->private_data;
1103         if (ir == NULL) {
1104                 zilog_error("close: no private_data attached to the file!\n");
1105                 return -ENODEV;
1106         }
1107
1108         /* decrement in use count */
1109         mutex_lock(&ir->ir_lock);
1110         --ir->open;
1111         set_use_dec(ir);
1112         mutex_unlock(&ir->ir_lock);
1113
1114         return 0;
1115 }
1116
1117 static struct lirc_driver lirc_template = {
1118         .name           = "lirc_zilog",
1119         .set_use_inc    = set_use_inc,
1120         .set_use_dec    = set_use_dec,
1121         .owner          = THIS_MODULE
1122 };
1123
1124 static int ir_remove(struct i2c_client *client);
1125 static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id);
1126
1127 #define ID_FLAG_TX      0x01
1128 #define ID_FLAG_HDPVR   0x02
1129
1130 static const struct i2c_device_id ir_transceiver_id[] = {
1131         { "ir_tx_z8f0811_haup",  ID_FLAG_TX                 },
1132         { "ir_rx_z8f0811_haup",  0                          },
1133         { "ir_tx_z8f0811_hdpvr", ID_FLAG_HDPVR | ID_FLAG_TX },
1134         { "ir_rx_z8f0811_hdpvr", ID_FLAG_HDPVR              },
1135         { }
1136 };
1137
1138 static struct i2c_driver driver = {
1139         .driver = {
1140                 .owner  = THIS_MODULE,
1141                 .name   = "Zilog/Hauppauge i2c IR",
1142         },
1143         .probe          = ir_probe,
1144         .remove         = ir_remove,
1145         .id_table       = ir_transceiver_id,
1146 };
1147
1148 static const struct file_operations lirc_fops = {
1149         .owner          = THIS_MODULE,
1150         .llseek         = lseek,
1151         .read           = read,
1152         .write          = write,
1153         .poll           = poll,
1154         .unlocked_ioctl = ioctl,
1155 #ifdef CONFIG_COMPAT
1156         .compat_ioctl   = ioctl,
1157 #endif
1158         .open           = open,
1159         .release        = close
1160 };
1161
1162 static void destroy_rx_kthread(struct IR_rx *rx)
1163 {
1164         /* end up polling thread */
1165         if (rx != NULL && !IS_ERR_OR_NULL(rx->task)) {
1166                 kthread_stop(rx->task);
1167                 rx->task = NULL;
1168         }
1169 }
1170
1171 /* ir_devices_lock must be held */
1172 static int add_ir_device(struct IR *ir)
1173 {
1174         int i;
1175
1176         for (i = 0; i < MAX_IRCTL_DEVICES; i++)
1177                 if (ir_devices[i] == NULL) {
1178                         ir_devices[i] = ir;
1179                         break;
1180                 }
1181
1182         return i == MAX_IRCTL_DEVICES ? -ENOMEM : i;
1183 }
1184
1185 /* ir_devices_lock must be held */
1186 static void del_ir_device(struct IR *ir)
1187 {
1188         int i;
1189
1190         for (i = 0; i < MAX_IRCTL_DEVICES; i++)
1191                 if (ir_devices[i] == ir) {
1192                         ir_devices[i] = NULL;
1193                         break;
1194                 }
1195 }
1196
1197 static int ir_remove(struct i2c_client *client)
1198 {
1199         struct IR *ir = i2c_get_clientdata(client);
1200
1201         mutex_lock(&ir_devices_lock);
1202
1203         if (ir == NULL) {
1204                 /* We destroyed everything when the first client came through */
1205                 mutex_unlock(&ir_devices_lock);
1206                 return 0;
1207         }
1208
1209         /* Good-bye LIRC */
1210         lirc_unregister_driver(ir->l.minor);
1211
1212         /* Good-bye Rx */
1213         destroy_rx_kthread(ir->rx);
1214         if (ir->rx != NULL) {
1215                 if (ir->rx->buf.fifo_initialized)
1216                         lirc_buffer_free(&ir->rx->buf);
1217                 i2c_set_clientdata(ir->rx->c, NULL);
1218                 kfree(ir->rx);
1219         }
1220
1221         /* Good-bye Tx */
1222         i2c_set_clientdata(ir->tx->c, NULL);
1223         kfree(ir->tx);
1224
1225         /* Good-bye IR */
1226         del_ir_device(ir);
1227         kfree(ir);
1228
1229         mutex_unlock(&ir_devices_lock);
1230         return 0;
1231 }
1232
1233
1234 /* ir_devices_lock must be held */
1235 static struct IR *find_ir_device_by_adapter(struct i2c_adapter *adapter)
1236 {
1237         int i;
1238         struct IR *ir = NULL;
1239
1240         for (i = 0; i < MAX_IRCTL_DEVICES; i++)
1241                 if (ir_devices[i] != NULL &&
1242                     ir_devices[i]->adapter == adapter) {
1243                         ir = ir_devices[i];
1244                         break;
1245                 }
1246
1247         return ir;
1248 }
1249
1250 static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1251 {
1252         struct IR *ir;
1253         struct i2c_adapter *adap = client->adapter;
1254         int ret;
1255         bool tx_probe = false;
1256
1257         dprintk("%s: %s on i2c-%d (%s), client addr=0x%02x\n",
1258                 __func__, id->name, adap->nr, adap->name, client->addr);
1259
1260         /*
1261          * The IR receiver    is at i2c address 0x71.
1262          * The IR transmitter is at i2c address 0x70.
1263          */
1264
1265         if (id->driver_data & ID_FLAG_TX)
1266                 tx_probe = true;
1267         else if (tx_only) /* module option */
1268                 return -ENXIO;
1269
1270         zilog_info("probing IR %s on %s (i2c-%d)\n",
1271                    tx_probe ? "Tx" : "Rx", adap->name, adap->nr);
1272
1273         mutex_lock(&ir_devices_lock);
1274
1275         /* Use a single struct IR instance for both the Rx and Tx functions */
1276         ir = find_ir_device_by_adapter(adap);
1277         if (ir == NULL) {
1278                 ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
1279                 if (ir == NULL) {
1280                         ret = -ENOMEM;
1281                         goto out_no_ir;
1282                 }
1283                 /* store for use in ir_probe() again, and open() later on */
1284                 ret = add_ir_device(ir);
1285                 if (ret)
1286                         goto out_free_ir;
1287
1288                 ir->adapter = adap;
1289                 mutex_init(&ir->ir_lock);
1290
1291                 /* set lirc_dev stuff */
1292                 memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));
1293                 ir->l.minor       = minor; /* module option */
1294                 ir->l.code_length = 13;
1295                 ir->l.rbuf        = NULL;
1296                 ir->l.fops        = &lirc_fops;
1297                 ir->l.data        = ir;
1298                 ir->l.dev         = &adap->dev;
1299                 ir->l.sample_rate = 0;
1300         }
1301
1302         if (tx_probe) {
1303                 /* Set up a struct IR_tx instance */
1304                 ir->tx = kzalloc(sizeof(struct IR_tx), GFP_KERNEL);
1305                 if (ir->tx == NULL) {
1306                         ret = -ENOMEM;
1307                         goto out_free_xx;
1308                 }
1309
1310                 ir->tx->c = client;
1311                 ir->tx->need_boot = 1;
1312                 ir->tx->post_tx_ready_poll =
1313                                (id->driver_data & ID_FLAG_HDPVR) ? false : true;
1314         } else {
1315                 /* Set up a struct IR_rx instance */
1316                 ir->rx = kzalloc(sizeof(struct IR_rx), GFP_KERNEL);
1317                 if (ir->rx == NULL) {
1318                         ret = -ENOMEM;
1319                         goto out_free_xx;
1320                 }
1321
1322                 ret = lirc_buffer_init(&ir->rx->buf, 2, BUFLEN / 2);
1323                 if (ret)
1324                         goto out_free_xx;
1325
1326                 mutex_init(&ir->rx->buf_lock);
1327                 ir->rx->c = client;
1328                 ir->rx->hdpvr_data_fmt =
1329                                (id->driver_data & ID_FLAG_HDPVR) ? true : false;
1330
1331                 /* set lirc_dev stuff */
1332                 ir->l.rbuf = &ir->rx->buf;
1333         }
1334
1335         i2c_set_clientdata(client, ir);
1336
1337         /* Proceed only if we have the required Tx and Rx clients ready to go */
1338         if (ir->tx == NULL ||
1339             (ir->rx == NULL && !tx_only)) {
1340                 zilog_info("probe of IR %s on %s (i2c-%d) done. Waiting on "
1341                            "IR %s.\n", tx_probe ? "Tx" : "Rx", adap->name,
1342                            adap->nr, tx_probe ? "Rx" : "Tx");
1343                 goto out_ok;
1344         }
1345
1346         /* initialise RX device */
1347         if (ir->rx != NULL) {
1348                 /* try to fire up polling thread */
1349                 ir->rx->task = kthread_run(lirc_thread, ir,
1350                                            "zilog-rx-i2c-%d", adap->nr);
1351                 if (IS_ERR(ir->rx->task)) {
1352                         ret = PTR_ERR(ir->rx->task);
1353                         zilog_error("%s: could not start IR Rx polling thread"
1354                                     "\n", __func__);
1355                         goto out_free_xx;
1356                 }
1357         }
1358
1359         /* register with lirc */
1360         ir->l.minor = lirc_register_driver(&ir->l);
1361         if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) {
1362                 zilog_error("%s: \"minor\" must be between 0 and %d (%d)!\n",
1363                             __func__, MAX_IRCTL_DEVICES-1, ir->l.minor);
1364                 ret = -EBADRQC;
1365                 goto out_free_thread;
1366         }
1367
1368         /*
1369          * if we have the tx device, load the 'firmware'.  We do this
1370          * after registering with lirc as otherwise hotplug seems to take
1371          * 10s to create the lirc device.
1372          */
1373         ret = tx_init(ir->tx);
1374         if (ret != 0)
1375                 goto out_unregister;
1376
1377         zilog_info("probe of IR %s on %s (i2c-%d) done. IR unit ready.\n",
1378                    tx_probe ? "Tx" : "Rx", adap->name, adap->nr);
1379 out_ok:
1380         mutex_unlock(&ir_devices_lock);
1381         return 0;
1382
1383 out_unregister:
1384         lirc_unregister_driver(ir->l.minor);
1385 out_free_thread:
1386         destroy_rx_kthread(ir->rx);
1387 out_free_xx:
1388         if (ir->rx != NULL) {
1389                 if (ir->rx->buf.fifo_initialized)
1390                         lirc_buffer_free(&ir->rx->buf);
1391                 if (ir->rx->c != NULL)
1392                         i2c_set_clientdata(ir->rx->c, NULL);
1393                 kfree(ir->rx);
1394         }
1395         if (ir->tx != NULL) {
1396                 if (ir->tx->c != NULL)
1397                         i2c_set_clientdata(ir->tx->c, NULL);
1398                 kfree(ir->tx);
1399         }
1400 out_free_ir:
1401         del_ir_device(ir);
1402         kfree(ir);
1403 out_no_ir:
1404         zilog_error("%s: probing IR %s on %s (i2c-%d) failed with %d\n",
1405                     __func__, tx_probe ? "Tx" : "Rx", adap->name, adap->nr,
1406                    ret);
1407         mutex_unlock(&ir_devices_lock);
1408         return ret;
1409 }
1410
1411 static int __init zilog_init(void)
1412 {
1413         int ret;
1414
1415         zilog_notify("Zilog/Hauppauge IR driver initializing\n");
1416
1417         mutex_init(&tx_data_lock);
1418         mutex_init(&ir_devices_lock);
1419
1420         request_module("firmware_class");
1421
1422         ret = i2c_add_driver(&driver);
1423         if (ret)
1424                 zilog_error("initialization failed\n");
1425         else
1426                 zilog_notify("initialization complete\n");
1427
1428         return ret;
1429 }
1430
1431 static void __exit zilog_exit(void)
1432 {
1433         i2c_del_driver(&driver);
1434         /* if loaded */
1435         fw_unload();
1436         zilog_notify("Zilog/Hauppauge IR driver unloaded\n");
1437 }
1438
1439 module_init(zilog_init);
1440 module_exit(zilog_exit);
1441
1442 MODULE_DESCRIPTION("Zilog/Hauppauge infrared transmitter driver (i2c stack)");
1443 MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, "
1444               "Ulrich Mueller, Stefan Jahn, Jerome Brock, Mark Weaver");
1445 MODULE_LICENSE("GPL");
1446 /* for compat with old name, which isn't all that accurate anymore */
1447 MODULE_ALIAS("lirc_pvr150");
1448
1449 module_param(minor, int, 0444);
1450 MODULE_PARM_DESC(minor, "Preferred minor device number");
1451
1452 module_param(debug, bool, 0644);
1453 MODULE_PARM_DESC(debug, "Enable debugging messages");
1454
1455 module_param(tx_only, bool, 0644);
1456 MODULE_PARM_DESC(tx_only, "Only handle the IR transmit function");