Skip to content

Commit ee999fb

Browse files
Tomasz FigaSamuel Ortiz
authored andcommitted
mfd: max8998: Add support for Device Tree
This patch adds Device Tree support to max8998 driver. Signed-off-by: Tomasz Figa <t.figa@samsung.com> Acked-by: Mark Brown <broonie@linaro.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 4280e0b commit ee999fb

6 files changed

Lines changed: 316 additions & 7 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
* Maxim MAX8998, National/TI LP3974 multi-function device
2+
3+
The Maxim MAX8998 is a multi-function device which includes voltage/current
4+
regulators, real time clock, battery charging controller and several
5+
other sub-blocks. It is interfaced using an I2C interface. Each sub-block
6+
is addressed by the host system using different i2c slave address.
7+
8+
PMIC sub-block
9+
--------------
10+
11+
The PMIC sub-block contains a number of voltage and current regulators,
12+
with controllable parameters and dynamic voltage scaling capability.
13+
In addition, it includes a real time clock and battery charging controller
14+
as well. It is accessible at I2C address 0x66.
15+
16+
Required properties:
17+
- compatible: Should be one of the following:
18+
- "maxim,max8998" for Maxim MAX8998
19+
- "national,lp3974" or "ti,lp3974" for National/TI LP3974.
20+
- reg: Specifies the i2c slave address of the pmic block. It should be 0x66.
21+
22+
Optional properties:
23+
- interrupt-parent: Specifies the phandle of the interrupt controller to which
24+
the interrupts from MAX8998 are routed to.
25+
- interrupts: Interrupt specifiers for two interrupt sources.
26+
- First interrupt specifier is for main interrupt.
27+
- Second interrupt specifier is for power-on/-off interrupt.
28+
- max8998,pmic-buck1-dvs-gpios: GPIO specifiers for two host gpios used
29+
for buck 1 dvs. The format of the gpio specifier depends on the gpio
30+
controller.
31+
- max8998,pmic-buck2-dvs-gpio: GPIO specifier for host gpio used
32+
for buck 2 dvs. The format of the gpio specifier depends on the gpio
33+
controller.
34+
- max8998,pmic-buck1-default-dvs-idx: Default voltage setting selected from
35+
the possible 4 options selectable by the dvs gpios. The value of this
36+
property should be 0, 1, 2 or 3. If not specified or out of range,
37+
a default value of 0 is taken.
38+
- max8998,pmic-buck2-default-dvs-idx: Default voltage setting selected from
39+
the possible 2 options selectable by the dvs gpios. The value of this
40+
property should be 0 or 1. If not specified or out of range, a default
41+
value of 0 is taken.
42+
- max8998,pmic-buck-voltage-lock: If present, disallows changing of
43+
preprogrammed buck dvfs voltages.
44+
45+
Additional properties required if max8998,pmic-buck1-dvs-gpios is defined:
46+
- max8998,pmic-buck1-dvs-voltage: An array of 4 voltage values in microvolts
47+
for buck1 regulator that can be selected using dvs gpio.
48+
49+
Additional properties required if max8998,pmic-buck2-dvs-gpio is defined:
50+
- max8998,pmic-buck2-dvs-voltage: An array of 2 voltage values in microvolts
51+
for buck2 regulator that can be selected using dvs gpio.
52+
53+
Regulators: All the regulators of MAX8998 to be instantiated shall be
54+
listed in a child node named 'regulators'. Each regulator is represented
55+
by a child node of the 'regulators' node.
56+
57+
regulator-name {
58+
/* standard regulator bindings here */
59+
};
60+
61+
Following regulators of the MAX8998 PMIC block are supported. Note that
62+
the 'n' in regulator name, as in LDOn or BUCKn, represents the LDO or BUCK
63+
number as described in MAX8998 datasheet.
64+
65+
- LDOn
66+
- valid values for n are 2 to 17
67+
- Example: LDO2, LDO10, LDO17
68+
- BUCKn
69+
- valid values for n are 1 to 4.
70+
- Example: BUCK1, BUCK2, BUCK3, BUCK4
71+
72+
- ENVICHG: Battery Charging Current Monitor Output. This is a fixed
73+
voltage type regulator
74+
75+
- ESAFEOUT1: (ldo19)
76+
- ESAFEOUT2: (ld020)
77+
78+
Standard regulator bindings are used inside regulator subnodes. Check
79+
Documentation/devicetree/bindings/regulator/regulator.txt
80+
for more details.
81+
82+
Example:
83+
84+
pmic@66 {
85+
compatible = "maxim,max8998-pmic";
86+
reg = <0x66>;
87+
interrupt-parent = <&wakeup_eint>;
88+
interrupts = <4 0>, <3 0>;
89+
90+
/* Buck 1 DVS settings */
91+
max8998,pmic-buck1-default-dvs-idx = <0>;
92+
max8998,pmic-buck1-dvs-gpios = <&gpx0 0 1 0 0>, /* SET1 */
93+
<&gpx0 1 1 0 0>; /* SET2 */
94+
max8998,pmic-buck1-dvs-voltage = <1350000>, <1300000>,
95+
<1000000>, <950000>;
96+
97+
/* Buck 2 DVS settings */
98+
max8998,pmic-buck2-default-dvs-idx = <0>;
99+
max8998,pmic-buck2-dvs-gpio = <&gpx0 0 3 0 0>; /* SET3 */
100+
max8998,pmic-buck2-dvs-voltage = <1350000>, <1300000>;
101+
102+
/* Regulators to instantiate */
103+
regulators {
104+
ldo2_reg: LDO2 {
105+
regulator-name = "VDD_ALIVE_1.1V";
106+
regulator-min-microvolt = <1100000>;
107+
regulator-max-microvolt = <1100000>;
108+
regulator-always-on;
109+
};
110+
111+
buck1_reg: BUCK1 {
112+
regulator-name = "VDD_ARM_1.2V";
113+
regulator-min-microvolt = <950000>;
114+
regulator-max-microvolt = <1350000>;
115+
regulator-always-on;
116+
regulator-boot-on;
117+
};
118+
};
119+
};

