parport_pc.c 92 KB

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