Unverified Commit c06c4f7c authored by Mohammad Rafi Shaik's avatar Mohammad Rafi Shaik Committed by Mark Brown
Browse files

ASoC: codecs: wcd937x: Add static channel mapping support in wcd937x-sdw



Add static channel mapping between master and slave ports in wcd937x-sdw
driver.

Currently, the channel mask for each soundwire port is hardcoded in the
wcd937x-sdw driver, and the same channel mask value is configured in the
soundwire master.

The Qualcomm boards like the QCM6490-IDP require different channel mask
settings for the soundwire master and slave ports.

Implemented logic to read TX/RX channel mappings from device tree
properties (qcom,tx-channel-mapping and qcom,rx-channel-mapping).

Modified the wcd937x_connect_port to handle master channel masks during
port enable/disable operations.

Added wcd937x_get_channel_map api to retrieve the current master
channel map for TX and RX paths.

Signed-off-by: default avatarMohammad Rafi Shaik <quic_mohs@quicinc.com>
Link: https://patch.msgid.link/20250206112225.3270400-3-quic_mohs@quicinc.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 72826381
Loading
Loading
Loading
Loading
+35 −4
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
#include <sound/soc.h>
#include "wcd937x.h"

static const struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
static struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
	WCD_SDW_CH(WCD937X_HPH_L, WCD937X_HPH_PORT, BIT(0)),
	WCD_SDW_CH(WCD937X_HPH_R, WCD937X_HPH_PORT, BIT(1)),
	WCD_SDW_CH(WCD937X_CLSH, WCD937X_CLSH_PORT, BIT(0)),
@@ -30,7 +30,7 @@ static const struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = {
	WCD_SDW_CH(WCD937X_DSD_R, WCD937X_DSD_PORT, BIT(1)),
};

