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