| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ISP1704 USB Charger Detection driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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> |
|---|
| 20 | 7 | */ |
|---|
| 21 | 8 | |
|---|
| 22 | 9 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 30 | 17 | #include <linux/power_supply.h> |
|---|
| 31 | 18 | #include <linux/delay.h> |
|---|
| 32 | 19 | #include <linux/of.h> |
|---|
| 33 | | -#include <linux/of_gpio.h> |
|---|
| 34 | 20 | |
|---|
| 21 | +#include <linux/gpio/consumer.h> |
|---|
| 35 | 22 | #include <linux/usb/otg.h> |
|---|
| 36 | 23 | #include <linux/usb/ulpi.h> |
|---|
| 37 | 24 | #include <linux/usb/ch9.h> |
|---|
| 38 | 25 | #include <linux/usb/gadget.h> |
|---|
| 39 | | -#include <linux/power/isp1704_charger.h> |
|---|
| 40 | 26 | |
|---|
| 41 | 27 | /* Vendor specific Power Control register */ |
|---|
| 42 | 28 | #define ISP1704_PWR_CTRL 0x3d |
|---|
| .. | .. |
|---|
| 60 | 46 | struct device *dev; |
|---|
| 61 | 47 | struct power_supply *psy; |
|---|
| 62 | 48 | struct power_supply_desc psy_desc; |
|---|
| 49 | + struct gpio_desc *enable_gpio; |
|---|
| 63 | 50 | struct usb_phy *phy; |
|---|
| 64 | 51 | struct notifier_block nb; |
|---|
| 65 | 52 | struct work_struct work; |
|---|
| .. | .. |
|---|
| 81 | 68 | return usb_phy_io_write(isp->phy, val, reg); |
|---|
| 82 | 69 | } |
|---|
| 83 | 70 | |
|---|
| 84 | | -/* |
|---|
| 85 | | - * Disable/enable the power from the isp1704 if a function for it |
|---|
| 86 | | - * has been provided with platform data. |
|---|
| 87 | | - */ |
|---|
| 88 | 71 | static void isp1704_charger_set_power(struct isp1704_charger *isp, bool on) |
|---|
| 89 | 72 | { |
|---|
| 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); |
|---|
| 96 | 74 | } |
|---|
| 97 | 75 | |
|---|
| 98 | 76 | /* |
|---|
| .. | .. |
|---|
| 364 | 342 | int vendor; |
|---|
| 365 | 343 | int product; |
|---|
| 366 | 344 | int i; |
|---|
| 367 | | - int ret = -ENODEV; |
|---|
| 345 | + int ret; |
|---|
| 368 | 346 | |
|---|
| 369 | 347 | /* Test ULPI interface */ |
|---|
| 370 | 348 | ret = isp1704_write(isp, ULPI_SCRATCH, 0xaa); |
|---|
| .. | .. |
|---|
| 405 | 383 | int ret = -ENODEV; |
|---|
| 406 | 384 | struct power_supply_config psy_cfg = {}; |
|---|
| 407 | 385 | |
|---|
| 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 | | - |
|---|
| 443 | 386 | isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL); |
|---|
| 444 | 387 | if (!isp) |
|---|
| 445 | 388 | return -ENOMEM; |
|---|
| 446 | 389 | |
|---|
| 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) |
|---|
| 448 | 399 | isp->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); |
|---|
| 449 | 400 | else |
|---|
| 450 | 401 | isp->phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); |
|---|