2 * ci13xxx_pci.c - MIPS USB IP core family device controller
4 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/pci.h>
16 #include "ci13xxx_udc.c"
19 #define UDC_DRIVER_NAME "ci13xxx_pci"
21 /******************************************************************************
23 *****************************************************************************/
25 * ci13xxx_pci_irq: interrut handler
27 * @pdev: USB Device Controller interrupt source
29 * This function returns IRQ_HANDLED if the IRQ has been handled
30 * This is an ISR don't trace, use attribute interface instead
32 static irqreturn_t
ci13xxx_pci_irq(int irq
, void *pdev
)
35 dev_err(&((struct pci_dev
*)pdev
)->dev
, "Invalid IRQ0 usage!");
41 static struct ci13xxx_udc_driver ci13xxx_pci_udc_driver
= {
42 .name
= UDC_DRIVER_NAME
,
46 * ci13xxx_pci_probe: PCI probe
47 * @pdev: USB device controller being probed
48 * @id: PCI hotplug ID connecting controller to UDC framework
50 * This function returns an error code
51 * Allocates basic PCI resources for this USB device controller, and then
52 * invokes the udc_probe() method to start the UDC associated with it
54 static int __devinit
ci13xxx_pci_probe(struct pci_dev
*pdev
,
55 const struct pci_device_id
*id
)
57 void __iomem
*regs
= NULL
;
63 retval
= pci_enable_device(pdev
);
68 dev_err(&pdev
->dev
, "No IRQ, check BIOS/PCI setup!");
73 retval
= pci_request_regions(pdev
, UDC_DRIVER_NAME
);
77 /* BAR 0 holds all the registers */
78 regs
= pci_iomap(pdev
, 0, 0);
80 dev_err(&pdev
->dev
, "Error mapping memory!");
84 pci_set_drvdata(pdev
, (__force
void *)regs
);
87 pci_try_set_mwi(pdev
);
89 retval
= udc_probe(&ci13xxx_pci_udc_driver
, &pdev
->dev
, regs
);
93 /* our device does not have MSI capability */
95 retval
= request_irq(pdev
->irq
, ci13xxx_pci_irq
, IRQF_SHARED
,
96 UDC_DRIVER_NAME
, pdev
);
105 pci_iounmap(pdev
, regs
);
107 pci_release_regions(pdev
);
109 pci_disable_device(pdev
);
115 * ci13xxx_pci_remove: PCI remove
116 * @pdev: USB Device Controller being removed
118 * Reverses the effect of ci13xxx_pci_probe(),
119 * first invoking the udc_remove() and then releases
120 * all PCI resources allocated for this USB device controller
122 static void __devexit
ci13xxx_pci_remove(struct pci_dev
*pdev
)
124 free_irq(pdev
->irq
, pdev
);
126 pci_iounmap(pdev
, (__force
void __iomem
*)pci_get_drvdata(pdev
));
127 pci_release_regions(pdev
);
128 pci_disable_device(pdev
);
133 * PCI device structure
135 * Check "pci.h" for details
137 static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table
) = {
138 { PCI_DEVICE(0x153F, 0x1004) },
139 { PCI_DEVICE(0x153F, 0x1006) },
140 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
142 MODULE_DEVICE_TABLE(pci
, ci13xxx_pci_id_table
);
144 static struct pci_driver ci13xxx_pci_driver
= {
145 .name
= UDC_DRIVER_NAME
,
146 .id_table
= ci13xxx_pci_id_table
,
147 .probe
= ci13xxx_pci_probe
,
148 .remove
= __devexit_p(ci13xxx_pci_remove
),
152 * ci13xxx_pci_init: module init
156 static int __init
ci13xxx_pci_init(void)
158 return pci_register_driver(&ci13xxx_pci_driver
);
160 module_init(ci13xxx_pci_init
);
163 * ci13xxx_pci_exit: module exit
167 static void __exit
ci13xxx_pci_exit(void)
169 pci_unregister_driver(&ci13xxx_pci_driver
);
171 module_exit(ci13xxx_pci_exit
);
173 MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
174 MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
175 MODULE_LICENSE("GPL");
176 MODULE_VERSION("June 2008");