sc27xx-poweroff.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Spreadtrum Communications Inc.
  4. * Copyright (C) 2018 Linaro Ltd.
  5. */
  6. #include <linux/cpu.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/pm.h>
  11. #include <linux/regmap.h>
  12. #include <linux/syscore_ops.h>
  13. #define SC27XX_PWR_PD_HW 0xc2c
  14. #define SC27XX_PWR_OFF_EN BIT(0)
  15. #define SC27XX_SLP_CTRL 0xdf0
  16. #define SC27XX_LDO_XTL_EN BIT(3)
  17. static struct regmap *regmap;
  18. /*
  19. * On Spreadtrum platform, we need power off system through external SC27xx
  20. * series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC,
  21. * which is not fast io access.
  22. *
  23. * So before stopping other cores, we need release other cores' resource by
  24. * taking cpus down to avoid racing regmap or spi mutex lock when poweroff
  25. * system through PMIC.
  26. */
  27. static void sc27xx_poweroff_shutdown(void *data)
  28. {
  29. #ifdef CONFIG_HOTPLUG_CPU
  30. int cpu;
  31. for_each_online_cpu(cpu) {
  32. if (cpu != smp_processor_id())
  33. remove_cpu(cpu);
  34. }
  35. #endif
  36. }
  37. static const struct syscore_ops poweroff_syscore_ops = {
  38. .shutdown = sc27xx_poweroff_shutdown,
  39. };
  40. static struct syscore poweroff_syscore = {
  41. .ops = &poweroff_syscore_ops,
  42. };
  43. static void sc27xx_poweroff_do_poweroff(void)
  44. {
  45. /* Disable the external subsys connection's power firstly */
  46. regmap_write(regmap, SC27XX_SLP_CTRL, SC27XX_LDO_XTL_EN);
  47. regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN);
  48. }
  49. static int sc27xx_poweroff_probe(struct platform_device *pdev)
  50. {
  51. if (regmap)
  52. return -EINVAL;
  53. regmap = dev_get_regmap(pdev->dev.parent, NULL);
  54. if (!regmap)
  55. return -ENODEV;
  56. pm_power_off = sc27xx_poweroff_do_poweroff;
  57. register_syscore(&poweroff_syscore);
  58. return 0;
  59. }
  60. static struct platform_driver sc27xx_poweroff_driver = {
  61. .probe = sc27xx_poweroff_probe,
  62. .driver = {
  63. .name = "sc27xx-poweroff",
  64. },
  65. };
  66. module_platform_driver(sc27xx_poweroff_driver);
  67. MODULE_DESCRIPTION("Power off driver for SC27XX PMIC Device");
  68. MODULE_AUTHOR("Baolin Wang <baolin.wang@unisoc.com>");
  69. MODULE_LICENSE("GPL v2");