xref: /linux/sound/soc/codecs/cs35l56-i2c.c (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
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 	cs35l56->base.can_hibernate = true;
31 
32 	i2c_set_clientdata(client, cs35l56);
33 	cs35l56->base.regmap = devm_regmap_init_i2c(client, regmap_config);
34 	if (IS_ERR(cs35l56->base.regmap)) {
35 		ret = PTR_ERR(cs35l56->base.regmap);
36 		return dev_err_probe(cs35l56->base.dev, ret, "Failed to allocate register map\n");
37 	}
38 
39 	ret = cs35l56_common_probe(cs35l56);
40 	if (ret != 0)
41 		return ret;
42 
43 	ret = cs35l56_init(cs35l56);
44 	if (ret == 0)
45 		ret = cs35l56_irq_request(&cs35l56->base, client->irq);
46 	if (ret < 0)
47 		cs35l56_remove(cs35l56);
48 
49 	return ret;
50 }
51 
52 static void cs35l56_i2c_remove(struct i2c_client *client)
53 {
54 	struct cs35l56_private *cs35l56 = i2c_get_clientdata(client);
55 
56 	cs35l56_remove(cs35l56);
57 }
58 
59 static const struct i2c_device_id cs35l56_id_i2c[] = {
60 	{ "cs35l56" },
61 	{}
62 };
63 MODULE_DEVICE_TABLE(i2c, cs35l56_id_i2c);
64 
65 #ifdef CONFIG_ACPI
66 static const struct acpi_device_id cs35l56_asoc_acpi_match[] = {
67 	{ "CSC355C", 0 },
68 	{},
69 };
70 MODULE_DEVICE_TABLE(acpi, cs35l56_asoc_acpi_match);
71 #endif
72 
73 static struct i2c_driver cs35l56_i2c_driver = {
74 	.driver = {
75 		.name		= "cs35l56",
76 		.pm = pm_ptr(&cs35l56_pm_ops_i2c_spi),
77 		.acpi_match_table = ACPI_PTR(cs35l56_asoc_acpi_match),
78 	},
79 	.id_table	= cs35l56_id_i2c,
80 	.probe		= cs35l56_i2c_probe,
81 	.remove		= cs35l56_i2c_remove,
82 };
83 
84 module_i2c_driver(cs35l56_i2c_driver);
85 
86 MODULE_DESCRIPTION("ASoC CS35L56 I2C driver");
87 MODULE_IMPORT_NS(SND_SOC_CS35L56_CORE);
88 MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED);
89 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
90 MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>");
91 MODULE_LICENSE("GPL");
92