aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKishon Vijay Abraham I <kishon@ti.com>2012-06-22 07:32:47 -0400
committerFelipe Balbi <balbi@ti.com>2012-06-25 07:06:16 -0400
commit410219dcd2ba8d8b4bcfa9c232f35bf505bc021a (patch)
tree6aadab913c25bf86763649907a2d4ec0b9fa1582
parent662dca54ca67c92b7aa14b9a2ec54acacf33ce45 (diff)
usb: otg: utils: devres: Add API's to associate a device with the phy
Used devres API's to associate the phy with a device so that on driver detach, release function is invoked on the devres data(usb_phy) and devres data(usb_phy) is released. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r--drivers/usb/otg/otg.c62
-rw-r--r--include/linux/usb/otg.h13
2 files changed, 75 insertions, 0 deletions
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index a23065820ea..0fa4d8c1b1e 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -13,6 +13,7 @@
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/slab.h>
16 17
17#include <linux/usb/otg.h> 18#include <linux/usb/otg.h>
18 19
@@ -34,6 +35,48 @@ static struct usb_phy *__usb_find_phy(struct list_head *list,
34 return ERR_PTR(-ENODEV); 35 return ERR_PTR(-ENODEV);
35} 36}
36 37
38static void devm_usb_phy_release(struct device *dev, void *res)
39{
40 struct usb_phy *phy = *(struct usb_phy **)res;
41
42 usb_put_phy(phy);
43}
44
45static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
46{
47 return res == match_data;
48}
49
50/**
51 * devm_usb_get_phy - find the USB PHY
52 * @dev - device that requests this phy
53 * @type - the type of the phy the controller requires
54 *
55 * Gets the phy using usb_get_phy(), and associates a device with it using
56 * devres. On driver detach, release function is invoked on the devres data,
57 * then, devres data is freed.
58 *
59 * For use by USB host and peripheral drivers.
60 */
61struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
62{
63 struct usb_phy **ptr, *phy;
64
65 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
66 if (!ptr)
67 return NULL;
68
69 phy = usb_get_phy(type);
70 if (phy) {
71 *ptr = phy;
72 devres_add(dev, ptr);
73 } else
74 devres_free(ptr);
75
76 return phy;
77}
78EXPORT_SYMBOL(devm_usb_get_phy);
79
37/** 80/**
38 * usb_get_phy - find the USB PHY 81 * usb_get_phy - find the USB PHY
39 * @type - the type of the phy the controller requires 82 * @type - the type of the phy the controller requires
@@ -67,6 +110,25 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)
67EXPORT_SYMBOL(usb_get_phy); 110EXPORT_SYMBOL(usb_get_phy);
68 111
69/** 112/**
113 * devm_usb_put_phy - release the USB PHY
114 * @dev - device that wants to release this phy
115 * @phy - the phy returned by devm_usb_get_phy()
116 *
117 * destroys the devres associated with this phy and invokes usb_put_phy
118 * to release the phy.
119 *
120 * For use by USB host and peripheral drivers.
121 */
122void devm_usb_put_phy(struct device *dev, struct usb_phy *phy)
123{
124 int r;
125
126 r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy);
127 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
128}
129EXPORT_SYMBOL(devm_usb_put_phy);
130
131/**
70 * usb_put_phy - release the USB PHY 132 * usb_put_phy - release the USB PHY
71 * @x: the phy returned by usb_get_phy() 133 * @x: the phy returned by usb_get_phy()
72 * 134 *
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 1def65fb57d..0cb2ec2e50c 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -185,7 +185,10 @@ usb_phy_shutdown(struct usb_phy *x)
185/* for usb host and peripheral controller drivers */ 185/* for usb host and peripheral controller drivers */
186#ifdef CONFIG_USB_OTG_UTILS 186#ifdef CONFIG_USB_OTG_UTILS
187extern struct usb_phy *usb_get_phy(enum usb_phy_type type); 187extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
188extern struct usb_phy *devm_usb_get_phy(struct device *dev,
189 enum usb_phy_type type);
188extern void usb_put_phy(struct usb_phy *); 190extern void usb_put_phy(struct usb_phy *);
191extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
189extern const char *otg_state_string(enum usb_otg_state state); 192extern const char *otg_state_string(enum usb_otg_state state);
190#else 193#else
191static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) 194static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
@@ -193,10 +196,20 @@ static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
193 return NULL; 196 return NULL;
194} 197}
195 198
199static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
200 enum usb_phy_type type)
201{
202 return NULL;
203}
204
196static inline void usb_put_phy(struct usb_phy *x) 205static inline void usb_put_phy(struct usb_phy *x)
197{ 206{
198} 207}
199 208
209static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
210{
211}
212
200static inline const char *otg_state_string(enum usb_otg_state state) 213static inline const char *otg_state_string(enum usb_otg_state state)
201{ 214{
202 return NULL; 215 return NULL;