Skip to content

Commit 39b419e

Browse files
committed
Merge tag 'hwlock-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux
Pull hwspinlock updates from Bjorn Andersson: "This contains a change to the stm32 hwspinlock driver to ensure that the hardware is operational even without CONFIG_PM" * tag 'hwlock-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux: hwspinlock: stm32: enable clock at probe
2 parents 9961315 + 6063092 commit 39b419e

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

drivers/hwspinlock/stm32_hwspinlock.c

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,23 @@ static const struct hwspinlock_ops stm32_hwspinlock_ops = {
5454
.relax = stm32_hwspinlock_relax,
5555
};
5656

57+
static void stm32_hwspinlock_disable_clk(void *data)
58+
{
59+
struct platform_device *pdev = data;
60+
struct stm32_hwspinlock *hw = platform_get_drvdata(pdev);
61+
struct device *dev = &pdev->dev;
62+
63+
pm_runtime_get_sync(dev);
64+
pm_runtime_disable(dev);
65+
pm_runtime_set_suspended(dev);
66+
pm_runtime_put_noidle(dev);
67+
68+
clk_disable_unprepare(hw->clk);
69+
}
70+
5771
static int stm32_hwspinlock_probe(struct platform_device *pdev)
5872
{
73+
struct device *dev = &pdev->dev;
5974
struct stm32_hwspinlock *hw;
6075
void __iomem *io_base;
6176
size_t array_size;
@@ -66,41 +81,43 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev)
6681
return PTR_ERR(io_base);
6782

6883
array_size = STM32_MUTEX_NUM_LOCKS * sizeof(struct hwspinlock);
69-
hw = devm_kzalloc(&pdev->dev, sizeof(*hw) + array_size, GFP_KERNEL);
84+
hw = devm_kzalloc(dev, sizeof(*hw) + array_size, GFP_KERNEL);
7085
if (!hw)
7186
return -ENOMEM;
7287

73-
hw->clk = devm_clk_get(&pdev->dev, "hsem");
88+
hw->clk = devm_clk_get(dev, "hsem");
7489
if (IS_ERR(hw->clk))
7590
return PTR_ERR(hw->clk);
7691

77-
for (i = 0; i < STM32_MUTEX_NUM_LOCKS; i++)
78-
hw->bank.lock[i].priv = io_base + i * sizeof(u32);
92+
ret = clk_prepare_enable(hw->clk);
93+
if (ret) {
94+
dev_err(dev, "Failed to prepare_enable clock\n");
95+
return ret;
96+
}
7997

8098
platform_set_drvdata(pdev, hw);
81-
pm_runtime_enable(&pdev->dev);
8299

83-
ret = hwspin_lock_register(&hw->bank, &pdev->dev, &stm32_hwspinlock_ops,
84-
0, STM32_MUTEX_NUM_LOCKS);
100+
pm_runtime_get_noresume(dev);
101+
pm_runtime_set_active(dev);
102+
pm_runtime_enable(dev);
103+
pm_runtime_put(dev);
85104

86-
if (ret)
87-
pm_runtime_disable(&pdev->dev);
105+
ret = devm_add_action_or_reset(dev, stm32_hwspinlock_disable_clk, pdev);
106+
if (ret) {
107+
dev_err(dev, "Failed to register action\n");
108+
return ret;
109+
}
88110

89-
return ret;
90-
}
111+
for (i = 0; i < STM32_MUTEX_NUM_LOCKS; i++)
112+
hw->bank.lock[i].priv = io_base + i * sizeof(u32);
91113

92-
static int stm32_hwspinlock_remove(struct platform_device *pdev)
93-
{
94-
struct stm32_hwspinlock *hw = platform_get_drvdata(pdev);
95-
int ret;
114+
ret = devm_hwspin_lock_register(dev, &hw->bank, &stm32_hwspinlock_ops,
115+
0, STM32_MUTEX_NUM_LOCKS);
96116

97-
ret = hwspin_lock_unregister(&hw->bank);
98117
if (ret)
99-
dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
100-
101-
pm_runtime_disable(&pdev->dev);
118+
dev_err(dev, "Failed to register hwspinlock\n");
102119

103-
return 0;
120+
return ret;
104121
}
105122

106123
static int __maybe_unused stm32_hwspinlock_runtime_suspend(struct device *dev)
@@ -135,7 +152,6 @@ MODULE_DEVICE_TABLE(of, stm32_hwpinlock_ids);
135152

136153
static struct platform_driver stm32_hwspinlock_driver = {
137154
.probe = stm32_hwspinlock_probe,
138-
.remove = stm32_hwspinlock_remove,
139155
.driver = {
140156
.name = "stm32_hwspinlock",
141157
.of_match_table = stm32_hwpinlock_ids,

0 commit comments

Comments
 (0)