From 19856a07e5fd25821084b6b8d9ef177d21909483 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Thu, 8 Feb 2024 10:51:11 -0600 Subject: hwspinlock: omap: Remove unneeded check for OF node We do not use the OF node anymore, nor does it matter how we got to probe, so remove the check for of_node. Signed-off-by: Andrew Davis Link: https://lore.kernel.org/r/20240208165114.63148-1-afd@ti.com Signed-off-by: Bjorn Andersson --- drivers/hwspinlock/omap_hwspinlock.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index a9fd9ca45f2a89..cca55143d24d4b 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -74,7 +74,6 @@ static const struct hwspinlock_ops omap_hwspinlock_ops = { static int omap_hwspinlock_probe(struct platform_device *pdev) { - struct device_node *node = pdev->dev.of_node; struct hwspinlock_device *bank; struct hwspinlock *hwlock; void __iomem *io_base; @@ -82,9 +81,6 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) /* Only a single hwspinlock block device is supported */ int base_id = 0; - if (!node) - return -ENODEV; - io_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(io_base)) return PTR_ERR(io_base); -- cgit 1.2.3-korg From 25f7d74d451484fc09772fc276b161d1a6bc64b6 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Thu, 8 Feb 2024 10:51:12 -0600 Subject: hwspinlock: omap: Use devm_pm_runtime_enable() helper This disables runtime PM on module exit automatically for us, currently we manually disable runtime PM which can be error-prone if not done in the right order or missed in some exit path. This also allows us to simplify the probe exit path and remove callbacks. Do that here. While here, as we can now return right after registering our hwspinlock, simply return directly and remove the extra debug message. Signed-off-by: Andrew Davis Link: https://lore.kernel.org/r/20240208165114.63148-2-afd@ti.com Signed-off-by: Bjorn Andersson --- drivers/hwspinlock/omap_hwspinlock.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index cca55143d24d4b..3bd3ffab92100b 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -89,10 +89,10 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) * make sure the module is enabled and clocked before reading * the module SYSSTATUS register */ - pm_runtime_enable(&pdev->dev); + devm_pm_runtime_enable(&pdev->dev); ret = pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) - goto runtime_err; + return ret; /* Determine number of locks */ i = readl(io_base + SYSSTATUS_OFFSET); @@ -104,41 +104,26 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) */ ret = pm_runtime_put(&pdev->dev); if (ret < 0) - goto runtime_err; + return ret; /* one of the four lsb's must be set, and nothing else */ - if (hweight_long(i & 0xf) != 1 || i > 8) { - ret = -EINVAL; - goto runtime_err; - } + if (hweight_long(i & 0xf) != 1 || i > 8) + return -EINVAL; num_locks = i * 32; /* actual number of locks in this device */ bank = devm_kzalloc(&pdev->dev, struct_size(bank, lock, num_locks), GFP_KERNEL); - if (!bank) { - ret = -ENOMEM; - goto runtime_err; - } + if (!bank) + return -ENOMEM; platform_set_drvdata(pdev, bank); for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++) hwlock->priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i; - ret = hwspin_lock_register(bank, &pdev->dev, &omap_hwspinlock_ops, + return hwspin_lock_register(bank, &pdev->dev, &omap_hwspinlock_ops, base_id, num_locks); - if (ret) - goto runtime_err; - - dev_dbg(&pdev->dev, "Registered %d locks with HwSpinlock core\n", - num_locks); - - return 0; - -runtime_err: - pm_runtime_disable(&pdev->dev); - return ret; } static void omap_hwspinlock_remove(struct platform_device *pdev) @@ -151,8 +136,6 @@ static void omap_hwspinlock_remove(struct platform_device *pdev) dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret); return; } - - pm_runtime_disable(&pdev->dev); } static const struct of_device_id omap_hwspinlock_of_match[] = { -- cgit 1.2.3-korg From 8781ec87795a8812b22579ba7ccdc0fdc16ba003 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Thu, 8 Feb 2024 10:51:13 -0600 Subject: hwspinlock: omap: Use devm_hwspin_lock_register() helper This will unregister the HW spinlock on module exit automatically for us, currently we manually unregister which can be error-prone if not done in the right order. This also allows us to remove the remove callback. Do that here. Signed-off-by: Andrew Davis Link: https://lore.kernel.org/r/20240208165114.63148-3-afd@ti.com Signed-off-by: Bjorn Andersson --- drivers/hwspinlock/omap_hwspinlock.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index 3bd3ffab92100b..fe73da80018b11 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -117,27 +117,13 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) if (!bank) return -ENOMEM; - platform_set_drvdata(pdev, bank); - for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++) hwlock->priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i; - return hwspin_lock_register(bank, &pdev->dev, &omap_hwspinlock_ops, + return devm_hwspin_lock_register(&pdev->dev, bank, &omap_hwspinlock_ops, base_id, num_locks); } -static void omap_hwspinlock_remove(struct platform_device *pdev) -{ - struct hwspinlock_device *bank = platform_get_drvdata(pdev); - int ret; - - ret = hwspin_lock_unregister(bank); - if (ret) { - dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret); - return; - } -} - static const struct of_device_id omap_hwspinlock_of_match[] = { { .compatible = "ti,omap4-hwspinlock", }, { .compatible = "ti,am64-hwspinlock", }, @@ -148,7 +134,6 @@ MODULE_DEVICE_TABLE(of, omap_hwspinlock_of_match); static struct platform_driver omap_hwspinlock_driver = { .probe = omap_hwspinlock_probe, - .remove_new = omap_hwspinlock_remove, .driver = { .name = "omap_hwspinlock", .of_match_table = omap_hwspinlock_of_match, -- cgit 1.2.3-korg From cebaa386d5ee1a44a58c12f1d220f62cc567fdb0 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Thu, 8 Feb 2024 10:51:14 -0600 Subject: hwspinlock: omap: Use index to get hwspinlock pointer For loops with multiple initializers and increments are hard to read and reason about, simplify this by using the looping index to index into the hwspinlock array. Signed-off-by: Andrew Davis Link: https://lore.kernel.org/r/20240208165114.63148-4-afd@ti.com Signed-off-by: Bjorn Andersson --- drivers/hwspinlock/omap_hwspinlock.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index fe73da80018b11..27b47b8623c09c 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -75,7 +75,6 @@ static const struct hwspinlock_ops omap_hwspinlock_ops = { static int omap_hwspinlock_probe(struct platform_device *pdev) { struct hwspinlock_device *bank; - struct hwspinlock *hwlock; void __iomem *io_base; int num_locks, i, ret; /* Only a single hwspinlock block device is supported */ @@ -117,8 +116,8 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) if (!bank) return -ENOMEM; - for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++) - hwlock->priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i; + for (i = 0; i < num_locks; i++) + bank->lock[i].priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i; return devm_hwspin_lock_register(&pdev->dev, bank, &omap_hwspinlock_ops, base_id, num_locks); -- cgit 1.2.3-korg