sysreset_sti.c 1.9 KB

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