|
| 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 (1U << 1) |
| 16 | +#define DRW_PRV_IRQCTL_ENUMIRQ_CLEAR (1U << 2) |
| 17 | +#define DRW_PRV_IRQCTL_DLISTIRQ_CLEAR (1U << 3) |
| 18 | +#define DRW_PRV_IRQCTL_BUSIRQ_CLEAR (1U << 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 | +#define VECTOR_NUMBER_DRW_INT DT_IRQN(DT_NODELABEL(drw)) |
| 26 | +#if defined(VECTOR_NUMBER_DRW_INT) |
| 27 | +#define DRW_CFG_INT_IRQ VECTOR_NUMBER_DRW_INT |
| 28 | +#endif |
| 29 | + |
| 30 | +static struct k_sem d1_queryirq_sem; |
| 31 | +K_HEAP_DEFINE(drw_heap_runtime, CONFIG_RENESAS_DAVE2D_RUNTIME_HEAP_SIZE); |
| 32 | + |
| 33 | +d1_int_t d1_initirq_intern(d1_device_flex *handle) |
| 34 | +{ |
| 35 | + d1_int_t ret = 1; |
| 36 | + |
| 37 | + if (DRW_CFG_INT_IRQ >= 0) { |
| 38 | + /* Clear all the D/AVE 2D IRQs and enable Display list IRQ. */ |
| 39 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_CLEAR_AND_DLISTIRQ_ENABLE; |
| 40 | + R_FSP_IsrContextSet((IRQn_Type)DRW_CFG_INT_IRQ, handle); |
| 41 | + } |
| 42 | + |
| 43 | + /* Initialize semaphore for use in d1_queryirq() */ |
| 44 | + if (0 != k_sem_init(&d1_queryirq_sem, 0, 1)) { |
| 45 | + ret = 0; |
| 46 | + } |
| 47 | + |
| 48 | + return ret; |
| 49 | +} |
| 50 | + |
| 51 | +d1_int_t d1_shutdownirq_intern(d1_device_flex *handle) |
| 52 | +{ |
| 53 | + ARG_UNUSED(handle); |
| 54 | + |
| 55 | + /* Disable D/AVE 2D interrupt in NVIC. */ |
| 56 | + irq_disable(DRW_CFG_INT_IRQ); |
| 57 | + |
| 58 | + /* Clear all the D/AVE 2D IRQs and disable Display list IRQ. */ |
| 59 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_DISABLE_AND_CLEAR; |
| 60 | + |
| 61 | + return 1; |
| 62 | +} |
| 63 | + |
| 64 | +d1_int_t d1_queryirq(d1_device *handle, d1_int_t irqmask, d1_int_t timeout) |
| 65 | +{ |
| 66 | + d1_int_t ret = 1; |
| 67 | + |
| 68 | + /* Wait for dlist processing to complete. */ |
| 69 | + int err = k_sem_take(&d1_queryirq_sem, K_MSEC(timeout)); |
| 70 | + |
| 71 | + /* If the wait timed out return 0. */ |
| 72 | + if (err != 0) { |
| 73 | + ret = 0; |
| 74 | + } |
| 75 | + |
| 76 | + return ret; |
| 77 | +} |
| 78 | + |
| 79 | +void *d1_malloc(d1_uint_t size) |
| 80 | +{ |
| 81 | + return k_heap_alloc(&drw_heap_runtime, size, K_NO_WAIT); |
| 82 | +} |
| 83 | + |
| 84 | +void d1_free(void *ptr) |
| 85 | +{ |
| 86 | + k_heap_free(&drw_heap_runtime, ptr); |
| 87 | +} |
| 88 | + |
| 89 | +void drw_zephyr_irq_handler(const struct device *dev) |
| 90 | +{ |
| 91 | + uint32_t int_status; |
| 92 | + IRQn_Type irq = R_FSP_CurrentIrqGet(); |
| 93 | + /* Read D/AVE 2D interrupt status */ |
| 94 | + int_status = R_DRW->STATUS; |
| 95 | + /* Get current IRQ number */ |
| 96 | + /* Clear all D/AVE 2D interrupts except for Display List IRQ enable */ |
| 97 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_CLEAR_AND_DLISTIRQ_ENABLE; |
| 98 | + |
| 99 | + if (int_status & DRW_PRV_STATUS_DLISTIRQ_TRIGGERED) { |
| 100 | +#if DRW_CFG_USE_DLIST_INDIRECT |
| 101 | + d1_device_flex *p_context = (d1_device_flex *)R_FSP_IsrContextGet(irq); |
| 102 | + |
| 103 | + if (p_context->dlist_indirect_enable && |
| 104 | + (NULL != (uint32_t *)*(p_context->pp_dlist_indirect_start))) { |
| 105 | + R_DRW->DLISTSTART = *(p_context->pp_dlist_indirect_start); |
| 106 | + p_context->pp_dlist_indirect_start++; |
| 107 | + } else |
| 108 | +#endif |
| 109 | + { |
| 110 | + k_sem_give(&d1_queryirq_sem); |
| 111 | + } |
| 112 | + } |
| 113 | + /* Clear IRQ status. */ |
| 114 | + R_BSP_IrqStatusClear(irq); |
| 115 | + |
| 116 | + /* No explicit irq_clear needed unless your platform requires it */ |
| 117 | +} |
| 118 | + |
| 119 | +#define DRW_INIT(inst) \ |
| 120 | + static int drw_renesas_ra_configure_func_##inst(void) \ |
| 121 | + { \ |
| 122 | + R_ICU->IELSR[DT_INST_IRQ_BY_NAME(inst, drw, irq)] = ELC_EVENT_DRW_INT; \ |
| 123 | + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, drw, irq), \ |
| 124 | + DT_INST_IRQ_BY_NAME(inst, drw, priority), drw_zephyr_irq_handler, \ |
| 125 | + DEVICE_DT_INST_GET(inst), 0); \ |
| 126 | + irq_enable(DT_INST_IRQ_BY_NAME(inst, drw, irq)); \ |
| 127 | + return 0; \ |
| 128 | + } \ |
| 129 | + static int renesas_drw_init_##inst(const struct device *dev) \ |
| 130 | + { \ |
| 131 | + ARG_UNUSED(dev); \ |
| 132 | + return drw_renesas_ra_configure_func_##inst(); \ |
| 133 | + } \ |
| 134 | + DEVICE_DT_INST_DEFINE(inst, renesas_drw_init_##inst, NULL, NULL, NULL, POST_KERNEL, \ |
| 135 | + CONFIG_RENESAS_DRW_INIT_PRIORITY, NULL); |
| 136 | + |
| 137 | +DT_INST_FOREACH_STATUS_OKAY(DRW_INIT) |
0 commit comments