diff mbox series

[RFC] usb: chipidea: Add minimal support for HSIC interface on i.MX6QDL

Message ID 1539005352-10909-1-git-send-email-frieder.schrempf@exceet.de (mailing list archive)
State New, archived
Headers show
Series [RFC] usb: chipidea: Add minimal support for HSIC interface on i.MX6QDL | expand

Commit Message

Frieder Schrempf Oct. 8, 2018, 1:29 p.m. UTC
Current mainline doesn't support USB hosts 2 and 3 which only use
HSIC mode and I was wondering how this would need to be implemented.

The topic has been discussed before: [1]
And there is some implementation in the vendor kernel: [2]

It seems like two things need to be done:

1. Switch the pinmux of the strobe signal to use a pullup after
   the core has been initialized.
2. Enable HSIC mode and HSIC clock

This patch only implements these basics in a minimal approach.
You need to have an additional pinmux setting "active" in the dt,
that sets the pullup.

It was tested with the SMSC LAN9730 USB Ethernet adapter on the
iMXceet Solo S board.

[1] https://patchwork.kernel.org/patch/3541771/
[2] http://git.freescale.com/git/cgit.cgi/imx/linux-imx.git/commit/?id=cf2d3ff6b217ef41f0e594daa9615e2

Signed-off-by: Frieder Schrempf <frieder.schrempf@exceet.de>
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 10 ++++++++++
 drivers/usb/chipidea/usbmisc_imx.c | 22 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)

Comments

Peter Chen Oct. 9, 2018, 1:24 a.m. UTC | #1
> 
> The topic has been discussed before: [1] And there is some implementation in the
> vendor kernel: [2]
> 
> It seems like two things need to be done:
> 
> 1. Switch the pinmux of the strobe signal to use a pullup after
>    the core has been initialized.
> 2. Enable HSIC mode and HSIC clock
> 
> This patch only implements these basics in a minimal approach.
> You need to have an additional pinmux setting "active" in the dt, that sets the pullup.
> 
> It was tested with the SMSC LAN9730 USB Ethernet adapter on the iMXceet Solo S
> board.
> 

Thanks, I should do it earlier, I could not find a suitable board with HSIC support at mainline kernel.
It is very kind that you could help on it and test function at real board. My suggestion is
follow all flows in Link [2] since we need to cover suspend/resume and remote wakeup. 

Peter

