1 /*
2 * SPDX-License-Identifier: Apache-2.0
3 * Copyright (c) 2024 sensry.io
4 */
5
6 #include <zephyr/device.h>
7 #include <zephyr/init.h>
8
9 #include <zephyr/sys/util.h>
10
11 #define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
12 #include <zephyr/logging/log.h>
13 LOG_MODULE_REGISTER(soc);
14
15 #include "soc.h"
16
17 /* ITC */
18 #define SY1XX_ARCHI_ITC_MASK_OFFSET 0x0
19 #define SY1XX_ARCHI_ITC_MASK_SET_OFFSET 0x4
20 #define SY1XX_ARCHI_ITC_MASK_CLR_OFFSET 0x8
21 #define SY1XX_ARCHI_ITC_STATUS_OFFSET 0xc
22 #define SY1XX_ARCHI_ITC_STATUS_SET_OFFSET 0x10
23 #define SY1XX_ARCHI_ITC_STATUS_CLR_OFFSET 0x14
24 #define SY1XX_ARCHI_ITC_ACK_OFFSET 0x18
25 #define SY1XX_ARCHI_ITC_ACK_SET_OFFSET 0x1c
26 #define SY1XX_ARCHI_ITC_ACK_CLR_OFFSET 0x20
27 #define SY1XX_ARCHI_ITC_FIFO_OFFSET 0x24
28
sys_arch_reboot(int type)29 void sys_arch_reboot(int type)
30 {
31 ARG_UNUSED(type);
32 }
33
34 #define SY1XX_ARCHI_REF_CLOCK (32768)
35 #define SY1XX_ARCHI_PER_CLOCK (125000000)
36
sy1xx_soc_get_rts_clock_frequency(void)37 uint32_t sy1xx_soc_get_rts_clock_frequency(void)
38 {
39 return SY1XX_ARCHI_REF_CLOCK;
40 }
41
sy1xx_soc_get_peripheral_clock(void)42 uint32_t sy1xx_soc_get_peripheral_clock(void)
43 {
44 return SY1XX_ARCHI_PER_CLOCK;
45 }
46
riscv_clic_irq_priority_set(uint32_t irq,uint32_t prio,uint32_t flags)47 void riscv_clic_irq_priority_set(uint32_t irq, uint32_t prio, uint32_t flags)
48 {
49 /* we do not support priorities */
50 }
51
soc_enable_irq(uint32_t idx)52 void soc_enable_irq(uint32_t idx)
53 {
54 uint32_t current = sys_read32(SY1XX_ARCHI_FC_ITC_ADDR + SY1XX_ARCHI_ITC_MASK_SET_OFFSET);
55
56 sys_write32(current | (1 << (idx & 0x1f)),
57 SY1XX_ARCHI_FC_ITC_ADDR + SY1XX_ARCHI_ITC_MASK_SET_OFFSET);
58 }
59
soc_disable_irq(uint32_t idx)60 void soc_disable_irq(uint32_t idx)
61 {
62 uint32_t current = sys_read32(SY1XX_ARCHI_FC_ITC_ADDR + SY1XX_ARCHI_ITC_MASK_CLR_OFFSET);
63
64 sys_write32(current & (~(1 << (idx & 0x1f))),
65 SY1XX_ARCHI_FC_ITC_ADDR + SY1XX_ARCHI_ITC_MASK_CLR_OFFSET);
66 }
67
68 /*
69 * SoC-level interrupt initialization. Clear any pending interrupts or
70 * events, and find the INTMUX device if necessary.
71 *
72 * This gets called as almost the first thing z_cstart() does, so it
73 * will happen before any calls to the _arch_irq_xxx() routines above.
74 */
soc_interrupt_init(void)75 void soc_interrupt_init(void)
76 {
77 }
78
79 /**
80 * @brief Perform basic hardware initialization
81 *
82 * Initializes the base clocks and LPFLL using helpers provided by the HAL.
83 *
84 * @return 0
85 */
sy1xx_soc_init(void)86 static int sy1xx_soc_init(void)
87 {
88
89 return 0;
90 }
91
92 SYS_INIT(sy1xx_soc_init, PRE_KERNEL_1, 0);
93