smsc-ircc2.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414
  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. *
  15. *
  16. * Based on smc-ircc.c:
  17. *
  18. * Copyright (c) 2001 Stefani Seibold
  19. * Copyright (c) 1999-2001 Dag Brattli
  20. * Copyright (c) 1998-1999 Thomas Davis,
  21. *
  22. * and irport.c:
  23. *
  24. * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
  25. *
  26. *
  27. * This program is free software; you can redistribute it and/or
  28. * modify it under the terms of the GNU General Public License as
  29. * published by the Free Software Foundation; either version 2 of
  30. * the License, or (at your option) any later version.
  31. *
  32. * This program is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. * GNU General Public License for more details.
  36. *
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  40. * MA 02111-1307 USA
  41. *
  42. ********************************************************************/
  43. #include <linux/module.h>
  44. #include <linux/kernel.h>
  45. #include <linux/types.h>
  46. #include <linux/skbuff.h>
  47. #include <linux/netdevice.h>
  48. #include <linux/ioport.h>
  49. #include <linux/delay.h>
  50. #include <linux/slab.h>
  51. #include <linux/init.h>
  52. #include <linux/rtnetlink.h>
  53. #include <linux/serial_reg.h>
  54. #include <linux/dma-mapping.h>
  55. #include <linux/platform_device.h>
  56. #include <asm/io.h>
  57. #include <asm/dma.h>
  58. #include <asm/byteorder.h>
  59. #include <linux/spinlock.h>
  60. #include <linux/pm.h>
  61. #include <net/irda/wrapper.h>
  62. #include <net/irda/irda.h>
  63. #include <net/irda/irda_device.h>
  64. #include "smsc-ircc2.h"
  65. #include "smsc-sio.h"
  66. MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
  67. MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
  68. MODULE_LICENSE("GPL");
  69. static int ircc_dma = 255;
  70. module_param(ircc_dma, int, 0);
  71. MODULE_PARM_DESC(ircc_dma, "DMA channel");
  72. static int ircc_irq = 255;
  73. module_param(ircc_irq, int, 0);
  74. MODULE_PARM_DESC(ircc_irq, "IRQ line");
  75. static int ircc_fir;
  76. module_param(ircc_fir, int, 0);
  77. MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
  78. static int ircc_sir;
  79. module_param(ircc_sir, int, 0);
  80. MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
  81. static int ircc_cfg;
  82. module_param(ircc_cfg, int, 0);
  83. MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
  84. static int ircc_transceiver;
  85. module_param(ircc_transceiver, int, 0);
  86. MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
  87. /* Types */
  88. struct smsc_transceiver {
  89. char *name;
  90. void (*set_for_speed)(int fir_base, u32 speed);
  91. int (*probe)(int fir_base);
  92. };
  93. struct smsc_chip {
  94. char *name;
  95. #if 0
  96. u8 type;
  97. #endif
  98. u16 flags;
  99. u8 devid;
  100. u8 rev;
  101. };
  102. struct smsc_chip_address {
  103. unsigned int cfg_base;
  104. unsigned int type;
  105. };
  106. /* Private data for each instance */
  107. struct smsc_ircc_cb {
  108. struct net_device *netdev; /* Yes! we are some kind of netdevice */
  109. struct net_device_stats stats;
  110. struct irlap_cb *irlap; /* The link layer we are binded to */
  111. chipio_t io; /* IrDA controller information */
  112. iobuff_t tx_buff; /* Transmit buffer */
  113. iobuff_t rx_buff; /* Receive buffer */
  114. dma_addr_t tx_buff_dma;
  115. dma_addr_t rx_buff_dma;
  116. struct qos_info qos; /* QoS capabilities for this device */
  117. spinlock_t lock; /* For serializing operations */
  118. __u32 new_speed;
  119. __u32 flags; /* Interface flags */
  120. int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
  121. int tx_len; /* Number of frames in tx_buff */
  122. int transceiver;
  123. struct platform_device *pldev;
  124. };
  125. /* Constants */
  126. #define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
  127. #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
  128. #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
  129. #define SMSC_IRCC2_C_NET_TIMEOUT 0
  130. #define SMSC_IRCC2_C_SIR_STOP 0
  131. static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
  132. /* Prototypes */
  133. static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
  134. static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
  135. static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
  136. static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
  137. static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
  138. static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
  139. static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
  140. static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
  141. static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
  142. static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
  143. static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
  144. static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
  145. static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
  146. static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
  147. static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
  148. static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  149. static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
  150. static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
  151. #if SMSC_IRCC2_C_SIR_STOP
  152. static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
  153. #endif
  154. static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
  155. static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
  156. static int smsc_ircc_net_open(struct net_device *dev);
  157. static int smsc_ircc_net_close(struct net_device *dev);
  158. static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  159. #if SMSC_IRCC2_C_NET_TIMEOUT
  160. static void smsc_ircc_timeout(struct net_device *dev);
  161. #endif
  162. static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
  163. static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
  164. static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
  165. static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
  166. static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
  167. /* Probing */
  168. static int __init smsc_ircc_look_for_chips(void);
  169. static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
  170. static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
  171. static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
  172. static int __init smsc_superio_fdc(unsigned short cfg_base);
  173. static int __init smsc_superio_lpc(unsigned short cfg_base);
  174. /* Transceivers specific functions */
  175. static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
  176. static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
  177. static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
  178. static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
  179. static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
  180. static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
  181. /* Power Management */
  182. static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
  183. static int smsc_ircc_resume(struct platform_device *dev);
  184. static struct platform_driver smsc_ircc_driver = {
  185. .suspend = smsc_ircc_suspend,
  186. .resume = smsc_ircc_resume,
  187. .driver = {
  188. .name = SMSC_IRCC2_DRIVER_NAME,
  189. },
  190. };
  191. /* Transceivers for SMSC-ircc */
  192. static struct smsc_transceiver smsc_transceivers[] =
  193. {
  194. { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
  195. { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
  196. { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
  197. { NULL, NULL }
  198. };
  199. #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
  200. /* SMC SuperIO chipsets definitions */
  201. #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
  202. #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
  203. #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
  204. #define SIR 0 /* SuperIO Chip has only slow IRDA */
  205. #define FIR 4 /* SuperIO Chip has fast IRDA */
  206. #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
  207. static struct smsc_chip __initdata fdc_chips_flat[] =
  208. {
  209. /* Base address 0x3f0 or 0x370 */
  210. { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
  211. { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
  212. { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
  213. { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
  214. { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
  215. { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
  216. { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
  217. { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
  218. { NULL }
  219. };
  220. static struct smsc_chip __initdata fdc_chips_paged[] =
  221. {
  222. /* Base address 0x3f0 or 0x370 */
  223. { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
  224. { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
  225. { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
  226. { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
  227. { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
  228. { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
  229. { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
  230. { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
  231. { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
  232. { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
  233. { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
  234. { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
  235. { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
  236. { NULL }
  237. };
  238. static struct smsc_chip __initdata lpc_chips_flat[] =
  239. {
  240. /* Base address 0x2E or 0x4E */
  241. { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
  242. { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
  243. { NULL }
  244. };
  245. static struct smsc_chip __initdata lpc_chips_paged[] =
  246. {
  247. /* Base address 0x2E or 0x4E */
  248. { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
  249. { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
  250. { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
  251. { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
  252. { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
  253. { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
  254. { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
  255. { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
  256. { NULL }
  257. };
  258. #define SMSCSIO_TYPE_FDC 1
  259. #define SMSCSIO_TYPE_LPC 2
  260. #define SMSCSIO_TYPE_FLAT 4
  261. #define SMSCSIO_TYPE_PAGED 8
  262. static struct smsc_chip_address __initdata possible_addresses[] =
  263. {
  264. { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  265. { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  266. { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  267. { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  268. { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
  269. { 0, 0 }
  270. };
  271. /* Globals */
  272. static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
  273. static unsigned short dev_count;
  274. static inline void register_bank(int iobase, int bank)
  275. {
  276. outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
  277. iobase + IRCC_MASTER);
  278. }
  279. /*******************************************************************************
  280. *
  281. *
  282. * SMSC-ircc stuff
  283. *
  284. *
  285. *******************************************************************************/
  286. /*
  287. * Function smsc_ircc_init ()
  288. *
  289. * Initialize chip. Just try to find out how many chips we are dealing with
  290. * and where they are
  291. */
  292. static int __init smsc_ircc_init(void)
  293. {
  294. int ret;
  295. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  296. ret = platform_driver_register(&smsc_ircc_driver);
  297. if (ret) {
  298. IRDA_ERROR("%s, Can't register driver!\n", driver_name);
  299. return ret;
  300. }
  301. dev_count = 0;
  302. if (ircc_fir > 0 && ircc_sir > 0) {
  303. IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
  304. IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
  305. if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
  306. ret = -ENODEV;
  307. } else {
  308. ret = -ENODEV;
  309. /* try user provided configuration register base address */
  310. if (ircc_cfg > 0) {
  311. IRDA_MESSAGE(" Overriding configuration address "
  312. "0x%04x\n", ircc_cfg);
  313. if (!smsc_superio_fdc(ircc_cfg))
  314. ret = 0;
  315. if (!smsc_superio_lpc(ircc_cfg))
  316. ret = 0;
  317. }
  318. if (smsc_ircc_look_for_chips() > 0)
  319. ret = 0;
  320. }
  321. if (ret)
  322. platform_driver_unregister(&smsc_ircc_driver);
  323. return ret;
  324. }
  325. /*
  326. * Function smsc_ircc_open (firbase, sirbase, dma, irq)
  327. *
  328. * Try to open driver instance
  329. *
  330. */
  331. static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
  332. {
  333. struct smsc_ircc_cb *self;
  334. struct net_device *dev;
  335. int err;
  336. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  337. err = smsc_ircc_present(fir_base, sir_base);
  338. if (err)
  339. goto err_out;
  340. err = -ENOMEM;
  341. if (dev_count >= ARRAY_SIZE(dev_self)) {
  342. IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
  343. goto err_out1;
  344. }
  345. /*
  346. * Allocate new instance of the driver
  347. */
  348. dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
  349. if (!dev) {
  350. IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
  351. goto err_out1;
  352. }
  353. SET_MODULE_OWNER(dev);
  354. dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
  355. #if SMSC_IRCC2_C_NET_TIMEOUT
  356. dev->tx_timeout = smsc_ircc_timeout;
  357. dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
  358. #endif
  359. dev->open = smsc_ircc_net_open;
  360. dev->stop = smsc_ircc_net_close;
  361. dev->do_ioctl = smsc_ircc_net_ioctl;
  362. dev->get_stats = smsc_ircc_net_get_stats;
  363. self = netdev_priv(dev);
  364. self->netdev = dev;
  365. /* Make ifconfig display some details */
  366. dev->base_addr = self->io.fir_base = fir_base;
  367. dev->irq = self->io.irq = irq;
  368. /* Need to store self somewhere */
  369. dev_self[dev_count] = self;
  370. spin_lock_init(&self->lock);
  371. self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
  372. self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
  373. self->rx_buff.head =
  374. dma_alloc_coherent(NULL, self->rx_buff.truesize,
  375. &self->rx_buff_dma, GFP_KERNEL);
  376. if (self->rx_buff.head == NULL) {
  377. IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
  378. driver_name);
  379. goto err_out2;
  380. }
  381. self->tx_buff.head =
  382. dma_alloc_coherent(NULL, self->tx_buff.truesize,
  383. &self->tx_buff_dma, GFP_KERNEL);
  384. if (self->tx_buff.head == NULL) {
  385. IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
  386. driver_name);
  387. goto err_out3;
  388. }
  389. memset(self->rx_buff.head, 0, self->rx_buff.truesize);
  390. memset(self->tx_buff.head, 0, self->tx_buff.truesize);
  391. self->rx_buff.in_frame = FALSE;
  392. self->rx_buff.state = OUTSIDE_FRAME;
  393. self->tx_buff.data = self->tx_buff.head;
  394. self->rx_buff.data = self->rx_buff.head;
  395. smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
  396. smsc_ircc_setup_qos(self);
  397. smsc_ircc_init_chip(self);
  398. if (ircc_transceiver > 0 &&
  399. ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
  400. self->transceiver = ircc_transceiver;
  401. else
  402. smsc_ircc_probe_transceiver(self);
  403. err = register_netdev(self->netdev);
  404. if (err) {
  405. IRDA_ERROR("%s, Network device registration failed!\n",
  406. driver_name);
  407. goto err_out4;
  408. }
  409. self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
  410. dev_count, NULL, 0);
  411. if (IS_ERR(self->pldev)) {
  412. err = PTR_ERR(self->pldev);
  413. goto err_out5;
  414. }
  415. platform_set_drvdata(self->pldev, self);
  416. IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
  417. dev_count++;
  418. return 0;
  419. err_out5:
  420. unregister_netdev(self->netdev);
  421. err_out4:
  422. dma_free_coherent(NULL, self->tx_buff.truesize,
  423. self->tx_buff.head, self->tx_buff_dma);
  424. err_out3:
  425. dma_free_coherent(NULL, self->rx_buff.truesize,
  426. self->rx_buff.head, self->rx_buff_dma);
  427. err_out2:
  428. free_netdev(self->netdev);
  429. dev_self[dev_count] = NULL;
  430. err_out1:
  431. release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
  432. release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
  433. err_out:
  434. return err;
  435. }
  436. /*
  437. * Function smsc_ircc_present(fir_base, sir_base)
  438. *
  439. * Check the smsc-ircc chip presence
  440. *
  441. */
  442. static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
  443. {
  444. unsigned char low, high, chip, config, dma, irq, version;
  445. if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
  446. driver_name)) {
  447. IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
  448. __FUNCTION__, fir_base);
  449. goto out1;
  450. }
  451. if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
  452. driver_name)) {
  453. IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
  454. __FUNCTION__, sir_base);
  455. goto out2;
  456. }
  457. register_bank(fir_base, 3);
  458. high = inb(fir_base + IRCC_ID_HIGH);
  459. low = inb(fir_base + IRCC_ID_LOW);
  460. chip = inb(fir_base + IRCC_CHIP_ID);
  461. version = inb(fir_base + IRCC_VERSION);
  462. config = inb(fir_base + IRCC_INTERFACE);
  463. dma = config & IRCC_INTERFACE_DMA_MASK;
  464. irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
  465. if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
  466. IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
  467. __FUNCTION__, fir_base);
  468. goto out3;
  469. }
  470. IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
  471. "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
  472. chip & 0x0f, version, fir_base, sir_base, dma, irq);
  473. return 0;
  474. out3:
  475. release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
  476. out2:
  477. release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
  478. out1:
  479. return -ENODEV;
  480. }
  481. /*
  482. * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
  483. *
  484. * Setup I/O
  485. *
  486. */
  487. static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
  488. unsigned int fir_base, unsigned int sir_base,
  489. u8 dma, u8 irq)
  490. {
  491. unsigned char config, chip_dma, chip_irq;
  492. register_bank(fir_base, 3);
  493. config = inb(fir_base + IRCC_INTERFACE);
  494. chip_dma = config & IRCC_INTERFACE_DMA_MASK;
  495. chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
  496. self->io.fir_base = fir_base;
  497. self->io.sir_base = sir_base;
  498. self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
  499. self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
  500. self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
  501. self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
  502. if (irq < 255) {
  503. if (irq != chip_irq)
  504. IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
  505. driver_name, chip_irq, irq);
  506. self->io.irq = irq;
  507. } else
  508. self->io.irq = chip_irq;
  509. if (dma < 255) {
  510. if (dma != chip_dma)
  511. IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
  512. driver_name, chip_dma, dma);
  513. self->io.dma = dma;
  514. } else
  515. self->io.dma = chip_dma;
  516. }
  517. /*
  518. * Function smsc_ircc_setup_qos(self)
  519. *
  520. * Setup qos
  521. *
  522. */
  523. static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
  524. {
  525. /* Initialize QoS for this device */
  526. irda_init_max_qos_capabilies(&self->qos);
  527. self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
  528. IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
  529. self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
  530. self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
  531. irda_qos_bits_to_value(&self->qos);
  532. }
  533. /*
  534. * Function smsc_ircc_init_chip(self)
  535. *
  536. * Init chip
  537. *
  538. */
  539. static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
  540. {
  541. int iobase = self->io.fir_base;
  542. register_bank(iobase, 0);
  543. outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
  544. outb(0x00, iobase + IRCC_MASTER);
  545. register_bank(iobase, 1);
  546. outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
  547. iobase + IRCC_SCE_CFGA);
  548. #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
  549. outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
  550. iobase + IRCC_SCE_CFGB);
  551. #else
  552. outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
  553. iobase + IRCC_SCE_CFGB);
  554. #endif
  555. (void) inb(iobase + IRCC_FIFO_THRESHOLD);
  556. outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
  557. register_bank(iobase, 4);
  558. outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
  559. register_bank(iobase, 0);
  560. outb(0, iobase + IRCC_LCR_A);
  561. smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
  562. /* Power on device */
  563. outb(0x00, iobase + IRCC_MASTER);
  564. }
  565. /*
  566. * Function smsc_ircc_net_ioctl (dev, rq, cmd)
  567. *
  568. * Process IOCTL commands for this device
  569. *
  570. */
  571. static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  572. {
  573. struct if_irda_req *irq = (struct if_irda_req *) rq;
  574. struct smsc_ircc_cb *self;
  575. unsigned long flags;
  576. int ret = 0;
  577. IRDA_ASSERT(dev != NULL, return -1;);
  578. self = netdev_priv(dev);
  579. IRDA_ASSERT(self != NULL, return -1;);
  580. IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
  581. switch (cmd) {
  582. case SIOCSBANDWIDTH: /* Set bandwidth */
  583. if (!capable(CAP_NET_ADMIN))
  584. ret = -EPERM;
  585. else {
  586. /* Make sure we are the only one touching
  587. * self->io.speed and the hardware - Jean II */
  588. spin_lock_irqsave(&self->lock, flags);
  589. smsc_ircc_change_speed(self, irq->ifr_baudrate);
  590. spin_unlock_irqrestore(&self->lock, flags);
  591. }
  592. break;
  593. case SIOCSMEDIABUSY: /* Set media busy */
  594. if (!capable(CAP_NET_ADMIN)) {
  595. ret = -EPERM;
  596. break;
  597. }
  598. irda_device_set_media_busy(self->netdev, TRUE);
  599. break;
  600. case SIOCGRECEIVING: /* Check if we are receiving right now */
  601. irq->ifr_receiving = smsc_ircc_is_receiving(self);
  602. break;
  603. #if 0
  604. case SIOCSDTRRTS:
  605. if (!capable(CAP_NET_ADMIN)) {
  606. ret = -EPERM;
  607. break;
  608. }
  609. smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
  610. break;
  611. #endif
  612. default:
  613. ret = -EOPNOTSUPP;
  614. }
  615. return ret;
  616. }
  617. static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
  618. {
  619. struct smsc_ircc_cb *self = netdev_priv(dev);
  620. return &self->stats;
  621. }
  622. #if SMSC_IRCC2_C_NET_TIMEOUT
  623. /*
  624. * Function smsc_ircc_timeout (struct net_device *dev)
  625. *
  626. * The networking timeout management.
  627. *
  628. */
  629. static void smsc_ircc_timeout(struct net_device *dev)
  630. {
  631. struct smsc_ircc_cb *self = netdev_priv(dev);
  632. unsigned long flags;
  633. IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
  634. dev->name, self->io.speed);
  635. spin_lock_irqsave(&self->lock, flags);
  636. smsc_ircc_sir_start(self);
  637. smsc_ircc_change_speed(self, self->io.speed);
  638. dev->trans_start = jiffies;
  639. netif_wake_queue(dev);
  640. spin_unlock_irqrestore(&self->lock, flags);
  641. }
  642. #endif
  643. /*
  644. * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
  645. *
  646. * Transmits the current frame until FIFO is full, then
  647. * waits until the next transmit interrupt, and continues until the
  648. * frame is transmitted.
  649. */
  650. int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
  651. {
  652. struct smsc_ircc_cb *self;
  653. unsigned long flags;
  654. s32 speed;
  655. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  656. IRDA_ASSERT(dev != NULL, return 0;);
  657. self = netdev_priv(dev);
  658. IRDA_ASSERT(self != NULL, return 0;);
  659. netif_stop_queue(dev);
  660. /* Make sure test of self->io.speed & speed change are atomic */
  661. spin_lock_irqsave(&self->lock, flags);
  662. /* Check if we need to change the speed */
  663. speed = irda_get_next_speed(skb);
  664. if (speed != self->io.speed && speed != -1) {
  665. /* Check for empty frame */
  666. if (!skb->len) {
  667. /*
  668. * We send frames one by one in SIR mode (no
  669. * pipelining), so at this point, if we were sending
  670. * a previous frame, we just received the interrupt
  671. * telling us it is finished (UART_IIR_THRI).
  672. * Therefore, waiting for the transmitter to really
  673. * finish draining the fifo won't take too long.
  674. * And the interrupt handler is not expected to run.
  675. * - Jean II */
  676. smsc_ircc_sir_wait_hw_transmitter_finish(self);
  677. smsc_ircc_change_speed(self, speed);
  678. spin_unlock_irqrestore(&self->lock, flags);
  679. dev_kfree_skb(skb);
  680. return 0;
  681. }
  682. self->new_speed = speed;
  683. }
  684. /* Init tx buffer */
  685. self->tx_buff.data = self->tx_buff.head;
  686. /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
  687. self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
  688. self->tx_buff.truesize);
  689. self->stats.tx_bytes += self->tx_buff.len;
  690. /* Turn on transmit finished interrupt. Will fire immediately! */
  691. outb(UART_IER_THRI, self->io.sir_base + UART_IER);
  692. spin_unlock_irqrestore(&self->lock, flags);
  693. dev_kfree_skb(skb);
  694. return 0;
  695. }
  696. /*
  697. * Function smsc_ircc_set_fir_speed (self, baud)
  698. *
  699. * Change the speed of the device
  700. *
  701. */
  702. static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
  703. {
  704. int fir_base, ir_mode, ctrl, fast;
  705. IRDA_ASSERT(self != NULL, return;);
  706. fir_base = self->io.fir_base;
  707. self->io.speed = speed;
  708. switch (speed) {
  709. default:
  710. case 576000:
  711. ir_mode = IRCC_CFGA_IRDA_HDLC;
  712. ctrl = IRCC_CRC;
  713. fast = 0;
  714. IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
  715. break;
  716. case 1152000:
  717. ir_mode = IRCC_CFGA_IRDA_HDLC;
  718. ctrl = IRCC_1152 | IRCC_CRC;
  719. fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
  720. IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
  721. __FUNCTION__);
  722. break;
  723. case 4000000:
  724. ir_mode = IRCC_CFGA_IRDA_4PPM;
  725. ctrl = IRCC_CRC;
  726. fast = IRCC_LCR_A_FAST;
  727. IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
  728. __FUNCTION__);
  729. break;
  730. }
  731. #if 0
  732. Now in tranceiver!
  733. /* This causes an interrupt */
  734. register_bank(fir_base, 0);
  735. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
  736. #endif
  737. register_bank(fir_base, 1);
  738. outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
  739. register_bank(fir_base, 4);
  740. outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
  741. }
  742. /*
  743. * Function smsc_ircc_fir_start(self)
  744. *
  745. * Change the speed of the device
  746. *
  747. */
  748. static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
  749. {
  750. struct net_device *dev;
  751. int fir_base;
  752. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  753. IRDA_ASSERT(self != NULL, return;);
  754. dev = self->netdev;
  755. IRDA_ASSERT(dev != NULL, return;);
  756. fir_base = self->io.fir_base;
  757. /* Reset everything */
  758. /* Install FIR transmit handler */
  759. dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
  760. /* Clear FIFO */
  761. outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
  762. /* Enable interrupt */
  763. /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
  764. register_bank(fir_base, 1);
  765. /* Select the TX/RX interface */
  766. #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
  767. outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
  768. fir_base + IRCC_SCE_CFGB);
  769. #else
  770. outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
  771. fir_base + IRCC_SCE_CFGB);
  772. #endif
  773. (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
  774. /* Enable SCE interrupts */
  775. outb(0, fir_base + IRCC_MASTER);
  776. register_bank(fir_base, 0);
  777. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
  778. outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
  779. }
  780. /*
  781. * Function smsc_ircc_fir_stop(self, baud)
  782. *
  783. * Change the speed of the device
  784. *
  785. */
  786. static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
  787. {
  788. int fir_base;
  789. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  790. IRDA_ASSERT(self != NULL, return;);
  791. fir_base = self->io.fir_base;
  792. register_bank(fir_base, 0);
  793. /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
  794. outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
  795. }
  796. /*
  797. * Function smsc_ircc_change_speed(self, baud)
  798. *
  799. * Change the speed of the device
  800. *
  801. * This function *must* be called with spinlock held, because it may
  802. * be called from the irq handler. - Jean II
  803. */
  804. static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
  805. {
  806. struct net_device *dev;
  807. int last_speed_was_sir;
  808. IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
  809. IRDA_ASSERT(self != NULL, return;);
  810. dev = self->netdev;
  811. last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
  812. #if 0
  813. /* Temp Hack */
  814. speed= 1152000;
  815. self->io.speed = speed;
  816. last_speed_was_sir = 0;
  817. smsc_ircc_fir_start(self);
  818. #endif
  819. if (self->io.speed == 0)
  820. smsc_ircc_sir_start(self);
  821. #if 0
  822. if (!last_speed_was_sir) speed = self->io.speed;
  823. #endif
  824. if (self->io.speed != speed)
  825. smsc_ircc_set_transceiver_for_speed(self, speed);
  826. self->io.speed = speed;
  827. if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
  828. if (!last_speed_was_sir) {
  829. smsc_ircc_fir_stop(self);
  830. smsc_ircc_sir_start(self);
  831. }
  832. smsc_ircc_set_sir_speed(self, speed);
  833. } else {
  834. if (last_speed_was_sir) {
  835. #if SMSC_IRCC2_C_SIR_STOP
  836. smsc_ircc_sir_stop(self);
  837. #endif
  838. smsc_ircc_fir_start(self);
  839. }
  840. smsc_ircc_set_fir_speed(self, speed);
  841. #if 0
  842. self->tx_buff.len = 10;
  843. self->tx_buff.data = self->tx_buff.head;
  844. smsc_ircc_dma_xmit(self, 4000);
  845. #endif
  846. /* Be ready for incoming frames */
  847. smsc_ircc_dma_receive(self);
  848. }
  849. netif_wake_queue(dev);
  850. }
  851. /*
  852. * Function smsc_ircc_set_sir_speed (self, speed)
  853. *
  854. * Set speed of IrDA port to specified baudrate
  855. *
  856. */
  857. void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
  858. {
  859. int iobase;
  860. int fcr; /* FIFO control reg */
  861. int lcr; /* Line control reg */
  862. int divisor;
  863. IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
  864. IRDA_ASSERT(self != NULL, return;);
  865. iobase = self->io.sir_base;
  866. /* Update accounting for new speed */
  867. self->io.speed = speed;
  868. /* Turn off interrupts */
  869. outb(0, iobase + UART_IER);
  870. divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
  871. fcr = UART_FCR_ENABLE_FIFO;
  872. /*
  873. * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
  874. * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
  875. * about this timeout since it will always be fast enough.
  876. */
  877. fcr |= self->io.speed < 38400 ?
  878. UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
  879. /* IrDA ports use 8N1 */
  880. lcr = UART_LCR_WLEN8;
  881. outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
  882. outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
  883. outb(divisor >> 8, iobase + UART_DLM);
  884. outb(lcr, iobase + UART_LCR); /* Set 8N1 */
  885. outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
  886. /* Turn on interrups */
  887. outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
  888. IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
  889. }
  890. /*
  891. * Function smsc_ircc_hard_xmit_fir (skb, dev)
  892. *
  893. * Transmit the frame!
  894. *
  895. */
  896. static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
  897. {
  898. struct smsc_ircc_cb *self;
  899. unsigned long flags;
  900. s32 speed;
  901. int mtt;
  902. IRDA_ASSERT(dev != NULL, return 0;);
  903. self = netdev_priv(dev);
  904. IRDA_ASSERT(self != NULL, return 0;);
  905. netif_stop_queue(dev);
  906. /* Make sure test of self->io.speed & speed change are atomic */
  907. spin_lock_irqsave(&self->lock, flags);
  908. /* Check if we need to change the speed after this frame */
  909. speed = irda_get_next_speed(skb);
  910. if (speed != self->io.speed && speed != -1) {
  911. /* Check for empty frame */
  912. if (!skb->len) {
  913. /* Note : you should make sure that speed changes
  914. * are not going to corrupt any outgoing frame.
  915. * Look at nsc-ircc for the gory details - Jean II */
  916. smsc_ircc_change_speed(self, speed);
  917. spin_unlock_irqrestore(&self->lock, flags);
  918. dev_kfree_skb(skb);
  919. return 0;
  920. }
  921. self->new_speed = speed;
  922. }
  923. memcpy(self->tx_buff.head, skb->data, skb->len);
  924. self->tx_buff.len = skb->len;
  925. self->tx_buff.data = self->tx_buff.head;
  926. mtt = irda_get_mtt(skb);
  927. if (mtt) {
  928. int bofs;
  929. /*
  930. * Compute how many BOFs (STA or PA's) we need to waste the
  931. * min turn time given the speed of the link.
  932. */
  933. bofs = mtt * (self->io.speed / 1000) / 8000;
  934. if (bofs > 4095)
  935. bofs = 4095;
  936. smsc_ircc_dma_xmit(self, bofs);
  937. } else {
  938. /* Transmit frame */
  939. smsc_ircc_dma_xmit(self, 0);
  940. }
  941. spin_unlock_irqrestore(&self->lock, flags);
  942. dev_kfree_skb(skb);
  943. return 0;
  944. }
  945. /*
  946. * Function smsc_ircc_dma_xmit (self, bofs)
  947. *
  948. * Transmit data using DMA
  949. *
  950. */
  951. static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
  952. {
  953. int iobase = self->io.fir_base;
  954. u8 ctrl;
  955. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  956. #if 1
  957. /* Disable Rx */
  958. register_bank(iobase, 0);
  959. outb(0x00, iobase + IRCC_LCR_B);
  960. #endif
  961. register_bank(iobase, 1);
  962. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  963. iobase + IRCC_SCE_CFGB);
  964. self->io.direction = IO_XMIT;
  965. /* Set BOF additional count for generating the min turn time */
  966. register_bank(iobase, 4);
  967. outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
  968. ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
  969. outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
  970. /* Set max Tx frame size */
  971. outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
  972. outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
  973. /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
  974. /* Enable burst mode chip Tx DMA */
  975. register_bank(iobase, 1);
  976. outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
  977. IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
  978. /* Setup DMA controller (must be done after enabling chip DMA) */
  979. irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
  980. DMA_TX_MODE);
  981. /* Enable interrupt */
  982. register_bank(iobase, 0);
  983. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  984. outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
  985. /* Enable transmit */
  986. outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
  987. }
  988. /*
  989. * Function smsc_ircc_dma_xmit_complete (self)
  990. *
  991. * The transfer of a frame in finished. This function will only be called
  992. * by the interrupt handler
  993. *
  994. */
  995. static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
  996. {
  997. int iobase = self->io.fir_base;
  998. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  999. #if 0
  1000. /* Disable Tx */
  1001. register_bank(iobase, 0);
  1002. outb(0x00, iobase + IRCC_LCR_B);
  1003. #endif
  1004. register_bank(iobase, 1);
  1005. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1006. iobase + IRCC_SCE_CFGB);
  1007. /* Check for underrun! */
  1008. register_bank(iobase, 0);
  1009. if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
  1010. self->stats.tx_errors++;
  1011. self->stats.tx_fifo_errors++;
  1012. /* Reset error condition */
  1013. register_bank(iobase, 0);
  1014. outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
  1015. outb(0x00, iobase + IRCC_MASTER);
  1016. } else {
  1017. self->stats.tx_packets++;
  1018. self->stats.tx_bytes += self->tx_buff.len;
  1019. }
  1020. /* Check if it's time to change the speed */
  1021. if (self->new_speed) {
  1022. smsc_ircc_change_speed(self, self->new_speed);
  1023. self->new_speed = 0;
  1024. }
  1025. netif_wake_queue(self->netdev);
  1026. }
  1027. /*
  1028. * Function smsc_ircc_dma_receive(self)
  1029. *
  1030. * Get ready for receiving a frame. The device will initiate a DMA
  1031. * if it starts to receive a frame.
  1032. *
  1033. */
  1034. static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
  1035. {
  1036. int iobase = self->io.fir_base;
  1037. #if 0
  1038. /* Turn off chip DMA */
  1039. register_bank(iobase, 1);
  1040. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1041. iobase + IRCC_SCE_CFGB);
  1042. #endif
  1043. /* Disable Tx */
  1044. register_bank(iobase, 0);
  1045. outb(0x00, iobase + IRCC_LCR_B);
  1046. /* Turn off chip DMA */
  1047. register_bank(iobase, 1);
  1048. outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
  1049. iobase + IRCC_SCE_CFGB);
  1050. self->io.direction = IO_RECV;
  1051. self->rx_buff.data = self->rx_buff.head;
  1052. /* Set max Rx frame size */
  1053. register_bank(iobase, 4);
  1054. outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
  1055. outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
  1056. /* Setup DMA controller */
  1057. irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
  1058. DMA_RX_MODE);
  1059. /* Enable burst mode chip Rx DMA */
  1060. register_bank(iobase, 1);
  1061. outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
  1062. IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
  1063. /* Enable interrupt */
  1064. register_bank(iobase, 0);
  1065. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  1066. outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
  1067. /* Enable receiver */
  1068. register_bank(iobase, 0);
  1069. outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
  1070. iobase + IRCC_LCR_B);
  1071. return 0;
  1072. }
  1073. /*
  1074. * Function smsc_ircc_dma_receive_complete(self)
  1075. *
  1076. * Finished with receiving frames
  1077. *
  1078. */
  1079. static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
  1080. {
  1081. struct sk_buff *skb;
  1082. int len, msgcnt, lsr;
  1083. int iobase = self->io.fir_base;
  1084. register_bank(iobase, 0);
  1085. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1086. #if 0
  1087. /* Disable Rx */
  1088. register_bank(iobase, 0);
  1089. outb(0x00, iobase + IRCC_LCR_B);
  1090. #endif
  1091. register_bank(iobase, 0);
  1092. outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
  1093. lsr= inb(iobase + IRCC_LSR);
  1094. msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
  1095. IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
  1096. get_dma_residue(self->io.dma));
  1097. len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
  1098. /* Look for errors */
  1099. if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
  1100. self->stats.rx_errors++;
  1101. if (lsr & IRCC_LSR_FRAME_ERROR)
  1102. self->stats.rx_frame_errors++;
  1103. if (lsr & IRCC_LSR_CRC_ERROR)
  1104. self->stats.rx_crc_errors++;
  1105. if (lsr & IRCC_LSR_SIZE_ERROR)
  1106. self->stats.rx_length_errors++;
  1107. if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
  1108. self->stats.rx_length_errors++;
  1109. return;
  1110. }
  1111. /* Remove CRC */
  1112. len -= self->io.speed < 4000000 ? 2 : 4;
  1113. if (len < 2 || len > 2050) {
  1114. IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
  1115. return;
  1116. }
  1117. IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
  1118. skb = dev_alloc_skb(len + 1);
  1119. if (!skb) {
  1120. IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
  1121. __FUNCTION__);
  1122. return;
  1123. }
  1124. /* Make sure IP header gets aligned */
  1125. skb_reserve(skb, 1);
  1126. memcpy(skb_put(skb, len), self->rx_buff.data, len);
  1127. self->stats.rx_packets++;
  1128. self->stats.rx_bytes += len;
  1129. skb->dev = self->netdev;
  1130. skb->mac.raw = skb->data;
  1131. skb->protocol = htons(ETH_P_IRDA);
  1132. netif_rx(skb);
  1133. }
  1134. /*
  1135. * Function smsc_ircc_sir_receive (self)
  1136. *
  1137. * Receive one frame from the infrared port
  1138. *
  1139. */
  1140. static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
  1141. {
  1142. int boguscount = 0;
  1143. int iobase;
  1144. IRDA_ASSERT(self != NULL, return;);
  1145. iobase = self->io.sir_base;
  1146. /*
  1147. * Receive all characters in Rx FIFO, unwrap and unstuff them.
  1148. * async_unwrap_char will deliver all found frames
  1149. */
  1150. do {
  1151. async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
  1152. inb(iobase + UART_RX));
  1153. /* Make sure we don't stay here to long */
  1154. if (boguscount++ > 32) {
  1155. IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
  1156. break;
  1157. }
  1158. } while (inb(iobase + UART_LSR) & UART_LSR_DR);
  1159. }
  1160. /*
  1161. * Function smsc_ircc_interrupt (irq, dev_id, regs)
  1162. *
  1163. * An interrupt from the chip has arrived. Time to do some work
  1164. *
  1165. */
  1166. static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1167. {
  1168. struct net_device *dev = (struct net_device *) dev_id;
  1169. struct smsc_ircc_cb *self;
  1170. int iobase, iir, lcra, lsr;
  1171. irqreturn_t ret = IRQ_NONE;
  1172. if (dev == NULL) {
  1173. printk(KERN_WARNING "%s: irq %d for unknown device.\n",
  1174. driver_name, irq);
  1175. goto irq_ret;
  1176. }
  1177. self = netdev_priv(dev);
  1178. IRDA_ASSERT(self != NULL, return IRQ_NONE;);
  1179. /* Serialise the interrupt handler in various CPUs, stop Tx path */
  1180. spin_lock(&self->lock);
  1181. /* Check if we should use the SIR interrupt handler */
  1182. if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
  1183. ret = smsc_ircc_interrupt_sir(dev);
  1184. goto irq_ret_unlock;
  1185. }
  1186. iobase = self->io.fir_base;
  1187. register_bank(iobase, 0);
  1188. iir = inb(iobase + IRCC_IIR);
  1189. if (iir == 0)
  1190. goto irq_ret_unlock;
  1191. ret = IRQ_HANDLED;
  1192. /* Disable interrupts */
  1193. outb(0, iobase + IRCC_IER);
  1194. lcra = inb(iobase + IRCC_LCR_A);
  1195. lsr = inb(iobase + IRCC_LSR);
  1196. IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
  1197. if (iir & IRCC_IIR_EOM) {
  1198. if (self->io.direction == IO_RECV)
  1199. smsc_ircc_dma_receive_complete(self);
  1200. else
  1201. smsc_ircc_dma_xmit_complete(self);
  1202. smsc_ircc_dma_receive(self);
  1203. }
  1204. if (iir & IRCC_IIR_ACTIVE_FRAME) {
  1205. /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
  1206. }
  1207. /* Enable interrupts again */
  1208. register_bank(iobase, 0);
  1209. outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
  1210. irq_ret_unlock:
  1211. spin_unlock(&self->lock);
  1212. irq_ret:
  1213. return ret;
  1214. }
  1215. /*
  1216. * Function irport_interrupt_sir (irq, dev_id, regs)
  1217. *
  1218. * Interrupt handler for SIR modes
  1219. */
  1220. static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
  1221. {
  1222. struct smsc_ircc_cb *self = netdev_priv(dev);
  1223. int boguscount = 0;
  1224. int iobase;
  1225. int iir, lsr;
  1226. /* Already locked comming here in smsc_ircc_interrupt() */
  1227. /*spin_lock(&self->lock);*/
  1228. iobase = self->io.sir_base;
  1229. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  1230. if (iir == 0)
  1231. return IRQ_NONE;
  1232. while (iir) {
  1233. /* Clear interrupt */
  1234. lsr = inb(iobase + UART_LSR);
  1235. IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
  1236. __FUNCTION__, iir, lsr, iobase);
  1237. switch (iir) {
  1238. case UART_IIR_RLSI:
  1239. IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
  1240. break;
  1241. case UART_IIR_RDI:
  1242. /* Receive interrupt */
  1243. smsc_ircc_sir_receive(self);
  1244. break;
  1245. case UART_IIR_THRI:
  1246. if (lsr & UART_LSR_THRE)
  1247. /* Transmitter ready for data */
  1248. smsc_ircc_sir_write_wakeup(self);
  1249. break;
  1250. default:
  1251. IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
  1252. __FUNCTION__, iir);
  1253. break;
  1254. }
  1255. /* Make sure we don't stay here to long */
  1256. if (boguscount++ > 100)
  1257. break;
  1258. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  1259. }
  1260. /*spin_unlock(&self->lock);*/
  1261. return IRQ_HANDLED;
  1262. }
  1263. #if 0 /* unused */
  1264. /*
  1265. * Function ircc_is_receiving (self)
  1266. *
  1267. * Return TRUE is we are currently receiving a frame
  1268. *
  1269. */
  1270. static int ircc_is_receiving(struct smsc_ircc_cb *self)
  1271. {
  1272. int status = FALSE;
  1273. /* int iobase; */
  1274. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1275. IRDA_ASSERT(self != NULL, return FALSE;);
  1276. IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
  1277. get_dma_residue(self->io.dma));
  1278. status = (self->rx_buff.state != OUTSIDE_FRAME);
  1279. return status;
  1280. }
  1281. #endif /* unused */
  1282. static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
  1283. {
  1284. int error;
  1285. error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
  1286. self->netdev->name, self->netdev);
  1287. if (error)
  1288. IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
  1289. __FUNCTION__, self->io.irq, error);
  1290. return error;
  1291. }
  1292. static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
  1293. {
  1294. unsigned long flags;
  1295. spin_lock_irqsave(&self->lock, flags);
  1296. self->io.speed = 0;
  1297. smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
  1298. spin_unlock_irqrestore(&self->lock, flags);
  1299. }
  1300. static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
  1301. {
  1302. int iobase = self->io.fir_base;
  1303. unsigned long flags;
  1304. spin_lock_irqsave(&self->lock, flags);
  1305. register_bank(iobase, 0);
  1306. outb(0, iobase + IRCC_IER);
  1307. outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
  1308. outb(0x00, iobase + IRCC_MASTER);
  1309. spin_unlock_irqrestore(&self->lock, flags);
  1310. }
  1311. /*
  1312. * Function smsc_ircc_net_open (dev)
  1313. *
  1314. * Start the device
  1315. *
  1316. */
  1317. static int smsc_ircc_net_open(struct net_device *dev)
  1318. {
  1319. struct smsc_ircc_cb *self;
  1320. char hwname[16];
  1321. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1322. IRDA_ASSERT(dev != NULL, return -1;);
  1323. self = netdev_priv(dev);
  1324. IRDA_ASSERT(self != NULL, return 0;);
  1325. if (self->io.suspended) {
  1326. IRDA_DEBUG(0, "%s(), device is suspended\n", __FUNCTION__);
  1327. return -EAGAIN;
  1328. }
  1329. if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
  1330. (void *) dev)) {
  1331. IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
  1332. __FUNCTION__, self->io.irq);
  1333. return -EAGAIN;
  1334. }
  1335. smsc_ircc_start_interrupts(self);
  1336. /* Give self a hardware name */
  1337. /* It would be cool to offer the chip revision here - Jean II */
  1338. sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
  1339. /*
  1340. * Open new IrLAP layer instance, now that everything should be
  1341. * initialized properly
  1342. */
  1343. self->irlap = irlap_open(dev, &self->qos, hwname);
  1344. /*
  1345. * Always allocate the DMA channel after the IRQ,
  1346. * and clean up on failure.
  1347. */
  1348. if (request_dma(self->io.dma, dev->name)) {
  1349. smsc_ircc_net_close(dev);
  1350. IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
  1351. __FUNCTION__, self->io.dma);
  1352. return -EAGAIN;
  1353. }
  1354. netif_start_queue(dev);
  1355. return 0;
  1356. }
  1357. /*
  1358. * Function smsc_ircc_net_close (dev)
  1359. *
  1360. * Stop the device
  1361. *
  1362. */
  1363. static int smsc_ircc_net_close(struct net_device *dev)
  1364. {
  1365. struct smsc_ircc_cb *self;
  1366. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1367. IRDA_ASSERT(dev != NULL, return -1;);
  1368. self = netdev_priv(dev);
  1369. IRDA_ASSERT(self != NULL, return 0;);
  1370. /* Stop device */
  1371. netif_stop_queue(dev);
  1372. /* Stop and remove instance of IrLAP */
  1373. if (self->irlap)
  1374. irlap_close(self->irlap);
  1375. self->irlap = NULL;
  1376. smsc_ircc_stop_interrupts(self);
  1377. /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
  1378. if (!self->io.suspended)
  1379. free_irq(self->io.irq, dev);
  1380. disable_dma(self->io.dma);
  1381. free_dma(self->io.dma);
  1382. return 0;
  1383. }
  1384. static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
  1385. {
  1386. struct smsc_ircc_cb *self = platform_get_drvdata(dev);
  1387. if (!self->io.suspended) {
  1388. IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
  1389. rtnl_lock();
  1390. if (netif_running(self->netdev)) {
  1391. netif_device_detach(self->netdev);
  1392. smsc_ircc_stop_interrupts(self);
  1393. free_irq(self->io.irq, self->netdev);
  1394. disable_dma(self->io.dma);
  1395. }
  1396. self->io.suspended = 1;
  1397. rtnl_unlock();
  1398. }
  1399. return 0;
  1400. }
  1401. static int smsc_ircc_resume(struct platform_device *dev)
  1402. {
  1403. struct smsc_ircc_cb *self = platform_get_drvdata(dev);
  1404. if (self->io.suspended) {
  1405. IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
  1406. rtnl_lock();
  1407. smsc_ircc_init_chip(self);
  1408. if (netif_running(self->netdev)) {
  1409. if (smsc_ircc_request_irq(self)) {
  1410. /*
  1411. * Don't fail resume process, just kill this
  1412. * network interface
  1413. */
  1414. unregister_netdevice(self->netdev);
  1415. } else {
  1416. enable_dma(self->io.dma);
  1417. smsc_ircc_start_interrupts(self);
  1418. netif_device_attach(self->netdev);
  1419. }
  1420. }
  1421. self->io.suspended = 0;
  1422. rtnl_unlock();
  1423. }
  1424. return 0;
  1425. }
  1426. /*
  1427. * Function smsc_ircc_close (self)
  1428. *
  1429. * Close driver instance
  1430. *
  1431. */
  1432. static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
  1433. {
  1434. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1435. IRDA_ASSERT(self != NULL, return -1;);
  1436. platform_device_unregister(self->pldev);
  1437. /* Remove netdevice */
  1438. unregister_netdev(self->netdev);
  1439. smsc_ircc_stop_interrupts(self);
  1440. /* Release the PORTS that this driver is using */
  1441. IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
  1442. self->io.fir_base);
  1443. release_region(self->io.fir_base, self->io.fir_ext);
  1444. IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
  1445. self->io.sir_base);
  1446. release_region(self->io.sir_base, self->io.sir_ext);
  1447. if (self->tx_buff.head)
  1448. dma_free_coherent(NULL, self->tx_buff.truesize,
  1449. self->tx_buff.head, self->tx_buff_dma);
  1450. if (self->rx_buff.head)
  1451. dma_free_coherent(NULL, self->rx_buff.truesize,
  1452. self->rx_buff.head, self->rx_buff_dma);
  1453. free_netdev(self->netdev);
  1454. return 0;
  1455. }
  1456. static void __exit smsc_ircc_cleanup(void)
  1457. {
  1458. int i;
  1459. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1460. for (i = 0; i < 2; i++) {
  1461. if (dev_self[i])
  1462. smsc_ircc_close(dev_self[i]);
  1463. }
  1464. platform_driver_unregister(&smsc_ircc_driver);
  1465. }
  1466. /*
  1467. * Start SIR operations
  1468. *
  1469. * This function *must* be called with spinlock held, because it may
  1470. * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
  1471. */
  1472. void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
  1473. {
  1474. struct net_device *dev;
  1475. int fir_base, sir_base;
  1476. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1477. IRDA_ASSERT(self != NULL, return;);
  1478. dev = self->netdev;
  1479. IRDA_ASSERT(dev != NULL, return;);
  1480. dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
  1481. fir_base = self->io.fir_base;
  1482. sir_base = self->io.sir_base;
  1483. /* Reset everything */
  1484. outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
  1485. #if SMSC_IRCC2_C_SIR_STOP
  1486. /*smsc_ircc_sir_stop(self);*/
  1487. #endif
  1488. register_bank(fir_base, 1);
  1489. outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
  1490. /* Initialize UART */
  1491. outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
  1492. outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
  1493. /* Turn on interrups */
  1494. outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
  1495. IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
  1496. outb(0x00, fir_base + IRCC_MASTER);
  1497. }
  1498. #if SMSC_IRCC2_C_SIR_STOP
  1499. void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
  1500. {
  1501. int iobase;
  1502. IRDA_DEBUG(3, "%s\n", __FUNCTION__);
  1503. iobase = self->io.sir_base;
  1504. /* Reset UART */
  1505. outb(0, iobase + UART_MCR);
  1506. /* Turn off interrupts */
  1507. outb(0, iobase + UART_IER);
  1508. }
  1509. #endif
  1510. /*
  1511. * Function smsc_sir_write_wakeup (self)
  1512. *
  1513. * Called by the SIR interrupt handler when there's room for more data.
  1514. * If we have more packets to send, we send them here.
  1515. *
  1516. */
  1517. static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
  1518. {
  1519. int actual = 0;
  1520. int iobase;
  1521. int fcr;
  1522. IRDA_ASSERT(self != NULL, return;);
  1523. IRDA_DEBUG(4, "%s\n", __FUNCTION__);
  1524. iobase = self->io.sir_base;
  1525. /* Finished with frame? */
  1526. if (self->tx_buff.len > 0) {
  1527. /* Write data left in transmit buffer */
  1528. actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
  1529. self->tx_buff.data, self->tx_buff.len);
  1530. self->tx_buff.data += actual;
  1531. self->tx_buff.len -= actual;
  1532. } else {
  1533. /*if (self->tx_buff.len ==0) {*/
  1534. /*
  1535. * Now serial buffer is almost free & we can start
  1536. * transmission of another packet. But first we must check
  1537. * if we need to change the speed of the hardware
  1538. */
  1539. if (self->new_speed) {
  1540. IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
  1541. __FUNCTION__, self->new_speed);
  1542. smsc_ircc_sir_wait_hw_transmitter_finish(self);
  1543. smsc_ircc_change_speed(self, self->new_speed);
  1544. self->new_speed = 0;
  1545. } else {
  1546. /* Tell network layer that we want more frames */
  1547. netif_wake_queue(self->netdev);
  1548. }
  1549. self->stats.tx_packets++;
  1550. if (self->io.speed <= 115200) {
  1551. /*
  1552. * Reset Rx FIFO to make sure that all reflected transmit data
  1553. * is discarded. This is needed for half duplex operation
  1554. */
  1555. fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
  1556. fcr |= self->io.speed < 38400 ?
  1557. UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
  1558. outb(fcr, iobase + UART_FCR);
  1559. /* Turn on receive interrupts */
  1560. outb(UART_IER_RDI, iobase + UART_IER);
  1561. }
  1562. }
  1563. }
  1564. /*
  1565. * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
  1566. *
  1567. * Fill Tx FIFO with transmit data
  1568. *
  1569. */
  1570. static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
  1571. {
  1572. int actual = 0;
  1573. /* Tx FIFO should be empty! */
  1574. if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
  1575. IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
  1576. return 0;
  1577. }
  1578. /* Fill FIFO with current frame */
  1579. while (fifo_size-- > 0 && actual < len) {
  1580. /* Transmit next byte */
  1581. outb(buf[actual], iobase + UART_TX);
  1582. actual++;
  1583. }
  1584. return actual;
  1585. }
  1586. /*
  1587. * Function smsc_ircc_is_receiving (self)
  1588. *
  1589. * Returns true is we are currently receiving data
  1590. *
  1591. */
  1592. static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
  1593. {
  1594. return (self->rx_buff.state != OUTSIDE_FRAME);
  1595. }
  1596. /*
  1597. * Function smsc_ircc_probe_transceiver(self)
  1598. *
  1599. * Tries to find the used Transceiver
  1600. *
  1601. */
  1602. static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
  1603. {
  1604. unsigned int i;
  1605. IRDA_ASSERT(self != NULL, return;);
  1606. for (i = 0; smsc_transceivers[i].name != NULL; i++)
  1607. if (smsc_transceivers[i].probe(self->io.fir_base)) {
  1608. IRDA_MESSAGE(" %s transceiver found\n",
  1609. smsc_transceivers[i].name);
  1610. self->transceiver= i + 1;
  1611. return;
  1612. }
  1613. IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
  1614. smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
  1615. self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
  1616. }
  1617. /*
  1618. * Function smsc_ircc_set_transceiver_for_speed(self, speed)
  1619. *
  1620. * Set the transceiver according to the speed
  1621. *
  1622. */
  1623. static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
  1624. {
  1625. unsigned int trx;
  1626. trx = self->transceiver;
  1627. if (trx > 0)
  1628. smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
  1629. }
  1630. /*
  1631. * Function smsc_ircc_wait_hw_transmitter_finish ()
  1632. *
  1633. * Wait for the real end of HW transmission
  1634. *
  1635. * The UART is a strict FIFO, and we get called only when we have finished
  1636. * pushing data to the FIFO, so the maximum amount of time we must wait
  1637. * is only for the FIFO to drain out.
  1638. *
  1639. * We use a simple calibrated loop. We may need to adjust the loop
  1640. * delay (udelay) to balance I/O traffic and latency. And we also need to
  1641. * adjust the maximum timeout.
  1642. * It would probably be better to wait for the proper interrupt,
  1643. * but it doesn't seem to be available.
  1644. *
  1645. * We can't use jiffies or kernel timers because :
  1646. * 1) We are called from the interrupt handler, which disable softirqs,
  1647. * so jiffies won't be increased
  1648. * 2) Jiffies granularity is usually very coarse (10ms), and we don't
  1649. * want to wait that long to detect stuck hardware.
  1650. * Jean II
  1651. */
  1652. static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
  1653. {
  1654. int iobase = self->io.sir_base;
  1655. int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
  1656. /* Calibrated busy loop */
  1657. while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
  1658. udelay(1);
  1659. if (count == 0)
  1660. IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
  1661. }
  1662. /* PROBING
  1663. *
  1664. *
  1665. */
  1666. static int __init smsc_ircc_look_for_chips(void)
  1667. {
  1668. struct smsc_chip_address *address;
  1669. char *type;
  1670. unsigned int cfg_base, found;
  1671. found = 0;
  1672. address = possible_addresses;
  1673. while (address->cfg_base) {
  1674. cfg_base = address->cfg_base;
  1675. /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
  1676. if (address->type & SMSCSIO_TYPE_FDC) {
  1677. type = "FDC";
  1678. if (address->type & SMSCSIO_TYPE_FLAT)
  1679. if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
  1680. found++;
  1681. if (address->type & SMSCSIO_TYPE_PAGED)
  1682. if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
  1683. found++;
  1684. }
  1685. if (address->type & SMSCSIO_TYPE_LPC) {
  1686. type = "LPC";
  1687. if (address->type & SMSCSIO_TYPE_FLAT)
  1688. if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
  1689. found++;
  1690. if (address->type & SMSCSIO_TYPE_PAGED)
  1691. if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
  1692. found++;
  1693. }
  1694. address++;
  1695. }
  1696. return found;
  1697. }
  1698. /*
  1699. * Function smsc_superio_flat (chip, base, type)
  1700. *
  1701. * Try to get configuration of a smc SuperIO chip with flat register model
  1702. *
  1703. */
  1704. static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
  1705. {
  1706. unsigned short firbase, sirbase;
  1707. u8 mode, dma, irq;
  1708. int ret = -ENODEV;
  1709. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1710. if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
  1711. return ret;
  1712. outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
  1713. mode = inb(cfgbase + 1);
  1714. /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
  1715. if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
  1716. IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
  1717. outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
  1718. sirbase = inb(cfgbase + 1) << 2;
  1719. /* FIR iobase */
  1720. outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
  1721. firbase = inb(cfgbase + 1) << 3;
  1722. /* DMA */
  1723. outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
  1724. dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
  1725. /* IRQ */
  1726. outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
  1727. irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
  1728. IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
  1729. if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
  1730. ret = 0;
  1731. /* Exit configuration */
  1732. outb(SMSCSIO_CFGEXITKEY, cfgbase);
  1733. return ret;
  1734. }
  1735. /*
  1736. * Function smsc_superio_paged (chip, base, type)
  1737. *
  1738. * Try to get configuration of a smc SuperIO chip with paged register model
  1739. *
  1740. */
  1741. static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
  1742. {
  1743. unsigned short fir_io, sir_io;
  1744. int ret = -ENODEV;
  1745. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1746. if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
  1747. return ret;
  1748. /* Select logical device (UART2) */
  1749. outb(0x07, cfg_base);
  1750. outb(0x05, cfg_base + 1);
  1751. /* SIR iobase */
  1752. outb(0x60, cfg_base);
  1753. sir_io = inb(cfg_base + 1) << 8;
  1754. outb(0x61, cfg_base);
  1755. sir_io |= inb(cfg_base + 1);
  1756. /* Read FIR base */
  1757. outb(0x62, cfg_base);
  1758. fir_io = inb(cfg_base + 1) << 8;
  1759. outb(0x63, cfg_base);
  1760. fir_io |= inb(cfg_base + 1);
  1761. outb(0x2b, cfg_base); /* ??? */
  1762. if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
  1763. ret = 0;
  1764. /* Exit configuration */
  1765. outb(SMSCSIO_CFGEXITKEY, cfg_base);
  1766. return ret;
  1767. }
  1768. static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
  1769. {
  1770. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1771. outb(reg, cfg_base);
  1772. return inb(cfg_base) != reg ? -1 : 0;
  1773. }
  1774. static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
  1775. {
  1776. u8 devid, xdevid, rev;
  1777. IRDA_DEBUG(1, "%s\n", __FUNCTION__);
  1778. /* Leave configuration */
  1779. outb(SMSCSIO_CFGEXITKEY, cfg_base);
  1780. if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
  1781. return NULL;
  1782. outb(reg, cfg_base);
  1783. xdevid = inb(cfg_base + 1);
  1784. /* Enter configuration */
  1785. outb(SMSCSIO_CFGACCESSKEY, cfg_base);
  1786. #if 0
  1787. if (smsc_access(cfg_base,0x55)) /* send second key and check */
  1788. return NULL;
  1789. #endif
  1790. /* probe device ID */
  1791. if (smsc_access(cfg_base, reg))
  1792. return NULL;
  1793. devid = inb(cfg_base + 1);
  1794. if (devid == 0 || devid == 0xff) /* typical values for unused port */
  1795. return NULL;
  1796. /* probe revision ID */
  1797. if (smsc_access(cfg_base, reg + 1))
  1798. return NULL;
  1799. rev = inb(cfg_base + 1);
  1800. if (rev >= 128) /* i think this will make no sense */
  1801. return NULL;
  1802. if (devid == xdevid) /* protection against false positives */
  1803. return NULL;
  1804. /* Check for expected device ID; are there others? */
  1805. while (chip->devid != devid) {
  1806. chip++;
  1807. if (chip->name == NULL)
  1808. return NULL;
  1809. }
  1810. IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
  1811. devid, rev, cfg_base, type, chip->name);
  1812. if (chip->rev > rev) {
  1813. IRDA_MESSAGE("Revision higher than expected\n");
  1814. return NULL;
  1815. }
  1816. if (chip->flags & NoIRDA)
  1817. IRDA_MESSAGE("chipset does not support IRDA\n");
  1818. return chip;
  1819. }
  1820. static int __init smsc_superio_fdc(unsigned short cfg_base)
  1821. {
  1822. int ret = -1;
  1823. if (!request_region(cfg_base, 2, driver_name)) {
  1824. IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
  1825. __FUNCTION__, cfg_base);
  1826. } else {
  1827. if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
  1828. !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
  1829. ret = 0;
  1830. release_region(cfg_base, 2);
  1831. }
  1832. return ret;
  1833. }
  1834. static int __init smsc_superio_lpc(unsigned short cfg_base)
  1835. {
  1836. int ret = -1;
  1837. if (!request_region(cfg_base, 2, driver_name)) {
  1838. IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
  1839. __FUNCTION__, cfg_base);
  1840. } else {
  1841. if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
  1842. !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
  1843. ret = 0;
  1844. release_region(cfg_base, 2);
  1845. }
  1846. return ret;
  1847. }
  1848. /************************************************
  1849. *
  1850. * Transceivers specific functions
  1851. *
  1852. ************************************************/
  1853. /*
  1854. * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
  1855. *
  1856. * Program transceiver through smsc-ircc ATC circuitry
  1857. *
  1858. */
  1859. static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
  1860. {
  1861. unsigned long jiffies_now, jiffies_timeout;
  1862. u8 val;
  1863. jiffies_now = jiffies;
  1864. jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
  1865. /* ATC */
  1866. register_bank(fir_base, 4);
  1867. outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
  1868. fir_base + IRCC_ATC);
  1869. while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
  1870. !time_after(jiffies, jiffies_timeout))
  1871. /* empty */;
  1872. if (val)
  1873. IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
  1874. inb(fir_base + IRCC_ATC));
  1875. }
  1876. /*
  1877. * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
  1878. *
  1879. * Probe transceiver smsc-ircc ATC circuitry
  1880. *
  1881. */
  1882. static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
  1883. {
  1884. return 0;
  1885. }
  1886. /*
  1887. * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
  1888. *
  1889. * Set transceiver
  1890. *
  1891. */
  1892. static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
  1893. {
  1894. u8 fast_mode;
  1895. switch (speed) {
  1896. default:
  1897. case 576000 :
  1898. fast_mode = 0;
  1899. break;
  1900. case 1152000 :
  1901. case 4000000 :
  1902. fast_mode = IRCC_LCR_A_FAST;
  1903. break;
  1904. }
  1905. register_bank(fir_base, 0);
  1906. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
  1907. }
  1908. /*
  1909. * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
  1910. *
  1911. * Probe transceiver
  1912. *
  1913. */
  1914. static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
  1915. {
  1916. return 0;
  1917. }
  1918. /*
  1919. * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
  1920. *
  1921. * Set transceiver
  1922. *
  1923. */
  1924. static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
  1925. {
  1926. u8 fast_mode;
  1927. switch (speed) {
  1928. default:
  1929. case 576000 :
  1930. fast_mode = 0;
  1931. break;
  1932. case 1152000 :
  1933. case 4000000 :
  1934. fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
  1935. break;
  1936. }
  1937. /* This causes an interrupt */
  1938. register_bank(fir_base, 0);
  1939. outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
  1940. }
  1941. /*
  1942. * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
  1943. *
  1944. * Probe transceiver
  1945. *
  1946. */
  1947. static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
  1948. {
  1949. return 0;
  1950. }
  1951. module_init(smsc_ircc_init);
  1952. module_exit(smsc_ircc_cleanup);