static const struct wcd937x_sdw_ch_info wcd937x_sdw_tx_ch_info[] = {
static struct wcd937x_sdw_ch_info wcd937x_sdw_tx_ch_info[] = {
	WCD_SDW_CH(WCD937X_ADC1, WCD937X_ADC_1_PORT, BIT(0)),
	WCD_SDW_CH(WCD937X_ADC2, WCD937X_ADC_2_3_PORT, BIT(0)),
	WCD_SDW_CH(WCD937X_ADC3, WCD937X_ADC_2_3_PORT, BIT(0)),
@@ -1019,7 +1019,9 @@ static int wcd9370_probe(struct sdw_slave *pdev,
{
	struct device *dev = &pdev->dev;
	struct wcd937x_sdw_priv *wcd;
	int ret;
	u8 master_ch_mask[WCD937X_MAX_SWR_CH_IDS];
	int master_ch_mask_size = 0;
	int ret, i;

	wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL);
	if (!wcd)
@@ -1048,10 +1050,36 @@ static int wcd9370_probe(struct sdw_slave *pdev,
				   SDW_SCP_INT1_PARITY;
	pdev->prop.lane_control_support = true;
	pdev->prop.simple_clk_stop_capable = true;

	memset(master_ch_mask, 0, WCD937X_MAX_SWR_CH_IDS);

	if (wcd->is_tx) {
		pdev->prop.source_ports = GENMASK(WCD937X_MAX_TX_SWR_PORTS - 1, 0);
		master_ch_mask_size = of_property_count_u8_elems(dev->of_node,
								 "qcom,tx-channel-mapping");

		if (master_ch_mask_size)
			ret = of_property_read_u8_array(dev->of_node, "qcom,tx-channel-mapping",
							master_ch_mask, master_ch_mask_size);
	} else {
		master_ch_mask_size = of_property_count_u8_elems(dev->of_node,
								 "qcom,rx-channel-mapping");

		if (master_ch_mask_size)
			ret = of_property_read_u8_array(dev->of_node, "qcom,rx-channel-mapping",
							master_ch_mask, master_ch_mask_size);
	}

	if (ret < 0)
		dev_info(dev, "Static channel mapping not specified using device channel maps\n");

	if (wcd->is_tx) {
		pdev->prop.source_ports = GENMASK(WCD937X_MAX_TX_SWR_PORTS, 0);
		pdev->prop.src_dpn_prop = wcd937x_dpn_prop;
		wcd->ch_info = &wcd937x_sdw_tx_ch_info[0];

		for (i = 0; i < master_ch_mask_size; i++)
			wcd->ch_info[i].master_ch_mask = WCD937X_SWRM_CH_MASK(master_ch_mask[i]);

		pdev->prop.wake_capable = true;

		wcd->regmap = devm_regmap_init_sdw(pdev, &wcd937x_regmap_config);
@@ -1065,6 +1093,9 @@ static int wcd9370_probe(struct sdw_slave *pdev,
		pdev->prop.sink_ports = GENMASK(WCD937X_MAX_SWR_PORTS - 1, 0);
		pdev->prop.sink_dpn_prop = wcd937x_dpn_prop;
		wcd->ch_info = &wcd937x_sdw_rx_ch_info[0];

		for (i = 0; i < master_ch_mask_size; i++)
			wcd->ch_info[i].master_ch_mask = WCD937X_SWRM_CH_MASK(master_ch_mask[i]);
	}


+51 −2
Original line number Diff line number Diff line
@@ -1197,13 +1197,21 @@ static int wcd937x_connect_port(struct wcd937x_sdw_priv *wcd, u8 port_idx, u8 ch
	const struct wcd937x_sdw_ch_info *ch_info = &wcd->ch_info[ch_id];
	u8 port_num = ch_info->port_num;
	u8 ch_mask = ch_info->ch_mask;
	u8 mstr_port_num, mstr_ch_mask;
	struct sdw_slave *sdev = wcd->sdev;

	port_config->num = port_num;

	if (enable)
	mstr_port_num = sdev->m_port_map[port_num];
	mstr_ch_mask = ch_info->master_ch_mask;

	if (enable) {
		port_config->ch_mask |= ch_mask;
	else
		wcd->master_channel_map[mstr_port_num] |= mstr_ch_mask;
	} else {
		port_config->ch_mask &= ~ch_mask;
		wcd->master_channel_map[mstr_port_num] &= ~mstr_ch_mask;
	}

	return 0;
}
@@ -2689,10 +2697,51 @@ static int wcd937x_codec_set_sdw_stream(struct snd_soc_dai *dai,
	return 0;
}

static int wcd937x_get_channel_map(const struct snd_soc_dai *dai,
				   unsigned int *tx_num, unsigned int *tx_slot,
				   unsigned int *rx_num, unsigned int *rx_slot)
{
	struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev);
	struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id];
	int i;

	switch (dai->id) {
	case AIF1_PB:
		if (!rx_slot || !rx_num) {
			dev_err(dai->dev, "Invalid rx_slot %p or rx_num %p\n",
				rx_slot, rx_num);
			return -EINVAL;
		}

		for (i = 0; i < SDW_MAX_PORTS; i++)
			rx_slot[i] = wcd->master_channel_map[i];

		*rx_num = i;
		break;
	case AIF1_CAP:
		if (!tx_slot || !tx_num) {
			dev_err(dai->dev, "Invalid tx_slot %p or tx_num %p\n",
				tx_slot, tx_num);
			return -EINVAL;
		}

		for (i = 0; i < SDW_MAX_PORTS; i++)
			tx_slot[i] = wcd->master_channel_map[i];

		*tx_num = i;
		break;
	default:
		break;
	}

	return 0;
}

static const struct snd_soc_dai_ops wcd937x_sdw_dai_ops = {
	.hw_params = wcd937x_codec_hw_params,
	.hw_free = wcd937x_codec_free,
	.set_stream = wcd937x_codec_set_sdw_stream,
	.get_channel_map = wcd937x_get_channel_map,
};

static struct snd_soc_dai_driver wcd937x_dais[] = {
+6 −1
Original line number Diff line number Diff line
@@ -489,6 +489,7 @@
#define WCD937X_MAX_MICBIAS			3
#define WCD937X_MAX_BULK_SUPPLY			4
#define WCD937X_MAX_SWR_CH_IDS			15
#define WCD937X_SWRM_CH_MASK(ch_idx)		BIT(ch_idx - 1)

enum wcd937x_tx_sdw_ports {
	WCD937X_ADC_1_PORT = 1,
@@ -510,12 +511,14 @@ enum wcd937x_rx_sdw_ports {
struct wcd937x_sdw_ch_info {
	int port_num;
	unsigned int ch_mask;
	unsigned int master_ch_mask;
};

#define WCD_SDW_CH(id, pn, cmask)	\
	[id] = {			\
		.port_num = pn,		\
		.ch_mask = cmask,	\
		.master_ch_mask = cmask,	\
	}

struct wcd937x_priv;
@@ -524,9 +527,11 @@ struct wcd937x_sdw_priv {
	struct sdw_stream_config sconfig;
	struct sdw_stream_runtime *sruntime;
	struct sdw_port_config port_config[WCD937X_MAX_SWR_PORTS];
	const struct wcd937x_sdw_ch_info *ch_info;
	struct wcd937x_sdw_ch_info *ch_info;
	bool port_enable[WCD937X_MAX_SWR_CH_IDS];
	unsigned int master_channel_map[SDW_MAX_PORTS];
	int active_ports;
	int num_ports;
	bool is_tx;
	struct wcd937x_priv *wcd937x;
	struct irq_domain *slave_irq;