BACKPORT: soc: qcom: smp2p_sleepstate: Add support for multiple clients

Created context variables to support multiple clients to
know smp2p sleepstate status.

Change-Id: I145a7077c69c17d5df4451b1009c029dd02fc398
Signed-off-by: Vivek Golani <vgolani@codeaurora.org>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
This commit is contained in:
Vivek Golani 2021-10-08 09:49:15 +05:30 committed by spakkkk
parent 436bdb633e
commit d84e1ef33b

View File

@ -14,9 +14,13 @@
#define PROC_AWAKE_ID 12 /* 12th bit */
#define AWAKE_BIT BIT(PROC_AWAKE_ID)
static struct qcom_smem_state *state;
static struct wakeup_source *notify_ws;
struct smp2p_state {
struct qcom_smem_state *state;
struct notifier_block nb;
};
/**
* sleepstate_pm_notifier() - PM notifier callback function.
* @nb: Pointer to the notifier block.
@ -29,24 +33,21 @@ static struct wakeup_source *notify_ws;
static int sleepstate_pm_notifier(struct notifier_block *nb,
unsigned long event, void *unused)
{
struct smp2p_state *smp2p_info = container_of(nb, struct smp2p_state, nb);
switch (event) {
case PM_SUSPEND_PREPARE:
qcom_smem_state_update_bits(state, AWAKE_BIT, 0);
qcom_smem_state_update_bits(smp2p_info->state, AWAKE_BIT, 0);
break;
case PM_POST_SUSPEND:
qcom_smem_state_update_bits(state, AWAKE_BIT, AWAKE_BIT);
qcom_smem_state_update_bits(smp2p_info->state, AWAKE_BIT, AWAKE_BIT);
break;
}
return NOTIFY_DONE;
}
static struct notifier_block sleepstate_pm_nb = {
.notifier_call = sleepstate_pm_notifier,
.priority = INT_MAX,
};
static irqreturn_t smp2p_sleepstate_handler(int irq, void *ctxt)
{
__pm_wakeup_event(notify_ws, 200);
@ -59,13 +60,21 @@ static int smp2p_sleepstate_probe(struct platform_device *pdev)
int irq;
struct device *dev = &pdev->dev;
struct device_node *node = dev->of_node;
struct smp2p_state *smp2p_info;
state = qcom_smem_state_get(&pdev->dev, NULL, &ret);
if (IS_ERR(state))
return PTR_ERR(state);
qcom_smem_state_update_bits(state, AWAKE_BIT, AWAKE_BIT);
smp2p_info = devm_kzalloc(dev, sizeof(*smp2p_info), GFP_KERNEL);
if (!smp2p_info)
return PTR_ERR(smp2p_info);
ret = register_pm_notifier(&sleepstate_pm_nb);
smp2p_info->state = qcom_smem_state_get(&pdev->dev, NULL, &ret);
if (IS_ERR(smp2p_info->state))
return PTR_ERR(smp2p_info->state);
qcom_smem_state_update_bits(smp2p_info->state, AWAKE_BIT, AWAKE_BIT);
smp2p_info->nb.notifier_call = sleepstate_pm_notifier;
smp2p_info->nb.priority = INT_MAX;
ret = register_pm_notifier(&smp2p_info->nb);
if (ret) {
dev_err(dev, "%s: power state notif error %d\n", __func__, ret);
return ret;
@ -96,7 +105,7 @@ static int smp2p_sleepstate_probe(struct platform_device *pdev)
err:
wakeup_source_unregister(notify_ws);
err_ws:
unregister_pm_notifier(&sleepstate_pm_nb);
unregister_pm_notifier(&smp2p_info->nb);
return ret;
}