parport_pc.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:83k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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