w83977af_ir.c 32 KB

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