parport_pc.c 85 KB

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