smsc-ircc2.c 75 KB

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