From 1d2e35e74ec264a153dcd478ce3770bb4fd88a3e Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 28 Oct 2020 15:53:43 +0800 Subject: [PATCH 1/2] soc: qcom: qpnp-pbs: add an API to trigger single PBS event A simple PBS can be triggered by SW writing to SW_TRIGGER (bit 7) in TRIG_CTL register without passing any parameters through SCRATCH1 register and not waiting on any condition. Also, this simple PBS is more like a fire and forget and doesn't even need to check on the status through SCRATCH2 register. Add support for this simple PBS through an API qpnp_pbs_trigger_single_event(). Change-Id: I8a6448f9be8f84269c6ba5672bead01a152185ad Signed-off-by: Fenglin Wu --- drivers/soc/qcom/qpnp-pbs.c | 41 ++++++++++++++++++++++++++++++++++- include/linux/qpnp/qpnp-pbs.h | 11 +++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/soc/qcom/qpnp-pbs.c b/drivers/soc/qcom/qpnp-pbs.c index b28c84141ae7..c9fb002a1851 100644 --- a/drivers/soc/qcom/qpnp-pbs.c +++ b/drivers/soc/qcom/qpnp-pbs.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2018, 2020, The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "PBS: %s: " fmt, __func__ @@ -145,6 +145,45 @@ static int qpnp_pbs_wait_for_ack(struct qpnp_pbs *pbs, u8 bit_pos) return 0; } +/** + * qpnp_pbs_trigger_single_event - trigger PBS sequence which is connected + * directly to SW_TRIGGER bit without using bitmap. + * + * Returns = 0 enable SW_TRIGGER in PBS client successfully. + * + * Returns < 0 for errors. + * + * This function is used to trigger the PBS that is hooked on the + * SW_TRIGGER directly in PBS client. + */ +int qpnp_pbs_trigger_single_event(struct device_node *dev_node) +{ + struct qpnp_pbs *pbs_dev; + int rc; + + if (!dev_node) + return -EINVAL; + + pbs_dev = get_pbs_client_node(dev_node); + if (IS_ERR(pbs_dev)) { + rc = PTR_ERR(pbs_dev); + pr_err("Unable to find the PBS dev_node, rc=%d\n", rc); + return rc; + } + + mutex_lock(&pbs_dev->pbs_lock); + rc = qpnp_pbs_masked_write(pbs_dev, pbs_dev->base + + PBS_CLIENT_TRIG_CTL, PBS_CLIENT_SW_TRIG_BIT, + PBS_CLIENT_SW_TRIG_BIT); + if (rc < 0) + pr_err("Failed to write register %x rc=%d\n", + PBS_CLIENT_TRIG_CTL, rc); + mutex_unlock(&pbs_dev->pbs_lock); + + return rc; +} +EXPORT_SYMBOL(qpnp_pbs_trigger_single_event); + /** * qpnp_pbs_trigger_event - Trigger the PBS RAM sequence * diff --git a/include/linux/qpnp/qpnp-pbs.h b/include/linux/qpnp/qpnp-pbs.h index 771170485c85..7cc0828cbce1 100644 --- a/include/linux/qpnp/qpnp-pbs.h +++ b/include/linux/qpnp/qpnp-pbs.h @@ -13,11 +13,20 @@ struct device_node; #if IS_ENABLED(CONFIG_QPNP_PBS) int qpnp_pbs_trigger_event(struct device_node *dev_node, u8 bitmap); +int qpnp_pbs_trigger_single_event(struct device_node *dev_node); #else static inline int qpnp_pbs_trigger_event(struct device_node *dev_node, - u8 bitmap) { + u8 bitmap) +{ return -ENODEV; } + +static inline int qpnp_pbs_trigger_single_event( + struct device_node *dev_node) +{ + return -ENODEV; +} + #endif #endif From 20a1939587be49c836f68133a1bcc73df7a02407 Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 28 Oct 2020 15:45:56 +0800 Subject: [PATCH 2/2] input: qcom-hv-haptics: switch API to trigger PBS for ISC configuration SW trigger for PBS to configure ISC in LRA detection doesn't need to pass any parameter or wait on any condition including checking status. Hence switch using qpnp_pbs_trigger_single_event() instead of qpnp_pbs_trigger_event() to trigger PBS. Change-Id: I8b252e293265994976924435f8a6a11d9b463119 Signed-off-by: Fenglin Wu --- drivers/input/misc/qcom-hv-haptics.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/input/misc/qcom-hv-haptics.c b/drivers/input/misc/qcom-hv-haptics.c index 9922fe9637e7..0ce698211f8c 100644 --- a/drivers/input/misc/qcom-hv-haptics.c +++ b/drivers/input/misc/qcom-hv-haptics.c @@ -3600,7 +3600,6 @@ static int haptics_init_swr_slave_regulator(struct haptics_chip *chip) return rc; } -#define PBS_SW_TRG_LRA_ISC_CFG_BIT BIT(7) static int haptics_pbs_trigger_isc_config(struct haptics_chip *chip) { int rc; @@ -3610,7 +3609,7 @@ static int haptics_pbs_trigger_isc_config(struct haptics_chip *chip) return -ENODEV; } - rc = qpnp_pbs_trigger_event(chip->pbs_node, PBS_SW_TRG_LRA_ISC_CFG_BIT); + rc = qpnp_pbs_trigger_single_event(chip->pbs_node); if (rc < 0) dev_err(chip->dev, "Trigger PBS to config ISC failed, rc=%d\n", rc);