|
| 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_FSP_IsrContextSet((IRQn_Type)VECTOR_NUMBER_DRW_INT, handle); |
| 39 | + irq_enable(VECTOR_NUMBER_DRW_INT); |
| 40 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_CLEAR_AND_DLISTIRQ_ENABLE; |
| 41 | + } |
| 42 | + |
| 43 | + return (k_sem_init(&d1_queryirq_sem, 0, 1) == 0); |
| 44 | +} |
| 45 | + |
| 46 | +d1_int_t d1_shutdownirq_intern(d1_device_flex *handle) |
| 47 | +{ |
| 48 | + ARG_UNUSED(handle); |
| 49 | + |
| 50 | + /* Disable D/AVE 2D interrupt in NVIC. */ |
| 51 | + irq_disable(VECTOR_NUMBER_DRW_INT); |
| 52 | + |
| 53 | + /* Clear all the D/AVE 2D IRQs and disable Display list IRQ. */ |
| 54 | + R_DRW->IRQCTL = DRW_PRV_IRQCTL_ALLIRQ_DISABLE_AND_CLEAR; |
| 55 | + |
| 56 | + return 1; |
| 57 | +} |
| 58 | + |
| 59 | +d1_int_t d1_queryirq(d1_device *handle, d1_int_t irqmask, d1_int_t timeout) |
| 60 | +{ |
| 61 | + /* Wait for dlist processing to complete. */ |
| 62 | + return (k_sem_take(&d1_queryirq_sem, K_MSEC(timeout)) == 0); |
| 63 | +} |
| 64 | + |
| 65 | +void *d1_malloc(d1_uint_t size) |
| 66 | +{ |
| 67 | + return k_heap_alloc(&drw_heap_runtime, size, K_NO_WAIT); |
| 68 | +} |
| 69 | + |
| 70 | +void d1_free(void *ptr) |
| 71 | +{ |
| 72 | + k_heap_free(&drw_heap_runtime, ptr); |
| 73 | +} |
| 74 | + |
| 75 | +void drw_zephyr_irq_handler(const struct device *dev) |
| 76 | +{ |
| 77 | + uint32_t int_status; |
| 78 | + IRQn_Type irq = R_FSP_CurrentIrqGet(); /* Get current IRQ number */ |
| 79 | + |
| 80 | + int_status = R_DRW->STATUS; /* Read D/AVE 2D interrupt status */ |
| 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_d1_handle = (d1_device_flex *)R_FSP_IsrContextGet(irq); |
| 86 | + |
| 87 | + if (p_d1_handle != NULL) { |
| 88 | + uint32_t **pp_dlist_indirect_start = |
| 89 | + (uint32_t **)p_d1_handle->pp_dlist_indirect_start; |
| 90 | + if (p_d1_handle->dlist_indirect_enable && |
| 91 | + *pp_dlist_indirect_start != NULL) { |
| 92 | + R_DRW->DLISTSTART = *pp_dlist_indirect_start; |
| 93 | + p_d1_handle->pp_dlist_indirect_start++; |
| 94 | + } else { |
| 95 | + k_sem_give(&d1_queryirq_sem); |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + /* Clear IRQ status. */ |
| 100 | + R_BSP_IrqStatusClear(irq); |
| 101 | +} |
| 102 | + |
| 103 | +#define DRW_INIT(inst) \ |
| 104 | + static int drw_renesas_ra_configure_func_##inst(void) \ |
| 105 | + { \ |
| 106 | + R_ICU->IELSR[DT_INST_IRQ_BY_NAME(inst, drw, irq)] = ELC_EVENT_DRW_INT; \ |
| 107 | + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, drw, irq), \ |
| 108 | + DT_INST_IRQ_BY_NAME(inst, drw, priority), drw_zephyr_irq_handler, \ |
| 109 | + DEVICE_DT_INST_GET(inst), 0); \ |
| 110 | + return 0; \ |
| 111 | + } \ |
| 112 | + static int renesas_drw_init_##inst(const struct device *dev) \ |
| 113 | + { \ |
| 114 | + ARG_UNUSED(dev); \ |
| 115 | + return drw_renesas_ra_configure_func_##inst(); \ |
| 116 | + } \ |
| 117 | + DEVICE_DT_INST_DEFINE(inst, renesas_drw_init_##inst, NULL, NULL, NULL, POST_KERNEL, \ |
| 118 | + CONFIG_RENESAS_DRW_INIT_PRIORITY, NULL); |
| 119 | + |
| 120 | +DT_INST_FOREACH_STATUS_OKAY(DRW_INIT) |
0 commit comments