diff options
author | Gyungoh Yoo <jack.yoo@maxim-ic.com> | 2012-08-15 12:28:46 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-09-17 09:03:28 -0400 |
commit | a91d2f8d6e4c0fd3d6e1a2b5609eb93b114effb6 (patch) | |
tree | 500b88f82e1010a0ce56d363830dba31809eeb52 | |
parent | 7fb9c1a4851562e9f9b522ff929c0742797f301a (diff) |
mfd: Add MAX8907 core driver
The MAX8907 is an I2C-based power-management IC containing voltage
regulators, a reset controller, a real-time clock, and a touch-screen
controller.
The original driver was written by:
* Gyungoh Yoo <jack.yoo@maxim-ic.com>
Various fixes and enhancements by:
* Jin Park <jinyoungp@nvidia.com>
* Tom Cherry <tcherry@nvidia.com>
* Prashant Gaikwad <pgaikwad@nvidia.com>
* Dan Willemsen <dwillemsen@nvidia.com>
* Laxman Dewangan <ldewangan@nvidia.com>
During upstreaming, I (swarren):
* Converted to regmap.
* Converted to regmap-irq.
* Allowed probing from device tree.
* Renamed from max8907c->max8907, since the driver covers at least the
C and B revisions.
* General cleanup.
Signed-off-by: Gyungoh Yoo <jack.yoo@maxim-ic.com>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com> #v3
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r-- | Documentation/devicetree/bindings/regulator/max8907.txt | 71 | ||||
-rw-r--r-- | drivers/mfd/Kconfig | 12 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 1 | ||||
-rw-r--r-- | drivers/mfd/max8907.c | 331 | ||||
-rw-r--r-- | include/linux/mfd/max8907.h | 250 |
5 files changed, 665 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/regulator/max8907.txt b/Documentation/devicetree/bindings/regulator/max8907.txt new file mode 100644 index 000000000000..4fd847f0afc0 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/max8907.txt | |||
@@ -0,0 +1,71 @@ | |||
1 | MAX8907 regulator | ||
2 | |||
3 | Required properties: | ||
4 | - compatible: "maxim,max8907" | ||
5 | - reg: I2C slave address | ||
6 | - interrupts: The interrupt output of the controller | ||
7 | - mbatt-supply: The input supply for MBATT, BBAT, SDBY, VRTC. | ||
8 | - in-v1-supply: The input supply for SD1. | ||
9 | - in-v2-supply: The input supply for SD2. | ||
10 | - in-v3-supply: The input supply for SD3. | ||
11 | - in1-supply: The input supply for LDO1. | ||
12 | ... | ||
13 | - in20-supply: The input supply for LDO20. | ||
14 | - regulators: A node that houses a sub-node for each regulator within the | ||
15 | device. Each sub-node is identified using the regulator-compatible | ||
16 | property, with valid values listed below. The content of each sub-node | ||
17 | is defined by the standard binding for regulators; see regulator.txt. | ||
18 | |||
19 | Valid regulator-compatible values are: | ||
20 | |||
21 | sd1, sd2, sd3, ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8, ldo9, ldo10, | ||
22 | ldo11, ldo12, ldo13, ldo14, ldo15, ldo16, ldo17, ldo18, ldo19, ldo20, out5v, | ||
23 | out33v, bbat, sdby, vrtc. | ||
24 | |||
25 | Example: | ||
26 | |||
27 | max8907@3c { | ||
28 | compatible = "maxim,max8907"; | ||
29 | reg = <0x3c>; | ||
30 | interrupts = <0 86 0x4>; | ||
31 | |||
32 | mbatt-supply = <&some_reg>; | ||
33 | in-v1-supply = <&mbatt_reg>; | ||
34 | ... | ||
35 | in1-supply = <&mbatt_reg>; | ||
36 | ... | ||
37 | |||
38 | regulators { | ||
39 | #address-cells = <1>; | ||
40 | #size-cells = <0>; | ||
41 | |||
42 | mbatt_reg: regulator@0 { | ||
43 | reg = <0>; | ||
44 | regulator-compatible = "mbatt"; | ||
45 | regulator-name = "vbat_pmu"; | ||
46 | regulator-min-microvolt = <5000000>; | ||
47 | regulator-max-microvolt = <5000000>; | ||
48 | regulator-always-on; | ||
49 | }; | ||
50 | |||
51 | regulator@1 { | ||
52 | reg = <1>; | ||
53 | regulator-compatible = "sd1"; | ||
54 | regulator-name = "nvvdd_sv1,vdd_cpu_pmu"; | ||
55 | regulator-min-microvolt = <1000000>; | ||
56 | regulator-max-microvolt = <1000000>; | ||
57 | regulator-always-on; | ||
58 | }; | ||
59 | |||
60 | regulator@2 { | ||
61 | reg = <2>; | ||
62 | regulator-compatible = "sd2"; | ||
63 | regulator-name = "nvvdd_sv2,vdd_core"; | ||
64 | regulator-min-microvolt = <1200000>; | ||
65 | regulator-max-microvolt = <1200000>; | ||
66 | regulator-always-on; | ||
67 | }; | ||
68 | ... | ||
69 | }; | ||
70 | }; | ||
71 | }; | ||
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index d1facef28a60..856ec00ab787 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -476,6 +476,18 @@ config MFD_MAX77693 | |||
476 | additional drivers must be enabled in order to use the functionality | 476 | additional drivers must be enabled in order to use the functionality |
477 | of the device. | 477 | of the device. |
478 | 478 | ||
479 | config MFD_MAX8907 | ||
480 | tristate "Maxim Semiconductor MAX8907 PMIC Support" | ||
481 | select MFD_CORE | ||
482 | depends on I2C=y && GENERIC_HARDIRQS | ||
483 | select REGMAP_I2C | ||
484 | select REGMAP_IRQ | ||
485 | help | ||
486 | Say yes here to support for Maxim Semiconductor MAX8907. This is | ||
487 | a Power Management IC. This driver provides common support for | ||
488 | accessing the device; additional drivers must be enabled in order | ||
489 | to use the functionality of the device. | ||
490 | |||
479 | config MFD_MAX8925 | 491 | config MFD_MAX8925 |
480 | bool "Maxim Semiconductor MAX8925 PMIC Support" | 492 | bool "Maxim Semiconductor MAX8925 PMIC Support" |
481 | depends on I2C=y && GENERIC_HARDIRQS | 493 | depends on I2C=y && GENERIC_HARDIRQS |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 79dd22d1dc3d..2a4108d98442 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -92,6 +92,7 @@ obj-$(CONFIG_MFD_DA9052_I2C) += da9052-i2c.o | |||
92 | 92 | ||
93 | obj-$(CONFIG_MFD_MAX77686) += max77686.o max77686-irq.o | 93 | obj-$(CONFIG_MFD_MAX77686) += max77686.o max77686-irq.o |
94 | obj-$(CONFIG_MFD_MAX77693) += max77693.o max77693-irq.o | 94 | obj-$(CONFIG_MFD_MAX77693) += max77693.o max77693-irq.o |
95 | obj-$(CONFIG_MFD_MAX8907) += max8907.o | ||
95 | max8925-objs := max8925-core.o max8925-i2c.o | 96 | max8925-objs := max8925-core.o max8925-i2c.o |
96 | obj-$(CONFIG_MFD_MAX8925) += max8925.o | 97 | obj-$(CONFIG_MFD_MAX8925) += max8925.o |
97 | obj-$(CONFIG_MFD_MAX8997) += max8997.o max8997-irq.o | 98 | obj-$(CONFIG_MFD_MAX8997) += max8997.o max8997-irq.o |
diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c new file mode 100644 index 000000000000..6497c98e030d --- /dev/null +++ b/drivers/mfd/max8907.c | |||
@@ -0,0 +1,331 @@ | |||
1 | /* | ||
2 | * max8907.c - mfd driver for MAX8907 | ||
3 | * | ||
4 | * Copyright (C) 2010 Gyungoh Yoo <jack.yoo@maxim-ic.com> | ||
5 | * Copyright (C) 2010-2012, NVIDIA CORPORATION. All rights reserved. | ||
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 version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/err.h> | ||
13 | #include <linux/i2c.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/interrupt.h> | ||
16 | #include <linux/irq.h> | ||
17 | #include <linux/mfd/core.h> | ||
18 | #include <linux/mfd/max8907.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/of_device.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/slab.h> | ||
23 | |||
24 | static struct mfd_cell max8907_cells[] = { | ||
25 | { .name = "max8907-regulator", }, | ||
26 | { .name = "max8907-rtc", }, | ||
27 | }; | ||
28 | |||
29 | static bool max8907_gen_is_volatile_reg(struct device *dev, unsigned int reg) | ||
30 | { | ||
31 | switch (reg) { | ||
32 | case MAX8907_REG_ON_OFF_IRQ1: | ||
33 | case MAX8907_REG_ON_OFF_STAT: | ||
34 | case MAX8907_REG_ON_OFF_IRQ2: | ||
35 | case MAX8907_REG_CHG_IRQ1: | ||
36 | case MAX8907_REG_CHG_IRQ2: | ||
37 | case MAX8907_REG_CHG_STAT: | ||
38 | return true; | ||
39 | default: | ||
40 | return false; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | static bool max8907_gen_is_precious_reg(struct device *dev, unsigned int reg) | ||
45 | { | ||
46 | switch (reg) { | ||
47 | case MAX8907_REG_ON_OFF_IRQ1: | ||
48 | case MAX8907_REG_ON_OFF_IRQ2: | ||
49 | case MAX8907_REG_CHG_IRQ1: | ||
50 | case MAX8907_REG_CHG_IRQ2: | ||
51 | return true; | ||
52 | default: | ||
53 | return false; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | static bool max8907_gen_is_writeable_reg(struct device *dev, unsigned int reg) | ||
58 | { | ||
59 | return !max8907_gen_is_volatile_reg(dev, reg); | ||
60 | } | ||
61 | |||
62 | static const struct regmap_config max8907_regmap_gen_config = { | ||
63 | .reg_bits = 8, | ||
64 | .val_bits = 8, | ||
65 | .volatile_reg = max8907_gen_is_volatile_reg, | ||
66 | .precious_reg = max8907_gen_is_precious_reg, | ||
67 | .writeable_reg = max8907_gen_is_writeable_reg, | ||
68 | .max_register = MAX8907_REG_LDO20VOUT, | ||
69 | .cache_type = REGCACHE_RBTREE, | ||
70 | }; | ||
71 | |||
72 | static bool max8907_rtc_is_volatile_reg(struct device *dev, unsigned int reg) | ||
73 | { | ||
74 | if (reg <= MAX8907_REG_RTC_YEAR2) | ||
75 | return true; | ||
76 | |||
77 | switch (reg) { | ||
78 | case MAX8907_REG_RTC_STATUS: | ||
79 | case MAX8907_REG_RTC_IRQ: | ||
80 | return true; | ||
81 | default: | ||
82 | return false; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | static bool max8907_rtc_is_precious_reg(struct device *dev, unsigned int reg) | ||
87 | { | ||
88 | switch (reg) { | ||
89 | case MAX8907_REG_RTC_IRQ: | ||
90 | return true; | ||
91 | default: | ||
92 | return false; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | static bool max8907_rtc_is_writeable_reg(struct device *dev, unsigned int reg) | ||
97 | { | ||
98 | switch (reg) { | ||
99 | case MAX8907_REG_RTC_STATUS: | ||
100 | case MAX8907_REG_RTC_IRQ: | ||
101 | return false; | ||
102 | default: | ||
103 | return true; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | static const struct regmap_config max8907_regmap_rtc_config = { | ||
108 | .reg_bits = 8, | ||
109 | .val_bits = 8, | ||
110 | .volatile_reg = max8907_rtc_is_volatile_reg, | ||
111 | .precious_reg = max8907_rtc_is_precious_reg, | ||
112 | .writeable_reg = max8907_rtc_is_writeable_reg, | ||
113 | .max_register = MAX8907_REG_MPL_CNTL, | ||
114 | .cache_type = REGCACHE_RBTREE, | ||
115 | }; | ||
116 | |||
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, }, | ||
129 | }; | ||
130 | |||
131 | static const struct regmap_irq_chip max8907_chg_irq_chip = { | ||
132 | .name = "max8907 chg", | ||
133 | .status_base = MAX8907_REG_CHG_IRQ1, | ||
134 | .mask_base = MAX8907_REG_CHG_IRQ1_MASK, | ||
135 | .wake_base = MAX8907_REG_CHG_IRQ1_MASK, | ||
136 | .irq_reg_stride = MAX8907_REG_CHG_IRQ2 - MAX8907_REG_CHG_IRQ1, | ||
137 | .num_regs = 2, | ||
138 | .irqs = max8907_chg_irqs, | ||
139 | .num_irqs = ARRAY_SIZE(max8907_chg_irqs), | ||
140 | }; | ||
141 | |||
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, }, | ||
153 | }; | ||
154 | |||
155 | static const struct regmap_irq_chip max8907_on_off_irq_chip = { | ||
156 | .name = "max8907 on_off", | ||
157 | .status_base = MAX8907_REG_ON_OFF_IRQ1, | ||
158 | .mask_base = MAX8907_REG_ON_OFF_IRQ1_MASK, | ||
159 | .irq_reg_stride = MAX8907_REG_ON_OFF_IRQ2 - MAX8907_REG_ON_OFF_IRQ1, | ||
160 | .num_regs = 2, | ||
161 | .irqs = max8907_on_off_irqs, | ||
162 | .num_irqs = ARRAY_SIZE(max8907_on_off_irqs), | ||
163 | }; | ||
164 | |||
165 | static const struct regmap_irq max8907_rtc_irqs[] = { | ||
166 | { .reg_offset = 0, .mask = 1 << 2, }, | ||
167 | { .reg_offset = 0, .mask = 1 << 3, }, | ||
168 | }; | ||
169 | |||
170 | static const struct regmap_irq_chip max8907_rtc_irq_chip = { | ||
171 | .name = "max8907 rtc", | ||
172 | .status_base = MAX8907_REG_RTC_IRQ, | ||
173 | .mask_base = MAX8907_REG_RTC_IRQ_MASK, | ||
174 | .num_regs = 1, | ||
175 | .irqs = max8907_rtc_irqs, | ||
176 | .num_irqs = ARRAY_SIZE(max8907_rtc_irqs), | ||
177 | }; | ||
178 | |||
179 | static __devinit int max8907_i2c_probe(struct i2c_client *i2c, | ||
180 | const struct i2c_device_id *id) | ||
181 | { | ||
182 | struct max8907 *max8907; | ||
183 | int ret; | ||
184 | |||
185 | max8907 = devm_kzalloc(&i2c->dev, sizeof(struct max8907), GFP_KERNEL); | ||
186 | if (!max8907) { | ||
187 | ret = -ENOMEM; | ||
188 | goto err_alloc_drvdata; | ||
189 | } | ||
190 | |||
191 | max8907->dev = &i2c->dev; | ||
192 | dev_set_drvdata(max8907->dev, max8907); | ||
193 | |||
194 | max8907->i2c_gen = i2c; | ||
195 | i2c_set_clientdata(i2c, max8907); | ||
196 | max8907->regmap_gen = devm_regmap_init_i2c(i2c, | ||
197 | &max8907_regmap_gen_config); | ||
198 | if (IS_ERR(max8907->regmap_gen)) { | ||
199 | ret = PTR_ERR(max8907->regmap_gen); | ||
200 | dev_err(&i2c->dev, "gen regmap init failed: %d\n", ret); | ||
201 | goto err_regmap_gen; | ||
202 | } | ||
203 | |||
204 | max8907->i2c_rtc = i2c_new_dummy(i2c->adapter, MAX8907_RTC_I2C_ADDR); | ||
205 | if (!max8907->i2c_rtc) { | ||
206 | ret = -ENOMEM; | ||
207 | goto err_dummy_rtc; | ||
208 | } | ||
209 | i2c_set_clientdata(max8907->i2c_rtc, max8907); | ||
210 | max8907->regmap_rtc = devm_regmap_init_i2c(max8907->i2c_rtc, | ||
211 | &max8907_regmap_rtc_config); | ||
212 | if (IS_ERR(max8907->regmap_rtc)) { | ||
213 | ret = PTR_ERR(max8907->regmap_rtc); | ||
214 | dev_err(&i2c->dev, "rtc regmap init failed: %d\n", ret); | ||
215 | goto err_regmap_rtc; | ||
216 | } | ||
217 | |||
218 | irq_set_status_flags(max8907->i2c_gen->irq, IRQ_NOAUTOEN); | ||
219 | |||
220 | ret = regmap_add_irq_chip(max8907->regmap_gen, max8907->i2c_gen->irq, | ||
221 | IRQF_ONESHOT | IRQF_SHARED, -1, | ||
222 | &max8907_chg_irq_chip, | ||
223 | &max8907->irqc_chg); | ||
224 | if (ret != 0) { | ||
225 | dev_err(&i2c->dev, "failed to add chg irq chip: %d\n", ret); | ||
226 | goto err_irqc_chg; | ||
227 | } | ||
228 | ret = regmap_add_irq_chip(max8907->regmap_gen, max8907->i2c_gen->irq, | ||
229 | IRQF_ONESHOT | IRQF_SHARED, -1, | ||
230 | &max8907_on_off_irq_chip, | ||
231 | &max8907->irqc_on_off); | ||
232 | if (ret != 0) { | ||
233 | dev_err(&i2c->dev, "failed to add on off irq chip: %d\n", ret); | ||
234 | goto err_irqc_on_off; | ||
235 | } | ||
236 | ret = regmap_add_irq_chip(max8907->regmap_rtc, max8907->i2c_gen->irq, | ||
237 | IRQF_ONESHOT | IRQF_SHARED, -1, | ||
238 | &max8907_rtc_irq_chip, | ||
239 | &max8907->irqc_rtc); | ||
240 | if (ret != 0) { | ||
241 | dev_err(&i2c->dev, "failed to add rtc irq chip: %d\n", ret); | ||
242 | goto err_irqc_rtc; | ||
243 | } | ||
244 | |||
245 | enable_irq(max8907->i2c_gen->irq); | ||
246 | |||
247 | ret = mfd_add_devices(max8907->dev, -1, max8907_cells, | ||
248 | ARRAY_SIZE(max8907_cells), NULL, 0, NULL); | ||
249 | if (ret != 0) { | ||
250 | dev_err(&i2c->dev, "failed to add MFD devices %d\n", ret); | ||
251 | goto err_add_devices; | ||
252 | } | ||
253 | |||
254 | return 0; | ||
255 | |||
256 | err_add_devices: | ||
257 | regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_rtc); | ||
258 | err_irqc_rtc: | ||
259 | regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_on_off); | ||
260 | err_irqc_on_off: | ||
261 | regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_chg); | ||
262 | err_irqc_chg: | ||
263 | err_regmap_rtc: | ||
264 | i2c_unregister_device(max8907->i2c_rtc); | ||
265 | err_dummy_rtc: | ||
266 | err_regmap_gen: | ||
267 | err_alloc_drvdata: | ||
268 | return ret; | ||
269 | } | ||
270 | |||
271 | static __devexit int max8907_i2c_remove(struct i2c_client *i2c) | ||
272 | { | ||
273 | struct max8907 *max8907 = i2c_get_clientdata(i2c); | ||
274 | |||
275 | mfd_remove_devices(max8907->dev); | ||
276 | |||
277 | regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_rtc); | ||
278 | regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_on_off); | ||
279 | regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_chg); | ||
280 | |||
281 | i2c_unregister_device(max8907->i2c_rtc); | ||
282 | |||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | #ifdef CONFIG_OF | ||
287 | static struct of_device_id max8907_of_match[] = { | ||
288 | { .compatible = "maxim,max8907" }, | ||
289 | { }, | ||
290 | }; | ||
291 | MODULE_DEVICE_TABLE(of, max8907_of_match); | ||
292 | #endif | ||
293 | |||
294 | static const struct i2c_device_id max8907_i2c_id[] = { | ||
295 | {"max8907", 0}, | ||
296 | {} | ||
297 | }; | ||
298 | MODULE_DEVICE_TABLE(i2c, max8907_i2c_id); | ||
299 | |||
300 | static struct i2c_driver max8907_i2c_driver = { | ||
301 | .driver = { | ||
302 | .name = "max8907", | ||
303 | .owner = THIS_MODULE, | ||
304 | .of_match_table = of_match_ptr(max8907_of_match), | ||
305 | }, | ||
306 | .probe = max8907_i2c_probe, | ||
307 | .remove = max8907_i2c_remove, | ||
308 | .id_table = max8907_i2c_id, | ||
309 | }; | ||
310 | |||
311 | static int __init max8907_i2c_init(void) | ||
312 | { | ||
313 | int ret = -ENODEV; | ||
314 | |||
315 | ret = i2c_add_driver(&max8907_i2c_driver); | ||
316 | if (ret != 0) | ||
317 | pr_err("Failed to register I2C driver: %d\n", ret); | ||
318 | |||
319 | return ret; | ||
320 | } | ||
321 | subsys_initcall(max8907_i2c_init); | ||
322 | |||
323 | static void __exit max8907_i2c_exit(void) | ||
324 | { | ||
325 | i2c_del_driver(&max8907_i2c_driver); | ||
326 | } | ||
327 | module_exit(max8907_i2c_exit); | ||
328 | |||
329 | MODULE_DESCRIPTION("MAX8907 multi-function core driver"); | ||
330 | MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@maxim-ic.com>"); | ||
331 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/include/linux/mfd/max8907.h b/include/linux/mfd/max8907.h new file mode 100644 index 000000000000..283531fde4e0 --- /dev/null +++ b/include/linux/mfd/max8907.h | |||
@@ -0,0 +1,250 @@ | |||
1 | /* | ||
2 | * Functions to access MAX8907 power management chip. | ||
3 | * | ||
4 | * Copyright (C) 2010 Gyungoh Yoo <jack.yoo@maxim-ic.com> | ||
5 | * Copyright (C) 2012, NVIDIA CORPORATION. All rights reserved. | ||
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 version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #ifndef __LINUX_MFD_MAX8907_H | ||
13 | #define __LINUX_MFD_MAX8907_H | ||
14 | |||
15 | #include <linux/mutex.h> | ||
16 | #include <linux/pm.h> | ||
17 | |||
18 | #define MAX8907_GEN_I2C_ADDR (0x78 >> 1) | ||
19 | #define MAX8907_ADC_I2C_ADDR (0x8e >> 1) | ||
20 | #define MAX8907_RTC_I2C_ADDR (0xd0 >> 1) | ||
21 | |||
22 | /* MAX8907 register map */ | ||
23 | #define MAX8907_REG_SYSENSEL 0x00 | ||
24 | #define MAX8907_REG_ON_OFF_IRQ1 0x01 | ||
25 | #define MAX8907_REG_ON_OFF_IRQ1_MASK 0x02 | ||
26 | #define MAX8907_REG_ON_OFF_STAT 0x03 | ||
27 | #define MAX8907_REG_SDCTL1 0x04 | ||
28 | #define MAX8907_REG_SDSEQCNT1 0x05 | ||
29 | #define MAX8907_REG_SDV1 0x06 | ||
30 | #define MAX8907_REG_SDCTL2 0x07 | ||
31 | #define MAX8907_REG_SDSEQCNT2 0x08 | ||
32 | #define MAX8907_REG_SDV2 0x09 | ||
33 | #define MAX8907_REG_SDCTL3 0x0A | ||
34 | #define MAX8907_REG_SDSEQCNT3 0x0B | ||
35 | #define MAX8907_REG_SDV3 0x0C | ||
36 | #define MAX8907_REG_ON_OFF_IRQ2 0x0D | ||
37 | #define MAX8907_REG_ON_OFF_IRQ2_MASK 0x0E | ||
38 | #define MAX8907_REG_RESET_CNFG 0x0F | ||
39 | #define MAX8907_REG_LDOCTL16 0x10 | ||
40 | #define MAX8907_REG_LDOSEQCNT16 0x11 | ||
41 | #define MAX8907_REG_LDO16VOUT 0x12 | ||
42 | #define MAX8907_REG_SDBYSEQCNT 0x13 | ||
43 | #define MAX8907_REG_LDOCTL17 0x14 | ||
44 | #define MAX8907_REG_LDOSEQCNT17 0x15 | ||
45 | #define MAX8907_REG_LDO17VOUT 0x16 | ||
46 | #define MAX8907_REG_LDOCTL1 0x18 | ||
47 | #define MAX8907_REG_LDOSEQCNT1 0x19 | ||
48 | #define MAX8907_REG_LDO1VOUT 0x1A | ||
49 | #define MAX8907_REG_LDOCTL2 0x1C | ||
50 | #define MAX8907_REG_LDOSEQCNT2 0x1D | ||
51 | #define MAX8907_REG_LDO2VOUT 0x1E | ||
52 | #define MAX8907_REG_LDOCTL3 0x20 | ||
53 | #define MAX8907_REG_LDOSEQCNT3 0x21 | ||
54 | #define MAX8907_REG_LDO3VOUT 0x22 | ||
55 | #define MAX8907_REG_LDOCTL4 0x24 | ||
56 | #define MAX8907_REG_LDOSEQCNT4 0x25 | ||
57 | #define MAX8907_REG_LDO4VOUT 0x26 | ||
58 | #define MAX8907_REG_LDOCTL5 0x28 | ||
59 | #define MAX8907_REG_LDOSEQCNT5 0x29 | ||
60 | #define MAX8907_REG_LDO5VOUT 0x2A | ||
61 | #define MAX8907_REG_LDOCTL6 0x2C | ||
62 | #define MAX8907_REG_LDOSEQCNT6 0x2D | ||
63 | #define MAX8907_REG_LDO6VOUT 0x2E | ||
64 | #define MAX8907_REG_LDOCTL7 0x30 | ||
65 | #define MAX8907_REG_LDOSEQCNT7 0x31 | ||
66 | #define MAX8907_REG_LDO7VOUT 0x32 | ||
67 | #define MAX8907_REG_LDOCTL8 0x34 | ||
68 | #define MAX8907_REG_LDOSEQCNT8 0x35 | ||
69 | #define MAX8907_REG_LDO8VOUT 0x36 | ||
70 | #define MAX8907_REG_LDOCTL9 0x38 | ||
71 | #define MAX8907_REG_LDOSEQCNT9 0x39 | ||
72 | #define MAX8907_REG_LDO9VOUT 0x3A | ||
73 | #define MAX8907_REG_LDOCTL10 0x3C | ||
74 | #define MAX8907_REG_LDOSEQCNT10 0x3D | ||
75 | #define MAX8907_REG_LDO10VOUT 0x3E | ||
76 | #define MAX8907_REG_LDOCTL11 0x40 | ||
77 | #define MAX8907_REG_LDOSEQCNT11 0x41 | ||
78 | #define MAX8907_REG_LDO11VOUT 0x42 | ||
79 | #define MAX8907_REG_LDOCTL12 0x44 | ||
80 | #define MAX8907_REG_LDOSEQCNT12 0x45 | ||
81 | #define MAX8907_REG_LDO12VOUT 0x46 | ||
82 | #define MAX8907_REG_LDOCTL13 0x48 | ||
83 | #define MAX8907_REG_LDOSEQCNT13 0x49 | ||
84 | #define MAX8907_REG_LDO13VOUT 0x4A | ||
85 | #define MAX8907_REG_LDOCTL14 0x4C | ||
86 | #define MAX8907_REG_LDOSEQCNT14 0x4D | ||
87 | #define MAX8907_REG_LDO14VOUT 0x4E | ||
88 | #define MAX8907_REG_LDOCTL15 0x50 | ||
89 | #define MAX8907_REG_LDOSEQCNT15 0x51 | ||
90 | #define MAX8907_REG_LDO15VOUT 0x52 | ||
91 | #define MAX8907_REG_OUT5VEN 0x54 | ||
92 | #define MAX8907_REG_OUT5VSEQ 0x55 | ||
93 | #define MAX8907_REG_OUT33VEN 0x58 | ||
94 | #define MAX8907_REG_OUT33VSEQ 0x59 | ||
95 | #define MAX8907_REG_LDOCTL19 0x5C | ||
96 | #define MAX8907_REG_LDOSEQCNT19 0x5D | ||
97 | #define MAX8907_REG_LDO19VOUT 0x5E | ||
98 | #define MAX8907_REG_LBCNFG 0x60 | ||
99 | #define MAX8907_REG_SEQ1CNFG 0x64 | ||
100 | #define MAX8907_REG_SEQ2CNFG 0x65 | ||
101 | #define MAX8907_REG_SEQ3CNFG 0x66 | ||
102 | #define MAX8907_REG_SEQ4CNFG 0x67 | ||
103 | #define MAX8907_REG_SEQ5CNFG 0x68 | ||
104 | #define MAX8907_REG_SEQ6CNFG 0x69 | ||
105 | #define MAX8907_REG_SEQ7CNFG 0x6A | ||
106 | #define MAX8907_REG_LDOCTL18 0x72 | ||
107 | #define MAX8907_REG_LDOSEQCNT18 0x73 | ||
108 | #define MAX8907_REG_LDO18VOUT 0x74 | ||
109 | #define MAX8907_REG_BBAT_CNFG 0x78 | ||
110 | #define MAX8907_REG_CHG_CNTL1 0x7C | ||
111 | #define MAX8907_REG_CHG_CNTL2 0x7D | ||
112 | #define MAX8907_REG_CHG_IRQ1 0x7E | ||
113 | #define MAX8907_REG_CHG_IRQ2 0x7F | ||
114 | #define MAX8907_REG_CHG_IRQ1_MASK 0x80 | ||
115 | #define MAX8907_REG_CHG_IRQ2_MASK 0x81 | ||
116 | #define MAX8907_REG_CHG_STAT 0x82 | ||
117 | #define MAX8907_REG_WLED_MODE_CNTL 0x84 | ||
118 | #define MAX8907_REG_ILED_CNTL 0x84 | ||
119 | #define MAX8907_REG_II1RR 0x8E | ||
120 | #define MAX8907_REG_II2RR 0x8F | ||
121 | #define MAX8907_REG_LDOCTL20 0x9C | ||
122 | #define MAX8907_REG_LDOSEQCNT20 0x9D | ||
123 | #define MAX8907_REG_LDO20VOUT 0x9E | ||
124 | |||
125 | /* RTC register map */ | ||
126 | #define MAX8907_REG_RTC_SEC 0x00 | ||
127 | #define MAX8907_REG_RTC_MIN 0x01 | ||
128 | #define MAX8907_REG_RTC_HOURS 0x02 | ||
129 | #define MAX8907_REG_RTC_WEEKDAY 0x03 | ||
130 | #define MAX8907_REG_RTC_DATE 0x04 | ||
131 | #define MAX8907_REG_RTC_MONTH 0x05 | ||
132 | #define MAX8907_REG_RTC_YEAR1 0x06 | ||
133 | #define MAX8907_REG_RTC_YEAR2 0x07 | ||
134 | #define MAX8907_REG_ALARM0_SEC 0x08 | ||
135 | #define MAX8907_REG_ALARM0_MIN 0x09 | ||
136 | #define MAX8907_REG_ALARM0_HOURS 0x0A | ||
137 | #define MAX8907_REG_ALARM0_WEEKDAY 0x0B | ||
138 | #define MAX8907_REG_ALARM0_DATE 0x0C | ||
139 | #define MAX8907_REG_ALARM0_MONTH 0x0D | ||
140 | #define MAX8907_REG_ALARM0_YEAR1 0x0E | ||
141 | #define MAX8907_REG_ALARM0_YEAR2 0x0F | ||
142 | #define MAX8907_REG_ALARM1_SEC 0x10 | ||
143 | #define MAX8907_REG_ALARM1_MIN 0x11 | ||
144 | #define MAX8907_REG_ALARM1_HOURS 0x12 | ||
145 | #define MAX8907_REG_ALARM1_WEEKDAY 0x13 | ||
146 | #define MAX8907_REG_ALARM1_DATE 0x14 | ||
147 | #define MAX8907_REG_ALARM1_MONTH 0x15 | ||
148 | #define MAX8907_REG_ALARM1_YEAR1 0x16 | ||
149 | #define MAX8907_REG_ALARM1_YEAR2 0x17 | ||
150 | #define MAX8907_REG_ALARM0_CNTL 0x18 | ||
151 | #define MAX8907_REG_ALARM1_CNTL 0x19 | ||
152 | #define MAX8907_REG_RTC_STATUS 0x1A | ||
153 | #define MAX8907_REG_RTC_CNTL 0x1B | ||
154 | #define MAX8907_REG_RTC_IRQ 0x1C | ||
155 | #define MAX8907_REG_RTC_IRQ_MASK 0x1D | ||
156 | #define MAX8907_REG_MPL_CNTL 0x1E | ||
157 | |||
158 | /* ADC and Touch Screen Controller register map */ | ||
159 | #define MAX8907_CTL 0 | ||
160 | #define MAX8907_SEQCNT 1 | ||
161 | #define MAX8907_VOUT 2 | ||
162 | |||
163 | /* mask bit fields */ | ||
164 | #define MAX8907_MASK_LDO_SEQ 0x1C | ||
165 | #define MAX8907_MASK_LDO_EN 0x01 | ||
166 | #define MAX8907_MASK_VBBATTCV 0x03 | ||
167 | #define MAX8907_MASK_OUT5V_VINEN 0x10 | ||
168 | #define MAX8907_MASK_OUT5V_ENSRC 0x0E | ||
169 | #define MAX8907_MASK_OUT5V_EN 0x01 | ||
170 | |||
171 | /* Regulator IDs */ | ||
172 | #define MAX8907_MBATT 0 | ||
173 | #define MAX8907_SD1 1 | ||
174 | #define MAX8907_SD2 2 | ||
175 | #define MAX8907_SD3 3 | ||
176 | #define MAX8907_LDO1 4 | ||
177 | #define MAX8907_LDO2 5 | ||
178 | #define MAX8907_LDO3 6 | ||
179 | #define MAX8907_LDO4 7 | ||
180 | #define MAX8907_LDO5 8 | ||
181 | #define MAX8907_LDO6 9 | ||
182 | #define MAX8907_LDO7 10 | ||
183 | #define MAX8907_LDO8 11 | ||
184 | #define MAX8907_LDO9 12 | ||
185 | #define MAX8907_LDO10 13 | ||
186 | #define MAX8907_LDO11 14 | ||
187 | #define MAX8907_LDO12 15 | ||
188 | #define MAX8907_LDO13 16 | ||
189 | #define MAX8907_LDO14 17 | ||
190 | #define MAX8907_LDO15 18 | ||
191 | #define MAX8907_LDO16 19 | ||
192 | #define MAX8907_LDO17 20 | ||
193 | #define MAX8907_LDO18 21 | ||
194 | #define MAX8907_LDO19 22 | ||
195 | #define MAX8907_LDO20 23 | ||
196 | #define MAX8907_OUT5V 24 | ||
197 | #define MAX8907_OUT33V 25 | ||
198 | #define MAX8907_BBAT 26 | ||
199 | #define MAX8907_SDBY 27 | ||
200 | #define MAX8907_VRTC 28 | ||
201 | #define MAX8907_NUM_REGULATORS (MAX8907_VRTC + 1) | ||
202 | |||
203 | /* IRQ definitions */ | ||
204 | enum { | ||
205 | MAX8907_IRQ_VCHG_DC_OVP = 0, | ||
206 | MAX8907_IRQ_VCHG_DC_F, | ||
207 | MAX8907_IRQ_VCHG_DC_R, | ||
208 | MAX8907_IRQ_VCHG_THM_OK_R, | ||
209 | MAX8907_IRQ_VCHG_THM_OK_F, | ||
210 | MAX8907_IRQ_VCHG_MBATTLOW_F, | ||
211 | MAX8907_IRQ_VCHG_MBATTLOW_R, | ||
212 | MAX8907_IRQ_VCHG_RST, | ||
213 | MAX8907_IRQ_VCHG_DONE, | ||
214 | MAX8907_IRQ_VCHG_TOPOFF, | ||
215 | MAX8907_IRQ_VCHG_TMR_FAULT, | ||
216 | |||
217 | MAX8907_IRQ_GPM_RSTIN = 0, | ||
218 | MAX8907_IRQ_GPM_MPL, | ||
219 | MAX8907_IRQ_GPM_SW_3SEC, | ||
220 | MAX8907_IRQ_GPM_EXTON_F, | ||
221 | MAX8907_IRQ_GPM_EXTON_R, | ||
222 | MAX8907_IRQ_GPM_SW_1SEC, | ||
223 | MAX8907_IRQ_GPM_SW_F, | ||
224 | MAX8907_IRQ_GPM_SW_R, | ||
225 | MAX8907_IRQ_GPM_SYSCKEN_F, | ||
226 | MAX8907_IRQ_GPM_SYSCKEN_R, | ||
227 | |||
228 | MAX8907_IRQ_RTC_ALARM1 = 0, | ||
229 | MAX8907_IRQ_RTC_ALARM0, | ||
230 | }; | ||
231 | |||
232 | struct max8907_platform_data { | ||
233 | struct regulator_init_data *init_data[MAX8907_NUM_REGULATORS]; | ||
234 | }; | ||
235 | |||
236 | struct regmap_irq_chips_data; | ||
237 | |||
238 | struct max8907 { | ||
239 | struct device *dev; | ||
240 | struct mutex irq_lock; | ||
241 | struct i2c_client *i2c_gen; | ||
242 | struct i2c_client *i2c_rtc; | ||
243 | struct regmap *regmap_gen; | ||
244 | struct regmap *regmap_rtc; | ||
245 | struct regmap_irq_chip_data *irqc_chg; | ||
246 | struct regmap_irq_chip_data *irqc_on_off; | ||
247 | struct regmap_irq_chip_data *irqc_rtc; | ||
248 | }; | ||
249 | |||
250 | #endif | ||