forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset_numaker.c
74 lines (56 loc) · 2.05 KB
/
reset_numaker.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2023 Nuvoton Technology Corporation.
*/
#define DT_DRV_COMPAT nuvoton_numaker_rst
#include <zephyr/arch/cpu.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/reset.h>
/* Reset controller module IPRST offset */
#define NUMAKER_RESET_IPRST0_OFFSET (8UL)
#define NUMAKER_RESET_IP_OFFSET(id) (NUMAKER_RESET_IPRST0_OFFSET + (((id) >> 24UL) & 0xffUL))
/* Reset controller module configuration bit */
#define NUMAKER_RESET_IP_BIT(id) (id & 0x00ffffffUL)
struct reset_numaker_config {
uint32_t base;
};
static int reset_numaker_status(const struct device *dev, uint32_t id, uint8_t *status)
{
const struct reset_numaker_config *config = dev->config;
*status = !!sys_test_bit(config->base + NUMAKER_RESET_IP_OFFSET(id),
NUMAKER_RESET_IP_BIT(id));
return 0;
}
static int reset_numaker_line_assert(const struct device *dev, uint32_t id)
{
const struct reset_numaker_config *config = dev->config;
/* Generate reset signal to the corresponding module */
sys_set_bit(config->base + NUMAKER_RESET_IP_OFFSET(id), NUMAKER_RESET_IP_BIT(id));
return 0;
}
static int reset_numaker_line_deassert(const struct device *dev, uint32_t id)
{
const struct reset_numaker_config *config = dev->config;
/* Release corresponding module from reset state */
sys_clear_bit(config->base + NUMAKER_RESET_IP_OFFSET(id), NUMAKER_RESET_IP_BIT(id));
return 0;
}
static int reset_numaker_line_toggle(const struct device *dev, uint32_t id)
{
(void)reset_numaker_line_assert(dev, id);
(void)reset_numaker_line_deassert(dev, id);
return 0;
}
static const struct reset_driver_api reset_numaker_driver_api = {
.status = reset_numaker_status,
.line_assert = reset_numaker_line_assert,
.line_deassert = reset_numaker_line_deassert,
.line_toggle = reset_numaker_line_toggle,
};
static const struct reset_numaker_config config = {
.base = (uint32_t)DT_INST_REG_ADDR(0),
};
DEVICE_DT_INST_DEFINE(0, NULL, NULL, NULL, &config, PRE_KERNEL_1,
CONFIG_RESET_INIT_PRIORITY, &reset_numaker_driver_api);