.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * max8952.c - Voltage and current regulation for the Maxim 8952 |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2010 Samsung Electronics |
---|
5 | 6 | * MyungJoo Ham <myungjoo.ham@samsung.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License as published by |
---|
9 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
10 | | - * (at your option) any later version. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, |
---|
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - * GNU General Public License for more details. |
---|
16 | | - * |
---|
17 | | - * You should have received a copy of the GNU General Public License |
---|
18 | | - * along with this program; if not, write to the Free Software |
---|
19 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
20 | 7 | */ |
---|
21 | 8 | |
---|
22 | 9 | #include <linux/module.h> |
---|
.. | .. |
---|
26 | 13 | #include <linux/platform_device.h> |
---|
27 | 14 | #include <linux/regulator/driver.h> |
---|
28 | 15 | #include <linux/regulator/max8952.h> |
---|
29 | | -#include <linux/gpio.h> |
---|
30 | 16 | #include <linux/gpio/consumer.h> |
---|
31 | 17 | #include <linux/io.h> |
---|
32 | 18 | #include <linux/of.h> |
---|
33 | | -#include <linux/of_gpio.h> |
---|
34 | 19 | #include <linux/regulator/of_regulator.h> |
---|
35 | 20 | #include <linux/slab.h> |
---|
36 | 21 | |
---|
.. | .. |
---|
50 | 35 | struct max8952_data { |
---|
51 | 36 | struct i2c_client *client; |
---|
52 | 37 | struct max8952_platform_data *pdata; |
---|
53 | | - |
---|
| 38 | + struct gpio_desc *vid0_gpiod; |
---|
| 39 | + struct gpio_desc *vid1_gpiod; |
---|
54 | 40 | bool vid0; |
---|
55 | 41 | bool vid1; |
---|
56 | 42 | }; |
---|
.. | .. |
---|
100 | 86 | { |
---|
101 | 87 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); |
---|
102 | 88 | |
---|
103 | | - if (!gpio_is_valid(max8952->pdata->gpio_vid0) || |
---|
104 | | - !gpio_is_valid(max8952->pdata->gpio_vid1)) { |
---|
| 89 | + if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) { |
---|
105 | 90 | /* DVS not supported */ |
---|
106 | 91 | return -EPERM; |
---|
107 | 92 | } |
---|
108 | 93 | |
---|
109 | 94 | max8952->vid0 = selector & 0x1; |
---|
110 | 95 | max8952->vid1 = (selector >> 1) & 0x1; |
---|
111 | | - gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0); |
---|
112 | | - gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1); |
---|
| 96 | + gpiod_set_value(max8952->vid0_gpiod, max8952->vid0); |
---|
| 97 | + gpiod_set_value(max8952->vid1_gpiod, max8952->vid1); |
---|
113 | 98 | |
---|
114 | 99 | return 0; |
---|
115 | 100 | } |
---|
.. | .. |
---|
146 | 131 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); |
---|
147 | 132 | if (!pd) |
---|
148 | 133 | return NULL; |
---|
149 | | - |
---|
150 | | - pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0); |
---|
151 | | - pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1); |
---|
152 | 134 | |
---|
153 | 135 | if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode)) |
---|
154 | 136 | dev_warn(dev, "Default mode not specified, assuming 0\n"); |
---|
.. | .. |
---|
192 | 174 | static int max8952_pmic_probe(struct i2c_client *client, |
---|
193 | 175 | const struct i2c_device_id *i2c_id) |
---|
194 | 176 | { |
---|
195 | | - struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
---|
| 177 | + struct i2c_adapter *adapter = client->adapter; |
---|
196 | 178 | struct max8952_platform_data *pdata = dev_get_platdata(&client->dev); |
---|
197 | 179 | struct regulator_config config = { }; |
---|
198 | 180 | struct max8952_data *max8952; |
---|
.. | .. |
---|
200 | 182 | struct gpio_desc *gpiod; |
---|
201 | 183 | enum gpiod_flags gflags; |
---|
202 | 184 | |
---|
203 | | - int ret = 0, err = 0; |
---|
| 185 | + int ret = 0; |
---|
204 | 186 | |
---|
205 | 187 | if (client->dev.of_node) |
---|
206 | 188 | pdata = max8952_parse_dt(&client->dev); |
---|
.. | .. |
---|
230 | 212 | gflags = GPIOD_OUT_HIGH; |
---|
231 | 213 | else |
---|
232 | 214 | gflags = GPIOD_OUT_LOW; |
---|
233 | | - gpiod = devm_gpiod_get_optional(&client->dev, |
---|
234 | | - "max8952,en", |
---|
235 | | - gflags); |
---|
| 215 | + gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE; |
---|
| 216 | + /* |
---|
| 217 | + * Do not use devm* here: the regulator core takes over the |
---|
| 218 | + * lifecycle management of the GPIO descriptor. |
---|
| 219 | + */ |
---|
| 220 | + gpiod = gpiod_get_optional(&client->dev, |
---|
| 221 | + "max8952,en", |
---|
| 222 | + gflags); |
---|
236 | 223 | if (IS_ERR(gpiod)) |
---|
237 | 224 | return PTR_ERR(gpiod); |
---|
238 | 225 | if (gpiod) |
---|
.. | .. |
---|
248 | 235 | max8952->vid0 = pdata->default_mode & 0x1; |
---|
249 | 236 | max8952->vid1 = (pdata->default_mode >> 1) & 0x1; |
---|
250 | 237 | |
---|
251 | | - if (gpio_is_valid(pdata->gpio_vid0) && |
---|
252 | | - gpio_is_valid(pdata->gpio_vid1)) { |
---|
253 | | - unsigned long gpio_flags; |
---|
| 238 | + /* Fetch vid0 and vid1 GPIOs if available */ |
---|
| 239 | + gflags = max8952->vid0 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; |
---|
| 240 | + max8952->vid0_gpiod = devm_gpiod_get_index_optional(&client->dev, |
---|
| 241 | + "max8952,vid", |
---|
| 242 | + 0, gflags); |
---|
| 243 | + if (IS_ERR(max8952->vid0_gpiod)) |
---|
| 244 | + return PTR_ERR(max8952->vid0_gpiod); |
---|
| 245 | + gflags = max8952->vid1 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; |
---|
| 246 | + max8952->vid1_gpiod = devm_gpiod_get_index_optional(&client->dev, |
---|
| 247 | + "max8952,vid", |
---|
| 248 | + 1, gflags); |
---|
| 249 | + if (IS_ERR(max8952->vid1_gpiod)) |
---|
| 250 | + return PTR_ERR(max8952->vid1_gpiod); |
---|
254 | 251 | |
---|
255 | | - gpio_flags = max8952->vid0 ? |
---|
256 | | - GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; |
---|
257 | | - if (devm_gpio_request_one(&client->dev, pdata->gpio_vid0, |
---|
258 | | - gpio_flags, "MAX8952 VID0")) |
---|
259 | | - err = 1; |
---|
260 | | - |
---|
261 | | - gpio_flags = max8952->vid1 ? |
---|
262 | | - GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; |
---|
263 | | - if (devm_gpio_request_one(&client->dev, pdata->gpio_vid1, |
---|
264 | | - gpio_flags, "MAX8952 VID1")) |
---|
265 | | - err = 2; |
---|
266 | | - } else |
---|
267 | | - err = 3; |
---|
268 | | - |
---|
269 | | - if (err) { |
---|
| 252 | + /* If either VID GPIO is missing just disable this */ |
---|
| 253 | + if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) { |
---|
270 | 254 | dev_warn(&client->dev, "VID0/1 gpio invalid: " |
---|
271 | | - "DVS not available.\n"); |
---|
| 255 | + "DVS not available.\n"); |
---|
272 | 256 | max8952->vid0 = 0; |
---|
273 | 257 | max8952->vid1 = 0; |
---|
274 | | - /* Mark invalid */ |
---|
275 | | - pdata->gpio_vid0 = -1; |
---|
276 | | - pdata->gpio_vid1 = -1; |
---|
| 258 | + /* Make sure if we have any descriptors they get set to low */ |
---|
| 259 | + if (max8952->vid0_gpiod) |
---|
| 260 | + gpiod_set_value(max8952->vid0_gpiod, 0); |
---|
| 261 | + if (max8952->vid1_gpiod) |
---|
| 262 | + gpiod_set_value(max8952->vid1_gpiod, 0); |
---|
277 | 263 | |
---|
278 | 264 | /* Disable Pulldown of EN only */ |
---|
279 | 265 | max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60); |
---|