parport_pc.c 93 KB

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