250 lines
6.9 KiB
Diff
250 lines
6.9 KiB
Diff
From 7f9a7065bc23ee2da17c45ff4097cdbc9b70065d Mon Sep 17 00:00:00 2001
|
|
From: Lionel VITTE <lionel.vitte@st.com>
|
|
Date: Thu, 11 Jul 2019 14:12:00 +0200
|
|
Subject: [PATCH 08/30] ARM stm32mp1 r2 HWSPINLOCK
|
|
|
|
---
|
|
drivers/hwspinlock/Kconfig | 9 ++
|
|
drivers/hwspinlock/Makefile | 1 +
|
|
drivers/hwspinlock/hwspinlock_core.c | 15 ++--
|
|
drivers/hwspinlock/stm32_hwspinlock.c | 164 ++++++++++++++++++++++++++++++++++
|
|
4 files changed, 182 insertions(+), 7 deletions(-)
|
|
create mode 100644 drivers/hwspinlock/stm32_hwspinlock.c
|
|
|
|
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
|
|
index e895d29..7869c67 100644
|
|
--- a/drivers/hwspinlock/Kconfig
|
|
+++ b/drivers/hwspinlock/Kconfig
|
|
@@ -49,6 +49,15 @@ config HWSPINLOCK_SPRD
|
|
|
|
If unsure, say N.
|
|
|
|
+config HWSPINLOCK_STM32
|
|
+ tristate "STM32 Hardware Spinlock device"
|
|
+ depends on MACH_STM32MP157
|
|
+ depends on HWSPINLOCK
|
|
+ help
|
|
+ Say y here to support the STM32 Hardware Spinlock device.
|
|
+
|
|
+ If unsure, say N.
|
|
+
|
|
config HSEM_U8500
|
|
tristate "STE Hardware Semaphore functionality"
|
|
depends on HWSPINLOCK
|
|
diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile
|
|
index b87c01a..ed053e3 100644
|
|
--- a/drivers/hwspinlock/Makefile
|
|
+++ b/drivers/hwspinlock/Makefile
|
|
@@ -8,4 +8,5 @@ obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o
|
|
obj-$(CONFIG_HWSPINLOCK_QCOM) += qcom_hwspinlock.o
|
|
obj-$(CONFIG_HWSPINLOCK_SIRF) += sirf_hwspinlock.o
|
|
obj-$(CONFIG_HWSPINLOCK_SPRD) += sprd_hwspinlock.o
|
|
+obj-$(CONFIG_HWSPINLOCK_STM32) += stm32_hwspinlock.o
|
|
obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o
|
|
diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c
|
|
index 2bad40d..287e1b3 100644
|
|
--- a/drivers/hwspinlock/hwspinlock_core.c
|
|
+++ b/drivers/hwspinlock/hwspinlock_core.c
|
|
@@ -333,6 +333,9 @@ int of_hwspin_lock_get_id(struct device_node *np, int index)
|
|
if (ret)
|
|
return ret;
|
|
|
|
+ if (!of_device_is_available(args.np))
|
|
+ return -ENOENT;
|
|
+
|
|
/* Find the hwspinlock device: we need its base_id */
|
|
ret = -EPROBE_DEFER;
|
|
rcu_read_lock();
|
|
@@ -742,13 +745,11 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id)
|
|
/* sanity check (this shouldn't happen) */
|
|
WARN_ON(hwlock_to_id(hwlock) != id);
|
|
|
|
- /* make sure this hwspinlock is unused */
|
|
- ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED);
|
|
- if (ret == 0) {
|
|
- pr_warn("hwspinlock %u is already in use\n", id);
|
|
- hwlock = NULL;
|
|
- goto out;
|
|
- }
|
|
+ /*
|
|
+ * We intentionally do not check for the HWSPINLOCK_UNUSED tag as
|
|
+ * we want to share HWSPINLOCK between several devices. This is safe
|
|
+ * since the lock/unlock requests are called under &hwlock->lock control
|
|
+ */
|
|
|
|
/* mark as used and power up */
|
|
ret = __hwspin_lock_request(hwlock);
|
|
diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c
|
|
new file mode 100644
|
|
index 0000000..b9b9b99
|
|
--- /dev/null
|
|
+++ b/drivers/hwspinlock/stm32_hwspinlock.c
|
|
@@ -0,0 +1,164 @@
|
|
+// SPDX-License-Identifier: GPL-2.0
|
|
+/*
|
|
+ * Copyright (C) STMicroelectronics SA 2018
|
|
+ * Author: Benjamin Gaignard <benjamin.gaignard@st.com> for STMicroelectronics.
|
|
+ */
|
|
+
|
|
+#include <linux/clk.h>
|
|
+#include <linux/delay.h>
|
|
+#include <linux/hwspinlock.h>
|
|
+#include <linux/io.h>
|
|
+#include <linux/kernel.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/of.h>
|
|
+#include <linux/platform_device.h>
|
|
+#include <linux/pm_runtime.h>
|
|
+
|
|
+#include "hwspinlock_internal.h"
|
|
+
|
|
+#define STM32_MUTEX_COREID BIT(8)
|
|
+#define STM32_MUTEX_LOCK_BIT BIT(31)
|
|
+#define STM32_MUTEX_NUM_LOCKS 32
|
|
+
|
|
+struct stm32_hwspinlock {
|
|
+ struct clk *clk;
|
|
+ struct hwspinlock_device bank;
|
|
+};
|
|
+
|
|
+static int stm32_hwspinlock_trylock(struct hwspinlock *lock)
|
|
+{
|
|
+ void __iomem *lock_addr = lock->priv;
|
|
+ u32 status;
|
|
+
|
|
+ writel(STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID, lock_addr);
|
|
+ status = readl(lock_addr);
|
|
+
|
|
+ return status == (STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID);
|
|
+}
|
|
+
|
|
+static void stm32_hwspinlock_unlock(struct hwspinlock *lock)
|
|
+{
|
|
+ void __iomem *lock_addr = lock->priv;
|
|
+
|
|
+ writel(STM32_MUTEX_COREID, lock_addr);
|
|
+}
|
|
+
|
|
+static void stm32_hwspinlock_relax(struct hwspinlock *lock)
|
|
+{
|
|
+ ndelay(50);
|
|
+}
|
|
+
|
|
+static const struct hwspinlock_ops stm32_hwspinlock_ops = {
|
|
+ .trylock = stm32_hwspinlock_trylock,
|
|
+ .unlock = stm32_hwspinlock_unlock,
|
|
+ .relax = stm32_hwspinlock_relax,
|
|
+};
|
|
+
|
|
+static int stm32_hwspinlock_probe(struct platform_device *pdev)
|
|
+{
|
|
+ struct stm32_hwspinlock *hw;
|
|
+ void __iomem *io_base;
|
|
+ struct resource *res;
|
|
+ size_t array_size;
|
|
+ int i, ret;
|
|
+
|
|
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
+ io_base = devm_ioremap_resource(&pdev->dev, res);
|
|
+ if (!io_base)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ array_size = STM32_MUTEX_NUM_LOCKS * sizeof(struct hwspinlock);
|
|
+ hw = devm_kzalloc(&pdev->dev, sizeof(*hw) + array_size, GFP_KERNEL);
|
|
+ if (!hw)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ hw->clk = devm_clk_get(&pdev->dev, "hsem");
|
|
+ if (IS_ERR(hw->clk))
|
|
+ return PTR_ERR(hw->clk);
|
|
+
|
|
+ for (i = 0; i < STM32_MUTEX_NUM_LOCKS; i++)
|
|
+ hw->bank.lock[i].priv = io_base + i * sizeof(u32);
|
|
+
|
|
+ platform_set_drvdata(pdev, hw);
|
|
+ pm_runtime_enable(&pdev->dev);
|
|
+
|
|
+ ret = hwspin_lock_register(&hw->bank, &pdev->dev, &stm32_hwspinlock_ops,
|
|
+ 0, STM32_MUTEX_NUM_LOCKS);
|
|
+
|
|
+ if (ret)
|
|
+ pm_runtime_disable(&pdev->dev);
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+static int stm32_hwspinlock_remove(struct platform_device *pdev)
|
|
+{
|
|
+ struct stm32_hwspinlock *hw = platform_get_drvdata(pdev);
|
|
+ int ret;
|
|
+
|
|
+ ret = hwspin_lock_unregister(&hw->bank);
|
|
+ if (ret)
|
|
+ dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
|
|
+
|
|
+ pm_runtime_disable(&pdev->dev);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int __maybe_unused stm32_hwspinlock_runtime_suspend(struct device *dev)
|
|
+{
|
|
+ struct stm32_hwspinlock *hw = dev_get_drvdata(dev);
|
|
+
|
|
+ clk_disable_unprepare(hw->clk);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int __maybe_unused stm32_hwspinlock_runtime_resume(struct device *dev)
|
|
+{
|
|
+ struct stm32_hwspinlock *hw = dev_get_drvdata(dev);
|
|
+
|
|
+ clk_prepare_enable(hw->clk);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static const struct dev_pm_ops stm32_hwspinlock_pm_ops = {
|
|
+ SET_RUNTIME_PM_OPS(stm32_hwspinlock_runtime_suspend,
|
|
+ stm32_hwspinlock_runtime_resume,
|
|
+ NULL)
|
|
+};
|
|
+
|
|
+static const struct of_device_id stm32_hwpinlock_ids[] = {
|
|
+ { .compatible = "st,stm32-hwspinlock", },
|
|
+ {},
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, stm32_hwpinlock_ids);
|
|
+
|
|
+static struct platform_driver stm32_hwspinlock_driver = {
|
|
+ .probe = stm32_hwspinlock_probe,
|
|
+ .remove = stm32_hwspinlock_remove,
|
|
+ .driver = {
|
|
+ .name = "stm32_hwspinlock",
|
|
+ .of_match_table = stm32_hwpinlock_ids,
|
|
+ .pm = &stm32_hwspinlock_pm_ops,
|
|
+ },
|
|
+};
|
|
+
|
|
+static int __init stm32_hwspinlock_init(void)
|
|
+{
|
|
+ return platform_driver_register(&stm32_hwspinlock_driver);
|
|
+}
|
|
+
|
|
+/* board init code might need to reserve hwspinlocks for predefined purposes */
|
|
+postcore_initcall(stm32_hwspinlock_init);
|
|
+
|
|
+static void __exit stm32_hwspinlock_exit(void)
|
|
+{
|
|
+ platform_driver_unregister(&stm32_hwspinlock_driver);
|
|
+}
|
|
+module_exit(stm32_hwspinlock_exit);
|
|
+
|
|
+MODULE_LICENSE("GPL v2");
|
|
+MODULE_DESCRIPTION("Hardware spinlock driver for STM32 SoCs");
|
|
+MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
|
|
--
|
|
2.7.4
|
|
|