aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/irda
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/irda')
-rw-r--r--drivers/net/irda/Kconfig15
-rw-r--r--drivers/net/irda/Makefile1
-rw-r--r--drivers/net/irda/ali-ircc.c106
-rw-r--r--drivers/net/irda/irda-usb.c327
-rw-r--r--drivers/net/irda/irda-usb.h10
-rw-r--r--drivers/net/irda/mcs7780.c1009
-rw-r--r--drivers/net/irda/mcs7780.h167
-rw-r--r--drivers/net/irda/stir4200.c38
-rw-r--r--drivers/net/irda/vlsi_ir.c2
9 files changed, 1403 insertions, 272 deletions
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index cff8598aa80..d2ce4896abf 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -417,5 +417,20 @@ config PXA_FICP
417 available capabilities may vary from one PXA2xx target to 417 available capabilities may vary from one PXA2xx target to
418 another. 418 another.
419 419
420config MCS_FIR
421 tristate "MosChip MCS7780 IrDA-USB dongle"
422 depends on IRDA && USB && EXPERIMENTAL
423 help
424 Say Y or M here if you want to build support for the MosChip
425 MCS7780 IrDA-USB bridge device driver.
426
427 USB bridge based on the MosChip MCS7780 don't conform to the
428 IrDA-USB device class specification, and therefore need their
429 own specific driver. Those dongles support SIR and FIR (4Mbps)
430 speeds.
431
432 To compile it as a module, choose M here: the module will be called
433 mcs7780.
434
420endmenu 435endmenu
421 436
diff --git a/drivers/net/irda/Makefile b/drivers/net/irda/Makefile
index c1ce2398efe..5be09f1b9ee 100644
--- a/drivers/net/irda/Makefile
+++ b/drivers/net/irda/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_ALI_FIR) += ali-ircc.o
19obj-$(CONFIG_VLSI_FIR) += vlsi_ir.o 19obj-$(CONFIG_VLSI_FIR) += vlsi_ir.o
20obj-$(CONFIG_VIA_FIR) += via-ircc.o 20obj-$(CONFIG_VIA_FIR) += via-ircc.o
21obj-$(CONFIG_PXA_FICP) += pxaficp_ir.o 21obj-$(CONFIG_PXA_FICP) += pxaficp_ir.o
22obj-$(CONFIG_MCS_FIR) += mcs7780.o
22# Old dongle drivers for old SIR drivers 23# Old dongle drivers for old SIR drivers
23obj-$(CONFIG_ESI_DONGLE_OLD) += esi.o 24obj-$(CONFIG_ESI_DONGLE_OLD) += esi.o
24obj-$(CONFIG_TEKRAM_DONGLE_OLD) += tekram.o 25obj-$(CONFIG_TEKRAM_DONGLE_OLD) += tekram.o
diff --git a/drivers/net/irda/ali-ircc.c b/drivers/net/irda/ali-ircc.c
index 2e7882eb7d6..bf1fca5a3fa 100644
--- a/drivers/net/irda/ali-ircc.c
+++ b/drivers/net/irda/ali-ircc.c
@@ -34,14 +34,12 @@
34#include <linux/rtnetlink.h> 34#include <linux/rtnetlink.h>
35#include <linux/serial_reg.h> 35#include <linux/serial_reg.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/platform_device.h>
37 38
38#include <asm/io.h> 39#include <asm/io.h>
39#include <asm/dma.h> 40#include <asm/dma.h>
40#include <asm/byteorder.h> 41#include <asm/byteorder.h>
41 42
42#include <linux/pm.h>
43#include <linux/pm_legacy.h>
44
45#include <net/irda/wrapper.h> 43#include <net/irda/wrapper.h>
46#include <net/irda/irda.h> 44#include <net/irda/irda.h>
47#include <net/irda/irda_device.h> 45#include <net/irda/irda_device.h>
@@ -51,7 +49,19 @@
51#define CHIP_IO_EXTENT 8 49#define CHIP_IO_EXTENT 8
52#define BROKEN_DONGLE_ID 50#define BROKEN_DONGLE_ID
53 51
54static char *driver_name = "ali-ircc"; 52#define ALI_IRCC_DRIVER_NAME "ali-ircc"
53
54/* Power Management */
55static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state);
56static int ali_ircc_resume(struct platform_device *dev);
57
58static struct platform_driver ali_ircc_driver = {
59 .suspend = ali_ircc_suspend,
60 .resume = ali_ircc_resume,
61 .driver = {
62 .name = ALI_IRCC_DRIVER_NAME,
63 },
64};
55 65
56/* Module parameters */ 66/* Module parameters */
57static int qos_mtt_bits = 0x07; /* 1 ms or more */ 67static int qos_mtt_bits = 0x07; /* 1 ms or more */
@@ -97,10 +107,7 @@ static int ali_ircc_is_receiving(struct ali_ircc_cb *self);
97static int ali_ircc_net_open(struct net_device *dev); 107static int ali_ircc_net_open(struct net_device *dev);
98static int ali_ircc_net_close(struct net_device *dev); 108static int ali_ircc_net_close(struct net_device *dev);
99static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 109static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
100static int ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
101static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud); 110static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud);
102static void ali_ircc_suspend(struct ali_ircc_cb *self);
103static void ali_ircc_wakeup(struct ali_ircc_cb *self);
104static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev); 111static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev);
105 112
106/* SIR function */ 113/* SIR function */
@@ -145,6 +152,14 @@ static int __init ali_ircc_init(void)
145 int i = 0; 152 int i = 0;
146 153
147 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 154 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
155
156 ret = platform_driver_register(&ali_ircc_driver);
157 if (ret) {
158 IRDA_ERROR("%s, Can't register driver!\n",
159 ALI_IRCC_DRIVER_NAME);
160 return ret;
161 }
162
148 163
149 /* Probe for all the ALi chipsets we know about */ 164 /* Probe for all the ALi chipsets we know about */
150 for (chip= chips; chip->name; chip++, i++) 165 for (chip= chips; chip->name; chip++, i++)
@@ -214,6 +229,10 @@ static int __init ali_ircc_init(void)
214 } 229 }
215 230
216 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__); 231 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
232
233 if (ret)
234 platform_driver_unregister(&ali_ircc_driver);
235
217 return ret; 236 return ret;
218} 237}
219 238
@@ -228,14 +247,14 @@ static void __exit ali_ircc_cleanup(void)
228 int i; 247 int i;
229 248
230 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 249 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
231
232 pm_unregister_all(ali_ircc_pmproc);
233 250
234 for (i=0; i < 4; i++) { 251 for (i=0; i < 4; i++) {
235 if (dev_self[i]) 252 if (dev_self[i])
236 ali_ircc_close(dev_self[i]); 253 ali_ircc_close(dev_self[i]);
237 } 254 }
238 255
256 platform_driver_unregister(&ali_ircc_driver);
257
239 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__); 258 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
240} 259}
241 260
@@ -249,7 +268,6 @@ static int ali_ircc_open(int i, chipio_t *info)
249{ 268{
250 struct net_device *dev; 269 struct net_device *dev;
251 struct ali_ircc_cb *self; 270 struct ali_ircc_cb *self;
252 struct pm_dev *pmdev;
253 int dongle_id; 271 int dongle_id;
254 int err; 272 int err;
255 273
@@ -284,7 +302,8 @@ static int ali_ircc_open(int i, chipio_t *info)
284 self->io.fifo_size = 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */ 302 self->io.fifo_size = 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
285 303
286 /* Reserve the ioports that we need */ 304 /* Reserve the ioports that we need */
287 if (!request_region(self->io.fir_base, self->io.fir_ext, driver_name)) { 305 if (!request_region(self->io.fir_base, self->io.fir_ext,
306 ALI_IRCC_DRIVER_NAME)) {
288 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__, 307 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__,
289 self->io.fir_base); 308 self->io.fir_base);
290 err = -ENODEV; 309 err = -ENODEV;
@@ -354,13 +373,10 @@ static int ali_ircc_open(int i, chipio_t *info)
354 373
355 /* Check dongle id */ 374 /* Check dongle id */
356 dongle_id = ali_ircc_read_dongle_id(i, info); 375 dongle_id = ali_ircc_read_dongle_id(i, info);
357 IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__, driver_name, dongle_types[dongle_id]); 376 IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__,
377 ALI_IRCC_DRIVER_NAME, dongle_types[dongle_id]);
358 378
359 self->io.dongle_id = dongle_id; 379 self->io.dongle_id = dongle_id;
360
361 pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, ali_ircc_pmproc);
362 if (pmdev)
363 pmdev->data = self;
364 380
365 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__); 381 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
366 382
@@ -548,12 +564,11 @@ static int ali_ircc_setup(chipio_t *info)
548 /* Should be 0x00 in the M1535/M1535D */ 564 /* Should be 0x00 in the M1535/M1535D */
549 if(version != 0x00) 565 if(version != 0x00)
550 { 566 {
551 IRDA_ERROR("%s, Wrong chip version %02x\n", driver_name, version); 567 IRDA_ERROR("%s, Wrong chip version %02x\n",
568 ALI_IRCC_DRIVER_NAME, version);
552 return -1; 569 return -1;
553 } 570 }
554 571
555 // IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, info->cfg_base);
556
557 /* Set FIR FIFO Threshold Register */ 572 /* Set FIR FIFO Threshold Register */
558 switch_bank(iobase, BANK1); 573 switch_bank(iobase, BANK1);
559 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR); 574 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
@@ -583,7 +598,8 @@ static int ali_ircc_setup(chipio_t *info)
583 /* Switch to SIR space */ 598 /* Switch to SIR space */
584 FIR2SIR(iobase); 599 FIR2SIR(iobase);
585 600
586 IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n", driver_name); 601 IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n",
602 ALI_IRCC_DRIVER_NAME);
587 603
588 /* Enable receive interrupts */ 604 /* Enable receive interrupts */
589 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM 605 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
@@ -647,7 +663,8 @@ static irqreturn_t ali_ircc_interrupt(int irq, void *dev_id,
647 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 663 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
648 664
649 if (!dev) { 665 if (!dev) {
650 IRDA_WARNING("%s: irq %d for unknown device.\n", driver_name, irq); 666 IRDA_WARNING("%s: irq %d for unknown device.\n",
667 ALI_IRCC_DRIVER_NAME, irq);
651 return IRQ_NONE; 668 return IRQ_NONE;
652 } 669 }
653 670
@@ -1328,7 +1345,8 @@ static int ali_ircc_net_open(struct net_device *dev)
1328 /* Request IRQ and install Interrupt Handler */ 1345 /* Request IRQ and install Interrupt Handler */
1329 if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev)) 1346 if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev))
1330 { 1347 {
1331 IRDA_WARNING("%s, unable to allocate irq=%d\n", driver_name, 1348 IRDA_WARNING("%s, unable to allocate irq=%d\n",
1349 ALI_IRCC_DRIVER_NAME,
1332 self->io.irq); 1350 self->io.irq);
1333 return -EAGAIN; 1351 return -EAGAIN;
1334 } 1352 }
@@ -1338,7 +1356,8 @@ static int ali_ircc_net_open(struct net_device *dev)
1338 * failure. 1356 * failure.
1339 */ 1357 */
1340 if (request_dma(self->io.dma, dev->name)) { 1358 if (request_dma(self->io.dma, dev->name)) {
1341 IRDA_WARNING("%s, unable to allocate dma=%d\n", driver_name, 1359 IRDA_WARNING("%s, unable to allocate dma=%d\n",
1360 ALI_IRCC_DRIVER_NAME,
1342 self->io.dma); 1361 self->io.dma);
1343 free_irq(self->io.irq, self); 1362 free_irq(self->io.irq, self);
1344 return -EAGAIN; 1363 return -EAGAIN;
@@ -2108,61 +2127,38 @@ static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev)
2108 return &self->stats; 2127 return &self->stats;
2109} 2128}
2110 2129
2111static void ali_ircc_suspend(struct ali_ircc_cb *self) 2130static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state)
2112{ 2131{
2113 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ ); 2132 struct ali_ircc_cb *self = platform_get_drvdata(dev);
2114 2133
2115 IRDA_MESSAGE("%s, Suspending\n", driver_name); 2134 IRDA_MESSAGE("%s, Suspending\n", ALI_IRCC_DRIVER_NAME);
2116 2135
2117 if (self->io.suspended) 2136 if (self->io.suspended)
2118 return; 2137 return 0;
2119 2138
2120 ali_ircc_net_close(self->netdev); 2139 ali_ircc_net_close(self->netdev);
2121 2140
2122 self->io.suspended = 1; 2141 self->io.suspended = 1;
2123 2142
2124 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ ); 2143 return 0;
2125} 2144}
2126 2145
2127static void ali_ircc_wakeup(struct ali_ircc_cb *self) 2146static int ali_ircc_resume(struct platform_device *dev)
2128{ 2147{
2129 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ ); 2148 struct ali_ircc_cb *self = platform_get_drvdata(dev);
2130 2149
2131 if (!self->io.suspended) 2150 if (!self->io.suspended)
2132 return; 2151 return 0;
2133 2152
2134 ali_ircc_net_open(self->netdev); 2153 ali_ircc_net_open(self->netdev);
2135 2154
2136 IRDA_MESSAGE("%s, Waking up\n", driver_name); 2155 IRDA_MESSAGE("%s, Waking up\n", ALI_IRCC_DRIVER_NAME);
2137 2156
2138 self->io.suspended = 0; 2157 self->io.suspended = 0;
2139
2140 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2141}
2142 2158
2143static int ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data)
2144{
2145 struct ali_ircc_cb *self = (struct ali_ircc_cb*) dev->data;
2146
2147 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2148
2149 if (self) {
2150 switch (rqst) {
2151 case PM_SUSPEND:
2152 ali_ircc_suspend(self);
2153 break;
2154 case PM_RESUME:
2155 ali_ircc_wakeup(self);
2156 break;
2157 }
2158 }
2159
2160 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2161
2162 return 0; 2159 return 0;
2163} 2160}
2164 2161
2165
2166/* ALi Chip Function */ 2162/* ALi Chip Function */
2167 2163
2168static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable) 2164static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable)
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index cd87593e4e8..844fa74ac9e 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -83,9 +83,9 @@ static struct usb_device_id dongles[] = {
83 /* Extended Systems, Inc., XTNDAccess IrDA USB (ESI-9685) */ 83 /* Extended Systems, Inc., XTNDAccess IrDA USB (ESI-9685) */
84 { USB_DEVICE(0x8e9, 0x100), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW }, 84 { USB_DEVICE(0x8e9, 0x100), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
85 /* SigmaTel STIR4210/4220/4116 USB IrDA (VFIR) Bridge */ 85 /* SigmaTel STIR4210/4220/4116 USB IrDA (VFIR) Bridge */
86 { USB_DEVICE(0x66f, 0x4210), .driver_info = IUC_STIR_4210 | IUC_SPEED_BUG }, 86 { USB_DEVICE(0x66f, 0x4210), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
87 { USB_DEVICE(0x66f, 0x4220), .driver_info = IUC_STIR_4210 | IUC_SPEED_BUG }, 87 { USB_DEVICE(0x66f, 0x4220), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
88 { USB_DEVICE(0x66f, 0x4116), .driver_info = IUC_STIR_4210 | IUC_SPEED_BUG }, 88 { USB_DEVICE(0x66f, 0x4116), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
89 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS | 89 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
90 USB_DEVICE_ID_MATCH_INT_SUBCLASS, 90 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
91 .bInterfaceClass = USB_CLASS_APP_SPEC, 91 .bInterfaceClass = USB_CLASS_APP_SPEC,
@@ -154,7 +154,7 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
154 * and if either speed or xbofs (or both) needs 154 * and if either speed or xbofs (or both) needs
155 * to be changed. 155 * to be changed.
156 */ 156 */
157 if (self->capability & IUC_STIR_4210 && 157 if (self->capability & IUC_STIR421X &&
158 ((self->new_speed != -1) || (self->new_xbofs != -1))) { 158 ((self->new_speed != -1) || (self->new_xbofs != -1))) {
159 159
160 /* With STIR421x, speed and xBOFs must be set at the same 160 /* With STIR421x, speed and xBOFs must be set at the same
@@ -318,7 +318,7 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
318 /* Set the new speed and xbofs in this fake frame */ 318 /* Set the new speed and xbofs in this fake frame */
319 irda_usb_build_header(self, frame, 1); 319 irda_usb_build_header(self, frame, 1);
320 320
321 if ( self->capability & IUC_STIR_4210 ) { 321 if (self->capability & IUC_STIR421X) {
322 if (frame[0] == 0) return ; // do nothing if no change 322 if (frame[0] == 0) return ; // do nothing if no change
323 frame[1] = 0; // other parameters don't change here 323 frame[1] = 0; // other parameters don't change here
324 frame[2] = 0; 324 frame[2] = 0;
@@ -455,7 +455,7 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
455 455
456 /* Change setting for next frame */ 456 /* Change setting for next frame */
457 457
458 if ( self->capability & IUC_STIR_4210 ) { 458 if (self->capability & IUC_STIR421X) {
459 __u8 turnaround_time; 459 __u8 turnaround_time;
460 __u8* frame; 460 __u8* frame;
461 turnaround_time = get_turnaround_time( skb ); 461 turnaround_time = get_turnaround_time( skb );
@@ -897,10 +897,13 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
897 docopy = (urb->actual_length < IRDA_RX_COPY_THRESHOLD); 897 docopy = (urb->actual_length < IRDA_RX_COPY_THRESHOLD);
898 898
899 /* Allocate a new skb */ 899 /* Allocate a new skb */
900 if ( self->capability & IUC_STIR_4210 ) 900 if (self->capability & IUC_STIR421X)
901 newskb = dev_alloc_skb(docopy ? urb->actual_length : IRDA_SKB_MAX_MTU + USB_IRDA_SIGMATEL_HEADER); 901 newskb = dev_alloc_skb(docopy ? urb->actual_length :
902 IRDA_SKB_MAX_MTU +
903 USB_IRDA_STIR421X_HEADER);
902 else 904 else
903 newskb = dev_alloc_skb(docopy ? urb->actual_length : IRDA_SKB_MAX_MTU); 905 newskb = dev_alloc_skb(docopy ? urb->actual_length :
906 IRDA_SKB_MAX_MTU);
904 907
905 if (!newskb) { 908 if (!newskb) {
906 self->stats.rx_dropped++; 909 self->stats.rx_dropped++;
@@ -1022,188 +1025,140 @@ static int irda_usb_is_receiving(struct irda_usb_cb *self)
1022 return 0; /* For now */ 1025 return 0; /* For now */
1023} 1026}
1024 1027
1025 1028#define STIR421X_PATCH_PRODUCT_VER "Product Version: "
1026#define STIR421X_PATCH_PRODUCT_VERSION_STR "Product Version: " 1029#define STIR421X_PATCH_STMP_TAG "STMP"
1027#define STIR421X_PATCH_COMPONENT_VERSION_STR "Component Version: " 1030#define STIR421X_PATCH_CODE_OFFSET 512 /* patch image starts before here */
1028#define STIR421X_PATCH_DATA_TAG_STR "STMP" 1031/* marks end of patch file header (PC DOS text file EOF character) */
1029#define STIR421X_PATCH_FILE_VERSION_MAX_OFFSET 512 /* version info is before here */ 1032#define STIR421X_PATCH_END_OF_HDR_TAG 0x1A
1030#define STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET 512 /* patch image starts before here */ 1033#define STIR421X_PATCH_BLOCK_SIZE 1023
1031#define STIR421X_PATCH_FILE_END_OF_HEADER_TAG 0x1A /* marks end of patch file header (PC DOS text file EOF character) */
1032 1034
1033/* 1035/*
1034 * Known firmware patches for STIR421x dongles 1036 * Function stir421x_fwupload (struct irda_usb_cb *self,
1037 * unsigned char *patch,
1038 * const unsigned int patch_len)
1039 *
1040 * Upload firmware code to SigmaTel 421X IRDA-USB dongle
1035 */ 1041 */
1036static char * stir421x_patches[] = { 1042static int stir421x_fw_upload(struct irda_usb_cb *self,
1037 "42101001.sb", 1043 unsigned char *patch,
1038 "42101002.sb", 1044 const unsigned int patch_len)
1039};
1040
1041static int stir421x_get_patch_version(unsigned char * patch, const unsigned long patch_len)
1042{ 1045{
1043 unsigned int version_offset; 1046 int ret = -ENOMEM;
1044 unsigned long version_major, version_minor, version_build; 1047 int actual_len = 0;
1045 unsigned char * version_start; 1048 unsigned int i;
1046 int version_found = 0; 1049 unsigned int block_size = 0;
1047 1050 unsigned char *patch_block;
1048 for (version_offset = 0; 1051
1049 version_offset < STIR421X_PATCH_FILE_END_OF_HEADER_TAG; 1052 patch_block = kzalloc(STIR421X_PATCH_BLOCK_SIZE, GFP_KERNEL);
1050 version_offset++) { 1053 if (patch_block == NULL)
1051 if (!memcmp(patch + version_offset, 1054 return -ENOMEM;
1052 STIR421X_PATCH_PRODUCT_VERSION_STR, 1055
1053 sizeof(STIR421X_PATCH_PRODUCT_VERSION_STR) - 1)) { 1056 /* break up patch into 1023-byte sections */
1054 version_found = 1; 1057 for (i = 0; i < patch_len; i += block_size) {
1055 version_start = patch + 1058 block_size = patch_len - i;
1056 version_offset + 1059
1057 sizeof(STIR421X_PATCH_PRODUCT_VERSION_STR) - 1; 1060 if (block_size > STIR421X_PATCH_BLOCK_SIZE)
1058 break; 1061 block_size = STIR421X_PATCH_BLOCK_SIZE;
1059 } 1062
1063 /* upload the patch section */
1064 memcpy(patch_block, patch + i, block_size);
1065
1066 ret = usb_bulk_msg(self->usbdev,
1067 usb_sndbulkpipe(self->usbdev,
1068 self->bulk_out_ep),
1069 patch_block, block_size,
1070 &actual_len, msecs_to_jiffies(500));
1071 IRDA_DEBUG(3,"%s(): Bulk send %u bytes, ret=%d\n",
1072 __FUNCTION__, actual_len, ret);
1073
1074 if (ret < 0)
1075 break;
1060 } 1076 }
1061 1077
1062 /* We couldn't find a product version on this patch */ 1078 kfree(patch_block);
1063 if (!version_found)
1064 return -EINVAL;
1065
1066 /* Let's check if the product version is dotted */
1067 if (version_start[3] != '.' ||
1068 version_start[7] != '.')
1069 return -EINVAL;
1070
1071 version_major = simple_strtoul(version_start, NULL, 10);
1072 version_minor = simple_strtoul(version_start + 4, NULL, 10);
1073 version_build = simple_strtoul(version_start + 8, NULL, 10);
1074
1075 IRDA_DEBUG(2, "%s(), Major: %ld Minor: %ld Build: %ld\n",
1076 __FUNCTION__,
1077 version_major, version_minor, version_build);
1078
1079 return (((version_major) << 12) +
1080 ((version_minor) << 8) +
1081 ((version_build / 10) << 4) +
1082 (version_build % 10));
1083
1084}
1085
1086
1087static int stir421x_upload_patch (struct irda_usb_cb *self,
1088 unsigned char * patch,
1089 const unsigned int patch_len)
1090{
1091 int retval = 0;
1092 int actual_len;
1093 unsigned int i = 0, download_amount = 0;
1094 unsigned char * patch_chunk;
1095
1096 IRDA_DEBUG (2, "%s(), Uploading STIR421x Patch\n", __FUNCTION__);
1097
1098 patch_chunk = kzalloc(STIR421X_MAX_PATCH_DOWNLOAD_SIZE, GFP_KERNEL);
1099 if (patch_chunk == NULL)
1100 return -ENOMEM;
1101
1102 /* break up patch into 1023-byte sections */
1103 for (i = 0; retval >= 0 && i < patch_len; i += download_amount) {
1104 download_amount = patch_len - i;
1105 if (download_amount > STIR421X_MAX_PATCH_DOWNLOAD_SIZE)
1106 download_amount = STIR421X_MAX_PATCH_DOWNLOAD_SIZE;
1107
1108 /* download the patch section */
1109 memcpy(patch_chunk, patch + i, download_amount);
1110
1111 retval = usb_bulk_msg (self->usbdev,
1112 usb_sndbulkpipe (self->usbdev,
1113 self->bulk_out_ep),
1114 patch_chunk, download_amount,
1115 &actual_len, msecs_to_jiffies (500));
1116 IRDA_DEBUG (2, "%s(), Sent %u bytes\n", __FUNCTION__,
1117 actual_len);
1118 if (retval == 0)
1119 mdelay(10);
1120 }
1121
1122 kfree(patch_chunk);
1123
1124 if (i != patch_len) {
1125 IRDA_ERROR ("%s(), Pushed %d bytes (!= patch_len (%d))\n",
1126 __FUNCTION__, i, patch_len);
1127 retval = -EIO;
1128 }
1129
1130 if (retval < 0)
1131 /* todo - mark device as not ready */
1132 IRDA_ERROR ("%s(), STIR421x patch upload failed (%d)\n",
1133 __FUNCTION__, retval);
1134
1135 return retval;
1136}
1137 1079
1080 return ret;
1081 }
1138 1082
1083/*
1084 * Function stir421x_patch_device(struct irda_usb_cb *self)
1085 *
1086 * Get a firmware code from userspase using hotplug request_firmware() call
1087 */
1139static int stir421x_patch_device(struct irda_usb_cb *self) 1088static int stir421x_patch_device(struct irda_usb_cb *self)
1140{ 1089{
1141 unsigned int i, patch_found = 0, data_found = 0, data_offset; 1090 unsigned int i;
1142 int patch_version, ret = 0; 1091 int ret;
1143 const struct firmware *fw_entry; 1092 char stir421x_fw_name[11];
1144 1093 const struct firmware *fw;
1145 for (i = 0; i < ARRAY_SIZE(stir421x_patches); i++) { 1094 unsigned char *fw_version_ptr; /* pointer to version string */
1146 if(request_firmware(&fw_entry, stir421x_patches[i], &self->usbdev->dev) != 0) { 1095 unsigned long fw_version = 0;
1147 IRDA_ERROR( "%s(), Patch %s is not available\n", __FUNCTION__, stir421x_patches[i]); 1096
1148 continue; 1097 /*
1149 } 1098 * Known firmware patch file names for STIR421x dongles
1150 1099 * are "42101001.sb" or "42101002.sb"
1151 /* We found a patch from userspace */ 1100 */
1152 patch_version = stir421x_get_patch_version (fw_entry->data, fw_entry->size); 1101 sprintf(stir421x_fw_name, "4210%4X.sb",
1153 1102 self->usbdev->descriptor.bcdDevice);
1154 if (patch_version < 0) { 1103 ret = request_firmware(&fw, stir421x_fw_name, &self->usbdev->dev);
1155 /* Couldn't fetch a version, let's move on to the next file */ 1104 if (ret < 0)
1156 IRDA_ERROR("%s(), version parsing failed\n", __FUNCTION__); 1105 return ret;
1157 ret = patch_version; 1106
1158 release_firmware(fw_entry); 1107 /* We get a patch from userspace */
1159 continue; 1108 IRDA_MESSAGE("%s(): Received firmware %s (%u bytes)\n",
1160 } 1109 __FUNCTION__, stir421x_fw_name, fw->size);
1161 1110
1162 if (patch_version != self->usbdev->descriptor.bcdDevice) { 1111 ret = -EINVAL;
1163 /* Patch version and device don't match */ 1112
1164 IRDA_ERROR ("%s(), wrong patch version (%d <-> %d)\n", 1113 /* Get the bcd product version */
1165 __FUNCTION__, 1114 if (!memcmp(fw->data, STIR421X_PATCH_PRODUCT_VER,
1166 patch_version, self->usbdev->descriptor.bcdDevice); 1115 sizeof(STIR421X_PATCH_PRODUCT_VER) - 1)) {
1167 ret = -EINVAL; 1116 fw_version_ptr = fw->data +
1168 release_firmware(fw_entry); 1117 sizeof(STIR421X_PATCH_PRODUCT_VER) - 1;
1169 continue; 1118
1170 } 1119 /* Let's check if the product version is dotted */
1171 1120 if (fw_version_ptr[3] == '.' &&
1172 /* If we're here, we've found a correct patch */ 1121 fw_version_ptr[7] == '.') {
1173 patch_found = 1; 1122 unsigned long major, minor, build;
1174 break; 1123 major = simple_strtoul(fw_version_ptr, NULL, 10);
1175 1124 minor = simple_strtoul(fw_version_ptr + 4, NULL, 10);
1176 } 1125 build = simple_strtoul(fw_version_ptr + 8, NULL, 10);
1177 1126
1178 /* We couldn't find a valid firmware, let's leave */ 1127 fw_version = (major << 12)
1179 if (!patch_found) 1128 + (minor << 8)
1180 return ret; 1129 + ((build / 10) << 4)
1181 1130 + (build % 10);
1182 /* The actual image starts after the "STMP" keyword */ 1131
1183 for (data_offset = 0; data_offset < STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET; data_offset++) { 1132 IRDA_DEBUG(3, "%s(): Firmware Product version %ld\n",
1184 if (!memcmp(fw_entry->data + data_offset, 1133 __FUNCTION__, fw_version);
1185 STIR421X_PATCH_DATA_TAG_STR, 1134 }
1186 sizeof(STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET))) { 1135 }
1187 IRDA_DEBUG(2, "%s(), found patch data for STIR421x at offset %d\n", 1136
1188 __FUNCTION__, data_offset); 1137 if (self->usbdev->descriptor.bcdDevice == fw_version) {
1189 data_found = 1; 1138 /*
1190 break; 1139 * If we're here, we've found a correct patch
1191 } 1140 * The actual image starts after the "STMP" keyword
1192 } 1141 * so forward to the firmware header tag
1193 1142 */
1194 /* We couldn't find "STMP" from the header */ 1143 for (i = 0; (fw->data[i] != STIR421X_PATCH_END_OF_HDR_TAG)
1195 if (!data_found) 1144 && (i < fw->size); i++) ;
1196 return -EINVAL; 1145 /* here we check for the out of buffer case */
1197 1146 if ((STIR421X_PATCH_END_OF_HDR_TAG == fw->data[i])
1198 /* Let's upload the patch to the target */ 1147 && (i < STIR421X_PATCH_CODE_OFFSET)) {
1199 ret = stir421x_upload_patch(self, 1148 if (!memcmp(fw->data + i + 1, STIR421X_PATCH_STMP_TAG,
1200 &fw_entry->data[data_offset + sizeof(STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET)], 1149 sizeof(STIR421X_PATCH_STMP_TAG) - 1)) {
1201 fw_entry->size - (data_offset + sizeof(STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET))); 1150
1202 1151 /* We can upload the patch to the target */
1203 release_firmware(fw_entry); 1152 i += sizeof(STIR421X_PATCH_STMP_TAG);
1204 1153 ret = stir421x_fw_upload(self, &fw->data[i],
1205 return ret; 1154 fw->size - i);
1206 1155 }
1156 }
1157 }
1158
1159 release_firmware(fw);
1160
1161 return ret;
1207} 1162}
1208 1163
1209 1164
@@ -1702,12 +1657,12 @@ static int irda_usb_probe(struct usb_interface *intf,
1702 init_timer(&self->rx_defer_timer); 1657 init_timer(&self->rx_defer_timer);
1703 1658
1704 self->capability = id->driver_info; 1659 self->capability = id->driver_info;
1705 self->needspatch = ((self->capability & IUC_STIR_4210) != 0) ; 1660 self->needspatch = ((self->capability & IUC_STIR421X) != 0);
1706 1661
1707 /* Create all of the needed urbs */ 1662 /* Create all of the needed urbs */
1708 if (self->capability & IUC_STIR_4210) { 1663 if (self->capability & IUC_STIR421X) {
1709 self->max_rx_urb = IU_SIGMATEL_MAX_RX_URBS; 1664 self->max_rx_urb = IU_SIGMATEL_MAX_RX_URBS;
1710 self->header_length = USB_IRDA_SIGMATEL_HEADER; 1665 self->header_length = USB_IRDA_STIR421X_HEADER;
1711 } else { 1666 } else {
1712 self->max_rx_urb = IU_MAX_RX_URBS; 1667 self->max_rx_urb = IU_MAX_RX_URBS;
1713 self->header_length = USB_IRDA_HEADER; 1668 self->header_length = USB_IRDA_HEADER;
@@ -1813,8 +1768,8 @@ static int irda_usb_probe(struct usb_interface *intf,
1813 /* Now we fetch and upload the firmware patch */ 1768 /* Now we fetch and upload the firmware patch */
1814 ret = stir421x_patch_device(self); 1769 ret = stir421x_patch_device(self);
1815 self->needspatch = (ret < 0); 1770 self->needspatch = (ret < 0);
1816 if (ret < 0) { 1771 if (self->needspatch) {
1817 printk("patch_device failed\n"); 1772 IRDA_ERROR("STIR421X: Couldn't upload patch\n");
1818 goto err_out_5; 1773 goto err_out_5;
1819 } 1774 }
1820 1775
diff --git a/drivers/net/irda/irda-usb.h b/drivers/net/irda/irda-usb.h
index d833db52ceb..6b2271f18e7 100644
--- a/drivers/net/irda/irda-usb.h
+++ b/drivers/net/irda/irda-usb.h
@@ -34,9 +34,6 @@
34#include <net/irda/irda.h> 34#include <net/irda/irda.h>
35#include <net/irda/irda_device.h> /* struct irlap_cb */ 35#include <net/irda/irda_device.h> /* struct irlap_cb */
36 36
37#define PATCH_FILE_SIZE_MAX 65536
38#define PATCH_FILE_SIZE_MIN 80
39
40#define RX_COPY_THRESHOLD 200 37#define RX_COPY_THRESHOLD 200
41#define IRDA_USB_MAX_MTU 2051 38#define IRDA_USB_MAX_MTU 2051
42#define IRDA_USB_SPEED_MTU 64 /* Weird, but work like this */ 39#define IRDA_USB_SPEED_MTU 64 /* Weird, but work like this */
@@ -107,14 +104,15 @@
107#define IUC_SMALL_PKT 0x10 /* Device doesn't behave with big Rx packets */ 104#define IUC_SMALL_PKT 0x10 /* Device doesn't behave with big Rx packets */
108#define IUC_MAX_WINDOW 0x20 /* Device underestimate the Rx window */ 105#define IUC_MAX_WINDOW 0x20 /* Device underestimate the Rx window */
109#define IUC_MAX_XBOFS 0x40 /* Device need more xbofs than advertised */ 106#define IUC_MAX_XBOFS 0x40 /* Device need more xbofs than advertised */
110#define IUC_STIR_4210 0x80 /* SigmaTel 4210/4220/4116 VFIR */ 107#define IUC_STIR421X 0x80 /* SigmaTel 4210/4220/4116 VFIR */
111 108
112/* USB class definitions */ 109/* USB class definitions */
113#define USB_IRDA_HEADER 0x01 110#define USB_IRDA_HEADER 0x01
114#define USB_CLASS_IRDA 0x02 /* USB_CLASS_APP_SPEC subclass */ 111#define USB_CLASS_IRDA 0x02 /* USB_CLASS_APP_SPEC subclass */
115#define USB_DT_IRDA 0x21 112#define USB_DT_IRDA 0x21
116#define USB_IRDA_SIGMATEL_HEADER 0x03 113#define USB_IRDA_STIR421X_HEADER 0x03
117#define IU_SIGMATEL_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + USB_IRDA_SIGMATEL_HEADER) 114#define IU_SIGMATEL_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + \
115 USB_IRDA_STIR421X_HEADER)
118 116
119struct irda_class_desc { 117struct irda_class_desc {
120 __u8 bLength; 118 __u8 bLength;
diff --git a/drivers/net/irda/mcs7780.c b/drivers/net/irda/mcs7780.c
new file mode 100644
index 00000000000..754297fc8f2
--- /dev/null
+++ b/drivers/net/irda/mcs7780.c
@@ -0,0 +1,1009 @@
1/*****************************************************************************
2*
3* Filename: mcs7780.c
4* Version: 0.4-alpha
5* Description: Irda MosChip USB Dongle Driver
6* Authors: Lukasz Stelmach <stlman@poczta.fm>
7* Brian Pugh <bpugh@cs.pdx.edu>
8* Judy Fischbach <jfisch@cs.pdx.edu>
9*
10* Based on stir4200 driver, but some things done differently.
11* Based on earlier driver by Paul Stewart <stewart@parc.com>
12*
13* Copyright (C) 2000, Roman Weissgaerber <weissg@vienna.at>
14* Copyright (C) 2001, Dag Brattli <dag@brattli.net>
15* Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
16* Copyright (C) 2004, Stephen Hemminger <shemminger@osdl.org>
17* Copyright (C) 2005, Lukasz Stelmach <stlman@poczta.fm>
18* Copyright (C) 2005, Brian Pugh <bpugh@cs.pdx.edu>
19* Copyright (C) 2005, Judy Fischbach <jfisch@cs.pdx.edu>
20*
21* This program is free software; you can redistribute it and/or modify
22* it under the terms of the GNU General Public License as published by
23* the Free Software Foundation; either version 2 of the License, or
24* (at your option) any later version.
25*
26* This program is distributed in the hope that it will be useful,
27* but WITHOUT ANY WARRANTY; without even the implied warranty of
28* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29* GNU General Public License for more details.
30*
31* You should have received a copy of the GNU General Public License
32* along with this program; if not, write to the Free Software
33* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34*
35*****************************************************************************/
36
37/*
38 * MCS7780 is a simple USB to IrDA bridge by MosChip. It is neither
39 * compatibile with irda-usb nor with stir4200. Although it is quite
40 * similar to the later as far as general idea of operation is concerned.
41 * That is it requires the software to do all the framing job at SIR speeds.
42 * The hardware does take care of the framing at MIR and FIR speeds.
43 * It supports all speeds from 2400 through 4Mbps
44 */
45
46#include <linux/module.h>
47#include <linux/moduleparam.h>
48#include <linux/config.h>
49#include <linux/kernel.h>
50#include <linux/types.h>
51#include <linux/errno.h>
52#include <linux/init.h>
53#include <linux/slab.h>
54#include <linux/module.h>
55#include <linux/kref.h>
56#include <linux/usb.h>
57#include <linux/device.h>
58#include <linux/crc32.h>
59
60#include <asm/unaligned.h>
61#include <asm/byteorder.h>
62#include <asm/uaccess.h>
63
64#include <net/irda/irda.h>
65#include <net/irda/wrapper.h>
66#include <net/irda/crc.h>
67
68#include "mcs7780.h"
69
70#define MCS_VENDOR_ID 0x9710
71#define MCS_PRODUCT_ID 0x7780
72
73static struct usb_device_id mcs_table[] = {
74 /* MosChip Corp., MCS7780 FIR-USB Adapter */
75 {USB_DEVICE(MCS_VENDOR_ID, MCS_PRODUCT_ID)},
76 {},
77};
78
79MODULE_AUTHOR("Brian Pugh <bpugh@cs.pdx.edu>");
80MODULE_DESCRIPTION("IrDA-USB Dongle Driver for MosChip MCS7780");
81MODULE_VERSION("0.3alpha");
82MODULE_LICENSE("GPL");
83
84MODULE_DEVICE_TABLE(usb, mcs_table);
85
86static int qos_mtt_bits = 0x07 /* > 1ms */ ;
87module_param(qos_mtt_bits, int, 0);
88MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time");
89
90static int receive_mode = 0x1;
91module_param(receive_mode, int, 0);
92MODULE_PARM_DESC(receive_mode,
93 "Receive mode of the device (1:fast, 0:slow, default:1)");
94
95static int sir_tweak = 1;
96module_param(sir_tweak, int, 0444);
97MODULE_PARM_DESC(sir_tweak,
98 "Default pulse width (1:1.6us, 0:3/16 bit, default:1).");
99
100static int transceiver_type = MCS_TSC_VISHAY;
101module_param(transceiver_type, int, 0444);
102MODULE_PARM_DESC(transceiver_type, "IR transceiver type, see mcs7780.h.");
103
104struct usb_driver mcs_driver = {
105 .name = "mcs7780",
106 .probe = mcs_probe,
107 .disconnect = mcs_disconnect,
108 .id_table = mcs_table,
109};
110
111/* speed flag selection by direct addressing.
112addr = (speed >> 8) & 0x0f
113
1140x1 57600 0x2 115200 0x4 1152000 0x5 9600
1150x6 38400 0x9 2400 0xa 576000 0xb 19200
116
1174Mbps (or 2400) must be checked separately. Since it also has
118to be programmed in a different manner that is not a big problem.
119*/
120static __u16 mcs_speed_set[16] = { 0,
121 MCS_SPEED_57600,
122 MCS_SPEED_115200,
123 0,
124 MCS_SPEED_1152000,
125 MCS_SPEED_9600,
126 MCS_SPEED_38400,
127 0, 0,
128 MCS_SPEED_2400,
129 MCS_SPEED_576000,
130 MCS_SPEED_19200,
131 0, 0, 0,
132};
133
134/* Set given 16 bit register with a 16 bit value. Send control message
135 * to set dongle register. */
136static int mcs_set_reg(struct mcs_cb *mcs, __u16 reg, __u16 val)
137{
138 struct usb_device *dev = mcs->usbdev;
139 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
140 MCS_WR_RTYPE, val, reg, NULL, 0,
141 msecs_to_jiffies(MCS_CTRL_TIMEOUT));
142}
143
144/* Get 16 bit register value. Send contol message to read dongle register. */
145static int mcs_get_reg(struct mcs_cb *mcs, __u16 reg, __u16 * val)
146{
147 struct usb_device *dev = mcs->usbdev;
148 int ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
149 MCS_RD_RTYPE, 0, reg, val, 2,
150 msecs_to_jiffies(MCS_CTRL_TIMEOUT));
151
152 return ret;
153}
154
155/* Setup a communication between mcs7780 and TFDU chips. It is described
156 * in more detail in the data sheet. The setup sequence puts the the
157 * vishay tranceiver into high speed mode. It will also receive SIR speed
158 * packets but at reduced sensitivity.
159 */
160
161/* 0: OK 1:ERROR */
162static inline int mcs_setup_transceiver_vishay(struct mcs_cb *mcs)
163{
164 int ret = 0;
165 __u16 rval;
166
167 /* mcs_get_reg should read exactly two bytes from the dongle */
168 ret = mcs_get_reg(mcs, MCS_XCVR_REG, &rval);
169 if (unlikely(ret != 2)) {
170 ret = -EIO;
171 goto error;
172 }
173
174 /* The MCS_XCVR_CONF bit puts the transceiver into configuration
175 * mode. The MCS_MODE0 bit must start out high (1) and then
176 * transition to low and the MCS_STFIR and MCS_MODE1 bits must
177 * be low.
178 */
179 rval |= (MCS_MODE0 | MCS_XCVR_CONF);
180 rval &= ~MCS_STFIR;
181 rval &= ~MCS_MODE1;
182 ret = mcs_set_reg(mcs, MCS_XCVR_REG, rval);
183 if (unlikely(ret))
184 goto error;
185
186 rval &= ~MCS_MODE0;
187 ret = mcs_set_reg(mcs, MCS_XCVR_REG, rval);
188 if (unlikely(ret))
189 goto error;
190
191 rval &= ~MCS_XCVR_CONF;
192 ret = mcs_set_reg(mcs, MCS_XCVR_REG, rval);
193 if (unlikely(ret))
194 goto error;
195
196 ret = 0;
197 error:
198 return ret;
199}
200
201/* Setup a communication between mcs7780 and agilent chip. */
202static inline int mcs_setup_transceiver_agilent(struct mcs_cb *mcs)
203{
204 IRDA_WARNING("This transceiver type is not supported yet.");
205 return 1;
206}
207
208/* Setup a communication between mcs7780 and sharp chip. */
209static inline int mcs_setup_transceiver_sharp(struct mcs_cb *mcs)
210{
211 IRDA_WARNING("This transceiver type is not supported yet.");
212 return 1;
213}
214
215/* Common setup for all transceivers */
216static inline int mcs_setup_transceiver(struct mcs_cb *mcs)
217{
218 int ret = 0;
219 __u16 rval;
220 char *msg;
221
222 msg = "Basic transceiver setup error.";
223
224 /* read value of MODE Register, set the DRIVER and RESET bits
225 * and write value back out to MODE Register
226 */
227 ret = mcs_get_reg(mcs, MCS_MODE_REG, &rval);
228 if(unlikely(ret != 2))
229 goto error;
230 rval |= MCS_DRIVER; /* put the mcs7780 into configuration mode. */
231 ret = mcs_set_reg(mcs, MCS_MODE_REG, rval);
232 if(unlikely(ret))
233 goto error;
234
235 rval = 0; /* set min pulse width to 0 initially. */
236 ret = mcs_set_reg(mcs, MCS_MINRXPW_REG, rval);
237 if(unlikely(ret))
238 goto error;
239
240 ret = mcs_get_reg(mcs, MCS_MODE_REG, &rval);
241 if(unlikely(ret != 2))
242 goto error;
243
244 rval &= ~MCS_FIR; /* turn off fir mode. */
245 if(mcs->sir_tweak)
246 rval |= MCS_SIR16US; /* 1.6us pulse width */
247 else
248 rval &= ~MCS_SIR16US; /* 3/16 bit time pulse width */
249
250 /* make sure ask mode and back to back packets are off. */
251 rval &= ~(MCS_BBTG | MCS_ASK);
252
253 rval &= ~MCS_SPEED_MASK;
254 rval |= MCS_SPEED_9600; /* make sure initial speed is 9600. */
255 mcs->speed = 9600;
256 mcs->new_speed = 0; /* new_speed is set to 0 */
257 rval &= ~MCS_PLLPWDN; /* disable power down. */
258
259 /* make sure device determines direction and that the auto send sip
260 * pulse are on.
261 */
262 rval |= MCS_DTD | MCS_SIPEN;
263
264 ret = mcs_set_reg(mcs, MCS_MODE_REG, rval);
265 if(unlikely(ret))
266 goto error;
267
268 msg = "transceiver model specific setup error.";
269 switch (mcs->transceiver_type) {
270 case MCS_TSC_VISHAY:
271 ret = mcs_setup_transceiver_vishay(mcs);
272 break;
273
274 case MCS_TSC_SHARP:
275 ret = mcs_setup_transceiver_sharp(mcs);
276 break;
277
278 case MCS_TSC_AGILENT:
279 ret = mcs_setup_transceiver_agilent(mcs);
280 break;
281
282 default:
283 IRDA_WARNING("Unknown transceiver type: %d",
284 mcs->transceiver_type);
285 ret = 1;
286 }
287 if (unlikely(ret))
288 goto error;
289
290 /* If transceiver is not SHARP, then if receive mode set
291 * on the RXFAST bit in the XCVR Register otherwise unset it
292 */
293 if (mcs->transceiver_type != MCS_TSC_SHARP) {
294
295 ret = mcs_get_reg(mcs, MCS_XCVR_REG, &rval);
296 if (unlikely(ret != 2))
297 goto error;
298 if (mcs->receive_mode)
299 rval |= MCS_RXFAST;
300 else
301 rval &= ~MCS_RXFAST;
302 ret = mcs_set_reg(mcs, MCS_XCVR_REG, rval);
303 if (unlikely(ret))
304 goto error;
305 }
306
307 msg = "transceiver reset.";
308
309 ret = mcs_get_reg(mcs, MCS_MODE_REG, &rval);
310 if (unlikely(ret != 2))
311 goto error;
312
313 /* reset the mcs7780 so all changes take effect. */
314 rval &= ~MCS_RESET;
315 ret = mcs_set_reg(mcs, MCS_MODE_REG, rval);
316 if (unlikely(ret))
317 goto error;
318 else
319 return ret;
320
321error:
322 IRDA_ERROR("%s", msg);
323 return ret;
324}
325
326/* Wraps the data in format for SIR */
327static inline int mcs_wrap_sir_skb(struct sk_buff *skb, __u8 * buf)
328{
329 int wraplen;
330
331 /* 2: full frame length, including "the length" */
332 wraplen = async_wrap_skb(skb, buf + 2, 4094);
333
334 wraplen += 2;
335 buf[0] = wraplen & 0xff;
336 buf[1] = (wraplen >> 8) & 0xff;
337
338 return wraplen;
339}
340
341/* Wraps the data in format for FIR */
342static unsigned mcs_wrap_fir_skb(const struct sk_buff *skb, __u8 *buf)
343{
344 unsigned int len = 0;
345 __u32 fcs = ~(crc32_le(~0, skb->data, skb->len));
346
347 /* add 2 bytes for length value and 4 bytes for fcs. */
348 len = skb->len + 6;
349
350 /* The mcs7780 requires that the first two bytes are the packet
351 * length in little endian order. Note: the length value includes
352 * the two bytes for the length value itself.
353 */
354 buf[0] = len & 0xff;
355 buf[1] = (len >> 8) & 0xff;
356 /* copy the data into the tx buffer. */
357 memcpy(buf+2, skb->data, skb->len);
358 /* put the fcs in the last four bytes in little endian order. */
359 buf[len - 4] = fcs & 0xff;
360 buf[len - 3] = (fcs >> 8) & 0xff;
361 buf[len - 2] = (fcs >> 16) & 0xff;
362 buf[len - 1] = (fcs >> 24) & 0xff;
363
364 return len;
365}
366
367/* Wraps the data in format for MIR */
368static unsigned mcs_wrap_mir_skb(const struct sk_buff *skb, __u8 *buf)
369{
370 __u16 fcs = 0;
371 int len = skb->len + 4;
372
373 fcs = ~(irda_calc_crc16(~fcs, skb->data, skb->len));
374 /* put the total packet length in first. Note: packet length
375 * value includes the two bytes that hold the packet length
376 * itself.
377 */
378 buf[0] = len & 0xff;
379 buf[1] = (len >> 8) & 0xff;
380 /* copy the data */
381 memcpy(buf+2, skb->data, skb->len);
382 /* put the fcs in last two bytes in little endian order. */
383 buf[len - 2] = fcs & 0xff;
384 buf[len - 1] = (fcs >> 8) & 0xff;
385
386 return len;
387}
388
389/* Unwrap received packets at MIR speed. A 16 bit crc_ccitt checksum is
390 * used for the fcs. When performed over the entire packet the result
391 * should be GOOD_FCS = 0xf0b8. Hands the unwrapped data off to the IrDA
392 * layer via a sk_buff.
393 */
394static void mcs_unwrap_mir(struct mcs_cb *mcs, __u8 *buf, int len)
395{
396 __u16 fcs;
397 int new_len;
398 struct sk_buff *skb;
399
400 /* Assume that the frames are going to fill a single packet
401 * rather than span multiple packets.
402 */
403
404 new_len = len - 2;
405 if(unlikely(new_len <= 0)) {
406 IRDA_ERROR("%s short frame length %d\n",
407 mcs->netdev->name, new_len);
408 ++mcs->stats.rx_errors;
409 ++mcs->stats.rx_length_errors;
410 return;
411 }
412 fcs = 0;
413 fcs = irda_calc_crc16(~fcs, buf, len);
414
415 if(fcs != GOOD_FCS) {
416 IRDA_ERROR("crc error calc 0x%x len %d\n",
417 fcs, new_len);
418 mcs->stats.rx_errors++;
419 mcs->stats.rx_crc_errors++;
420 return;
421 }
422
423 skb = dev_alloc_skb(new_len + 1);
424 if(unlikely(!skb)) {
425 ++mcs->stats.rx_dropped;
426 return;
427 }
428
429 skb_reserve(skb, 1);
430 memcpy(skb->data, buf, new_len);
431 skb_put(skb, new_len);
432 skb->mac.raw = skb->data;
433 skb->protocol = htons(ETH_P_IRDA);
434 skb->dev = mcs->netdev;
435
436 netif_rx(skb);
437
438 mcs->stats.rx_packets++;
439 mcs->stats.rx_bytes += new_len;
440
441 return;
442}
443
444/* Unwrap received packets at FIR speed. A 32 bit crc_ccitt checksum is
445 * used for the fcs. Hands the unwrapped data off to the IrDA
446 * layer via a sk_buff.
447 */
448static void mcs_unwrap_fir(struct mcs_cb *mcs, __u8 *buf, int len)
449{
450 __u32 fcs;
451 int new_len;
452 struct sk_buff *skb;
453
454 /* Assume that the frames are going to fill a single packet
455 * rather than span multiple packets. This is most likely a false
456 * assumption.
457 */
458
459 new_len = len - 4;
460 if(unlikely(new_len <= 0)) {
461 IRDA_ERROR("%s short frame length %d\n",
462 mcs->netdev->name, new_len);
463 ++mcs->stats.rx_errors;
464 ++mcs->stats.rx_length_errors;
465 return;
466 }
467
468 fcs = ~(crc32_le(~0, buf, new_len));
469 if(fcs != le32_to_cpu(get_unaligned((u32 *)(buf+new_len)))) {
470 IRDA_ERROR("crc error calc 0x%x len %d\n", fcs, new_len);
471 mcs->stats.rx_errors++;
472 mcs->stats.rx_crc_errors++;
473 return;
474 }
475
476 skb = dev_alloc_skb(new_len + 1);
477 if(unlikely(!skb)) {
478 ++mcs->stats.rx_dropped;
479 return;
480 }
481
482 skb_reserve(skb, 1);
483 memcpy(skb->data, buf, new_len);
484 skb_put(skb, new_len);
485 skb->mac.raw = skb->data;
486 skb->protocol = htons(ETH_P_IRDA);
487 skb->dev = mcs->netdev;
488
489 netif_rx(skb);
490
491 mcs->stats.rx_packets++;
492 mcs->stats.rx_bytes += new_len;
493
494 return;
495}
496
497
498/* Allocates urbs for both receive and transmit.
499 * If alloc fails return error code 0 (fail) otherwise
500 * return error code 1 (success).
501 */
502static inline int mcs_setup_urbs(struct mcs_cb *mcs)
503{
504 mcs->rx_urb = NULL;
505
506 mcs->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
507 if (!mcs->tx_urb)
508 return 0;
509
510 mcs->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
511 if (!mcs->rx_urb)
512 return 0;
513
514 return 1;
515}
516
517/* Sets up state to be initially outside frame, gets receive urb,
518 * sets status to successful and then submits the urb to start
519 * receiving the data.
520 */
521static inline int mcs_receive_start(struct mcs_cb *mcs)
522{
523 mcs->rx_buff.in_frame = FALSE;
524 mcs->rx_buff.state = OUTSIDE_FRAME;
525
526 usb_fill_bulk_urb(mcs->rx_urb, mcs->usbdev,
527 usb_rcvbulkpipe(mcs->usbdev, mcs->ep_in),
528 mcs->in_buf, 4096, mcs_receive_irq, mcs);
529
530 mcs->rx_urb->status = 0;
531 return usb_submit_urb(mcs->rx_urb, GFP_KERNEL);
532}
533
534/* Finds the in and out endpoints for the mcs control block */
535static inline int mcs_find_endpoints(struct mcs_cb *mcs,
536 struct usb_host_endpoint *ep, int epnum)
537{
538 int i;
539 int ret = 0;
540
541 /* If no place to store the endpoints just return */
542 if (!ep)
543 return ret;
544
545 /* cycle through all endpoints, find the first two that are DIR_IN */
546 for (i = 0; i < epnum; i++) {
547 if (ep[i].desc.bEndpointAddress & USB_DIR_IN)
548 mcs->ep_in = ep[i].desc.bEndpointAddress;
549 else
550 mcs->ep_out = ep[i].desc.bEndpointAddress;
551
552 /* MosChip says that the chip has only two bulk
553 * endpoints. Find one for each direction and move on.
554 */
555 if ((mcs->ep_in != 0) && (mcs->ep_out != 0)) {
556 ret = 1;
557 break;
558 }
559 }
560
561 return ret;
562}
563
564static void mcs_speed_work(void *arg)
565{
566 struct mcs_cb *mcs = arg;
567 struct net_device *netdev = mcs->netdev;
568
569 mcs_speed_change(mcs);
570 netif_wake_queue(netdev);
571}
572
573/* Function to change the speed of the mcs7780. Fully supports SIR,
574 * MIR, and FIR speeds.
575 */
576static int mcs_speed_change(struct mcs_cb *mcs)
577{
578 int ret = 0;
579 int rst = 0;
580 int cnt = 0;
581 __u16 nspeed;
582 __u16 rval;
583
584 nspeed = mcs_speed_set[(mcs->new_speed >> 8) & 0x0f];
585
586 do {
587 mcs_get_reg(mcs, MCS_RESV_REG, &rval);
588 } while(cnt++ < 100 && (rval & MCS_IRINTX));
589
590 if(cnt >= 100) {
591 IRDA_ERROR("unable to change speed");
592 ret = -EIO;
593 goto error;
594 }
595
596 mcs_get_reg(mcs, MCS_MODE_REG, &rval);
597
598 /* MINRXPW values recomended by MosChip */
599 if (mcs->new_speed <= 115200) {
600 rval &= ~MCS_FIR;
601
602 if ((rst = (mcs->speed > 115200)))
603 mcs_set_reg(mcs, MCS_MINRXPW_REG, 0);
604
605 } else if (mcs->new_speed <= 1152000) {
606 rval &= ~MCS_FIR;
607
608 if ((rst = !(mcs->speed == 576000 || mcs->speed == 1152000)))
609 mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
610
611 } else {
612 rval |= MCS_FIR;
613
614 if ((rst = (mcs->speed != 4000000)))
615 mcs_set_reg(mcs, MCS_MINRXPW_REG, 5);
616
617 }
618
619 rval &= ~MCS_SPEED_MASK;
620 rval |= nspeed;
621
622 ret = mcs_set_reg(mcs, MCS_MODE_REG, rval);
623 if (unlikely(ret))
624 goto error;
625
626 if (rst)
627 switch (mcs->transceiver_type) {
628 case MCS_TSC_VISHAY:
629 ret = mcs_setup_transceiver_vishay(mcs);
630 break;
631
632 case MCS_TSC_SHARP:
633 ret = mcs_setup_transceiver_sharp(mcs);
634 break;
635
636 case MCS_TSC_AGILENT:
637 ret = mcs_setup_transceiver_agilent(mcs);
638 break;
639
640 default:
641 ret = 1;
642 IRDA_WARNING("Unknown transceiver type: %d",
643 mcs->transceiver_type);
644 }
645 if (unlikely(ret))
646 goto error;
647
648 mcs_get_reg(mcs, MCS_MODE_REG, &rval);
649 rval &= ~MCS_RESET;
650 ret = mcs_set_reg(mcs, MCS_MODE_REG, rval);
651
652 mcs->speed = mcs->new_speed;
653 error:
654 mcs->new_speed = 0;
655 return ret;
656}
657
658/* Ioctl calls not supported at this time. Can be an area of future work. */
659static int mcs_net_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
660{
661 /* struct if_irda_req *irq = (struct if_irda_req *)rq; */
662 /* struct mcs_cb *mcs = netdev_priv(netdev); */
663 int ret = 0;
664
665 switch (cmd) {
666 default:
667 ret = -EOPNOTSUPP;
668 }
669
670 return ret;
671}
672
673/* Network device is taken down, done by "ifconfig irda0 down" */
674static int mcs_net_close(struct net_device *netdev)
675{
676 int ret = 0;
677 struct mcs_cb *mcs = netdev_priv(netdev);
678
679 /* Stop transmit processing */
680 netif_stop_queue(netdev);
681
682 /* kill and free the receive and transmit URBs */
683 usb_kill_urb(mcs->rx_urb);
684 usb_free_urb(mcs->rx_urb);
685 usb_kill_urb(mcs->tx_urb);
686 usb_free_urb(mcs->tx_urb);
687
688 /* Stop and remove instance of IrLAP */
689 if (mcs->irlap)
690 irlap_close(mcs->irlap);
691
692 mcs->irlap = NULL;
693 return ret;
694}
695
696/* Network device is taken up, done by "ifconfig irda0 up" */
697static int mcs_net_open(struct net_device *netdev)
698{
699 struct mcs_cb *mcs = netdev_priv(netdev);
700 char hwname[16];
701 int ret = 0;
702
703 ret = usb_clear_halt(mcs->usbdev,
704 usb_sndbulkpipe(mcs->usbdev, mcs->ep_in));
705 if (ret)
706 goto error1;
707 ret = usb_clear_halt(mcs->usbdev,
708 usb_rcvbulkpipe(mcs->usbdev, mcs->ep_out));
709 if (ret)
710 goto error1;
711
712 ret = mcs_setup_transceiver(mcs);
713 if (ret)
714 goto error1;
715
716 ret = -ENOMEM;
717
718 /* Initialize for SIR/FIR to copy data directly into skb. */
719 mcs->receiving = 0;
720 mcs->rx_buff.truesize = IRDA_SKB_MAX_MTU;
721 mcs->rx_buff.skb = dev_alloc_skb(IRDA_SKB_MAX_MTU);
722 if (!mcs->rx_buff.skb)
723 goto error1;
724
725 skb_reserve(mcs->rx_buff.skb, 1);
726 mcs->rx_buff.head = mcs->rx_buff.skb->data;
727 do_gettimeofday(&mcs->rx_time);
728
729 /*
730 * Now that everything should be initialized properly,
731 * Open new IrLAP layer instance to take care of us...
732 * Note : will send immediately a speed change...
733 */
734 sprintf(hwname, "usb#%d", mcs->usbdev->devnum);
735 mcs->irlap = irlap_open(netdev, &mcs->qos, hwname);
736 if (!mcs->irlap) {
737 IRDA_ERROR("mcs7780: irlap_open failed");
738 goto error2;
739 }
740
741 if (!mcs_setup_urbs(mcs))
742 goto error3;
743
744 ret = mcs_receive_start(mcs);
745 if (ret)
746 goto error3;
747
748 netif_start_queue(netdev);
749 return 0;
750
751 error3:
752 irlap_close(mcs->irlap);
753 error2:
754 kfree_skb(mcs->rx_buff.skb);
755 error1:
756 return ret;
757}
758
759
760/* Get device stats for /proc/net/dev and ifconfig */
761static struct net_device_stats *mcs_net_get_stats(struct net_device *netdev)
762{
763 struct mcs_cb *mcs = netdev_priv(netdev);
764 return &mcs->stats;
765}
766
767/* Receive callback function. */
768static void mcs_receive_irq(struct urb *urb, struct pt_regs *regs)
769{
770 __u8 *bytes;
771 struct mcs_cb *mcs = urb->context;
772 int i;
773 int ret;
774
775 if (!netif_running(mcs->netdev))
776 return;
777
778 if (urb->status)
779 return;
780
781 if (urb->actual_length > 0) {
782 bytes = urb->transfer_buffer;
783
784 /* MCS returns frames without BOF and EOF
785 * I assume it returns whole frames.
786 */
787 /* SIR speed */
788 if(mcs->speed < 576000) {
789 async_unwrap_char(mcs->netdev, &mcs->stats,
790 &mcs->rx_buff, 0xc0);
791
792 for (i = 0; i < urb->actual_length; i++)
793 async_unwrap_char(mcs->netdev, &mcs->stats,
794 &mcs->rx_buff, bytes[i]);
795
796 async_unwrap_char(mcs->netdev, &mcs->stats,
797 &mcs->rx_buff, 0xc1);
798 }
799 /* MIR speed */
800 else if(mcs->speed == 576000 || mcs->speed == 1152000) {
801 mcs_unwrap_mir(mcs, urb->transfer_buffer,
802 urb->actual_length);
803 }
804 /* FIR speed */
805 else {
806 mcs_unwrap_fir(mcs, urb->transfer_buffer,
807 urb->actual_length);
808 }
809 mcs->netdev->last_rx = jiffies;
810 do_gettimeofday(&mcs->rx_time);
811 }
812
813 ret = usb_submit_urb(urb, GFP_ATOMIC);
814}
815
816/* Transmit callback funtion. */
817static void mcs_send_irq(struct urb *urb, struct pt_regs *regs)
818{
819 struct mcs_cb *mcs = urb->context;
820 struct net_device *ndev = mcs->netdev;
821
822 if (unlikely(mcs->new_speed))
823 schedule_work(&mcs->work);
824 else
825 netif_wake_queue(ndev);
826}
827
828/* Transmit callback funtion. */
829static int mcs_hard_xmit(struct sk_buff *skb, struct net_device *ndev)
830{
831 unsigned long flags;
832 struct mcs_cb *mcs;
833 int wraplen;
834 int ret = 0;
835
836
837 if (skb == NULL || ndev == NULL)
838 return -EINVAL;
839
840 netif_stop_queue(ndev);
841 mcs = netdev_priv(ndev);
842
843 spin_lock_irqsave(&mcs->lock, flags);
844
845 mcs->new_speed = irda_get_next_speed(skb);
846 if (likely(mcs->new_speed == mcs->speed))
847 mcs->new_speed = 0;
848
849 /* SIR speed */
850 if(mcs->speed < 576000) {
851 wraplen = mcs_wrap_sir_skb(skb, mcs->out_buf);
852 }
853 /* MIR speed */
854 else if(mcs->speed == 576000 || mcs->speed == 1152000) {
855 wraplen = mcs_wrap_mir_skb(skb, mcs->out_buf);
856 }
857 /* FIR speed */
858 else {
859 wraplen = mcs_wrap_fir_skb(skb, mcs->out_buf);
860 }
861 usb_fill_bulk_urb(mcs->tx_urb, mcs->usbdev,
862 usb_sndbulkpipe(mcs->usbdev, mcs->ep_out),
863 mcs->out_buf, wraplen, mcs_send_irq, mcs);
864
865 if ((ret = usb_submit_urb(mcs->tx_urb, GFP_ATOMIC))) {
866 IRDA_ERROR("failed tx_urb: %d", ret);
867 switch (ret) {
868 case -ENODEV:
869 case -EPIPE:
870 break;
871 default:
872 mcs->stats.tx_errors++;
873 netif_start_queue(ndev);
874 }
875 } else {
876 mcs->stats.tx_packets++;
877 mcs->stats.tx_bytes += skb->len;
878 }
879
880 dev_kfree_skb(skb);
881 spin_unlock_irqrestore(&mcs->lock, flags);
882 return ret;
883}
884
885/*
886 * This function is called by the USB subsystem for each new device in the
887 * system. Need to verify the device and if it is, then start handling it.
888 */
889static int mcs_probe(struct usb_interface *intf,
890 const struct usb_device_id *id)
891{
892 struct usb_device *udev = interface_to_usbdev(intf);
893 struct net_device *ndev = NULL;
894 struct mcs_cb *mcs;
895 int ret = -ENOMEM;
896
897 ndev = alloc_irdadev(sizeof(*mcs));
898 if (!ndev)
899 goto error1;
900
901 IRDA_DEBUG(1, "MCS7780 USB-IrDA bridge found at %d.", udev->devnum);
902
903 /* what is it realy for? */
904 SET_MODULE_OWNER(ndev);
905 SET_NETDEV_DEV(ndev, &intf->dev);
906
907 ret = usb_reset_configuration(udev);
908 if (ret != 0) {
909 IRDA_ERROR("mcs7780: usb reset configuration failed");
910 goto error2;
911 }
912
913 mcs = netdev_priv(ndev);
914 mcs->usbdev = udev;
915 mcs->netdev = ndev;
916 spin_lock_init(&mcs->lock);
917
918 /* Initialize QoS for this device */
919 irda_init_max_qos_capabilies(&mcs->qos);
920
921 /* That's the Rx capability. */
922 mcs->qos.baud_rate.bits &=
923 IR_2400 | IR_9600 | IR_19200 | IR_38400 | IR_57600 | IR_115200
924 | IR_576000 | IR_1152000 | (IR_4000000 << 8);
925
926
927 mcs->qos.min_turn_time.bits &= qos_mtt_bits;
928 irda_qos_bits_to_value(&mcs->qos);
929
930 /* Speed change work initialisation*/
931 INIT_WORK(&mcs->work, mcs_speed_work, mcs);
932
933 /* Override the network functions we need to use */
934 ndev->hard_start_xmit = mcs_hard_xmit;
935 ndev->open = mcs_net_open;
936 ndev->stop = mcs_net_close;
937 ndev->get_stats = mcs_net_get_stats;
938 ndev->do_ioctl = mcs_net_ioctl;
939
940 if (!intf->cur_altsetting)
941 goto error2;
942
943 ret = mcs_find_endpoints(mcs, intf->cur_altsetting->endpoint,
944 intf->cur_altsetting->desc.bNumEndpoints);
945 if (!ret) {
946 ret = -ENODEV;
947 goto error2;
948 }
949
950 ret = register_netdev(ndev);
951 if (ret != 0)
952 goto error2;
953
954 IRDA_DEBUG(1, "IrDA: Registered MosChip MCS7780 device as %s",
955 ndev->name);
956
957 mcs->transceiver_type = transceiver_type;
958 mcs->sir_tweak = sir_tweak;
959 mcs->receive_mode = receive_mode;
960
961 usb_set_intfdata(intf, mcs);
962 return 0;
963
964 error2:
965 free_netdev(ndev);
966
967 error1:
968 return ret;
969}
970
971/* The current device is removed, the USB layer tells us to shut down. */
972static void mcs_disconnect(struct usb_interface *intf)
973{
974 struct mcs_cb *mcs = usb_get_intfdata(intf);
975
976 if (!mcs)
977 return;
978
979 flush_scheduled_work();
980
981 unregister_netdev(mcs->netdev);
982 free_netdev(mcs->netdev);
983
984 usb_set_intfdata(intf, NULL);
985 IRDA_DEBUG(0, "MCS7780 now disconnected.");
986}
987
988/* Module insertion */
989static int __init mcs_init(void)
990{
991 int result;
992
993 /* register this driver with the USB subsystem */
994 result = usb_register(&mcs_driver);
995 if (result)
996 IRDA_ERROR("usb_register failed. Error number %d", result);
997
998 return result;
999}
1000module_init(mcs_init);
1001
1002/* Module removal */
1003static void __exit mcs_exit(void)
1004{
1005 /* deregister this driver with the USB subsystem */
1006 usb_deregister(&mcs_driver);
1007}
1008module_exit(mcs_exit);
1009
diff --git a/drivers/net/irda/mcs7780.h b/drivers/net/irda/mcs7780.h
new file mode 100644
index 00000000000..1a723d725c2
--- /dev/null
+++ b/drivers/net/irda/mcs7780.h
@@ -0,0 +1,167 @@
1/*****************************************************************************
2*
3* Filename: mcs7780.h
4* Version: 0.2-alpha
5* Description: Irda MosChip USB Dongle
6* Status: Experimental
7* Authors: Lukasz Stelmach <stlman@poczta.fm>
8* Brian Pugh <bpugh@cs.pdx.edu>
9*
10* Copyright (C) 2005, Lukasz Stelmach <stlman@poczta.fm>
11* Copyright (C) 2005, Brian Pugh <bpugh@cs.pdx.edu>
12*
13* This program is free software; you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation; either version 2 of the License, or
16* (at your option) any later version.
17*
18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details.
22*
23* You should have received a copy of the GNU General Public License
24* along with this program; if not, write to the Free Software
25* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*
27*****************************************************************************/
28#ifndef _MCS7780_H
29#define _MCS7780_H
30
31#define MCS_MODE_SIR 0
32#define MCS_MODE_MIR 1
33#define MCS_MODE_FIR 2
34
35#define MCS_CTRL_TIMEOUT 500
36#define MCS_XMIT_TIMEOUT 500
37/* Possible transceiver types */
38#define MCS_TSC_VISHAY 0 /* Vishay TFD, default choice */
39#define MCS_TSC_AGILENT 1 /* Agilent 3602/3600 */
40#define MCS_TSC_SHARP 2 /* Sharp GP2W1000YP */
41
42/* Requests */
43#define MCS_RD_RTYPE 0xC0
44#define MCS_WR_RTYPE 0x40
45#define MCS_RDREQ 0x0F
46#define MCS_WRREQ 0x0E
47
48/* Register 0x00 */
49#define MCS_MODE_REG 0
50#define MCS_FIR ((__u16)0x0001)
51#define MCS_SIR16US ((__u16)0x0002)
52#define MCS_BBTG ((__u16)0x0004)
53#define MCS_ASK ((__u16)0x0008)
54#define MCS_PARITY ((__u16)0x0010)
55
56/* SIR/MIR speed constants */
57#define MCS_SPEED_SHIFT 5
58#define MCS_SPEED_MASK ((__u16)0x00E0)
59#define MCS_SPEED(x) ((x & MCS_SPEED_MASK) >> MCS_SPEED_SHIFT)
60#define MCS_SPEED_2400 ((0 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
61#define MCS_SPEED_9600 ((1 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
62#define MCS_SPEED_19200 ((2 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
63#define MCS_SPEED_38400 ((3 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
64#define MCS_SPEED_57600 ((4 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
65#define MCS_SPEED_115200 ((5 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
66#define MCS_SPEED_576000 ((6 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
67#define MCS_SPEED_1152000 ((7 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
68
69#define MCS_PLLPWDN ((__u16)0x0100)
70#define MCS_DRIVER ((__u16)0x0200)
71#define MCS_DTD ((__u16)0x0400)
72#define MCS_DIR ((__u16)0x0800)
73#define MCS_SIPEN ((__u16)0x1000)
74#define MCS_SENDSIP ((__u16)0x2000)
75#define MCS_CHGDIR ((__u16)0x4000)
76#define MCS_RESET ((__u16)0x8000)
77
78/* Register 0x02 */
79#define MCS_XCVR_REG 2
80#define MCS_MODE0 ((__u16)0x0001)
81#define MCS_STFIR ((__u16)0x0002)
82#define MCS_XCVR_CONF ((__u16)0x0004)
83#define MCS_RXFAST ((__u16)0x0008)
84/* TXCUR [6:4] */
85#define MCS_TXCUR_SHIFT 4
86#define MCS_TXCUR_MASK ((__u16)0x0070)
87#define MCS_TXCUR(x) ((x & MCS_TXCUR_MASK) >> MCS_TXCUR_SHIFT)
88#define MCS_SETTXCUR(x,y) \
89 ((x & ~MCS_TXCUR_MASK) | (y << MCS_TXCUR_SHIFT) & MCS_TXCUR_MASK)
90
91#define MCS_MODE1 ((__u16)0x0080)
92#define MCS_SMODE0 ((__u16)0x0100)
93#define MCS_SMODE1 ((__u16)0x0200)
94#define MCS_INVTX ((__u16)0x0400)
95#define MCS_INVRX ((__u16)0x0800)
96
97#define MCS_MINRXPW_REG 4
98
99#define MCS_RESV_REG 7
100#define MCS_IRINTX ((__u16)0x0001)
101#define MCS_IRINRX ((__u16)0x0002)
102
103struct mcs_cb {
104 struct usb_device *usbdev; /* init: probe_irda */
105 struct net_device *netdev; /* network layer */
106 struct irlap_cb *irlap; /* The link layer we are binded to */
107 struct net_device_stats stats; /* network statistics */
108 struct qos_info qos;
109 unsigned int speed; /* Current speed */
110 unsigned int new_speed; /* new speed */
111
112 struct work_struct work; /* Change speed work */
113
114 struct sk_buff *tx_pending;
115 char in_buf[4096]; /* transmit/receive buffer */
116 char out_buf[4096]; /* transmit/receive buffer */
117 __u8 *fifo_status;
118
119 iobuff_t rx_buff; /* receive unwrap state machine */
120 struct timeval rx_time;
121 spinlock_t lock;
122 int receiving;
123
124 __u8 ep_in;
125 __u8 ep_out;
126
127 struct urb *rx_urb;
128 struct urb *tx_urb;
129
130 int transceiver_type;
131 int sir_tweak;
132 int receive_mode;
133};
134
135static int mcs_set_reg(struct mcs_cb *mcs, __u16 reg, __u16 val);
136static int mcs_get_reg(struct mcs_cb *mcs, __u16 reg, __u16 * val);
137
138static inline int mcs_setup_transceiver_vishay(struct mcs_cb *mcs);
139static inline int mcs_setup_transceiver_agilent(struct mcs_cb *mcs);
140static inline int mcs_setup_transceiver_sharp(struct mcs_cb *mcs);
141static inline int mcs_setup_transceiver(struct mcs_cb *mcs);
142static inline int mcs_wrap_sir_skb(struct sk_buff *skb, __u8 * buf);
143static unsigned mcs_wrap_fir_skb(const struct sk_buff *skb, __u8 *buf);
144static unsigned mcs_wrap_mir_skb(const struct sk_buff *skb, __u8 *buf);
145static void mcs_unwrap_mir(struct mcs_cb *mcs, __u8 *buf, int len);
146static void mcs_unwrap_fir(struct mcs_cb *mcs, __u8 *buf, int len);
147static inline int mcs_setup_urbs(struct mcs_cb *mcs);
148static inline int mcs_receive_start(struct mcs_cb *mcs);
149static inline int mcs_find_endpoints(struct mcs_cb *mcs,
150 struct usb_host_endpoint *ep, int epnum);
151
152static int mcs_speed_change(struct mcs_cb *mcs);
153
154static int mcs_net_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd);
155static int mcs_net_close(struct net_device *netdev);
156static int mcs_net_open(struct net_device *netdev);
157static struct net_device_stats *mcs_net_get_stats(struct net_device *netdev);
158
159static void mcs_receive_irq(struct urb *urb, struct pt_regs *regs);
160static void mcs_send_irq(struct urb *urb, struct pt_regs *regs);
161static int mcs_hard_xmit(struct sk_buff *skb, struct net_device *netdev);
162
163static int mcs_probe(struct usb_interface *intf,
164 const struct usb_device_id *id);
165static void mcs_disconnect(struct usb_interface *intf);
166
167#endif /* _MCS7780_H */
diff --git a/drivers/net/irda/stir4200.c b/drivers/net/irda/stir4200.c
index 31867e4b891..d61b208b52a 100644
--- a/drivers/net/irda/stir4200.c
+++ b/drivers/net/irda/stir4200.c
@@ -50,6 +50,7 @@
50#include <linux/delay.h> 50#include <linux/delay.h>
51#include <linux/usb.h> 51#include <linux/usb.h>
52#include <linux/crc32.h> 52#include <linux/crc32.h>
53#include <linux/kthread.h>
53#include <net/irda/irda.h> 54#include <net/irda/irda.h>
54#include <net/irda/irlap.h> 55#include <net/irda/irlap.h>
55#include <net/irda/irda_device.h> 56#include <net/irda/irda_device.h>
@@ -173,9 +174,7 @@ struct stir_cb {
173 struct qos_info qos; 174 struct qos_info qos;
174 unsigned speed; /* Current speed */ 175 unsigned speed; /* Current speed */
175 176
176 wait_queue_head_t thr_wait; /* transmit thread wakeup */ 177 struct task_struct *thread; /* transmit thread */
177 struct completion thr_exited;
178 pid_t thr_pid;
179 178
180 struct sk_buff *tx_pending; 179 struct sk_buff *tx_pending;
181 void *io_buf; /* transmit/receive buffer */ 180 void *io_buf; /* transmit/receive buffer */
@@ -577,7 +576,7 @@ static int stir_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
577 SKB_LINEAR_ASSERT(skb); 576 SKB_LINEAR_ASSERT(skb);
578 577
579 skb = xchg(&stir->tx_pending, skb); 578 skb = xchg(&stir->tx_pending, skb);
580 wake_up(&stir->thr_wait); 579 wake_up_process(stir->thread);
581 580
582 /* this should never happen unless stop/wakeup problem */ 581 /* this should never happen unless stop/wakeup problem */
583 if (unlikely(skb)) { 582 if (unlikely(skb)) {
@@ -753,13 +752,7 @@ static int stir_transmit_thread(void *arg)
753 struct net_device *dev = stir->netdev; 752 struct net_device *dev = stir->netdev;
754 struct sk_buff *skb; 753 struct sk_buff *skb;
755 754
756 daemonize("%s", dev->name); 755 while (!kthread_should_stop()) {
757 allow_signal(SIGTERM);
758
759 while (netif_running(dev)
760 && netif_device_present(dev)
761 && !signal_pending(current))
762 {
763#ifdef CONFIG_PM 756#ifdef CONFIG_PM
764 /* if suspending, then power off and wait */ 757 /* if suspending, then power off and wait */
765 if (unlikely(freezing(current))) { 758 if (unlikely(freezing(current))) {
@@ -813,10 +806,11 @@ static int stir_transmit_thread(void *arg)
813 } 806 }
814 807
815 /* sleep if nothing to send */ 808 /* sleep if nothing to send */
816 wait_event_interruptible(stir->thr_wait, stir->tx_pending); 809 set_current_state(TASK_INTERRUPTIBLE);
817 } 810 schedule();
818 811
819 complete_and_exit (&stir->thr_exited, 0); 812 }
813 return 0;
820} 814}
821 815
822 816
@@ -859,7 +853,7 @@ static void stir_rcv_irq(struct urb *urb, struct pt_regs *regs)
859 warn("%s: usb receive submit error: %d", 853 warn("%s: usb receive submit error: %d",
860 stir->netdev->name, err); 854 stir->netdev->name, err);
861 stir->receiving = 0; 855 stir->receiving = 0;
862 wake_up(&stir->thr_wait); 856 wake_up_process(stir->thread);
863 } 857 }
864} 858}
865 859
@@ -928,10 +922,10 @@ static int stir_net_open(struct net_device *netdev)
928 } 922 }
929 923
930 /** Start kernel thread for transmit. */ 924 /** Start kernel thread for transmit. */
931 stir->thr_pid = kernel_thread(stir_transmit_thread, stir, 925 stir->thread = kthread_run(stir_transmit_thread, stir,
932 CLONE_FS|CLONE_FILES); 926 "%s", stir->netdev->name);
933 if (stir->thr_pid < 0) { 927 if (IS_ERR(stir->thread)) {
934 err = stir->thr_pid; 928 err = PTR_ERR(stir->thread);
935 err("stir4200: unable to start kernel thread"); 929 err("stir4200: unable to start kernel thread");
936 goto err_out6; 930 goto err_out6;
937 } 931 }
@@ -968,8 +962,7 @@ static int stir_net_close(struct net_device *netdev)
968 netif_stop_queue(netdev); 962 netif_stop_queue(netdev);
969 963
970 /* Kill transmit thread */ 964 /* Kill transmit thread */
971 kill_proc(stir->thr_pid, SIGTERM, 1); 965 kthread_stop(stir->thread);
972 wait_for_completion(&stir->thr_exited);
973 kfree(stir->fifo_status); 966 kfree(stir->fifo_status);
974 967
975 /* Mop up receive urb's */ 968 /* Mop up receive urb's */
@@ -1084,9 +1077,6 @@ static int stir_probe(struct usb_interface *intf,
1084 stir->qos.min_turn_time.bits &= qos_mtt_bits; 1077 stir->qos.min_turn_time.bits &= qos_mtt_bits;
1085 irda_qos_bits_to_value(&stir->qos); 1078 irda_qos_bits_to_value(&stir->qos);
1086 1079
1087 init_completion (&stir->thr_exited);
1088 init_waitqueue_head (&stir->thr_wait);
1089
1090 /* Override the network functions we need to use */ 1080 /* Override the network functions we need to use */
1091 net->hard_start_xmit = stir_hard_xmit; 1081 net->hard_start_xmit = stir_hard_xmit;
1092 net->open = stir_net_open; 1082 net->open = stir_net_open;
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index 97a49e0be76..d70b9e8d6e6 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -959,7 +959,7 @@ static int vlsi_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
959 || (now.tv_sec==ready.tv_sec && now.tv_usec>=ready.tv_usec)) 959 || (now.tv_sec==ready.tv_sec && now.tv_usec>=ready.tv_usec))
960 break; 960 break;
961 udelay(100); 961 udelay(100);
962 /* must not sleep here - we are called under xmit_lock! */ 962 /* must not sleep here - called under netif_tx_lock! */
963 } 963 }
964 } 964 }
965 965