Re: [alsa-devel] [RFC PATCH 02/40] soundwire: cadence_master: add debugfs register dump

Pierre-Louis Bossart
2019-08-05T15:20:40Z

>> +static ssize_t cdns_reg_read(struct file *file, char __user *user_buf,
>> + size_t count, loff_t *ppos)
>> +{
>> + struct sdw_cdns *cdns = file->private_data;
>> + char *buf;
>> + ssize_t ret;
>> + int i, j;
>> +
>> + buf = kzalloc(RD_BUF, GFP_KERNEL);
>> + if (!buf)
>> + return -ENOMEM;
>> +
>> + ret = scnprintf(buf, RD_BUF, "Register Value\n");
>> + ret += scnprintf(buf + ret, RD_BUF - ret, "\nMCP Registers\n");
>> + for (i = 0; i < 8; i++) /* 8 MCP registers */
>> + ret += cdns_sprintf(cdns, buf, ret, i * 4);
>> +
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nStatus & Intr Registers\n");
>> + for (i = 0; i < 13; i++) /* 13 Status & Intr registers */
>> + ret += cdns_sprintf(cdns, buf, ret, CDNS_MCP_STAT + i * 4);
>> +
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nSSP & Clk ctrl Registers\n");
>> + ret += cdns_sprintf(cdns, buf, ret, CDNS_MCP_SSP_CTRL0);
>> + ret += cdns_sprintf(cdns, buf, ret, CDNS_MCP_SSP_CTRL1);
>> + ret += cdns_sprintf(cdns, buf, ret, CDNS_MCP_CLK_CTRL0);
>> + ret += cdns_sprintf(cdns, buf, ret, CDNS_MCP_CLK_CTRL1);
>> +
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nDPn B0 Registers\n");
>> + for (i = 0; i < 7; i++) {
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nDP-%d\n", i);
>> + for (j = 0; j < 6; j++)
>> + ret += cdns_sprintf(cdns, buf, ret,
>> + CDNS_DPN_B0_CONFIG(i) + j * 4);
>> + }
>> +
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nDPn B1 Registers\n");
>> + for (i = 0; i < 7; i++) {
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nDP-%d\n", i);
>> +
>> + for (j = 0; j < 6; j++)
>> + ret += cdns_sprintf(cdns, buf, ret,
>> + CDNS_DPN_B1_CONFIG(i) + j * 4);
>> + }
>> +
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nDPn Control Registers\n");
>> + for (i = 0; i < 7; i++)
>> + ret += cdns_sprintf(cdns, buf, ret,
>> + CDNS_PORTCTRL + i * CDNS_PORT_OFFSET);
>> +
>> + ret += scnprintf(buf + ret, RD_BUF - ret,
>> + "\nPDIn Config Registers\n");
>> + for (i = 0; i < 7; i++)
>
> please use macros for all the hardcodings.

yes, I completely changed that part in the upcoming update by using
register start/stop for all loops, it makes the code more consistent and
easier to change (SoundWire 1.2 registers will need to be added)