diff options
Diffstat (limited to 'drivers/mfd/max8997.c')
-rw-r--r-- | drivers/mfd/max8997.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c index f123517065ec..abd5c80c7cf5 100644 --- a/drivers/mfd/max8997.c +++ b/drivers/mfd/max8997.c | |||
@@ -21,8 +21,10 @@ | |||
21 | * This driver is based on max8998.c | 21 | * This driver is based on max8998.c |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/err.h> | ||
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
25 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include <linux/of_irq.h> | ||
26 | #include <linux/interrupt.h> | 28 | #include <linux/interrupt.h> |
27 | #include <linux/pm_runtime.h> | 29 | #include <linux/pm_runtime.h> |
28 | #include <linux/module.h> | 30 | #include <linux/module.h> |
@@ -47,6 +49,13 @@ static struct mfd_cell max8997_devs[] = { | |||
47 | { .name = "max8997-led", .id = 2 }, | 49 | { .name = "max8997-led", .id = 2 }, |
48 | }; | 50 | }; |
49 | 51 | ||
52 | #ifdef CONFIG_OF | ||
53 | static struct of_device_id __devinitdata max8997_pmic_dt_match[] = { | ||
54 | { .compatible = "maxim,max8997-pmic", .data = TYPE_MAX8997 }, | ||
55 | {}, | ||
56 | }; | ||
57 | #endif | ||
58 | |||
50 | int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) | 59 | int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) |
51 | { | 60 | { |
52 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); | 61 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
@@ -123,6 +132,58 @@ int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask) | |||
123 | } | 132 | } |
124 | EXPORT_SYMBOL_GPL(max8997_update_reg); | 133 | EXPORT_SYMBOL_GPL(max8997_update_reg); |
125 | 134 | ||
135 | #ifdef CONFIG_OF | ||
136 | /* | ||
137 | * Only the common platform data elements for max8997 are parsed here from the | ||
138 | * device tree. Other sub-modules of max8997 such as pmic, rtc and others have | ||
139 | * to parse their own platform data elements from device tree. | ||
140 | * | ||
141 | * The max8997 platform data structure is instantiated here and the drivers for | ||
142 | * the sub-modules need not instantiate another instance while parsing their | ||
143 | * platform data. | ||
144 | */ | ||
145 | static struct max8997_platform_data *max8997_i2c_parse_dt_pdata( | ||
146 | struct device *dev) | ||
147 | { | ||
148 | struct max8997_platform_data *pd; | ||
149 | |||
150 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); | ||
151 | if (!pd) { | ||
152 | dev_err(dev, "could not allocate memory for pdata\n"); | ||
153 | return ERR_PTR(-ENOMEM); | ||
154 | } | ||
155 | |||
156 | pd->ono = irq_of_parse_and_map(dev->of_node, 1); | ||
157 | |||
158 | /* | ||
159 | * ToDo: the 'wakeup' member in the platform data is more of a linux | ||
160 | * specfic information. Hence, there is no binding for that yet and | ||
161 | * not parsed here. | ||
162 | */ | ||
163 | |||
164 | return pd; | ||
165 | } | ||
166 | #else | ||
167 | static struct max8997_platform_data *max8997_i2c_parse_dt_pdata( | ||
168 | struct device *dev) | ||
169 | { | ||
170 | return 0; | ||
171 | } | ||
172 | #endif | ||
173 | |||
174 | static inline int max8997_i2c_get_driver_data(struct i2c_client *i2c, | ||
175 | const struct i2c_device_id *id) | ||
176 | { | ||
177 | #ifdef CONFIG_OF | ||
178 | if (i2c->dev.of_node) { | ||
179 | const struct of_device_id *match; | ||
180 | match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node); | ||
181 | return (int)match->data; | ||
182 | } | ||
183 | #endif | ||
184 | return (int)id->driver_data; | ||
185 | } | ||
186 | |||
126 | static int max8997_i2c_probe(struct i2c_client *i2c, | 187 | static int max8997_i2c_probe(struct i2c_client *i2c, |
127 | const struct i2c_device_id *id) | 188 | const struct i2c_device_id *id) |
128 | { | 189 | { |
@@ -137,12 +198,21 @@ static int max8997_i2c_probe(struct i2c_client *i2c, | |||
137 | i2c_set_clientdata(i2c, max8997); | 198 | i2c_set_clientdata(i2c, max8997); |
138 | max8997->dev = &i2c->dev; | 199 | max8997->dev = &i2c->dev; |
139 | max8997->i2c = i2c; | 200 | max8997->i2c = i2c; |
140 | max8997->type = id->driver_data; | 201 | max8997->type = max8997_i2c_get_driver_data(i2c, id); |
141 | max8997->irq = i2c->irq; | 202 | max8997->irq = i2c->irq; |
142 | 203 | ||
204 | if (max8997->dev->of_node) { | ||
205 | pdata = max8997_i2c_parse_dt_pdata(max8997->dev); | ||
206 | if (IS_ERR(pdata)) { | ||
207 | ret = PTR_ERR(pdata); | ||
208 | goto err; | ||
209 | } | ||
210 | } | ||
211 | |||
143 | if (!pdata) | 212 | if (!pdata) |
144 | goto err; | 213 | goto err; |
145 | 214 | ||
215 | max8997->pdata = pdata; | ||
146 | max8997->ono = pdata->ono; | 216 | max8997->ono = pdata->ono; |
147 | 217 | ||
148 | mutex_init(&max8997->iolock); | 218 | mutex_init(&max8997->iolock); |
@@ -434,6 +504,7 @@ static struct i2c_driver max8997_i2c_driver = { | |||
434 | .name = "max8997", | 504 | .name = "max8997", |
435 | .owner = THIS_MODULE, | 505 | .owner = THIS_MODULE, |
436 | .pm = &max8997_pm, | 506 | .pm = &max8997_pm, |
507 | .of_match_table = of_match_ptr(max8997_pmic_dt_match), | ||
437 | }, | 508 | }, |
438 | .probe = max8997_i2c_probe, | 509 | .probe = max8997_i2c_probe, |
439 | .remove = max8997_i2c_remove, | 510 | .remove = max8997_i2c_remove, |