as3722-poweroff.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Power off driver for ams AS3722 device.
  3. *
  4. * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * Author: Laxman Dewangan <ldewangan@nvidia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. */
  17. #include <linux/mfd/as3722.h>
  18. #include <linux/module.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/slab.h>
  23. struct as3722_poweroff {
  24. struct device *dev;
  25. struct as3722 *as3722;
  26. };
  27. static struct as3722_poweroff *as3722_pm_poweroff;
  28. static void as3722_pm_power_off(void)
  29. {
  30. int ret;
  31. if (!as3722_pm_poweroff) {
  32. pr_err("AS3722 poweroff is not initialised\n");
  33. return;
  34. }
  35. ret = as3722_update_bits(as3722_pm_poweroff->as3722,
  36. AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
  37. if (ret < 0)
  38. dev_err(as3722_pm_poweroff->dev,
  39. "RESET_CONTROL_REG update failed, %d\n", ret);
  40. }
  41. static int as3722_poweroff_probe(struct platform_device *pdev)
  42. {
  43. struct as3722_poweroff *as3722_poweroff;
  44. struct device_node *np = pdev->dev.parent->of_node;
  45. if (!np)
  46. return -EINVAL;
  47. if (!of_property_read_bool(np, "ams,system-power-controller"))
  48. return 0;
  49. as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff),
  50. GFP_KERNEL);
  51. if (!as3722_poweroff)
  52. return -ENOMEM;
  53. as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
  54. as3722_poweroff->dev = &pdev->dev;
  55. as3722_pm_poweroff = as3722_poweroff;
  56. if (!pm_power_off)
  57. pm_power_off = as3722_pm_power_off;
  58. return 0;
  59. }
  60. static int as3722_poweroff_remove(struct platform_device *pdev)
  61. {
  62. if (pm_power_off == as3722_pm_power_off)
  63. pm_power_off = NULL;
  64. as3722_pm_poweroff = NULL;
  65. return 0;
  66. }
  67. static struct platform_driver as3722_poweroff_driver = {
  68. .driver = {
  69. .name = "as3722-power-off",
  70. },
  71. .probe = as3722_poweroff_probe,
  72. .remove = as3722_poweroff_remove,
  73. };
  74. module_platform_driver(as3722_poweroff_driver);
  75. MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device");
  76. MODULE_ALIAS("platform:as3722-power-off");
  77. MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
  78. MODULE_LICENSE("GPL v2");