smsc-ircc2.c 76 KB

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