Skip to content

Commit ca2a06c

Browse files
plbossartbardliao
authored andcommitted
ASoC/soundwire: remove sdw_slave_extended_id
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>
1 parent 1718310 commit ca2a06c

10 files changed

Lines changed: 47 additions & 53 deletions

File tree

drivers/soundwire/amd_init.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ EXPORT_SYMBOL_NS(sdw_amd_probe, SOUNDWIRE_AMD_INIT);
178178
void sdw_amd_exit(struct sdw_amd_ctx *ctx)
179179
{
180180
sdw_amd_cleanup(ctx);
181-
kfree(ctx->ids);
181+
kfree(ctx->peripherals);
182182
kfree(ctx);
183183
}
184184
EXPORT_SYMBOL_NS(sdw_amd_exit, SOUNDWIRE_AMD_INIT);
@@ -205,19 +205,19 @@ int sdw_amd_get_slave_info(struct sdw_amd_ctx *ctx)
205205
num_slaves++;
206206
}
207207

208-
ctx->ids = kcalloc(num_slaves, sizeof(*ctx->ids), GFP_KERNEL);
209-
if (!ctx->ids)
208+
ctx->peripherals = kmalloc(struct_size(ctx->peripherals, array, num_slaves),
209+
GFP_KERNEL);
210+
if (!ctx->peripherals)
210211
return -ENOMEM;
211-
ctx->num_slaves = num_slaves;
212+
ctx->peripherals->num_peripherals = num_slaves;
212213
for (index = 0; index < ctx->count; index++) {
213214
if (!(ctx->link_mask & BIT(index)))
214215
continue;
215216
amd_manager = dev_get_drvdata(&ctx->pdev[index]->dev);
216217
if (amd_manager) {
217218
bus = &amd_manager->bus;
218219
list_for_each_entry(slave, &bus->slaves, node) {
219-
ctx->ids[i].id = slave->id;
220-
ctx->ids[i].link_id = bus->link_id;
220+
ctx->peripherals->array[i] = slave;
221221
i++;
222222
}
223223
}

drivers/soundwire/intel_init.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,16 @@ static struct sdw_intel_ctx
252252
num_slaves++;
253253
}
254254

255-
ctx->ids = kcalloc(num_slaves, sizeof(*ctx->ids), GFP_KERNEL);
256-
if (!ctx->ids)
255+
ctx->peripherals = kmalloc(struct_size(ctx->peripherals, array, num_slaves),
256+
GFP_KERNEL);
257+
if (!ctx->peripherals)
257258
goto err;
258-
259-
ctx->num_slaves = num_slaves;
259+
ctx->peripherals->num_peripherals = num_slaves;
260260
i = 0;
261261
list_for_each_entry(link, &ctx->link_list, list) {
262262
bus = &link->cdns->bus;
263263
list_for_each_entry(slave, &bus->slaves, node) {
264-
ctx->ids[i].id = slave->id;
265-
ctx->ids[i].link_id = bus->link_id;
264+
ctx->peripherals->array[i] = slave;
266265
i++;
267266
}
268267
}
@@ -371,7 +370,7 @@ void sdw_intel_exit(struct sdw_intel_ctx *ctx)
371370
}
372371

373372
sdw_intel_cleanup(ctx);
374-
kfree(ctx->ids);
373+
kfree(ctx->peripherals);
375374
kfree(ctx->ldev);
376375
kfree(ctx);
377376
}

include/linux/soundwire/sdw.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ struct sdw_slave_id {
472472
__u8 sdw_version:4;
473473
};
474474

