summaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-04-16 18:40:42 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-04-16 18:40:42 +0200
commit32a48332753ac141998197f9f0e9c99d0d855102 (patch)
tree458d76d9917dc6640f0d0f53e718c4b12cd95242 /drivers/mfd
parentddc3394069ab2e43e64b3f0c2465a3fb3069a970 (diff)
parentb2cd220105a6bd03ff819a99ce0c3c853a6d00f3 (diff)
downloadbarebox-32a48332753ac141998197f9f0e9c99d0d855102.tar.gz
barebox-32a48332753ac141998197f9f0e9c99d0d855102.tar.xz
Merge branch 'for-next/pwm'
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/Kconfig7
-rw-r--r--drivers/mfd/Makefile1
-rw-r--r--drivers/mfd/stm32-timers.c74
3 files changed, 82 insertions, 0 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 412ec926c8..32a2c661fc 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -82,4 +82,11 @@ config SMSC_SUPERIO
help
Select this to probe for IO-port connected SMSC Super I/O chips.
+config MFD_STM32_TIMERS
+ bool "STM32 Timers"
+ depends on ARCH_STM32MP
+ help
+ Select this to get regmap support for the timer blocks on STM32
+ MCUs and MPUs.
+
endmenu
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 0c24493e3d..a3b296a803 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_MFD_STPMIC1) += stpmic1.o
obj-$(CONFIG_MFD_SUPERIO) += superio.o
obj-$(CONFIG_FINTEK_SUPERIO) += fintek-superio.o
obj-$(CONFIG_SMSC_SUPERIO) += smsc-superio.o
+obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o
diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
new file mode 100644
index 0000000000..c53a25687e
--- /dev/null
+++ b/drivers/mfd/stm32-timers.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) STMicroelectronics 2016
+ * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
+ */
+
+#include <common.h>
+#include <linux/clk.h>
+#include <driver.h>
+#include <init.h>
+#include <io.h>
+#include <linux/bitfield.h>
+#include <linux/mfd/stm32-timers.h>
+#include <of.h>
+#include <linux/reset.h>
+
+#define STM32_TIMERS_MAX_REGISTERS 0x3fc
+
+static const struct regmap_config stm32_timers_regmap_cfg = {
+ .reg_bits = 32,
+ .val_bits = 32,
+ .reg_stride = sizeof(u32),
+ .max_register = STM32_TIMERS_MAX_REGISTERS,
+};
+
+static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
+{
+ /*
+ * Only the available bits will be written so when readback
+ * we get the maximum value of auto reload register
+ */
+ regmap_write(ddata->regmap, TIM_ARR, ~0L);
+ regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr);
+ regmap_write(ddata->regmap, TIM_ARR, 0x0);
+}
+
+static int stm32_timers_probe(struct device_d *dev)
+{
+ struct stm32_timers *ddata;
+ struct resource *res;
+
+ ddata = xzalloc(sizeof(*ddata));
+
+ res = dev_request_mem_resource(dev, 0);
+ if (IS_ERR(res))
+ return PTR_ERR(res);
+
+ ddata->regmap = regmap_init_mmio_clk(dev, "int", IOMEM(res->start),
+ &stm32_timers_regmap_cfg);
+ if (IS_ERR(ddata->regmap))
+ return PTR_ERR(ddata->regmap);
+
+ ddata->clk = clk_get(dev, NULL);
+ if (IS_ERR(ddata->clk))
+ return PTR_ERR(ddata->clk);
+
+ stm32_timers_get_arr_size(ddata);
+
+ dev->priv = ddata;
+
+ return of_platform_populate(dev->device_node, NULL, dev);
+}
+
+static const struct of_device_id stm32_timers_of_match[] = {
+ { .compatible = "st,stm32-timers", },
+ { /* sentinel */ },
+};
+
+static struct driver_d stm32_timers_driver = {
+ .name = "stm32-timers",
+ .probe = stm32_timers_probe,
+ .of_compatible = stm32_timers_of_match,
+};
+coredevice_platform_driver(stm32_timers_driver);