From f13a8268c1ea4a52aedbd2da60c050cff61cc022 Mon Sep 17 00:00:00 2001 From: David Collins Date: Thu, 20 Apr 2017 16:34:46 -0700 Subject: [PATCH 1/3] spmi: spmi-pmic-arb-debug: add clock management support Add support to enable and disable the clock used by the SPMI PMIC arbiter debug bus. This is needed to avoid unclocked accesses. Change-Id: If9eee1317a88c143452d8b46b89aff89d1e956b7 Signed-off-by: David Collins --- drivers/spmi/spmi-pmic-arb-debug.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/spmi/spmi-pmic-arb-debug.c b/drivers/spmi/spmi-pmic-arb-debug.c index ba3fe4010ce2..a5d77ea9f424 100644 --- a/drivers/spmi/spmi-pmic-arb-debug.c +++ b/drivers/spmi/spmi-pmic-arb-debug.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. */ +#include #include #include #include @@ -59,6 +60,7 @@ enum pmic_arb_cmd_op_code { struct spmi_pmic_arb_debug { void __iomem *addr; raw_spinlock_t lock; + struct clk *clock; }; static inline void pmic_arb_debug_write(struct spmi_pmic_arb_debug *pa, @@ -171,6 +173,12 @@ static int pmic_arb_debug_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, else return -EINVAL; + rc = clk_prepare_enable(pa->clock); + if (rc) { + pr_err("%s: failed to enable core clock, rc=%d\n", + __func__, rc); + return rc; + } raw_spin_lock_irqsave(&pa->lock, flags); rc = pmic_arb_debug_issue_command(ctrl, opc, sid, addr, len); @@ -182,6 +190,7 @@ static int pmic_arb_debug_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, buf[i] = pmic_arb_debug_read(pa, PMIC_ARB_DEBUG_RDATA(i)); done: raw_spin_unlock_irqrestore(&pa->lock, flags); + clk_disable_unprepare(pa->clock); return rc; } @@ -211,6 +220,12 @@ static int pmic_arb_debug_write_cmd(struct spmi_controller *ctrl, u8 opc, else return -EINVAL; + rc = clk_prepare_enable(pa->clock); + if (rc) { + pr_err("%s: failed to enable core clock, rc=%d\n", + __func__, rc); + return rc; + } raw_spin_lock_irqsave(&pa->lock, flags); /* Write data to FIFO */ @@ -220,6 +235,7 @@ static int pmic_arb_debug_write_cmd(struct spmi_controller *ctrl, u8 opc, rc = pmic_arb_debug_issue_command(ctrl, opc, sid, addr, len); raw_spin_unlock_irqrestore(&pa->lock, flags); + clk_disable_unprepare(pa->clock); return rc; } @@ -283,6 +299,17 @@ static int spmi_pmic_arb_debug_probe(struct platform_device *pdev) goto err_put_ctrl; } + if (of_find_property(pdev->dev.of_node, "clock-names", NULL)) { + pa->clock = devm_clk_get(&pdev->dev, "core_clk"); + if (IS_ERR(pa->clock)) { + rc = PTR_ERR(pa->clock); + if (rc != -EPROBE_DEFER) + dev_err(&pdev->dev, "unable to request core clock, rc=%d\n", + rc); + goto err_put_ctrl; + } + } + platform_set_drvdata(pdev, ctrl); raw_spin_lock_init(&pa->lock); From a3c59b8c160fbcbe750c28b1cbeb36c85dc5b0c1 Mon Sep 17 00:00:00 2001 From: Subbaraman Narayanamurthy Date: Wed, 27 Jun 2018 17:32:38 -0700 Subject: [PATCH 2/3] spmi: spmi-pmic-arb-debug: Change the probe init order Currently, both the regular and debug spmi pmic arbiter devices are probed in the same initcall order (arch_init). This is fine. However, most of the sepolicy rules set in the userspace are for the PMIC devices under spmi-0 bus. If the debug spmi pmic arbiter device probes first and takes "spmi-0" name, then the sepolicy rules set will be broken. Fix it by changing the probe init order of debug spmi pmic arbiter device to module init. Change-Id: I145e78a205bc80f274d8d926353a88255a7f4167 Signed-off-by: Subbaraman Narayanamurthy --- drivers/spmi/spmi-pmic-arb-debug.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb-debug.c b/drivers/spmi/spmi-pmic-arb-debug.c index a5d77ea9f424..1c5240a2c0c8 100644 --- a/drivers/spmi/spmi-pmic-arb-debug.c +++ b/drivers/spmi/spmi-pmic-arb-debug.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. */ #include #include @@ -355,17 +355,7 @@ static struct platform_driver spmi_pmic_arb_debug_driver = { }, }; -int __init spmi_pmic_arb_debug_init(void) -{ - return platform_driver_register(&spmi_pmic_arb_debug_driver); -} -arch_initcall(spmi_pmic_arb_debug_init); - -static void __exit spmi_pmic_arb_debug_exit(void) -{ - platform_driver_unregister(&spmi_pmic_arb_debug_driver); -} -module_exit(spmi_pmic_arb_debug_exit); +module_platform_driver(spmi_pmic_arb_debug_driver); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:spmi_pmic_arb_debug"); From 2b37abe39681a38bbcabcb8d94dd882919f0b3f0 Mon Sep 17 00:00:00 2001 From: David Collins Date: Thu, 19 Nov 2020 13:38:59 -0800 Subject: [PATCH 3/3] spmi: spmi-pmic-arb-debug: add support for fuse enable bit Add support for detecting a fuse bit that enables instead of disables SPMI PMIC arbiter debug bus hardware. Change-Id: Ia5190c1cc53a8f65ea83294dafd0ddc8861293ba Signed-off-by: David Collins --- drivers/spmi/spmi-pmic-arb-debug.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb-debug.c b/drivers/spmi/spmi-pmic-arb-debug.c index 1c5240a2c0c8..b600b2541b3d 100644 --- a/drivers/spmi/spmi-pmic-arb-debug.c +++ b/drivers/spmi/spmi-pmic-arb-debug.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2012-2018, 2020, The Linux Foundation. All rights reserved. */ #include #include @@ -248,13 +248,21 @@ static int spmi_pmic_arb_debug_probe(struct platform_device *pdev) int rc; u32 fuse_val, fuse_bit; void __iomem *fuse_addr; + bool is_disable_fuse = true; - /* Check if the debug bus is disabled by a fuse. */ + /* Check if the debug bus is enabled or disabled by a fuse. */ rc = of_property_read_u32(pdev->dev.of_node, "qcom,fuse-disable-bit", &fuse_bit); + if (rc) { + is_disable_fuse = false; + rc = of_property_read_u32(pdev->dev.of_node, + "qcom,fuse-enable-bit", + &fuse_bit); + } if (!rc) { if (fuse_bit > 31) { - dev_err(&pdev->dev, "qcom,fuse-disable-bit supports values 0 to 31, but %u specified\n", + dev_err(&pdev->dev, "qcom,fuse-%s-bit supports values 0 to 31, but %u specified\n", + is_disable_fuse ? "disable" : "enable", fuse_bit); return -EINVAL; } @@ -273,7 +281,7 @@ static int spmi_pmic_arb_debug_probe(struct platform_device *pdev) fuse_val = readl_relaxed(fuse_addr); iounmap(fuse_addr); - if (fuse_val & BIT(fuse_bit)) { + if (!!(fuse_val & BIT(fuse_bit)) == is_disable_fuse) { dev_err(&pdev->dev, "SPMI PMIC arbiter debug bus disabled by fuse\n"); return -ENODEV; }