]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ASoC/soundwire: remove sdw_slave_extended_id
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Wed, 16 Oct 2024 10:23:24 +0000 (18:23 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 17 Oct 2024 17:42:10 +0000 (18:42 +0100)
This structure is used to copy information from the 'sdw_slave'
structures, it's better to create a flexible array of 'sdw_slave'
pointers and directly access the information. This will also help
access additional information stored in the 'sdw_slave' structure,
such as an SDCA context.

This patch does not add new functionality, it only modified how the
information is retrieved.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://patch.msgid.link/20241016102333.294448-3-yung-chuan.liao@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/soundwire/amd_init.c
drivers/soundwire/intel_init.c
include/linux/soundwire/sdw.h
include/linux/soundwire/sdw_amd.h
include/linux/soundwire/sdw_intel.h
include/sound/soc-acpi.h
sound/soc/amd/ps/pci-ps.c
sound/soc/soc-acpi.c
sound/soc/sof/amd/acp-common.c
sound/soc/sof/intel/hda.c

index db040f435059945b7564d63a20c10b42132efdd2..53d1d707ca1a7bcb0bd03a7de340418edf7f68bb 100644 (file)
@@ -177,7 +177,7 @@ EXPORT_SYMBOL_NS(sdw_amd_probe, SOUNDWIRE_AMD_INIT);
 void sdw_amd_exit(struct sdw_amd_ctx *ctx)
 {
        sdw_amd_cleanup(ctx);
-       kfree(ctx->ids);
+       kfree(ctx->peripherals);
        kfree(ctx);
 }
 EXPORT_SYMBOL_NS(sdw_amd_exit, SOUNDWIRE_AMD_INIT);
@@ -204,10 +204,11 @@ int sdw_amd_get_slave_info(struct sdw_amd_ctx *ctx)
                        num_slaves++;
        }
 
-       ctx->ids = kcalloc(num_slaves, sizeof(*ctx->ids), GFP_KERNEL);
-       if (!ctx->ids)
+       ctx->peripherals = kmalloc(struct_size(ctx->peripherals, array, num_slaves),
+                                  GFP_KERNEL);
+       if (!ctx->peripherals)
                return -ENOMEM;
-       ctx->num_slaves = num_slaves;
+       ctx->peripherals->num_peripherals = num_slaves;
        for (index = 0; index < ctx->count; index++) {
                if (!(ctx->link_mask & BIT(index)))
                        continue;
@@ -215,8 +216,7 @@ int sdw_amd_get_slave_info(struct sdw_amd_ctx *ctx)
                if (amd_manager) {
                        bus = &amd_manager->bus;
                        list_for_each_entry(slave, &bus->slaves, node) {
-                               ctx->ids[i].id = slave->id;
-                               ctx->ids[i].link_id = bus->link_id;
+                               ctx->peripherals->array[i] = slave;
                                i++;
                        }
                }
index a09134b97cd6667b0b5f6471cdff329cc1148ca4..12e7a98f319f8c870037f28916204110a2a91181 100644 (file)
@@ -252,17 +252,16 @@ static struct sdw_intel_ctx
                        num_slaves++;
        }
 
-       ctx->ids = kcalloc(num_slaves, sizeof(*ctx->ids), GFP_KERNEL);
-       if (!ctx->ids)
+       ctx->peripherals = kmalloc(struct_size(ctx->peripherals, array, num_slaves),
+                                  GFP_KERNEL);
+       if (!ctx->peripherals)
                goto err;
-
-       ctx->num_slaves = num_slaves;
+       ctx->peripherals->num_peripherals = num_slaves;
        i = 0;
        list_for_each_entry(link, &ctx->link_list, list) {
                bus = &link->cdns->bus;
                list_for_each_entry(slave, &bus->slaves, node) {
-                       ctx->ids[i].id = slave->id;
-                       ctx->ids[i].link_id = bus->link_id;
+                       ctx->peripherals->array[i] = slave;
                        i++;
                }
        }
@@ -371,7 +370,7 @@ void sdw_intel_exit(struct sdw_intel_ctx *ctx)
        }
 
        sdw_intel_cleanup(ctx);
-       kfree(ctx->ids);
+       kfree(ctx->peripherals);
        kfree(ctx->ldev);
        kfree(ctx);
 }
index 5e0dd47a041240fe7ec64c15c4f180c878fc231b..283c8bfdde49248ae12bf64b12d5af44fe46cb23 100644 (file)
@@ -488,9 +488,9 @@ struct sdw_slave_id {
        __u8 sdw_version:4;
 };
 
