Commit 410219dc authored by Kishon Vijay Abraham I's avatar Kishon Vijay Abraham I Committed by Felipe Balbi

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: default avatarKishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 662dca54
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/slab.h>
#include <linux/usb/otg.h> #include <linux/usb/otg.h>
...@@ -34,6 +35,48 @@ static struct usb_phy *__usb_find_phy(struct list_head *list, ...@@ -34,6 +35,48 @@ static struct usb_phy *__usb_find_phy(struct list_head *list,
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
} }
static void devm_usb_phy_release(struct device *dev, void *res)
{
struct usb_phy *phy = *(struct usb_phy **)res;
usb_put_phy(phy);
}
static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
{
return res == match_data;
}
/**
* devm_usb_get_phy - find the USB PHY
* @dev - device that requests this phy
* @type - the type of the phy the controller requires
*
* Gets the phy using usb_get_phy(), and associates a device with it using
* devres. On driver detach, release function is invoked on the devres data,
* then, devres data is freed.
*
* For use by USB host and peripheral drivers.
*/
struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
{
struct usb_phy **ptr, *phy;
ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return NULL;
phy = usb_get_phy(type);
if (phy) {
*ptr = phy;
devres_add(dev, ptr);
} else
devres_free(ptr);
return phy;
}
EXPORT_SYMBOL(devm_usb_get_phy);
/** /**
* usb_get_phy - find the USB PHY * usb_get_phy - find the USB PHY
* @type - the type of the phy the controller requires * @type - the type of the phy the controller requires
...@@ -66,6 +109,25 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type) ...@@ -66,6 +109,25 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)
} }
EXPORT_SYMBOL(usb_get_phy); EXPORT_SYMBOL(usb_get_phy);
/**
* devm_usb_put_phy - release the USB PHY
* @dev - device that wants to release this phy
* @phy - the phy returned by devm_usb_get_phy()
*
* destroys the devres associated with this phy and invokes usb_put_phy
* to release the phy.
*
* For use by USB host and peripheral drivers.
*/
void devm_usb_put_phy(struct device *dev, struct usb_phy *phy)
{
int r;
r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy);
dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
}
EXPORT_SYMBOL(devm_usb_put_phy);
/** /**
* usb_put_phy - release the USB PHY * usb_put_phy - release the USB PHY
* @x: the phy returned by usb_get_phy() * @x: the phy returned by usb_get_phy()
......
...@@ -185,7 +185,10 @@ usb_phy_shutdown(struct usb_phy *x) ...@@ -185,7 +185,10 @@ usb_phy_shutdown(struct usb_phy *x)
/* for usb host and peripheral controller drivers */ /* for usb host and peripheral controller drivers */
#ifdef CONFIG_USB_OTG_UTILS #ifdef CONFIG_USB_OTG_UTILS
extern struct usb_phy *usb_get_phy(enum usb_phy_type type); extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
extern struct usb_phy *devm_usb_get_phy(struct device *dev,
enum usb_phy_type type);
extern void usb_put_phy(struct usb_phy *); extern void usb_put_phy(struct usb_phy *);
extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
extern const char *otg_state_string(enum usb_otg_state state); extern const char *otg_state_string(enum usb_otg_state state);
#else #else
static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) static 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,10 +196,20 @@ static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
return NULL; return NULL;
} }
static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
enum usb_phy_type type)
{
return NULL;
}
static inline void usb_put_phy(struct usb_phy *x) static inline void usb_put_phy(struct usb_phy *x)
{ {
} }
static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
{
}
static inline const char *otg_state_string(enum usb_otg_state state) static inline const char *otg_state_string(enum usb_otg_state state)
{ {
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment