* [PATCH] usb: phy: tahvo: Use devm_extcon_dev_* function for resource management of extcon
@ 2014-04-23 4:12 Chanwoo Choi
2014-04-23 16:03 ` Felipe Balbi
0 siblings, 1 reply; 2+ messages in thread
From: Chanwoo Choi @ 2014-04-23 4:12 UTC (permalink / raw)
To: balbi, gregkh; +Cc: linux-usb, linux-kernel, Chanwoo Choi
This patch uses devm_extcon_dev_{allocate, register} function for automatically
resource management of extcon device instead of legacy method and simplifies
the behavior of register/unregister for extcon device.
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
This patch has dependency about following patches[1-2]:
[1] https://lkml.org/lkml/2014/4/21/140
[2] https://lkml.org/lkml/2014/4/21/164
drivers/usb/phy/phy-tahvo.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
index cc61ee4..8cde928 100644
--- a/drivers/usb/phy/phy-tahvo.c
+++ b/drivers/usb/phy/phy-tahvo.c
@@ -57,7 +57,7 @@ struct tahvo_usb {
struct clk *ick;
int irq;
int tahvo_mode;
- struct extcon_dev extcon;
+ struct extcon_dev *extcon;
};
static const char *tahvo_cable[] = {
@@ -118,7 +118,7 @@ static void check_vbus_state(struct tahvo_usb *tu)
prev_state = tu->vbus_state;
tu->vbus_state = reg & TAHVO_STAT_VBUS;
if (prev_state != tu->vbus_state) {
- extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
+ extcon_set_cable_state(tu->extcon, "USB", tu->vbus_state);
sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state");
}
}
@@ -127,7 +127,7 @@ static void tahvo_usb_become_host(struct tahvo_usb *tu)
{
struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
- extcon_set_cable_state(&tu->extcon, "USB-HOST", true);
+ extcon_set_cable_state(tu->extcon, "USB-HOST", true);
/* Power up the transceiver in USB host mode */
retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
@@ -146,7 +146,7 @@ static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)
{
struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
- extcon_set_cable_state(&tu->extcon, "USB-HOST", false);
+ extcon_set_cable_state(tu->extcon, "USB-HOST", false);
/* Power up transceiver and set it in USB peripheral mode */
retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT |
@@ -360,11 +360,15 @@ static int tahvo_usb_probe(struct platform_device *pdev)
*/
tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS;
- tu->extcon.name = DRIVER_NAME;
- tu->extcon.supported_cable = tahvo_cable;
- tu->extcon.dev.parent = &pdev->dev;
+ tu->extcon = devm_extcon_dev_allocate(&pdev->dev, tahvo_cable);
+ if (!tu->extcon) {
+ dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
+ return -ENOMEM;
+ }
+ tu->extcon->name = DRIVER_NAME;
+ tu->extcon->dev.parent = &pdev->dev;
- ret = extcon_dev_register(&tu->extcon);
+ ret = devm_extcon_dev_register(&pdev->dev, tu->extcon);
if (ret) {
dev_err(&pdev->dev, "could not register extcon device: %d\n",
ret);
@@ -372,9 +376,9 @@ static int tahvo_usb_probe(struct platform_device *pdev)
}
/* Set the initial cable state. */
- extcon_set_cable_state(&tu->extcon, "USB-HOST",
+ extcon_set_cable_state(tu->extcon, "USB-HOST",
tu->tahvo_mode == TAHVO_MODE_HOST);
- extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
+ extcon_set_cable_state(tu->extcon, "USB", tu->vbus_state);
/* Create OTG interface */
tahvo_usb_power_off(tu);
@@ -391,7 +395,7 @@ static int tahvo_usb_probe(struct platform_device *pdev)
if (ret < 0) {
dev_err(&pdev->dev, "cannot register USB transceiver: %d\n",
ret);
- goto err_extcon_unreg;
+ goto err_disable_clk;
}
dev_set_drvdata(&pdev->dev, tu);
@@ -418,8 +422,6 @@ err_free_irq:
free_irq(tu->irq, tu);
err_remove_phy:
usb_remove_phy(&tu->phy);
-err_extcon_unreg:
- extcon_dev_unregister(&tu->extcon);
err_disable_clk:
if (!IS_ERR(tu->ick))
clk_disable(tu->ick);
@@ -434,7 +436,6 @@ static int tahvo_usb_remove(struct platform_device *pdev)
sysfs_remove_group(&pdev->dev.kobj, &tahvo_attr_group);
free_irq(tu->irq, tu);
usb_remove_phy(&tu->phy);
- extcon_dev_unregister(&tu->extcon);
if (!IS_ERR(tu->ick))
clk_disable(tu->ick);
--
1.8.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] usb: phy: tahvo: Use devm_extcon_dev_* function for resource management of extcon
2014-04-23 4:12 [PATCH] usb: phy: tahvo: Use devm_extcon_dev_* function for resource management of extcon Chanwoo Choi
@ 2014-04-23 16:03 ` Felipe Balbi
0 siblings, 0 replies; 2+ messages in thread
From: Felipe Balbi @ 2014-04-23 16:03 UTC (permalink / raw)
To: Chanwoo Choi; +Cc: balbi, gregkh, linux-usb, linux-kernel, Aaro Koskinen
[-- Attachment #1: Type: text/plain, Size: 4479 bytes --]
On Wed, Apr 23, 2014 at 01:12:43PM +0900, Chanwoo Choi wrote:
> This patch uses devm_extcon_dev_{allocate, register} function for automatically
> resource management of extcon device instead of legacy method and simplifies
> the behavior of register/unregister for extcon device.
>
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Aaro, if you can give me your Tested-by and/or Acked-by, I'll take this
to v3.16
> ---
> This patch has dependency about following patches[1-2]:
> [1] https://lkml.org/lkml/2014/4/21/140
> [2] https://lkml.org/lkml/2014/4/21/164
>
> drivers/usb/phy/phy-tahvo.c | 29 +++++++++++++++--------------
> 1 file changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
> index cc61ee4..8cde928 100644
> --- a/drivers/usb/phy/phy-tahvo.c
> +++ b/drivers/usb/phy/phy-tahvo.c
> @@ -57,7 +57,7 @@ struct tahvo_usb {
> struct clk *ick;
> int irq;
> int tahvo_mode;
> - struct extcon_dev extcon;
> + struct extcon_dev *extcon;
> };
>
> static const char *tahvo_cable[] = {
> @@ -118,7 +118,7 @@ static void check_vbus_state(struct tahvo_usb *tu)
> prev_state = tu->vbus_state;
> tu->vbus_state = reg & TAHVO_STAT_VBUS;
> if (prev_state != tu->vbus_state) {
> - extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
> + extcon_set_cable_state(tu->extcon, "USB", tu->vbus_state);
> sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state");
> }
> }
> @@ -127,7 +127,7 @@ static void tahvo_usb_become_host(struct tahvo_usb *tu)
> {
> struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
>
> - extcon_set_cable_state(&tu->extcon, "USB-HOST", true);
> + extcon_set_cable_state(tu->extcon, "USB-HOST", true);
>
> /* Power up the transceiver in USB host mode */
> retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
> @@ -146,7 +146,7 @@ static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)
> {
> struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
>
> - extcon_set_cable_state(&tu->extcon, "USB-HOST", false);
> + extcon_set_cable_state(tu->extcon, "USB-HOST", false);
>
> /* Power up transceiver and set it in USB peripheral mode */
> retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT |
> @@ -360,11 +360,15 @@ static int tahvo_usb_probe(struct platform_device *pdev)
> */
> tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS;
>
> - tu->extcon.name = DRIVER_NAME;
> - tu->extcon.supported_cable = tahvo_cable;
> - tu->extcon.dev.parent = &pdev->dev;
> + tu->extcon = devm_extcon_dev_allocate(&pdev->dev, tahvo_cable);
> + if (!tu->extcon) {
> + dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
> + return -ENOMEM;
> + }
> + tu->extcon->name = DRIVER_NAME;
> + tu->extcon->dev.parent = &pdev->dev;
>
> - ret = extcon_dev_register(&tu->extcon);
> + ret = devm_extcon_dev_register(&pdev->dev, tu->extcon);
> if (ret) {
> dev_err(&pdev->dev, "could not register extcon device: %d\n",
> ret);
> @@ -372,9 +376,9 @@ static int tahvo_usb_probe(struct platform_device *pdev)
> }
>
> /* Set the initial cable state. */
> - extcon_set_cable_state(&tu->extcon, "USB-HOST",
> + extcon_set_cable_state(tu->extcon, "USB-HOST",
> tu->tahvo_mode == TAHVO_MODE_HOST);
> - extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
> + extcon_set_cable_state(tu->extcon, "USB", tu->vbus_state);
>
> /* Create OTG interface */
> tahvo_usb_power_off(tu);
> @@ -391,7 +395,7 @@ static int tahvo_usb_probe(struct platform_device *pdev)
> if (ret < 0) {
> dev_err(&pdev->dev, "cannot register USB transceiver: %d\n",
> ret);
> - goto err_extcon_unreg;
> + goto err_disable_clk;
> }
>
> dev_set_drvdata(&pdev->dev, tu);
> @@ -418,8 +422,6 @@ err_free_irq:
> free_irq(tu->irq, tu);
> err_remove_phy:
> usb_remove_phy(&tu->phy);
> -err_extcon_unreg:
> - extcon_dev_unregister(&tu->extcon);
> err_disable_clk:
> if (!IS_ERR(tu->ick))
> clk_disable(tu->ick);
> @@ -434,7 +436,6 @@ static int tahvo_usb_remove(struct platform_device *pdev)
> sysfs_remove_group(&pdev->dev.kobj, &tahvo_attr_group);
> free_irq(tu->irq, tu);
> usb_remove_phy(&tu->phy);
> - extcon_dev_unregister(&tu->extcon);
> if (!IS_ERR(tu->ick))
> clk_disable(tu->ick);
>
> --
> 1.8.0
>
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-04-23 16:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-23 4:12 [PATCH] usb: phy: tahvo: Use devm_extcon_dev_* function for resource management of extcon Chanwoo Choi
2014-04-23 16:03 ` Felipe Balbi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®