xref: /openbmc/linux/drivers/mfd/da9055-i2c.c (revision 12eb4683)
1  /* I2C access for DA9055 PMICs.
2  *
3  * Copyright(c) 2012 Dialog Semiconductor Ltd.
4  *
5  * Author: David Dajun Chen <dchen@diasemi.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  */
13 
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/i2c.h>
17 #include <linux/err.h>
18 
19 #include <linux/mfd/da9055/core.h>
20 
21 static int da9055_i2c_probe(struct i2c_client *i2c,
22 				      const struct i2c_device_id *id)
23 {
24 	struct da9055 *da9055;
25 	int ret;
26 
27 	da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
28 	if (!da9055)
29 		return -ENOMEM;
30 
31 	da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
32 	if (IS_ERR(da9055->regmap)) {
33 		ret = PTR_ERR(da9055->regmap);
34 		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
35 			ret);
36 		return ret;
37 	}
38 
39 	da9055->dev = &i2c->dev;
40 	da9055->chip_irq = i2c->irq;
41 
42 	i2c_set_clientdata(i2c, da9055);
43 
44 	return da9055_device_init(da9055);
45 }
46 
47 static int da9055_i2c_remove(struct i2c_client *i2c)
48 {
49 	struct da9055 *da9055 = i2c_get_clientdata(i2c);
50 
51 	da9055_device_exit(da9055);
52 
53 	return 0;
54 }
55 
56 static struct i2c_device_id da9055_i2c_id[] = {
57 	{"da9055", 0},
58 	{ }
59 };
60 
61 static struct i2c_driver da9055_i2c_driver = {
62 	.probe = da9055_i2c_probe,
63 	.remove = da9055_i2c_remove,
64 	.id_table = da9055_i2c_id,
65 	.driver = {
66 		.name = "da9055",
67 		.owner = THIS_MODULE,
68 	},
69 };
70 
71 static int __init da9055_i2c_init(void)
72 {
73 	int ret;
74 
75 	ret = i2c_add_driver(&da9055_i2c_driver);
76 	if (ret != 0) {
77 		pr_err("DA9055 I2C registration failed %d\n", ret);
78 		return ret;
79 	}
80 
81 	return 0;
82 }
83 subsys_initcall(da9055_i2c_init);
84 
85 static void __exit da9055_i2c_exit(void)
86 {
87 	i2c_del_driver(&da9055_i2c_driver);
88 }
89 module_exit(da9055_i2c_exit);
90 
91 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
92 MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
93 MODULE_LICENSE("GPL");
94