Skip to content

Commit 6450ef5

Browse files
drhodescirrusbroonie
authored andcommitted
ASoC: cs35l41: CS35L41 Boosted Smart Amplifier
SoC Audio driver for the Cirrus Logic CS35L41 amplifier Signed-off-by: David Rhodes <drhodes@opensource.cirrus.com> Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://lore.kernel.org/r/20210907225719.2018115-2-drhodes@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 0c7985e commit 6450ef5

File tree

8 files changed

+3224
-0
lines changed

8 files changed

+3224
-0
lines changed

include/sound/cs35l41.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0
2+
*
3+
* linux/sound/cs35l41.h -- Platform data for CS35L41
4+
*
5+
* Copyright (c) 2017-2021 Cirrus Logic Inc.
6+
*
7+
* Author: David Rhodes <david.rhodes@cirrus.com>
8+
*/
9+
10+
#ifndef __CS35L41_H
11+
#define __CS35L41_H
12+
13+
enum cs35l41_clk_ids {
14+
CS35L41_CLKID_SCLK = 0,
15+
CS35L41_CLKID_LRCLK = 1,
16+
CS35L41_CLKID_MCLK = 4,
17+
};
18+
19+
struct cs35l41_irq_cfg {
20+
bool irq_pol_inv;
21+
bool irq_out_en;
22+
int irq_src_sel;
23+
};
24+
25+
struct cs35l41_platform_data {
26+
int bst_ind;
27+
int bst_ipk;
28+
int bst_cap;
29+
int dout_hiz;
30+
struct cs35l41_irq_cfg irq_config1;
31+
struct cs35l41_irq_cfg irq_config2;
32+
};
33+
34+
#endif /* __CS35L41_H */

sound/soc/codecs/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ config SND_SOC_ALL_CODECS
6161
imply SND_SOC_CS35L34
6262
imply SND_SOC_CS35L35
6363
imply SND_SOC_CS35L36
64+
imply SND_SOC_CS35L41_SPI
65+
imply SND_SOC_CS35L41_I2C
6466
imply SND_SOC_CS42L42
6567
imply SND_SOC_CS42L51_I2C
6668
imply SND_SOC_CS42L52
@@ -602,6 +604,16 @@ config SND_SOC_CS35L36
602604
tristate "Cirrus Logic CS35L36 CODEC"
603605
depends on I2C
604606

607+
config SND_SOC_CS35L41_SPI
608+
tristate "Cirrus Logic CS35L41 CODEC (SPI)"
609+
depends on SPI_MASTER
610+
select REGMAP_SPI
611+
612+
config SND_SOC_CS35L41_I2C
613+
tristate "Cirrus Logic CS35L41 CODEC (I2C)"
614+
depends on I2C
615+
select REGMAP_I2C
616+
605617
config SND_SOC_CS42L42
606618
tristate "Cirrus Logic CS42L42 CODEC"
607619
depends on I2C

sound/soc/codecs/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ snd-soc-cs35l33-objs := cs35l33.o
5454
snd-soc-cs35l34-objs := cs35l34.o
5555
snd-soc-cs35l35-objs := cs35l35.o
5656
snd-soc-cs35l36-objs := cs35l36.o
57+
snd-soc-cs35l41-spi-objs := cs35l41-spi.o cs35l41.o cs35l41-tables.o
58+
snd-soc-cs35l41-i2c-objs := cs35l41-i2c.o cs35l41.o cs35l41-tables.o
5759
snd-soc-cs42l42-objs := cs42l42.o
5860
snd-soc-cs42l51-objs := cs42l51.o
5961
snd-soc-cs42l51-i2c-objs := cs42l51-i2c.o
@@ -385,6 +387,8 @@ obj-$(CONFIG_SND_SOC_CS35L33) += snd-soc-cs35l33.o
385387
obj-$(CONFIG_SND_SOC_CS35L34) += snd-soc-cs35l34.o
386388
obj-$(CONFIG_SND_SOC_CS35L35) += snd-soc-cs35l35.o
387389
obj-$(CONFIG_SND_SOC_CS35L36) += snd-soc-cs35l36.o
390+
obj-$(CONFIG_SND_SOC_CS35L41_SPI) += snd-soc-cs35l41-spi.o
391+
obj-$(CONFIG_SND_SOC_CS35L41_I2C) += snd-soc-cs35l41-i2c.o
388392
obj-$(CONFIG_SND_SOC_CS42L42) += snd-soc-cs42l42.o
389393
obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o
390394
obj-$(CONFIG_SND_SOC_CS42L51_I2C) += snd-soc-cs42l51-i2c.o

