diff options
author | Alexander Shishkin <alexander.shishkin@linux.intel.com> | 2012-05-11 10:25:47 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-05-11 19:52:10 -0400 |
commit | 5f36e231e9dbffb5264612e5b5817ab574a5e5db (patch) | |
tree | a71027cded532334d3d51cbf737925240d34e7df /drivers/usb/chipidea | |
parent | e443b333629f82ca0da91a05ca638050943bbedd (diff) |
usb: chipidea: add support for roles
Add some generic code for roles and implement simple role switching
based on ID pin state and/or a sysfs file. At this, we also rename
the device to ci_hdrc, which is what it is.
The "manual" switch is made into a sysfs file and not debugfs, because
it might be useful even in non-debug context. For some boards, like
sheevaplug, it seems to be the only way to switch roles without modifying
the hardware, since the ID pin is always grounded.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/chipidea')
-rw-r--r-- | drivers/usb/chipidea/bits.h | 18 | ||||
-rw-r--r-- | drivers/usb/chipidea/ci.h | 64 | ||||
-rw-r--r-- | drivers/usb/chipidea/ci13xxx_msm.c | 4 | ||||
-rw-r--r-- | drivers/usb/chipidea/ci13xxx_pci.c | 4 | ||||
-rw-r--r-- | drivers/usb/chipidea/core.c | 250 | ||||
-rw-r--r-- | drivers/usb/chipidea/udc.c | 80 | ||||
-rw-r--r-- | drivers/usb/chipidea/udc.h | 20 |
7 files changed, 325 insertions, 115 deletions
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h index 5fbff11cf220..62c35af1a5af 100644 --- a/drivers/usb/chipidea/bits.h +++ b/drivers/usb/chipidea/bits.h | |||
@@ -50,6 +50,24 @@ | |||
50 | #define DEVLC_PSPD (0x03UL << 25) | 50 | #define DEVLC_PSPD (0x03UL << 25) |
51 | #define DEVLC_PSPD_HS (0x02UL << 25) | 51 | #define DEVLC_PSPD_HS (0x02UL << 25) |
52 | 52 | ||
53 | /* OTGSC */ | ||
54 | #define OTGSC_IDPU BIT(5) | ||
55 | #define OTGSC_ID BIT(8) | ||
56 | #define OTGSC_AVV BIT(9) | ||
57 | #define OTGSC_ASV BIT(10) | ||
58 | #define OTGSC_BSV BIT(11) | ||
59 | #define OTGSC_BSE BIT(12) | ||
60 | #define OTGSC_IDIS BIT(16) | ||
61 | #define OTGSC_AVVIS BIT(17) | ||
62 | #define OTGSC_ASVIS BIT(18) | ||
63 | #define OTGSC_BSVIS BIT(19) | ||
64 | #define OTGSC_BSEIS BIT(20) | ||
65 | #define OTGSC_IDIE BIT(24) | ||
66 | #define OTGSC_AVVIE BIT(25) | ||
67 | #define OTGSC_ASVIE BIT(26) | ||
68 | #define OTGSC_BSVIE BIT(27) | ||
69 | #define OTGSC_BSEIE BIT(28) | ||
70 | |||
53 | /* USBMODE */ | 71 | /* USBMODE */ |
54 | #define USBMODE_CM (0x03UL << 0) | 72 | #define USBMODE_CM (0x03UL << 0) |
55 | #define USBMODE_CM_IDLE (0x00UL << 0) | 73 | #define USBMODE_CM_IDLE (0x00UL << 0) |
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index f5b3b8538a3b..56cb73b1e903 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #define __DRIVERS_USB_CHIPIDEA_CI_H | 14 | #define __DRIVERS_USB_CHIPIDEA_CI_H |
15 | 15 | ||
16 | #include <linux/list.h> | 16 | #include <linux/list.h> |
17 | #include <linux/irqreturn.h> | ||
17 | #include <linux/usb/gadget.h> | 18 | #include <linux/usb/gadget.h> |
18 | 19 | ||
19 | /****************************************************************************** | 20 | /****************************************************************************** |
@@ -47,6 +48,26 @@ struct ci13xxx_ep { | |||
47 | struct dma_pool *td_pool; | 48 | struct dma_pool *td_pool; |
48 | }; | 49 | }; |
49 | 50 | ||
51 | enum ci_role { | ||
52 | CI_ROLE_HOST = 0, | ||
53 | CI_ROLE_GADGET, | ||
54 | CI_ROLE_END, | ||
55 | }; | ||
56 | |||
57 | /** | ||
58 | * struct ci_role_driver - host/gadget role driver | ||
59 | * start: start this role | ||
60 | * stop: stop this role | ||
61 | * irq: irq handler for this role | ||
62 | * name: role name string (host/gadget) | ||
63 | */ | ||
64 | struct ci_role_driver { | ||
65 | int (*start)(struct ci13xxx *); | ||
66 | void (*stop)(struct ci13xxx *); | ||
67 | irqreturn_t (*irq)(struct ci13xxx *); | ||
68 | const char *name; | ||
69 | }; | ||
70 | |||
50 | struct hw_bank { | 71 | struct hw_bank { |
51 | unsigned lpm; /* is LPM? */ | 72 | unsigned lpm; /* is LPM? */ |
52 | void __iomem *abs; /* bus map offset */ | 73 | void __iomem *abs; /* bus map offset */ |
@@ -85,8 +106,47 @@ struct ci13xxx { | |||
85 | struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ | 106 | struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ |
86 | int vbus_active; /* is VBUS active */ | 107 | int vbus_active; /* is VBUS active */ |
87 | struct usb_phy *transceiver; /* Transceiver struct */ | 108 | struct usb_phy *transceiver; /* Transceiver struct */ |
109 | struct ci_role_driver *roles[CI_ROLE_END]; | ||
110 | enum ci_role role; | ||
111 | bool is_otg; | ||
112 | struct work_struct work; | ||
113 | struct workqueue_struct *wq; | ||
88 | }; | 114 | }; |
89 | 115 | ||
116 | static inline struct ci_role_driver *ci_role(struct ci13xxx *ci) | ||
117 | { | ||
118 | BUG_ON(ci->role >= CI_ROLE_END || !ci->roles[ci->role]); | ||
119 | return ci->roles[ci->role]; | ||
120 | } | ||
121 | |||
122 | static inline int ci_role_start(struct ci13xxx *ci, enum ci_role role) | ||
123 | { | ||
124 | int ret; | ||
125 | |||
126 | if (role >= CI_ROLE_END) | ||
127 | return -EINVAL; | ||
128 | |||
129 | if (!ci->roles[role]) | ||
130 | return -ENXIO; | ||
131 | |||
132 | ret = ci->roles[role]->start(ci); | ||
133 | if (!ret) | ||
134 | ci->role = role; | ||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | static inline void ci_role_stop(struct ci13xxx *ci) | ||
139 | { | ||
140 | enum ci_role role = ci->role; | ||
141 | |||
142 | if (role == CI_ROLE_END) | ||
143 | return; | ||
144 | |||
145 | ci->role = CI_ROLE_END; | ||
146 | |||
147 | ci->roles[role]->stop(ci); | ||
148 | } | ||
149 | |||
90 | /****************************************************************************** | 150 | /****************************************************************************** |
91 | * REGISTERS | 151 | * REGISTERS |
92 | *****************************************************************************/ | 152 | *****************************************************************************/ |
@@ -107,6 +167,7 @@ enum ci13xxx_regs { | |||
107 | OP_ENDPTLISTADDR, | 167 | OP_ENDPTLISTADDR, |
108 | OP_PORTSC, | 168 | OP_PORTSC, |
109 | OP_DEVLC, | 169 | OP_DEVLC, |
170 | OP_OTGSC, | ||
110 | OP_USBMODE, | 171 | OP_USBMODE, |
111 | OP_ENDPTSETUPSTAT, | 172 | OP_ENDPTSETUPSTAT, |
112 | OP_ENDPTPRIME, | 173 | OP_ENDPTPRIME, |
@@ -118,7 +179,6 @@ enum ci13xxx_regs { | |||
118 | OP_LAST = OP_ENDPTCTRL + ENDPT_MAX / 2, | 179 | OP_LAST = OP_ENDPTCTRL + ENDPT_MAX / 2, |
119 | }; | 180 | }; |
120 | 181 | ||
121 | |||
122 | /** | 182 | /** |
123 | * ffs_nr: find first (least significant) bit set | 183 | * ffs_nr: find first (least significant) bit set |
124 | * @x: the word to search | 184 | * @x: the word to search |
@@ -193,8 +253,6 @@ static inline u32 hw_test_and_write(struct ci13xxx *udc, enum ci13xxx_regs reg, | |||
193 | return (val & mask) >> ffs_nr(mask); | 253 | return (val & mask) >> ffs_nr(mask); |
194 | } | 254 | } |
195 | 255 | ||
196 | int hw_device_init(struct ci13xxx *udc, void __iomem *base, | ||
197 | uintptr_t cap_offset); | ||
198 | int hw_device_reset(struct ci13xxx *ci); | 256 | int hw_device_reset(struct ci13xxx *ci); |
199 | 257 | ||
200 | int hw_port_test_set(struct ci13xxx *ci, u8 mode); | 258 | int hw_port_test_set(struct ci13xxx *ci, u8 mode); |
diff --git a/drivers/usb/chipidea/ci13xxx_msm.c b/drivers/usb/chipidea/ci13xxx_msm.c index 27427931b681..9b09f0cd3d5a 100644 --- a/drivers/usb/chipidea/ci13xxx_msm.c +++ b/drivers/usb/chipidea/ci13xxx_msm.c | |||
@@ -62,9 +62,9 @@ static int ci13xxx_msm_probe(struct platform_device *pdev) | |||
62 | 62 | ||
63 | dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n"); | 63 | dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n"); |
64 | 64 | ||
65 | plat_ci = platform_device_alloc("ci_udc", -1); | 65 | plat_ci = platform_device_alloc("ci_hdrc", -1); |
66 | if (!plat_ci) { | 66 | if (!plat_ci) { |
67 | dev_err(&pdev->dev, "can't allocate ci_udc platform device\n"); | 67 | dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n"); |
68 | return -ENOMEM; | 68 | return -ENOMEM; |
69 | } | 69 | } |
70 | 70 | ||
diff --git a/drivers/usb/chipidea/ci13xxx_pci.c b/drivers/usb/chipidea/ci13xxx_pci.c index 84e8ab8d4f47..f190140cf612 100644 --- a/drivers/usb/chipidea/ci13xxx_pci.c +++ b/drivers/usb/chipidea/ci13xxx_pci.c | |||
@@ -69,9 +69,9 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, | |||
69 | pci_set_master(pdev); | 69 | pci_set_master(pdev); |
70 | pci_try_set_mwi(pdev); | 70 | pci_try_set_mwi(pdev); |
71 | 71 | ||
72 | plat_ci = platform_device_alloc("ci_udc", -1); | 72 | plat_ci = platform_device_alloc("ci_hdrc", -1); |
73 | if (!plat_ci) { | 73 | if (!plat_ci) { |
74 | dev_err(&pdev->dev, "can't allocate ci_udc platform device\n"); | 74 | dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n"); |
75 | retval = -ENOMEM; | 75 | retval = -ENOMEM; |
76 | goto disable_device; | 76 | goto disable_device; |
77 | } | 77 | } |
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index f6eab327ffea..2342f35c8071 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c | |||
@@ -75,7 +75,7 @@ | |||
75 | /* MSM specific */ | 75 | /* MSM specific */ |
76 | #define ABS_AHBBURST (0x0090UL) | 76 | #define ABS_AHBBURST (0x0090UL) |
77 | #define ABS_AHBMODE (0x0098UL) | 77 | #define ABS_AHBMODE (0x0098UL) |
78 | /* UDC register map */ | 78 | /* Controller register map */ |
79 | static uintptr_t ci_regs_nolpm[] = { | 79 | static uintptr_t ci_regs_nolpm[] = { |
80 | [CAP_CAPLENGTH] = 0x000UL, | 80 | [CAP_CAPLENGTH] = 0x000UL, |
81 | [CAP_HCCPARAMS] = 0x008UL, | 81 | [CAP_HCCPARAMS] = 0x008UL, |
@@ -88,6 +88,7 @@ static uintptr_t ci_regs_nolpm[] = { | |||
88 | [OP_ENDPTLISTADDR] = 0x018UL, | 88 | [OP_ENDPTLISTADDR] = 0x018UL, |
89 | [OP_PORTSC] = 0x044UL, | 89 | [OP_PORTSC] = 0x044UL, |
90 | [OP_DEVLC] = 0x084UL, | 90 | [OP_DEVLC] = 0x084UL, |
91 | [OP_OTGSC] = 0x064UL, | ||
91 | [OP_USBMODE] = 0x068UL, | 92 | [OP_USBMODE] = 0x068UL, |
92 | [OP_ENDPTSETUPSTAT] = 0x06CUL, | 93 | [OP_ENDPTSETUPSTAT] = 0x06CUL, |
93 | [OP_ENDPTPRIME] = 0x070UL, | 94 | [OP_ENDPTPRIME] = 0x070UL, |
@@ -109,6 +110,7 @@ static uintptr_t ci_regs_lpm[] = { | |||
109 | [OP_ENDPTLISTADDR] = 0x018UL, | 110 | [OP_ENDPTLISTADDR] = 0x018UL, |
110 | [OP_PORTSC] = 0x044UL, | 111 | [OP_PORTSC] = 0x044UL, |
111 | [OP_DEVLC] = 0x084UL, | 112 | [OP_DEVLC] = 0x084UL, |
113 | [OP_OTGSC] = 0x0C4UL, | ||
112 | [OP_USBMODE] = 0x0C8UL, | 114 | [OP_USBMODE] = 0x0C8UL, |
113 | [OP_ENDPTSETUPSTAT] = 0x0D8UL, | 115 | [OP_ENDPTSETUPSTAT] = 0x0D8UL, |
114 | [OP_ENDPTPRIME] = 0x0DCUL, | 116 | [OP_ENDPTPRIME] = 0x0DCUL, |
@@ -118,24 +120,24 @@ static uintptr_t ci_regs_lpm[] = { | |||
118 | [OP_ENDPTCTRL] = 0x0ECUL, | 120 | [OP_ENDPTCTRL] = 0x0ECUL, |
119 | }; | 121 | }; |
120 | 122 | ||
121 | static int hw_alloc_regmap(struct ci13xxx *udc, bool is_lpm) | 123 | static int hw_alloc_regmap(struct ci13xxx *ci, bool is_lpm) |
122 | { | 124 | { |
123 | int i; | 125 | int i; |
124 | 126 | ||
125 | kfree(udc->hw_bank.regmap); | 127 | kfree(ci->hw_bank.regmap); |
126 | 128 | ||
127 | udc->hw_bank.regmap = kzalloc((OP_LAST + 1) * sizeof(void *), | 129 | ci->hw_bank.regmap = kzalloc((OP_LAST + 1) * sizeof(void *), |
128 | GFP_KERNEL); | 130 | GFP_KERNEL); |
129 | if (!udc->hw_bank.regmap) | 131 | if (!ci->hw_bank.regmap) |
130 | return -ENOMEM; | 132 | return -ENOMEM; |
131 | 133 | ||
132 | for (i = 0; i < OP_ENDPTCTRL; i++) | 134 | for (i = 0; i < OP_ENDPTCTRL; i++) |
133 | udc->hw_bank.regmap[i] = | 135 | ci->hw_bank.regmap[i] = |
134 | (i <= CAP_LAST ? udc->hw_bank.cap : udc->hw_bank.op) + | 136 | (i <= CAP_LAST ? ci->hw_bank.cap : ci->hw_bank.op) + |
135 | (is_lpm ? ci_regs_lpm[i] : ci_regs_nolpm[i]); | 137 | (is_lpm ? ci_regs_lpm[i] : ci_regs_nolpm[i]); |
136 | 138 | ||
137 | for (; i <= OP_LAST; i++) | 139 | for (; i <= OP_LAST; i++) |
138 | udc->hw_bank.regmap[i] = udc->hw_bank.op + | 140 | ci->hw_bank.regmap[i] = ci->hw_bank.op + |
139 | 4 * (i - OP_ENDPTCTRL) + | 141 | 4 * (i - OP_ENDPTCTRL) + |
140 | (is_lpm | 142 | (is_lpm |
141 | ? ci_regs_lpm[OP_ENDPTCTRL] | 143 | ? ci_regs_lpm[OP_ENDPTCTRL] |
@@ -171,36 +173,35 @@ u8 hw_port_test_get(struct ci13xxx *ci) | |||
171 | return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); | 173 | return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); |
172 | } | 174 | } |
173 | 175 | ||
174 | int hw_device_init(struct ci13xxx *udc, void __iomem *base, | 176 | static int hw_device_init(struct ci13xxx *ci, void __iomem *base) |
175 | uintptr_t cap_offset) | ||
176 | { | 177 | { |
177 | u32 reg; | 178 | u32 reg; |
178 | 179 | ||
179 | /* bank is a module variable */ | 180 | /* bank is a module variable */ |
180 | udc->hw_bank.abs = base; | 181 | ci->hw_bank.abs = base; |
181 | 182 | ||
182 | udc->hw_bank.cap = udc->hw_bank.abs; | 183 | ci->hw_bank.cap = ci->hw_bank.abs; |
183 | udc->hw_bank.cap += cap_offset; | 184 | ci->hw_bank.cap += ci->udc_driver->capoffset; |
184 | udc->hw_bank.op = udc->hw_bank.cap + ioread8(udc->hw_bank.cap); | 185 | ci->hw_bank.op = ci->hw_bank.cap + ioread8(ci->hw_bank.cap); |
185 | 186 | ||
186 | hw_alloc_regmap(udc, false); | 187 | hw_alloc_regmap(ci, false); |
187 | reg = hw_read(udc, CAP_HCCPARAMS, HCCPARAMS_LEN) >> | 188 | reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> |
188 | ffs_nr(HCCPARAMS_LEN); | 189 | ffs_nr(HCCPARAMS_LEN); |
189 | udc->hw_bank.lpm = reg; | 190 | ci->hw_bank.lpm = reg; |
190 | hw_alloc_regmap(udc, !!reg); | 191 | hw_alloc_regmap(ci, !!reg); |
191 | udc->hw_bank.size = udc->hw_bank.op - udc->hw_bank.abs; | 192 | ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; |
192 | udc->hw_bank.size += OP_LAST; | 193 | ci->hw_bank.size += OP_LAST; |
193 | udc->hw_bank.size /= sizeof(u32); | 194 | ci->hw_bank.size /= sizeof(u32); |
194 | 195 | ||
195 | reg = hw_read(udc, CAP_DCCPARAMS, DCCPARAMS_DEN) >> | 196 | reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >> |
196 | ffs_nr(DCCPARAMS_DEN); | 197 | ffs_nr(DCCPARAMS_DEN); |
197 | udc->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ | 198 | ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ |
198 | 199 | ||
199 | if (udc->hw_ep_max == 0 || udc->hw_ep_max > ENDPT_MAX) | 200 | if (ci->hw_ep_max == 0 || ci->hw_ep_max > ENDPT_MAX) |
200 | return -ENODEV; | 201 | return -ENODEV; |
201 | 202 | ||
202 | dev_dbg(udc->dev, "ChipIdea UDC found, lpm: %d; cap: %p op: %p\n", | 203 | dev_dbg(ci->dev, "ChipIdea HDRC found, lpm: %d; cap: %p op: %p\n", |
203 | udc->hw_bank.lpm, udc->hw_bank.cap, udc->hw_bank.op); | 204 | ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); |
204 | 205 | ||
205 | /* setup lock mode ? */ | 206 | /* setup lock mode ? */ |
206 | 207 | ||
@@ -250,16 +251,98 @@ int hw_device_reset(struct ci13xxx *ci) | |||
250 | return 0; | 251 | return 0; |
251 | } | 252 | } |
252 | 253 | ||
253 | static int __devinit ci_udc_probe(struct platform_device *pdev) | 254 | /** |
255 | * ci_otg_role - pick role based on ID pin state | ||
256 | * @ci: the controller | ||
257 | */ | ||
258 | static enum ci_role ci_otg_role(struct ci13xxx *ci) | ||
259 | { | ||
260 | u32 sts = hw_read(ci, OP_OTGSC, ~0); | ||
261 | enum ci_role role = sts & OTGSC_ID | ||
262 | ? CI_ROLE_GADGET | ||
263 | : CI_ROLE_HOST; | ||
264 | |||
265 | return role; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * ci_role_work - perform role changing based on ID pin | ||
270 | * @work: work struct | ||
271 | */ | ||
272 | static void ci_role_work(struct work_struct *work) | ||
273 | { | ||
274 | struct ci13xxx *ci = container_of(work, struct ci13xxx, work); | ||
275 | enum ci_role role = ci_otg_role(ci); | ||
276 | |||
277 | hw_write(ci, OP_OTGSC, OTGSC_IDIS, OTGSC_IDIS); | ||
278 | |||
279 | if (role != ci->role) { | ||
280 | dev_dbg(ci->dev, "switching from %s to %s\n", | ||
281 | ci_role(ci)->name, ci->roles[role]->name); | ||
282 | |||
283 | ci_role_stop(ci); | ||
284 | ci_role_start(ci, role); | ||
285 | } | ||
286 | } | ||
287 | |||
288 | static ssize_t show_role(struct device *dev, struct device_attribute *attr, | ||
289 | char *buf) | ||
290 | { | ||
291 | struct ci13xxx *ci = dev_get_drvdata(dev); | ||
292 | |||
293 | return sprintf(buf, "%s\n", ci_role(ci)->name); | ||
294 | } | ||
295 | |||
296 | static ssize_t store_role(struct device *dev, struct device_attribute *attr, | ||
297 | const char *buf, size_t count) | ||
298 | { | ||
299 | struct ci13xxx *ci = dev_get_drvdata(dev); | ||
300 | enum ci_role role; | ||
301 | int ret; | ||
302 | |||
303 | for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++) | ||
304 | if (ci->roles[role] && !strcmp(buf, ci->roles[role]->name)) | ||
305 | break; | ||
306 | |||
307 | if (role == CI_ROLE_END || role == ci->role) | ||
308 | return -EINVAL; | ||
309 | |||
310 | ci_role_stop(ci); | ||
311 | ret = ci_role_start(ci, role); | ||
312 | if (ret) | ||
313 | return ret; | ||
314 | |||
315 | return count; | ||
316 | } | ||
317 | |||
318 | static DEVICE_ATTR(role, S_IRUSR | S_IWUSR, show_role, store_role); | ||
319 | |||
320 | static irqreturn_t ci_irq(int irq, void *data) | ||
321 | { | ||
322 | struct ci13xxx *ci = data; | ||
323 | irqreturn_t ret = IRQ_NONE; | ||
324 | |||
325 | if (ci->is_otg) { | ||
326 | u32 sts = hw_read(ci, OP_OTGSC, ~0); | ||
327 | |||
328 | if (sts & OTGSC_IDIS) { | ||
329 | queue_work(ci->wq, &ci->work); | ||
330 | ret = IRQ_HANDLED; | ||
331 | } | ||
332 | } | ||
333 | |||
334 | return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci); | ||
335 | } | ||
336 | |||
337 | static int __devinit ci_hdrc_probe(struct platform_device *pdev) | ||
254 | { | 338 | { |
255 | struct device *dev = &pdev->dev; | 339 | struct device *dev = &pdev->dev; |
256 | struct ci13xxx_udc_driver *driver = dev->platform_data; | 340 | struct ci13xxx *ci; |
257 | struct ci13xxx *udc; | ||
258 | struct resource *res; | 341 | struct resource *res; |
259 | void __iomem *base; | 342 | void __iomem *base; |
260 | int ret; | 343 | int ret; |
261 | 344 | ||
262 | if (!driver) { | 345 | if (!dev->platform_data) { |
263 | dev_err(dev, "platform data missing\n"); | 346 | dev_err(dev, "platform data missing\n"); |
264 | return -ENODEV; | 347 | return -ENODEV; |
265 | } | 348 | } |
@@ -276,49 +359,112 @@ static int __devinit ci_udc_probe(struct platform_device *pdev) | |||
276 | return -ENOMEM; | 359 | return -ENOMEM; |
277 | } | 360 | } |
278 | 361 | ||
279 | ret = udc_probe(driver, dev, base, &udc); | 362 | ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL); |
280 | if (ret) | 363 | if (!ci) { |
281 | return ret; | 364 | dev_err(dev, "can't allocate device\n"); |
365 | return -ENOMEM; | ||
366 | } | ||
367 | |||
368 | ci->dev = dev; | ||
369 | ci->udc_driver = dev->platform_data; | ||
370 | |||
371 | ret = hw_device_init(ci, base); | ||
372 | if (ret < 0) { | ||
373 | dev_err(dev, "can't initialize hardware\n"); | ||
374 | return -ENODEV; | ||
375 | } | ||
282 | 376 | ||
283 | udc->irq = platform_get_irq(pdev, 0); | 377 | ci->irq = platform_get_irq(pdev, 0); |
284 | if (udc->irq < 0) { | 378 | if (ci->irq < 0) { |
285 | dev_err(dev, "missing IRQ\n"); | 379 | dev_err(dev, "missing IRQ\n"); |
380 | return -ENODEV; | ||
381 | } | ||
382 | |||
383 | INIT_WORK(&ci->work, ci_role_work); | ||
384 | ci->wq = create_singlethread_workqueue("ci_otg"); | ||
385 | if (!ci->wq) { | ||
386 | dev_err(dev, "can't create workqueue\n"); | ||
387 | return -ENODEV; | ||
388 | } | ||
389 | |||
390 | /* initialize role(s) before the interrupt is requested */ | ||
391 | ret = ci_hdrc_gadget_init(ci); | ||
392 | if (ret) | ||
393 | dev_info(dev, "doesn't support gadget\n"); | ||
394 | |||
395 | if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { | ||
396 | dev_err(dev, "no supported roles\n"); | ||
397 | ret = -ENODEV; | ||
398 | goto rm_wq; | ||
399 | } | ||
400 | |||
401 | if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { | ||
402 | ci->is_otg = true; | ||
403 | ci->role = ci_otg_role(ci); | ||
404 | } else { | ||
405 | ci->role = ci->roles[CI_ROLE_HOST] | ||
406 | ? CI_ROLE_HOST | ||
407 | : CI_ROLE_GADGET; | ||
408 | } | ||
409 | |||
410 | ret = ci_role_start(ci, ci->role); | ||
411 | if (ret) { | ||
412 | dev_err(dev, "can't start %s role\n", ci_role(ci)->name); | ||
286 | ret = -ENODEV; | 413 | ret = -ENODEV; |
287 | goto out; | 414 | goto rm_wq; |
288 | } | 415 | } |
289 | 416 | ||
290 | platform_set_drvdata(pdev, udc); | 417 | platform_set_drvdata(pdev, ci); |
291 | ret = request_irq(udc->irq, udc_irq, IRQF_SHARED, driver->name, udc); | 418 | ret = request_irq(ci->irq, ci_irq, IRQF_SHARED, ci->udc_driver->name, |
419 | ci); | ||
420 | if (ret) | ||
421 | goto stop; | ||
292 | 422 | ||
293 | out: | 423 | ret = device_create_file(dev, &dev_attr_role); |
294 | if (ret) | 424 | if (ret) |
295 | udc_remove(udc); | 425 | goto rm_attr; |
426 | |||
427 | if (ci->is_otg) | ||
428 | hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE); | ||
429 | |||
430 | return ret; | ||
431 | |||
432 | rm_attr: | ||
433 | device_remove_file(dev, &dev_attr_role); | ||
434 | stop: | ||
435 | ci_role_stop(ci); | ||
436 | rm_wq: | ||
437 | flush_workqueue(ci->wq); | ||
438 | destroy_workqueue(ci->wq); | ||
296 | 439 | ||
297 | return ret; | 440 | return ret; |
298 | } | 441 | } |
299 | 442 | ||
300 | static int __devexit ci_udc_remove(struct platform_device *pdev) | 443 | static int __devexit ci_hdrc_remove(struct platform_device *pdev) |
301 | { | 444 | { |
302 | struct ci13xxx *udc = platform_get_drvdata(pdev); | 445 | struct ci13xxx *ci = platform_get_drvdata(pdev); |
303 | 446 | ||
304 | free_irq(udc->irq, udc); | 447 | flush_workqueue(ci->wq); |
305 | udc_remove(udc); | 448 | destroy_workqueue(ci->wq); |
449 | device_remove_file(ci->dev, &dev_attr_role); | ||
450 | free_irq(ci->irq, ci); | ||
451 | ci_role_stop(ci); | ||
306 | 452 | ||
307 | return 0; | 453 | return 0; |
308 | } | 454 | } |
309 | 455 | ||
310 | static struct platform_driver ci_udc_driver = { | 456 | static struct platform_driver ci_hdrc_driver = { |
311 | .probe = ci_udc_probe, | 457 | .probe = ci_hdrc_probe, |
312 | .remove = __devexit_p(ci_udc_remove), | 458 | .remove = __devexit_p(ci_hdrc_remove), |
313 | .driver = { | 459 | .driver = { |
314 | .name = "ci_udc", | 460 | .name = "ci_hdrc", |
315 | }, | 461 | }, |
316 | }; | 462 | }; |
317 | 463 | ||
318 | module_platform_driver(ci_udc_driver); | 464 | module_platform_driver(ci_hdrc_driver); |
319 | 465 | ||
320 | MODULE_ALIAS("platform:ci_udc"); | 466 | MODULE_ALIAS("platform:ci_hdrc"); |
321 | MODULE_ALIAS("platform:ci13xxx"); | 467 | MODULE_ALIAS("platform:ci13xxx"); |
322 | MODULE_LICENSE("GPL v2"); | 468 | MODULE_LICENSE("GPL v2"); |
323 | MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>"); | 469 | MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>"); |
324 | MODULE_DESCRIPTION("ChipIdea UDC Driver"); | 470 | MODULE_DESCRIPTION("ChipIdea HDRC Driver"); |
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 6866ef085397..9133a59450f4 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -1592,14 +1592,13 @@ static int ci13xxx_stop(struct usb_gadget *gadget, | |||
1592 | * BUS block | 1592 | * BUS block |
1593 | *****************************************************************************/ | 1593 | *****************************************************************************/ |
1594 | /** | 1594 | /** |
1595 | * udc_irq: global interrupt handler | 1595 | * udc_irq: udc interrupt handler |
1596 | * | 1596 | * |
1597 | * This function returns IRQ_HANDLED if the IRQ has been handled | 1597 | * This function returns IRQ_HANDLED if the IRQ has been handled |
1598 | * It locks access to registers | 1598 | * It locks access to registers |
1599 | */ | 1599 | */ |
1600 | irqreturn_t udc_irq(int irq, void *data) | 1600 | static irqreturn_t udc_irq(struct ci13xxx *udc) |
1601 | { | 1601 | { |
1602 | struct ci13xxx *udc = data; | ||
1603 | irqreturn_t retval; | 1602 | irqreturn_t retval; |
1604 | u32 intr; | 1603 | u32 intr; |
1605 | 1604 | ||
@@ -1666,38 +1665,24 @@ static void udc_release(struct device *dev) | |||
1666 | } | 1665 | } |
1667 | 1666 | ||
1668 | /** | 1667 | /** |
1669 | * udc_probe: parent probe must call this to initialize UDC | 1668 | * udc_start: initialize gadget role |
1670 | * @dev: parent device | 1669 | * @udc: chipidea controller |
1671 | * @regs: registers base address | ||
1672 | * @name: driver name | ||
1673 | * | ||
1674 | * This function returns an error code | ||
1675 | * No interrupts active, the IRQ has not been requested yet | ||
1676 | * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask | ||
1677 | */ | 1670 | */ |
1678 | int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | 1671 | static int udc_start(struct ci13xxx *udc) |
1679 | void __iomem *regs, struct ci13xxx **_udc) | ||
1680 | { | 1672 | { |
1681 | struct ci13xxx *udc; | 1673 | struct device *dev = udc->dev; |
1682 | int retval = 0; | 1674 | int retval = 0; |
1683 | 1675 | ||
1684 | if (dev == NULL || regs == NULL || driver == NULL || | 1676 | if (!udc) |
1685 | driver->name == NULL) | ||
1686 | return -EINVAL; | 1677 | return -EINVAL; |
1687 | 1678 | ||
1688 | udc = kzalloc(sizeof(struct ci13xxx), GFP_KERNEL); | ||
1689 | if (udc == NULL) | ||
1690 | return -ENOMEM; | ||
1691 | |||
1692 | spin_lock_init(&udc->lock); | 1679 | spin_lock_init(&udc->lock); |
1693 | udc->regs = regs; | ||
1694 | udc->udc_driver = driver; | ||
1695 | 1680 | ||
1696 | udc->gadget.ops = &usb_gadget_ops; | 1681 | udc->gadget.ops = &usb_gadget_ops; |
1697 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1682 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
1698 | udc->gadget.max_speed = USB_SPEED_HIGH; | 1683 | udc->gadget.max_speed = USB_SPEED_HIGH; |
1699 | udc->gadget.is_otg = 0; | 1684 | udc->gadget.is_otg = 0; |
1700 | udc->gadget.name = driver->name; | 1685 | udc->gadget.name = udc->udc_driver->name; |
1701 | 1686 | ||
1702 | INIT_LIST_HEAD(&udc->gadget.ep_list); | 1687 | INIT_LIST_HEAD(&udc->gadget.ep_list); |
1703 | 1688 | ||
@@ -1707,16 +1692,12 @@ int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | |||
1707 | udc->gadget.dev.parent = dev; | 1692 | udc->gadget.dev.parent = dev; |
1708 | udc->gadget.dev.release = udc_release; | 1693 | udc->gadget.dev.release = udc_release; |
1709 | 1694 | ||
1710 | udc->dev = dev; | ||
1711 | |||
1712 | /* alloc resources */ | 1695 | /* alloc resources */ |
1713 | udc->qh_pool = dma_pool_create("ci13xxx_qh", dev, | 1696 | udc->qh_pool = dma_pool_create("ci13xxx_qh", dev, |
1714 | sizeof(struct ci13xxx_qh), | 1697 | sizeof(struct ci13xxx_qh), |
1715 | 64, CI13XXX_PAGE_SIZE); | 1698 | 64, CI13XXX_PAGE_SIZE); |
1716 | if (udc->qh_pool == NULL) { | 1699 | if (udc->qh_pool == NULL) |
1717 | retval = -ENOMEM; | 1700 | return -ENOMEM; |
1718 | goto free_udc; | ||
1719 | } | ||
1720 | 1701 | ||
1721 | udc->td_pool = dma_pool_create("ci13xxx_td", dev, | 1702 | udc->td_pool = dma_pool_create("ci13xxx_td", dev, |
1722 | sizeof(struct ci13xxx_td), | 1703 | sizeof(struct ci13xxx_td), |
@@ -1726,10 +1707,6 @@ int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | |||
1726 | goto free_qh_pool; | 1707 | goto free_qh_pool; |
1727 | } | 1708 | } |
1728 | 1709 | ||
1729 | retval = hw_device_init(udc, regs, driver->capoffset); | ||
1730 | if (retval < 0) | ||
1731 | goto free_pools; | ||
1732 | |||
1733 | retval = init_eps(udc); | 1710 | retval = init_eps(udc); |
1734 | if (retval) | 1711 | if (retval) |
1735 | goto free_pools; | 1712 | goto free_pools; |
@@ -1775,7 +1752,6 @@ int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | |||
1775 | pm_runtime_no_callbacks(&udc->gadget.dev); | 1752 | pm_runtime_no_callbacks(&udc->gadget.dev); |
1776 | pm_runtime_enable(&udc->gadget.dev); | 1753 | pm_runtime_enable(&udc->gadget.dev); |
1777 | 1754 | ||
1778 | *_udc = udc; | ||
1779 | return retval; | 1755 | return retval; |
1780 | 1756 | ||
1781 | remove_trans: | 1757 | remove_trans: |
@@ -1796,9 +1772,6 @@ free_pools: | |||
1796 | dma_pool_destroy(udc->td_pool); | 1772 | dma_pool_destroy(udc->td_pool); |
1797 | free_qh_pool: | 1773 | free_qh_pool: |
1798 | dma_pool_destroy(udc->qh_pool); | 1774 | dma_pool_destroy(udc->qh_pool); |
1799 | free_udc: | ||
1800 | kfree(udc); | ||
1801 | *_udc = NULL; | ||
1802 | return retval; | 1775 | return retval; |
1803 | } | 1776 | } |
1804 | 1777 | ||
@@ -1807,7 +1780,7 @@ free_udc: | |||
1807 | * | 1780 | * |
1808 | * No interrupts active, the IRQ has been released | 1781 | * No interrupts active, the IRQ has been released |
1809 | */ | 1782 | */ |
1810 | void udc_remove(struct ci13xxx *udc) | 1783 | static void udc_stop(struct ci13xxx *udc) |
1811 | { | 1784 | { |
1812 | int i; | 1785 | int i; |
1813 | 1786 | ||
@@ -1826,12 +1799,37 @@ void udc_remove(struct ci13xxx *udc) | |||
1826 | dma_pool_destroy(udc->qh_pool); | 1799 | dma_pool_destroy(udc->qh_pool); |
1827 | 1800 | ||
1828 | if (udc->transceiver) { | 1801 | if (udc->transceiver) { |
1829 | otg_set_peripheral(udc->transceiver->otg, &udc->gadget); | 1802 | otg_set_peripheral(udc->transceiver->otg, NULL); |
1830 | usb_put_transceiver(udc->transceiver); | 1803 | usb_put_transceiver(udc->transceiver); |
1831 | } | 1804 | } |
1832 | dbg_remove_files(&udc->gadget.dev); | 1805 | dbg_remove_files(&udc->gadget.dev); |
1833 | device_unregister(&udc->gadget.dev); | 1806 | device_unregister(&udc->gadget.dev); |
1807 | /* my kobject is dynamic, I swear! */ | ||
1808 | memset(&udc->gadget, 0, sizeof(udc->gadget)); | ||
1809 | } | ||
1810 | |||
1811 | /** | ||
1812 | * ci_hdrc_gadget_init - initialize device related bits | ||
1813 | * ci: the controller | ||
1814 | * | ||
1815 | * This function enables the gadget role, if the device is "device capable". | ||
1816 | */ | ||
1817 | int ci_hdrc_gadget_init(struct ci13xxx *ci) | ||
1818 | { | ||
1819 | struct ci_role_driver *rdrv; | ||
1820 | |||
1821 | if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC)) | ||
1822 | return -ENXIO; | ||
1823 | |||
1824 | rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL); | ||
1825 | if (!rdrv) | ||
1826 | return -ENOMEM; | ||
1827 | |||
1828 | rdrv->start = udc_start; | ||
1829 | rdrv->stop = udc_stop; | ||
1830 | rdrv->irq = udc_irq; | ||
1831 | rdrv->name = "gadget"; | ||
1832 | ci->roles[CI_ROLE_GADGET] = rdrv; | ||
1834 | 1833 | ||
1835 | kfree(udc->hw_bank.regmap); | 1834 | return 0; |
1836 | kfree(udc); | ||
1837 | } | 1835 | } |
diff --git a/drivers/usb/chipidea/udc.h b/drivers/usb/chipidea/udc.h index 82c9e3e772f7..3a9e6694f327 100644 --- a/drivers/usb/chipidea/udc.h +++ b/drivers/usb/chipidea/udc.h | |||
@@ -71,26 +71,16 @@ struct ci13xxx_req { | |||
71 | }; | 71 | }; |
72 | 72 | ||
73 | #ifdef CONFIG_USB_CHIPIDEA_UDC | 73 | #ifdef CONFIG_USB_CHIPIDEA_UDC |
74 | irqreturn_t udc_irq(int irq, void *data); | 74 | |
75 | int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | 75 | int ci_hdrc_gadget_init(struct ci13xxx *ci); |
76 | void __iomem *regs, struct ci13xxx **_udc); | 76 | |
77 | void udc_remove(struct ci13xxx *udc); | ||
78 | #else | 77 | #else |
79 | static inline irqreturn_t udc_irq(int irq, void *data) | ||
80 | { | ||
81 | return IRQ_NONE; | ||
82 | } | ||
83 | 78 | ||
84 | static inline | 79 | static inline int ci_hdrc_gadget_init(struct ci13xxx *ci) |
85 | int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | ||
86 | void __iomem *regs, struct ci13xxx **_udc) | ||
87 | { | 80 | { |
88 | return -ENODEV; | 81 | return -ENXIO; |
89 | } | 82 | } |
90 | 83 | ||
91 | static inline void udc_remove(struct ci13xxx *udc) | ||
92 | { | ||
93 | } | ||
94 | #endif | 84 | #endif |
95 | 85 | ||
96 | #endif /* __DRIVERS_USB_CHIPIDEA_UDC_H */ | 86 | #endif /* __DRIVERS_USB_CHIPIDEA_UDC_H */ |