> [1]
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.
> kernel.org%2Fpatch%2F3541771%2F&amp;data=02%7C01%7CPeter.Chen%40nx
> p.com%7Cea362518eae9440028aa08d62d22246b%7C686ea1d3bc2b4c6fa92cd99
> c5c301635%7C0%7C0%7C636746022015840824&amp;sdata=sHE2yZha9%2FhN
> SSBjXogDMtdflhNc2n9mNlUe9t8E1kY%3D&amp;reserved=0
> [2]
> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgit.freescale
> .com%2Fgit%2Fcgit.cgi%2Fimx%2Flinux-
> imx.git%2Fcommit%2F%3Fid%3Dcf2d3ff6b217ef41f0e594daa9615e2&amp;data=0
> 2%7C01%7CPeter.Chen%40nxp.com%7Cea362518eae9440028aa08d62d22246b
> %7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636746022015840824
> &amp;sdata=iDRlnA9liWua7UMHBcVdUlMkBP6MIG7KUpHIAwQbDA0%3D&amp;re
> served=0
> 
> Signed-off-by: Frieder Schrempf <frieder.schrempf@exceet.de>
> ---
>  drivers/usb/chipidea/ci_hdrc_imx.c | 10 ++++++++++
> drivers/usb/chipidea/usbmisc_imx.c | 22 ++++++++++++++++++++++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
> index 19f5f5f..fef8bda 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -256,6 +256,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
>  	const struct of_device_id *of_id;
>  	const struct ci_hdrc_imx_platform_flag *imx_platform_flag;
>  	struct device_node *np = pdev->dev.of_node;
> +	struct pinctrl *pinctrl;
> 
>  	of_id = of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev);
>  	if (!of_id)
> @@ -331,6 +332,15 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
>  		pm_runtime_enable(&pdev->dev);
>  	}
> 
> +	pinctrl = devm_pinctrl_get(&pdev->dev);
> +	if (!IS_ERR(pinctrl)) {
> +		struct pinctrl_state *state;
> +
> +		state = pinctrl_lookup_state(pinctrl, "active");
> +		if (!IS_ERR(state))
> +			pinctrl_select_state(pinctrl, state);
> +	}
> +
>  	device_set_wakeup_capable(&pdev->dev, true);
> 
>  	return 0;
> diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> index 34ad5bf..a6556c8 100644
> --- a/drivers/usb/chipidea/usbmisc_imx.c
> +++ b/drivers/usb/chipidea/usbmisc_imx.c
> @@ -64,10 +64,16 @@
>  #define MX6_BM_OVER_CUR_DIS		BIT(7)
>  #define MX6_BM_OVER_CUR_POLARITY	BIT(8)
>  #define MX6_BM_WAKEUP_ENABLE		BIT(10)
> +#define MX6_BM_UTMI_ON_CLOCK		BIT(13)
>  #define MX6_BM_ID_WAKEUP		BIT(16)
>  #define MX6_BM_VBUS_WAKEUP		BIT(17)
>  #define MX6SX_BM_DPDM_WAKEUP_EN		BIT(29)
>  #define MX6_BM_WAKEUP_INTR		BIT(31)
> +
> +#define MX6_USB_HSIC_CTRL_OFFSET	0x10
> +#define MX6_BM_HSIC_CLK_ON		BIT(11)
> +#define MX6_BM_HSIC_EN			BIT(12)
> +
>  #define MX6_USB_OTG1_PHY_CTRL		0x18
>  /* For imx6dql, it is host-only controller, for later imx6, it is otg's */
>  #define MX6_USB_OTG2_PHY_CTRL		0x1c
> @@ -351,6 +357,22 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data
> *data)
>  	writel(reg | MX6_BM_NON_BURST_SETTING,
>  			usbmisc->base + data->index * 4);
> 
> +	/*
> +	 * Core 2 and 3 are host only and HSIC only,
> +	 * so we enable HSIC by default to make them usable
> +	 */
> +	if (data->index == 2 || data->index == 3) {
> +		reg = readl(usbmisc->base + data->index * 4);
> +		writel(reg | MX6_BM_UTMI_ON_CLOCK,
> +		       usbmisc->base + data->index * 4);
> +
> +		reg = readl(usbmisc->base + MX6_USB_HSIC_CTRL_OFFSET +
> +			    (data->index - 2) * 4);
> +		reg |= MX6_BM_HSIC_EN | MX6_BM_HSIC_CLK_ON;
> +		writel(reg, usbmisc->base + MX6_USB_HSIC_CTRL_OFFSET +
> +		       (data->index - 2) * 4);
> +	}
> +
>  	spin_unlock_irqrestore(&usbmisc->lock, flags);
> 
>  	usbmisc_imx6q_set_wakeup(data, false);
> --
> 2.7.4
Frieder Schrempf Oct. 10, 2018, 12:52 p.m. UTC | #2
Hi Peter,

On 09.10.2018 03:24, Peter Chen wrote:
>   
>>
>> The topic has been discussed before: [1] And there is some implementation in the
>> vendor kernel: [2]
>>
>> It seems like two things need to be done:
>>
>> 1. Switch the pinmux of the strobe signal to use a pullup after
>>     the core has been initialized.
>> 2. Enable HSIC mode and HSIC clock
>>
>> This patch only implements these basics in a minimal approach.
>> You need to have an additional pinmux setting "active" in the dt, that sets the pullup.
>>
>> It was tested with the SMSC LAN9730 USB Ethernet adapter on the iMXceet Solo S
>> board.
>>
> 
> Thanks, I should do it earlier, I could not find a suitable board with HSIC support at mainline kernel.
> It is very kind that you could help on it and test function at real board. My suggestion is
> follow all flows in Link [2] since we need to cover suspend/resume and remote wakeup.

It seems like power management and other things in the linux-imx kernel 
are not fully implemented in mainline so there are quite a few differences.

My knowledge of USB, etc. is very limited, so I guess this is currently 
beyond my skills. Can you or someone else provide a patch to get 
started? I could help with testing, reviewing, etc.

Or maybe you can point out what needs to be done in more detail?

Thanks,
Frieder
Peter Chen Oct. 12, 2018, 1:19 a.m. UTC | #3
> > Thanks, I should do it earlier, I could not find a suitable board with HSIC support
> at mainline kernel.
> > It is very kind that you could help on it and test function at real
> > board. My suggestion is follow all flows in Link [2] since we need to cover
> suspend/resume and remote wakeup.
> 
> It seems like power management and other things in the linux-imx kernel are not
> fully implemented in mainline so there are quite a few differences.
> 
> My knowledge of USB, etc. is very limited, so I guess this is currently beyond my
> skills. Can you or someone else provide a patch to get started? I could help with
> testing, reviewing, etc.
> 
 
