1 // SPDX-License-Identifier: GPL-2.0-only
3 * I2C bus interface to Cirrus Logic Madera codecs
5 * Copyright (C) 2015-2018 Cirrus Logic
8 #include <linux/device.h>
10 #include <linux/i2c.h>
11 #include <linux/module.h>
13 #include <linux/of_device.h>
14 #include <linux/regmap.h>
16 #include <linux/mfd/madera/core.h>
20 static int madera_i2c_probe(struct i2c_client
*i2c
,
21 const struct i2c_device_id
*id
)
23 struct madera
*madera
;
24 const struct regmap_config
*regmap_16bit_config
= NULL
;
25 const struct regmap_config
*regmap_32bit_config
= NULL
;
31 of_data
= of_device_get_match_data(&i2c
->dev
);
33 type
= (unsigned long)of_data
;
35 type
= id
->driver_data
;
39 if (IS_ENABLED(CONFIG_MFD_CS47L15
)) {
40 regmap_16bit_config
= &cs47l15_16bit_i2c_regmap
;
41 regmap_32bit_config
= &cs47l15_32bit_i2c_regmap
;
45 if (IS_ENABLED(CONFIG_MFD_CS47L35
)) {
46 regmap_16bit_config
= &cs47l35_16bit_i2c_regmap
;
47 regmap_32bit_config
= &cs47l35_32bit_i2c_regmap
;
52 if (IS_ENABLED(CONFIG_MFD_CS47L85
)) {
53 regmap_16bit_config
= &cs47l85_16bit_i2c_regmap
;
54 regmap_32bit_config
= &cs47l85_32bit_i2c_regmap
;
59 if (IS_ENABLED(CONFIG_MFD_CS47L90
)) {
60 regmap_16bit_config
= &cs47l90_16bit_i2c_regmap
;
61 regmap_32bit_config
= &cs47l90_32bit_i2c_regmap
;
67 if (IS_ENABLED(CONFIG_MFD_CS47L92
)) {
68 regmap_16bit_config
= &cs47l92_16bit_i2c_regmap
;
69 regmap_32bit_config
= &cs47l92_32bit_i2c_regmap
;
74 "Unknown Madera I2C device type %ld\n", type
);
78 name
= madera_name_from_type(type
);
80 if (!regmap_16bit_config
) {
81 /* it's polite to say which codec isn't built into the kernel */
83 "Kernel does not include support for %s\n", name
);
87 madera
= devm_kzalloc(&i2c
->dev
, sizeof(*madera
), GFP_KERNEL
);
92 madera
->regmap
= devm_regmap_init_i2c(i2c
, regmap_16bit_config
);
93 if (IS_ERR(madera
->regmap
)) {
94 ret
= PTR_ERR(madera
->regmap
);
96 "Failed to allocate 16-bit register map: %d\n", ret
);
100 madera
->regmap_32bit
= devm_regmap_init_i2c(i2c
, regmap_32bit_config
);
101 if (IS_ERR(madera
->regmap_32bit
)) {
102 ret
= PTR_ERR(madera
->regmap_32bit
);
104 "Failed to allocate 32-bit register map: %d\n", ret
);
109 madera
->type_name
= name
;
110 madera
->dev
= &i2c
->dev
;
111 madera
->irq
= i2c
->irq
;
113 return madera_dev_init(madera
);
116 static int madera_i2c_remove(struct i2c_client
*i2c
)
118 struct madera
*madera
= dev_get_drvdata(&i2c
->dev
);
120 madera_dev_exit(madera
);
125 static const struct i2c_device_id madera_i2c_id
[] = {
126 { "cs47l15", CS47L15
},
127 { "cs47l35", CS47L35
},
128 { "cs47l85", CS47L85
},
129 { "cs47l90", CS47L90
},
130 { "cs47l91", CS47L91
},
131 { "cs42l92", CS42L92
},
132 { "cs47l92", CS47L92
},
133 { "cs47l93", CS47L93
},
134 { "wm1840", WM1840
},
137 MODULE_DEVICE_TABLE(i2c
, madera_i2c_id
);
139 static struct i2c_driver madera_i2c_driver
= {
142 .pm
= &madera_pm_ops
,
143 .of_match_table
= of_match_ptr(madera_of_match
),
145 .probe
= madera_i2c_probe
,
146 .remove
= madera_i2c_remove
,
147 .id_table
= madera_i2c_id
,
150 module_i2c_driver(madera_i2c_driver
);
152 MODULE_DESCRIPTION("Madera I2C bus interface");
153 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
154 MODULE_LICENSE("GPL v2");