diff mbox

[1/9] usb: chipidea: usbmisc: Add USB Host support for i.MX25/i.MX35 CPUs

Message ID 1394211863-7569-1-git-send-email-denis@eukrea.com (mailing list archive)
State New, archived
Headers show

Commit Message

Denis Carikli March 7, 2014, 5:04 p.m. UTC
Signed-off-by: Denis Carikli <denis@eukrea.com>
---
 drivers/usb/chipidea/usbmisc_imx.c |   59 ++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

Comments

Sergei Shtylyov March 7, 2014, 7:01 p.m. UTC | #1
Hello.

On 03/07/2014 08:04 PM, Denis Carikli wrote:

> Signed-off-by: Denis Carikli <denis@eukrea.com>
> ---
>   drivers/usb/chipidea/usbmisc_imx.c |   59 ++++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)

> diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> index cd061ab..d956ad0 100644
> --- a/drivers/usb/chipidea/usbmisc_imx.c
> +++ b/drivers/usb/chipidea/usbmisc_imx.c
> @@ -21,6 +21,26 @@
>   #define MX25_USB_PHY_CTRL_OFFSET	0x08
>   #define MX25_BM_EXTERNAL_VBUS_DIVIDER	BIT(23)
>
> +#define MXC_EHCI_INTERFACE_SINGLE_UNI	(2 << 0)
> +#define MXC_EHCI_INTERFACE_DIFF_UNI	(0 << 0)
> +#define MXC_EHCI_INTERFACE_MASK		(0xf)
> +
> +#define MX25_OTG_SIC_SHIFT		29
> +#define MX25_OTG_SIC_MASK		(0x3 << MX25_OTG_SIC_SHIFT)
> +#define MX25_OTG_PM_BIT			BIT(24)
> +#define MX25_OTG_PP_BIT			BIT(11)
> +#define MX25_OTG_OCPOL_BIT		(1 << 3)

    Hm, why not BIT(3). Though frankly speaking, I don't think (x << n) macros 
go together well with BIT() ones.

> +
> +#define MX25_H1_SIC_SHIFT		21
> +#define MX25_H1_SIC_MASK		(0x3 << MX25_H1_SIC_SHIFT)
> +#define MX25_H1_PP_BIT			BIT(18)
> +#define MX25_H1_PM_BIT			BIT(16)
> +#define MX25_H1_IPPUE_UP_BIT		BIT(7)
> +#define MX25_H1_IPPUE_DOWN_BIT		BIT(6)
> +#define MX25_H1_TLL_BIT			BIT(5)
> +#define MX25_H1_USBTE_BIT		BIT(4)
> +#define MX25_H1_OCPOL_BIT		(1 << 2)

    BIT(2)?

WBR, Sergei
Alexander Shiyan March 8, 2014, 5:32 a.m. UTC | #2
???????,  7 ????? 2014, 18:04 +01:00 ?? Denis Carikli <denis@eukrea.com>:
> Signed-off-by: Denis Carikli <denis@eukrea.com>
> ---
>  drivers/usb/chipidea/usbmisc_imx.c |   59 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 59 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> index cd061ab..d956ad0 100644
> --- a/drivers/usb/chipidea/usbmisc_imx.c
> +++ b/drivers/usb/chipidea/usbmisc_imx.c
...
> +		val = readl(usbmisc->base);
> +		val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT);
> +		val |= (MXC_EHCI_INTERFACE_DIFF_UNI & MXC_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT;
> +		val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT);
> +		writel(val, usbmisc->base);

At the moment, we only enable/disable interface and manage overcurrent option
in the usbmisc driver.
Is it worth it to handle type of interface here?