sound/soc/codecs/cs35l41-i2c.c

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// cs35l41-i2c.c -- CS35l41 I2C driver
4+
//
5+
// Copyright 2017-2021 Cirrus Logic, Inc.
6+
//
7+
// Author: David Rhodes <david.rhodes@cirrus.com>
8+
9+
#include <linux/acpi.h>
10+
#include <linux/delay.h>
11+
#include <linux/i2c.h>
12+
#include <linux/init.h>
13+
#include <linux/kernel.h>
14+
#include <linux/module.h>
15+
#include <linux/moduleparam.h>
16+
#include <linux/of_device.h>
17+
#include <linux/platform_device.h>
18+
#include <linux/slab.h>
19+
20+
#include <sound/cs35l41.h>
21+
#include "cs35l41.h"
22+
23+
static struct regmap_config cs35l41_regmap_i2c = {
24+
.reg_bits = 32,
25+
.val_bits = 32,
26+
.reg_stride = CS35L41_REGSTRIDE,
27+
.reg_format_endian = REGMAP_ENDIAN_BIG,
28+
.val_format_endian = REGMAP_ENDIAN_BIG,
29+
.max_register = CS35L41_LASTREG,
30+
.reg_defaults = cs35l41_reg,
31+
.num_reg_defaults = ARRAY_SIZE(cs35l41_reg),
32+
.volatile_reg = cs35l41_volatile_reg,
33+
.readable_reg = cs35l41_readable_reg,
34+
.precious_reg = cs35l41_precious_reg,
35+
.cache_type = REGCACHE_RBTREE,
36+
};
37+
38+
static const struct i2c_device_id cs35l41_id_i2c[] = {
39+
{ "cs35l40", 0 },
40+
{ "cs35l41", 0 },
41+
{}
42+
};
43+
44+
MODULE_DEVICE_TABLE(i2c, cs35l41_id_i2c);
45+
46+
static int cs35l41_i2c_probe(struct i2c_client *client,
47+
const struct i2c_device_id *id)
48+
{
49+
struct cs35l41_private *cs35l41;
50+
struct device *dev = &client->dev;
51+
struct cs35l41_platform_data *pdata = dev_get_platdata(dev);
52+
const struct regmap_config *regmap_config = &cs35l41_regmap_i2c;
53+
int ret;
54+
55+
cs35l41 = devm_kzalloc(dev, sizeof(struct cs35l41_private), GFP_KERNEL);
56+
57+
if (!cs35l41)
58+
return -ENOMEM;
59+
60+
cs35l41->dev = dev;
61+
cs35l41->irq = client->irq;
62+
63+
i2c_set_clientdata(client, cs35l41);
64+
cs35l41->regmap = devm_regmap_init_i2c(client, regmap_config);
65+
if (IS_ERR(cs35l41->regmap)) {
66+
ret = PTR_ERR(cs35l41->regmap);
67+
dev_err(cs35l41->dev, "Failed to allocate register map: %d\n",
68+
ret);
69+
return ret;
70+
}
71+
72+
return cs35l41_probe(cs35l41, pdata);
73+
}
74+
75+
static int cs35l41_i2c_remove(struct i2c_client *client)
76+
{
77+
struct cs35l41_private *cs35l41 = i2c_get_clientdata(client);
78+
79+
return cs35l41_remove(cs35l41);
80+
}
81+
82+
#ifdef CONFIG_OF
83+
static const struct of_device_id cs35l41_of_match[] = {
84+
{ .compatible = "cirrus,cs35l40" },
85+
{ .compatible = "cirrus,cs35l41" },
86+
{},
87+
};
88+
MODULE_DEVICE_TABLE(of, cs35l41_of_match);
89+
#endif
90+
91+
#ifdef CONFIG_ACPI
92+
static const struct acpi_device_id cs35l41_acpi_match[] = {
93+
{ "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */
94+
{},
95+
};
96+
MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match);
97+
#endif
98+
99+
static struct i2c_driver cs35l41_i2c_driver = {
100+
.driver = {
101+
.name = "cs35l41",
102+
.of_match_table = of_match_ptr(cs35l41_of_match),
103+
.acpi_match_table = ACPI_PTR(cs35l41_acpi_match),
104+
},
105+
.id_table = cs35l41_id_i2c,
106+
.probe = cs35l41_i2c_probe,
107+
.remove = cs35l41_i2c_remove,
108+
};
109+
110+
module_i2c_driver(cs35l41_i2c_driver);
111+
112+
MODULE_DESCRIPTION("I2C CS35L41 driver");
113+
MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>");
114+
MODULE_LICENSE("GPL");