475-
struct sdw_extended_slave_id {
476-
int link_id;
477-
struct sdw_slave_id id;
475+
struct sdw_peripherals {
476+
int num_peripherals;
477+
struct sdw_slave *array[];
478478
};
479479

480480
/*

include/linux/soundwire/sdw_amd.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,16 @@ struct sdw_amd_acpi_info {
119119
* struct sdw_amd_ctx - context allocated by the controller driver probe
120120
*
121121
* @count: link count
122-
* @num_slaves: total number of devices exposed across all enabled links
123122
* @link_mask: bit-wise mask listing SoundWire links reported by the
124123
* Controller
125-
* @ids: array of slave_id, representing Slaves exposed across all enabled
126-
* links
127124
* @pdev: platform device structure
125+
* @peripherals: array representing Peripherals exposed across all enabled links
128126
*/
129127
struct sdw_amd_ctx {
130128
int count;
131-
int num_slaves;
132129
u32 link_mask;
133-
struct sdw_extended_slave_id *ids;
134130
struct platform_device *pdev[AMD_SDW_MAX_MANAGER_COUNT];
131+
struct sdw_peripherals *peripherals;
135132
};
136133

137134
/**

include/linux/soundwire/sdw_intel.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,31 +287,28 @@ struct hdac_bus;
287287
* hardware capabilities after all power dependencies are settled.
288288
* @link_mask: bit-wise mask listing SoundWire links reported by the
289289
* Controller
290-
* @num_slaves: total number of devices exposed across all enabled links
291290
* @handle: ACPI parent handle
292291
* @ldev: information for each link (controller-specific and kept
293292
* opaque here)
294-
* @ids: array of slave_id, representing Slaves exposed across all enabled
295-
* links
296293
* @link_list: list to handle interrupts across all links
297294
* @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers.
298295
* @shim_mask: flags to track initialization of SHIM shared registers
299296
* @shim_base: sdw shim base.
300297
* @alh_base: sdw alh base.
298+
* @peripherals: array representing Peripherals exposed across all enabled links
301299
*/
302300
struct sdw_intel_ctx {
303301
int count;
304302
void __iomem *mmio_base;
305303
u32 link_mask;
306-
int num_slaves;
307304
acpi_handle handle;
308305
struct sdw_intel_link_dev **ldev;
309-
struct sdw_extended_slave_id *ids;
310306
struct list_head link_list;
311307
struct mutex shim_lock; /* lock for access to shared SHIM registers */
312308
u32 shim_mask;
313309
u32 shim_base;
314310
u32 alh_base;
311+
struct sdw_peripherals *peripherals;
315312
};
316313

317314
/**

include/sound/soc-acpi.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ static inline bool snd_soc_acpi_sof_parent(struct device *dev)
233233

234234
bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
235235
const struct snd_soc_acpi_link_adr *link,
236-
struct sdw_extended_slave_id *ids,
237-
int num_slaves);
236+
struct sdw_peripherals *peripherals);
238237

239238
#endif

sound/soc/amd/ps/pci-ps.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ static struct snd_soc_acpi_mach *acp63_sdw_machine_select(struct device *dev)
303303
link = mach->links;
304304
for (i = 0; i < acp_data->info.count && link->num_adr; link++, i++) {
305305
if (!snd_soc_acpi_sdw_link_slaves_found(dev, link,
306-
acp_data->sdw->ids,
307-
acp_data->sdw->num_slaves))
306+
acp_data->sdw->peripherals))
308307
break;
309308
}
310309
if (i == acp_data->info.count || !link->num_adr)

sound/soc/soc-acpi.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
131131
/* Check if all Slaves defined on the link can be found */
132132
bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
133133
const struct snd_soc_acpi_link_adr *link,
134-
struct sdw_extended_slave_id *ids,
135-
int num_slaves)
134+
struct sdw_peripherals *peripherals)
136135
{
137136
unsigned int part_id, link_id, unique_id, mfg_id, version;
138137
int i, j, k;
@@ -146,22 +145,25 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
146145
link_id = SDW_DISCO_LINK_ID(adr);
147146
version = SDW_VERSION(adr);
148147

149-
for (j = 0; j < num_slaves; j++) {
148+
for (j = 0; j < peripherals->num_peripherals; j++) {
149+
struct sdw_slave *peripheral = peripherals->array[j];
150+
150151
/* find out how many identical parts were reported on that link */
151-
if (ids[j].link_id == link_id &&
152-
ids[j].id.part_id == part_id &&
153-
ids[j].id.mfg_id == mfg_id &&
154-
ids[j].id.sdw_version == version)
152+
if (peripheral->bus->link_id == link_id &&
153+
peripheral->id.part_id == part_id &&
154+
peripheral->id.mfg_id == mfg_id &&
155+
peripheral->id.sdw_version == version)
155156
reported_part_count++;
156157
}
157158

158-
for (j = 0; j < num_slaves; j++) {
159+
for (j = 0; j < peripherals->num_peripherals; j++) {
160+
struct sdw_slave *peripheral = peripherals->array[j];
159161
int expected_part_count = 0;
160162

161-
if (ids[j].link_id != link_id ||
162-
ids[j].id.part_id != part_id ||
163-
ids[j].id.mfg_id != mfg_id ||
164-
ids[j].id.sdw_version != version)
163+
if (peripheral->bus->link_id != link_id ||
164+
peripheral->id.part_id != part_id ||
165+
peripheral->id.mfg_id != mfg_id ||
166+
peripheral->id.sdw_version != version)
165167
continue;
166168

167169
/* find out how many identical parts are expected */
@@ -180,7 +182,7 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
180182
*/
181183
unique_id = SDW_UNIQUE_ID(adr);
182184
if (reported_part_count == 1 ||
183-
ids[j].id.unique_id == unique_id) {
185+
peripheral->id.unique_id == unique_id) {
184186
dev_dbg(dev, "found part_id %#x at link %d\n", part_id, link_id);
185187
break;
186188
}
@@ -189,7 +191,7 @@ bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
189191
part_id, reported_part_count, expected_part_count, link_id);
190192
}
191193
}
192-
if (j == num_slaves) {
194+
if (j == peripherals->num_peripherals) {
193195
dev_dbg(dev, "Slave part_id %#x not found\n", part_id);
194196
return false;
195197
}

sound/soc/sof/amd/acp-common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev *
145145
link = mach->links;
146146
for (i = 0; i < acp_data->info.count && link->num_adr; link++, i++) {
147147
if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link,
148-
acp_data->sdw->ids,
149-
acp_data->sdw->num_slaves))
148+
acp_data->sdw->peripherals))
150149
break;
151150
}
152151
if (i == acp_data->info.count || !link->num_adr)

