soundwire: Add generic bandwidth allocation algorithm
Bard Liao
maintainerPATCH 1/1 soundwire: Add generic bandwidth allocation algorithm
This algorithm computes bus parameters like clock frequency, frame shape and port transport parameters based on active stream(s) running on the bus.
Developers can also implement their own .compute_params() callback for specific resource management algorithm, and set if before calling sdw_add_bus_master()
Credits: this patch is based on an earlier internal contribution by Vinod Koul, Sanyog Kale, Shreyas Nc and Hardik Shah. All hard-coded values were removed from the initial contribution to use BIOS information instead.
--- drivers/soundwire/Kconfig | 5 + drivers/soundwire/Makefile | 3 + drivers/soundwire/bus.c | 6 + drivers/soundwire/bus.h | 46 +- .../soundwire/generic_bandwidth_allocation.c | 427 ++++++++++++++++++ drivers/soundwire/intel.c | 3 + drivers/soundwire/stream.c | 12 + include/linux/soundwire/sdw.h | 3 + 8 files changed, 503 insertions(+), 2 deletions(-) create mode 100644 drivers/soundwire/generic_bandwidth_allocation.c
drivers/soundwire/Kconfig +5 -0
@@ -24,6 +24,7 @@ config SOUNDWIRE_CADENCE config SOUNDWIRE_INTEL tristate "Intel SoundWire Master driver" select SOUNDWIRE_CADENCE + select SOUNDWIRE_GENERIC_ALLOCATION depends on ACPI && SND_SOC help SoundWire Intel Master driver.
@@ -40,4 +41,8 @@ config SOUNDWIRE_QCOM If you have an Qualcomm platform which has a SoundWire Master then enable this config option to get the SoundWire support for that device + +config SOUNDWIRE_GENERIC_ALLOCATION + tristate + endif
drivers/soundwire/Makefile +3 -0
@@ -8,6 +8,9 @@ soundwire-bus-y := bus_type.o bus.o master.o slave.o mipi_disco.o stream.o \ sysfs_slave.o sysfs_slave_dpn.o obj-$(CONFIG_SOUNDWIRE) += soundwire-bus.o +soundwire-generic-allocation-objs := generic_bandwidth_allocation.o +obj-$(CONFIG_SOUNDWIRE_GENERIC_ALLOCATION) += soundwire-generic-allocation.o + ifdef CONFIG_DEBUG_FS soundwire-bus-y += debugfs.o endif
drivers/soundwire/bus.c +6 -0
@@ -61,6 +61,12 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,return -EINVAL ; } +if (!bus->compute_params) { +dev_err (bus->dev, +"Bandwidth allocation not configured, compute_params no set\n" ); +return -EINVAL ; + } +mutex_init (&bus->msg_lock);mutex_init (&bus->bus_lock);INIT_LIST_HEAD (&bus->slaves);
drivers/soundwire/bus.h +44 -2
59 lines not on this page · raw message
drivers/soundwire/generic_bandwidth_allocation.c new file +427 -0
427 lines not on this page · raw message
drivers/soundwire/intel.c +3 -0
@@ -1318,6 +1318,9 @@ static int intel_master_probe(struct platform_device *pdev)/* set driver data, accessed by snd_soc_dai_get_drvdata() */ dev_set_drvdata (dev, cdns); +/* use generic bandwidth allocation algorithm */ + sdw->cdns.bus.compute_params = sdw_compute_params; + ret =sdw_bus_master_add (bus, dev, dev->fwnode);if (ret) {dev_err (dev,"sdw_bus_master_add fail: %d\n" , ret);
drivers/soundwire/stream.c +12 -0
@@ -25,8 +25,10 @@int sdw_rows[SDW_FRAME_ROWS ] = {48 ,50 ,60 ,64 ,75 ,80 ,125 ,147 ,96 ,100 ,120 ,128 ,150 ,160 ,250 ,0 ,192 ,200 ,240 ,256 ,72 ,144 ,90 ,180 }; +EXPORT_SYMBOL (sdw_rows);int sdw_cols[SDW_FRAME_COLS ] = {2 ,4 ,6 ,8 ,10 ,12 ,14 ,16 }; +EXPORT_SYMBOL (sdw_cols);int sdw_find_col_index (int col) {
@@ -1782,6 +1784,16 @@ static int _sdw_deprepare_stream(struct sdw_stream_runtime *stream) bus->params.bandwidth -= m_rt->stream->params.rate * m_rt->ch_count * m_rt->stream->params.bps; +/* Compute params */ +if (bus->compute_params) { + ret = bus->compute_params (bus); +if (ret <0 ) { +dev_err (bus->dev,"Compute params failed: %d" , + ret); +return ret; + } + } +/* Program params */ ret =sdw_program_params (bus, false);if (ret <0 ) {
include/linux/soundwire/sdw.h +3 -0
@@ -955,6 +955,9 @@ struct sdw_stream_runtime {struct sdw_stream_runtime *sdw_alloc_stream (const char *stream_name);void sdw_release_stream (struct sdw_stream_runtime *stream); + +int sdw_compute_params (struct sdw_bus *bus); + int sdw_stream_add_master(struct sdw_bus *bus, struct sdw_stream_config *stream_config, struct sdw_port_config *port_config,
Signature · 1 line
2.17.1
Dne 08. 09. 20 v 15:15 Bard Liao napsal(a):
Quoted 14 lines
This algorithm computes bus parameters like clock frequency, frame shape and port transport parameters based on active stream(s) running on the bus.
Developers can also implement their own .compute_params() callback for specific resource management algorithm, and set if before calling
sdw_add_bus_master()Credits: this patch is based on an earlier internal contribution by Vinod Koul, Sanyog Kale, Shreyas Nc and Hardik Shah. All hard-coded values were removed from the initial contribution to use BIOS information instead.
Signed-off-by Bard Liao <[email protected]>
Quoted 11 lines
--- drivers/soundwire/Kconfig | 5 + drivers/soundwire/Makefile | 3 + drivers/soundwire/bus.c | 6 + drivers/soundwire/bus.h | 46 +- .../soundwire/generic_bandwidth_allocation.c | 427 ++++++++++++++++++ drivers/soundwire/intel.c | 3 + drivers/soundwire/stream.c | 12 + include/linux/soundwire/sdw.h | 3 + 8 files changed, 503 insertions(+), 2 deletions(-) create mode 100644 drivers/soundwire/generic_bandwidth_allocation.c
I did testing and I've not found any issues. The abstraction looks good.
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Dne 09. 09. 20 v 8:26 Jaroslav Kysela napsal(a):
Quoted 27 lines
Dne 08. 09. 20 v 15:15 Bard Liao napsal(a):
Quoted 14 lines
This algorithm computes bus parameters like clock frequency, frame shape and port transport parameters based on active stream(s) running on the bus.
Developers can also implement their own .compute_params() callback for specific resource management algorithm, and set if before calling
sdw_add_bus_master()Credits: this patch is based on an earlier internal contribution by Vinod Koul, Sanyog Kale, Shreyas Nc and Hardik Shah. All hard-coded values were removed from the initial contribution to use BIOS information instead.
Signed-off-by Bard Liao <[email protected]>Quoted 11 lines
--- drivers/soundwire/Kconfig | 5 + drivers/soundwire/Makefile | 3 + drivers/soundwire/bus.c | 6 + drivers/soundwire/bus.h | 46 +- .../soundwire/generic_bandwidth_allocation.c | 427 ++++++++++++++++++ drivers/soundwire/intel.c | 3 + drivers/soundwire/stream.c | 12 + include/linux/soundwire/sdw.h | 3 + 8 files changed, 503 insertions(+), 2 deletions(-) create mode 100644 drivers/soundwire/generic_bandwidth_allocation.c
Quoted 4 lines
I did testing and I've not found any issues. The abstraction looks good.
Acked-by Jaroslav Kysela <[email protected]>
Vinod, ping.... This is the last patch which is missing to get the soundwire audio working on some Intel hardware platforms (laptops) which are already on the market.
Thank you,
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Quoted 4 lines · Bard Liao
This algorithm computes bus parameters like clock frequency, frame shape and port transport parameters based on active stream(s) running on the bus.
Quoted 8 lines
Developers can also implement their own .compute_params() callback for specific resource management algorithm, and set if before calling
sdw_add_bus_master()Credits: this patch is based on an earlier internal contribution by Vinod Koul, Sanyog Kale, Shreyas Nc and Hardik Shah. All hard-coded values were removed from the initial contribution to use BIOS information instead.
Applied, thanks
Signature · 1 line
~Vinod