parport_serial.c 13 KB

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