smsc-ircc2.c 78 KB

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