diff mbox

[U-Boot,v4,06/12] usb: ohci: Add STi ohci support

Message ID 1494332206-24843-7-git-send-email-patrice.chotard@st.com
State Superseded
Delegated to: Marek Vasut
Headers show

Commit Message

Patrice CHOTARD May 9, 2017, 12:16 p.m. UTC
From: Patrice Chotard <patrice.chotard@st.com>

Add support for on-chip ohci controller available
on STMicrolectronics SoCs.
Ohci support will be then available on both type A
USB 2.0 connectors.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
v4:	_ update to use the new PHY uclass currently available on dm-next branch

v3: _ update to use new USB PHY uclass

v2:	_ put board specific defines in a separate patch


 drivers/usb/host/Kconfig    |   9 ++++
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/ohci-sti.c | 119 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 129 insertions(+)
 create mode 100644 drivers/usb/host/ohci-sti.c

Comments

Marek Vasut May 10, 2017, 11:03 a.m. UTC | #1
On 05/09/2017 02:16 PM, patrice.chotard@st.com wrote:
> From: Patrice Chotard <patrice.chotard@st.com>
> 
> Add support for on-chip ohci controller available
> on STMicrolectronics SoCs.
> Ohci support will be then available on both type A
> USB 2.0 connectors.
> 
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
> v4:	_ update to use the new PHY uclass currently available on dm-next branch
> 
> v3: _ update to use new USB PHY uclass
> 
> v2:	_ put board specific defines in a separate patch
> 
> 

This might be a good candidate for ohci-generic .
Patrice CHOTARD May 10, 2017, 3:39 p.m. UTC | #2
Hi Marek

On 05/10/2017 01:03 PM, Marek Vasut wrote:
> On 05/09/2017 02:16 PM, patrice.chotard@st.com wrote:

>> From: Patrice Chotard <patrice.chotard@st.com>

>>

>> Add support for on-chip ohci controller available

>> on STMicrolectronics SoCs.

>> Ohci support will be then available on both type A

>> USB 2.0 connectors.

>>

>> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

>> ---

>> v4:	_ update to use the new PHY uclass currently available on dm-next branch

>>

>> v3: _ update to use new USB PHY uclass

>>

>> v2:	_ put board specific defines in a separate patch

>>

>>

>

> This might be a good candidate for ohci-generic .


Exact, i will extend ohci-generic driver as ehci_generic.c with clock, 
reset and phy

Thanks for pointing this ;-)

Patrice

>
diff mbox

Patch

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 7c29bf5..b259a05 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -169,6 +169,15 @@  config USB_OHCI_GENERIC
 	---help---
 	  Enables support for generic OHCI controller.
 
+config USB_OHCI_STI
+	bool "Support for STMicroelectronics OHCI USB controller"
+	depends on ARCH_STI
+	depends on OF_CONTROL
+	depends on DM_USB
+	select USB_HOST
+	---help---
+	  Enables support for the on-chip OHCI controller on STMicroelectronics SoCs.
+
 endif # USB_OHCI_HCD
 
 config USB_UHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 303aa32..b78e632 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -22,6 +22,7 @@  obj-$(CONFIG_USB_OHCI_EP93XX) += ohci-ep93xx.o
 obj-$(CONFIG_USB_OHCI_SUNXI) += ohci-sunxi.o
 obj-$(CONFIG_USB_OHCI_LPC32XX) += ohci-lpc32xx.o
 obj-$(CONFIG_USB_OHCI_GENERIC) += ohci-generic.o
+obj-$(CONFIG_USB_OHCI_STI) += ohci-sti.o
 
 # echi
 obj-$(CONFIG_USB_EHCI) += ehci-hcd.o
diff --git a/drivers/usb/host/ohci-sti.c b/drivers/usb/host/ohci-sti.c
new file mode 100644
index 0000000..77f8447
--- /dev/null
+++ b/drivers/usb/host/ohci-sti.c
@@ -0,0 +1,119 @@ 
+/*
+ * Copyright (c) 2017
+ * Patrice Chotard <patrice.chotard@st.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <errno.h>
+#include <generic-phy.h>
+#include "ohci.h"
+#include <reset-uclass.h>
+#include <usb.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if !defined(CONFIG_USB_OHCI_NEW)
+# error "Generic OHCI driver requires CONFIG_USB_OHCI_NEW"
+#endif
+
+struct sti_ohci_priv {
+	ohci_t ohci;
+	struct reset_ctl power_ctl;
+	struct reset_ctl softreset_ctl;
+	struct phy usb_phy;
+};
+
+static int ohci_usb_probe(struct udevice *dev)
+{
+	struct sti_ohci_priv *priv = dev_get_priv(dev);
+	struct ohci_regs *regs;
+	int ret;
+
+	regs = (struct ohci_regs *)dev_get_addr(dev);
+	if (regs == (void *)FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	ret = reset_get_by_name(dev, "power", &priv->power_ctl);
+	if (ret) {
+		error("can't get power reset for %s (%d)", dev->name, ret);
+		return ret;
+	}
+
+	ret = reset_get_by_name(dev, "softreset", &priv->softreset_ctl);
+	if (ret) {
+		error("can't get USB PHY for %s (%d)", dev->name, ret);
+		return ret;
+	}
+
+	ret = generic_phy_get_by_name(dev, "usb", &priv->usb_phy);
+	if (ret) {
+		error("can't get soft reset for %s (%d)", dev->name, ret);
+		return ret;
+	}
+
+	ret = reset_deassert(&priv->power_ctl);
+	if (ret < 0) {
+		error("OHCI power reset deassert failed: %d", ret);
+		return ret;
+	}
+
+	ret = reset_deassert(&priv->softreset_ctl);
+	if (ret < 0) {
+		error("OHCI soft reset deassert failed: %d", ret);
+		return ret;
+	}
+
+	ret = generic_phy_init(&priv->usb_phy);
+	if (ret) {
+		error("Can't init USB PHY\n");
+		return ret;
+	}
+
+	return ohci_register(dev, regs);
+}
+
+static int ohci_usb_remove(struct udevice *dev)
+{
+	struct sti_ohci_priv *priv = dev_get_priv(dev);
+	int ret;
+
+	ret = reset_deassert(&priv->power_ctl);
+	if (ret < 0) {
+		error("OHCI power reset assert failed: %d", ret);
+		return ret;
+	}
+
+	ret = reset_deassert(&priv->softreset_ctl);
+	if (ret < 0) {
+		error("OHCI soft reset assert failed: %d", ret);
+		return ret;
+	}
+
+	ret = generic_phy_exit(&priv->usb_phy);
+	if (ret) {
+		error("Can't deinit USB PHY\n");
+		return ret;
+	}
+
+	return ohci_deregister(dev);
+}
+
+static const struct udevice_id sti_usb_ids[] = {
+	{ .compatible = "st,st-ohci-300x" },
+	{ }
+};
+
+U_BOOT_DRIVER(ohci_sti) = {
+	.name = "ohci_sti",
+	.id = UCLASS_USB,
+	.of_match = sti_usb_ids,
+	.probe = ohci_usb_probe,
+	.remove = ohci_usb_remove,
+	.ops = &ohci_usb_ops,
+	.priv_auto_alloc_size = sizeof(struct sti_ohci_priv),
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};