parport_serial.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Support for common PCI multi-I/O cards (which is most of them)
  4. *
  5. * Copyright (C) 2001 Tim Waugh <twaugh@redhat.com>
  6. *
  7. * Multi-function PCI cards are supposed to present separate logical
  8. * devices on the bus. A common thing to do seems to be to just use
  9. * one logical device with lots of base address registers for both
  10. * parallel ports and serial ports. This driver is for dealing with
  11. * that.
  12. */
  13. #include <linux/interrupt.h>
  14. #include <linux/module.h>
  15. #include <linux/parport.h>
  16. #include <linux/parport_pc.h>
  17. #include <linux/pci.h>
  18. #include <linux/slab.h>
  19. #include <linux/types.h>
  20. #include <linux/8250_pci.h>
  21. enum parport_pc_pci_cards {
  22. titan_110l = 0,
  23. titan_210l,
  24. netmos_9xx5_combo,
  25. netmos_9855,
  26. netmos_9855_2p,
  27. netmos_9900,
  28. netmos_9900_2p,
  29. netmos_99xx_1p,
  30. avlab_1s1p,
  31. avlab_1s2p,
  32. avlab_2s1p,
  33. siig_1s1p_10x,
  34. siig_2s1p_10x,
  35. siig_2p1s_20x,
  36. siig_1s1p_20x,
  37. siig_2s1p_20x,
  38. timedia_4078a,
  39. timedia_4079h,
  40. timedia_4085h,
  41. timedia_4088a,
  42. timedia_4089a,
  43. timedia_4095a,
  44. timedia_4096a,
  45. timedia_4078u,
  46. timedia_4079a,
  47. timedia_4085u,
  48. timedia_4079r,
  49. timedia_4079s,
  50. timedia_4079d,
  51. timedia_4079e,
  52. timedia_4079f,
  53. timedia_9079a,
  54. timedia_9079b,
  55. timedia_9079c,
  56. wch_ch353_1s1p,
  57. wch_ch353_2s1p,
  58. wch_ch382_0s1p,
  59. wch_ch382_2s1p,
  60. brainboxes_5s1p,
  61. sunix_2s1p,
  62. };
  63. /* each element directly indexed from enum list, above */
  64. struct parport_pc_pci {
  65. int numports;
  66. struct { /* BAR (base address registers) numbers in the config
  67. space header */
  68. int lo;
  69. int hi; /* -1 if not there, >6 for offset-method (max
  70. BAR is 6) */
  71. } addr[4];
  72. /* If set, this is called immediately after pci_enable_device.
  73. * If it returns non-zero, no probing will take place and the
  74. * ports will not be used. */
  75. int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card,
  76. int autoirq, int autodma);
  77. /* If set, this is called after probing for ports. If 'failed'
  78. * is non-zero we couldn't use any of the ports. */
  79. void (*postinit_hook) (struct pci_dev *pdev,
  80. struct parport_pc_pci *card, int failed);
  81. };
  82. static int netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *par,
  83. int autoirq, int autodma)
  84. {
  85. /* the rule described below doesn't hold for this device */
  86. if (dev->device == PCI_DEVICE_ID_NETMOS_9835 &&
  87. dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
  88. dev->subsystem_device == 0x0299)
  89. return -ENODEV;
  90. if (dev->device == PCI_DEVICE_ID_NETMOS_9912) {
  91. par->numports = 1;
  92. } else {
  93. /*
  94. * Netmos uses the subdevice ID to indicate the number of parallel
  95. * and serial ports. The form is 0x00PS, where <P> is the number of
  96. * parallel ports and <S> is the number of serial ports.
  97. */
  98. par->numports = (dev->subsystem_device & 0xf0) >> 4;
  99. if (par->numports > ARRAY_SIZE(par->addr))
  100. par->numports = ARRAY_SIZE(par->addr);
  101. }
  102. return 0;
  103. }
  104. static struct parport_pc_pci cards[] = {
  105. /* titan_110l */ { 1, { { 3, -1 }, } },
  106. /* titan_210l */ { 1, { { 3, -1 }, } },
  107. /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init },
  108. /* netmos_9855 */ { 1, { { 0, -1 }, }, netmos_parallel_init },
  109. /* netmos_9855_2p */ { 2, { { 0, -1 }, { 2, -1 }, } },
  110. /* netmos_9900 */ {1, { { 3, 4 }, }, netmos_parallel_init },
  111. /* netmos_9900_2p */ {2, { { 0, 1 }, { 3, 4 }, } },
  112. /* netmos_99xx_1p */ {1, { { 0, 1 }, } },
  113. /* avlab_1s1p */ { 1, { { 1, 2}, } },
  114. /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} },
  115. /* avlab_2s1p */ { 1, { { 2, 3}, } },
  116. /* siig_1s1p_10x */ { 1, { { 3, 4 }, } },
  117. /* siig_2s1p_10x */ { 1, { { 4, 5 }, } },
  118. /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } },
  119. /* siig_1s1p_20x */ { 1, { { 1, 2 }, } },
  120. /* siig_2s1p_20x */ { 1, { { 2, 3 }, } },
  121. /* timedia_4078a */ { 1, { { 2, -1 }, } },
  122. /* timedia_4079h */ { 1, { { 2, 3 }, } },
  123. /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
  124. /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
  125. /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
  126. /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
  127. /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
  128. /* timedia_4078u */ { 1, { { 2, -1 }, } },
  129. /* timedia_4079a */ { 1, { { 2, 3 }, } },
  130. /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
  131. /* timedia_4079r */ { 1, { { 2, 3 }, } },
  132. /* timedia_4079s */ { 1, { { 2, 3 }, } },
  133. /* timedia_4079d */ { 1, { { 2, 3 }, } },
  134. /* timedia_4079e */ { 1, { { 2, 3 }, } },
  135. /* timedia_4079f */ { 1, { { 2, 3 }, } },
  136. /* timedia_9079a */ { 1, { { 2, 3 }, } },
  137. /* timedia_9079b */ { 1, { { 2, 3 }, } },
  138. /* timedia_9079c */ { 1, { { 2, 3 }, } },
  139. /* wch_ch353_1s1p*/ { 1, { { 1, -1}, } },
  140. /* wch_ch353_2s1p*/ { 1, { { 2, -1}, } },
  141. /* wch_ch382_0s1p*/ { 1, { { 2, -1}, } },
  142. /* wch_ch382_2s1p*/ { 1, { { 2, -1}, } },
  143. /* brainboxes_5s1p */ { 1, { { 3, -1 }, } },
  144. /* sunix_2s1p */ { 1, { { 3, -1 }, } },
  145. };
  146. static struct pci_device_id parport_serial_pci_tbl[] = {
  147. /* PCI cards */
  148. { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L,
  149. PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l },
  150. { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L,
  151. PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l },
  152. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
  153. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  154. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745,
  155. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  156. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
  157. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  158. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
  159. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
  160. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  161. 0x1000, 0x0020, 0, 0, netmos_9855_2p },
  162. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  163. 0x1000, 0x0022, 0, 0, netmos_9855_2p },
  164. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
  165. PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
  166. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
  167. 0xA000, 0x3011, 0, 0, netmos_9900 },
  168. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
  169. 0xA000, 0x3012, 0, 0, netmos_9900 },
  170. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
  171. 0xA000, 0x3020, 0, 0, netmos_9900_2p },
  172. { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9912,
  173. 0xA000, 0x2000, 0, 0, netmos_99xx_1p },
  174. /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
  175. { PCI_VENDOR_ID_AFAVLAB, 0x2110,
  176. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  177. { PCI_VENDOR_ID_AFAVLAB, 0x2111,
  178. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  179. { PCI_VENDOR_ID_AFAVLAB, 0x2112,
  180. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p },
  181. { PCI_VENDOR_ID_AFAVLAB, 0x2140,
  182. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  183. { PCI_VENDOR_ID_AFAVLAB, 0x2141,
  184. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  185. { PCI_VENDOR_ID_AFAVLAB, 0x2142,
  186. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p },
  187. { PCI_VENDOR_ID_AFAVLAB, 0x2160,
  188. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  189. { PCI_VENDOR_ID_AFAVLAB, 0x2161,
  190. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  191. { PCI_VENDOR_ID_AFAVLAB, 0x2162,
  192. PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p },
  193. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
  194. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  195. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
  196. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  197. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
  198. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x },
  199. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
  200. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  201. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
  202. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  203. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
  204. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x },
  205. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
  206. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  207. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
  208. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  209. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
  210. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x },
  211. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
  212. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  213. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
  214. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
  215. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
  216. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x },
  217. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
  218. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  219. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
  220. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  221. { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
  222. PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x },
  223. /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
  224. { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
  225. { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
  226. { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
  227. { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
  228. { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
  229. { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
  230. { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
  231. { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
  232. { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
  233. { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
  234. { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
  235. { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
  236. { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
  237. { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
  238. { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
  239. { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
  240. { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
  241. { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
  242. /* WCH CARDS */
  243. { 0x4348, 0x5053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, wch_ch353_1s1p},
  244. { 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p},
  245. { 0x1c00, 0x3050, 0x1c00, 0x3050, 0, 0, wch_ch382_0s1p},
  246. { 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p},
  247. /* BrainBoxes PX272/PX306 MIO card */
  248. { PCI_VENDOR_ID_INTASHIELD, 0x4100,
  249. PCI_ANY_ID, PCI_ANY_ID, 0, 0, brainboxes_5s1p },
  250. /*
  251. * More SUNIX variations. At least one of these has part number
  252. * '5079A but subdevice 0x102. That board reports 0x0708 as
  253. * its PCI Class.
  254. */
  255. { PCI_VENDOR_ID_SUNIX, PCI_DEVICE_ID_SUNIX_1999, PCI_VENDOR_ID_SUNIX,
  256. 0x0102, 0, 0, sunix_2s1p },
  257. { 0, } /* terminate list */
  258. };
  259. MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl);
  260. /*
  261. * This table describes the serial "geometry" of these boards. Any
  262. * quirks for these can be found in drivers/serial/8250_pci.c
  263. *
  264. * Cards not tested are marked n/t
  265. * If you have one of these cards and it works for you, please tell me..
  266. */
  267. static struct pciserial_board pci_parport_serial_boards[] = {
  268. [titan_110l] = {
  269. .flags = FL_BASE1 | FL_BASE_BARS,
  270. .num_ports = 1,
  271. .base_baud = 921600,
  272. .uart_offset = 8,
  273. },
  274. [titan_210l] = {
  275. .flags = FL_BASE1 | FL_BASE_BARS,
  276. .num_ports = 2,
  277. .base_baud = 921600,
  278. .uart_offset = 8,
  279. },
  280. [netmos_9xx5_combo] = {
  281. .flags = FL_BASE0 | FL_BASE_BARS,
  282. .num_ports = 1,
  283. .base_baud = 115200,
  284. .uart_offset = 8,
  285. },
  286. [netmos_9855] = {
  287. .flags = FL_BASE2 | FL_BASE_BARS,
  288. .num_ports = 1,
  289. .base_baud = 115200,
  290. .uart_offset = 8,
  291. },
  292. [netmos_9855_2p] = {
  293. .flags = FL_BASE4 | FL_BASE_BARS,
  294. .num_ports = 1,
  295. .base_baud = 115200,
  296. .uart_offset = 8,
  297. },
  298. [netmos_9900] = { /* n/t */
  299. .flags = FL_BASE0 | FL_BASE_BARS,
  300. .num_ports = 1,
  301. .base_baud = 115200,
  302. .uart_offset = 8,
  303. },
  304. [netmos_9900_2p] = { /* parallel only */ /* n/t */
  305. .flags = FL_BASE0,
  306. .num_ports = 0,
  307. .base_baud = 115200,
  308. .uart_offset = 8,
  309. },
  310. [netmos_99xx_1p] = { /* parallel only */ /* n/t */
  311. .flags = FL_BASE0,
  312. .num_ports = 0,
  313. .base_baud = 115200,
  314. .uart_offset = 8,
  315. },
  316. [avlab_1s1p] = { /* n/t */
  317. .flags = FL_BASE0 | FL_BASE_BARS,
  318. .num_ports = 1,
  319. .base_baud = 115200,
  320. .uart_offset = 8,
  321. },
  322. [avlab_1s2p] = { /* n/t */
  323. .flags = FL_BASE0 | FL_BASE_BARS,
  324. .num_ports = 1,
  325. .base_baud = 115200,
  326. .uart_offset = 8,
  327. },
  328. [avlab_2s1p] = { /* n/t */
  329. .flags = FL_BASE0 | FL_BASE_BARS,
  330. .num_ports = 2,
  331. .base_baud = 115200,
  332. .uart_offset = 8,
  333. },
  334. [siig_1s1p_10x] = {
  335. .flags = FL_BASE2,
  336. .num_ports = 1,
  337. .base_baud = 460800,
  338. .uart_offset = 8,
  339. },
  340. [siig_2s1p_10x] = {
  341. .flags = FL_BASE2,
  342. .num_ports = 1,
  343. .base_baud = 921600,
  344. .uart_offset = 8,
  345. },
  346. [siig_2p1s_20x] = {
  347. .flags = FL_BASE0,
  348. .num_ports = 1,
  349. .base_baud = 921600,
  350. .uart_offset = 8,
  351. },
  352. [siig_1s1p_20x] = {
  353. .flags = FL_BASE0,
  354. .num_ports = 1,
  355. .base_baud = 921600,
  356. .uart_offset = 8,
  357. },
  358. [siig_2s1p_20x] = {
  359. .flags = FL_BASE0,
  360. .num_ports = 1,
  361. .base_baud = 921600,
  362. .uart_offset = 8,
  363. },
  364. [timedia_4078a] = {
  365. .flags = FL_BASE0|FL_BASE_BARS,
  366. .num_ports = 1,
  367. .base_baud = 921600,
  368. .uart_offset = 8,
  369. },
  370. [timedia_4079h] = {
  371. .flags = FL_BASE0|FL_BASE_BARS,
  372. .num_ports = 1,
  373. .base_baud = 921600,
  374. .uart_offset = 8,
  375. },
  376. [timedia_4085h] = {
  377. .flags = FL_BASE0|FL_BASE_BARS,
  378. .num_ports = 1,
  379. .base_baud = 921600,
  380. .uart_offset = 8,
  381. },
  382. [timedia_4088a] = {
  383. .flags = FL_BASE0|FL_BASE_BARS,
  384. .num_ports = 1,
  385. .base_baud = 921600,
  386. .uart_offset = 8,
  387. },
  388. [timedia_4089a] = {
  389. .flags = FL_BASE0|FL_BASE_BARS,
  390. .num_ports = 1,
  391. .base_baud = 921600,
  392. .uart_offset = 8,
  393. },
  394. [timedia_4095a] = {
  395. .flags = FL_BASE0|FL_BASE_BARS,
  396. .num_ports = 1,
  397. .base_baud = 921600,
  398. .uart_offset = 8,
  399. },
  400. [timedia_4096a] = {
  401. .flags = FL_BASE0|FL_BASE_BARS,
  402. .num_ports = 1,
  403. .base_baud = 921600,
  404. .uart_offset = 8,
  405. },
  406. [timedia_4078u] = {
  407. .flags = FL_BASE0|FL_BASE_BARS,
  408. .num_ports = 1,
  409. .base_baud = 921600,
  410. .uart_offset = 8,
  411. },
  412. [timedia_4079a] = {
  413. .flags = FL_BASE0|FL_BASE_BARS,
  414. .num_ports = 1,
  415. .base_baud = 921600,
  416. .uart_offset = 8,
  417. },
  418. [timedia_4085u] = {
  419. .flags = FL_BASE0|FL_BASE_BARS,
  420. .num_ports = 1,
  421. .base_baud = 921600,
  422. .uart_offset = 8,
  423. },
  424. [timedia_4079r] = {
  425. .flags = FL_BASE0|FL_BASE_BARS,
  426. .num_ports = 1,
  427. .base_baud = 921600,
  428. .uart_offset = 8,
  429. },
  430. [timedia_4079s] = {
  431. .flags = FL_BASE0|FL_BASE_BARS,
  432. .num_ports = 1,
  433. .base_baud = 921600,
  434. .uart_offset = 8,
  435. },
  436. [timedia_4079d] = {
  437. .flags = FL_BASE0|FL_BASE_BARS,
  438. .num_ports = 1,
  439. .base_baud = 921600,
  440. .uart_offset = 8,
  441. },
  442. [timedia_4079e] = {
  443. .flags = FL_BASE0|FL_BASE_BARS,
  444. .num_ports = 1,
  445. .base_baud = 921600,
  446. .uart_offset = 8,
  447. },
  448. [timedia_4079f] = {
  449. .flags = FL_BASE0|FL_BASE_BARS,
  450. .num_ports = 1,
  451. .base_baud = 921600,
  452. .uart_offset = 8,
  453. },
  454. [timedia_9079a] = {
  455. .flags = FL_BASE0|FL_BASE_BARS,
  456. .num_ports = 1,
  457. .base_baud = 921600,
  458. .uart_offset = 8,
  459. },
  460. [timedia_9079b] = {
  461. .flags = FL_BASE0|FL_BASE_BARS,
  462. .num_ports = 1,
  463. .base_baud = 921600,
  464. .uart_offset = 8,
  465. },
  466. [timedia_9079c] = {
  467. .flags = FL_BASE0|FL_BASE_BARS,
  468. .num_ports = 1,
  469. .base_baud = 921600,
  470. .uart_offset = 8,
  471. },
  472. [wch_ch353_1s1p] = {
  473. .flags = FL_BASE0|FL_BASE_BARS,
  474. .num_ports = 1,
  475. .base_baud = 115200,
  476. .uart_offset = 8,
  477. },
  478. [wch_ch353_2s1p] = {
  479. .flags = FL_BASE0|FL_BASE_BARS,
  480. .num_ports = 2,
  481. .base_baud = 115200,
  482. .uart_offset = 8,
  483. },
  484. [wch_ch382_0s1p] = {
  485. .flags = FL_BASE0,
  486. .num_ports = 0,
  487. .base_baud = 115200,
  488. .uart_offset = 8,
  489. },
  490. [wch_ch382_2s1p] = {
  491. .flags = FL_BASE0,
  492. .num_ports = 2,
  493. .base_baud = 115200,
  494. .uart_offset = 8,
  495. .first_offset = 0xC0,
  496. },
  497. [brainboxes_5s1p] = {
  498. .flags = FL_BASE2,
  499. .num_ports = 5,
  500. .base_baud = 921600,
  501. .uart_offset = 8,
  502. },
  503. [sunix_2s1p] = {
  504. .flags = FL_BASE0|FL_BASE_BARS,
  505. .num_ports = 2,
  506. .base_baud = 921600,
  507. .uart_offset = 8,
  508. },
  509. };
  510. struct parport_serial_private {
  511. struct serial_private *serial;
  512. int num_par;
  513. struct parport *port[PARPORT_MAX];
  514. struct parport_pc_pci par;
  515. };
  516. /* Register the serial port(s) of a PCI card. */
  517. static int serial_register(struct pci_dev *dev, const struct pci_device_id *id)
  518. {
  519. struct parport_serial_private *priv = pci_get_drvdata (dev);
  520. struct pciserial_board *board;
  521. struct serial_private *serial;
  522. board = &pci_parport_serial_boards[id->driver_data];
  523. if (board->num_ports == 0)
  524. return 0;
  525. serial = pciserial_init_ports(dev, board);
  526. if (IS_ERR(serial))
  527. return PTR_ERR(serial);
  528. priv->serial = serial;
  529. return 0;
  530. }
  531. /* Register the parallel port(s) of a PCI card. */
  532. static int parport_register(struct pci_dev *dev, const struct pci_device_id *id)
  533. {
  534. struct parport_pc_pci *card;
  535. struct parport_serial_private *priv = pci_get_drvdata (dev);
  536. int n, success = 0;
  537. priv->par = cards[id->driver_data];
  538. card = &priv->par;
  539. if (card->preinit_hook &&
  540. card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
  541. return -ENODEV;
  542. for (n = 0; n < card->numports; n++) {
  543. struct parport *port;
  544. int lo = card->addr[n].lo;
  545. int hi = card->addr[n].hi;
  546. unsigned long io_lo, io_hi;
  547. int irq;
  548. if (priv->num_par == ARRAY_SIZE (priv->port)) {
  549. dev_warn(&dev->dev,
  550. "only %zu parallel ports supported (%d reported)\n",
  551. ARRAY_SIZE(priv->port), card->numports);
  552. break;
  553. }
  554. io_lo = pci_resource_start (dev, lo);
  555. io_hi = 0;
  556. if ((hi >= 0) && (hi <= 6))
  557. io_hi = pci_resource_start (dev, hi);
  558. else if (hi > 6)
  559. io_lo += hi; /* Reinterpret the meaning of
  560. "hi" as an offset (see SYBA
  561. def.) */
  562. /* TODO: test if sharing interrupts works */
  563. irq = dev->irq;
  564. if (irq == IRQ_NONE) {
  565. dev_dbg(&dev->dev,
  566. "PCI parallel port detected: I/O at %#lx(%#lx)\n",
  567. io_lo, io_hi);
  568. irq = PARPORT_IRQ_NONE;
  569. } else {
  570. dev_dbg(&dev->dev,
  571. "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
  572. io_lo, io_hi, irq);
  573. }
  574. port = parport_pc_probe_port (io_lo, io_hi, irq,
  575. PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED);
  576. if (port) {
  577. priv->port[priv->num_par++] = port;
  578. success = 1;
  579. }
  580. }
  581. if (card->postinit_hook)
  582. card->postinit_hook (dev, card, !success);
  583. return 0;
  584. }
  585. static int parport_serial_pci_probe(struct pci_dev *dev,
  586. const struct pci_device_id *id)
  587. {
  588. struct parport_serial_private *priv;
  589. int err;
  590. priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
  591. if (!priv)
  592. return -ENOMEM;
  593. pci_set_drvdata (dev, priv);
  594. err = pcim_enable_device(dev);
  595. if (err)
  596. return err;
  597. err = parport_register(dev, id);
  598. if (err)
  599. return err;
  600. err = serial_register(dev, id);
  601. if (err) {
  602. int i;
  603. for (i = 0; i < priv->num_par; i++)
  604. parport_pc_unregister_port (priv->port[i]);
  605. return err;
  606. }
  607. return 0;
  608. }
  609. static void parport_serial_pci_remove(struct pci_dev *dev)
  610. {
  611. struct parport_serial_private *priv = pci_get_drvdata (dev);
  612. int i;
  613. // Serial ports
  614. if (priv->serial)
  615. pciserial_remove_ports(priv->serial);
  616. // Parallel ports
  617. for (i = 0; i < priv->num_par; i++)
  618. parport_pc_unregister_port (priv->port[i]);
  619. return;
  620. }
  621. static int __maybe_unused parport_serial_pci_suspend(struct device *dev)
  622. {
  623. struct pci_dev *pdev = to_pci_dev(dev);
  624. struct parport_serial_private *priv = pci_get_drvdata(pdev);
  625. if (priv->serial)
  626. pciserial_suspend_ports(priv->serial);
  627. /* FIXME: What about parport? */
  628. return 0;
  629. }
  630. static int __maybe_unused parport_serial_pci_resume(struct device *dev)
  631. {
  632. struct pci_dev *pdev = to_pci_dev(dev);
  633. struct parport_serial_private *priv = pci_get_drvdata(pdev);
  634. if (priv->serial)
  635. pciserial_resume_ports(priv->serial);
  636. /* FIXME: What about parport? */
  637. return 0;
  638. }
  639. static SIMPLE_DEV_PM_OPS(parport_serial_pm_ops,
  640. parport_serial_pci_suspend, parport_serial_pci_resume);
  641. static struct pci_driver parport_serial_pci_driver = {
  642. .name = "parport_serial",
  643. .id_table = parport_serial_pci_tbl,
  644. .probe = parport_serial_pci_probe,
  645. .remove = parport_serial_pci_remove,
  646. .driver = {
  647. .pm = &parport_serial_pm_ops,
  648. },
  649. };
  650. module_pci_driver(parport_serial_pci_driver);
  651. MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>");
  652. MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards");
  653. MODULE_LICENSE("GPL");