diff options
Diffstat (limited to 'drivers/mfd/tps65217.c')
-rw-r--r-- | drivers/mfd/tps65217.c | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c index db194e433c0..61c097a98f5 100644 --- a/drivers/mfd/tps65217.c +++ b/drivers/mfd/tps65217.c | |||
@@ -24,6 +24,7 @@ | |||
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 | 28 | ||
28 | #include <linux/mfd/core.h> | 29 | #include <linux/mfd/core.h> |
29 | #include <linux/mfd/tps65217.h> | 30 | #include <linux/mfd/tps65217.h> |
@@ -132,6 +133,61 @@ int tps65217_clear_bits(struct tps65217 *tps, unsigned int reg, | |||
132 | } | 133 | } |
133 | EXPORT_SYMBOL_GPL(tps65217_clear_bits); | 134 | EXPORT_SYMBOL_GPL(tps65217_clear_bits); |
134 | 135 | ||
136 | #ifdef CONFIG_OF | ||
137 | static 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 | |||
147 | static 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 | |||
180 | static struct of_device_id tps65217_of_match[] = { | ||
181 | { .compatible = "ti,tps65217", }, | ||
182 | { }, | ||
183 | }; | ||
184 | #else | ||
185 | static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client) | ||
186 | { | ||
187 | return NULL; | ||
188 | } | ||
189 | #endif | ||
190 | |||
135 | static struct regmap_config tps65217_regmap_config = { | 191 | static struct regmap_config tps65217_regmap_config = { |
136 | .reg_bits = 8, | 192 | .reg_bits = 8, |
137 | .val_bits = 8, | 193 | .val_bits = 8, |
@@ -141,10 +197,14 @@ static int __devinit tps65217_probe(struct i2c_client *client, | |||
141 | const struct i2c_device_id *ids) | 197 | const struct i2c_device_id *ids) |
142 | { | 198 | { |
143 | struct tps65217 *tps; | 199 | struct tps65217 *tps; |
200 | struct regulator_init_data *reg_data; | ||
144 | struct tps65217_board *pdata = client->dev.platform_data; | 201 | struct tps65217_board *pdata = client->dev.platform_data; |
145 | int i, ret; | 202 | int i, ret; |
146 | unsigned int version; | 203 | unsigned int version; |
147 | 204 | ||
205 | if (!pdata && client->dev.of_node) | ||
206 | pdata = tps65217_parse_dt(client); | ||
207 | |||
148 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); | 208 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); |
149 | if (!tps) | 209 | if (!tps) |
150 | return -ENOMEM; | 210 | return -ENOMEM; |
@@ -182,8 +242,9 @@ static int __devinit tps65217_probe(struct i2c_client *client, | |||
182 | } | 242 | } |
183 | 243 | ||
184 | pdev->dev.parent = tps->dev; | 244 | pdev->dev.parent = tps->dev; |
185 | platform_device_add_data(pdev, &pdata->tps65217_init_data[i], | 245 | pdev->dev.of_node = pdata->of_node[i]; |
186 | sizeof(pdata->tps65217_init_data[i])); | 246 | reg_data = pdata->tps65217_init_data[i]; |
247 | platform_device_add_data(pdev, reg_data, sizeof(*reg_data)); | ||
187 | tps->regulator_pdev[i] = pdev; | 248 | tps->regulator_pdev[i] = pdev; |
188 | 249 | ||
189 | platform_device_add(pdev); | 250 | platform_device_add(pdev); |
@@ -212,6 +273,8 @@ MODULE_DEVICE_TABLE(i2c, tps65217_id_table); | |||
212 | static struct i2c_driver tps65217_driver = { | 273 | static struct i2c_driver tps65217_driver = { |
213 | .driver = { | 274 | .driver = { |
214 | .name = "tps65217", | 275 | .name = "tps65217", |
276 | .owner = THIS_MODULE, | ||
277 | .of_match_table = of_match_ptr(tps65217_of_match), | ||
215 | }, | 278 | }, |
216 | .id_table = tps65217_id_table, | 279 | .id_table = tps65217_id_table, |
217 | .probe = tps65217_probe, | 280 | .probe = tps65217_probe, |