Commit 078e7183 authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown

ASoC: wm_adsp: Replace debugfs lock with more general DSP power lock

Most events around the DSP just need to be locked to ensure that the DSP
can't change power state whilst they are happening. This includes the
debugfs entries and this will make sorting the rest of the locking
simpler.
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 04d1300f
...@@ -275,30 +275,24 @@ static void wm_adsp_debugfs_save_wmfwname(struct wm_adsp *dsp, const char *s) ...@@ -275,30 +275,24 @@ static void wm_adsp_debugfs_save_wmfwname(struct wm_adsp *dsp, const char *s)
{ {
char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); char *tmp = kasprintf(GFP_KERNEL, "%s\n", s);
mutex_lock(&dsp->debugfs_lock);
kfree(dsp->wmfw_file_name); kfree(dsp->wmfw_file_name);
dsp->wmfw_file_name = tmp; dsp->wmfw_file_name = tmp;
mutex_unlock(&dsp->debugfs_lock);
} }
static void wm_adsp_debugfs_save_binname(struct wm_adsp *dsp, const char *s) static void wm_adsp_debugfs_save_binname(struct wm_adsp *dsp, const char *s)
{ {
char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); char *tmp = kasprintf(GFP_KERNEL, "%s\n", s);
mutex_lock(&dsp->debugfs_lock);
kfree(dsp->bin_file_name); kfree(dsp->bin_file_name);
dsp->bin_file_name = tmp; dsp->bin_file_name = tmp;
mutex_unlock(&dsp->debugfs_lock);
} }
static void wm_adsp_debugfs_clear(struct wm_adsp *dsp) static void wm_adsp_debugfs_clear(struct wm_adsp *dsp)
{ {
mutex_lock(&dsp->debugfs_lock);
kfree(dsp->wmfw_file_name); kfree(dsp->wmfw_file_name);
kfree(dsp->bin_file_name); kfree(dsp->bin_file_name);
dsp->wmfw_file_name = NULL; dsp->wmfw_file_name = NULL;
dsp->bin_file_name = NULL; dsp->bin_file_name = NULL;
mutex_unlock(&dsp->debugfs_lock);
} }
static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file, static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file,
...@@ -308,7 +302,7 @@ static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file, ...@@ -308,7 +302,7 @@ static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file,
struct wm_adsp *dsp = file->private_data; struct wm_adsp *dsp = file->private_data;
ssize_t ret; ssize_t ret;
mutex_lock(&dsp->debugfs_lock); mutex_lock(&dsp->pwr_lock);
if (!dsp->wmfw_file_name || !dsp->running) if (!dsp->wmfw_file_name || !dsp->running)
ret = 0; ret = 0;
...@@ -317,7 +311,7 @@ static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file, ...@@ -317,7 +311,7 @@ static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file,
dsp->wmfw_file_name, dsp->wmfw_file_name,
strlen(dsp->wmfw_file_name)); strlen(dsp->wmfw_file_name));
mutex_unlock(&dsp->debugfs_lock); mutex_unlock(&dsp->pwr_lock);
return ret; return ret;
} }
...@@ -328,7 +322,7 @@ static ssize_t wm_adsp_debugfs_bin_read(struct file *file, ...@@ -328,7 +322,7 @@ static ssize_t wm_adsp_debugfs_bin_read(struct file *file,
struct wm_adsp *dsp = file->private_data; struct wm_adsp *dsp = file->private_data;
ssize_t ret; ssize_t ret;
mutex_lock(&dsp->debugfs_lock); mutex_lock(&dsp->pwr_lock);
if (!dsp->bin_file_name || !dsp->running) if (!dsp->bin_file_name || !dsp->running)
ret = 0; ret = 0;
...@@ -337,7 +331,7 @@ static ssize_t wm_adsp_debugfs_bin_read(struct file *file, ...@@ -337,7 +331,7 @@ static ssize_t wm_adsp_debugfs_bin_read(struct file *file,
dsp->bin_file_name, dsp->bin_file_name,
strlen(dsp->bin_file_name)); strlen(dsp->bin_file_name));
mutex_unlock(&dsp->debugfs_lock); mutex_unlock(&dsp->pwr_lock);
return ret; return ret;
} }
...@@ -1799,9 +1793,8 @@ int wm_adsp1_init(struct wm_adsp *dsp) ...@@ -1799,9 +1793,8 @@ int wm_adsp1_init(struct wm_adsp *dsp)
{ {
INIT_LIST_HEAD(&dsp->alg_regions); INIT_LIST_HEAD(&dsp->alg_regions);
#ifdef CONFIG_DEBUG_FS mutex_init(&dsp->pwr_lock);
mutex_init(&dsp->debugfs_lock);
#endif
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(wm_adsp1_init); EXPORT_SYMBOL_GPL(wm_adsp1_init);
...@@ -1820,6 +1813,8 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w, ...@@ -1820,6 +1813,8 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
dsp->card = codec->component.card; dsp->card = codec->component.card;
mutex_lock(&dsp->pwr_lock);
switch (event) { switch (event) {
case SND_SOC_DAPM_POST_PMU: case SND_SOC_DAPM_POST_PMU:
regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30,
...@@ -1834,7 +1829,7 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w, ...@@ -1834,7 +1829,7 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
if (ret != 0) { if (ret != 0) {
adsp_err(dsp, "Failed to read SYSCLK state: %d\n", adsp_err(dsp, "Failed to read SYSCLK state: %d\n",
ret); ret);
return ret; goto err_mutex;
} }
val = (val & dsp->sysclk_mask) val = (val & dsp->sysclk_mask)
...@@ -1846,31 +1841,31 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w, ...@@ -1846,31 +1841,31 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
if (ret != 0) { if (ret != 0) {
adsp_err(dsp, "Failed to set clock rate: %d\n", adsp_err(dsp, "Failed to set clock rate: %d\n",
ret); ret);
return ret; goto err_mutex;
} }
} }
ret = wm_adsp_load(dsp); ret = wm_adsp_load(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
ret = wm_adsp1_setup_algs(dsp); ret = wm_adsp1_setup_algs(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
ret = wm_adsp_load_coeff(dsp); ret = wm_adsp_load_coeff(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
/* Initialize caches for enabled and unset controls */ /* Initialize caches for enabled and unset controls */
ret = wm_coeff_init_control_caches(dsp); ret = wm_coeff_init_control_caches(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
/* Sync set controls */ /* Sync set controls */
ret = wm_coeff_sync_controls(dsp); ret = wm_coeff_sync_controls(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
/* Start the core running */ /* Start the core running */
regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30,
...@@ -1905,11 +1900,16 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w, ...@@ -1905,11 +1900,16 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
break; break;
} }
mutex_unlock(&dsp->pwr_lock);
return 0; return 0;
err: err_ena:
regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30,
ADSP1_SYS_ENA, 0); ADSP1_SYS_ENA, 0);
err_mutex:
mutex_unlock(&dsp->pwr_lock);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(wm_adsp1_event); EXPORT_SYMBOL_GPL(wm_adsp1_event);
...@@ -1955,6 +1955,8 @@ static void wm_adsp2_boot_work(struct work_struct *work) ...@@ -1955,6 +1955,8 @@ static void wm_adsp2_boot_work(struct work_struct *work)
int ret; int ret;
unsigned int val; unsigned int val;
mutex_lock(&dsp->pwr_lock);
/* /*
* For simplicity set the DSP clock rate to be the * For simplicity set the DSP clock rate to be the
* SYSCLK rate rather than making it configurable. * SYSCLK rate rather than making it configurable.
...@@ -1962,7 +1964,7 @@ static void wm_adsp2_boot_work(struct work_struct *work) ...@@ -1962,7 +1964,7 @@ static void wm_adsp2_boot_work(struct work_struct *work)
ret = regmap_read(dsp->regmap, ARIZONA_SYSTEM_CLOCK_1, &val); ret = regmap_read(dsp->regmap, ARIZONA_SYSTEM_CLOCK_1, &val);
if (ret != 0) { if (ret != 0) {
adsp_err(dsp, "Failed to read SYSCLK state: %d\n", ret); adsp_err(dsp, "Failed to read SYSCLK state: %d\n", ret);
return; goto err_mutex;
} }
val = (val & ARIZONA_SYSCLK_FREQ_MASK) val = (val & ARIZONA_SYSCLK_FREQ_MASK)
>> ARIZONA_SYSCLK_FREQ_SHIFT; >> ARIZONA_SYSCLK_FREQ_SHIFT;
...@@ -1972,42 +1974,46 @@ static void wm_adsp2_boot_work(struct work_struct *work) ...@@ -1972,42 +1974,46 @@ static void wm_adsp2_boot_work(struct work_struct *work)
ADSP2_CLK_SEL_MASK, val); ADSP2_CLK_SEL_MASK, val);
if (ret != 0) { if (ret != 0) {
adsp_err(dsp, "Failed to set clock rate: %d\n", ret); adsp_err(dsp, "Failed to set clock rate: %d\n", ret);
return; goto err_mutex;
} }
ret = wm_adsp2_ena(dsp); ret = wm_adsp2_ena(dsp);
if (ret != 0) if (ret != 0)
return; goto err_mutex;
ret = wm_adsp_load(dsp); ret = wm_adsp_load(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
ret = wm_adsp2_setup_algs(dsp); ret = wm_adsp2_setup_algs(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
ret = wm_adsp_load_coeff(dsp); ret = wm_adsp_load_coeff(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
/* Initialize caches for enabled and unset controls */ /* Initialize caches for enabled and unset controls */
ret = wm_coeff_init_control_caches(dsp); ret = wm_coeff_init_control_caches(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
/* Sync set controls */ /* Sync set controls */
ret = wm_coeff_sync_controls(dsp); ret = wm_coeff_sync_controls(dsp);
if (ret != 0) if (ret != 0)
goto err; goto err_ena;
dsp->running = true; dsp->running = true;
mutex_unlock(&dsp->pwr_lock);
return; return;
err: err_ena:
regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL,
ADSP2_SYS_ENA | ADSP2_CORE_ENA | ADSP2_START, 0); ADSP2_SYS_ENA | ADSP2_CORE_ENA | ADSP2_START, 0);
err_mutex:
mutex_unlock(&dsp->pwr_lock);
} }
int wm_adsp2_early_event(struct snd_soc_dapm_widget *w, int wm_adsp2_early_event(struct snd_soc_dapm_widget *w,
...@@ -2060,6 +2066,8 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w, ...@@ -2060,6 +2066,8 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
/* Log firmware state, it can be useful for analysis */ /* Log firmware state, it can be useful for analysis */
wm_adsp2_show_fw_status(dsp); wm_adsp2_show_fw_status(dsp);
mutex_lock(&dsp->pwr_lock);
wm_adsp_debugfs_clear(dsp); wm_adsp_debugfs_clear(dsp);
dsp->fw_id = 0; dsp->fw_id = 0;
...@@ -2086,6 +2094,8 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w, ...@@ -2086,6 +2094,8 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
kfree(alg_region); kfree(alg_region);
} }
mutex_unlock(&dsp->pwr_lock);
adsp_dbg(dsp, "Shutdown complete\n"); adsp_dbg(dsp, "Shutdown complete\n");
break; break;
...@@ -2138,9 +2148,8 @@ int wm_adsp2_init(struct wm_adsp *dsp) ...@@ -2138,9 +2148,8 @@ int wm_adsp2_init(struct wm_adsp *dsp)
INIT_LIST_HEAD(&dsp->ctl_list); INIT_LIST_HEAD(&dsp->ctl_list);
INIT_WORK(&dsp->boot_work, wm_adsp2_boot_work); INIT_WORK(&dsp->boot_work, wm_adsp2_boot_work);
#ifdef CONFIG_DEBUG_FS mutex_init(&dsp->pwr_lock);
mutex_init(&dsp->debugfs_lock);
#endif
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(wm_adsp2_init); EXPORT_SYMBOL_GPL(wm_adsp2_init);
......
...@@ -59,9 +59,10 @@ struct wm_adsp { ...@@ -59,9 +59,10 @@ struct wm_adsp {
struct work_struct boot_work; struct work_struct boot_work;
struct mutex pwr_lock;
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
struct dentry *debugfs_root; struct dentry *debugfs_root;
struct mutex debugfs_lock;
char *wmfw_file_name; char *wmfw_file_name;
char *bin_file_name; char *bin_file_name;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment