smsc-ircc2.c 60 KB

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