From c3576f091c1bedad866a32f11882dc37e76587cb Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Fri, 16 Oct 2020 16:01:24 -0500 Subject: [PATCH 1/2] ASoC: codecs: rt1308-sdw: add IV feedback support The RT1308 can provide feedback for two speakers. Each speaker is handled by a port, and each port transmits two channels for I and V. The data is handled as a single 4ch stream and a single DAI. Co-developed-by: Shuming Fan Signed-off-by: Shuming Fan Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/rt1308-sdw.c | 79 ++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/sound/soc/codecs/rt1308-sdw.c b/sound/soc/codecs/rt1308-sdw.c index ec5564f780e8c6..83a4eb95c2e95c 100644 --- a/sound/soc/codecs/rt1308-sdw.c +++ b/sound/soc/codecs/rt1308-sdw.c @@ -118,7 +118,8 @@ static int rt1308_clock_config(struct device *dev) static int rt1308_read_prop(struct sdw_slave *slave) { struct sdw_slave_prop *prop = &slave->prop; - int nval, i; + int nval; + int i, j; u32 bit; unsigned long addr; struct sdw_dpn_prop *dpn; @@ -129,20 +130,19 @@ static int rt1308_read_prop(struct sdw_slave *slave) prop->paging_support = true; /* first we need to allocate memory for set bits in port lists */ - prop->source_ports = 0x00; /* BITMAP: 00010100 (not enable yet) */ + prop->source_ports = 0x14; /* BITMAP: 00010100 */ prop->sink_ports = 0x2; /* BITMAP: 00000010 */ - /* for sink */ - nval = hweight32(prop->sink_ports); - prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, - sizeof(*prop->sink_dpn_prop), + nval = hweight32(prop->source_ports); + prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, + sizeof(*prop->src_dpn_prop), GFP_KERNEL); - if (!prop->sink_dpn_prop) + if (!prop->src_dpn_prop) return -ENOMEM; i = 0; - dpn = prop->sink_dpn_prop; - addr = prop->sink_ports; + dpn = prop->src_dpn_prop; + addr = prop->source_ports; for_each_set_bit(bit, &addr, 32) { dpn[i].num = bit; dpn[i].type = SDW_DPN_FULL; @@ -151,6 +151,25 @@ static int rt1308_read_prop(struct sdw_slave *slave) i++; } + /* do this again for sink now */ + nval = hweight32(prop->sink_ports); + prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval, + sizeof(*prop->sink_dpn_prop), + GFP_KERNEL); + if (!prop->sink_dpn_prop) + return -ENOMEM; + + j = 0; + dpn = prop->sink_dpn_prop; + addr = prop->sink_ports; + for_each_set_bit(bit, &addr, 32) { + dpn[j].num = bit; + dpn[j].type = SDW_DPN_FULL; + dpn[j].simple_ch_prep_sm = true; + dpn[j].ch_prep_timeout = 10; + j++; + } + /* set the timeout values */ prop->clk_stop_timeout = 20; @@ -526,6 +545,7 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream, snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config; struct sdw_port_config port_config; + struct sdw_port_config port_config_feedback[2]; enum sdw_data_direction direction; struct sdw_stream_data *stream; int retval, port, num_channels, ch_mask; @@ -540,13 +560,12 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream, return -EINVAL; /* SoundWire specific configuration */ + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) + goto capture; + /* port 1 for playback */ - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - direction = SDW_DATA_DIR_RX; - port = 1; - } else { - return -EINVAL; - } + direction = SDW_DATA_DIR_RX; + port = 1; if (rt1308->slots) { num_channels = rt1308->slots; @@ -571,6 +590,29 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream, return retval; } + return retval; + +capture: + direction = SDW_DATA_DIR_TX; + num_channels = 4; + + stream_config.frame_rate = params_rate(params); + stream_config.ch_count = num_channels; + stream_config.bps = snd_pcm_format_width(params_format(params)); + stream_config.direction = direction; + + port_config_feedback[0].ch_mask = BIT(0) | BIT(1); + port_config_feedback[0].num = 2; /* DP2 */ + port_config_feedback[1].ch_mask = BIT(0) | BIT(1); + port_config_feedback[1].num = 4; /* DP4 */ + + retval = sdw_stream_add_slave(rt1308->sdw_slave, &stream_config, + port_config_feedback, 2, stream->sdw_stream); + if (retval) { + dev_err(dai->dev, "Unable to configure port\n"); + return retval; + } + return retval; } @@ -633,6 +675,13 @@ static struct snd_soc_dai_driver rt1308_sdw_dai[] = { .rates = RT1308_STEREO_RATES, .formats = RT1308_FORMATS, }, + .capture = { + .stream_name = "DP2-4 Capture", + .channels_min = 4, + .channels_max = 4, + .rates = RT1308_STEREO_RATES, + .formats = RT1308_FORMATS, + }, .ops = &rt1308_aif_dai_ops, }, }; From d41d1c1cfb52c80c748e7a6ce3e9824d18f6fe47 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Fri, 16 Oct 2020 16:07:42 -0500 Subject: [PATCH 2/2] ASoC: Intel: sof_sdw: add feedback support for RT1308 FIXME: for now there is no initialization on capture. Signed-off-by: Pierre-Louis Bossart --- sound/soc/intel/boards/sof_sdw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index ca968901ac96f3..02e80cfedec04b 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -292,7 +292,7 @@ static struct sof_sdw_codec_info codec_info_list[] = { { .part_id = 0x1308, .acpi_id = "10EC1308", - .direction = {true, false}, + .direction = {true, true}, .dai_name = "rt1308-aif", .ops = &sof_sdw_rt1308_i2s_ops, .init = sof_sdw_rt1308_init,