sound/soc/codecs/cs35l41-spi.c

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// cs35l41-spi.c -- CS35l41 SPI driver
4+
//
5+
// Copyright 2017-2021 Cirrus Logic, Inc.
6+
//
7+
// Author: David Rhodes <david.rhodes@cirrus.com>
8+
9+
#include <linux/acpi.h>
10+
#include <linux/delay.h>
11+
#include <linux/init.h>
12+
#include <linux/kernel.h>
13+
#include <linux/module.h>
14+
#include <linux/moduleparam.h>
15+
#include <linux/platform_device.h>
16+
#include <linux/spi/spi.h>
17+
18+
#include <sound/cs35l41.h>
19+
#include "cs35l41.h"
20+
21+
static struct regmap_config cs35l41_regmap_spi = {
22+
.reg_bits = 32,
23+
.val_bits = 32,
24+
.pad_bits = 16,
25+
.reg_stride = CS35L41_REGSTRIDE,
26+
.reg_format_endian = REGMAP_ENDIAN_BIG,
27+
.val_format_endian = REGMAP_ENDIAN_BIG,
28+
.max_register = CS35L41_LASTREG,
29+
.reg_defaults = cs35l41_reg,
30+
.num_reg_defaults = ARRAY_SIZE(cs35l41_reg),
31+
.volatile_reg = cs35l41_volatile_reg,
32+
.readable_reg = cs35l41_readable_reg,
33+
.precious_reg = cs35l41_precious_reg,
34+
.cache_type = REGCACHE_RBTREE,
35+
};
36+
37+
static const struct spi_device_id cs35l41_id_spi[] = {
38+
{ "cs35l40", 0 },
39+
{ "cs35l41", 0 },
40+
{}
41+
};
42+
43+
MODULE_DEVICE_TABLE(spi, cs35l41_id_spi);
44+
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+
73+
static int cs35l41_spi_probe(struct spi_device *spi)
74+
{
75+
const struct regmap_config *regmap_config = &cs35l41_regmap_spi;
76+
struct cs35l41_platform_data *pdata =
77+
dev_get_platdata(&spi->dev);
78+
struct cs35l41_private *cs35l41;
79+
int ret;
80+
81+
cs35l41 = devm_kzalloc(&spi->dev,
82+
sizeof(struct cs35l41_private),
83+
GFP_KERNEL);
84+
if (!cs35l41)
85+
return -ENOMEM;
86+
87+
88+
spi_set_drvdata(spi, cs35l41);
89+
cs35l41->regmap = devm_regmap_init_spi(spi, regmap_config);
90+
if (IS_ERR(cs35l41->regmap)) {
91+
ret = PTR_ERR(cs35l41->regmap);
92+
dev_err(&spi->dev, "Failed to allocate register map: %d\n",
93+
ret);
94+
return ret;
95+
}
96+
97+
cs35l41->dev = &spi->dev;
98+
cs35l41->irq = spi->irq;
99+
cs35l41->otp_setup = cs35l41_spi_otp_setup;
100+
101+
return cs35l41_probe(cs35l41, pdata);
102+
}
103+
104+
static int cs35l41_spi_remove(struct spi_device *spi)
105+
{
106+
struct cs35l41_private *cs35l41 = spi_get_drvdata(spi);
107+
108+
return cs35l41_remove(cs35l41);
109+
}
110+
111+
#ifdef CONFIG_OF
112+
static const struct of_device_id cs35l41_of_match[] = {
113+
{ .compatible = "cirrus,cs35l40" },
114+
{ .compatible = "cirrus,cs35l41" },
115+
{},
116+
};
117+
MODULE_DEVICE_TABLE(of, cs35l41_of_match);
118+
#endif
119+
120+
#ifdef CONFIG_ACPI
121+
static const struct acpi_device_id cs35l41_acpi_match[] = {
122+
{ "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */
123+
{},
124+
};
125+
MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match);
126+
#endif
127+
128+
static struct spi_driver cs35l41_spi_driver = {
129+
.driver = {
130+
.name = "cs35l41",
131+
.of_match_table = of_match_ptr(cs35l41_of_match),
132+
.acpi_match_table = ACPI_PTR(cs35l41_acpi_match),
133+
},
134+
.id_table = cs35l41_id_spi,
135+
.probe = cs35l41_spi_probe,
136+
.remove = cs35l41_spi_remove,
137+
};
138+
139+
module_spi_driver(cs35l41_spi_driver);
140+
141+
MODULE_DESCRIPTION("SPI CS35L41 driver");
142+
MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>");
143+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)