smsc-ircc2.c 78 KB

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