Skip to content

Commit 8c286a0

Browse files
Lucas Tanuretiwai
authored andcommitted
ALSA: hda: cs35l41: Tidyup code
Clean up and simplify cs35l41_hda_bind function Signed-off-by: Lucas Tanure <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent a025df0 commit 8c286a0

File tree

4 files changed

+49
-54
lines changed

4 files changed

+49
-54
lines changed

sound/pci/hda/cs35l41_hda.c

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
//
3-
// cs35l41.c -- CS35l41 ALSA HDA audio driver
3+
// CS35l41 ALSA HDA audio driver
44
//
55
// Copyright 2021 Cirrus Logic, Inc.
66
//
@@ -17,19 +17,19 @@
1717
#include "cs35l41_hda.h"
1818

1919
static const struct reg_sequence cs35l41_hda_config[] = {
20-
{ CS35L41_PLL_CLK_CTRL, 0x00000430 }, //3200000Hz, BCLK Input, PLL_REFCLK_EN = 1
21-
{ CS35L41_GLOBAL_CLK_CTRL, 0x00000003 }, //GLOBAL_FS = 48 kHz
22-
{ CS35L41_SP_ENABLES, 0x00010000 }, //ASP_RX1_EN = 1
23-
{ CS35L41_SP_RATE_CTRL, 0x00000021 }, //ASP_BCLK_FREQ = 3.072 MHz
24-
{ CS35L41_SP_FORMAT, 0x20200200 }, //24 bits, I2S, BCLK Slave, FSYNC Slave
25-
{ CS35L41_DAC_PCM1_SRC, 0x00000008 }, //DACPCM1_SRC = ASPRX1
26-
{ CS35L41_AMP_DIG_VOL_CTRL, 0x00000000 }, //AMP_VOL_PCM 0.0 dB
27-
{ CS35L41_AMP_GAIN_CTRL, 0x00000084 }, //AMP_GAIN_PCM 4.5 dB
28-
{ CS35L41_PWR_CTRL2, 0x00000001 }, //AMP_EN = 1
20+
{ CS35L41_PLL_CLK_CTRL, 0x00000430 }, // 3200000Hz, BCLK Input, PLL_REFCLK_EN = 1
21+
{ CS35L41_GLOBAL_CLK_CTRL, 0x00000003 }, // GLOBAL_FS = 48 kHz
22+
{ CS35L41_SP_ENABLES, 0x00010000 }, // ASP_RX1_EN = 1
23+
{ CS35L41_SP_RATE_CTRL, 0x00000021 }, // ASP_BCLK_FREQ = 3.072 MHz
24+
{ CS35L41_SP_FORMAT, 0x20200200 }, // 24 bits, I2S, BCLK Slave, FSYNC Slave
25+
{ CS35L41_DAC_PCM1_SRC, 0x00000008 }, // DACPCM1_SRC = ASPRX1
26+
{ CS35L41_AMP_DIG_VOL_CTRL, 0x00000000 }, // AMP_VOL_PCM 0.0 dB
27+
{ CS35L41_AMP_GAIN_CTRL, 0x00000084 }, // AMP_GAIN_PCM 4.5 dB
28+
{ CS35L41_PWR_CTRL2, 0x00000001 }, // AMP_EN = 1
2929
};
3030

3131
static const struct reg_sequence cs35l41_hda_start_bst[] = {
32-
{ CS35L41_PWR_CTRL2, 0x00000021 }, //BST_EN = 10, AMP_EN = 1
32+
{ CS35L41_PWR_CTRL2, 0x00000021 }, // BST_EN = 10, AMP_EN = 1
3333
{ CS35L41_PWR_CTRL1, 0x00000001, 3000}, // set GLOBAL_EN = 1
3434
};
3535

