platform.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Damien Le Moal <damien.lemoal@wdc.com>
  8. */
  9. #include <sbi/riscv_encoding.h>
  10. #include <sbi/sbi_const.h>
  11. #include <sbi/sbi_hart.h>
  12. #include <sbi/sbi_platform.h>
  13. #include <sbi/sbi_console.h>
  14. #include <plat/irqchip/plic.h>
  15. #include <plat/sys/clint.h>
  16. #include "platform.h"
  17. #include "uarths.h"
  18. #define K210_UART_BAUDRATE 115200
  19. static int k210_console_init(void)
  20. {
  21. uarths_init(K210_UART_BAUDRATE, UARTHS_STOP_1);
  22. return 0;
  23. }
  24. static void k210_console_putc(char c)
  25. {
  26. uarths_putc(c);
  27. }
  28. static int k210_console_getc(void)
  29. {
  30. return uarths_getc();
  31. }
  32. static int k210_irqchip_init(bool cold_boot)
  33. {
  34. int rc;
  35. u32 hartid = sbi_current_hartid();
  36. if (cold_boot) {
  37. rc = plic_cold_irqchip_init(PLIC_BASE_ADDR, PLIC_NUM_SOURCES,
  38. K210_HART_COUNT);
  39. if (rc)
  40. return rc;
  41. }
  42. return plic_warm_irqchip_init(hartid, (2 * hartid), (2 * hartid + 1));
  43. }
  44. static int k210_ipi_init(bool cold_boot)
  45. {
  46. int rc;
  47. if (cold_boot) {
  48. rc = clint_cold_ipi_init(CLINT_BASE_ADDR, K210_HART_COUNT);
  49. if (rc)
  50. return rc;
  51. }
  52. return clint_warm_ipi_init();
  53. }
  54. static int k210_timer_init(bool cold_boot)
  55. {
  56. int rc;
  57. if (cold_boot) {
  58. rc = clint_cold_timer_init(CLINT_BASE_ADDR, K210_HART_COUNT);
  59. if (rc)
  60. return rc;
  61. }
  62. return clint_warm_timer_init();
  63. }
  64. static int k210_system_reboot(u32 type)
  65. {
  66. /* For now nothing to do. */
  67. sbi_printf("System reboot\n");
  68. return 0;
  69. }
  70. static int k210_system_shutdown(u32 type)
  71. {
  72. /* For now nothing to do. */
  73. sbi_printf("System shutdown\n");
  74. return 0;
  75. }
  76. const struct sbi_platform platform = {
  77. .name = "Kendryte K210",
  78. .features = SBI_PLATFORM_HAS_TIMER_VALUE,
  79. .hart_count = K210_HART_COUNT,
  80. .hart_stack_size = K210_HART_STACK_SIZE,
  81. .disabled_hart_mask = 0,
  82. .console_init = k210_console_init,
  83. .console_putc = k210_console_putc,
  84. .console_getc = k210_console_getc,
  85. .irqchip_init = k210_irqchip_init,
  86. .ipi_init = k210_ipi_init,
  87. .ipi_send = clint_ipi_send,
  88. .ipi_sync = clint_ipi_sync,
  89. .ipi_clear = clint_ipi_clear,
  90. .timer_init = k210_timer_init,
  91. .timer_value = clint_timer_value,
  92. .timer_event_stop = clint_timer_event_stop,
  93. .timer_event_start = clint_timer_event_start,
  94. .system_reboot = k210_system_reboot,
  95. .system_shutdown = k210_system_shutdown
  96. };