1 /************************************************************************
2 * Copyright 2003 Digi International (www.digi.com)
4 * Copyright (C) 2004 IBM Corporation. All rights reserved.
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)
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.
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,
21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ibm.com>
26 ***********************************************************************/
27 #include <linux/moduleparam.h>
28 #include <linux/pci.h>
32 MODULE_AUTHOR("Digi International, http://www.digi.com");
33 MODULE_DESCRIPTION("Driver for the Digi International "
34 "Neo PCI based product line");
35 MODULE_LICENSE("GPL");
36 MODULE_SUPPORTED_DEVICE("jsm");
38 #define JSM_DRIVER_NAME "jsm"
40 #define JSM_MINOR_START 0
42 struct uart_driver jsm_uart_driver = {
44 .driver_name = JSM_DRIVER_NAME,
47 .minor = JSM_MINOR_START,
52 module_param(jsm_debug, int, 0);
53 MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
55 static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
58 struct jsm_board *brd;
59 static int adapter_count = 0;
62 rc = pci_enable_device(pdev);
64 dev_err(&pdev->dev, "Device enable FAILED\n");
68 rc = pci_request_regions(pdev, "jsm");
70 dev_err(&pdev->dev, "pci_request_region FAILED\n");
71 goto out_disable_device;
74 brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL);
77 "memory allocation for board structure failed\n");
79 goto out_release_regions;
82 /* store the info for the board we've found */
83 brd->boardnum = adapter_count++;
87 spin_lock_init(&brd->bd_lock);
88 spin_lock_init(&brd->bd_intr_lock);
90 /* store which revision we have */
91 brd->rev = pdev->revision;
95 jsm_printk(INIT, INFO, &brd->pci_dev,
96 "jsm_found_board - NEO adapter\n");
98 /* get the PCI Base Address Registers */
99 brd->membase = pci_resource_start(pdev, 0);
100 brd->membase_end = pci_resource_end(pdev, 0);
102 if (brd->membase & 1)
107 /* Assign the board_ops struct */
108 brd->bd_ops = &jsm_neo_ops;
110 brd->bd_uart_offset = 0x200;
111 brd->bd_dividend = 921600;
113 brd->re_map_membase = ioremap(brd->membase, 0x1000);
114 if (!brd->re_map_membase) {
116 "card has no PCI Memory resources, "
122 rc = request_irq(brd->irq, brd->bd_ops->intr,
123 IRQF_DISABLED|IRQF_SHARED, "JSM", brd);
125 printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
129 rc = jsm_tty_init(brd);
131 dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
136 rc = jsm_uart_port_init(brd);
138 /* XXX: leaking all resources from jsm_tty_init here! */
139 dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
144 /* Log the information about the board */
145 dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
146 adapter_count, brd->rev, brd->irq);
149 * allocate flip buffer for board.
151 * Okay to malloc with GFP_KERNEL, we are not at interrupt
152 * context, and there are no locks held.
154 brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
156 /* XXX: leaking all resources from jsm_tty_init and
157 jsm_uart_port_init here! */
158 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
163 pci_set_drvdata(pdev, brd);
167 free_irq(brd->irq, brd);
169 iounmap(brd->re_map_membase);
173 pci_release_regions(pdev);
175 pci_disable_device(pdev);
180 static void jsm_remove_one(struct pci_dev *pdev)
182 struct jsm_board *brd = pci_get_drvdata(pdev);
185 jsm_remove_uart_port(brd);
187 free_irq(brd->irq, brd);
188 iounmap(brd->re_map_membase);
190 /* Free all allocated channels structs */
191 for (i = 0; i < brd->maxports; i++) {
192 if (brd->channels[i]) {
193 kfree(brd->channels[i]->ch_rqueue);
194 kfree(brd->channels[i]->ch_equeue);
195 kfree(brd->channels[i]->ch_wqueue);
196 kfree(brd->channels[i]);
200 pci_release_regions(pdev);
201 pci_disable_device(pdev);
206 static struct pci_device_id jsm_pci_tbl[] = {
207 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
208 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
209 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
210 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
213 MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
215 static struct pci_driver jsm_driver = {
217 .id_table = jsm_pci_tbl,
218 .probe = jsm_probe_one,
219 .remove = __devexit_p(jsm_remove_one),
222 static int __init jsm_init_module(void)
226 rc = uart_register_driver(&jsm_uart_driver);
228 rc = pci_register_driver(&jsm_driver);
230 uart_unregister_driver(&jsm_uart_driver);
235 static void __exit jsm_exit_module(void)
237 pci_unregister_driver(&jsm_driver);
238 uart_unregister_driver(&jsm_uart_driver);
241 module_init(jsm_init_module);
242 module_exit(jsm_exit_module);