smsc-ircc2.c 78 KB

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