diff options
author | Tomasz Figa <t.figa@samsung.com> | 2013-04-04 12:17:20 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-04-05 06:20:52 -0400 |
commit | 3ff4aa95b3cd960a1c2e1422bc3dbd604f88271b (patch) | |
tree | 49386cec88cdb492559b345d82eaf483ffb55341 /drivers/regulator | |
parent | 3ec6eb9cc2dbfa5b626f813ab8077eb71da60af2 (diff) |
regulator: max8952: Add Device Tree support
This patch adds Device Tree support to max8952 regulator driver.
Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/max8952.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c index 100b9177dba1..4259c78abf88 100644 --- a/drivers/regulator/max8952.c +++ b/drivers/regulator/max8952.c | |||
@@ -28,6 +28,9 @@ | |||
28 | #include <linux/regulator/max8952.h> | 28 | #include <linux/regulator/max8952.h> |
29 | #include <linux/gpio.h> | 29 | #include <linux/gpio.h> |
30 | #include <linux/io.h> | 30 | #include <linux/io.h> |
31 | #include <linux/of.h> | ||
32 | #include <linux/of_gpio.h> | ||
33 | #include <linux/regulator/of_regulator.h> | ||
31 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
32 | 35 | ||
33 | /* Registers */ | 36 | /* Registers */ |
@@ -126,6 +129,69 @@ static const struct regulator_desc regulator = { | |||
126 | .owner = THIS_MODULE, | 129 | .owner = THIS_MODULE, |
127 | }; | 130 | }; |
128 | 131 | ||
132 | #ifdef CONFIG_OF | ||
133 | static struct of_device_id max8952_dt_match[] = { | ||
134 | { .compatible = "maxim,max8952" }, | ||
135 | {}, | ||
136 | }; | ||
137 | MODULE_DEVICE_TABLE(of, max8952_dt_match); | ||
138 | |||
139 | static struct max8952_platform_data *max8952_parse_dt(struct device *dev) | ||
140 | { | ||
141 | struct max8952_platform_data *pd; | ||
142 | struct device_node *np = dev->of_node; | ||
143 | int ret; | ||
144 | int i; | ||
145 | |||
146 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); | ||
147 | if (!pd) { | ||
148 | dev_err(dev, "Failed to allocate platform data\n"); | ||
149 | return NULL; | ||
150 | } | ||
151 | |||
152 | pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0); | ||
153 | pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1); | ||
154 | pd->gpio_en = of_get_named_gpio(np, "max8952,en-gpio", 0); | ||
155 | |||
156 | if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode)) | ||
157 | dev_warn(dev, "Default mode not specified, assuming 0\n"); | ||
158 | |||
159 | ret = of_property_read_u32_array(np, "max8952,dvs-mode-microvolt", | ||
160 | pd->dvs_mode, ARRAY_SIZE(pd->dvs_mode)); | ||
161 | if (ret) { | ||
162 | dev_err(dev, "max8952,dvs-mode-microvolt property not specified"); | ||
163 | return NULL; | ||
164 | } | ||
165 | |||
166 | for (i = 0; i < ARRAY_SIZE(pd->dvs_mode); ++i) { | ||
167 | if (pd->dvs_mode[i] < 770000 || pd->dvs_mode[i] > 1400000) { | ||
168 | dev_err(dev, "DVS voltage %d out of range\n", i); | ||
169 | return NULL; | ||
170 | } | ||
171 | pd->dvs_mode[i] = (pd->dvs_mode[i] - 770000) / 10000; | ||
172 | } | ||
173 | |||
174 | if (of_property_read_u32(np, "max8952,sync-freq", &pd->sync_freq)) | ||
175 | dev_warn(dev, "max8952,sync-freq property not specified, defaulting to 26MHz\n"); | ||
176 | |||
177 | if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed)) | ||
178 | dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n"); | ||
179 | |||
180 | pd->reg_data = of_get_regulator_init_data(dev, np); | ||
181 | if (!pd->reg_data) { | ||
182 | dev_err(dev, "Failed to parse regulator init data\n"); | ||
183 | return NULL; | ||
184 | } | ||
185 | |||
186 | return pd; | ||
187 | } | ||
188 | #else | ||
189 | static struct max8952_platform_data *max8952_parse_dt(struct device *dev) | ||
190 | { | ||
191 | return NULL; | ||
192 | } | ||
193 | #endif | ||
194 | |||
129 | static int max8952_pmic_probe(struct i2c_client *client, | 195 | static int max8952_pmic_probe(struct i2c_client *client, |
130 | const struct i2c_device_id *i2c_id) | 196 | const struct i2c_device_id *i2c_id) |
131 | { | 197 | { |
@@ -136,6 +202,9 @@ static int max8952_pmic_probe(struct i2c_client *client, | |||
136 | 202 | ||
137 | int ret = 0, err = 0; | 203 | int ret = 0, err = 0; |
138 | 204 | ||
205 | if (client->dev.of_node) | ||
206 | pdata = max8952_parse_dt(&client->dev); | ||
207 | |||
139 | if (!pdata) { | 208 | if (!pdata) { |
140 | dev_err(&client->dev, "Require the platform data\n"); | 209 | dev_err(&client->dev, "Require the platform data\n"); |
141 | return -EINVAL; | 210 | return -EINVAL; |
@@ -271,6 +340,7 @@ static struct i2c_driver max8952_pmic_driver = { | |||
271 | .remove = max8952_pmic_remove, | 340 | .remove = max8952_pmic_remove, |
272 | .driver = { | 341 | .driver = { |
273 | .name = "max8952", | 342 | .name = "max8952", |
343 | .of_match_table = of_match_ptr(max8952_dt_match), | ||
274 | }, | 344 | }, |
275 | .id_table = max8952_ids, | 345 | .id_table = max8952_ids, |
276 | }; | 346 | }; |