smsc-ircc2.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949
  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. * Copyright (c) 2006 Linus Walleij
  15. *
  16. *
  17. * Based on smc-ircc.c:
  18. *
  19. * Copyright (c) 2001 Stefani Seibold
  20. * Copyright (c) 1999-2001 Dag Brattli
  21. * Copyright (c) 1998-1999 Thomas Davis,
  22. *
  23. * and irport.c:
  24. *
  25. * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
  26. *
  27. *
  28. * This program is free software; you can redistribute it and/or
  29. * modify it under the terms of the GNU General Public License as
  30. * published by the Free Software Foundation; either version 2 of
  31. * the License, or (at your option) any later version.
  32. *
  33. * This program is distributed in the hope that it will be useful,
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. * GNU General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program; if not, write to the Free Software
  40. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  41. * MA 02111-1307 USA
  42. *
  43. ********************************************************************/
  44. #include <linux/module.h>
  45. #include <linux/kernel.h>
  46. #include <linux/types.h>
  47. #include <linux/skbuff.h>
  48. #include <linux/netdevice.h>
  49. #include <linux/ioport.h>
  50. #include <linux/delay.h>
  51. #include <linux/slab.h>
  52. #include <linux/init.h>
  53. #include <linux/rtnetlink.h>
  54. #include <linux/serial_reg.h>
  55. #include <linux/dma-mapping.h>
  56. #include <linux/pnp.h>
  57. #include <linux/platform_device.h>
  58. #include <asm/io.h>
  59. #include <asm/dma.h>
  60. #include <asm/byteorder.h>
  61. #include <linux/spinlock.h>
  62. #include <linux/pm.h>
  63. #ifdef CONFIG_PCI
  64. #include <linux/pci.h>
  65. #endif
  66. #include <net/irda/wrapper.h>
  67. #include <net/irda/irda.h>
  68. #include <net/irda/irda_device.h>
  69. #include "smsc-ircc2.h"
  70. #include "smsc-sio.h"
  71. MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
  72. MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
  73. MODULE_LICENSE("GPL");
  74. static int ircc_dma = 255;
  75. module_param(ircc_dma, int, 0);
  76. MODULE_PARM_DESC(ircc_dma, "DMA channel");
  77. static int ircc_irq = 255;
  78. module_param(ircc_irq, int, 0);
  79. MODULE_PARM_DESC(ircc_irq, "IRQ line");
  80. static int ircc_fir;
  81. module_param(ircc_fir, int, 0);
  82. MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
  83. static int ircc_sir;
  84. module_param(ircc_sir, int, 0);
  85. MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
  86. static int ircc_cfg;
  87. module_param(ircc_cfg, int, 0);
  88. MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
  89. static int ircc_transceiver;
  90. module_param(ircc_transceiver, int, 0);
  91. MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
  92. /* Types */
  93. #ifdef CONFIG_PCI
  94. struct smsc_ircc_subsystem_configuration {
  95. unsigned short vendor; /* PCI vendor ID */
  96. unsigned short device; /* PCI vendor ID */
  97. unsigned short subvendor; /* PCI subsystem vendor ID */
  98. unsigned short subdevice; /* PCI sybsystem device ID */
  99. unsigned short sir_io; /* I/O port for SIR */
  100. unsigned short fir_io; /* I/O port for FIR */
  101. unsigned char fir_irq; /* FIR IRQ */
  102. unsigned char fir_dma; /* FIR DMA */
  103. unsigned short cfg_base; /* I/O port for chip configuration */
  104. int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
  105. const char *name; /* name shown as info */
  106. };
  107. #endif
  108. struct smsc_transceiver {
  109. char *name;
  110. void (*set_for_speed)(int fir_base, u32 speed);
  111. int (*probe)(int fir_base);
  112. };
  113. struct smsc_chip {
  114. char *name;
  115. #if 0
  116. u8 type;
  117. #endif
  118. u16 flags;
  119. u8 devid;
  120. u8 rev;
  121. };
  122. struct smsc_chip_address {
  123. unsigned int cfg_base;
  124. unsigned int type;
  125. };
  126. /* Private data for each instance */
  127. struct smsc_ircc_cb {
  128. struct net_device *netdev; /* Yes! we are some kind of netdevice */
  129. struct net_device_stats stats;
  130. struct irlap_cb *irlap; /* The link layer we are binded to */
  131. chipio_t io; /* IrDA controller information */
  132. iobuff_t tx_buff; /* Transmit buffer */
  133. iobuff_t rx_buff; /* Receive buffer */
  134. dma_addr_t tx_buff_dma;
  135. dma_addr_t rx_buff_dma;
  136. struct qos_info qos; /* QoS capabilities for this device */
  137. spinlock_t lock; /* For serializing operations */
  138. __u32 new_speed;
  139. __u32 flags; /* Interface flags */
  140. int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
  141. int tx_len; /* Number of frames in tx_buff */
  142. int transceiver;
  143. struct platform_device *pldev;
  144. };
  145. /* Constants */
  146. #define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
  147. #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
  148. #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
  149. #define SMSC_IRCC2_C_NET_TIMEOUT 0
  150. #define SMSC_IRCC2_C_SIR_STOP 0
  151. static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
  152. /* Prototypes */
  153. static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
  154. static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
  155. static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
  156. static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
  157. static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
  158. static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
  159. static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
  160. static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
  161. static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
  162. static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
  163. static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
  164. static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
  165. static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
  166. static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
  167. static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
  168. static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  169. static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
  170. static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
  171. #if SMSC_IRCC2_C_SIR_STOP
  172. static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
  173. #endif
  174. static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
  175. static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
  176. static int smsc_ircc_net_open(struct net_device *dev);
  177. static int smsc_ircc_net_close(struct net_device *dev);
  178. static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  179. #if SMSC_IRCC2_C_NET_TIMEOUT
  180. static void smsc_ircc_timeout(struct net_device *dev);
  181. #endif
  182. static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
  183. static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
  184. static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
  185. static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
  186. static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
  187. /* Probing */
  188. static int __init smsc_ircc_look_for_chips(void);
  189. static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
  190. static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
  191. static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
  192. static int __init smsc_superio_fdc(unsigned short cfg_base);
  193. static int __init smsc_superio_lpc(unsigned short cfg_base);
  194. #ifdef CONFIG_PCI
  195. static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
  196. static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
  197. static void __init preconfigure_ali_port(struct pci_dev *dev,
  198. unsigned short port);
  199. static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
  200. static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
  201. unsigned short ircc_fir,
  202. unsigned short ircc_sir,
  203. unsigned char ircc_dma,
  204. unsigned char ircc_irq);
  205. #endif
  206. /* Transceivers specific functions */
  207. static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
  208. static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
  209. static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
  210. static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
  211. static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
  212. static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
  213. /* Power Management */
  214. static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
  215. static int smsc_ircc_resume(struct platform_device *dev);
  216. static struct platform_driver smsc_ircc_driver = {
  217. .suspend = smsc_ircc_suspend,
  218. .resume = smsc_ircc_resume,
  219. .driver = {
  220. .name = SMSC_IRCC2_DRIVER_NAME,
  221. },
  222. };
  223. /* Transceivers for SMSC-ircc */
  224. static struct smsc_transceiver smsc_transceivers[] =
  225. {
  226. { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
  227. { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
  228. { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
  229. { NULL, NULL }
  230. };
  231. #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
  232. /* SMC SuperIO chipsets definitions */
  233. #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
  234. #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
  235. #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
  236. #define SIR 0 /* SuperIO Chip has only slow IRDA */
  237. #define FIR 4 /* SuperIO Chip has fast IRDA */
  238. #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
  239. static struct smsc_chip __initdata fdc_chips_flat[] =
  240. {
  241. /* Base address 0x3f0 or 0x370 */
  242. { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
  243. { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
  244. { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
  245. { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
  246. { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
  247. { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
  248. { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
  249. { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
  250. { NULL }
  251. };
  252. static struct smsc_chip __initdata fdc_chips_paged[] =
  253. {
  254. /* Base address 0x3f0 or 0x370 */
  255. { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
  256. { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
  257. { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
  258. { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
  259. { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
  260. { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
  261. { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
  262. { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
  263. { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
  264. { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
  265. { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
  266. { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
  267. { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
  268. { NULL }
  269. };
  270. static struct smsc_chip __initdata lpc_chips_flat[] =
  271. {
  272. /* Base address 0x2E or 0x4E */
  273. { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
  274. { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
  275. { NULL }
  276. };
  277. static struct smsc_chip __initdata lpc_chips_paged[] =
  278. {
  279. /* Base address 0x2E or 0x4E */
  280. { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
  281. { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
  282. { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
  283. { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
  284. { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
  285. { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
  286. { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
  287. { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
  288. { NULL }
  289. };
  290. #define SMSCSIO_TYPE_FDC 1
  291. #define SMSCSIO_TYPE_LPC 2
  292. #define SMSCSIO_TYPE_FLAT 4
  293. #define SMSCSIO_TYPE_PAGED 8
  294. static struct smsc_chip_address __initdata possible_addresses[] =
  295. {
  296. { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  297. { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  298. { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  299. { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  300. { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  301. { 0, 0 }
  302. };
  303. /* Globals */
  304. static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
  305. static unsigned short dev_count;
  306. static inline void register_bank(int iobase, int bank)
  307. {
  308. outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
  309. iobase + IRCC_MASTER);
  310. }
  311. #ifdef CONFIG_PNP
  312. /* PNP hotplug support */
  313. static const struct pnp_device_id smsc_ircc_pnp_table[] = {
  314. { .id = "SMCf010", .driver_data = 0 },
  315. /* and presumably others */
  316. { }
  317. };
  318. MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
  319. #endif
  320. /*******************************************************************************
  321. *
  322. *
  323. * SMSC-ircc stuff
  324. *
  325. *
  326. *******************************************************************************/
  327. /*
  328. * Function smsc_ircc_init ()
  329. *
  330. * Initialize chip. Just try to find out how many chips we are dealing with
  331. * and where they are
  332. */
  333. static int __init smsc_ircc_init(void)
  334. {
  335. int ret;
  336. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  337. ret = platform_driver_register(&smsc_ircc_driver);
  338. if (ret) {
  339. IRDA_ERROR("%s, Can't register driver!\n", driver_name);
  340. return ret;
  341. }
  342. #ifdef CONFIG_PCI
  343. if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
  344. /* Ignore errors from preconfiguration */
  345. IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
  346. }
  347. #endif
  348. dev_count = 0;
  349. if (ircc_fir > 0 && ircc_sir > 0) {
  350. IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
  351. IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
  352. if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
  353. ret = -ENODEV;
  354. } else {
  355. ret = -ENODEV;
  356. /* try user provided configuration register base address */
  357. if (ircc_cfg > 0) {
  358. IRDA_MESSAGE(" Overriding configuration address "
  359. "0x%04x\n", ircc_cfg);
  360. if (!smsc_superio_fdc(ircc_cfg))
  361. ret = 0;
  362. if (!smsc_superio_lpc(ircc_cfg))
  363. ret = 0;
  364. }
  365. if (smsc_ircc_look_for_chips() > 0)
  366. ret = 0;
  367. }
  368. if (ret)
  369. platform_driver_unregister(&smsc_ircc_driver);
  370. return ret;
  371. }
  372. /*
  373. * Function smsc_ircc_open (firbase, sirbase, dma, irq)
  374. *
  375. * Try to open driver instance
  376. *
  377. */
  378. static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
  379. {
  380. struct smsc_ircc_cb *self;
  381. struct net_device *dev;
  382. int err;
  383. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  384. err = smsc_ircc_present(fir_base, sir_base);
  385. if (err)
  386. goto err_out;
  387. err = -ENOMEM;
  388. if (dev_count >= ARRAY_SIZE(dev_self)) {
  389. IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
  390. goto err_out1;
  391. }
  392. /*
  393. * Allocate new instance of the driver
  394. */
  395. dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
  396. if (!dev) {
  397. IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
  398. goto err_out1;
  399. }
  400. SET_MODULE_OWNER(dev);
  401. dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
  402. #if SMSC_IRCC2_C_NET_TIMEOUT
  403. dev->tx_timeout = smsc_ircc_timeout;
  404. dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
  405. #endif
  406. dev->open = smsc_ircc_net_open;
  407. dev->stop = smsc_ircc_net_close;
  408. dev->do_ioctl = smsc_ircc_net_ioctl;
  409. dev->get_stats = smsc_ircc_net_get_stats;
  410. self = netdev_priv(dev);
  411. self->netdev = dev;
  412. /* Make ifconfig display some details */
  413. dev->base_addr = self->io.fir_base = fir_base;
  414. dev->irq = self->io.irq = irq;
  415. /* Need to store self somewhere */
  416. dev_self[dev_count] = self;
  417. spin_lock_init(&self->lock);
  418. self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
  419. self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
  420. self->rx_buff.head =
  421. dma_alloc_coherent(NULL, self->rx_buff.truesize,
  422. &self->rx_buff_dma, GFP_KERNEL);
  423. if (self->rx_buff.head == NULL) {
  424. IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
  425. driver_name);
  426. goto err_out2;
  427. }
  428. self->tx_buff.head =
  429. dma_alloc_coherent(NULL, self->tx_buff.truesize,
  430. &self->tx_buff_dma, GFP_KERNEL);
  431. if (self->tx_buff.head == NULL) {
  432. IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
  433. driver_name);
  434. goto err_out3;
  435. }
  436. memset(self->rx_buff.head, 0, self->rx_buff.truesize);
  437. memset(self->tx_buff.head, 0, self->tx_buff.truesize);
  438. self->rx_buff.in_frame = FALSE;
  439. self->rx_buff.state = OUTSIDE_FRAME;
  440. self->tx_buff.data = self->tx_buff.head;
  441. self->rx_buff.data = self->rx_buff.head;
  442. smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
  443. smsc_ircc_setup_qos(self);
  444. smsc_ircc_init_chip(self);
  445. if (ircc_transceiver > 0 &&
  446. ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
  447. self->transceiver = ircc_transceiver;
  448. else
  449. smsc_ircc_probe_transceiver(self);
  450. err = register_netdev(self->netdev);
  451. if (err) {
  452. IRDA_ERROR("%s, Network device registration failed!\n",
  453. driver_name);
  454. goto err_out4;
  455. }
  456. self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
  457. dev_count, NULL, 0);
  458. if (IS_ERR(self->pldev)) {
  459. err = PTR_ERR(self->pldev);
  460. goto err_out5;
  461. }
  462. platform_set_drvdata(self->pldev, self);
  463. IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
  464. dev_count++;
  465. return 0;
  466. err_out5:
  467. unregister_netdev(self->netdev);
  468. err_out4:
  469. dma_free_coherent(NULL, self->tx_buff.truesize,
  470. self->tx_buff.head, self->tx_buff_dma);
  471. err_out3:
  472. dma_free_coherent(NULL, self->rx_buff.truesize,
  473. self->rx_buff.head, self->rx_buff_dma);
  474. err_out2:
  475. free_netdev(self->netdev);
  476. dev_self[dev_count] = NULL;
  477. err_out1:
  478. release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
  479. release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
  480. err_out:
  481. return err;
  482. }
  483. /*
  484. * Function smsc_ircc_present(fir_base, sir_base)
  485. *
  486. * Check the smsc-ircc chip presence
  487. *
  488. */
  489. static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
  490. {
  491. unsigned char low, high, chip, config, dma, irq, version;
  492. if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
  493. driver_name)) {
  494. IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
  495. __FUNCTION__, fir_base);
  496. goto out1;
  497. }
  498. if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
  499. driver_name)) {
  500. IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
  501. __FUNCTION__, sir_base);
  502. goto out2;
  503. }
  504. register_bank(fir_base, 3);
  505. high = inb(fir_base + IRCC_ID_HIGH);
  506. low = inb(fir_base + IRCC_ID_LOW);
  507. chip = inb(fir_base + IRCC_CHIP_ID);
  508. version = inb(fir_base + IRCC_VERSION);
  509. config = inb(fir_base + IRCC_INTERFACE);
  510. dma = config & IRCC_INTERFACE_DMA_MASK;
  511. irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
  512. if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
  513. IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
  514. __FUNCTION__, fir_base);
  515. goto out3;
  516. }
  517. IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
  518. "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
  519. chip & 0x0f, version, fir_base, sir_base, dma, irq);
  520. return 0;
  521. out3:
  522. release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
  523. out2:
  524. release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
  525. out1:
  526. return -ENODEV;
  527. }
  528. /*
  529. * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
  530. *
  531. * Setup I/O
  532. *
  533. */
  534. static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
  535. unsigned int fir_base, unsigned int sir_base,
  536. u8 dma, u8 irq)
  537. {
  538. unsigned char config, chip_dma, chip_irq;
  539. register_bank(fir_base, 3);
  540. config = inb(fir_base + IRCC_INTERFACE);
  541. chip_dma = config & IRCC_INTERFACE_DMA_MASK;
  542. chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
  543. self->io.fir_base = fir_base;
  544. self->io.sir_base = sir_base;
  545. self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
  546. self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
  547. self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
  548. self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
  549. if (irq < 255) {
  550. if (irq != chip_irq)
  551. IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
  552. driver_name, chip_irq, irq);
  553. self->io.irq = irq;
  554. } else
  555. self->io.irq = chip_irq;
  556. if (dma < 255) {
  557. if (dma != chip_dma)
  558. IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
  559. driver_name, chip_dma, dma);
  560. self->io.dma = dma;
  561. } else
  562. self->io.dma = chip_dma;
  563. }
  564. /*
  565. * Function smsc_ircc_setup_qos(self)
  566. *
  567. * Setup qos
  568. *
  569. */
  570. static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
  571. {
  572. /* Initialize QoS for this device */
  573. irda_init_max_qos_capabilies(&self->qos);
  574. self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
  575. IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
  576. self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
  577. self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
  578. irda_qos_bits_to_value(&self->qos);
  579. }
  580. /*
  581. * Function smsc_ircc_init_chip(self)
  582. *
  583. * Init chip
  584. *
  585. */
  586. static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
  587. {
  588. int iobase = self->io.fir_base;
  589. register_bank(iobase, 0);
  590. outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
  591. outb(0x00, iobase + IRCC_MASTER);
  592. register_bank(iobase, 1);
  593. outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
  594. iobase + IRCC_SCE_CFGA);
  595. #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
  596. outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
  597. iobase + IRCC_SCE_CFGB);
  598. #else
  599. outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
  600. iobase + IRCC_SCE_CFGB);
  601. #endif
  602. (void) inb(iobase + IRCC_FIFO_THRESHOLD);
  603. outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
  604. register_bank(iobase, 4);
  605. outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
  606. register_bank(iobase, 0);
  607. outb(0, iobase + IRCC_LCR_A);
  608. smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
  609. /* Power on device */
  610. outb(0x00, iobase + IRCC_MASTER);
  611. }
  612. /*
  613. * Function smsc_ircc_net_ioctl (dev, rq, cmd)
  614. *
  615. * Process IOCTL commands for this device
  616. *
  617. */
  618. static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  619. {
  620. struct if_irda_req *irq = (struct if_irda_req *) rq;
  621. struct smsc_ircc_cb *self;
  622. unsigned long flags;
  623. int ret = 0;
  624. IRDA_ASSERT(dev != NULL, return -1;);
  625. self = netdev_priv(dev);
  626. IRDA_ASSERT(self != NULL, return -1;);
  627. IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
  628. switch (cmd) {
  629. case SIOCSBANDWIDTH: /* Set bandwidth */
  630. if (!capable(CAP_NET_ADMIN))
  631. ret = -EPERM;
  632. else {
  633. /* Make sure we are the only one touching
  634. * self->io.speed and the hardware - Jean II */
  635. spin_lock_irqsave(&self->lock, flags);
  636. smsc_ircc_change_speed(self, irq->ifr_baudrate);
  637. spin_unlock_irqrestore(&self->lock, flags);
  638. }
  639. break;
  640. case SIOCSMEDIABUSY: /* Set media busy */
  641. if (!capable(CAP_NET_ADMIN)) {
  642. ret = -EPERM;
  643. break;
  644. }
  645. irda_device_set_media_busy(self->netdev, TRUE);
  646. break;
  647. case SIOCGRECEIVING: /* Check if we are receiving right now */
  648. irq->ifr_receiving = smsc_ircc_is_receiving(self);
  649. break;
  650. #if 0
  651. case SIOCSDTRRTS:
  652. if (!capable(CAP_NET_ADMIN)) {
  653. ret = -EPERM;
  654. break;
  655. }
  656. smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
  657. break;
  658. #endif
  659. default:
  660. ret = -EOPNOTSUPP;
  661. }
  662. return ret;
  663. }
  664. static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
  665. {
  666. struct smsc_ircc_cb *self = netdev_priv(dev);
  667. return &self->stats;
  668. }
  669. #if SMSC_IRCC2_C_NET_TIMEOUT
  670. /*
  671. * Function smsc_ircc_timeout (struct net_device *dev)
  672. *
  673. * The networking timeout management.
  674. *
  675. */
  676. static void smsc_ircc_timeout(struct net_device *dev)
  677. {
  678. struct smsc_ircc_cb *self = netdev_priv(dev);
  679. unsigned long flags;
  680. IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
  681. dev->name, self->io.speed);
  682. spin_lock_irqsave(&self->lock, flags);
  683. smsc_ircc_sir_start(self);
  684. smsc_ircc_change_speed(self, self->io.speed);
  685. dev->trans_start = jiffies;
  686. netif_wake_queue(dev);
  687. spin_unlock_irqrestore(&self->lock, flags);
  688. }
  689. #endif
  690. /*
  691. * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
  692. *
  693. * Transmits the current frame until FIFO is full, then
  694. * waits until the next transmit interrupt, and continues until the
  695. * frame is transmitted.
  696. */
  697. int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
  698. {
  699. struct smsc_ircc_cb *self;
  700. unsigned long flags;
  701. s32 speed;
  702. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  703. IRDA_ASSERT(dev != NULL, return 0;);
  704. self = netdev_priv(dev);
  705. IRDA_ASSERT(self != NULL, return 0;);
  706. netif_stop_queue(dev);
  707. /* Make sure test of self->io.speed & speed change are atomic */
  708. spin_lock_irqsave(&self->lock, flags);
  709. /* Check if we need to change the speed */
  710. speed = irda_get_next_speed(skb);
  711. if (speed != self->io.speed && speed != -1) {
  712. /* Check for empty frame */
  713. if (!skb->len) {
  714. /*
  715. * We send frames one by one in SIR mode (no
  716. * pipelining), so at this point, if we were sending
  717. * a previous frame, we just received the interrupt
  718. * telling us it is finished (UART_IIR_THRI).
  719. * Therefore, waiting for the transmitter to really
  720. * finish draining the fifo won't take too long.
  721. * And the interrupt handler is not expected to run.
  722. * - Jean II */
  723. smsc_ircc_sir_wait_hw_transmitter_finish(self);
  724. smsc_ircc_change_speed(self, speed);
  725. spin_unlock_irqrestore(&self->lock, flags);
  726. dev_kfree_skb(skb);
  727. return 0;
  728. }
  729. self->new_speed = speed;
  730. }
  731. /* Init tx buffer */
  732. self->tx_buff.data = self->tx_buff.head;
  733. /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
  734. self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
  735. self->tx_buff.truesize);
  736. self->stats.tx_bytes += self->tx_buff.len;
  737. /* Turn on transmit finished interrupt. Will fire immediately! */
  738. outb(UART_IER_THRI, self->io.sir_base + UART_IER);
  739. spin_unlock_irqrestore(&self->lock, flags);
  740. dev_kfree_skb(skb);
  741. return 0;
  742. }
  743. /*
  744. * Function smsc_ircc_set_fir_speed (self, baud)
  745. *
  746. * Change the speed of the device
  747. *
  748. */
  749. static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
  750. {
  751. int fir_base, ir_mode, ctrl, fast;
  752. IRDA_ASSERT(self != NULL, return;);
  753. fir_base = self->io.fir_base;
  754. self->io.speed = speed;
  755. switch (speed) {
  756. default:
  757. case 576000:
  758. ir_mode = IRCC_CFGA_IRDA_HDLC;
  759. ctrl = IRCC_CRC;
  760. fast = 0;
  761. IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
  762. break;
  763. case 1152000:
  764. ir_mode = IRCC_CFGA_IRDA_HDLC;
  765. ctrl = IRCC_1152 | IRCC_CRC;
  766. fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
  767. IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
  768. __FUNCTION__);
  769. break;
  770. case 4000000:
  771. ir_mode = IRCC_CFGA_IRDA_4PPM;
  772. ctrl = IRCC_CRC;
  773. fast = IRCC_LCR_A_FAST;
  774. IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
  775. __FUNCTION__);
  776. break;
  777. }
  778. #if 0
  779. Now in tranceiver!
  780. /* This causes an interrupt */
  781. register_bank(fir_base, 0);
  782. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
  783. #endif
  784. register_bank(fir_base, 1);
  785. outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
  786. register_bank(fir_base, 4);
  787. outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
  788. }
  789. /*
  790. * Function smsc_ircc_fir_start(self)
  791. *
  792. * Change the speed of the device
  793. *
  794. */
  795. static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
  796. {
  797. struct net_device *dev;
  798. int fir_base;
  799. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  800. IRDA_ASSERT(self != NULL, return;);
  801. dev = self->netdev;
  802. IRDA_ASSERT(dev != NULL, return;);
  803. fir_base = self->io.fir_base;
  804. /* Reset everything */
  805. /* Install FIR transmit handler */
  806. dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
  807. /* Clear FIFO */
  808. outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
  809. /* Enable interrupt */
  810. /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
  811. register_bank(fir_base, 1);
  812. /* Select the TX/RX interface */
  813. #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
  814. outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
  815. fir_base + IRCC_SCE_CFGB);
  816. #else
  817. outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
  818. fir_base + IRCC_SCE_CFGB);
  819. #endif
  820. (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
  821. /* Enable SCE interrupts */
  822. outb(0, fir_base + IRCC_MASTER);
  823. register_bank(fir_base, 0);
  824. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
  825. outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
  826. }
  827. /*
  828. * Function smsc_ircc_fir_stop(self, baud)
  829. *
  830. * Change the speed of the device
  831. *
  832. */
  833. static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
  834. {
  835. int fir_base;
  836. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  837. IRDA_ASSERT(self != NULL, return;);
  838. fir_base = self->io.fir_base;
  839. register_bank(fir_base, 0);
  840. /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
  841. outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
  842. }
  843. /*
  844. * Function smsc_ircc_change_speed(self, baud)
  845. *
  846. * Change the speed of the device
  847. *
  848. * This function *must* be called with spinlock held, because it may
  849. * be called from the irq handler. - Jean II
  850. */
  851. static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
  852. {
  853. struct net_device *dev;
  854. int last_speed_was_sir;
  855. IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
  856. IRDA_ASSERT(self != NULL, return;);
  857. dev = self->netdev;
  858. last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
  859. #if 0
  860. /* Temp Hack */
  861. speed= 1152000;
  862. self->io.speed = speed;
  863. last_speed_was_sir = 0;
  864. smsc_ircc_fir_start(self);
  865. #endif
  866. if (self->io.speed == 0)
  867. smsc_ircc_sir_start(self);
  868. #if 0
  869. if (!last_speed_was_sir) speed = self->io.speed;
  870. #endif
  871. if (self->io.speed != speed)
  872. smsc_ircc_set_transceiver_for_speed(self, speed);
  873. self->io.speed = speed;
  874. if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
  875. if (!last_speed_was_sir) {
  876. smsc_ircc_fir_stop(self);
  877. smsc_ircc_sir_start(self);
  878. }
  879. smsc_ircc_set_sir_speed(self, speed);
  880. } else {
  881. if (last_speed_was_sir) {
  882. #if SMSC_IRCC2_C_SIR_STOP
  883. smsc_ircc_sir_stop(self);
  884. #endif
  885. smsc_ircc_fir_start(self);
  886. }
  887. smsc_ircc_set_fir_speed(self, speed);
  888. #if 0
  889. self->tx_buff.len = 10;
  890. self->tx_buff.data = self->tx_buff.head;
  891. smsc_ircc_dma_xmit(self, 4000);
  892. #endif
  893. /* Be ready for incoming frames */
  894. smsc_ircc_dma_receive(self);
  895. }
  896. netif_wake_queue(dev);
  897. }
  898. /*
  899. * Function smsc_ircc_set_sir_speed (self, speed)
  900. *
  901. * Set speed of IrDA port to specified baudrate
  902. *
  903. */
  904. void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
  905. {
  906. int iobase;
  907. int fcr; /* FIFO control reg */
  908. int lcr; /* Line control reg */
  909. int divisor;
  910. IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
  911. IRDA_ASSERT(self != NULL, return;);
  912. iobase = self->io.sir_base;
  913. /* Update accounting for new speed */
  914. self->io.speed = speed;
  915. /* Turn off interrupts */
  916. outb(0, iobase + UART_IER);
  917. divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
  918. fcr = UART_FCR_ENABLE_FIFO;
  919. /*
  920. * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
  921. * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
  922. * about this timeout since it will always be fast enough.
  923. */
  924. fcr |= self->io.speed < 38400 ?
  925. UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
  926. /* IrDA ports use 8N1 */
  927. lcr = UART_LCR_WLEN8;
  928. outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
  929. outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
  930. outb(divisor >> 8, iobase + UART_DLM);
  931. outb(lcr, iobase + UART_LCR); /* Set 8N1 */
  932. outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
  933. /* Turn on interrups */
  934. outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
  935. IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
  936. }
  937. /*
  938. * Function smsc_ircc_hard_xmit_fir (skb, dev)
  939. *
  940. * Transmit the frame!
  941. *
  942. */
  943. static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
  944. {
  945. struct smsc_ircc_cb *self;
  946. unsigned long flags;
  947. s32 speed;
  948. int mtt;
  949. IRDA_ASSERT(dev != NULL, return 0;);
  950. self = netdev_priv(dev);
  951. IRDA_ASSERT(self != NULL, return 0;);
  952. netif_stop_queue(dev);
  953. /* Make sure test of self->io.speed & speed change are atomic */
  954. spin_lock_irqsave(&self->lock, flags);
  955. /* Check if we need to change the speed after this frame */
  956. speed = irda_get_next_speed(skb);
  957. if (speed != self->io.speed && speed != -1) {
  958. /* Check for empty frame */
  959. if (!skb->len) {
  960. /* Note : you should make sure that speed changes
  961. * are not going to corrupt any outgoing frame.
  962. * Look at nsc-ircc for the gory details - Jean II */
  963. smsc_ircc_change_speed(self, speed);
  964. spin_unlock_irqrestore(&self->lock, flags);
  965. dev_kfree_skb(skb);
  966. return 0;
  967. }
  968. self->new_speed = speed;
  969. }
  970. memcpy(self->tx_buff.head, skb->data, skb->len);
  971. self->tx_buff.len = skb->len;
  972. self->tx_buff.data = self->tx_buff.head;
  973. mtt = irda_get_mtt(skb);
  974. if (mtt) {
  975. int bofs;
  976. /*
  977. * Compute how many BOFs (STA or PA's) we need to waste the
  978. * min turn time given the speed of the link.
  979. */
  980. bofs = mtt * (self->io.speed / 1000) / 8000;
  981. if (bofs > 4095)
  982. bofs = 4095;
  983. smsc_ircc_dma_xmit(self, bofs);
  984. } else {
  985. /* Transmit frame */
  986. smsc_ircc_dma_xmit(self, 0);
  987. }
  988. spin_unlock_irqrestore(&self->lock, flags);
  989. dev_kfree_skb(skb);
  990. return 0;
  991. }
  992. /*
  993. * Function smsc_ircc_dma_xmit (self, bofs)
  994. *
  995. * Transmit data using DMA
  996. *
  997. */
  998. static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
  999. {
  1000. int iobase = self->io.fir_base;
  1001. u8 ctrl;
  1002. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1003. #if 1
  1004. /* Disable Rx */
  1005. register_bank(iobase, 0);
  1006. outb(0x00, iobase + IRCC_LCR_B);
  1007. #endif
  1008. register_bank(iobase, 1);
  1009. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1010. iobase + IRCC_SCE_CFGB);
  1011. self->io.direction = IO_XMIT;
  1012. /* Set BOF additional count for generating the min turn time */
  1013. register_bank(iobase, 4);
  1014. outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
  1015. ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
  1016. outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
  1017. /* Set max Tx frame size */
  1018. outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
  1019. outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
  1020. /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
  1021. /* Enable burst mode chip Tx DMA */
  1022. register_bank(iobase, 1);
  1023. outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
  1024. IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
  1025. /* Setup DMA controller (must be done after enabling chip DMA) */
  1026. irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
  1027. DMA_TX_MODE);
  1028. /* Enable interrupt */
  1029. register_bank(iobase, 0);
  1030. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  1031. outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
  1032. /* Enable transmit */
  1033. outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
  1034. }
  1035. /*
  1036. * Function smsc_ircc_dma_xmit_complete (self)
  1037. *
  1038. * The transfer of a frame in finished. This function will only be called
  1039. * by the interrupt handler
  1040. *
  1041. */
  1042. static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
  1043. {
  1044. int iobase = self->io.fir_base;
  1045. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1046. #if 0
  1047. /* Disable Tx */
  1048. register_bank(iobase, 0);
  1049. outb(0x00, iobase + IRCC_LCR_B);
  1050. #endif
  1051. register_bank(iobase, 1);
  1052. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1053. iobase + IRCC_SCE_CFGB);
  1054. /* Check for underrun! */
  1055. register_bank(iobase, 0);
  1056. if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
  1057. self->stats.tx_errors++;
  1058. self->stats.tx_fifo_errors++;
  1059. /* Reset error condition */
  1060. register_bank(iobase, 0);
  1061. outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
  1062. outb(0x00, iobase + IRCC_MASTER);
  1063. } else {
  1064. self->stats.tx_packets++;
  1065. self->stats.tx_bytes += self->tx_buff.len;
  1066. }
  1067. /* Check if it's time to change the speed */
  1068. if (self->new_speed) {
  1069. smsc_ircc_change_speed(self, self->new_speed);
  1070. self->new_speed = 0;
  1071. }
  1072. netif_wake_queue(self->netdev);
  1073. }
  1074. /*
  1075. * Function smsc_ircc_dma_receive(self)
  1076. *
  1077. * Get ready for receiving a frame. The device will initiate a DMA
  1078. * if it starts to receive a frame.
  1079. *
  1080. */
  1081. static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
  1082. {
  1083. int iobase = self->io.fir_base;
  1084. #if 0
  1085. /* Turn off chip DMA */
  1086. register_bank(iobase, 1);
  1087. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1088. iobase + IRCC_SCE_CFGB);
  1089. #endif
  1090. /* Disable Tx */
  1091. register_bank(iobase, 0);
  1092. outb(0x00, iobase + IRCC_LCR_B);
  1093. /* Turn off chip DMA */
  1094. register_bank(iobase, 1);
  1095. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1096. iobase + IRCC_SCE_CFGB);
  1097. self->io.direction = IO_RECV;
  1098. self->rx_buff.data = self->rx_buff.head;
  1099. /* Set max Rx frame size */
  1100. register_bank(iobase, 4);
  1101. outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
  1102. outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
  1103. /* Setup DMA controller */
  1104. irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
  1105. DMA_RX_MODE);
  1106. /* Enable burst mode chip Rx DMA */
  1107. register_bank(iobase, 1);
  1108. outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
  1109. IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
  1110. /* Enable interrupt */
  1111. register_bank(iobase, 0);
  1112. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  1113. outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
  1114. /* Enable receiver */
  1115. register_bank(iobase, 0);
  1116. outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
  1117. iobase + IRCC_LCR_B);
  1118. return 0;
  1119. }
  1120. /*
  1121. * Function smsc_ircc_dma_receive_complete(self)
  1122. *
  1123. * Finished with receiving frames
  1124. *
  1125. */
  1126. static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
  1127. {
  1128. struct sk_buff *skb;
  1129. int len, msgcnt, lsr;
  1130. int iobase = self->io.fir_base;
  1131. register_bank(iobase, 0);
  1132. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1133. #if 0
  1134. /* Disable Rx */
  1135. register_bank(iobase, 0);
  1136. outb(0x00, iobase + IRCC_LCR_B);
  1137. #endif
  1138. register_bank(iobase, 0);
  1139. outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
  1140. lsr= inb(iobase + IRCC_LSR);
  1141. msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
  1142. IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
  1143. get_dma_residue(self->io.dma));
  1144. len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
  1145. /* Look for errors */
  1146. if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
  1147. self->stats.rx_errors++;
  1148. if (lsr & IRCC_LSR_FRAME_ERROR)
  1149. self->stats.rx_frame_errors++;
  1150. if (lsr & IRCC_LSR_CRC_ERROR)
  1151. self->stats.rx_crc_errors++;
  1152. if (lsr & IRCC_LSR_SIZE_ERROR)
  1153. self->stats.rx_length_errors++;
  1154. if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
  1155. self->stats.rx_length_errors++;
  1156. return;
  1157. }
  1158. /* Remove CRC */
  1159. len -= self->io.speed < 4000000 ? 2 : 4;
  1160. if (len < 2 || len > 2050) {
  1161. IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
  1162. return;
  1163. }
  1164. IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
  1165. skb = dev_alloc_skb(len + 1);
  1166. if (!skb) {
  1167. IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
  1168. __FUNCTION__);
  1169. return;
  1170. }
  1171. /* Make sure IP header gets aligned */
  1172. skb_reserve(skb, 1);
  1173. memcpy(skb_put(skb, len), self->rx_buff.data, len);
  1174. self->stats.rx_packets++;
  1175. self->stats.rx_bytes += len;
  1176. skb->dev = self->netdev;
  1177. skb->mac.raw = skb->data;
  1178. skb->protocol = htons(ETH_P_IRDA);
  1179. netif_rx(skb);
  1180. }
  1181. /*
  1182. * Function smsc_ircc_sir_receive (self)
  1183. *
  1184. * Receive one frame from the infrared port
  1185. *
  1186. */
  1187. static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
  1188. {
  1189. int boguscount = 0;
  1190. int iobase;
  1191. IRDA_ASSERT(self != NULL, return;);
  1192. iobase = self->io.sir_base;
  1193. /*
  1194. * Receive all characters in Rx FIFO, unwrap and unstuff them.
  1195. * async_unwrap_char will deliver all found frames
  1196. */
  1197. do {
  1198. async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
  1199. inb(iobase + UART_RX));
  1200. /* Make sure we don't stay here to long */
  1201. if (boguscount++ > 32) {
  1202. IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
  1203. break;
  1204. }
  1205. } while (inb(iobase + UART_LSR) & UART_LSR_DR);
  1206. }
  1207. /*
  1208. * Function smsc_ircc_interrupt (irq, dev_id, regs)
  1209. *
  1210. * An interrupt from the chip has arrived. Time to do some work
  1211. *
  1212. */
  1213. static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1214. {
  1215. struct net_device *dev = (struct net_device *) dev_id;
  1216. struct smsc_ircc_cb *self;
  1217. int iobase, iir, lcra, lsr;
  1218. irqreturn_t ret = IRQ_NONE;
  1219. if (dev == NULL) {
  1220. printk(KERN_WARNING "%s: irq %d for unknown device.\n",
  1221. driver_name, irq);
  1222. goto irq_ret;
  1223. }
  1224. self = netdev_priv(dev);
  1225. IRDA_ASSERT(self != NULL, return IRQ_NONE;);
  1226. /* Serialise the interrupt handler in various CPUs, stop Tx path */
  1227. spin_lock(&self->lock);
  1228. /* Check if we should use the SIR interrupt handler */
  1229. if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
  1230. ret = smsc_ircc_interrupt_sir(dev);
  1231. goto irq_ret_unlock;
  1232. }
  1233. iobase = self->io.fir_base;
  1234. register_bank(iobase, 0);
  1235. iir = inb(iobase + IRCC_IIR);
  1236. if (iir == 0)
  1237. goto irq_ret_unlock;
  1238. ret = IRQ_HANDLED;
  1239. /* Disable interrupts */
  1240. outb(0, iobase + IRCC_IER);
  1241. lcra = inb(iobase + IRCC_LCR_A);
  1242. lsr = inb(iobase + IRCC_LSR);
  1243. IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
  1244. if (iir & IRCC_IIR_EOM) {
  1245. if (self->io.direction == IO_RECV)
  1246. smsc_ircc_dma_receive_complete(self);
  1247. else
  1248. smsc_ircc_dma_xmit_complete(self);
  1249. smsc_ircc_dma_receive(self);
  1250. }
  1251. if (iir & IRCC_IIR_ACTIVE_FRAME) {
  1252. /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
  1253. }
  1254. /* Enable interrupts again */
  1255. register_bank(iobase, 0);
  1256. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  1257. irq_ret_unlock:
  1258. spin_unlock(&self->lock);
  1259. irq_ret:
  1260. return ret;
  1261. }
  1262. /*
  1263. * Function irport_interrupt_sir (irq, dev_id, regs)
  1264. *
  1265. * Interrupt handler for SIR modes
  1266. */
  1267. static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
  1268. {
  1269. struct smsc_ircc_cb *self = netdev_priv(dev);
  1270. int boguscount = 0;
  1271. int iobase;
  1272. int iir, lsr;
  1273. /* Already locked comming here in smsc_ircc_interrupt() */
  1274. /*spin_lock(&self->lock);*/
  1275. iobase = self->io.sir_base;
  1276. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  1277. if (iir == 0)
  1278. return IRQ_NONE;
  1279. while (iir) {
  1280. /* Clear interrupt */
  1281. lsr = inb(iobase + UART_LSR);
  1282. IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
  1283. __FUNCTION__, iir, lsr, iobase);
  1284. switch (iir) {
  1285. case UART_IIR_RLSI:
  1286. IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
  1287. break;
  1288. case UART_IIR_RDI:
  1289. /* Receive interrupt */
  1290. smsc_ircc_sir_receive(self);
  1291. break;
  1292. case UART_IIR_THRI:
  1293. if (lsr & UART_LSR_THRE)
  1294. /* Transmitter ready for data */
  1295. smsc_ircc_sir_write_wakeup(self);
  1296. break;
  1297. default:
  1298. IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
  1299. __FUNCTION__, iir);
  1300. break;
  1301. }
  1302. /* Make sure we don't stay here to long */
  1303. if (boguscount++ > 100)
  1304. break;
  1305. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  1306. }
  1307. /*spin_unlock(&self->lock);*/
  1308. return IRQ_HANDLED;
  1309. }
  1310. #if 0 /* unused */
  1311. /*
  1312. * Function ircc_is_receiving (self)
  1313. *
  1314. * Return TRUE is we are currently receiving a frame
  1315. *
  1316. */
  1317. static int ircc_is_receiving(struct smsc_ircc_cb *self)
  1318. {
  1319. int status = FALSE;
  1320. /* int iobase; */
  1321. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1322. IRDA_ASSERT(self != NULL, return FALSE;);
  1323. IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
  1324. get_dma_residue(self->io.dma));
  1325. status = (self->rx_buff.state != OUTSIDE_FRAME);
  1326. return status;
  1327. }
  1328. #endif /* unused */
  1329. static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
  1330. {
  1331. int error;
  1332. error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
  1333. self->netdev->name, self->netdev);
  1334. if (error)
  1335. IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
  1336. __FUNCTION__, self->io.irq, error);
  1337. return error;
  1338. }
  1339. static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
  1340. {
  1341. unsigned long flags;
  1342. spin_lock_irqsave(&self->lock, flags);
  1343. self->io.speed = 0;
  1344. smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
  1345. spin_unlock_irqrestore(&self->lock, flags);
  1346. }
  1347. static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
  1348. {
  1349. int iobase = self->io.fir_base;
  1350. unsigned long flags;
  1351. spin_lock_irqsave(&self->lock, flags);
  1352. register_bank(iobase, 0);
  1353. outb(0, iobase + IRCC_IER);
  1354. outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
  1355. outb(0x00, iobase + IRCC_MASTER);
  1356. spin_unlock_irqrestore(&self->lock, flags);
  1357. }
  1358. /*
  1359. * Function smsc_ircc_net_open (dev)
  1360. *
  1361. * Start the device
  1362. *
  1363. */
  1364. static int smsc_ircc_net_open(struct net_device *dev)
  1365. {
  1366. struct smsc_ircc_cb *self;
  1367. char hwname[16];
  1368. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1369. IRDA_ASSERT(dev != NULL, return -1;);
  1370. self = netdev_priv(dev);
  1371. IRDA_ASSERT(self != NULL, return 0;);
  1372. if (self->io.suspended) {
  1373. IRDA_DEBUG(0, "%s(), device is suspended\n", __FUNCTION__);
  1374. return -EAGAIN;
  1375. }
  1376. if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
  1377. (void *) dev)) {
  1378. IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
  1379. __FUNCTION__, self->io.irq);
  1380. return -EAGAIN;
  1381. }
  1382. smsc_ircc_start_interrupts(self);
  1383. /* Give self a hardware name */
  1384. /* It would be cool to offer the chip revision here - Jean II */
  1385. sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
  1386. /*
  1387. * Open new IrLAP layer instance, now that everything should be
  1388. * initialized properly
  1389. */
  1390. self->irlap = irlap_open(dev, &self->qos, hwname);
  1391. /*
  1392. * Always allocate the DMA channel after the IRQ,
  1393. * and clean up on failure.
  1394. */
  1395. if (request_dma(self->io.dma, dev->name)) {
  1396. smsc_ircc_net_close(dev);
  1397. IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
  1398. __FUNCTION__, self->io.dma);
  1399. return -EAGAIN;
  1400. }
  1401. netif_start_queue(dev);
  1402. return 0;
  1403. }
  1404. /*
  1405. * Function smsc_ircc_net_close (dev)
  1406. *
  1407. * Stop the device
  1408. *
  1409. */
  1410. static int smsc_ircc_net_close(struct net_device *dev)
  1411. {
  1412. struct smsc_ircc_cb *self;
  1413. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1414. IRDA_ASSERT(dev != NULL, return -1;);
  1415. self = netdev_priv(dev);
  1416. IRDA_ASSERT(self != NULL, return 0;);
  1417. /* Stop device */
  1418. netif_stop_queue(dev);
  1419. /* Stop and remove instance of IrLAP */
  1420. if (self->irlap)
  1421. irlap_close(self->irlap);
  1422. self->irlap = NULL;
  1423. smsc_ircc_stop_interrupts(self);
  1424. /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
  1425. if (!self->io.suspended)
  1426. free_irq(self->io.irq, dev);
  1427. disable_dma(self->io.dma);
  1428. free_dma(self->io.dma);
  1429. return 0;
  1430. }
  1431. static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
  1432. {
  1433. struct smsc_ircc_cb *self = platform_get_drvdata(dev);
  1434. if (!self->io.suspended) {
  1435. IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
  1436. rtnl_lock();
  1437. if (netif_running(self->netdev)) {
  1438. netif_device_detach(self->netdev);
  1439. smsc_ircc_stop_interrupts(self);
  1440. free_irq(self->io.irq, self->netdev);
  1441. disable_dma(self->io.dma);
  1442. }
  1443. self->io.suspended = 1;
  1444. rtnl_unlock();
  1445. }
  1446. return 0;
  1447. }
  1448. static int smsc_ircc_resume(struct platform_device *dev)
  1449. {
  1450. struct smsc_ircc_cb *self = platform_get_drvdata(dev);
  1451. if (self->io.suspended) {
  1452. IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
  1453. rtnl_lock();
  1454. smsc_ircc_init_chip(self);
  1455. if (netif_running(self->netdev)) {
  1456. if (smsc_ircc_request_irq(self)) {
  1457. /*
  1458. * Don't fail resume process, just kill this
  1459. * network interface
  1460. */
  1461. unregister_netdevice(self->netdev);
  1462. } else {
  1463. enable_dma(self->io.dma);
  1464. smsc_ircc_start_interrupts(self);
  1465. netif_device_attach(self->netdev);
  1466. }
  1467. }
  1468. self->io.suspended = 0;
  1469. rtnl_unlock();
  1470. }
  1471. return 0;
  1472. }
  1473. /*
  1474. * Function smsc_ircc_close (self)
  1475. *
  1476. * Close driver instance
  1477. *
  1478. */
  1479. static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
  1480. {
  1481. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1482. IRDA_ASSERT(self != NULL, return -1;);
  1483. platform_device_unregister(self->pldev);
  1484. /* Remove netdevice */
  1485. unregister_netdev(self->netdev);
  1486. smsc_ircc_stop_interrupts(self);
  1487. /* Release the PORTS that this driver is using */
  1488. IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
  1489. self->io.fir_base);
  1490. release_region(self->io.fir_base, self->io.fir_ext);
  1491. IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
  1492. self->io.sir_base);
  1493. release_region(self->io.sir_base, self->io.sir_ext);
  1494. if (self->tx_buff.head)
  1495. dma_free_coherent(NULL, self->tx_buff.truesize,
  1496. self->tx_buff.head, self->tx_buff_dma);
  1497. if (self->rx_buff.head)
  1498. dma_free_coherent(NULL, self->rx_buff.truesize,
  1499. self->rx_buff.head, self->rx_buff_dma);
  1500. free_netdev(self->netdev);
  1501. return 0;
  1502. }
  1503. static void __exit smsc_ircc_cleanup(void)
  1504. {
  1505. int i;
  1506. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1507. for (i = 0; i < 2; i++) {
  1508. if (dev_self[i])
  1509. smsc_ircc_close(dev_self[i]);
  1510. }
  1511. platform_driver_unregister(&smsc_ircc_driver);
  1512. }
  1513. /*
  1514. * Start SIR operations
  1515. *
  1516. * This function *must* be called with spinlock held, because it may
  1517. * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
  1518. */
  1519. void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
  1520. {
  1521. struct net_device *dev;
  1522. int fir_base, sir_base;
  1523. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1524. IRDA_ASSERT(self != NULL, return;);
  1525. dev = self->netdev;
  1526. IRDA_ASSERT(dev != NULL, return;);
  1527. dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
  1528. fir_base = self->io.fir_base;
  1529. sir_base = self->io.sir_base;
  1530. /* Reset everything */
  1531. outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
  1532. #if SMSC_IRCC2_C_SIR_STOP
  1533. /*smsc_ircc_sir_stop(self);*/
  1534. #endif
  1535. register_bank(fir_base, 1);
  1536. outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
  1537. /* Initialize UART */
  1538. outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
  1539. outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
  1540. /* Turn on interrups */
  1541. outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
  1542. IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
  1543. outb(0x00, fir_base + IRCC_MASTER);
  1544. }
  1545. #if SMSC_IRCC2_C_SIR_STOP
  1546. void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
  1547. {
  1548. int iobase;
  1549. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1550. iobase = self->io.sir_base;
  1551. /* Reset UART */
  1552. outb(0, iobase + UART_MCR);
  1553. /* Turn off interrupts */
  1554. outb(0, iobase + UART_IER);
  1555. }
  1556. #endif
  1557. /*
  1558. * Function smsc_sir_write_wakeup (self)
  1559. *
  1560. * Called by the SIR interrupt handler when there's room for more data.
  1561. * If we have more packets to send, we send them here.
  1562. *
  1563. */
  1564. static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
  1565. {
  1566. int actual = 0;
  1567. int iobase;
  1568. int fcr;
  1569. IRDA_ASSERT(self != NULL, return;);
  1570. IRDA_DEBUG(4, "%s\n", __FUNCTION__);
  1571. iobase = self->io.sir_base;
  1572. /* Finished with frame? */
  1573. if (self->tx_buff.len > 0) {
  1574. /* Write data left in transmit buffer */
  1575. actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
  1576. self->tx_buff.data, self->tx_buff.len);
  1577. self->tx_buff.data += actual;
  1578. self->tx_buff.len -= actual;
  1579. } else {
  1580. /*if (self->tx_buff.len ==0) {*/
  1581. /*
  1582. * Now serial buffer is almost free & we can start
  1583. * transmission of another packet. But first we must check
  1584. * if we need to change the speed of the hardware
  1585. */
  1586. if (self->new_speed) {
  1587. IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
  1588. __FUNCTION__, self->new_speed);
  1589. smsc_ircc_sir_wait_hw_transmitter_finish(self);
  1590. smsc_ircc_change_speed(self, self->new_speed);
  1591. self->new_speed = 0;
  1592. } else {
  1593. /* Tell network layer that we want more frames */
  1594. netif_wake_queue(self->netdev);
  1595. }
  1596. self->stats.tx_packets++;
  1597. if (self->io.speed <= 115200) {
  1598. /*
  1599. * Reset Rx FIFO to make sure that all reflected transmit data
  1600. * is discarded. This is needed for half duplex operation
  1601. */
  1602. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
  1603. fcr |= self->io.speed < 38400 ?
  1604. UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
  1605. outb(fcr, iobase + UART_FCR);
  1606. /* Turn on receive interrupts */
  1607. outb(UART_IER_RDI, iobase + UART_IER);
  1608. }
  1609. }
  1610. }
  1611. /*
  1612. * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
  1613. *
  1614. * Fill Tx FIFO with transmit data
  1615. *
  1616. */
  1617. static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
  1618. {
  1619. int actual = 0;
  1620. /* Tx FIFO should be empty! */
  1621. if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
  1622. IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
  1623. return 0;
  1624. }
  1625. /* Fill FIFO with current frame */
  1626. while (fifo_size-- > 0 && actual < len) {
  1627. /* Transmit next byte */
  1628. outb(buf[actual], iobase + UART_TX);
  1629. actual++;
  1630. }
  1631. return actual;
  1632. }
  1633. /*
  1634. * Function smsc_ircc_is_receiving (self)
  1635. *
  1636. * Returns true is we are currently receiving data
  1637. *
  1638. */
  1639. static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
  1640. {
  1641. return (self->rx_buff.state != OUTSIDE_FRAME);
  1642. }
  1643. /*
  1644. * Function smsc_ircc_probe_transceiver(self)
  1645. *
  1646. * Tries to find the used Transceiver
  1647. *
  1648. */
  1649. static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
  1650. {
  1651. unsigned int i;
  1652. IRDA_ASSERT(self != NULL, return;);
  1653. for (i = 0; smsc_transceivers[i].name != NULL; i++)
  1654. if (smsc_transceivers[i].probe(self->io.fir_base)) {
  1655. IRDA_MESSAGE(" %s transceiver found\n",
  1656. smsc_transceivers[i].name);
  1657. self->transceiver= i + 1;
  1658. return;
  1659. }
  1660. IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
  1661. smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
  1662. self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
  1663. }
  1664. /*
  1665. * Function smsc_ircc_set_transceiver_for_speed(self, speed)
  1666. *
  1667. * Set the transceiver according to the speed
  1668. *
  1669. */
  1670. static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
  1671. {
  1672. unsigned int trx;
  1673. trx = self->transceiver;
  1674. if (trx > 0)
  1675. smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
  1676. }
  1677. /*
  1678. * Function smsc_ircc_wait_hw_transmitter_finish ()
  1679. *
  1680. * Wait for the real end of HW transmission
  1681. *
  1682. * The UART is a strict FIFO, and we get called only when we have finished
  1683. * pushing data to the FIFO, so the maximum amount of time we must wait
  1684. * is only for the FIFO to drain out.
  1685. *
  1686. * We use a simple calibrated loop. We may need to adjust the loop
  1687. * delay (udelay) to balance I/O traffic and latency. And we also need to
  1688. * adjust the maximum timeout.
  1689. * It would probably be better to wait for the proper interrupt,
  1690. * but it doesn't seem to be available.
  1691. *
  1692. * We can't use jiffies or kernel timers because :
  1693. * 1) We are called from the interrupt handler, which disable softirqs,
  1694. * so jiffies won't be increased
  1695. * 2) Jiffies granularity is usually very coarse (10ms), and we don't
  1696. * want to wait that long to detect stuck hardware.
  1697. * Jean II
  1698. */
  1699. static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
  1700. {
  1701. int iobase = self->io.sir_base;
  1702. int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
  1703. /* Calibrated busy loop */
  1704. while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
  1705. udelay(1);
  1706. if (count == 0)
  1707. IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
  1708. }
  1709. /* PROBING
  1710. *
  1711. * REVISIT we can be told about the device by PNP, and should use that info
  1712. * instead of probing hardware and creating a platform_device ...
  1713. */
  1714. static int __init smsc_ircc_look_for_chips(void)
  1715. {
  1716. struct smsc_chip_address *address;
  1717. char *type;
  1718. unsigned int cfg_base, found;
  1719. found = 0;
  1720. address = possible_addresses;
  1721. while (address->cfg_base) {
  1722. cfg_base = address->cfg_base;
  1723. /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
  1724. if (address->type & SMSCSIO_TYPE_FDC) {
  1725. type = "FDC";
  1726. if (address->type & SMSCSIO_TYPE_FLAT)
  1727. if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
  1728. found++;
  1729. if (address->type & SMSCSIO_TYPE_PAGED)
  1730. if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
  1731. found++;
  1732. }
  1733. if (address->type & SMSCSIO_TYPE_LPC) {
  1734. type = "LPC";
  1735. if (address->type & SMSCSIO_TYPE_FLAT)
  1736. if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
  1737. found++;
  1738. if (address->type & SMSCSIO_TYPE_PAGED)
  1739. if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
  1740. found++;
  1741. }
  1742. address++;
  1743. }
  1744. return found;
  1745. }
  1746. /*
  1747. * Function smsc_superio_flat (chip, base, type)
  1748. *
  1749. * Try to get configuration of a smc SuperIO chip with flat register model
  1750. *
  1751. */
  1752. static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
  1753. {
  1754. unsigned short firbase, sirbase;
  1755. u8 mode, dma, irq;
  1756. int ret = -ENODEV;
  1757. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1758. if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
  1759. return ret;
  1760. outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
  1761. mode = inb(cfgbase + 1);
  1762. /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
  1763. if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
  1764. IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
  1765. outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
  1766. sirbase = inb(cfgbase + 1) << 2;
  1767. /* FIR iobase */
  1768. outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
  1769. firbase = inb(cfgbase + 1) << 3;
  1770. /* DMA */
  1771. outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
  1772. dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
  1773. /* IRQ */
  1774. outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
  1775. irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
  1776. IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
  1777. if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
  1778. ret = 0;
  1779. /* Exit configuration */
  1780. outb(SMSCSIO_CFGEXITKEY, cfgbase);
  1781. return ret;
  1782. }
  1783. /*
  1784. * Function smsc_superio_paged (chip, base, type)
  1785. *
  1786. * Try to get configuration of a smc SuperIO chip with paged register model
  1787. *
  1788. */
  1789. static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
  1790. {
  1791. unsigned short fir_io, sir_io;
  1792. int ret = -ENODEV;
  1793. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1794. if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
  1795. return ret;
  1796. /* Select logical device (UART2) */
  1797. outb(0x07, cfg_base);
  1798. outb(0x05, cfg_base + 1);
  1799. /* SIR iobase */
  1800. outb(0x60, cfg_base);
  1801. sir_io = inb(cfg_base + 1) << 8;
  1802. outb(0x61, cfg_base);
  1803. sir_io |= inb(cfg_base + 1);
  1804. /* Read FIR base */
  1805. outb(0x62, cfg_base);
  1806. fir_io = inb(cfg_base + 1) << 8;
  1807. outb(0x63, cfg_base);
  1808. fir_io |= inb(cfg_base + 1);
  1809. outb(0x2b, cfg_base); /* ??? */
  1810. if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
  1811. ret = 0;
  1812. /* Exit configuration */
  1813. outb(SMSCSIO_CFGEXITKEY, cfg_base);
  1814. return ret;
  1815. }
  1816. static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
  1817. {
  1818. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1819. outb(reg, cfg_base);
  1820. return inb(cfg_base) != reg ? -1 : 0;
  1821. }
  1822. static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
  1823. {
  1824. u8 devid, xdevid, rev;
  1825. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1826. /* Leave configuration */
  1827. outb(SMSCSIO_CFGEXITKEY, cfg_base);
  1828. if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
  1829. return NULL;
  1830. outb(reg, cfg_base);
  1831. xdevid = inb(cfg_base + 1);
  1832. /* Enter configuration */
  1833. outb(SMSCSIO_CFGACCESSKEY, cfg_base);
  1834. #if 0
  1835. if (smsc_access(cfg_base,0x55)) /* send second key and check */
  1836. return NULL;
  1837. #endif
  1838. /* probe device ID */
  1839. if (smsc_access(cfg_base, reg))
  1840. return NULL;
  1841. devid = inb(cfg_base + 1);
  1842. if (devid == 0 || devid == 0xff) /* typical values for unused port */
  1843. return NULL;
  1844. /* probe revision ID */
  1845. if (smsc_access(cfg_base, reg + 1))
  1846. return NULL;
  1847. rev = inb(cfg_base + 1);
  1848. if (rev >= 128) /* i think this will make no sense */
  1849. return NULL;
  1850. if (devid == xdevid) /* protection against false positives */
  1851. return NULL;
  1852. /* Check for expected device ID; are there others? */
  1853. while (chip->devid != devid) {
  1854. chip++;
  1855. if (chip->name == NULL)
  1856. return NULL;
  1857. }
  1858. IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
  1859. devid, rev, cfg_base, type, chip->name);
  1860. if (chip->rev > rev) {
  1861. IRDA_MESSAGE("Revision higher than expected\n");
  1862. return NULL;
  1863. }
  1864. if (chip->flags & NoIRDA)
  1865. IRDA_MESSAGE("chipset does not support IRDA\n");
  1866. return chip;
  1867. }
  1868. static int __init smsc_superio_fdc(unsigned short cfg_base)
  1869. {
  1870. int ret = -1;
  1871. if (!request_region(cfg_base, 2, driver_name)) {
  1872. IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
  1873. __FUNCTION__, cfg_base);
  1874. } else {
  1875. if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
  1876. !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
  1877. ret = 0;
  1878. release_region(cfg_base, 2);
  1879. }
  1880. return ret;
  1881. }
  1882. static int __init smsc_superio_lpc(unsigned short cfg_base)
  1883. {
  1884. int ret = -1;
  1885. if (!request_region(cfg_base, 2, driver_name)) {
  1886. IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
  1887. __FUNCTION__, cfg_base);
  1888. } else {
  1889. if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
  1890. !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
  1891. ret = 0;
  1892. release_region(cfg_base, 2);
  1893. }
  1894. return ret;
  1895. }
  1896. /*
  1897. * Look for some specific subsystem setups that need
  1898. * pre-configuration not properly done by the BIOS (especially laptops)
  1899. * This code is based in part on smcinit.c, tosh1800-smcinit.c
  1900. * and tosh2450-smcinit.c. The table lists the device entries
  1901. * for ISA bridges with an LPC (Low Pin Count) controller which
  1902. * handles the communication with the SMSC device. After the LPC
  1903. * controller is initialized through PCI, the SMSC device is initialized
  1904. * through a dedicated port in the ISA port-mapped I/O area, this latter
  1905. * area is used to configure the SMSC device with default
  1906. * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
  1907. * used different sets of parameters and different control port
  1908. * addresses making a subsystem device table necessary.
  1909. */
  1910. #ifdef CONFIG_PCI
  1911. #define PCIID_VENDOR_INTEL 0x8086
  1912. #define PCIID_VENDOR_ALI 0x10b9
  1913. static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
  1914. {
  1915. .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
  1916. .device = 0x24cc,
  1917. .subvendor = 0x103c,
  1918. .subdevice = 0x088c,
  1919. /* Quite certain these are the same for nc8000 as for nc6000 */
  1920. .sir_io = 0x02f8,
  1921. .fir_io = 0x0130,
  1922. .fir_irq = 0x05,
  1923. .fir_dma = 0x03,
  1924. .cfg_base = 0x004e,
  1925. .preconfigure = preconfigure_through_82801,
  1926. .name = "HP nc8000",
  1927. },
  1928. {
  1929. .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
  1930. .device = 0x24cc,
  1931. .subvendor = 0x103c,
  1932. .subdevice = 0x0890,
  1933. .sir_io = 0x02f8,
  1934. .fir_io = 0x0130,
  1935. .fir_irq = 0x05,
  1936. .fir_dma = 0x03,
  1937. .cfg_base = 0x004e,
  1938. .preconfigure = preconfigure_through_82801,
  1939. .name = "HP nc6000",
  1940. },
  1941. {
  1942. /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
  1943. .vendor = PCIID_VENDOR_INTEL,
  1944. .device = 0x24c0,
  1945. .subvendor = 0x1179,
  1946. .subdevice = 0xffff, /* 0xffff is "any" */
  1947. .sir_io = 0x03f8,
  1948. .fir_io = 0x0130,
  1949. .fir_irq = 0x07,
  1950. .fir_dma = 0x01,
  1951. .cfg_base = 0x002e,
  1952. .preconfigure = preconfigure_through_82801,
  1953. .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
  1954. },
  1955. {
  1956. .vendor = PCIID_VENDOR_INTEL, /* Intel 82801CAM ISA bridge */
  1957. .device = 0x248c,
  1958. .subvendor = 0x1179,
  1959. .subdevice = 0xffff, /* 0xffff is "any" */
  1960. .sir_io = 0x03f8,
  1961. .fir_io = 0x0130,
  1962. .fir_irq = 0x03,
  1963. .fir_dma = 0x03,
  1964. .cfg_base = 0x002e,
  1965. .preconfigure = preconfigure_through_82801,
  1966. .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
  1967. },
  1968. {
  1969. /* 82801DBM (ICH4-M) LPC Interface Bridge */
  1970. .vendor = PCIID_VENDOR_INTEL,
  1971. .device = 0x24cc,
  1972. .subvendor = 0x1179,
  1973. .subdevice = 0xffff, /* 0xffff is "any" */
  1974. .sir_io = 0x03f8,
  1975. .fir_io = 0x0130,
  1976. .fir_irq = 0x03,
  1977. .fir_dma = 0x03,
  1978. .cfg_base = 0x002e,
  1979. .preconfigure = preconfigure_through_82801,
  1980. .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
  1981. },
  1982. {
  1983. /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
  1984. .vendor = PCIID_VENDOR_ALI,
  1985. .device = 0x1533,
  1986. .subvendor = 0x1179,
  1987. .subdevice = 0xffff, /* 0xffff is "any" */
  1988. .sir_io = 0x02e8,
  1989. .fir_io = 0x02f8,
  1990. .fir_irq = 0x07,
  1991. .fir_dma = 0x03,
  1992. .cfg_base = 0x002e,
  1993. .preconfigure = preconfigure_through_ali,
  1994. .name = "Toshiba laptop with ALi ISA bridge",
  1995. },
  1996. { } // Terminator
  1997. };
  1998. /*
  1999. * This sets up the basic SMSC parameters
  2000. * (FIR port, SIR port, FIR DMA, FIR IRQ)
  2001. * through the chip configuration port.
  2002. */
  2003. static int __init preconfigure_smsc_chip(struct
  2004. smsc_ircc_subsystem_configuration
  2005. *conf)
  2006. {
  2007. unsigned short iobase = conf->cfg_base;
  2008. unsigned char tmpbyte;
  2009. outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
  2010. outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
  2011. tmpbyte = inb(iobase +1); // Read device ID
  2012. IRDA_DEBUG(0,
  2013. "Detected Chip id: 0x%02x, setting up registers...\n",
  2014. tmpbyte);
  2015. /* Disable UART1 and set up SIR I/O port */
  2016. outb(0x24, iobase); // select CR24 - UART1 base addr
  2017. outb(0x00, iobase + 1); // disable UART1
  2018. outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
  2019. outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
  2020. tmpbyte = inb(iobase + 1);
  2021. if (tmpbyte != (conf->sir_io >> 2) ) {
  2022. IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
  2023. IRDA_WARNING("Try to supply ircc_cfg argument.\n");
  2024. return -ENXIO;
  2025. }
  2026. /* Set up FIR IRQ channel for UART2 */
  2027. outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
  2028. tmpbyte = inb(iobase + 1);
  2029. tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
  2030. tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
  2031. outb(tmpbyte, iobase + 1);
  2032. tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
  2033. if (tmpbyte != conf->fir_irq) {
  2034. IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
  2035. return -ENXIO;
  2036. }
  2037. /* Set up FIR I/O port */
  2038. outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
  2039. outb((conf->fir_io >> 3), iobase + 1);
  2040. tmpbyte = inb(iobase + 1);
  2041. if (tmpbyte != (conf->fir_io >> 3) ) {
  2042. IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
  2043. return -ENXIO;
  2044. }
  2045. /* Set up FIR DMA channel */
  2046. outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
  2047. outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
  2048. tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
  2049. if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
  2050. IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
  2051. return -ENXIO;
  2052. }
  2053. outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
  2054. tmpbyte = inb(iobase + 1);
  2055. tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
  2056. SMSCSIOFLAT_UART2MODE_VAL_IRDA;
  2057. outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
  2058. outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
  2059. tmpbyte = inb(iobase + 1);
  2060. outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
  2061. /* This one was not part of tosh1800 */
  2062. outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
  2063. tmpbyte = inb(iobase + 1);
  2064. outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
  2065. outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
  2066. tmpbyte = inb(iobase + 1);
  2067. outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
  2068. outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
  2069. tmpbyte = inb(iobase + 1);
  2070. outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
  2071. outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
  2072. return 0;
  2073. }
  2074. /* 82801CAM generic registers */
  2075. #define VID 0x00
  2076. #define DID 0x02
  2077. #define PIRQ_A_D_ROUT 0x60
  2078. #define SIRQ_CNTL 0x64
  2079. #define PIRQ_E_H_ROUT 0x68
  2080. #define PCI_DMA_C 0x90
  2081. /* LPC-specific registers */
  2082. #define COM_DEC 0xe0
  2083. #define GEN1_DEC 0xe4
  2084. #define LPC_EN 0xe6
  2085. #define GEN2_DEC 0xec
  2086. /*
  2087. * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
  2088. * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
  2089. * They all work the same way!
  2090. */
  2091. static int __init preconfigure_through_82801(struct pci_dev *dev,
  2092. struct
  2093. smsc_ircc_subsystem_configuration
  2094. *conf)
  2095. {
  2096. unsigned short tmpword;
  2097. unsigned char tmpbyte;
  2098. IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
  2099. /*
  2100. * Select the range for the COMA COM port (SIR)
  2101. * Register COM_DEC:
  2102. * Bit 7: reserved
  2103. * Bit 6-4, COMB decode range
  2104. * Bit 3: reserved
  2105. * Bit 2-0, COMA decode range
  2106. *
  2107. * Decode ranges:
  2108. * 000 = 0x3f8-0x3ff (COM1)
  2109. * 001 = 0x2f8-0x2ff (COM2)
  2110. * 010 = 0x220-0x227
  2111. * 011 = 0x228-0x22f
  2112. * 100 = 0x238-0x23f
  2113. * 101 = 0x2e8-0x2ef (COM4)
  2114. * 110 = 0x338-0x33f
  2115. * 111 = 0x3e8-0x3ef (COM3)
  2116. */
  2117. pci_read_config_byte(dev, COM_DEC, &tmpbyte);
  2118. tmpbyte &= 0xf8; /* mask COMA bits */
  2119. switch(conf->sir_io) {
  2120. case 0x3f8:
  2121. tmpbyte |= 0x00;
  2122. break;
  2123. case 0x2f8:
  2124. tmpbyte |= 0x01;
  2125. break;
  2126. case 0x220:
  2127. tmpbyte |= 0x02;
  2128. break;
  2129. case 0x228:
  2130. tmpbyte |= 0x03;
  2131. break;
  2132. case 0x238:
  2133. tmpbyte |= 0x04;
  2134. break;
  2135. case 0x2e8:
  2136. tmpbyte |= 0x05;
  2137. break;
  2138. case 0x338:
  2139. tmpbyte |= 0x06;
  2140. break;
  2141. case 0x3e8:
  2142. tmpbyte |= 0x07;
  2143. break;
  2144. default:
  2145. tmpbyte |= 0x01; /* COM2 default */
  2146. }
  2147. IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
  2148. pci_write_config_byte(dev, COM_DEC, tmpbyte);
  2149. /* Enable Low Pin Count interface */
  2150. pci_read_config_word(dev, LPC_EN, &tmpword);
  2151. /* These seem to be set up at all times,
  2152. * just make sure it is properly set.
  2153. */
  2154. switch(conf->cfg_base) {
  2155. case 0x04e:
  2156. tmpword |= 0x2000;
  2157. break;
  2158. case 0x02e:
  2159. tmpword |= 0x1000;
  2160. break;
  2161. case 0x062:
  2162. tmpword |= 0x0800;
  2163. break;
  2164. case 0x060:
  2165. tmpword |= 0x0400;
  2166. break;
  2167. default:
  2168. IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
  2169. conf->cfg_base);
  2170. break;
  2171. }
  2172. tmpword &= 0xfffd; /* disable LPC COMB */
  2173. tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
  2174. IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
  2175. pci_write_config_word(dev, LPC_EN, tmpword);
  2176. /*
  2177. * Configure LPC DMA channel
  2178. * PCI_DMA_C bits:
  2179. * Bit 15-14: DMA channel 7 select
  2180. * Bit 13-12: DMA channel 6 select
  2181. * Bit 11-10: DMA channel 5 select
  2182. * Bit 9-8: Reserved
  2183. * Bit 7-6: DMA channel 3 select
  2184. * Bit 5-4: DMA channel 2 select
  2185. * Bit 3-2: DMA channel 1 select
  2186. * Bit 1-0: DMA channel 0 select
  2187. * 00 = Reserved value
  2188. * 01 = PC/PCI DMA
  2189. * 10 = Reserved value
  2190. * 11 = LPC I/F DMA
  2191. */
  2192. pci_read_config_word(dev, PCI_DMA_C, &tmpword);
  2193. switch(conf->fir_dma) {
  2194. case 0x07:
  2195. tmpword |= 0xc000;
  2196. break;
  2197. case 0x06:
  2198. tmpword |= 0x3000;
  2199. break;
  2200. case 0x05:
  2201. tmpword |= 0x0c00;
  2202. break;
  2203. case 0x03:
  2204. tmpword |= 0x00c0;
  2205. break;
  2206. case 0x02:
  2207. tmpword |= 0x0030;
  2208. break;
  2209. case 0x01:
  2210. tmpword |= 0x000c;
  2211. break;
  2212. case 0x00:
  2213. tmpword |= 0x0003;
  2214. break;
  2215. default:
  2216. break; /* do not change settings */
  2217. }
  2218. IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
  2219. pci_write_config_word(dev, PCI_DMA_C, tmpword);
  2220. /*
  2221. * GEN2_DEC bits:
  2222. * Bit 15-4: Generic I/O range
  2223. * Bit 3-1: reserved (read as 0)
  2224. * Bit 0: enable GEN2 range on LPC I/F
  2225. */
  2226. tmpword = conf->fir_io & 0xfff8;
  2227. tmpword |= 0x0001;
  2228. IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
  2229. pci_write_config_word(dev, GEN2_DEC, tmpword);
  2230. /* Pre-configure chip */
  2231. return preconfigure_smsc_chip(conf);
  2232. }
  2233. /*
  2234. * Pre-configure a certain port on the ALi 1533 bridge.
  2235. * This is based on reverse-engineering since ALi does not
  2236. * provide any data sheet for the 1533 chip.
  2237. */
  2238. static void __init preconfigure_ali_port(struct pci_dev *dev,
  2239. unsigned short port)
  2240. {
  2241. unsigned char reg;
  2242. /* These bits obviously control the different ports */
  2243. unsigned char mask;
  2244. unsigned char tmpbyte;
  2245. switch(port) {
  2246. case 0x0130:
  2247. case 0x0178:
  2248. reg = 0xb0;
  2249. mask = 0x80;
  2250. break;
  2251. case 0x03f8:
  2252. reg = 0xb4;
  2253. mask = 0x80;
  2254. break;
  2255. case 0x02f8:
  2256. reg = 0xb4;
  2257. mask = 0x30;
  2258. break;
  2259. case 0x02e8:
  2260. reg = 0xb4;
  2261. mask = 0x08;
  2262. break;
  2263. default:
  2264. IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
  2265. return;
  2266. }
  2267. pci_read_config_byte(dev, reg, &tmpbyte);
  2268. /* Turn on the right bits */
  2269. tmpbyte |= mask;
  2270. pci_write_config_byte(dev, reg, tmpbyte);
  2271. IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
  2272. return;
  2273. }
  2274. static int __init preconfigure_through_ali(struct pci_dev *dev,
  2275. struct
  2276. smsc_ircc_subsystem_configuration
  2277. *conf)
  2278. {
  2279. /* Configure the two ports on the ALi 1533 */
  2280. preconfigure_ali_port(dev, conf->sir_io);
  2281. preconfigure_ali_port(dev, conf->fir_io);
  2282. /* Pre-configure chip */
  2283. return preconfigure_smsc_chip(conf);
  2284. }
  2285. static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
  2286. unsigned short ircc_fir,
  2287. unsigned short ircc_sir,
  2288. unsigned char ircc_dma,
  2289. unsigned char ircc_irq)
  2290. {
  2291. struct pci_dev *dev = NULL;
  2292. unsigned short ss_vendor = 0x0000;
  2293. unsigned short ss_device = 0x0000;
  2294. int ret = 0;
  2295. dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
  2296. while (dev != NULL) {
  2297. struct smsc_ircc_subsystem_configuration *conf;
  2298. /*
  2299. * Cache the subsystem vendor/device:
  2300. * some manufacturers fail to set this for all components,
  2301. * so we save it in case there is just 0x0000 0x0000 on the
  2302. * device we want to check.
  2303. */
  2304. if (dev->subsystem_vendor != 0x0000U) {
  2305. ss_vendor = dev->subsystem_vendor;
  2306. ss_device = dev->subsystem_device;
  2307. }
  2308. conf = subsystem_configurations;
  2309. for( ; conf->subvendor; conf++) {
  2310. if(conf->vendor == dev->vendor &&
  2311. conf->device == dev->device &&
  2312. conf->subvendor == ss_vendor &&
  2313. /* Sometimes these are cached values */
  2314. (conf->subdevice == ss_device ||
  2315. conf->subdevice == 0xffff)) {
  2316. struct smsc_ircc_subsystem_configuration
  2317. tmpconf;
  2318. memcpy(&tmpconf, conf,
  2319. sizeof(struct smsc_ircc_subsystem_configuration));
  2320. /*
  2321. * Override the default values with anything
  2322. * passed in as parameter
  2323. */
  2324. if (ircc_cfg != 0)
  2325. tmpconf.cfg_base = ircc_cfg;
  2326. if (ircc_fir != 0)
  2327. tmpconf.fir_io = ircc_fir;
  2328. if (ircc_sir != 0)
  2329. tmpconf.sir_io = ircc_sir;
  2330. if (ircc_dma != 0xff)
  2331. tmpconf.fir_dma = ircc_dma;
  2332. if (ircc_irq != 0xff)
  2333. tmpconf.fir_irq = ircc_irq;
  2334. IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
  2335. if (conf->preconfigure)
  2336. ret = conf->preconfigure(dev, &tmpconf);
  2337. else
  2338. ret = -ENODEV;
  2339. }
  2340. }
  2341. dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
  2342. }
  2343. return ret;
  2344. }
  2345. #endif // CONFIG_PCI
  2346. /************************************************
  2347. *
  2348. * Transceivers specific functions
  2349. *
  2350. ************************************************/
  2351. /*
  2352. * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
  2353. *
  2354. * Program transceiver through smsc-ircc ATC circuitry
  2355. *
  2356. */
  2357. static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
  2358. {
  2359. unsigned long jiffies_now, jiffies_timeout;
  2360. u8 val;
  2361. jiffies_now = jiffies;
  2362. jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
  2363. /* ATC */
  2364. register_bank(fir_base, 4);
  2365. outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
  2366. fir_base + IRCC_ATC);
  2367. while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
  2368. !time_after(jiffies, jiffies_timeout))
  2369. /* empty */;
  2370. if (val)
  2371. IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
  2372. inb(fir_base + IRCC_ATC));
  2373. }
  2374. /*
  2375. * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
  2376. *
  2377. * Probe transceiver smsc-ircc ATC circuitry
  2378. *
  2379. */
  2380. static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
  2381. {
  2382. return 0;
  2383. }
  2384. /*
  2385. * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
  2386. *
  2387. * Set transceiver
  2388. *
  2389. */
  2390. static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
  2391. {
  2392. u8 fast_mode;
  2393. switch (speed) {
  2394. default:
  2395. case 576000 :
  2396. fast_mode = 0;
  2397. break;
  2398. case 1152000 :
  2399. case 4000000 :
  2400. fast_mode = IRCC_LCR_A_FAST;
  2401. break;
  2402. }
  2403. register_bank(fir_base, 0);
  2404. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
  2405. }
  2406. /*
  2407. * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
  2408. *
  2409. * Probe transceiver
  2410. *
  2411. */
  2412. static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
  2413. {
  2414. return 0;
  2415. }
  2416. /*
  2417. * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
  2418. *
  2419. * Set transceiver
  2420. *
  2421. */
  2422. static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
  2423. {
  2424. u8 fast_mode;
  2425. switch (speed) {
  2426. default:
  2427. case 576000 :
  2428. fast_mode = 0;
  2429. break;
  2430. case 1152000 :
  2431. case 4000000 :
  2432. fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
  2433. break;
  2434. }
  2435. /* This causes an interrupt */
  2436. register_bank(fir_base, 0);
  2437. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
  2438. }
  2439. /*
  2440. * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
  2441. *
  2442. * Probe transceiver
  2443. *
  2444. */
  2445. static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
  2446. {
  2447. return 0;
  2448. }
  2449. module_init(smsc_ircc_init);
  2450. module_exit(smsc_ircc_cleanup);