sound/soc/sof/intel/hda.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
10701070
{
10711071
struct snd_sof_pdata *pdata = sdev->pdata;
10721072
const struct snd_soc_acpi_link_adr *link;
1073-
struct sdw_extended_slave_id *ids;
1073+
struct sdw_peripherals *peripherals;
10741074
struct snd_soc_acpi_mach *mach;
10751075
struct sof_intel_hda_dev *hdev;
10761076
u32 link_mask;
@@ -1089,7 +1089,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
10891089
return NULL;
10901090
}
10911091

1092-
if (!hdev->sdw->num_slaves) {
1092+
if (!hdev->sdw->peripherals || !hdev->sdw->peripherals->num_peripherals) {
10931093
dev_warn(sdev->dev, "No SoundWire peripheral detected in ACPI tables\n");
10941094
return NULL;
10951095
}
@@ -1125,8 +1125,7 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
11251125
* are not found on this link.
11261126
*/
11271127
if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link,
1128-
hdev->sdw->ids,
1129-
hdev->sdw->num_slaves))
1128+
hdev->sdw->peripherals))
11301129
break;
11311130
}
11321131
/* Found if all Slaves are checked */
@@ -1142,10 +1141,13 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
11421141
}
11431142

11441143
dev_info(sdev->dev, "No SoundWire machine driver found for the ACPI-reported configuration:\n");
1145-
ids = hdev->sdw->ids;
1146-
for (i = 0; i < hdev->sdw->num_slaves; i++)
1144+
peripherals = hdev->sdw->peripherals;
1145+
for (i = 0; i < peripherals->num_peripherals; i++)
11471146
dev_info(sdev->dev, "link %d mfg_id 0x%04x part_id 0x%04x version %#x\n",
1148-
ids[i].link_id, ids[i].id.mfg_id, ids[i].id.part_id, ids[i].id.sdw_version);
1147+
peripherals->array[i]->bus->link_id,
1148+
peripherals->array[i]->id.mfg_id,
1149+
peripherals->array[i]->id.part_id,
1150+
peripherals->array[i]->id.sdw_version);
11491151

11501152
return NULL;
11511153
}

0 commit comments

Comments
 (0)