smsc-ircc2.c 77 KB

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