ali-ircc.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271
  1. /*********************************************************************
  2. *
  3. * Filename: ali-ircc.h
  4. * Version: 0.5
  5. * Description: Driver for the ALI M1535D and M1543C FIR Controller
  6. * Status: Experimental.
  7. * Author: Benjamin Kong <benjamin_kong@ali.com.tw>
  8. * Created at: 2000/10/16 03:46PM
  9. * Modified at: 2001/1/3 02:55PM
  10. * Modified by: Benjamin Kong <benjamin_kong@ali.com.tw>
  11. * Modified at: 2003/11/6 and support for ALi south-bridge chipsets M1563
  12. * Modified by: Clear Zhang <clear_zhang@ali.com.tw>
  13. *
  14. * Copyright (c) 2000 Benjamin Kong <benjamin_kong@ali.com.tw>
  15. * All Rights Reserved
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. ********************************************************************/
  23. #include <linux/module.h>
  24. #include <linux/gfp.h>
  25. #include <linux/kernel.h>
  26. #include <linux/types.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/ioport.h>
  30. #include <linux/delay.h>
  31. #include <linux/init.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/rtnetlink.h>
  34. #include <linux/serial_reg.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/platform_device.h>
  37. #include <asm/io.h>
  38. #include <asm/dma.h>
  39. #include <asm/byteorder.h>
  40. #include <net/irda/wrapper.h>
  41. #include <net/irda/irda.h>
  42. #include <net/irda/irda_device.h>
  43. #include "ali-ircc.h"
  44. #define CHIP_IO_EXTENT 8
  45. #define BROKEN_DONGLE_ID
  46. #define ALI_IRCC_DRIVER_NAME "ali-ircc"
  47. /* Power Management */
  48. static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state);
  49. static int ali_ircc_resume(struct platform_device *dev);
  50. static struct platform_driver ali_ircc_driver = {
  51. .suspend = ali_ircc_suspend,
  52. .resume = ali_ircc_resume,
  53. .driver = {
  54. .name = ALI_IRCC_DRIVER_NAME,
  55. .owner = THIS_MODULE,
  56. },
  57. };
  58. /* Module parameters */
  59. static int qos_mtt_bits = 0x07; /* 1 ms or more */
  60. /* Use BIOS settions by default, but user may supply module parameters */
  61. static unsigned int io[] = { ~0, ~0, ~0, ~0 };
  62. static unsigned int irq[] = { 0, 0, 0, 0 };
  63. static unsigned int dma[] = { 0, 0, 0, 0 };
  64. static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info);
  65. static int ali_ircc_init_43(ali_chip_t *chip, chipio_t *info);
  66. static int ali_ircc_init_53(ali_chip_t *chip, chipio_t *info);
  67. /* These are the currently known ALi south-bridge chipsets, the only one difference
  68. * is that M1543C doesn't support HP HDSL-3600
  69. */
  70. static ali_chip_t chips[] =
  71. {
  72. { "M1543", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x43, ali_ircc_probe_53, ali_ircc_init_43 },
  73. { "M1535", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x53, ali_ircc_probe_53, ali_ircc_init_53 },
  74. { "M1563", { 0x3f0, 0x370 }, 0x51, 0x23, 0x20, 0x63, ali_ircc_probe_53, ali_ircc_init_53 },
  75. { NULL }
  76. };
  77. /* Max 4 instances for now */
  78. static struct ali_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
  79. /* Dongle Types */
  80. static char *dongle_types[] = {
  81. "TFDS6000",
  82. "HP HSDL-3600",
  83. "HP HSDL-1100",
  84. "No dongle connected",
  85. };
  86. /* Some prototypes */
  87. static int ali_ircc_open(int i, chipio_t *info);
  88. static int ali_ircc_close(struct ali_ircc_cb *self);
  89. static int ali_ircc_setup(chipio_t *info);
  90. static int ali_ircc_is_receiving(struct ali_ircc_cb *self);
  91. static int ali_ircc_net_open(struct net_device *dev);
  92. static int ali_ircc_net_close(struct net_device *dev);
  93. static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  94. static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud);
  95. /* SIR function */
  96. static netdev_tx_t ali_ircc_sir_hard_xmit(struct sk_buff *skb,
  97. struct net_device *dev);
  98. static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self);
  99. static void ali_ircc_sir_receive(struct ali_ircc_cb *self);
  100. static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self);
  101. static int ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
  102. static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
  103. /* FIR function */
  104. static netdev_tx_t ali_ircc_fir_hard_xmit(struct sk_buff *skb,
  105. struct net_device *dev);
  106. static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 speed);
  107. static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self);
  108. static int ali_ircc_dma_receive(struct ali_ircc_cb *self);
  109. static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self);
  110. static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self);
  111. static void ali_ircc_dma_xmit(struct ali_ircc_cb *self);
  112. /* My Function */
  113. static int ali_ircc_read_dongle_id (int i, chipio_t *info);
  114. static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed);
  115. /* ALi chip function */
  116. static void SIR2FIR(int iobase);
  117. static void FIR2SIR(int iobase);
  118. static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable);
  119. /*
  120. * Function ali_ircc_init ()
  121. *
  122. * Initialize chip. Find out whay kinds of chips we are dealing with
  123. * and their configuration registers address
  124. */
  125. static int __init ali_ircc_init(void)
  126. {
  127. ali_chip_t *chip;
  128. chipio_t info;
  129. int ret;
  130. int cfg, cfg_base;
  131. int reg, revision;
  132. int i = 0;
  133. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  134. ret = platform_driver_register(&ali_ircc_driver);
  135. if (ret) {
  136. IRDA_ERROR("%s, Can't register driver!\n",
  137. ALI_IRCC_DRIVER_NAME);
  138. return ret;
  139. }
  140. ret = -ENODEV;
  141. /* Probe for all the ALi chipsets we know about */
  142. for (chip= chips; chip->name; chip++, i++)
  143. {
  144. IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __func__, chip->name);
  145. /* Try all config registers for this chip */
  146. for (cfg=0; cfg<2; cfg++)
  147. {
  148. cfg_base = chip->cfg[cfg];
  149. if (!cfg_base)
  150. continue;
  151. memset(&info, 0, sizeof(chipio_t));
  152. info.cfg_base = cfg_base;
  153. info.fir_base = io[i];
  154. info.dma = dma[i];
  155. info.irq = irq[i];
  156. /* Enter Configuration */
  157. outb(chip->entr1, cfg_base);
  158. outb(chip->entr2, cfg_base);
  159. /* Select Logical Device 5 Registers (UART2) */
  160. outb(0x07, cfg_base);
  161. outb(0x05, cfg_base+1);
  162. /* Read Chip Identification Register */
  163. outb(chip->cid_index, cfg_base);
  164. reg = inb(cfg_base+1);
  165. if (reg == chip->cid_value)
  166. {
  167. IRDA_DEBUG(2, "%s(), Chip found at 0x%03x\n", __func__, cfg_base);
  168. outb(0x1F, cfg_base);
  169. revision = inb(cfg_base+1);
  170. IRDA_DEBUG(2, "%s(), Found %s chip, revision=%d\n", __func__,
  171. chip->name, revision);
  172. /*
  173. * If the user supplies the base address, then
  174. * we init the chip, if not we probe the values
  175. * set by the BIOS
  176. */
  177. if (io[i] < 2000)
  178. {
  179. chip->init(chip, &info);
  180. }
  181. else
  182. {
  183. chip->probe(chip, &info);
  184. }
  185. if (ali_ircc_open(i, &info) == 0)
  186. ret = 0;
  187. i++;
  188. }
  189. else
  190. {
  191. IRDA_DEBUG(2, "%s(), No %s chip at 0x%03x\n", __func__, chip->name, cfg_base);
  192. }
  193. /* Exit configuration */
  194. outb(0xbb, cfg_base);
  195. }
  196. }
  197. IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__);
  198. if (ret)
  199. platform_driver_unregister(&ali_ircc_driver);
  200. return ret;
  201. }
  202. /*
  203. * Function ali_ircc_cleanup ()
  204. *
  205. * Close all configured chips
  206. *
  207. */
  208. static void __exit ali_ircc_cleanup(void)
  209. {
  210. int i;
  211. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  212. for (i=0; i < ARRAY_SIZE(dev_self); i++) {
  213. if (dev_self[i])
  214. ali_ircc_close(dev_self[i]);
  215. }
  216. platform_driver_unregister(&ali_ircc_driver);
  217. IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__);
  218. }
  219. static const struct net_device_ops ali_ircc_sir_ops = {
  220. .ndo_open = ali_ircc_net_open,
  221. .ndo_stop = ali_ircc_net_close,
  222. .ndo_start_xmit = ali_ircc_sir_hard_xmit,
  223. .ndo_do_ioctl = ali_ircc_net_ioctl,
  224. };
  225. static const struct net_device_ops ali_ircc_fir_ops = {
  226. .ndo_open = ali_ircc_net_open,
  227. .ndo_stop = ali_ircc_net_close,
  228. .ndo_start_xmit = ali_ircc_fir_hard_xmit,
  229. .ndo_do_ioctl = ali_ircc_net_ioctl,
  230. };
  231. /*
  232. * Function ali_ircc_open (int i, chipio_t *inf)
  233. *
  234. * Open driver instance
  235. *
  236. */
  237. static int ali_ircc_open(int i, chipio_t *info)
  238. {
  239. struct net_device *dev;
  240. struct ali_ircc_cb *self;
  241. int dongle_id;
  242. int err;
  243. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  244. if (i >= ARRAY_SIZE(dev_self)) {
  245. IRDA_ERROR("%s(), maximum number of supported chips reached!\n",
  246. __func__);
  247. return -ENOMEM;
  248. }
  249. /* Set FIR FIFO and DMA Threshold */
  250. if ((ali_ircc_setup(info)) == -1)
  251. return -1;
  252. dev = alloc_irdadev(sizeof(*self));
  253. if (dev == NULL) {
  254. IRDA_ERROR("%s(), can't allocate memory for control block!\n",
  255. __func__);
  256. return -ENOMEM;
  257. }
  258. self = netdev_priv(dev);
  259. self->netdev = dev;
  260. spin_lock_init(&self->lock);
  261. /* Need to store self somewhere */
  262. dev_self[i] = self;
  263. self->index = i;
  264. /* Initialize IO */
  265. self->io.cfg_base = info->cfg_base; /* In ali_ircc_probe_53 assign */
  266. self->io.fir_base = info->fir_base; /* info->sir_base = info->fir_base */
  267. self->io.sir_base = info->sir_base; /* ALi SIR and FIR use the same address */
  268. self->io.irq = info->irq;
  269. self->io.fir_ext = CHIP_IO_EXTENT;
  270. self->io.dma = info->dma;
  271. self->io.fifo_size = 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
  272. /* Reserve the ioports that we need */
  273. if (!request_region(self->io.fir_base, self->io.fir_ext,
  274. ALI_IRCC_DRIVER_NAME)) {
  275. IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __func__,
  276. self->io.fir_base);
  277. err = -ENODEV;
  278. goto err_out1;
  279. }
  280. /* Initialize QoS for this device */
  281. irda_init_max_qos_capabilies(&self->qos);
  282. /* The only value we must override it the baudrate */
  283. self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
  284. IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); // benjamin 2000/11/8 05:27PM
  285. self->qos.min_turn_time.bits = qos_mtt_bits;
  286. irda_qos_bits_to_value(&self->qos);
  287. /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
  288. self->rx_buff.truesize = 14384;
  289. self->tx_buff.truesize = 14384;
  290. /* Allocate memory if needed */
  291. self->rx_buff.head =
  292. dma_zalloc_coherent(NULL, self->rx_buff.truesize,
  293. &self->rx_buff_dma, GFP_KERNEL);
  294. if (self->rx_buff.head == NULL) {
  295. err = -ENOMEM;
  296. goto err_out2;
  297. }
  298. self->tx_buff.head =
  299. dma_zalloc_coherent(NULL, self->tx_buff.truesize,
  300. &self->tx_buff_dma, GFP_KERNEL);
  301. if (self->tx_buff.head == NULL) {
  302. err = -ENOMEM;
  303. goto err_out3;
  304. }
  305. self->rx_buff.in_frame = FALSE;
  306. self->rx_buff.state = OUTSIDE_FRAME;
  307. self->tx_buff.data = self->tx_buff.head;
  308. self->rx_buff.data = self->rx_buff.head;
  309. /* Reset Tx queue info */
  310. self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
  311. self->tx_fifo.tail = self->tx_buff.head;
  312. /* Override the network functions we need to use */
  313. dev->netdev_ops = &ali_ircc_sir_ops;
  314. err = register_netdev(dev);
  315. if (err) {
  316. IRDA_ERROR("%s(), register_netdev() failed!\n", __func__);
  317. goto err_out4;
  318. }
  319. IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
  320. /* Check dongle id */
  321. dongle_id = ali_ircc_read_dongle_id(i, info);
  322. IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __func__,
  323. ALI_IRCC_DRIVER_NAME, dongle_types[dongle_id]);
  324. self->io.dongle_id = dongle_id;
  325. IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__);
  326. return 0;
  327. err_out4:
  328. dma_free_coherent(NULL, self->tx_buff.truesize,
  329. self->tx_buff.head, self->tx_buff_dma);
  330. err_out3:
  331. dma_free_coherent(NULL, self->rx_buff.truesize,
  332. self->rx_buff.head, self->rx_buff_dma);
  333. err_out2:
  334. release_region(self->io.fir_base, self->io.fir_ext);
  335. err_out1:
  336. dev_self[i] = NULL;
  337. free_netdev(dev);
  338. return err;
  339. }
  340. /*
  341. * Function ali_ircc_close (self)
  342. *
  343. * Close driver instance
  344. *
  345. */
  346. static int __exit ali_ircc_close(struct ali_ircc_cb *self)
  347. {
  348. int iobase;
  349. IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __func__);
  350. IRDA_ASSERT(self != NULL, return -1;);
  351. iobase = self->io.fir_base;
  352. /* Remove netdevice */
  353. unregister_netdev(self->netdev);
  354. /* Release the PORT that this driver is using */
  355. IRDA_DEBUG(4, "%s(), Releasing Region %03x\n", __func__, self->io.fir_base);
  356. release_region(self->io.fir_base, self->io.fir_ext);
  357. if (self->tx_buff.head)
  358. dma_free_coherent(NULL, self->tx_buff.truesize,
  359. self->tx_buff.head, self->tx_buff_dma);
  360. if (self->rx_buff.head)
  361. dma_free_coherent(NULL, self->rx_buff.truesize,
  362. self->rx_buff.head, self->rx_buff_dma);
  363. dev_self[self->index] = NULL;
  364. free_netdev(self->netdev);
  365. IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__);
  366. return 0;
  367. }
  368. /*
  369. * Function ali_ircc_init_43 (chip, info)
  370. *
  371. * Initialize the ALi M1543 chip.
  372. */
  373. static int ali_ircc_init_43(ali_chip_t *chip, chipio_t *info)
  374. {
  375. /* All controller information like I/O address, DMA channel, IRQ
  376. * are set by BIOS
  377. */
  378. return 0;
  379. }
  380. /*
  381. * Function ali_ircc_init_53 (chip, info)
  382. *
  383. * Initialize the ALi M1535 chip.
  384. */
  385. static int ali_ircc_init_53(ali_chip_t *chip, chipio_t *info)
  386. {
  387. /* All controller information like I/O address, DMA channel, IRQ
  388. * are set by BIOS
  389. */
  390. return 0;
  391. }
  392. /*
  393. * Function ali_ircc_probe_53 (chip, info)
  394. *
  395. * Probes for the ALi M1535D or M1535
  396. */
  397. static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info)
  398. {
  399. int cfg_base = info->cfg_base;
  400. int hi, low, reg;
  401. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  402. /* Enter Configuration */
  403. outb(chip->entr1, cfg_base);
  404. outb(chip->entr2, cfg_base);
  405. /* Select Logical Device 5 Registers (UART2) */
  406. outb(0x07, cfg_base);
  407. outb(0x05, cfg_base+1);
  408. /* Read address control register */
  409. outb(0x60, cfg_base);
  410. hi = inb(cfg_base+1);
  411. outb(0x61, cfg_base);
  412. low = inb(cfg_base+1);
  413. info->fir_base = (hi<<8) + low;
  414. info->sir_base = info->fir_base;
  415. IRDA_DEBUG(2, "%s(), probing fir_base=0x%03x\n", __func__, info->fir_base);
  416. /* Read IRQ control register */
  417. outb(0x70, cfg_base);
  418. reg = inb(cfg_base+1);
  419. info->irq = reg & 0x0f;
  420. IRDA_DEBUG(2, "%s(), probing irq=%d\n", __func__, info->irq);
  421. /* Read DMA channel */
  422. outb(0x74, cfg_base);
  423. reg = inb(cfg_base+1);
  424. info->dma = reg & 0x07;
  425. if(info->dma == 0x04)
  426. IRDA_WARNING("%s(), No DMA channel assigned !\n", __func__);
  427. else
  428. IRDA_DEBUG(2, "%s(), probing dma=%d\n", __func__, info->dma);
  429. /* Read Enabled Status */
  430. outb(0x30, cfg_base);
  431. reg = inb(cfg_base+1);
  432. info->enabled = (reg & 0x80) && (reg & 0x01);
  433. IRDA_DEBUG(2, "%s(), probing enabled=%d\n", __func__, info->enabled);
  434. /* Read Power Status */
  435. outb(0x22, cfg_base);
  436. reg = inb(cfg_base+1);
  437. info->suspended = (reg & 0x20);
  438. IRDA_DEBUG(2, "%s(), probing suspended=%d\n", __func__, info->suspended);
  439. /* Exit configuration */
  440. outb(0xbb, cfg_base);
  441. IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __func__);
  442. return 0;
  443. }
  444. /*
  445. * Function ali_ircc_setup (info)
  446. *
  447. * Set FIR FIFO and DMA Threshold
  448. * Returns non-negative on success.
  449. *
  450. */
  451. static int ali_ircc_setup(chipio_t *info)
  452. {
  453. unsigned char tmp;
  454. int version;
  455. int iobase = info->fir_base;
  456. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  457. /* Locking comments :
  458. * Most operations here need to be protected. We are called before
  459. * the device instance is created in ali_ircc_open(), therefore
  460. * nobody can bother us - Jean II */
  461. /* Switch to FIR space */
  462. SIR2FIR(iobase);
  463. /* Master Reset */
  464. outb(0x40, iobase+FIR_MCR); // benjamin 2000/11/30 11:45AM
  465. /* Read FIR ID Version Register */
  466. switch_bank(iobase, BANK3);
  467. version = inb(iobase+FIR_ID_VR);
  468. /* Should be 0x00 in the M1535/M1535D */
  469. if(version != 0x00)
  470. {
  471. IRDA_ERROR("%s, Wrong chip version %02x\n",
  472. ALI_IRCC_DRIVER_NAME, version);
  473. return -1;
  474. }
  475. /* Set FIR FIFO Threshold Register */
  476. switch_bank(iobase, BANK1);
  477. outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
  478. /* Set FIR DMA Threshold Register */
  479. outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
  480. /* CRC enable */
  481. switch_bank(iobase, BANK2);
  482. outb(inb(iobase+FIR_IRDA_CR) | IRDA_CR_CRC, iobase+FIR_IRDA_CR);
  483. /* NDIS driver set TX Length here BANK2 Alias 3, Alias4*/
  484. /* Switch to Bank 0 */
  485. switch_bank(iobase, BANK0);
  486. tmp = inb(iobase+FIR_LCR_B);
  487. tmp &=~0x20; // disable SIP
  488. tmp |= 0x80; // these two steps make RX mode
  489. tmp &= 0xbf;
  490. outb(tmp, iobase+FIR_LCR_B);
  491. /* Disable Interrupt */
  492. outb(0x00, iobase+FIR_IER);
  493. /* Switch to SIR space */
  494. FIR2SIR(iobase);
  495. IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n",
  496. ALI_IRCC_DRIVER_NAME);
  497. /* Enable receive interrupts */
  498. // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
  499. // Turn on the interrupts in ali_ircc_net_open
  500. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__);
  501. return 0;
  502. }
  503. /*
  504. * Function ali_ircc_read_dongle_id (int index, info)
  505. *
  506. * Try to read dongle indentification. This procedure needs to be executed
  507. * once after power-on/reset. It also needs to be used whenever you suspect
  508. * that the user may have plugged/unplugged the IrDA Dongle.
  509. */
  510. static int ali_ircc_read_dongle_id (int i, chipio_t *info)
  511. {
  512. int dongle_id, reg;
  513. int cfg_base = info->cfg_base;
  514. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  515. /* Enter Configuration */
  516. outb(chips[i].entr1, cfg_base);
  517. outb(chips[i].entr2, cfg_base);
  518. /* Select Logical Device 5 Registers (UART2) */
  519. outb(0x07, cfg_base);
  520. outb(0x05, cfg_base+1);
  521. /* Read Dongle ID */
  522. outb(0xf0, cfg_base);
  523. reg = inb(cfg_base+1);
  524. dongle_id = ((reg>>6)&0x02) | ((reg>>5)&0x01);
  525. IRDA_DEBUG(2, "%s(), probing dongle_id=%d, dongle_types=%s\n", __func__,
  526. dongle_id, dongle_types[dongle_id]);
  527. /* Exit configuration */
  528. outb(0xbb, cfg_base);
  529. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__);
  530. return dongle_id;
  531. }
  532. /*
  533. * Function ali_ircc_interrupt (irq, dev_id, regs)
  534. *
  535. * An interrupt from the chip has arrived. Time to do some work
  536. *
  537. */
  538. static irqreturn_t ali_ircc_interrupt(int irq, void *dev_id)
  539. {
  540. struct net_device *dev = dev_id;
  541. struct ali_ircc_cb *self;
  542. int ret;
  543. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  544. self = netdev_priv(dev);
  545. spin_lock(&self->lock);
  546. /* Dispatch interrupt handler for the current speed */
  547. if (self->io.speed > 115200)
  548. ret = ali_ircc_fir_interrupt(self);
  549. else
  550. ret = ali_ircc_sir_interrupt(self);
  551. spin_unlock(&self->lock);
  552. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__);
  553. return ret;
  554. }
  555. /*
  556. * Function ali_ircc_fir_interrupt(irq, struct ali_ircc_cb *self)
  557. *
  558. * Handle MIR/FIR interrupt
  559. *
  560. */
  561. static irqreturn_t ali_ircc_fir_interrupt(struct ali_ircc_cb *self)
  562. {
  563. __u8 eir, OldMessageCount;
  564. int iobase, tmp;
  565. IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__);
  566. iobase = self->io.fir_base;
  567. switch_bank(iobase, BANK0);
  568. self->InterruptID = inb(iobase+FIR_IIR);
  569. self->BusStatus = inb(iobase+FIR_BSR);
  570. OldMessageCount = (self->LineStatus + 1) & 0x07;
  571. self->LineStatus = inb(iobase+FIR_LSR);
  572. //self->ier = inb(iobase+FIR_IER); 2000/12/1 04:32PM
  573. eir = self->InterruptID & self->ier; /* Mask out the interesting ones */
  574. IRDA_DEBUG(1, "%s(), self->InterruptID = %x\n", __func__,self->InterruptID);
  575. IRDA_DEBUG(1, "%s(), self->LineStatus = %x\n", __func__,self->LineStatus);
  576. IRDA_DEBUG(1, "%s(), self->ier = %x\n", __func__,self->ier);
  577. IRDA_DEBUG(1, "%s(), eir = %x\n", __func__,eir);
  578. /* Disable interrupts */
  579. SetCOMInterrupts(self, FALSE);
  580. /* Tx or Rx Interrupt */
  581. if (eir & IIR_EOM)
  582. {
  583. if (self->io.direction == IO_XMIT) /* TX */
  584. {
  585. IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Tx) *******\n", __func__);
  586. if(ali_ircc_dma_xmit_complete(self))
  587. {
  588. if (irda_device_txqueue_empty(self->netdev))
  589. {
  590. /* Prepare for receive */
  591. ali_ircc_dma_receive(self);
  592. self->ier = IER_EOM;
  593. }
  594. }
  595. else
  596. {
  597. self->ier = IER_EOM;
  598. }
  599. }
  600. else /* RX */
  601. {
  602. IRDA_DEBUG(1, "%s(), ******* IIR_EOM (Rx) *******\n", __func__);
  603. if(OldMessageCount > ((self->LineStatus+1) & 0x07))
  604. {
  605. self->rcvFramesOverflow = TRUE;
  606. IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE ********\n", __func__);
  607. }
  608. if (ali_ircc_dma_receive_complete(self))
  609. {
  610. IRDA_DEBUG(1, "%s(), ******* receive complete ********\n", __func__);
  611. self->ier = IER_EOM;
  612. }
  613. else
  614. {
  615. IRDA_DEBUG(1, "%s(), ******* Not receive complete ********\n", __func__);
  616. self->ier = IER_EOM | IER_TIMER;
  617. }
  618. }
  619. }
  620. /* Timer Interrupt */
  621. else if (eir & IIR_TIMER)
  622. {
  623. if(OldMessageCount > ((self->LineStatus+1) & 0x07))
  624. {
  625. self->rcvFramesOverflow = TRUE;
  626. IRDA_DEBUG(1, "%s(), ******* self->rcvFramesOverflow = TRUE *******\n", __func__);
  627. }
  628. /* Disable Timer */
  629. switch_bank(iobase, BANK1);
  630. tmp = inb(iobase+FIR_CR);
  631. outb( tmp& ~CR_TIMER_EN, iobase+FIR_CR);
  632. /* Check if this is a Tx timer interrupt */
  633. if (self->io.direction == IO_XMIT)
  634. {
  635. ali_ircc_dma_xmit(self);
  636. /* Interrupt on EOM */
  637. self->ier = IER_EOM;
  638. }
  639. else /* Rx */
  640. {
  641. if(ali_ircc_dma_receive_complete(self))
  642. {
  643. self->ier = IER_EOM;
  644. }
  645. else
  646. {
  647. self->ier = IER_EOM | IER_TIMER;
  648. }
  649. }
  650. }
  651. /* Restore Interrupt */
  652. SetCOMInterrupts(self, TRUE);
  653. IRDA_DEBUG(1, "%s(), ----------------- End ---------------\n", __func__);
  654. return IRQ_RETVAL(eir);
  655. }
  656. /*
  657. * Function ali_ircc_sir_interrupt (irq, self, eir)
  658. *
  659. * Handle SIR interrupt
  660. *
  661. */
  662. static irqreturn_t ali_ircc_sir_interrupt(struct ali_ircc_cb *self)
  663. {
  664. int iobase;
  665. int iir, lsr;
  666. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  667. iobase = self->io.sir_base;
  668. iir = inb(iobase+UART_IIR) & UART_IIR_ID;
  669. if (iir) {
  670. /* Clear interrupt */
  671. lsr = inb(iobase+UART_LSR);
  672. IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", __func__,
  673. iir, lsr, iobase);
  674. switch (iir)
  675. {
  676. case UART_IIR_RLSI:
  677. IRDA_DEBUG(2, "%s(), RLSI\n", __func__);
  678. break;
  679. case UART_IIR_RDI:
  680. /* Receive interrupt */
  681. ali_ircc_sir_receive(self);
  682. break;
  683. case UART_IIR_THRI:
  684. if (lsr & UART_LSR_THRE)
  685. {
  686. /* Transmitter ready for data */
  687. ali_ircc_sir_write_wakeup(self);
  688. }
  689. break;
  690. default:
  691. IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", __func__, iir);
  692. break;
  693. }
  694. }
  695. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__);
  696. return IRQ_RETVAL(iir);
  697. }
  698. /*
  699. * Function ali_ircc_sir_receive (self)
  700. *
  701. * Receive one frame from the infrared port
  702. *
  703. */
  704. static void ali_ircc_sir_receive(struct ali_ircc_cb *self)
  705. {
  706. int boguscount = 0;
  707. int iobase;
  708. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__);
  709. IRDA_ASSERT(self != NULL, return;);
  710. iobase = self->io.sir_base;
  711. /*
  712. * Receive all characters in Rx FIFO, unwrap and unstuff them.
  713. * async_unwrap_char will deliver all found frames
  714. */
  715. do {
  716. async_unwrap_char(self->netdev, &self->netdev->stats, &self->rx_buff,
  717. inb(iobase+UART_RX));
  718. /* Make sure we don't stay here too long */
  719. if (boguscount++ > 32) {
  720. IRDA_DEBUG(2,"%s(), breaking!\n", __func__);
  721. break;
  722. }
  723. } while (inb(iobase+UART_LSR) & UART_LSR_DR);
  724. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  725. }
  726. /*
  727. * Function ali_ircc_sir_write_wakeup (tty)
  728. *
  729. * Called by the driver when there's room for more data. If we have
  730. * more packets to send, we send them here.
  731. *
  732. */
  733. static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self)
  734. {
  735. int actual = 0;
  736. int iobase;
  737. IRDA_ASSERT(self != NULL, return;);
  738. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__ );
  739. iobase = self->io.sir_base;
  740. /* Finished with frame? */
  741. if (self->tx_buff.len > 0)
  742. {
  743. /* Write data left in transmit buffer */
  744. actual = ali_ircc_sir_write(iobase, self->io.fifo_size,
  745. self->tx_buff.data, self->tx_buff.len);
  746. self->tx_buff.data += actual;
  747. self->tx_buff.len -= actual;
  748. }
  749. else
  750. {
  751. if (self->new_speed)
  752. {
  753. /* We must wait until all data are gone */
  754. while(!(inb(iobase+UART_LSR) & UART_LSR_TEMT))
  755. IRDA_DEBUG(1, "%s(), UART_LSR_THRE\n", __func__ );
  756. IRDA_DEBUG(1, "%s(), Changing speed! self->new_speed = %d\n", __func__ , self->new_speed);
  757. ali_ircc_change_speed(self, self->new_speed);
  758. self->new_speed = 0;
  759. // benjamin 2000/11/10 06:32PM
  760. if (self->io.speed > 115200)
  761. {
  762. IRDA_DEBUG(2, "%s(), ali_ircc_change_speed from UART_LSR_TEMT\n", __func__ );
  763. self->ier = IER_EOM;
  764. // SetCOMInterrupts(self, TRUE);
  765. return;
  766. }
  767. }
  768. else
  769. {
  770. netif_wake_queue(self->netdev);
  771. }
  772. self->netdev->stats.tx_packets++;
  773. /* Turn on receive interrupts */
  774. outb(UART_IER_RDI, iobase+UART_IER);
  775. }
  776. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  777. }
  778. static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud)
  779. {
  780. struct net_device *dev = self->netdev;
  781. int iobase;
  782. IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__ );
  783. IRDA_DEBUG(2, "%s(), setting speed = %d\n", __func__ , baud);
  784. /* This function *must* be called with irq off and spin-lock.
  785. * - Jean II */
  786. iobase = self->io.fir_base;
  787. SetCOMInterrupts(self, FALSE); // 2000/11/24 11:43AM
  788. /* Go to MIR, FIR Speed */
  789. if (baud > 115200)
  790. {
  791. ali_ircc_fir_change_speed(self, baud);
  792. /* Install FIR xmit handler*/
  793. dev->netdev_ops = &ali_ircc_fir_ops;
  794. /* Enable Interuupt */
  795. self->ier = IER_EOM; // benjamin 2000/11/20 07:24PM
  796. /* Be ready for incoming frames */
  797. ali_ircc_dma_receive(self); // benajmin 2000/11/8 07:46PM not complete
  798. }
  799. /* Go to SIR Speed */
  800. else
  801. {
  802. ali_ircc_sir_change_speed(self, baud);
  803. /* Install SIR xmit handler*/
  804. dev->netdev_ops = &ali_ircc_sir_ops;
  805. }
  806. SetCOMInterrupts(self, TRUE); // 2000/11/24 11:43AM
  807. netif_wake_queue(self->netdev);
  808. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  809. }
  810. static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 baud)
  811. {
  812. int iobase;
  813. struct ali_ircc_cb *self = priv;
  814. struct net_device *dev;
  815. IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__ );
  816. IRDA_ASSERT(self != NULL, return;);
  817. dev = self->netdev;
  818. iobase = self->io.fir_base;
  819. IRDA_DEBUG(1, "%s(), self->io.speed = %d, change to speed = %d\n", __func__ ,self->io.speed,baud);
  820. /* Come from SIR speed */
  821. if(self->io.speed <=115200)
  822. {
  823. SIR2FIR(iobase);
  824. }
  825. /* Update accounting for new speed */
  826. self->io.speed = baud;
  827. // Set Dongle Speed mode
  828. ali_ircc_change_dongle_speed(self, baud);
  829. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  830. }
  831. /*
  832. * Function ali_sir_change_speed (self, speed)
  833. *
  834. * Set speed of IrDA port to specified baudrate
  835. *
  836. */
  837. static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed)
  838. {
  839. struct ali_ircc_cb *self = priv;
  840. unsigned long flags;
  841. int iobase;
  842. int fcr; /* FIFO control reg */
  843. int lcr; /* Line control reg */
  844. int divisor;
  845. IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__ );
  846. IRDA_DEBUG(1, "%s(), Setting speed to: %d\n", __func__ , speed);
  847. IRDA_ASSERT(self != NULL, return;);
  848. iobase = self->io.sir_base;
  849. /* Come from MIR or FIR speed */
  850. if(self->io.speed >115200)
  851. {
  852. // Set Dongle Speed mode first
  853. ali_ircc_change_dongle_speed(self, speed);
  854. FIR2SIR(iobase);
  855. }
  856. // Clear Line and Auxiluary status registers 2000/11/24 11:47AM
  857. inb(iobase+UART_LSR);
  858. inb(iobase+UART_SCR);
  859. /* Update accounting for new speed */
  860. self->io.speed = speed;
  861. spin_lock_irqsave(&self->lock, flags);
  862. divisor = 115200/speed;
  863. fcr = UART_FCR_ENABLE_FIFO;
  864. /*
  865. * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
  866. * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
  867. * about this timeout since it will always be fast enough.
  868. */
  869. if (self->io.speed < 38400)
  870. fcr |= UART_FCR_TRIGGER_1;
  871. else
  872. fcr |= UART_FCR_TRIGGER_14;
  873. /* IrDA ports use 8N1 */
  874. lcr = UART_LCR_WLEN8;
  875. outb(UART_LCR_DLAB | lcr, iobase+UART_LCR); /* Set DLAB */
  876. outb(divisor & 0xff, iobase+UART_DLL); /* Set speed */
  877. outb(divisor >> 8, iobase+UART_DLM);
  878. outb(lcr, iobase+UART_LCR); /* Set 8N1 */
  879. outb(fcr, iobase+UART_FCR); /* Enable FIFO's */
  880. /* without this, the connection will be broken after come back from FIR speed,
  881. but with this, the SIR connection is harder to established */
  882. outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase+UART_MCR);
  883. spin_unlock_irqrestore(&self->lock, flags);
  884. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  885. }
  886. static void ali_ircc_change_dongle_speed(struct ali_ircc_cb *priv, int speed)
  887. {
  888. struct ali_ircc_cb *self = priv;
  889. int iobase,dongle_id;
  890. int tmp = 0;
  891. IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__ );
  892. iobase = self->io.fir_base; /* or iobase = self->io.sir_base; */
  893. dongle_id = self->io.dongle_id;
  894. /* We are already locked, no need to do it again */
  895. IRDA_DEBUG(1, "%s(), Set Speed for %s , Speed = %d\n", __func__ , dongle_types[dongle_id], speed);
  896. switch_bank(iobase, BANK2);
  897. tmp = inb(iobase+FIR_IRDA_CR);
  898. /* IBM type dongle */
  899. if(dongle_id == 0)
  900. {
  901. if(speed == 4000000)
  902. {
  903. // __ __
  904. // SD/MODE __| |__ __
  905. // __ __
  906. // IRTX __ __| |__
  907. // T1 T2 T3 T4 T5
  908. tmp &= ~IRDA_CR_HDLC; // HDLC=0
  909. tmp |= IRDA_CR_CRC; // CRC=1
  910. switch_bank(iobase, BANK2);
  911. outb(tmp, iobase+FIR_IRDA_CR);
  912. // T1 -> SD/MODE:0 IRTX:0
  913. tmp &= ~0x09;
  914. tmp |= 0x02;
  915. outb(tmp, iobase+FIR_IRDA_CR);
  916. udelay(2);
  917. // T2 -> SD/MODE:1 IRTX:0
  918. tmp &= ~0x01;
  919. tmp |= 0x0a;
  920. outb(tmp, iobase+FIR_IRDA_CR);
  921. udelay(2);
  922. // T3 -> SD/MODE:1 IRTX:1
  923. tmp |= 0x0b;
  924. outb(tmp, iobase+FIR_IRDA_CR);
  925. udelay(2);
  926. // T4 -> SD/MODE:0 IRTX:1
  927. tmp &= ~0x08;
  928. tmp |= 0x03;
  929. outb(tmp, iobase+FIR_IRDA_CR);
  930. udelay(2);
  931. // T5 -> SD/MODE:0 IRTX:0
  932. tmp &= ~0x09;
  933. tmp |= 0x02;
  934. outb(tmp, iobase+FIR_IRDA_CR);
  935. udelay(2);
  936. // reset -> Normal TX output Signal
  937. outb(tmp & ~0x02, iobase+FIR_IRDA_CR);
  938. }
  939. else /* speed <=1152000 */
  940. {
  941. // __
  942. // SD/MODE __| |__
  943. //
  944. // IRTX ________
  945. // T1 T2 T3
  946. /* MIR 115200, 57600 */
  947. if (speed==1152000)
  948. {
  949. tmp |= 0xA0; //HDLC=1, 1.152Mbps=1
  950. }
  951. else
  952. {
  953. tmp &=~0x80; //HDLC 0.576Mbps
  954. tmp |= 0x20; //HDLC=1,
  955. }
  956. tmp |= IRDA_CR_CRC; // CRC=1
  957. switch_bank(iobase, BANK2);
  958. outb(tmp, iobase+FIR_IRDA_CR);
  959. /* MIR 115200, 57600 */
  960. //switch_bank(iobase, BANK2);
  961. // T1 -> SD/MODE:0 IRTX:0
  962. tmp &= ~0x09;
  963. tmp |= 0x02;
  964. outb(tmp, iobase+FIR_IRDA_CR);
  965. udelay(2);
  966. // T2 -> SD/MODE:1 IRTX:0
  967. tmp &= ~0x01;
  968. tmp |= 0x0a;
  969. outb(tmp, iobase+FIR_IRDA_CR);
  970. // T3 -> SD/MODE:0 IRTX:0
  971. tmp &= ~0x09;
  972. tmp |= 0x02;
  973. outb(tmp, iobase+FIR_IRDA_CR);
  974. udelay(2);
  975. // reset -> Normal TX output Signal
  976. outb(tmp & ~0x02, iobase+FIR_IRDA_CR);
  977. }
  978. }
  979. else if (dongle_id == 1) /* HP HDSL-3600 */
  980. {
  981. switch(speed)
  982. {
  983. case 4000000:
  984. tmp &= ~IRDA_CR_HDLC; // HDLC=0
  985. break;
  986. case 1152000:
  987. tmp |= 0xA0; // HDLC=1, 1.152Mbps=1
  988. break;
  989. case 576000:
  990. tmp &=~0x80; // HDLC 0.576Mbps
  991. tmp |= 0x20; // HDLC=1,
  992. break;
  993. }
  994. tmp |= IRDA_CR_CRC; // CRC=1
  995. switch_bank(iobase, BANK2);
  996. outb(tmp, iobase+FIR_IRDA_CR);
  997. }
  998. else /* HP HDSL-1100 */
  999. {
  1000. if(speed <= 115200) /* SIR */
  1001. {
  1002. tmp &= ~IRDA_CR_FIR_SIN; // HP sin select = 0
  1003. switch_bank(iobase, BANK2);
  1004. outb(tmp, iobase+FIR_IRDA_CR);
  1005. }
  1006. else /* MIR FIR */
  1007. {
  1008. switch(speed)
  1009. {
  1010. case 4000000:
  1011. tmp &= ~IRDA_CR_HDLC; // HDLC=0
  1012. break;
  1013. case 1152000:
  1014. tmp |= 0xA0; // HDLC=1, 1.152Mbps=1
  1015. break;
  1016. case 576000:
  1017. tmp &=~0x80; // HDLC 0.576Mbps
  1018. tmp |= 0x20; // HDLC=1,
  1019. break;
  1020. }
  1021. tmp |= IRDA_CR_CRC; // CRC=1
  1022. tmp |= IRDA_CR_FIR_SIN; // HP sin select = 1
  1023. switch_bank(iobase, BANK2);
  1024. outb(tmp, iobase+FIR_IRDA_CR);
  1025. }
  1026. }
  1027. switch_bank(iobase, BANK0);
  1028. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1029. }
  1030. /*
  1031. * Function ali_ircc_sir_write (driver)
  1032. *
  1033. * Fill Tx FIFO with transmit data
  1034. *
  1035. */
  1036. static int ali_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
  1037. {
  1038. int actual = 0;
  1039. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__ );
  1040. /* Tx FIFO should be empty! */
  1041. if (!(inb(iobase+UART_LSR) & UART_LSR_THRE)) {
  1042. IRDA_DEBUG(0, "%s(), failed, fifo not empty!\n", __func__ );
  1043. return 0;
  1044. }
  1045. /* Fill FIFO with current frame */
  1046. while ((fifo_size-- > 0) && (actual < len)) {
  1047. /* Transmit next byte */
  1048. outb(buf[actual], iobase+UART_TX);
  1049. actual++;
  1050. }
  1051. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  1052. return actual;
  1053. }
  1054. /*
  1055. * Function ali_ircc_net_open (dev)
  1056. *
  1057. * Start the device
  1058. *
  1059. */
  1060. static int ali_ircc_net_open(struct net_device *dev)
  1061. {
  1062. struct ali_ircc_cb *self;
  1063. int iobase;
  1064. char hwname[32];
  1065. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__ );
  1066. IRDA_ASSERT(dev != NULL, return -1;);
  1067. self = netdev_priv(dev);
  1068. IRDA_ASSERT(self != NULL, return 0;);
  1069. iobase = self->io.fir_base;
  1070. /* Request IRQ and install Interrupt Handler */
  1071. if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev))
  1072. {
  1073. IRDA_WARNING("%s, unable to allocate irq=%d\n",
  1074. ALI_IRCC_DRIVER_NAME,
  1075. self->io.irq);
  1076. return -EAGAIN;
  1077. }
  1078. /*
  1079. * Always allocate the DMA channel after the IRQ, and clean up on
  1080. * failure.
  1081. */
  1082. if (request_dma(self->io.dma, dev->name)) {
  1083. IRDA_WARNING("%s, unable to allocate dma=%d\n",
  1084. ALI_IRCC_DRIVER_NAME,
  1085. self->io.dma);
  1086. free_irq(self->io.irq, dev);
  1087. return -EAGAIN;
  1088. }
  1089. /* Turn on interrups */
  1090. outb(UART_IER_RDI , iobase+UART_IER);
  1091. /* Ready to play! */
  1092. netif_start_queue(dev); //benjamin by irport
  1093. /* Give self a hardware name */
  1094. sprintf(hwname, "ALI-FIR @ 0x%03x", self->io.fir_base);
  1095. /*
  1096. * Open new IrLAP layer instance, now that everything should be
  1097. * initialized properly
  1098. */
  1099. self->irlap = irlap_open(dev, &self->qos, hwname);
  1100. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  1101. return 0;
  1102. }
  1103. /*
  1104. * Function ali_ircc_net_close (dev)
  1105. *
  1106. * Stop the device
  1107. *
  1108. */
  1109. static int ali_ircc_net_close(struct net_device *dev)
  1110. {
  1111. struct ali_ircc_cb *self;
  1112. //int iobase;
  1113. IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __func__ );
  1114. IRDA_ASSERT(dev != NULL, return -1;);
  1115. self = netdev_priv(dev);
  1116. IRDA_ASSERT(self != NULL, return 0;);
  1117. /* Stop device */
  1118. netif_stop_queue(dev);
  1119. /* Stop and remove instance of IrLAP */
  1120. if (self->irlap)
  1121. irlap_close(self->irlap);
  1122. self->irlap = NULL;
  1123. disable_dma(self->io.dma);
  1124. /* Disable interrupts */
  1125. SetCOMInterrupts(self, FALSE);
  1126. free_irq(self->io.irq, dev);
  1127. free_dma(self->io.dma);
  1128. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  1129. return 0;
  1130. }
  1131. /*
  1132. * Function ali_ircc_fir_hard_xmit (skb, dev)
  1133. *
  1134. * Transmit the frame
  1135. *
  1136. */
  1137. static netdev_tx_t ali_ircc_fir_hard_xmit(struct sk_buff *skb,
  1138. struct net_device *dev)
  1139. {
  1140. struct ali_ircc_cb *self;
  1141. unsigned long flags;
  1142. int iobase;
  1143. __u32 speed;
  1144. int mtt, diff;
  1145. IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__ );
  1146. self = netdev_priv(dev);
  1147. iobase = self->io.fir_base;
  1148. netif_stop_queue(dev);
  1149. /* Make sure tests *& speed change are atomic */
  1150. spin_lock_irqsave(&self->lock, flags);
  1151. /* Note : you should make sure that speed changes are not going
  1152. * to corrupt any outgoing frame. Look at nsc-ircc for the gory
  1153. * details - Jean II */
  1154. /* Check if we need to change the speed */
  1155. speed = irda_get_next_speed(skb);
  1156. if ((speed != self->io.speed) && (speed != -1)) {
  1157. /* Check for empty frame */
  1158. if (!skb->len) {
  1159. ali_ircc_change_speed(self, speed);
  1160. dev->trans_start = jiffies;
  1161. spin_unlock_irqrestore(&self->lock, flags);
  1162. dev_kfree_skb(skb);
  1163. return NETDEV_TX_OK;
  1164. } else
  1165. self->new_speed = speed;
  1166. }
  1167. /* Register and copy this frame to DMA memory */
  1168. self->tx_fifo.queue[self->tx_fifo.free].start = self->tx_fifo.tail;
  1169. self->tx_fifo.queue[self->tx_fifo.free].len = skb->len;
  1170. self->tx_fifo.tail += skb->len;
  1171. dev->stats.tx_bytes += skb->len;
  1172. skb_copy_from_linear_data(skb, self->tx_fifo.queue[self->tx_fifo.free].start,
  1173. skb->len);
  1174. self->tx_fifo.len++;
  1175. self->tx_fifo.free++;
  1176. /* Start transmit only if there is currently no transmit going on */
  1177. if (self->tx_fifo.len == 1)
  1178. {
  1179. /* Check if we must wait the min turn time or not */
  1180. mtt = irda_get_mtt(skb);
  1181. if (mtt)
  1182. {
  1183. /* Check how much time we have used already */
  1184. do_gettimeofday(&self->now);
  1185. diff = self->now.tv_usec - self->stamp.tv_usec;
  1186. /* self->stamp is set from ali_ircc_dma_receive_complete() */
  1187. IRDA_DEBUG(1, "%s(), ******* diff = %d *******\n", __func__ , diff);
  1188. if (diff < 0)
  1189. diff += 1000000;
  1190. /* Check if the mtt is larger than the time we have
  1191. * already used by all the protocol processing
  1192. */
  1193. if (mtt > diff)
  1194. {
  1195. mtt -= diff;
  1196. /*
  1197. * Use timer if delay larger than 1000 us, and
  1198. * use udelay for smaller values which should
  1199. * be acceptable
  1200. */
  1201. if (mtt > 500)
  1202. {
  1203. /* Adjust for timer resolution */
  1204. mtt = (mtt+250) / 500; /* 4 discard, 5 get advanced, Let's round off */
  1205. IRDA_DEBUG(1, "%s(), ************** mtt = %d ***********\n", __func__ , mtt);
  1206. /* Setup timer */
  1207. if (mtt == 1) /* 500 us */
  1208. {
  1209. switch_bank(iobase, BANK1);
  1210. outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR);
  1211. }
  1212. else if (mtt == 2) /* 1 ms */
  1213. {
  1214. switch_bank(iobase, BANK1);
  1215. outb(TIMER_IIR_1ms, iobase+FIR_TIMER_IIR);
  1216. }
  1217. else /* > 2ms -> 4ms */
  1218. {
  1219. switch_bank(iobase, BANK1);
  1220. outb(TIMER_IIR_2ms, iobase+FIR_TIMER_IIR);
  1221. }
  1222. /* Start timer */
  1223. outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
  1224. self->io.direction = IO_XMIT;
  1225. /* Enable timer interrupt */
  1226. self->ier = IER_TIMER;
  1227. SetCOMInterrupts(self, TRUE);
  1228. /* Timer will take care of the rest */
  1229. goto out;
  1230. }
  1231. else
  1232. udelay(mtt);
  1233. } // if (if (mtt > diff)
  1234. }// if (mtt)
  1235. /* Enable EOM interrupt */
  1236. self->ier = IER_EOM;
  1237. SetCOMInterrupts(self, TRUE);
  1238. /* Transmit frame */
  1239. ali_ircc_dma_xmit(self);
  1240. } // if (self->tx_fifo.len == 1)
  1241. out:
  1242. /* Not busy transmitting anymore if window is not full */
  1243. if (self->tx_fifo.free < MAX_TX_WINDOW)
  1244. netif_wake_queue(self->netdev);
  1245. /* Restore bank register */
  1246. switch_bank(iobase, BANK0);
  1247. dev->trans_start = jiffies;
  1248. spin_unlock_irqrestore(&self->lock, flags);
  1249. dev_kfree_skb(skb);
  1250. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1251. return NETDEV_TX_OK;
  1252. }
  1253. static void ali_ircc_dma_xmit(struct ali_ircc_cb *self)
  1254. {
  1255. int iobase, tmp;
  1256. unsigned char FIFO_OPTI, Hi, Lo;
  1257. IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__ );
  1258. iobase = self->io.fir_base;
  1259. /* FIFO threshold , this method comes from NDIS5 code */
  1260. if(self->tx_fifo.queue[self->tx_fifo.ptr].len < TX_FIFO_Threshold)
  1261. FIFO_OPTI = self->tx_fifo.queue[self->tx_fifo.ptr].len-1;
  1262. else
  1263. FIFO_OPTI = TX_FIFO_Threshold;
  1264. /* Disable DMA */
  1265. switch_bank(iobase, BANK1);
  1266. outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
  1267. self->io.direction = IO_XMIT;
  1268. irda_setup_dma(self->io.dma,
  1269. ((u8 *)self->tx_fifo.queue[self->tx_fifo.ptr].start -
  1270. self->tx_buff.head) + self->tx_buff_dma,
  1271. self->tx_fifo.queue[self->tx_fifo.ptr].len,
  1272. DMA_TX_MODE);
  1273. /* Reset Tx FIFO */
  1274. switch_bank(iobase, BANK0);
  1275. outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A);
  1276. /* Set Tx FIFO threshold */
  1277. if (self->fifo_opti_buf!=FIFO_OPTI)
  1278. {
  1279. switch_bank(iobase, BANK1);
  1280. outb(FIFO_OPTI, iobase+FIR_FIFO_TR) ;
  1281. self->fifo_opti_buf=FIFO_OPTI;
  1282. }
  1283. /* Set Tx DMA threshold */
  1284. switch_bank(iobase, BANK1);
  1285. outb(TX_DMA_Threshold, iobase+FIR_DMA_TR);
  1286. /* Set max Tx frame size */
  1287. Hi = (self->tx_fifo.queue[self->tx_fifo.ptr].len >> 8) & 0x0f;
  1288. Lo = self->tx_fifo.queue[self->tx_fifo.ptr].len & 0xff;
  1289. switch_bank(iobase, BANK2);
  1290. outb(Hi, iobase+FIR_TX_DSR_HI);
  1291. outb(Lo, iobase+FIR_TX_DSR_LO);
  1292. /* Disable SIP , Disable Brick Wall (we don't support in TX mode), Change to TX mode */
  1293. switch_bank(iobase, BANK0);
  1294. tmp = inb(iobase+FIR_LCR_B);
  1295. tmp &= ~0x20; // Disable SIP
  1296. outb(((unsigned char)(tmp & 0x3f) | LCR_B_TX_MODE) & ~LCR_B_BW, iobase+FIR_LCR_B);
  1297. IRDA_DEBUG(1, "%s(), *** Change to TX mode: FIR_LCR_B = 0x%x ***\n", __func__ , inb(iobase+FIR_LCR_B));
  1298. outb(0, iobase+FIR_LSR);
  1299. /* Enable DMA and Burst Mode */
  1300. switch_bank(iobase, BANK1);
  1301. outb(inb(iobase+FIR_CR) | CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
  1302. switch_bank(iobase, BANK0);
  1303. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1304. }
  1305. static int ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self)
  1306. {
  1307. int iobase;
  1308. int ret = TRUE;
  1309. IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__ );
  1310. iobase = self->io.fir_base;
  1311. /* Disable DMA */
  1312. switch_bank(iobase, BANK1);
  1313. outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
  1314. /* Check for underrun! */
  1315. switch_bank(iobase, BANK0);
  1316. if((inb(iobase+FIR_LSR) & LSR_FRAME_ABORT) == LSR_FRAME_ABORT)
  1317. {
  1318. IRDA_ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __func__);
  1319. self->netdev->stats.tx_errors++;
  1320. self->netdev->stats.tx_fifo_errors++;
  1321. }
  1322. else
  1323. {
  1324. self->netdev->stats.tx_packets++;
  1325. }
  1326. /* Check if we need to change the speed */
  1327. if (self->new_speed)
  1328. {
  1329. ali_ircc_change_speed(self, self->new_speed);
  1330. self->new_speed = 0;
  1331. }
  1332. /* Finished with this frame, so prepare for next */
  1333. self->tx_fifo.ptr++;
  1334. self->tx_fifo.len--;
  1335. /* Any frames to be sent back-to-back? */
  1336. if (self->tx_fifo.len)
  1337. {
  1338. ali_ircc_dma_xmit(self);
  1339. /* Not finished yet! */
  1340. ret = FALSE;
  1341. }
  1342. else
  1343. { /* Reset Tx FIFO info */
  1344. self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
  1345. self->tx_fifo.tail = self->tx_buff.head;
  1346. }
  1347. /* Make sure we have room for more frames */
  1348. if (self->tx_fifo.free < MAX_TX_WINDOW) {
  1349. /* Not busy transmitting anymore */
  1350. /* Tell the network layer, that we can accept more frames */
  1351. netif_wake_queue(self->netdev);
  1352. }
  1353. switch_bank(iobase, BANK0);
  1354. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1355. return ret;
  1356. }
  1357. /*
  1358. * Function ali_ircc_dma_receive (self)
  1359. *
  1360. * Get ready for receiving a frame. The device will initiate a DMA
  1361. * if it starts to receive a frame.
  1362. *
  1363. */
  1364. static int ali_ircc_dma_receive(struct ali_ircc_cb *self)
  1365. {
  1366. int iobase, tmp;
  1367. IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__ );
  1368. iobase = self->io.fir_base;
  1369. /* Reset Tx FIFO info */
  1370. self->tx_fifo.len = self->tx_fifo.ptr = self->tx_fifo.free = 0;
  1371. self->tx_fifo.tail = self->tx_buff.head;
  1372. /* Disable DMA */
  1373. switch_bank(iobase, BANK1);
  1374. outb(inb(iobase+FIR_CR) & ~CR_DMA_EN, iobase+FIR_CR);
  1375. /* Reset Message Count */
  1376. switch_bank(iobase, BANK0);
  1377. outb(0x07, iobase+FIR_LSR);
  1378. self->rcvFramesOverflow = FALSE;
  1379. self->LineStatus = inb(iobase+FIR_LSR) ;
  1380. /* Reset Rx FIFO info */
  1381. self->io.direction = IO_RECV;
  1382. self->rx_buff.data = self->rx_buff.head;
  1383. /* Reset Rx FIFO */
  1384. // switch_bank(iobase, BANK0);
  1385. outb(LCR_A_FIFO_RESET, iobase+FIR_LCR_A);
  1386. self->st_fifo.len = self->st_fifo.pending_bytes = 0;
  1387. self->st_fifo.tail = self->st_fifo.head = 0;
  1388. irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
  1389. DMA_RX_MODE);
  1390. /* Set Receive Mode,Brick Wall */
  1391. //switch_bank(iobase, BANK0);
  1392. tmp = inb(iobase+FIR_LCR_B);
  1393. outb((unsigned char)(tmp &0x3f) | LCR_B_RX_MODE | LCR_B_BW , iobase + FIR_LCR_B); // 2000/12/1 05:16PM
  1394. IRDA_DEBUG(1, "%s(), *** Change To RX mode: FIR_LCR_B = 0x%x ***\n", __func__ , inb(iobase+FIR_LCR_B));
  1395. /* Set Rx Threshold */
  1396. switch_bank(iobase, BANK1);
  1397. outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
  1398. outb(RX_DMA_Threshold, iobase+FIR_DMA_TR);
  1399. /* Enable DMA and Burst Mode */
  1400. // switch_bank(iobase, BANK1);
  1401. outb(CR_DMA_EN | CR_DMA_BURST, iobase+FIR_CR);
  1402. switch_bank(iobase, BANK0);
  1403. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1404. return 0;
  1405. }
  1406. static int ali_ircc_dma_receive_complete(struct ali_ircc_cb *self)
  1407. {
  1408. struct st_fifo *st_fifo;
  1409. struct sk_buff *skb;
  1410. __u8 status, MessageCount;
  1411. int len, i, iobase, val;
  1412. IRDA_DEBUG(1, "%s(), ---------------- Start -----------------\n", __func__ );
  1413. st_fifo = &self->st_fifo;
  1414. iobase = self->io.fir_base;
  1415. switch_bank(iobase, BANK0);
  1416. MessageCount = inb(iobase+ FIR_LSR)&0x07;
  1417. if (MessageCount > 0)
  1418. IRDA_DEBUG(0, "%s(), Message count = %d,\n", __func__ , MessageCount);
  1419. for (i=0; i<=MessageCount; i++)
  1420. {
  1421. /* Bank 0 */
  1422. switch_bank(iobase, BANK0);
  1423. status = inb(iobase+FIR_LSR);
  1424. switch_bank(iobase, BANK2);
  1425. len = inb(iobase+FIR_RX_DSR_HI) & 0x0f;
  1426. len = len << 8;
  1427. len |= inb(iobase+FIR_RX_DSR_LO);
  1428. IRDA_DEBUG(1, "%s(), RX Length = 0x%.2x,\n", __func__ , len);
  1429. IRDA_DEBUG(1, "%s(), RX Status = 0x%.2x,\n", __func__ , status);
  1430. if (st_fifo->tail >= MAX_RX_WINDOW) {
  1431. IRDA_DEBUG(0, "%s(), window is full!\n", __func__ );
  1432. continue;
  1433. }
  1434. st_fifo->entries[st_fifo->tail].status = status;
  1435. st_fifo->entries[st_fifo->tail].len = len;
  1436. st_fifo->pending_bytes += len;
  1437. st_fifo->tail++;
  1438. st_fifo->len++;
  1439. }
  1440. for (i=0; i<=MessageCount; i++)
  1441. {
  1442. /* Get first entry */
  1443. status = st_fifo->entries[st_fifo->head].status;
  1444. len = st_fifo->entries[st_fifo->head].len;
  1445. st_fifo->pending_bytes -= len;
  1446. st_fifo->head++;
  1447. st_fifo->len--;
  1448. /* Check for errors */
  1449. if ((status & 0xd8) || self->rcvFramesOverflow || (len==0))
  1450. {
  1451. IRDA_DEBUG(0,"%s(), ************* RX Errors ************\n", __func__ );
  1452. /* Skip frame */
  1453. self->netdev->stats.rx_errors++;
  1454. self->rx_buff.data += len;
  1455. if (status & LSR_FIFO_UR)
  1456. {
  1457. self->netdev->stats.rx_frame_errors++;
  1458. IRDA_DEBUG(0,"%s(), ************* FIFO Errors ************\n", __func__ );
  1459. }
  1460. if (status & LSR_FRAME_ERROR)
  1461. {
  1462. self->netdev->stats.rx_frame_errors++;
  1463. IRDA_DEBUG(0,"%s(), ************* FRAME Errors ************\n", __func__ );
  1464. }
  1465. if (status & LSR_CRC_ERROR)
  1466. {
  1467. self->netdev->stats.rx_crc_errors++;
  1468. IRDA_DEBUG(0,"%s(), ************* CRC Errors ************\n", __func__ );
  1469. }
  1470. if(self->rcvFramesOverflow)
  1471. {
  1472. self->netdev->stats.rx_frame_errors++;
  1473. IRDA_DEBUG(0,"%s(), ************* Overran DMA buffer ************\n", __func__ );
  1474. }
  1475. if(len == 0)
  1476. {
  1477. self->netdev->stats.rx_frame_errors++;
  1478. IRDA_DEBUG(0,"%s(), ********** Receive Frame Size = 0 *********\n", __func__ );
  1479. }
  1480. }
  1481. else
  1482. {
  1483. if (st_fifo->pending_bytes < 32)
  1484. {
  1485. switch_bank(iobase, BANK0);
  1486. val = inb(iobase+FIR_BSR);
  1487. if ((val& BSR_FIFO_NOT_EMPTY)== 0x80)
  1488. {
  1489. IRDA_DEBUG(0, "%s(), ************* BSR_FIFO_NOT_EMPTY ************\n", __func__ );
  1490. /* Put this entry back in fifo */
  1491. st_fifo->head--;
  1492. st_fifo->len++;
  1493. st_fifo->pending_bytes += len;
  1494. st_fifo->entries[st_fifo->head].status = status;
  1495. st_fifo->entries[st_fifo->head].len = len;
  1496. /*
  1497. * DMA not finished yet, so try again
  1498. * later, set timer value, resolution
  1499. * 500 us
  1500. */
  1501. switch_bank(iobase, BANK1);
  1502. outb(TIMER_IIR_500, iobase+FIR_TIMER_IIR); // 2001/1/2 05:07PM
  1503. /* Enable Timer */
  1504. outb(inb(iobase+FIR_CR) | CR_TIMER_EN, iobase+FIR_CR);
  1505. return FALSE; /* I'll be back! */
  1506. }
  1507. }
  1508. /*
  1509. * Remember the time we received this frame, so we can
  1510. * reduce the min turn time a bit since we will know
  1511. * how much time we have used for protocol processing
  1512. */
  1513. do_gettimeofday(&self->stamp);
  1514. skb = dev_alloc_skb(len+1);
  1515. if (skb == NULL)
  1516. {
  1517. IRDA_WARNING("%s(), memory squeeze, "
  1518. "dropping frame.\n",
  1519. __func__);
  1520. self->netdev->stats.rx_dropped++;
  1521. return FALSE;
  1522. }
  1523. /* Make sure IP header gets aligned */
  1524. skb_reserve(skb, 1);
  1525. /* Copy frame without CRC, CRC is removed by hardware*/
  1526. skb_put(skb, len);
  1527. skb_copy_to_linear_data(skb, self->rx_buff.data, len);
  1528. /* Move to next frame */
  1529. self->rx_buff.data += len;
  1530. self->netdev->stats.rx_bytes += len;
  1531. self->netdev->stats.rx_packets++;
  1532. skb->dev = self->netdev;
  1533. skb_reset_mac_header(skb);
  1534. skb->protocol = htons(ETH_P_IRDA);
  1535. netif_rx(skb);
  1536. }
  1537. }
  1538. switch_bank(iobase, BANK0);
  1539. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1540. return TRUE;
  1541. }
  1542. /*
  1543. * Function ali_ircc_sir_hard_xmit (skb, dev)
  1544. *
  1545. * Transmit the frame!
  1546. *
  1547. */
  1548. static netdev_tx_t ali_ircc_sir_hard_xmit(struct sk_buff *skb,
  1549. struct net_device *dev)
  1550. {
  1551. struct ali_ircc_cb *self;
  1552. unsigned long flags;
  1553. int iobase;
  1554. __u32 speed;
  1555. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__ );
  1556. IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
  1557. self = netdev_priv(dev);
  1558. IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
  1559. iobase = self->io.sir_base;
  1560. netif_stop_queue(dev);
  1561. /* Make sure tests *& speed change are atomic */
  1562. spin_lock_irqsave(&self->lock, flags);
  1563. /* Note : you should make sure that speed changes are not going
  1564. * to corrupt any outgoing frame. Look at nsc-ircc for the gory
  1565. * details - Jean II */
  1566. /* Check if we need to change the speed */
  1567. speed = irda_get_next_speed(skb);
  1568. if ((speed != self->io.speed) && (speed != -1)) {
  1569. /* Check for empty frame */
  1570. if (!skb->len) {
  1571. ali_ircc_change_speed(self, speed);
  1572. dev->trans_start = jiffies;
  1573. spin_unlock_irqrestore(&self->lock, flags);
  1574. dev_kfree_skb(skb);
  1575. return NETDEV_TX_OK;
  1576. } else
  1577. self->new_speed = speed;
  1578. }
  1579. /* Init tx buffer */
  1580. self->tx_buff.data = self->tx_buff.head;
  1581. /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
  1582. self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
  1583. self->tx_buff.truesize);
  1584. self->netdev->stats.tx_bytes += self->tx_buff.len;
  1585. /* Turn on transmit finished interrupt. Will fire immediately! */
  1586. outb(UART_IER_THRI, iobase+UART_IER);
  1587. dev->trans_start = jiffies;
  1588. spin_unlock_irqrestore(&self->lock, flags);
  1589. dev_kfree_skb(skb);
  1590. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  1591. return NETDEV_TX_OK;
  1592. }
  1593. /*
  1594. * Function ali_ircc_net_ioctl (dev, rq, cmd)
  1595. *
  1596. * Process IOCTL commands for this device
  1597. *
  1598. */
  1599. static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1600. {
  1601. struct if_irda_req *irq = (struct if_irda_req *) rq;
  1602. struct ali_ircc_cb *self;
  1603. unsigned long flags;
  1604. int ret = 0;
  1605. IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__ );
  1606. IRDA_ASSERT(dev != NULL, return -1;);
  1607. self = netdev_priv(dev);
  1608. IRDA_ASSERT(self != NULL, return -1;);
  1609. IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__ , dev->name, cmd);
  1610. switch (cmd) {
  1611. case SIOCSBANDWIDTH: /* Set bandwidth */
  1612. IRDA_DEBUG(1, "%s(), SIOCSBANDWIDTH\n", __func__ );
  1613. /*
  1614. * This function will also be used by IrLAP to change the
  1615. * speed, so we still must allow for speed change within
  1616. * interrupt context.
  1617. */
  1618. if (!in_interrupt() && !capable(CAP_NET_ADMIN))
  1619. return -EPERM;
  1620. spin_lock_irqsave(&self->lock, flags);
  1621. ali_ircc_change_speed(self, irq->ifr_baudrate);
  1622. spin_unlock_irqrestore(&self->lock, flags);
  1623. break;
  1624. case SIOCSMEDIABUSY: /* Set media busy */
  1625. IRDA_DEBUG(1, "%s(), SIOCSMEDIABUSY\n", __func__ );
  1626. if (!capable(CAP_NET_ADMIN))
  1627. return -EPERM;
  1628. irda_device_set_media_busy(self->netdev, TRUE);
  1629. break;
  1630. case SIOCGRECEIVING: /* Check if we are receiving right now */
  1631. IRDA_DEBUG(2, "%s(), SIOCGRECEIVING\n", __func__ );
  1632. /* This is protected */
  1633. irq->ifr_receiving = ali_ircc_is_receiving(self);
  1634. break;
  1635. default:
  1636. ret = -EOPNOTSUPP;
  1637. }
  1638. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  1639. return ret;
  1640. }
  1641. /*
  1642. * Function ali_ircc_is_receiving (self)
  1643. *
  1644. * Return TRUE is we are currently receiving a frame
  1645. *
  1646. */
  1647. static int ali_ircc_is_receiving(struct ali_ircc_cb *self)
  1648. {
  1649. unsigned long flags;
  1650. int status = FALSE;
  1651. int iobase;
  1652. IRDA_DEBUG(2, "%s(), ---------------- Start -----------------\n", __func__ );
  1653. IRDA_ASSERT(self != NULL, return FALSE;);
  1654. spin_lock_irqsave(&self->lock, flags);
  1655. if (self->io.speed > 115200)
  1656. {
  1657. iobase = self->io.fir_base;
  1658. switch_bank(iobase, BANK1);
  1659. if((inb(iobase+FIR_FIFO_FR) & 0x3f) != 0)
  1660. {
  1661. /* We are receiving something */
  1662. IRDA_DEBUG(1, "%s(), We are receiving something\n", __func__ );
  1663. status = TRUE;
  1664. }
  1665. switch_bank(iobase, BANK0);
  1666. }
  1667. else
  1668. {
  1669. status = (self->rx_buff.state != OUTSIDE_FRAME);
  1670. }
  1671. spin_unlock_irqrestore(&self->lock, flags);
  1672. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  1673. return status;
  1674. }
  1675. static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state)
  1676. {
  1677. struct ali_ircc_cb *self = platform_get_drvdata(dev);
  1678. IRDA_MESSAGE("%s, Suspending\n", ALI_IRCC_DRIVER_NAME);
  1679. if (self->io.suspended)
  1680. return 0;
  1681. ali_ircc_net_close(self->netdev);
  1682. self->io.suspended = 1;
  1683. return 0;
  1684. }
  1685. static int ali_ircc_resume(struct platform_device *dev)
  1686. {
  1687. struct ali_ircc_cb *self = platform_get_drvdata(dev);
  1688. if (!self->io.suspended)
  1689. return 0;
  1690. ali_ircc_net_open(self->netdev);
  1691. IRDA_MESSAGE("%s, Waking up\n", ALI_IRCC_DRIVER_NAME);
  1692. self->io.suspended = 0;
  1693. return 0;
  1694. }
  1695. /* ALi Chip Function */
  1696. static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable)
  1697. {
  1698. unsigned char newMask;
  1699. int iobase = self->io.fir_base; /* or sir_base */
  1700. IRDA_DEBUG(2, "%s(), -------- Start -------- ( Enable = %d )\n", __func__ , enable);
  1701. /* Enable the interrupt which we wish to */
  1702. if (enable){
  1703. if (self->io.direction == IO_XMIT)
  1704. {
  1705. if (self->io.speed > 115200) /* FIR, MIR */
  1706. {
  1707. newMask = self->ier;
  1708. }
  1709. else /* SIR */
  1710. {
  1711. newMask = UART_IER_THRI | UART_IER_RDI;
  1712. }
  1713. }
  1714. else {
  1715. if (self->io.speed > 115200) /* FIR, MIR */
  1716. {
  1717. newMask = self->ier;
  1718. }
  1719. else /* SIR */
  1720. {
  1721. newMask = UART_IER_RDI;
  1722. }
  1723. }
  1724. }
  1725. else /* Disable all the interrupts */
  1726. {
  1727. newMask = 0x00;
  1728. }
  1729. //SIR and FIR has different registers
  1730. if (self->io.speed > 115200)
  1731. {
  1732. switch_bank(iobase, BANK0);
  1733. outb(newMask, iobase+FIR_IER);
  1734. }
  1735. else
  1736. outb(newMask, iobase+UART_IER);
  1737. IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
  1738. }
  1739. static void SIR2FIR(int iobase)
  1740. {
  1741. //unsigned char tmp;
  1742. IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__ );
  1743. /* Already protected (change_speed() or setup()), no need to lock.
  1744. * Jean II */
  1745. outb(0x28, iobase+UART_MCR);
  1746. outb(0x68, iobase+UART_MCR);
  1747. outb(0x88, iobase+UART_MCR);
  1748. outb(0x60, iobase+FIR_MCR); /* Master Reset */
  1749. outb(0x20, iobase+FIR_MCR); /* Master Interrupt Enable */
  1750. //tmp = inb(iobase+FIR_LCR_B); /* SIP enable */
  1751. //tmp |= 0x20;
  1752. //outb(tmp, iobase+FIR_LCR_B);
  1753. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1754. }
  1755. static void FIR2SIR(int iobase)
  1756. {
  1757. unsigned char val;
  1758. IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __func__ );
  1759. /* Already protected (change_speed() or setup()), no need to lock.
  1760. * Jean II */
  1761. outb(0x20, iobase+FIR_MCR); /* IRQ to low */
  1762. outb(0x00, iobase+UART_IER);
  1763. outb(0xA0, iobase+FIR_MCR); /* Don't set master reset */
  1764. outb(0x00, iobase+UART_FCR);
  1765. outb(0x07, iobase+UART_FCR);
  1766. val = inb(iobase+UART_RX);
  1767. val = inb(iobase+UART_LSR);
  1768. val = inb(iobase+UART_MSR);
  1769. IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
  1770. }
  1771. MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
  1772. MODULE_DESCRIPTION("ALi FIR Controller Driver");
  1773. MODULE_LICENSE("GPL");
  1774. MODULE_ALIAS("platform:" ALI_IRCC_DRIVER_NAME);
  1775. module_param_array(io, int, NULL, 0);
  1776. MODULE_PARM_DESC(io, "Base I/O addresses");
  1777. module_param_array(irq, int, NULL, 0);
  1778. MODULE_PARM_DESC(irq, "IRQ lines");
  1779. module_param_array(dma, int, NULL, 0);
  1780. MODULE_PARM_DESC(dma, "DMA channels");
  1781. module_init(ali_ircc_init);
  1782. module_exit(ali_ircc_cleanup);