hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/power/supply/isp1704_charger.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ISP1704 USB Charger Detection driver
34 *
45 * Copyright (C) 2010 Nokia Corporation
5
- * Copyright (C) 2012 - 2013 Pali Rohár <pali.rohar@gmail.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
6
+ * Copyright (C) 2012 - 2013 Pali Rohár <pali@kernel.org>
207 */
218
229 #include <linux/kernel.h>
....@@ -30,13 +17,12 @@
3017 #include <linux/power_supply.h>
3118 #include <linux/delay.h>
3219 #include <linux/of.h>
33
-#include <linux/of_gpio.h>
3420
21
+#include <linux/gpio/consumer.h>
3522 #include <linux/usb/otg.h>
3623 #include <linux/usb/ulpi.h>
3724 #include <linux/usb/ch9.h>
3825 #include <linux/usb/gadget.h>
39
-#include <linux/power/isp1704_charger.h>
4026
4127 /* Vendor specific Power Control register */
4228 #define ISP1704_PWR_CTRL 0x3d
....@@ -60,6 +46,7 @@
6046 struct device *dev;
6147 struct power_supply *psy;
6248 struct power_supply_desc psy_desc;
49
+ struct gpio_desc *enable_gpio;
6350 struct usb_phy *phy;
6451 struct notifier_block nb;
6552 struct work_struct work;
....@@ -81,18 +68,9 @@
8168 return usb_phy_io_write(isp->phy, val, reg);
8269 }
8370
84
-/*
85
- * Disable/enable the power from the isp1704 if a function for it
86
- * has been provided with platform data.
87
- */
8871 static void isp1704_charger_set_power(struct isp1704_charger *isp, bool on)
8972 {
90
- struct isp1704_charger_data *board = isp->dev->platform_data;
91
-
92
- if (board && board->set_power)
93
- board->set_power(on);
94
- else if (board)
95
- gpio_set_value(board->enable_gpio, on);
73
+ gpiod_set_value(isp->enable_gpio, on);
9674 }
9775
9876 /*
....@@ -364,7 +342,7 @@
364342 int vendor;
365343 int product;
366344 int i;
367
- int ret = -ENODEV;
345
+ int ret;
368346
369347 /* Test ULPI interface */
370348 ret = isp1704_write(isp, ULPI_SCRATCH, 0xaa);
....@@ -405,46 +383,19 @@
405383 int ret = -ENODEV;
406384 struct power_supply_config psy_cfg = {};
407385
408
- struct isp1704_charger_data *pdata = dev_get_platdata(&pdev->dev);
409
- struct device_node *np = pdev->dev.of_node;
410
-
411
- if (np) {
412
- int gpio = of_get_named_gpio(np, "nxp,enable-gpio", 0);
413
-
414
- if (gpio < 0) {
415
- dev_err(&pdev->dev, "missing DT GPIO nxp,enable-gpio\n");
416
- return gpio;
417
- }
418
-
419
- pdata = devm_kzalloc(&pdev->dev,
420
- sizeof(struct isp1704_charger_data), GFP_KERNEL);
421
- if (!pdata) {
422
- ret = -ENOMEM;
423
- goto fail0;
424
- }
425
- pdata->enable_gpio = gpio;
426
-
427
- dev_info(&pdev->dev, "init gpio %d\n", pdata->enable_gpio);
428
-
429
- ret = devm_gpio_request_one(&pdev->dev, pdata->enable_gpio,
430
- GPIOF_OUT_INIT_HIGH, "isp1704_reset");
431
- if (ret) {
432
- dev_err(&pdev->dev, "gpio request failed\n");
433
- goto fail0;
434
- }
435
- }
436
-
437
- if (!pdata) {
438
- dev_err(&pdev->dev, "missing platform data!\n");
439
- return -ENODEV;
440
- }
441
-
442
-
443386 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL);
444387 if (!isp)
445388 return -ENOMEM;
446389
447
- if (np)
390
+ isp->enable_gpio = devm_gpiod_get(&pdev->dev, "nxp,enable",
391
+ GPIOD_OUT_HIGH);
392
+ if (IS_ERR(isp->enable_gpio)) {
393
+ ret = PTR_ERR(isp->enable_gpio);
394
+ dev_err(&pdev->dev, "Could not get reset gpio: %d\n", ret);
395
+ return ret;
396
+ }
397
+
398
+ if (pdev->dev.of_node)
448399 isp->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
449400 else
450401 isp->phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);