|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Renesas Electronics Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#define DT_DRV_COMPAT renesas_ra_drw |
| 8 | + |
| 9 | +#include <zephyr/kernel.h> |
| 10 | +#include <zephyr/irq.h> |
| 11 | +#include <soc.h> |
| 12 | +#include <r_drw_base.h> |
| 13 | +#include <r_drw_cfg.h> |
| 14 | + |
| 15 | +#define DRW_PRV_IRQCTL_DLISTIRQ_ENABLE BIT(1) |
| 16 | +#define DRW_PRV_IRQCTL_ENUMIRQ_CLEAR BIT(2) |
| 17 | +#define DRW_PRV_IRQCTL_DLISTIRQ_CLEAR BIT(3) |
| 18 | +#define DRW_PRV_IRQCTL_BUSIRQ_CLEAR BIT(5) |
| 19 | +#define DRW_PRV_IRQCTL_ALLIRQ_DISABLE_AND_CLEAR \ |
| 20 | + (DRW_PRV_IRQCTL_BUSIRQ_CLEAR | DRW_PRV_IRQCTL_DLISTIRQ_CLEAR | DRW_PRV_IRQCTL_ENUMIRQ_CLEAR) |
| 21 | +#define DRW_PRV_IRQCTL_ALLIRQ_CLEAR_AND_DLISTIRQ_ENABLE \ |
| 22 | + (DRW_PRV_IRQCTL_BUSIRQ_CLEAR | DRW_PRV_IRQCTL_DLISTIRQ_CLEAR | \ |
| 23 | + DRW_PRV_IRQCTL_ENUMIRQ_CLEAR | DRW_PRV_IRQCTL_DLISTIRQ_ENABLE) |
| 24 | +#define DRW_PRV_STATUS_DLISTIRQ_TRIGGERED (1U << 5) |
| 25 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(drw), okay) |
| 26 | +#define VECTOR_NUMBER_DRW_INT DT_IRQN(DT_NODELABEL(drw)) |
| 27 | +#else |
| 28 | +#error "Device tree node 'drw' not found or disabled (status != okay)" |
| 29 | +#endif |
| 30 | + |
| 31 | +static struct k_sem d1_queryirq_sem; |
| 32 | +K_HEAP_DEFINE(drw_heap_runtime, CONFIG_RENESAS_DAVE2D_RUNTIME_HEAP_SIZE); |
| 33 | + |
| 34 | +d1_int_t d1_initirq_intern(d1_device_flex *handle) |
| 35 | +{ |
| 36 | + if (VECTOR_NUMBER_DRW_INT >= 0) { |
| 37 | + /* Clear all the D/AVE 2D IRQs and enable Display list IRQ. */ |
| 38 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_CLEAR_AND_DLISTIRQ_ENABLE; |
| 39 | + R_FSP_IsrContextSet((IRQn_Type)VECTOR_NUMBER_DRW_INT, handle); |
| 40 | + } |
| 41 | + |
| 42 | + return (k_sem_init(&d1_queryirq_sem, 0, 1) == 0); |
| 43 | +} |
| 44 | + |
| 45 | +d1_int_t d1_shutdownirq_intern(d1_device_flex *handle) |
| 46 | +{ |
| 47 | + ARG_UNUSED(handle); |
| 48 | + |
| 49 | + /* Disable D/AVE 2D interrupt in NVIC. */ |
| 50 | + irq_disable(VECTOR_NUMBER_DRW_INT); |
| 51 | + |
| 52 | + /* Clear all the D/AVE 2D IRQs and disable Display list IRQ. */ |
| 53 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_DISABLE_AND_CLEAR; |
| 54 | + |
| 55 | + return 1; |
| 56 | +} |
| 57 | + |
| 58 | +d1_int_t d1_queryirq(d1_device *handle, d1_int_t irqmask, d1_int_t timeout) |
| 59 | +{ |
| 60 | + /* Wait for dlist processing to complete. */ |
| 61 | + return (k_sem_take(&d1_queryirq_sem, K_MSEC(timeout)) == 0); |
| 62 | +} |
| 63 | + |
| 64 | +void *d1_malloc(d1_uint_t size) |
| 65 | +{ |
| 66 | + return k_heap_alloc(&drw_heap_runtime, size, K_NO_WAIT); |
| 67 | +} |
| 68 | + |
| 69 | +void d1_free(void *ptr) |
| 70 | +{ |
| 71 | + k_heap_free(&drw_heap_runtime, ptr); |
| 72 | +} |
| 73 | + |
| 74 | +void drw_zephyr_irq_handler(const struct device *dev) |
| 75 | +{ |
| 76 | + uint32_t int_status; |
| 77 | + IRQn_Type irq = R_FSP_CurrentIrqGet(); |
| 78 | + /* Read D/AVE 2D interrupt status */ |
| 79 | + int_status = R_DRW->STATUS; |
| 80 | + /* Get current IRQ number */ |
| 81 | + /* Clear all D/AVE 2D interrupts except for Display List IRQ enable */ |
| 82 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_CLEAR_AND_DLISTIRQ_ENABLE; |
| 83 | + |
| 84 | + if (int_status & DRW_PRV_STATUS_DLISTIRQ_TRIGGERED) { |
| 85 | + d1_device_flex *p_context = (d1_device_flex *)R_FSP_IsrContextGet(irq); |
| 86 | + |
| 87 | + if (p_context->dlist_indirect_enable && |
| 88 | + (NULL != (uint32_t *)*(p_context->pp_dlist_indirect_start))) { |
| 89 | + R_DRW->DLISTSTART = *(p_context->pp_dlist_indirect_start); |
| 90 | + p_context->pp_dlist_indirect_start++; |
| 91 | + } else { |
| 92 | + k_sem_give(&d1_queryirq_sem); |
| 93 | + } |
| 94 | + } |
| 95 | + /* Clear IRQ status. */ |
| 96 | + R_BSP_IrqStatusClear(irq); |
| 97 | +} |
| 98 | + |
| 99 | +#define DRW_INIT(inst) \ |
| 100 | + static int drw_renesas_ra_configure_func_##inst(void) \ |
| 101 | + { \ |
| 102 | + R_ICU->IELSR[DT_INST_IRQ_BY_NAME(inst, drw, irq)] = ELC_EVENT_DRW_INT; \ |
| 103 | + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, drw, irq), \ |
| 104 | + DT_INST_IRQ_BY_NAME(inst, drw, priority), drw_zephyr_irq_handler, \ |
| 105 | + DEVICE_DT_INST_GET(inst), 0); \ |
| 106 | + irq_enable(DT_INST_IRQ_BY_NAME(inst, drw, irq)); \ |
| 107 | + return 0; \ |
| 108 | + } \ |
| 109 | + static int renesas_drw_init_##inst(const struct device *dev) \ |
| 110 | + { \ |
| 111 | + ARG_UNUSED(dev); \ |
| 112 | + return drw_renesas_ra_configure_func_##inst(); \ |
| 113 | + } \ |
| 114 | + DEVICE_DT_INST_DEFINE(inst, renesas_drw_init_##inst, NULL, NULL, NULL, POST_KERNEL, \ |
| 115 | + CONFIG_RENESAS_DRW_INIT_PRIORITY, NULL); |
| 116 | + |
| 117 | +DT_INST_FOREACH_STATUS_OKAY(DRW_INIT) |
0 commit comments