Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

isp1704_charger: Add DT support

This patch introduces device tree support to the isp1704 charger driver.
Adding support involved moving the handling of the enable GPIO from board
code into the driver.

Signed-off-by: Sebastian Reichel <sre@debian.org>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>

authored by

Sebastian Reichel and committed by
Anton Vorontsov
34a10961 434a09f9

+51 -4
+50 -4
drivers/power/isp1704_charger.c
··· 29 29 #include <linux/platform_device.h> 30 30 #include <linux/power_supply.h> 31 31 #include <linux/delay.h> 32 + #include <linux/of.h> 33 + #include <linux/of_gpio.h> 32 34 33 35 #include <linux/usb/otg.h> 34 36 #include <linux/usb/ulpi.h> ··· 90 88 91 89 if (board && board->set_power) 92 90 board->set_power(on); 91 + else if (board) 92 + gpio_set_value(board->enable_gpio, on); 93 93 } 94 94 95 95 /* ··· 404 400 struct isp1704_charger *isp; 405 401 int ret = -ENODEV; 406 402 403 + struct isp1704_charger_data *pdata = dev_get_platdata(&pdev->dev); 404 + struct device_node *np = pdev->dev.of_node; 405 + 406 + if (np) { 407 + int gpio = of_get_named_gpio(np, "nxp,enable-gpio", 0); 408 + 409 + if (gpio < 0) 410 + return gpio; 411 + 412 + pdata = devm_kzalloc(&pdev->dev, 413 + sizeof(struct isp1704_charger_data), GFP_KERNEL); 414 + pdata->enable_gpio = gpio; 415 + 416 + dev_info(&pdev->dev, "init gpio %d\n", pdata->enable_gpio); 417 + 418 + ret = devm_gpio_request_one(&pdev->dev, pdata->enable_gpio, 419 + GPIOF_OUT_INIT_HIGH, "isp1704_reset"); 420 + if (ret) 421 + goto fail0; 422 + } 423 + 424 + if (!pdata) { 425 + dev_err(&pdev->dev, "missing platform data!\n"); 426 + return -ENODEV; 427 + } 428 + 429 + 407 430 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL); 408 431 if (!isp) 409 432 return -ENOMEM; 410 433 411 - isp->phy = usb_get_phy(USB_PHY_TYPE_USB2); 412 - if (IS_ERR_OR_NULL(isp->phy)) 434 + if (np) 435 + isp->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); 436 + else 437 + isp->phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 438 + 439 + if (IS_ERR(isp->phy)) { 440 + ret = PTR_ERR(isp->phy); 441 + goto fail0; 442 + } 443 + if (!isp->phy) 413 444 goto fail0; 414 445 415 446 isp->dev = &pdev->dev; ··· 503 464 power_supply_unregister(&isp->psy); 504 465 fail1: 505 466 isp1704_charger_set_power(isp, 0); 506 - usb_put_phy(isp->phy); 507 467 fail0: 508 468 dev_err(&pdev->dev, "failed to register isp1704 with error %d\n", ret); 509 469 ··· 515 477 516 478 usb_unregister_notifier(isp->phy, &isp->nb); 517 479 power_supply_unregister(&isp->psy); 518 - usb_put_phy(isp->phy); 519 480 isp1704_charger_set_power(isp, 0); 520 481 521 482 return 0; 522 483 } 523 484 485 + #ifdef CONFIG_OF 486 + static const struct of_device_id omap_isp1704_of_match[] = { 487 + { .compatible = "nxp,isp1704", }, 488 + {}, 489 + }; 490 + MODULE_DEVICE_TABLE(of, omap_isp1704_of_match); 491 + #endif 492 + 524 493 static struct platform_driver isp1704_charger_driver = { 525 494 .driver = { 526 495 .name = "isp1704_charger", 496 + .of_match_table = of_match_ptr(omap_isp1704_of_match), 527 497 }, 528 498 .probe = isp1704_charger_probe, 529 499 .remove = isp1704_charger_remove,
+1
include/linux/power/isp1704_charger.h
··· 24 24 25 25 struct isp1704_charger_data { 26 26 void (*set_power)(bool on); 27 + int enable_gpio; 27 28 }; 28 29 29 30 #endif