]> err.no Git - linux-2.6/blob - drivers/serial/jsm/jsm_driver.c
Merge branch 'for-2.6.26' of master.kernel.org:/pub/scm/linux/kernel/git/jwboyer...
[linux-2.6] / drivers / serial / jsm / jsm_driver.c
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
30 #include "jsm.h"
31
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");
37
38 #define JSM_DRIVER_NAME "jsm"
39 #define NR_PORTS        32
40 #define JSM_MINOR_START 0
41
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,
49 };
50
51 int jsm_debug;
52 module_param(jsm_debug, int, 0);
53 MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
54
55 static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
56 {
57         int rc = 0;
58         struct jsm_board *brd;
59         static int adapter_count = 0;
60         int retval;
61
62         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
74         brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL);
75         if (!brd) {
76                 dev_err(&pdev->dev,
77                         "memory allocation for board structure failed\n");
78                 rc = -ENOMEM;
79                 goto out_release_regions;
80         }
81
82         /* store the info for the board we've found */
83         brd->boardnum = adapter_count++;
84         brd->pci_dev = pdev;
85         if (pdev->device == PCIE_DEVICE_ID_NEO_4_IBM)
86                 brd->maxports = 4;
87         else
88                 brd->maxports = 2;
89
90         spin_lock_init(&brd->bd_lock);
91         spin_lock_init(&brd->bd_intr_lock);
92
93         /* store which revision we have */
94         brd->rev = pdev->revision;
95
96         brd->irq = pdev->irq;
97
98         jsm_printk(INIT, INFO, &brd->pci_dev,
99                 "jsm_found_board - NEO adapter\n");
100
101         /* get the PCI Base Address Registers */
102         brd->membase    = pci_resource_start(pdev, 0);
103         brd->membase_end = pci_resource_end(pdev, 0);
104
105         if (brd->membase & 1)
106                 brd->membase &= ~3;
107         else
108                 brd->membase &= ~15;
109
110         /* Assign the board_ops struct */
111         brd->bd_ops = &jsm_neo_ops;
112
113         brd->bd_uart_offset = 0x200;
114         brd->bd_dividend = 921600;
115
116         brd->re_map_membase = ioremap(brd->membase, 0x1000);
117         if (!brd->re_map_membase) {
118                 dev_err(&pdev->dev,
119                         "card has no PCI Memory resources, "
120                         "failing board.\n");
121                 rc = -ENOMEM;
122                 goto out_kfree_brd;
123         }
124
125         rc = request_irq(brd->irq, brd->bd_ops->intr,
126                         IRQF_DISABLED|IRQF_SHARED, "JSM", brd);
127         if (rc) {
128                 printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
129                 goto out_iounmap;
130         }
131
132         rc = jsm_tty_init(brd);
133         if (rc < 0) {
134                 dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
135                 retval = -ENXIO;
136                 goto out_free_irq;
137         }
138
139         rc = jsm_uart_port_init(brd);
140         if (rc < 0) {
141                 /* XXX: leaking all resources from jsm_tty_init here! */
142                 dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
143                 retval = -ENXIO;
144                 goto out_free_irq;
145         }
146
147         /* Log the information about the board */
148         dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
149                         adapter_count, brd->rev, brd->irq);
150
151         /*
152          * allocate flip buffer for board.
153          *
154          * Okay to malloc with GFP_KERNEL, we are not at interrupt
155          * context, and there are no locks held.
156          */
157         brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
158         if (!brd->flipbuf) {
159                 /* XXX: leaking all resources from jsm_tty_init and
160                         jsm_uart_port_init here! */
161                 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
162                 retval = -ENOMEM;
163                 goto out_free_irq;
164         }
165
166         pci_set_drvdata(pdev, brd);
167
168         return 0;
169  out_free_irq:
170         free_irq(brd->irq, brd);
171  out_iounmap:
172         iounmap(brd->re_map_membase);
173  out_kfree_brd:
174         kfree(brd);
175  out_release_regions:
176         pci_release_regions(pdev);
177  out_disable_device:
178         pci_disable_device(pdev);
179  out:
180         return rc;
181 }
182
183 static void jsm_remove_one(struct pci_dev *pdev)
184 {
185         struct jsm_board *brd = pci_get_drvdata(pdev);
186         int i = 0;
187
188         jsm_remove_uart_port(brd);
189
190         free_irq(brd->irq, brd);
191         iounmap(brd->re_map_membase);
192
193         /* Free all allocated channels structs */
194         for (i = 0; i < brd->maxports; i++) {
195                 if (brd->channels[i]) {
196                         kfree(brd->channels[i]->ch_rqueue);
197                         kfree(brd->channels[i]->ch_equeue);
198                         kfree(brd->channels[i]->ch_wqueue);
199                         kfree(brd->channels[i]);
200                 }
201         }
202
203         pci_release_regions(pdev);
204         pci_disable_device(pdev);
205         kfree(brd->flipbuf);
206         kfree(brd);
207 }
208
209 static struct pci_device_id jsm_pci_tbl[] = {
210         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
211         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
212         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
213         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
214         { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4_IBM), 0, 0, 4 },
215         { 0, }
216 };
217 MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
218
219 static struct pci_driver jsm_driver = {
220         .name           = "jsm",
221         .id_table       = jsm_pci_tbl,
222         .probe          = jsm_probe_one,
223         .remove         = __devexit_p(jsm_remove_one),
224 };
225
226 static int __init jsm_init_module(void)
227 {
228         int rc;
229
230         rc = uart_register_driver(&jsm_uart_driver);
231         if (!rc) {
232                 rc = pci_register_driver(&jsm_driver);
233                 if (rc)
234                         uart_unregister_driver(&jsm_uart_driver);
235         }
236         return rc;
237 }
238
239 static void __exit jsm_exit_module(void)
240 {
241         pci_unregister_driver(&jsm_driver);
242         uart_unregister_driver(&jsm_uart_driver);
243 }
244
245 module_init(jsm_init_module);
246 module_exit(jsm_exit_module);