Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Pierre-Louis Bossart and committed by
Vinod Koul
39d80b0e 23afc82f

+27 -14
+7 -9
drivers/soundwire/bus.c
··· 12 12 #include "sysfs_local.h" 13 13 14 14 static DEFINE_IDA(sdw_bus_ida); 15 - static DEFINE_IDA(sdw_peripheral_ida); 16 15 17 16 static int sdw_get_id(struct sdw_bus *bus) 18 17 { ··· 167 168 168 169 if (slave->dev_num) { /* clear dev_num if assigned */ 169 170 clear_bit(slave->dev_num, bus->assigned); 170 - if (bus->dev_num_ida_min) 171 - ida_free(&sdw_peripheral_ida, slave->dev_num); 171 + if (bus->ops && bus->ops->put_device_num) 172 + bus->ops->put_device_num(bus, slave); 172 173 } 173 174 list_del_init(&slave->node); 174 175 mutex_unlock(&bus->bus_lock); ··· 709 710 /* called with bus_lock held */ 710 711 static int sdw_get_device_num(struct sdw_slave *slave) 711 712 { 713 + struct sdw_bus *bus = slave->bus; 712 714 int bit; 713 715 714 - if (slave->bus->dev_num_ida_min) { 715 - bit = ida_alloc_range(&sdw_peripheral_ida, 716 - slave->bus->dev_num_ida_min, SDW_MAX_DEVICES, 717 - GFP_KERNEL); 716 + if (bus->ops && bus->ops->get_device_num) { 717 + bit = bus->ops->get_device_num(bus, slave); 718 718 if (bit < 0) 719 719 goto err; 720 720 } else { 721 - bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES); 721 + bit = find_first_zero_bit(bus->assigned, SDW_MAX_DEVICES); 722 722 if (bit == SDW_MAX_DEVICES) { 723 723 bit = -ENODEV; 724 724 goto err; ··· 728 730 * Do not update dev_num in Slave data structure here, 729 731 * Update once program dev_num is successful 730 732 */ 731 - set_bit(bit, slave->bus->assigned); 733 + set_bit(bit, bus->assigned); 732 734 733 735 err: 734 736 return bit;
+16 -1
drivers/soundwire/intel_auxdevice.c
··· 125 125 return 0; 126 126 } 127 127 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 + 128 142 static struct sdw_master_ops sdw_intel_ops = { 129 143 .read_prop = intel_prop_read, 130 144 .override_adr = sdw_dmi_override_adr, ··· 148 134 .pre_bank_switch = generic_pre_bank_switch, 149 135 .post_bank_switch = generic_post_bank_switch, 150 136 .read_ping_status = cdns_read_ping_status, 137 + .get_device_num = intel_get_device_num_ida, 138 + .put_device_num = intel_put_device_num_ida, 151 139 .new_peripheral_assigned = generic_new_peripheral_assigned, 152 140 }; 153 141 ··· 183 167 cdns->msg_count = 0; 184 168 185 169 bus->link_id = auxdev->id; 186 - bus->dev_num_ida_min = INTEL_DEV_NUM_IDA_MIN; 187 170 bus->clk_stop_timeout = 1; 188 171 189 172 sdw_cdns_probe(cdns);
+4 -4
include/linux/soundwire/sdw.h
··· 847 847 * @post_bank_switch: Callback for post bank switch 848 848 * @read_ping_status: Read status from PING frames, reported with two bits per Device. 849 849 * 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 850 852 * @new_peripheral_assigned: Callback to handle enumeration of new peripheral. 851 853 */ 852 854 struct sdw_master_ops { ··· 864 862 int (*pre_bank_switch)(struct sdw_bus *bus); 865 863 int (*post_bank_switch)(struct sdw_bus *bus); 866 864 u32 (*read_ping_status)(struct sdw_bus *bus); 865 + int (*get_device_num)(struct sdw_bus *bus, struct sdw_slave *slave); 866 + void (*put_device_num)(struct sdw_bus *bus, struct sdw_slave *slave); 867 867 void (*new_peripheral_assigned)(struct sdw_bus *bus, 868 868 struct sdw_slave *slave, 869 869 int dev_num); ··· 902 898 * meaningful if multi_link is set. If set to 1, hardware-based 903 899 * synchronization will be used even if a stream only uses a single 904 900 * SoundWire segment. 905 - * @dev_num_ida_min: if set, defines the minimum values for the IDA 906 - * used to allocate system-unique device numbers. This value needs to be 907 - * identical across all SoundWire bus in the system. 908 901 */ 909 902 struct sdw_bus { 910 903 struct device *dev; ··· 928 927 u32 bank_switch_timeout; 929 928 bool multi_link; 930 929 int hw_sync_min_links; 931 - int dev_num_ida_min; 932 930 }; 933 931 934 932 int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,