smsc-ircc2.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370
  1. /*********************************************************************
  2. * $Id: smsc-ircc2.c,v 1.19.2.5 2002/10/27 11:34:26 dip Exp $
  3. *
  4. * Description: Driver for the SMC Infrared Communications Controller
  5. * Status: Experimental.
  6. * Author: Daniele Peri (peri@csai.unipa.it)
  7. * Created at:
  8. * Modified at:
  9. * Modified by:
  10. *
  11. * Copyright (c) 2002 Daniele Peri
  12. * All Rights Reserved.
  13. * Copyright (c) 2002 Jean Tourrilhes
  14. *
  15. *
  16. * Based on smc-ircc.c:
  17. *
  18. * Copyright (c) 2001 Stefani Seibold
  19. * Copyright (c) 1999-2001 Dag Brattli
  20. * Copyright (c) 1998-1999 Thomas Davis,
  21. *
  22. * and irport.c:
  23. *
  24. * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
  25. *
  26. *
  27. * This program is free software; you can redistribute it and/or
  28. * modify it under the terms of the GNU General Public License as
  29. * published by the Free Software Foundation; either version 2 of
  30. * the License, or (at your option) any later version.
  31. *
  32. * This program is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. * GNU General Public License for more details.
  36. *
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  40. * MA 02111-1307 USA
  41. *
  42. ********************************************************************/
  43. #include <linux/module.h>
  44. #include <linux/kernel.h>
  45. #include <linux/types.h>
  46. #include <linux/skbuff.h>
  47. #include <linux/netdevice.h>
  48. #include <linux/ioport.h>
  49. #include <linux/delay.h>
  50. #include <linux/slab.h>
  51. #include <linux/init.h>
  52. #include <linux/rtnetlink.h>
  53. #include <linux/serial_reg.h>
  54. #include <linux/dma-mapping.h>
  55. #include <asm/io.h>
  56. #include <asm/dma.h>
  57. #include <asm/byteorder.h>
  58. #include <linux/spinlock.h>
  59. #include <linux/pm.h>
  60. #include <net/irda/wrapper.h>
  61. #include <net/irda/irda.h>
  62. #include <net/irda/irda_device.h>
  63. #include "smsc-ircc2.h"
  64. #include "smsc-sio.h"
  65. MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
  66. MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
  67. MODULE_LICENSE("GPL");
  68. static int ircc_dma = 255;
  69. module_param(ircc_dma, int, 0);
  70. MODULE_PARM_DESC(ircc_dma, "DMA channel");
  71. static int ircc_irq = 255;
  72. module_param(ircc_irq, int, 0);
  73. MODULE_PARM_DESC(ircc_irq, "IRQ line");
  74. static int ircc_fir;
  75. module_param(ircc_fir, int, 0);
  76. MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
  77. static int ircc_sir;
  78. module_param(ircc_sir, int, 0);
  79. MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
  80. static int ircc_cfg;
  81. module_param(ircc_cfg, int, 0);
  82. MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
  83. static int ircc_transceiver;
  84. module_param(ircc_transceiver, int, 0);
  85. MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
  86. /* Types */
  87. struct smsc_transceiver {
  88. char *name;
  89. void (*set_for_speed)(int fir_base, u32 speed);
  90. int (*probe)(int fir_base);
  91. };
  92. struct smsc_chip {
  93. char *name;
  94. #if 0
  95. u8 type;
  96. #endif
  97. u16 flags;
  98. u8 devid;
  99. u8 rev;
  100. };
  101. struct smsc_chip_address {
  102. unsigned int cfg_base;
  103. unsigned int type;
  104. };
  105. /* Private data for each instance */
  106. struct smsc_ircc_cb {
  107. struct net_device *netdev; /* Yes! we are some kind of netdevice */
  108. struct net_device_stats stats;
  109. struct irlap_cb *irlap; /* The link layer we are binded to */
  110. chipio_t io; /* IrDA controller information */
  111. iobuff_t tx_buff; /* Transmit buffer */
  112. iobuff_t rx_buff; /* Receive buffer */
  113. dma_addr_t tx_buff_dma;
  114. dma_addr_t rx_buff_dma;
  115. struct qos_info qos; /* QoS capabilities for this device */
  116. spinlock_t lock; /* For serializing operations */
  117. __u32 new_speed;
  118. __u32 flags; /* Interface flags */
  119. int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
  120. int tx_len; /* Number of frames in tx_buff */
  121. int transceiver;
  122. struct platform_device *pldev;
  123. };
  124. /* Constants */
  125. #define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
  126. #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
  127. #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
  128. #define SMSC_IRCC2_C_NET_TIMEOUT 0
  129. #define SMSC_IRCC2_C_SIR_STOP 0
  130. static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
  131. /* Prototypes */
  132. static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
  133. static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
  134. static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
  135. static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
  136. static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
  137. static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
  138. static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
  139. static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
  140. static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
  141. static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
  142. static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
  143. static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
  144. static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
  145. static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
  146. static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
  147. static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  148. static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
  149. static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
  150. #if SMSC_IRCC2_C_SIR_STOP
  151. static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
  152. #endif
  153. static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
  154. static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
  155. static int smsc_ircc_net_open(struct net_device *dev);
  156. static int smsc_ircc_net_close(struct net_device *dev);
  157. static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  158. #if SMSC_IRCC2_C_NET_TIMEOUT
  159. static void smsc_ircc_timeout(struct net_device *dev);
  160. #endif
  161. static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
  162. static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
  163. static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
  164. static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
  165. static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
  166. /* Probing */
  167. static int __init smsc_ircc_look_for_chips(void);
  168. static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
  169. static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
  170. static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
  171. static int __init smsc_superio_fdc(unsigned short cfg_base);
  172. static int __init smsc_superio_lpc(unsigned short cfg_base);
  173. /* Transceivers specific functions */
  174. static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
  175. static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
  176. static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
  177. static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
  178. static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
  179. static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
  180. /* Power Management */
  181. static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level);
  182. static int smsc_ircc_resume(struct device *dev, u32 level);
  183. static struct device_driver smsc_ircc_driver = {
  184. .name = SMSC_IRCC2_DRIVER_NAME,
  185. .bus = &platform_bus_type,
  186. .suspend = smsc_ircc_suspend,
  187. .resume = smsc_ircc_resume,
  188. };
  189. /* Transceivers for SMSC-ircc */
  190. static struct smsc_transceiver smsc_transceivers[] =
  191. {
  192. { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
  193. { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
  194. { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
  195. { NULL, NULL }
  196. };
  197. #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
  198. /* SMC SuperIO chipsets definitions */
  199. #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
  200. #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
  201. #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
  202. #define SIR 0 /* SuperIO Chip has only slow IRDA */
  203. #define FIR 4 /* SuperIO Chip has fast IRDA */
  204. #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
  205. static struct smsc_chip __initdata fdc_chips_flat[] =
  206. {
  207. /* Base address 0x3f0 or 0x370 */
  208. { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
  209. { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
  210. { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
  211. { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
  212. { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
  213. { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
  214. { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
  215. { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
  216. { NULL }
  217. };
  218. static struct smsc_chip __initdata fdc_chips_paged[] =
  219. {
  220. /* Base address 0x3f0 or 0x370 */
  221. { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
  222. { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
  223. { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
  224. { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
  225. { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
  226. { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
  227. { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
  228. { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
  229. { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
  230. { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
  231. { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
  232. { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
  233. { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
  234. { NULL }
  235. };
  236. static struct smsc_chip __initdata lpc_chips_flat[] =
  237. {
  238. /* Base address 0x2E or 0x4E */
  239. { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
  240. { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
  241. { NULL }
  242. };
  243. static struct smsc_chip __initdata lpc_chips_paged[] =
  244. {
  245. /* Base address 0x2E or 0x4E */
  246. { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
  247. { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
  248. { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
  249. { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
  250. { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
  251. { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
  252. { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
  253. { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
  254. { NULL }
  255. };
  256. #define SMSCSIO_TYPE_FDC 1
  257. #define SMSCSIO_TYPE_LPC 2
  258. #define SMSCSIO_TYPE_FLAT 4
  259. #define SMSCSIO_TYPE_PAGED 8
  260. static struct smsc_chip_address __initdata possible_addresses[] =
  261. {
  262. { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  263. { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  264. { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  265. { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  266. { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  267. { 0, 0 }
  268. };
  269. /* Globals */
  270. static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
  271. static unsigned short dev_count;
  272. static inline void register_bank(int iobase, int bank)
  273. {
  274. outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
  275. iobase + IRCC_MASTER);
  276. }
  277. /*******************************************************************************
  278. *
  279. *
  280. * SMSC-ircc stuff
  281. *
  282. *
  283. *******************************************************************************/
  284. /*
  285. * Function smsc_ircc_init ()
  286. *
  287. * Initialize chip. Just try to find out how many chips we are dealing with
  288. * and where they are
  289. */
  290. static int __init smsc_ircc_init(void)
  291. {
  292. int ret;
  293. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  294. ret = driver_register(&smsc_ircc_driver);
  295. if (ret) {
  296. IRDA_ERROR("%s, Can't register driver!\n", driver_name);
  297. return ret;
  298. }
  299. dev_count = 0;
  300. if (ircc_fir > 0 && ircc_sir > 0) {
  301. IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
  302. IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
  303. if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
  304. ret = -ENODEV;
  305. } else {
  306. /* try user provided configuration register base address */
  307. if (ircc_cfg > 0) {
  308. IRDA_MESSAGE(" Overriding configuration address "
  309. "0x%04x\n", ircc_cfg);
  310. if (!smsc_superio_fdc(ircc_cfg))
  311. ret = 0;
  312. if (!smsc_superio_lpc(ircc_cfg))
  313. ret = 0;
  314. }
  315. if (smsc_ircc_look_for_chips() > 0)
  316. ret = 0;
  317. }
  318. if (ret)
  319. driver_unregister(&smsc_ircc_driver);
  320. return ret;
  321. }
  322. /*
  323. * Function smsc_ircc_open (firbase, sirbase, dma, irq)
  324. *
  325. * Try to open driver instance
  326. *
  327. */
  328. static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
  329. {
  330. struct smsc_ircc_cb *self;
  331. struct net_device *dev;
  332. int err;
  333. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  334. err = smsc_ircc_present(fir_base, sir_base);
  335. if (err)
  336. goto err_out;
  337. err = -ENOMEM;
  338. if (dev_count >= ARRAY_SIZE(dev_self)) {
  339. IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
  340. goto err_out1;
  341. }
  342. /*
  343. * Allocate new instance of the driver
  344. */
  345. dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
  346. if (!dev) {
  347. IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
  348. goto err_out1;
  349. }
  350. SET_MODULE_OWNER(dev);
  351. dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
  352. #if SMSC_IRCC2_C_NET_TIMEOUT
  353. dev->tx_timeout = smsc_ircc_timeout;
  354. dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
  355. #endif
  356. dev->open = smsc_ircc_net_open;
  357. dev->stop = smsc_ircc_net_close;
  358. dev->do_ioctl = smsc_ircc_net_ioctl;
  359. dev->get_stats = smsc_ircc_net_get_stats;
  360. self = netdev_priv(dev);
  361. self->netdev = dev;
  362. /* Make ifconfig display some details */
  363. dev->base_addr = self->io.fir_base = fir_base;
  364. dev->irq = self->io.irq = irq;
  365. /* Need to store self somewhere */
  366. dev_self[dev_count] = self;
  367. spin_lock_init(&self->lock);
  368. self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
  369. self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
  370. self->rx_buff.head =
  371. dma_alloc_coherent(NULL, self->rx_buff.truesize,
  372. &self->rx_buff_dma, GFP_KERNEL);
  373. if (self->rx_buff.head == NULL) {
  374. IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
  375. driver_name);
  376. goto err_out2;
  377. }
  378. self->tx_buff.head =
  379. dma_alloc_coherent(NULL, self->tx_buff.truesize,
  380. &self->tx_buff_dma, GFP_KERNEL);
  381. if (self->tx_buff.head == NULL) {
  382. IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
  383. driver_name);
  384. goto err_out3;
  385. }
  386. memset(self->rx_buff.head, 0, self->rx_buff.truesize);
  387. memset(self->tx_buff.head, 0, self->tx_buff.truesize);
  388. self->rx_buff.in_frame = FALSE;
  389. self->rx_buff.state = OUTSIDE_FRAME;
  390. self->tx_buff.data = self->tx_buff.head;
  391. self->rx_buff.data = self->rx_buff.head;
  392. smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
  393. smsc_ircc_setup_qos(self);
  394. smsc_ircc_init_chip(self);
  395. if (ircc_transceiver > 0 &&
  396. ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
  397. self->transceiver = ircc_transceiver;
  398. else
  399. smsc_ircc_probe_transceiver(self);
  400. err = register_netdev(self->netdev);
  401. if (err) {
  402. IRDA_ERROR("%s, Network device registration failed!\n",
  403. driver_name);
  404. goto err_out4;
  405. }
  406. self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
  407. dev_count, NULL, 0);
  408. if (IS_ERR(self->pldev)) {
  409. err = PTR_ERR(self->pldev);
  410. goto err_out5;
  411. }
  412. dev_set_drvdata(&self->pldev->dev, self);
  413. IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
  414. dev_count++;
  415. return 0;
  416. err_out5:
  417. unregister_netdev(self->netdev);
  418. err_out4:
  419. dma_free_coherent(NULL, self->tx_buff.truesize,
  420. self->tx_buff.head, self->tx_buff_dma);
  421. err_out3:
  422. dma_free_coherent(NULL, self->rx_buff.truesize,
  423. self->rx_buff.head, self->rx_buff_dma);
  424. err_out2:
  425. free_netdev(self->netdev);
  426. dev_self[dev_count] = NULL;
  427. err_out1:
  428. release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
  429. release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
  430. err_out:
  431. return err;
  432. }
  433. /*
  434. * Function smsc_ircc_present(fir_base, sir_base)
  435. *
  436. * Check the smsc-ircc chip presence
  437. *
  438. */
  439. static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
  440. {
  441. unsigned char low, high, chip, config, dma, irq, version;
  442. if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
  443. driver_name)) {
  444. IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
  445. __FUNCTION__, fir_base);
  446. goto out1;
  447. }
  448. if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
  449. driver_name)) {
  450. IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
  451. __FUNCTION__, sir_base);
  452. goto out2;
  453. }
  454. register_bank(fir_base, 3);
  455. high = inb(fir_base + IRCC_ID_HIGH);
  456. low = inb(fir_base + IRCC_ID_LOW);
  457. chip = inb(fir_base + IRCC_CHIP_ID);
  458. version = inb(fir_base + IRCC_VERSION);
  459. config = inb(fir_base + IRCC_INTERFACE);
  460. dma = config & IRCC_INTERFACE_DMA_MASK;
  461. irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
  462. if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
  463. IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
  464. __FUNCTION__, fir_base);
  465. goto out3;
  466. }
  467. IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
  468. "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
  469. chip & 0x0f, version, fir_base, sir_base, dma, irq);
  470. return 0;
  471. out3:
  472. release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
  473. out2:
  474. release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
  475. out1:
  476. return -ENODEV;
  477. }
  478. /*
  479. * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
  480. *
  481. * Setup I/O
  482. *
  483. */
  484. static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
  485. unsigned int fir_base, unsigned int sir_base,
  486. u8 dma, u8 irq)
  487. {
  488. unsigned char config, chip_dma, chip_irq;
  489. register_bank(fir_base, 3);
  490. config = inb(fir_base + IRCC_INTERFACE);
  491. chip_dma = config & IRCC_INTERFACE_DMA_MASK;
  492. chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
  493. self->io.fir_base = fir_base;
  494. self->io.sir_base = sir_base;
  495. self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
  496. self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
  497. self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
  498. self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
  499. if (irq < 255) {
  500. if (irq != chip_irq)
  501. IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
  502. driver_name, chip_irq, irq);
  503. self->io.irq = irq;
  504. } else
  505. self->io.irq = chip_irq;
  506. if (dma < 255) {
  507. if (dma != chip_dma)
  508. IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
  509. driver_name, chip_dma, dma);
  510. self->io.dma = dma;
  511. } else
  512. self->io.dma = chip_dma;
  513. }
  514. /*
  515. * Function smsc_ircc_setup_qos(self)
  516. *
  517. * Setup qos
  518. *
  519. */
  520. static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
  521. {
  522. /* Initialize QoS for this device */
  523. irda_init_max_qos_capabilies(&self->qos);
  524. self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
  525. IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
  526. self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
  527. self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
  528. irda_qos_bits_to_value(&self->qos);
  529. }
  530. /*
  531. * Function smsc_ircc_init_chip(self)
  532. *
  533. * Init chip
  534. *
  535. */
  536. static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
  537. {
  538. int iobase, ir_mode, ctrl, fast;
  539. IRDA_ASSERT(self != NULL, return;);
  540. iobase = self->io.fir_base;
  541. ir_mode = IRCC_CFGA_IRDA_SIR_A;
  542. ctrl = 0;
  543. fast = 0;
  544. register_bank(iobase, 0);
  545. outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
  546. outb(0x00, iobase + IRCC_MASTER);
  547. register_bank(iobase, 1);
  548. outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode),
  549. iobase + IRCC_SCE_CFGA);
  550. #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
  551. outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
  552. iobase + IRCC_SCE_CFGB);
  553. #else
  554. outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
  555. iobase + IRCC_SCE_CFGB);
  556. #endif
  557. (void) inb(iobase + IRCC_FIFO_THRESHOLD);
  558. outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
  559. register_bank(iobase, 4);
  560. outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL);
  561. register_bank(iobase, 0);
  562. outb(fast, iobase + IRCC_LCR_A);
  563. smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
  564. /* Power on device */
  565. outb(0x00, iobase + IRCC_MASTER);
  566. }
  567. /*
  568. * Function smsc_ircc_net_ioctl (dev, rq, cmd)
  569. *
  570. * Process IOCTL commands for this device
  571. *
  572. */
  573. static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  574. {
  575. struct if_irda_req *irq = (struct if_irda_req *) rq;
  576. struct smsc_ircc_cb *self;
  577. unsigned long flags;
  578. int ret = 0;
  579. IRDA_ASSERT(dev != NULL, return -1;);
  580. self = netdev_priv(dev);
  581. IRDA_ASSERT(self != NULL, return -1;);
  582. IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
  583. switch (cmd) {
  584. case SIOCSBANDWIDTH: /* Set bandwidth */
  585. if (!capable(CAP_NET_ADMIN))
  586. ret = -EPERM;
  587. else {
  588. /* Make sure we are the only one touching
  589. * self->io.speed and the hardware - Jean II */
  590. spin_lock_irqsave(&self->lock, flags);
  591. smsc_ircc_change_speed(self, irq->ifr_baudrate);
  592. spin_unlock_irqrestore(&self->lock, flags);
  593. }
  594. break;
  595. case SIOCSMEDIABUSY: /* Set media busy */
  596. if (!capable(CAP_NET_ADMIN)) {
  597. ret = -EPERM;
  598. break;
  599. }
  600. irda_device_set_media_busy(self->netdev, TRUE);
  601. break;
  602. case SIOCGRECEIVING: /* Check if we are receiving right now */
  603. irq->ifr_receiving = smsc_ircc_is_receiving(self);
  604. break;
  605. #if 0
  606. case SIOCSDTRRTS:
  607. if (!capable(CAP_NET_ADMIN)) {
  608. ret = -EPERM;
  609. break;
  610. }
  611. smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
  612. break;
  613. #endif
  614. default:
  615. ret = -EOPNOTSUPP;
  616. }
  617. return ret;
  618. }
  619. static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
  620. {
  621. struct smsc_ircc_cb *self = netdev_priv(dev);
  622. return &self->stats;
  623. }
  624. #if SMSC_IRCC2_C_NET_TIMEOUT
  625. /*
  626. * Function smsc_ircc_timeout (struct net_device *dev)
  627. *
  628. * The networking timeout management.
  629. *
  630. */
  631. static void smsc_ircc_timeout(struct net_device *dev)
  632. {
  633. struct smsc_ircc_cb *self = netdev_priv(dev);
  634. unsigned long flags;
  635. IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
  636. dev->name, self->io.speed);
  637. spin_lock_irqsave(&self->lock, flags);
  638. smsc_ircc_sir_start(self);
  639. smsc_ircc_change_speed(self, self->io.speed);
  640. dev->trans_start = jiffies;
  641. netif_wake_queue(dev);
  642. spin_unlock_irqrestore(&self->lock, flags);
  643. }
  644. #endif
  645. /*
  646. * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
  647. *
  648. * Transmits the current frame until FIFO is full, then
  649. * waits until the next transmit interrupt, and continues until the
  650. * frame is transmitted.
  651. */
  652. int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
  653. {
  654. struct smsc_ircc_cb *self;
  655. unsigned long flags;
  656. s32 speed;
  657. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  658. IRDA_ASSERT(dev != NULL, return 0;);
  659. self = netdev_priv(dev);
  660. IRDA_ASSERT(self != NULL, return 0;);
  661. netif_stop_queue(dev);
  662. /* Make sure test of self->io.speed & speed change are atomic */
  663. spin_lock_irqsave(&self->lock, flags);
  664. /* Check if we need to change the speed */
  665. speed = irda_get_next_speed(skb);
  666. if (speed != self->io.speed && speed != -1) {
  667. /* Check for empty frame */
  668. if (!skb->len) {
  669. /*
  670. * We send frames one by one in SIR mode (no
  671. * pipelining), so at this point, if we were sending
  672. * a previous frame, we just received the interrupt
  673. * telling us it is finished (UART_IIR_THRI).
  674. * Therefore, waiting for the transmitter to really
  675. * finish draining the fifo won't take too long.
  676. * And the interrupt handler is not expected to run.
  677. * - Jean II */
  678. smsc_ircc_sir_wait_hw_transmitter_finish(self);
  679. smsc_ircc_change_speed(self, speed);
  680. spin_unlock_irqrestore(&self->lock, flags);
  681. dev_kfree_skb(skb);
  682. return 0;
  683. }
  684. self->new_speed = speed;
  685. }
  686. /* Init tx buffer */
  687. self->tx_buff.data = self->tx_buff.head;
  688. /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
  689. self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
  690. self->tx_buff.truesize);
  691. self->stats.tx_bytes += self->tx_buff.len;
  692. /* Turn on transmit finished interrupt. Will fire immediately! */
  693. outb(UART_IER_THRI, self->io.sir_base + UART_IER);
  694. spin_unlock_irqrestore(&self->lock, flags);
  695. dev_kfree_skb(skb);
  696. return 0;
  697. }
  698. /*
  699. * Function smsc_ircc_set_fir_speed (self, baud)
  700. *
  701. * Change the speed of the device
  702. *
  703. */
  704. static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
  705. {
  706. int fir_base, ir_mode, ctrl, fast;
  707. IRDA_ASSERT(self != NULL, return;);
  708. fir_base = self->io.fir_base;
  709. self->io.speed = speed;
  710. switch (speed) {
  711. default:
  712. case 576000:
  713. ir_mode = IRCC_CFGA_IRDA_HDLC;
  714. ctrl = IRCC_CRC;
  715. fast = 0;
  716. IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
  717. break;
  718. case 1152000:
  719. ir_mode = IRCC_CFGA_IRDA_HDLC;
  720. ctrl = IRCC_1152 | IRCC_CRC;
  721. fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
  722. IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
  723. __FUNCTION__);
  724. break;
  725. case 4000000:
  726. ir_mode = IRCC_CFGA_IRDA_4PPM;
  727. ctrl = IRCC_CRC;
  728. fast = IRCC_LCR_A_FAST;
  729. IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
  730. __FUNCTION__);
  731. break;
  732. }
  733. #if 0
  734. Now in tranceiver!
  735. /* This causes an interrupt */
  736. register_bank(fir_base, 0);
  737. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
  738. #endif
  739. register_bank(fir_base, 1);
  740. outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
  741. register_bank(fir_base, 4);
  742. outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
  743. }
  744. /*
  745. * Function smsc_ircc_fir_start(self)
  746. *
  747. * Change the speed of the device
  748. *
  749. */
  750. static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
  751. {
  752. struct net_device *dev;
  753. int fir_base;
  754. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  755. IRDA_ASSERT(self != NULL, return;);
  756. dev = self->netdev;
  757. IRDA_ASSERT(dev != NULL, return;);
  758. fir_base = self->io.fir_base;
  759. /* Reset everything */
  760. /* Install FIR transmit handler */
  761. dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
  762. /* Clear FIFO */
  763. outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
  764. /* Enable interrupt */
  765. /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
  766. register_bank(fir_base, 1);
  767. /* Select the TX/RX interface */
  768. #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
  769. outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
  770. fir_base + IRCC_SCE_CFGB);
  771. #else
  772. outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
  773. fir_base + IRCC_SCE_CFGB);
  774. #endif
  775. (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
  776. /* Enable SCE interrupts */
  777. outb(0, fir_base + IRCC_MASTER);
  778. register_bank(fir_base, 0);
  779. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
  780. outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
  781. }
  782. /*
  783. * Function smsc_ircc_fir_stop(self, baud)
  784. *
  785. * Change the speed of the device
  786. *
  787. */
  788. static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
  789. {
  790. int fir_base;
  791. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  792. IRDA_ASSERT(self != NULL, return;);
  793. fir_base = self->io.fir_base;
  794. register_bank(fir_base, 0);
  795. /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
  796. outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
  797. }
  798. /*
  799. * Function smsc_ircc_change_speed(self, baud)
  800. *
  801. * Change the speed of the device
  802. *
  803. * This function *must* be called with spinlock held, because it may
  804. * be called from the irq handler. - Jean II
  805. */
  806. static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
  807. {
  808. struct net_device *dev;
  809. int last_speed_was_sir;
  810. IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
  811. IRDA_ASSERT(self != NULL, return;);
  812. dev = self->netdev;
  813. last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
  814. #if 0
  815. /* Temp Hack */
  816. speed= 1152000;
  817. self->io.speed = speed;
  818. last_speed_was_sir = 0;
  819. smsc_ircc_fir_start(self);
  820. #endif
  821. if (self->io.speed == 0)
  822. smsc_ircc_sir_start(self);
  823. #if 0
  824. if (!last_speed_was_sir) speed = self->io.speed;
  825. #endif
  826. if (self->io.speed != speed)
  827. smsc_ircc_set_transceiver_for_speed(self, speed);
  828. self->io.speed = speed;
  829. if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
  830. if (!last_speed_was_sir) {
  831. smsc_ircc_fir_stop(self);
  832. smsc_ircc_sir_start(self);
  833. }
  834. smsc_ircc_set_sir_speed(self, speed);
  835. } else {
  836. if (last_speed_was_sir) {
  837. #if SMSC_IRCC2_C_SIR_STOP
  838. smsc_ircc_sir_stop(self);
  839. #endif
  840. smsc_ircc_fir_start(self);
  841. }
  842. smsc_ircc_set_fir_speed(self, speed);
  843. #if 0
  844. self->tx_buff.len = 10;
  845. self->tx_buff.data = self->tx_buff.head;
  846. smsc_ircc_dma_xmit(self, 4000);
  847. #endif
  848. /* Be ready for incoming frames */
  849. smsc_ircc_dma_receive(self);
  850. }
  851. netif_wake_queue(dev);
  852. }
  853. /*
  854. * Function smsc_ircc_set_sir_speed (self, speed)
  855. *
  856. * Set speed of IrDA port to specified baudrate
  857. *
  858. */
  859. void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
  860. {
  861. int iobase;
  862. int fcr; /* FIFO control reg */
  863. int lcr; /* Line control reg */
  864. int divisor;
  865. IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
  866. IRDA_ASSERT(self != NULL, return;);
  867. iobase = self->io.sir_base;
  868. /* Update accounting for new speed */
  869. self->io.speed = speed;
  870. /* Turn off interrupts */
  871. outb(0, iobase + UART_IER);
  872. divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
  873. fcr = UART_FCR_ENABLE_FIFO;
  874. /*
  875. * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
  876. * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
  877. * about this timeout since it will always be fast enough.
  878. */
  879. fcr |= self->io.speed < 38400 ?
  880. UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
  881. /* IrDA ports use 8N1 */
  882. lcr = UART_LCR_WLEN8;
  883. outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
  884. outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
  885. outb(divisor >> 8, iobase + UART_DLM);
  886. outb(lcr, iobase + UART_LCR); /* Set 8N1 */
  887. outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
  888. /* Turn on interrups */
  889. outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
  890. IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
  891. }
  892. /*
  893. * Function smsc_ircc_hard_xmit_fir (skb, dev)
  894. *
  895. * Transmit the frame!
  896. *
  897. */
  898. static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
  899. {
  900. struct smsc_ircc_cb *self;
  901. unsigned long flags;
  902. s32 speed;
  903. int mtt;
  904. IRDA_ASSERT(dev != NULL, return 0;);
  905. self = netdev_priv(dev);
  906. IRDA_ASSERT(self != NULL, return 0;);
  907. netif_stop_queue(dev);
  908. /* Make sure test of self->io.speed & speed change are atomic */
  909. spin_lock_irqsave(&self->lock, flags);
  910. /* Check if we need to change the speed after this frame */
  911. speed = irda_get_next_speed(skb);
  912. if (speed != self->io.speed && speed != -1) {
  913. /* Check for empty frame */
  914. if (!skb->len) {
  915. /* Note : you should make sure that speed changes
  916. * are not going to corrupt any outgoing frame.
  917. * Look at nsc-ircc for the gory details - Jean II */
  918. smsc_ircc_change_speed(self, speed);
  919. spin_unlock_irqrestore(&self->lock, flags);
  920. dev_kfree_skb(skb);
  921. return 0;
  922. }
  923. self->new_speed = speed;
  924. }
  925. memcpy(self->tx_buff.head, skb->data, skb->len);
  926. self->tx_buff.len = skb->len;
  927. self->tx_buff.data = self->tx_buff.head;
  928. mtt = irda_get_mtt(skb);
  929. if (mtt) {
  930. int bofs;
  931. /*
  932. * Compute how many BOFs (STA or PA's) we need to waste the
  933. * min turn time given the speed of the link.
  934. */
  935. bofs = mtt * (self->io.speed / 1000) / 8000;
  936. if (bofs > 4095)
  937. bofs = 4095;
  938. smsc_ircc_dma_xmit(self, bofs);
  939. } else {
  940. /* Transmit frame */
  941. smsc_ircc_dma_xmit(self, 0);
  942. }
  943. spin_unlock_irqrestore(&self->lock, flags);
  944. dev_kfree_skb(skb);
  945. return 0;
  946. }
  947. /*
  948. * Function smsc_ircc_dma_xmit (self, bofs)
  949. *
  950. * Transmit data using DMA
  951. *
  952. */
  953. static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
  954. {
  955. int iobase = self->io.fir_base;
  956. u8 ctrl;
  957. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  958. #if 1
  959. /* Disable Rx */
  960. register_bank(iobase, 0);
  961. outb(0x00, iobase + IRCC_LCR_B);
  962. #endif
  963. register_bank(iobase, 1);
  964. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  965. iobase + IRCC_SCE_CFGB);
  966. self->io.direction = IO_XMIT;
  967. /* Set BOF additional count for generating the min turn time */
  968. register_bank(iobase, 4);
  969. outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
  970. ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
  971. outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
  972. /* Set max Tx frame size */
  973. outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
  974. outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
  975. /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
  976. /* Enable burst mode chip Tx DMA */
  977. register_bank(iobase, 1);
  978. outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
  979. IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
  980. /* Setup DMA controller (must be done after enabling chip DMA) */
  981. irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
  982. DMA_TX_MODE);
  983. /* Enable interrupt */
  984. register_bank(iobase, 0);
  985. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  986. outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
  987. /* Enable transmit */
  988. outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
  989. }
  990. /*
  991. * Function smsc_ircc_dma_xmit_complete (self)
  992. *
  993. * The transfer of a frame in finished. This function will only be called
  994. * by the interrupt handler
  995. *
  996. */
  997. static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
  998. {
  999. int iobase = self->io.fir_base;
  1000. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1001. #if 0
  1002. /* Disable Tx */
  1003. register_bank(iobase, 0);
  1004. outb(0x00, iobase + IRCC_LCR_B);
  1005. #endif
  1006. register_bank(iobase, 1);
  1007. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1008. iobase + IRCC_SCE_CFGB);
  1009. /* Check for underrun! */
  1010. register_bank(iobase, 0);
  1011. if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
  1012. self->stats.tx_errors++;
  1013. self->stats.tx_fifo_errors++;
  1014. /* Reset error condition */
  1015. register_bank(iobase, 0);
  1016. outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
  1017. outb(0x00, iobase + IRCC_MASTER);
  1018. } else {
  1019. self->stats.tx_packets++;
  1020. self->stats.tx_bytes += self->tx_buff.len;
  1021. }
  1022. /* Check if it's time to change the speed */
  1023. if (self->new_speed) {
  1024. smsc_ircc_change_speed(self, self->new_speed);
  1025. self->new_speed = 0;
  1026. }
  1027. netif_wake_queue(self->netdev);
  1028. }
  1029. /*
  1030. * Function smsc_ircc_dma_receive(self)
  1031. *
  1032. * Get ready for receiving a frame. The device will initiate a DMA
  1033. * if it starts to receive a frame.
  1034. *
  1035. */
  1036. static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
  1037. {
  1038. int iobase = self->io.fir_base;
  1039. #if 0
  1040. /* Turn off chip DMA */
  1041. register_bank(iobase, 1);
  1042. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1043. iobase + IRCC_SCE_CFGB);
  1044. #endif
  1045. /* Disable Tx */
  1046. register_bank(iobase, 0);
  1047. outb(0x00, iobase + IRCC_LCR_B);
  1048. /* Turn off chip DMA */
  1049. register_bank(iobase, 1);
  1050. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1051. iobase + IRCC_SCE_CFGB);
  1052. self->io.direction = IO_RECV;
  1053. self->rx_buff.data = self->rx_buff.head;
  1054. /* Set max Rx frame size */
  1055. register_bank(iobase, 4);
  1056. outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
  1057. outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
  1058. /* Setup DMA controller */
  1059. irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
  1060. DMA_RX_MODE);
  1061. /* Enable burst mode chip Rx DMA */
  1062. register_bank(iobase, 1);
  1063. outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
  1064. IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
  1065. /* Enable interrupt */
  1066. register_bank(iobase, 0);
  1067. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  1068. outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
  1069. /* Enable receiver */
  1070. register_bank(iobase, 0);
  1071. outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
  1072. iobase + IRCC_LCR_B);
  1073. return 0;
  1074. }
  1075. /*
  1076. * Function smsc_ircc_dma_receive_complete(self)
  1077. *
  1078. * Finished with receiving frames
  1079. *
  1080. */
  1081. static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
  1082. {
  1083. struct sk_buff *skb;
  1084. int len, msgcnt, lsr;
  1085. int iobase = self->io.fir_base;
  1086. register_bank(iobase, 0);
  1087. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1088. #if 0
  1089. /* Disable Rx */
  1090. register_bank(iobase, 0);
  1091. outb(0x00, iobase + IRCC_LCR_B);
  1092. #endif
  1093. register_bank(iobase, 0);
  1094. outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
  1095. lsr= inb(iobase + IRCC_LSR);
  1096. msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
  1097. IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
  1098. get_dma_residue(self->io.dma));
  1099. len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
  1100. /* Look for errors */
  1101. if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
  1102. self->stats.rx_errors++;
  1103. if (lsr & IRCC_LSR_FRAME_ERROR)
  1104. self->stats.rx_frame_errors++;
  1105. if (lsr & IRCC_LSR_CRC_ERROR)
  1106. self->stats.rx_crc_errors++;
  1107. if (lsr & IRCC_LSR_SIZE_ERROR)
  1108. self->stats.rx_length_errors++;
  1109. if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
  1110. self->stats.rx_length_errors++;
  1111. return;
  1112. }
  1113. /* Remove CRC */
  1114. len -= self->io.speed < 4000000 ? 2 : 4;
  1115. if (len < 2 || len > 2050) {
  1116. IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
  1117. return;
  1118. }
  1119. IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
  1120. skb = dev_alloc_skb(len + 1);
  1121. if (!skb) {
  1122. IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
  1123. __FUNCTION__);
  1124. return;
  1125. }
  1126. /* Make sure IP header gets aligned */
  1127. skb_reserve(skb, 1);
  1128. memcpy(skb_put(skb, len), self->rx_buff.data, len);
  1129. self->stats.rx_packets++;
  1130. self->stats.rx_bytes += len;
  1131. skb->dev = self->netdev;
  1132. skb->mac.raw = skb->data;
  1133. skb->protocol = htons(ETH_P_IRDA);
  1134. netif_rx(skb);
  1135. }
  1136. /*
  1137. * Function smsc_ircc_sir_receive (self)
  1138. *
  1139. * Receive one frame from the infrared port
  1140. *
  1141. */
  1142. static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
  1143. {
  1144. int boguscount = 0;
  1145. int iobase;
  1146. IRDA_ASSERT(self != NULL, return;);
  1147. iobase = self->io.sir_base;
  1148. /*
  1149. * Receive all characters in Rx FIFO, unwrap and unstuff them.
  1150. * async_unwrap_char will deliver all found frames
  1151. */
  1152. do {
  1153. async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
  1154. inb(iobase + UART_RX));
  1155. /* Make sure we don't stay here to long */
  1156. if (boguscount++ > 32) {
  1157. IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
  1158. break;
  1159. }
  1160. } while (inb(iobase + UART_LSR) & UART_LSR_DR);
  1161. }
  1162. /*
  1163. * Function smsc_ircc_interrupt (irq, dev_id, regs)
  1164. *
  1165. * An interrupt from the chip has arrived. Time to do some work
  1166. *
  1167. */
  1168. static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1169. {
  1170. struct net_device *dev = (struct net_device *) dev_id;
  1171. struct smsc_ircc_cb *self;
  1172. int iobase, iir, lcra, lsr;
  1173. irqreturn_t ret = IRQ_NONE;
  1174. if (dev == NULL) {
  1175. printk(KERN_WARNING "%s: irq %d for unknown device.\n",
  1176. driver_name, irq);
  1177. goto irq_ret;
  1178. }
  1179. self = netdev_priv(dev);
  1180. IRDA_ASSERT(self != NULL, return IRQ_NONE;);
  1181. /* Serialise the interrupt handler in various CPUs, stop Tx path */
  1182. spin_lock(&self->lock);
  1183. /* Check if we should use the SIR interrupt handler */
  1184. if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
  1185. ret = smsc_ircc_interrupt_sir(dev);
  1186. goto irq_ret_unlock;
  1187. }
  1188. iobase = self->io.fir_base;
  1189. register_bank(iobase, 0);
  1190. iir = inb(iobase + IRCC_IIR);
  1191. if (iir == 0)
  1192. goto irq_ret_unlock;
  1193. ret = IRQ_HANDLED;
  1194. /* Disable interrupts */
  1195. outb(0, iobase + IRCC_IER);
  1196. lcra = inb(iobase + IRCC_LCR_A);
  1197. lsr = inb(iobase + IRCC_LSR);
  1198. IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
  1199. if (iir & IRCC_IIR_EOM) {
  1200. if (self->io.direction == IO_RECV)
  1201. smsc_ircc_dma_receive_complete(self);
  1202. else
  1203. smsc_ircc_dma_xmit_complete(self);
  1204. smsc_ircc_dma_receive(self);
  1205. }
  1206. if (iir & IRCC_IIR_ACTIVE_FRAME) {
  1207. /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
  1208. }
  1209. /* Enable interrupts again */
  1210. register_bank(iobase, 0);
  1211. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  1212. irq_ret_unlock:
  1213. spin_unlock(&self->lock);
  1214. irq_ret:
  1215. return ret;
  1216. }
  1217. /*
  1218. * Function irport_interrupt_sir (irq, dev_id, regs)
  1219. *
  1220. * Interrupt handler for SIR modes
  1221. */
  1222. static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
  1223. {
  1224. struct smsc_ircc_cb *self = netdev_priv(dev);
  1225. int boguscount = 0;
  1226. int iobase;
  1227. int iir, lsr;
  1228. /* Already locked comming here in smsc_ircc_interrupt() */
  1229. /*spin_lock(&self->lock);*/
  1230. iobase = self->io.sir_base;
  1231. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  1232. if (iir == 0)
  1233. return IRQ_NONE;
  1234. while (iir) {
  1235. /* Clear interrupt */
  1236. lsr = inb(iobase + UART_LSR);
  1237. IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
  1238. __FUNCTION__, iir, lsr, iobase);
  1239. switch (iir) {
  1240. case UART_IIR_RLSI:
  1241. IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
  1242. break;
  1243. case UART_IIR_RDI:
  1244. /* Receive interrupt */
  1245. smsc_ircc_sir_receive(self);
  1246. break;
  1247. case UART_IIR_THRI:
  1248. if (lsr & UART_LSR_THRE)
  1249. /* Transmitter ready for data */
  1250. smsc_ircc_sir_write_wakeup(self);
  1251. break;
  1252. default:
  1253. IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
  1254. __FUNCTION__, iir);
  1255. break;
  1256. }
  1257. /* Make sure we don't stay here to long */
  1258. if (boguscount++ > 100)
  1259. break;
  1260. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  1261. }
  1262. /*spin_unlock(&self->lock);*/
  1263. return IRQ_HANDLED;
  1264. }
  1265. #if 0 /* unused */
  1266. /*
  1267. * Function ircc_is_receiving (self)
  1268. *
  1269. * Return TRUE is we are currently receiving a frame
  1270. *
  1271. */
  1272. static int ircc_is_receiving(struct smsc_ircc_cb *self)
  1273. {
  1274. int status = FALSE;
  1275. /* int iobase; */
  1276. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1277. IRDA_ASSERT(self != NULL, return FALSE;);
  1278. IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
  1279. get_dma_residue(self->io.dma));
  1280. status = (self->rx_buff.state != OUTSIDE_FRAME);
  1281. return status;
  1282. }
  1283. #endif /* unused */
  1284. /*
  1285. * Function smsc_ircc_net_open (dev)
  1286. *
  1287. * Start the device
  1288. *
  1289. */
  1290. static int smsc_ircc_net_open(struct net_device *dev)
  1291. {
  1292. struct smsc_ircc_cb *self;
  1293. char hwname[16];
  1294. unsigned long flags;
  1295. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1296. IRDA_ASSERT(dev != NULL, return -1;);
  1297. self = netdev_priv(dev);
  1298. IRDA_ASSERT(self != NULL, return 0;);
  1299. if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
  1300. (void *) dev)) {
  1301. IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
  1302. __FUNCTION__, self->io.irq);
  1303. return -EAGAIN;
  1304. }
  1305. spin_lock_irqsave(&self->lock, flags);
  1306. /*smsc_ircc_sir_start(self);*/
  1307. self->io.speed = 0;
  1308. smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
  1309. spin_unlock_irqrestore(&self->lock, flags);
  1310. /* Give self a hardware name */
  1311. /* It would be cool to offer the chip revision here - Jean II */
  1312. sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
  1313. /*
  1314. * Open new IrLAP layer instance, now that everything should be
  1315. * initialized properly
  1316. */
  1317. self->irlap = irlap_open(dev, &self->qos, hwname);
  1318. /*
  1319. * Always allocate the DMA channel after the IRQ,
  1320. * and clean up on failure.
  1321. */
  1322. if (request_dma(self->io.dma, dev->name)) {
  1323. smsc_ircc_net_close(dev);
  1324. IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
  1325. __FUNCTION__, self->io.dma);
  1326. return -EAGAIN;
  1327. }
  1328. netif_start_queue(dev);
  1329. return 0;
  1330. }
  1331. /*
  1332. * Function smsc_ircc_net_close (dev)
  1333. *
  1334. * Stop the device
  1335. *
  1336. */
  1337. static int smsc_ircc_net_close(struct net_device *dev)
  1338. {
  1339. struct smsc_ircc_cb *self;
  1340. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1341. IRDA_ASSERT(dev != NULL, return -1;);
  1342. self = netdev_priv(dev);
  1343. IRDA_ASSERT(self != NULL, return 0;);
  1344. /* Stop device */
  1345. netif_stop_queue(dev);
  1346. /* Stop and remove instance of IrLAP */
  1347. if (self->irlap)
  1348. irlap_close(self->irlap);
  1349. self->irlap = NULL;
  1350. free_irq(self->io.irq, dev);
  1351. disable_dma(self->io.dma);
  1352. free_dma(self->io.dma);
  1353. return 0;
  1354. }
  1355. static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level)
  1356. {
  1357. struct smsc_ircc_cb *self = dev_get_drvdata(dev);
  1358. IRDA_MESSAGE("%s, Suspending\n", driver_name);
  1359. if (level == SUSPEND_DISABLE && !self->io.suspended) {
  1360. smsc_ircc_net_close(self->netdev);
  1361. self->io.suspended = 1;
  1362. }
  1363. return 0;
  1364. }
  1365. static int smsc_ircc_resume(struct device *dev, u32 level)
  1366. {
  1367. struct smsc_ircc_cb *self = dev_get_drvdata(dev);
  1368. if (level == RESUME_ENABLE && self->io.suspended) {
  1369. smsc_ircc_net_open(self->netdev);
  1370. self->io.suspended = 0;
  1371. IRDA_MESSAGE("%s, Waking up\n", driver_name);
  1372. }
  1373. return 0;
  1374. }
  1375. /*
  1376. * Function smsc_ircc_close (self)
  1377. *
  1378. * Close driver instance
  1379. *
  1380. */
  1381. static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
  1382. {
  1383. int iobase;
  1384. unsigned long flags;
  1385. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1386. IRDA_ASSERT(self != NULL, return -1;);
  1387. platform_device_unregister(self->pldev);
  1388. /* Remove netdevice */
  1389. unregister_netdev(self->netdev);
  1390. /* Make sure the irq handler is not exectuting */
  1391. spin_lock_irqsave(&self->lock, flags);
  1392. /* Stop interrupts */
  1393. iobase = self->io.fir_base;
  1394. register_bank(iobase, 0);
  1395. outb(0, iobase + IRCC_IER);
  1396. outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
  1397. outb(0x00, iobase + IRCC_MASTER);
  1398. #if 0
  1399. /* Reset to SIR mode */
  1400. register_bank(iobase, 1);
  1401. outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA);
  1402. outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB);
  1403. #endif
  1404. spin_unlock_irqrestore(&self->lock, flags);
  1405. /* Release the PORTS that this driver is using */
  1406. IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
  1407. self->io.fir_base);
  1408. release_region(self->io.fir_base, self->io.fir_ext);
  1409. IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
  1410. self->io.sir_base);
  1411. release_region(self->io.sir_base, self->io.sir_ext);
  1412. if (self->tx_buff.head)
  1413. dma_free_coherent(NULL, self->tx_buff.truesize,
  1414. self->tx_buff.head, self->tx_buff_dma);
  1415. if (self->rx_buff.head)
  1416. dma_free_coherent(NULL, self->rx_buff.truesize,
  1417. self->rx_buff.head, self->rx_buff_dma);
  1418. free_netdev(self->netdev);
  1419. return 0;
  1420. }
  1421. static void __exit smsc_ircc_cleanup(void)
  1422. {
  1423. int i;
  1424. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1425. for (i = 0; i < 2; i++) {
  1426. if (dev_self[i])
  1427. smsc_ircc_close(dev_self[i]);
  1428. }
  1429. driver_unregister(&smsc_ircc_driver);
  1430. }
  1431. /*
  1432. * Start SIR operations
  1433. *
  1434. * This function *must* be called with spinlock held, because it may
  1435. * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
  1436. */
  1437. void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
  1438. {
  1439. struct net_device *dev;
  1440. int fir_base, sir_base;
  1441. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1442. IRDA_ASSERT(self != NULL, return;);
  1443. dev = self->netdev;
  1444. IRDA_ASSERT(dev != NULL, return;);
  1445. dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
  1446. fir_base = self->io.fir_base;
  1447. sir_base = self->io.sir_base;
  1448. /* Reset everything */
  1449. outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
  1450. #if SMSC_IRCC2_C_SIR_STOP
  1451. /*smsc_ircc_sir_stop(self);*/
  1452. #endif
  1453. register_bank(fir_base, 1);
  1454. outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
  1455. /* Initialize UART */
  1456. outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
  1457. outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
  1458. /* Turn on interrups */
  1459. outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
  1460. IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
  1461. outb(0x00, fir_base + IRCC_MASTER);
  1462. }
  1463. #if SMSC_IRCC2_C_SIR_STOP
  1464. void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
  1465. {
  1466. int iobase;
  1467. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1468. iobase = self->io.sir_base;
  1469. /* Reset UART */
  1470. outb(0, iobase + UART_MCR);
  1471. /* Turn off interrupts */
  1472. outb(0, iobase + UART_IER);
  1473. }
  1474. #endif
  1475. /*
  1476. * Function smsc_sir_write_wakeup (self)
  1477. *
  1478. * Called by the SIR interrupt handler when there's room for more data.
  1479. * If we have more packets to send, we send them here.
  1480. *
  1481. */
  1482. static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
  1483. {
  1484. int actual = 0;
  1485. int iobase;
  1486. int fcr;
  1487. IRDA_ASSERT(self != NULL, return;);
  1488. IRDA_DEBUG(4, "%s\n", __FUNCTION__);
  1489. iobase = self->io.sir_base;
  1490. /* Finished with frame? */
  1491. if (self->tx_buff.len > 0) {
  1492. /* Write data left in transmit buffer */
  1493. actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
  1494. self->tx_buff.data, self->tx_buff.len);
  1495. self->tx_buff.data += actual;
  1496. self->tx_buff.len -= actual;
  1497. } else {
  1498. /*if (self->tx_buff.len ==0) {*/
  1499. /*
  1500. * Now serial buffer is almost free & we can start
  1501. * transmission of another packet. But first we must check
  1502. * if we need to change the speed of the hardware
  1503. */
  1504. if (self->new_speed) {
  1505. IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
  1506. __FUNCTION__, self->new_speed);
  1507. smsc_ircc_sir_wait_hw_transmitter_finish(self);
  1508. smsc_ircc_change_speed(self, self->new_speed);
  1509. self->new_speed = 0;
  1510. } else {
  1511. /* Tell network layer that we want more frames */
  1512. netif_wake_queue(self->netdev);
  1513. }
  1514. self->stats.tx_packets++;
  1515. if (self->io.speed <= 115200) {
  1516. /*
  1517. * Reset Rx FIFO to make sure that all reflected transmit data
  1518. * is discarded. This is needed for half duplex operation
  1519. */
  1520. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
  1521. fcr |= self->io.speed < 38400 ?
  1522. UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
  1523. outb(fcr, iobase + UART_FCR);
  1524. /* Turn on receive interrupts */
  1525. outb(UART_IER_RDI, iobase + UART_IER);
  1526. }
  1527. }
  1528. }
  1529. /*
  1530. * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
  1531. *
  1532. * Fill Tx FIFO with transmit data
  1533. *
  1534. */
  1535. static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
  1536. {
  1537. int actual = 0;
  1538. /* Tx FIFO should be empty! */
  1539. if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
  1540. IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
  1541. return 0;
  1542. }
  1543. /* Fill FIFO with current frame */
  1544. while (fifo_size-- > 0 && actual < len) {
  1545. /* Transmit next byte */
  1546. outb(buf[actual], iobase + UART_TX);
  1547. actual++;
  1548. }
  1549. return actual;
  1550. }
  1551. /*
  1552. * Function smsc_ircc_is_receiving (self)
  1553. *
  1554. * Returns true is we are currently receiving data
  1555. *
  1556. */
  1557. static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
  1558. {
  1559. return (self->rx_buff.state != OUTSIDE_FRAME);
  1560. }
  1561. /*
  1562. * Function smsc_ircc_probe_transceiver(self)
  1563. *
  1564. * Tries to find the used Transceiver
  1565. *
  1566. */
  1567. static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
  1568. {
  1569. unsigned int i;
  1570. IRDA_ASSERT(self != NULL, return;);
  1571. for (i = 0; smsc_transceivers[i].name != NULL; i++)
  1572. if (smsc_transceivers[i].probe(self->io.fir_base)) {
  1573. IRDA_MESSAGE(" %s transceiver found\n",
  1574. smsc_transceivers[i].name);
  1575. self->transceiver= i + 1;
  1576. return;
  1577. }
  1578. IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
  1579. smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
  1580. self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
  1581. }
  1582. /*
  1583. * Function smsc_ircc_set_transceiver_for_speed(self, speed)
  1584. *
  1585. * Set the transceiver according to the speed
  1586. *
  1587. */
  1588. static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
  1589. {
  1590. unsigned int trx;
  1591. trx = self->transceiver;
  1592. if (trx > 0)
  1593. smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
  1594. }
  1595. /*
  1596. * Function smsc_ircc_wait_hw_transmitter_finish ()
  1597. *
  1598. * Wait for the real end of HW transmission
  1599. *
  1600. * The UART is a strict FIFO, and we get called only when we have finished
  1601. * pushing data to the FIFO, so the maximum amount of time we must wait
  1602. * is only for the FIFO to drain out.
  1603. *
  1604. * We use a simple calibrated loop. We may need to adjust the loop
  1605. * delay (udelay) to balance I/O traffic and latency. And we also need to
  1606. * adjust the maximum timeout.
  1607. * It would probably be better to wait for the proper interrupt,
  1608. * but it doesn't seem to be available.
  1609. *
  1610. * We can't use jiffies or kernel timers because :
  1611. * 1) We are called from the interrupt handler, which disable softirqs,
  1612. * so jiffies won't be increased
  1613. * 2) Jiffies granularity is usually very coarse (10ms), and we don't
  1614. * want to wait that long to detect stuck hardware.
  1615. * Jean II
  1616. */
  1617. static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
  1618. {
  1619. int iobase = self->io.sir_base;
  1620. int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
  1621. /* Calibrated busy loop */
  1622. while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
  1623. udelay(1);
  1624. if (count == 0)
  1625. IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
  1626. }
  1627. /* PROBING
  1628. *
  1629. *
  1630. */
  1631. static int __init smsc_ircc_look_for_chips(void)
  1632. {
  1633. struct smsc_chip_address *address;
  1634. char *type;
  1635. unsigned int cfg_base, found;
  1636. found = 0;
  1637. address = possible_addresses;
  1638. while (address->cfg_base) {
  1639. cfg_base = address->cfg_base;
  1640. /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
  1641. if (address->type & SMSCSIO_TYPE_FDC) {
  1642. type = "FDC";
  1643. if (address->type & SMSCSIO_TYPE_FLAT)
  1644. if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
  1645. found++;
  1646. if (address->type & SMSCSIO_TYPE_PAGED)
  1647. if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
  1648. found++;
  1649. }
  1650. if (address->type & SMSCSIO_TYPE_LPC) {
  1651. type = "LPC";
  1652. if (address->type & SMSCSIO_TYPE_FLAT)
  1653. if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
  1654. found++;
  1655. if (address->type & SMSCSIO_TYPE_PAGED)
  1656. if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
  1657. found++;
  1658. }
  1659. address++;
  1660. }
  1661. return found;
  1662. }
  1663. /*
  1664. * Function smsc_superio_flat (chip, base, type)
  1665. *
  1666. * Try to get configuration of a smc SuperIO chip with flat register model
  1667. *
  1668. */
  1669. static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
  1670. {
  1671. unsigned short firbase, sirbase;
  1672. u8 mode, dma, irq;
  1673. int ret = -ENODEV;
  1674. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1675. if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
  1676. return ret;
  1677. outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
  1678. mode = inb(cfgbase + 1);
  1679. /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
  1680. if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
  1681. IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
  1682. outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
  1683. sirbase = inb(cfgbase + 1) << 2;
  1684. /* FIR iobase */
  1685. outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
  1686. firbase = inb(cfgbase + 1) << 3;
  1687. /* DMA */
  1688. outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
  1689. dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
  1690. /* IRQ */
  1691. outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
  1692. irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
  1693. IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
  1694. if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
  1695. ret = 0;
  1696. /* Exit configuration */
  1697. outb(SMSCSIO_CFGEXITKEY, cfgbase);
  1698. return ret;
  1699. }
  1700. /*
  1701. * Function smsc_superio_paged (chip, base, type)
  1702. *
  1703. * Try to get configuration of a smc SuperIO chip with paged register model
  1704. *
  1705. */
  1706. static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
  1707. {
  1708. unsigned short fir_io, sir_io;
  1709. int ret = -ENODEV;
  1710. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1711. if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
  1712. return ret;
  1713. /* Select logical device (UART2) */
  1714. outb(0x07, cfg_base);
  1715. outb(0x05, cfg_base + 1);
  1716. /* SIR iobase */
  1717. outb(0x60, cfg_base);
  1718. sir_io = inb(cfg_base + 1) << 8;
  1719. outb(0x61, cfg_base);
  1720. sir_io |= inb(cfg_base + 1);
  1721. /* Read FIR base */
  1722. outb(0x62, cfg_base);
  1723. fir_io = inb(cfg_base + 1) << 8;
  1724. outb(0x63, cfg_base);
  1725. fir_io |= inb(cfg_base + 1);
  1726. outb(0x2b, cfg_base); /* ??? */
  1727. if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
  1728. ret = 0;
  1729. /* Exit configuration */
  1730. outb(SMSCSIO_CFGEXITKEY, cfg_base);
  1731. return ret;
  1732. }
  1733. static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
  1734. {
  1735. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1736. outb(reg, cfg_base);
  1737. return inb(cfg_base) != reg ? -1 : 0;
  1738. }
  1739. static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
  1740. {
  1741. u8 devid, xdevid, rev;
  1742. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1743. /* Leave configuration */
  1744. outb(SMSCSIO_CFGEXITKEY, cfg_base);
  1745. if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
  1746. return NULL;
  1747. outb(reg, cfg_base);
  1748. xdevid = inb(cfg_base + 1);
  1749. /* Enter configuration */
  1750. outb(SMSCSIO_CFGACCESSKEY, cfg_base);
  1751. #if 0
  1752. if (smsc_access(cfg_base,0x55)) /* send second key and check */
  1753. return NULL;
  1754. #endif
  1755. /* probe device ID */
  1756. if (smsc_access(cfg_base, reg))
  1757. return NULL;
  1758. devid = inb(cfg_base + 1);
  1759. if (devid == 0 || devid == 0xff) /* typical values for unused port */
  1760. return NULL;
  1761. /* probe revision ID */
  1762. if (smsc_access(cfg_base, reg + 1))
  1763. return NULL;
  1764. rev = inb(cfg_base + 1);
  1765. if (rev >= 128) /* i think this will make no sense */
  1766. return NULL;
  1767. if (devid == xdevid) /* protection against false positives */
  1768. return NULL;
  1769. /* Check for expected device ID; are there others? */
  1770. while (chip->devid != devid) {
  1771. chip++;
  1772. if (chip->name == NULL)
  1773. return NULL;
  1774. }
  1775. IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
  1776. devid, rev, cfg_base, type, chip->name);
  1777. if (chip->rev > rev) {
  1778. IRDA_MESSAGE("Revision higher than expected\n");
  1779. return NULL;
  1780. }
  1781. if (chip->flags & NoIRDA)
  1782. IRDA_MESSAGE("chipset does not support IRDA\n");
  1783. return chip;
  1784. }
  1785. static int __init smsc_superio_fdc(unsigned short cfg_base)
  1786. {
  1787. int ret = -1;
  1788. if (!request_region(cfg_base, 2, driver_name)) {
  1789. IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
  1790. __FUNCTION__, cfg_base);
  1791. } else {
  1792. if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
  1793. !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
  1794. ret = 0;
  1795. release_region(cfg_base, 2);
  1796. }
  1797. return ret;
  1798. }
  1799. static int __init smsc_superio_lpc(unsigned short cfg_base)
  1800. {
  1801. int ret = -1;
  1802. if (!request_region(cfg_base, 2, driver_name)) {
  1803. IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
  1804. __FUNCTION__, cfg_base);
  1805. } else {
  1806. if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
  1807. !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
  1808. ret = 0;
  1809. release_region(cfg_base, 2);
  1810. }
  1811. return ret;
  1812. }
  1813. /************************************************
  1814. *
  1815. * Transceivers specific functions
  1816. *
  1817. ************************************************/
  1818. /*
  1819. * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
  1820. *
  1821. * Program transceiver through smsc-ircc ATC circuitry
  1822. *
  1823. */
  1824. static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
  1825. {
  1826. unsigned long jiffies_now, jiffies_timeout;
  1827. u8 val;
  1828. jiffies_now = jiffies;
  1829. jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
  1830. /* ATC */
  1831. register_bank(fir_base, 4);
  1832. outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
  1833. fir_base + IRCC_ATC);
  1834. while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
  1835. !time_after(jiffies, jiffies_timeout))
  1836. /* empty */;
  1837. if (val)
  1838. IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
  1839. inb(fir_base + IRCC_ATC));
  1840. }
  1841. /*
  1842. * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
  1843. *
  1844. * Probe transceiver smsc-ircc ATC circuitry
  1845. *
  1846. */
  1847. static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
  1848. {
  1849. return 0;
  1850. }
  1851. /*
  1852. * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
  1853. *
  1854. * Set transceiver
  1855. *
  1856. */
  1857. static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
  1858. {
  1859. u8 fast_mode;
  1860. switch (speed) {
  1861. default:
  1862. case 576000 :
  1863. fast_mode = 0;
  1864. break;
  1865. case 1152000 :
  1866. case 4000000 :
  1867. fast_mode = IRCC_LCR_A_FAST;
  1868. break;
  1869. }
  1870. register_bank(fir_base, 0);
  1871. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
  1872. }
  1873. /*
  1874. * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
  1875. *
  1876. * Probe transceiver
  1877. *
  1878. */
  1879. static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
  1880. {
  1881. return 0;
  1882. }
  1883. /*
  1884. * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
  1885. *
  1886. * Set transceiver
  1887. *
  1888. */
  1889. static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
  1890. {
  1891. u8 fast_mode;
  1892. switch (speed) {
  1893. default:
  1894. case 576000 :
  1895. fast_mode = 0;
  1896. break;
  1897. case 1152000 :
  1898. case 4000000 :
  1899. fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
  1900. break;
  1901. }
  1902. /* This causes an interrupt */
  1903. register_bank(fir_base, 0);
  1904. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
  1905. }
  1906. /*
  1907. * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
  1908. *
  1909. * Probe transceiver
  1910. *
  1911. */
  1912. static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
  1913. {
  1914. return 0;
  1915. }
  1916. module_init(smsc_ircc_init);
  1917. module_exit(smsc_ircc_cleanup);