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/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/parport.h>
  25. #include <linux/parport_pc.h>
  26. #include <linux/8250_pci.h>
  27. enum parport_pc_pci_cards {
  28. titan_110l = 0,
  29. titan_210l,
  30. netmos_9xx5_combo,
  31. netmos_9855,
  32. netmos_9855_2p,
  33. avlab_1s1p,
  34. avlab_1s2p,
  35. avlab_2s1p,
  36. siig_1s1p_10x,
  37. siig_2s1p_10x,
  38. siig_2p1s_20x,
  39. siig_1s1p_20x,
  40. siig_2s1p_20x,
  41. };
  42. /* each element directly indexed from enum list, above */
  43. struct parport_pc_pci {
  44. int numports;
  45. struct { /* BAR (base address registers) numbers in the config
  46. space header */
  47. int lo;
  48. int hi; /* -1 if not there, >6 for offset-method (max
  49. BAR is 6) */
  50. } addr[4];
  51. /* If set, this is called immediately after pci_enable_device.
  52. * If it returns non-zero, no probing will take place and the
  53. * ports will not be used. */
  54. int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card,
  55. int autoirq, int autodma);
  56. /* If set, this is called after probing for ports. If 'failed'
  57. * is non-zero we couldn't use any of the ports. */
  58. void (*postinit_hook) (struct pci_dev *pdev,
  59. struct parport_pc_pci *card, int failed);
  60. };
  61. static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *par, int autoirq, int autodma)
  62. {
  63. /* the rule described below doesn't hold for this device */
  64. if (dev->device == PCI_DEVICE_ID_NETMOS_9835 &&
  65. dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
  66. dev->subsystem_device == 0x0299)
  67. return -ENODEV;
  68. /*
  69. * Netmos uses the subdevice ID to indicate the number of parallel
  70. * and serial ports. The form is 0x00PS, where <P> is the number of
  71. * parallel ports and <S> is the number of serial ports.
  72. */
  73. par->numports = (dev->subsystem_device & 0xf0) >> 4;
  74. if (par->numports > ARRAY_SIZE(par->addr))
  75. par->numports = ARRAY_SIZE(par->addr);
  76. /*
  77. * This function is currently only called for cards with up to
  78. * one parallel port.
  79. * Parallel port BAR is either before or after serial ports BARS;
  80. * hence, lo should be either 0 or equal to the number of serial ports.
  81. */
  82. if (par->addr[0].lo != 0)
  83. par->addr[0].lo = dev->subsystem_device & 0xf;
  84. return 0;
  85. }
  86. static struct parport_pc_pci cards[] __devinitdata = {
  87. /* titan_110l */ { 1, { { 3, -1 }, } },
  88. /* titan_210l */ { 1, { { 3, -1 }, } },
  89. /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
  90. /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
  91. /* netmos_9855_2p */ { 2, { { 0, -1 }, { 2, -1 }, } },
  92. /* avlab_1s1p */ { 1, { { 1, 2}, } },
  93. /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
  94. /* avlab_2s1p */ { 1, { { 2, 3}, } },
  95. /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
  96. /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
  97. /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
  98. /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
  99. /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
  100. };
  101. static struct pci_device_id parport_serial_pci_tbl[] = {
  102. /* PCI cards */
  103. { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
  104. PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
  105. { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
  106. PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
  107. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
  108. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  109. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
  110. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  111. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
  112. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  113. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
  114. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  115. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  116. 0x1000, 0x0020, 0, 0, netmos_9855_2p },
  117. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  118. 0x1000, 0x0022, 0, 0, netmos_9855_2p },
  119. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  120. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
  121. /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
  122. { PCI_VENDOR_ID_AFAVLAB, 0x2110,
  123. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  124. { PCI_VENDOR_ID_AFAVLAB, 0x2111,
  125. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  126. { PCI_VENDOR_ID_AFAVLAB, 0x2112,
  127. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  128. { PCI_VENDOR_ID_AFAVLAB, 0x2140,
  129. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  130. { PCI_VENDOR_ID_AFAVLAB, 0x2141,
  131. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  132. { PCI_VENDOR_ID_AFAVLAB, 0x2142,
  133. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  134. { PCI_VENDOR_ID_AFAVLAB, 0x2160,
  135. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  136. { PCI_VENDOR_ID_AFAVLAB, 0x2161,
  137. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  138. { PCI_VENDOR_ID_AFAVLAB, 0x2162,
  139. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  140. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
  141. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  142. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
  143. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  144. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
  145. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  146. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
  147. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  148. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
  149. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  150. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
  151. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  152. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
  153. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  154. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
  155. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  156. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
  157. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  158. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
  159. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  160. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
  161. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
  162. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
  163. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
  164. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
  165. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  166. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
  167. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  168. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
  169. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  170. { 0, } /* terminate list */
  171. };
  172. MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
  173. /*
  174. * This table describes the serial "geometry" of these boards. Any
  175. * quirks for these can be found in drivers/serial/8250_pci.c
  176. *
  177. * Cards not tested are marked n/t
  178. * If you have one of these cards and it works for you, please tell me..
  179. */
  180. static struct pciserial_board pci_parport_serial_boards[] __devinitdata = {
  181. [titan_110l] = {
  182. .flags = FL_BASE1 | FL_BASE_BARS,
  183. .num_ports = 1,
  184. .base_baud = 921600,
  185. .uart_offset = 8,
  186. },
  187. [titan_210l] = {
  188. .flags = FL_BASE1 | FL_BASE_BARS,
  189. .num_ports = 2,
  190. .base_baud = 921600,
  191. .uart_offset = 8,
  192. },
  193. [netmos_9xx5_combo] = {
  194. .flags = FL_BASE0 | FL_BASE_BARS,
  195. .num_ports = 1,
  196. .base_baud = 115200,
  197. .uart_offset = 8,
  198. },
  199. [netmos_9855] = {
  200. .flags = FL_BASE2 | FL_BASE_BARS,
  201. .num_ports = 1,
  202. .base_baud = 115200,
  203. .uart_offset = 8,
  204. },
  205. [netmos_9855_2p] = {
  206. .flags = FL_BASE4 | FL_BASE_BARS,
  207. .num_ports = 1,
  208. .base_baud = 115200,
  209. .uart_offset = 8,
  210. },
  211. [avlab_1s1p] = { /* n/t */
  212. .flags = FL_BASE0 | FL_BASE_BARS,
  213. .num_ports = 1,
  214. .base_baud = 115200,
  215. .uart_offset = 8,
  216. },
  217. [avlab_1s2p] = { /* n/t */
  218. .flags = FL_BASE0 | FL_BASE_BARS,
  219. .num_ports = 1,
  220. .base_baud = 115200,
  221. .uart_offset = 8,
  222. },
  223. [avlab_2s1p] = { /* n/t */
  224. .flags = FL_BASE0 | FL_BASE_BARS,
  225. .num_ports = 2,
  226. .base_baud = 115200,
  227. .uart_offset = 8,
  228. },
  229. [siig_1s1p_10x] = {
  230. .flags = FL_BASE2,
  231. .num_ports = 1,
  232. .base_baud = 460800,
  233. .uart_offset = 8,
  234. },
  235. [siig_2s1p_10x] = {
  236. .flags = FL_BASE2,
  237. .num_ports = 1,
  238. .base_baud = 921600,
  239. .uart_offset = 8,
  240. },
  241. [siig_2p1s_20x] = {
  242. .flags = FL_BASE0,
  243. .num_ports = 1,
  244. .base_baud = 921600,
  245. .uart_offset = 8,
  246. },
  247. [siig_1s1p_20x] = {
  248. .flags = FL_BASE0,
  249. .num_ports = 1,
  250. .base_baud = 921600,
  251. .uart_offset = 8,
  252. },
  253. [siig_2s1p_20x] = {
  254. .flags = FL_BASE0,
  255. .num_ports = 1,
  256. .base_baud = 921600,
  257. .uart_offset = 8,
  258. },
  259. };
  260. struct parport_serial_private {
  261. struct serial_private *serial;
  262. int num_par;
  263. struct parport *port[PARPORT_MAX];
  264. struct parport_pc_pci par;
  265. };
  266. /* Register the serial port(s) of a PCI card. */
  267. static int __devinit serial_register (struct pci_dev *dev,
  268. const struct pci_device_id *id)
  269. {
  270. struct parport_serial_private *priv = pci_get_drvdata (dev);
  271. struct pciserial_board *board;
  272. struct serial_private *serial;
  273. board = &pci_parport_serial_boards[id->driver_data];
  274. serial = pciserial_init_ports(dev, board);
  275. if (IS_ERR(serial))
  276. return PTR_ERR(serial);
  277. priv->serial = serial;
  278. return 0;
  279. }
  280. /* Register the parallel port(s) of a PCI card. */
  281. static int __devinit parport_register (struct pci_dev *dev,
  282. const struct pci_device_id *id)
  283. {
  284. struct parport_pc_pci *card;
  285. struct parport_serial_private *priv = pci_get_drvdata (dev);
  286. int n, success = 0;
  287. priv->par = cards[id->driver_data];
  288. card = &priv->par;
  289. if (card->preinit_hook &&
  290. card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
  291. return -ENODEV;
  292. for (n = 0; n < card->numports; n++) {
  293. struct parport *port;
  294. int lo = card->addr[n].lo;
  295. int hi = card->addr[n].hi;
  296. unsigned long io_lo, io_hi;
  297. int irq;
  298. if (priv->num_par == ARRAY_SIZE (priv->port)) {
  299. printk (KERN_WARNING
  300. "parport_serial: %s: only %zu parallel ports "
  301. "supported (%d reported)\n", pci_name (dev),
  302. ARRAY_SIZE(priv->port), card->numports);
  303. break;
  304. }
  305. io_lo = pci_resource_start (dev, lo);
  306. io_hi = 0;
  307. if ((hi >= 0) && (hi <= 6))
  308. io_hi = pci_resource_start (dev, hi);
  309. else if (hi > 6)
  310. io_lo += hi; /* Reinterpret the meaning of
  311. "hi" as an offset (see SYBA
  312. def.) */
  313. /* TODO: test if sharing interrupts works */
  314. irq = dev->irq;
  315. if (irq == IRQ_NONE) {
  316. dev_dbg(&dev->dev,
  317. "PCI parallel port detected: I/O at %#lx(%#lx)\n",
  318. io_lo, io_hi);
  319. irq = PARPORT_IRQ_NONE;
  320. } else {
  321. dev_dbg(&dev->dev,
  322. "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
  323. io_lo, io_hi, irq);
  324. irq = PARPORT_IRQ_NONE;
  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);