drv_por.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-03-21 qiujingbao the first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #define DBG_TAG "DRV.POR"
  13. #define DBG_LVL DBG_WARNING
  14. #include <rtdbg.h>
  15. #include "mmio.h"
  16. #include "drv_ioremap.h"
  17. static rt_ubase_t _cvi_rtc_ctrl_base = 0x05025000U;
  18. static rt_ubase_t _cvi_rtc_reg_base = 0x05026000U;
  19. #define CVI_RTC_CTRL_BASE _cvi_rtc_ctrl_base
  20. #define CVI_RTC_REG_BASE _cvi_rtc_reg_base
  21. #define RTC_CTRL0_UNLOCKKEY 0x4
  22. #define RTC_CTRL0 0x8
  23. #define RTC_APB_BUSY_SEL 0x3C
  24. #define RTC_EN_WARM_RST_REQ 0xCC
  25. #define RSM_STATE 0xD4
  26. #define ST_ON 0x3
  27. static int cvi_restart(void)
  28. {
  29. /* Enable power suspend wakeup source mask */
  30. mmio_write_32(CVI_RTC_REG_BASE + RTC_APB_BUSY_SEL,0x1);
  31. /* unlock register */
  32. mmio_write_32(CVI_RTC_CTRL_BASE + RTC_CTRL0_UNLOCKKEY, 0xAB18);
  33. mmio_write_32(CVI_RTC_REG_BASE + RTC_EN_WARM_RST_REQ, 0x1);
  34. while (mmio_read_32(CVI_RTC_REG_BASE + RTC_EN_WARM_RST_REQ) != 0x01);
  35. while (mmio_read_32(CVI_RTC_REG_BASE + RSM_STATE) != ST_ON);
  36. mmio_write_32( CVI_RTC_CTRL_BASE + RTC_CTRL0,0xFFFF0800 | (0x1 << 4));
  37. return 0;
  38. }
  39. void rt_hw_cpu_reset(void)
  40. {
  41. rt_kprintf("Rebooting...\n");
  42. _cvi_rtc_ctrl_base = (rt_ubase_t)DRV_IOREMAP((void *)_cvi_rtc_ctrl_base, 0x1000);
  43. _cvi_rtc_reg_base = (rt_ubase_t)DRV_IOREMAP((void *)_cvi_rtc_reg_base, 0x1000);
  44. cvi_restart();
  45. rt_kprintf("ERROR: Failed to reboot the system\n");
  46. while (1);
  47. }
  48. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);