Ok, I will supply the patch, and you could add your dts changes as well as testing.
Thanks.

Peter
Frieder Schrempf Oct. 15, 2018, 10:28 a.m. UTC | #4
On 12.10.2018 03:19, Peter Chen wrote:
>   
>>> Thanks, I should do it earlier, I could not find a suitable board with HSIC support
>> at mainline kernel.
>>> It is very kind that you could help on it and test function at real
>>> board. My suggestion is follow all flows in Link [2] since we need to cover
>> suspend/resume and remote wakeup.
>>
>> It seems like power management and other things in the linux-imx kernel are not
>> fully implemented in mainline so there are quite a few differences.
>>
>> My knowledge of USB, etc. is very limited, so I guess this is currently beyond my
>> skills. Can you or someone else provide a patch to get started? I could help with
>> testing, reviewing, etc.
>>
>   
> Ok, I will supply the patch, and you could add your dts changes as well as testing.
> Thanks.

Ok, great. Just let me know when you have something that is ready for 
testing and I will give it a try on my setup.

Thanks,
Frieder
diff mbox series

Patch

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index 19f5f5f..fef8bda 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -256,6 +256,7 @@  static int ci_hdrc_imx_probe(struct platform_device *pdev)
 	const struct of_device_id *of_id;
 	const struct ci_hdrc_imx_platform_flag *imx_platform_flag;
 	struct device_node *np = pdev->dev.of_node;
+	struct pinctrl *pinctrl;
 
 	of_id = of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev);
 	if (!of_id)
@@ -331,6 +332,15 @@  static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		pm_runtime_enable(&pdev->dev);
 	}
 
+	pinctrl = devm_pinctrl_get(&pdev->dev);
+	if (!IS_ERR(pinctrl)) {
+		struct pinctrl_state *state;
+
+		state = pinctrl_lookup_state(pinctrl, "active");
+		if (!IS_ERR(state))
+			pinctrl_select_state(pinctrl, state);
+	}
+
 	device_set_wakeup_capable(&pdev->dev, true);
 
 	return 0;
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
index 34ad5bf..a6556c8 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -64,10 +64,16 @@ 
 #define MX6_BM_OVER_CUR_DIS		BIT(7)
 #define MX6_BM_OVER_CUR_POLARITY	BIT(8)
 #define MX6_BM_WAKEUP_ENABLE		BIT(10)
+#define MX6_BM_UTMI_ON_CLOCK		BIT(13)
 #define MX6_BM_ID_WAKEUP		BIT(16)
 #define MX6_BM_VBUS_WAKEUP		BIT(17)
 #define MX6SX_BM_DPDM_WAKEUP_EN		BIT(29)
 #define MX6_BM_WAKEUP_INTR		BIT(31)
+
+#define MX6_USB_HSIC_CTRL_OFFSET	0x10
+#define MX6_BM_HSIC_CLK_ON		BIT(11)
+#define MX6_BM_HSIC_EN			BIT(12)
+
 #define MX6_USB_OTG1_PHY_CTRL		0x18
 /* For imx6dql, it is host-only controller, for later imx6, it is otg's */
 #define MX6_USB_OTG2_PHY_CTRL		0x1c
@@ -351,6 +357,22 @@  static int usbmisc_imx6q_init(struct imx_usbmisc_data *data)
 	writel(reg | MX6_BM_NON_BURST_SETTING,
 			usbmisc->base + data->index * 4);
 
+	/*
+	 * Core 2 and 3 are host only and HSIC only,
+	 * so we enable HSIC by default to make them usable
+	 */
+	if (data->index == 2 || data->index == 3) {
+		reg = readl(usbmisc->base + data->index * 4);
+		writel(reg | MX6_BM_UTMI_ON_CLOCK,
+		       usbmisc->base + data->index * 4);
+
+		reg = readl(usbmisc->base + MX6_USB_HSIC_CTRL_OFFSET +
+			    (data->index - 2) * 4);
+		reg |= MX6_BM_HSIC_EN | MX6_BM_HSIC_CLK_ON;
+		writel(reg, usbmisc->base + MX6_USB_HSIC_CTRL_OFFSET +
+		       (data->index - 2) * 4);
+	}
+
 	spin_unlock_irqrestore(&usbmisc->lock, flags);
 
 	usbmisc_imx6q_set_wakeup(data, false);