From 6abd07746db24b6e2cf16a7e23ed0d5baa3c15e9 Mon Sep 17 00:00:00 2001 From: Chao Song Date: Tue, 14 Nov 2023 13:45:59 +0800 Subject: [PATCH 1/2] soundwire: mipi_disco: read lane mapping properties from ACPI This patch adds the code to read lane mapping information from ACPI for soundwire peripheral. Signed-off-by: Chao Song --- drivers/soundwire/mipi_disco.c | 31 +++++++++++++++++++++++++++++++ include/linux/soundwire/sdw.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/drivers/soundwire/mipi_disco.c b/drivers/soundwire/mipi_disco.c index 55a9c51c84c19a..fe06b8d5080a2b 100644 --- a/drivers/soundwire/mipi_disco.c +++ b/drivers/soundwire/mipi_disco.c @@ -280,6 +280,35 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave, return 0; } +/* + * In MIPI DisCo spec for SoundWire, lane mapping for a slave device is done with + * mipi-sdw-lane-x-mapping properties, where x is 1..7, and the values for those + * properties are mipi-sdw-manager-lane-x or mipi-sdw-peripheral-link-y, where x + * is an integer between 1 to 7 if the lane is connected to a master lane, y is a + * character between A to E if the lane is connected to another slave lane. + */ +static int sdw_slave_read_lane_mapping(struct sdw_slave *slave) +{ + struct sdw_slave_prop *prop = &slave->prop; + struct device *dev = &slave->dev; + char prop_name[30]; + const char *prop_val; + size_t len; + int ret, i; + + for (i = 0; i < SDW_MAX_LANES; i++) { + snprintf(prop_name, sizeof(prop_name), "mipi-sdw-lane-%d-mapping", i); + ret = device_property_read_string(dev, prop_name, &prop_val); + if (ret) + continue; + len = strlen(prop_val); + /* The last character is enough to identify the connection */ + prop->lane_maps[i] = prop_val[len - 1]; + dev_err(dev, "[Chao] %c\n", prop->lane_maps[i]); + } + return 0; +} + /** * sdw_slave_read_prop() - Read Slave properties * @slave: SDW Slave @@ -382,6 +411,8 @@ int sdw_slave_read_prop(struct sdw_slave *slave) sdw_slave_read_dpn(slave, prop->sink_dpn_prop, nval, prop->sink_ports, "sink"); + sdw_slave_read_lane_mapping(slave); + return 0; } EXPORT_SYMBOL(sdw_slave_read_prop); diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index 4f3d14bb15385a..97ca0468a47d92 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -46,6 +46,8 @@ struct sdw_slave; #define SDW_MAX_PORTS 15 #define SDW_VALID_PORT_RANGE(n) ((n) < SDW_MAX_PORTS && (n) >= 1) +#define SDW_MAX_LANES 8 + enum { SDW_PORT_DIRN_SINK = 0, SDW_PORT_DIRN_SOURCE, @@ -361,6 +363,7 @@ struct sdw_dpn_prop { * @p15_behave: Slave behavior when the Master attempts a read to the Port15 * alias * @lane_control_support: Slave supports lane control + * @lane_maps: Lane mapping for the slave * @master_count: Number of Masters present on this Slave * @source_ports: Bitmap identifying source ports * @sink_ports: Bitmap identifying sink ports @@ -388,6 +391,7 @@ struct sdw_slave_prop { bool bank_delay_support; enum sdw_p15_behave p15_behave; bool lane_control_support; + u8 lane_maps[SDW_MAX_LANES]; u32 master_count; u32 source_ports; u32 sink_ports; From 8708d906534b1d2621772f39523d847b1d20b03d Mon Sep 17 00:00:00 2001 From: Chao Song Date: Tue, 14 Nov 2023 13:47:11 +0800 Subject: [PATCH 2/2] ASoC: rt722-sdca-sdw: read DisCo properties in read_prop ops This patch reads DisCo properties for rt722-sdca soundwire peripheral device. Signed-off-by: Chao Song --- sound/soc/codecs/rt722-sdca-sdw.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/soc/codecs/rt722-sdca-sdw.c b/sound/soc/codecs/rt722-sdca-sdw.c index e24b9cbdc10c95..00fa6c6a7c0ae7 100644 --- a/sound/soc/codecs/rt722-sdca-sdw.c +++ b/sound/soc/codecs/rt722-sdca-sdw.c @@ -201,6 +201,8 @@ static int rt722_sdca_read_prop(struct sdw_slave *slave) unsigned long addr; struct sdw_dpn_prop *dpn; + sdw_slave_read_prop(slave); + prop->scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY; prop->quirks = SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY;