blob: 81792e6eeb2d045bf27069a10f58417a84805642 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/************************************************************************
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>
Adrian Bunk2a08b4e2006-04-01 01:04:20 +020023 * Wendy Xiong <wendyx@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
V. ANANDA KRISHNANc2236952005-07-27 11:43:49 -070025 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 ***********************************************************************/
27#include <linux/moduleparam.h>
28#include <linux/pci.h>
29
30#include "jsm.h"
31
32MODULE_AUTHOR("Digi International, http://www.digi.com");
Christoph Hellwig614a7d62005-04-16 15:25:44 -070033MODULE_DESCRIPTION("Driver for the Digi International "
34 "Neo PCI based product line");
35MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -070036MODULE_SUPPORTED_DEVICE("jsm");
37
38#define JSM_DRIVER_NAME "jsm"
39#define NR_PORTS 32
40#define JSM_MINOR_START 0
41
42struct uart_driver jsm_uart_driver = {
43 .owner = THIS_MODULE,
44 .driver_name = JSM_DRIVER_NAME,
45 .dev_name = "ttyn",
V. ANANDA KRISHNAN9539c1d2005-07-27 11:43:48 -070046 .major = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .minor = JSM_MINOR_START,
48 .nr = NR_PORTS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
51int jsm_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052module_param(jsm_debug, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Christoph Hellwig614a7d62005-04-16 15:25:44 -070055static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 struct jsm_board *brd;
Christoph Hellwig614a7d62005-04-16 15:25:44 -070059 static int adapter_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int retval;
61
Christoph Hellwig614a7d62005-04-16 15:25:44 -070062 rc = pci_enable_device(pdev);
63 if (rc) {
64 dev_err(&pdev->dev, "Device enable FAILED\n");
65 goto out;
66 }
67
68 rc = pci_request_regions(pdev, "jsm");
69 if (rc) {
70 dev_err(&pdev->dev, "pci_request_region FAILED\n");
71 goto out_disable_device;
72 }
73
Burman Yan8f31bb32007-02-14 00:33:07 -080074 brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 if (!brd) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -070076 dev_err(&pdev->dev,
77 "memory allocation for board structure failed\n");
78 rc = -ENOMEM;
79 goto out_release_regions;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 /* store the info for the board we've found */
Christoph Hellwig614a7d62005-04-16 15:25:44 -070083 brd->boardnum = adapter_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 brd->pci_dev = pdev;
Christoph Hellwig614a7d62005-04-16 15:25:44 -070085 brd->maxports = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 spin_lock_init(&brd->bd_lock);
88 spin_lock_init(&brd->bd_intr_lock);
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* store which revision we have */
91 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
92
93 brd->irq = pdev->irq;
94
Christoph Hellwig614a7d62005-04-16 15:25:44 -070095 jsm_printk(INIT, INFO, &brd->pci_dev,
96 "jsm_found_board - NEO adapter\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Christoph Hellwig614a7d62005-04-16 15:25:44 -070098 /* get the PCI Base Address Registers */
99 brd->membase = pci_resource_start(pdev, 0);
100 brd->membase_end = pci_resource_end(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700102 if (brd->membase & 1)
103 brd->membase &= ~3;
104 else
105 brd->membase &= ~15;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700107 /* Assign the board_ops struct */
108 brd->bd_ops = &jsm_neo_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700110 brd->bd_uart_offset = 0x200;
111 brd->bd_dividend = 921600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700113 brd->re_map_membase = ioremap(brd->membase, 0x1000);
114 if (!brd->re_map_membase) {
115 dev_err(&pdev->dev,
116 "card has no PCI Memory resources, "
117 "failing board.\n");
118 rc = -ENOMEM;
119 goto out_kfree_brd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700122 rc = request_irq(brd->irq, brd->bd_ops->intr,
Thomas Gleixner40663cc2006-07-01 19:29:43 -0700123 IRQF_DISABLED|IRQF_SHARED, "JSM", brd);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700124 if (rc) {
125 printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
126 goto out_iounmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
129 rc = jsm_tty_init(brd);
130 if (rc < 0) {
131 dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 retval = -ENXIO;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700133 goto out_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
135
136 rc = jsm_uart_port_init(brd);
137 if (rc < 0) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700138 /* XXX: leaking all resources from jsm_tty_init here! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 retval = -ENXIO;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700141 goto out_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* Log the information about the board */
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700145 dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
146 adapter_count, brd->rev, brd->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /*
149 * allocate flip buffer for board.
150 *
151 * Okay to malloc with GFP_KERNEL, we are not at interrupt
152 * context, and there are no locks held.
153 */
Burman Yan8f31bb32007-02-14 00:33:07 -0800154 brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (!brd->flipbuf) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700156 /* XXX: leaking all resources from jsm_tty_init and
157 jsm_uart_port_init here! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 retval = -ENOMEM;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700160 goto out_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700163 pci_set_drvdata(pdev, brd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 return 0;
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700166 out_free_irq:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 free_irq(brd->irq, brd);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700168 out_iounmap:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 iounmap(brd->re_map_membase);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700170 out_kfree_brd:
171 kfree(brd);
172 out_release_regions:
173 pci_release_regions(pdev);
174 out_disable_device:
175 pci_disable_device(pdev);
176 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return rc;
178}
179
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700180static void jsm_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700182 struct jsm_board *brd = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 int i = 0;
184
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700185 jsm_remove_uart_port(brd);
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 free_irq(brd->irq, brd);
188 iounmap(brd->re_map_membase);
189
190 /* Free all allocated channels structs */
191 for (i = 0; i < brd->maxports; i++) {
192 if (brd->channels[i]) {
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700193 kfree(brd->channels[i]->ch_rqueue);
194 kfree(brd->channels[i]->ch_equeue);
195 kfree(brd->channels[i]->ch_wqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 kfree(brd->channels[i]);
197 }
198 }
199
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700200 pci_release_regions(pdev);
201 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 kfree(brd->flipbuf);
203 kfree(brd);
204}
205
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700206static 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 },
211 { 0, }
212};
213MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700215static struct pci_driver jsm_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 .name = "jsm",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 .id_table = jsm_pci_tbl,
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700218 .probe = jsm_probe_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 .remove = __devexit_p(jsm_remove_one),
220};
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static int __init jsm_init_module(void)
223{
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700224 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 rc = uart_register_driver(&jsm_uart_driver);
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700227 if (!rc) {
228 rc = pci_register_driver(&jsm_driver);
229 if (rc)
230 uart_unregister_driver(&jsm_uart_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return rc;
233}
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235static void __exit jsm_exit_module(void)
236{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 pci_unregister_driver(&jsm_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 uart_unregister_driver(&jsm_uart_driver);
239}
Christoph Hellwig614a7d62005-04-16 15:25:44 -0700240
241module_init(jsm_init_module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242module_exit(jsm_exit_module);