smsc-ircc2.c 77 KB

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