ali-ircc.c 57 KB

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