aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/tps65217.c
diff options
context:
space:
mode:
authorAnilKumar Ch <anilkumar@ti.com>2012-08-13 11:06:05 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2012-08-22 04:49:35 -0400
commit817bb7fbfb0a1ad5f9d475cef0752d4ec5fdeac2 (patch)
treefa725f8e1a7b3a3f7eac166a1de8cea29adf46ae /drivers/mfd/tps65217.c
parentd9875690d9b89a866022ff49e3fcea892345ad92 (diff)
mfd: Move tps65217 regulator plat data handling to regulator
Regulator platform data handling was mistakenly added to MFD driver. So we will see build errors if we compile MFD drivers without CONFIG_REGULATOR. This patch moves regulator platform data handling from TPS65217 MFD driver to regulator driver. This makes MFD driver independent of REGULATOR framework so build error is fixed if CONFIG_REGULATOR is not set. drivers/built-in.o: In function `tps65217_probe': tps65217.c:(.devinit.text+0x13e37): undefined reference to `of_regulator_match' This patch also fix allocation size of tps65217 platform data. Current implementation allocates a struct tps65217_board for each regulator specified in the device tree. But the structure itself provides array of regulators so one instance of it is sufficient. Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
Diffstat (limited to 'drivers/mfd/tps65217.c')
-rw-r--r--drivers/mfd/tps65217.c130
1 files changed, 43 insertions, 87 deletions
diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c
index 61c097a98f5d..3bc274409b58 100644
--- a/drivers/mfd/tps65217.c
+++ b/drivers/mfd/tps65217.c
@@ -24,11 +24,18 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/regmap.h> 25#include <linux/regmap.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/regulator/of_regulator.h> 27#include <linux/of.h>
28#include <linux/of_device.h>
28 29
29#include <linux/mfd/core.h> 30#include <linux/mfd/core.h>
30#include <linux/mfd/tps65217.h> 31#include <linux/mfd/tps65217.h>
31 32
33static struct mfd_cell tps65217s[] = {
34 {
35 .name = "tps65217-pmic",
36 },
37};
38
32/** 39/**
33 * tps65217_reg_read: Read a single tps65217 register. 40 * tps65217_reg_read: Read a single tps65217 register.
34 * 41 *
@@ -133,83 +140,48 @@ int tps65217_clear_bits(struct tps65217 *tps, unsigned int reg,
133} 140}
134EXPORT_SYMBOL_GPL(tps65217_clear_bits); 141EXPORT_SYMBOL_GPL(tps65217_clear_bits);
135 142
136#ifdef CONFIG_OF
137static struct of_regulator_match reg_matches[] = {
138 { .name = "dcdc1", .driver_data = (void *)TPS65217_DCDC_1 },
139 { .name = "dcdc2", .driver_data = (void *)TPS65217_DCDC_2 },
140 { .name = "dcdc3", .driver_data = (void *)TPS65217_DCDC_3 },
141 { .name = "ldo1", .driver_data = (void *)TPS65217_LDO_1 },
142 { .name = "ldo2", .driver_data = (void *)TPS65217_LDO_2 },
143 { .name = "ldo3", .driver_data = (void *)TPS65217_LDO_3 },
144 { .name = "ldo4", .driver_data = (void *)TPS65217_LDO_4 },
145};
146
147static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client)
148{
149 struct device_node *node = client->dev.of_node;
150 struct tps65217_board *pdata;
151 struct device_node *regs;
152 int count = ARRAY_SIZE(reg_matches);
153 int ret, i;
154
155 regs = of_find_node_by_name(node, "regulators");
156 if (!regs)
157 return NULL;
158
159 ret = of_regulator_match(&client->dev, regs, reg_matches, count);
160 of_node_put(regs);
161 if ((ret < 0) || (ret > count))
162 return NULL;
163
164 count = ret;
165 pdata = devm_kzalloc(&client->dev, count * sizeof(*pdata), GFP_KERNEL);
166 if (!pdata)
167 return NULL;
168
169 for (i = 0; i < count; i++) {
170 if (!reg_matches[i].init_data || !reg_matches[i].of_node)
171 continue;
172
173 pdata->tps65217_init_data[i] = reg_matches[i].init_data;
174 pdata->of_node[i] = reg_matches[i].of_node;
175 }
176
177 return pdata;
178}
179
180static struct of_device_id tps65217_of_match[] = {
181 { .compatible = "ti,tps65217", },
182 { },
183};
184#else
185static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client)
186{
187 return NULL;
188}
189#endif
190
191static struct regmap_config tps65217_regmap_config = { 143static struct regmap_config tps65217_regmap_config = {
192 .reg_bits = 8, 144 .reg_bits = 8,
193 .val_bits = 8, 145 .val_bits = 8,
194}; 146};
195 147
148static const struct of_device_id tps65217_of_match[] = {
149 { .compatible = "ti,tps65217", .data = (void *)TPS65217 },
150 { /* sentinel */ },
151};
152
196static int __devinit tps65217_probe(struct i2c_client *client, 153static int __devinit tps65217_probe(struct i2c_client *client,
197 const struct i2c_device_id *ids) 154 const struct i2c_device_id *ids)
198{ 155{
199 struct tps65217 *tps; 156 struct tps65217 *tps;
200 struct regulator_init_data *reg_data;
201 struct tps65217_board *pdata = client->dev.platform_data;
202 int i, ret;
203 unsigned int version; 157 unsigned int version;
158 unsigned int chip_id = ids->driver_data;
159 const struct of_device_id *match;
160 int ret;
204 161
205 if (!pdata && client->dev.of_node) 162 if (client->dev.of_node) {
206 pdata = tps65217_parse_dt(client); 163 match = of_match_device(tps65217_of_match, &client->dev);
164 if (!match) {
165 dev_err(&client->dev,
166 "Failed to find matching dt id\n");
167 return -EINVAL;
168 }
169 chip_id = (unsigned int)match->data;
170 }
171
172 if (!chip_id) {
173 dev_err(&client->dev, "id is null.\n");
174 return -ENODEV;
175 }
207 176
208 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 177 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
209 if (!tps) 178 if (!tps)
210 return -ENOMEM; 179 return -ENOMEM;
211 180
212 tps->pdata = pdata; 181 i2c_set_clientdata(client, tps);
182 tps->dev = &client->dev;
183 tps->id = chip_id;
184
213 tps->regmap = devm_regmap_init_i2c(client, &tps65217_regmap_config); 185 tps->regmap = devm_regmap_init_i2c(client, &tps65217_regmap_config);
214 if (IS_ERR(tps->regmap)) { 186 if (IS_ERR(tps->regmap)) {
215 ret = PTR_ERR(tps->regmap); 187 ret = PTR_ERR(tps->regmap);
@@ -218,8 +190,12 @@ static int __devinit tps65217_probe(struct i2c_client *client,
218 return ret; 190 return ret;
219 } 191 }
220 192
221 i2c_set_clientdata(client, tps); 193 ret = mfd_add_devices(tps->dev, -1, tps65217s,
222 tps->dev = &client->dev; 194 ARRAY_SIZE(tps65217s), NULL, 0);
195 if (ret < 0) {
196 dev_err(tps->dev, "mfd_add_devices failed: %d\n", ret);
197 return ret;
198 }
223 199
224 ret = tps65217_reg_read(tps, TPS65217_REG_CHIPID, &version); 200 ret = tps65217_reg_read(tps, TPS65217_REG_CHIPID, &version);
225 if (ret < 0) { 201 if (ret < 0) {
@@ -232,41 +208,21 @@ static int __devinit tps65217_probe(struct i2c_client *client,
232 (version & TPS65217_CHIPID_CHIP_MASK) >> 4, 208 (version & TPS65217_CHIPID_CHIP_MASK) >> 4,
233 version & TPS65217_CHIPID_REV_MASK); 209 version & TPS65217_CHIPID_REV_MASK);
234 210
235 for (i = 0; i < TPS65217_NUM_REGULATOR; i++) {
236 struct platform_device *pdev;
237
238 pdev = platform_device_alloc("tps65217-pmic", i);
239 if (!pdev) {
240 dev_err(tps->dev, "Cannot create regulator %d\n", i);
241 continue;
242 }
243
244 pdev->dev.parent = tps->dev;
245 pdev->dev.of_node = pdata->of_node[i];
246 reg_data = pdata->tps65217_init_data[i];
247 platform_device_add_data(pdev, reg_data, sizeof(*reg_data));
248 tps->regulator_pdev[i] = pdev;
249
250 platform_device_add(pdev);
251 }
252
253 return 0; 211 return 0;
254} 212}
255 213
256static int __devexit tps65217_remove(struct i2c_client *client) 214static int __devexit tps65217_remove(struct i2c_client *client)
257{ 215{
258 struct tps65217 *tps = i2c_get_clientdata(client); 216 struct tps65217 *tps = i2c_get_clientdata(client);
259 int i;
260 217
261 for (i = 0; i < TPS65217_NUM_REGULATOR; i++) 218 mfd_remove_devices(tps->dev);
262 platform_device_unregister(tps->regulator_pdev[i]);
263 219
264 return 0; 220 return 0;
265} 221}
266 222
267static const struct i2c_device_id tps65217_id_table[] = { 223static const struct i2c_device_id tps65217_id_table[] = {
268 {"tps65217", 0xF0}, 224 {"tps65217", TPS65217},
269 {/* end of list */} 225 { /* sentinel */ }
270}; 226};
271MODULE_DEVICE_TABLE(i2c, tps65217_id_table); 227MODULE_DEVICE_TABLE(i2c, tps65217_id_table);
272 228