---
Peter Chen March 10, 2014, 12:40 a.m. UTC | #3
On Sat, Mar 08, 2014 at 09:32:15AM +0400, Alexander Shiyan wrote:
> ???????,  7 ????? 2014, 18:04 +01:00 ?? Denis Carikli <denis@eukrea.com>:
> > Signed-off-by: Denis Carikli <denis@eukrea.com>
> > ---
> >  drivers/usb/chipidea/usbmisc_imx.c |   59 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 59 insertions(+)
> > 
> > diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> > index cd061ab..d956ad0 100644
> > --- a/drivers/usb/chipidea/usbmisc_imx.c
> > +++ b/drivers/usb/chipidea/usbmisc_imx.c
> ...
> > +		val = readl(usbmisc->base);
> > +		val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT);
> > +		val |= (MXC_EHCI_INTERFACE_DIFF_UNI & MXC_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT;
> > +		val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT);
> > +		writel(val, usbmisc->base);
> 
> At the moment, we only enable/disable interface and manage overcurrent option
> in the usbmisc driver.
> Is it worth it to handle type of interface here?
> 

All usb related things which are not included at chipidea core can be in
usbmisc driver.
Fabio Estevam March 10, 2014, 1:21 a.m. UTC | #4
Hi Denis,

On Fri, Mar 7, 2014 at 2:04 PM, Denis Carikli <denis@eukrea.com> wrote:

