xref: /openbmc/linux/sound/soc/codecs/cs42xx8-i2c.c (revision 2a12187d)
1 /*
2  * Cirrus Logic CS42448/CS42888 Audio CODEC DAI I2C driver
3  *
4  * Copyright (C) 2014 Freescale Semiconductor, Inc.
5  *
6  * Author: Nicolin Chen <Guangyu.Chen@freescale.com>
7  *
8  * This file is licensed under the terms of the GNU General Public License
9  * version 2. This program is licensed "as is" without any warranty of any
10  * kind, whether express or implied.
11  */
12 
13 #include <linux/i2c.h>
14 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/pm_runtime.h>
17 #include <sound/soc.h>
18 
19 #include "cs42xx8.h"
20 
21 static const struct of_device_id cs42xx8_of_match[];
22 
23 static int cs42xx8_i2c_probe(struct i2c_client *i2c)
24 {
25 	int ret;
26 	struct cs42xx8_driver_data *drvdata;
27 	const struct of_device_id *of_id;
28 
29 	of_id = of_match_device(cs42xx8_of_match, &i2c->dev);
30 	if (!of_id) {
31 		dev_err(&i2c->dev, "failed to find driver data\n");
32 		return -EINVAL;
33 	}
34 
35 	drvdata = (struct cs42xx8_driver_data *)of_id->data;
36 
37 	ret = cs42xx8_probe(&i2c->dev,
38 		devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config), drvdata);
39 	if (ret)
40 		return ret;
41 
42 	pm_runtime_enable(&i2c->dev);
43 	pm_request_idle(&i2c->dev);
44 
45 	return 0;
46 }
47 
48 static void cs42xx8_i2c_remove(struct i2c_client *i2c)
49 {
50 	pm_runtime_disable(&i2c->dev);
51 }
52 
53 static const struct of_device_id cs42xx8_of_match[] = {
54 	{ .compatible = "cirrus,cs42448", .data = &cs42448_data, },
55 	{ .compatible = "cirrus,cs42888", .data = &cs42888_data, },
56 	{ /* sentinel */ }
57 };
58 MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
59 
60 static const struct i2c_device_id cs42xx8_i2c_id[] = {
61 	{"cs42448", (kernel_ulong_t)&cs42448_data},
62 	{"cs42888", (kernel_ulong_t)&cs42888_data},
63 	{}
64 };
65 MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
66 
67 static struct i2c_driver cs42xx8_i2c_driver = {
68 	.driver = {
69 		.name = "cs42xx8",
70 		.pm = &cs42xx8_pm,
71 		.of_match_table = cs42xx8_of_match,
72 	},
73 	.probe_new = cs42xx8_i2c_probe,
74 	.remove = cs42xx8_i2c_remove,
75 	.id_table = cs42xx8_i2c_id,
76 };
77 
78 module_i2c_driver(cs42xx8_i2c_driver);
79 
80 MODULE_DESCRIPTION("Cirrus Logic CS42448/CS42888 ALSA SoC Codec I2C Driver");
81 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
82 MODULE_LICENSE("GPL");
83