tps65086-restart.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 Emil Renner Berthing
  4. */
  5. #include <linux/mfd/tps65086.h>
  6. #include <linux/mod_devicetable.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/reboot.h>
  10. static int tps65086_restart_notify(struct sys_off_data *data)
  11. {
  12. struct tps65086 *tps65086 = data->cb_data;
  13. int ret;
  14. ret = regmap_write(tps65086->regmap, TPS65086_FORCESHUTDN, 1);
  15. if (ret) {
  16. dev_err(tps65086->dev, "%s: error writing to tps65086 pmic: %d\n",
  17. __func__, ret);
  18. return NOTIFY_DONE;
  19. }
  20. /* give it a little time */
  21. mdelay(200);
  22. WARN_ON(1);
  23. return NOTIFY_DONE;
  24. }
  25. static int tps65086_restart_probe(struct platform_device *pdev)
  26. {
  27. struct tps65086 *tps65086 = dev_get_drvdata(pdev->dev.parent);
  28. return devm_register_sys_off_handler(&pdev->dev,
  29. SYS_OFF_MODE_RESTART,
  30. SYS_OFF_PRIO_HIGH,
  31. tps65086_restart_notify,
  32. tps65086);
  33. }
  34. static const struct platform_device_id tps65086_restart_id_table[] = {
  35. { "tps65086-reset", },
  36. { /* sentinel */ }
  37. };
  38. MODULE_DEVICE_TABLE(platform, tps65086_restart_id_table);
  39. static struct platform_driver tps65086_restart_driver = {
  40. .driver = {
  41. .name = "tps65086-restart",
  42. },
  43. .probe = tps65086_restart_probe,
  44. .id_table = tps65086_restart_id_table,
  45. };
  46. module_platform_driver(tps65086_restart_driver);
  47. MODULE_AUTHOR("Emil Renner Berthing <kernel@esmil.dk>");
  48. MODULE_DESCRIPTION("TPS65086 restart driver");