[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / serial / jsm / jsm_driver.c
blob7e56c78241945975081657176342f0416c935cd7
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)
9 * any later version.
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,
19 * MA 02111-1307, USA.
21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com>
26 ***********************************************************************/
27 #include <linux/moduleparam.h>
28 #include <linux/pci.h>
30 #include "jsm.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"
39 #define NR_PORTS 32
40 #define JSM_MINOR_START 0
42 struct uart_driver jsm_uart_driver = {
43 .owner = THIS_MODULE,
44 .driver_name = JSM_DRIVER_NAME,
45 .dev_name = "ttyn",
46 .major = 0,
47 .minor = JSM_MINOR_START,
48 .nr = NR_PORTS,
51 int jsm_debug;
52 int jsm_rawreadok;
53 module_param(jsm_debug, int, 0);
54 module_param(jsm_rawreadok, int, 0);
55 MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
56 MODULE_PARM_DESC(jsm_rawreadok, "Bypass flip buffers on input");
58 static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
60 int rc = 0;
61 struct jsm_board *brd;
62 static int adapter_count = 0;
63 int retval;
65 rc = pci_enable_device(pdev);
66 if (rc) {
67 dev_err(&pdev->dev, "Device enable FAILED\n");
68 goto out;
71 rc = pci_request_regions(pdev, "jsm");
72 if (rc) {
73 dev_err(&pdev->dev, "pci_request_region FAILED\n");
74 goto out_disable_device;
77 brd = kmalloc(sizeof(struct jsm_board), GFP_KERNEL);
78 if (!brd) {
79 dev_err(&pdev->dev,
80 "memory allocation for board structure failed\n");
81 rc = -ENOMEM;
82 goto out_release_regions;
84 memset(brd, 0, sizeof(struct jsm_board));
86 /* store the info for the board we've found */
87 brd->boardnum = adapter_count++;
88 brd->pci_dev = pdev;
89 brd->maxports = 2;
91 spin_lock_init(&brd->bd_lock);
92 spin_lock_init(&brd->bd_intr_lock);
94 /* store which revision we have */
95 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
97 brd->irq = pdev->irq;
99 jsm_printk(INIT, INFO, &brd->pci_dev,
100 "jsm_found_board - NEO adapter\n");
102 /* get the PCI Base Address Registers */
103 brd->membase = pci_resource_start(pdev, 0);
104 brd->membase_end = pci_resource_end(pdev, 0);
106 if (brd->membase & 1)
107 brd->membase &= ~3;
108 else
109 brd->membase &= ~15;
111 /* Assign the board_ops struct */
112 brd->bd_ops = &jsm_neo_ops;
114 brd->bd_uart_offset = 0x200;
115 brd->bd_dividend = 921600;
117 brd->re_map_membase = ioremap(brd->membase, 0x1000);
118 if (!brd->re_map_membase) {
119 dev_err(&pdev->dev,
120 "card has no PCI Memory resources, "
121 "failing board.\n");
122 rc = -ENOMEM;
123 goto out_kfree_brd;
126 rc = request_irq(brd->irq, brd->bd_ops->intr,
127 SA_INTERRUPT|SA_SHIRQ, "JSM", brd);
128 if (rc) {
129 printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
130 goto out_iounmap;
133 rc = jsm_tty_init(brd);
134 if (rc < 0) {
135 dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
136 retval = -ENXIO;
137 goto out_free_irq;
140 rc = jsm_uart_port_init(brd);
141 if (rc < 0) {
142 /* XXX: leaking all resources from jsm_tty_init here! */
143 dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
144 retval = -ENXIO;
145 goto out_free_irq;
148 /* Log the information about the board */
149 dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
150 adapter_count, brd->rev, brd->irq);
153 * allocate flip buffer for board.
155 * Okay to malloc with GFP_KERNEL, we are not at interrupt
156 * context, and there are no locks held.
158 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
159 if (!brd->flipbuf) {
160 /* XXX: leaking all resources from jsm_tty_init and
161 jsm_uart_port_init here! */
162 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
163 retval = -ENOMEM;
164 goto out_free_irq;
166 memset(brd->flipbuf, 0, MYFLIPLEN);
168 pci_set_drvdata(pdev, brd);
170 return 0;
171 out_free_irq:
172 free_irq(brd->irq, brd);
173 out_iounmap:
174 iounmap(brd->re_map_membase);
175 out_kfree_brd:
176 kfree(brd);
177 out_release_regions:
178 pci_release_regions(pdev);
179 out_disable_device:
180 pci_disable_device(pdev);
181 out:
182 return rc;
185 static void jsm_remove_one(struct pci_dev *pdev)
187 struct jsm_board *brd = pci_get_drvdata(pdev);
188 int i = 0;
190 jsm_remove_uart_port(brd);
192 free_irq(brd->irq, brd);
193 iounmap(brd->re_map_membase);
195 /* Free all allocated channels structs */
196 for (i = 0; i < brd->maxports; i++) {
197 if (brd->channels[i]) {
198 kfree(brd->channels[i]->ch_rqueue);
199 kfree(brd->channels[i]->ch_equeue);
200 kfree(brd->channels[i]->ch_wqueue);
201 kfree(brd->channels[i]);
205 pci_release_regions(pdev);
206 pci_disable_device(pdev);
207 kfree(brd->flipbuf);
208 kfree(brd);
211 static struct pci_device_id jsm_pci_tbl[] = {
212 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
213 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
214 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
215 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
216 { 0, }
218 MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
220 static struct pci_driver jsm_driver = {
221 .name = "jsm",
222 .id_table = jsm_pci_tbl,
223 .probe = jsm_probe_one,
224 .remove = __devexit_p(jsm_remove_one),
227 static int __init jsm_init_module(void)
229 int rc;
231 rc = uart_register_driver(&jsm_uart_driver);
232 if (!rc) {
233 rc = pci_register_driver(&jsm_driver);
234 if (rc)
235 uart_unregister_driver(&jsm_uart_driver);
237 return rc;
240 static void __exit jsm_exit_module(void)
242 pci_unregister_driver(&jsm_driver);
243 uart_unregister_driver(&jsm_uart_driver);
246 module_init(jsm_init_module);
247 module_exit(jsm_exit_module);