parport_pc.c 95 KB

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