w83977af_ir.c 33 KB

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