as3722-poweroff.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Power off driver for ams AS3722 device.
  4. *
  5. * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
  6. *
  7. * Author: Laxman Dewangan <ldewangan@nvidia.com>
  8. */
  9. #include <linux/mfd/as3722.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/of_device.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/slab.h>
  15. struct as3722_poweroff {
  16. struct device *dev;
  17. struct as3722 *as3722;
  18. };
  19. static struct as3722_poweroff *as3722_pm_poweroff;
  20. static void as3722_pm_power_off(void)
  21. {
  22. int ret;
  23. if (!as3722_pm_poweroff) {
  24. pr_err("AS3722 poweroff is not initialised\n");
  25. return;
  26. }
  27. ret = as3722_update_bits(as3722_pm_poweroff->as3722,
  28. AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
  29. if (ret < 0)
  30. dev_err(as3722_pm_poweroff->dev,
  31. "RESET_CONTROL_REG update failed, %d\n", ret);
  32. }
  33. static int as3722_poweroff_probe(struct platform_device *pdev)
  34. {
  35. struct as3722_poweroff *as3722_poweroff;
  36. struct device_node *np = pdev->dev.parent->of_node;
  37. if (!np)
  38. return -EINVAL;
  39. if (!of_property_read_bool(np, "ams,system-power-controller"))
  40. return 0;
  41. as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff),
  42. GFP_KERNEL);
  43. if (!as3722_poweroff)
  44. return -ENOMEM;
  45. as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
  46. as3722_poweroff->dev = &pdev->dev;
  47. as3722_pm_poweroff = as3722_poweroff;
  48. if (!pm_power_off)
  49. pm_power_off = as3722_pm_power_off;
  50. return 0;
  51. }
  52. static int as3722_poweroff_remove(struct platform_device *pdev)
  53. {
  54. if (pm_power_off == as3722_pm_power_off)
  55. pm_power_off = NULL;
  56. as3722_pm_poweroff = NULL;
  57. return 0;
  58. }
  59. static struct platform_driver as3722_poweroff_driver = {
  60. .driver = {
  61. .name = "as3722-power-off",
  62. },
  63. .probe = as3722_poweroff_probe,
  64. .remove = as3722_poweroff_remove,
  65. };
  66. module_platform_driver(as3722_poweroff_driver);
  67. MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device");
  68. MODULE_ALIAS("platform:as3722-power-off");
  69. MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
  70. MODULE_LICENSE("GPL v2");