sysreset_sti.c 1.9 KB

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