jsm_driver.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.ibm.com>
  24. *
  25. *
  26. ***********************************************************************/
  27. #include <linux/moduleparam.h>
  28. #include <linux/pci.h>
  29. #include "jsm.h"
  30. MODULE_AUTHOR("Digi International, http://www.digi.com");
  31. MODULE_DESCRIPTION("Driver for the Digi International "
  32. "Neo PCI based product line");
  33. MODULE_LICENSE("GPL");
  34. MODULE_SUPPORTED_DEVICE("jsm");
  35. #define JSM_DRIVER_NAME "jsm"
  36. #define NR_PORTS 32
  37. #define JSM_MINOR_START 0
  38. struct uart_driver jsm_uart_driver = {
  39. .owner = THIS_MODULE,
  40. .driver_name = JSM_DRIVER_NAME,
  41. .dev_name = "ttyn",
  42. .major = 0,
  43. .minor = JSM_MINOR_START,
  44. .nr = NR_PORTS,
  45. };
  46. int jsm_debug;
  47. module_param(jsm_debug, int, 0);
  48. MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
  49. static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  50. {
  51. int rc = 0;
  52. struct jsm_board *brd;
  53. static int adapter_count = 0;
  54. int retval;
  55. rc = pci_enable_device(pdev);
  56. if (rc) {
  57. dev_err(&pdev->dev, "Device enable FAILED\n");
  58. goto out;
  59. }
  60. rc = pci_request_regions(pdev, "jsm");
  61. if (rc) {
  62. dev_err(&pdev->dev, "pci_request_region FAILED\n");
  63. goto out_disable_device;
  64. }
  65. brd = kmalloc(sizeof(struct jsm_board), GFP_KERNEL);
  66. if (!brd) {
  67. dev_err(&pdev->dev,
  68. "memory allocation for board structure failed\n");
  69. rc = -ENOMEM;
  70. goto out_release_regions;
  71. }
  72. memset(brd, 0, sizeof(struct jsm_board));
  73. /* store the info for the board we've found */
  74. brd->boardnum = adapter_count++;
  75. brd->pci_dev = pdev;
  76. brd->maxports = 2;
  77. spin_lock_init(&brd->bd_lock);
  78. spin_lock_init(&brd->bd_intr_lock);
  79. /* store which revision we have */
  80. pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
  81. brd->irq = pdev->irq;
  82. jsm_printk(INIT, INFO, &brd->pci_dev,
  83. "jsm_found_board - NEO adapter\n");
  84. /* get the PCI Base Address Registers */
  85. brd->membase = pci_resource_start(pdev, 0);
  86. brd->membase_end = pci_resource_end(pdev, 0);
  87. if (brd->membase & 1)
  88. brd->membase &= ~3;
  89. else
  90. brd->membase &= ~15;
  91. /* Assign the board_ops struct */
  92. brd->bd_ops = &jsm_neo_ops;
  93. brd->bd_uart_offset = 0x200;
  94. brd->bd_dividend = 921600;
  95. brd->re_map_membase = ioremap(brd->membase, 0x1000);
  96. if (!brd->re_map_membase) {
  97. dev_err(&pdev->dev,
  98. "card has no PCI Memory resources, "
  99. "failing board.\n");
  100. rc = -ENOMEM;
  101. goto out_kfree_brd;
  102. }
  103. rc = request_irq(brd->irq, brd->bd_ops->intr,
  104. SA_INTERRUPT|SA_SHIRQ, "JSM", brd);
  105. if (rc) {
  106. printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
  107. goto out_iounmap;
  108. }
  109. rc = jsm_tty_init(brd);
  110. if (rc < 0) {
  111. dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
  112. retval = -ENXIO;
  113. goto out_free_irq;
  114. }
  115. rc = jsm_uart_port_init(brd);
  116. if (rc < 0) {
  117. /* XXX: leaking all resources from jsm_tty_init here! */
  118. dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
  119. retval = -ENXIO;
  120. goto out_free_irq;
  121. }
  122. /* Log the information about the board */
  123. dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
  124. adapter_count, brd->rev, brd->irq);
  125. /*
  126. * allocate flip buffer for board.
  127. *
  128. * Okay to malloc with GFP_KERNEL, we are not at interrupt
  129. * context, and there are no locks held.
  130. */
  131. brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
  132. if (!brd->flipbuf) {
  133. /* XXX: leaking all resources from jsm_tty_init and
  134. jsm_uart_port_init here! */
  135. dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
  136. retval = -ENOMEM;
  137. goto out_free_irq;
  138. }
  139. memset(brd->flipbuf, 0, MYFLIPLEN);
  140. pci_set_drvdata(pdev, brd);
  141. return 0;
  142. out_free_irq:
  143. free_irq(brd->irq, brd);
  144. out_iounmap:
  145. iounmap(brd->re_map_membase);
  146. out_kfree_brd:
  147. kfree(brd);
  148. out_release_regions:
  149. pci_release_regions(pdev);
  150. out_disable_device:
  151. pci_disable_device(pdev);
  152. out:
  153. return rc;
  154. }
  155. static void jsm_remove_one(struct pci_dev *pdev)
  156. {
  157. struct jsm_board *brd = pci_get_drvdata(pdev);
  158. int i = 0;
  159. jsm_remove_uart_port(brd);
  160. free_irq(brd->irq, brd);
  161. iounmap(brd->re_map_membase);
  162. /* Free all allocated channels structs */
  163. for (i = 0; i < brd->maxports; i++) {
  164. if (brd->channels[i]) {
  165. kfree(brd->channels[i]->ch_rqueue);
  166. kfree(brd->channels[i]->ch_equeue);
  167. kfree(brd->channels[i]->ch_wqueue);
  168. kfree(brd->channels[i]);
  169. }
  170. }
  171. pci_release_regions(pdev);
  172. pci_disable_device(pdev);
  173. kfree(brd->flipbuf);
  174. kfree(brd);
  175. }
  176. static struct pci_device_id jsm_pci_tbl[] = {
  177. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
  178. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
  179. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
  180. { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
  181. { 0, }
  182. };
  183. MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
  184. static struct pci_driver jsm_driver = {
  185. .name = "jsm",
  186. .id_table = jsm_pci_tbl,
  187. .probe = jsm_probe_one,
  188. .remove = __devexit_p(jsm_remove_one),
  189. };
  190. static int __init jsm_init_module(void)
  191. {
  192. int rc;
  193. rc = uart_register_driver(&jsm_uart_driver);
  194. if (!rc) {
  195. rc = pci_register_driver(&jsm_driver);
  196. if (rc)
  197. uart_unregister_driver(&jsm_uart_driver);
  198. }
  199. return rc;
  200. }
  201. static void __exit jsm_exit_module(void)
  202. {
  203. pci_unregister_driver(&jsm_driver);
  204. uart_unregister_driver(&jsm_uart_driver);
  205. }
  206. module_init(jsm_init_module);
  207. module_exit(jsm_exit_module);