parport_pc.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361
  1. /* Low-level parallel-port routines for 8255-based PC-style hardware.
  2. *
  3. * Authors: Phil Blundell <philb@gnu.org>
  4. * Tim Waugh <tim@cyberelk.demon.co.uk>
  5. * Jose Renau <renau@acm.org>
  6. * David Campbell
  7. * Andrea Arcangeli
  8. *
  9. * based on work by Grant Guenther <grant@torque.net> and Phil Blundell.
  10. *
  11. * Cleaned up include files - Russell King <linux@arm.uk.linux.org>
  12. * DMA support - Bert De Jonghe <bert@sophis.be>
  13. * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999
  14. * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G.
  15. * Various hacks, Fred Barnes, 04/2001
  16. * Updated probing logic - Adam Belay <ambx1@neo.rr.com>
  17. */
  18. /* This driver should work with any hardware that is broadly compatible
  19. * with that in the IBM PC. This applies to the majority of integrated
  20. * I/O chipsets that are commonly available. The expected register
  21. * layout is:
  22. *
  23. * base+0 data
  24. * base+1 status
  25. * base+2 control
  26. *
  27. * In addition, there are some optional registers:
  28. *
  29. * base+3 EPP address
  30. * base+4 EPP data
  31. * base+0x400 ECP config A
  32. * base+0x401 ECP config B
  33. * base+0x402 ECP control
  34. *
  35. * All registers are 8 bits wide and read/write. If your hardware differs
  36. * only in register addresses (eg because your registers are on 32-bit
  37. * word boundaries) then you can alter the constants in parport_pc.h to
  38. * accommodate this.
  39. *
  40. * Note that the ECP registers may not start at offset 0x400 for PCI cards,
  41. * but rather will start at port->base_hi.
  42. */
  43. #include <linux/module.h>
  44. #include <linux/init.h>
  45. #include <linux/sched.h>
  46. #include <linux/delay.h>
  47. #include <linux/errno.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/ioport.h>
  50. #include <linux/kernel.h>
  51. #include <linux/slab.h>
  52. #include <linux/dma-mapping.h>
  53. #include <linux/pci.h>
  54. #include <linux/pnp.h>
  55. #include <linux/platform_device.h>
  56. #include <linux/sysctl.h>
  57. #include <linux/io.h>
  58. #include <linux/uaccess.h>
  59. #include <asm/dma.h>
  60. #include <linux/parport.h>
  61. #include <linux/parport_pc.h>
  62. #include <linux/via.h>
  63. #include <asm/parport.h>
  64. #define PARPORT_PC_MAX_PORTS PARPORT_MAX
  65. #ifdef CONFIG_ISA_DMA_API
  66. #define HAS_DMA
  67. #endif
  68. /* ECR modes */
  69. #define ECR_SPP 00
  70. #define ECR_PS2 01
  71. #define ECR_PPF 02
  72. #define ECR_ECP 03
  73. #define ECR_EPP 04
  74. #define ECR_VND 05
  75. #define ECR_TST 06
  76. #define ECR_CNF 07
  77. #define ECR_MODE_MASK 0xe0
  78. #define ECR_WRITE(p, v) frob_econtrol((p), 0xff, (v))
  79. #undef DEBUG
  80. #ifdef DEBUG
  81. #define DPRINTK printk
  82. #else
  83. #define DPRINTK(stuff...)
  84. #endif
  85. #define NR_SUPERIOS 3
  86. static struct superio_struct { /* For Super-IO chips autodetection */
  87. int io;
  88. int irq;
  89. int dma;
  90. } superios[NR_SUPERIOS] = { {0,},};
  91. static int user_specified;
  92. #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
  93. (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
  94. static int verbose_probing;
  95. #endif
  96. static int pci_registered_parport;
  97. static int pnp_registered_parport;
  98. /* frob_control, but for ECR */
  99. static void frob_econtrol(struct parport *pb, unsigned char m,
  100. unsigned char v)
  101. {
  102. unsigned char ectr = 0;
  103. if (m != 0xff)
  104. ectr = inb(ECONTROL(pb));
  105. DPRINTK(KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
  106. m, v, ectr, (ectr & ~m) ^ v);
  107. outb((ectr & ~m) ^ v, ECONTROL(pb));
  108. }
  109. static inline void frob_set_mode(struct parport *p, int mode)
  110. {
  111. frob_econtrol(p, ECR_MODE_MASK, mode << 5);
  112. }
  113. #ifdef CONFIG_PARPORT_PC_FIFO
  114. /* Safely change the mode bits in the ECR
  115. Returns:
  116. 0 : Success
  117. -EBUSY: Could not drain FIFO in some finite amount of time,
  118. mode not changed!
  119. */
  120. static int change_mode(struct parport *p, int m)
  121. {
  122. const struct parport_pc_private *priv = p->physport->private_data;
  123. unsigned char oecr;
  124. int mode;
  125. DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n", m);
  126. if (!priv->ecr) {
  127. printk(KERN_DEBUG "change_mode: but there's no ECR!\n");
  128. return 0;
  129. }
  130. /* Bits <7:5> contain the mode. */
  131. oecr = inb(ECONTROL(p));
  132. mode = (oecr >> 5) & 0x7;
  133. if (mode == m)
  134. return 0;
  135. if (mode >= 2 && !(priv->ctr & 0x20)) {
  136. /* This mode resets the FIFO, so we may
  137. * have to wait for it to drain first. */
  138. unsigned long expire = jiffies + p->physport->cad->timeout;
  139. int counter;
  140. switch (mode) {
  141. case ECR_PPF: /* Parallel Port FIFO mode */
  142. case ECR_ECP: /* ECP Parallel Port mode */
  143. /* Busy wait for 200us */
  144. for (counter = 0; counter < 40; counter++) {
  145. if (inb(ECONTROL(p)) & 0x01)
  146. break;
  147. if (signal_pending(current))
  148. break;
  149. udelay(5);
  150. }
  151. /* Poll slowly. */
  152. while (!(inb(ECONTROL(p)) & 0x01)) {
  153. if (time_after_eq(jiffies, expire))
  154. /* The FIFO is stuck. */
  155. return -EBUSY;
  156. schedule_timeout_interruptible(
  157. msecs_to_jiffies(10));
  158. if (signal_pending(current))
  159. break;
  160. }
  161. }
  162. }
  163. if (mode >= 2 && m >= 2) {
  164. /* We have to go through mode 001 */
  165. oecr &= ~(7 << 5);
  166. oecr |= ECR_PS2 << 5;
  167. ECR_WRITE(p, oecr);
  168. }
  169. /* Set the mode. */
  170. oecr &= ~(7 << 5);
  171. oecr |= m << 5;
  172. ECR_WRITE(p, oecr);
  173. return 0;
  174. }
  175. #endif /* FIFO support */
  176. /*
  177. * Clear TIMEOUT BIT in EPP MODE
  178. *
  179. * This is also used in SPP detection.
  180. */
  181. static int clear_epp_timeout(struct parport *pb)
  182. {
  183. unsigned char r;
  184. if (!(parport_pc_read_status(pb) & 0x01))
  185. return 1;
  186. /* To clear timeout some chips require double read */
  187. parport_pc_read_status(pb);
  188. r = parport_pc_read_status(pb);
  189. outb(r | 0x01, STATUS(pb)); /* Some reset by writing 1 */
  190. outb(r & 0xfe, STATUS(pb)); /* Others by writing 0 */
  191. r = parport_pc_read_status(pb);
  192. return !(r & 0x01);
  193. }
  194. /*
  195. * Access functions.
  196. *
  197. * Most of these aren't static because they may be used by the
  198. * parport_xxx_yyy macros. extern __inline__ versions of several
  199. * of these are in parport_pc.h.
  200. */
  201. static void parport_pc_init_state(struct pardevice *dev,
  202. struct parport_state *s)
  203. {
  204. s->u.pc.ctr = 0xc;
  205. if (dev->irq_func &&
  206. dev->port->irq != PARPORT_IRQ_NONE)
  207. /* Set ackIntEn */
  208. s->u.pc.ctr |= 0x10;
  209. s->u.pc.ecr = 0x34; /* NetMos chip can cause problems 0x24;
  210. * D.Gruszka VScom */
  211. }
  212. static void parport_pc_save_state(struct parport *p, struct parport_state *s)
  213. {
  214. const struct parport_pc_private *priv = p->physport->private_data;
  215. s->u.pc.ctr = priv->ctr;
  216. if (priv->ecr)
  217. s->u.pc.ecr = inb(ECONTROL(p));
  218. }
  219. static void parport_pc_restore_state(struct parport *p,
  220. struct parport_state *s)
  221. {
  222. struct parport_pc_private *priv = p->physport->private_data;
  223. register unsigned char c = s->u.pc.ctr & priv->ctr_writable;
  224. outb(c, CONTROL(p));
  225. priv->ctr = c;
  226. if (priv->ecr)
  227. ECR_WRITE(p, s->u.pc.ecr);
  228. }
  229. #ifdef CONFIG_PARPORT_1284
  230. static size_t parport_pc_epp_read_data(struct parport *port, void *buf,
  231. size_t length, int flags)
  232. {
  233. size_t got = 0;
  234. if (flags & PARPORT_W91284PIC) {
  235. unsigned char status;
  236. size_t left = length;
  237. /* use knowledge about data lines..:
  238. * nFault is 0 if there is at least 1 byte in the Warp's FIFO
  239. * pError is 1 if there are 16 bytes in the Warp's FIFO
  240. */
  241. status = inb(STATUS(port));
  242. while (!(status & 0x08) && got < length) {
  243. if (left >= 16 && (status & 0x20) && !(status & 0x08)) {
  244. /* can grab 16 bytes from warp fifo */
  245. if (!((long)buf & 0x03))
  246. insl(EPPDATA(port), buf, 4);
  247. else
  248. insb(EPPDATA(port), buf, 16);
  249. buf += 16;
  250. got += 16;
  251. left -= 16;
  252. } else {
  253. /* grab single byte from the warp fifo */
  254. *((char *)buf) = inb(EPPDATA(port));
  255. buf++;
  256. got++;
  257. left--;
  258. }
  259. status = inb(STATUS(port));
  260. if (status & 0x01) {
  261. /* EPP timeout should never occur... */
  262. printk(KERN_DEBUG
  263. "%s: EPP timeout occurred while talking to w91284pic (should not have done)\n", port->name);
  264. clear_epp_timeout(port);
  265. }
  266. }
  267. return got;
  268. }
  269. if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
  270. if (!(((long)buf | length) & 0x03))
  271. insl(EPPDATA(port), buf, (length >> 2));
  272. else
  273. insb(EPPDATA(port), buf, length);
  274. if (inb(STATUS(port)) & 0x01) {
  275. clear_epp_timeout(port);
  276. return -EIO;
  277. }
  278. return length;
  279. }
  280. for (; got < length; got++) {
  281. *((char *)buf) = inb(EPPDATA(port));
  282. buf++;
  283. if (inb(STATUS(port)) & 0x01) {
  284. /* EPP timeout */
  285. clear_epp_timeout(port);
  286. break;
  287. }
  288. }
  289. return got;
  290. }
  291. static size_t parport_pc_epp_write_data(struct parport *port, const void *buf,
  292. size_t length, int flags)
  293. {
  294. size_t written = 0;
  295. if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
  296. if (!(((long)buf | length) & 0x03))
  297. outsl(EPPDATA(port), buf, (length >> 2));
  298. else
  299. outsb(EPPDATA(port), buf, length);
  300. if (inb(STATUS(port)) & 0x01) {
  301. clear_epp_timeout(port);
  302. return -EIO;
  303. }
  304. return length;
  305. }
  306. for (; written < length; written++) {
  307. outb(*((char *)buf), EPPDATA(port));
  308. buf++;
  309. if (inb(STATUS(port)) & 0x01) {
  310. clear_epp_timeout(port);
  311. break;
  312. }
  313. }
  314. return written;
  315. }
  316. static size_t parport_pc_epp_read_addr(struct parport *port, void *buf,
  317. size_t length, int flags)
  318. {
  319. size_t got = 0;
  320. if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
  321. insb(EPPADDR(port), buf, length);
  322. if (inb(STATUS(port)) & 0x01) {
  323. clear_epp_timeout(port);
  324. return -EIO;
  325. }
  326. return length;
  327. }
  328. for (; got < length; got++) {
  329. *((char *)buf) = inb(EPPADDR(port));
  330. buf++;
  331. if (inb(STATUS(port)) & 0x01) {
  332. clear_epp_timeout(port);
  333. break;
  334. }
  335. }
  336. return got;
  337. }
  338. static size_t parport_pc_epp_write_addr(struct parport *port,
  339. const void *buf, size_t length,
  340. int flags)
  341. {
  342. size_t written = 0;
  343. if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
  344. outsb(EPPADDR(port), buf, length);
  345. if (inb(STATUS(port)) & 0x01) {
  346. clear_epp_timeout(port);
  347. return -EIO;
  348. }
  349. return length;
  350. }
  351. for (; written < length; written++) {
  352. outb(*((char *)buf), EPPADDR(port));
  353. buf++;
  354. if (inb(STATUS(port)) & 0x01) {
  355. clear_epp_timeout(port);
  356. break;
  357. }
  358. }
  359. return written;
  360. }
  361. static size_t parport_pc_ecpepp_read_data(struct parport *port, void *buf,
  362. size_t length, int flags)
  363. {
  364. size_t got;
  365. frob_set_mode(port, ECR_EPP);
  366. parport_pc_data_reverse(port);
  367. parport_pc_write_control(port, 0x4);
  368. got = parport_pc_epp_read_data(port, buf, length, flags);
  369. frob_set_mode(port, ECR_PS2);
  370. return got;
  371. }
  372. static size_t parport_pc_ecpepp_write_data(struct parport *port,
  373. const void *buf, size_t length,
  374. int flags)
  375. {
  376. size_t written;
  377. frob_set_mode(port, ECR_EPP);
  378. parport_pc_write_control(port, 0x4);
  379. parport_pc_data_forward(port);
  380. written = parport_pc_epp_write_data(port, buf, length, flags);
  381. frob_set_mode(port, ECR_PS2);
  382. return written;
  383. }
  384. static size_t parport_pc_ecpepp_read_addr(struct parport *port, void *buf,
  385. size_t length, int flags)
  386. {
  387. size_t got;
  388. frob_set_mode(port, ECR_EPP);
  389. parport_pc_data_reverse(port);
  390. parport_pc_write_control(port, 0x4);
  391. got = parport_pc_epp_read_addr(port, buf, length, flags);
  392. frob_set_mode(port, ECR_PS2);
  393. return got;
  394. }
  395. static size_t parport_pc_ecpepp_write_addr(struct parport *port,
  396. const void *buf, size_t length,
  397. int flags)
  398. {
  399. size_t written;
  400. frob_set_mode(port, ECR_EPP);
  401. parport_pc_write_control(port, 0x4);
  402. parport_pc_data_forward(port);
  403. written = parport_pc_epp_write_addr(port, buf, length, flags);
  404. frob_set_mode(port, ECR_PS2);
  405. return written;
  406. }
  407. #endif /* IEEE 1284 support */
  408. #ifdef CONFIG_PARPORT_PC_FIFO
  409. static size_t parport_pc_fifo_write_block_pio(struct parport *port,
  410. const void *buf, size_t length)
  411. {
  412. int ret = 0;
  413. const unsigned char *bufp = buf;
  414. size_t left = length;
  415. unsigned long expire = jiffies + port->physport->cad->timeout;
  416. const int fifo = FIFO(port);
  417. int poll_for = 8; /* 80 usecs */
  418. const struct parport_pc_private *priv = port->physport->private_data;
  419. const int fifo_depth = priv->fifo_depth;
  420. port = port->physport;
  421. /* We don't want to be interrupted every character. */
  422. parport_pc_disable_irq(port);
  423. /* set nErrIntrEn and serviceIntr */
  424. frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
  425. /* Forward mode. */
  426. parport_pc_data_forward(port); /* Must be in PS2 mode */
  427. while (left) {
  428. unsigned char byte;
  429. unsigned char ecrval = inb(ECONTROL(port));
  430. int i = 0;
  431. if (need_resched() && time_before(jiffies, expire))
  432. /* Can't yield the port. */
  433. schedule();
  434. /* Anyone else waiting for the port? */
  435. if (port->waithead) {
  436. printk(KERN_DEBUG "Somebody wants the port\n");
  437. break;
  438. }
  439. if (ecrval & 0x02) {
  440. /* FIFO is full. Wait for interrupt. */
  441. /* Clear serviceIntr */
  442. ECR_WRITE(port, ecrval & ~(1<<2));
  443. false_alarm:
  444. ret = parport_wait_event(port, HZ);
  445. if (ret < 0)
  446. break;
  447. ret = 0;
  448. if (!time_before(jiffies, expire)) {
  449. /* Timed out. */
  450. printk(KERN_DEBUG "FIFO write timed out\n");
  451. break;
  452. }
  453. ecrval = inb(ECONTROL(port));
  454. if (!(ecrval & (1<<2))) {
  455. if (need_resched() &&
  456. time_before(jiffies, expire))
  457. schedule();
  458. goto false_alarm;
  459. }
  460. continue;
  461. }
  462. /* Can't fail now. */
  463. expire = jiffies + port->cad->timeout;
  464. poll:
  465. if (signal_pending(current))
  466. break;
  467. if (ecrval & 0x01) {
  468. /* FIFO is empty. Blast it full. */
  469. const int n = left < fifo_depth ? left : fifo_depth;
  470. outsb(fifo, bufp, n);
  471. bufp += n;
  472. left -= n;
  473. /* Adjust the poll time. */
  474. if (i < (poll_for - 2))
  475. poll_for--;
  476. continue;
  477. } else if (i++ < poll_for) {
  478. udelay(10);
  479. ecrval = inb(ECONTROL(port));
  480. goto poll;
  481. }
  482. /* Half-full(call me an optimist) */
  483. byte = *bufp++;
  484. outb(byte, fifo);
  485. left--;
  486. }
  487. dump_parport_state("leave fifo_write_block_pio", port);
  488. return length - left;
  489. }
  490. #ifdef HAS_DMA
  491. static size_t parport_pc_fifo_write_block_dma(struct parport *port,
  492. const void *buf, size_t length)
  493. {
  494. int ret = 0;
  495. unsigned long dmaflag;
  496. size_t left = length;
  497. const struct parport_pc_private *priv = port->physport->private_data;
  498. struct device *dev = port->physport->dev;
  499. dma_addr_t dma_addr, dma_handle;
  500. size_t maxlen = 0x10000; /* max 64k per DMA transfer */
  501. unsigned long start = (unsigned long) buf;
  502. unsigned long end = (unsigned long) buf + length - 1;
  503. dump_parport_state("enter fifo_write_block_dma", port);
  504. if (end < MAX_DMA_ADDRESS) {
  505. /* If it would cross a 64k boundary, cap it at the end. */
  506. if ((start ^ end) & ~0xffffUL)
  507. maxlen = 0x10000 - (start & 0xffff);
  508. dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
  509. DMA_TO_DEVICE);
  510. } else {
  511. /* above 16 MB we use a bounce buffer as ISA-DMA
  512. is not possible */
  513. maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
  514. dma_addr = priv->dma_handle;
  515. dma_handle = 0;
  516. }
  517. port = port->physport;
  518. /* We don't want to be interrupted every character. */
  519. parport_pc_disable_irq(port);
  520. /* set nErrIntrEn and serviceIntr */
  521. frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
  522. /* Forward mode. */
  523. parport_pc_data_forward(port); /* Must be in PS2 mode */
  524. while (left) {
  525. unsigned long expire = jiffies + port->physport->cad->timeout;
  526. size_t count = left;
  527. if (count > maxlen)
  528. count = maxlen;
  529. if (!dma_handle) /* bounce buffer ! */
  530. memcpy(priv->dma_buf, buf, count);
  531. dmaflag = claim_dma_lock();
  532. disable_dma(port->dma);
  533. clear_dma_ff(port->dma);
  534. set_dma_mode(port->dma, DMA_MODE_WRITE);
  535. set_dma_addr(port->dma, dma_addr);
  536. set_dma_count(port->dma, count);
  537. /* Set DMA mode */
  538. frob_econtrol(port, 1<<3, 1<<3);
  539. /* Clear serviceIntr */
  540. frob_econtrol(port, 1<<2, 0);
  541. enable_dma(port->dma);
  542. release_dma_lock(dmaflag);
  543. /* assume DMA will be successful */
  544. left -= count;
  545. buf += count;
  546. if (dma_handle)
  547. dma_addr += count;
  548. /* Wait for interrupt. */
  549. false_alarm:
  550. ret = parport_wait_event(port, HZ);
  551. if (ret < 0)
  552. break;
  553. ret = 0;
  554. if (!time_before(jiffies, expire)) {
  555. /* Timed out. */
  556. printk(KERN_DEBUG "DMA write timed out\n");
  557. break;
  558. }
  559. /* Is serviceIntr set? */
  560. if (!(inb(ECONTROL(port)) & (1<<2))) {
  561. cond_resched();
  562. goto false_alarm;
  563. }
  564. dmaflag = claim_dma_lock();
  565. disable_dma(port->dma);
  566. clear_dma_ff(port->dma);
  567. count = get_dma_residue(port->dma);
  568. release_dma_lock(dmaflag);
  569. cond_resched(); /* Can't yield the port. */
  570. /* Anyone else waiting for the port? */
  571. if (port->waithead) {
  572. printk(KERN_DEBUG "Somebody wants the port\n");
  573. break;
  574. }
  575. /* update for possible DMA residue ! */
  576. buf -= count;
  577. left += count;
  578. if (dma_handle)
  579. dma_addr -= count;
  580. }
  581. /* Maybe got here through break, so adjust for DMA residue! */
  582. dmaflag = claim_dma_lock();
  583. disable_dma(port->dma);
  584. clear_dma_ff(port->dma);
  585. left += get_dma_residue(port->dma);
  586. release_dma_lock(dmaflag);
  587. /* Turn off DMA mode */
  588. frob_econtrol(port, 1<<3, 0);
  589. if (dma_handle)
  590. dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
  591. dump_parport_state("leave fifo_write_block_dma", port);
  592. return length - left;
  593. }
  594. #endif
  595. static inline size_t parport_pc_fifo_write_block(struct parport *port,
  596. const void *buf, size_t length)
  597. {
  598. #ifdef HAS_DMA
  599. if (port->dma != PARPORT_DMA_NONE)
  600. return parport_pc_fifo_write_block_dma(port, buf, length);
  601. #endif
  602. return parport_pc_fifo_write_block_pio(port, buf, length);
  603. }
  604. /* Parallel Port FIFO mode (ECP chipsets) */
  605. static size_t parport_pc_compat_write_block_pio(struct parport *port,
  606. const void *buf, size_t length,
  607. int flags)
  608. {
  609. size_t written;
  610. int r;
  611. unsigned long expire;
  612. const struct parport_pc_private *priv = port->physport->private_data;
  613. /* Special case: a timeout of zero means we cannot call schedule().
  614. * Also if O_NONBLOCK is set then use the default implementation. */
  615. if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
  616. return parport_ieee1284_write_compat(port, buf,
  617. length, flags);
  618. /* Set up parallel port FIFO mode.*/
  619. parport_pc_data_forward(port); /* Must be in PS2 mode */
  620. parport_pc_frob_control(port, PARPORT_CONTROL_STROBE, 0);
  621. r = change_mode(port, ECR_PPF); /* Parallel port FIFO */
  622. if (r)
  623. printk(KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n",
  624. port->name);
  625. port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
  626. /* Write the data to the FIFO. */
  627. written = parport_pc_fifo_write_block(port, buf, length);
  628. /* Finish up. */
  629. /* For some hardware we don't want to touch the mode until
  630. * the FIFO is empty, so allow 4 seconds for each position
  631. * in the fifo.
  632. */
  633. expire = jiffies + (priv->fifo_depth * HZ * 4);
  634. do {
  635. /* Wait for the FIFO to empty */
  636. r = change_mode(port, ECR_PS2);
  637. if (r != -EBUSY)
  638. break;
  639. } while (time_before(jiffies, expire));
  640. if (r == -EBUSY) {
  641. printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name);
  642. /* Prevent further data transfer. */
  643. frob_set_mode(port, ECR_TST);
  644. /* Adjust for the contents of the FIFO. */
  645. for (written -= priv->fifo_depth; ; written++) {
  646. if (inb(ECONTROL(port)) & 0x2) {
  647. /* Full up. */
  648. break;
  649. }
  650. outb(0, FIFO(port));
  651. }
  652. /* Reset the FIFO and return to PS2 mode. */
  653. frob_set_mode(port, ECR_PS2);
  654. }
  655. r = parport_wait_peripheral(port,
  656. PARPORT_STATUS_BUSY,
  657. PARPORT_STATUS_BUSY);
  658. if (r)
  659. printk(KERN_DEBUG
  660. "%s: BUSY timeout (%d) in compat_write_block_pio\n",
  661. port->name, r);
  662. port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
  663. return written;
  664. }
  665. /* ECP */
  666. #ifdef CONFIG_PARPORT_1284
  667. static size_t parport_pc_ecp_write_block_pio(struct parport *port,
  668. const void *buf, size_t length,
  669. int flags)
  670. {
  671. size_t written;
  672. int r;
  673. unsigned long expire;
  674. const struct parport_pc_private *priv = port->physport->private_data;
  675. /* Special case: a timeout of zero means we cannot call schedule().
  676. * Also if O_NONBLOCK is set then use the default implementation. */
  677. if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
  678. return parport_ieee1284_ecp_write_data(port, buf,
  679. length, flags);
  680. /* Switch to forward mode if necessary. */
  681. if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
  682. /* Event 47: Set nInit high. */
  683. parport_frob_control(port,
  684. PARPORT_CONTROL_INIT
  685. | PARPORT_CONTROL_AUTOFD,
  686. PARPORT_CONTROL_INIT
  687. | PARPORT_CONTROL_AUTOFD);
  688. /* Event 49: PError goes high. */
  689. r = parport_wait_peripheral(port,
  690. PARPORT_STATUS_PAPEROUT,
  691. PARPORT_STATUS_PAPEROUT);
  692. if (r) {
  693. printk(KERN_DEBUG "%s: PError timeout (%d) "
  694. "in ecp_write_block_pio\n", port->name, r);
  695. }
  696. }
  697. /* Set up ECP parallel port mode.*/
  698. parport_pc_data_forward(port); /* Must be in PS2 mode */
  699. parport_pc_frob_control(port,
  700. PARPORT_CONTROL_STROBE |
  701. PARPORT_CONTROL_AUTOFD,
  702. 0);
  703. r = change_mode(port, ECR_ECP); /* ECP FIFO */
  704. if (r)
  705. printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n",
  706. port->name);
  707. port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
  708. /* Write the data to the FIFO. */
  709. written = parport_pc_fifo_write_block(port, buf, length);
  710. /* Finish up. */
  711. /* For some hardware we don't want to touch the mode until
  712. * the FIFO is empty, so allow 4 seconds for each position
  713. * in the fifo.
  714. */
  715. expire = jiffies + (priv->fifo_depth * (HZ * 4));
  716. do {
  717. /* Wait for the FIFO to empty */
  718. r = change_mode(port, ECR_PS2);
  719. if (r != -EBUSY)
  720. break;
  721. } while (time_before(jiffies, expire));
  722. if (r == -EBUSY) {
  723. printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name);
  724. /* Prevent further data transfer. */
  725. frob_set_mode(port, ECR_TST);
  726. /* Adjust for the contents of the FIFO. */
  727. for (written -= priv->fifo_depth; ; written++) {
  728. if (inb(ECONTROL(port)) & 0x2) {
  729. /* Full up. */
  730. break;
  731. }
  732. outb(0, FIFO(port));
  733. }
  734. /* Reset the FIFO and return to PS2 mode. */
  735. frob_set_mode(port, ECR_PS2);
  736. /* Host transfer recovery. */
  737. parport_pc_data_reverse(port); /* Must be in PS2 mode */
  738. udelay(5);
  739. parport_frob_control(port, PARPORT_CONTROL_INIT, 0);
  740. r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0);
  741. if (r)
  742. printk(KERN_DEBUG "%s: PE,1 timeout (%d) "
  743. "in ecp_write_block_pio\n", port->name, r);
  744. parport_frob_control(port,
  745. PARPORT_CONTROL_INIT,
  746. PARPORT_CONTROL_INIT);
  747. r = parport_wait_peripheral(port,
  748. PARPORT_STATUS_PAPEROUT,
  749. PARPORT_STATUS_PAPEROUT);
  750. if (r)
  751. printk(KERN_DEBUG "%s: PE,2 timeout (%d) "
  752. "in ecp_write_block_pio\n", port->name, r);
  753. }
  754. r = parport_wait_peripheral(port,
  755. PARPORT_STATUS_BUSY,
  756. PARPORT_STATUS_BUSY);
  757. if (r)
  758. printk(KERN_DEBUG
  759. "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
  760. port->name, r);
  761. port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
  762. return written;
  763. }
  764. #endif /* IEEE 1284 support */
  765. #endif /* Allowed to use FIFO/DMA */
  766. /*
  767. * ******************************************
  768. * INITIALISATION AND MODULE STUFF BELOW HERE
  769. * ******************************************
  770. */
  771. /* GCC is not inlining extern inline function later overwriten to non-inline,
  772. so we use outlined_ variants here. */
  773. static const struct parport_operations parport_pc_ops = {
  774. .write_data = parport_pc_write_data,
  775. .read_data = parport_pc_read_data,
  776. .write_control = parport_pc_write_control,
  777. .read_control = parport_pc_read_control,
  778. .frob_control = parport_pc_frob_control,
  779. .read_status = parport_pc_read_status,
  780. .enable_irq = parport_pc_enable_irq,
  781. .disable_irq = parport_pc_disable_irq,
  782. .data_forward = parport_pc_data_forward,
  783. .data_reverse = parport_pc_data_reverse,
  784. .init_state = parport_pc_init_state,
  785. .save_state = parport_pc_save_state,
  786. .restore_state = parport_pc_restore_state,
  787. .epp_write_data = parport_ieee1284_epp_write_data,
  788. .epp_read_data = parport_ieee1284_epp_read_data,
  789. .epp_write_addr = parport_ieee1284_epp_write_addr,
  790. .epp_read_addr = parport_ieee1284_epp_read_addr,
  791. .ecp_write_data = parport_ieee1284_ecp_write_data,
  792. .ecp_read_data = parport_ieee1284_ecp_read_data,
  793. .ecp_write_addr = parport_ieee1284_ecp_write_addr,
  794. .compat_write_data = parport_ieee1284_write_compat,
  795. .nibble_read_data = parport_ieee1284_read_nibble,
  796. .byte_read_data = parport_ieee1284_read_byte,
  797. .owner = THIS_MODULE,
  798. };
  799. #ifdef CONFIG_PARPORT_PC_SUPERIO
  800. static struct superio_struct *find_free_superio(void)
  801. {
  802. int i;
  803. for (i = 0; i < NR_SUPERIOS; i++)
  804. if (superios[i].io == 0)
  805. return &superios[i];
  806. return NULL;
  807. }
  808. /* Super-IO chipset detection, Winbond, SMSC */
  809. static void show_parconfig_smsc37c669(int io, int key)
  810. {
  811. int cr1, cr4, cra, cr23, cr26, cr27;
  812. struct superio_struct *s;
  813. static const char *const modes[] = {
  814. "SPP and Bidirectional (PS/2)",
  815. "EPP and SPP",
  816. "ECP",
  817. "ECP and EPP" };
  818. outb(key, io);
  819. outb(key, io);
  820. outb(1, io);
  821. cr1 = inb(io + 1);
  822. outb(4, io);
  823. cr4 = inb(io + 1);
  824. outb(0x0a, io);
  825. cra = inb(io + 1);
  826. outb(0x23, io);
  827. cr23 = inb(io + 1);
  828. outb(0x26, io);
  829. cr26 = inb(io + 1);
  830. outb(0x27, io);
  831. cr27 = inb(io + 1);
  832. outb(0xaa, io);
  833. if (verbose_probing) {
  834. printk(KERN_INFO
  835. "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
  836. "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
  837. cr1, cr4, cra, cr23, cr26, cr27);
  838. /* The documentation calls DMA and IRQ-Lines by letters, so
  839. the board maker can/will wire them
  840. appropriately/randomly... G=reserved H=IDE-irq, */
  841. printk(KERN_INFO
  842. "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, fifo threshold=%d\n",
  843. cr23 * 4,
  844. (cr27 & 0x0f) ? 'A' - 1 + (cr27 & 0x0f) : '-',
  845. (cr26 & 0x0f) ? 'A' - 1 + (cr26 & 0x0f) : '-',
  846. cra & 0x0f);
  847. printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n",
  848. (cr23 * 4 >= 0x100) ? "yes" : "no",
  849. (cr1 & 4) ? "yes" : "no");
  850. printk(KERN_INFO
  851. "SMSC LPT Config: Port mode=%s, EPP version =%s\n",
  852. (cr1 & 0x08) ? "Standard mode only (SPP)"
  853. : modes[cr4 & 0x03],
  854. (cr4 & 0x40) ? "1.7" : "1.9");
  855. }
  856. /* Heuristics ! BIOS setup for this mainboard device limits
  857. the choices to standard settings, i.e. io-address and IRQ
  858. are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
  859. DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
  860. if (cr23 * 4 >= 0x100) { /* if active */
  861. s = find_free_superio();
  862. if (s == NULL)
  863. printk(KERN_INFO "Super-IO: too many chips!\n");
  864. else {
  865. int d;
  866. switch (cr23 * 4) {
  867. case 0x3bc:
  868. s->io = 0x3bc;
  869. s->irq = 7;
  870. break;
  871. case 0x378:
  872. s->io = 0x378;
  873. s->irq = 7;
  874. break;
  875. case 0x278:
  876. s->io = 0x278;
  877. s->irq = 5;
  878. }
  879. d = (cr26 & 0x0f);
  880. if (d == 1 || d == 3)
  881. s->dma = d;
  882. else
  883. s->dma = PARPORT_DMA_NONE;
  884. }
  885. }
  886. }
  887. static void show_parconfig_winbond(int io, int key)
  888. {
  889. int cr30, cr60, cr61, cr70, cr74, crf0;
  890. struct superio_struct *s;
  891. static const char *const modes[] = {
  892. "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
  893. "EPP-1.9 and SPP",
  894. "ECP",
  895. "ECP and EPP-1.9",
  896. "Standard (SPP)",
  897. "EPP-1.7 and SPP", /* 5 */
  898. "undefined!",
  899. "ECP and EPP-1.7" };
  900. static char *const irqtypes[] = {
  901. "pulsed low, high-Z",
  902. "follows nACK" };
  903. /* The registers are called compatible-PnP because the
  904. register layout is modelled after ISA-PnP, the access
  905. method is just another ... */
  906. outb(key, io);
  907. outb(key, io);
  908. outb(0x07, io); /* Register 7: Select Logical Device */
  909. outb(0x01, io + 1); /* LD1 is Parallel Port */
  910. outb(0x30, io);
  911. cr30 = inb(io + 1);
  912. outb(0x60, io);
  913. cr60 = inb(io + 1);
  914. outb(0x61, io);
  915. cr61 = inb(io + 1);
  916. outb(0x70, io);
  917. cr70 = inb(io + 1);
  918. outb(0x74, io);
  919. cr74 = inb(io + 1);
  920. outb(0xf0, io);
  921. crf0 = inb(io + 1);
  922. outb(0xaa, io);
  923. if (verbose_probing) {
  924. printk(KERN_INFO
  925. "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x 70=%02x 74=%02x, f0=%02x\n",
  926. cr30, cr60, cr61, cr70, cr74, crf0);
  927. printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
  928. (cr30 & 0x01) ? "yes" : "no", cr60, cr61, cr70 & 0x0f);
  929. if ((cr74 & 0x07) > 3)
  930. printk("dma=none\n");
  931. else
  932. printk("dma=%d\n", cr74 & 0x07);
  933. printk(KERN_INFO
  934. "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
  935. irqtypes[crf0>>7], (crf0>>3)&0x0f);
  936. printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n",
  937. modes[crf0 & 0x07]);
  938. }
  939. if (cr30 & 0x01) { /* the settings can be interrogated later ... */
  940. s = find_free_superio();
  941. if (s == NULL)
  942. printk(KERN_INFO "Super-IO: too many chips!\n");
  943. else {
  944. s->io = (cr60 << 8) | cr61;
  945. s->irq = cr70 & 0x0f;
  946. s->dma = (((cr74 & 0x07) > 3) ?
  947. PARPORT_DMA_NONE : (cr74 & 0x07));
  948. }
  949. }
  950. }
  951. static void decode_winbond(int efer, int key, int devid, int devrev, int oldid)
  952. {
  953. const char *type = "unknown";
  954. int id, progif = 2;
  955. if (devid == devrev)
  956. /* simple heuristics, we happened to read some
  957. non-winbond register */
  958. return;
  959. id = (devid << 8) | devrev;
  960. /* Values are from public data sheets pdf files, I can just
  961. confirm 83977TF is correct :-) */
  962. if (id == 0x9771)
  963. type = "83977F/AF";
  964. else if (id == 0x9773)
  965. type = "83977TF / SMSC 97w33x/97w34x";
  966. else if (id == 0x9774)
  967. type = "83977ATF";
  968. else if ((id & ~0x0f) == 0x5270)
  969. type = "83977CTF / SMSC 97w36x";
  970. else if ((id & ~0x0f) == 0x52f0)
  971. type = "83977EF / SMSC 97w35x";
  972. else if ((id & ~0x0f) == 0x5210)
  973. type = "83627";
  974. else if ((id & ~0x0f) == 0x6010)
  975. type = "83697HF";
  976. else if ((oldid & 0x0f) == 0x0a) {
  977. type = "83877F";
  978. progif = 1;
  979. } else if ((oldid & 0x0f) == 0x0b) {
  980. type = "83877AF";
  981. progif = 1;
  982. } else if ((oldid & 0x0f) == 0x0c) {
  983. type = "83877TF";
  984. progif = 1;
  985. } else if ((oldid & 0x0f) == 0x0d) {
  986. type = "83877ATF";
  987. progif = 1;
  988. } else
  989. progif = 0;
  990. if (verbose_probing)
  991. printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
  992. "devid=%02x devrev=%02x oldid=%02x type=%s\n",
  993. efer, key, devid, devrev, oldid, type);
  994. if (progif == 2)
  995. show_parconfig_winbond(efer, key);
  996. }
  997. static void decode_smsc(int efer, int key, int devid, int devrev)
  998. {
  999. const char *type = "unknown";
  1000. void (*func)(int io, int key);
  1001. int id;
  1002. if (devid == devrev)
  1003. /* simple heuristics, we happened to read some
  1004. non-smsc register */
  1005. return;
  1006. func = NULL;
  1007. id = (devid << 8) | devrev;
  1008. if (id == 0x0302) {
  1009. type = "37c669";
  1010. func = show_parconfig_smsc37c669;
  1011. } else if (id == 0x6582)
  1012. type = "37c665IR";
  1013. else if (devid == 0x65)
  1014. type = "37c665GT";
  1015. else if (devid == 0x66)
  1016. type = "37c666GT";
  1017. if (verbose_probing)
  1018. printk(KERN_INFO "SMSC chip at EFER=0x%x "
  1019. "key=0x%02x devid=%02x devrev=%02x type=%s\n",
  1020. efer, key, devid, devrev, type);
  1021. if (func)
  1022. func(efer, key);
  1023. }
  1024. static void winbond_check(int io, int key)
  1025. {
  1026. int origval, devid, devrev, oldid, x_devid, x_devrev, x_oldid;
  1027. if (!request_region(io, 3, __func__))
  1028. return;
  1029. origval = inb(io); /* Save original value */
  1030. /* First probe without key */
  1031. outb(0x20, io);
  1032. x_devid = inb(io + 1);
  1033. outb(0x21, io);
  1034. x_devrev = inb(io + 1);
  1035. outb(0x09, io);
  1036. x_oldid = inb(io + 1);
  1037. outb(key, io);
  1038. outb(key, io); /* Write Magic Sequence to EFER, extended
  1039. function enable register */
  1040. outb(0x20, io); /* Write EFIR, extended function index register */
  1041. devid = inb(io + 1); /* Read EFDR, extended function data register */
  1042. outb(0x21, io);
  1043. devrev = inb(io + 1);
  1044. outb(0x09, io);
  1045. oldid = inb(io + 1);
  1046. outb(0xaa, io); /* Magic Seal */
  1047. outb(origval, io); /* in case we poked some entirely different hardware */
  1048. if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
  1049. goto out; /* protection against false positives */
  1050. decode_winbond(io, key, devid, devrev, oldid);
  1051. out:
  1052. release_region(io, 3);
  1053. }
  1054. static void winbond_check2(int io, int key)
  1055. {
  1056. int origval[3], devid, devrev, oldid, x_devid, x_devrev, x_oldid;
  1057. if (!request_region(io, 3, __func__))
  1058. return;
  1059. origval[0] = inb(io); /* Save original values */
  1060. origval[1] = inb(io + 1);
  1061. origval[2] = inb(io + 2);
  1062. /* First probe without the key */
  1063. outb(0x20, io + 2);
  1064. x_devid = inb(io + 2);
  1065. outb(0x21, io + 1);
  1066. x_devrev = inb(io + 2);
  1067. outb(0x09, io + 1);
  1068. x_oldid = inb(io + 2);
  1069. outb(key, io); /* Write Magic Byte to EFER, extended
  1070. function enable register */
  1071. outb(0x20, io + 2); /* Write EFIR, extended function index register */
  1072. devid = inb(io + 2); /* Read EFDR, extended function data register */
  1073. outb(0x21, io + 1);
  1074. devrev = inb(io + 2);
  1075. outb(0x09, io + 1);
  1076. oldid = inb(io + 2);
  1077. outb(0xaa, io); /* Magic Seal */
  1078. outb(origval[0], io); /* in case we poked some entirely different hardware */
  1079. outb(origval[1], io + 1);
  1080. outb(origval[2], io + 2);
  1081. if (x_devid == devid && x_devrev == devrev && x_oldid == oldid)
  1082. goto out; /* protection against false positives */
  1083. decode_winbond(io, key, devid, devrev, oldid);
  1084. out:
  1085. release_region(io, 3);
  1086. }
  1087. static void smsc_check(int io, int key)
  1088. {
  1089. int origval, id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev;
  1090. if (!request_region(io, 3, __func__))
  1091. return;
  1092. origval = inb(io); /* Save original value */
  1093. /* First probe without the key */
  1094. outb(0x0d, io);
  1095. x_oldid = inb(io + 1);
  1096. outb(0x0e, io);
  1097. x_oldrev = inb(io + 1);
  1098. outb(0x20, io);
  1099. x_id = inb(io + 1);
  1100. outb(0x21, io);
  1101. x_rev = inb(io + 1);
  1102. outb(key, io);
  1103. outb(key, io); /* Write Magic Sequence to EFER, extended
  1104. function enable register */
  1105. outb(0x0d, io); /* Write EFIR, extended function index register */
  1106. oldid = inb(io + 1); /* Read EFDR, extended function data register */
  1107. outb(0x0e, io);
  1108. oldrev = inb(io + 1);
  1109. outb(0x20, io);
  1110. id = inb(io + 1);
  1111. outb(0x21, io);
  1112. rev = inb(io + 1);
  1113. outb(0xaa, io); /* Magic Seal */
  1114. outb(origval, io); /* in case we poked some entirely different hardware */
  1115. if (x_id == id && x_oldrev == oldrev &&
  1116. x_oldid == oldid && x_rev == rev)
  1117. goto out; /* protection against false positives */
  1118. decode_smsc(io, key, oldid, oldrev);
  1119. out:
  1120. release_region(io, 3);
  1121. }
  1122. static void detect_and_report_winbond(void)
  1123. {
  1124. if (verbose_probing)
  1125. printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
  1126. winbond_check(0x3f0, 0x87);
  1127. winbond_check(0x370, 0x87);
  1128. winbond_check(0x2e , 0x87);
  1129. winbond_check(0x4e , 0x87);
  1130. winbond_check(0x3f0, 0x86);
  1131. winbond_check2(0x250, 0x88);
  1132. winbond_check2(0x250, 0x89);
  1133. }
  1134. static void detect_and_report_smsc(void)
  1135. {
  1136. if (verbose_probing)
  1137. printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
  1138. smsc_check(0x3f0, 0x55);
  1139. smsc_check(0x370, 0x55);
  1140. smsc_check(0x3f0, 0x44);
  1141. smsc_check(0x370, 0x44);
  1142. }
  1143. static void detect_and_report_it87(void)
  1144. {
  1145. u16 dev;
  1146. u8 origval, r;
  1147. if (verbose_probing)
  1148. printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...\n");
  1149. if (!request_muxed_region(0x2e, 2, __func__))
  1150. return;
  1151. origval = inb(0x2e); /* Save original value */
  1152. outb(0x87, 0x2e);
  1153. outb(0x01, 0x2e);
  1154. outb(0x55, 0x2e);
  1155. outb(0x55, 0x2e);
  1156. outb(0x20, 0x2e);
  1157. dev = inb(0x2f) << 8;
  1158. outb(0x21, 0x2e);
  1159. dev |= inb(0x2f);
  1160. if (dev == 0x8712 || dev == 0x8705 || dev == 0x8715 ||
  1161. dev == 0x8716 || dev == 0x8718 || dev == 0x8726) {
  1162. printk(KERN_INFO "IT%04X SuperIO detected.\n", dev);
  1163. outb(0x07, 0x2E); /* Parallel Port */
  1164. outb(0x03, 0x2F);
  1165. outb(0xF0, 0x2E); /* BOOT 0x80 off */
  1166. r = inb(0x2f);
  1167. outb(0xF0, 0x2E);
  1168. outb(r | 8, 0x2F);
  1169. outb(0x02, 0x2E); /* Lock */
  1170. outb(0x02, 0x2F);
  1171. } else {
  1172. outb(origval, 0x2e); /* Oops, sorry to disturb */
  1173. }
  1174. release_region(0x2e, 2);
  1175. }
  1176. #endif /* CONFIG_PARPORT_PC_SUPERIO */
  1177. static struct superio_struct *find_superio(struct parport *p)
  1178. {
  1179. int i;
  1180. for (i = 0; i < NR_SUPERIOS; i++)
  1181. if (superios[i].io == p->base)
  1182. return &superios[i];
  1183. return NULL;
  1184. }
  1185. static int get_superio_dma(struct parport *p)
  1186. {
  1187. struct superio_struct *s = find_superio(p);
  1188. if (s)
  1189. return s->dma;
  1190. return PARPORT_DMA_NONE;
  1191. }
  1192. static int get_superio_irq(struct parport *p)
  1193. {
  1194. struct superio_struct *s = find_superio(p);
  1195. if (s)
  1196. return s->irq;
  1197. return PARPORT_IRQ_NONE;
  1198. }
  1199. /* --- Mode detection ------------------------------------- */
  1200. /*
  1201. * Checks for port existence, all ports support SPP MODE
  1202. * Returns:
  1203. * 0 : No parallel port at this address
  1204. * PARPORT_MODE_PCSPP : SPP port detected
  1205. * (if the user specified an ioport himself,
  1206. * this shall always be the case!)
  1207. *
  1208. */
  1209. static int parport_SPP_supported(struct parport *pb)
  1210. {
  1211. unsigned char r, w;
  1212. /*
  1213. * first clear an eventually pending EPP timeout
  1214. * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
  1215. * that does not even respond to SPP cycles if an EPP
  1216. * timeout is pending
  1217. */
  1218. clear_epp_timeout(pb);
  1219. /* Do a simple read-write test to make sure the port exists. */
  1220. w = 0xc;
  1221. outb(w, CONTROL(pb));
  1222. /* Is there a control register that we can read from? Some
  1223. * ports don't allow reads, so read_control just returns a
  1224. * software copy. Some ports _do_ allow reads, so bypass the
  1225. * software copy here. In addition, some bits aren't
  1226. * writable. */
  1227. r = inb(CONTROL(pb));
  1228. if ((r & 0xf) == w) {
  1229. w = 0xe;
  1230. outb(w, CONTROL(pb));
  1231. r = inb(CONTROL(pb));
  1232. outb(0xc, CONTROL(pb));
  1233. if ((r & 0xf) == w)
  1234. return PARPORT_MODE_PCSPP;
  1235. }
  1236. if (user_specified)
  1237. /* That didn't work, but the user thinks there's a
  1238. * port here. */
  1239. printk(KERN_INFO "parport 0x%lx (WARNING): CTR: "
  1240. "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
  1241. /* Try the data register. The data lines aren't tri-stated at
  1242. * this stage, so we expect back what we wrote. */
  1243. w = 0xaa;
  1244. parport_pc_write_data(pb, w);
  1245. r = parport_pc_read_data(pb);
  1246. if (r == w) {
  1247. w = 0x55;
  1248. parport_pc_write_data(pb, w);
  1249. r = parport_pc_read_data(pb);
  1250. if (r == w)
  1251. return PARPORT_MODE_PCSPP;
  1252. }
  1253. if (user_specified) {
  1254. /* Didn't work, but the user is convinced this is the
  1255. * place. */
  1256. printk(KERN_INFO "parport 0x%lx (WARNING): DATA: "
  1257. "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
  1258. printk(KERN_INFO "parport 0x%lx: You gave this address, "
  1259. "but there is probably no parallel port there!\n",
  1260. pb->base);
  1261. }
  1262. /* It's possible that we can't read the control register or
  1263. * the data register. In that case just believe the user. */
  1264. if (user_specified)
  1265. return PARPORT_MODE_PCSPP;
  1266. return 0;
  1267. }
  1268. /* Check for ECR
  1269. *
  1270. * Old style XT ports alias io ports every 0x400, hence accessing ECR
  1271. * on these cards actually accesses the CTR.
  1272. *
  1273. * Modern cards don't do this but reading from ECR will return 0xff
  1274. * regardless of what is written here if the card does NOT support
  1275. * ECP.
  1276. *
  1277. * We first check to see if ECR is the same as CTR. If not, the low
  1278. * two bits of ECR aren't writable, so we check by writing ECR and
  1279. * reading it back to see if it's what we expect.
  1280. */
  1281. static int parport_ECR_present(struct parport *pb)
  1282. {
  1283. struct parport_pc_private *priv = pb->private_data;
  1284. unsigned char r = 0xc;
  1285. outb(r, CONTROL(pb));
  1286. if ((inb(ECONTROL(pb)) & 0x3) == (r & 0x3)) {
  1287. outb(r ^ 0x2, CONTROL(pb)); /* Toggle bit 1 */
  1288. r = inb(CONTROL(pb));
  1289. if ((inb(ECONTROL(pb)) & 0x2) == (r & 0x2))
  1290. goto no_reg; /* Sure that no ECR register exists */
  1291. }
  1292. if ((inb(ECONTROL(pb)) & 0x3) != 0x1)
  1293. goto no_reg;
  1294. ECR_WRITE(pb, 0x34);
  1295. if (inb(ECONTROL(pb)) != 0x35)
  1296. goto no_reg;
  1297. priv->ecr = 1;
  1298. outb(0xc, CONTROL(pb));
  1299. /* Go to mode 000 */
  1300. frob_set_mode(pb, ECR_SPP);
  1301. return 1;
  1302. no_reg:
  1303. outb(0xc, CONTROL(pb));
  1304. return 0;
  1305. }
  1306. #ifdef CONFIG_PARPORT_1284
  1307. /* Detect PS/2 support.
  1308. *
  1309. * Bit 5 (0x20) sets the PS/2 data direction; setting this high
  1310. * allows us to read data from the data lines. In theory we would get back
  1311. * 0xff but any peripheral attached to the port may drag some or all of the
  1312. * lines down to zero. So if we get back anything that isn't the contents
  1313. * of the data register we deem PS/2 support to be present.
  1314. *
  1315. * Some SPP ports have "half PS/2" ability - you can't turn off the line
  1316. * drivers, but an external peripheral with sufficiently beefy drivers of
  1317. * its own can overpower them and assert its own levels onto the bus, from
  1318. * where they can then be read back as normal. Ports with this property
  1319. * and the right type of device attached are likely to fail the SPP test,
  1320. * (as they will appear to have stuck bits) and so the fact that they might
  1321. * be misdetected here is rather academic.
  1322. */
  1323. static int parport_PS2_supported(struct parport *pb)
  1324. {
  1325. int ok = 0;
  1326. clear_epp_timeout(pb);
  1327. /* try to tri-state the buffer */
  1328. parport_pc_data_reverse(pb);
  1329. parport_pc_write_data(pb, 0x55);
  1330. if (parport_pc_read_data(pb) != 0x55)
  1331. ok++;
  1332. parport_pc_write_data(pb, 0xaa);
  1333. if (parport_pc_read_data(pb) != 0xaa)
  1334. ok++;
  1335. /* cancel input mode */
  1336. parport_pc_data_forward(pb);
  1337. if (ok) {
  1338. pb->modes |= PARPORT_MODE_TRISTATE;
  1339. } else {
  1340. struct parport_pc_private *priv = pb->private_data;
  1341. priv->ctr_writable &= ~0x20;
  1342. }
  1343. return ok;
  1344. }
  1345. #ifdef CONFIG_PARPORT_PC_FIFO
  1346. static int parport_ECP_supported(struct parport *pb)
  1347. {
  1348. int i;
  1349. int config, configb;
  1350. int pword;
  1351. struct parport_pc_private *priv = pb->private_data;
  1352. /* Translate ECP intrLine to ISA irq value */
  1353. static const int intrline[] = { 0, 7, 9, 10, 11, 14, 15, 5 };
  1354. /* If there is no ECR, we have no hope of supporting ECP. */
  1355. if (!priv->ecr)
  1356. return 0;
  1357. /* Find out FIFO depth */
  1358. ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
  1359. ECR_WRITE(pb, ECR_TST << 5); /* TEST FIFO */
  1360. for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02); i++)
  1361. outb(0xaa, FIFO(pb));
  1362. /*
  1363. * Using LGS chipset it uses ECR register, but
  1364. * it doesn't support ECP or FIFO MODE
  1365. */
  1366. if (i == 1024) {
  1367. ECR_WRITE(pb, ECR_SPP << 5);
  1368. return 0;
  1369. }
  1370. priv->fifo_depth = i;
  1371. if (verbose_probing)
  1372. printk(KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i);
  1373. /* Find out writeIntrThreshold */
  1374. frob_econtrol(pb, 1<<2, 1<<2);
  1375. frob_econtrol(pb, 1<<2, 0);
  1376. for (i = 1; i <= priv->fifo_depth; i++) {
  1377. inb(FIFO(pb));
  1378. udelay(50);
  1379. if (inb(ECONTROL(pb)) & (1<<2))
  1380. break;
  1381. }
  1382. if (i <= priv->fifo_depth) {
  1383. if (verbose_probing)
  1384. printk(KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n",
  1385. pb->base, i);
  1386. } else
  1387. /* Number of bytes we know we can write if we get an
  1388. interrupt. */
  1389. i = 0;
  1390. priv->writeIntrThreshold = i;
  1391. /* Find out readIntrThreshold */
  1392. frob_set_mode(pb, ECR_PS2); /* Reset FIFO and enable PS2 */
  1393. parport_pc_data_reverse(pb); /* Must be in PS2 mode */
  1394. frob_set_mode(pb, ECR_TST); /* Test FIFO */
  1395. frob_econtrol(pb, 1<<2, 1<<2);
  1396. frob_econtrol(pb, 1<<2, 0);
  1397. for (i = 1; i <= priv->fifo_depth; i++) {
  1398. outb(0xaa, FIFO(pb));
  1399. if (inb(ECONTROL(pb)) & (1<<2))
  1400. break;
  1401. }
  1402. if (i <= priv->fifo_depth) {
  1403. if (verbose_probing)
  1404. printk(KERN_INFO "0x%lx: readIntrThreshold is %d\n",
  1405. pb->base, i);
  1406. } else
  1407. /* Number of bytes we can read if we get an interrupt. */
  1408. i = 0;
  1409. priv->readIntrThreshold = i;
  1410. ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
  1411. ECR_WRITE(pb, 0xf4); /* Configuration mode */
  1412. config = inb(CONFIGA(pb));
  1413. pword = (config >> 4) & 0x7;
  1414. switch (pword) {
  1415. case 0:
  1416. pword = 2;
  1417. printk(KERN_WARNING "0x%lx: Unsupported pword size!\n",
  1418. pb->base);
  1419. break;
  1420. case 2:
  1421. pword = 4;
  1422. printk(KERN_WARNING "0x%lx: Unsupported pword size!\n",
  1423. pb->base);
  1424. break;
  1425. default:
  1426. printk(KERN_WARNING "0x%lx: Unknown implementation ID\n",
  1427. pb->base);
  1428. /* Assume 1 */
  1429. case 1:
  1430. pword = 1;
  1431. }
  1432. priv->pword = pword;
  1433. if (verbose_probing) {
  1434. printk(KERN_DEBUG "0x%lx: PWord is %d bits\n",
  1435. pb->base, 8 * pword);
  1436. printk(KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
  1437. config & 0x80 ? "Level" : "Pulses");
  1438. configb = inb(CONFIGB(pb));
  1439. printk(KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
  1440. pb->base, config, configb);
  1441. printk(KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
  1442. if ((configb >> 3) & 0x07)
  1443. printk("%d", intrline[(configb >> 3) & 0x07]);
  1444. else
  1445. printk("<none or set by other means>");
  1446. printk(" dma=");
  1447. if ((configb & 0x03) == 0x00)
  1448. printk("<none or set by other means>\n");
  1449. else
  1450. printk("%d\n", configb & 0x07);
  1451. }
  1452. /* Go back to mode 000 */
  1453. frob_set_mode(pb, ECR_SPP);
  1454. return 1;
  1455. }
  1456. #endif
  1457. #ifdef CONFIG_X86_32
  1458. static int intel_bug_present_check_epp(struct parport *pb)
  1459. {
  1460. const struct parport_pc_private *priv = pb->private_data;
  1461. int bug_present = 0;
  1462. if (priv->ecr) {
  1463. /* store value of ECR */
  1464. unsigned char ecr = inb(ECONTROL(pb));
  1465. unsigned char i;
  1466. for (i = 0x00; i < 0x80; i += 0x20) {
  1467. ECR_WRITE(pb, i);
  1468. if (clear_epp_timeout(pb)) {
  1469. /* Phony EPP in ECP. */
  1470. bug_present = 1;
  1471. break;
  1472. }
  1473. }
  1474. /* return ECR into the inital state */
  1475. ECR_WRITE(pb, ecr);
  1476. }
  1477. return bug_present;
  1478. }
  1479. static int intel_bug_present(struct parport *pb)
  1480. {
  1481. /* Check whether the device is legacy, not PCI or PCMCIA. Only legacy is known to be affected. */
  1482. if (pb->dev != NULL) {
  1483. return 0;
  1484. }
  1485. return intel_bug_present_check_epp(pb);
  1486. }
  1487. #else
  1488. static int intel_bug_present(struct parport *pb)
  1489. {
  1490. return 0;
  1491. }
  1492. #endif /* CONFIG_X86_32 */
  1493. static int parport_ECPPS2_supported(struct parport *pb)
  1494. {
  1495. const struct parport_pc_private *priv = pb->private_data;
  1496. int result;
  1497. unsigned char oecr;
  1498. if (!priv->ecr)
  1499. return 0;
  1500. oecr = inb(ECONTROL(pb));
  1501. ECR_WRITE(pb, ECR_PS2 << 5);
  1502. result = parport_PS2_supported(pb);
  1503. ECR_WRITE(pb, oecr);
  1504. return result;
  1505. }
  1506. /* EPP mode detection */
  1507. static int parport_EPP_supported(struct parport *pb)
  1508. {
  1509. /*
  1510. * Theory:
  1511. * Bit 0 of STR is the EPP timeout bit, this bit is 0
  1512. * when EPP is possible and is set high when an EPP timeout
  1513. * occurs (EPP uses the HALT line to stop the CPU while it does
  1514. * the byte transfer, an EPP timeout occurs if the attached
  1515. * device fails to respond after 10 micro seconds).
  1516. *
  1517. * This bit is cleared by either reading it (National Semi)
  1518. * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
  1519. * This bit is always high in non EPP modes.
  1520. */
  1521. /* If EPP timeout bit clear then EPP available */
  1522. if (!clear_epp_timeout(pb))
  1523. return 0; /* No way to clear timeout */
  1524. /* Check for Intel bug. */
  1525. if (intel_bug_present(pb))
  1526. return 0;
  1527. pb->modes |= PARPORT_MODE_EPP;
  1528. /* Set up access functions to use EPP hardware. */
  1529. pb->ops->epp_read_data = parport_pc_epp_read_data;
  1530. pb->ops->epp_write_data = parport_pc_epp_write_data;
  1531. pb->ops->epp_read_addr = parport_pc_epp_read_addr;
  1532. pb->ops->epp_write_addr = parport_pc_epp_write_addr;
  1533. return 1;
  1534. }
  1535. static int parport_ECPEPP_supported(struct parport *pb)
  1536. {
  1537. struct parport_pc_private *priv = pb->private_data;
  1538. int result;
  1539. unsigned char oecr;
  1540. if (!priv->ecr)
  1541. return 0;
  1542. oecr = inb(ECONTROL(pb));
  1543. /* Search for SMC style EPP+ECP mode */
  1544. ECR_WRITE(pb, 0x80);
  1545. outb(0x04, CONTROL(pb));
  1546. result = parport_EPP_supported(pb);
  1547. ECR_WRITE(pb, oecr);
  1548. if (result) {
  1549. /* Set up access functions to use ECP+EPP hardware. */
  1550. pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
  1551. pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
  1552. pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
  1553. pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
  1554. }
  1555. return result;
  1556. }
  1557. #else /* No IEEE 1284 support */
  1558. /* Don't bother probing for modes we know we won't use. */
  1559. static int parport_PS2_supported(struct parport *pb) { return 0; }
  1560. #ifdef CONFIG_PARPORT_PC_FIFO
  1561. static int parport_ECP_supported(struct parport *pb)
  1562. {
  1563. return 0;
  1564. }
  1565. #endif
  1566. static int parport_EPP_supported(struct parport *pb)
  1567. {
  1568. return 0;
  1569. }
  1570. static int parport_ECPEPP_supported(struct parport *pb)
  1571. {
  1572. return 0;
  1573. }
  1574. static int parport_ECPPS2_supported(struct parport *pb)
  1575. {
  1576. return 0;
  1577. }
  1578. #endif /* No IEEE 1284 support */
  1579. /* --- IRQ detection -------------------------------------- */
  1580. /* Only if supports ECP mode */
  1581. static int programmable_irq_support(struct parport *pb)
  1582. {
  1583. int irq, intrLine;
  1584. unsigned char oecr = inb(ECONTROL(pb));
  1585. static const int lookup[8] = {
  1586. PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
  1587. };
  1588. ECR_WRITE(pb, ECR_CNF << 5); /* Configuration MODE */
  1589. intrLine = (inb(CONFIGB(pb)) >> 3) & 0x07;
  1590. irq = lookup[intrLine];
  1591. ECR_WRITE(pb, oecr);
  1592. return irq;
  1593. }
  1594. static int irq_probe_ECP(struct parport *pb)
  1595. {
  1596. int i;
  1597. unsigned long irqs;
  1598. irqs = probe_irq_on();
  1599. ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
  1600. ECR_WRITE(pb, (ECR_TST << 5) | 0x04);
  1601. ECR_WRITE(pb, ECR_TST << 5);
  1602. /* If Full FIFO sure that writeIntrThreshold is generated */
  1603. for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02) ; i++)
  1604. outb(0xaa, FIFO(pb));
  1605. pb->irq = probe_irq_off(irqs);
  1606. ECR_WRITE(pb, ECR_SPP << 5);
  1607. if (pb->irq <= 0)
  1608. pb->irq = PARPORT_IRQ_NONE;
  1609. return pb->irq;
  1610. }
  1611. /*
  1612. * This detection seems that only works in National Semiconductors
  1613. * This doesn't work in SMC, LGS, and Winbond
  1614. */
  1615. static int irq_probe_EPP(struct parport *pb)
  1616. {
  1617. #ifndef ADVANCED_DETECT
  1618. return PARPORT_IRQ_NONE;
  1619. #else
  1620. int irqs;
  1621. unsigned char oecr;
  1622. if (pb->modes & PARPORT_MODE_PCECR)
  1623. oecr = inb(ECONTROL(pb));
  1624. irqs = probe_irq_on();
  1625. if (pb->modes & PARPORT_MODE_PCECR)
  1626. frob_econtrol(pb, 0x10, 0x10);
  1627. clear_epp_timeout(pb);
  1628. parport_pc_frob_control(pb, 0x20, 0x20);
  1629. parport_pc_frob_control(pb, 0x10, 0x10);
  1630. clear_epp_timeout(pb);
  1631. /* Device isn't expecting an EPP read
  1632. * and generates an IRQ.
  1633. */
  1634. parport_pc_read_epp(pb);
  1635. udelay(20);
  1636. pb->irq = probe_irq_off(irqs);
  1637. if (pb->modes & PARPORT_MODE_PCECR)
  1638. ECR_WRITE(pb, oecr);
  1639. parport_pc_write_control(pb, 0xc);
  1640. if (pb->irq <= 0)
  1641. pb->irq = PARPORT_IRQ_NONE;
  1642. return pb->irq;
  1643. #endif /* Advanced detection */
  1644. }
  1645. static int irq_probe_SPP(struct parport *pb)
  1646. {
  1647. /* Don't even try to do this. */
  1648. return PARPORT_IRQ_NONE;
  1649. }
  1650. /* We will attempt to share interrupt requests since other devices
  1651. * such as sound cards and network cards seem to like using the
  1652. * printer IRQs.
  1653. *
  1654. * When ECP is available we can autoprobe for IRQs.
  1655. * NOTE: If we can autoprobe it, we can register the IRQ.
  1656. */
  1657. static int parport_irq_probe(struct parport *pb)
  1658. {
  1659. struct parport_pc_private *priv = pb->private_data;
  1660. if (priv->ecr) {
  1661. pb->irq = programmable_irq_support(pb);
  1662. if (pb->irq == PARPORT_IRQ_NONE)
  1663. pb->irq = irq_probe_ECP(pb);
  1664. }
  1665. if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr &&
  1666. (pb->modes & PARPORT_MODE_EPP))
  1667. pb->irq = irq_probe_EPP(pb);
  1668. clear_epp_timeout(pb);
  1669. if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
  1670. pb->irq = irq_probe_EPP(pb);
  1671. clear_epp_timeout(pb);
  1672. if (pb->irq == PARPORT_IRQ_NONE)
  1673. pb->irq = irq_probe_SPP(pb);
  1674. if (pb->irq == PARPORT_IRQ_NONE)
  1675. pb->irq = get_superio_irq(pb);
  1676. return pb->irq;
  1677. }
  1678. /* --- DMA detection -------------------------------------- */
  1679. /* Only if chipset conforms to ECP ISA Interface Standard */
  1680. static int programmable_dma_support(struct parport *p)
  1681. {
  1682. unsigned char oecr = inb(ECONTROL(p));
  1683. int dma;
  1684. frob_set_mode(p, ECR_CNF);
  1685. dma = inb(CONFIGB(p)) & 0x07;
  1686. /* 000: Indicates jumpered 8-bit DMA if read-only.
  1687. 100: Indicates jumpered 16-bit DMA if read-only. */
  1688. if ((dma & 0x03) == 0)
  1689. dma = PARPORT_DMA_NONE;
  1690. ECR_WRITE(p, oecr);
  1691. return dma;
  1692. }
  1693. static int parport_dma_probe(struct parport *p)
  1694. {
  1695. const struct parport_pc_private *priv = p->private_data;
  1696. if (priv->ecr) /* ask ECP chipset first */
  1697. p->dma = programmable_dma_support(p);
  1698. if (p->dma == PARPORT_DMA_NONE) {
  1699. /* ask known Super-IO chips proper, although these
  1700. claim ECP compatible, some don't report their DMA
  1701. conforming to ECP standards */
  1702. p->dma = get_superio_dma(p);
  1703. }
  1704. return p->dma;
  1705. }
  1706. /* --- Initialisation code -------------------------------- */
  1707. static LIST_HEAD(ports_list);
  1708. static DEFINE_SPINLOCK(ports_lock);
  1709. struct parport *parport_pc_probe_port(unsigned long int base,
  1710. unsigned long int base_hi,
  1711. int irq, int dma,
  1712. struct device *dev,
  1713. int irqflags)
  1714. {
  1715. struct parport_pc_private *priv;
  1716. struct parport_operations *ops;
  1717. struct parport *p;
  1718. int probedirq = PARPORT_IRQ_NONE;
  1719. struct resource *base_res;
  1720. struct resource *ECR_res = NULL;
  1721. struct resource *EPP_res = NULL;
  1722. struct platform_device *pdev = NULL;
  1723. int ret;
  1724. if (!dev) {
  1725. /* We need a physical device to attach to, but none was
  1726. * provided. Create our own. */
  1727. pdev = platform_device_register_simple("parport_pc",
  1728. base, NULL, 0);
  1729. if (IS_ERR(pdev))
  1730. return NULL;
  1731. dev = &pdev->dev;
  1732. ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(24));
  1733. if (ret) {
  1734. dev_err(dev, "Unable to set coherent dma mask: disabling DMA\n");
  1735. dma = PARPORT_DMA_NONE;
  1736. }
  1737. }
  1738. ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
  1739. if (!ops)
  1740. goto out1;
  1741. priv = kmalloc(sizeof(struct parport_pc_private), GFP_KERNEL);
  1742. if (!priv)
  1743. goto out2;
  1744. /* a misnomer, actually - it's allocate and reserve parport number */
  1745. p = parport_register_port(base, irq, dma, ops);
  1746. if (!p)
  1747. goto out3;
  1748. base_res = request_region(base, 3, p->name);
  1749. if (!base_res)
  1750. goto out4;
  1751. memcpy(ops, &parport_pc_ops, sizeof(struct parport_operations));
  1752. priv->ctr = 0xc;
  1753. priv->ctr_writable = ~0x10;
  1754. priv->ecr = 0;
  1755. priv->fifo_depth = 0;
  1756. priv->dma_buf = NULL;
  1757. priv->dma_handle = 0;
  1758. INIT_LIST_HEAD(&priv->list);
  1759. priv->port = p;
  1760. p->dev = dev;
  1761. p->base_hi = base_hi;
  1762. p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
  1763. p->private_data = priv;
  1764. if (base_hi) {
  1765. ECR_res = request_region(base_hi, 3, p->name);
  1766. if (ECR_res)
  1767. parport_ECR_present(p);
  1768. }
  1769. if (base != 0x3bc) {
  1770. EPP_res = request_region(base+0x3, 5, p->name);
  1771. if (EPP_res)
  1772. if (!parport_EPP_supported(p))
  1773. parport_ECPEPP_supported(p);
  1774. }
  1775. if (!parport_SPP_supported(p))
  1776. /* No port. */
  1777. goto out5;
  1778. if (priv->ecr)
  1779. parport_ECPPS2_supported(p);
  1780. else
  1781. parport_PS2_supported(p);
  1782. p->size = (p->modes & PARPORT_MODE_EPP) ? 8 : 3;
  1783. printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
  1784. if (p->base_hi && priv->ecr)
  1785. printk(KERN_CONT " (0x%lx)", p->base_hi);
  1786. if (p->irq == PARPORT_IRQ_AUTO) {
  1787. p->irq = PARPORT_IRQ_NONE;
  1788. parport_irq_probe(p);
  1789. } else if (p->irq == PARPORT_IRQ_PROBEONLY) {
  1790. p->irq = PARPORT_IRQ_NONE;
  1791. parport_irq_probe(p);
  1792. probedirq = p->irq;
  1793. p->irq = PARPORT_IRQ_NONE;
  1794. }
  1795. if (p->irq != PARPORT_IRQ_NONE) {
  1796. printk(KERN_CONT ", irq %d", p->irq);
  1797. priv->ctr_writable |= 0x10;
  1798. if (p->dma == PARPORT_DMA_AUTO) {
  1799. p->dma = PARPORT_DMA_NONE;
  1800. parport_dma_probe(p);
  1801. }
  1802. }
  1803. if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
  1804. is mandatory (see above) */
  1805. p->dma = PARPORT_DMA_NONE;
  1806. #ifdef CONFIG_PARPORT_PC_FIFO
  1807. if (parport_ECP_supported(p) &&
  1808. p->dma != PARPORT_DMA_NOFIFO &&
  1809. priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
  1810. p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
  1811. p->ops->compat_write_data = parport_pc_compat_write_block_pio;
  1812. #ifdef CONFIG_PARPORT_1284
  1813. p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
  1814. /* currently broken, but working on it.. (FB) */
  1815. /* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */
  1816. #endif /* IEEE 1284 support */
  1817. if (p->dma != PARPORT_DMA_NONE) {
  1818. printk(KERN_CONT ", dma %d", p->dma);
  1819. p->modes |= PARPORT_MODE_DMA;
  1820. } else
  1821. printk(KERN_CONT ", using FIFO");
  1822. } else
  1823. /* We can't use the DMA channel after all. */
  1824. p->dma = PARPORT_DMA_NONE;
  1825. #endif /* Allowed to use FIFO/DMA */
  1826. printk(KERN_CONT " [");
  1827. #define printmode(x) \
  1828. {\
  1829. if (p->modes & PARPORT_MODE_##x) {\
  1830. printk(KERN_CONT "%s%s", f ? "," : "", #x);\
  1831. f++;\
  1832. } \
  1833. }
  1834. {
  1835. int f = 0;
  1836. printmode(PCSPP);
  1837. printmode(TRISTATE);
  1838. printmode(COMPAT)
  1839. printmode(EPP);
  1840. printmode(ECP);
  1841. printmode(DMA);
  1842. }
  1843. #undef printmode
  1844. #ifndef CONFIG_PARPORT_1284
  1845. printk(KERN_CONT "(,...)");
  1846. #endif /* CONFIG_PARPORT_1284 */
  1847. printk(KERN_CONT "]\n");
  1848. if (probedirq != PARPORT_IRQ_NONE)
  1849. printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
  1850. /* If No ECP release the ports grabbed above. */
  1851. if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) {
  1852. release_region(base_hi, 3);
  1853. ECR_res = NULL;
  1854. }
  1855. /* Likewise for EEP ports */
  1856. if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) {
  1857. release_region(base+3, 5);
  1858. EPP_res = NULL;
  1859. }
  1860. if (p->irq != PARPORT_IRQ_NONE) {
  1861. if (request_irq(p->irq, parport_irq_handler,
  1862. irqflags, p->name, p)) {
  1863. printk(KERN_WARNING "%s: irq %d in use, "
  1864. "resorting to polled operation\n",
  1865. p->name, p->irq);
  1866. p->irq = PARPORT_IRQ_NONE;
  1867. p->dma = PARPORT_DMA_NONE;
  1868. }
  1869. #ifdef CONFIG_PARPORT_PC_FIFO
  1870. #ifdef HAS_DMA
  1871. if (p->dma != PARPORT_DMA_NONE) {
  1872. if (request_dma(p->dma, p->name)) {
  1873. printk(KERN_WARNING "%s: dma %d in use, "
  1874. "resorting to PIO operation\n",
  1875. p->name, p->dma);
  1876. p->dma = PARPORT_DMA_NONE;
  1877. } else {
  1878. priv->dma_buf =
  1879. dma_alloc_coherent(dev,
  1880. PAGE_SIZE,
  1881. &priv->dma_handle,
  1882. GFP_KERNEL);
  1883. if (!priv->dma_buf) {
  1884. printk(KERN_WARNING "%s: "
  1885. "cannot get buffer for DMA, "
  1886. "resorting to PIO operation\n",
  1887. p->name);
  1888. free_dma(p->dma);
  1889. p->dma = PARPORT_DMA_NONE;
  1890. }
  1891. }
  1892. }
  1893. #endif
  1894. #endif
  1895. }
  1896. /* Done probing. Now put the port into a sensible start-up state. */
  1897. if (priv->ecr)
  1898. /*
  1899. * Put the ECP detected port in PS2 mode.
  1900. * Do this also for ports that have ECR but don't do ECP.
  1901. */
  1902. ECR_WRITE(p, 0x34);
  1903. parport_pc_write_data(p, 0);
  1904. parport_pc_data_forward(p);
  1905. /* Now that we've told the sharing engine about the port, and
  1906. found out its characteristics, let the high-level drivers
  1907. know about it. */
  1908. spin_lock(&ports_lock);
  1909. list_add(&priv->list, &ports_list);
  1910. spin_unlock(&ports_lock);
  1911. parport_announce_port(p);
  1912. return p;
  1913. out5:
  1914. if (ECR_res)
  1915. release_region(base_hi, 3);
  1916. if (EPP_res)
  1917. release_region(base+0x3, 5);
  1918. release_region(base, 3);
  1919. out4:
  1920. parport_del_port(p);
  1921. out3:
  1922. kfree(priv);
  1923. out2:
  1924. kfree(ops);
  1925. out1:
  1926. if (pdev)
  1927. platform_device_unregister(pdev);
  1928. return NULL;
  1929. }
  1930. EXPORT_SYMBOL(parport_pc_probe_port);
  1931. void parport_pc_unregister_port(struct parport *p)
  1932. {
  1933. struct parport_pc_private *priv = p->private_data;
  1934. struct parport_operations *ops = p->ops;
  1935. parport_remove_port(p);
  1936. spin_lock(&ports_lock);
  1937. list_del_init(&priv->list);
  1938. spin_unlock(&ports_lock);
  1939. #if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
  1940. if (p->dma != PARPORT_DMA_NONE)
  1941. free_dma(p->dma);
  1942. #endif
  1943. if (p->irq != PARPORT_IRQ_NONE)
  1944. free_irq(p->irq, p);
  1945. release_region(p->base, 3);
  1946. if (p->size > 3)
  1947. release_region(p->base + 3, p->size - 3);
  1948. if (p->modes & PARPORT_MODE_ECP)
  1949. release_region(p->base_hi, 3);
  1950. #if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
  1951. if (priv->dma_buf)
  1952. dma_free_coherent(p->physport->dev, PAGE_SIZE,
  1953. priv->dma_buf,
  1954. priv->dma_handle);
  1955. #endif
  1956. kfree(p->private_data);
  1957. parport_del_port(p);
  1958. kfree(ops); /* hope no-one cached it */
  1959. }
  1960. EXPORT_SYMBOL(parport_pc_unregister_port);
  1961. #ifdef CONFIG_PCI
  1962. /* ITE support maintained by Rich Liu <richliu@poorman.org> */
  1963. static int sio_ite_8872_probe(struct pci_dev *pdev, int autoirq, int autodma,
  1964. const struct parport_pc_via_data *via)
  1965. {
  1966. short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
  1967. u32 ite8872set;
  1968. u32 ite8872_lpt, ite8872_lpthi;
  1969. u8 ite8872_irq, type;
  1970. int irq;
  1971. int i;
  1972. DPRINTK(KERN_DEBUG "sio_ite_8872_probe()\n");
  1973. /* make sure which one chip */
  1974. for (i = 0; i < 5; i++) {
  1975. if (request_region(inta_addr[i], 32, "it887x")) {
  1976. int test;
  1977. pci_write_config_dword(pdev, 0x60,
  1978. 0xe5000000 | inta_addr[i]);
  1979. pci_write_config_dword(pdev, 0x78,
  1980. 0x00000000 | inta_addr[i]);
  1981. test = inb(inta_addr[i]);
  1982. if (test != 0xff)
  1983. break;
  1984. release_region(inta_addr[i], 32);
  1985. }
  1986. }
  1987. if (i >= 5) {
  1988. printk(KERN_INFO "parport_pc: cannot find ITE8872 INTA\n");
  1989. return 0;
  1990. }
  1991. type = inb(inta_addr[i] + 0x18);
  1992. type &= 0x0f;
  1993. switch (type) {
  1994. case 0x2:
  1995. printk(KERN_INFO "parport_pc: ITE8871 found (1P)\n");
  1996. ite8872set = 0x64200000;
  1997. break;
  1998. case 0xa:
  1999. printk(KERN_INFO "parport_pc: ITE8875 found (1P)\n");
  2000. ite8872set = 0x64200000;
  2001. break;
  2002. case 0xe:
  2003. printk(KERN_INFO "parport_pc: ITE8872 found (2S1P)\n");
  2004. ite8872set = 0x64e00000;
  2005. break;
  2006. case 0x6:
  2007. printk(KERN_INFO "parport_pc: ITE8873 found (1S)\n");
  2008. release_region(inta_addr[i], 32);
  2009. return 0;
  2010. case 0x8:
  2011. printk(KERN_INFO "parport_pc: ITE8874 found (2S)\n");
  2012. release_region(inta_addr[i], 32);
  2013. return 0;
  2014. default:
  2015. printk(KERN_INFO "parport_pc: unknown ITE887x\n");
  2016. printk(KERN_INFO "parport_pc: please mail 'lspci -nvv' "
  2017. "output to Rich.Liu@ite.com.tw\n");
  2018. release_region(inta_addr[i], 32);
  2019. return 0;
  2020. }
  2021. pci_read_config_byte(pdev, 0x3c, &ite8872_irq);
  2022. pci_read_config_dword(pdev, 0x1c, &ite8872_lpt);
  2023. ite8872_lpt &= 0x0000ff00;
  2024. pci_read_config_dword(pdev, 0x20, &ite8872_lpthi);
  2025. ite8872_lpthi &= 0x0000ff00;
  2026. pci_write_config_dword(pdev, 0x6c, 0xe3000000 | ite8872_lpt);
  2027. pci_write_config_dword(pdev, 0x70, 0xe3000000 | ite8872_lpthi);
  2028. pci_write_config_dword(pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
  2029. /* SET SPP&EPP , Parallel Port NO DMA , Enable All Function */
  2030. /* SET Parallel IRQ */
  2031. pci_write_config_dword(pdev, 0x9c,
  2032. ite8872set | (ite8872_irq * 0x11111));
  2033. DPRINTK(KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq);
  2034. DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n",
  2035. ite8872_lpt);
  2036. DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n",
  2037. ite8872_lpthi);
  2038. /* Let the user (or defaults) steer us away from interrupts */
  2039. irq = ite8872_irq;
  2040. if (autoirq != PARPORT_IRQ_AUTO)
  2041. irq = PARPORT_IRQ_NONE;
  2042. /*
  2043. * Release the resource so that parport_pc_probe_port can get it.
  2044. */
  2045. release_region(inta_addr[i], 32);
  2046. if (parport_pc_probe_port(ite8872_lpt, ite8872_lpthi,
  2047. irq, PARPORT_DMA_NONE, &pdev->dev, 0)) {
  2048. printk(KERN_INFO
  2049. "parport_pc: ITE 8872 parallel port: io=0x%X",
  2050. ite8872_lpt);
  2051. if (irq != PARPORT_IRQ_NONE)
  2052. printk(", irq=%d", irq);
  2053. printk("\n");
  2054. return 1;
  2055. }
  2056. return 0;
  2057. }
  2058. /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru>
  2059. based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */
  2060. static int parport_init_mode;
  2061. /* Data for two known VIA chips */
  2062. static struct parport_pc_via_data via_686a_data = {
  2063. 0x51,
  2064. 0x50,
  2065. 0x85,
  2066. 0x02,
  2067. 0xE2,
  2068. 0xF0,
  2069. 0xE6
  2070. };
  2071. static struct parport_pc_via_data via_8231_data = {
  2072. 0x45,
  2073. 0x44,
  2074. 0x50,
  2075. 0x04,
  2076. 0xF2,
  2077. 0xFA,
  2078. 0xF6
  2079. };
  2080. static int sio_via_probe(struct pci_dev *pdev, int autoirq, int autodma,
  2081. const struct parport_pc_via_data *via)
  2082. {
  2083. u8 tmp, tmp2, siofunc;
  2084. u8 ppcontrol = 0;
  2085. int dma, irq;
  2086. unsigned port1, port2;
  2087. unsigned have_epp = 0;
  2088. printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n");
  2089. switch (parport_init_mode) {
  2090. case 1:
  2091. printk(KERN_DEBUG "parport_pc: setting SPP mode\n");
  2092. siofunc = VIA_FUNCTION_PARPORT_SPP;
  2093. break;
  2094. case 2:
  2095. printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n");
  2096. siofunc = VIA_FUNCTION_PARPORT_SPP;
  2097. ppcontrol = VIA_PARPORT_BIDIR;
  2098. break;
  2099. case 3:
  2100. printk(KERN_DEBUG "parport_pc: setting EPP mode\n");
  2101. siofunc = VIA_FUNCTION_PARPORT_EPP;
  2102. ppcontrol = VIA_PARPORT_BIDIR;
  2103. have_epp = 1;
  2104. break;
  2105. case 4:
  2106. printk(KERN_DEBUG "parport_pc: setting ECP mode\n");
  2107. siofunc = VIA_FUNCTION_PARPORT_ECP;
  2108. ppcontrol = VIA_PARPORT_BIDIR;
  2109. break;
  2110. case 5:
  2111. printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n");
  2112. siofunc = VIA_FUNCTION_PARPORT_ECP;
  2113. ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP;
  2114. have_epp = 1;
  2115. break;
  2116. default:
  2117. printk(KERN_DEBUG
  2118. "parport_pc: probing current configuration\n");
  2119. siofunc = VIA_FUNCTION_PROBE;
  2120. break;
  2121. }
  2122. /*
  2123. * unlock super i/o configuration
  2124. */
  2125. pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
  2126. tmp |= via->via_pci_superio_config_data;
  2127. pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
  2128. /* Bits 1-0: Parallel Port Mode / Enable */
  2129. outb(via->viacfg_function, VIA_CONFIG_INDEX);
  2130. tmp = inb(VIA_CONFIG_DATA);
  2131. /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */
  2132. outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
  2133. tmp2 = inb(VIA_CONFIG_DATA);
  2134. if (siofunc == VIA_FUNCTION_PROBE) {
  2135. siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE;
  2136. ppcontrol = tmp2;
  2137. } else {
  2138. tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
  2139. tmp |= siofunc;
  2140. outb(via->viacfg_function, VIA_CONFIG_INDEX);
  2141. outb(tmp, VIA_CONFIG_DATA);
  2142. tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
  2143. tmp2 |= ppcontrol;
  2144. outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
  2145. outb(tmp2, VIA_CONFIG_DATA);
  2146. }
  2147. /* Parallel Port I/O Base Address, bits 9-2 */
  2148. outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
  2149. port1 = inb(VIA_CONFIG_DATA) << 2;
  2150. printk(KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",
  2151. port1);
  2152. if (port1 == 0x3BC && have_epp) {
  2153. outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
  2154. outb((0x378 >> 2), VIA_CONFIG_DATA);
  2155. printk(KERN_DEBUG
  2156. "parport_pc: Parallel port base changed to 0x378\n");
  2157. port1 = 0x378;
  2158. }
  2159. /*
  2160. * lock super i/o configuration
  2161. */
  2162. pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
  2163. tmp &= ~via->via_pci_superio_config_data;
  2164. pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
  2165. if (siofunc == VIA_FUNCTION_PARPORT_DISABLE) {
  2166. printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n");
  2167. return 0;
  2168. }
  2169. /* Bits 7-4: PnP Routing for Parallel Port IRQ */
  2170. pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp);
  2171. irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4);
  2172. if (siofunc == VIA_FUNCTION_PARPORT_ECP) {
  2173. /* Bits 3-2: PnP Routing for Parallel Port DMA */
  2174. pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp);
  2175. dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2);
  2176. } else
  2177. /* if ECP not enabled, DMA is not enabled, assumed
  2178. bogus 'dma' value */
  2179. dma = PARPORT_DMA_NONE;
  2180. /* Let the user (or defaults) steer us away from interrupts and DMA */
  2181. if (autoirq == PARPORT_IRQ_NONE) {
  2182. irq = PARPORT_IRQ_NONE;
  2183. dma = PARPORT_DMA_NONE;
  2184. }
  2185. if (autodma == PARPORT_DMA_NONE)
  2186. dma = PARPORT_DMA_NONE;
  2187. switch (port1) {
  2188. case 0x3bc:
  2189. port2 = 0x7bc; break;
  2190. case 0x378:
  2191. port2 = 0x778; break;
  2192. case 0x278:
  2193. port2 = 0x678; break;
  2194. default:
  2195. printk(KERN_INFO
  2196. "parport_pc: Weird VIA parport base 0x%X, ignoring\n",
  2197. port1);
  2198. return 0;
  2199. }
  2200. /* filter bogus IRQs */
  2201. switch (irq) {
  2202. case 0:
  2203. case 2:
  2204. case 8:
  2205. case 13:
  2206. irq = PARPORT_IRQ_NONE;
  2207. break;
  2208. default: /* do nothing */
  2209. break;
  2210. }
  2211. /* finally, do the probe with values obtained */
  2212. if (parport_pc_probe_port(port1, port2, irq, dma, &pdev->dev, 0)) {
  2213. printk(KERN_INFO
  2214. "parport_pc: VIA parallel port: io=0x%X", port1);
  2215. if (irq != PARPORT_IRQ_NONE)
  2216. printk(", irq=%d", irq);
  2217. if (dma != PARPORT_DMA_NONE)
  2218. printk(", dma=%d", dma);
  2219. printk("\n");
  2220. return 1;
  2221. }
  2222. printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n",
  2223. port1, irq, dma);
  2224. return 0;
  2225. }
  2226. enum parport_pc_sio_types {
  2227. sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */
  2228. sio_via_8231, /* Via VT8231 south bridge integrated Super IO */
  2229. sio_ite_8872,
  2230. last_sio
  2231. };
  2232. /* each element directly indexed from enum list, above */
  2233. static struct parport_pc_superio {
  2234. int (*probe) (struct pci_dev *pdev, int autoirq, int autodma,
  2235. const struct parport_pc_via_data *via);
  2236. const struct parport_pc_via_data *via;
  2237. } parport_pc_superio_info[] = {
  2238. { sio_via_probe, &via_686a_data, },
  2239. { sio_via_probe, &via_8231_data, },
  2240. { sio_ite_8872_probe, NULL, },
  2241. };
  2242. enum parport_pc_pci_cards {
  2243. siig_1p_10x = last_sio,
  2244. siig_2p_10x,
  2245. siig_1p_20x,
  2246. siig_2p_20x,
  2247. lava_parallel,
  2248. lava_parallel_dual_a,
  2249. lava_parallel_dual_b,
  2250. boca_ioppar,
  2251. plx_9050,
  2252. timedia_4006a,
  2253. timedia_4014,
  2254. timedia_4008a,
  2255. timedia_4018,
  2256. timedia_9018a,
  2257. syba_2p_epp,
  2258. syba_1p_ecp,
  2259. titan_010l,
  2260. avlab_1p,
  2261. avlab_2p,
  2262. oxsemi_952,
  2263. oxsemi_954,
  2264. oxsemi_840,
  2265. oxsemi_pcie_pport,
  2266. aks_0100,
  2267. mobility_pp,
  2268. netmos_9705,
  2269. netmos_9715,
  2270. netmos_9755,
  2271. netmos_9805,
  2272. netmos_9815,
  2273. netmos_9901,
  2274. netmos_9865,
  2275. quatech_sppxp100,
  2276. wch_ch382l,
  2277. };
  2278. /* each element directly indexed from enum list, above
  2279. * (but offset by last_sio) */
  2280. static struct parport_pc_pci {
  2281. int numports;
  2282. struct { /* BAR (base address registers) numbers in the config
  2283. space header */
  2284. int lo;
  2285. int hi;
  2286. /* -1 if not there, >6 for offset-method (max BAR is 6) */
  2287. } addr[4];
  2288. /* If set, this is called immediately after pci_enable_device.
  2289. * If it returns non-zero, no probing will take place and the
  2290. * ports will not be used. */
  2291. int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma);
  2292. /* If set, this is called after probing for ports. If 'failed'
  2293. * is non-zero we couldn't use any of the ports. */
  2294. void (*postinit_hook) (struct pci_dev *pdev, int failed);
  2295. } cards[] = {
  2296. /* siig_1p_10x */ { 1, { { 2, 3 }, } },
  2297. /* siig_2p_10x */ { 2, { { 2, 3 }, { 4, 5 }, } },
  2298. /* siig_1p_20x */ { 1, { { 0, 1 }, } },
  2299. /* siig_2p_20x */ { 2, { { 0, 1 }, { 2, 3 }, } },
  2300. /* lava_parallel */ { 1, { { 0, -1 }, } },
  2301. /* lava_parallel_dual_a */ { 1, { { 0, -1 }, } },
  2302. /* lava_parallel_dual_b */ { 1, { { 0, -1 }, } },
  2303. /* boca_ioppar */ { 1, { { 0, -1 }, } },
  2304. /* plx_9050 */ { 2, { { 4, -1 }, { 5, -1 }, } },
  2305. /* timedia_4006a */ { 1, { { 0, -1 }, } },
  2306. /* timedia_4014 */ { 2, { { 0, -1 }, { 2, -1 }, } },
  2307. /* timedia_4008a */ { 1, { { 0, 1 }, } },
  2308. /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } },
  2309. /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } },
  2310. /* SYBA uses fixed offsets in
  2311. a 1K io window */
  2312. /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
  2313. /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
  2314. /* titan_010l */ { 1, { { 3, -1 }, } },
  2315. /* avlab_1p */ { 1, { { 0, 1}, } },
  2316. /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} },
  2317. /* The Oxford Semi cards are unusual: 954 doesn't support ECP,
  2318. * and 840 locks up if you write 1 to bit 2! */
  2319. /* oxsemi_952 */ { 1, { { 0, 1 }, } },
  2320. /* oxsemi_954 */ { 1, { { 0, -1 }, } },
  2321. /* oxsemi_840 */ { 1, { { 0, 1 }, } },
  2322. /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } },
  2323. /* aks_0100 */ { 1, { { 0, -1 }, } },
  2324. /* mobility_pp */ { 1, { { 0, 1 }, } },
  2325. /* The netmos entries below are untested */
  2326. /* netmos_9705 */ { 1, { { 0, -1 }, } },
  2327. /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} },
  2328. /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} },
  2329. /* netmos_9805 */ { 1, { { 0, 1 }, } },
  2330. /* netmos_9815 */ { 2, { { 0, 1 }, { 2, 3 }, } },
  2331. /* netmos_9901 */ { 1, { { 0, -1 }, } },
  2332. /* netmos_9865 */ { 1, { { 0, -1 }, } },
  2333. /* quatech_sppxp100 */ { 1, { { 0, 1 }, } },
  2334. /* wch_ch382l */ { 1, { { 2, -1 }, } },
  2335. };
  2336. static const struct pci_device_id parport_pc_pci_tbl[] = {
  2337. /* Super-IO onboard chips */
  2338. { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
  2339. { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 },
  2340. { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
  2341. PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 },
  2342. /* PCI cards */
  2343. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
  2344. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
  2345. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
  2346. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
  2347. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
  2348. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
  2349. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
  2350. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
  2351. { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
  2352. PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
  2353. { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
  2354. PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
  2355. { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
  2356. PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
  2357. { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
  2358. PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
  2359. { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
  2360. PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0, 0, plx_9050 },
  2361. /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
  2362. { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
  2363. { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
  2364. { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
  2365. { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
  2366. { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
  2367. { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
  2368. PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
  2369. { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
  2370. PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
  2371. { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
  2372. PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
  2373. /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
  2374. /* AFAVLAB_TK9902 */
  2375. { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p},
  2376. { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
  2377. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
  2378. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
  2379. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
  2380. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
  2381. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
  2382. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 },
  2383. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840,
  2384. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2385. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840_G,
  2386. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2387. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0,
  2388. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2389. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0_G,
  2390. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2391. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1,
  2392. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2393. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_G,
  2394. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2395. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_U,
  2396. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2397. { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU,
  2398. PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  2399. { PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD,
  2400. PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 },
  2401. { 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp },
  2402. /* NetMos communication controllers */
  2403. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705,
  2404. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 },
  2405. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715,
  2406. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 },
  2407. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755,
  2408. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 },
  2409. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805,
  2410. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
  2411. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
  2412. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
  2413. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9901,
  2414. 0xA000, 0x2000, 0, 0, netmos_9901 },
  2415. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9865,
  2416. 0xA000, 0x1000, 0, 0, netmos_9865 },
  2417. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9865,
  2418. 0xA000, 0x2000, 0, 0, netmos_9865 },
  2419. /* Quatech SPPXP-100 Parallel port PCI ExpressCard */
  2420. { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100,
  2421. PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
  2422. /* WCH CH382L PCI-E single parallel port card */
  2423. { 0x1c00, 0x3050, 0x1c00, 0x3050, 0, 0, wch_ch382l },
  2424. { 0, } /* terminate list */
  2425. };
  2426. MODULE_DEVICE_TABLE(pci, parport_pc_pci_tbl);
  2427. struct pci_parport_data {
  2428. int num;
  2429. struct parport *ports[2];
  2430. };
  2431. static int parport_pc_pci_probe(struct pci_dev *dev,
  2432. const struct pci_device_id *id)
  2433. {
  2434. int err, count, n, i = id->driver_data;
  2435. struct pci_parport_data *data;
  2436. if (i < last_sio)
  2437. /* This is an onboard Super-IO and has already been probed */
  2438. return 0;
  2439. /* This is a PCI card */
  2440. i -= last_sio;
  2441. count = 0;
  2442. err = pci_enable_device(dev);
  2443. if (err)
  2444. return err;
  2445. data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL);
  2446. if (!data)
  2447. return -ENOMEM;
  2448. if (cards[i].preinit_hook &&
  2449. cards[i].preinit_hook(dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) {
  2450. kfree(data);
  2451. return -ENODEV;
  2452. }
  2453. for (n = 0; n < cards[i].numports; n++) {
  2454. int lo = cards[i].addr[n].lo;
  2455. int hi = cards[i].addr[n].hi;
  2456. int irq;
  2457. unsigned long io_lo, io_hi;
  2458. io_lo = pci_resource_start(dev, lo);
  2459. io_hi = 0;
  2460. if ((hi >= 0) && (hi <= 6))
  2461. io_hi = pci_resource_start(dev, hi);
  2462. else if (hi > 6)
  2463. io_lo += hi; /* Reinterpret the meaning of
  2464. "hi" as an offset (see SYBA
  2465. def.) */
  2466. /* TODO: test if sharing interrupts works */
  2467. irq = dev->irq;
  2468. if (irq == IRQ_NONE) {
  2469. printk(KERN_DEBUG
  2470. "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n",
  2471. id->vendor, id->device, io_lo, io_hi);
  2472. irq = PARPORT_IRQ_NONE;
  2473. } else {
  2474. printk(KERN_DEBUG
  2475. "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n",
  2476. id->vendor, id->device, io_lo, io_hi, irq);
  2477. }
  2478. data->ports[count] =
  2479. parport_pc_probe_port(io_lo, io_hi, irq,
  2480. PARPORT_DMA_NONE, &dev->dev,
  2481. IRQF_SHARED);
  2482. if (data->ports[count])
  2483. count++;
  2484. }
  2485. data->num = count;
  2486. if (cards[i].postinit_hook)
  2487. cards[i].postinit_hook(dev, count == 0);
  2488. if (count) {
  2489. pci_set_drvdata(dev, data);
  2490. return 0;
  2491. }
  2492. kfree(data);
  2493. return -ENODEV;
  2494. }
  2495. static void parport_pc_pci_remove(struct pci_dev *dev)
  2496. {
  2497. struct pci_parport_data *data = pci_get_drvdata(dev);
  2498. int i;
  2499. if (data) {
  2500. for (i = data->num - 1; i >= 0; i--)
  2501. parport_pc_unregister_port(data->ports[i]);
  2502. kfree(data);
  2503. }
  2504. }
  2505. static struct pci_driver parport_pc_pci_driver = {
  2506. .name = "parport_pc",
  2507. .id_table = parport_pc_pci_tbl,
  2508. .probe = parport_pc_pci_probe,
  2509. .remove = parport_pc_pci_remove,
  2510. };
  2511. static int __init parport_pc_init_superio(int autoirq, int autodma)
  2512. {
  2513. const struct pci_device_id *id;
  2514. struct pci_dev *pdev = NULL;
  2515. int ret = 0;
  2516. for_each_pci_dev(pdev) {
  2517. id = pci_match_id(parport_pc_pci_tbl, pdev);
  2518. if (id == NULL || id->driver_data >= last_sio)
  2519. continue;
  2520. if (parport_pc_superio_info[id->driver_data].probe(
  2521. pdev, autoirq, autodma,
  2522. parport_pc_superio_info[id->driver_data].via)) {
  2523. ret++;
  2524. }
  2525. }
  2526. return ret; /* number of devices found */
  2527. }
  2528. #else
  2529. static struct pci_driver parport_pc_pci_driver;
  2530. static int __init parport_pc_init_superio(int autoirq, int autodma)
  2531. {
  2532. return 0;
  2533. }
  2534. #endif /* CONFIG_PCI */
  2535. #ifdef CONFIG_PNP
  2536. static const struct pnp_device_id parport_pc_pnp_tbl[] = {
  2537. /* Standard LPT Printer Port */
  2538. {.id = "PNP0400", .driver_data = 0},
  2539. /* ECP Printer Port */
  2540. {.id = "PNP0401", .driver_data = 0},
  2541. { }
  2542. };
  2543. MODULE_DEVICE_TABLE(pnp, parport_pc_pnp_tbl);
  2544. static int parport_pc_pnp_probe(struct pnp_dev *dev,
  2545. const struct pnp_device_id *id)
  2546. {
  2547. struct parport *pdata;
  2548. unsigned long io_lo, io_hi;
  2549. int dma, irq;
  2550. if (pnp_port_valid(dev, 0) &&
  2551. !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) {
  2552. io_lo = pnp_port_start(dev, 0);
  2553. } else
  2554. return -EINVAL;
  2555. if (pnp_port_valid(dev, 1) &&
  2556. !(pnp_port_flags(dev, 1) & IORESOURCE_DISABLED)) {
  2557. io_hi = pnp_port_start(dev, 1);
  2558. } else
  2559. io_hi = 0;
  2560. if (pnp_irq_valid(dev, 0) &&
  2561. !(pnp_irq_flags(dev, 0) & IORESOURCE_DISABLED)) {
  2562. irq = pnp_irq(dev, 0);
  2563. } else
  2564. irq = PARPORT_IRQ_NONE;
  2565. if (pnp_dma_valid(dev, 0) &&
  2566. !(pnp_dma_flags(dev, 0) & IORESOURCE_DISABLED)) {
  2567. dma = pnp_dma(dev, 0);
  2568. } else
  2569. dma = PARPORT_DMA_NONE;
  2570. dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
  2571. pdata = parport_pc_probe_port(io_lo, io_hi, irq, dma, &dev->dev, 0);
  2572. if (pdata == NULL)
  2573. return -ENODEV;
  2574. pnp_set_drvdata(dev, pdata);
  2575. return 0;
  2576. }
  2577. static void parport_pc_pnp_remove(struct pnp_dev *dev)
  2578. {
  2579. struct parport *pdata = (struct parport *)pnp_get_drvdata(dev);
  2580. if (!pdata)
  2581. return;
  2582. parport_pc_unregister_port(pdata);
  2583. }
  2584. /* we only need the pnp layer to activate the device, at least for now */
  2585. static struct pnp_driver parport_pc_pnp_driver = {
  2586. .name = "parport_pc",
  2587. .id_table = parport_pc_pnp_tbl,
  2588. .probe = parport_pc_pnp_probe,
  2589. .remove = parport_pc_pnp_remove,
  2590. };
  2591. #else
  2592. static struct pnp_driver parport_pc_pnp_driver;
  2593. #endif /* CONFIG_PNP */
  2594. static int parport_pc_platform_probe(struct platform_device *pdev)
  2595. {
  2596. /* Always succeed, the actual probing is done in
  2597. * parport_pc_probe_port(). */
  2598. return 0;
  2599. }
  2600. static struct platform_driver parport_pc_platform_driver = {
  2601. .driver = {
  2602. .name = "parport_pc",
  2603. },
  2604. .probe = parport_pc_platform_probe,
  2605. };
  2606. /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
  2607. static int __attribute__((unused))
  2608. parport_pc_find_isa_ports(int autoirq, int autodma)
  2609. {
  2610. int count = 0;
  2611. if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL, 0))
  2612. count++;
  2613. if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL, 0))
  2614. count++;
  2615. if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL, 0))
  2616. count++;
  2617. return count;
  2618. }
  2619. /* This function is called by parport_pc_init if the user didn't
  2620. * specify any ports to probe. Its job is to find some ports. Order
  2621. * is important here -- we want ISA ports to be registered first,
  2622. * followed by PCI cards (for least surprise), but before that we want
  2623. * to do chipset-specific tests for some onboard ports that we know
  2624. * about.
  2625. *
  2626. * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
  2627. * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
  2628. */
  2629. static void __init parport_pc_find_ports(int autoirq, int autodma)
  2630. {
  2631. int count = 0, err;
  2632. #ifdef CONFIG_PARPORT_PC_SUPERIO
  2633. detect_and_report_it87();
  2634. detect_and_report_winbond();
  2635. detect_and_report_smsc();
  2636. #endif
  2637. /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
  2638. count += parport_pc_init_superio(autoirq, autodma);
  2639. /* PnP ports, skip detection if SuperIO already found them */
  2640. if (!count) {
  2641. err = pnp_register_driver(&parport_pc_pnp_driver);
  2642. if (!err)
  2643. pnp_registered_parport = 1;
  2644. }
  2645. /* ISA ports and whatever (see asm/parport.h). */
  2646. parport_pc_find_nonpci_ports(autoirq, autodma);
  2647. err = pci_register_driver(&parport_pc_pci_driver);
  2648. if (!err)
  2649. pci_registered_parport = 1;
  2650. }
  2651. /*
  2652. * Piles of crap below pretend to be a parser for module and kernel
  2653. * parameters. Say "thank you" to whoever had come up with that
  2654. * syntax and keep in mind that code below is a cleaned up version.
  2655. */
  2656. static int __initdata io[PARPORT_PC_MAX_PORTS+1] = {
  2657. [0 ... PARPORT_PC_MAX_PORTS] = 0
  2658. };
  2659. static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = {
  2660. [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO
  2661. };
  2662. static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = {
  2663. [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE
  2664. };
  2665. static int __initdata irqval[PARPORT_PC_MAX_PORTS] = {
  2666. [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY
  2667. };
  2668. static int __init parport_parse_param(const char *s, int *val,
  2669. int automatic, int none, int nofifo)
  2670. {
  2671. if (!s)
  2672. return 0;
  2673. if (!strncmp(s, "auto", 4))
  2674. *val = automatic;
  2675. else if (!strncmp(s, "none", 4))
  2676. *val = none;
  2677. else if (nofifo && !strncmp(s, "nofifo", 6))
  2678. *val = nofifo;
  2679. else {
  2680. char *ep;
  2681. unsigned long r = simple_strtoul(s, &ep, 0);
  2682. if (ep != s)
  2683. *val = r;
  2684. else {
  2685. printk(KERN_ERR "parport: bad specifier `%s'\n", s);
  2686. return -1;
  2687. }
  2688. }
  2689. return 0;
  2690. }
  2691. static int __init parport_parse_irq(const char *irqstr, int *val)
  2692. {
  2693. return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO,
  2694. PARPORT_IRQ_NONE, 0);
  2695. }
  2696. static int __init parport_parse_dma(const char *dmastr, int *val)
  2697. {
  2698. return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO,
  2699. PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO);
  2700. }
  2701. #ifdef CONFIG_PCI
  2702. static int __init parport_init_mode_setup(char *str)
  2703. {
  2704. printk(KERN_DEBUG
  2705. "parport_pc.c: Specified parameter parport_init_mode=%s\n", str);
  2706. if (!strcmp(str, "spp"))
  2707. parport_init_mode = 1;
  2708. if (!strcmp(str, "ps2"))
  2709. parport_init_mode = 2;
  2710. if (!strcmp(str, "epp"))
  2711. parport_init_mode = 3;
  2712. if (!strcmp(str, "ecp"))
  2713. parport_init_mode = 4;
  2714. if (!strcmp(str, "ecpepp"))
  2715. parport_init_mode = 5;
  2716. return 1;
  2717. }
  2718. #endif
  2719. #ifdef MODULE
  2720. static char *irq[PARPORT_PC_MAX_PORTS];
  2721. static char *dma[PARPORT_PC_MAX_PORTS];
  2722. MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
  2723. module_param_array(io, int, NULL, 0);
  2724. MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
  2725. module_param_array(io_hi, int, NULL, 0);
  2726. MODULE_PARM_DESC(irq, "IRQ line");
  2727. module_param_array(irq, charp, NULL, 0);
  2728. MODULE_PARM_DESC(dma, "DMA channel");
  2729. module_param_array(dma, charp, NULL, 0);
  2730. #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
  2731. (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
  2732. MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation");
  2733. module_param(verbose_probing, int, 0644);
  2734. #endif
  2735. #ifdef CONFIG_PCI
  2736. static char *init_mode;
  2737. MODULE_PARM_DESC(init_mode,
  2738. "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)");
  2739. module_param(init_mode, charp, 0);
  2740. #endif
  2741. static int __init parse_parport_params(void)
  2742. {
  2743. unsigned int i;
  2744. int val;
  2745. #ifdef CONFIG_PCI
  2746. if (init_mode)
  2747. parport_init_mode_setup(init_mode);
  2748. #endif
  2749. for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) {
  2750. if (parport_parse_irq(irq[i], &val))
  2751. return 1;
  2752. irqval[i] = val;
  2753. if (parport_parse_dma(dma[i], &val))
  2754. return 1;
  2755. dmaval[i] = val;
  2756. }
  2757. if (!io[0]) {
  2758. /* The user can make us use any IRQs or DMAs we find. */
  2759. if (irq[0] && !parport_parse_irq(irq[0], &val))
  2760. switch (val) {
  2761. case PARPORT_IRQ_NONE:
  2762. case PARPORT_IRQ_AUTO:
  2763. irqval[0] = val;
  2764. break;
  2765. default:
  2766. printk(KERN_WARNING
  2767. "parport_pc: irq specified "
  2768. "without base address. Use 'io=' "
  2769. "to specify one\n");
  2770. }
  2771. if (dma[0] && !parport_parse_dma(dma[0], &val))
  2772. switch (val) {
  2773. case PARPORT_DMA_NONE:
  2774. case PARPORT_DMA_AUTO:
  2775. dmaval[0] = val;
  2776. break;
  2777. default:
  2778. printk(KERN_WARNING
  2779. "parport_pc: dma specified "
  2780. "without base address. Use 'io=' "
  2781. "to specify one\n");
  2782. }
  2783. }
  2784. return 0;
  2785. }
  2786. #else
  2787. static int parport_setup_ptr __initdata;
  2788. /*
  2789. * Acceptable parameters:
  2790. *
  2791. * parport=0
  2792. * parport=auto
  2793. * parport=0xBASE[,IRQ[,DMA]]
  2794. *
  2795. * IRQ/DMA may be numeric or 'auto' or 'none'
  2796. */
  2797. static int __init parport_setup(char *str)
  2798. {
  2799. char *endptr;
  2800. char *sep;
  2801. int val;
  2802. if (!str || !*str || (*str == '0' && !*(str+1))) {
  2803. /* Disable parport if "parport=0" in cmdline */
  2804. io[0] = PARPORT_DISABLE;
  2805. return 1;
  2806. }
  2807. if (!strncmp(str, "auto", 4)) {
  2808. irqval[0] = PARPORT_IRQ_AUTO;
  2809. dmaval[0] = PARPORT_DMA_AUTO;
  2810. return 1;
  2811. }
  2812. val = simple_strtoul(str, &endptr, 0);
  2813. if (endptr == str) {
  2814. printk(KERN_WARNING "parport=%s not understood\n", str);
  2815. return 1;
  2816. }
  2817. if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) {
  2818. printk(KERN_ERR "parport=%s ignored, too many ports\n", str);
  2819. return 1;
  2820. }
  2821. io[parport_setup_ptr] = val;
  2822. irqval[parport_setup_ptr] = PARPORT_IRQ_NONE;
  2823. dmaval[parport_setup_ptr] = PARPORT_DMA_NONE;
  2824. sep = strchr(str, ',');
  2825. if (sep++) {
  2826. if (parport_parse_irq(sep, &val))
  2827. return 1;
  2828. irqval[parport_setup_ptr] = val;
  2829. sep = strchr(sep, ',');
  2830. if (sep++) {
  2831. if (parport_parse_dma(sep, &val))
  2832. return 1;
  2833. dmaval[parport_setup_ptr] = val;
  2834. }
  2835. }
  2836. parport_setup_ptr++;
  2837. return 1;
  2838. }
  2839. static int __init parse_parport_params(void)
  2840. {
  2841. return io[0] == PARPORT_DISABLE;
  2842. }
  2843. __setup("parport=", parport_setup);
  2844. /*
  2845. * Acceptable parameters:
  2846. *
  2847. * parport_init_mode=[spp|ps2|epp|ecp|ecpepp]
  2848. */
  2849. #ifdef CONFIG_PCI
  2850. __setup("parport_init_mode=", parport_init_mode_setup);
  2851. #endif
  2852. #endif
  2853. /* "Parser" ends here */
  2854. static int __init parport_pc_init(void)
  2855. {
  2856. int err;
  2857. if (parse_parport_params())
  2858. return -EINVAL;
  2859. err = platform_driver_register(&parport_pc_platform_driver);
  2860. if (err)
  2861. return err;
  2862. if (io[0]) {
  2863. int i;
  2864. /* Only probe the ports we were given. */
  2865. user_specified = 1;
  2866. for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
  2867. if (!io[i])
  2868. break;
  2869. if (io_hi[i] == PARPORT_IOHI_AUTO)
  2870. io_hi[i] = 0x400 + io[i];
  2871. parport_pc_probe_port(io[i], io_hi[i],
  2872. irqval[i], dmaval[i], NULL, 0);
  2873. }
  2874. } else
  2875. parport_pc_find_ports(irqval[0], dmaval[0]);
  2876. return 0;
  2877. }
  2878. static void __exit parport_pc_exit(void)
  2879. {
  2880. if (pci_registered_parport)
  2881. pci_unregister_driver(&parport_pc_pci_driver);
  2882. if (pnp_registered_parport)
  2883. pnp_unregister_driver(&parport_pc_pnp_driver);
  2884. platform_driver_unregister(&parport_pc_platform_driver);
  2885. while (!list_empty(&ports_list)) {
  2886. struct parport_pc_private *priv;
  2887. struct parport *port;
  2888. struct device *dev;
  2889. priv = list_entry(ports_list.next,
  2890. struct parport_pc_private, list);
  2891. port = priv->port;
  2892. dev = port->dev;
  2893. parport_pc_unregister_port(port);
  2894. if (dev && dev->bus == &platform_bus_type)
  2895. platform_device_unregister(to_platform_device(dev));
  2896. }
  2897. }
  2898. MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
  2899. MODULE_DESCRIPTION("PC-style parallel port driver");
  2900. MODULE_LICENSE("GPL");
  2901. module_init(parport_pc_init)
  2902. module_exit(parport_pc_exit)