From 63cd5102a403b5ca68feacf1a02e451c6305e4e3 Mon Sep 17 00:00:00 2001 From: Vidyakumar Athota Date: Wed, 4 Jan 2017 11:46:17 -0800 Subject: [PATCH] drivers: mfd: fix audio mute issue after ADSP SSR Native audio playback is muted after adsp subsystem restart, because codec device_reset() API is called even before device_down() API finishes execution. This causes audio to mute, as codec is not in proper reset state. Add new lock to synchronize codec subsystem restart APIs. Change-Id: I2366f8b04fc6cb7d874661b948c3e9af10470107 Signed-off-by: Vidyakumar Athota --- drivers/mfd/wcd9xxx-core.c | 17 ++++++++++++++++- drivers/mfd/wcd9xxx-irq.c | 3 ++- include/linux/mfd/wcd9xxx/core.h | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/mfd/wcd9xxx-core.c b/drivers/mfd/wcd9xxx-core.c index 54a5e9b1e0d9..f17541bcf74a 100644 --- a/drivers/mfd/wcd9xxx-core.c +++ b/drivers/mfd/wcd9xxx-core.c @@ -505,6 +505,7 @@ static int wcd9xxx_device_init(struct wcd9xxx *wcd9xxx) mutex_init(&wcd9xxx->io_lock); mutex_init(&wcd9xxx->xfer_lock); + mutex_init(&wcd9xxx->reset_lock); ret = wcd9xxx_bringup(wcd9xxx->dev); if (ret) { @@ -583,6 +584,7 @@ err: err_bring_up: mutex_destroy(&wcd9xxx->io_lock); mutex_destroy(&wcd9xxx->xfer_lock); + mutex_destroy(&wcd9xxx->reset_lock); return ret; } @@ -595,6 +597,7 @@ static void wcd9xxx_device_exit(struct wcd9xxx *wcd9xxx) wcd9xxx_core_res_deinit(&wcd9xxx->core_res); mutex_destroy(&wcd9xxx->io_lock); mutex_destroy(&wcd9xxx->xfer_lock); + mutex_destroy(&wcd9xxx->reset_lock); if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) slim_remove_device(wcd9xxx->slim_slave); } @@ -1469,9 +1472,11 @@ static int wcd9xxx_slim_device_reset(struct slim_device *sldev) if (wcd9xxx->dev_up) return 0; + mutex_lock(&wcd9xxx->reset_lock); ret = wcd9xxx_reset(wcd9xxx->dev); if (ret) dev_err(wcd9xxx->dev, "%s: Resetting Codec failed\n", __func__); + mutex_unlock(&wcd9xxx->reset_lock); return ret; } @@ -1479,6 +1484,7 @@ static int wcd9xxx_slim_device_reset(struct slim_device *sldev) static int wcd9xxx_slim_device_up(struct slim_device *sldev) { struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev); + int ret = 0; if (!wcd9xxx) { pr_err("%s: wcd9xxx is NULL\n", __func__); @@ -1490,7 +1496,12 @@ static int wcd9xxx_slim_device_up(struct slim_device *sldev) return 0; wcd9xxx->dev_up = true; - return wcd9xxx_device_up(wcd9xxx); + + mutex_lock(&wcd9xxx->reset_lock); + ret = wcd9xxx_device_up(wcd9xxx); + mutex_unlock(&wcd9xxx->reset_lock); + + return ret; } static int wcd9xxx_slim_device_down(struct slim_device *sldev) @@ -1508,10 +1519,14 @@ static int wcd9xxx_slim_device_down(struct slim_device *sldev) return 0; wcd9xxx->dev_up = false; + + mutex_lock(&wcd9xxx->reset_lock); if (wcd9xxx->dev_down) wcd9xxx->dev_down(wcd9xxx); wcd9xxx_irq_exit(&wcd9xxx->core_res); wcd9xxx_reset_low(wcd9xxx->dev); + mutex_unlock(&wcd9xxx->reset_lock); + return 0; } diff --git a/drivers/mfd/wcd9xxx-irq.c b/drivers/mfd/wcd9xxx-irq.c index b6a476cd882d..a337d1ff8950 100644 --- a/drivers/mfd/wcd9xxx-irq.c +++ b/drivers/mfd/wcd9xxx-irq.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -304,6 +304,7 @@ static irqreturn_t wcd9xxx_irq_thread(int irq, void *data) goto err_disable_irq; } + memset(status, 0, sizeof(status)); ret = regmap_bulk_read(wcd9xxx_res->wcd_core_regmap, wcd9xxx_res->intr_reg[WCD9XXX_INTR_STATUS_BASE], status, num_irq_regs); diff --git a/include/linux/mfd/wcd9xxx/core.h b/include/linux/mfd/wcd9xxx/core.h index 11e8d89c337b..6eb8c1893a53 100644 --- a/include/linux/mfd/wcd9xxx/core.h +++ b/include/linux/mfd/wcd9xxx/core.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -334,6 +334,7 @@ struct wcd9xxx { struct slim_device *slim_slave; struct mutex io_lock; struct mutex xfer_lock; + struct mutex reset_lock; u8 version; int reset_gpio;