drv_por.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #define CVI_RTC_CTRL_BASE 0x05025000U
  17. #define CVI_RTC_REG_BASE 0x05026000U
  18. #define RTC_CTRL0_UNLOCKKEY 0x4
  19. #define RTC_CTRL0 0x8
  20. #define RTC_APB_BUSY_SEL 0x3C
  21. #define RTC_EN_WARM_RST_REQ 0xCC
  22. #define RSM_STATE 0xD4
  23. #define ST_ON 0x3
  24. static int cvi_restart(void)
  25. {
  26. /* Enable power suspend wakeup source mask */
  27. mmio_write_32(CVI_RTC_REG_BASE + RTC_APB_BUSY_SEL,0x1);
  28. /* unlock register */
  29. mmio_write_32(CVI_RTC_CTRL_BASE + RTC_CTRL0_UNLOCKKEY, 0xAB18);
  30. mmio_write_32(CVI_RTC_REG_BASE + RTC_EN_WARM_RST_REQ, 0x1);
  31. while (mmio_read_32(CVI_RTC_REG_BASE + RTC_EN_WARM_RST_REQ) != 0x01);
  32. while (mmio_read_32(CVI_RTC_REG_BASE + RSM_STATE) != ST_ON);
  33. mmio_write_32( CVI_RTC_CTRL_BASE + RTC_CTRL0,0xFFFF0800 | (0x1 << 4));
  34. return 0;
  35. }
  36. void rt_hw_cpu_reset(void)
  37. {
  38. cvi_restart();
  39. while (1);
  40. }
  41. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);