Skip to content

Commit 39d80b0

Browse files
plbossartvinodkoul
authored andcommitted
soundwire: bus: add callbacks for device_number allocation
Rather than add logic in the core for vendor-specific usages, add callbacks for vendor-specific device_number allocation and release. This patch only moves the existing IDA-based allocator used only by Intel to the intel_auxdevice.c file and does not change the functionality. Follow-up patches will extend the behavior by modifying the Intel callbacks. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Rander Wang <rander.wang@intel.com> Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com> Link: https://lore.kernel.org/r/20230731091333.3593132-3-yung-chuan.liao@linux.intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 23afc82 commit 39d80b0

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

drivers/soundwire/bus.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "sysfs_local.h"
1313

1414
static DEFINE_IDA(sdw_bus_ida);
15-
static DEFINE_IDA(sdw_peripheral_ida);
1615

1716
static int sdw_get_id(struct sdw_bus *bus)
1817
{
@@ -168,8 +167,8 @@ static int sdw_delete_slave(struct device *dev, void *data)
168167

169168
if (slave->dev_num) { /* clear dev_num if assigned */
170169
clear_bit(slave->dev_num, bus->assigned);
171-
if (bus->dev_num_ida_min)
172-
ida_free(&sdw_peripheral_ida, slave->dev_num);
170+
if (bus->ops && bus->ops->put_device_num)
171+
bus->ops->put_device_num(bus, slave);
173172
}
174173
list_del_init(&slave->node);
175174
mutex_unlock(&bus->bus_lock);
@@ -710,16 +709,15 @@ EXPORT_SYMBOL(sdw_compare_devid);
710709
/* called with bus_lock held */
711710
static int sdw_get_device_num(struct sdw_slave *slave)
712711
{
712+
struct sdw_bus *bus = slave->bus;
713713
int bit;
714714

715-
if (slave->bus->dev_num_ida_min) {
716-
bit = ida_alloc_range(&sdw_peripheral_ida,
717-
slave->bus->dev_num_ida_min, SDW_MAX_DEVICES,
718-
GFP_KERNEL);
715+
if (bus->ops && bus->ops->get_device_num) {
716+
bit = bus->ops->get_device_num(bus, slave);
719717
if (bit < 0)
720718
goto err;
721719
} else {
722-
bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES);
720+
bit = find_first_zero_bit(bus->assigned, SDW_MAX_DEVICES);
723721
if (bit == SDW_MAX_DEVICES) {
724722
bit = -ENODEV;
725723
goto err;
@@ -730,7 +728,7 @@ static int sdw_get_device_num(struct sdw_slave *slave)
730728
* Do not update dev_num in Slave data structure here,
731729
* Update once program dev_num is successful
732730
*/
733-
set_bit(bit, slave->bus->assigned);
731+
set_bit(bit, bus->assigned);
734732

735733
err:
736734
return bit;

drivers/soundwire/intel_auxdevice.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ static int intel_prop_read(struct sdw_bus *bus)
125125
return 0;
126126
}
127127

128+
static DEFINE_IDA(intel_peripheral_ida);
129+
130+
static int intel_get_device_num_ida(struct sdw_bus *bus, struct sdw_slave *slave)
131+
{
132+
return ida_alloc_range(&intel_peripheral_ida,
133+
INTEL_DEV_NUM_IDA_MIN, SDW_MAX_DEVICES,
134+
GFP_KERNEL);
135+
}
136+
137+
static void intel_put_device_num_ida(struct sdw_bus *bus, struct sdw_slave *slave)
138+
{
139+
return ida_free(&intel_peripheral_ida, slave->dev_num);
140+
}
141+
128142
static struct sdw_master_ops sdw_intel_ops = {
129143
.read_prop = intel_prop_read,
130144
.override_adr = sdw_dmi_override_adr,
@@ -134,6 +148,8 @@ static struct sdw_master_ops sdw_intel_ops = {
134148
.pre_bank_switch = generic_pre_bank_switch,
135149
.post_bank_switch = generic_post_bank_switch,
136150
.read_ping_status = cdns_read_ping_status,
151+
.get_device_num = intel_get_device_num_ida,
152+
.put_device_num = intel_put_device_num_ida,
137153
.new_peripheral_assigned = generic_new_peripheral_assigned,
138154
};
139155

@@ -167,7 +183,6 @@ static int intel_link_probe(struct auxiliary_device *auxdev,
167183
cdns->msg_count = 0;
168184

169185
bus->link_id = auxdev->id;
170-
bus->dev_num_ida_min = INTEL_DEV_NUM_IDA_MIN;
171186
bus->clk_stop_timeout = 1;
172187

173188
sdw_cdns_probe(cdns);

include/linux/soundwire/sdw.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,8 @@ struct sdw_defer {
847847
* @post_bank_switch: Callback for post bank switch
848848
* @read_ping_status: Read status from PING frames, reported with two bits per Device.
849849
* Bits 31:24 are reserved.
850+
* @get_device_num: Callback for vendor-specific device_number allocation
851+
* @put_device_num: Callback for vendor-specific device_number release
850852
* @new_peripheral_assigned: Callback to handle enumeration of new peripheral.
851853
*/
852854
struct sdw_master_ops {
@@ -862,6 +864,8 @@ struct sdw_master_ops {
862864
int (*pre_bank_switch)(struct sdw_bus *bus);
863865
int (*post_bank_switch)(struct sdw_bus *bus);
864866
u32 (*read_ping_status)(struct sdw_bus *bus);
867+
int (*get_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
868+
void (*put_device_num)(struct sdw_bus *bus, struct sdw_slave *slave);
865869
void (*new_peripheral_assigned)(struct sdw_bus *bus,
866870
struct sdw_slave *slave,
867871
int dev_num);
@@ -898,9 +902,6 @@ struct sdw_master_ops {
898902
* meaningful if multi_link is set. If set to 1, hardware-based
899903
* synchronization will be used even if a stream only uses a single
900904
* SoundWire segment.
901-
* @dev_num_ida_min: if set, defines the minimum values for the IDA
902-
* used to allocate system-unique device numbers. This value needs to be
903-
* identical across all SoundWire bus in the system.
904905
*/
905906
struct sdw_bus {
906907
struct device *dev;
@@ -927,7 +928,6 @@ struct sdw_bus {
927928
u32 bank_switch_timeout;
928929
bool multi_link;
929930
int hw_sync_min_links;
930-
int dev_num_ida_min;
931931
};
932932

933933
int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,

0 commit comments

Comments
 (0)