parport_pc.c 93 KB

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