parport_serial.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * Support for common PCI multi-I/O cards (which is most of them)
  3. *
  4. * Copyright (C) 2001 Tim Waugh <twaugh@redhat.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. *
  12. * Multi-function PCI cards are supposed to present separate logical
  13. * devices on the bus. A common thing to do seems to be to just use
  14. * one logical device with lots of base address registers for both
  15. * parallel ports and serial ports. This driver is for dealing with
  16. * that.
  17. *
  18. */
  19. #include <linux/types.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/pci.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/parport.h>
  26. #include <linux/parport_pc.h>
  27. #include <linux/8250_pci.h>
  28. enum parport_pc_pci_cards {
  29. titan_110l = 0,
  30. titan_210l,
  31. netmos_9xx5_combo,
  32. netmos_9855,
  33. netmos_9855_2p,
  34. avlab_1s1p,
  35. avlab_1s2p,
  36. avlab_2s1p,
  37. siig_1s1p_10x,
  38. siig_2s1p_10x,
  39. siig_2p1s_20x,
  40. siig_1s1p_20x,
  41. siig_2s1p_20x,
  42. };
  43. /* each element directly indexed from enum list, above */
  44. struct parport_pc_pci {
  45. int numports;
  46. struct { /* BAR (base address registers) numbers in the config
  47. space header */
  48. int lo;
  49. int hi; /* -1 if not there, >6 for offset-method (max
  50. BAR is 6) */
  51. } addr[4];
  52. /* If set, this is called immediately after pci_enable_device.
  53. * If it returns non-zero, no probing will take place and the
  54. * ports will not be used. */
  55. int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card,
  56. int autoirq, int autodma);
  57. /* If set, this is called after probing for ports. If 'failed'
  58. * is non-zero we couldn't use any of the ports. */
  59. void (*postinit_hook) (struct pci_dev *pdev,
  60. struct parport_pc_pci *card, int failed);
  61. };
  62. static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *par, int autoirq, int autodma)
  63. {
  64. /* the rule described below doesn't hold for this device */
  65. if (dev->device == PCI_DEVICE_ID_NETMOS_9835 &&
  66. dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
  67. dev->subsystem_device == 0x0299)
  68. return -ENODEV;
  69. /*
  70. * Netmos uses the subdevice ID to indicate the number of parallel
  71. * and serial ports. The form is 0x00PS, where <P> is the number of
  72. * parallel ports and <S> is the number of serial ports.
  73. */
  74. par->numports = (dev->subsystem_device & 0xf0) >> 4;
  75. if (par->numports > ARRAY_SIZE(par->addr))
  76. par->numports = ARRAY_SIZE(par->addr);
  77. /*
  78. * This function is currently only called for cards with up to
  79. * one parallel port.
  80. * Parallel port BAR is either before or after serial ports BARS;
  81. * hence, lo should be either 0 or equal to the number of serial ports.
  82. */
  83. if (par->addr[0].lo != 0)
  84. par->addr[0].lo = dev->subsystem_device & 0xf;
  85. return 0;
  86. }
  87. static struct parport_pc_pci cards[] __devinitdata = {
  88. /* titan_110l */ { 1, { { 3, -1 }, } },
  89. /* titan_210l */ { 1, { { 3, -1 }, } },
  90. /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
  91. /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
  92. /* netmos_9855_2p */ { 2, { { 0, -1 }, { 2, -1 }, } },
  93. /* avlab_1s1p */ { 1, { { 1, 2}, } },
  94. /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
  95. /* avlab_2s1p */ { 1, { { 2, 3}, } },
  96. /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
  97. /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
  98. /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
  99. /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
  100. /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
  101. };
  102. static struct pci_device_id parport_serial_pci_tbl[] = {
  103. /* PCI cards */
  104. { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
  105. PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
  106. { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
  107. PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
  108. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
  109. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  110. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
  111. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  112. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
  113. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  114. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
  115. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  116. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  117. 0x1000, 0x0020, 0, 0, netmos_9855_2p },
  118. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  119. 0x1000, 0x0022, 0, 0, netmos_9855_2p },
  120. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  121. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
  122. /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
  123. { PCI_VENDOR_ID_AFAVLAB, 0x2110,
  124. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  125. { PCI_VENDOR_ID_AFAVLAB, 0x2111,
  126. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  127. { PCI_VENDOR_ID_AFAVLAB, 0x2112,
  128. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  129. { PCI_VENDOR_ID_AFAVLAB, 0x2140,
  130. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  131. { PCI_VENDOR_ID_AFAVLAB, 0x2141,
  132. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  133. { PCI_VENDOR_ID_AFAVLAB, 0x2142,
  134. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  135. { PCI_VENDOR_ID_AFAVLAB, 0x2160,
  136. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  137. { PCI_VENDOR_ID_AFAVLAB, 0x2161,
  138. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  139. { PCI_VENDOR_ID_AFAVLAB, 0x2162,
  140. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  141. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
  142. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  143. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
  144. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  145. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
  146. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  147. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
  148. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  149. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
  150. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  151. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
  152. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  153. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
  154. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  155. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
  156. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  157. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
  158. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  159. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
  160. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  161. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
  162. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
  163. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
  164. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
  165. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
  166. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  167. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
  168. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  169. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
  170. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  171. { 0, } /* terminate list */
  172. };
  173. MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
  174. /*
  175. * This table describes the serial "geometry" of these boards. Any
  176. * quirks for these can be found in drivers/serial/8250_pci.c
  177. *
  178. * Cards not tested are marked n/t
  179. * If you have one of these cards and it works for you, please tell me..
  180. */
  181. static struct pciserial_board pci_parport_serial_boards[] __devinitdata = {
  182. [titan_110l] = {
  183. .flags = FL_BASE1 | FL_BASE_BARS,
  184. .num_ports = 1,
  185. .base_baud = 921600,
  186. .uart_offset = 8,
  187. },
  188. [titan_210l] = {
  189. .flags = FL_BASE1 | FL_BASE_BARS,
  190. .num_ports = 2,
  191. .base_baud = 921600,
  192. .uart_offset = 8,
  193. },
  194. [netmos_9xx5_combo] = {
  195. .flags = FL_BASE0 | FL_BASE_BARS,
  196. .num_ports = 1,
  197. .base_baud = 115200,
  198. .uart_offset = 8,
  199. },
  200. [netmos_9855] = {
  201. .flags = FL_BASE2 | FL_BASE_BARS,
  202. .num_ports = 1,
  203. .base_baud = 115200,
  204. .uart_offset = 8,
  205. },
  206. [netmos_9855_2p] = {
  207. .flags = FL_BASE4 | FL_BASE_BARS,
  208. .num_ports = 1,
  209. .base_baud = 115200,
  210. .uart_offset = 8,
  211. },
  212. [avlab_1s1p] = { /* n/t */
  213. .flags = FL_BASE0 | FL_BASE_BARS,
  214. .num_ports = 1,
  215. .base_baud = 115200,
  216. .uart_offset = 8,
  217. },
  218. [avlab_1s2p] = { /* n/t */
  219. .flags = FL_BASE0 | FL_BASE_BARS,
  220. .num_ports = 1,
  221. .base_baud = 115200,
  222. .uart_offset = 8,
  223. },
  224. [avlab_2s1p] = { /* n/t */
  225. .flags = FL_BASE0 | FL_BASE_BARS,
  226. .num_ports = 2,
  227. .base_baud = 115200,
  228. .uart_offset = 8,
  229. },
  230. [siig_1s1p_10x] = {
  231. .flags = FL_BASE2,
  232. .num_ports = 1,
  233. .base_baud = 460800,
  234. .uart_offset = 8,
  235. },
  236. [siig_2s1p_10x] = {
  237. .flags = FL_BASE2,
  238. .num_ports = 1,
  239. .base_baud = 921600,
  240. .uart_offset = 8,
  241. },
  242. [siig_2p1s_20x] = {
  243. .flags = FL_BASE0,
  244. .num_ports = 1,
  245. .base_baud = 921600,
  246. .uart_offset = 8,
  247. },
  248. [siig_1s1p_20x] = {
  249. .flags = FL_BASE0,
  250. .num_ports = 1,
  251. .base_baud = 921600,
  252. .uart_offset = 8,
  253. },
  254. [siig_2s1p_20x] = {
  255. .flags = FL_BASE0,
  256. .num_ports = 1,
  257. .base_baud = 921600,
  258. .uart_offset = 8,
  259. },
  260. };
  261. struct parport_serial_private {
  262. struct serial_private *serial;
  263. int num_par;
  264. struct parport *port[PARPORT_MAX];
  265. struct parport_pc_pci par;
  266. };
  267. /* Register the serial port(s) of a PCI card. */
  268. static int __devinit serial_register (struct pci_dev *dev,
  269. const struct pci_device_id *id)
  270. {
  271. struct parport_serial_private *priv = pci_get_drvdata (dev);
  272. struct pciserial_board *board;
  273. struct serial_private *serial;
  274. board = &pci_parport_serial_boards[id->driver_data];
  275. serial = pciserial_init_ports(dev, board);
  276. if (IS_ERR(serial))
  277. return PTR_ERR(serial);
  278. priv->serial = serial;
  279. return 0;
  280. }
  281. /* Register the parallel port(s) of a PCI card. */
  282. static int __devinit parport_register (struct pci_dev *dev,
  283. const struct pci_device_id *id)
  284. {
  285. struct parport_pc_pci *card;
  286. struct parport_serial_private *priv = pci_get_drvdata (dev);
  287. int n, success = 0;
  288. priv->par = cards[id->driver_data];
  289. card = &priv->par;
  290. if (card->preinit_hook &&
  291. card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
  292. return -ENODEV;
  293. for (n = 0; n < card->numports; n++) {
  294. struct parport *port;
  295. int lo = card->addr[n].lo;
  296. int hi = card->addr[n].hi;
  297. unsigned long io_lo, io_hi;
  298. int irq;
  299. if (priv->num_par == ARRAY_SIZE (priv->port)) {
  300. printk (KERN_WARNING
  301. "parport_serial: %s: only %zu parallel ports "
  302. "supported (%d reported)\n", pci_name (dev),
  303. ARRAY_SIZE(priv->port), card->numports);
  304. break;
  305. }
  306. io_lo = pci_resource_start (dev, lo);
  307. io_hi = 0;
  308. if ((hi >= 0) && (hi <= 6))
  309. io_hi = pci_resource_start (dev, hi);
  310. else if (hi > 6)
  311. io_lo += hi; /* Reinterpret the meaning of
  312. "hi" as an offset (see SYBA
  313. def.) */
  314. /* TODO: test if sharing interrupts works */
  315. irq = dev->irq;
  316. if (irq == IRQ_NONE) {
  317. dev_dbg(&dev->dev,
  318. "PCI parallel port detected: I/O at %#lx(%#lx)\n",
  319. io_lo, io_hi);
  320. irq = PARPORT_IRQ_NONE;
  321. } else {
  322. dev_dbg(&dev->dev,
  323. "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
  324. io_lo, io_hi, irq);
  325. }
  326. port = parport_pc_probe_port (io_lo, io_hi, irq,
  327. PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED);
  328. if (port) {
  329. priv->port[priv->num_par++] = port;
  330. success = 1;
  331. }
  332. }
  333. if (card->postinit_hook)
  334. card->postinit_hook (dev, card, !success);
  335. return 0;
  336. }
  337. static int __devinit parport_serial_pci_probe (struct pci_dev *dev,
  338. const struct pci_device_id *id)
  339. {
  340. struct parport_serial_private *priv;
  341. int err;
  342. priv = kzalloc (sizeof *priv, GFP_KERNEL);
  343. if (!priv)
  344. return -ENOMEM;
  345. pci_set_drvdata (dev, priv);
  346. err = pci_enable_device (dev);
  347. if (err) {
  348. pci_set_drvdata (dev, NULL);
  349. kfree (priv);
  350. return err;
  351. }
  352. if (parport_register (dev, id)) {
  353. pci_set_drvdata (dev, NULL);
  354. kfree (priv);
  355. return -ENODEV;
  356. }
  357. if (serial_register (dev, id)) {
  358. int i;
  359. for (i = 0; i < priv->num_par; i++)
  360. parport_pc_unregister_port (priv->port[i]);
  361. pci_set_drvdata (dev, NULL);
  362. kfree (priv);
  363. return -ENODEV;
  364. }
  365. return 0;
  366. }
  367. static void __devexit parport_serial_pci_remove (struct pci_dev *dev)
  368. {
  369. struct parport_serial_private *priv = pci_get_drvdata (dev);
  370. int i;
  371. pci_set_drvdata(dev, NULL);
  372. // Serial ports
  373. if (priv->serial)
  374. pciserial_remove_ports(priv->serial);
  375. // Parallel ports
  376. for (i = 0; i < priv->num_par; i++)
  377. parport_pc_unregister_port (priv->port[i]);
  378. kfree (priv);
  379. return;
  380. }
  381. #ifdef CONFIG_PM
  382. static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state)
  383. {
  384. struct parport_serial_private *priv = pci_get_drvdata(dev);
  385. if (priv->serial)
  386. pciserial_suspend_ports(priv->serial);
  387. /* FIXME: What about parport? */
  388. pci_save_state(dev);
  389. pci_set_power_state(dev, pci_choose_state(dev, state));
  390. return 0;
  391. }
  392. static int parport_serial_pci_resume(struct pci_dev *dev)
  393. {
  394. struct parport_serial_private *priv = pci_get_drvdata(dev);
  395. int err;
  396. pci_set_power_state(dev, PCI_D0);
  397. pci_restore_state(dev);
  398. /*
  399. * The device may have been disabled. Re-enable it.
  400. */
  401. err = pci_enable_device(dev);
  402. if (err) {
  403. printk(KERN_ERR "parport_serial: %s: error enabling "
  404. "device for resume (%d)\n", pci_name(dev), err);
  405. return err;
  406. }
  407. if (priv->serial)
  408. pciserial_resume_ports(priv->serial);
  409. /* FIXME: What about parport? */
  410. return 0;
  411. }
  412. #endif
  413. static struct pci_driver parport_serial_pci_driver = {
  414. .name = "parport_serial",
  415. .id_table = parport_serial_pci_tbl,
  416. .probe = parport_serial_pci_probe,
  417. .remove = __devexit_p(parport_serial_pci_remove),
  418. #ifdef CONFIG_PM
  419. .suspend = parport_serial_pci_suspend,
  420. .resume = parport_serial_pci_resume,
  421. #endif
  422. };
  423. static int __init parport_serial_init (void)
  424. {
  425. return pci_register_driver (&parport_serial_pci_driver);
  426. }
  427. static void __exit parport_serial_exit (void)
  428. {
  429. pci_unregister_driver (&parport_serial_pci_driver);
  430. return;
  431. }
  432. MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
  433. MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
  434. MODULE_LICENSE("GPL");
  435. module_init(parport_serial_init);
  436. module_exit(parport_serial_exit);