Index: drivers/kcompat.h =================================================================== RCS file: /cvsroot/lirc/lirc/drivers/kcompat.h,v retrieving revision 5.30 diff -u -u -r5.30 kcompat.h --- drivers/kcompat.h 2 Jan 2007 21:45:08 -0000 5.30 +++ drivers/kcompat.h 16 Sep 2007 20:58:39 -0000 @@ -5,24 +5,24 @@ #include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) #define LIRC_THIS_MODULE(x) x, #else /* >= 2.6.16 */ #define LIRC_THIS_MODULE(x) #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) #include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) #define LIRC_HAVE_DEVFS #define LIRC_HAVE_DEVFS_26 #endif #define LIRC_HAVE_SYSFS -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 13) typedef struct class_simple lirc_class_t; @@ -46,7 +46,7 @@ #else /* >= 2.6.13 */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 15) #define lirc_class_device_create(cs, parent, dev, device, fmt, args...) \ class_device_create(cs, dev, device, fmt, ## args) @@ -62,7 +62,7 @@ #endif -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) #define LIRC_HAVE_DEVFS #define LIRC_HAVE_DEVFS_24 #endif @@ -74,7 +74,7 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) #include #include -static inline void del_timer_sync(struct timer_list * timerlist) +static inline void del_timer_sync(struct timer_list *timerlist) { start_bh_atomic(); del_timer(timerlist); @@ -86,30 +86,30 @@ #ifdef daemonize #undef daemonize #endif -#define daemonize(name) do { \ - \ - lock_kernel(); \ - \ - exit_mm(current); \ - exit_files(current); \ - exit_fs(current); \ - current->session = 1; \ - current->pgrp = 1; \ - current->euid = 0; \ - current->tty = NULL; \ - sigfillset(¤t->blocked); \ - \ - strcpy(current->comm, name); \ - \ - unlock_kernel(); \ - \ +#define daemonize(name) do { \ + \ + lock_kernel(); \ + \ + exit_mm(current); \ + exit_files(current); \ + exit_fs(current); \ + current->session = 1; \ + current->pgrp = 1; \ + current->euid = 0; \ + current->tty = NULL; \ + sigfillset(¤t->blocked); \ + \ + strcpy(current->comm, name); \ + \ + unlock_kernel(); \ + \ } while (0) /* Not sure when this was introduced, sometime during 2.5.X */ #define MODULE_PARM_int(x) MODULE_PARM(x, "i") #define MODULE_PARM_bool(x) MODULE_PARM(x, "i") #define MODULE_PARM_long(x) MODULE_PARM(x, "l") -#define module_param(x,y,z) MODULE_PARM_##y(x) +#define module_param(x, y, z) MODULE_PARM_##y(x) #else #include #endif /* Linux < 2.6.0 */ @@ -131,27 +131,27 @@ #endif /* DEVFS 2.4 */ #ifndef LIRC_HAVE_SYSFS -#define class_destroy(x) do { } while(0) -#define class_create(x,y) NULL -#define class_device_destroy(x,y) do { } while(0) +#define class_destroy(x) do { } while (0) +#define class_create(x, y) NULL +#define class_device_destroy(x, y) do { } while (0) #define lirc_class_device_create(x, y, z, xx, yy, zz) 0 #define IS_ERR(x) 0 -typedef struct class_simple +typedef struct class_simple { int notused; -} lirc_class_t; +} lirc_class_t; #endif /* No SYSFS */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) #define KERNEL_2_5 /* - * We still are using MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT in the set_use_inc + * We still are using MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT in the set_use_inc * function of all modules for 2.4 kernel compatibility. - * - * For 2.6 kernels reference counting is done in lirc_dev by + * + * For 2.6 kernels reference counting is done in lirc_dev by * try_module_get()/module_put() because the old approach is racy. - * + * */ #ifdef MOD_INC_USE_COUNT #undef MOD_INC_USE_COUNT @@ -186,7 +186,7 @@ #endif #ifndef MODULE_PARM_DESC -#define MODULE_PARM_DESC(x,y) +#define MODULE_PARM_DESC(x, y) #endif #ifndef MODULE_ALIAS_CHARDEV_MAJOR @@ -194,7 +194,7 @@ #endif #ifndef MODULE_DEVICE_TABLE -#define MODULE_DEVICE_TABLE(x,y) +#define MODULE_DEVICE_TABLE(x, y) #endif #include @@ -215,20 +215,23 @@ #endif #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) #if !defined(local_irq_save) -#define local_irq_save(flags) do{ save_flags(flags);cli(); } while(0) +#define local_irq_save(flags) do { save_flags(flags); cli(); } while (0) #endif #if !defined(local_irq_restore) -#define local_irq_restore(flags) do{ restore_flags(flags); } while(0) +#define local_irq_restore(flags) do { restore_flags(flags); } while (0) +#endif #endif -#if KERNEL_VERSION(2, 4, 0) <= LINUX_VERSION_CODE && LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 22) +#if KERNEL_VERSION(2, 4, 0) <= LINUX_VERSION_CODE \ + && LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 22) #include static inline char *pci_name(struct pci_dev *pdev) { return pdev->slot_name; } -#endif // 2.4.0 <= kernel < 2.4.22 +#endif /* 2.4.0 <= kernel < 2.4.22 */ /*************************** I2C specific *****************************/ #include @@ -277,7 +280,7 @@ /* removed in 2.6.14 */ #ifndef URB_ASYNC_UNLINK -#define URB_ASYNC_UNLINK 0 +#define URB_ASYNC_UNLINK 0 #endif #endif @@ -321,12 +324,9 @@ /******************************* pm.h *********************************/ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && \ + LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11) typedef u32 pm_message_t; #endif -#endif - #endif /* _KCOMPAT_H */ Index: drivers/lirc.h =================================================================== RCS file: /cvsroot/lirc/lirc/drivers/lirc.h,v retrieving revision 5.12 diff -u -u -r5.12 lirc.h --- drivers/lirc.h 14 Apr 2007 15:57:21 -0000 5.12 +++ drivers/lirc.h 16 Sep 2007 20:58:39 -0000 @@ -3,12 +3,12 @@ #ifndef _LINUX_LIRC_H #define _LINUX_LIRC_H -#if defined (__linux__) +#if defined(__linux__) #include #include #else #include -#if defined (__NetBSD__) +#if defined(__NetBSD__) #include #endif typedef u_int32_t __u32; Index: drivers/lirc_atiusb/lirc_atiusb.c =================================================================== RCS file: /cvsroot/lirc/lirc/drivers/lirc_atiusb/lirc_atiusb.c,v retrieving revision 1.63 diff -u -u -r1.63 lirc_atiusb.c --- drivers/lirc_atiusb/lirc_atiusb.c 22 Jul 2007 07:37:30 -0000 1.63 +++ drivers/lirc_atiusb/lirc_atiusb.c 16 Sep 2007 20:58:42 -0000 @@ -53,7 +53,11 @@ #include #include #include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) +#include +#else #include +#endif #include #include #include @@ -84,31 +88,32 @@ /* module parameters */ #ifdef CONFIG_USB_DEBUG - static int debug = 1; +static int debug = 1; #else - static int debug = 0; +static int debug; #endif -#define dprintk(fmt, args...) \ - do{ \ - if(debug) printk(KERN_DEBUG fmt, ## args); \ - }while(0) +#define dprintk(fmt, args...) \ + do { \ + if (debug) \ + printk(KERN_DEBUG fmt, ## args); \ + } while (0) -// ATI, ATI2, XBOX +/* ATI, ATI2, XBOX */ static const int code_length[] = {5, 3, 6}; static const int code_min_length[] = {3, 3, 6}; static const int decode_length[] = {5, 3, 1}; -// USB_BUFF_LEN must be the maximum value of the code_length array. -// It is used for static arrays. +/* USB_BUFF_LEN must be the maximum value of the code_length array. + * It is used for static arrays. */ #define USB_BUFF_LEN 6 -static int mask = 0xFFFF; // channel acceptance bit mask -static int unique = 0; // enable channel-specific codes -static int repeat = 10; // repeat time in 1/100 sec -static int emit_updown = 0; // send seperate press/release codes (rw2) -static int emit_modekeys = 0; // send keycodes for aux1-aux4, pc, and mouse (rw2) -static unsigned long repeat_jiffies; // repeat timeout -static int mdeadzone = 0; // mouse sensitivity >= 0 -static int mgradient = 375; // 1000*gradient from cardinal direction +static int mask = 0xFFFF; /* channel acceptance bit mask */ +static int unique; /* enable channel-specific codes */ +static int repeat = 10; /* repeat time in 1/100 sec */ +static int emit_updown; /* send seperate press/release codes (rw2) */ +static int emit_modekeys; /* send keycodes for aux1-4, pc, and mouse (rw2) */ +static unsigned long repeat_jiffies; /* repeat timeout */ +static int mdeadzone; /* mouse sensitivity >= 0 */ +static int mgradient = 375; /* 1000*gradient from cardinal direction */ /* get hi and low bytes of a 16-bits int */ #define HI(a) ((unsigned char)((a) >> 8)) @@ -137,28 +142,50 @@ #define VENDOR_MS3 0xFFFF static struct usb_device_id usb_remote_table [] = { - { USB_DEVICE(VENDOR_ATI1, 0x0002) }, /* X10 USB Firecracker Interface */ - { USB_DEVICE(VENDOR_ATI1, 0x0003) }, /* X10 VGA Video Sender */ - { USB_DEVICE(VENDOR_ATI1, 0x0004) }, /* ATI Wireless Remote Receiver */ - { USB_DEVICE(VENDOR_ATI1, 0x0005) }, /* NVIDIA Wireless Remote Receiver */ - { USB_DEVICE(VENDOR_ATI1, 0x0006) }, /* ATI Wireless Remote Receiver */ - { USB_DEVICE(VENDOR_ATI1, 0x0007) }, /* X10 USB Wireless Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x0008) }, /* X10 USB Wireless Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x0009) }, /* X10 USB Wireless Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x000A) }, /* X10 USB Wireless Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x000B) }, /* X10 USB Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x000C) }, /* X10 USB Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x000D) }, /* X10 USB Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x000E) }, /* X10 USB Transceiver */ - { USB_DEVICE(VENDOR_ATI1, 0x000F) }, /* X10 USB Transceiver */ - - { USB_DEVICE(VENDOR_ATI2, 0x0602) }, /* ATI Remote Wonder 2: Input Device */ - { USB_DEVICE(VENDOR_ATI2, 0x0603) }, /* ATI Remote Wonder 2: Controller (???) */ - - { USB_DEVICE(VENDOR_MS1, 0x6521) }, /* Gamester Xbox DVD Movie Playback Kit IR */ - { USB_DEVICE(VENDOR_MS2, 0x0284) }, /* Microsoft Xbox DVD Movie Playback Kit IR */ - { USB_DEVICE(VENDOR_MS3, 0xFFFF) }, /* Some chinese manufacterer -- conflicts with the joystick from the same manufacterer */ - { } /* Terminating entry */ + /* X10 USB Firecracker Interface */ + { USB_DEVICE(VENDOR_ATI1, 0x0002) }, + + /* X10 VGA Video Sender */ + { USB_DEVICE(VENDOR_ATI1, 0x0003) }, + + /* ATI Wireless Remote Receiver */ + { USB_DEVICE(VENDOR_ATI1, 0x0004) }, + + /* NVIDIA Wireless Remote Receiver */ + { USB_DEVICE(VENDOR_ATI1, 0x0005) }, + + /* ATI Wireless Remote Receiver */ + { USB_DEVICE(VENDOR_ATI1, 0x0006) }, + + /* X10 USB Wireless Transceivers */ + { USB_DEVICE(VENDOR_ATI1, 0x0007) }, + { USB_DEVICE(VENDOR_ATI1, 0x0008) }, + { USB_DEVICE(VENDOR_ATI1, 0x0009) }, + { USB_DEVICE(VENDOR_ATI1, 0x000A) }, + { USB_DEVICE(VENDOR_ATI1, 0x000B) }, + { USB_DEVICE(VENDOR_ATI1, 0x000C) }, + { USB_DEVICE(VENDOR_ATI1, 0x000D) }, + { USB_DEVICE(VENDOR_ATI1, 0x000E) }, + { USB_DEVICE(VENDOR_ATI1, 0x000F) }, + + /* ATI Remote Wonder 2: Input Device */ + { USB_DEVICE(VENDOR_ATI2, 0x0602) }, + + /* ATI Remote Wonder 2: Controller (???) */ + { USB_DEVICE(VENDOR_ATI2, 0x0603) }, + + /* Gamester Xbox DVD Movie Playback Kit IR */ + { USB_DEVICE(VENDOR_MS1, 0x6521) }, + + /* Microsoft Xbox DVD Movie Playback Kit IR */ + { USB_DEVICE(VENDOR_MS2, 0x0284) }, + + /* Some chinese manufacterer -- conflicts with the joystick from the + * same manufacterer */ + { USB_DEVICE(VENDOR_MS3, 0xFFFF) }, + + /* Terminating entry */ + { } }; @@ -168,8 +195,6 @@ static char init1[] = {0x01, 0x00, 0x20, 0x14}; static char init2[] = {0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20}; - - struct in_endpt { /* inner link in list of endpoints for the remote specified by ir */ struct list_head iep_list_link; @@ -244,8 +269,10 @@ /* Convenience macros to retrieve a pointer to the surrounding struct from * the given list_head reference within, pointed at by link. */ -#define get_iep_from_link(link) list_entry((link), struct in_endpt, iep_list_link); -#define get_irctl_from_link(link) list_entry((link), struct irctl, remote_list_link); +#define get_iep_from_link(link) \ + list_entry((link), struct in_endpt, iep_list_link); +#define get_irctl_from_link(link) \ + list_entry((link), struct irctl, remote_list_link); /* send packet - used to initialize remote */ static void send_packet(struct out_endpt *oep, u16 cmd, unsigned char *data) @@ -282,7 +309,7 @@ IRUNLOCK; while (timeout && (oep->urb->status == -EINPROGRESS) - && !(oep->send_flags & SEND_FLAG_COMPLETE)) { + && !(oep->send_flags & SEND_FLAG_COMPLETE)) { timeout = schedule_timeout(timeout); rmb(); } @@ -340,14 +367,17 @@ /* extract the current in_endpt */ iep = get_iep_from_link(pos); iep->urb->dev = ir->usbdev; - dprintk(DRIVER_NAME "[%d]: linking iep 0x%02x (%p)\n", ir->devnum, iep->ep->bEndpointAddress, iep); + dprintk(DRIVER_NAME "[%d]: linking iep 0x%02x (%p)\n", + ir->devnum, iep->ep->bEndpointAddress, iep); #ifdef KERNEL_2_5 - if ((rtn = usb_submit_urb(iep->urb, GFP_ATOMIC)) < 0) { + rtn = usb_submit_urb(iep->urb, GFP_ATOMIC); #else - if ((rtn = usb_submit_urb(iep->urb)) < 0) { + rtn = usb_submit_urb(iep->urb); #endif - printk(DRIVER_NAME "[%d]: open result = %d error " - "submitting urb\n", ir->devnum, rtn); + if (rtn) { + printk(DRIVER_NAME "[%d]: open result = %d " + "error submitting urb\n", + ir->devnum, rtn); IRUNLOCK; MOD_DEC_USE_COUNT; return -EIO; @@ -377,7 +407,8 @@ /* Free inbound usb urbs */ list_for_each_safe(pos, n, &ir->iep_listhead) { iep = get_iep_from_link(pos); - dprintk(DRIVER_NAME "[%d]: unlinking iep 0x%02x (%p)\n", ir->devnum, iep->ep->bEndpointAddress, iep); + dprintk(DRIVER_NAME "[%d]: unlinking iep 0x%02x (%p)\n", + ir->devnum, iep->ep->bEndpointAddress, iep); usb_kill_urb(iep->urb); } ir->connected = 0; @@ -395,9 +426,8 @@ if (len <= 0) return; - for (i = 0; i < len && i < clen; i++) { + for (i = 0; i < len && i < clen; i++) snprintf(codes+i*3, 4, "%02x ", buf[i] & 0xFF); - } printk(DRIVER_NAME "[%d]: data received %s (ep=0x%x length=%d)\n", iep->ir->devnum, codes, iep->ep->bEndpointAddress, len); } @@ -412,7 +442,7 @@ if (len < CODE_MIN_LENGTH || len > CODE_LENGTH) return -1; - // *** channel not tested with 4/5-byte Dutch remotes *** + /* *** channel not tested with 4/5-byte Dutch remotes *** */ chan = ((iep->buf[len-1]>>4) & 0x0F); /* strip channel code */ @@ -421,8 +451,9 @@ iep->buf[len-3] -= (chan<<4); } - if ( !((1U<devnum, chan+1); + if (!((1U<devnum, chan+1); return -1; } dprintk(DRIVER_NAME "[%d]: accept channel %d\n", ir->devnum, chan+1); @@ -431,12 +462,10 @@ for (i = len; i < CODE_LENGTH; i++) iep->buf[i] = 0; /* check for repeats */ if (memcmp(iep->old, iep->buf, len) == 0) { - if (iep->old_jiffies + repeat_jiffies > jiffies) { + if (iep->old_jiffies + repeat_jiffies > jiffies) return -1; - } - } else { + } else memcpy(iep->old, iep->buf, CODE_LENGTH); - } iep->old_jiffies = jiffies; } @@ -466,10 +495,10 @@ * handle this we need a seperate parameter, like rw2modes, with the * following values and meanings: * - * 0: Don't squash any channel info - * 1: Only squash channel data for non-mode setting keys - * 2: Ignore aux keypresses, but don't squash channel - * 3: Ignore aux keypresses and squash channel data + * 0: Don't squash any channel info + * 1: Only squash channel data for non-mode setting keys + * 2: Ignore aux keypresses, but don't squash channel + * 3: Ignore aux keypresses and squash channel data * * Option 1 may seem useless since the mouse sends the same code, but one * need only ignore in userspace any press of a mode-setting code that only @@ -502,8 +531,8 @@ * and the third, the y-axis. Treated as signed integers, these axes range * approximately as follows: * - * x: (left) -46 ... 46 (right) (0xd2..0x2e) - * y: (up) -46 ... 46 (down) (0xd2..0x2e) + * x: (left) -46 ... 46 (right) (0xd2..0x2e) + * y: (up) -46 ... 46 (down) (0xd2..0x2e) * * NB these values do not correspond to the pressure with which the mouse * norb is pushed in a given direction, but rather seems to indicate the @@ -515,13 +544,14 @@ * * d. The interrupt rate of the mouse vs. the normal keys is different. * - * mouse: ~27Hz (37ms between interrupts) - * keys: ~10Hz (100ms between interrupts) + * mouse: ~27Hz (37ms between interrupts) + * keys: ~10Hz (100ms between interrupts) * * This means that the normal gap mechanism for lircd won't work as * expected; is emit_updown>0 if you can get away with it. */ -static int code_check_ati2(struct in_endpt *iep, int len) { +static int code_check_ati2(struct in_endpt *iep, int len) +{ struct irctl *ir = iep->ir; int mode, i; char *buf = iep->buf; @@ -540,11 +570,12 @@ if (!unique) buf[0] = 0; if (iep->ep->bEndpointAddress == EP_KEYS_ADDR) { - /* ignore mouse navigation indicator key and mode-set (aux) keys */ + /* ignore mouse navigation indicator key and + * mode-set (aux) keys */ if (buf[2] == RW2_MODENAV_KEYCODE) { - if (emit_modekeys >= 2) { /* emit raw */ + if (emit_modekeys >= 2) /* emit raw */ buf[0] = mode; - } else if (emit_modekeys == 1) { /* translate */ + else if (emit_modekeys == 1) { /* translate */ buf[0] = mode; if (ir->mode != mode) { buf[1] = 0x03; @@ -552,8 +583,10 @@ return SUCCESS; } } else { - dprintk(DRIVER_NAME "[%d]: ignore dummy code 0x%x (ep=0x%x)\n", - ir->devnum, buf[2], iep->ep->bEndpointAddress); + dprintk(DRIVER_NAME + "[%d]: ignore dummy code 0x%x " + "(ep=0x%x)\n", ir->devnum, + buf[2], iep->ep->bEndpointAddress); return -1; } } @@ -562,8 +595,8 @@ /* handle press/release codes */ if (emit_updown == 0) /* ignore */ return -1; - else if(emit_updown == 1) /* normalize keycode */ - buf[2] = RW2_PRESSRELEASE_KEYCODE; + else if (emit_updown == 1) /* normalize keycode */ + buf[2] = RW2_PRESSRELEASE_KEYCODE; /* else emit raw */ } @@ -596,11 +629,11 @@ dir_ns = (y > 0) ? MOUSE_S : MOUSE_N; /* convert coordintes(angle) into compass direction */ - if (x == 0) { + if (x == 0) code = dir_ns; - } else if (y == 0) { + else if (y == 0) code = dir_ew; - } else { + else { if (abs(1000*y/x) > mgradient) code = dir_ns; if (abs(1000*x/y) > mgradient) @@ -623,24 +656,19 @@ struct irctl *ir = iep->ir; const int clen = CODE_LENGTH; - if (len != clen) - { - dprintk(DRIVER_NAME ": We got %d instead of %d bytes from xbox ir.. ?\n", len, clen); + if (len != clen) { + dprintk(DRIVER_NAME ": We got %d instead of %d bytes from xbox " + "ir.. ?\n", len, clen); return -1; } /* check for repeats */ - if (memcmp(iep->old, iep->buf, len) == 0) - { - if (iep->old_jiffies + repeat_jiffies > jiffies) - { + if (memcmp(iep->old, iep->buf, len) == 0) { + if (iep->old_jiffies + repeat_jiffies > jiffies) return -1; - } - } - else - { - // the third byte of xbox ir packet seems to contain key info - // the last two bytes are.. some kind of clock? + } else { + /* the third byte of xbox ir packet seems to contain key info + * the last two bytes are.. some kind of clock? */ iep->buf[0] = iep->buf[2]; memset(iep->buf + 1, 0, len - 1); memcpy(iep->old, iep->buf, len); @@ -661,7 +689,8 @@ if (!urb) return; - if (!(iep = urb->context)) { + iep = urb->context; + if (!iep) { #ifdef KERNEL_2_5 urb->transfer_flags |= URB_ASYNC_UNLINK; #endif @@ -673,13 +702,12 @@ len = urb->actual_length; if (debug) - print_data(iep,urb->transfer_buffer,len); + print_data(iep, urb->transfer_buffer, len); switch (urb->status) { /* success */ case SUCCESS: - switch (iep->ir->remote_type) { case XBOX_COMPATIBLE: result = code_check_xbox(iep, len); @@ -691,7 +719,8 @@ default: result = code_check_ati1(iep, len); } - if (result < 0) break; + if (result < 0) + break; lirc_buffer_write_1(iep->ir->p->rbuf, iep->buf); wake_up(&iep->ir->p->rbuf->wait_poll); break; @@ -727,7 +756,8 @@ if (!urb) return; - if (!(oep = urb->context)) { + oep = urb->context; + if (!oep) { #ifdef KERNEL_2_5 urb->transfer_flags |= URB_ASYNC_UNLINK; #endif @@ -773,7 +803,8 @@ case FREE_ALL: case 5: list_del(&iep->iep_list_link); - dprintk(DRIVER_NAME "[%d]: free_in_endpt removing ep=0x%0x from list\n", ir->devnum, iep->ep->bEndpointAddress); + dprintk(DRIVER_NAME "[%d]: free_in_endpt removing ep=0x%0x " + "from list\n", ir->devnum, iep->ep->bEndpointAddress); case 4: if (iep->urb) { #ifdef KERNEL_2_5 @@ -782,9 +813,9 @@ usb_unlink_urb(iep->urb); usb_free_urb(iep->urb); iep->urb = 0; - } else { - dprintk(DRIVER_NAME "[%d]: free_in_endpt null urb!\n", ir->devnum); - } + } else + dprintk(DRIVER_NAME "[%d]: free_in_endpt null urb!\n", + ir->devnum); case 3: #ifdef KERNEL_2_5 usb_buffer_free(iep->ir->usbdev, iep->len, iep->buf, iep->dma); @@ -802,7 +833,8 @@ * Construct a new inbound endpoint for this remote, and add it to the list of * in_epts in ir. */ -static struct in_endpt *new_in_endpt(struct irctl *ir, struct usb_endpoint_descriptor *ep) +static struct in_endpt *new_in_endpt(struct irctl *ir, + struct usb_endpoint_descriptor *ep) { struct usb_device *dev = ir->usbdev; struct in_endpt *iep; @@ -813,42 +845,49 @@ pipe = usb_rcvintpipe(dev, addr); maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); -// len = (maxp > USB_BUFLEN) ? USB_BUFLEN : maxp; -// len -= (len % CODE_LENGTH); +/* len = (maxp > USB_BUFLEN) ? USB_BUFLEN : maxp; + * len -= (len % CODE_LENGTH); */ len = CODE_LENGTH; - dprintk(DRIVER_NAME "[%d]: acceptable inbound endpoint (0x%x) found (maxp=%d len=%d)\n", ir->devnum, addr, maxp, len); + dprintk(DRIVER_NAME "[%d]: acceptable inbound endpoint (0x%x) found " + "(maxp=%d len=%d)\n", ir->devnum, addr, maxp, len); mem_failure = 0; - if ( !(iep = kmalloc(sizeof(*iep), GFP_KERNEL)) ) { + iep = kmalloc(sizeof(*iep), GFP_KERNEL); + if (!iep) mem_failure = 1; - } else { + else { memset(iep, 0, sizeof(*iep)); iep->ir = ir; iep->ep = ep; iep->len = len; #ifdef KERNEL_2_5 - if ( !(iep->buf = usb_buffer_alloc(dev, len, GFP_ATOMIC, &iep->dma)) ) { - mem_failure = 2; - } else if ( !(iep->urb = usb_alloc_urb(0, GFP_KERNEL)) ) { - mem_failure = 3; - } + iep->buf = usb_buffer_alloc(dev, len, GFP_ATOMIC, &iep->dma); #else - if ( !(iep->buf = kmalloc(len, GFP_KERNEL)) ) { + iep->buf = kmalloc(len, GFP_KERNEL); +#endif + if (!iep->buf) mem_failure = 2; - } else if ( !(iep->urb = usb_alloc_urb(0)) ) { - mem_failure = 3; - } + else { +#ifdef KERNEL_2_5 + iep->urb = usb_alloc_urb(0, GFP_KERNEL); +#else + iep->urb = usb_alloc_urb(0); #endif + if (!iep->urb) + mem_failure = 3; + } } if (mem_failure) { free_in_endpt(iep, mem_failure); - printk(DRIVER_NAME "[%d]: ep=0x%x out of memory (code=%d)\n", ir->devnum, addr, mem_failure); + printk(DRIVER_NAME "[%d]: ep=0x%x out of memory (code=%d)\n", + ir->devnum, addr, mem_failure); return NULL; } list_add_tail(&iep->iep_list_link, &ir->iep_listhead); - dprintk(DRIVER_NAME "[%d]: adding ep=0x%0x to list\n", ir->devnum, iep->ep->bEndpointAddress); + dprintk(DRIVER_NAME "[%d]: adding ep=0x%0x to list\n", + ir->devnum, iep->ep->bEndpointAddress); return iep; } @@ -856,7 +895,8 @@ { struct irctl *ir; dprintk(DRIVER_NAME ": free_out_endpt(%p, %d)\n", oep, mem_failure); - if (!oep) return; + if (!oep) + return; wake_up_all(&oep->wait); @@ -877,11 +917,13 @@ usb_free_urb(oep->urb); oep->urb = 0; } else { - dprintk(DRIVER_NAME "[%d]: free_out_endpt: null urb!\n", ir->devnum); + dprintk(DRIVER_NAME "[%d]: free_out_endpt: null urb!\n", + ir->devnum); } case 3: #ifdef KERNEL_2_5 - usb_buffer_free(oep->ir->usbdev, USB_OUTLEN, oep->buf, oep->dma); + usb_buffer_free(oep->ir->usbdev, USB_OUTLEN, + oep->buf, oep->dma); #else kfree(oep->buf); #endif @@ -892,7 +934,8 @@ IRUNLOCK; } -static struct out_endpt *new_out_endpt(struct irctl *ir, struct usb_endpoint_descriptor *ep) +static struct out_endpt *new_out_endpt(struct irctl *ir, + struct usb_endpoint_descriptor *ep) { #ifdef KERNEL_2_5 struct usb_device *dev = ir->usbdev; @@ -900,34 +943,41 @@ struct out_endpt *oep; int mem_failure; - dprintk(DRIVER_NAME "[%d]: acceptable outbound endpoint (0x%x) found\n", ir->devnum, ep->bEndpointAddress); + dprintk(DRIVER_NAME "[%d]: acceptable outbound endpoint (0x%x) found\n", + ir->devnum, ep->bEndpointAddress); mem_failure = 0; - if ( !(oep = kmalloc(sizeof(*oep), GFP_KERNEL)) ) { + oep = kmalloc(sizeof(*oep), GFP_KERNEL); + if (!oep) mem_failure = 1; - } else { + else { memset(oep, 0, sizeof(*oep)); oep->ir = ir; oep->ep = ep; init_waitqueue_head(&oep->wait); #ifdef KERNEL_2_5 - if ( !(oep->buf = usb_buffer_alloc(dev, USB_OUTLEN, GFP_ATOMIC, &oep->dma)) ) { - mem_failure = 2; - } else if ( !(oep->urb = usb_alloc_urb(0, GFP_KERNEL)) ) { - mem_failure = 3; - } + oep->buf = usb_buffer_alloc(dev, USB_OUTLEN, + GFP_ATOMIC, &oep->dma); #else - if ( !(oep->buf = kmalloc(USB_OUTLEN, GFP_KERNEL)) ) { + oep->buf = kmalloc(USB_OUTLEN, GFP_KERNEL); +#endif + if (!oep->buf) mem_failure = 2; - } else if ( !(oep->urb = usb_alloc_urb(0)) ) { - mem_failure = 3; - } + else { +#ifdef KERNEL_2_5 + oep->urb = usb_alloc_urb(0, GFP_KERNEL); +#else + oep->urb = usb_alloc_urb(0); #endif + if (!oep->urb) + mem_failure = 3; + } } if (mem_failure) { free_out_endpt(oep, mem_failure); - printk(DRIVER_NAME "[%d]: ep=0x%x out of memory (code=%d)\n", ir->devnum, ep->bEndpointAddress, mem_failure); + printk(DRIVER_NAME "[%d]: ep=0x%x out of memory (code=%d)\n", + ir->devnum, ep->bEndpointAddress, mem_failure); return NULL; } return oep; @@ -939,7 +989,8 @@ struct in_endpt *in; dprintk(DRIVER_NAME ": free_irctl(%p, %d)\n", ir, mem_failure); - if (!ir) return; + if (!ir) + return; list_for_each_safe(pos, n, &ir->iep_listhead) { in = get_iep_from_link(pos); @@ -954,13 +1005,14 @@ switch (mem_failure) { case FREE_ALL: case 6: - if (!--ir->dev_refcount) { + if (!--ir->dev_refcount) { list_del(&ir->remote_list_link); - dprintk(DRIVER_NAME "[%d]: free_irctl: removing remote from list\n", - ir->devnum); + dprintk(DRIVER_NAME "[%d]: free_irctl: removing " + "remote from list\n", ir->devnum); } else { dprintk(DRIVER_NAME "[%d]: free_irctl: refcount at %d," - "aborting free_irctl\n", ir->devnum, ir->dev_refcount); + "aborting free_irctl\n", + ir->devnum, ir->dev_refcount); IRUNLOCK; return; } @@ -969,13 +1021,16 @@ case 3: if (ir->p) { switch (mem_failure) { - case 5: lirc_buffer_free(ir->p->rbuf); - case 4: kfree(ir->p->rbuf); - case 3: kfree(ir->p); + case 5: + lirc_buffer_free(ir->p->rbuf); + case 4: + kfree(ir->p->rbuf); + case 3: + kfree(ir->p); } - } else { - printk(DRIVER_NAME "[%d]: ir->p is a null pointer!\n", ir->devnum); - } + } else + printk(DRIVER_NAME "[%d]: ir->p is a null pointer!\n", + ir->devnum); case 2: IRUNLOCK; kfree(ir); @@ -1015,51 +1070,58 @@ /* allocate kernel memory */ mem_failure = 0; - if ( !(ir = kmalloc(sizeof(*ir), GFP_KERNEL)) ) { + ir = kmalloc(sizeof(*ir), GFP_KERNEL); + if (!ir) mem_failure = 1; - } else { - // at this stage we cannot use the macro [DE]CODE_LENGTH: ir is not yet setup - const int dclen = decode_length[type]; + else { + /* at this stage we cannot use the macro [DE]CODE_LENGTH: ir + * is not yet setup */ + const int dclen = decode_length[type]; memset(ir, 0, sizeof(*ir)); - /* add this infrared remote struct to remote_list, keeping track of - * the number of drivers registered. */ + /* add this infrared remote struct to remote_list, keeping track + * of the number of drivers registered. */ dprintk(DRIVER_NAME "[%d]: adding remote to list\n", devnum); list_add_tail(&ir->remote_list_link, &remote_list); - ir->dev_refcount=1; + ir->dev_refcount = 1; - if (!(plugin = kmalloc(sizeof(*plugin), GFP_KERNEL))) { + plugin = kmalloc(sizeof(*plugin), GFP_KERNEL); + if (!plugin) mem_failure = 2; - } else if (!(rbuf = kmalloc(sizeof(*rbuf), GFP_KERNEL))) { - mem_failure = 3; - } else if (lirc_buffer_init(rbuf, dclen, 1)) { - mem_failure = 4; - } else { - memset(plugin, 0, sizeof(*plugin)); - strcpy(plugin->name, DRIVER_NAME " "); - plugin->minor = -1; - plugin->code_length = dclen * 8; - plugin->features = LIRC_CAN_REC_LIRCCODE; - plugin->data = ir; - plugin->rbuf = rbuf; - plugin->set_use_inc = &set_use_inc; - plugin->set_use_dec = &set_use_dec; + else { + rbuf = kmalloc(sizeof(*rbuf), GFP_KERNEL); + if (!rbuf) + mem_failure = 3; + else if (lirc_buffer_init(rbuf, dclen, 1)) + mem_failure = 4; + else { + memset(plugin, 0, sizeof(*plugin)); + strcpy(plugin->name, DRIVER_NAME " "); + plugin->minor = -1; + plugin->code_length = dclen * 8; + plugin->features = LIRC_CAN_REC_LIRCCODE; + plugin->data = ir; + plugin->rbuf = rbuf; + plugin->set_use_inc = &set_use_inc; + plugin->set_use_dec = &set_use_dec; #ifdef LIRC_HAVE_SYSFS - plugin->dev = &dev->dev; + plugin->dev = &dev->dev; #endif - plugin->owner = THIS_MODULE; - ir->usbdev = dev; - ir->p = plugin; - ir->remote_type = type; - ir->devnum = devnum; - ir->mode = RW2_NULL_MODE; - - init_MUTEX(&ir->lock); - INIT_LIST_HEAD(&ir->iep_listhead); + plugin->owner = THIS_MODULE; + ir->usbdev = dev; + ir->p = plugin; + ir->remote_type = type; + ir->devnum = devnum; + ir->mode = RW2_NULL_MODE; + + init_MUTEX(&ir->lock); + INIT_LIST_HEAD(&ir->iep_listhead); + } } } if (mem_failure) { free_irctl(ir, mem_failure); - printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n", devnum, mem_failure); + printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n", + devnum, mem_failure); return NULL; } return ir; @@ -1071,7 +1133,8 @@ * If it is, the corresponding irctl is returned, with its dev_refcount * incremented. Otherwise, returns null. */ -static struct irctl *get_prior_reg_ir(struct usb_device *dev) { +static struct irctl *get_prior_reg_ir(struct usb_device *dev) +{ struct list_head *pos; struct irctl *ir = NULL; @@ -1079,12 +1142,14 @@ list_for_each(pos, &remote_list) { ir = get_irctl_from_link(pos); if (ir->usbdev != dev) { - dprintk(DRIVER_NAME "[%d]: device %d isn't it...", dev->devnum, ir->devnum); + dprintk(DRIVER_NAME "[%d]: device %d isn't it...", + dev->devnum, ir->devnum); ir = NULL; } else { - dprintk(DRIVER_NAME "[%d]: prior instance found.\n", dev->devnum); - ir->dev_refcount++; - break; + dprintk(DRIVER_NAME "[%d]: prior instance found.\n", + dev->devnum); + ir->dev_refcount++; + break; } } return ir; @@ -1092,13 +1157,16 @@ /* If the USB interface has an out endpoint for control (eg, the first Remote * Wonder) send the appropriate initialization packets. */ -static void send_outbound_init(struct irctl *ir) { +static void send_outbound_init(struct irctl *ir) +{ if (ir->out_init) { struct out_endpt *oep = ir->out_init; - dprintk(DRIVER_NAME "[%d]: usb_remote_probe: initializing outbound ep\n", ir->devnum); + dprintk(DRIVER_NAME "[%d]: usb_remote_probe: initializing " + "outbound ep\n", ir->devnum); usb_fill_int_urb(oep->urb, ir->usbdev, - usb_sndintpipe(ir->usbdev, oep->ep->bEndpointAddress), oep->buf, - USB_OUTLEN, usb_remote_send, oep, oep->ep->bInterval); + usb_sndintpipe(ir->usbdev, oep->ep->bEndpointAddress), + oep->buf, USB_OUTLEN, usb_remote_send, + oep, oep->ep->bInterval); send_packet(oep, 0x8004, init1); send_packet(oep, 0x8007, init2); @@ -1106,13 +1174,14 @@ } /* Log driver and usb info */ -static void log_usb_dev_info(struct usb_device *dev) { - char buf[63], name[128]=""; +static void log_usb_dev_info(struct usb_device *dev) +{ + char buf[63], name[128] = ""; if (dev->descriptor.iManufacturer - && usb_string(dev, dev->descriptor.iManufacturer, buf, 63) > 0) + && usb_string(dev, dev->descriptor.iManufacturer, buf, 63) > 0) strncpy(name, buf, 128); if (dev->descriptor.iProduct - && usb_string(dev, dev->descriptor.iProduct, buf, 63) > 0) + && usb_string(dev, dev->descriptor.iProduct, buf, 63) > 0) snprintf(name, 128, "%s %s", name, buf); printk(DRIVER_NAME "[%d]: %s on usb%d:%d\n", dev->devnum, name, dev->bus->busnum, dev->devnum); @@ -1140,26 +1209,28 @@ dprintk(DRIVER_NAME "[%d]: usb_remote_probe: dev:%p, intf:%p, id:%p)\n", dev->devnum, dev, intf, id); -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,4) - idesc = intf->cur_altsetting; -#else +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 5) idesc = &intf->altsetting[intf->act_altsetting]; +#else + idesc = intf->cur_altsetting; #endif /* Check if a usb remote has already been registered for this device */ ir = get_prior_reg_ir(dev); - if ( !ir && !(ir = new_irctl(dev)) ) { + if (!ir) { + ir = new_irctl(dev); + if (!ir) #ifdef KERNEL_2_5 - return -ENOMEM; + return -ENOMEM; #else - return NULL; + return NULL; #endif } type = ir->remote_type; - // step through the endpoints to find first in and first out endpoint - // of type interrupt transfer + /* step through the endpoints to find first in and first out endpoint + * of type interrupt transfer */ #ifdef KERNEL_2_5 for (i = 0; i < idesc->desc.bNumEndpoints; ++i) { ep = &idesc->endpoint[i].desc; @@ -1167,26 +1238,32 @@ for (i = 0; i < idesc->bNumEndpoints; ++i) { ep = &idesc->endpoint[i]; #endif - dprintk(DRIVER_NAME "[%d]: processing endpoint %d\n", dev->devnum, i); - if ( ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) - && ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) { + dprintk(DRIVER_NAME "[%d]: processing endpoint %d\n", + dev->devnum, i); + if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == + USB_DIR_IN) && + ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == + USB_ENDPOINT_XFER_INT)) { - if ((iep = new_in_endpt(ir,ep))) { + iep = new_in_endpt(ir, ep); + if (iep) usb_fill_int_urb(iep->urb, dev, - usb_rcvintpipe(dev,iep->ep->bEndpointAddress), iep->buf, - iep->len, usb_remote_recv, iep, iep->ep->bInterval); - } + usb_rcvintpipe(dev, + iep->ep->bEndpointAddress), + iep->buf, iep->len, usb_remote_recv, + iep, iep->ep->bInterval); } - if ( ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) - && ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) - && (ir->out_init == NULL)) { - - ir->out_init = new_out_endpt(ir,ep); - } + if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == + USB_DIR_OUT) && + ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == + USB_ENDPOINT_XFER_INT) && + (ir->out_init == NULL)) + ir->out_init = new_out_endpt(ir, ep); } if (list_empty(&ir->iep_listhead)) { - printk(DRIVER_NAME "[%d]: inbound endpoint not found\n", ir->devnum); + printk(DRIVER_NAME "[%d]: inbound endpoint not found\n", + ir->devnum); free_irctl(ir, FREE_ALL); #ifdef KERNEL_2_5 return -ENODEV; @@ -1195,7 +1272,8 @@ #endif } if (ir->dev_refcount == 1) { - if ((ir->p->minor = lirc_register_plugin(ir->p)) < 0) { + ir->p->minor = lirc_register_plugin(ir->p); + if (ir->p->minor < 0) { free_irctl(ir, FREE_ALL); #ifdef KERNEL_2_5 return -ENODEV; @@ -1222,7 +1300,7 @@ #ifdef KERNEL_2_5 static void usb_remote_disconnect(struct usb_interface *intf) { -// struct usb_device *dev = interface_to_usbdev(intf); +/* struct usb_device *dev = interface_to_usbdev(intf); */ struct irctl *ir = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); #else @@ -1231,7 +1309,8 @@ struct irctl *ir = ptr; #endif - dprintk(DRIVER_NAME ": disconnecting remote %d:\n", (ir? ir->devnum: -1)); + dprintk(DRIVER_NAME ": disconnecting remote %d:\n", + (ir? ir->devnum: -1)); if (!ir || !ir->p) return; @@ -1247,10 +1326,10 @@ static struct usb_driver usb_remote_driver = { LIRC_THIS_MODULE(.owner = THIS_MODULE) - .name = DRIVER_NAME, - .probe = usb_remote_probe, - .disconnect = usb_remote_disconnect, - .id_table = usb_remote_table + .name = DRIVER_NAME, + .probe = usb_remote_probe, + .disconnect = usb_remote_disconnect, + .id_table = usb_remote_table }; static int __init usb_remote_init(void) @@ -1259,15 +1338,18 @@ INIT_LIST_HEAD(&remote_list); - printk("\n" DRIVER_NAME ": " DRIVER_DESC " " DRIVER_VERSION "\n"); + printk(KERN_INFO "\n" DRIVER_NAME ": " DRIVER_DESC " " + DRIVER_VERSION "\n"); printk(DRIVER_NAME ": " DRIVER_AUTHOR "\n"); - dprintk(DRIVER_NAME ": debug mode enabled: $Id: lirc_atiusb.c,v 1.63 2007/07/22 07:37:30 lirc Exp $\n"); + dprintk(DRIVER_NAME ": debug mode enabled: " + "$Id: lirc_atiusb.c,v 1.63 2007/07/22 07:37:30 lirc Exp $\n"); request_module("lirc_dev"); repeat_jiffies = repeat*HZ/100; - if ((i = usb_register(&usb_remote_driver)) < 0) { + i = usb_register(&usb_remote_driver); + if (i) { printk(DRIVER_NAME ": usb register failed, result = %d\n", i); return -ENODEV; } @@ -1307,9 +1389,9 @@ * Enabling this will cause the built-in Remote Wonder II repeate coding to * not be squashed. The second byte of the keys output will then be: * - * 1 initial press (button down) - * 2 holding (button remains pressed) - * 0 release (button up) + * 1 initial press (button down) + * 2 holding (button remains pressed) + * 0 release (button up) * * By default, the driver emits 2 for both 1 and 2, and emits nothing for 0. * This is good for people having trouble getting their rw2 to send a good @@ -1319,18 +1401,22 @@ * at random points while you're still holding a button, then you can enable * this parameter to get finer grain repeat control out of your remote: * - * 1 Emit a single (per-channel) virtual code for all up/down events - * 2 Emit the actual rw2 output + * 1 Emit a single (per-channel) virtual code for all up/down events + * 2 Emit the actual rw2 output * * 1 is easier to write lircd configs for; 2 allows full control. */ module_param(emit_updown, int, 0644); -MODULE_PARM_DESC(emit_updown, "emit press/release codes (rw2): 0:don't (default), 1:emit 2 codes only, 2:code for each button"); +MODULE_PARM_DESC(emit_updown, "emit press/release codes (rw2): 0:don't " + "(default), 1:emit 2 codes only, 2:code for each button"); module_param(emit_modekeys, int, 0644); -MODULE_PARM_DESC(emit_modekeys, "emit keycodes for aux1-aux4, pc, and mouse (rw2): 0:don't (default), 1:emit translated codes: one for mode switch, one for same mode, 2:raw codes"); +MODULE_PARM_DESC(emit_modekeys, "emit keycodes for aux1-aux4, pc, and mouse " + "(rw2): 0:don't (default), 1:emit translated codes: one for " + "mode switch, one for same mode, 2:raw codes"); module_param(mgradient, int, 0644); -MODULE_PARM_DESC(mgradient, "rw2 mouse: 1000*gradient from E to NE (default: 500 => .5 => ~27 degrees)"); +MODULE_PARM_DESC(mgradient, "rw2 mouse: 1000*gradient from E to NE (default: " + "500 => .5 => ~27 degrees)"); EXPORT_NO_SYMBOLS; Index: drivers/lirc_bt829/lirc_bt829.c =================================================================== RCS file: /cvsroot/lirc/lirc/drivers/lirc_bt829/lirc_bt829.c,v retrieving revision 1.16 diff -u -u -r1.16 lirc_bt829.c --- drivers/lirc_bt829/lirc_bt829.c 13 Feb 2007 07:28:38 -0000 1.16 +++ drivers/lirc_bt829/lirc_bt829.c 16 Sep 2007 20:58:42 -0000 @@ -38,7 +38,7 @@ static int poll_main(void); static int atir_init_start(void); -static void write_index(unsigned char index,unsigned int value); +static void write_index(unsigned char index, unsigned int value); static unsigned int read_index(unsigned char index); static void do_i2c_start(void); @@ -48,7 +48,7 @@ static unsigned char seems_rd_byte(void); static unsigned int read_index(unsigned char al); -static void write_index(unsigned char ah,unsigned int edx); +static void write_index(unsigned char ah, unsigned int edx); static void cycle_delay(int cycle); @@ -58,11 +58,11 @@ #define DATA_PCI_OFF 0x7FFC00 #define WAIT_CYCLE 20 -static int debug = 0; -#define dprintk(fmt, args...) \ - do{ \ - if(debug) printk(KERN_DEBUG fmt, ## args); \ - }while(0) +static int debug; +#define dprintk(fmt, args...) \ + do { \ + if (debug) printk(KERN_DEBUG fmt, ## args); \ + } while (0) static int atir_minor; static unsigned long pci_addr_phys; @@ -75,20 +75,21 @@ struct pci_dev *my_dev; #ifndef KERNEL_2_5 /* unnecessary with recent kernels */ - if ( !pci_present() ) { + if (!pci_present()) printk(KERN_ERR "ATIR: no pci in this kernel\n"); - } #endif - my_dev = (struct pci_dev *)pci_find_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_264VT,NULL); - if ( my_dev ) { + my_dev = pci_get_device(PCI_VENDOR_ID_ATI, + PCI_DEVICE_ID_ATI_264VT, NULL); + if (my_dev) { printk(KERN_ERR "ATIR: Using device: %s\n", pci_name(my_dev)); pci_addr_phys = 0; - if ( my_dev->resource[0].flags & IORESOURCE_MEM ) { + if (my_dev->resource[0].flags & IORESOURCE_MEM) { pci_addr_phys = my_dev->resource[0].start; - printk(KERN_INFO "ATIR memory at 0x%08X \n",(unsigned int)pci_addr_phys); + printk(KERN_INFO "ATIR memory at 0x%08X \n", + (unsigned int)pci_addr_phys); } - if ( pci_addr_phys == 0 ) { + if (pci_addr_phys == 0) { printk(KERN_ERR "ATIR no memory resource ?\n"); return NULL; } @@ -99,29 +100,28 @@ return my_dev; } -static int atir_add_to_buf (void* data, struct lirc_buffer* buf) +static int atir_add_to_buf(void *data, struct lirc_buffer *buf) { unsigned char key; int status; status = poll_main(); key = (status >> 8) & 0xFF; - if( status & 0xFF ) - { - // printk(KERN_INFO "ATIR reading key %02X\n",*key); - lirc_buffer_write_1( buf, &key ); + if (status & 0xFF) { + dprintk("ATIR reading key %02X\n", key); + lirc_buffer_write_1(buf, &key); return 0; } return -ENODATA; } -static int atir_set_use_inc(void* data) +static int atir_set_use_inc(void *data) { MOD_INC_USE_COUNT; dprintk("ATIR driver is opened\n"); return 0; } -static void atir_set_use_dec(void* data) +static void atir_set_use_dec(void *data) { MOD_DEC_USE_COUNT; dprintk("ATIR driver is closed\n"); @@ -132,15 +132,13 @@ struct pci_dev *pdev; pdev = do_pci_probe(); - if ( pdev == NULL ) { + if (pdev == NULL) return 1; - } - if ( !atir_init_start() ) { + if (!atir_init_start()) return 1; - } - strcpy(atir_plugin.name,"ATIR"); + strcpy(atir_plugin.name, "ATIR"); atir_plugin.minor = -1; atir_plugin.code_length = 8; atir_plugin.sample_rate = 10; @@ -154,7 +152,7 @@ atir_plugin.owner = THIS_MODULE; atir_minor = lirc_register_plugin(&atir_plugin); - dprintk("ATIR driver is registered on minor %d\n",atir_minor); + dprintk("ATIR driver is registered on minor %d\n", atir_minor); return 0; } @@ -168,8 +166,8 @@ static int atir_init_start(void) { - pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF,0x400); - if ( pci_addr_lin == 0 ) { + pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400); + if (pci_addr_lin == 0) { printk(KERN_INFO "atir: pci mem must be mapped\n"); return 0; } @@ -185,7 +183,7 @@ static int poll_main() { unsigned char status_high, status_low; - + do_i2c_start(); seems_wr_byte(0xAA); @@ -237,14 +235,14 @@ { int i; unsigned char reg; - + reg = do_get_bits(); - for(i = 0;i < 8;i++) { - if ( value & 0x80 ) { + for (i = 0; i < 8; i++) { + if (value & 0x80) reg |= 0x02; - } else { + else reg &= 0xFD; - } + do_set_bits(reg); cycle_delay(1); @@ -283,7 +281,7 @@ do_set_bits(bits_1); rd_byte = 0; - for(i = 0;i < 8;i++) { + for (i = 0; i < 8; i++) { bits_1 &= 0xFE; do_set_bits(bits_1); cycle_delay(2); @@ -292,16 +290,17 @@ do_set_bits(bits_1); cycle_delay(1); - if ( (bits_2 = do_get_bits()) & 2 ) { + bits_2 = do_get_bits(); + if (bits_2 & 2) rd_byte |= 1; - } + rd_byte <<= 1; } bits_1 = 0; - if ( bits_2 == 0 ) { + if (bits_2 == 0) bits_1 |= 2; - } + do_set_bits(bits_1); cycle_delay(2); @@ -322,7 +321,7 @@ { int reg_val; reg_val = read_index(0x34); - if ( new_bits & 2 ) { + if (new_bits & 2) { reg_val &= 0xFFFFFFDF; reg_val |= 1; } else { @@ -330,16 +329,16 @@ reg_val |= 0x20; } reg_val |= 0x10; - write_index(0x34,reg_val); + write_index(0x34, reg_val); reg_val = read_index(0x31); - if ( new_bits & 1 ) { + if (new_bits & 1) { reg_val |= 0x1000000; } else { reg_val &= 0xFEFFFFFF; } reg_val |= 0x8000000; - write_index(0x31,reg_val); + write_index(0x31, reg_val); } static unsigned char do_get_bits(void) @@ -350,18 +349,18 @@ reg_val = read_index(0x34); reg_val |= 0x10; reg_val &= 0xFFFFFFDF; - write_index(0x34,reg_val); + write_index(0x34, reg_val); reg_val = read_index(0x34); bits = 0; - if ( reg_val & 8 ) { + if (reg_val & 8) { bits |= 2; } else { bits &= 0xFD; } reg_val = read_index(0x31); - if ( reg_val & 0x1000000 ) { - bits |= 1; + if (reg_val & 0x1000000) { + bits |= 1; } else { bits &= 0xFE; } @@ -372,17 +371,17 @@ { unsigned char *addr; unsigned int value; - // addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); + /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */ addr = pci_addr_lin + ((index & 0xFF) << 2); value = readl(addr); return value; } -static void write_index(unsigned char index,unsigned int reg_val) +static void write_index(unsigned char index, unsigned int reg_val) { unsigned char *addr; addr = pci_addr_lin + ((index & 0xFF) << 2); - writel(reg_val,addr); + writel(reg_val, addr); } MODULE_AUTHOR("Froenchenko Leonid"); Index: drivers/lirc_cmdir/commandir.c =================================================================== RCS file: /cvsroot/lirc/lirc/drivers/lirc_cmdir/commandir.c,v retrieving revision 1.3 diff -u -u -r1.3 commandir.c --- drivers/lirc_cmdir/commandir.c 9 Sep 2007 15:33:44 -0000 1.3 +++ drivers/lirc_cmdir/commandir.c 16 Sep 2007 20:58:48 -0000 @@ -11,7 +11,7 @@ */ #include -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18) #include #else #include @@ -36,8 +36,12 @@ #include #else #include +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18) +#include +#else #include #endif +#endif #define DRIVER_VERSION "v1.1.2" #define DRIVER_AUTHOR "Evelyn Yeung, InnovationOne" @@ -48,134 +52,141 @@ #define USB_CMDIR_MINOR_BASE 192 /* table of devices that work with this driver */ -static struct usb_device_id cmdir_table [] = +static struct usb_device_id cmdir_table [] = { { USB_DEVICE(USB_CMDIR_VENDOR_ID, USB_CMDIR_PRODUCT_ID) }, { } /* Terminating entry */ }; -MODULE_DEVICE_TABLE (usb, cmdir_table); +MODULE_DEVICE_TABLE(usb, cmdir_table); -static int cmdir_open (struct inode *inode, struct file *file); +static int cmdir_open(struct inode *inode, struct file *file); #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -static void * cmdir_probe (struct usb_device *dev,unsigned int ifnum,const struct usb_device_id *id); -static int cmdir_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg); -static void cmdir_disconnect (struct usb_device *dev, void *ptr); +static void *cmdir_probe(struct usb_device *dev, unsigned int ifnum, + const struct usb_device_id *id); +static int cmdir_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg); +static void cmdir_disconnect(struct usb_device *dev, void *ptr); #else -static int cmdir_probe(struct usb_interface *interface, const struct usb_device_id *id); +static int cmdir_probe(struct usb_interface *interface, + const struct usb_device_id *id); static void cmdir_disconnect(struct usb_interface *interface); #endif -static int cmdir_release (struct inode *inode, struct file *file); -static int cmdir_check (int device_num); -static void init_cmdir_var (int device_num); -static void reset_cmdir (int device_num); -static void update_cmdir_string (int device_num); -static void print_cmdir (int device_num); -static ssize_t cmdir_file_read (struct file *file, char *buffer, size_t count, loff_t *ppos); -ssize_t cmdir_read (unsigned char *buffer, size_t count); -static ssize_t cmdir_file_write (struct file *file, const char *buffer, size_t count, loff_t *ppos); +static int cmdir_release(struct inode *inode, struct file *file); +static int cmdir_check(int device_num); +static void init_cmdir_var(int device_num); +static void reset_cmdir(int device_num); +static void update_cmdir_string(int device_num); +static void print_cmdir(int device_num); +static ssize_t cmdir_file_read(struct file *file, char *buffer, + size_t count, loff_t *ppos); +ssize_t cmdir_read(unsigned char *buffer, size_t count); +static ssize_t cmdir_file_write(struct file *file, const char *buffer, + size_t count, loff_t *ppos); int cmdir_write(unsigned char *buffer, int count, void *callback_fct, int u); -int write_core(unsigned char *buffer, int count, void *callback_fct, int device_num); +int write_core(unsigned char *buffer, int count, + void *callback_fct, int device_num); #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -static void cmdir_write_bulk_callback (struct urb *urb); +static void cmdir_write_bulk_callback(struct urb *urb); #else static void cmdir_write_bulk_callback(struct urb *urb, struct pt_regs *regs); #endif -int set_tx_channels (unsigned int next_tx); +int set_tx_channels(unsigned int next_tx); -int add_cmdir_queue(unsigned char *buffer, int count, void *callback_vct, int usecdelay); +int add_cmdir_queue(unsigned char *buffer, int count, + void *callback_vct, int usecdelay); int cmdir_write_queue(unsigned char *buffer, int count, void *callback_vct); int send_queue(void); int wait_to_tx(int usecs); -// circular packet queue +/* circular packet queue */ unsigned char ourbuffers[QUEUELENGTH][64]; int waitusecs[QUEUELENGTH]; int ourbufferlengths[QUEUELENGTH]; -int nexttosend = 0; -int nexttofill = 0; +int nexttosend; +int nexttofill; int send_status = SEND_IDLE; -int last_tx_sec = 0; -int last_tx_usec = 0; +int last_tx_sec; +int last_tx_usec; -static int curTXFill = 0; -struct timeval tp; +static int curTXFill; +struct timeval tp; -int debug_commandir=0; +int debug_commandir; #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) /* Structure to hold all of our device specific stuff */ -struct usb_skel +struct usb_skel { - struct usb_device * udev; /* save off the usb device pointer */ - struct usb_interface * interface; /* the interface for this device */ - devfs_handle_t devfs; /* devfs device node */ - unsigned char minor; /* the starting minor number */ - unsigned char num_ports; /* the number of ports this device has */ - char num_interrupt_in; /* number of interrupt in endpoints */ - char num_bulk_in; /* number of bulk in endpoints */ - char num_bulk_out; /* number of bulk out endpoints */ - - unsigned char * bulk_in_buffer; /* the buffer to receive data */ - int bulk_in_size; /* the size of the receive buffer */ - __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ - - unsigned char * bulk_out_buffer; /* the buffer to send data */ - int bulk_out_size; /* the size of the send buffer */ - struct urb * write_urb; /* the urb used to send data */ - __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ - - struct tq_struct tqueue; /* task queue for line discipline waking up */ - int open_count; /* number of times this port has been opened */ - struct semaphore sem; /* locks this structure */ + struct usb_device *udev; /* save off the usb device pointer */ + struct usb_interface *interface; /* the interface for this device */ + devfs_handle_t devfs; /* devfs device node */ + unsigned char minor; /* the starting minor number */ + unsigned char num_ports; /* the number of ports this device has */ + char num_interrupt_in; /* number of interrupt in endpoints */ + char num_bulk_in; /* number of bulk in endpoints */ + char num_bulk_out; /* number of bulk out endpoints */ + + unsigned char *bulk_in_buffer; /* the buffer to receive data */ + int bulk_in_size; /* the size of the receive buffer */ + __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ + + unsigned char *bulk_out_buffer; /* the buffer to send data */ + int bulk_out_size; /* the size of the send buffer */ + struct urb *write_urb; /* the urb used to send data */ + __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ + + struct tq_struct tqueue; /* task queue for line discipline waking up */ + int open_count; /* number of times this port has been opened */ + struct semaphore sem; /* locks this structure */ }; -extern devfs_handle_t usb_devfs_handle; /* the global usb devfs handle */ +extern devfs_handle_t usb_devfs_handle; /* the global usb devfs handle */ /* array of pointers to our devices that are currently connected */ -static struct usb_skel *minor_table[MAX_DEVICES]; -static DECLARE_MUTEX (minor_table_mutex); /* lock to protect the minor_table structure */ - -static struct file_operations cmdir_fops = -{ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) - owner: THIS_MODULE, -#endif - read: cmdir_file_read, - write: cmdir_file_write, - ioctl: cmdir_ioctl, - open: cmdir_open, - release: cmdir_release, -}; +static struct usb_skel *minor_table[MAX_DEVICES]; +/* lock to protect the minor_table structure */ +static DECLARE_MUTEX(minor_table_mutex); + +static struct file_operations cmdir_fops = { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) \ + && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) + .owner = THIS_MODULE, +#endif + .read = cmdir_file_read, + .write = cmdir_file_write, + .ioctl = cmdir_ioctl, + .open = cmdir_open, + .release = cmdir_release, +}; /* usb specific object needed to register this driver with the usb subsystem */ -static struct usb_driver cmdir_driver = -{ - name: "commandir", - probe: cmdir_probe, - disconnect: cmdir_disconnect, - fops: &cmdir_fops, - minor: USB_CMDIR_MINOR_BASE, - id_table: cmdir_table, +static struct usb_driver cmdir_driver = { + .name = "commandir", + .probe = cmdir_probe, + .disconnect = cmdir_disconnect, + .fops = &cmdir_fops, + .minor = USB_CMDIR_MINOR_BASE, + .id_table = cmdir_table, }; -#else +#else /* kernel >= 2.6 */ /* Structure to hold all of our device specific stuff */ -struct usb_skel +struct usb_skel { - struct usb_device * udev; /* the usb device for this device */ - struct usb_interface * interface; /* the interface for this device */ - unsigned char * bulk_in_buffer; /* the buffer to receive data */ - size_t bulk_in_size; /* the size of the receive buffer */ - __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ - __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ - struct kref kref; + struct usb_device *udev; /* the usb device for this device */ + struct usb_interface *interface; /* the interface for this device */ + unsigned char *bulk_in_buffer; /* the buffer to receive data */ + size_t bulk_in_size; /* the size of the receive buffer */ + __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ + __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ + struct kref kref; }; #define to_skel_dev(d) container_of(d, struct usb_skel, kref) -static struct file_operations cmdir_fops = -{ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) +static struct file_operations cmdir_fops = { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) \ + && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) .owner = THIS_MODULE, #endif .read = cmdir_file_read, @@ -186,17 +197,17 @@ /* usb class driver info in order to get a minor number from the usb core, * and to have the device registered with devfs and the driver core */ -static struct usb_class_driver cmdir_class = -{ +static struct usb_class_driver cmdir_class = { .name = "usb/commandir%d", .fops = &cmdir_fops, - //.mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, + /* .mode = S_IFCHR | S_IRUSR | S_IWUSR | + * S_IRGRP | S_IWGRP | S_IROTH, */ .minor_base = USB_CMDIR_MINOR_BASE, }; -static struct usb_driver cmdir_driver = -{ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) +static struct usb_driver cmdir_driver = { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) \ + && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) .owner = THIS_MODULE, #endif .name = "commandir", @@ -205,41 +216,41 @@ .id_table = cmdir_table, }; -#endif +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */ -static int lcd_device=0; -static int rx_device=0; -static int def_device=0; +static int lcd_device; +static int rx_device; +static int def_device; #define DEFAULT_TRANSMITTERS 0x0F -static unsigned int transmitters=DEFAULT_TRANSMITTERS; -static unsigned int next_transmitters=DEFAULT_TRANSMITTERS; +static unsigned int transmitters = DEFAULT_TRANSMITTERS; +static unsigned int next_transmitters = DEFAULT_TRANSMITTERS; #define CMDIR_VAR_LEN 68 -static char cmdir_var[] = -"COMMANDIRx:\n TX Enabled: 1, 2, 3, 4\n RX: commandirx\n LCD: commandirx"; +static char cmdir_var[] = +"COMMANDIRx:\n TX Enabled: 1, 2, 3, 4\n RX: commandirx\n LCD: commandirx"; #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -static inline void cmdir_delete (struct usb_skel *dev) +static inline void cmdir_delete(struct usb_skel *dev) { minor_table[dev->minor] = NULL; if (dev->bulk_in_buffer != NULL) - kfree (dev->bulk_in_buffer); + kfree(dev->bulk_in_buffer); if (dev->bulk_out_buffer != NULL) - kfree (dev->bulk_out_buffer); + kfree(dev->bulk_out_buffer); if (dev->write_urb != NULL) - usb_free_urb (dev->write_urb); - kfree (dev); + usb_free_urb(dev->write_urb); + kfree(dev); } #else static void cmdir_delete(struct kref *kref) -{ +{ struct usb_skel *dev = to_skel_dev(kref); usb_put_dev(dev->udev); - kfree (dev->bulk_in_buffer); - kfree (dev); + kfree(dev->bulk_in_buffer); + kfree(dev); } #endif @@ -250,26 +261,25 @@ /* register this driver with the USB subsystem */ result = usb_register(&cmdir_driver); -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) - if (result < 0) - { - err("usb_register failed for the "__FILE__" driver. Error number %d", - result); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) + if (result < 0) { + err("usb_register failed for the "__FILE__ + " driver. Error number %d", result); return -1; } info(DRIVER_DESC " " DRIVER_VERSION); - + return 0; #else if (result) err("usb_register failed. Error number %d", result); return result; -#endif +#endif } -static int cmdir_open (struct inode *inode, struct file *file) +static int cmdir_open(struct inode *inode, struct file *file) { struct usb_skel *dev; #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0) @@ -279,50 +289,45 @@ int retval = 0; #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) - subminor = MINOR (inode->i_rdev) - USB_CMDIR_MINOR_BASE; - if ((subminor < 0) || (subminor >= MAX_DEVICES)) - { + subminor = MINOR(inode->i_rdev) - USB_CMDIR_MINOR_BASE; + if ((subminor < 0) || (subminor >= MAX_DEVICES)) return -ENODEV; - } MOD_INC_USE_COUNT; /* lock our minor table and get our local data for this minor */ - down (&minor_table_mutex); + down(&minor_table_mutex); dev = minor_table[subminor]; - if (dev == NULL) - { - up (&minor_table_mutex); + if (dev == NULL) { + up(&minor_table_mutex); MOD_DEC_USE_COUNT; return -ENODEV; } - down (&dev->sem); /* lock this device */ - up (&minor_table_mutex); /* unlock the minor table */ - ++dev->open_count; /* increment our usage count for the driver */ - file->private_data = dev; /* save our object in the file's private structure */ - up (&dev->sem); /* unlock this device */ - + down(&dev->sem); /* lock this device */ + up(&minor_table_mutex); /* unlock the minor table */ + ++dev->open_count; /* increment our usage count for the driver */ + file->private_data = dev; /* save object in file's private structure */ + up(&dev->sem); /* unlock this device */ + return retval; #else subminor = iminor(inode); interface = usb_find_interface(&cmdir_driver, subminor); - if (!interface) - { - err ("%s - error, can't find device for minor %d", + if (!interface) { + err("%s - error, can't find device for minor %d", __FUNCTION__, subminor); retval = -ENODEV; goto exit; } - + dev = usb_get_intfdata(interface); - if (!dev) - { + if (!dev) { retval = -ENODEV; goto exit; } - - kref_get(&dev->kref); /* increment our usage count for the device */ - file->private_data = dev; /* save our object in the file's private structure */ + + kref_get(&dev->kref); /* increment our usage count for the device */ + file->private_data = dev; /* save object in file's private structure */ exit: return retval; @@ -330,7 +335,8 @@ } #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -static void * cmdir_probe(struct usb_device *udev,unsigned int ifnum,const struct usb_device_id *id) +static void *cmdir_probe(struct usb_device *udev, unsigned int ifnum, + const struct usb_device_id *id) { struct usb_skel *dev = NULL; struct usb_interface *interface; @@ -340,87 +346,76 @@ int buffer_size; int i; char name[10]; - + /* See if the device offered us matches what we can accept */ if ((udev->descriptor.idVendor != USB_CMDIR_VENDOR_ID) || - (udev->descriptor.idProduct != USB_CMDIR_PRODUCT_ID)) - { + (udev->descriptor.idProduct != USB_CMDIR_PRODUCT_ID)) return NULL; - } - + /* select a "subminor" number (part of a minor number) */ - down (&minor_table_mutex); - for (minor = 0; minor < MAX_DEVICES; ++minor) - { + down(&minor_table_mutex); + for (minor = 0; minor < MAX_DEVICES; ++minor) { if (minor_table[minor] == NULL) break; } - if (minor >= MAX_DEVICES) - { - info ("Too many devices plugged in, cannot handle this device."); + if (minor >= MAX_DEVICES) { + info("Too many devices plugged in, cannot handle this device."); goto exit; } /* allocate memory for our device state and intialize it */ - dev = kmalloc (sizeof(struct usb_skel), GFP_KERNEL); - if (dev == NULL) - { - err ("Out of memory"); + dev = kmalloc(sizeof(struct usb_skel), GFP_KERNEL); + if (dev == NULL) { + err("Out of memory"); goto exit; } - memset (dev, 0x00, sizeof (*dev)); + memset(dev, 0x00, sizeof(*dev)); minor_table[minor] = dev; interface = &udev->actconfig->interface[ifnum]; - init_MUTEX (&dev->sem); + init_MUTEX(&dev->sem); dev->udev = udev; dev->interface = interface; dev->minor = minor; /* set up and check the endpoint information */ iface_desc = &interface->altsetting[0]; - for (i = 0; i < iface_desc->bNumEndpoints; ++i) - { + for (i = 0; i < iface_desc->bNumEndpoints; ++i) { endpoint = &iface_desc->endpoint[i]; if ((endpoint->bEndpointAddress & 0x80) && - ((endpoint->bmAttributes & 3) == 0x02)) - { + ((endpoint->bmAttributes & 3) == 0x02)) { /* we found a bulk in endpoint */ buffer_size = endpoint->wMaxPacketSize; dev->bulk_in_size = buffer_size; dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; - dev->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL); - if (!dev->bulk_in_buffer) - { + dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); + if (!dev->bulk_in_buffer) { err("Couldn't allocate bulk_in_buffer"); goto error; } } - + if (((endpoint->bEndpointAddress & 0x80) == 0x00) && - ((endpoint->bmAttributes & 3) == 0x02)) - { + ((endpoint->bmAttributes & 3) == 0x02)) { /* we found a bulk out endpoint */ dev->write_urb = usb_alloc_urb(0); - if (!dev->write_urb) - { + if (!dev->write_urb) { err("No free urbs available"); goto error; } buffer_size = endpoint->wMaxPacketSize; dev->bulk_out_size = buffer_size; dev->bulk_out_endpointAddr = endpoint->bEndpointAddress; - dev->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL); - if (!dev->bulk_out_buffer) - { + dev->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); + if (!dev->bulk_out_buffer) { err("Couldn't allocate bulk_out_buffer"); goto error; } - FILL_BULK_URB(dev->write_urb, udev, - usb_sndbulkpipe(udev, - endpoint->bEndpointAddress), + FILL_BULK_URB(dev->write_urb, udev, + usb_sndbulkpipe(udev, + endpoint->bEndpointAddress), dev->bulk_out_buffer, buffer_size, cmdir_write_bulk_callback, dev); } @@ -428,77 +423,74 @@ /* initialize the devfs node for this device and register it */ sprintf(name, "commandir%d", dev->minor); - - dev->devfs = devfs_register (usb_devfs_handle, name, + + dev->devfs = devfs_register(usb_devfs_handle, name, DEVFS_FL_DEFAULT, USB_MAJOR, USB_CMDIR_MINOR_BASE + dev->minor, - S_IFCHR | S_IRUSR | S_IWUSR | - S_IRGRP | S_IWGRP | S_IROTH, + S_IFCHR | S_IRUSR | S_IWUSR | + S_IRGRP | S_IWGRP | S_IROTH, &cmdir_fops, NULL); /* let the user know what node this device is now attached to */ - info ("CommandIR USB device now attached to commandir%d", dev->minor); - + info("CommandIR USB device now attached to commandir%d", dev->minor); + /* should reset just the one that was plugged in */ reset_cmdir(minor); - + goto exit; - + error: - cmdir_delete (dev); + cmdir_delete(dev); dev = NULL; exit: - up (&minor_table_mutex); + up(&minor_table_mutex); return dev; } #else -static int cmdir_probe(struct usb_interface *interface, const struct usb_device_id *id) +static int cmdir_probe(struct usb_interface *interface, + const struct usb_device_id *id) { struct usb_skel *dev = NULL; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; size_t buffer_size; - + int i; int retval = -ENOMEM; int minor; /* allocate memory for our device state and initialize it */ dev = kmalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) - { + if (dev == NULL) { err("Out of memory"); goto error; } memset(dev, 0x00, sizeof(*dev)); -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) kref_init(&dev->kref, cmdir_delete); #else kref_init(&dev->kref); -#endif +#endif dev->udev = usb_get_dev(interface_to_usbdev(interface)); dev->interface = interface; /* set up the endpoint information */ /* use only the first bulk-in and bulk-out endpoints */ iface_desc = interface->cur_altsetting; - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) - { + for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { endpoint = &iface_desc->endpoint[i].desc; if (!dev->bulk_in_endpointAddr && (endpoint->bEndpointAddress & USB_DIR_IN) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) - == USB_ENDPOINT_XFER_BULK)) - { + == USB_ENDPOINT_XFER_BULK)) { /* we found a bulk in endpoint */ buffer_size = endpoint->wMaxPacketSize; dev->bulk_in_size = buffer_size; dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); - if (!dev->bulk_in_buffer) - { + if (!dev->bulk_in_buffer) { err("Could not allocate bulk_in_buffer"); goto error; } @@ -507,14 +499,12 @@ if (!dev->bulk_out_endpointAddr && !(endpoint->bEndpointAddress & USB_DIR_IN) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) - == USB_ENDPOINT_XFER_BULK)) - { + == USB_ENDPOINT_XFER_BULK)) { /* we found a bulk out endpoint */ dev->bulk_out_endpointAddr = endpoint->bEndpointAddress; } } - if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) - { + if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) { err("Could not find both bulk-in and bulk-out endpoints"); goto error; } @@ -524,28 +514,27 @@ /* we can register the device now, as it is ready */ retval = usb_register_dev(interface, &cmdir_class); - if (retval) - { + if (retval) { /* something prevented us from registering this driver */ err("Not able to get a minor for this device."); usb_set_intfdata(interface, NULL); goto error; } - + /* check whether minor already includes base */ minor = interface->minor; - if (minor >= USB_CMDIR_MINOR_BASE) minor=minor-USB_CMDIR_MINOR_BASE; + if (minor >= USB_CMDIR_MINOR_BASE) minor = minor-USB_CMDIR_MINOR_BASE; /* let the user know what node this device is now attached to */ info("CommandIR USB device now attached to commandir%d", minor); - + reset_cmdir(minor); - + return 0; error: if (dev) -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) kref_put(&dev->kref); #else kref_put(&dev->kref, cmdir_delete); @@ -555,25 +544,25 @@ #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -static int cmdir_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) +static int cmdir_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) { struct usb_skel *dev; dev = (struct usb_skel *)file->private_data; /* lock this object */ - down (&dev->sem); + down(&dev->sem); /* verify that the device wasn't unplugged */ - if (dev->udev == NULL) - { - up (&dev->sem); + if (dev->udev == NULL) { + up(&dev->sem); return -ENODEV; } /* unlock the device */ - up (&dev->sem); - + up(&dev->sem); + /* return that we did not understand this ioctl call */ return -ENOTTY; } @@ -586,38 +575,36 @@ int minor; dev = (struct usb_skel *)ptr; - - down (&minor_table_mutex); - down (&dev->sem); - + + down(&minor_table_mutex); + down(&dev->sem); + minor = dev->minor; /* remove our devfs node */ devfs_unregister(dev->devfs); /* if the device is not opened, then we clean up right now */ - if (!dev->open_count) - { - up (&dev->sem); - cmdir_delete (dev); + if (!dev->open_count) { + up(&dev->sem); + cmdir_delete(dev); } else { dev->udev = NULL; - up (&dev->sem); + up(&dev->sem); } info("CommandIR #%d now disconnected", minor); - up (&minor_table_mutex); - + up(&minor_table_mutex); + /* check if default RX device still exists */ - if (minor == rx_device) - { + if (minor == rx_device) { /* decrement until find next valid device */ - while (rx_device > 0) - { + while (rx_device > 0) { rx_device--; - if (cmdir_check(rx_device)==0) break; + if (cmdir_check(rx_device) == 0) break; } - if (minor > 0) info("Active Receiver is on CommandIR #%d", rx_device); + if (minor > 0) + info("Active Receiver is on CommandIR #%d", rx_device); } } @@ -639,75 +626,69 @@ unlock_kernel(); /* decrement our usage count */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) kref_put(&dev->kref); #else kref_put(&dev->kref, cmdir_delete); #endif - + /* check whether minor already includes base */ - if (minor >= USB_CMDIR_MINOR_BASE) minor=minor-USB_CMDIR_MINOR_BASE; - + if (minor >= USB_CMDIR_MINOR_BASE) minor = minor-USB_CMDIR_MINOR_BASE; + info("CommandIR #%d now disconnected", minor); - + /* check if default RX device still exists */ - if (minor == rx_device) - { + if (minor == rx_device) { /* decrement until find next valid device */ - while (rx_device > 0) - { + while (rx_device > 0) { rx_device--; - if (cmdir_check(rx_device)==0) break; + if (cmdir_check(rx_device) == 0) break; } - if (minor > 0) info("Active Receiver is on CommandIR #%d", rx_device); + if (minor > 0) + info("Active Receiver is on CommandIR #%d", rx_device); } } #endif -static int cmdir_release (struct inode *inode, struct file *file) +static int cmdir_release(struct inode *inode, struct file *file) { struct usb_skel *dev; int retval = 0; dev = (struct usb_skel *)file->private_data; - if (dev == NULL) - { + if (dev == NULL) /*dbg(" - object is NULL");*/ return -ENODEV; - } #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) - + /* lock our minor table */ - down (&minor_table_mutex); + down(&minor_table_mutex); /* lock our device */ - down (&dev->sem); + down(&dev->sem); - if (dev->open_count <= 0) - { + if (dev->open_count <= 0) { /*dbg(" - device not opened");*/ retval = -ENODEV; goto exit_not_opened; } - if (dev->udev == NULL) - { + if (dev->udev == NULL) { /* the device was unplugged before the file was released */ - /*dbg (" - device unplugged before file released");*/ - up (&dev->sem); - cmdir_delete (dev); - up (&minor_table_mutex); + /*dbg(" - device unplugged before file released");*/ + up(&dev->sem); + cmdir_delete(dev); + up(&minor_table_mutex); MOD_DEC_USE_COUNT; return 0; } /* decrement our usage count for the device */ --dev->open_count; - if (dev->open_count <= 0) - { + if (dev->open_count <= 0) { /* shutdown any bulk writes that might be going on */ - usb_unlink_urb (dev->write_urb); + usb_unlink_urb(dev->write_urb); dev->open_count = 0; } @@ -715,14 +696,14 @@ MOD_DEC_USE_COUNT; exit_not_opened: - up (&dev->sem); - up (&minor_table_mutex); + up(&dev->sem); + up(&minor_table_mutex); return retval; - + #else /* decrement the count on our device */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9) kref_put(&dev->kref); #else kref_put(&dev->kref, cmdir_delete); @@ -738,327 +719,331 @@ } -static int cmdir_check (int device_num) +static int cmdir_check(int device_num) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) - if (minor_table[device_num] == NULL) - { + if (minor_table[device_num] == NULL) return -ENODEV; - } return 0; -#else +#else struct usb_interface *interface; - - interface = usb_find_interface(&cmdir_driver, USB_CMDIR_MINOR_BASE+device_num); - if (!interface) - { + + interface = usb_find_interface(&cmdir_driver, + USB_CMDIR_MINOR_BASE+device_num); + if (!interface) { /* also check without adding base, for devfs */ interface = usb_find_interface(&cmdir_driver, rx_device); - if (!interface) - { + if (!interface) return -ENODEV; - } } return 0; #endif } -static void init_cmdir_var (int device_num) +static void init_cmdir_var(int device_num) { int i; - unsigned int multiplier=1; - - for (i=0;i 0) cmdir_var[next_pos-2] = ','; - next_pos+=3; + next_pos += 3; next_comma++; } - if (transmitters & (multiplier*0x04)) - { + if (transmitters & (multiplier*0x04)) { cmdir_var[next_pos] = '3'; if (next_comma > 0) cmdir_var[next_pos-2] = ','; - next_pos+=3; + next_pos += 3; next_comma++; } - if (transmitters & (multiplier*0x08)) - { + if (transmitters & (multiplier*0x08)) { cmdir_var[next_pos] = '4'; if (next_comma > 0) cmdir_var[next_pos-2] = ','; - next_pos+=3; + next_pos += 3; next_comma++; } - return; + return; } -static void print_cmdir (int device_num) +static void print_cmdir(int device_num) { update_cmdir_string(device_num); info("%s", cmdir_var); return; } -static ssize_t cmdir_file_read (struct file *file, char *buffer, size_t count, loff_t *ppos) +static ssize_t cmdir_file_read(struct file *file, char *buffer, + size_t count, loff_t *ppos) { - int retval=0; - int minor=0; + int retval = 0; + int minor = 0; struct usb_skel *dev; dev = (struct usb_skel *)file->private_data; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) minor = dev->minor; #else minor = dev->interface->minor; - if (minor>=USB_CMDIR_MINOR_BASE) minor=minor-USB_CMDIR_MINOR_BASE; + if (minor >= USB_CMDIR_MINOR_BASE) + minor = minor - USB_CMDIR_MINOR_BASE; #endif - - if (((int)*ppos) == 0) - { + + if (((int)*ppos) == 0) { update_cmdir_string(minor); - if (copy_to_user (buffer, cmdir_var, CMDIR_VAR_LEN)) + if (copy_to_user(buffer, cmdir_var, CMDIR_VAR_LEN)) retval = -EFAULT; else retval = CMDIR_VAR_LEN; return retval; - } - else - { + } else return 0; - } } /* Read data from CommandIR */ -ssize_t cmdir_read (unsigned char *buffer, size_t count) +ssize_t cmdir_read(unsigned char *buffer, size_t count) { struct usb_skel *dev; int retval = 0; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) - if (minor_table[rx_device] == NULL) - { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) + if (minor_table[rx_device] == NULL) return -ENODEV; - } dev = minor_table[rx_device]; /* lock this object */ - down (&dev->sem); - retval = usb_bulk_msg (dev->udev, usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr), - dev->bulk_in_buffer, dev->bulk_in_size, &count, HZ*100); + down(&dev->sem); + retval = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, + dev->bulk_in_endpointAddr), + dev->bulk_in_buffer, dev->bulk_in_size, &count, HZ*100); #else struct usb_interface *interface; - interface = usb_find_interface(&cmdir_driver, USB_CMDIR_MINOR_BASE+rx_device); - if (!interface) - { + interface = usb_find_interface(&cmdir_driver, + USB_CMDIR_MINOR_BASE+rx_device); + if (!interface) { /* also check without adding base, for devfs */ interface = usb_find_interface(&cmdir_driver, rx_device); - if (!interface) - { + if (!interface) return -ENODEV; - } } dev = usb_get_intfdata(interface); - if (!dev) - { + if (!dev) return -ENODEV; - } - retval = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), - dev->bulk_in_buffer, min(dev->bulk_in_size, count), &count, HZ*10); -#endif - if (!retval) - { - if (!memcpy(buffer, dev->bulk_in_buffer, count)) - { + retval = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, + dev->bulk_in_endpointAddr), + dev->bulk_in_buffer, min(dev->bulk_in_size, count), + &count, HZ*10); +#endif + if (!retval) { + if (!memcpy(buffer, dev->bulk_in_buffer, count)) retval = -EFAULT; - } - else - { - curTXFill = buffer[2]; // current status of the TX buffer + else { + /* current status of the TX buffer */ + curTXFill = buffer[2]; retval = count; } - } + } /* suppress errors */ /* - else - { + else { err("Read from device failed, error %d",retval); } */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) /* unlock the device */ - up (&dev->sem); + up(&dev->sem); #endif - // printk("CommandIR Reporting TX buffer at %d bytes. \n", curTXFill); + /* printk(KERN_INFO "CommandIR Reporting TX buffer at %d bytes. \n", + * curTXFill); */ return retval; -} +} +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) +EXPORT_SYMBOL_NOVERS(cmdir_read); +#else +EXPORT_SYMBOL(cmdir_read); +#endif -static ssize_t cmdir_file_write (struct file *file, const char *buffer, size_t count, loff_t *ppos) +static ssize_t cmdir_file_write(struct file *file, const char *buffer, + size_t count, loff_t *ppos) { int retval; int i; - int equalsign=0; - int changeType=0; + int equalsign = 0; + int changeType = 0; unsigned char ctrl_buffer[MCU_CTRL_SIZE]; char *local_buffer; int minor; - - /* set as default - if non-specific error, won't keep calling this function */ + + /* set as default - if non-specific error, + * won't keep calling this function */ retval = count; - local_buffer = kmalloc(count, GFP_KERNEL); - + local_buffer = kmalloc(count, GFP_KERNEL); + /* verify that we actually have some data to write */ - if (count == 0) - { + if (count == 0) { err("Write request of 0 bytes"); goto exit; } - if (count > 64) - { + if (count > 64) { err("Input too long"); goto exit; } /* copy the data from userspace into our local buffer */ - if (copy_from_user(local_buffer, buffer, count)) - { + if (copy_from_user(local_buffer, buffer, count)) { retval = -EFAULT; goto exit; } - + /* parse code */ changeType = cNothing; equalsign = 0; - for (i=0; i0)&&((local_buffer[i-1]=='R')||(local_buffer[i-1]=='r'))) - { + for (i = 0; i < MCU_CTRL_SIZE; i++) + ctrl_buffer[i] = 'j'; + + for (i = 0; i < count; i++) { + switch (local_buffer[i]) { + case 'X': + case 'x': + if ((i > 0) && ((local_buffer[i - 1] == 'R') + || (local_buffer[i - 1] == 'r'))) changeType = cRX; - } break; - case 'S': case 's': - if ((i>1)&&((local_buffer[i-1]=='E')||(local_buffer[i-1]=='e'))) - { - if ((local_buffer[i-2]=='R')||(local_buffer[i-2]=='r')) - { + case 'S': + case 's': + if ((i > 1) && ((local_buffer[i - 1] == 'E') + || (local_buffer[i - 1] == 'e'))) { + if ((local_buffer[i-2] == 'R') + || (local_buffer[i-2] == 'r')) changeType = cRESET; - } } break; - case 'L': case 'l': - if ((i>0)&&((local_buffer[i-1]=='F')||(local_buffer[i-1]=='f'))) - { - changeType=cFLASH; - } + case 'L': + case 'l': + if ((i > 0) && ((local_buffer[i - 1] == 'F') + || (local_buffer[i - 1] == 'f'))) + changeType = cFLASH; break; - case 'C': case 'c': - if((i>0)&&((local_buffer[i-1]=='L')||(local_buffer[i-1]=='l'))) - { - changeType=cLCD; - } + case 'C': + case 'c': + if ((i > 0) && ((local_buffer[i - 1] == 'L') + || (local_buffer[i - 1] == 'l'))) + changeType = cLCD; break; case '=': - if (changeType != cNothing) equalsign = i; + if (changeType != cNothing) + equalsign = i; break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - if(equalsign>0) - { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + if (equalsign > 0) { minor = local_buffer[i] - ASCII0; - switch (changeType) - { + switch (changeType) { case cRESET: - ctrl_buffer[0]=RESET_HEADER; - retval=write_core(ctrl_buffer,MCU_CTRL_SIZE, - cmdir_write_bulk_callback,minor); - if (retval != MCU_CTRL_SIZE) - { - if (retval==-ENODEV) - err("Device %d unplugged",minor); + ctrl_buffer[0] = RESET_HEADER; + retval = write_core(ctrl_buffer, + MCU_CTRL_SIZE, + cmdir_write_bulk_callback, + minor); + if (retval != MCU_CTRL_SIZE) { + if (retval == -ENODEV) + err("Device %d " + "unplugged", minor); else - err("Error on write to %d",minor); + err("Error on write to " + "%d", minor); goto exit; - } - else - { - retval=count; - } + } else + retval = count; init_cmdir_var(minor); break; case cFLASH: - ctrl_buffer[0]=FLASH_HEADER; - info("Flashing indicators on device %d",minor); - retval=write_core(ctrl_buffer,MCU_CTRL_SIZE, - cmdir_write_bulk_callback,minor); - if (retval != MCU_CTRL_SIZE) - { - if (retval==-ENODEV) - err("Device %d unplugged",minor); + ctrl_buffer[0] = FLASH_HEADER; + info("Flashing indicators on device %d", + minor); + retval = write_core(ctrl_buffer, + MCU_CTRL_SIZE, + cmdir_write_bulk_callback, + minor); + if (retval != MCU_CTRL_SIZE) { + if (retval == -ENODEV) + err("Device %d " + "unplugged", minor); else - err("Error on write to %d",minor); + err("Error on write to " + "%d", minor); goto exit; - } - else - { - retval=count; - } + } else + retval = count; break; case cRX: - rx_device=minor; - info("Default receiver set to %d",minor); + rx_device = minor; + info("Default receiver set to %d", + minor); break; case cLCD: - lcd_device=minor; - info("commandir: Default LCD set to %d",minor); + lcd_device = minor; + info("commandir: Default LCD set to %d", + minor); break; default: break; @@ -1070,63 +1055,72 @@ changeType = cNothing; break; default: - if ((equalsign > 0)&&(local_buffer[i]>32)) - { + if ((equalsign > 0) && (local_buffer[i] > 32)) { err("Non-numerical argument"); goto exit; } break; } } - + if ((changeType != cNothing) && (equalsign == 0)) - err("No device specified"); - if (changeType==cNothing) err("Unknown command"); + err("No device specified"); + if (changeType == cNothing) + err("Unknown command"); exit: kfree(local_buffer); return retval; } -int cmdir_write(unsigned char *buffer, int count, void *callback_fct, int usecdelay) +int cmdir_write(unsigned char *buffer, int count, + void *callback_fct, int usecdelay) { - // Always add to queue, then send queue number - // no locks - // mbodkin, Sept 8, 2005 + /* Always add to queue, then send queue number + * no locks + * mbodkin, Sept 8, 2005 */ int ret = 0; - if(debug_commandir == 1){ + if (debug_commandir == 1) { do_gettimeofday(&tp); - printk("cmdir_write at %d\n", (int)tp.tv_usec); + printk(KERN_INFO "cmdir_write at %d\n", (int)tp.tv_usec); } ret = add_cmdir_queue(buffer, count, callback_fct, usecdelay); - if(ret == -1) { - printk("cmdir_write returning 0\n"); + if (ret == -1) { + printk(KERN_INFO "cmdir_write returning 0\n"); return 0; } return count; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) +EXPORT_SYMBOL_NOVERS(cmdir_write); +#else +EXPORT_SYMBOL(cmdir_write); +#endif -int add_cmdir_queue(unsigned char *buffer, int count, void *callback_vct, int usecdelay) +int add_cmdir_queue(unsigned char *buffer, int count, + void *callback_vct, int usecdelay) { int ret = 0; - if((nexttofill + 1) % (QUEUELENGTH -1) == nexttosend){ - - // our buffer is full - printk("Too many packets backlogged in CommandIR Queue.\n"); + if ((nexttofill + 1) % (QUEUELENGTH - 1) == nexttosend) { + + /* our buffer is full */ + printk(KERN_INFO "Too many packets backlogged " + "in CommandIR Queue.\n"); return -1; } - // go ahead and use this one: + /* go ahead and use this one: */ memcpy(ourbuffers[nexttofill], buffer, count); ourbufferlengths[nexttofill] = count; - waitusecs[nexttofill] = (usecdelay==0) ? 10000 : usecdelay; - //printk("Adding %d to queue at position %d.\n", count, nexttofill); - nexttofill = (nexttofill + 1) % (QUEUELENGTH -1); - ret = nexttofill; -// if(timer_running==0) - send_queue(); // fake it if the timer's not running - return ret; // we accepted the full packet + waitusecs[nexttofill] = (usecdelay == 0) ? 10000 : usecdelay; + /* printk(KERN_INFO "Adding %d to queue at position %d.\n", + * count, nexttofill); */ + nexttofill = (nexttofill + 1) % (QUEUELENGTH - 1); + ret = nexttofill; + /* if (timer_running == 0) */ + send_queue(); /* fake it if the timer's not running */ + return ret; /* we accepted the full packet */ } @@ -1134,174 +1128,196 @@ { int last_sent = 0; int ret = 0; - if(debug_commandir == 1){ + if (debug_commandir == 1) { do_gettimeofday(&tp); - printk("Send_queue() at %d\n", (int)tp.tv_usec); + printk(KERN_INFO "Send_queue() at %d\n", (int)tp.tv_usec); } - // initiate the send/callback routine if not already running. - if(send_status == SEND_IDLE){ - if(!(nexttofill == nexttosend)){ - // start it up: - - last_sent = nexttosend -1; - if (last_sent< 0) last_sent = QUEUELENGTH-1; - // Final check - is it TIME to send this packet yet? - // if(wait_to_tx(waitusecs[last_sent]) == 0){ - if(curTXFill < 190){ // always send if there's room, otherwise wait until room - if(debug_commandir == 1){ + /* initiate the send/callback routine if not already running. */ + if (send_status == SEND_IDLE) { + if (!(nexttofill == nexttosend)) { + /* start it up: */ + + last_sent = nexttosend - 1; + if (last_sent < 0) last_sent = QUEUELENGTH - 1; + /* Final check - is it TIME to send this packet yet? */ + /* if (wait_to_tx(waitusecs[last_sent]) == 0) { */ + /* always send if there's room, + * otherwise wait until room */ + if (curTXFill < 190) { + if (debug_commandir == 1) { do_gettimeofday(&tp); - printk("Sending packet data at %d\n", (int)tp.tv_usec); + printk(KERN_INFO "Sending packet data " + "at %d\n", (int)tp.tv_usec); } - ret = cmdir_write_queue(ourbuffers[nexttosend], ourbufferlengths[nexttosend], NULL); - if(ret <= 0){ - // send failed - the device is either unplugged or full - // nexttosend = (nexttosend + 1) % (QUEUELENGTH-1); + ret = cmdir_write_queue(ourbuffers[nexttosend], + ourbufferlengths[nexttosend], NULL); + if (ret <= 0) { + /* send failed - the device is either + * unplugged or full + * nexttosend = + * (nexttosend + 1) + * % (QUEUELENGTH - 1); */ send_status = SEND_IDLE; - return 0; //send_queue(); - } else { - nexttosend = (nexttosend + 1) % (QUEUELENGTH-1); - } + return 0; /*send_queue(); */ + } else + nexttosend = (nexttosend + 1) + % (QUEUELENGTH - 1); return 1; } else { - if(debug_commandir == 1){ + if (debug_commandir == 1) { do_gettimeofday(&tp); - printk("Not time to send yet - starting timer at %d.\n", (int)tp.tv_usec); - printk("Enabling timer.\n"); + printk(KERN_INFO "Not time to send yet " + "- starting timer at %d.\n", + (int)tp.tv_usec); + printk(KERN_INFO "Enabling timer.\n"); } - return 0; // doesn't matter anymore + return 0; /* doesn't matter anymore */ } } else { - if(debug_commandir == 1){ + if (debug_commandir == 1) { do_gettimeofday(&tp); - printk("No more data to send %d!\n", (int)tp.tv_usec); + printk(KERN_INFO "No more data to send %d!\n", + (int)tp.tv_usec); } - last_tx_sec = 0; // reset our TX counters + last_tx_sec = 0; /* reset our TX counters */ last_tx_usec = 0; - return 1; // nothing more to send! + return 1; /* nothing more to send! */ } } else { - if(debug_commandir == 1) printk("Already sending\n"); // will try again on the callback - return 1; // then the timer shouldn't be running... + if (debug_commandir == 1) + /* will try again on the callback */ + printk(KERN_INFO "Already sending\n"); + return 1; /* then the timer shouldn't be running... */ } - return 0; // should never get here... + return 0; /* should never get here... */ } -int wait_to_tx(int usecs){ - // don't return until last_time + usecs has been reached - // for non-zero last_tx's. +int wait_to_tx(int usecs) +{ + /* don't return until last_time + usecs has been reached + * for non-zero last_tx's. */ int wait_until_sec = 0, wait_until_usec = 0; int now_sec = 0, now_usec = 0; - if(debug_commandir == 1) printk("waittotx(%d)\n", usecs); - if(usecs == 0) return 0; + if (debug_commandir == 1) printk(KERN_INFO "waittotx(%d)\n", usecs); + if (usecs == 0) return 0; - if(!(last_tx_sec == 0 && last_tx_usec == 0)){ - // calculate wait time: + if (!(last_tx_sec == 0 && last_tx_usec == 0)) { + /* calculate wait time: */ wait_until_sec = last_tx_sec + (usecs / 1000000); wait_until_usec = last_tx_usec + usecs; - + do_gettimeofday(&tp); now_sec = tp.tv_sec; now_usec = tp.tv_usec; - - if(wait_until_usec > 1000000) { - // we've spilled over to the next second. + + if (wait_until_usec > 1000000) { + /* we've spilled over to the next second. */ wait_until_sec++; wait_until_usec -= 1000000; - // printk("usec rollover\n"); + /* printk(KERN_INFO "usec rollover\n"); */ } - if(debug_commandir == 1) printk("Testing for the right second, now = %d %d, wait = %d %d\n", now_sec, now_usec, wait_until_sec, wait_until_usec); - // now we are always on the same second. - if( now_sec > wait_until_sec ){ - if(debug_commandir == 1) printk("Setting last_tx_sec to %d.\n", wait_until_sec); + if (debug_commandir == 1) + printk(KERN_INFO "Testing for the right second, now = " + "%d %d, wait = %d %d\n", + now_sec, now_usec, + wait_until_sec, wait_until_usec); + /* now we are always on the same second. */ + if (now_sec > wait_until_sec) { + if (debug_commandir == 1) + printk(KERN_INFO "Setting last_tx_sec to %d.\n", + wait_until_sec); last_tx_sec = wait_until_sec; last_tx_usec = wait_until_usec; return 0; } - - if((now_sec == wait_until_sec) && (now_usec > wait_until_usec)){ - if(debug_commandir == 1) printk("Setting last_tx_sec to %d.\n", wait_until_sec); + + if ((now_sec == wait_until_sec) + && (now_usec > wait_until_usec)) { + if (debug_commandir == 1) + printk(KERN_INFO "Setting last_tx_sec to %d.\n", + wait_until_sec); last_tx_sec = wait_until_sec; last_tx_usec = wait_until_usec; return 0; } - return -1; // didn't send + return -1; /* didn't send */ } - + do_gettimeofday(&tp); last_tx_usec = tp.tv_usec; last_tx_sec = tp.tv_sec; - return 0; // if there's no last even, go ahead and send + return 0; /* if there's no last even, go ahead and send */ } int cmdir_write_queue(unsigned char *buffer, int count, void *callback_fct) { int retval = count; - static char prev_signal_num = 0; + static char prev_signal_num; unsigned char next_mask; unsigned int multiplier; int i; - + send_status = SEND_ACTIVE; - - if (count < 2) - { + + if (count < 2) { err("Not enough bytes (write request of %d bytes)", count); return count; - } - + } + /* check data; decide which device to send to */ - switch (buffer[0]) - { + switch (buffer[0]) { case TX_HEADER: case TX_HEADER_NEW: /* this is LIRC transmit data */ - if(curTXFill >= 190) { - printk("TX buffer too full to send more TX data\n"); + if (curTXFill >= 190) { + printk(KERN_INFO + "TX buffer too full to send more TX data\n"); return 0; } - if (next_transmitters != transmitters) - { + if (next_transmitters != transmitters) { if (buffer[1] != prev_signal_num) - { /* this is new signal; change transmitter mask*/ transmitters = next_transmitters; - } } - prev_signal_num=buffer[1]; - - multiplier=1; - for (i=0; i 0) - { + if (next_mask > 0) { buffer[1] = next_mask; - retval = write_core(buffer,count,callback_fct,i); - if (retval != count) - { - if (retval==-ENODEV) - err("Device %d not plugged in",i); + retval = write_core(buffer, count, + callback_fct, i); + if (retval != count) { + if (retval == -ENODEV) + err("Device %d not plugged in", + i); else - err("Write error to device %d", i); + err("Write error to device %d", + i); return retval; } } - multiplier=multiplier*0x10; + multiplier = multiplier*0x10; } return retval; break; case LCD_HEADER: - return write_core(buffer,count,callback_fct,lcd_device); - break; + return write_core(buffer, count, callback_fct, lcd_device); + break; default: - return write_core(buffer,count,callback_fct,def_device); + return write_core(buffer, count, callback_fct, def_device); break; } /* should never get here */ @@ -1309,140 +1325,125 @@ } -int write_core(unsigned char *buffer, int count, void *callback_fct, int device_num) +int write_core(unsigned char *buffer, int count, + void *callback_fct, int device_num) { struct usb_skel *dev; int retval = count; - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) ssize_t bytes_written = 0; - if (minor_table[device_num] == NULL) - { + if (minor_table[device_num] == NULL) /* device is unplugged */ return -ENODEV; - } dev = minor_table[device_num]; /* lock this object */ - down (&dev->sem); - + down(&dev->sem); + /* see if we are already in the middle of a write */ - if (dev->write_urb->status == -EINPROGRESS) - { + if (dev->write_urb->status == -EINPROGRESS) { /*suppress errors - should just try sending again*/ - /*dbg (" - already writing");*/ + /*dbg(" - already writing");*/ retval = -EINPROGRESS; goto exit; } - + /* we can only write as much as 1 urb will hold */ - bytes_written = (count > dev->bulk_out_size) ? + bytes_written = (count > dev->bulk_out_size) ? dev->bulk_out_size : count; /* copy the data into our urb */ - if (!(memcpy(dev->write_urb->transfer_buffer, buffer, bytes_written))) - { + if (!(memcpy(dev->write_urb->transfer_buffer, buffer, bytes_written))) { retval = -EFAULT; goto exit; } - + /* set up our urb */ - if (callback_fct == NULL) - { - /*FILL_BULK_URB(dev->write_urb, dev->udev, + if (callback_fct == NULL) { + /*FILL_BULK_URB(dev->write_urb, dev->udev, usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), dev->write_urb->transfer_buffer, bytes_written, cmdir_write_bulk_callback, dev); */ - usb_fill_bulk_urb(dev->write_urb, dev->udev, + usb_fill_bulk_urb(dev->write_urb, dev->udev, usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), dev->write_urb->transfer_buffer, bytes_written, cmdir_write_bulk_callback, dev); - } - else - { - FILL_BULK_URB(dev->write_urb, dev->udev, + } else { + FILL_BULK_URB(dev->write_urb, dev->udev, usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), dev->write_urb->transfer_buffer, bytes_written, callback_fct, dev); } - + /* send the data out the bulk port */ retval = usb_submit_urb(dev->write_urb); if (!(retval)) - { retval = bytes_written; - } /* suppress errors */ - /* else - { + /* else { err("Failed submitting write urb, error %d", retval); } */ exit: /* unlock the device */ - up (&dev->sem); - return retval; // this should be return error I think - + up(&dev->sem); + return retval; /* this should be return error I think */ + #else struct usb_interface *interface; struct urb *urb = NULL; char *buf = NULL; - interface = usb_find_interface(&cmdir_driver, USB_CMDIR_MINOR_BASE+device_num); - if (!interface) - { + interface = usb_find_interface(&cmdir_driver, + USB_CMDIR_MINOR_BASE + device_num); + if (!interface) { /* also check without adding base, for devfs */ interface = usb_find_interface(&cmdir_driver, device_num); - if (!interface) - { + if (!interface) return -ENODEV; - } } dev = usb_get_intfdata(interface); - if (!dev) - { + if (!dev) return -ENODEV; - } /* create a urb, and a buffer for it, and copy the data to the urb */ - urb = usb_alloc_urb(0, GFP_ATOMIC); // Now -=Atomic=- - if (!urb) - { + urb = usb_alloc_urb(0, GFP_ATOMIC); /* Now -=Atomic=- */ + if (!urb) { retval = -ENOMEM; goto error; } - buf = usb_buffer_alloc(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); - if (!buf) - { + buf = usb_buffer_alloc(dev->udev, count, + GFP_KERNEL, &urb->transfer_dma); + if (!buf) { retval = -ENOMEM; goto error; } - if (!memcpy(buf, buffer, count)) - { + if (!memcpy(buf, buffer, count)) { retval = -EFAULT; goto error; } /* initialize the urb properly */ - if (callback_fct == NULL) - { + if (callback_fct == NULL) { usb_fill_bulk_urb(urb, dev->udev, - usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), + usb_sndbulkpipe(dev->udev, + dev->bulk_out_endpointAddr), buf, count, (void *) cmdir_write_bulk_callback, dev); - } - else - { + } else { usb_fill_bulk_urb(urb, dev->udev, - usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), + usb_sndbulkpipe(dev->udev, + dev->bulk_out_endpointAddr), buf, count, callback_fct, dev); - } - urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; // double check this + } + urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; /* double check this */ /* send the data out the bulk port */ retval = usb_submit_urb(urb, GFP_KERNEL); - if (retval) - { - err("%s - failed submitting write urb, error %d", __FUNCTION__, retval); + if (retval) { + err("%s - failed submitting write urb, error %d", + __FUNCTION__, retval); goto error; } - /* release our reference to this urb, the USB core will eventually free it entirely */ + /* release our reference to this urb, the USB + * core will eventually free it entirely */ usb_free_urb(urb); return count; @@ -1454,24 +1455,23 @@ } #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -static void cmdir_write_bulk_callback (struct urb *urb) +static void cmdir_write_bulk_callback(struct urb *urb) { - if(debug_commandir == 1){ + if (debug_commandir == 1) { do_gettimeofday(&tp); - printk("cmdir_write_bulk_callback at %d\n", (int)tp.tv_usec); + printk(KERN_INFO "cmdir_write_bulk_callback at %d\n", + (int)tp.tv_usec); } - /*if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)) - { + /*if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)) return; - } else { - dbg(" - urb status: %d", urb->status); - return; - }*/ - + dbg(" - urb status: %d", urb->status); + return; + }*/ + send_status = SEND_IDLE; - // printk("cmdir_write_bulk_callback - set idle\n"); - send_queue(); // send the next packet + /* printk(KERN_INFO "cmdir_write_bulk_callback - set idle\n"); */ + send_queue(); /* send the next packet */ return; } #else @@ -1480,34 +1480,29 @@ struct usb_skel *dev; dev = (struct usb_skel *)urb->context; send_status = SEND_IDLE; - if(debug_commandir == 1) printk("callback()\n"); + if (debug_commandir == 1) printk(KERN_INFO "callback()\n"); /* free up our allocated buffer */ - usb_buffer_free(urb->dev, urb->transfer_buffer_length, + usb_buffer_free(urb->dev, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma); - send_queue(); // send the next packet + send_queue(); /* send the next packet */ } #endif -int set_tx_channels (unsigned int next_tx) +int set_tx_channels(unsigned int next_tx) { - next_transmitters=next_tx; + next_transmitters = next_tx; return 0; } - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -EXPORT_SYMBOL_NOVERS(cmdir_write); -EXPORT_SYMBOL_NOVERS(cmdir_read); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) EXPORT_SYMBOL_NOVERS(set_tx_channels); #else -EXPORT_SYMBOL(cmdir_write); -EXPORT_SYMBOL(cmdir_read); EXPORT_SYMBOL(set_tx_channels); #endif -module_init (usb_cmdir_init); -module_exit (usb_cmdir_exit); +module_init(usb_cmdir_init); +module_exit(usb_cmdir_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); Index: drivers/lirc_cmdir/commandir.h =================================================================== RCS file: /cvsroot/lirc/lirc/drivers/lirc_cmdir/commandir.h,v retrieving revision 1.1 diff -u -u -r1.1 commandir.h --- drivers/lirc_cmdir/commandir.h 2 Jul 2007 22:30:36 -0000 1.1 +++ drivers/lirc_cmdir/commandir.h 16 Sep 2007 20:58:48 -0000 @@ -33,8 +33,9 @@ #define SEND_ACTIVE 1 #define QUEUELENGTH 256 - -extern int cmdir_write (unsigned char *buffer, int count, void *callback_fct, int u); -extern ssize_t cmdir_read (unsigned char *buffer, size_t count); -extern int set_tx_channels (unsigned int next_tx); + +extern int cmdir_write(unsigned char *buffer, int count, + void *callback_fct, int u); +extern ssize_t cmdir_read(unsigned char *buffer, size_t count); +extern int set_tx_channels(unsigned int next_tx); Index: drivers/lirc_cmdir/lirc_cmdir.c =================================================================== RCS file: /cvsroot/lirc/lirc/drivers/lirc_cmdir/lirc_cmdir.c,v retrieving revision 1.7 diff -u -u -r1.7 lirc_cmdir.c --- drivers/lirc_cmdir/lirc_cmdir.c 13 Jul 2007 16:24:04 -0000 1.7 +++ drivers/lirc_cmdir/lirc_cmdir.c 16 Sep 2007 20:58:48 -0000 @@ -27,7 +27,7 @@ #ifdef HAVE_CONFIG_H # include #endif - + #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) #error "**********************************************************" @@ -50,13 +50,18 @@ #include "drivers/kcompat.h" #include "lirc_cmdir.h" +static int debug; +#define dprintk(fmt, args...) \ + do { \ + if (debug) printk(KERN_DEBUG fmt, ## args); \ + } while (0) + struct lirc_cmdir { int features; }; -struct lirc_cmdir hardware= -{ +struct lirc_cmdir hardware = { ( /* LIRC_CAN_SET_SEND_DUTY_CYCLE| */ LIRC_CAN_SET_SEND_CARRIER| @@ -75,10 +80,10 @@ static lirc_t wbuf[WBUF_LEN]; static unsigned char cmdir_char[4*WBUF_LEN]; static unsigned char write_control[MCU_CTRL_SIZE]; -static unsigned int last_mc_time = 0; -static int usb_status=ON; -static unsigned char signal_num=0; -char timerval=0; +static unsigned int last_mc_time; +static int usb_status = ON; +static unsigned char signal_num; +char timerval; unsigned int freq = 38000; /* unsigned int duty_cycle = 50; */ @@ -92,54 +97,47 @@ static inline void safe_udelay(unsigned long usecs) { - while(usecs>MAX_UDELAY_US) - { + while (usecs > MAX_UDELAY_US) { udelay(MAX_UDELAY_US); - usecs-=MAX_UDELAY_US; + usecs -= MAX_UDELAY_US; } udelay(usecs); } -static unsigned int get_time_value(unsigned int firstint, unsigned int secondint, unsigned char overflow) +static unsigned int get_time_value(unsigned int firstint, + unsigned int secondint, unsigned char overflow) { /* get difference between two timestamps from MCU */ unsigned int t_answer = 0; - - if (secondint > firstint) - { + + if (secondint > firstint) { t_answer = secondint - firstint + overflow*65536; - } - else - { - if (overflow > 0) - { - t_answer = (65536 - firstint) + secondint + (overflow - 1)*65536; - } - else - { + } else { + if (overflow > 0) + t_answer = (65536 - firstint) + secondint + + (overflow - 1) * 65536; + else t_answer = (65536 - firstint) + secondint; - } } /* clamp to long signal */ - if (t_answer > 16000000) t_answer = PULSE_MASK; - + if (t_answer > 16000000) + t_answer = PULSE_MASK; + return t_answer; } -static int set_use_inc(void* data) +static int set_use_inc(void *data) { /* Init read buffer. */ if (lirc_buffer_init(&rbuf, sizeof(lirc_t), RBUF_LEN) < 0) - { return -ENOMEM; - } - + MOD_INC_USE_COUNT; return 0; } -static void set_use_dec(void* data) +static void set_use_dec(void *data) { lirc_buffer_free(&rbuf); MOD_DEC_USE_COUNT; @@ -148,35 +146,29 @@ static void usb_error_handle(int retval) { - switch (retval) - { - case -ENODEV: - /* device has been unplugged */ - if (usb_status == ON) - { - usb_status = OFF; - printk(LIRC_DRIVER_NAME ": device is unplugged\n"); - } - break; - default: - printk(LIRC_DRIVER_NAME ": usb error = %d\n", retval); - break; + switch (retval) { + case -ENODEV: + /* device has been unplugged */ + if (usb_status == ON) { + usb_status = OFF; + printk(LIRC_DRIVER_NAME ": device is unplugged\n"); + } + break; + default: + printk(LIRC_DRIVER_NAME ": usb error = %d\n", retval); + break; } } static int write_to_usb(unsigned char *buffer, int count, int time_elapsed) { int write_return; - + write_return = cmdir_write(buffer, count, NULL, time_elapsed); - if (write_return != count) - { + if (write_return != count) { usb_error_handle(write_return); - } - else - { - if (usb_status == OFF) - { + } else { + if (usb_status == OFF) { printk(LIRC_DRIVER_NAME ": device is now plugged in\n"); usb_status = ON; } @@ -186,17 +178,22 @@ static void set_freq(void) { - /* float tempfreq=0.0; */ + /* float tempfreq = 0.0; */ int write_return; - - /* can't use floating point in 2.6 kernel! May be some loss of precision */ + + /* + * Can't use floating point in 2.6 kernel! + * May be some loss of precision + */ timerval = (1000000 / freq) / 2; - write_control[0]=FREQ_HEADER; - write_control[1]=timerval; - write_control[2]=0; + write_control[0] = FREQ_HEADER; + write_control[1] = timerval; + write_control[2] = 0; write_return = write_to_usb(write_control, MCU_CTRL_SIZE, 0); - if (write_return == MCU_CTRL_SIZE) printk(LIRC_DRIVER_NAME ": freq set to %dHz\n", freq); - else printk(LIRC_DRIVER_NAME ": freq unchanged\n"); + if (write_return == MCU_CTRL_SIZE) + printk(LIRC_DRIVER_NAME ": freq set to %dHz\n", freq); + else + printk(LIRC_DRIVER_NAME ": freq unchanged\n"); } @@ -204,72 +201,84 @@ { unsigned char tmp_char_buffer[80]; unsigned int tmp_int_buffer[20]; - unsigned int final_data_buffer[20]; + unsigned int final_data_buffer[20]; unsigned int num_data_values = 0; unsigned char num_data_bytes = 0; unsigned int orig_index = 0; int i; - - for (i=0; i<80; i++) tmp_char_buffer[i]=0; - for (i=0; i<20; i++) tmp_int_buffer[i]=0; - /* get number of data bytes that follow the control bytes (NOT including them) */ + for (i = 0; i < 80; i++) + tmp_char_buffer[i] = 0; + for (i = 0; i < 20; i++) + tmp_int_buffer[i] = 0; + + /* + * get number of data bytes that follow the control bytes + * (NOT including them) + */ num_data_bytes = orig_rxbuffer[1]; - - /* check if num_bytes is multiple of 3; if not, error */ - if (num_data_bytes%3 > 0) return -1; - if (num_data_bytes > 60) return -3; - if (num_data_bytes < 3) return -2; - - /* get number of ints to be returned; num_data_bytes does NOT include control bytes */ + + /* check if num_bytes is multiple of 3; if not, error */ + if (num_data_bytes % 3 > 0) + return -1; + if (num_data_bytes > 60) + return -3; + if (num_data_bytes < 3) + return -2; + + /* + * get number of ints to be returned; num_data_bytes does + * NOT include control bytes + */ num_data_values = num_data_bytes/3; - - for (i=0; iWBUF_LEN || count%2==0) return(-EINVAL); - if(copy_from_user(wbuf,buf,n)) return -EFAULT; + if (n % sizeof(lirc_t)) + return -EINVAL; - // the first time we have to flag that this is the start of a new signal - // otherwise COMMANDIR may receive 2 back-to-back pulses & invert the signal + count = n/sizeof(lirc_t); + if (count > WBUF_LEN || count % 2 == 0) + return -EINVAL; + if (copy_from_user(wbuf, buf, n)) + return -EFAULT; + + /* + * the first time we have to flag that this is the start of a new + * signal otherwise COMMANDIR may receive 2 back-to-back pulses & + * invert the signal + */ cmdir_char[0] = TX_HEADER_NEW; signal_num++; cmdir_char[1] = signal_num; cmdir_cnt = 2; - for(i=0;i> 3; - - //if (mod_signal_length%2 == 1) mod_signal_length++; //want even number - /* if (i%2==0) mod_signal_length-=5; - else mod_signal_length+=5; - */ - // account for minor rounding errors - calculate length from this: + /* + * account for minor rounding errors - + * calculate length from this: + */ time_elapse += mod_signal_length * timerval; - hibyte = mod_signal_length/256; - lobyte = mod_signal_length%256; + hibyte = mod_signal_length / 256; + lobyte = mod_signal_length % 256; cmdir_char[cmdir_cnt+1] = lobyte; cmdir_char[cmdir_cnt] = hibyte; - // (unsigned short)(cmdir_char[cmdir_cnt]) = mod_signal_length; cmdir_cnt += 2; - + /* write data to usb if full packet is collected */ - if (cmdir_cnt%MAX_PACKET == 0) - { + if (cmdir_cnt % MAX_PACKET == 0) { write_to_usb(cmdir_char, MAX_PACKET, time_elapse); - + total_time_elapsed += time_elapse; - - num_bytes_already_sent+= MAX_PACKET; + + num_bytes_already_sent += MAX_PACKET; time_elapse = 0; - - if ((i+1) 0) - { - // time_elapse - total_time_elapsed += time_elapse; //time_elapse; + if (cmdir_cnt > 0) { + total_time_elapsed += time_elapse; write_to_usb(cmdir_char, cmdir_cnt, time_elapse); } - // --------------------------------------------------------------------------- - // we need to _manually delay ourselves_ to remain backwards compatible with - // LIRC and prevent our queue buffer from overflowing. Queuing in this driver - // is about instant, and send_start for example will fill it up quickly and - // prevent send_stop from taking immediate effect. - // --------------------------------------------------------------------------- - // printk("Total elapsed time is: %d. \n", total_time_elapsed); + /* XXX ERS remove all this? */ + /* + * we need to _manually delay ourselves_ to remain backwards + * compatible with LIRC and prevent our queue buffer from overflowing. + * Queuing in this driver is about instant, and send_start for example + * will fill it up quickly and prevent send_stop from taking immediate + * effect. + */ + dprintk("Total elapsed time is: %d. \n", total_time_elapsed); do_gettimeofday(&end_time); - // udelay for the difference between endtime and start+total_time_elapsed - if(start_time.tv_usec < end_time.tv_usec){ + /* + * udelay for the difference between endtime and + * start + total_time_elapsed + */ + if (start_time.tv_usec < end_time.tv_usec) real_time_elapsed = (end_time.tv_usec - start_time.tv_usec); - } else { - real_time_elapsed = ((end_time.tv_usec + 1000000) - start_time.tv_usec); - } - // printk("Real time elapsed was %u.\n", real_time_elapsed); - if(real_time_elapsed < (total_time_elapsed-1000)){ + else + real_time_elapsed = ((end_time.tv_usec + 1000000) - + start_time.tv_usec); + dprintk("Real time elapsed was %u.\n", real_time_elapsed); + if (real_time_elapsed < (total_time_elapsed - 1000)) wait_this = total_time_elapsed - real_time_elapsed - 1000; - } - // safe_udelay(wait_this); // enable this for backwards compatibility - + +#if 0 /* enable this for backwards compatibility */ + safe_udelay(wait_this); +#endif + return(n); } -static int lirc_ioctl(struct inode *node,struct file *filep,unsigned int cmd, +static int lirc_ioctl(struct inode *node, struct file *filep, unsigned int cmd, unsigned long arg) { - int result; + int result; unsigned long value; unsigned int ivalue; - unsigned int multiplier=1; - unsigned int mask=0; + unsigned int multiplier = 1; + unsigned int mask = 0; int i; - switch(cmd) - { + + switch (cmd) { case LIRC_SET_TRANSMITTER_MASK: if (!(hardware.features&LIRC_CAN_SET_TRANSMITTER_MASK)) - { - return(-ENOIOCTLCMD); - } - result=get_user(ivalue,(unsigned int *) arg); - if(result) return(result); - for(i=0;i= mask) return (MAX_CHANNELS); + if (ivalue >= mask) + return MAX_CHANNELS; set_tx_channels(ivalue); - return (0); + return 0; break; - + case LIRC_GET_SEND_MODE: - if(!(hardware.features&LIRC_CAN_SEND_MASK)) - { - return(-ENOIOCTLCMD); - } - - result=put_user(LIRC_SEND2MODE - (hardware.features&LIRC_CAN_SEND_MASK), + if (!(hardware.features & LIRC_CAN_SEND_MASK)) + return -ENOIOCTLCMD; + + result = put_user(LIRC_SEND2MODE + (hardware.features & LIRC_CAN_SEND_MASK), (unsigned long *) arg); - if(result) return(result); + if (result) + return result; break; - + case LIRC_SET_SEND_MODE: - if(!(hardware.features&LIRC_CAN_SEND_MASK)) - { - return(-ENOIOCTLCMD); - } - - result=get_user(value,(unsigned long *) arg); - if(result) return(result); + if (!(hardware.features&LIRC_CAN_SEND_MASK)) + return -ENOIOCTLCMD; + + result = get_user(value, (unsigned long *)arg); + if (result) + return result; break; - + case LIRC_GET_LENGTH: - return(-ENOSYS); + return -ENOSYS; break; - + case LIRC_SET_SEND_DUTY_CYCLE: -# ifdef DEBUG - printk(KERN_WARNING LIRC_DRIVER_NAME ": SET_SEND_DUTY_CYCLE\n"); -# endif - - if(!(hardware.features&LIRC_CAN_SET_SEND_DUTY_CYCLE)) - { - return(-ENOIOCTLCMD); - } - - result=get_user(ivalue,(unsigned int *) arg); - if(result) return(result); - if(ivalue<=0 || ivalue>100) return(-EINVAL); - + dprintk(KERN_WARNING LIRC_DRIVER_NAME + ": SET_SEND_DUTY_CYCLE\n"); + + if (!(hardware.features&LIRC_CAN_SET_SEND_DUTY_CYCLE)) + return -ENOIOCTLCMD; + + result = get_user(ivalue, (unsigned int *)arg); + if (result) + return result; + if (ivalue <= 0 || ivalue > 100) + return -EINVAL; + /* TODO: */ - /* printk(LIRC_DRIVER_NAME ": set_send_duty_cycle not yet supported\n"); */ - + dprintk(LIRC_DRIVER_NAME + ": set_send_duty_cycle not yet supported\n"); + return 0; break; - + case LIRC_SET_SEND_CARRIER: -# ifdef DEBUG - printk(KERN_WARNING LIRC_DRIVER_NAME ": SET_SEND_CARRIER\n"); -# endif - - if(!(hardware.features&LIRC_CAN_SET_SEND_CARRIER)) - { - return(-ENOIOCTLCMD); - } - - result=get_user(ivalue,(unsigned int *) arg); - if(result) return(result); - if(ivalue>500000 || ivalue<24000) return(-EINVAL); - if (ivalue != freq) - { - freq=ivalue; + dprintk(KERN_WARNING LIRC_DRIVER_NAME ": SET_SEND_CARRIER\n"); + + if (!(hardware.features & LIRC_CAN_SET_SEND_CARRIER)) + return -ENOIOCTLCMD; + + result = get_user(ivalue, (unsigned int *)arg); + if (result) + return result; + if (ivalue > 500000 || ivalue < 24000) + return -EINVAL; + if (ivalue != freq) { + freq = ivalue; set_freq(); } return 0; break; - + default: - return(-ENOIOCTLCMD); + return -ENOIOCTLCMD; } - return(0); + return 0; } -static struct file_operations lirc_fops = -{ - write: lirc_write, +static struct file_operations lirc_fops = { + .write = lirc_write, }; static struct lirc_plugin plugin = { - name: LIRC_DRIVER_NAME, - minor: -1, - code_length: 1, - sample_rate: 20, - data: NULL, - add_to_buf: add_to_buf, - get_queue: NULL, - rbuf: &rbuf, - set_use_inc: set_use_inc, - set_use_dec: set_use_dec, - ioctl: lirc_ioctl, - fops: &lirc_fops, - dev: NULL, - owner: THIS_MODULE, + .name = LIRC_DRIVER_NAME, + .minor = -1, + .code_length = 1, + .sample_rate = 20, + .data = NULL, + .add_to_buf = add_to_buf, + .get_queue = NULL, + .rbuf = &rbuf, + .set_use_inc = set_use_inc, + .set_use_dec = set_use_dec, + .ioctl = lirc_ioctl, + .fops = &lirc_fops, + .dev = NULL, + .owner = THIS_MODULE, }; #ifdef MODULE MODULE_AUTHOR("Evelyn Yeung, Matt Bodkin"); -MODULE_DESCRIPTION("InnovationOne driver for CommandIR USB infrared transceiver"); +MODULE_DESCRIPTION("InnovationOne driver for " + "CommandIR USB infrared transceiver"); #ifdef MODULE_LICENSE MODULE_LICENSE("GPL"); #endif +module_param(debug, bool, 0644); +MODULE_PARM_DESC(debug, "Enable debugging messages"); + #ifndef KERNEL_2_5 EXPORT_NO_SYMBOLS; #endif @@ -589,9 +590,9 @@ int init_module(void) { plugin.features = hardware.features; - if ((plugin.minor = lirc_register_plugin(&plugin)) < 0) - { - printk(KERN_ERR LIRC_DRIVER_NAME + plugin.minor = lirc_register_plugin(&plugin); + if (plugin.