parport_serial.c 12 KB

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