parport_pc.c 95 KB

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