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