Commit 2f36ff69 authored by Felipe Balbi's avatar Felipe Balbi

usb: phy: generic: allow multiples calls to usb_phy_generic_register()

it's now very easy to return a platform_device pointer
and have the caller pass it as argument when calling
usb_phy_generic_unregister().
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent e741e637
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
struct am35x_glue { struct am35x_glue {
struct device *dev; struct device *dev;
struct platform_device *musb; struct platform_device *musb;
struct platform_device *phy;
struct clk *phy_clk; struct clk *phy_clk;
struct clk *clk; struct clk *clk;
}; };
...@@ -503,7 +504,9 @@ static int am35x_probe(struct platform_device *pdev) ...@@ -503,7 +504,9 @@ static int am35x_probe(struct platform_device *pdev)
pdata->platform_ops = &am35x_ops; pdata->platform_ops = &am35x_ops;
usb_phy_generic_register(); glue->phy = usb_phy_generic_register();
if (IS_ERR(glue->phy))
goto err7;
platform_set_drvdata(pdev, glue); platform_set_drvdata(pdev, glue);
pinfo = am35x_dev_info; pinfo = am35x_dev_info;
...@@ -517,11 +520,14 @@ static int am35x_probe(struct platform_device *pdev) ...@@ -517,11 +520,14 @@ static int am35x_probe(struct platform_device *pdev)
if (IS_ERR(musb)) { if (IS_ERR(musb)) {
ret = PTR_ERR(musb); ret = PTR_ERR(musb);
dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
goto err7; goto err8;
} }
return 0; return 0;
err8:
usb_phy_generic_unregister(glue->phy);
err7: err7:
clk_disable(clk); clk_disable(clk);
...@@ -546,7 +552,7 @@ static int am35x_remove(struct platform_device *pdev) ...@@ -546,7 +552,7 @@ static int am35x_remove(struct platform_device *pdev)
struct am35x_glue *glue = platform_get_drvdata(pdev); struct am35x_glue *glue = platform_get_drvdata(pdev);
platform_device_unregister(glue->musb); platform_device_unregister(glue->musb);
usb_phy_generic_unregister(); usb_phy_generic_unregister(glue->phy);
clk_disable(glue->clk); clk_disable(glue->clk);
clk_disable(glue->phy_clk); clk_disable(glue->phy_clk);
clk_put(glue->clk); clk_put(glue->clk);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
struct bfin_glue { struct bfin_glue {
struct device *dev; struct device *dev;
struct platform_device *musb; struct platform_device *musb;
struct platform_device *phy;
}; };
#define glue_to_musb(g) platform_get_drvdata(g->musb) #define glue_to_musb(g) platform_get_drvdata(g->musb)
...@@ -475,7 +476,9 @@ static int bfin_probe(struct platform_device *pdev) ...@@ -475,7 +476,9 @@ static int bfin_probe(struct platform_device *pdev)
pdata->platform_ops = &bfin_ops; pdata->platform_ops = &bfin_ops;
usb_phy_generic_register(); glue->phy = usb_phy_generic_register();
if (IS_ERR(glue->phy))
goto err2;
platform_set_drvdata(pdev, glue); platform_set_drvdata(pdev, glue);
memset(musb_resources, 0x00, sizeof(*musb_resources) * memset(musb_resources, 0x00, sizeof(*musb_resources) *
...@@ -513,6 +516,9 @@ static int bfin_probe(struct platform_device *pdev) ...@@ -513,6 +516,9 @@ static int bfin_probe(struct platform_device *pdev)
return 0; return 0;
err3: err3:
usb_phy_generic_unregister(glue->phy);
err2:
platform_device_put(musb); platform_device_put(musb);
err1: err1:
...@@ -527,7 +533,7 @@ static int bfin_remove(struct platform_device *pdev) ...@@ -527,7 +533,7 @@ static int bfin_remove(struct platform_device *pdev)
struct bfin_glue *glue = platform_get_drvdata(pdev); struct bfin_glue *glue = platform_get_drvdata(pdev);
platform_device_unregister(glue->musb); platform_device_unregister(glue->musb);
usb_phy_generic_unregister(); usb_phy_generic_unregister(glue->phy);
kfree(glue); kfree(glue);
return 0; return 0;
......
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
struct da8xx_glue { struct da8xx_glue {
struct device *dev; struct device *dev;
struct platform_device *musb; struct platform_device *musb;
struct platform_device *phy;
struct clk *clk; struct clk *clk;
}; };
...@@ -510,7 +511,11 @@ static int da8xx_probe(struct platform_device *pdev) ...@@ -510,7 +511,11 @@ static int da8xx_probe(struct platform_device *pdev)
pdata->platform_ops = &da8xx_ops; pdata->platform_ops = &da8xx_ops;
usb_phy_generic_register(); glue->phy = usb_phy_generic_register();
if (IS_ERR(glue->phy)) {
ret = PTR_ERR(glue->phy);
goto err5;
}
platform_set_drvdata(pdev, glue); platform_set_drvdata(pdev, glue);
memset(musb_resources, 0x00, sizeof(*musb_resources) * memset(musb_resources, 0x00, sizeof(*musb_resources) *
...@@ -537,11 +542,14 @@ static int da8xx_probe(struct platform_device *pdev) ...@@ -537,11 +542,14 @@ static int da8xx_probe(struct platform_device *pdev)
if (IS_ERR(musb)) { if (IS_ERR(musb)) {
ret = PTR_ERR(musb); ret = PTR_ERR(musb);
dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
goto err5; goto err6;
} }
return 0; return 0;
err6:
usb_phy_generic_unregister(glue->phy);
err5: err5:
clk_disable(clk); clk_disable(clk);
...@@ -560,7 +568,7 @@ static int da8xx_remove(struct platform_device *pdev) ...@@ -560,7 +568,7 @@ static int da8xx_remove(struct platform_device *pdev)
struct da8xx_glue *glue = platform_get_drvdata(pdev); struct da8xx_glue *glue = platform_get_drvdata(pdev);
platform_device_unregister(glue->musb); platform_device_unregister(glue->musb);
usb_phy_generic_unregister(); usb_phy_generic_unregister(glue->phy);
clk_disable(glue->clk); clk_disable(glue->clk);
clk_put(glue->clk); clk_put(glue->clk);
kfree(glue); kfree(glue);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
struct tusb6010_glue { struct tusb6010_glue {
struct device *dev; struct device *dev;
struct platform_device *musb; struct platform_device *musb;
struct platform_device *phy;
}; };
static void tusb_musb_set_vbus(struct musb *musb, int is_on); static void tusb_musb_set_vbus(struct musb *musb, int is_on);
...@@ -1222,7 +1223,7 @@ static int tusb_remove(struct platform_device *pdev) ...@@ -1222,7 +1223,7 @@ static int tusb_remove(struct platform_device *pdev)
struct tusb6010_glue *glue = platform_get_drvdata(pdev); struct tusb6010_glue *glue = platform_get_drvdata(pdev);
platform_device_unregister(glue->musb); platform_device_unregister(glue->musb);
usb_phy_generic_unregister(); usb_phy_generic_unregister(glue->phy);
kfree(glue); kfree(glue);
return 0; return 0;
......
...@@ -41,25 +41,16 @@ ...@@ -41,25 +41,16 @@
#include "phy-generic.h" #include "phy-generic.h"
static struct platform_device *pd; struct platform_device *usb_phy_generic_register(void)
void usb_phy_generic_register(void)
{ {
if (pd) return platform_device_register_simple("usb_phy_generic",
return; PLATFORM_DEVID_AUTO, NULL, 0);
pd = platform_device_register_simple("usb_phy_generic", -1, NULL, 0);
if (IS_ERR(pd)) {
pr_err("Unable to register generic usb transceiver\n");
pd = NULL;
return;
}
} }
EXPORT_SYMBOL_GPL(usb_phy_generic_register); EXPORT_SYMBOL_GPL(usb_phy_generic_register);
void usb_phy_generic_unregister(void) void usb_phy_generic_unregister(struct platform_device *pdev)
{ {
platform_device_unregister(pd); platform_device_unregister(pdev);
pd = NULL;
} }
EXPORT_SYMBOL_GPL(usb_phy_generic_unregister); EXPORT_SYMBOL_GPL(usb_phy_generic_unregister);
......
...@@ -15,14 +15,15 @@ struct usb_phy_generic_platform_data { ...@@ -15,14 +15,15 @@ struct usb_phy_generic_platform_data {
#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
/* sometimes transceivers are accessed only through e.g. ULPI */ /* sometimes transceivers are accessed only through e.g. ULPI */
extern void usb_phy_generic_register(void); extern struct platform_device *usb_phy_generic_register(void);
extern void usb_phy_generic_unregister(void); extern void usb_phy_generic_unregister(struct platform_device *);
#else #else
static inline void usb_phy_generic_register(void) static inline struct platform_device *usb_phy_generic_register(void)
{ {
return NULL;
} }
static inline void usb_phy_generic_unregister(void) static inline void usb_phy_generic_unregister(struct platform_device *pdev)
{ {
} }
#endif #endif
......
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