> +static int usbmisc_imx25_init(struct imx_usbmisc_data *data)
> +{
> +       void __iomem *reg = NULL;

This variable is not used and causes a warning. Please remove it.

After applying this patch things go further when I boot with a USB
thumb connected to the USB Host1 port:

ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
usbcore: registered new interface driver usb-storage
53ff4400.usb supply vbus not found, using dummy regulator
ci_hdrc ci_hdrc.0: EHCI Host Controller
ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1
ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
....

usb 1-1: new full-speed USB device number 2 using ci_hdrc

(Not sure why it says full-speed device. When I connect the same
device to a PC it says high-speed)

usb 1-1: not running at top speed; connect to a high speed hub
usb-storage 1-1:1.0: USB Mass Storage device detected
usb-storage 1-1:1.0: Quirks match for vid 0457 pid 0151: 80
scsi0 : usb-storage 1-1:1.0
scsi 0:0:0:0: Direct-Access     Ut163    USB2FlashStorage 0.00 PQ: 0 ANSI: 2
sd 0:0:0:0: [sda] 248000 512-byte logical blocks: (126 MB/121 MiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
 sda: sda1
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] Attached SCSI removable disk
fec 50038000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
Sending DHCP requests ., OK
IP-Config: Got DHCP answer from 192.168.0.1, my address is 192.168.0.8
IP-Config: Complete:
     device=eth0, hwaddr=00:04:00:00:00:00, ipaddr=192.168.0.8, mask=255.255.251
     host=192.168.0.8, domain=, nis-domain=(none)
     bootserver=192.168.0.1, rootserver=192.168.0.2, rootpath=
     nameserver0=192.168.0.1
ALSA device list:
  No soundcards found.
VFS: Mounted root (nfs filesystem) readonly on device 0:13.
devtmpfs: mounted
Freeing unused kernel memory: 276K (c0697000 - c06dc000)
starting pid 536, tty '': '/etc/rc.d/rcS'
Mounting /proc and /sys
Starting the hotplug events dispatcher udevd
Synthesizing initial hotplug events
imx-sdma 53fd4000.sdma: firmware not found

(Then system hangs here).

If I boot without the USB thumb connected, then I reach the prompt,
however after inserting the USB pen drive into USBH1 there is no
detection.

Any ideas?

Thanks,

Fabio Estevam
Alexander Shiyan March 10, 2014, 4:58 a.m. UTC | #5
???????????,  9 ????? 2014, 22:21 -03:00 ?? Fabio Estevam <festevam@gmail.com>:
> Hi Denis,
> 
> On Fri, Mar 7, 2014 at 2:04 PM, Denis Carikli <denis@eukrea.com> wrote:
> 
> > +static int usbmisc_imx25_init(struct imx_usbmisc_data *data)
> > +{
> > +       void __iomem *reg = NULL;
> 
> This variable is not used and causes a warning. Please remove it.
> 
> After applying this patch things go further when I boot with a USB
> thumb connected to the USB Host1 port:
...
> (Not sure why it says full-speed device. When I connect the same
> device to a PC it says high-speed)
...
> (Then system hangs here).
> 
> If I boot without the USB thumb connected, then I reach the prompt,
> however after inserting the USB pen drive into USBH1 there is no
> detection.
> 
> Any ideas?

Fabio, start with to make work USB port on your board in the bootloader.
Then with the previous driver (ehci-mxc).
Most likely problem is a wrong (or missing) clock.
As I mentioned earlier, DTS has incorrect clock nodes.

---
Eric Bénard March 10, 2014, 5:55 a.m. UTC | #6
Hi Fabio,

Le Sun, 9 Mar 2014 22:21:59 -0300,
Fabio Estevam <festevam@gmail.com> a écrit :
> On Fri, Mar 7, 2014 at 2:04 PM, Denis Carikli <denis@eukrea.com> wrote:
> 
> > +static int usbmisc_imx25_init(struct imx_usbmisc_data *data)
> > +{
> > +       void __iomem *reg = NULL;
> 
> This variable is not used and causes a warning. Please remove it.
> 
> After applying this patch things go further when I boot with a USB
> thumb connected to the USB Host1 port:
> 
> ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
> usbcore: registered new interface driver usb-storage
> 53ff4400.usb supply vbus not found, using dummy regulator
> ci_hdrc ci_hdrc.0: EHCI Host Controller
> ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1
> ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
> hub 1-0:1.0: USB hub found
> hub 1-0:1.0: 1 port detected
> ....
> 
> usb 1-1: new full-speed USB device number 2 using ci_hdrc
> 
> (Not sure why it says full-speed device. When I connect the same
> device to a PC it says high-speed)
> 
because i.MX25 and i.MX35 only have a full speed phy on the host port.

Eric
Fabio Estevam March 10, 2014, 11:16 a.m. UTC | #7
Hi Alexander,

On Mon, Mar 10, 2014 at 1:58 AM, Alexander Shiyan <shc_work@mail.ru> wrote:

> Fabio, start with to make work USB port on your board in the bootloader.
> Then with the previous driver (ehci-mxc).
> Most likely problem is a wrong (or missing) clock.
> As I mentioned earlier, DTS has incorrect clock nodes.

Yes, you are right, thanks.

If I change the usb host clocks as:

-                               clocks = <&clks 9>, <&clks 70>, <&clks 8>;
-                               clock-names = "ipg", "ahb", "per";
+                               clocks = <&clks 70>;

Then USB host1 works fine on my mx25pdk board.

Denis,

Could you please resend 4/9 by changing the clocks nodes in the OTG
and Host1 ports as shown above?

Thanks,

Fabio Estevam
Fabio Estevam March 10, 2014, 11:19 a.m. UTC | #8
Hi Eric,

On Mon, Mar 10, 2014 at 2:55 AM, Eric Bénard <eric@eukrea.com> wrote:
> Hi Fabio,

>> (Not sure why it says full-speed device. When I connect the same
>> device to a PC it says high-speed)
>>
> because i.MX25 and i.MX35 only have a full speed phy on the host port.

This makes sense, thanks.
Fabio Estevam March 10, 2014, 3:32 p.m. UTC | #9
Hi Denis,

On Mon, Mar 10, 2014 at 8:16 AM, Fabio Estevam <festevam@gmail.com> wrote:

> Denis,
>
> Could you please resend 4/9 by changing the clocks nodes in the OTG
> and Host1 ports as shown above?

Thinking more about it, it would be better to send the USB clock
change as a separate patch.

I can submit the dts changes to the linux-arm-kernel list later today.

Regards,

Fabio Estevam
diff mbox

Patch

diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
index cd061ab..d956ad0 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -21,6 +21,26 @@ 
 #define MX25_USB_PHY_CTRL_OFFSET	0x08
 #define MX25_BM_EXTERNAL_VBUS_DIVIDER	BIT(23)
 
+#define MXC_EHCI_INTERFACE_SINGLE_UNI	(2 << 0)
+#define MXC_EHCI_INTERFACE_DIFF_UNI	(0 << 0)
+#define MXC_EHCI_INTERFACE_MASK		(0xf)
+
+#define MX25_OTG_SIC_SHIFT		29
+#define MX25_OTG_SIC_MASK		(0x3 << MX25_OTG_SIC_SHIFT)
+#define MX25_OTG_PM_BIT			BIT(24)
+#define MX25_OTG_PP_BIT			BIT(11)
+#define MX25_OTG_OCPOL_BIT		(1 << 3)
+
+#define MX25_H1_SIC_SHIFT		21
+#define MX25_H1_SIC_MASK		(0x3 << MX25_H1_SIC_SHIFT)
+#define MX25_H1_PP_BIT			BIT(18)
+#define MX25_H1_PM_BIT			BIT(16)
+#define MX25_H1_IPPUE_UP_BIT		BIT(7)
+#define MX25_H1_IPPUE_DOWN_BIT		BIT(6)
+#define MX25_H1_TLL_BIT			BIT(5)
+#define MX25_H1_USBTE_BIT		BIT(4)
+#define MX25_H1_OCPOL_BIT		(1 << 2)
+
 #define MX27_H1_PM_BIT			BIT(8)
 #define MX27_H2_PM_BIT			BIT(16)
 #define MX27_OTG_PM_BIT			BIT(24)
@@ -50,6 +70,40 @@  struct imx_usbmisc {
 
 static struct imx_usbmisc *usbmisc;
 
+static int usbmisc_imx25_init(struct imx_usbmisc_data *data)
+{
+	void __iomem *reg = NULL;
+	unsigned long flags;
+	u32 val = 0;
+
+	if (data->index > 1)
+		return -EINVAL;
+
+	spin_lock_irqsave(&usbmisc->lock, flags);
+	switch (data->index) {
+	case 0:
+		val = readl(usbmisc->base);
+		val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT);
+		val |= (MXC_EHCI_INTERFACE_DIFF_UNI & MXC_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT;
+		val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT);
+		writel(val, usbmisc->base);
+		break;
+	case 1:
+		val = readl(usbmisc->base);
+		val &= ~(MX25_H1_SIC_MASK | MX25_H1_PP_BIT |  MX25_H1_IPPUE_UP_BIT);
+		val |= (MXC_EHCI_INTERFACE_SINGLE_UNI & MXC_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT;
+		val |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT |
+			MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT);
+
+		writel(val, usbmisc->base);
+
+		break;
+	}
+	spin_unlock_irqrestore(&usbmisc->lock, flags);
+
+	return 0;
+}
+
 static int usbmisc_imx25_post(struct imx_usbmisc_data *data)
 {
 	void __iomem *reg;
@@ -159,6 +213,7 @@  static int usbmisc_imx6q_init(struct imx_usbmisc_data *data)
 }
 
 static const struct usbmisc_ops imx25_usbmisc_ops = {
+	.init = usbmisc_imx25_init,
 	.post = usbmisc_imx25_post,
 };
 
@@ -200,6 +255,10 @@  static const struct of_device_id usbmisc_imx_dt_ids[] = {
 		.data = &imx25_usbmisc_ops,
 	},
 	{
+		.compatible = "fsl,imx35-usbmisc",
+		.data = &imx25_usbmisc_ops,
+	},
+	{
 		.compatible = "fsl,imx27-usbmisc",
 		.data = &imx27_usbmisc_ops,
 	},