hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/power/supply/gpio-charger.c
....@@ -1,19 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
34 * Driver for chargers which report their online status through a GPIO pin
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License as published by the
7
- * Free Software Foundation; either version 2 of the License, or (at your
8
- * option) any later version.
9
- *
10
- * You should have received a copy of the GNU General Public License along
11
- * with this program; if not, write to the Free Software Foundation, Inc.,
12
- * 675 Mass Ave, Cambridge, MA 02139, USA.
13
- *
145 */
156
16
-#include <linux/extcon-provider.h>
177 #include <linux/device.h>
188 #include <linux/init.h>
199 #include <linux/interrupt.h>
....@@ -40,13 +30,11 @@
4030
4131 struct power_supply *charger;
4232 struct power_supply_desc charger_desc;
43
- struct extcon_dev *edev;
4433 struct gpio_desc *gpiod;
4534 struct gpio_desc *charge_status;
4635
4736 struct gpio_descs *current_limit_gpios;
4837 struct gpio_mapping *current_limit_map;
49
- struct notifier_block cable_cg_nb;
5038 u32 current_limit_map_size;
5139 u32 charge_current_limit;
5240 };
....@@ -249,22 +237,6 @@
249237 return 0;
250238 }
251239
252
-static int gpio_charger_evt_notifier(struct notifier_block *nb,
253
- unsigned long event, void *ptr)
254
-{
255
- int limit_ua;
256
- struct gpio_charger *charger =
257
- container_of(nb, struct gpio_charger, cable_cg_nb);
258
-
259
- limit_ua = charger->current_limit_map[charger->current_limit_map_size - 1].limit_ua;
260
- if (extcon_get_state(charger->edev, EXTCON_CHG_USB_DCP) > 0)
261
- limit_ua = charger->current_limit_map[0].limit_ua;
262
-
263
- set_charge_current_limit(charger, limit_ua);
264
-
265
- return NOTIFY_DONE;
266
-}
267
-
268240 /*
269241 * The entries will be overwritten by driver's probe routine depending
270242 * on the available features. This list ensures, that the array is big
....@@ -280,7 +252,6 @@
280252 {
281253 struct device *dev = &pdev->dev;
282254 const struct gpio_charger_platform_data *pdata = dev->platform_data;
283
- struct extcon_dev *edev;
284255 struct power_supply_config psy_cfg = {};
285256 struct gpio_charger *gpio_charger;
286257 struct power_supply_desc *charger_desc;
....@@ -299,27 +270,6 @@
299270 return -ENOMEM;
300271 gpio_charger->dev = dev;
301272
302
- if (of_property_read_bool(dev->of_node, "extcon")) {
303
- edev = extcon_get_edev_by_phandle(dev, 0);
304
- if (IS_ERR(edev)) {
305
- if (PTR_ERR(edev) != -EPROBE_DEFER)
306
- dev_err(dev, "Invalid or missing extcon\n");
307
- return PTR_ERR(edev);
308
- }
309
- gpio_charger->edev = edev;
310
- gpio_charger->cable_cg_nb.notifier_call =
311
- gpio_charger_evt_notifier;
312
- ret = devm_extcon_register_notifier(dev, edev,
313
- EXTCON_CHG_USB_DCP,
314
- &gpio_charger->cable_cg_nb);
315
- if (ret) {
316
- dev_err(dev, "failed to register notifier for CDP\n");
317
- return ret;
318
- }
319
- } else {
320
- gpio_charger->edev = ERR_PTR(-ENODEV);
321
- }
322
-
323273 /*
324274 * This will fetch a GPIO descriptor from device tree, ACPI or
325275 * boardfile descriptor tables. It's good to try this first.
....@@ -327,10 +277,8 @@
327277 gpio_charger->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
328278 if (IS_ERR(gpio_charger->gpiod)) {
329279 /* Just try again if this happens */
330
- if (PTR_ERR(gpio_charger->gpiod) == -EPROBE_DEFER)
331
- return -EPROBE_DEFER;
332
- dev_err(dev, "error getting GPIO descriptor\n");
333
- return PTR_ERR(gpio_charger->gpiod);
280
+ return dev_err_probe(dev, PTR_ERR(gpio_charger->gpiod),
281
+ "error getting GPIO descriptor\n");
334282 }
335283
336284 if (gpio_charger->gpiod) {