usb: cdns3: Improvements for cdns3 DRD code
Subsystems (3)
Pawel Laszczak
maintainerv2 cover usb: cdns3: Improvements for cdns3 DRD code
Series introduce some improvements to drd.c, drd.h and core.c files of cdns3 driver.
Except for the first (1/9) patch that removes not needed function, the rest patches make improvements suggested by Dan Carpenter during reviewing CDNSP driver.
CDNSP is the next Cadence USBSSP driver which will be upstreamed. The DRD part is similar for both CDNS3 and CDNSP and Greg suggested to merge the similar part of DRD code. As first step I want to merge some improvements.
Changes for v2:
- Change patch titles as sugested by Peter Chen.
- Remove typos in patch 5 and patch 7.
- Add reviewed-by Peter Chen tag [Patch 1, patch 8 and Patch 9].
Pawel Laszczak (9):
usb: cdns3: core: removed cdns3_get_current_role_driver function
usb: cdns3: drd: removed not needed variables initialization
usb: cnds3: drd: deleted !=
usb: cdns3: drd: return IRQ_NONE explicitly.
usb: cdns3: drd: changed return type from int to bool
usb: cdns3: Added CDNS3_ID_PERIPHERAL and CDNS3_ID_HOST
usb: cdns3: core: removed 'goto not_otg'
usb: cdns3: core: removed overwriting some error code
usb: cdns3: drd: simplify *switch_gadet and *switch_host
drivers/usb/cdns3/core.c | 39 +++------ drivers/usb/cdns3/drd.c | 165 ++++++++++++++++++++----------------- drivers/usb/cdns3/drd.h | 13 ++- drivers/usb/cdns3/gadget.c | 4 +- drivers/usb/cdns3/host.c | 4 +- 5 files changed, 114 insertions(+), 111 deletions(-)
Signature · 1 line
2.17.1
Pawel Laszczak
maintainerPATCH v2 1/9 usb: cdns3: core: removed cdns3_get_current_role_driver function
Function is not used in driver so it can be removed.
--- drivers/usb/cdns3/core.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/usb/cdns3/core.c +0 -7
@@ -27,13 +27,6 @@static int cdns3_idle_init (struct cdns3 *cdns); -static inline -struct cdns3_role_driver *cdns3_get_current_role_driver (struct cdns3 *cdns) -{ -WARN_ON (!cdns->roles[cdns->role]); -return cdns->roles[cdns->role]; -} -static int cdns3_role_start (struct cdns3 *cdns,enum usb_role role) {int ret;
Signature · 1 line
2.17.1
Pawel Laszczak
maintainerPATCH v2 2/9 usb: cdns3: drd: removed not needed variables initialization
In reply to Pawel LaszczakPatch remove some variables initialization from core.c and drd.c file.
--- drivers/usb/cdns3/core.c | 4 ++-- drivers/usb/cdns3/drd.c | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-)
drivers/usb/cdns3/core.c +2 -2
@@ -86,7 +86,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns)struct device *dev = cdns->dev;enum usb_dr_mode best_dr_mode;enum usb_dr_mode dr_mode; -int ret =0 ; +int ret; dr_mode =usb_get_dr_mode (dev); cdns->role =USB_ROLE_NONE ;
@@ -177,7 +177,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) goto err; } -return ret; +return 0 ; err:cdns3_exit_roles (cdns);return ret;
drivers/usb/cdns3/drd.c +9 -10
@@ -29,7 +29,6 @@*/ int cdns3_set_mode (struct cdns3 *cdns,enum usb_dr_mode mode) { -int ret =0 ;u32 reg;switch (mode) {
@@ -61,7 +60,7 @@ int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)return -EINVAL ; } -return ret; +return 0 ; }int cdns3_get_id (struct cdns3 *cdns)
@@ -134,11 +133,11 @@ static void cdns3_otg_enable_irq(struct cdns3 *cdns)int cdns3_drd_switch_host (struct cdns3 *cdns,int on) {int ret, val; -u32 reg =OTGCMD_OTG_DIS ;/* switch OTG core */ if (on) { -writel (OTGCMD_HOST_BUS_REQ | reg, &cdns->otg_regs->cmd); +writel (OTGCMD_HOST_BUS_REQ |OTGCMD_OTG_DIS , + &cdns->otg_regs->cmd);dev_dbg (cdns->dev,"Waiting till Host mode is turned on\n" ); ret = readl_poll_timeout_atomic(&cdns->otg_regs->sts, val,
@@ -212,7 +211,7 @@ int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on)*/ static int cdns3_init_otg_mode (struct cdns3 *cdns) { -int ret =0 ; +int ret;cdns3_otg_disable_irq (cdns);/* clear all interrupts */
@@ -223,7 +222,8 @@ static int cdns3_init_otg_mode(struct cdns3 *cdns)return ret;cdns3_otg_enable_irq (cdns); -return ret; + +return 0 ; }/**
@@ -234,7 +234,7 @@ static int cdns3_init_otg_mode(struct cdns3 *cdns)*/ int cdns3_drd_update_mode (struct cdns3 *cdns) { -int ret =0 ; +int ret;switch (cdns->dr_mode) {case USB_DR_MODE_PERIPHERAL :
@@ -307,8 +307,8 @@ static irqreturn_t cdns3_drd_irq(int irq, void *data)int cdns3_drd_init (struct cdns3 *cdns) {void __iomem *regs; -int ret =0 ;u32 state; +int ret; regs =devm_ioremap_resource (cdns->dev, &cdns->otg_res);if (IS_ERR (regs))
@@ -359,7 +359,6 @@ int cdns3_drd_init(struct cdns3 *cdns) cdns3_drd_thread_irq,IRQF_SHARED , dev_name(cdns->dev), cdns); -if (ret) {dev_err (cdns->dev,"couldn't get otg_irq\n" );return ret;
@@ -371,7 +370,7 @@ int cdns3_drd_init(struct cdns3 *cdns)return -ENODEV ; } -return ret; +return 0 ; }int cdns3_drd_exit (struct cdns3 *cdns)
Signature · 1 line
2.17.1
Re: [PATCH v2 2/9] usb: cdns3: drd: removed not needed variables initialization
Quoted 4 lines · Pawel Laszczak
Patch remove some variables initialization from
core.canddrd.cfile.Signed-off-by Pawel Laszczak <[email protected]>
Peter
Quoted 120 lines
--- drivers/usb/cdns3/core.c | 4 ++-- drivers/usb/cdns3/drd.c | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-)drivers/usb/cdns3/core.c +2
-2@@ -86,7 +86,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns)struct device *dev = cdns->dev;enum usb_dr_mode best_dr_mode;enum usb_dr_mode dr_mode; -int ret =0 ; +int ret; dr_mode =usb_get_dr_mode (dev); cdns->role =USB_ROLE_NONE ;@@ -177,7 +177,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) goto err; } -return ret; +return 0 ; err:cdns3_exit_roles (cdns);return ret;drivers/usb/cdns3/drd.c +9
-10@@ -29,7 +29,6 @@*/ int cdns3_set_mode (struct cdns3 *cdns,enum usb_dr_mode mode) { -int ret =0 ;u32 reg;switch (mode) {@@ -61,7 +60,7 @@ int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)return -EINVAL ; } -return ret; +return 0 ; }int cdns3_get_id (struct cdns3 *cdns)@@ -134,11 +133,11 @@ static void cdns3_otg_enable_irq(struct cdns3 *cdns)int cdns3_drd_switch_host (struct cdns3 *cdns,int on) {int ret, val; -u32 reg =OTGCMD_OTG_DIS ;/* switch OTG core */ if (on) { -writel (OTGCMD_HOST_BUS_REQ | reg, &cdns->otg_regs->cmd); +writel (OTGCMD_HOST_BUS_REQ |OTGCMD_OTG_DIS , + &cdns->otg_regs->cmd);dev_dbg (cdns->dev,"Waiting till Host mode is turned on\n" ); ret = readl_poll_timeout_atomic(&cdns->otg_regs->sts, val,@@ -212,7 +211,7 @@ int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on)*/ static int cdns3_init_otg_mode (struct cdns3 *cdns) { -int ret =0 ; +int ret;cdns3_otg_disable_irq (cdns);/* clear all interrupts */ @@ -223,7 +222,8 @@ static int cdns3_init_otg_mode(struct cdns3 *cdns)return ret;cdns3_otg_enable_irq (cdns); -return ret; + +return 0 ; }/** @@ -234,7 +234,7 @@ static int cdns3_init_otg_mode(struct cdns3 *cdns)*/ int cdns3_drd_update_mode (struct cdns3 *cdns) { -int ret =0 ; +int ret;switch (cdns->dr_mode) {case USB_DR_MODE_PERIPHERAL :@@ -307,8 +307,8 @@ static irqreturn_t cdns3_drd_irq(int irq, void *data)int cdns3_drd_init (struct cdns3 *cdns) {void __iomem *regs; -int ret =0 ;u32 state; +int ret; regs =devm_ioremap_resource (cdns->dev, &cdns->otg_res);if (IS_ERR (regs))@@ -359,7 +359,6 @@ int cdns3_drd_init(struct cdns3 *cdns) cdns3_drd_thread_irq,IRQF_SHARED , dev_name(cdns->dev), cdns); -if (ret) {dev_err (cdns->dev,"couldn't get otg_irq\n" );return ret;@@ -371,7 +370,7 @@ int cdns3_drd_init(struct cdns3 *cdns)return -ENODEV ; } -return ret; +return 0 ; }int cdns3_drd_exit (struct cdns3 *cdns)Signature · 1 line
2.17.1
Signature · 2 lines
Thanks, Peter Chen
Pawel Laszczak
maintainerPATCH v2 3/9 usb: cnds3: drd: deleted !=
In reply to Pawel LaszczakPatch deletes unnecessary != from condition statement in cdns3_drd_init function.
--- drivers/usb/cdns3/drd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/cdns3/drd.c +1 -1
@@ -365,7 +365,7 @@ int cdns3_drd_init(struct cdns3 *cdns) } state =readl (&cdns->otg_regs->sts); -if (OTGSTS_OTG_NRDY (state) !=0 ) { +if (OTGSTS_OTG_NRDY (state)) {dev_err (cdns->dev,"Cadence USB3 OTG device not ready\n" );return -ENODEV ; }
Signature · 1 line
2.17.1
Re: [PATCH v2 3/9] usb: cnds3: drd: deleted !=
Quoted 4 lines · Pawel Laszczak
Patch deletes unnecessary != from condition statement in
cdns3_drd_initfunction.Signed-off-by Pawel Laszczak <[email protected]>
Quoted 20 lines
--- drivers/usb/cdns3/drd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/cdns3/drd.c +1
-1@@ -365,7 +365,7 @@ int cdns3_drd_init(struct cdns3 *cdns) } state =readl (&cdns->otg_regs->sts); -if (OTGSTS_OTG_NRDY (state) !=0 ) { +if (OTGSTS_OTG_NRDY (state)) {dev_err (cdns->dev,"Cadence USB3 OTG device not ready\n" );return -ENODEV ; }Signature · 1 line
2.17.1
Signature · 2 lines
Thanks, Peter Chen
Pawel Laszczak
maintainerPATCH v2 4/9 usb: cdns3: drd: return IRQ_NONE explicitly.
In reply to Pawel LaszczakIRQ_NONE can be returned indirect.
--- drivers/usb/cdns3/drd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/cdns3/drd.c +2 -2
@@ -279,12 +279,12 @@ static irqreturn_t cdns3_drd_irq(int irq, void *data)u32 reg;if (cdns->dr_mode !=USB_DR_MODE_OTG ) -return ret; +return IRQ_NONE ; reg =readl (&cdns->otg_regs->ivect);if (!reg) -return ret; +return IRQ_NONE ;if (reg &OTGIEN_ID_CHANGE_INT ) { dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n",
Signature · 1 line
2.17.1
Re: [PATCH v2 4/9] usb: cdns3: drd: return IRQ_NONE explicitly.
Quoted 3 lines · Pawel Laszczak
IRQ_NONEcan be returned indirect.Signed-off-by Pawel Laszczak <[email protected]>
Quoted 26 lines
--- drivers/usb/cdns3/drd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/cdns3/drd.c +2
-2@@ -279,12 +279,12 @@ static irqreturn_t cdns3_drd_irq(int irq, void *data)u32 reg;if (cdns->dr_mode !=USB_DR_MODE_OTG ) -return ret; +return IRQ_NONE ; reg =readl (&cdns->otg_regs->ivect);if (!reg) -return ret; +return IRQ_NONE ;if (reg &OTGIEN_ID_CHANGE_INT ) { dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n",Signature · 1 line
2.17.1
Signature · 2 lines
Thanks, Peter Chen
Pawel Laszczak
maintainerPATCH v2 5/9 usb: cdns3: drd: changed return type from int to bool
In reply to Pawel LaszczakPatch changes return type from int to bool forcdns3_is_host and cdns3_is_device functions.
--- drivers/usb/cdns3/drd.c | 16 ++++++++-------- drivers/usb/cdns3/drd.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/usb/cdns3/drd.c +8 -8
@@ -83,25 +83,25 @@ int cdns3_get_vbus(struct cdns3 *cdns)return vbus; } -int cdns3_is_host (struct cdns3 *cdns) +bool cdns3_is_host (struct cdns3 *cdns) {if (cdns->dr_mode ==USB_DR_MODE_HOST ) -return 1 ; +return true;else if (!cdns3_get_id (cdns)) -return 1 ; +return true; -return 0 ; +return false; } -int cdns3_is_device (struct cdns3 *cdns) +bool cdns3_is_device (struct cdns3 *cdns) {if (cdns->dr_mode ==USB_DR_MODE_PERIPHERAL ) -return 1 ; +return true;else if (cdns->dr_mode ==USB_DR_MODE_OTG )if (cdns3_get_id (cdns)) -return 1 ; +return true; -return 0 ; +return false; }/**
drivers/usb/cdns3/drd.h +2 -2
@@ -153,8 +153,8 @@ struct cdns3_otg_common_regs {/* Only for CDNS3_CONTROLLER_V0 version */ #define OVERRIDE_IDPULLUP_V0 BIT(24) -int cdns3_is_host (struct cdns3 *cdns); -int cdns3_is_device (struct cdns3 *cdns); +bool cdns3_is_host (struct cdns3 *cdns); +bool cdns3_is_device (struct cdns3 *cdns);int cdns3_get_id (struct cdns3 *cdns);int cdns3_get_vbus (struct cdns3 *cdns);int cdns3_drd_init (struct cdns3 *cdns);
Signature · 1 line
2.17.1
Re: [PATCH v2 5/9] usb: cdns3: drd: changed return type from int to bool
Quoted 4 lines · Pawel Laszczak
Patch changes return type from int to bool for
cdns3_is_hostandcdns3_is_devicefunctions.Signed-off-by Pawel Laszczak <[email protected]>
Quoted 61 lines
--- drivers/usb/cdns3/drd.c | 16 ++++++++-------- drivers/usb/cdns3/drd.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-)drivers/usb/cdns3/drd.c +8
-8@@ -83,25 +83,25 @@ int cdns3_get_vbus(struct cdns3 *cdns)return vbus; } -int cdns3_is_host (struct cdns3 *cdns) +bool cdns3_is_host (struct cdns3 *cdns) {if (cdns->dr_mode ==USB_DR_MODE_HOST ) -return 1 ; +return true;else if (!cdns3_get_id (cdns)) -return 1 ; +return true; -return 0 ; +return false; } -int cdns3_is_device (struct cdns3 *cdns) +bool cdns3_is_device (struct cdns3 *cdns) {if (cdns->dr_mode ==USB_DR_MODE_PERIPHERAL ) -return 1 ; +return true;else if (cdns->dr_mode ==USB_DR_MODE_OTG )if (cdns3_get_id (cdns)) -return 1 ; +return true; -return 0 ; +return false; }/** drivers/usb/cdns3/drd.h +2
-2@@ -153,8 +153,8 @@ struct cdns3_otg_common_regs {/* Only for CDNS3_CONTROLLER_V0 version */ #define OVERRIDE_IDPULLUP_V0 BIT(24) -int cdns3_is_host (struct cdns3 *cdns); -int cdns3_is_device (struct cdns3 *cdns); +bool cdns3_is_host (struct cdns3 *cdns); +bool cdns3_is_device (struct cdns3 *cdns);int cdns3_get_id (struct cdns3 *cdns);int cdns3_get_vbus (struct cdns3 *cdns);int cdns3_drd_init (struct cdns3 *cdns);Signature · 1 line
2.17.1
Signature · 2 lines
Thanks, Peter Chen
Pawel Laszczak
maintainerPATCH v2 6/9 usb: cdns3: Added CDNS3_ID_PERIPHERAL and CDNS3_ID_HOST
In reply to Pawel LaszczakPatch adds 2 definitions that make it easier to understand the code.
--- drivers/usb/cdns3/drd.c | 4 ++-- drivers/usb/cdns3/drd.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/usb/cdns3/drd.c +2 -2
@@ -87,7 +87,7 @@ bool cdns3_is_host(struct cdns3 *cdns) {if (cdns->dr_mode ==USB_DR_MODE_HOST )return true; -else if (!cdns3_get_id (cdns)) +else if (cdns3_get_id (cdns) ==CDNS3_ID_HOST )return true;return false;
@@ -98,7 +98,7 @@ bool cdns3_is_device(struct cdns3 *cdns)if (cdns->dr_mode ==USB_DR_MODE_PERIPHERAL )return true;else if (cdns->dr_mode ==USB_DR_MODE_OTG ) -if (cdns3_get_id (cdns)) +if (cdns3_get_id (cdns) ==CDNS3_ID_PERIPHERAL )return true;return false;
drivers/usb/cdns3/drd.h +3 -0
@@ -153,6 +153,9 @@ struct cdns3_otg_common_regs {/* Only for CDNS3_CONTROLLER_V0 version */ #define OVERRIDE_IDPULLUP_V0 BIT(24) +#define CDNS3_ID_PERIPHERAL 1 +#define CDNS3_ID_HOST 0 +bool cdns3_is_host (struct cdns3 *cdns);bool cdns3_is_device (struct cdns3 *cdns);int cdns3_get_id (struct cdns3 *cdns);
Signature · 1 line
2.17.1
Re: [PATCH v2 6/9] usb: cdns3: Added CDNS3_ID_PERIPHERAL and CDNS3_ID_HOST
Quoted 35 lines · Pawel Laszczak
Patch adds 2 definitions that make it easier to understand the code.
Signed-off-by Pawel Laszczak <[email protected]>--- drivers/usb/cdns3/drd.c | 4 ++-- drivers/usb/cdns3/drd.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)drivers/usb/cdns3/drd.c +2
-2@@ -87,7 +87,7 @@ bool cdns3_is_host(struct cdns3 *cdns) {if (cdns->dr_mode ==USB_DR_MODE_HOST )return true; -else if (!cdns3_get_id (cdns)) +else if (cdns3_get_id (cdns) ==CDNS3_ID_HOST )return true;return false;@@ -98,7 +98,7 @@ bool cdns3_is_device(struct cdns3 *cdns)if (cdns->dr_mode ==USB_DR_MODE_PERIPHERAL )return true;else if (cdns->dr_mode ==USB_DR_MODE_OTG ) -if (cdns3_get_id (cdns)) +if (cdns3_get_id (cdns) ==CDNS3_ID_PERIPHERAL )return true;return false;drivers/usb/cdns3/drd.h +0
-0
drivers/usb/cdns3/drd.h struct cdns3_otg_common_regs { · line 156
Quoted 4 lines
drivers/usb/cdns3/drd.h +1
-0@@ -153,6 +153,9 @@ struct cdns3_otg_common_regs {/* Only for CDNS3_CONTROLLER_V0 version */ #define OVERRIDE_IDPULLUP_V0 BIT(24) +#define CDNS3_ID_PERIPHERAL 1
Since you use cdns3_is_device for function name, it is better define as CDNS3_ID_DEVICE.
Otherwise:
Quoted 8 lines
drivers/usb/cdns3/drd.h +2
-0+#define CDNS3_ID_HOST 0 +bool cdns3_is_host (struct cdns3 *cdns);bool cdns3_is_device (struct cdns3 *cdns);int cdns3_get_id (struct cdns3 *cdns);Signature · 1 line
2.17.1
Signature · 2 lines
Thanks, Peter Chen
Pawel Laszczak
maintainerPATCH v2 7/9 usb: cdns3: core: removed 'goto not_otg'
In reply to Pawel LaszczakPatch removes 'goto not_otg' instruction fromcdns3_hw_role_state_machine function.
--- drivers/usb/cdns3/core.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/usb/cdns3/core.c +9 -11
@@ -191,11 +191,17 @@ static int cdns3_core_init_role(struct cdns3 *cdns)*/ static enum usb_role cdns3_hw_role_state_machine (struct cdns3 *cdns) { -enum usb_role role; +enum usb_role role =USB_ROLE_NONE ;int id, vbus; -if (cdns->dr_mode !=USB_DR_MODE_OTG ) - goto not_otg; +if (cdns->dr_mode !=USB_DR_MODE_OTG ) { +if (cdns3_is_host (cdns)) + role =USB_ROLE_HOST ; +if (cdns3_is_device (cdns)) + role =USB_ROLE_DEVICE ; + +return role; + } id =cdns3_get_id (cdns); vbus =cdns3_get_vbus (cdns);
@@ -232,14 +238,6 @@ static enum usb_role cdns3_hw_role_state_machine(struct cdns3 *cdns)dev_dbg (cdns->dev,"role %d -> %d\n" , cdns->role, role);return role; - -not_otg: -if (cdns3_is_host (cdns)) - role =USB_ROLE_HOST ; -if (cdns3_is_device (cdns)) - role =USB_ROLE_DEVICE ; - -return role; }static int cdns3_idle_role_start (struct cdns3 *cdns)
Signature · 1 line
2.17.1
Re: [PATCH v2 7/9] usb: cdns3: core: removed 'goto not_otg'
Quoted 20 lines · Pawel Laszczak
Patch removes 'goto
not_otg' instruction fromcdns3_hw_role_state_machinefunction.Signed-off-by Pawel Laszczak <[email protected]>--- drivers/usb/cdns3/core.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/usb/cdns3/core.c +1
-1@@ -191,11 +191,17 @@ static int cdns3_core_init_role(struct cdns3 *cdns)*/ static enum usb_role cdns3_hw_role_state_machine (struct cdns3 *cdns) { -enum usb_role role; +enum usb_role role =USB_ROLE_NONE ;int id, vbus;
drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 204
Quoted 10 lines
drivers/usb/cdns3/core.c +8
-2-if (cdns->dr_mode !=USB_DR_MODE_OTG ) - goto not_otg; +if (cdns->dr_mode !=USB_DR_MODE_OTG ) { +if (cdns3_is_host (cdns)) + role =USB_ROLE_HOST ; +if (cdns3_is_device (cdns)) + role =USB_ROLE_DEVICE ; + +return role; + }
Would you please improve it a bit like below:
if (cdns->dr_mode != USB_DR_MODE_OTG) {
if (cdns3_is_host(cdns))
role = USB_ROLE_HOST;
else if (cdns3_is_device(cdns))
role = USB_ROLE_DEVICE;
else
role = USB_ROLE_NONE;
return role;
}Peter
Quoted 21 lines
drivers/usb/cdns3/core.c +0
-8id =cdns3_get_id (cdns); vbus =cdns3_get_vbus (cdns);@@ -232,14 +238,6 @@ static enum usb_role cdns3_hw_role_state_machine(struct cdns3 *cdns)dev_dbg (cdns->dev,"role %d -> %d\n" , cdns->role, role);return role; - -not_otg: -if (cdns3_is_host (cdns)) - role =USB_ROLE_HOST ; -if (cdns3_is_device (cdns)) - role =USB_ROLE_DEVICE ; - -return role; }static int cdns3_idle_role_start (struct cdns3 *cdns)Signature · 1 line
2.17.1
Signature · 2 lines
Thanks, Peter Chen
Pawel Laszczak
maintainerRE: [PATCH v2 7/9] usb: cdns3: core: removed 'goto not_otg'
Quoted 35 lines · Pawel Laszczak
Quoted 20 lines
Patch removes 'goto
not_otg' instruction fromcdns3_hw_role_state_machinefunction.Signed-off-by Pawel Laszczak <[email protected]>--- drivers/usb/cdns3/core.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/usb/cdns3/core.c +1
-1@@ -191,11 +191,17 @@ static int cdns3_core_init_role(struct cdns3 *cdns)*/ static enum usb_role cdns3_hw_role_state_machine (struct cdns3 *cdns) { -enum usb_role role; +enum usb_role role =USB_ROLE_NONE ;int id, vbus;drivers/usb/cdns3/core.c static int cdns3_core_init_role(struct cdns3 *cdns) · line 204
Quoted 10 lines
drivers/usb/cdns3/core.c +8
-2-if (cdns->dr_mode !=USB_DR_MODE_OTG ) - goto not_otg; +if (cdns->dr_mode !=USB_DR_MODE_OTG ) { +if (cdns3_is_host (cdns)) + role =USB_ROLE_HOST ; +if (cdns3_is_device (cdns)) + role =USB_ROLE_DEVICE ; + +return role; + }Would you please improve it a bit like below:
Quoted 11 lines
if (cdns->dr_mode != USB_DR_MODE_OTG) {
if (cdns3_is_host(cdns))
role = USB_ROLE_HOST;
else if (cdns3_is_device(cdns))
role = USB_ROLE_DEVICE;
else
role = USB_ROLE_NONE;
return role;
}Sorry for delay, I had holiday.
Currently this patch was added by Greg to his usb-next branch, so I don't want to change anything. Next time I will add such changes.
Quoted 25 lines
Peter
Quoted 19 lines
drivers/usb/cdns3/core.c +0
-9id =cdns3_get_id (cdns); vbus =cdns3_get_vbus (cdns);@@ -232,14 +238,6 @@ static enum usb_role cdns3_hw_role_state_machine(struct cdns3 *cdns)dev_dbg (cdns->dev,"role %d -> %d\n" , cdns->role, role);return role; - -not_otg: -if (cdns3_is_host (cdns)) - role =USB_ROLE_HOST ; -if (cdns3_is_device (cdns)) - role =USB_ROLE_DEVICE ; - -return role; }static int cdns3_idle_role_start (struct cdns3 *cdns) --Quoted 2 lines
2.17.1
--
Quoted 2 lines
Thanks,
Peter Chen
Thanks,
Pawel
Pawel Laszczak
maintainerPATCH v2 8/9 usb: cdns3: core: removed overwriting some error code
In reply to Pawel LaszczakSome error code can be preserved, so we can remove overwriting error code returned by some functions.
--- drivers/usb/cdns3/core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/usb/cdns3/core.c +2 -6
@@ -347,7 +347,6 @@ static int cdns3_role_set(struct usb_role_switch *sw, enum usb_role role)case USB_ROLE_HOST :break ;default : - ret = -EPERM ; goto pm_put; } }
@@ -358,17 +357,14 @@ static int cdns3_role_set(struct usb_role_switch *sw, enum usb_role role)case USB_ROLE_DEVICE :break ;default : - ret = -EPERM ; goto pm_put; } }cdns3_role_stop (cdns); ret =cdns3_role_start (cdns, role); -if (ret) { +if (ret)dev_err (cdns->dev,"set role %d has failed\n" , role); - ret = -EPERM ; - } pm_put:pm_runtime_put_sync (cdns->dev);
@@ -393,7 +389,7 @@ static int cdns3_probe(struct platform_device *pdev) ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 ));if (ret) {dev_err (dev,"error setting dma mask: %d\n" , ret); -return -ENODEV ; +return ret; } cdns =devm_kzalloc (dev,sizeof (*cdns),GFP_KERNEL );
Signature · 1 line
2.17.1
Pawel Laszczak
maintainerPATCH v2 9/9 usb: cdns3: drd: simplify *switch_gadet and *switch_host
In reply to Pawel LaszczakPatch split function cdns3_drd_switch_gadget andcdns3_drd_switch_host into:
- cdns3_drd_host_on
- cdns3_drd_host_off
- cdns3_drd_gadget_on
- cdns3_drd_gadgett_off
These functions don't have any shared code so it's better to have smaller, faster and easier functions.
--- drivers/usb/cdns3/drd.c | 124 ++++++++++++++++++++----------------- drivers/usb/cdns3/drd.h | 6 +- drivers/usb/cdns3/gadget.c | 4 +- drivers/usb/cdns3/host.c | 4 +- 4 files changed, 76 insertions(+), 62 deletions(-)
drivers/usb/cdns3/drd.c +68 -56
@@ -124,85 +124,97 @@ static void cdns3_otg_enable_irq(struct cdns3 *cdns) }/** -* cdns3_drd_switch_host - start/stop host -* @cdns: Pointer to controller context structure -* @on: 1 for start, 0 for stop +* cdns3_drd_host_on - start host. +* @cdns: Pointer to controller context structure. * -* Returns 0 on success otherwise negative errno +* Returns 0 on success otherwise negative errno. */ -int cdns3_drd_switch_host (struct cdns3 *cdns,int on) +int cdns3_drd_host_on (struct cdns3 *cdns) { -int ret, val; +u32 val; +int ret; -/* switch OTG core */ -if (on) { -writel (OTGCMD_HOST_BUS_REQ |OTGCMD_OTG_DIS , - &cdns->otg_regs->cmd); - -dev_dbg (cdns->dev,"Waiting till Host mode is turned on\n" ); - ret =readl_poll_timeout_atomic (&cdns->otg_regs->sts, val, - val &OTGSTS_XHCI_READY , -1 ,100000 ); -if (ret) { -dev_err (cdns->dev,"timeout waiting for xhci_ready\n" ); -return ret; - } - }else { -writel (OTGCMD_HOST_BUS_DROP |OTGCMD_DEV_BUS_DROP | -OTGCMD_DEV_POWER_OFF |OTGCMD_HOST_POWER_OFF , - &cdns->otg_regs->cmd); -/* Waiting till H_IDLE state.*/ -readl_poll_timeout_atomic (&cdns->otg_regs->state, val, - !(val &OTGSTATE_HOST_STATE_MASK ), -1 ,2000000 ); - } +/* Enable host mode. */ +writel (OTGCMD_HOST_BUS_REQ |OTGCMD_OTG_DIS , + &cdns->otg_regs->cmd); -return 0 ; +dev_dbg (cdns->dev,"Waiting till Host mode is turned on\n" ); + ret =readl_poll_timeout_atomic (&cdns->otg_regs->sts, val, + val &OTGSTS_XHCI_READY ,1 ,100000 ); + +if (ret) +dev_err (cdns->dev,"timeout waiting for xhci_ready\n" ); + +return ret; }/** -* cdns3_drd_switch_gadget - start/stop gadget -* @cdns: Pointer to controller context structure -* @on: 1 for start, 0 for stop +* cdns3_drd_host_off - stop host. +* @cdns: Pointer to controller context structure. +*/ +void cdns3_drd_host_off (struct cdns3 *cdns) +{ +u32 val; + +writel (OTGCMD_HOST_BUS_DROP |OTGCMD_DEV_BUS_DROP | +OTGCMD_DEV_POWER_OFF |OTGCMD_HOST_POWER_OFF , + &cdns->otg_regs->cmd); + +/* Waiting till H_IDLE state.*/ +readl_poll_timeout_atomic (&cdns->otg_regs->state, val, + !(val &OTGSTATE_HOST_STATE_MASK ), +1 ,2000000 ); +} + +/** +* cdns3_drd_gadget_on - start gadget. +* @cdns: Pointer to controller context structure. * * Returns 0 on success otherwise negative errno */ -int cdns3_drd_switch_gadget (struct cdns3 *cdns,int on) +int cdns3_drd_gadget_on (struct cdns3 *cdns) {int ret, val;u32 reg =OTGCMD_OTG_DIS ;/* switch OTG core */ -if (on) { -writel (OTGCMD_DEV_BUS_REQ | reg, &cdns->otg_regs->cmd); +writel (OTGCMD_DEV_BUS_REQ | reg, &cdns->otg_regs->cmd); -dev_dbg (cdns->dev,"Waiting till Device mode is turned on\n" ); +dev_dbg (cdns->dev,"Waiting till Device mode is turned on\n" ); - ret =readl_poll_timeout_atomic (&cdns->otg_regs->sts, val, - val &OTGSTS_DEV_READY , -1 ,100000 ); -if (ret) { -dev_err (cdns->dev,"timeout waiting for dev_ready\n" ); -return ret; - } - }else { -/* -* driver should wait at least 10us after disabling Device -* before turning-off Device (DEV_BUS_DROP) -*/ -usleep_range (20 ,30 ); -writel (OTGCMD_HOST_BUS_DROP |OTGCMD_DEV_BUS_DROP | -OTGCMD_DEV_POWER_OFF |OTGCMD_HOST_POWER_OFF , - &cdns->otg_regs->cmd); -/* Waiting till DEV_IDLE state.*/ -readl_poll_timeout_atomic (&cdns->otg_regs->state, val, - !(val &OTGSTATE_DEV_STATE_MASK ), -1 ,2000000 ); + ret =readl_poll_timeout_atomic (&cdns->otg_regs->sts, val, + val &OTGSTS_DEV_READY , +1 ,100000 ); +if (ret) { +dev_err (cdns->dev,"timeout waiting for dev_ready\n" ); +return ret; }return 0 ; } +/** +* cdns3_drd_gadget_off - stop gadget. +* @cdns: Pointer to controller context structure. +*/ +void cdns3_drd_gadget_off (struct cdns3 *cdns) +{ +u32 val; + +/* +* Driver should wait at least 10us after disabling Device +* before turning-off Device (DEV_BUS_DROP). +*/ +usleep_range (20 ,30 ); +writel (OTGCMD_HOST_BUS_DROP |OTGCMD_DEV_BUS_DROP | +OTGCMD_DEV_POWER_OFF |OTGCMD_HOST_POWER_OFF , + &cdns->otg_regs->cmd); +/* Waiting till DEV_IDLE state.*/ +readl_poll_timeout_atomic (&cdns->otg_regs->state, val, + !(val &OTGSTATE_DEV_STATE_MASK ), +1 ,2000000 ); +} +/** * cdns3_init_otg_mode - initialize drd controller * @cdns: Pointer to controller context structure
drivers/usb/cdns3/drd.h +4 -2
@@ -163,8 +163,10 @@ int cdns3_get_vbus(struct cdns3 *cdns);int cdns3_drd_init (struct cdns3 *cdns);int cdns3_drd_exit (struct cdns3 *cdns);int cdns3_drd_update_mode (struct cdns3 *cdns); -int cdns3_drd_switch_gadget (struct cdns3 *cdns,int on); -int cdns3_drd_switch_host (struct cdns3 *cdns,int on); +int cdns3_drd_gadget_on (struct cdns3 *cdns); +void cdns3_drd_gadget_off (struct cdns3 *cdns); +int cdns3_drd_host_on (struct cdns3 *cdns); +void cdns3_drd_host_off (struct cdns3 *cdns);int cdns3_set_mode (struct cdns3 *cdns,enum usb_dr_mode mode);#endif /* __LINUX_CDNS3_DRD */
drivers/usb/cdns3/gadget.c +2 -2
@@ -3015,7 +3015,7 @@ void cdns3_gadget_exit(struct cdns3 *cdns)kfree (priv_dev->zlp_buf);kfree (priv_dev); cdns->gadget_dev =NULL ; -cdns3_drd_switch_gadget (cdns,0 ); +cdns3_drd_gadget_off (cdns); }static int cdns3_gadget_start (struct cdns3 *cdns)
@@ -3146,7 +3146,7 @@ static int __cdns3_gadget_init(struct cdns3 *cdns)return ret; } -cdns3_drd_switch_gadget (cdns,1 ); +cdns3_drd_gadget_on (cdns);pm_runtime_get_sync (cdns->dev); ret =cdns3_gadget_start (cdns);
drivers/usb/cdns3/host.c +2 -2
@@ -19,7 +19,7 @@ static int __cdns3_host_init(struct cdns3 *cdns)struct platform_device *xhci;int ret; -cdns3_drd_switch_host (cdns,1 ); +cdns3_drd_host_on (cdns); xhci =platform_device_alloc ("xhci-hcd" ,PLATFORM_DEVID_AUTO );if (!xhci) {
@@ -53,7 +53,7 @@ static void cdns3_host_exit(struct cdns3 *cdns) {platform_device_unregister (cdns->host_dev); cdns->host_dev =NULL ; -cdns3_drd_switch_host (cdns,0 ); +cdns3_drd_host_off (cdns); }int cdns3_host_init (struct cdns3 *cdns)
Signature · 1 line
2.17.1