smsc-ircc2.c 71 KB

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