sysreset_sti.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
  4. * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <regmap.h>
  9. #include <syscon.h>
  10. #include <sysreset.h>
  11. #include <asm/io.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. struct sti_sysreset_priv {
  14. phys_addr_t base;
  15. };
  16. static int sti_sysreset_request(struct udevice *dev, enum sysreset_t type)
  17. {
  18. struct sti_sysreset_priv *priv = dev_get_priv(dev);
  19. generic_clear_bit(0, (void __iomem *)priv->base);
  20. return -EINPROGRESS;
  21. }
  22. static int sti_sysreset_probe(struct udevice *dev)
  23. {
  24. struct sti_sysreset_priv *priv = dev_get_priv(dev);
  25. struct udevice *syscon;
  26. struct regmap *regmap;
  27. struct fdtdec_phandle_args syscfg_phandle;
  28. int ret;
  29. /* get corresponding syscon phandle */
  30. ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
  31. "st,syscfg", NULL, 0, 0,
  32. &syscfg_phandle);
  33. if (ret < 0) {
  34. pr_err("Can't get syscfg phandle: %d\n", ret);
  35. return ret;
  36. }
  37. ret = uclass_get_device_by_of_offset(UCLASS_SYSCON,
  38. syscfg_phandle.node,
  39. &syscon);
  40. if (ret) {
  41. pr_err("%s: uclass_get_device_by_of_offset failed: %d\n",
  42. __func__, ret);
  43. return ret;
  44. }
  45. regmap = syscon_get_regmap(syscon);
  46. if (!regmap) {
  47. pr_err("unable to get regmap for %s\n", syscon->name);
  48. return -ENODEV;
  49. }
  50. priv->base = regmap->ranges[0].start;
  51. return 0;
  52. }
  53. static struct sysreset_ops sti_sysreset = {
  54. .request = sti_sysreset_request,
  55. };
  56. static const struct udevice_id sti_sysreset_ids[] = {
  57. { .compatible = "st,stih407-restart" },
  58. { }
  59. };
  60. U_BOOT_DRIVER(sysreset_sti) = {
  61. .name = "sysreset_sti",
  62. .id = UCLASS_SYSRESET,
  63. .ops = &sti_sysreset,
  64. .probe = sti_sysreset_probe,
  65. .of_match = sti_sysreset_ids,
  66. .priv_auto_alloc_size = sizeof(struct sti_sysreset_priv),
  67. };