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