Re: [PATCH v5 3/4] usb: musb: Add a new argument to musb_platform_set_mode()

From: Alexandre Bailon
Date: Mon Nov 14 2016 - 12:37:56 EST


On 11/14/2016 06:36 PM, Bin Liu wrote:
> Hi,
>
> On Mon, Nov 07, 2016 at 02:05:07PM +0100, Alexandre Bailon wrote:
>> During the init, the driver will use musb_platform_set_mode()
>> to configure the controller mode and the PHY mode.
>> The PHY of DA8xx has some issues when the PHY is forced in host or device,
>> so we want to keep it in OTG mode unless the user request a specific mode
>> by using the sysfs.
>> Add the init argument to musb_platform_set_mode() in order to let the
>> callback change its behavior if it is called during the init.
>
> Tony's patch set which fixes musb pm regression (but has not been merged
> yet) introduces musb->is_initialized. You might want to use this new
> variable in da8xx_musb_set_mode(), instead of adding this init flag.
OK. I will take a look and update the series.
>
> Regards,
> -Bin.
>
>>
>> Signed-off-by: Alexandre Bailon <abailon@xxxxxxxxxxxx>
>> ---
>> drivers/usb/musb/am35x.c | 2 +-
>> drivers/usb/musb/blackfin.c | 2 +-
>> drivers/usb/musb/da8xx.c | 2 +-
>> drivers/usb/musb/davinci.c | 2 +-
>> drivers/usb/musb/musb_core.c | 12 ++++++------
>> drivers/usb/musb/musb_core.h | 6 +++---
>> drivers/usb/musb/musb_dsps.c | 2 +-
>> drivers/usb/musb/sunxi.c | 2 +-
>> drivers/usb/musb/tusb6010.c | 2 +-
>> 9 files changed, 16 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
>> index 50ca805..7136888 100644
>> --- a/drivers/usb/musb/am35x.c
>> +++ b/drivers/usb/musb/am35x.c
>> @@ -332,7 +332,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
>> return ret;
>> }
>>
>> -static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode)
>> +static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode, bool init)
>> {
>> struct device *dev = musb->controller;
>> struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
>> diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
>> index 310238c..544e98f 100644
>> --- a/drivers/usb/musb/blackfin.c
>> +++ b/drivers/usb/musb/blackfin.c
>> @@ -356,7 +356,7 @@ static int bfin_musb_vbus_status(struct musb *musb)
>> return 0;
>> }
>>
>> -static int bfin_musb_set_mode(struct musb *musb, u8 musb_mode)
>> +static int bfin_musb_set_mode(struct musb *musb, u8 musb_mode, bool init)
>> {
>> return -EIO;
>> }
>> diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
>> index 6749aa1..ac0c2f7 100644
>> --- a/drivers/usb/musb/da8xx.c
>> +++ b/drivers/usb/musb/da8xx.c
>> @@ -335,7 +335,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
>> return ret;
>> }
>>
>> -static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
>> +static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode, bool init)
>> {
>> struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
>> enum phy_mode phy_mode;
>> diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
>> index cee61a5..d12b902 100644
>> --- a/drivers/usb/musb/davinci.c
>> +++ b/drivers/usb/musb/davinci.c
>> @@ -369,7 +369,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
>> return retval;
>> }
>>
>> -static int davinci_musb_set_mode(struct musb *musb, u8 mode)
>> +static int davinci_musb_set_mode(struct musb *musb, u8 mode, bool init)
>> {
>> /* EVM can't do this (right?) */
>> return -EIO;
>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
>> index 27dadc0..4a8d394 100644
>> --- a/drivers/usb/musb/musb_core.c
>> +++ b/drivers/usb/musb/musb_core.c
>> @@ -1730,11 +1730,11 @@ musb_mode_store(struct device *dev, struct device_attribute *attr,
>>
>> spin_lock_irqsave(&musb->lock, flags);
>> if (sysfs_streq(buf, "host"))
>> - status = musb_platform_set_mode(musb, MUSB_HOST);
>> + status = musb_platform_set_mode(musb, MUSB_HOST, false);
>> else if (sysfs_streq(buf, "peripheral"))
>> - status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
>> + status = musb_platform_set_mode(musb, MUSB_PERIPHERAL, false);
>> else if (sysfs_streq(buf, "otg"))
>> - status = musb_platform_set_mode(musb, MUSB_OTG);
>> + status = musb_platform_set_mode(musb, MUSB_OTG, false);
>> else
>> status = -EINVAL;
>> spin_unlock_irqrestore(&musb->lock, flags);
>> @@ -2261,13 +2261,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
>> status = musb_host_setup(musb, plat->power);
>> if (status < 0)
>> goto fail3;
>> - status = musb_platform_set_mode(musb, MUSB_HOST);
>> + status = musb_platform_set_mode(musb, MUSB_HOST, true);
>> break;
>> case MUSB_PORT_MODE_GADGET:
>> status = musb_gadget_setup(musb);
>> if (status < 0)
>> goto fail3;
>> - status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
>> + status = musb_platform_set_mode(musb, MUSB_PERIPHERAL, true);
>> break;
>> case MUSB_PORT_MODE_DUAL_ROLE:
>> status = musb_host_setup(musb, plat->power);
>> @@ -2278,7 +2278,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
>> musb_host_cleanup(musb);
>> goto fail3;
>> }
>> - status = musb_platform_set_mode(musb, MUSB_OTG);
>> + status = musb_platform_set_mode(musb, MUSB_OTG, true);
>> break;
>> default:
>> dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
>> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
>> index 2cb88a49..1bfc8fa 100644
>> --- a/drivers/usb/musb/musb_core.h
>> +++ b/drivers/usb/musb/musb_core.h
>> @@ -203,7 +203,7 @@ struct musb_platform_ops {
>> struct dma_controller *
>> (*dma_init) (struct musb *musb, void __iomem *base);
>> void (*dma_exit)(struct dma_controller *c);
>> - int (*set_mode)(struct musb *musb, u8 mode);
>> + int (*set_mode)(struct musb *musb, u8 mode, bool init);
>> void (*try_idle)(struct musb *musb, unsigned long timeout);
>> int (*recover)(struct musb *musb);
>>
>> @@ -558,12 +558,12 @@ static inline void musb_platform_disable(struct musb *musb)
>> musb->ops->disable(musb);
>> }
>>
>> -static inline int musb_platform_set_mode(struct musb *musb, u8 mode)
>> +static inline int musb_platform_set_mode(struct musb *musb, u8 mode, bool init)
>> {
>> if (!musb->ops->set_mode)
>> return 0;
>>
>> - return musb->ops->set_mode(musb, mode);
>> + return musb->ops->set_mode(musb, mode, init);
>> }
>>
>> static inline void musb_platform_try_idle(struct musb *musb,
>> diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
>> index 0f17d21..a889679 100644
>> --- a/drivers/usb/musb/musb_dsps.c
>> +++ b/drivers/usb/musb/musb_dsps.c
>> @@ -462,7 +462,7 @@ static int dsps_musb_exit(struct musb *musb)
>> return 0;
>> }
>>
>> -static int dsps_musb_set_mode(struct musb *musb, u8 mode)
>> +static int dsps_musb_set_mode(struct musb *musb, u8 mode, bool init)
>> {
>> struct device *dev = musb->controller;
>> struct dsps_glue *glue = dev_get_drvdata(dev->parent);
>> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
>> index 1408245..04bf763 100644
>> --- a/drivers/usb/musb/sunxi.c
>> +++ b/drivers/usb/musb/sunxi.c
>> @@ -346,7 +346,7 @@ static void sunxi_musb_dma_controller_destroy(struct dma_controller *c)
>> {
>> }
>>
>> -static int sunxi_musb_set_mode(struct musb *musb, u8 mode)
>> +static int sunxi_musb_set_mode(struct musb *musb, u8 mode, bool init)
>> {
>> struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
>> enum phy_mode new_mode;
>> diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
>> index df7c9f4..8a74587 100644
>> --- a/drivers/usb/musb/tusb6010.c
>> +++ b/drivers/usb/musb/tusb6010.c
>> @@ -628,7 +628,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on)
>> * Note that if a mini-A cable is plugged in the ID line will stay down as
>> * the weak ID pull-up is not able to pull the ID up.
>> */
>> -static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode)
>> +static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode, bool init)
>> {
>> void __iomem *tbase = musb->ctrl_base;
>> u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf;
>> --
>> 2.7.3
>>