@@ -60,7 +60,7 @@ static const struct reg_sequence cs35l41_stop_ext_vspk[] = {
6060
{ 0x00000040, 0x00000055 },
6161
{ 0x00000040, 0x000000AA },
6262
{ 0x00007438, 0x00585941 },
63-
{ 0x00002014, 0x00000000, 3000}, //set GLOBAL_EN = 0
63+
{ 0x00002014, 0x00000000, 3000}, // set GLOBAL_EN = 0
6464
{ 0x0000742C, 0x00000009 },
6565
{ 0x00007438, 0x00580941 },
6666
{ 0x00011008, 0x00000001 },
@@ -78,7 +78,7 @@ static const struct reg_sequence cs35l41_safe_to_active[] = {
7878
{ 0x0000742C, 0x0000000F },
7979
{ 0x0000742C, 0x00000079 },
8080
{ 0x00007438, 0x00585941 },
81-
{ CS35L41_PWR_CTRL1, 0x00000001, 2000 }, //GLOBAL_EN = 1
81+
{ CS35L41_PWR_CTRL1, 0x00000001, 2000 }, // GLOBAL_EN = 1
8282
{ 0x0000742C, 0x000000F9 },
8383
{ 0x00007438, 0x00580941 },
8484
{ 0x00000040, 0x000000CC },
@@ -89,8 +89,8 @@ static const struct reg_sequence cs35l41_active_to_safe[] = {
8989
{ 0x00000040, 0x00000055 },
9090
{ 0x00000040, 0x000000AA },
9191
{ 0x00007438, 0x00585941 },
92-
{ CS35L41_AMP_DIG_VOL_CTRL, 0x0000A678 }, //AMP_VOL_PCM Mute
93-
{ CS35L41_PWR_CTRL2, 0x00000000 }, //AMP_EN = 0
92+
{ CS35L41_AMP_DIG_VOL_CTRL, 0x0000A678 }, // AMP_VOL_PCM Mute
93+
{ CS35L41_PWR_CTRL2, 0x00000000 }, // AMP_EN = 0
9494
{ CS35L41_PWR_CTRL1, 0x00000000 },
9595
{ 0x0000742C, 0x00000009, 2000 },
9696
{ 0x00007438, 0x00580941 },
@@ -168,7 +168,6 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
168168

169169
if (ret)
170170
dev_warn(cs35l41->dev, "Failed to apply multi reg write: %d\n", ret);
171-
172171
}
173172

174173
static int cs35l41_hda_channel_map(struct device *dev, unsigned int tx_num, unsigned int *tx_slot,
@@ -185,20 +184,19 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
185184
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
186185
struct hda_component *comps = master_data;
187186

188-
if (comps && cs35l41->index >= 0 && cs35l41->index < HDA_MAX_COMPONENTS)
189-
comps = &comps[cs35l41->index];
190-
else
187+
if (!comps || cs35l41->index < 0 || cs35l41->index >= HDA_MAX_COMPONENTS)
191188
return -EINVAL;
192189

193-
if (!comps->dev) {
194-
comps->dev = dev;
195-
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
196-
comps->playback_hook = cs35l41_hda_playback_hook;
197-
comps->set_channel_map = cs35l41_hda_channel_map;
198-
return 0;
199-
}
190+
comps = &comps[cs35l41->index];
191+
if (comps->dev)
192+
return -EBUSY;
200193

201-
return -EBUSY;
194+
comps->dev = dev;
195+
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
196+
comps->playback_hook = cs35l41_hda_playback_hook;
197+
comps->set_channel_map = cs35l41_hda_channel_map;
198+
199+
return 0;
202200
}
203201

204202
static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *master_data)
@@ -269,11 +267,7 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41,
269267
cs35l41->reg_seq = &cs35l41_hda_reg_seq_ext_bst;
270268
}
271269

272-
ret = cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, (unsigned int *)&hw_cfg->spk_pos);
273-
if (ret)
274-
return ret;
275-
276-
return 0;
270+
return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, (unsigned int *)&hw_cfg->spk_pos);
277271
}
278272

279273
static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41,
@@ -282,7 +276,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
282276
struct cs35l41_hda_hw_config *hw_cfg;
283277
u32 values[HDA_MAX_COMPONENTS];
284278
struct acpi_device *adev;
285-
struct device *acpi_dev;
279+
struct device *physdev;
286280
char *property;
287281
size_t nval;
288282
int i, ret;
@@ -293,11 +287,11 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
293287
return ERR_PTR(-ENODEV);
294288
}
295289

296-
acpi_dev = get_device(acpi_get_first_physical_node(adev));
290+
physdev = get_device(acpi_get_first_physical_node(adev));
297291
acpi_dev_put(adev);
298292

299293
property = "cirrus,dev-index";
300-
ret = device_property_count_u32(acpi_dev, property);
294+
ret = device_property_count_u32(physdev, property);
301295
if (ret <= 0)
302296
goto no_acpi_dsd;
303297

@@ -307,7 +301,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
307301
}
308302
nval = ret;
309303

310-
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
304+
ret = device_property_read_u32_array(physdev, property, values, nval);
311305
if (ret)
312306
goto err;
313307

@@ -324,7 +318,9 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
324318
goto err;
325319
}
326320

327-
/* No devm_ version as CLSA0100, in no_acpi_dsd case, can't use devm version */
321+
/* To use the same release code for all laptop variants we can't use devm_ version of
322+
* gpiod_get here, as CLSA010* don't have a fully functional bios with an _DSD node
323+
*/
328324
cs35l41->reset_gpio = fwnode_gpiod_get_index(&adev->fwnode, "reset", cs35l41->index,
329325
GPIOD_OUT_LOW, "cs35l41-reset");
330326

@@ -335,46 +331,46 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
335331
}
336332

337333
property = "cirrus,speaker-position";
338-
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
334+
ret = device_property_read_u32_array(physdev, property, values, nval);
339335
if (ret)
340336
goto err_free;
341337
hw_cfg->spk_pos = values[cs35l41->index];
342338

