smsc-ircc2.c 77 KB

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