-struct sdw_extended_slave_id {
-       int link_id;
-       struct sdw_slave_id id;
+struct sdw_peripherals {
+       int num_peripherals;
+       struct sdw_slave *array[];
 };
 
 /*
index 28a4eb77717f987c1a389ff722632ed719e63f97..585b4c58a8a6f2b3b26f970b8a076eb8dce33823 100644 (file)
@@ -115,19 +115,16 @@ struct sdw_amd_acpi_info {
  * struct sdw_amd_ctx - context allocated by the controller driver probe
  *
  * @count: link count
- * @num_slaves: total number of devices exposed across all enabled links
  * @link_mask: bit-wise mask listing SoundWire links reported by the
  * Controller
- * @ids: array of slave_id, representing Slaves exposed across all enabled
- * links
  * @pdev: platform device structure
+ * @peripherals: array representing Peripherals exposed across all enabled links
  */
 struct sdw_amd_ctx {
        int count;
-       int num_slaves;
        u32 link_mask;
-       struct sdw_extended_slave_id *ids;
        struct platform_device *pdev[AMD_SDW_MAX_MANAGER_COUNT];
+       struct sdw_peripherals *peripherals;
 };
 
 /**
index fae345987b8cbb72efc046a4ec3d68f6f0e28963..491ddd27270fa1dabc67e3fe5ffb7e40fdd268de 100644 (file)
@@ -287,31 +287,28 @@ struct hdac_bus;
  * hardware capabilities after all power dependencies are settled.
  * @link_mask: bit-wise mask listing SoundWire links reported by the
  * Controller
- * @num_slaves: total number of devices exposed across all enabled links
  * @handle: ACPI parent handle
  * @ldev: information for each link (controller-specific and kept
  * opaque here)
- * @ids: array of slave_id, representing Slaves exposed across all enabled
- * links
  * @link_list: list to handle interrupts across all links
  * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers.
  * @shim_mask: flags to track initialization of SHIM shared registers
  * @shim_base: sdw shim base.
  * @alh_base: sdw alh base.
+ * @peripherals: array representing Peripherals exposed across all enabled links
  */
 struct sdw_intel_ctx {
        int count;
        void __iomem *mmio_base;
        u32 link_mask;
-       int num_slaves;
        acpi_handle handle;
        struct sdw_intel_link_dev **ldev;
-       struct sdw_extended_slave_id *ids;
        struct list_head link_list;
        struct mutex shim_lock; /* lock for access to shared SHIM registers */
        u32 shim_mask;
        u32 shim_base;
        u32 alh_base;
+       struct sdw_peripherals *peripherals;
 };
 
 /**
index 60d3b86a4660ff6379c4afabd61dece8042f894b..ac7f9e791ee183ea4e868d787644aecd4735cec7 100644 (file)
@@ -233,7 +233,6 @@ static inline bool snd_soc_acpi_sof_parent(struct device *dev)
 
 bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
                                        const struct snd_soc_acpi_link_adr *link,
-                                       struct sdw_extended_slave_id *ids,
-                                       int num_slaves);
+                                       struct sdw_peripherals *peripherals);
 
 #endif
index c72d666d51bdf426897dca3b61379642543f09cb..4365499c8f82a41f245a1434ba87ed4ac2a6e512 100644 (file)
@@ -302,8 +302,7 @@ static struct snd_soc_acpi_mach *acp63_sdw_machine_select(struct device *dev)
                        link = mach->links;
                        for (i = 0; i < acp_data->info.count && link->num_adr; link++, i++) {
                                if (!snd_soc_acpi_sdw_link_slaves_found(dev, link,
-                                                                       acp_data->sdw->ids,
-                                                                       acp_data->sdw->num_slaves))
+                                                                       acp_data->sdw->peripherals))
                                        break;
                        }
                        if (i == acp_data->info.count || !link->num_adr)
index 6d693b2ad5a35bee0a41b9709e40edb40a0392f5..270f9777942f0223880af740e3aedc1d1619a0b6 100644 (file)
@@ -131,8 +131,7 @@ EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
 /* Check if all Slaves defined on the link can be found */
 bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
                                        const struct snd_soc_acpi_link_adr *link,
-                                       struct sdw_extended_slave_id *ids,
-                                       int num_slaves)
+                                       struct sdw_peripherals *peripherals)
 {
        unsigned int part_id, link_id, unique_id, mfg_id, version;
        int i, j, k;
@@ -146,22 +145,25 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
                link_id = SDW_DISCO_LINK_ID(adr);
                version = SDW_VERSION(adr);
 
-               for (j = 0; j < num_slaves; j++) {
+               for (j = 0; j < peripherals->num_peripherals; j++) {
+                       struct sdw_slave *peripheral = peripherals->array[j];
+
                        /* find out how many identical parts were reported on that link */
-                       if (ids[j].link_id == link_id &&
-                           ids[j].id.part_id == part_id &&
-                           ids[j].id.mfg_id == mfg_id &&
-                           ids[j].id.sdw_version == version)
+                       if (peripheral->bus->link_id == link_id &&
+                           peripheral->id.part_id == part_id &&
+                           peripheral->id.mfg_id == mfg_id &&
+                           peripheral->id.sdw_version == version)
                                reported_part_count++;
                }
 
-               for (j = 0; j < num_slaves; j++) {
+               for (j = 0; j < peripherals->num_peripherals; j++) {
+                       struct sdw_slave *peripheral = peripherals->array[j];
                        int expected_part_count = 0;
 
-                       if (ids[j].link_id != link_id ||
-                           ids[j].id.part_id != part_id ||
-                           ids[j].id.mfg_id != mfg_id ||
-                           ids[j].id.sdw_version != version)
+                       if (peripheral->bus->link_id != link_id ||
+                           peripheral->id.part_id != part_id ||
+                           peripheral->id.mfg_id != mfg_id ||
+                           peripheral->id.sdw_version != version)
                                continue;
 
                        /* find out how many identical parts are expected */
@@ -180,7 +182,7 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
                                 */
                                unique_id = SDW_UNIQUE_ID(adr);
                                if (reported_part_count == 1 ||
-                                   ids[j].id.unique_id == unique_id) {
+                                   peripheral->id.unique_id == unique_id) {
                                        dev_dbg(dev, "found part_id %#x at link %d\n", part_id, link_id);
                                        break;
                                }
@@ -189,7 +191,7 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
                                        part_id, reported_part_count, expected_part_count, link_id);
                        }
                }
-               if (j == num_slaves) {
+               if (j == peripherals->num_peripherals) {
                        dev_dbg(dev, "Slave part_id %#x not found\n", part_id);
                        return false;
                }
index dbcaac84cb73afacc432900e2d1b6766354ba2e0..fc792956bb97626af68f1456f6e2b8fdb8df773b 100644 (file)
@@ -145,8 +145,7 @@ static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev *
                        link = mach->links;
                        for (i = 0; i < acp_data->info.count && link->num_adr; link++, i++) {
                                if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link,
-                                                                       acp_data->sdw->ids,
-                                                                       acp_data->sdw->num_slaves))
+                                                                       acp_data->sdw->peripherals))
                                        break;
                        }
                        if (i == acp_data->info.count || !link->num_adr)
