Skip to content

Commit 872fc0b

Browse files
Lucas Tanurebroonie
authored andcommitted
ASoC: cs35l41: Set the max SPI speed for the whole device
Higher speeds are only supported when PLL is enabled, but the current driver doesn't enable PLL outside of stream use cases, so better to set the lowest SPI speed accepted by the entire device. Move the current frequency set to the spi sub-driver so the whole device can benefit from that speed. spi-max-frequency property could be used, but ACPI systems don't support it, so by setting it in the spi sub-driver probe both Device Trees and ACPI systems are supported. Signed-off-by: Lucas Tanure <[email protected]> Reviewed-by: Charles Keepax <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 8a6cc0d commit 872fc0b

File tree

3 files changed

+4
-39
lines changed

3 files changed

+4
-39
lines changed

sound/soc/codecs/cs35l41-spi.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,6 @@ static const struct spi_device_id cs35l41_id_spi[] = {
4242

4343
MODULE_DEVICE_TABLE(spi, cs35l41_id_spi);
4444

45-
static void cs35l41_spi_otp_setup(struct cs35l41_private *cs35l41,
46-
bool is_pre_setup, unsigned int *freq)
47-
{
48-
struct spi_device *spi;
49-
u32 orig_spi_freq;
50-
51-
spi = to_spi_device(cs35l41->dev);
52-
53-
if (!spi) {
54-
dev_err(cs35l41->dev, "%s: No SPI device\n", __func__);
55-
return;
56-
}
57-
58-
if (is_pre_setup) {
59-
orig_spi_freq = spi->max_speed_hz;
60-
if (orig_spi_freq > CS35L41_SPI_MAX_FREQ_OTP) {
61-
spi->max_speed_hz = CS35L41_SPI_MAX_FREQ_OTP;
62-
spi_setup(spi);
63-
}
64-
*freq = orig_spi_freq;
65-
} else {
66-
if (spi->max_speed_hz != *freq) {
67-
spi->max_speed_hz = *freq;
68-
spi_setup(spi);
69-
}
70-
}
71-
}
72-
7345
static int cs35l41_spi_probe(struct spi_device *spi)
7446
{
7547
const struct regmap_config *regmap_config = &cs35l41_regmap_spi;
@@ -81,6 +53,9 @@ static int cs35l41_spi_probe(struct spi_device *spi)
8153
if (!cs35l41)
8254
return -ENOMEM;
8355

56+
spi->max_speed_hz = CS35L41_SPI_MAX_FREQ;
57+
spi_setup(spi);
58+
8459
spi_set_drvdata(spi, cs35l41);
8560
cs35l41->regmap = devm_regmap_init_spi(spi, regmap_config);
8661
if (IS_ERR(cs35l41->regmap)) {
@@ -91,7 +66,6 @@ static int cs35l41_spi_probe(struct spi_device *spi)
9166

9267
cs35l41->dev = &spi->dev;
9368
cs35l41->irq = spi->irq;
94-
cs35l41->otp_setup = cs35l41_spi_otp_setup;
9569

9670
return cs35l41_probe(cs35l41, pdata);
9771
}

sound/soc/codecs/cs35l41.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ static int cs35l41_otp_unpack(void *data)
302302
const struct cs35l41_otp_packed_element_t *otp_map;
303303
struct cs35l41_private *cs35l41 = data;
304304
int bit_offset, word_offset, ret, i;
305-
unsigned int orig_spi_freq;
306305
unsigned int bit_sum = 8;
307306
u32 otp_val, otp_id_reg;
308307
u32 *otp_mem;
@@ -326,19 +325,13 @@ static int cs35l41_otp_unpack(void *data)
326325
goto err_otp_unpack;
327326
}
328327

329-
if (cs35l41->otp_setup)
330-
cs35l41->otp_setup(cs35l41, true, &orig_spi_freq);
331-
332328
ret = regmap_bulk_read(cs35l41->regmap, CS35L41_OTP_MEM0, otp_mem,
333329
CS35L41_OTP_SIZE_WORDS);
334330
if (ret < 0) {
335331
dev_err(cs35l41->dev, "Read OTP Mem failed: %d\n", ret);
336332
goto err_otp_unpack;
337333
}
338334

339-
if (cs35l41->otp_setup)
340-
cs35l41->otp_setup(cs35l41, false, &orig_spi_freq);
341-
342335
otp_map = otp_map_match->map;
343336

344337
bit_offset = otp_map_match->bit_offset;

sound/soc/codecs/cs35l41.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@
726726
#define CS35L41_FS2_WINDOW_MASK 0x00FFF800
727727
#define CS35L41_FS2_WINDOW_SHIFT 12
728728

729-
#define CS35L41_SPI_MAX_FREQ_OTP 4000000
729+
#define CS35L41_SPI_MAX_FREQ 4000000
730730

731731
#define CS35L41_RX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
732732
#define CS35L41_TX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
@@ -764,8 +764,6 @@ struct cs35l41_private {
764764
int irq;
765765
/* GPIO for /RST */
766766
struct gpio_desc *reset_gpio;
767-
void (*otp_setup)(struct cs35l41_private *cs35l41, bool is_pre_setup,
768-
unsigned int *freq);
769767
};
770768

771769
int cs35l41_probe(struct cs35l41_private *cs35l41,

0 commit comments

Comments
 (0)