parport_pc.c 92 KB

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