‎drivers/mfd/max8998.c‎

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121
*/
2222

23+
#include <linux/err.h>
2324
#include <linux/module.h>
2425
#include <linux/moduleparam.h>
2526
#include <linux/init.h>
2627
#include <linux/slab.h>
2728
#include <linux/i2c.h>
2829
#include <linux/interrupt.h>
30+
#include <linux/of.h>
31+
#include <linux/of_irq.h>
2932
#include <linux/pm_runtime.h>
3033
#include <linux/mutex.h>
3134
#include <linux/mfd/core.h>
@@ -128,6 +131,56 @@ int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
128131
}
129132
EXPORT_SYMBOL(max8998_update_reg);
130133

134+
#ifdef CONFIG_OF
135+
static struct of_device_id max8998_dt_match[] = {
136+
{ .compatible = "maxim,max8998", .data = (void *)TYPE_MAX8998 },
137+
{ .compatible = "national,lp3974", .data = (void *)TYPE_LP3974 },
138+
{ .compatible = "ti,lp3974", .data = (void *)TYPE_LP3974 },
139+
{},
140+
};
141+
MODULE_DEVICE_TABLE(of, max8998_dt_match);
142+
#endif
143+
144+
/*
145+
* Only the common platform data elements for max8998 are parsed here from the
146+
* device tree. Other sub-modules of max8998 such as pmic, rtc and others have
147+
* to parse their own platform data elements from device tree.
148+
*
149+
* The max8998 platform data structure is instantiated here and the drivers for
150+
* the sub-modules need not instantiate another instance while parsing their
151+
* platform data.
152+
*/
153+
static struct max8998_platform_data *max8998_i2c_parse_dt_pdata(
154+
struct device *dev)
155+
{
156+
struct max8998_platform_data *pd;
157+
158+
pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
159+
if (!pd)
160+
return ERR_PTR(-ENOMEM);
161+
162+
pd->ono = irq_of_parse_and_map(dev->of_node, 1);
163+
164+
/*
165+
* ToDo: the 'wakeup' member in the platform data is more of a linux
166+
* specfic information. Hence, there is no binding for that yet and
167+
* not parsed here.
168+
*/
169+
return pd;
170+
}
171+
172+
static inline int max8998_i2c_get_driver_data(struct i2c_client *i2c,
173+
const struct i2c_device_id *id)
174+
{
175+
if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
176+
const struct of_device_id *match;
177+
match = of_match_node(max8998_dt_match, i2c->dev.of_node);
178+
return (int)match->data;
179+
}
180+
181+
return (int)id->driver_data;
182+
}
183+
131184
static int max8998_i2c_probe(struct i2c_client *i2c,
132185
const struct i2c_device_id *id)
133186
{
@@ -139,11 +192,20 @@ static int max8998_i2c_probe(struct i2c_client *i2c,
139192
if (max8998 == NULL)
140193
return -ENOMEM;
141194

195+
if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
196+
pdata = max8998_i2c_parse_dt_pdata(&i2c->dev);
197+
if (IS_ERR(pdata)) {
198+
ret = PTR_ERR(pdata);
199+
goto err;
200+
}
201+
}
202+
142203
i2c_set_clientdata(i2c, max8998);
143204
max8998->dev = &i2c->dev;
144205
max8998->i2c = i2c;
145206
max8998->irq = i2c->irq;
146-
max8998->type = id->driver_data;
207+
max8998->type = max8998_i2c_get_driver_data(i2c, id);
208+
max8998->pdata = pdata;
147209
if (pdata) {
148210
max8998->ono = pdata->ono;
149211
max8998->irq_base = pdata->irq_base;
@@ -158,7 +220,7 @@ static int max8998_i2c_probe(struct i2c_client *i2c,
158220

159221
pm_runtime_set_active(max8998->dev);
160222

161-
switch (id->driver_data) {
223+
switch (max8998->type) {
162224
case TYPE_LP3974:
163225
ret = mfd_add_devices(max8998->dev, -1,
164226
lp3974_devs, ARRAY_SIZE(lp3974_devs),
@@ -314,6 +376,7 @@ static struct i2c_driver max8998_i2c_driver = {
314376
.name = "max8998",
315377
.owner = THIS_MODULE,
316378
.pm = &max8998_pm,
379+
.of_match_table = of_match_ptr(max8998_dt_match),
317380
},
318381
.probe = max8998_i2c_probe,
319382
.remove = max8998_i2c_remove,

0 commit comments

Comments
 (0)