• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/serial/jsm/
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 <linux/slab.h>
30
31#include "jsm.h"
32
33MODULE_AUTHOR("Digi International, http://www.digi.com");
34MODULE_DESCRIPTION("Driver for the Digi International "
35		   "Neo PCI based product line");
36MODULE_LICENSE("GPL");
37MODULE_SUPPORTED_DEVICE("jsm");
38
39#define JSM_DRIVER_NAME "jsm"
40#define NR_PORTS	32
41#define JSM_MINOR_START	0
42
43struct uart_driver jsm_uart_driver = {
44	.owner		= THIS_MODULE,
45	.driver_name	= JSM_DRIVER_NAME,
46	.dev_name	= "ttyn",
47	.major		= 0,
48	.minor		= JSM_MINOR_START,
49	.nr		= NR_PORTS,
50};
51
52static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
53                                       pci_channel_state_t state);
54static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev);
55static void jsm_io_resume(struct pci_dev *pdev);
56
57static struct pci_error_handlers jsm_err_handler = {
58	.error_detected = jsm_io_error_detected,
59	.slot_reset = jsm_io_slot_reset,
60	.resume = jsm_io_resume,
61};
62
63int jsm_debug;
64module_param(jsm_debug, int, 0);
65MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
66
67static int __devinit jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
68{
69	int rc = 0;
70	struct jsm_board *brd;
71	static int adapter_count = 0;
72
73	rc = pci_enable_device(pdev);
74	if (rc) {
75		dev_err(&pdev->dev, "Device enable FAILED\n");
76		goto out;
77	}
78
79	rc = pci_request_regions(pdev, "jsm");
80	if (rc) {
81		dev_err(&pdev->dev, "pci_request_region FAILED\n");
82		goto out_disable_device;
83	}
84
85	brd = kzalloc(sizeof(struct jsm_board), GFP_KERNEL);
86	if (!brd) {
87		dev_err(&pdev->dev,
88			"memory allocation for board structure failed\n");
89		rc = -ENOMEM;
90		goto out_release_regions;
91	}
92
93	/* store the info for the board we've found */
94	brd->boardnum = adapter_count++;
95	brd->pci_dev = pdev;
96	if (pdev->device == PCIE_DEVICE_ID_NEO_4_IBM)
97		brd->maxports = 4;
98	else if (pdev->device == PCI_DEVICE_ID_DIGI_NEO_8)
99		brd->maxports = 8;
100	else
101		brd->maxports = 2;
102
103	spin_lock_init(&brd->bd_intr_lock);
104
105	/* store which revision we have */
106	brd->rev = pdev->revision;
107
108	brd->irq = pdev->irq;
109
110	jsm_printk(INIT, INFO, &brd->pci_dev,
111		"jsm_found_board - NEO adapter\n");
112
113	/* get the PCI Base Address Registers */
114	brd->membase	= pci_resource_start(pdev, 0);
115	brd->membase_end = pci_resource_end(pdev, 0);
116
117	if (brd->membase & 1)
118		brd->membase &= ~3;
119	else
120		brd->membase &= ~15;
121
122	/* Assign the board_ops struct */
123	brd->bd_ops = &jsm_neo_ops;
124
125	brd->bd_uart_offset = 0x200;
126	brd->bd_dividend = 921600;
127
128	brd->re_map_membase = ioremap(brd->membase, 0x1000);
129	if (!brd->re_map_membase) {
130		dev_err(&pdev->dev,
131			"card has no PCI Memory resources, "
132			"failing board.\n");
133		rc = -ENOMEM;
134		goto out_kfree_brd;
135	}
136
137	rc = request_irq(brd->irq, brd->bd_ops->intr,
138			IRQF_SHARED, "JSM", brd);
139	if (rc) {
140		printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
141		goto out_iounmap;
142	}
143
144	rc = jsm_tty_init(brd);
145	if (rc < 0) {
146		dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
147		rc = -ENXIO;
148		goto out_free_irq;
149	}
150
151	rc = jsm_uart_port_init(brd);
152	if (rc < 0) {
153		dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
154		rc = -ENXIO;
155		goto out_free_irq;
156	}
157
158	/* Log the information about the board */
159	dev_info(&pdev->dev, "board %d: Digi Neo (rev %d), irq %d\n",
160			adapter_count, brd->rev, brd->irq);
161
162	/*
163	 * allocate flip buffer for board.
164	 *
165	 * Okay to malloc with GFP_KERNEL, we are not at interrupt
166	 * context, and there are no locks held.
167	 */
168	brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
169	if (!brd->flipbuf) {
170		dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
171		rc = -ENOMEM;
172		goto out_free_irq;
173	}
174
175	pci_set_drvdata(pdev, brd);
176	pci_save_state(pdev);
177
178	return 0;
179 out_free_irq:
180	jsm_remove_uart_port(brd);
181	free_irq(brd->irq, brd);
182 out_iounmap:
183	iounmap(brd->re_map_membase);
184 out_kfree_brd:
185	kfree(brd);
186 out_release_regions:
187	pci_release_regions(pdev);
188 out_disable_device:
189	pci_disable_device(pdev);
190 out:
191	return rc;
192}
193
194static void __devexit jsm_remove_one(struct pci_dev *pdev)
195{
196	struct jsm_board *brd = pci_get_drvdata(pdev);
197	int i = 0;
198
199	jsm_remove_uart_port(brd);
200
201	free_irq(brd->irq, brd);
202	iounmap(brd->re_map_membase);
203
204	/* Free all allocated channels structs */
205	for (i = 0; i < brd->maxports; i++) {
206		if (brd->channels[i]) {
207			kfree(brd->channels[i]->ch_rqueue);
208			kfree(brd->channels[i]->ch_equeue);
209			kfree(brd->channels[i]->ch_wqueue);
210			kfree(brd->channels[i]);
211		}
212	}
213
214	pci_release_regions(pdev);
215	pci_disable_device(pdev);
216	kfree(brd->flipbuf);
217	kfree(brd);
218}
219
220static struct pci_device_id jsm_pci_tbl[] = {
221	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
222	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
223	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
224	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
225	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4_IBM), 0, 0, 4 },
226	{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_NEO_8), 0, 0, 5 },
227	{ 0, }
228};
229MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
230
231static struct pci_driver jsm_driver = {
232	.name		= "jsm",
233	.id_table	= jsm_pci_tbl,
234	.probe		= jsm_probe_one,
235	.remove		= __devexit_p(jsm_remove_one),
236	.err_handler    = &jsm_err_handler,
237};
238
239static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
240					pci_channel_state_t state)
241{
242	struct jsm_board *brd = pci_get_drvdata(pdev);
243
244	jsm_remove_uart_port(brd);
245
246	return PCI_ERS_RESULT_NEED_RESET;
247}
248
249static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev)
250{
251	int rc;
252
253	rc = pci_enable_device(pdev);
254
255	if (rc)
256		return PCI_ERS_RESULT_DISCONNECT;
257
258	pci_set_master(pdev);
259
260	return PCI_ERS_RESULT_RECOVERED;
261}
262
263static void jsm_io_resume(struct pci_dev *pdev)
264{
265	struct jsm_board *brd = pci_get_drvdata(pdev);
266
267	pci_restore_state(pdev);
268
269	jsm_uart_port_init(brd);
270}
271
272static int __init jsm_init_module(void)
273{
274	int rc;
275
276	rc = uart_register_driver(&jsm_uart_driver);
277	if (!rc) {
278		rc = pci_register_driver(&jsm_driver);
279		if (rc)
280			uart_unregister_driver(&jsm_uart_driver);
281	}
282	return rc;
283}
284
285static void __exit jsm_exit_module(void)
286{
287	pci_unregister_driver(&jsm_driver);
288	uart_unregister_driver(&jsm_uart_driver);
289}
290
291module_init(jsm_init_module);
292module_exit(jsm_exit_module);
293