parport_pc.c 92 KB

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