ASoC: Intel: catpt: Code cleanup and renames

Cezary Rojewski <cezary.rojewski@intel.com> says:

Direct follow up to the cleanup from June [1] and fixes from May [2].
Patches 4/8 and 5/8 is what I actually started with, several years ago
when doing first attempts in addressing the long-standing problem [3].
With these, it is easy for a developer to move between the driver and
the firmware repository.  A clear example of why naming is imporant.

Patches 2-8 carry no functional impact.
Patch 1/8 slightly alters the suspend procedure as explained in its
commit message.  From practical perspective though, 1/8 too has no real
impact on the functional flow.

Changes found here reduce the code complexity slightly and rename a
bunch of functions and variables.

[1]: https://lore.kernel.org/all/20260603085827.1964796-1-cezary.rojewski@intel.com/
[2]: https://lore.kernel.org/linux-sound/20260528083444.1439233-1-cezary.rojewski@intel.com/
[3]: https://lore.kernel.org/linux-sound/20260528083444.1439233-2-cezary.rojewski@intel.com/

Link: https://patch.msgid.link/20260729110057.342447-1-cezary.rojewski@intel.com
This commit is contained in:
Mark Brown 2026-07-30 22:30:58 +01:00
commit cd88e3d3e1
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
4 changed files with 106 additions and 109 deletions

View File

@ -139,9 +139,7 @@ int catpt_dsp_send_msg(struct catpt_dev *cdev, struct catpt_ipc_msg request,
int catpt_first_boot_firmware(struct catpt_dev *cdev);
int catpt_boot_firmware(struct catpt_dev *cdev, bool restore);
int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan);
int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan);
int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan);
int catpt_store_firmware_context(struct catpt_dev *cdev);
int catpt_coredump(struct catpt_dev *cdev);
#include <sound/memalloc.h>

View File

@ -28,44 +28,17 @@
static int catpt_do_suspend(struct device *dev)
{
struct catpt_dev *cdev = dev_get_drvdata(dev);
struct dma_chan *chan;
int ret;
chan = catpt_dma_request_config_chan(cdev);
if (IS_ERR(chan))
return PTR_ERR(chan);
memset(&cdev->dx_ctx, 0, sizeof(cdev->dx_ctx));
ret = catpt_ipc_enter_dxstate(cdev, CATPT_DX_STATE_D3, &cdev->dx_ctx);
if (ret) {
ret = CATPT_IPC_RET(ret);
goto release_dma_chan;
}
ret = catpt_dsp_stall(cdev, true);
if (ret)
goto release_dma_chan;
return CATPT_IPC_RET(ret);
ret = catpt_store_memdumps(cdev, chan);
if (ret) {
dev_err(cdev->dev, "store memdumps failed: %d\n", ret);
goto release_dma_chan;
}
ret = catpt_store_module_states(cdev, chan);
if (ret) {
dev_err(cdev->dev, "store module states failed: %d\n", ret);
goto release_dma_chan;
}
ret = catpt_store_streams_context(cdev, chan);
if (ret)
dev_err(cdev->dev, "store streams ctx failed: %d\n", ret);
release_dma_chan:
dma_release_channel(chan);
ret = catpt_store_firmware_context(cdev);
if (ret)
return ret;
return catpt_dsp_power_down(cdev);
}

View File

