xref: /openbmc/linux/sound/soc/codecs/cs42l42-i2c.c (revision c0d3b831)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * cs42l42-i2c.c -- CS42L42 ALSA SoC audio driver for I2C
4  *
5  * Copyright 2016, 2022 Cirrus Logic, Inc.
6  */
7 
8 #include <linux/i2c.h>
9 #include <linux/module.h>
10 #include <linux/regmap.h>
11 #include <linux/slab.h>
12 #include <linux/types.h>
13 
14 #include "cs42l42.h"
15 
16 static int cs42l42_i2c_probe(struct i2c_client *i2c_client)
17 {
18 	struct device *dev = &i2c_client->dev;
19 	struct cs42l42_private *cs42l42;
20 	struct regmap *regmap;
21 	int ret;
22 
23 	cs42l42 = devm_kzalloc(dev, sizeof(*cs42l42), GFP_KERNEL);
24 	if (!cs42l42)
25 		return -ENOMEM;
26 
27 	regmap = devm_regmap_init_i2c(i2c_client, &cs42l42_regmap);
28 	if (IS_ERR(regmap))
29 		return dev_err_probe(&i2c_client->dev, PTR_ERR(regmap),
30 				     "regmap_init() failed\n");
31 
32 	cs42l42->devid = CS42L42_CHIP_ID;
33 	cs42l42->dev = dev;
34 	cs42l42->regmap = regmap;
35 	cs42l42->irq = i2c_client->irq;
36 
37 	ret = cs42l42_common_probe(cs42l42, &cs42l42_soc_component, &cs42l42_dai);
38 	if (ret)
39 		return ret;
40 
41 	return cs42l42_init(cs42l42);
42 }
43 
44 static void cs42l42_i2c_remove(struct i2c_client *i2c_client)
45 {
46 	struct cs42l42_private *cs42l42 = dev_get_drvdata(&i2c_client->dev);
47 
48 	cs42l42_common_remove(cs42l42);
49 }
50 
51 static int __maybe_unused cs42l42_i2c_resume(struct device *dev)
52 {
53 	int ret;
54 
55 	ret = cs42l42_resume(dev);
56 	if (ret)
57 		return ret;
58 
59 	cs42l42_resume_restore(dev);
60 
61 	return 0;
62 }
63 
64 static const struct dev_pm_ops cs42l42_i2c_pm_ops = {
65 	SET_SYSTEM_SLEEP_PM_OPS(cs42l42_suspend, cs42l42_i2c_resume)
66 };
67 
68 static const struct of_device_id __maybe_unused cs42l42_of_match[] = {
69 	{ .compatible = "cirrus,cs42l42", },
70 	{}
71 };
72 MODULE_DEVICE_TABLE(of, cs42l42_of_match);
73 
74 static const struct acpi_device_id __maybe_unused cs42l42_acpi_match[] = {
75 	{"10134242", 0,},
76 	{}
77 };
78 MODULE_DEVICE_TABLE(acpi, cs42l42_acpi_match);
79 
80 static const struct i2c_device_id cs42l42_id[] = {
81 	{"cs42l42", 0},
82 	{}
83 };
84 
85 MODULE_DEVICE_TABLE(i2c, cs42l42_id);
86 
87 static struct i2c_driver cs42l42_i2c_driver = {
88 	.driver = {
89 		.name = "cs42l42",
90 		.pm = &cs42l42_i2c_pm_ops,
91 		.of_match_table = of_match_ptr(cs42l42_of_match),
92 		.acpi_match_table = ACPI_PTR(cs42l42_acpi_match),
93 		},
94 	.id_table = cs42l42_id,
95 	.probe_new = cs42l42_i2c_probe,
96 	.remove = cs42l42_i2c_remove,
97 };
98 
99 module_i2c_driver(cs42l42_i2c_driver);
100 
101 MODULE_DESCRIPTION("ASoC CS42L42 I2C driver");
102 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
103 MODULE_LICENSE("GPL");
104 MODULE_IMPORT_NS(SND_SOC_CS42L42_CORE);
105