parport_pc.c 92 KB

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