@ -26,7 +26,7 @@ struct catpt_fw_hdr {
u32 reserved[4];
} __packed;
struct catpt_fw_mod_hdr {
struct catpt_fw_module_hdr {
char signature[FW_SIGNATURE_SIZE];
u32 mod_size;
u32 blocks;
@ -81,7 +81,7 @@ catpt_request_region(struct resource *root, resource_size_t size)
return __request_region(root, addr, size, NULL, 0);
}
int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
static int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
{
struct catpt_stream_runtime *stream;
@ -108,7 +108,7 @@ int catpt_store_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
return 0;
}
int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan)
static int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan)
{
int i;
@ -138,7 +138,7 @@ int catpt_store_module_states(struct catpt_dev *cdev, struct dma_chan *chan)
return 0;
}
int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
static int catpt_store_dram_data(struct catpt_dev *cdev, struct dma_chan *chan)
{
int i;
@ -171,6 +171,39 @@ int catpt_store_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
return 0;
}
int catpt_store_firmware_context(struct catpt_dev *cdev)
{
struct dma_chan *chan;
int ret;
chan = catpt_dma_request_config_chan(cdev);
if (IS_ERR(chan))
return PTR_ERR(chan);
ret = catpt_dsp_stall(cdev, true);
if (ret)
goto exit;
ret = catpt_store_dram_data(cdev, chan);
if (ret) {
dev_err(cdev->dev, "store memdumps failed: %d\n", ret);
goto exit;
}
ret = catpt_store_module_states(cdev, chan);
if (ret) {
dev_err(cdev->dev, "store module states failed: %d\n", ret);
goto exit;
}
ret = catpt_store_streams_context(cdev, chan);
if (ret)
dev_err(cdev->dev, "store streams ctx failed: %d\n", ret);
exit:
dma_release_channel(chan);
return ret;
}
static int
catpt_restore_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
{
@ -199,7 +232,7 @@ catpt_restore_streams_context(struct catpt_dev *cdev, struct dma_chan *chan)
return 0;
}
static int catpt_restore_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
static int catpt_restore_dram_data(struct catpt_dev *cdev, struct dma_chan *chan)
{
int i;
@ -234,9 +267,9 @@ static int catpt_restore_memdumps(struct catpt_dev *cdev, struct dma_chan *chan)
return 0;
}
static int catpt_restore_fwimage(struct catpt_dev *cdev,
struct dma_chan *chan, dma_addr_t paddr,
struct catpt_fw_block_hdr *blk)
static int catpt_restore_dram_rodata(struct catpt_dev *cdev,
struct dma_chan *chan, dma_addr_t paddr,
struct catpt_fw_block_hdr *blk)
{
struct resource r1 = {};
int i;
@ -324,28 +357,26 @@ static int catpt_load_block(struct catpt_dev *cdev,
static int catpt_restore_basefw(struct catpt_dev *cdev,
struct dma_chan *chan, dma_addr_t paddr,
struct catpt_fw_mod_hdr *basefw)
struct catpt_fw_module_hdr *basefw)
{
u32 offset = sizeof(*basefw);
u32 off = sizeof(*basefw);
int ret, i;
print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
basefw, sizeof(*basefw), false);
/* restore basefw image */
/* Restore IRAM and .rodata for DRAM based on the firmware image. */
for (i = 0; i < basefw->blocks; i++) {
struct catpt_fw_block_hdr *blk;
blk = (struct catpt_fw_block_hdr *)((u8 *)basefw + offset);
blk = (struct catpt_fw_block_hdr *)((u8 *)basefw + off);
switch (blk->ram_type) {
case CATPT_RAM_TYPE_IRAM:
ret = catpt_load_block(cdev, chan, paddr + offset,
blk, false);
ret = catpt_load_block(cdev, chan, paddr + off, blk, false);
break;
default:
ret = catpt_restore_fwimage(cdev, chan, paddr + offset,
blk);
ret = catpt_restore_dram_rodata(cdev, chan, paddr + off, blk);
break;
}
@ -354,11 +385,11 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
return ret;
}
offset += sizeof(*blk) + blk->size;
off += sizeof(*blk) + blk->size;
}
/* then proceed with memory dumps */
ret = catpt_restore_memdumps(cdev, chan);
/* Then proceed with DRAM .data saved before D3. */
ret = catpt_restore_dram_data(cdev, chan);
if (ret)
dev_err(cdev->dev, "restore memdumps failed: %d\n", ret);
@ -367,9 +398,9 @@ static int catpt_restore_basefw(struct catpt_dev *cdev,
static int catpt_restore_module(struct catpt_dev *cdev,
struct dma_chan *chan, dma_addr_t paddr,
struct catpt_fw_mod_hdr *mod)
struct catpt_fw_module_hdr *mod)
{
u32 offset = sizeof(*mod);
u32 off = sizeof(*mod);
int i;
print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
@ -379,7 +410,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
struct catpt_fw_block_hdr *blk;
int ret;
blk = (struct catpt_fw_block_hdr *)((u8 *)mod + offset);
blk = (struct catpt_fw_block_hdr *)((u8 *)mod + off);
switch (blk->ram_type) {
case CATPT_RAM_TYPE_INSTANCE:
@ -390,7 +421,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
ALIGN(blk->size, 4));
break;
default:
ret = catpt_load_block(cdev, chan, paddr + offset,
ret = catpt_load_block(cdev, chan, paddr + off,
blk, false);
break;
}
@ -400,7 +431,7 @@ static int catpt_restore_module(struct catpt_dev *cdev,
return ret;
}
offset += sizeof(*blk) + blk->size;
off += sizeof(*blk) + blk->size;
}
return 0;
@ -408,10 +439,10 @@ static int catpt_restore_module(struct catpt_dev *cdev,
static int catpt_load_module(struct catpt_dev *cdev,
struct dma_chan *chan, dma_addr_t paddr,
struct catpt_fw_mod_hdr *mod)
struct catpt_fw_module_hdr *mod)
{
struct catpt_module_type *type;
u32 offset = sizeof(*mod);
u32 off = sizeof(*mod);
int i;
print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
@ -423,9 +454,9 @@ static int catpt_load_module(struct catpt_dev *cdev,
struct catpt_fw_block_hdr *blk;
int ret;
blk = (struct catpt_fw_block_hdr *)((u8 *)mod + offset);
blk = (struct catpt_fw_block_hdr *)((u8 *)mod + off);
ret = catpt_load_block(cdev, chan, paddr + offset, blk, true);
ret = catpt_load_block(cdev, chan, paddr + off, blk, true);
if (ret) {
dev_err(cdev->dev, "load block failed: %d\n", ret);
return ret;
@ -440,7 +471,7 @@ static int catpt_load_module(struct catpt_dev *cdev,
type->state_size = blk->size;
}
offset += sizeof(*blk) + blk->size;
off += sizeof(*blk) + blk->size;
}
/* init module type static info */
@ -457,17 +488,17 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
struct dma_chan *chan, dma_addr_t paddr,
struct catpt_fw_hdr *fw)
{
u32 offset = sizeof(*fw);
u32 off = sizeof(*fw);
int i;
print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
fw, sizeof(*fw), false);
for (i = 0; i < fw->modules; i++) {
struct catpt_fw_mod_hdr *mod;
struct catpt_fw_module_hdr *mod;
int ret;
mod = (struct catpt_fw_mod_hdr *)((u8 *)fw + offset);
mod = (struct catpt_fw_module_hdr *)((u8 *)fw + off);
if (strncmp(fw->signature, mod->signature,
FW_SIGNATURE_SIZE)) {
dev_err(cdev->dev, "module signature mismatch\n");
@ -479,12 +510,10 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
switch (mod->module_id) {
case CATPT_MODID_BASE_FW:
ret = catpt_restore_basefw(cdev, chan, paddr + offset,
mod);
ret = catpt_restore_basefw(cdev, chan, paddr + off, mod);
break;
default:
ret = catpt_restore_module(cdev, chan, paddr + offset,
mod);
ret = catpt_restore_module(cdev, chan, paddr + off, mod);
break;
}
@ -493,7 +522,7 @@ static int catpt_restore_firmware(struct catpt_dev *cdev,
return ret;
}
offset += sizeof(*mod) + mod->mod_size;
off += sizeof(*mod) + mod->mod_size;
}
return 0;
@ -503,17 +532,17 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
struct dma_chan *chan, dma_addr_t paddr,
struct catpt_fw_hdr *fw)
{
u32 offset = sizeof(*fw);
u32 off = sizeof(*fw);
int i;
print_hex_dump_debug(__func__, DUMP_PREFIX_OFFSET, 8, 4,
fw, sizeof(*fw), false);
for (i = 0; i < fw->modules; i++) {
struct catpt_fw_mod_hdr *mod;
struct catpt_fw_module_hdr *mod;
int ret;
mod = (struct catpt_fw_mod_hdr *)((u8 *)fw + offset);
mod = (struct catpt_fw_module_hdr *)((u8 *)fw + off);
if (strncmp(fw->signature, mod->signature,
FW_SIGNATURE_SIZE)) {
dev_err(cdev->dev, "module signature mismatch\n");
@ -523,21 +552,20 @@ static int catpt_load_firmware(struct catpt_dev *cdev,
if (mod->module_id > CATPT_MODID_LAST)
return -EINVAL;
ret = catpt_load_module(cdev, chan, paddr + offset, mod);
ret = catpt_load_module(cdev, chan, paddr + off, mod);
if (ret) {
dev_err(cdev->dev, "load module failed: %d\n", ret);
return ret;
}
offset += sizeof(*mod) + mod->mod_size;
off += sizeof(*mod) + mod->mod_size;
}
return 0;
}
static int catpt_load_image(struct catpt_dev *cdev, struct dma_chan *chan,
const char *name, const char *signature,
bool restore)
static int catpt_request_load_firmware(struct catpt_dev *cdev, struct dma_chan *chan,
const char *name, bool restore)
{
struct catpt_fw_hdr *fw;
struct firmware *img;
@ -550,7 +578,7 @@ static int catpt_load_image(struct catpt_dev *cdev, struct dma_chan *chan,
return ret;
fw = (struct catpt_fw_hdr *)img->data;
if (strncmp(fw->signature, signature, FW_SIGNATURE_SIZE)) {
if (strncmp(fw->signature, FW_SIGNATURE, FW_SIGNATURE_SIZE)) {
dev_err(cdev->dev, "firmware signature mismatch\n");
ret = -EINVAL;
goto release_fw;
@ -575,7 +603,7 @@ static int catpt_load_image(struct catpt_dev *cdev, struct dma_chan *chan,
return ret;
}
static int catpt_load_images(struct catpt_dev *cdev, bool restore)
static int catpt_request_dma_load_firmware(struct catpt_dev *cdev, bool restore)
{
struct dma_chan *chan;
int ret;
@ -584,8 +612,7 @@ static int catpt_load_images(struct catpt_dev *cdev, bool restore)
if (IS_ERR(chan))
return PTR_ERR(chan);
ret = catpt_load_image(cdev, chan, cdev->spec->fw_name,
FW_SIGNATURE, restore);
ret = catpt_request_load_firmware(cdev, chan, cdev->spec->fw_name, restore);
if (ret)
goto release_dma_chan;
@ -605,7 +632,7 @@ int catpt_boot_firmware(struct catpt_dev *cdev, bool restore)
catpt_dsp_stall(cdev, true);
ret = catpt_load_images(cdev, restore);
ret = catpt_request_dma_load_firmware(cdev, restore);
if (ret) {
dev_err(cdev->dev, "load binaries failed: %d\n", ret);
return ret;
@ -619,10 +646,10 @@ int catpt_boot_firmware(struct catpt_dev *cdev, bool restore)
if (!ret) {
dev_err(cdev->dev, "firmware ready timeout\n");
return -ETIMEDOUT;
/* Wake up does not mean FW is ready, an exception could occur. */
} else if (!cdev->ipc.ready) {
return -EREMOTEIO;
}
/* Wake up does not mean FW is ready, an exception could occur. */
if (!cdev->ipc.ready)
return -EREMOTEIO;
/* update sram pg & clock once done booting */
catpt_dsp_update_srampge(cdev, &cdev->dram, cdev->spec->dram_mask);

View File

@ -75,8 +75,8 @@ static struct catpt_stream_template *catpt_topology[] = {
static struct catpt_stream_template *
catpt_get_stream_template(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtm = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtm, 0);
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
enum catpt_stream_type type;
type = cpu_dai->driver->id;
@ -159,11 +159,11 @@ static void catpt_stream_read_position(struct catpt_dev *cdev,
static void catpt_arrange_page_table(struct snd_pcm_substream *substream,
struct snd_dma_buffer *pgtbl)
{
struct snd_pcm_runtime *rtm = substream->runtime;
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_dma_buffer *databuf = snd_pcm_get_dma_buf(substream);
int i, pages;
pages = snd_sgbuf_aligned_pages(rtm->dma_bytes);
pages = snd_sgbuf_aligned_pages(runtime->dma_bytes);
for (i = 0; i < pages; i++) {
u32 pfn, offset;
@ -386,7 +386,7 @@ static int catpt_dai_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
struct snd_pcm_runtime *rtm = substream->runtime;
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_dma_buffer *dmab;
struct catpt_stream_runtime *stream;
struct catpt_audio_format afmt;
@ -412,8 +412,8 @@ static int catpt_dai_hw_params(struct snd_pcm_substream *substream,
memset(&rinfo, 0, sizeof(rinfo));
rinfo.page_table_addr = stream->pgtbl.addr;
rinfo.num_pages = DIV_ROUND_UP(rtm->dma_bytes, PAGE_SIZE);
rinfo.size = rtm->dma_bytes;
rinfo.num_pages = DIV_ROUND_UP(runtime->dma_bytes, PAGE_SIZE);
rinfo.size = runtime->dma_bytes;
rinfo.offset = 0;
rinfo.ring_first_page_pfn = PFN_DOWN(snd_sgbuf_get_addr(dmab, 0));
@ -544,11 +544,11 @@ void catpt_stream_update_position(struct catpt_dev *cdev,
struct catpt_notify_position *pos)
{
struct snd_pcm_substream *substream = stream->substream;
struct snd_pcm_runtime *r = substream->runtime;
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_uframes_t dsppos, newpos;
int ret;
dsppos = bytes_to_frames(r, pos->stream_position);
dsppos = bytes_to_frames(runtime, pos->stream_position);
if (!stream->prepared)
goto exit;
@ -556,8 +556,8 @@ void catpt_stream_update_position(struct catpt_dev *cdev,
if (stream->template->type != CATPT_STRM_TYPE_RENDER)
goto exit;
if (dsppos >= r->buffer_size / 2)
newpos = r->buffer_size / 2;
if (dsppos >= runtime->buffer_size / 2)
newpos = runtime->buffer_size / 2;
else
newpos = 0;
/*
@ -565,7 +565,7 @@ void catpt_stream_update_position(struct catpt_dev *cdev,
* (buffer half consumed) update wp to allow stream progression.
*/
ret = catpt_ipc_set_write_pos(cdev, stream->info.stream_hw_id,
frames_to_bytes(r, newpos),
frames_to_bytes(runtime, newpos),
false, false);
if (ret) {
dev_err(cdev->dev, "update position for stream %d failed: %d\n",
@ -600,11 +600,11 @@ static const struct snd_pcm_hardware catpt_pcm_hardware = {
};
static int catpt_component_pcm_new(struct snd_soc_component *component,
struct snd_soc_pcm_runtime *rtm)
struct snd_soc_pcm_runtime *rtd)
{
struct catpt_dev *cdev = dev_get_drvdata(component->dev);
snd_pcm_set_managed_buffer_all(rtm->pcm, SNDRV_DMA_TYPE_DEV_SG,
snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV_SG,
cdev->dev,
catpt_pcm_hardware.buffer_bytes_max,
catpt_pcm_hardware.buffer_bytes_max);
@ -615,9 +615,9 @@ static int catpt_component_pcm_new(struct snd_soc_component *component,
static int catpt_component_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtm = snd_soc_substream_to_rtd(substream);
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
if (!rtm->dai_link->no_pcm)
if (!rtd->dai_link->no_pcm)
snd_soc_set_runtime_hwparams(substream, &catpt_pcm_hardware);
return 0;
}
@ -626,13 +626,13 @@ static snd_pcm_uframes_t
catpt_component_pointer(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtm = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtm, 0);
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
struct catpt_stream_runtime *stream;
struct catpt_dev *cdev = dev_get_drvdata(component->dev);
u32 pos;
if (rtm->dai_link->no_pcm)
if (rtd->dai_link->no_pcm)
return 0;
stream = snd_soc_dai_get_dma_data(cpu_dai, substream);
@ -650,10 +650,10 @@ static const struct snd_soc_dai_ops catpt_fe_dai_ops = {
.trigger = catpt_dai_trigger,
};
static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtm,
static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_dai *dai)
{
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtm, 0);
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
struct catpt_ssp_device_format devfmt;
struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
int ret;
@ -871,8 +871,7 @@ static int catpt_set_dspvol(struct catpt_dev *cdev, u8 stream_id, long *ctlvol)
return CATPT_IPC_RET(ret);
}
static int catpt_volume_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
static int catpt_volume_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = CATPT_CHANNELS_MAX;