forked from zephyrproject-rtos/zephyr
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwuc_ite_it8xxx2.c
120 lines (102 loc) · 3.21 KB
/
wuc_ite_it8xxx2.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright (c) 2022 ITE Corporation. All Rights Reserved
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ite_it8xxx2_wuc
#include <zephyr/device.h>
#include <zephyr/drivers/interrupt_controller/wuc_ite_it8xxx2.h>
#include <zephyr/dt-bindings/interrupt-controller/it8xxx2-wuc.h>
#include <zephyr/kernel.h>
#include <soc.h>
#include <soc_common.h>
#include <stdlib.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(wuc_ite_it8xxx2, CONFIG_INTC_LOG_LEVEL);
/* Driver config */
struct it8xxx2_wuc_cfg {
/* WUC wakeup edge mode register */
uint8_t *reg_wuemr;
/* WUC wakeup edge sense register */
uint8_t *reg_wuesr;
/* WUC wakeup enable register */
uint8_t *reg_wuenr;
/* WUC wakeup both edge mode register */
uint8_t *reg_wubemr;
};
void it8xxx2_wuc_enable(const struct device *dev, uint8_t mask)
{
const struct it8xxx2_wuc_cfg *config = dev->config;
volatile uint8_t *reg_wuenr = config->reg_wuenr;
/*
* WUC group only 1, 3, and 4 have enable/disable register,
* others are always enabled.
*/
if (reg_wuenr == IT8XXX2_WUC_UNUSED_REG) {
return;
}
/* Enable wakeup interrupt of the pin */
*reg_wuenr |= mask;
}
void it8xxx2_wuc_disable(const struct device *dev, uint8_t mask)
{
const struct it8xxx2_wuc_cfg *config = dev->config;
volatile uint8_t *reg_wuenr = config->reg_wuenr;
/*
* WUC group only 1, 3, and 4 have enable/disable register,
* others are always enabled.
*/
if (reg_wuenr == IT8XXX2_WUC_UNUSED_REG) {
return;
}
/* Disable wakeup interrupt of the pin */
*reg_wuenr &= ~mask;
}
void it8xxx2_wuc_clear_status(const struct device *dev, uint8_t mask)
{
const struct it8xxx2_wuc_cfg *config = dev->config;
volatile uint8_t *reg_wuesr = config->reg_wuesr;
if (reg_wuesr == IT8XXX2_WUC_UNUSED_REG) {
return;
}
/* W/C wakeup interrupt status of the pin */
*reg_wuesr = mask;
}
void it8xxx2_wuc_set_polarity(const struct device *dev, uint8_t mask, uint32_t flags)
{
const struct it8xxx2_wuc_cfg *config = dev->config;
volatile uint8_t *reg_wuemr = config->reg_wuemr;
volatile uint8_t *reg_wubemr = config->reg_wubemr;
if (reg_wuemr == IT8XXX2_WUC_UNUSED_REG) {
return;
}
/* Set wakeup interrupt edge trigger mode of the pin */
if ((flags & WUC_TYPE_EDGE_BOTH) == WUC_TYPE_EDGE_RISING) {
*reg_wubemr &= ~mask;
*reg_wuemr &= ~mask;
} else if ((flags & WUC_TYPE_EDGE_BOTH) == WUC_TYPE_EDGE_FALLING) {
*reg_wubemr &= ~mask;
*reg_wuemr |= mask;
} else {
/* Both edge trigger mode */
*reg_wubemr |= mask;
}
}
#define IT8XXX2_WUC_INIT(inst) \
\
static const struct it8xxx2_wuc_cfg it8xxx2_wuc_cfg_##inst = { \
.reg_wuemr = (uint8_t *) DT_INST_REG_ADDR_BY_IDX(inst, 0), \
.reg_wuesr = (uint8_t *) DT_INST_REG_ADDR_BY_IDX(inst, 1), \
.reg_wuenr = (uint8_t *) DT_INST_REG_ADDR_BY_IDX(inst, 2), \
.reg_wubemr = (uint8_t *) DT_INST_REG_ADDR_BY_IDX(inst, 3), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, \
NULL, \
NULL, \
NULL, \
&it8xxx2_wuc_cfg_##inst, \
PRE_KERNEL_1, \
CONFIG_KERNEL_INIT_PRIORITY_OBJECTS, \
NULL);
DT_INST_FOREACH_STATUS_OKAY(IT8XXX2_WUC_INIT)