smsc-ircc2.c 77 KB

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