Skip to content

Commit 08535cc

Browse files
ffainellivireshk
authored andcommitted
cpufreq: brcmstb-avs-cpufreq: Support polling AVS firmware
In case the interrupt towards the host is never raised, yet the AVS firmware responds correctly within the alloted time, allow supporting a polling mode. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Markus Mayer <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent b75acfb commit 08535cc

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

drivers/cpufreq/brcmstb-avs-cpufreq.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
*/
4343

4444
#include <linux/cpufreq.h>
45+
#include <linux/delay.h>
4546
#include <linux/interrupt.h>
4647
#include <linux/io.h>
4748
#include <linux/module.h>
@@ -178,6 +179,7 @@ struct private_data {
178179
struct completion done;
179180
struct semaphore sem;
180181
struct pmap pmap;
182+
int host_irq;
181183
};
182184

183185
static void __iomem *__map_region(const char *name)
@@ -195,12 +197,36 @@ static void __iomem *__map_region(const char *name)
195197
return ptr;
196198
}
197199

200+
static unsigned long wait_for_avs_command(struct private_data *priv,
201+
unsigned long timeout)
202+
{
203+
unsigned long time_left = 0;
204+
u32 val;
205+
206+
/* Event driven, wait for the command interrupt */
207+
if (priv->host_irq >= 0)
208+
return wait_for_completion_timeout(&priv->done,
209+
msecs_to_jiffies(timeout));
210+
211+
/* Polling for command completion */
212+
do {
213+
time_left = timeout;
214+
val = readl(priv->base + AVS_MBOX_STATUS);
215+
if (val)
216+
break;
217+
218+
usleep_range(1000, 2000);
219+
} while (--timeout);
220+
221+
return time_left;
222+
}
223+
198224
static int __issue_avs_command(struct private_data *priv, unsigned int cmd,
199225
unsigned int num_in, unsigned int num_out,
200226
u32 args[])
201227
{
202-
unsigned long time_left = msecs_to_jiffies(AVS_TIMEOUT);
203228
void __iomem *base = priv->base;
229+
unsigned long time_left;
204230
unsigned int i;
205231
int ret;
206232
u32 val;
@@ -238,7 +264,7 @@ static int __issue_avs_command(struct private_data *priv, unsigned int cmd,
238264
writel(AVS_CPU_L2_INT_MASK, priv->avs_intr_base + AVS_CPU_L2_SET0);
239265

240266
/* Wait for AVS co-processor to finish processing the command. */
241-
time_left = wait_for_completion_timeout(&priv->done, time_left);
267+
time_left = wait_for_avs_command(priv, AVS_TIMEOUT);
242268

243269
/*
244270
* If the AVS status is not in the expected range, it means AVS didn't
@@ -509,7 +535,7 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
509535
{
510536
struct private_data *priv;
511537
struct device *dev;
512-
int host_irq, ret;
538+
int ret;
513539

514540
dev = &pdev->dev;
515541
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -536,19 +562,14 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
536562
goto unmap_base;
537563
}
538564

539-
host_irq = platform_get_irq_byname(pdev, BRCM_AVS_HOST_INTR);
540-
if (host_irq < 0) {
541-
dev_err(dev, "Couldn't find interrupt %s -- %d\n",
542-
BRCM_AVS_HOST_INTR, host_irq);
543-
ret = host_irq;
544-
goto unmap_intr_base;
545-
}
565+
priv->host_irq = platform_get_irq_byname(pdev, BRCM_AVS_HOST_INTR);
546566

547-
ret = devm_request_irq(dev, host_irq, irq_handler, IRQF_TRIGGER_RISING,
567+
ret = devm_request_irq(dev, priv->host_irq, irq_handler,
568+
IRQF_TRIGGER_RISING,
548569
BRCM_AVS_HOST_INTR, priv);
549-
if (ret) {
570+
if (ret && priv->host_irq >= 0) {
550571
dev_err(dev, "IRQ request failed: %s (%d) -- %d\n",
551-
BRCM_AVS_HOST_INTR, host_irq, ret);
572+
BRCM_AVS_HOST_INTR, priv->host_irq, ret);
552573
goto unmap_intr_base;
553574
}
554575

0 commit comments

Comments
 (0)