[U-Boot] [RFC 24/35] reset: sunxi: Add initial RESET driver for A31/A31s

Jagan Teki jagan at amarulasolutions.com
Mon Jul 16 11:28:39 UTC 2018


Add initial reset driver for Allwinner A31/A31s.

Implement reset deassert and assert functions for
USB OHCI, EHCI, OTG and PHY bus reset and clock registers.

Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
 drivers/reset/sunxi/Kconfig     |   7 ++
 drivers/reset/sunxi/Makefile    |   1 +
 drivers/reset/sunxi/reset_a31.c | 123 ++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+)
 create mode 100644 drivers/reset/sunxi/reset_a31.c

diff --git a/drivers/reset/sunxi/Kconfig b/drivers/reset/sunxi/Kconfig
index 40f4f4d0e6..bf1a2f05bf 100644
--- a/drivers/reset/sunxi/Kconfig
+++ b/drivers/reset/sunxi/Kconfig
@@ -23,6 +23,13 @@ config RESET_SUN5I_A10S
 	  This enables common reset driver support for platforms based
 	  on Allwinner A10s/A13 SoC.
 
+config RESET_SUN6I_A31
+	bool "Reset driver for Allwinner A31/A31s"
+	default MACH_SUN6I
+	help
+	  This enables common reset driver support for platforms based
+	  on Allwinner A31/A31s SoC.
+
 config RESET_SUN8I_H3
 	bool "Reset driver for Allwinner H3/H5"
 	default MACH_SUNXI_H3_H5
diff --git a/drivers/reset/sunxi/Makefile b/drivers/reset/sunxi/Makefile
index 38b8907904..b599e1994b 100644
--- a/drivers/reset/sunxi/Makefile
+++ b/drivers/reset/sunxi/Makefile
@@ -6,5 +6,6 @@
 
 obj-$(CONFIG_RESET_SUN4I_A10) += reset_a10.o
 obj-$(CONFIG_RESET_SUN5I_A10S) += reset_a10s.o
+obj-$(CONFIG_RESET_SUN6I_A31) += reset_a31.o
 obj-$(CONFIG_RESET_SUN8I_H3) += reset_h3.o
 obj-$(CONFIG_RESET_SUN50I_A64) += reset_a64.o
diff --git a/drivers/reset/sunxi/reset_a31.c b/drivers/reset/sunxi/reset_a31.c
new file mode 100644
index 0000000000..8c7a8a6bb9
--- /dev/null
+++ b/drivers/reset/sunxi/reset_a31.c
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (C) 2018 Amarula Solutions B.V.
+ * Author: Jagan Teki <jagan at amarulasolutions.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <reset-uclass.h>
+#include <asm/io.h>
+#include <dm/lists.h>
+#include <dt-bindings/reset/sun6i-a31-ccu.h>
+
+struct a31_reset_priv {
+	void *base;
+};
+
+static int a31_reset_request(struct reset_ctl *reset_ctl)
+{
+	debug("%s(#%ld)\n", __func__, reset_ctl->id);
+
+	/* check dt-bindings/reset/sun6i-a31-ccu.h for max id */
+	if (reset_ctl->id > 56)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int a31_reset_free(struct reset_ctl *reset_ctl)
+{
+	debug("%s(#%ld)\n", __func__, reset_ctl->id);
+
+	return 0;
+}
+
+static int a31_reset_assert(struct reset_ctl *reset_ctl)
+{
+	struct a31_reset_priv *priv = dev_get_priv(reset_ctl->dev);
+
+	debug("%s(#%ld)\n", __func__, reset_ctl->id);
+
+	switch (reset_ctl->id) {
+	case RST_USB_PHY0:
+	case RST_USB_PHY1:
+	case RST_USB_PHY2:
+		clrbits_le32(priv->base + 0xcc, BIT(reset_ctl->id));
+		return 0;
+	case RST_AHB1_OTG:
+		clrbits_le32(priv->base + 0x2c0, BIT(24));
+		return 0;
+	case RST_AHB1_EHCI0:
+	case RST_AHB1_EHCI1:
+		clrbits_le32(priv->base + 0x2c0,
+			     BIT(26 + (reset_ctl->id - RST_AHB1_EHCI0)));
+		return 0;
+	case RST_AHB1_OHCI0:
+	case RST_AHB1_OHCI1:
+	case RST_AHB1_OHCI2:
+		clrbits_le32(priv->base + 0x2c0,
+			     BIT(29 + (reset_ctl->id - RST_AHB1_OHCI0)));
+		return 0;
+	default:
+		debug("%s (RST#%ld) unhandled\n", __func__, reset_ctl->id);
+		return -ENODEV;
+	}
+}
+
+static int a31_reset_deassert(struct reset_ctl *reset_ctl)
+{
+	struct a31_reset_priv *priv = dev_get_priv(reset_ctl->dev);
+
+	debug("%s(#%ld)\n", __func__, reset_ctl->id);
+
+	switch (reset_ctl->id) {
+	case RST_USB_PHY0:
+	case RST_USB_PHY1:
+	case RST_USB_PHY2:
+		setbits_le32(priv->base + 0xcc, BIT(reset_ctl->id));
+		return 0;
+	case RST_AHB1_OTG:
+		setbits_le32(priv->base + 0x2c0, BIT(24));
+		return 0;
+	case RST_AHB1_EHCI0:
+	case RST_AHB1_EHCI1:
+		setbits_le32(priv->base + 0x2c0,
+			     BIT(26 + (reset_ctl->id - RST_AHB1_EHCI0)));
+		return 0;
+	case RST_AHB1_OHCI0:
+	case RST_AHB1_OHCI1:
+	case RST_AHB1_OHCI2:
+		setbits_le32(priv->base + 0x2c0,
+			     BIT(29 + (reset_ctl->id - RST_AHB1_OHCI0)));
+		return 0;
+	default:
+		debug("%s (RST#%ld) unhandled\n", __func__, reset_ctl->id);
+		return -ENODEV;
+	}
+}
+
+struct reset_ops a31_reset_ops = {
+	.request = a31_reset_request,
+	.free = a31_reset_free,
+	.rst_assert = a31_reset_assert,
+	.rst_deassert = a31_reset_deassert,
+};
+
+static int a31_reset_probe(struct udevice *dev)
+{
+	struct a31_reset_priv *priv = dev_get_priv(dev);
+
+	priv->base = dev_read_addr_ptr(dev);
+
+	return 0;
+}
+
+U_BOOT_DRIVER(reset_sun6i_a31) = {
+	.name		= "sun6i_a31_reset",
+	.id		= UCLASS_RESET,
+	.ops		= &a31_reset_ops,
+	.probe		= a31_reset_probe,
+	.priv_auto_alloc_size = sizeof(struct a31_reset_priv),
+};
-- 
2.17.1



More information about the U-Boot mailing list