13 #include <linux/i2c.h>
19 #include <linux/module.h>
22 #include <linux/slab.h>
24 static struct mfd_cell max8907_cells[] = {
25 { .name =
"max8907-regulator", },
26 { .name =
"max8907-rtc", },
29 static bool max8907_gen_is_volatile_reg(
struct device *
dev,
unsigned int reg)
44 static bool max8907_gen_is_precious_reg(
struct device *dev,
unsigned int reg)
57 static bool max8907_gen_is_writeable_reg(
struct device *dev,
unsigned int reg)
59 return !max8907_gen_is_volatile_reg(dev, reg);
62 static const struct regmap_config max8907_regmap_gen_config = {
65 .volatile_reg = max8907_gen_is_volatile_reg,
66 .precious_reg = max8907_gen_is_precious_reg,
67 .writeable_reg = max8907_gen_is_writeable_reg,
72 static bool max8907_rtc_is_volatile_reg(
struct device *dev,
unsigned int reg)
86 static bool max8907_rtc_is_precious_reg(
struct device *dev,
unsigned int reg)
96 static bool max8907_rtc_is_writeable_reg(
struct device *dev,
unsigned int reg)
107 static const struct regmap_config max8907_regmap_rtc_config = {
110 .volatile_reg = max8907_rtc_is_volatile_reg,
111 .precious_reg = max8907_rtc_is_precious_reg,
112 .writeable_reg = max8907_rtc_is_writeable_reg,
117 static const struct regmap_irq max8907_chg_irqs[] = {
118 { .reg_offset = 0, .mask = 1 << 0, },
119 { .reg_offset = 0, .mask = 1 << 1, },
120 { .reg_offset = 0, .mask = 1 << 2, },
121 { .reg_offset = 1, .mask = 1 << 0, },
122 { .reg_offset = 1, .mask = 1 << 1, },
123 { .reg_offset = 1, .mask = 1 << 2, },
124 { .reg_offset = 1, .mask = 1 << 3, },
125 { .reg_offset = 1, .mask = 1 << 4, },
126 { .reg_offset = 1, .mask = 1 << 5, },
127 { .reg_offset = 1, .mask = 1 << 6, },
128 { .reg_offset = 1, .mask = 1 << 7, },
131 static const struct regmap_irq_chip max8907_chg_irq_chip = {
132 .name =
"max8907 chg",
138 .irqs = max8907_chg_irqs,
142 static const struct regmap_irq max8907_on_off_irqs[] = {
143 { .reg_offset = 0, .mask = 1 << 0, },
144 { .reg_offset = 0, .mask = 1 << 1, },
145 { .reg_offset = 0, .mask = 1 << 2, },
146 { .reg_offset = 0, .mask = 1 << 3, },
147 { .reg_offset = 0, .mask = 1 << 4, },
148 { .reg_offset = 0, .mask = 1 << 5, },
149 { .reg_offset = 0, .mask = 1 << 6, },
150 { .reg_offset = 0, .mask = 1 << 7, },
151 { .reg_offset = 1, .mask = 1 << 0, },
152 { .reg_offset = 1, .mask = 1 << 1, },
155 static const struct regmap_irq_chip max8907_on_off_irq_chip = {
156 .name =
"max8907 on_off",
161 .irqs = max8907_on_off_irqs,
165 static const struct regmap_irq max8907_rtc_irqs[] = {
166 { .reg_offset = 0, .mask = 1 << 2, },
167 { .reg_offset = 0, .mask = 1 << 3, },
170 static const struct regmap_irq_chip max8907_rtc_irq_chip = {
171 .name =
"max8907 rtc",
175 .irqs = max8907_rtc_irqs,
179 static struct max8907 *max8907_pm_off;
180 static void max8907_power_off(
void)
196 else if (i2c->
dev.of_node)
197 pm_off = of_property_read_bool(i2c->
dev.of_node,
198 "maxim,system-power-controller");
203 goto err_alloc_drvdata;
210 i2c_set_clientdata(i2c, max8907);
212 &max8907_regmap_gen_config);
215 dev_err(&i2c->
dev,
"gen regmap init failed: %d\n", ret);
224 i2c_set_clientdata(max8907->
i2c_rtc, max8907);
226 &max8907_regmap_rtc_config);
229 dev_err(&i2c->
dev,
"rtc regmap init failed: %d\n", ret);
237 &max8907_chg_irq_chip,
240 dev_err(&i2c->
dev,
"failed to add chg irq chip: %d\n", ret);
245 &max8907_on_off_irq_chip,
248 dev_err(&i2c->
dev,
"failed to add on off irq chip: %d\n", ret);
249 goto err_irqc_on_off;
253 &max8907_rtc_irq_chip,
256 dev_err(&i2c->
dev,
"failed to add rtc irq chip: %d\n", ret);
265 dev_err(&i2c->
dev,
"failed to add MFD devices %d\n", ret);
266 goto err_add_devices;
270 max8907_pm_off = max8907;
293 struct max8907 *max8907 = i2c_get_clientdata(i2c);
320 static struct i2c_driver max8907_i2c_driver = {
326 .probe = max8907_i2c_probe,
327 .remove = max8907_i2c_remove,
328 .id_table = max8907_i2c_id,
331 static int __init max8907_i2c_init(
void)
335 ret = i2c_add_driver(&max8907_i2c_driver);
337 pr_err(
"Failed to register I2C driver: %d\n", ret);
343 static void __exit max8907_i2c_exit(
void)