usb: chipidea: split the driver code into units
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / usb / chipidea / ci13xxx_pci.c
CommitLineData
409a15da
PK
1/*
2 * ci13xxx_pci.c - MIPS USB IP core family device controller
3 *
4 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
5 *
6 * Author: David Lopo
7 *
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.
11 */
12
62bb84ed 13#include <linux/platform_device.h>
409a15da
PK
14#include <linux/module.h>
15#include <linux/pci.h>
62bb84ed
AS
16#include <linux/interrupt.h>
17#include <linux/usb/gadget.h>
e443b333 18#include <linux/usb/chipidea.h>
409a15da
PK
19
20/* driver name */
21#define UDC_DRIVER_NAME "ci13xxx_pci"
22
23/******************************************************************************
24 * PCI block
25 *****************************************************************************/
62bb84ed
AS
26struct ci13xxx_udc_driver pci_driver = {
27 .name = UDC_DRIVER_NAME,
28 .capoffset = DEF_CAPOFFSET,
29};
409a15da 30
62bb84ed 31struct ci13xxx_udc_driver langwell_pci_driver = {
f01ef574 32 .name = UDC_DRIVER_NAME,
62bb84ed 33 .capoffset = 0,
f01ef574
PK
34};
35
409a15da
PK
36/**
37 * ci13xxx_pci_probe: PCI probe
38 * @pdev: USB device controller being probed
39 * @id: PCI hotplug ID connecting controller to UDC framework
40 *
41 * This function returns an error code
42 * Allocates basic PCI resources for this USB device controller, and then
43 * invokes the udc_probe() method to start the UDC associated with it
44 */
45static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
46 const struct pci_device_id *id)
47{
62bb84ed
AS
48 struct ci13xxx_udc_driver *driver = (void *)id->driver_data;
49 struct platform_device *plat_ci;
50 struct resource res[3];
51 int retval = 0, nres = 2;
409a15da 52
1989b5ce
AS
53 if (!driver) {
54 dev_err(&pdev->dev, "device doesn't provide driver data\n");
55 return -ENODEV;
56 }
57
409a15da
PK
58 retval = pci_enable_device(pdev);
59 if (retval)
60 goto done;
61
62 if (!pdev->irq) {
63 dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
64 retval = -ENODEV;
65 goto disable_device;
66 }
67
62bb84ed 68 pci_set_power_state(pdev, PCI_D0);
409a15da
PK
69 pci_set_master(pdev);
70 pci_try_set_mwi(pdev);
71
62bb84ed
AS
72 plat_ci = platform_device_alloc("ci_udc", -1);
73 if (!plat_ci) {
74 dev_err(&pdev->dev, "can't allocate ci_udc platform device\n");
75 retval = -ENOMEM;
76 goto disable_device;
77 }
f9df8395 78
62bb84ed
AS
79 memset(res, 0, sizeof(res));
80 res[0].start = pci_resource_start(pdev, 0);
81 res[0].end = pci_resource_end(pdev, 0);
82 res[0].flags = IORESOURCE_MEM;
83 res[1].start = pdev->irq;
84 res[1].flags = IORESOURCE_IRQ;
85
86 retval = platform_device_add_resources(plat_ci, res, nres);
87 if (retval) {
88 dev_err(&pdev->dev, "can't add resources to platform device\n");
89 goto put_platform;
90 }
91
92 retval = platform_device_add_data(plat_ci, driver, sizeof(*driver));
409a15da 93 if (retval)
62bb84ed 94 goto put_platform;
409a15da 95
62bb84ed
AS
96 dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask);
97 plat_ci->dev.dma_mask = pdev->dev.dma_mask;
98 plat_ci->dev.dma_parms = pdev->dev.dma_parms;
99 plat_ci->dev.parent = &pdev->dev;
409a15da 100
62bb84ed
AS
101 pci_set_drvdata(pdev, plat_ci);
102
103 retval = platform_device_add(plat_ci);
409a15da 104 if (retval)
62bb84ed 105 goto put_platform;
409a15da
PK
106
107 return 0;
108
62bb84ed
AS
109 put_platform:
110 pci_set_drvdata(pdev, NULL);
111 platform_device_put(plat_ci);
409a15da
PK
112 disable_device:
113 pci_disable_device(pdev);
114 done:
115 return retval;
116}
117
118/**
119 * ci13xxx_pci_remove: PCI remove
120 * @pdev: USB Device Controller being removed
121 *
122 * Reverses the effect of ci13xxx_pci_probe(),
123 * first invoking the udc_remove() and then releases
124 * all PCI resources allocated for this USB device controller
125 */
126static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
127{
62bb84ed
AS
128 struct platform_device *plat_ci = pci_get_drvdata(pdev);
129
130 platform_device_unregister(plat_ci);
131 pci_set_drvdata(pdev, NULL);
409a15da
PK
132 pci_disable_device(pdev);
133}
134
135/**
136 * PCI device table
137 * PCI device structure
138 *
139 * Check "pci.h" for details
140 */
141static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
62bb84ed
AS
142 {
143 PCI_DEVICE(0x153F, 0x1004),
144 .driver_data = (kernel_ulong_t)&pci_driver,
145 },
146 {
147 PCI_DEVICE(0x153F, 0x1006),
148 .driver_data = (kernel_ulong_t)&pci_driver,
149 },
150 {
151 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
152 .driver_data = (kernel_ulong_t)&langwell_pci_driver,
153 },
154 {
155 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
156 .driver_data = (kernel_ulong_t)&langwell_pci_driver,
157 },
409a15da
PK
158 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
159};
160MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);
161
162static struct pci_driver ci13xxx_pci_driver = {
163 .name = UDC_DRIVER_NAME,
164 .id_table = ci13xxx_pci_id_table,
165 .probe = ci13xxx_pci_probe,
166 .remove = __devexit_p(ci13xxx_pci_remove),
167};
168
3cdb7721 169module_pci_driver(ci13xxx_pci_driver);
409a15da
PK
170
171MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
172MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
173MODULE_LICENSE("GPL");
174MODULE_VERSION("June 2008");