aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/otg
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-25 12:09:46 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-25 12:09:46 -0500
commit4811f53fada7f2c6616229cc410e79362818a613 (patch)
tree7087507a15fe828ce80576a357a2a2d40c1ae191 /drivers/usb/otg
parentcba6c85027057d4bf7029d32c64e2647859be07a (diff)
parent5088b6f5bcf1747345ef9fe217fc80935b1b07df (diff)
Merge tag 'xceiv-for-v3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes: usb: xceiv: patches for v3.9 merge window Two new PHY drivers coming here: one for Samsung, one for OMAP. Both architectures are adding USB3 support to mainline kernel. The PHY layer now allows us to have mulitple PHYs of the same type, which is necessary for platforms which provide more than one USB peripheral port. There's also a few cleanups here: removal of __dev* annotations, conversion of a cast to to_delayed_work(), and mxs-phy learns about ->set_suspend.
Diffstat (limited to 'drivers/usb/otg')
-rw-r--r--drivers/usb/otg/mv_otg.c2
-rw-r--r--drivers/usb/otg/mxs-phy.c20
-rw-r--r--drivers/usb/otg/otg.c235
-rw-r--r--drivers/usb/otg/twl4030-usb.c3
4 files changed, 257 insertions, 3 deletions
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c
index da2d60c06f15..b6a9be31133b 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/otg/mv_otg.c
@@ -420,7 +420,7 @@ static void mv_otg_work(struct work_struct *work)
420 struct usb_otg *otg; 420 struct usb_otg *otg;
421 int old_state; 421 int old_state;
422 422
423 mvotg = container_of((struct delayed_work *)work, struct mv_otg, work); 423 mvotg = container_of(to_delayed_work(work), struct mv_otg, work);
424 424
425run: 425run:
426 /* work queue is single thread, or we need spin_lock to protect */ 426 /* work queue is single thread, or we need spin_lock to protect */
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
index 76302720055a..5158332522b1 100644
--- a/drivers/usb/otg/mxs-phy.c
+++ b/drivers/usb/otg/mxs-phy.c
@@ -76,6 +76,25 @@ static void mxs_phy_shutdown(struct usb_phy *phy)
76 clk_disable_unprepare(mxs_phy->clk); 76 clk_disable_unprepare(mxs_phy->clk);
77} 77}
78 78
79static int mxs_phy_suspend(struct usb_phy *x, int suspend)
80{
81 struct mxs_phy *mxs_phy = to_mxs_phy(x);
82
83 if (suspend) {
84 writel_relaxed(0xffffffff, x->io_priv + HW_USBPHY_PWD);
85 writel_relaxed(BM_USBPHY_CTRL_CLKGATE,
86 x->io_priv + HW_USBPHY_CTRL_SET);
87 clk_disable_unprepare(mxs_phy->clk);
88 } else {
89 clk_prepare_enable(mxs_phy->clk);
90 writel_relaxed(BM_USBPHY_CTRL_CLKGATE,
91 x->io_priv + HW_USBPHY_CTRL_CLR);
92 writel_relaxed(0, x->io_priv + HW_USBPHY_PWD);
93 }
94
95 return 0;
96}
97
79static int mxs_phy_on_connect(struct usb_phy *phy, 98static int mxs_phy_on_connect(struct usb_phy *phy,
80 enum usb_device_speed speed) 99 enum usb_device_speed speed)
81{ 100{
@@ -137,6 +156,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
137 mxs_phy->phy.label = DRIVER_NAME; 156 mxs_phy->phy.label = DRIVER_NAME;
138 mxs_phy->phy.init = mxs_phy_init; 157 mxs_phy->phy.init = mxs_phy_init;
139 mxs_phy->phy.shutdown = mxs_phy_shutdown; 158 mxs_phy->phy.shutdown = mxs_phy_shutdown;
159 mxs_phy->phy.set_suspend = mxs_phy_suspend;
140 mxs_phy->phy.notify_connect = mxs_phy_on_connect; 160 mxs_phy->phy.notify_connect = mxs_phy_on_connect;
141 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect; 161 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect;
142 162
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index a30c04115115..e1814397ca3a 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -13,11 +13,14 @@
13#include <linux/export.h> 13#include <linux/export.h>
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/module.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/of.h>
17 19
18#include <linux/usb/otg.h> 20#include <linux/usb/otg.h>
19 21
20static LIST_HEAD(phy_list); 22static LIST_HEAD(phy_list);
23static LIST_HEAD(phy_bind_list);
21static DEFINE_SPINLOCK(phy_lock); 24static DEFINE_SPINLOCK(phy_lock);
22 25
23static struct usb_phy *__usb_find_phy(struct list_head *list, 26static struct usb_phy *__usb_find_phy(struct list_head *list,
@@ -35,6 +38,38 @@ static struct usb_phy *__usb_find_phy(struct list_head *list,
35 return ERR_PTR(-ENODEV); 38 return ERR_PTR(-ENODEV);
36} 39}
37 40
41static struct usb_phy *__usb_find_phy_dev(struct device *dev,
42 struct list_head *list, u8 index)
43{
44 struct usb_phy_bind *phy_bind = NULL;
45
46 list_for_each_entry(phy_bind, list, list) {
47 if (!(strcmp(phy_bind->dev_name, dev_name(dev))) &&
48 phy_bind->index == index) {
49 if (phy_bind->phy)
50 return phy_bind->phy;
51 else
52 return ERR_PTR(-EPROBE_DEFER);
53 }
54 }
55
56 return ERR_PTR(-ENODEV);
57}
58
59static struct usb_phy *__of_usb_find_phy(struct device_node *node)
60{
61 struct usb_phy *phy;
62
63 list_for_each_entry(phy, &phy_list, head) {
64 if (node != phy->dev->of_node)
65 continue;
66
67 return phy;
68 }
69
70 return ERR_PTR(-ENODEV);
71}
72
38static void devm_usb_phy_release(struct device *dev, void *res) 73static void devm_usb_phy_release(struct device *dev, void *res)
39{ 74{
40 struct usb_phy *phy = *(struct usb_phy **)res; 75 struct usb_phy *phy = *(struct usb_phy **)res;
@@ -110,6 +145,133 @@ err0:
110} 145}
111EXPORT_SYMBOL(usb_get_phy); 146EXPORT_SYMBOL(usb_get_phy);
112 147
148 /**
149 * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
150 * @dev - device that requests this phy
151 * @phandle - name of the property holding the phy phandle value
152 * @index - the index of the phy
153 *
154 * Returns the phy driver associated with the given phandle value,
155 * after getting a refcount to it, -ENODEV if there is no such phy or
156 * -EPROBE_DEFER if there is a phandle to the phy, but the device is
157 * not yet loaded. While at that, it also associates the device with
158 * the phy using devres. On driver detach, release function is invoked
159 * on the devres data, then, devres data is freed.
160 *
161 * For use by USB host and peripheral drivers.
162 */
163struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
164 const char *phandle, u8 index)
165{
166 struct usb_phy *phy = ERR_PTR(-ENOMEM), **ptr;
167 unsigned long flags;
168 struct device_node *node;
169
170 if (!dev->of_node) {
171 dev_dbg(dev, "device does not have a device node entry\n");
172 return ERR_PTR(-EINVAL);
173 }
174
175 node = of_parse_phandle(dev->of_node, phandle, index);
176 if (!node) {
177 dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle,
178 dev->of_node->full_name);
179 return ERR_PTR(-ENODEV);
180 }
181
182 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
183 if (!ptr) {
184 dev_dbg(dev, "failed to allocate memory for devres\n");
185 goto err0;
186 }
187
188 spin_lock_irqsave(&phy_lock, flags);
189
190 phy = __of_usb_find_phy(node);
191 if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
192 phy = ERR_PTR(-EPROBE_DEFER);
193 devres_free(ptr);
194 goto err1;
195 }
196
197 *ptr = phy;
198 devres_add(dev, ptr);
199
200 get_device(phy->dev);
201
202err1:
203 spin_unlock_irqrestore(&phy_lock, flags);
204
205err0:
206 of_node_put(node);
207
208 return phy;
209}
210EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
211
212/**
213 * usb_get_phy_dev - find the USB PHY
214 * @dev - device that requests this phy
215 * @index - the index of the phy
216 *
217 * Returns the phy driver, after getting a refcount to it; or
218 * -ENODEV if there is no such phy. The caller is responsible for
219 * calling usb_put_phy() to release that count.
220 *
221 * For use by USB host and peripheral drivers.
222 */
223struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)
224{
225 struct usb_phy *phy = NULL;
226 unsigned long flags;
227
228 spin_lock_irqsave(&phy_lock, flags);
229
230 phy = __usb_find_phy_dev(dev, &phy_bind_list, index);
231 if (IS_ERR(phy)) {
232 pr_err("unable to find transceiver\n");
233 goto err0;
234 }
235
236 get_device(phy->dev);
237
238err0:
239 spin_unlock_irqrestore(&phy_lock, flags);
240
241 return phy;
242}
243EXPORT_SYMBOL(usb_get_phy_dev);
244
245/**
246 * devm_usb_get_phy_dev - find the USB PHY using device ptr and index
247 * @dev - device that requests this phy
248 * @index - the index of the phy
249 *
250 * Gets the phy using usb_get_phy_dev(), and associates a device with it using
251 * devres. On driver detach, release function is invoked on the devres data,
252 * then, devres data is freed.
253 *
254 * For use by USB host and peripheral drivers.
255 */
256struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index)
257{
258 struct usb_phy **ptr, *phy;
259
260 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
261 if (!ptr)
262 return NULL;
263
264 phy = usb_get_phy_dev(dev, index);
265 if (!IS_ERR(phy)) {
266 *ptr = phy;
267 devres_add(dev, ptr);
268 } else
269 devres_free(ptr);
270
271 return phy;
272}
273EXPORT_SYMBOL(devm_usb_get_phy_dev);
274
113/** 275/**
114 * devm_usb_put_phy - release the USB PHY 276 * devm_usb_put_phy - release the USB PHY
115 * @dev - device that wants to release this phy 277 * @dev - device that wants to release this phy
@@ -185,6 +347,36 @@ out:
185EXPORT_SYMBOL(usb_add_phy); 347EXPORT_SYMBOL(usb_add_phy);
186 348
187/** 349/**
350 * usb_add_phy_dev - declare the USB PHY
351 * @x: the USB phy to be used; or NULL
352 *
353 * This call is exclusively for use by phy drivers, which
354 * coordinate the activities of drivers for host and peripheral
355 * controllers, and in some cases for VBUS current regulation.
356 */
357int usb_add_phy_dev(struct usb_phy *x)
358{
359 struct usb_phy_bind *phy_bind;
360 unsigned long flags;
361
362 if (!x->dev) {
363 dev_err(x->dev, "no device provided for PHY\n");
364 return -EINVAL;
365 }
366
367 spin_lock_irqsave(&phy_lock, flags);
368 list_for_each_entry(phy_bind, &phy_bind_list, list)
369 if (!(strcmp(phy_bind->phy_dev_name, dev_name(x->dev))))
370 phy_bind->phy = x;
371
372 list_add_tail(&x->head, &phy_list);
373
374 spin_unlock_irqrestore(&phy_lock, flags);
375 return 0;
376}
377EXPORT_SYMBOL(usb_add_phy_dev);
378
379/**
188 * usb_remove_phy - remove the OTG PHY 380 * usb_remove_phy - remove the OTG PHY
189 * @x: the USB OTG PHY to be removed; 381 * @x: the USB OTG PHY to be removed;
190 * 382 *
@@ -193,14 +385,55 @@ EXPORT_SYMBOL(usb_add_phy);
193void usb_remove_phy(struct usb_phy *x) 385void usb_remove_phy(struct usb_phy *x)
194{ 386{
195 unsigned long flags; 387 unsigned long flags;
388 struct usb_phy_bind *phy_bind;
196 389
197 spin_lock_irqsave(&phy_lock, flags); 390 spin_lock_irqsave(&phy_lock, flags);
198 if (x) 391 if (x) {
392 list_for_each_entry(phy_bind, &phy_bind_list, list)
393 if (phy_bind->phy == x)
394 phy_bind->phy = NULL;
199 list_del(&x->head); 395 list_del(&x->head);
396 }
200 spin_unlock_irqrestore(&phy_lock, flags); 397 spin_unlock_irqrestore(&phy_lock, flags);
201} 398}
202EXPORT_SYMBOL(usb_remove_phy); 399EXPORT_SYMBOL(usb_remove_phy);
203 400
401/**
402 * usb_bind_phy - bind the phy and the controller that uses the phy
403 * @dev_name: the device name of the device that will bind to the phy
404 * @index: index to specify the port number
405 * @phy_dev_name: the device name of the phy
406 *
407 * Fills the phy_bind structure with the dev_name and phy_dev_name. This will
408 * be used when the phy driver registers the phy and when the controller
409 * requests this phy.
410 *
411 * To be used by platform specific initialization code.
412 */
413int __init usb_bind_phy(const char *dev_name, u8 index,
414 const char *phy_dev_name)
415{
416 struct usb_phy_bind *phy_bind;
417 unsigned long flags;
418
419 phy_bind = kzalloc(sizeof(*phy_bind), GFP_KERNEL);
420 if (!phy_bind) {
421 pr_err("phy_bind(): No memory for phy_bind");
422 return -ENOMEM;
423 }
424
425 phy_bind->dev_name = dev_name;
426 phy_bind->phy_dev_name = phy_dev_name;
427 phy_bind->index = index;
428
429 spin_lock_irqsave(&phy_lock, flags);
430 list_add_tail(&phy_bind->list, &phy_bind_list);
431 spin_unlock_irqrestore(&phy_lock, flags);
432
433 return 0;
434}
435EXPORT_SYMBOL_GPL(usb_bind_phy);
436
204const char *otg_state_string(enum usb_otg_state state) 437const char *otg_state_string(enum usb_otg_state state)
205{ 438{
206 switch (state) { 439 switch (state) {
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 0a701938ab53..a994715a3101 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -610,6 +610,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
610 twl->phy.dev = twl->dev; 610 twl->phy.dev = twl->dev;
611 twl->phy.label = "twl4030"; 611 twl->phy.label = "twl4030";
612 twl->phy.otg = otg; 612 twl->phy.otg = otg;
613 twl->phy.type = USB_PHY_TYPE_USB2;
613 twl->phy.set_suspend = twl4030_set_suspend; 614 twl->phy.set_suspend = twl4030_set_suspend;
614 615
615 otg->phy = &twl->phy; 616 otg->phy = &twl->phy;
@@ -624,7 +625,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
624 dev_err(&pdev->dev, "ldo init failed\n"); 625 dev_err(&pdev->dev, "ldo init failed\n");
625 return err; 626 return err;
626 } 627 }
627 usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2); 628 usb_add_phy_dev(&twl->phy);
628 629
629 platform_set_drvdata(pdev, twl); 630 platform_set_drvdata(pdev, twl);
630 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 631 if (device_create_file(&pdev->dev, &dev_attr_vbus))