ali-ircc.c 56 KB

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