Skip to content

Commit dc7adea

Browse files
committed
ASoC: SOF: Introduce a macro to set the firmware state
Add sof_set_fw_state() macro to wrap the sdev->fw_state management to allow actions to be taken when certain state is set or when state is changing. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent e52de07 commit dc7adea

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

sound/soc/sof/core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
147147
return ret;
148148
}
149149

150-
sdev->fw_state = SOF_FW_BOOT_PREPARE;
150+
sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
151151

152152
/* check machine info */
153153
ret = sof_machine_check(sdev);
@@ -189,7 +189,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
189189
goto fw_load_err;
190190
}
191191

192-
sdev->fw_state = SOF_FW_BOOT_IN_PROGRESS;
192+
sof_set_fw_state(sdev, SOF_FW_BOOT_IN_PROGRESS);
193193

194194
/*
195195
* Boot the firmware. The FW boot status will be modified
@@ -265,7 +265,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
265265
snd_sof_remove(sdev);
266266

267267
/* all resources freed, update state to match */
268-
sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;
268+
sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
269269
sdev->first_boot = true;
270270

271271
return ret;
@@ -300,7 +300,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
300300

301301
sdev->pdata = plat_data;
302302
sdev->first_boot = true;
303-
sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;
303+
sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
304304
#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
305305
sdev->extractor_stream_tag = SOF_PROBE_INVALID_NODE_ID;
306306
#endif

sound/soc/sof/ipc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
452452
if (sdev->fw_state == SOF_FW_BOOT_IN_PROGRESS) {
453453
err = sof_ops(sdev)->fw_ready(sdev, cmd);
454454
if (err < 0)
455-
sdev->fw_state = SOF_FW_BOOT_READY_FAILED;
455+
sof_set_fw_state(sdev, SOF_FW_BOOT_READY_FAILED);
456456
else
457-
sdev->fw_state = SOF_FW_BOOT_COMPLETE;
457+
sof_set_fw_state(sdev, SOF_FW_BOOT_COMPLETE);
458458

459459
/* wake up firmware loader */
460460
wake_up(&sdev->boot_wait);

sound/soc/sof/loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ int snd_sof_run_firmware(struct snd_sof_dev *sdev)
839839
dev_err(sdev->dev, "error: firmware boot failure\n");
840840
snd_sof_dsp_dbg_dump(sdev, SOF_DBG_DUMP_REGS | SOF_DBG_DUMP_MBOX |
841841
SOF_DBG_DUMP_TEXT | SOF_DBG_DUMP_PCI);
842-
sdev->fw_state = SOF_FW_BOOT_FAILED;
842+
sof_set_fw_state(sdev, SOF_FW_BOOT_FAILED);
843843
return -EIO;
844844
}
845845

sound/soc/sof/pm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int sof_resume(struct device *dev, bool runtime_resume)
122122
old_state == SOF_DSP_PM_D0)
123123
return 0;
124124

125-
sdev->fw_state = SOF_FW_BOOT_PREPARE;
125+
sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
126126

127127
/* load the firmware */
128128
ret = snd_sof_load_firmware(sdev);
@@ -133,7 +133,7 @@ static int sof_resume(struct device *dev, bool runtime_resume)
133133
return ret;
134134
}
135135

136-
sdev->fw_state = SOF_FW_BOOT_IN_PROGRESS;
136+
sof_set_fw_state(sdev, SOF_FW_BOOT_IN_PROGRESS);
137137

138138
/*
139139
* Boot the firmware. The FW boot status will be modified
@@ -257,7 +257,7 @@ static int sof_suspend(struct device *dev, bool runtime_suspend)
257257
return ret;
258258

259259
/* reset FW state */
260-
sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;
260+
sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
261261
sdev->enabled_cores_mask = 0;
262262

263263
return ret;

sound/soc/sof/sof-priv.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,19 @@ static inline void sof_oops(struct snd_sof_dev *sdev, void *oops)
577577

578578
extern const struct dsp_arch_ops sof_xtensa_arch_ops;
579579

580+
/*
581+
* Firmware state tracking
582+
*/
583+
static inline void sof_set_fw_state(struct snd_sof_dev *sdev,
584+
enum snd_sof_fw_state new_state)
585+
{
586+
if (sdev->fw_state == new_state)
587+
return;
588+
589+
dev_dbg(sdev->dev, "New firmware state: %d\n", new_state);
590+
sdev->fw_state = new_state;
591+
}
592+
580593
/*
581594
* Utilities
582595
*/

0 commit comments

Comments
 (0)