w83977af_ir.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. /*********************************************************************
  2. *
  3. * Filename: w83977af_ir.c
  4. * Version: 1.0
  5. * Description: FIR driver for the Winbond W83977AF Super I/O chip
  6. * Status: Experimental.
  7. * Author: Paul VanderSpek
  8. * Created at: Wed Nov 4 11:46:16 1998
  9. * Modified at: Fri Jan 28 12:10:59 2000
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>
  13. * Copyright (c) 1998-1999 Rebel.com
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * Neither Paul VanderSpek nor Rebel.com admit liability nor provide
  21. * warranty for any of this software. This material is provided "AS-IS"
  22. * and at no charge.
  23. *
  24. * If you find bugs in this file, its very likely that the same bug
  25. * will also be in pc87108.c since the implementations are quite
  26. * similar.
  27. *
  28. * Notice that all functions that needs to access the chip in _any_
  29. * way, must save BSR register on entry, and restore it on exit.
  30. * It is _very_ important to follow this policy!
  31. *
  32. * __u8 bank;
  33. *
  34. * bank = inb( iobase+BSR);
  35. *
  36. * do_your_stuff_here();
  37. *
  38. * outb( bank, iobase+BSR);
  39. *
  40. ********************************************************************/
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/types.h>
  44. #include <linux/skbuff.h>
  45. #include <linux/netdevice.h>
  46. #include <linux/ioport.h>
  47. #include <linux/delay.h>
  48. #include <linux/slab.h>
  49. #include <linux/init.h>
  50. #include <linux/rtnetlink.h>
  51. #include <linux/dma-mapping.h>
  52. #include <asm/io.h>
  53. #include <asm/dma.h>
  54. #include <asm/byteorder.h>
  55. #include <net/irda/irda.h>
  56. #include <net/irda/wrapper.h>
  57. #include <net/irda/irda_device.h>
  58. #include "w83977af.h"
  59. #include "w83977af_ir.h"
  60. #ifdef CONFIG_ARCH_NETWINDER /* Adjust to NetWinder differences */
  61. #undef CONFIG_NETWINDER_TX_DMA_PROBLEMS /* Not needed */
  62. #define CONFIG_NETWINDER_RX_DMA_PROBLEMS /* Must have this one! */
  63. #endif
  64. #undef CONFIG_USE_INTERNAL_TIMER /* Just cannot make that timer work */
  65. #define CONFIG_USE_W977_PNP /* Currently needed */
  66. #define PIO_MAX_SPEED 115200
  67. static char *driver_name = "w83977af_ir";
  68. static int qos_mtt_bits = 0x07; /* 1 ms or more */
  69. #define CHIP_IO_EXTENT 8
  70. static unsigned int io[] = { 0x180, ~0, ~0, ~0 };
  71. #ifdef CONFIG_ARCH_NETWINDER /* Adjust to NetWinder differences */
  72. static unsigned int irq[] = { 6, 0, 0, 0 };
  73. #else
  74. static unsigned int irq[] = { 11, 0, 0, 0 };
  75. #endif
  76. static unsigned int dma[] = { 1, 0, 0, 0 };
  77. static unsigned int efbase[] = { W977_EFIO_BASE, W977_EFIO2_BASE };
  78. static unsigned int efio = W977_EFIO_BASE;
  79. static struct w83977af_ir *dev_self[] = { NULL, NULL, NULL, NULL};
  80. /* Some prototypes */
  81. static int w83977af_open(int i, unsigned int iobase, unsigned int irq,
  82. unsigned int dma);
  83. static int w83977af_close(struct w83977af_ir *self);
  84. static int w83977af_probe(int iobase, int irq, int dma);
  85. static int w83977af_dma_receive(struct w83977af_ir *self);
  86. static int w83977af_dma_receive_complete(struct w83977af_ir *self);
  87. static int w83977af_hard_xmit(struct sk_buff *skb, struct net_device *dev);
  88. static int w83977af_pio_write(int iobase, __u8 *buf, int len, int fifo_size);
  89. static void w83977af_dma_write(struct w83977af_ir *self, int iobase);
  90. static void w83977af_change_speed(struct w83977af_ir *self, __u32 speed);
  91. static int w83977af_is_receiving(struct w83977af_ir *self);
  92. static int w83977af_net_open(struct net_device *dev);
  93. static int w83977af_net_close(struct net_device *dev);
  94. static int w83977af_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  95. /*
  96. * Function w83977af_init ()
  97. *
  98. * Initialize chip. Just try to find out how many chips we are dealing with
  99. * and where they are
  100. */
  101. static int __init w83977af_init(void)
  102. {
  103. int i;
  104. IRDA_DEBUG(0, "%s()\n", __func__ );
  105. for (i=0; (io[i] < 2000) && (i < ARRAY_SIZE(dev_self)); i++) {
  106. if (w83977af_open(i, io[i], irq[i], dma[i]) == 0)
  107. return 0;
  108. }
  109. return -ENODEV;
  110. }
  111. /*
  112. * Function w83977af_cleanup ()
  113. *
  114. * Close all configured chips
  115. *
  116. */
  117. static void __exit w83977af_cleanup(void)
  118. {
  119. int i;
  120. IRDA_DEBUG(4, "%s()\n", __func__ );
  121. for (i=0; i < ARRAY_SIZE(dev_self); i++) {
  122. if (dev_self[i])
  123. w83977af_close(dev_self[i]);
  124. }
  125. }
  126. /*
  127. * Function w83977af_open (iobase, irq)
  128. *
  129. * Open driver instance
  130. *
  131. */
  132. static int w83977af_open(int i, unsigned int iobase, unsigned int irq,
  133. unsigned int dma)
  134. {
  135. struct net_device *dev;
  136. struct w83977af_ir *self;
  137. int err;
  138. IRDA_DEBUG(0, "%s()\n", __func__ );
  139. /* Lock the port that we need */
  140. if (!request_region(iobase, CHIP_IO_EXTENT, driver_name)) {
  141. IRDA_DEBUG(0, "%s(), can't get iobase of 0x%03x\n",
  142. __func__ , iobase);
  143. return -ENODEV;
  144. }
  145. if (w83977af_probe(iobase, irq, dma) == -1) {
  146. err = -1;
  147. goto err_out;
  148. }
  149. /*
  150. * Allocate new instance of the driver
  151. */
  152. dev = alloc_irdadev(sizeof(struct w83977af_ir));
  153. if (dev == NULL) {
  154. printk( KERN_ERR "IrDA: Can't allocate memory for "
  155. "IrDA control block!\n");
  156. err = -ENOMEM;
  157. goto err_out;
  158. }
  159. self = netdev_priv(dev);
  160. spin_lock_init(&self->lock);
  161. /* Initialize IO */
  162. self->io.fir_base = iobase;
  163. self->io.irq = irq;
  164. self->io.fir_ext = CHIP_IO_EXTENT;
  165. self->io.dma = dma;
  166. self->io.fifo_size = 32;
  167. /* Initialize QoS for this device */
  168. irda_init_max_qos_capabilies(&self->qos);
  169. /* The only value we must override it the baudrate */
  170. /* FIXME: The HP HDLS-1100 does not support 1152000! */
  171. self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
  172. IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
  173. /* The HP HDLS-1100 needs 1 ms according to the specs */
  174. self->qos.min_turn_time.bits = qos_mtt_bits;
  175. irda_qos_bits_to_value(&self->qos);
  176. /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
  177. self->rx_buff.truesize = 14384;
  178. self->tx_buff.truesize = 4000;
  179. /* Allocate memory if needed */
  180. self->rx_buff.head =
  181. dma_alloc_coherent(NULL, self->rx_buff.truesize,
  182. &self->rx_buff_dma, GFP_KERNEL);
  183. if (self->rx_buff.head == NULL) {
  184. err = -ENOMEM;
  185. goto err_out1;
  186. }
  187. memset(self->rx_buff.head, 0, self->rx_buff.truesize);
  188. self->tx_buff.head =
  189. dma_alloc_coherent(NULL, self->tx_buff.truesize,
  190. &self->tx_buff_dma, GFP_KERNEL);
  191. if (self->tx_buff.head == NULL) {
  192. err = -ENOMEM;
  193. goto err_out2;
  194. }
  195. memset(self->tx_buff.head, 0, self->tx_buff.truesize);
  196. self->rx_buff.in_frame = FALSE;
  197. self->rx_buff.state = OUTSIDE_FRAME;
  198. self->tx_buff.data = self->tx_buff.head;
  199. self->rx_buff.data = self->rx_buff.head;
  200. self->netdev = dev;
  201. /* Override the network functions we need to use */
  202. dev->hard_start_xmit = w83977af_hard_xmit;
  203. dev->open = w83977af_net_open;
  204. dev->stop = w83977af_net_close;
  205. dev->do_ioctl = w83977af_net_ioctl;
  206. err = register_netdev(dev);
  207. if (err) {
  208. IRDA_ERROR("%s(), register_netdevice() failed!\n", __func__);
  209. goto err_out3;
  210. }
  211. IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
  212. /* Need to store self somewhere */
  213. dev_self[i] = self;
  214. return 0;
  215. err_out3:
  216. dma_free_coherent(NULL, self->tx_buff.truesize,
  217. self->tx_buff.head, self->tx_buff_dma);
  218. err_out2:
  219. dma_free_coherent(NULL, self->rx_buff.truesize,
  220. self->rx_buff.head, self->rx_buff_dma);
  221. err_out1:
  222. free_netdev(dev);
  223. err_out:
  224. release_region(iobase, CHIP_IO_EXTENT);
  225. return err;
  226. }
  227. /*
  228. * Function w83977af_close (self)
  229. *
  230. * Close driver instance
  231. *
  232. */
  233. static int w83977af_close(struct w83977af_ir *self)
  234. {
  235. int iobase;
  236. IRDA_DEBUG(0, "%s()\n", __func__ );
  237. iobase = self->io.fir_base;
  238. #ifdef CONFIG_USE_W977_PNP
  239. /* enter PnP configuration mode */
  240. w977_efm_enter(efio);
  241. w977_select_device(W977_DEVICE_IR, efio);
  242. /* Deactivate device */
  243. w977_write_reg(0x30, 0x00, efio);
  244. w977_efm_exit(efio);
  245. #endif /* CONFIG_USE_W977_PNP */
  246. /* Remove netdevice */
  247. unregister_netdev(self->netdev);
  248. /* Release the PORT that this driver is using */
  249. IRDA_DEBUG(0 , "%s(), Releasing Region %03x\n",
  250. __func__ , self->io.fir_base);
  251. release_region(self->io.fir_base, self->io.fir_ext);
  252. if (self->tx_buff.head)
  253. dma_free_coherent(NULL, self->tx_buff.truesize,
  254. self->tx_buff.head, self->tx_buff_dma);
  255. if (self->rx_buff.head)
  256. dma_free_coherent(NULL, self->rx_buff.truesize,
  257. self->rx_buff.head, self->rx_buff_dma);
  258. free_netdev(self->netdev);
  259. return 0;
  260. }
  261. static int w83977af_probe(int iobase, int irq, int dma)
  262. {
  263. int version;
  264. int i;
  265. for (i=0; i < 2; i++) {
  266. IRDA_DEBUG( 0, "%s()\n", __func__ );
  267. #ifdef CONFIG_USE_W977_PNP
  268. /* Enter PnP configuration mode */
  269. w977_efm_enter(efbase[i]);
  270. w977_select_device(W977_DEVICE_IR, efbase[i]);
  271. /* Configure PnP port, IRQ, and DMA channel */
  272. w977_write_reg(0x60, (iobase >> 8) & 0xff, efbase[i]);
  273. w977_write_reg(0x61, (iobase) & 0xff, efbase[i]);
  274. w977_write_reg(0x70, irq, efbase[i]);
  275. #ifdef CONFIG_ARCH_NETWINDER
  276. /* Netwinder uses 1 higher than Linux */
  277. w977_write_reg(0x74, dma+1, efbase[i]);
  278. #else
  279. w977_write_reg(0x74, dma, efbase[i]);
  280. #endif /*CONFIG_ARCH_NETWINDER */
  281. w977_write_reg(0x75, 0x04, efbase[i]); /* Disable Tx DMA */
  282. /* Set append hardware CRC, enable IR bank selection */
  283. w977_write_reg(0xf0, APEDCRC|ENBNKSEL, efbase[i]);
  284. /* Activate device */
  285. w977_write_reg(0x30, 0x01, efbase[i]);
  286. w977_efm_exit(efbase[i]);
  287. #endif /* CONFIG_USE_W977_PNP */
  288. /* Disable Advanced mode */
  289. switch_bank(iobase, SET2);
  290. outb(iobase+2, 0x00);
  291. /* Turn on UART (global) interrupts */
  292. switch_bank(iobase, SET0);
  293. outb(HCR_EN_IRQ, iobase+HCR);
  294. /* Switch to advanced mode */
  295. switch_bank(iobase, SET2);
  296. outb(inb(iobase+ADCR1) | ADCR1_ADV_SL, iobase+ADCR1);
  297. /* Set default IR-mode */
  298. switch_bank(iobase, SET0);
  299. outb(HCR_SIR, iobase+HCR);
  300. /* Read the Advanced IR ID */
  301. switch_bank(iobase, SET3);
  302. version = inb(iobase+AUID);
  303. /* Should be 0x1? */
  304. if (0x10 == (version & 0xf0)) {
  305. efio = efbase[i];
  306. /* Set FIFO size to 32 */
  307. switch_bank(iobase, SET2);
  308. outb(ADCR2_RXFS32|ADCR2_TXFS32, iobase+ADCR2);
  309. /* Set FIFO threshold to TX17, RX16 */
  310. switch_bank(iobase, SET0);
  311. outb(UFR_RXTL|UFR_TXTL|UFR_TXF_RST|UFR_RXF_RST|
  312. UFR_EN_FIFO,iobase+UFR);
  313. /* Receiver frame length */
  314. switch_bank(iobase, SET4);
  315. outb(2048 & 0xff, iobase+6);
  316. outb((2048 >> 8) & 0x1f, iobase+7);
  317. /*
  318. * Init HP HSDL-1100 transceiver.
  319. *
  320. * Set IRX_MSL since we have 2 * receive paths IRRX,
  321. * and IRRXH. Clear IRSL0D since we want IRSL0 * to
  322. * be a input pin used for IRRXH
  323. *
  324. * IRRX pin 37 connected to receiver
  325. * IRTX pin 38 connected to transmitter
  326. * FIRRX pin 39 connected to receiver (IRSL0)
  327. * CIRRX pin 40 connected to pin 37
  328. */
  329. switch_bank(iobase, SET7);
  330. outb(0x40, iobase+7);
  331. IRDA_MESSAGE("W83977AF (IR) driver loaded. "
  332. "Version: 0x%02x\n", version);
  333. return 0;
  334. } else {
  335. /* Try next extented function register address */
  336. IRDA_DEBUG( 0, "%s(), Wrong chip version", __func__ );
  337. }
  338. }
  339. return -1;
  340. }
  341. static void w83977af_change_speed(struct w83977af_ir *self, __u32 speed)
  342. {
  343. int ir_mode = HCR_SIR;
  344. int iobase;
  345. __u8 set;
  346. iobase = self->io.fir_base;
  347. /* Update accounting for new speed */
  348. self->io.speed = speed;
  349. /* Save current bank */
  350. set = inb(iobase+SSR);
  351. /* Disable interrupts */
  352. switch_bank(iobase, SET0);
  353. outb(0, iobase+ICR);
  354. /* Select Set 2 */
  355. switch_bank(iobase, SET2);
  356. outb(0x00, iobase+ABHL);
  357. switch (speed) {
  358. case 9600: outb(0x0c, iobase+ABLL); break;
  359. case 19200: outb(0x06, iobase+ABLL); break;
  360. case 38400: outb(0x03, iobase+ABLL); break;
  361. case 57600: outb(0x02, iobase+ABLL); break;
  362. case 115200: outb(0x01, iobase+ABLL); break;
  363. case 576000:
  364. ir_mode = HCR_MIR_576;
  365. IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __func__ );
  366. break;
  367. case 1152000:
  368. ir_mode = HCR_MIR_1152;
  369. IRDA_DEBUG(0, "%s(), handling baud of 1152000\n", __func__ );
  370. break;
  371. case 4000000:
  372. ir_mode = HCR_FIR;
  373. IRDA_DEBUG(0, "%s(), handling baud of 4000000\n", __func__ );
  374. break;
  375. default:
  376. ir_mode = HCR_FIR;
  377. IRDA_DEBUG(0, "%s(), unknown baud rate of %d\n", __func__ , speed);
  378. break;
  379. }
  380. /* Set speed mode */
  381. switch_bank(iobase, SET0);
  382. outb(ir_mode, iobase+HCR);
  383. /* set FIFO size to 32 */
  384. switch_bank(iobase, SET2);
  385. outb(ADCR2_RXFS32|ADCR2_TXFS32, iobase+ADCR2);
  386. /* set FIFO threshold to TX17, RX16 */
  387. switch_bank(iobase, SET0);
  388. outb(0x00, iobase+UFR); /* Reset */
  389. outb(UFR_EN_FIFO, iobase+UFR); /* First we must enable FIFO */
  390. outb(0xa7, iobase+UFR);
  391. netif_wake_queue(self->netdev);
  392. /* Enable some interrupts so we can receive frames */
  393. switch_bank(iobase, SET0);
  394. if (speed > PIO_MAX_SPEED) {
  395. outb(ICR_EFSFI, iobase+ICR);
  396. w83977af_dma_receive(self);
  397. } else
  398. outb(ICR_ERBRI, iobase+ICR);
  399. /* Restore SSR */
  400. outb(set, iobase+SSR);
  401. }
  402. /*
  403. * Function w83977af_hard_xmit (skb, dev)
  404. *
  405. * Sets up a DMA transfer to send the current frame.
  406. *
  407. */
  408. static int w83977af_hard_xmit(struct sk_buff *skb, struct net_device *dev)
  409. {
  410. struct w83977af_ir *self;
  411. __s32 speed;
  412. int iobase;
  413. __u8 set;
  414. int mtt;
  415. self = netdev_priv(dev);
  416. iobase = self->io.fir_base;
  417. IRDA_DEBUG(4, "%s(%ld), skb->len=%d\n", __func__ , jiffies,
  418. (int) skb->len);
  419. /* Lock transmit buffer */
  420. netif_stop_queue(dev);
  421. /* Check if we need to change the speed */
  422. speed = irda_get_next_speed(skb);
  423. if ((speed != self->io.speed) && (speed != -1)) {
  424. /* Check for empty frame */
  425. if (!skb->len) {
  426. w83977af_change_speed(self, speed);
  427. dev->trans_start = jiffies;
  428. dev_kfree_skb(skb);
  429. return 0;
  430. } else
  431. self->new_speed = speed;
  432. }
  433. /* Save current set */
  434. set = inb(iobase+SSR);
  435. /* Decide if we should use PIO or DMA transfer */
  436. if (self->io.speed > PIO_MAX_SPEED) {
  437. self->tx_buff.data = self->tx_buff.head;
  438. skb_copy_from_linear_data(skb, self->tx_buff.data, skb->len);
  439. self->tx_buff.len = skb->len;
  440. mtt = irda_get_mtt(skb);
  441. #ifdef CONFIG_USE_INTERNAL_TIMER
  442. if (mtt > 50) {
  443. /* Adjust for timer resolution */
  444. mtt /= 1000+1;
  445. /* Setup timer */
  446. switch_bank(iobase, SET4);
  447. outb(mtt & 0xff, iobase+TMRL);
  448. outb((mtt >> 8) & 0x0f, iobase+TMRH);
  449. /* Start timer */
  450. outb(IR_MSL_EN_TMR, iobase+IR_MSL);
  451. self->io.direction = IO_XMIT;
  452. /* Enable timer interrupt */
  453. switch_bank(iobase, SET0);
  454. outb(ICR_ETMRI, iobase+ICR);
  455. } else {
  456. #endif
  457. IRDA_DEBUG(4, "%s(%ld), mtt=%d\n", __func__ , jiffies, mtt);
  458. if (mtt)
  459. udelay(mtt);
  460. /* Enable DMA interrupt */
  461. switch_bank(iobase, SET0);
  462. outb(ICR_EDMAI, iobase+ICR);
  463. w83977af_dma_write(self, iobase);
  464. #ifdef CONFIG_USE_INTERNAL_TIMER
  465. }
  466. #endif
  467. } else {
  468. self->tx_buff.data = self->tx_buff.head;
  469. self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
  470. self->tx_buff.truesize);
  471. /* Add interrupt on tx low level (will fire immediately) */
  472. switch_bank(iobase, SET0);
  473. outb(ICR_ETXTHI, iobase+ICR);
  474. }
  475. dev->trans_start = jiffies;
  476. dev_kfree_skb(skb);
  477. /* Restore set register */
  478. outb(set, iobase+SSR);
  479. return 0;
  480. }
  481. /*
  482. * Function w83977af_dma_write (self, iobase)
  483. *
  484. * Send frame using DMA
  485. *
  486. */
  487. static void w83977af_dma_write(struct w83977af_ir *self, int iobase)
  488. {
  489. __u8 set;
  490. #ifdef CONFIG_NETWINDER_TX_DMA_PROBLEMS
  491. unsigned long flags;
  492. __u8 hcr;
  493. #endif
  494. IRDA_DEBUG(4, "%s(), len=%d\n", __func__ , self->tx_buff.len);
  495. /* Save current set */
  496. set = inb(iobase+SSR);
  497. /* Disable DMA */
  498. switch_bank(iobase, SET0);
  499. outb(inb(iobase+HCR) & ~HCR_EN_DMA, iobase+HCR);
  500. /* Choose transmit DMA channel */
  501. switch_bank(iobase, SET2);
  502. outb(ADCR1_D_CHSW|/*ADCR1_DMA_F|*/ADCR1_ADV_SL, iobase+ADCR1);
  503. #ifdef CONFIG_NETWINDER_TX_DMA_PROBLEMS
  504. spin_lock_irqsave(&self->lock, flags);
  505. disable_dma(self->io.dma);
  506. clear_dma_ff(self->io.dma);
  507. set_dma_mode(self->io.dma, DMA_MODE_READ);
  508. set_dma_addr(self->io.dma, self->tx_buff_dma);
  509. set_dma_count(self->io.dma, self->tx_buff.len);
  510. #else
  511. irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
  512. DMA_MODE_WRITE);
  513. #endif
  514. self->io.direction = IO_XMIT;
  515. /* Enable DMA */
  516. switch_bank(iobase, SET0);
  517. #ifdef CONFIG_NETWINDER_TX_DMA_PROBLEMS
  518. hcr = inb(iobase+HCR);
  519. outb(hcr | HCR_EN_DMA, iobase+HCR);
  520. enable_dma(self->io.dma);
  521. spin_unlock_irqrestore(&self->lock, flags);
  522. #else
  523. outb(inb(iobase+HCR) | HCR_EN_DMA | HCR_TX_WT, iobase+HCR);
  524. #endif
  525. /* Restore set register */
  526. outb(set, iobase+SSR);
  527. }
  528. /*
  529. * Function w83977af_pio_write (iobase, buf, len, fifo_size)
  530. *
  531. *
  532. *
  533. */
  534. static int w83977af_pio_write(int iobase, __u8 *buf, int len, int fifo_size)
  535. {
  536. int actual = 0;
  537. __u8 set;
  538. IRDA_DEBUG(4, "%s()\n", __func__ );
  539. /* Save current bank */
  540. set = inb(iobase+SSR);
  541. switch_bank(iobase, SET0);
  542. if (!(inb_p(iobase+USR) & USR_TSRE)) {
  543. IRDA_DEBUG(4,
  544. "%s(), warning, FIFO not empty yet!\n", __func__ );
  545. fifo_size -= 17;
  546. IRDA_DEBUG(4, "%s(), %d bytes left in tx fifo\n",
  547. __func__ , fifo_size);
  548. }
  549. /* Fill FIFO with current frame */
  550. while ((fifo_size-- > 0) && (actual < len)) {
  551. /* Transmit next byte */
  552. outb(buf[actual++], iobase+TBR);
  553. }
  554. IRDA_DEBUG(4, "%s(), fifo_size %d ; %d sent of %d\n",
  555. __func__ , fifo_size, actual, len);
  556. /* Restore bank */
  557. outb(set, iobase+SSR);
  558. return actual;
  559. }
  560. /*
  561. * Function w83977af_dma_xmit_complete (self)
  562. *
  563. * The transfer of a frame in finished. So do the necessary things
  564. *
  565. *
  566. */
  567. static void w83977af_dma_xmit_complete(struct w83977af_ir *self)
  568. {
  569. int iobase;
  570. __u8 set;
  571. IRDA_DEBUG(4, "%s(%ld)\n", __func__ , jiffies);
  572. IRDA_ASSERT(self != NULL, return;);
  573. iobase = self->io.fir_base;
  574. /* Save current set */
  575. set = inb(iobase+SSR);
  576. /* Disable DMA */
  577. switch_bank(iobase, SET0);
  578. outb(inb(iobase+HCR) & ~HCR_EN_DMA, iobase+HCR);
  579. /* Check for underrrun! */
  580. if (inb(iobase+AUDR) & AUDR_UNDR) {
  581. IRDA_DEBUG(0, "%s(), Transmit underrun!\n", __func__ );
  582. self->netdev->stats.tx_errors++;
  583. self->netdev->stats.tx_fifo_errors++;
  584. /* Clear bit, by writing 1 to it */
  585. outb(AUDR_UNDR, iobase+AUDR);
  586. } else
  587. self->netdev->stats.tx_packets++;
  588. if (self->new_speed) {
  589. w83977af_change_speed(self, self->new_speed);
  590. self->new_speed = 0;
  591. }
  592. /* Unlock tx_buff and request another frame */
  593. /* Tell the network layer, that we want more frames */
  594. netif_wake_queue(self->netdev);
  595. /* Restore set */
  596. outb(set, iobase+SSR);
  597. }
  598. /*
  599. * Function w83977af_dma_receive (self)
  600. *
  601. * Get ready for receiving a frame. The device will initiate a DMA
  602. * if it starts to receive a frame.
  603. *
  604. */
  605. static int w83977af_dma_receive(struct w83977af_ir *self)
  606. {
  607. int iobase;
  608. __u8 set;
  609. #ifdef CONFIG_NETWINDER_RX_DMA_PROBLEMS
  610. unsigned long flags;
  611. __u8 hcr;
  612. #endif
  613. IRDA_ASSERT(self != NULL, return -1;);
  614. IRDA_DEBUG(4, "%s\n", __func__ );
  615. iobase= self->io.fir_base;
  616. /* Save current set */
  617. set = inb(iobase+SSR);
  618. /* Disable DMA */
  619. switch_bank(iobase, SET0);
  620. outb(inb(iobase+HCR) & ~HCR_EN_DMA, iobase+HCR);
  621. /* Choose DMA Rx, DMA Fairness, and Advanced mode */
  622. switch_bank(iobase, SET2);
  623. outb((inb(iobase+ADCR1) & ~ADCR1_D_CHSW)/*|ADCR1_DMA_F*/|ADCR1_ADV_SL,
  624. iobase+ADCR1);
  625. self->io.direction = IO_RECV;
  626. self->rx_buff.data = self->rx_buff.head;
  627. #ifdef CONFIG_NETWINDER_RX_DMA_PROBLEMS
  628. spin_lock_irqsave(&self->lock, flags);
  629. disable_dma(self->io.dma);
  630. clear_dma_ff(self->io.dma);
  631. set_dma_mode(self->io.dma, DMA_MODE_READ);
  632. set_dma_addr(self->io.dma, self->rx_buff_dma);
  633. set_dma_count(self->io.dma, self->rx_buff.truesize);
  634. #else
  635. irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
  636. DMA_MODE_READ);
  637. #endif
  638. /*
  639. * Reset Rx FIFO. This will also flush the ST_FIFO, it's very
  640. * important that we don't reset the Tx FIFO since it might not
  641. * be finished transmitting yet
  642. */
  643. switch_bank(iobase, SET0);
  644. outb(UFR_RXTL|UFR_TXTL|UFR_RXF_RST|UFR_EN_FIFO, iobase+UFR);
  645. self->st_fifo.len = self->st_fifo.tail = self->st_fifo.head = 0;
  646. /* Enable DMA */
  647. switch_bank(iobase, SET0);
  648. #ifdef CONFIG_NETWINDER_RX_DMA_PROBLEMS
  649. hcr = inb(iobase+HCR);
  650. outb(hcr | HCR_EN_DMA, iobase+HCR);
  651. enable_dma(self->io.dma);
  652. spin_unlock_irqrestore(&self->lock, flags);
  653. #else
  654. outb(inb(iobase+HCR) | HCR_EN_DMA, iobase+HCR);
  655. #endif
  656. /* Restore set */
  657. outb(set, iobase+SSR);
  658. return 0;
  659. }
  660. /*
  661. * Function w83977af_receive_complete (self)
  662. *
  663. * Finished with receiving a frame
  664. *
  665. */
  666. static int w83977af_dma_receive_complete(struct w83977af_ir *self)
  667. {
  668. struct sk_buff *skb;
  669. struct st_fifo *st_fifo;
  670. int len;
  671. int iobase;
  672. __u8 set;
  673. __u8 status;
  674. IRDA_DEBUG(4, "%s\n", __func__ );
  675. st_fifo = &self->st_fifo;
  676. iobase = self->io.fir_base;
  677. /* Save current set */
  678. set = inb(iobase+SSR);
  679. iobase = self->io.fir_base;
  680. /* Read status FIFO */
  681. switch_bank(iobase, SET5);
  682. while ((status = inb(iobase+FS_FO)) & FS_FO_FSFDR) {
  683. st_fifo->entries[st_fifo->tail].status = status;
  684. st_fifo->entries[st_fifo->tail].len = inb(iobase+RFLFL);
  685. st_fifo->entries[st_fifo->tail].len |= inb(iobase+RFLFH) << 8;
  686. st_fifo->tail++;
  687. st_fifo->len++;
  688. }
  689. while (st_fifo->len) {
  690. /* Get first entry */
  691. status = st_fifo->entries[st_fifo->head].status;
  692. len = st_fifo->entries[st_fifo->head].len;
  693. st_fifo->head++;
  694. st_fifo->len--;
  695. /* Check for errors */
  696. if (status & FS_FO_ERR_MSK) {
  697. if (status & FS_FO_LST_FR) {
  698. /* Add number of lost frames to stats */
  699. self->netdev->stats.rx_errors += len;
  700. } else {
  701. /* Skip frame */
  702. self->netdev->stats.rx_errors++;
  703. self->rx_buff.data += len;
  704. if (status & FS_FO_MX_LEX)
  705. self->netdev->stats.rx_length_errors++;
  706. if (status & FS_FO_PHY_ERR)
  707. self->netdev->stats.rx_frame_errors++;
  708. if (status & FS_FO_CRC_ERR)
  709. self->netdev->stats.rx_crc_errors++;
  710. }
  711. /* The errors below can be reported in both cases */
  712. if (status & FS_FO_RX_OV)
  713. self->netdev->stats.rx_fifo_errors++;
  714. if (status & FS_FO_FSF_OV)
  715. self->netdev->stats.rx_fifo_errors++;
  716. } else {
  717. /* Check if we have transferred all data to memory */
  718. switch_bank(iobase, SET0);
  719. if (inb(iobase+USR) & USR_RDR) {
  720. #ifdef CONFIG_USE_INTERNAL_TIMER
  721. /* Put this entry back in fifo */
  722. st_fifo->head--;
  723. st_fifo->len++;
  724. st_fifo->entries[st_fifo->head].status = status;
  725. st_fifo->entries[st_fifo->head].len = len;
  726. /* Restore set register */
  727. outb(set, iobase+SSR);
  728. return FALSE; /* I'll be back! */
  729. #else
  730. udelay(80); /* Should be enough!? */
  731. #endif
  732. }
  733. skb = dev_alloc_skb(len+1);
  734. if (skb == NULL) {
  735. printk(KERN_INFO
  736. "%s(), memory squeeze, dropping frame.\n", __func__);
  737. /* Restore set register */
  738. outb(set, iobase+SSR);
  739. return FALSE;
  740. }
  741. /* Align to 20 bytes */
  742. skb_reserve(skb, 1);
  743. /* Copy frame without CRC */
  744. if (self->io.speed < 4000000) {
  745. skb_put(skb, len-2);
  746. skb_copy_to_linear_data(skb,
  747. self->rx_buff.data,
  748. len - 2);
  749. } else {
  750. skb_put(skb, len-4);
  751. skb_copy_to_linear_data(skb,
  752. self->rx_buff.data,
  753. len - 4);
  754. }
  755. /* Move to next frame */
  756. self->rx_buff.data += len;
  757. self->netdev->stats.rx_packets++;
  758. skb->dev = self->netdev;
  759. skb_reset_mac_header(skb);
  760. skb->protocol = htons(ETH_P_IRDA);
  761. netif_rx(skb);
  762. }
  763. }
  764. /* Restore set register */
  765. outb(set, iobase+SSR);
  766. return TRUE;
  767. }
  768. /*
  769. * Function pc87108_pio_receive (self)
  770. *
  771. * Receive all data in receiver FIFO
  772. *
  773. */
  774. static void w83977af_pio_receive(struct w83977af_ir *self)
  775. {
  776. __u8 byte = 0x00;
  777. int iobase;
  778. IRDA_DEBUG(4, "%s()\n", __func__ );
  779. IRDA_ASSERT(self != NULL, return;);
  780. iobase = self->io.fir_base;
  781. /* Receive all characters in Rx FIFO */
  782. do {
  783. byte = inb(iobase+RBR);
  784. async_unwrap_char(self->netdev, &self->netdev->stats, &self->rx_buff,
  785. byte);
  786. } while (inb(iobase+USR) & USR_RDR); /* Data available */
  787. }
  788. /*
  789. * Function w83977af_sir_interrupt (self, eir)
  790. *
  791. * Handle SIR interrupt
  792. *
  793. */
  794. static __u8 w83977af_sir_interrupt(struct w83977af_ir *self, int isr)
  795. {
  796. int actual;
  797. __u8 new_icr = 0;
  798. __u8 set;
  799. int iobase;
  800. IRDA_DEBUG(4, "%s(), isr=%#x\n", __func__ , isr);
  801. iobase = self->io.fir_base;
  802. /* Transmit FIFO low on data */
  803. if (isr & ISR_TXTH_I) {
  804. /* Write data left in transmit buffer */
  805. actual = w83977af_pio_write(self->io.fir_base,
  806. self->tx_buff.data,
  807. self->tx_buff.len,
  808. self->io.fifo_size);
  809. self->tx_buff.data += actual;
  810. self->tx_buff.len -= actual;
  811. self->io.direction = IO_XMIT;
  812. /* Check if finished */
  813. if (self->tx_buff.len > 0) {
  814. new_icr |= ICR_ETXTHI;
  815. } else {
  816. set = inb(iobase+SSR);
  817. switch_bank(iobase, SET0);
  818. outb(AUDR_SFEND, iobase+AUDR);
  819. outb(set, iobase+SSR);
  820. self->netdev->stats.tx_packets++;
  821. /* Feed me more packets */
  822. netif_wake_queue(self->netdev);
  823. new_icr |= ICR_ETBREI;
  824. }
  825. }
  826. /* Check if transmission has completed */
  827. if (isr & ISR_TXEMP_I) {
  828. /* Check if we need to change the speed? */
  829. if (self->new_speed) {
  830. IRDA_DEBUG(2,
  831. "%s(), Changing speed!\n", __func__ );
  832. w83977af_change_speed(self, self->new_speed);
  833. self->new_speed = 0;
  834. }
  835. /* Turn around and get ready to receive some data */
  836. self->io.direction = IO_RECV;
  837. new_icr |= ICR_ERBRI;
  838. }
  839. /* Rx FIFO threshold or timeout */
  840. if (isr & ISR_RXTH_I) {
  841. w83977af_pio_receive(self);
  842. /* Keep receiving */
  843. new_icr |= ICR_ERBRI;
  844. }
  845. return new_icr;
  846. }
  847. /*
  848. * Function pc87108_fir_interrupt (self, eir)
  849. *
  850. * Handle MIR/FIR interrupt
  851. *
  852. */
  853. static __u8 w83977af_fir_interrupt(struct w83977af_ir *self, int isr)
  854. {
  855. __u8 new_icr = 0;
  856. __u8 set;
  857. int iobase;
  858. iobase = self->io.fir_base;
  859. set = inb(iobase+SSR);
  860. /* End of frame detected in FIFO */
  861. if (isr & (ISR_FEND_I|ISR_FSF_I)) {
  862. if (w83977af_dma_receive_complete(self)) {
  863. /* Wait for next status FIFO interrupt */
  864. new_icr |= ICR_EFSFI;
  865. } else {
  866. /* DMA not finished yet */
  867. /* Set timer value, resolution 1 ms */
  868. switch_bank(iobase, SET4);
  869. outb(0x01, iobase+TMRL); /* 1 ms */
  870. outb(0x00, iobase+TMRH);
  871. /* Start timer */
  872. outb(IR_MSL_EN_TMR, iobase+IR_MSL);
  873. new_icr |= ICR_ETMRI;
  874. }
  875. }
  876. /* Timer finished */
  877. if (isr & ISR_TMR_I) {
  878. /* Disable timer */
  879. switch_bank(iobase, SET4);
  880. outb(0, iobase+IR_MSL);
  881. /* Clear timer event */
  882. /* switch_bank(iobase, SET0); */
  883. /* outb(ASCR_CTE, iobase+ASCR); */
  884. /* Check if this is a TX timer interrupt */
  885. if (self->io.direction == IO_XMIT) {
  886. w83977af_dma_write(self, iobase);
  887. new_icr |= ICR_EDMAI;
  888. } else {
  889. /* Check if DMA has now finished */
  890. w83977af_dma_receive_complete(self);
  891. new_icr |= ICR_EFSFI;
  892. }
  893. }
  894. /* Finished with DMA */
  895. if (isr & ISR_DMA_I) {
  896. w83977af_dma_xmit_complete(self);
  897. /* Check if there are more frames to be transmitted */
  898. /* if (irda_device_txqueue_empty(self)) { */
  899. /* Prepare for receive
  900. *
  901. * ** Netwinder Tx DMA likes that we do this anyway **
  902. */
  903. w83977af_dma_receive(self);
  904. new_icr = ICR_EFSFI;
  905. /* } */
  906. }
  907. /* Restore set */
  908. outb(set, iobase+SSR);
  909. return new_icr;
  910. }
  911. /*
  912. * Function w83977af_interrupt (irq, dev_id, regs)
  913. *
  914. * An interrupt from the chip has arrived. Time to do some work
  915. *
  916. */
  917. static irqreturn_t w83977af_interrupt(int irq, void *dev_id)
  918. {
  919. struct net_device *dev = dev_id;
  920. struct w83977af_ir *self;
  921. __u8 set, icr, isr;
  922. int iobase;
  923. self = netdev_priv(dev);
  924. iobase = self->io.fir_base;
  925. /* Save current bank */
  926. set = inb(iobase+SSR);
  927. switch_bank(iobase, SET0);
  928. icr = inb(iobase+ICR);
  929. isr = inb(iobase+ISR) & icr; /* Mask out the interesting ones */
  930. outb(0, iobase+ICR); /* Disable interrupts */
  931. if (isr) {
  932. /* Dispatch interrupt handler for the current speed */
  933. if (self->io.speed > PIO_MAX_SPEED )
  934. icr = w83977af_fir_interrupt(self, isr);
  935. else
  936. icr = w83977af_sir_interrupt(self, isr);
  937. }
  938. outb(icr, iobase+ICR); /* Restore (new) interrupts */
  939. outb(set, iobase+SSR); /* Restore bank register */
  940. return IRQ_RETVAL(isr);
  941. }
  942. /*
  943. * Function w83977af_is_receiving (self)
  944. *
  945. * Return TRUE is we are currently receiving a frame
  946. *
  947. */
  948. static int w83977af_is_receiving(struct w83977af_ir *self)
  949. {
  950. int status = FALSE;
  951. int iobase;
  952. __u8 set;
  953. IRDA_ASSERT(self != NULL, return FALSE;);
  954. if (self->io.speed > 115200) {
  955. iobase = self->io.fir_base;
  956. /* Check if rx FIFO is not empty */
  957. set = inb(iobase+SSR);
  958. switch_bank(iobase, SET2);
  959. if ((inb(iobase+RXFDTH) & 0x3f) != 0) {
  960. /* We are receiving something */
  961. status = TRUE;
  962. }
  963. outb(set, iobase+SSR);
  964. } else
  965. status = (self->rx_buff.state != OUTSIDE_FRAME);
  966. return status;
  967. }
  968. /*
  969. * Function w83977af_net_open (dev)
  970. *
  971. * Start the device
  972. *
  973. */
  974. static int w83977af_net_open(struct net_device *dev)
  975. {
  976. struct w83977af_ir *self;
  977. int iobase;
  978. char hwname[32];
  979. __u8 set;
  980. IRDA_DEBUG(0, "%s()\n", __func__ );
  981. IRDA_ASSERT(dev != NULL, return -1;);
  982. self = netdev_priv(dev);
  983. IRDA_ASSERT(self != NULL, return 0;);
  984. iobase = self->io.fir_base;
  985. if (request_irq(self->io.irq, w83977af_interrupt, 0, dev->name,
  986. (void *) dev)) {
  987. return -EAGAIN;
  988. }
  989. /*
  990. * Always allocate the DMA channel after the IRQ,
  991. * and clean up on failure.
  992. */
  993. if (request_dma(self->io.dma, dev->name)) {
  994. free_irq(self->io.irq, self);
  995. return -EAGAIN;
  996. }
  997. /* Save current set */
  998. set = inb(iobase+SSR);
  999. /* Enable some interrupts so we can receive frames again */
  1000. switch_bank(iobase, SET0);
  1001. if (self->io.speed > 115200) {
  1002. outb(ICR_EFSFI, iobase+ICR);
  1003. w83977af_dma_receive(self);
  1004. } else
  1005. outb(ICR_ERBRI, iobase+ICR);
  1006. /* Restore bank register */
  1007. outb(set, iobase+SSR);
  1008. /* Ready to play! */
  1009. netif_start_queue(dev);
  1010. /* Give self a hardware name */
  1011. sprintf(hwname, "w83977af @ 0x%03x", self->io.fir_base);
  1012. /*
  1013. * Open new IrLAP layer instance, now that everything should be
  1014. * initialized properly
  1015. */
  1016. self->irlap = irlap_open(dev, &self->qos, hwname);
  1017. return 0;
  1018. }
  1019. /*
  1020. * Function w83977af_net_close (dev)
  1021. *
  1022. * Stop the device
  1023. *
  1024. */
  1025. static int w83977af_net_close(struct net_device *dev)
  1026. {
  1027. struct w83977af_ir *self;
  1028. int iobase;
  1029. __u8 set;
  1030. IRDA_DEBUG(0, "%s()\n", __func__ );
  1031. IRDA_ASSERT(dev != NULL, return -1;);
  1032. self = netdev_priv(dev);
  1033. IRDA_ASSERT(self != NULL, return 0;);
  1034. iobase = self->io.fir_base;
  1035. /* Stop device */
  1036. netif_stop_queue(dev);
  1037. /* Stop and remove instance of IrLAP */
  1038. if (self->irlap)
  1039. irlap_close(self->irlap);
  1040. self->irlap = NULL;
  1041. disable_dma(self->io.dma);
  1042. /* Save current set */
  1043. set = inb(iobase+SSR);
  1044. /* Disable interrupts */
  1045. switch_bank(iobase, SET0);
  1046. outb(0, iobase+ICR);
  1047. free_irq(self->io.irq, dev);
  1048. free_dma(self->io.dma);
  1049. /* Restore bank register */
  1050. outb(set, iobase+SSR);
  1051. return 0;
  1052. }
  1053. /*
  1054. * Function w83977af_net_ioctl (dev, rq, cmd)
  1055. *
  1056. * Process IOCTL commands for this device
  1057. *
  1058. */
  1059. static int w83977af_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1060. {
  1061. struct if_irda_req *irq = (struct if_irda_req *) rq;
  1062. struct w83977af_ir *self;
  1063. unsigned long flags;
  1064. int ret = 0;
  1065. IRDA_ASSERT(dev != NULL, return -1;);
  1066. self = netdev_priv(dev);
  1067. IRDA_ASSERT(self != NULL, return -1;);
  1068. IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__ , dev->name, cmd);
  1069. spin_lock_irqsave(&self->lock, flags);
  1070. switch (cmd) {
  1071. case SIOCSBANDWIDTH: /* Set bandwidth */
  1072. if (!capable(CAP_NET_ADMIN)) {
  1073. ret = -EPERM;
  1074. goto out;
  1075. }
  1076. w83977af_change_speed(self, irq->ifr_baudrate);
  1077. break;
  1078. case SIOCSMEDIABUSY: /* Set media busy */
  1079. if (!capable(CAP_NET_ADMIN)) {
  1080. ret = -EPERM;
  1081. goto out;
  1082. }
  1083. irda_device_set_media_busy(self->netdev, TRUE);
  1084. break;
  1085. case SIOCGRECEIVING: /* Check if we are receiving right now */
  1086. irq->ifr_receiving = w83977af_is_receiving(self);
  1087. break;
  1088. default:
  1089. ret = -EOPNOTSUPP;
  1090. }
  1091. out:
  1092. spin_unlock_irqrestore(&self->lock, flags);
  1093. return ret;
  1094. }
  1095. MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
  1096. MODULE_DESCRIPTION("Winbond W83977AF IrDA Device Driver");
  1097. MODULE_LICENSE("GPL");
  1098. module_param(qos_mtt_bits, int, 0);
  1099. MODULE_PARM_DESC(qos_mtt_bits, "Mimimum Turn Time");
  1100. module_param_array(io, int, NULL, 0);
  1101. MODULE_PARM_DESC(io, "Base I/O addresses");
  1102. module_param_array(irq, int, NULL, 0);
  1103. MODULE_PARM_DESC(irq, "IRQ lines");
  1104. /*
  1105. * Function init_module (void)
  1106. *
  1107. *
  1108. *
  1109. */
  1110. module_init(w83977af_init);
  1111. /*
  1112. * Function cleanup_module (void)
  1113. *
  1114. *
  1115. *
  1116. */
  1117. module_exit(w83977af_cleanup);