index e4cb4ffc7270486a6a1fb8e3ccd3cef3f9f1a8d2..9abc4c071ae52ec7795c8eb25a72a29669b77f08 100644 (file)
@@ -1064,7 +1064,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
 {
        struct snd_sof_pdata *pdata = sdev->pdata;
        const struct snd_soc_acpi_link_adr *link;
-       struct sdw_extended_slave_id *ids;
+       struct sdw_peripherals *peripherals;
        struct snd_soc_acpi_mach *mach;
        struct sof_intel_hda_dev *hdev;
        u32 link_mask;
@@ -1083,7 +1083,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
                return NULL;
        }
 
-       if (!hdev->sdw->num_slaves) {
+       if (!hdev->sdw->peripherals || !hdev->sdw->peripherals->num_peripherals) {
                dev_warn(sdev->dev, "No SoundWire peripheral detected in ACPI tables\n");
                return NULL;
        }
@@ -1119,8 +1119,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
                         * are not found on this link.
                         */
                        if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link,
-                                                               hdev->sdw->ids,
-                                                               hdev->sdw->num_slaves))
+                                                               hdev->sdw->peripherals))
                                break;
                }
                /* Found if all Slaves are checked */
@@ -1136,10 +1135,13 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
        }
 
        dev_info(sdev->dev, "No SoundWire machine driver found for the ACPI-reported configuration:\n");
-       ids = hdev->sdw->ids;
-       for (i = 0; i < hdev->sdw->num_slaves; i++)
+       peripherals = hdev->sdw->peripherals;
+       for (i = 0; i < peripherals->num_peripherals; i++)
                dev_info(sdev->dev, "link %d mfg_id 0x%04x part_id 0x%04x version %#x\n",
-                        ids[i].link_id, ids[i].id.mfg_id, ids[i].id.part_id, ids[i].id.sdw_version);
+                        peripherals->array[i]->bus->link_id,
+                        peripherals->array[i]->id.mfg_id,
+                        peripherals->array[i]->id.part_id,
+                        peripherals->array[i]->id.sdw_version);
 
        return NULL;
 }