1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/module.h>
15#include <linux/device.h>
16#include <linux/i2c.h>
17#include <linux/err.h>
18#include <linux/of.h>
19#include <linux/of_device.h>
20
21#include <linux/mfd/da9055/core.h>
22
23static int da9055_i2c_probe(struct i2c_client *i2c,
24 const struct i2c_device_id *id)
25{
26 struct da9055 *da9055;
27 int ret;
28
29 da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
30 if (!da9055)
31 return -ENOMEM;
32
33 da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
34 if (IS_ERR(da9055->regmap)) {
35 ret = PTR_ERR(da9055->regmap);
36 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
37 ret);
38 return ret;
39 }
40
41 da9055->dev = &i2c->dev;
42 da9055->chip_irq = i2c->irq;
43
44 i2c_set_clientdata(i2c, da9055);
45
46 return da9055_device_init(da9055);
47}
48
49static int da9055_i2c_remove(struct i2c_client *i2c)
50{
51 struct da9055 *da9055 = i2c_get_clientdata(i2c);
52
53 da9055_device_exit(da9055);
54
55 return 0;
56}
57
58
59
60
61
62
63
64
65static const struct i2c_device_id da9055_i2c_id[] = {
66 {"da9055-pmic", 0},
67 { }
68};
69MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
70
71static const struct of_device_id da9055_of_match[] = {
72 { .compatible = "dlg,da9055-pmic", },
73 { }
74};
75
76static struct i2c_driver da9055_i2c_driver = {
77 .probe = da9055_i2c_probe,
78 .remove = da9055_i2c_remove,
79 .id_table = da9055_i2c_id,
80 .driver = {
81 .name = "da9055-pmic",
82 .of_match_table = of_match_ptr(da9055_of_match),
83 },
84};
85
86static int __init da9055_i2c_init(void)
87{
88 int ret;
89
90 ret = i2c_add_driver(&da9055_i2c_driver);
91 if (ret != 0) {
92 pr_err("DA9055 I2C registration failed %d\n", ret);
93 return ret;
94 }
95
96 return 0;
97}
98subsys_initcall(da9055_i2c_init);
99
100static void __exit da9055_i2c_exit(void)
101{
102 i2c_del_driver(&da9055_i2c_driver);
103}
104module_exit(da9055_i2c_exit);
105
106MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
107MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
108MODULE_LICENSE("GPL");
109