All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 05/11] sunxi: add module reset (UCLASS_RESET) support for sunxi
Date: Fri, 17 Feb 2017 18:52:42 +0100	[thread overview]
Message-ID: <3c7b1cdadabb3eed64fa84a1c5475e0c5b443ef8.1487349600.git.philipp.tomsich@theobroma-systems.com> (raw)
In-Reply-To: <cover.1487336688.git.philipp.tomsich@theobroma-systems.com>

In order to have the device model describe the module reset bits
on sunxi (well, at least for anything newer than sun6i), we need
a (rather simple) driver for 'allwinner,sun6i-a31-clock-reset'
nodes.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
---
 drivers/reset/Kconfig       |   9 ++++
 drivers/reset/Makefile      |   1 +
 drivers/reset/reset-sunxi.c | 107 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 drivers/reset/reset-sunxi.c

diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index c42b0bc..8db25fc 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -43,4 +43,13 @@ config RESET_UNIPHIER
 	  Say Y if you want to control reset signals provided by System Control
 	  block, Media I/O block, Peripheral Block.
 
+config RESET_SUNXI
+        bool "Reset controller driver for Allwiner SoCs"
+	depends on DM_RESET && ARCH_SUNXI
+	default y
+	help
+	  Support for reset controllers on Allwinner SoCs.
+	  Say Y if you want to control reset signals provided by CCU (e.g. sun50i)
+	  or PRCM (e.g. sun6i, sun9i) blocks.
+
 endmenu
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 5c4305c..0086da9 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -1,10 +1,11 @@
 # Copyright (c) 2016, NVIDIA CORPORATION.
 #
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_DM_RESET) += reset-uclass.o
 obj-$(CONFIG_SANDBOX_MBOX) += sandbox-reset.o
 obj-$(CONFIG_SANDBOX_MBOX) += sandbox-reset-test.o
 obj-$(CONFIG_TEGRA_CAR_RESET) += tegra-car-reset.o
 obj-$(CONFIG_TEGRA186_RESET) += tegra186-reset.o
 obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o
+obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o
diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
new file mode 100644
index 0000000..b667ca1
--- /dev/null
+++ b/drivers/reset/reset-sunxi.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2017 Theobroma Systems Design und Consulting GmbH
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <reset-uclass.h>
+#include <dm/device.h>
+#include <linux/bitops.h>
+#include <linux/io.h>
+#include <linux/sizes.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct sunxi_reset_priv {
+	void __iomem *base;
+	size_t  size;
+};
+
+static int sunxi_reset_request(struct reset_ctl *reset_ctl)
+{
+	debug("%s (%s): id %ld\n",
+	      reset_ctl->dev->name, __func__, reset_ctl->id);
+	return 0;
+}
+
+static int sunxi_reset_free(struct reset_ctl *reset_ctl)
+{
+	debug("%s (%s): id %ld\n",
+	      reset_ctl->dev->name, __func__, reset_ctl->id);
+	return 0;
+}
+
+static int sunxi_reset_update(struct reset_ctl *reset_ctl, bool assert)
+{
+	struct sunxi_reset_priv *priv = dev_get_priv(reset_ctl->dev);
+	unsigned long id = reset_ctl->id;
+	unsigned long offset = id / 32; /* TODO: symbolic name */
+	unsigned int bit = id % 32;
+
+	debug("%s (%s): id %ld base %p offset %lx bit %d assert %d size %ld\n",
+	      reset_ctl->dev->name, __func__, id, priv->base, offset,
+	      bit, assert, priv->size);
+
+	if (offset >= priv->size)
+		return -EINVAL;
+
+	if (assert)
+		clrbits_le32(priv->base + offset, BIT(bit));
+	else
+		setbits_le32(priv->base + offset, BIT(bit));
+
+	return 0;
+}
+
+static int sunxi_reset_assert(struct reset_ctl *reset_ctl)
+{
+	return sunxi_reset_update(reset_ctl, true);
+}
+
+static int sunxi_reset_deassert(struct reset_ctl *reset_ctl)
+{
+	return sunxi_reset_update(reset_ctl, false);
+}
+
+static const struct reset_ops sunxi_reset_ops = {
+	.request = sunxi_reset_request,
+	.free = sunxi_reset_free,
+	.rst_assert = sunxi_reset_assert,
+	.rst_deassert = sunxi_reset_deassert,
+};
+
+static int sunxi_reset_probe(struct udevice *dev)
+{
+	struct sunxi_reset_priv *priv = dev_get_priv(dev);
+	fdt_addr_t addr;
+	fdt_size_t size;
+
+	addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
+						  "reg", 0, &size, false);
+	if (addr == FDT_ADDR_T_NONE) {
+		debug("%s: failed to find base address ('reg')\n", dev->name);
+		return -ENODEV;
+	}
+	priv->base = (void *)addr;
+	priv->size = size;
+
+	if (!priv->base)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static const struct udevice_id sunxi_reset_match[] = {
+	{ .compatible = "allwinner,sun6i-a31-clock-reset" },
+	{ }
+};
+
+U_BOOT_DRIVER(sunxi_reset) = {
+	.name = "sunxi-reset",
+	.id = UCLASS_RESET,
+	.of_match = sunxi_reset_match,
+	.ops = &sunxi_reset_ops,
+	.priv_auto_alloc_size = sizeof(struct sunxi_reset_priv),
+	.probe = sunxi_reset_probe,
+};
-- 
1.9.1

  parent reply	other threads:[~2017-02-17 17:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 17:52 [U-Boot] [PATCH v1 00/11] sunxi: DM drivers for CLK, RESET and PINCTRL Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 01/11] spl: dm: Undefine DM_MMC, DM_MMC_OPS and BLK, if SPL_DM is not defined Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 02/11] sunxi: add pinctrl (UCLASS_PINCTRL) support for sunxi and tie back into GPIO Philipp Tomsich
2017-02-21  3:48   ` Chen-Yu Tsai
2017-02-21  9:39     ` Dr. Philipp Tomsich
2017-02-22  6:07       ` Chen-Yu Tsai
2017-02-22  9:26         ` Dr. Philipp Tomsich
2017-02-21 20:14   ` Maxime Ripard
2017-02-17 17:52 ` [U-Boot] [PATCH v1 03/11] sun50i: dts: add gpiobank nodes to the pinctrl nodes Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 04/11] sun50i: dts: update DTS to avoid warnings Philipp Tomsich
2017-02-21 20:15   ` Maxime Ripard
2017-02-17 17:52 ` Philipp Tomsich [this message]
2017-02-21 20:16   ` [U-Boot] [PATCH v1 05/11] sunxi: add module reset (UCLASS_RESET) support for sunxi Maxime Ripard
2017-02-17 17:52 ` [U-Boot] [PATCH v1 06/11] sunxi: add clock driver (UCLASS_CLK) " Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 07/11] sunxi: Scan DT tree node '/clocks' on sunxi boards Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 08/11] sun8i_emac: update to work with pinctrl-sunxi, reset-sunxi and clk-sunxi Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 09/11] sunxi_mmc: convert to a device-model driver Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 10/11] dts: sun50i: update mmc pin configuration and add mmc2_8bit_pins Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 11/11] sun50i: dts: add spi0 and spi1 nodes and pinconfig Philipp Tomsich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3c7b1cdadabb3eed64fa84a1c5475e0c5b443ef8.1487349600.git.philipp.tomsich@theobroma-systems.com \
    --to=philipp.tomsich@theobroma-systems.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.