From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/7] reset: add reset controller driver for STM32 RCC
Date: Wed, 10 Jul 2019 22:11:09 +0200 [thread overview]
Message-ID: <20190710201112.9086-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20190710201112.9086-1-a.fatoum@pengutronix.de>
On the STM32MP, reset of the I2C, SPI and USB IPs occurs over the RCC.
This driver adds support for the controller, so it may be reused by
other drivers.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/reset/Kconfig | 5 ++
drivers/reset/Makefile | 1 +
drivers/reset/reset-stm32.c | 109 ++++++++++++++++++++++++++++++++++++
3 files changed, 115 insertions(+)
create mode 100644 drivers/reset/reset-stm32.c
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index caf1dc9acb44..048f2081f82a 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -21,4 +21,9 @@ config RESET_IMX7
help
This enables the reset controller driver for i.MX7 SoCs.
+config RESET_STM32
+ bool "STM32 Reset Driver"
+ help
+ This enables the reset controller driver for STM32MP and STM32 MCUs.
+
endif
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 0b55caa20445..8460c4b154f5 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -1,3 +1,4 @@
obj-$(CONFIG_RESET_CONTROLLER) += core.o
obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o
obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
+obj-$(CONFIG_RESET_STM32) += reset-stm32.o
diff --git a/drivers/reset/reset-stm32.c b/drivers/reset/reset-stm32.c
new file mode 100644
index 000000000000..ff66fe310e1a
--- /dev/null
+++ b/drivers/reset/reset-stm32.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
+ * Copyright (C) 2019, Ahmad Fatoum, Pengutronix
+ * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <linux/err.h>
+#include <linux/reset-controller.h>
+#include <asm/io.h>
+
+#define RCC_CL 0x4
+
+struct stm32_reset {
+ void __iomem *base;
+ struct reset_controller_dev rcdev;
+ void (*reset)(void __iomem *reg, unsigned offset, bool assert);
+};
+
+static struct stm32_reset *to_stm32_reset(struct reset_controller_dev *rcdev)
+{
+ return container_of(rcdev, struct stm32_reset, rcdev);
+}
+
+static void stm32mp_reset(void __iomem *reg, unsigned offset, bool assert)
+{
+ if (assert)
+ offset += RCC_CL;
+
+ writel(BIT(offset), reg);
+}
+
+static void stm32mcu_reset(void __iomem *reg, unsigned offset, bool assert)
+{
+ if (assert)
+ setbits_le32(reg, BIT(offset));
+ else
+ clrbits_le32(reg, BIT(offset));
+}
+
+static void stm32_reset(struct stm32_reset *priv, unsigned long id, bool assert)
+{
+ int bank = (id / BITS_PER_LONG) * 4;
+ int offset = id % BITS_PER_LONG;
+
+ priv->reset(priv->base + bank, offset, assert);
+}
+
+static int stm32_reset_assert(struct reset_controller_dev *rcdev,
+ unsigned long id)
+{
+ stm32_reset(to_stm32_reset(rcdev), id, true);
+ return 0;
+}
+
+static int stm32_reset_deassert(struct reset_controller_dev *rcdev,
+ unsigned long id)
+{
+ stm32_reset(to_stm32_reset(rcdev), id, false);
+ return 0;
+}
+
+static const struct reset_control_ops stm32_reset_ops = {
+ .assert = stm32_reset_assert,
+ .deassert = stm32_reset_deassert,
+};
+
+static int stm32_reset_probe(struct device_d *dev)
+{
+ struct stm32_reset *priv;
+ struct resource *iores;
+ int ret;
+
+ priv = xzalloc(sizeof(*priv));
+ ret = dev_get_drvdata(dev, (const void **)&priv->reset);
+ if (ret)
+ return ret;
+
+ iores = dev_request_mem_resource(dev, 0);
+ if (IS_ERR(iores))
+ return PTR_ERR(iores);
+
+ priv->base = IOMEM(iores->start);
+ priv->rcdev.nr_resets = (iores->end - iores->start) * BITS_PER_BYTE;
+ priv->rcdev.ops = &stm32_reset_ops;
+ priv->rcdev.of_node = dev->device_node;
+
+ return reset_controller_register(&priv->rcdev);
+}
+
+static const struct of_device_id stm32_rcc_reset_dt_ids[] = {
+ { .compatible = "st,stm32mp1-rcc", .data = stm32mp_reset },
+ { .compatible = "st,stm32-rcc", .data = stm32mcu_reset },
+ { /* sentinel */ },
+};
+
+static struct driver_d stm32_rcc_reset_driver = {
+ .name = "stm32_rcc_reset",
+ .probe = stm32_reset_probe,
+ .of_compatible = DRV_OF_COMPAT(stm32_rcc_reset_dt_ids),
+};
+
+static int stm32_rcc_reset_init(void)
+{
+ return platform_driver_register(&stm32_rcc_reset_driver);
+}
+postcore_initcall(stm32_rcc_reset_init);
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-07-10 20:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 20:11 [PATCH 1/7] gpio: allow for arch-specific ARCH_NR_GPIOS > 256 Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 2/7] ARM: stm32mp: set CONFIG_ARCH_NR_GPIO = (26 * 16) Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 3/7] ARM: dts: stm32mp157c: correct gpioz id Ahmad Fatoum
2019-07-10 20:11 ` Ahmad Fatoum [this message]
2019-07-10 21:28 ` [PATCH] fixup! reset: add reset controller driver for STM32 RCC Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 5/7] i2c: add stm32f7 I2C adapter driver Ahmad Fatoum
2019-07-12 5:09 ` Sascha Hauer
2019-07-10 20:11 ` [PATCH 6/7] mfd: add support for STPMIC1 Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 7/7] watchdog: add support for STPMIC1 integrated watchdog Ahmad Fatoum
2019-07-15 6:42 ` [PATCH 1/7] gpio: allow for arch-specific ARCH_NR_GPIOS > 256 Sascha Hauer
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=20190710201112.9086-4-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox