1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/module.h>
14#include <linux/pci.h>
15
16#include "ci13xxx_udc.c"
17
18
19#define UDC_DRIVER_NAME "ci13xxx_pci"
20
21
22
23
24
25
26
27
28
29
30
31
32static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev)
33{
34 if (irq == 0) {
35 dev_err(&((struct pci_dev *)pdev)->dev, "Invalid IRQ0 usage!");
36 return IRQ_HANDLED;
37 }
38 return udc_irq();
39}
40
41static struct ci13xxx_udc_driver ci13xxx_pci_udc_driver = {
42 .name = UDC_DRIVER_NAME,
43};
44
45
46
47
48
49
50
51
52
53
54static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
55 const struct pci_device_id *id)
56{
57 void __iomem *regs = NULL;
58 int retval = 0;
59
60 if (id == NULL)
61 return -EINVAL;
62
63 retval = pci_enable_device(pdev);
64 if (retval)
65 goto done;
66
67 if (!pdev->irq) {
68 dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
69 retval = -ENODEV;
70 goto disable_device;
71 }
72
73 retval = pci_request_regions(pdev, UDC_DRIVER_NAME);
74 if (retval)
75 goto disable_device;
76
77
78 regs = pci_iomap(pdev, 0, 0);
79 if (!regs) {
80 dev_err(&pdev->dev, "Error mapping memory!");
81 retval = -EFAULT;
82 goto release_regions;
83 }
84 pci_set_drvdata(pdev, (__force void *)regs);
85
86 pci_set_master(pdev);
87 pci_try_set_mwi(pdev);
88
89 retval = udc_probe(&ci13xxx_pci_udc_driver, &pdev->dev, regs);
90 if (retval)
91 goto iounmap;
92
93
94
95 retval = request_irq(pdev->irq, ci13xxx_pci_irq, IRQF_SHARED,
96 UDC_DRIVER_NAME, pdev);
97 if (retval)
98 goto gadget_remove;
99
100 return 0;
101
102 gadget_remove:
103 udc_remove();
104 iounmap:
105 pci_iounmap(pdev, regs);
106 release_regions:
107 pci_release_regions(pdev);
108 disable_device:
109 pci_disable_device(pdev);
110 done:
111 return retval;
112}
113
114
115
116
117
118
119
120
121
122static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
123{
124 free_irq(pdev->irq, pdev);
125 udc_remove();
126 pci_iounmap(pdev, (__force void __iomem *)pci_get_drvdata(pdev));
127 pci_release_regions(pdev);
128 pci_disable_device(pdev);
129}
130
131
132
133
134
135
136
137static 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 }
141};
142MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);
143
144static 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),
149};
150
151
152
153
154
155
156static int __init ci13xxx_pci_init(void)
157{
158 return pci_register_driver(&ci13xxx_pci_driver);
159}
160module_init(ci13xxx_pci_init);
161
162
163
164
165
166
167static void __exit ci13xxx_pci_exit(void)
168{
169 pci_unregister_driver(&ci13xxx_pci_driver);
170}
171module_exit(ci13xxx_pci_exit);
172
173MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
174MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
175MODULE_LICENSE("GPL");
176MODULE_VERSION("June 2008");
177