parport_pc.c 93 KB

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