system_power.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2020 Sartura Ltd.
  3. * Author: Luka Kovacic <luka.kovacic@sartura.hr>
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. * https://spdx.org/licenses
  7. */
  8. #include <armada_common.h>
  9. #include <common/debug.h>
  10. #include <drivers/delay_timer.h>
  11. #include <drivers/ti/uart/uart_16550.h>
  12. #include <drivers/console.h>
  13. #include <plat_marvell.h>
  14. /*****************************************************************************
  15. * Platform specific power off functions
  16. * Power off PSU / Send command to power management MCU / ...
  17. *****************************************************************************
  18. */
  19. unsigned char add_xor_checksum(unsigned char *buf, unsigned char xor_len)
  20. {
  21. unsigned char xor_sum = 0;
  22. unsigned int i;
  23. for (i = 0; i < xor_len; i++)
  24. xor_sum ^= buf[i];
  25. return xor_sum;
  26. }
  27. int system_power_off(void)
  28. {
  29. static console_t console;
  30. /* WT61P803 MCU system_off_now command */
  31. unsigned char system_off_now[4] = { '@', 'C', '0' };
  32. int i, len;
  33. len = sizeof(system_off_now);
  34. system_off_now[len - 1] = add_xor_checksum(system_off_now, len);
  35. console_16550_register(PLAT_MARVELL_UART_BASE + 0x100,
  36. PLAT_MARVELL_UART_CLK_IN_HZ, 115200, &console);
  37. /* Send system_off_now to console */
  38. for (i = 0; i < len; i++) {
  39. console.putc(system_off_now[i], &console);
  40. udelay(1000);
  41. }
  42. console.flush(&console);
  43. (void)console_unregister(&console);
  44. mdelay(100);
  45. return 0;
  46. }