ali-ircc.c 56 KB

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