hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/regulator/max8952.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * max8952.c - Voltage and current regulation for the Maxim 8952
34 *
45 * Copyright (C) 2010 Samsung Electronics
56 * 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
207 */
218
229 #include <linux/module.h>
....@@ -26,11 +13,9 @@
2613 #include <linux/platform_device.h>
2714 #include <linux/regulator/driver.h>
2815 #include <linux/regulator/max8952.h>
29
-#include <linux/gpio.h>
3016 #include <linux/gpio/consumer.h>
3117 #include <linux/io.h>
3218 #include <linux/of.h>
33
-#include <linux/of_gpio.h>
3419 #include <linux/regulator/of_regulator.h>
3520 #include <linux/slab.h>
3621
....@@ -50,7 +35,8 @@
5035 struct max8952_data {
5136 struct i2c_client *client;
5237 struct max8952_platform_data *pdata;
53
-
38
+ struct gpio_desc *vid0_gpiod;
39
+ struct gpio_desc *vid1_gpiod;
5440 bool vid0;
5541 bool vid1;
5642 };
....@@ -100,16 +86,15 @@
10086 {
10187 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
10288
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) {
10590 /* DVS not supported */
10691 return -EPERM;
10792 }
10893
10994 max8952->vid0 = selector & 0x1;
11095 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);
11398
11499 return 0;
115100 }
....@@ -146,9 +131,6 @@
146131 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
147132 if (!pd)
148133 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);
152134
153135 if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode))
154136 dev_warn(dev, "Default mode not specified, assuming 0\n");
....@@ -192,7 +174,7 @@
192174 static int max8952_pmic_probe(struct i2c_client *client,
193175 const struct i2c_device_id *i2c_id)
194176 {
195
- struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
177
+ struct i2c_adapter *adapter = client->adapter;
196178 struct max8952_platform_data *pdata = dev_get_platdata(&client->dev);
197179 struct regulator_config config = { };
198180 struct max8952_data *max8952;
....@@ -200,7 +182,7 @@
200182 struct gpio_desc *gpiod;
201183 enum gpiod_flags gflags;
202184
203
- int ret = 0, err = 0;
185
+ int ret = 0;
204186
205187 if (client->dev.of_node)
206188 pdata = max8952_parse_dt(&client->dev);
....@@ -230,9 +212,14 @@
230212 gflags = GPIOD_OUT_HIGH;
231213 else
232214 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);
236223 if (IS_ERR(gpiod))
237224 return PTR_ERR(gpiod);
238225 if (gpiod)
....@@ -248,32 +235,31 @@
248235 max8952->vid0 = pdata->default_mode & 0x1;
249236 max8952->vid1 = (pdata->default_mode >> 1) & 0x1;
250237
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);
254251
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) {
270254 dev_warn(&client->dev, "VID0/1 gpio invalid: "
271
- "DVS not available.\n");
255
+ "DVS not available.\n");
272256 max8952->vid0 = 0;
273257 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);
277263
278264 /* Disable Pulldown of EN only */
279265 max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60);