Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/soundwire/amd_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ static int amd_sdw_hw_params(struct snd_pcm_substream *substream,
{
struct amd_sdw_manager *amd_manager = snd_soc_dai_get_drvdata(dai);
struct sdw_amd_dai_runtime *dai_runtime;
struct sdw_stream_config sconfig;
struct sdw_stream_config sconfig = {0};
int ch, dir;
int ret;

Expand Down
4 changes: 4 additions & 0 deletions drivers/soundwire/generic_bandwidth_allocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt,

port_bo += bps * ch;
slave_total_ch += ch;

}
/* Make sure all Peripherals use the same bit slots */
if (m_rt->stream->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL)
port_bo = t_data->block_offset;

if (m_rt->direction == SDW_DATA_DIR_TX &&
m_rt->ch_count == slave_total_ch) {
Expand Down
4 changes: 3 additions & 1 deletion drivers/soundwire/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream,
struct sdw_intel *sdw = cdns_to_intel(cdns);
struct sdw_cdns_dai_runtime *dai_runtime;
struct sdw_cdns_pdi *pdi;
struct sdw_stream_config sconfig;
struct sdw_stream_config sconfig = {0};
int ch, dir;
int ret;

Expand Down Expand Up @@ -963,6 +963,8 @@ static int intel_component_dais_suspend(struct snd_soc_component *component)
}

static const struct snd_soc_dai_ops intel_pcm_dai_ops = {
.probe = intel_dai_probe,
.remove = intel_dai_remove,
.hw_params = intel_hw_params,
.prepare = intel_prepare,
.hw_free = intel_hw_free,
Expand Down
4 changes: 4 additions & 0 deletions drivers/soundwire/intel.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct sdw_intel_bpt {
struct sdw_intel {
struct sdw_cdns cdns;
int instance;
unsigned long used_ports;
struct sdw_intel_link_res *link_res;
bool startup_done;
struct sdw_intel_bpt bpt_ctx;
Expand Down Expand Up @@ -126,6 +127,9 @@ static inline void intel_writew(void __iomem *base, int offset, u16 value)

#define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns)

int intel_dai_probe(struct snd_soc_dai *dai);
int intel_dai_remove(struct snd_soc_dai *dai);

#define INTEL_MASTER_RESET_ITERATIONS 10

#define SDW_INTEL_DELAYED_ENUMERATION_MS 100
Expand Down
6 changes: 4 additions & 2 deletions drivers/soundwire/intel_ace2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave *
struct sdw_bus *bus = &cdns->bus;
struct sdw_master_prop *prop = &bus->prop;
struct sdw_stream_runtime *stream;
struct sdw_stream_config sconfig;
struct sdw_stream_config sconfig = {0};
struct sdw_port_config *pconfig;
unsigned int pdi0_buf_size_pre_frame;
unsigned int pdi1_buf_size_pre_frame;
Expand Down Expand Up @@ -724,7 +724,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream,
struct sdw_intel *sdw = cdns_to_intel(cdns);
struct sdw_cdns_dai_runtime *dai_runtime;
struct sdw_cdns_pdi *pdi;
struct sdw_stream_config sconfig;
struct sdw_stream_config sconfig = {0};
int ch, dir;
int ret;

Expand Down Expand Up @@ -928,6 +928,8 @@ static int intel_trigger(struct snd_pcm_substream *substream, int cmd, struct sn
}

static const struct snd_soc_dai_ops intel_pcm_dai_ops = {
.probe = intel_dai_probe,
.remove = intel_dai_remove,
.hw_params = intel_hw_params,
.prepare = intel_prepare,
.hw_free = intel_hw_free,
Expand Down
56 changes: 56 additions & 0 deletions drivers/soundwire/intel_auxdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,60 @@ static void intel_put_device_num_ida(struct sdw_bus *bus, struct sdw_slave *slav
ida_free(&intel_peripheral_ida, slave->dev_num);
}

static int intel_get_port(struct sdw_bus *bus)
{
struct sdw_cdns *cdns = bus_to_cdns(bus);
struct sdw_intel *sdw = cdns_to_intel(cdns);
unsigned int limit = min_t(unsigned int, cdns->num_ports, SDW_MAX_PORTS);
unsigned int port;

port = find_next_zero_bit(&sdw->used_ports, limit, 2);
if (port >= limit)
return -ENOSPC;

set_bit(port, &sdw->used_ports);
return port;
Comment thread
bardliao marked this conversation as resolved.
Resolved
}

static void intel_put_port(struct sdw_bus *bus, unsigned int port)
{
struct sdw_intel *sdw = cdns_to_intel(bus_to_cdns(bus));

clear_bit(port, &sdw->used_ports);
}

int intel_dai_probe(struct snd_soc_dai *dai)
{
struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
struct sdw_intel *sdw = cdns_to_intel(cdns);
int ret = 0;

if (dai->id >= SDW_MAX_PORTS)
return 0;

mutex_lock(&cdns->bus.bus_lock);
if (test_and_set_bit(dai->id, &sdw->used_ports))
ret = -EBUSY;
mutex_unlock(&cdns->bus.bus_lock);

return ret;
}

int intel_dai_remove(struct snd_soc_dai *dai)
{
struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
struct sdw_intel *sdw = cdns_to_intel(cdns);

if (dai->id >= SDW_MAX_PORTS)
return 0;

mutex_lock(&cdns->bus.bus_lock);
clear_bit(dai->id, &sdw->used_ports);
mutex_unlock(&cdns->bus.bus_lock);

return 0;
}

static struct sdw_master_ops sdw_intel_ops = {
.read_prop = intel_prop_read,
.override_adr = sdw_dmi_override_adr,
Expand All @@ -300,6 +354,8 @@ static struct sdw_master_ops sdw_intel_ops = {
.read_ping_status = cdns_read_ping_status,
.get_device_num = intel_get_device_num_ida,
.put_device_num = intel_put_device_num_ida,
.get_port = intel_get_port,
.put_port = intel_put_port,
.new_peripheral_assigned = generic_new_peripheral_assigned,

.bpt_send_async = generic_bpt_send_async,
Expand Down
2 changes: 1 addition & 1 deletion drivers/soundwire/qcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
struct snd_pcm_hw_params *params,
int direction)
{
struct sdw_stream_config sconfig;
struct sdw_stream_config sconfig = {0};
struct sdw_master_runtime *m_rt;
struct sdw_slave_runtime *s_rt;
struct sdw_port_runtime *p_rt;
Expand Down
81 changes: 77 additions & 4 deletions drivers/soundwire/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ static int sdw_enable_disable_ports(struct sdw_master_runtime *m_rt, bool en)
}
}

if (m_rt->stream->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL)
return 0;

/* Enable/Disable Master port(s) */
list_for_each_entry(m_port, &m_rt->port_list, port_node) {
ret = sdw_enable_disable_master_ports(m_rt, m_port, en);
Expand Down Expand Up @@ -1391,6 +1394,7 @@ static int sdw_config_stream(struct device *dev,
}

stream->type = stream_config->type;
stream->transport_type = stream_config->transport_type;
stream->params.rate = stream_config->frame_rate;
stream->params.bps = stream_config->bps;

Expand Down Expand Up @@ -2019,6 +2023,14 @@ void sdw_release_stream(struct sdw_stream_runtime *stream)
}
EXPORT_SYMBOL(sdw_release_stream);

static int sdw_get_port(struct sdw_bus *bus)
{
if (!bus->ops || !bus->ops->get_port || !bus->ops->put_port)
return -EOPNOTSUPP;

return bus->ops->get_port(bus);
}

/**
* sdw_stream_add_master() - Allocate and add master runtime to a stream
*
Expand All @@ -2035,17 +2047,22 @@ int sdw_stream_add_master(struct sdw_bus *bus,
struct sdw_stream_runtime *stream)
{
struct sdw_master_runtime *m_rt;
struct sdw_port_config p2p_port_config;
bool alloc_master_rt = false;
bool alloc_master_port = false;
int reserved_port = -1;
int ret;

mutex_lock(&bus->bus_lock);
m_rt = sdw_master_rt_find(bus, stream);

/*
* For multi link streams, add the second master only if
* the bus supports it.
* Check if bus->multi_link is set
*/
if (!bus->multi_link && stream->m_rt_count > 0) {
if (!bus->multi_link && stream->m_rt_count > 0 &&
(!m_rt || !sdw_master_port_allocated(m_rt))) {
dev_err(bus->dev,
"Multilink not supported, link %d\n", bus->link_id);
ret = -EINVAL;
Expand All @@ -2056,7 +2073,6 @@ int sdw_stream_add_master(struct sdw_bus *bus,
* check if Master is already allocated (e.g. as a result of Slave adding
* it first), if so skip allocation and go to configuration
*/
m_rt = sdw_master_rt_find(bus, stream);
if (!m_rt) {
m_rt = sdw_master_rt_alloc(bus, stream);
if (IS_ERR(m_rt)) {
Expand All @@ -2080,28 +2096,79 @@ int sdw_stream_add_master(struct sdw_bus *bus,
if (ret)
goto alloc_error;

alloc_master_port = true;
stream->m_rt_count++;
}

ret = sdw_master_rt_config(m_rt, stream_config);
if (ret < 0)
goto unlock;
goto config_error;

ret = sdw_config_stream(bus->dev, stream, stream_config, false);
if (ret)
goto unlock;
goto config_error;

if (stream_config->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL) {
struct sdw_port_runtime *p_rt;

if (num_ports != 1) {
ret = -EOPNOTSUPP;
goto config_error;
}

if (!list_is_singular(&m_rt->port_list)) {
ret = -EINVAL;
goto config_error;
}

p_rt = list_first_entry(&m_rt->port_list, struct sdw_port_runtime, port_node);
if (!alloc_master_port && SDW_VALID_PORT_RANGE(p_rt->num)) {
ret = p_rt->num;
} else {
ret = sdw_get_port(bus);
if (ret < 0)
goto config_error;
reserved_port = ret;
if (!SDW_VALID_PORT_RANGE(ret)) {
ret = -EINVAL;
goto config_error;
}
}

p2p_port_config = *port_config;
p2p_port_config.num = ret;
port_config = &p2p_port_config;
}

ret = sdw_master_port_config(m_rt, port_config);
if (ret)
goto config_error;
reserved_port = -1;

goto unlock;

config_error:
if (stream_config->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL) {
if (alloc_master_port) {
sdw_master_port_free(m_rt);
stream->m_rt_count--;
}
if (alloc_master_rt)
sdw_master_rt_free(m_rt, stream);
}
goto unlock;

alloc_error:
/*
* we only cleanup what was allocated in this routine
*/
if (stream_config->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL)
sdw_master_port_free(m_rt);
if (alloc_master_rt)
sdw_master_rt_free(m_rt, stream);
unlock:
if (reserved_port >= 0)
bus->ops->put_port(bus, reserved_port);
mutex_unlock(&bus->bus_lock);
return ret;
}
Expand All @@ -2119,6 +2186,7 @@ int sdw_stream_remove_master(struct sdw_bus *bus,
struct sdw_stream_runtime *stream)
{
struct sdw_master_runtime *m_rt, *_m_rt;
struct sdw_port_runtime *p_rt;

mutex_lock(&bus->bus_lock);

Expand All @@ -2127,6 +2195,11 @@ int sdw_stream_remove_master(struct sdw_bus *bus,
if (m_rt->bus != bus)
continue;

if (stream->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL &&
bus->ops && bus->ops->put_port) {
list_for_each_entry(p_rt, &m_rt->port_list, port_node)
bus->ops->put_port(bus, p_rt->num);
}
sdw_master_port_free(m_rt);
sdw_master_rt_free(m_rt, stream);
stream->m_rt_count--;
Expand Down
20 changes: 20 additions & 0 deletions include/linux/soundwire/sdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,17 @@ struct sdw_port_params {
unsigned int data_mode;
};

/**
* enum sdw_transport_type: Data Port transport type
*
* @SDW_TRANSPORT_MANAGER_PERIPHERAL: Data is exchanged between the Manager and a Peripheral
* @SDW_TRANSPORT_PERIPHERAL_PERIPHERAL: Data is exchanged between Peripherals
*/
enum sdw_transport_type {
SDW_TRANSPORT_MANAGER_PERIPHERAL = 0,
SDW_TRANSPORT_PERIPHERAL_PERIPHERAL = 1,
};

/**
* struct sdw_transport_params: Data Port Transport Parameters
*
Expand Down Expand Up @@ -873,6 +884,9 @@ struct sdw_bpt_msg;
* Bits 31:24 are reserved.
* @get_device_num: Callback for vendor-specific device_number allocation
* @put_device_num: Callback for vendor-specific device_number release
* @get_port: Reserve an available manager data port, or return a negative error.
* Called with bus_lock held.
* @put_port: Release a port reserved by get_port, with bus_lock held.
* @new_peripheral_assigned: Callback to handle enumeration of new peripheral.
* @bpt_send_async: reserve resources for BPT stream and send message
* using BTP protocol
Expand All @@ -891,6 +905,8 @@ struct sdw_master_ops {
u32 (*read_ping_status)(struct sdw_bus *bus);
int (*get_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
void (*put_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
int (*get_port)(struct sdw_bus *bus);
void (*put_port)(struct sdw_bus *bus, unsigned int port);
void (*new_peripheral_assigned)(struct sdw_bus *bus,
struct sdw_slave *slave,
int dev_num);
Expand Down Expand Up @@ -924,13 +940,15 @@ struct sdw_port_config {
* @bps: Number of bits per audio sample
* @direction: Data direction
* @type: Stream type PCM, PDM or BPT
* @transport_type: Manager-Peripheral (default) or Peripheral-Peripheral transport
*/
struct sdw_stream_config {
unsigned int frame_rate;
unsigned int ch_count;
unsigned int bps;
enum sdw_data_direction direction;
enum sdw_stream_type type;
enum sdw_transport_type transport_type;
};

/**
Expand Down Expand Up @@ -974,6 +992,7 @@ struct sdw_stream_params {
* @params: Stream parameters
* @state: Current state of the stream
* @type: Stream type PCM, PDM or BPT
* @transport_type: Manager-Peripheral or Peripheral-Peripheral transport
* @m_rt_count: Count of Master runtime(s) in this stream
* @master_list: List of Master runtime(s) in this stream.
* master_list can contain only one m_rt per Master instance
Expand All @@ -984,6 +1003,7 @@ struct sdw_stream_runtime {
struct sdw_stream_params params;
enum sdw_stream_state state;
enum sdw_stream_type type;
enum sdw_transport_type transport_type;
int m_rt_count;
struct list_head master_list;
};
Expand Down
Loading
Loading