smsc-ircc2.c 78 KB

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