parport_pc.c 88 KB

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