Commit | Line | Data |
---|---|---|
5fd54ace | 1 | // SPDX-License-Identifier: GPL-2.0 |
409a15da | 2 | /* |
8e22978c | 3 | * ci_hdrc_pci.c - MIPS USB IP core family device controller |
409a15da PK |
4 | * |
5 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. | |
6 | * | |
7 | * Author: David Lopo | |
409a15da PK |
8 | */ |
9 | ||
62bb84ed | 10 | #include <linux/platform_device.h> |
409a15da PK |
11 | #include <linux/module.h> |
12 | #include <linux/pci.h> | |
62bb84ed AS |
13 | #include <linux/interrupt.h> |
14 | #include <linux/usb/gadget.h> | |
e443b333 | 15 | #include <linux/usb/chipidea.h> |
ba1aff67 | 16 | #include <linux/usb/usb_phy_generic.h> |
409a15da PK |
17 | |
18 | /* driver name */ | |
8e22978c | 19 | #define UDC_DRIVER_NAME "ci_hdrc_pci" |
409a15da | 20 | |
ba1aff67 AS |
21 | struct ci_hdrc_pci { |
22 | struct platform_device *ci; | |
23 | struct platform_device *phy; | |
24 | }; | |
25 | ||
409a15da PK |
26 | /****************************************************************************** |
27 | * PCI block | |
28 | *****************************************************************************/ | |
8e22978c | 29 | static struct ci_hdrc_platform_data pci_platdata = { |
62bb84ed AS |
30 | .name = UDC_DRIVER_NAME, |
31 | .capoffset = DEF_CAPOFFSET, | |
32 | }; | |
409a15da | 33 | |
8e22978c | 34 | static struct ci_hdrc_platform_data langwell_pci_platdata = { |
f01ef574 | 35 | .name = UDC_DRIVER_NAME, |
62bb84ed | 36 | .capoffset = 0, |
f01ef574 PK |
37 | }; |
38 | ||
8e22978c | 39 | static struct ci_hdrc_platform_data penwell_pci_platdata = { |
bd841986 AS |
40 | .name = UDC_DRIVER_NAME, |
41 | .capoffset = 0, | |
42 | .power_budget = 200, | |
43 | }; | |
44 | ||
409a15da | 45 | /** |
8e22978c | 46 | * ci_hdrc_pci_probe: PCI probe |
409a15da PK |
47 | * @pdev: USB device controller being probed |
48 | * @id: PCI hotplug ID connecting controller to UDC framework | |
49 | * | |
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 | |
53 | */ | |
8e22978c | 54 | static int ci_hdrc_pci_probe(struct pci_dev *pdev, |
409a15da PK |
55 | const struct pci_device_id *id) |
56 | { | |
8e22978c | 57 | struct ci_hdrc_platform_data *platdata = (void *)id->driver_data; |
ba1aff67 | 58 | struct ci_hdrc_pci *ci; |
62bb84ed AS |
59 | struct resource res[3]; |
60 | int retval = 0, nres = 2; | |
409a15da | 61 | |
77c4400f | 62 | if (!platdata) { |
1989b5ce AS |
63 | dev_err(&pdev->dev, "device doesn't provide driver data\n"); |
64 | return -ENODEV; | |
65 | } | |
66 | ||
ba1aff67 AS |
67 | ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL); |
68 | if (!ci) | |
69 | return -ENOMEM; | |
70 | ||
8b2379b4 | 71 | retval = pcim_enable_device(pdev); |
409a15da | 72 | if (retval) |
8b2379b4 | 73 | return retval; |
409a15da PK |
74 | |
75 | if (!pdev->irq) { | |
76 | dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); | |
8b2379b4 | 77 | return -ENODEV; |
409a15da PK |
78 | } |
79 | ||
409a15da PK |
80 | pci_set_master(pdev); |
81 | pci_try_set_mwi(pdev); | |
82 | ||
ba1aff67 AS |
83 | /* register a nop PHY */ |
84 | ci->phy = usb_phy_generic_register(); | |
8c0614ca WY |
85 | if (IS_ERR(ci->phy)) |
86 | return PTR_ERR(ci->phy); | |
ba1aff67 | 87 | |
62bb84ed AS |
88 | memset(res, 0, sizeof(res)); |
89 | res[0].start = pci_resource_start(pdev, 0); | |
90 | res[0].end = pci_resource_end(pdev, 0); | |
91 | res[0].flags = IORESOURCE_MEM; | |
92 | res[1].start = pdev->irq; | |
93 | res[1].flags = IORESOURCE_IRQ; | |
94 | ||
ba1aff67 AS |
95 | ci->ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata); |
96 | if (IS_ERR(ci->ci)) { | |
8e22978c | 97 | dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); |
ba1aff67 AS |
98 | usb_phy_generic_unregister(ci->phy); |
99 | return PTR_ERR(ci->ci); | |
62bb84ed AS |
100 | } |
101 | ||
ba1aff67 | 102 | pci_set_drvdata(pdev, ci); |
62bb84ed | 103 | |
409a15da | 104 | return 0; |
409a15da PK |
105 | } |
106 | ||
107 | /** | |
8e22978c | 108 | * ci_hdrc_pci_remove: PCI remove |
409a15da PK |
109 | * @pdev: USB Device Controller being removed |
110 | * | |
8e22978c | 111 | * Reverses the effect of ci_hdrc_pci_probe(), |
409a15da PK |
112 | * first invoking the udc_remove() and then releases |
113 | * all PCI resources allocated for this USB device controller | |
114 | */ | |
8e22978c | 115 | static void ci_hdrc_pci_remove(struct pci_dev *pdev) |
409a15da | 116 | { |
ba1aff67 | 117 | struct ci_hdrc_pci *ci = pci_get_drvdata(pdev); |
62bb84ed | 118 | |
ba1aff67 AS |
119 | ci_hdrc_remove_device(ci->ci); |
120 | usb_phy_generic_unregister(ci->phy); | |
409a15da PK |
121 | } |
122 | ||
123 | /** | |
124 | * PCI device table | |
125 | * PCI device structure | |
126 | * | |
127 | * Check "pci.h" for details | |
518ca8d9 AS |
128 | * |
129 | * Note: ehci-pci driver may try to probe the device first. You have to add an | |
130 | * ID to the bypass_pci_id_table in ehci-pci driver to prevent this. | |
409a15da | 131 | */ |
4e065b8b | 132 | static const struct pci_device_id ci_hdrc_pci_id_table[] = { |
62bb84ed AS |
133 | { |
134 | PCI_DEVICE(0x153F, 0x1004), | |
77c4400f | 135 | .driver_data = (kernel_ulong_t)&pci_platdata, |
62bb84ed AS |
136 | }, |
137 | { | |
138 | PCI_DEVICE(0x153F, 0x1006), | |
77c4400f | 139 | .driver_data = (kernel_ulong_t)&pci_platdata, |
62bb84ed AS |
140 | }, |
141 | { | |
46b95a1d | 142 | PCI_VDEVICE(INTEL, 0x0811), |
77c4400f | 143 | .driver_data = (kernel_ulong_t)&langwell_pci_platdata, |
62bb84ed AS |
144 | }, |
145 | { | |
46b95a1d | 146 | PCI_VDEVICE(INTEL, 0x0829), |
77c4400f | 147 | .driver_data = (kernel_ulong_t)&penwell_pci_platdata, |
62bb84ed | 148 | }, |
a214339d DC |
149 | { |
150 | /* Intel Clovertrail */ | |
46b95a1d | 151 | PCI_VDEVICE(INTEL, 0xe006), |
a214339d DC |
152 | .driver_data = (kernel_ulong_t)&penwell_pci_platdata, |
153 | }, | |
154 | { 0 } /* end: all zeroes */ | |
409a15da | 155 | }; |
8e22978c | 156 | MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table); |
409a15da | 157 | |
8e22978c | 158 | static struct pci_driver ci_hdrc_pci_driver = { |
409a15da | 159 | .name = UDC_DRIVER_NAME, |
8e22978c AS |
160 | .id_table = ci_hdrc_pci_id_table, |
161 | .probe = ci_hdrc_pci_probe, | |
162 | .remove = ci_hdrc_pci_remove, | |
409a15da PK |
163 | }; |
164 | ||
8e22978c | 165 | module_pci_driver(ci_hdrc_pci_driver); |
409a15da PK |
166 | |
167 | MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); | |
168 | MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); | |
169 | MODULE_LICENSE("GPL"); | |
8e22978c | 170 | MODULE_ALIAS("platform:ci13xxx_pci"); |