4 * Intel/Ziatech ZT5550 CompactPCI Host Controller driver
6 * Copyright 2002 SOMA Networks, Inc.
7 * Copyright 2001 Intel San Luis Obispo
8 * Copyright 2000,2001 MontaVista Software Inc.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 675 Mass Ave, Cambridge, MA 02139, USA.
30 * Send feedback to <scottm@somanetworks.com>
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/init.h>
37 #include <linux/errno.h>
38 #include <linux/pci.h>
39 #include "cpci_hotplug.h"
40 #include "cpcihp_zt5550.h"
42 #define DRIVER_VERSION "0.2"
43 #define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>"
44 #define DRIVER_DESC "ZT5550 CompactPCI Hot Plug Driver"
46 #define MY_NAME "cpcihp_zt5550"
48 #define dbg(format, arg...) \
51 printk (KERN_DEBUG "%s: " format "\n", \
54 #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME , ## arg)
55 #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME , ## arg)
56 #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME , ## arg)
61 static struct cpci_hp_controller_ops zt5550_hpc_ops;
62 static struct cpci_hp_controller zt5550_hpc;
64 /* Primary cPCI bus bridge device */
65 static struct pci_dev *bus0_dev;
66 static struct pci_bus *bus0;
68 /* Host controller device */
69 static struct pci_dev *hc_dev;
71 /* Host controller register addresses */
72 static void __iomem *hc_registers;
73 static void __iomem *csr_hc_index;
74 static void __iomem *csr_hc_data;
75 static void __iomem *csr_int_status;
76 static void __iomem *csr_int_mask;
79 static int zt5550_hc_config(struct pci_dev *pdev)
83 /* Since we know that no boards exist with two HC chips, treat it as an error */
85 err("too many host controller devices?");
89 ret = pci_enable_device(pdev);
91 err("cannot enable %s\n", pci_name(pdev));
96 dbg("hc_dev = %p", hc_dev);
97 dbg("pci resource start %lx", pci_resource_start(hc_dev, 1));
98 dbg("pci resource len %lx", pci_resource_len(hc_dev, 1));
100 if(!request_mem_region(pci_resource_start(hc_dev, 1),
101 pci_resource_len(hc_dev, 1), MY_NAME)) {
102 err("cannot reserve MMIO region");
104 goto exit_disable_device;
108 ioremap(pci_resource_start(hc_dev, 1), pci_resource_len(hc_dev, 1));
110 err("cannot remap MMIO region %lx @ %lx",
111 pci_resource_len(hc_dev, 1), pci_resource_start(hc_dev, 1));
113 goto exit_release_region;
116 csr_hc_index = hc_registers + CSR_HCINDEX;
117 csr_hc_data = hc_registers + CSR_HCDATA;
118 csr_int_status = hc_registers + CSR_INTSTAT;
119 csr_int_mask = hc_registers + CSR_INTMASK;
122 * Disable host control, fault and serial interrupts
124 dbg("disabling host control, fault and serial interrupts");
125 writeb((u8) HC_INT_MASK_REG, csr_hc_index);
126 writeb((u8) ALL_INDEXED_INTS_MASK, csr_hc_data);
127 dbg("disabled host control, fault and serial interrupts");
130 * Disable timer0, timer1 and ENUM interrupts
132 dbg("disabling timer0, timer1 and ENUM interrupts");
133 writeb((u8) ALL_DIRECT_INTS_MASK, csr_int_mask);
134 dbg("disabled timer0, timer1 and ENUM interrupts");
138 release_mem_region(pci_resource_start(hc_dev, 1),
139 pci_resource_len(hc_dev, 1));
141 pci_disable_device(hc_dev);
145 static int zt5550_hc_cleanup(void)
150 iounmap(hc_registers);
151 release_mem_region(pci_resource_start(hc_dev, 1),
152 pci_resource_len(hc_dev, 1));
153 pci_disable_device(hc_dev);
157 static int zt5550_hc_query_enum(void)
161 value = inb_p(ENUM_PORT);
162 return ((value & ENUM_MASK) == ENUM_MASK);
165 static int zt5550_hc_check_irq(void *dev_id)
171 if(dev_id == zt5550_hpc.dev_id) {
172 reg = readb(csr_int_status);
179 static int zt5550_hc_enable_irq(void)
186 reg = readb(csr_int_mask);
187 reg = reg & ~ENUM_INT_MASK;
188 writeb(reg, csr_int_mask);
192 static int zt5550_hc_disable_irq(void)
200 reg = readb(csr_int_mask);
201 reg = reg | ENUM_INT_MASK;
202 writeb(reg, csr_int_mask);
206 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
210 status = zt5550_hc_config(pdev);
214 dbg("returned from zt5550_hc_config");
216 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
217 zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
218 zt5550_hpc.ops = &zt5550_hpc_ops;
220 zt5550_hpc.irq = hc_dev->irq;
221 zt5550_hpc.irq_flags = SA_SHIRQ;
222 zt5550_hpc.dev_id = hc_dev;
224 zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
225 zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
226 zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
228 info("using ENUM# polling mode");
231 status = cpci_hp_register_controller(&zt5550_hpc);
233 err("could not register cPCI hotplug controller");
236 dbg("registered controller");
238 /* Look for first device matching cPCI bus's bridge vendor and device IDs */
239 if(!(bus0_dev = pci_get_device(PCI_VENDOR_ID_DEC,
240 PCI_DEVICE_ID_DEC_21154, NULL))) {
242 goto init_register_error;
244 bus0 = bus0_dev->subordinate;
245 pci_dev_put(bus0_dev);
247 status = cpci_hp_register_bus(bus0, 0x0a, 0x0f);
249 err("could not register cPCI hotplug bus");
250 goto init_register_error;
252 dbg("registered bus");
254 status = cpci_hp_start();
256 err("could not started cPCI hotplug system");
257 cpci_hp_unregister_bus(bus0);
258 goto init_register_error;
260 dbg("started cpci hp system");
264 cpci_hp_unregister_controller(&zt5550_hpc);
266 err("status = %d", status);
272 static void __devexit zt5550_hc_remove_one(struct pci_dev *pdev)
275 cpci_hp_unregister_bus(bus0);
276 cpci_hp_unregister_controller(&zt5550_hpc);
281 static struct pci_device_id zt5550_hc_pci_tbl[] = {
282 { PCI_VENDOR_ID_ZIATECH, PCI_DEVICE_ID_ZIATECH_5550_HC, PCI_ANY_ID, PCI_ANY_ID, },
285 MODULE_DEVICE_TABLE(pci, zt5550_hc_pci_tbl);
287 static struct pci_driver zt5550_hc_driver = {
289 .id_table = zt5550_hc_pci_tbl,
290 .probe = zt5550_hc_init_one,
291 .remove = __devexit_p(zt5550_hc_remove_one),
294 static int __init zt5550_init(void)
298 info(DRIVER_DESC " version: " DRIVER_VERSION);
299 r = request_region(ENUM_PORT, 1, "#ENUM hotswap signal register");
303 return pci_register_driver(&zt5550_hc_driver);
309 pci_unregister_driver(&zt5550_hc_driver);
310 release_region(ENUM_PORT, 1);
313 module_init(zt5550_init);
314 module_exit(zt5550_exit);
316 MODULE_AUTHOR(DRIVER_AUTHOR);
317 MODULE_DESCRIPTION(DRIVER_DESC);
318 MODULE_LICENSE("GPL");
319 module_param(debug, bool, 0644);
320 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
321 module_param(poll, bool, 0644);
322 MODULE_PARM_DESC(poll, "#ENUM polling mode enabled or not");