smsc-ircc2.c 77 KB

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