aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorTomasz Figa <t.figa@samsung.com>2013-06-25 10:08:10 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2013-06-30 17:30:04 -0400
commitee999fb3f17faa3af6028bf7130707fe0d4157a4 (patch)
tree9cbadb66c7a3f84c265fd2f7f10801385a7ea50b /drivers/mfd
parent4280e0b42bd590316a048d66ea356e78c5d0464e (diff)
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>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/max8998.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
index d7218cc90945..21af51a499f4 100644
--- a/drivers/mfd/max8998.c
+++ b/drivers/mfd/max8998.c
@@ -20,12 +20,15 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23#include <linux/err.h>
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
25#include <linux/init.h> 26#include <linux/init.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
27#include <linux/i2c.h> 28#include <linux/i2c.h>
28#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/of.h>
31#include <linux/of_irq.h>
29#include <linux/pm_runtime.h> 32#include <linux/pm_runtime.h>
30#include <linux/mutex.h> 33#include <linux/mutex.h>
31#include <linux/mfd/core.h> 34#include <linux/mfd/core.h>
@@ -128,6 +131,56 @@ int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
128} 131}
129EXPORT_SYMBOL(max8998_update_reg); 132EXPORT_SYMBOL(max8998_update_reg);
130 133
134#ifdef CONFIG_OF
135static 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};
141MODULE_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 */
153static 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
172static 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
131static int max8998_i2c_probe(struct i2c_client *i2c, 184static int max8998_i2c_probe(struct i2c_client *i2c,
132 const struct i2c_device_id *id) 185 const struct i2c_device_id *id)
133{ 186{
@@ -139,11 +192,20 @@ static int max8998_i2c_probe(struct i2c_client *i2c,
139 if (max8998 == NULL) 192 if (max8998 == NULL)
140 return -ENOMEM; 193 return -ENOMEM;
141 194
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
142 i2c_set_clientdata(i2c, max8998); 203 i2c_set_clientdata(i2c, max8998);
143 max8998->dev = &i2c->dev; 204 max8998->dev = &i2c->dev;
144 max8998->i2c = i2c; 205 max8998->i2c = i2c;
145 max8998->irq = i2c->irq; 206 max8998->irq = i2c->irq;
146 max8998->type = id->driver_data; 207 max8998->type = max8998_i2c_get_driver_data(i2c, id);
208 max8998->pdata = pdata;
147 if (pdata) { 209 if (pdata) {
148 max8998->ono = pdata->ono; 210 max8998->ono = pdata->ono;
149 max8998->irq_base = pdata->irq_base; 211 max8998->irq_base = pdata->irq_base;
@@ -158,7 +220,7 @@ static int max8998_i2c_probe(struct i2c_client *i2c,
158 220
159 pm_runtime_set_active(max8998->dev); 221 pm_runtime_set_active(max8998->dev);
160 222
161 switch (id->driver_data) { 223 switch (max8998->type) {
162 case TYPE_LP3974: 224 case TYPE_LP3974:
163 ret = mfd_add_devices(max8998->dev, -1, 225 ret = mfd_add_devices(max8998->dev, -1,
164 lp3974_devs, ARRAY_SIZE(lp3974_devs), 226 lp3974_devs, ARRAY_SIZE(lp3974_devs),
@@ -314,6 +376,7 @@ static struct i2c_driver max8998_i2c_driver = {
314 .name = "max8998", 376 .name = "max8998",
315 .owner = THIS_MODULE, 377 .owner = THIS_MODULE,
316 .pm = &max8998_pm, 378 .pm = &max8998_pm,
379 .of_match_table = of_match_ptr(max8998_dt_match),
317 }, 380 },
318 .probe = max8998_i2c_probe, 381 .probe = max8998_i2c_probe,
319 .remove = max8998_i2c_remove, 382 .remove = max8998_i2c_remove,