parport_serial.c 13 KB

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