343339
property = "cirrus,gpio1-func";
344-
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
340+
ret = device_property_read_u32_array(physdev, property, values, nval);
345341
if (ret)
346342
goto err_free;
347343
hw_cfg->gpio1_func = values[cs35l41->index];
348344

349345
property = "cirrus,gpio2-func";
350-
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
346+
ret = device_property_read_u32_array(physdev, property, values, nval);
351347
if (ret)
352348
goto err_free;
353349
hw_cfg->gpio2_func = values[cs35l41->index];
354350

355351
property = "cirrus,boost-peak-milliamp";
356-
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
352+
ret = device_property_read_u32_array(physdev, property, values, nval);
357353
if (ret == 0)
358354
hw_cfg->bst_ipk = values[cs35l41->index];
359355

360356
property = "cirrus,boost-ind-nanohenry";
361-
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
357+
ret = device_property_read_u32_array(physdev, property, values, nval);
362358
if (ret == 0)
363359
hw_cfg->bst_ind = values[cs35l41->index];
364360

365361
property = "cirrus,boost-cap-microfarad";
366-
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
362+
ret = device_property_read_u32_array(physdev, property, values, nval);
367363
if (ret == 0)
368364
hw_cfg->bst_cap = values[cs35l41->index];
369365

370-
put_device(acpi_dev);
366+
put_device(physdev);
371367

372368
return hw_cfg;
373369

374370
err_free:
375371
kfree(hw_cfg);
376372
err:
377-
put_device(acpi_dev);
373+
put_device(physdev);
378374
dev_err(cs35l41->dev, "Failed property %s: %d\n", property, ret);
379375

380376
return ERR_PTR(ret);
@@ -383,18 +379,18 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
383379
/*
384380
* Device CLSA0100 doesn't have _DSD so a gpiod_get by the label reset won't work.
385381
* And devices created by i2c-multi-instantiate don't have their device struct pointing to
386-
* the correct fwnode, so acpi_dev must be used here
382+
* the correct fwnode, so acpi_dev must be used here.
387383
* And devm functions expect that the device requesting the resource has the correct
388-
* fwnode
384+
* fwnode.
389385
*/
390386
if (strncmp(hid, "CLSA0100", 8) != 0)
391387
return ERR_PTR(-EINVAL);
392388

393389
/* check I2C address to assign the index */
394390
cs35l41->index = id == 0x40 ? 0 : 1;
395-
cs35l41->reset_gpio = gpiod_get_index(acpi_dev, NULL, 0, GPIOD_OUT_HIGH);
391+
cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
396392
cs35l41->vspk_always_on = true;
397-
put_device(acpi_dev);
393+
put_device(physdev);
398394

399395
return NULL;
400396
}
@@ -449,7 +445,8 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
449445

450446
ret = regmap_read(cs35l41->regmap, CS35L41_IRQ1_STATUS3, &int_sts);
451447
if (ret || (int_sts & CS35L41_OTP_BOOT_ERR)) {
452-
dev_err(cs35l41->dev, "OTP Boot error\n");
448+
dev_err(cs35l41->dev, "OTP Boot status %x error: %d\n",
449+
int_sts & CS35L41_OTP_BOOT_ERR, ret);
453450
ret = -EIO;
454451
goto err;
455452
}
@@ -501,7 +498,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
501498

502499
if (cs35l41->reg_seq->probe) {
503500
ret = regmap_multi_reg_write(cs35l41->regmap, cs35l41->reg_seq->probe,
504-
cs35l41->reg_seq->num_probe);
501+
cs35l41->reg_seq->num_probe);
505502
if (ret) {
506503
dev_err(cs35l41->dev, "Fail to apply probe reg patch: %d\n", ret);
507504
goto err;

sound/pci/hda/cs35l41_hda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0
22
*
3-
* cs35l41_hda.h -- CS35L41 ALSA HDA audio driver
3+
* CS35L41 ALSA HDA audio driver
44
*
55
* Copyright 2021 Cirrus Logic, Inc.
66
*

sound/pci/hda/cs35l41_hda_i2c.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static struct i2c_driver cs35l41_i2c_driver = {
5858
.probe = cs35l41_hda_i2c_probe,
5959
.remove = cs35l41_hda_i2c_remove,
6060
};
61-
6261
module_i2c_driver(cs35l41_i2c_driver);
6362

6463
MODULE_DESCRIPTION("HDA CS35L41 driver");

sound/pci/hda/cs35l41_hda_spi.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ static struct spi_driver cs35l41_spi_driver = {
5555
.probe = cs35l41_hda_spi_probe,
5656
.remove = cs35l41_hda_spi_remove,
5757
};
58-
5958
module_spi_driver(cs35l41_spi_driver);
6059

6160
MODULE_DESCRIPTION("HDA CS35L41 driver");

0 commit comments

Comments
 (0)