xref: /openbmc/linux/drivers/mfd/da9055-i2c.c (revision 046b212a)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2  /* I2C access for DA9055 PMICs.
3  *
4  * Copyright(c) 2012 Dialog Semiconductor Ltd.
5  *
6  * Author: David Dajun Chen <dchen@diasemi.com>
7  */
8 
9 #include <linux/module.h>
10 #include <linux/device.h>
11 #include <linux/i2c.h>
12 #include <linux/err.h>
13 #include <linux/of.h>
14 
15 #include <linux/mfd/da9055/core.h>
16 
17 static int da9055_i2c_probe(struct i2c_client *i2c)
18 {
19 	struct da9055 *da9055;
20 	int ret;
21 
22 	da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
23 	if (!da9055)
24 		return -ENOMEM;
25 
26 	da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
27 	if (IS_ERR(da9055->regmap)) {
28 		ret = PTR_ERR(da9055->regmap);
29 		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
30 			ret);
31 		return ret;
32 	}
33 
34 	da9055->dev = &i2c->dev;
35 	da9055->chip_irq = i2c->irq;
36 
37 	i2c_set_clientdata(i2c, da9055);
38 
39 	return da9055_device_init(da9055);
40 }
41 
42 static void da9055_i2c_remove(struct i2c_client *i2c)
43 {
44 	struct da9055 *da9055 = i2c_get_clientdata(i2c);
45 
46 	da9055_device_exit(da9055);
47 }
48 
49 /*
50  * DO NOT change the device Ids. The naming is intentionally specific as both
51  * the PMIC and CODEC parts of this chip are instantiated separately as I2C
52  * devices (both have configurable I2C addresses, and are to all intents and
53  * purposes separate). As a result there are specific DA9055 ids for PMIC
54  * and CODEC, which must be different to operate together.
55  */
56 static const struct i2c_device_id da9055_i2c_id[] = {
57 	{"da9055-pmic", 0},
58 	{ }
59 };
60 MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
61 
62 static const struct of_device_id da9055_of_match[] = {
63 	{ .compatible = "dlg,da9055-pmic", },
64 	{ }
65 };
66 
67 static struct i2c_driver da9055_i2c_driver = {
68 	.probe = da9055_i2c_probe,
69 	.remove = da9055_i2c_remove,
70 	.id_table = da9055_i2c_id,
71 	.driver = {
72 		.name = "da9055-pmic",
73 		.of_match_table = da9055_of_match,
74 	},
75 };
76 
77 static int __init da9055_i2c_init(void)
78 {
79 	int ret;
80 
81 	ret = i2c_add_driver(&da9055_i2c_driver);
82 	if (ret != 0) {
83 		pr_err("DA9055 I2C registration failed %d\n", ret);
84 		return ret;
85 	}
86 
87 	return 0;
88 }
89 subsys_initcall(da9055_i2c_init);
90 
91 static void __exit da9055_i2c_exit(void)
92 {
93 	i2c_del_driver(&da9055_i2c_driver);
94 }
95 module_exit(da9055_i2c_exit);
96 
97 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
98 MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
99