881-v6.3-mfd-axp20x-Switch-to-the-sys-off-handler-API.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From 1b1305e95e85624f538ec56db9acf88e2d3d7397 Mon Sep 17 00:00:00 2001
  2. From: Samuel Holland <[email protected]>
  3. Date: Wed, 28 Dec 2022 10:27:52 -0600
  4. Subject: [PATCH] mfd: axp20x: Switch to the sys-off handler API
  5. This removes a layer of indirection through pm_power_off() and allows
  6. the PMIC handler to be used as a fallback when firmware power off fails.
  7. This happens on boards like the Clockwork DevTerm R-01 where OpenSBI
  8. does not know how to use the PMIC to power off the board.
  9. Move the check for AXP288 to avoid registering a dummy handler.
  10. Signed-off-by: Samuel Holland <[email protected]>
  11. [Lee: Removed superfluous new line]
  12. Signed-off-by: Lee Jones <[email protected]>
  13. Link: https://lore.kernel.org/r/[email protected]
  14. ---
  15. drivers/mfd/axp20x.c | 27 +++++++++++----------------
  16. 1 file changed, 11 insertions(+), 16 deletions(-)
  17. --- a/drivers/mfd/axp20x.c
  18. +++ b/drivers/mfd/axp20x.c
  19. @@ -23,7 +23,7 @@
  20. #include <linux/mfd/core.h>
  21. #include <linux/module.h>
  22. #include <linux/of_device.h>
  23. -#include <linux/pm_runtime.h>
  24. +#include <linux/reboot.h>
  25. #include <linux/regmap.h>
  26. #include <linux/regulator/consumer.h>
  27. @@ -832,17 +832,16 @@ static const struct mfd_cell axp813_cell
  28. },
  29. };
  30. -static struct axp20x_dev *axp20x_pm_power_off;
  31. -static void axp20x_power_off(void)
  32. +static int axp20x_power_off(struct sys_off_data *data)
  33. {
  34. - if (axp20x_pm_power_off->variant == AXP288_ID)
  35. - return;
  36. + struct axp20x_dev *axp20x = data->cb_data;
  37. - regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
  38. - AXP20X_OFF);
  39. + regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
  40. /* Give capacitors etc. time to drain to avoid kernel panic msg. */
  41. mdelay(500);
  42. +
  43. + return NOTIFY_DONE;
  44. }
  45. int axp20x_match_device(struct axp20x_dev *axp20x)
  46. @@ -1009,10 +1008,11 @@ int axp20x_device_probe(struct axp20x_de
  47. return ret;
  48. }
  49. - if (!pm_power_off) {
  50. - axp20x_pm_power_off = axp20x;
  51. - pm_power_off = axp20x_power_off;
  52. - }
  53. + if (axp20x->variant != AXP288_ID)
  54. + devm_register_sys_off_handler(axp20x->dev,
  55. + SYS_OFF_MODE_POWER_OFF,
  56. + SYS_OFF_PRIO_DEFAULT,
  57. + axp20x_power_off, axp20x);
  58. dev_info(axp20x->dev, "AXP20X driver loaded\n");
  59. @@ -1022,11 +1022,6 @@ EXPORT_SYMBOL(axp20x_device_probe);
  60. void axp20x_device_remove(struct axp20x_dev *axp20x)
  61. {
  62. - if (axp20x == axp20x_pm_power_off) {
  63. - axp20x_pm_power_off = NULL;
  64. - pm_power_off = NULL;
  65. - }
  66. -
  67. mfd_remove_devices(axp20x->dev);
  68. regmap_del_irq_chip(axp20x->irq, axp20x->regmap_irqc);
  69. }