jsm_driver.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /************************************************************************
  2. * Copyright 2003 Digi International (www.digi.com)
  3. *
  4. * Copyright (C) 2004 IBM Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  13. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. * PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
  19. * MA 02111-1307, USA.
  20. *
  21. * Contact Information:
  22. * Scott H Kilau <Scott_Kilau@digi.com>
  23. * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com>
  24. *
  25. ***********************************************************************/
  26. #include <linux/moduleparam.h>
  27. #include <linux/pci.h>
  28. #include "jsm.h"
  29. MODULE_AUTHOR("Digi International, http://www.digi.com");
  30. MODULE_DESCRIPTION("Driver for the Digi International "
  31. "Neo PCI based product line");
  32. MODULE_LICENSE("GPL");
  33. MODULE_SUPPORTED_DEVICE("jsm");
  34. #define JSM_DRIVER_NAME "jsm"
  35. #define NR_PORTS 32
  36. #define JSM_MINOR_START 0
  37. struct uart_driver jsm_uart_driver = {
  38. .owner = THIS_MODULE,
  39. .driver_name = JSM_DRIVER_NAME,
  40. .dev_name = "ttyn",
  41. .major = 253,
  42. .minor = JSM_MINOR_START,
  43. .nr = NR_PORTS,
  44. };
  45. int jsm_debug;
  46. int jsm_rawreadok;
  47. module_param(jsm_debug, int, 0);
  48. module_param(jsm_rawreadok, int, 0);
  49. MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
  50. MODULE_PARM_DESC(jsm_rawreadok, "Bypass flip buffers on input");
  51. static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  52. {
  53. int rc = 0;
  54. struct jsm_board *brd;
  55. static int adapter_count = 0;
  56. int retval;
  57. rc = pci_enable_device(pdev);
  58. if (rc) {
  59. dev_err(&pdev->dev, "Device enable FAILED\n");
  60. goto out;
  61. }
  62. rc = pci_request_regions(pdev, "jsm");
  63. if (rc) {
  64. dev_err(&pdev->dev, "pci_request_region FAILED\n");
  65. goto out_disable_device;
  66. }
  67. brd = kmalloc(sizeof(struct jsm_board), GFP_KERNEL);
  68. if (!brd) {
  69. dev_err(&pdev->dev,
  70. "memory allocation for board structure failed\n");
  71. rc = -ENOMEM;
  72. goto out_release_regions;
  73. }
  74. memset(brd, 0, sizeof(struct jsm_board));
  75. /* store the info for the board we've found */
  76. brd->boardnum = adapter_count++;
  77. brd->pci_dev = pdev;
  78. brd->maxports = 2;
  79. spin_lock_init(&brd->bd_lock);
  80. spin_lock_init(&brd->bd_intr_lock);
  81. /* store which revision we have */
  82. pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
  83. brd->irq = pdev->irq;
  84. jsm_printk(INIT, INFO, &brd->pci_dev,
  85. "jsm_found_board - NEO adapter\n");
  86. /* get the PCI Base Address Registers */
  87. brd->membase = pci_resource_start(pdev, 0);
  88. brd->membase_end = pci_resource_end(pdev, 0);
  89. if (brd->membase & 1)
  90. brd->membase &= ~3;
  91. else
  92. brd->membase &= ~15;
  93. /* Assign the board_ops struct */
  94. brd->bd_ops = &jsm_neo_ops;
  95. brd->bd_uart_offset = 0x200;
  96. brd->bd_dividend = 921600;
  97. brd->re_map_membase = ioremap(brd->membase, 0x1000);
  98. if (!brd->re_map_membase) {
  99. dev_err(&pdev->dev,
  100. "card has no PCI Memory resources, "
  101. "failing board.\n");
  102. rc = -ENOMEM;
  103. goto out_kfree_brd;
  104. }
  105. rc = request_irq(brd->irq, brd->bd_ops->intr,
  106. SA_INTERRUPT|SA_SHIRQ, "JSM", brd);
  107. if (rc) {
  108. printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
  109. goto out_iounmap;
  110. }
  111. rc = jsm_tty_init(brd);
  112. if (rc < 0) {
  113. dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
  114. retval = -ENXIO;
  115. goto out_free_irq;
  116. }
  117. rc = jsm_uart_port_init(brd);
  118. if (rc < 0) {
  119. /* XXX: leaking all resources from jsm_tty_init here! */
  120. dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
  121. retval = -ENXIO;
  122. goto out_free_irq;
  123. }
  124. /* Log the information about the board */
  125. dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
  126. adapter_count, brd->rev, brd->irq);
  127. /*
  128. * allocate flip buffer for board.
  129. *
  130. * Okay to malloc with GFP_KERNEL, we are not at interrupt
  131. * context, and there are no locks held.
  132. */
  133. brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
  134. if (!brd->flipbuf) {
  135. /* XXX: leaking all resources from jsm_tty_init and
  136. jsm_uart_port_init here! */
  137. dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
  138. retval = -ENOMEM;
  139. goto out_free_irq;
  140. }
  141. memset(brd->flipbuf, 0, MYFLIPLEN);
  142. pci_set_drvdata(pdev, brd);
  143. return 0;
  144. out_free_irq:
  145. free_irq(brd->irq, brd);
  146. out_iounmap:
  147. iounmap(brd->re_map_membase);
  148. out_kfree_brd:
  149. kfree(brd);
  150. out_release_regions:
  151. pci_release_regions(pdev);
  152. out_disable_device:
  153. pci_disable_device(pdev);
  154. out:
  155. return rc;
  156. }
  157. static void jsm_remove_one(struct pci_dev *pdev)
  158. {
  159. struct jsm_board *brd = pci_get_drvdata(pdev);
  160. int i = 0;
  161. jsm_remove_uart_port(brd);
  162. free_irq(brd->irq, brd);
  163. iounmap(brd->re_map_membase);
  164. /* Free all allocated channels structs */
  165. for (i = 0; i < brd->maxports; i++) {
  166. if (brd->channels[i]) {
  167. kfree(brd->channels[i]->ch_rqueue);
  168. kfree(brd->channels[i]->ch_equeue);
  169. kfree(brd->channels[i]->ch_wqueue);
  170. kfree(brd->channels[i]);
  171. }
  172. }
  173. pci_release_regions(pdev);
  174. pci_disable_device(pdev);
  175. kfree(brd->flipbuf);
  176. kfree(brd);
  177. }
  178. static struct pci_device_id jsm_pci_tbl[] = {
  179. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
  180. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
  181. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
  182. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
  183. { 0, }
  184. };
  185. MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
  186. static struct pci_driver jsm_driver = {
  187. .name = "jsm",
  188. .id_table = jsm_pci_tbl,
  189. .probe = jsm_probe_one,
  190. .remove = __devexit_p(jsm_remove_one),
  191. };
  192. static int __init jsm_init_module(void)
  193. {
  194. int rc;
  195. rc = uart_register_driver(&jsm_uart_driver);
  196. if (!rc) {
  197. rc = pci_register_driver(&jsm_driver);
  198. if (rc)
  199. uart_unregister_driver(&jsm_uart_driver);
  200. }
  201. return rc;
  202. }
  203. static void __exit jsm_exit_module(void)
  204. {
  205. pci_unregister_driver(&jsm_driver);
  206. uart_unregister_driver(&jsm_uart_driver);
  207. }
  208. module_init(jsm_init_module);
  209. module_exit(jsm_exit_module);