Skip to content

Commit 0ca645a

Browse files
simontrimmerbroonie
authored andcommitted
spi: cs42l43: Add speaker id support to the bridge configuration
OEMs can connect a number of types of speakers to the sidecar cs35l56 amplifiers and a different speaker requires a different firmware configuration. When the cs42l43 ACPI includes a property indicating a particular type of speaker has been installed this should be passed to the cs35l56 driver instances as a device property. Signed-off-by: Simon Trimmer <[email protected]> Signed-off-by: Charles Keepax <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent cc169cf commit 0ca645a

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed

drivers/spi/spi-cs42l43.c

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,10 @@ static const unsigned int cs42l43_clock_divs[] = {
4545
2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
4646
};
4747

48-
static const struct software_node ampl = {
49-
.name = "cs35l56-left",
50-
};
51-
52-
static const struct software_node ampr = {
53-
.name = "cs35l56-right",
54-
};
55-
56-
static struct spi_board_info ampl_info = {
48+
static struct spi_board_info amp_info_template = {
5749
.modalias = "cs35l56",
5850
.max_speed_hz = 11 * HZ_PER_MHZ,
59-
.chip_select = 0,
6051
.mode = SPI_MODE_0,
61-
.swnode = &ampl,
62-
};
63-
64-
static struct spi_board_info ampr_info = {
65-
.modalias = "cs35l56",
66-
.max_speed_hz = 11 * HZ_PER_MHZ,
67-
.chip_select = 1,
68-
.mode = SPI_MODE_0,
69-
.swnode = &ampr,
7052
};
7153

7254
static const struct software_node cs42l43_gpiochip_swnode = {
@@ -274,6 +256,39 @@ static struct fwnode_handle *cs42l43_find_xu_node(struct fwnode_handle *fwnode)
274256
return NULL;
275257
}
276258

259+
static struct spi_board_info *cs42l43_create_bridge_amp(struct cs42l43_spi *priv,
260+
const char * const name,
261+
int cs, int spkid)
262+
{
263+
struct property_entry *props = NULL;
264+
struct software_node *swnode;
265+
struct spi_board_info *info;
266+
267+
if (spkid >= 0) {
268+
props = devm_kmalloc(priv->dev, sizeof(*props), GFP_KERNEL);
269+
if (!props)
270+
return NULL;
271+
272+
*props = PROPERTY_ENTRY_U32("cirrus,speaker-id", spkid);
273+
}
274+
275+
swnode = devm_kmalloc(priv->dev, sizeof(*swnode), GFP_KERNEL);
276+
if (!swnode)
277+
return NULL;
278+
279+
*swnode = SOFTWARE_NODE(name, props, NULL);
280+
281+
info = devm_kmemdup(priv->dev, &amp_info_template,
282+
sizeof(amp_info_template), GFP_KERNEL);
283+
if (!info)
284+
return NULL;
285+
286+
info->chip_select = cs;
287+
info->swnode = swnode;
288+
289+
return info;
290+
}
291+
277292
static void cs42l43_release_of_node(void *data)
278293
{
279294
fwnode_handle_put(data);
@@ -368,11 +383,27 @@ static int cs42l43_spi_probe(struct platform_device *pdev)
368383
"Failed to register SPI controller\n");
369384

370385
if (nsidecars) {
371-
if (!spi_new_device(priv->ctlr, &ampl_info))
386+
struct spi_board_info *ampl_info;
387+
struct spi_board_info *ampr_info;
388+
int spkid = -EINVAL;
389+
390+
fwnode_property_read_u32(xu_fwnode, "01fa-spk-id-val", &spkid);
391+
392+
dev_dbg(priv->dev, "Found speaker ID %d\n", spkid);
393+
394+
ampl_info = cs42l43_create_bridge_amp(priv, "cs35l56-left", 0, spkid);
395+
if (!ampl_info)
396+
return -ENOMEM;
397+
398+
ampr_info = cs42l43_create_bridge_amp(priv, "cs35l56-right", 1, spkid);
399+
if (!ampr_info)
400+
return -ENOMEM;
401+
402+
if (!spi_new_device(priv->ctlr, ampl_info))
372403
return dev_err_probe(priv->dev, -ENODEV,
373404
"Failed to create left amp slave\n");
374405

375-
if (!spi_new_device(priv->ctlr, &ampr_info))
406+
if (!spi_new_device(priv->ctlr, ampr_info))
376407
return dev_err_probe(priv->dev, -ENODEV,
377408
"Failed to create right amp slave\n");
378409
}

0 commit comments

Comments
 (0)