xref: /openbmc/linux/sound/soc/codecs/cs35l41-i2c.c (revision 2540d3c9)
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 "cs35l41.h"
21 
22 static const struct i2c_device_id cs35l41_id_i2c[] = {
23 	{ "cs35l40", 0 },
24 	{ "cs35l41", 0 },
25 	{ "cs35l51", 0 },
26 	{ "cs35l53", 0 },
27 	{}
28 };
29 
30 MODULE_DEVICE_TABLE(i2c, cs35l41_id_i2c);
31 
32 static int cs35l41_i2c_probe(struct i2c_client *client)
33 {
34 	struct cs35l41_private *cs35l41;
35 	struct device *dev = &client->dev;
36 	struct cs35l41_hw_cfg *hw_cfg = dev_get_platdata(dev);
37 	const struct regmap_config *regmap_config = &cs35l41_regmap_i2c;
38 	int ret;
39 
40 	cs35l41 = devm_kzalloc(dev, sizeof(struct cs35l41_private), GFP_KERNEL);
41 
42 	if (!cs35l41)
43 		return -ENOMEM;
44 
45 	cs35l41->dev = dev;
46 	cs35l41->irq = client->irq;
47 
48 	i2c_set_clientdata(client, cs35l41);
49 	cs35l41->regmap = devm_regmap_init_i2c(client, regmap_config);
50 	if (IS_ERR(cs35l41->regmap)) {
51 		ret = PTR_ERR(cs35l41->regmap);
52 		dev_err(cs35l41->dev, "Failed to allocate register map: %d\n", ret);
53 		return ret;
54 	}
55 
56 	return cs35l41_probe(cs35l41, hw_cfg);
57 }
58 
59 static int cs35l41_i2c_remove(struct i2c_client *client)
60 {
61 	struct cs35l41_private *cs35l41 = i2c_get_clientdata(client);
62 
63 	cs35l41_remove(cs35l41);
64 
65 	return 0;
66 }
67 
68 #ifdef CONFIG_OF
69 static const struct of_device_id cs35l41_of_match[] = {
70 	{ .compatible = "cirrus,cs35l40" },
71 	{ .compatible = "cirrus,cs35l41" },
72 	{},
73 };
74 MODULE_DEVICE_TABLE(of, cs35l41_of_match);
75 #endif
76 
77 #ifdef CONFIG_ACPI
78 static const struct acpi_device_id cs35l41_acpi_match[] = {
79 	{ "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */
80 	{},
81 };
82 MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match);
83 #endif
84 
85 static struct i2c_driver cs35l41_i2c_driver = {
86 	.driver = {
87 		.name		= "cs35l41",
88 		.pm		= &cs35l41_pm_ops,
89 		.of_match_table = of_match_ptr(cs35l41_of_match),
90 		.acpi_match_table = ACPI_PTR(cs35l41_acpi_match),
91 	},
92 	.id_table	= cs35l41_id_i2c,
93 	.probe_new	= cs35l41_i2c_probe,
94 	.remove		= cs35l41_i2c_remove,
95 };
96 
97 module_i2c_driver(cs35l41_i2c_driver);
98 
99 MODULE_DESCRIPTION("I2C CS35L41 driver");
100 MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>");
101 MODULE_LICENSE("GPL");
102