sc27xx-poweroff.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/platform_device.h>
  9. #include <linux/pm.h>
  10. #include <linux/regmap.h>
  11. #include <linux/syscore_ops.h>
  12. #define SC27XX_PWR_PD_HW 0xc2c
  13. #define SC27XX_PWR_OFF_EN BIT(0)
  14. static struct regmap *regmap;
  15. /*
  16. * On Spreadtrum platform, we need power off system through external SC27xx
  17. * series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC,
  18. * which is not fast io access.
  19. *
  20. * So before stopping other cores, we need release other cores' resource by
  21. * taking cpus down to avoid racing regmap or spi mutex lock when poweroff
  22. * system through PMIC.
  23. */
  24. static void sc27xx_poweroff_shutdown(void)
  25. {
  26. #ifdef CONFIG_PM_SLEEP_SMP
  27. int cpu = smp_processor_id();
  28. freeze_secondary_cpus(cpu);
  29. #endif
  30. }
  31. static struct syscore_ops poweroff_syscore_ops = {
  32. .shutdown = sc27xx_poweroff_shutdown,
  33. };
  34. static void sc27xx_poweroff_do_poweroff(void)
  35. {
  36. regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN);
  37. }
  38. static int sc27xx_poweroff_probe(struct platform_device *pdev)
  39. {
  40. if (regmap)
  41. return -EINVAL;
  42. regmap = dev_get_regmap(pdev->dev.parent, NULL);
  43. if (!regmap)
  44. return -ENODEV;
  45. pm_power_off = sc27xx_poweroff_do_poweroff;
  46. register_syscore_ops(&poweroff_syscore_ops);
  47. return 0;
  48. }
  49. static struct platform_driver sc27xx_poweroff_driver = {
  50. .probe = sc27xx_poweroff_probe,
  51. .driver = {
  52. .name = "sc27xx-poweroff",
  53. },
  54. };
  55. builtin_platform_driver(sc27xx_poweroff_driver);