xref: /openbmc/linux/sound/soc/codecs/cs35l56-i2c.c (revision 86e281fc)
1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // CS35L56 ALSA SoC audio driver I2C binding
4 //
5 // Copyright (C) 2023 Cirrus Logic, Inc. and
6 //                    Cirrus Logic International Semiconductor Ltd.
7 
8 #include <linux/acpi.h>
9 #include <linux/i2c.h>
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/regmap.h>
13 #include <linux/slab.h>
14 #include <linux/types.h>
15 
16 #include "cs35l56.h"
17 
18 static int cs35l56_i2c_probe(struct i2c_client *client)
19 {
20 	struct cs35l56_private *cs35l56;
21 	struct device *dev = &client->dev;
22 	const struct regmap_config *regmap_config = &cs35l56_regmap_i2c;
23 	int ret;
24 
25 	cs35l56 = devm_kzalloc(dev, sizeof(struct cs35l56_private), GFP_KERNEL);
26 	if (!cs35l56)
27 		return -ENOMEM;
28 
29 	cs35l56->base.dev = dev;
30 
31 	i2c_set_clientdata(client, cs35l56);
32 	cs35l56->base.regmap = devm_regmap_init_i2c(client, regmap_config);
33 	if (IS_ERR(cs35l56->base.regmap)) {
34 		ret = PTR_ERR(cs35l56->base.regmap);
35 		return dev_err_probe(cs35l56->base.dev, ret, "Failed to allocate register map\n");
36 	}
37 
38 	ret = cs35l56_common_probe(cs35l56);
39 	if (ret != 0)
40 		return ret;
41 
42 	ret = cs35l56_init(cs35l56);
43 	if (ret == 0)
44 		ret = cs35l56_irq_request(&cs35l56->base, client->irq);
45 	if (ret < 0)
46 		cs35l56_remove(cs35l56);
47 
48 	return ret;
49 }
50 
51 static void cs35l56_i2c_remove(struct i2c_client *client)
52 {
53 	struct cs35l56_private *cs35l56 = i2c_get_clientdata(client);
54 
55 	cs35l56_remove(cs35l56);
56 }
57 
58 static const struct i2c_device_id cs35l56_id_i2c[] = {
59 	{ "cs35l56", 0 },
60 	{}
61 };
62 MODULE_DEVICE_TABLE(i2c, cs35l56_id_i2c);
63 
64 #ifdef CONFIG_ACPI
65 static const struct acpi_device_id cs35l56_asoc_acpi_match[] = {
66 	{ "CSC355C", 0 },
67 	{},
68 };
69 MODULE_DEVICE_TABLE(acpi, cs35l56_asoc_acpi_match);
70 #endif
71 
72 static struct i2c_driver cs35l56_i2c_driver = {
73 	.driver = {
74 		.name		= "cs35l56",
75 		.pm = &cs35l56_pm_ops_i2c_spi,
76 		.acpi_match_table = ACPI_PTR(cs35l56_asoc_acpi_match),
77 	},
78 	.id_table	= cs35l56_id_i2c,
79 	.probe		= cs35l56_i2c_probe,
80 	.remove		= cs35l56_i2c_remove,
81 };
82 
83 module_i2c_driver(cs35l56_i2c_driver);
84 
85 MODULE_DESCRIPTION("ASoC CS35L56 I2C driver");
86 MODULE_IMPORT_NS(SND_SOC_CS35L56_CORE);
87 MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED);
88 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
89 MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>");
90 MODULE_LICENSE("GPL");
91