Lines Matching +full:zephyr +full:- +full:base

4  * SPDX-License-Identifier: Apache-2.0
11 * initialization, interrupt handling, and any other module-wide tasks. The current implementation
18 #include <zephyr/drivers/counter.h>
19 #include <zephyr/sys/util.h>
20 #include <zephyr/drivers/clock_control.h>
21 #include <zephyr/devicetree.h>
22 #include <zephyr/device.h>
23 #include <zephyr/irq.h>
24 #include <zephyr/drivers/reset.h>
29 #include <zephyr/logging/log.h>
34 (*(struct nxp_mrt_channel_data *const *const)dev->data)
36 /* Device config->data is an array of data pointers ordered by channel number,
37 * dev->data is a pointer to one of these pointers in that array,
38 * so the value of the dev->data - dev->config->data is the channel index
41 (((struct nxp_mrt_channel_data *const *)dev->data) - \
42 ((const struct nxp_mrt_config *)dev->config)->data)
54 MRT_Type *base; member
65 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_stop()
66 MRT_Type *base = config->base; in nxp_mrt_stop() local
69 LOG_DBG("MRT@%p channel %d stopped", base, channel_id); in nxp_mrt_stop()
73 base->CHANNEL[channel_id].INTVAL = MRT_CHANNEL_INTVAL_LOAD(1); in nxp_mrt_stop()
80 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_start()
81 MRT_Type *base = config->base; in nxp_mrt_start() local
85 if (data->top <= 1) { in nxp_mrt_start()
86 /* Zephyr API says default should be max top value */ in nxp_mrt_start()
88 base, channel_id, config->info.max_top_value); in nxp_mrt_start()
89 data->top = config->info.max_top_value; in nxp_mrt_start()
93 base->CHANNEL[channel_id].INTVAL = data->top; in nxp_mrt_start()
95 LOG_DBG("MRT@%p channel %d started with top value %d", base, channel_id, data->top); in nxp_mrt_start()
102 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_get_value()
103 MRT_Type *base = config->base; in nxp_mrt_get_value() local
106 *ticks = base->CHANNEL[channel_id].TIMER & MRT_CHANNEL_TIMER_VALUE_MASK; in nxp_mrt_get_value()
114 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_set_top_value()
115 MRT_Type *base = config->base; in nxp_mrt_set_top_value() local
118 /* By default in Zephyr API, the counter resets on changing top value */ in nxp_mrt_set_top_value()
119 bool reset = !(cfg->flags & COUNTER_TOP_CFG_DONT_RESET); in nxp_mrt_set_top_value()
120 bool active = base->CHANNEL[channel_id].STAT & MRT_CHANNEL_STAT_RUN_MASK; in nxp_mrt_set_top_value()
121 uint32_t current_val = base->CHANNEL[channel_id].TIMER & MRT_CHANNEL_TIMER_VALUE_MASK; in nxp_mrt_set_top_value()
125 data->top = cfg->ticks; in nxp_mrt_set_top_value()
128 data->cb = cfg->callback; in nxp_mrt_set_top_value()
129 data->user_data = cfg->user_data; in nxp_mrt_set_top_value()
134 LOG_DBG("Set MRT@%p channel %d top value to %d", base, channel_id, data->top); in nxp_mrt_set_top_value()
139 if (cfg->ticks < current_val) { in nxp_mrt_set_top_value()
142 base, channel_id, cfg->ticks, current_val); in nxp_mrt_set_top_value()
143 /* Zephyr API says return this error in case of lateness in nxp_mrt_set_top_value()
146 ret = reset ? 0 : -ETIME; in nxp_mrt_set_top_value()
148 reset |= cfg->flags & COUNTER_TOP_CFG_RESET_WHEN_LATE; in nxp_mrt_set_top_value()
152 base->CHANNEL[channel_id].INTVAL = MRT_CHANNEL_INTVAL_IVALUE(cfg->ticks) | in nxp_mrt_set_top_value()
156 base, channel_id, in nxp_mrt_set_top_value()
157 base->CHANNEL[channel_id].INTVAL & MRT_CHANNEL_INTVAL_IVALUE_MASK); in nxp_mrt_set_top_value()
164 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_get_top_value()
165 MRT_Type *base = config->base; in nxp_mrt_get_top_value() local
168 return base->CHANNEL[channel_id].INTVAL & MRT_CHANNEL_INTVAL_IVALUE_MASK; in nxp_mrt_get_top_value()
173 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_get_pending_int()
174 MRT_Type *base = config->base; in nxp_mrt_get_pending_int() local
177 return base->CHANNEL[channel_id].STAT & MRT_CHANNEL_STAT_INTFLAG_MASK; in nxp_mrt_get_pending_int()
189 return -ENOTSUP; in nxp_mrt_set_alarm()
198 return -ENOTSUP; in nxp_mrt_cancel_alarm()
203 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_get_freq()
206 clock_control_get_rate(config->clock_dev, config->clock_subsys, &freq); in nxp_mrt_get_freq()
213 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_init()
214 MRT_Type *base = config->base; in nxp_mrt_init() local
215 uint32_t num_channels = (base->MODCFG & MRT_MODCFG_NOC_MASK) >> MRT_MODCFG_NOC_SHIFT; in nxp_mrt_init()
218 if (!device_is_ready(config->reset.dev)) { in nxp_mrt_init()
220 return -ENODEV; in nxp_mrt_init()
223 ret = reset_line_toggle(config->reset.dev, config->reset.id); in nxp_mrt_init()
228 clock_control_on(config->clock_dev, config->clock_subsys); in nxp_mrt_init()
230 config->irq_config_func(dev); in nxp_mrt_init()
234 if (config->channels[i]) { in nxp_mrt_init()
235 base->CHANNEL[i].CTRL = MRT_CHANNEL_CTRL_INTEN_MASK; in nxp_mrt_init()
244 const struct nxp_mrt_config *config = dev->config; in nxp_mrt_isr()
245 MRT_Type *base = config->base; in nxp_mrt_isr() local
246 uint32_t irq_pends = base->IRQ_FLAG; in nxp_mrt_isr()
247 uint32_t num_channels = (base->MODCFG & MRT_MODCFG_NOC_MASK) >> MRT_MODCFG_NOC_SHIFT; in nxp_mrt_isr()
255 LOG_DBG("Handling interrupt for MRT%p channel %d", base, i); in nxp_mrt_isr()
258 base->CHANNEL[i].STAT |= MRT_CHANNEL_STAT_INTFLAG_MASK; in nxp_mrt_isr()
261 if (config->data[i]->cb) { in nxp_mrt_isr()
262 config->data[i]->cb(config->channels[i], config->data[i]->user_data); in nxp_mrt_isr()
338 GENMASK(DT_INST_PROP(n, num_bits) - 1, 0), \
341 .base = (MRT_Type *)DT_INST_REG_ADDR(n), \