|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
MIPI DSI-2 host driver – full HUM Ch 65 coverage. More...
#include "ra8_mipi_dsi.h"#include <stddef.h>#include <stdint.h>#include <string.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_mipi_dsi_internal.h"#include "ra8_mipi_dsi_regs.h"#include "ra8_mstp.h"Go to the source code of this file.
Functions | |
| static ra8_err_t | internal_ra8_mipi_dsi_validate_cfg (const ra8_mipi_dsi_config_t *cfg) |
| Validate a ra8_mipi_dsi_config_t argument. | |
| static void | internal_ra8_mipi_dsi_clear_all_status (void) |
| Clear every latched status bit in every sub-status register. | |
| static uint32_t | internal_ra8_mipi_dsi_make_txsetr (const ra8_mipi_dsi_config_t *cfg) |
| Compose TXSETR from a config (lane count + clock + data lane enable). | |
| static uint32_t | internal_ra8_mipi_dsi_make_dsisetr (const ra8_mipi_dsi_config_t *cfg) |
| Compose DSISETR from a config. | |
| ra8_err_t | priv_ra8_mipi_dsi_internal_wait_eq (volatile const uint32_t *reg, uint32_t mask, uint32_t expect) |
| Implementation of priv_ra8_mipi_dsi_internal_wait_eq() – bounded busy-poll. | |
| static void | internal_program_link (const ra8_mipi_dsi_config_t *cfg) |
| Pulse the RSTCR software reset and program the steady-state link-level registers. | |
| static void | internal_program_timeouts (const ra8_mipi_dsi_config_t *cfg) |
| Program the peripheral-response and transmit-side timeouts. | |
| ra8_err_t | ra8_mipi_dsi_init (const ra8_mipi_dsi_config_t *cfg) |
| Bring up the MIPI DSI host link layer. | |
| ra8_err_t | ra8_mipi_dsi_deinit (void) |
| Tear down the MIPI DSI host link layer. | |
| ra8_err_t | ra8_mipi_dsi_enter_stop (void) |
| Gate the MIPI DSI block at the MSTP register. | |
| ra8_err_t | ra8_mipi_dsi_exit_stop (void) |
| Re-enable the MIPI DSI block clock from MSTP. | |
| ra8_err_t | ra8_mipi_dsi_soft_reset (void) |
| Pulse RSTCR.SWRST to take the protocol-layer state back to a clean slate (registers retained). | |
| ra8_err_t | ra8_mipi_dsi_hs_clock_start (void) |
| Start the high-speed differential clock to the panel. | |
| ra8_err_t | ra8_mipi_dsi_hs_clock_stop (void) |
| Stop the high-speed differential clock. | |
| ra8_err_t | ra8_mipi_dsi_ulps_enter (uint8_t lanes) |
| Drive the selected lanes into Ultra-Low-Power State. | |
| ra8_err_t | ra8_mipi_dsi_ulps_exit (uint8_t lanes) |
| Wake the selected lanes out of ULPS. | |
Variables | |
| static const char * | s_tag = "MIPI_DSI" |
| Component tag used by the ra8_log_* family. | |
| ra8_mipi_dsi_event_fn_t | s_mipi_dsi_event_fn |
| Single definition of the shared IRQ callback pointer. | |
| void * | s_mipi_dsi_event_ctx |
| Single definition of the shared IRQ callback context. | |
| static bool | s_continuous_clock |
| Cache of cfg->clock_mode == continuous from the last init. | |
| static bool | s_clock_lanes_in_ulps |
| Software shadow of clock-lane ULPS state. | |
| static bool | s_data_lanes_in_ulps |
| Software shadow of data-lane ULPS state. | |
| uint8_t * | s_mipi_dsi_pending_rx_buffer |
| Single definition of the shared pending receive buffer. | |
| uint16_t | s_mipi_dsi_pending_rx_len |
| Single definition of the shared pending receive capacity. | |
| static bool | s_initialized |
| Software latch tracking whether the driver currently owns the MIPI-DSI module-stop reference count. | |
MIPI DSI-2 host driver – full HUM Ch 65 coverage.
Hand-written HAL for the RA8D2 MIPI DSI Host module (HUM Ch 65, p 3839-3934). Covers every documented register, every operating mode (sequence channel 0 LP, sequence channel 1 HS, video mode, BTA / read response, ULPS), every interrupt source (SQ0, SQ1, VM, RX, FERR, PHY), every error class (ECC single/multi, CRC, BTA TO, peripheral response timeout, fatal HS-Tx / LP-Rx / TA timeouts).
The D-PHY analog block (HUM Ch 64) is owned by ra8_mipi_phy.c. This driver only programmes the DSI link/protocol layer above it.
This translation unit carries the configuration, software-reset, module-stop lifecycle, HS-clock control, and ULPS paths – everything that owns the driver's module state. The sequence-channel command path lives in the sibling ra8_mipi_dsi_cmd.c, and the video-mode, status, IRQ-dispatch and convenience surfaces in ra8_mipi_dsi_dispatch.c; state shared across the three TUs lives in ra8_mipi_dsi_internal.h.
Every register access carries a HUM Ch 65 citation in the form required by scripts/checks/cite_check.py:
/* HUM Ch 65.X "name", p NNNN *\/
Definition in file ra8_mipi_dsi.c.
|
static |
Pulse the RSTCR software reset and program the steady-state link-level registers.
HUM Ch 65.2 "RSTCR" p 3853 plus the TXSETR / ULPSSETR / DSISETR / CLSTPTSETR / LPTRNSTSETR cluster (pp 3845-3887). Split out so ra8_mipi_dsi_init stays under the function-size threshold.
| [in] | cfg | Validated config. |
Definition at line 384 of file ra8_mipi_dsi.c.
References ra8_mipi_dsi_timing_t::clock_beforehand_time, ra8_mipi_dsi_timing_t::clock_keep_time, ra8_mipi_dsi_timing_t::clock_stop_time, r_mipi_dsi_regs_t::CLSTPTSETR, r_mipi_dsi_regs_t::DSISETR, ra8_mipi_dsi_timing_t::go_lp_and_back, internal_ra8_mipi_dsi_make_dsisetr(), internal_ra8_mipi_dsi_make_txsetr(), k_ra8_mipi_dsi_clstpt_clkbfht_mask, k_ra8_mipi_dsi_clstpt_clkbfht_shift, k_ra8_mipi_dsi_clstpt_clkkpt_mask, k_ra8_mipi_dsi_clstpt_clkkpt_shift, k_ra8_mipi_dsi_clstpt_clkstpt_mask, k_ra8_mipi_dsi_clstpt_clkstpt_shift, k_ra8_mipi_dsi_lptrnst_golpbkt_mask, k_ra8_mipi_dsi_rstcr_swrst, k_ulpssetr_wkup_shift, r_mipi_dsi_regs_t::LPTRNSTSETR, RA8_INTERNAL, ra8_mipi_dsi(), r_mipi_dsi_regs_t::RSTCR, ra8_mipi_dsi_config_t::timing, r_mipi_dsi_regs_t::TXSETR, ra8_mipi_dsi_config_t::ulps_wakeup_period, and r_mipi_dsi_regs_t::ULPSSETR.
Referenced by ra8_mipi_dsi_init().
|
static |
Program the peripheral-response and transmit-side timeouts.
HUM Ch 65.2 PRESPTOBTASETR / PRESPTOLPSETR / PRESPTOHSSETR / HSTXTOSETR / LRXHTOSETR / TATOSETR pp 3873-3881.
| [in] | cfg | Validated config. |
Definition at line 428 of file ra8_mipi_dsi.c.
References ra8_mipi_dsi_timeouts_t::bta_timeout, ra8_mipi_dsi_timeouts_t::hs_rw_timeout, ra8_mipi_dsi_timeouts_t::hs_tx_timeout, r_mipi_dsi_regs_t::HSTXTOSETR, ra8_mipi_dsi_timeouts_t::lp_rw_timeout, ra8_mipi_dsi_timeouts_t::lp_rx_host_timeout, r_mipi_dsi_regs_t::LRXHTOSETR, r_mipi_dsi_regs_t::PRESPTOBTASETR, r_mipi_dsi_regs_t::PRESPTOHSSETR, r_mipi_dsi_regs_t::PRESPTOLPSETR, RA8_INTERNAL, ra8_mipi_dsi(), r_mipi_dsi_regs_t::TATOSETR, ra8_mipi_dsi_config_t::timeouts, and ra8_mipi_dsi_timeouts_t::turnaround_timeout.
Referenced by ra8_mipi_dsi_init().
|
static |
Clear every latched status bit in every sub-status register.
RW1C semantics mean writing a 1 clears the bit; writing 0xFFFFFFFF clears them all in a single store. Used by both init and the dispatch routines.
Definition at line 271 of file ra8_mipi_dsi.c.
References r_mipi_dsi_regs_t::FERRSCR, k_ra8_mipi_dsi_ferrsr_clear_all, k_ra8_mipi_dsi_plsr_clear_all, k_ra8_mipi_dsi_rxsr_clear_all, k_ra8_mipi_dsi_sqch_clear_all, k_ra8_mipi_dsi_vmsr_clear_all, r_mipi_dsi_regs_t::PLSCR, RA8_INTERNAL, ra8_mipi_dsi(), r_mipi_dsi_regs_t::RXSCR, r_mipi_dsi_regs_t::SQCH0SCR, r_mipi_dsi_regs_t::SQCH1SCR, and r_mipi_dsi_regs_t::VMSCR.
Referenced by ra8_mipi_dsi_init().
|
static |
Compose DSISETR from a config.
| [in] | cfg | Validated configuration. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 327 of file ra8_mipi_dsi.c.
References ra8_mipi_dsi_config_t::crc_check_vc_mask, ra8_mipi_dsi_config_t::ecc_check_enable, ra8_mipi_dsi_config_t::eotp_enable, k_dsisetr_vc_crc_shift, k_ra8_mipi_dsi_dsisetr_eccen, k_ra8_mipi_dsi_dsisetr_eotpen, k_ra8_mipi_dsi_dsisetr_extemd, k_ra8_mipi_dsi_dsisetr_mrpsz_mask, k_ra8_mipi_dsi_dsisetr_scren, k_ra8_mipi_dsi_dsisetr_vc_crc_mask, ra8_mipi_dsi_config_t::max_return_packet_size, RA8_INTERNAL, ra8_mipi_dsi_config_t::scramble_enable, and ra8_mipi_dsi_config_t::tearing_detect_enable.
Referenced by internal_program_link().
|
static |
Compose TXSETR from a config (lane count + clock + data lane enable).
| [in] | cfg | Validated configuration. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 303 of file ra8_mipi_dsi.c.
References k_ra8_mipi_dsi_lanes_2, k_ra8_mipi_dsi_txset_clen, k_ra8_mipi_dsi_txset_dlen, k_ra8_mipi_dsi_txset_lane2, ra8_mipi_dsi_config_t::lane_count, and RA8_INTERNAL.
Referenced by internal_program_link().
|
static |
Validate a ra8_mipi_dsi_config_t argument.
| [in] | cfg | Caller-supplied config. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 247 of file ra8_mipi_dsi.c.
References k_ra8_err_invalid_arg, k_ra8_mipi_dsi_lanes_1, k_ra8_mipi_dsi_lanes_2, k_ra8_ok, ra8_mipi_dsi_config_t::lane_count, and RA8_INTERNAL.
Referenced by ra8_mipi_dsi_init().
| ra8_err_t priv_ra8_mipi_dsi_internal_wait_eq | ( | volatile const uint32_t * | reg, |
| uint32_t | mask, | ||
| uint32_t | expect ) |
Implementation of priv_ra8_mipi_dsi_internal_wait_eq() – bounded busy-poll.
Bounded poll waiting for (reg & mask) == expect.
Definition at line 349 of file ra8_mipi_dsi.c.
References k_ra8_err_hw_timeout, k_ra8_mipi_dsi_busy_loop_max, and k_ra8_ok.
Referenced by ra8_mipi_dsi_hs_clock_start(), ra8_mipi_dsi_hs_clock_stop(), ra8_mipi_dsi_video_start(), and ra8_mipi_dsi_video_stop().
|
nodiscard |
Tear down the MIPI DSI host link layer.
Detaches any IRQ handler, asserts RSTCR.SWRST, then disables the MSTP gate. Idempotent: calling twice in a row is harmless.
| k_ra8_ok | Block stopped, MSTP gated. |
| k_ra8_err_hw_timeout | MSTP read-back loop timed out. |
Definition at line 466 of file ra8_mipi_dsi.c.
References k_ra8_mipi_dsi_rstcr_swrst, k_ra8_mstp_mipi_dsi, k_ra8_ok, ra8_mipi_dsi(), ra8_mstp_disable(), r_mipi_dsi_regs_t::RSTCR, s_clock_lanes_in_ulps, s_continuous_clock, s_data_lanes_in_ulps, s_initialized, s_mipi_dsi_event_ctx, s_mipi_dsi_event_fn, s_mipi_dsi_pending_rx_buffer, and s_mipi_dsi_pending_rx_len.
|
nodiscard |
Gate the MIPI DSI block at the MSTP register.
| k_ra8_ok | Block gated. |
| k_ra8_err_hw_timeout | MSTP read-back loop timed out. |
Definition at line 495 of file ra8_mipi_dsi.c.
References k_ra8_err_invalid_state, k_ra8_mstp_mipi_dsi, k_ra8_ok, ra8_mstp_disable(), and s_initialized.
|
nodiscard |
Re-enable the MIPI DSI block clock from MSTP.
| k_ra8_ok | Block clocked again. |
| k_ra8_err_hw_timeout | MSTP read-back loop timed out. |
Definition at line 510 of file ra8_mipi_dsi.c.
References k_ra8_err_invalid_state, k_ra8_mstp_mipi_dsi, k_ra8_ok, ra8_mstp_enable(), and s_initialized.
|
nodiscard |
Start the high-speed differential clock to the panel.
Sets HSCLKSETR.HSCLST = 1 and, if the init config selected continuous mode, also sets HSCLMD = 1. Polls PLSR.CLLP2HS until the clock-lane LP-to-HS event fires (bounded by k_ra8_mipi_dsi_busy_loop_max).
Definition at line 539 of file ra8_mipi_dsi.c.
References r_mipi_dsi_regs_t::HSCLKSETR, k_ra8_mipi_dsi_hsclk_continuous, k_ra8_mipi_dsi_hsclk_start, k_ra8_mipi_dsi_plsr_cllp2hs, r_mipi_dsi_regs_t::PLSR, priv_ra8_mipi_dsi_internal_wait_eq(), ra8_mipi_dsi(), and s_continuous_clock.
Referenced by ra8_board_mipi_dsi_init().
|
nodiscard |
Stop the high-speed differential clock.
Clears HSCLKSETR.HSCLST and waits for PLSR.CLHS2LP.
Definition at line 554 of file ra8_mipi_dsi.c.
References r_mipi_dsi_regs_t::HSCLKSETR, k_ra8_mipi_dsi_plsr_clhs2lp, r_mipi_dsi_regs_t::PLSR, priv_ra8_mipi_dsi_internal_wait_eq(), and ra8_mipi_dsi().
|
nodiscard |
Bring up the MIPI DSI host link layer.
The HS clock is not started by this function; call ra8_mipi_dsi_hs_clock_start() separately so the application can insert PHY-level steps in between.
| [in] | cfg | Static driver configuration. Must not be nullptr. |
| k_ra8_ok | Driver initialized, link up. |
| k_ra8_err_null_ptr | cfg == nullptr. |
| k_ra8_err_invalid_arg | Lane count outside [1,2]. |
| k_ra8_err_hw_timeout | MSTP read-back loop timed out. |
Definition at line 439 of file ra8_mipi_dsi.c.
References ra8_mipi_dsi_config_t::clock_mode, internal_program_link(), internal_program_timeouts(), internal_ra8_mipi_dsi_clear_all_status(), internal_ra8_mipi_dsi_validate_cfg(), k_ra8_mipi_dsi_clock_continuous, k_ra8_mstp_mipi_dsi, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_clock_lanes_in_ulps, s_continuous_clock, s_data_lanes_in_ulps, s_initialized, s_mipi_dsi_event_ctx, s_mipi_dsi_event_fn, s_mipi_dsi_pending_rx_buffer, s_mipi_dsi_pending_rx_len, and s_tag.
Referenced by ra8_board_mipi_dsi_init().
|
nodiscard |
Pulse RSTCR.SWRST to take the protocol-layer state back to a clean slate (registers retained).
Definition at line 524 of file ra8_mipi_dsi.c.
References k_ra8_mipi_dsi_rstcr_swrst, k_ra8_ok, ra8_mipi_dsi(), and r_mipi_dsi_regs_t::RSTCR.
|
nodiscard |
Drive the selected lanes into Ultra-Low-Power State.
| [in] | lanes | OR of k_ra8_mipi_dsi_lane_clock / k_ra8_mipi_dsi_lane_data. |
Definition at line 570 of file ra8_mipi_dsi.c.
References k_ra8_err_invalid_arg, k_ra8_mipi_dsi_lane_clock, k_ra8_mipi_dsi_lane_data, k_ra8_mipi_dsi_lane_none, k_ra8_mipi_dsi_ulpscr_clent, k_ra8_mipi_dsi_ulpscr_dlent, k_ra8_ok, ra8_log_error, ra8_mipi_dsi(), s_clock_lanes_in_ulps, s_continuous_clock, s_data_lanes_in_ulps, s_tag, and r_mipi_dsi_regs_t::ULPSCR.
Referenced by ra8_mipi_dsi_enter_ulps().
|
nodiscard |
Wake the selected lanes out of ULPS.
| [in] | lanes | OR of k_ra8_mipi_dsi_lane_* bits. |
Definition at line 595 of file ra8_mipi_dsi.c.
References k_ra8_err_invalid_arg, k_ra8_mipi_dsi_lane_clock, k_ra8_mipi_dsi_lane_data, k_ra8_mipi_dsi_lane_none, k_ra8_mipi_dsi_ulpscr_clexit, k_ra8_mipi_dsi_ulpscr_dlexit, k_ra8_ok, ra8_mipi_dsi(), s_clock_lanes_in_ulps, s_data_lanes_in_ulps, and r_mipi_dsi_regs_t::ULPSCR.
Referenced by ra8_mipi_dsi_exit_ulps().
|
static |
Software shadow of clock-lane ULPS state.
The hardware does not expose a "currently in ULPS" bit cheaply, so the driver tracks it. Pulsing CLENT a second time while already in ULPS is a no-op in HW but FSP guards against it for symmetry; we do the same.
Definition at line 153 of file ra8_mipi_dsi.c.
Referenced by ra8_mipi_dsi_deinit(), ra8_mipi_dsi_init(), ra8_mipi_dsi_ulps_enter(), and ra8_mipi_dsi_ulps_exit().
|
static |
Cache of cfg->clock_mode == continuous from the last init.
Needed because the ULPS-enter helper must reject a clock-lane ULPS request when continuous-clock mode is on – the FSP source enforces the same rule. Snap-shotting it once at init avoids an extra register read on every ra8_mipi_dsi_ulps_enter() call.
Definition at line 137 of file ra8_mipi_dsi.c.
Referenced by ra8_mipi_dsi_deinit(), ra8_mipi_dsi_hs_clock_start(), ra8_mipi_dsi_init(), and ra8_mipi_dsi_ulps_enter().
|
static |
Software shadow of data-lane ULPS state.
Definition at line 163 of file ra8_mipi_dsi.c.
Referenced by ra8_mipi_dsi_deinit(), ra8_mipi_dsi_init(), ra8_mipi_dsi_ulps_enter(), and ra8_mipi_dsi_ulps_exit().
|
static |
Software latch tracking whether the driver currently owns the MIPI-DSI module-stop reference count.
Set true at the tail of ra8_mipi_dsi_init() once the MSTPC bit has been ungated, and cleared at the tail of ra8_mipi_dsi_deinit() once the bit has been gated. ra8_mipi_dsi_enter_stop() clears it (because it gives the MSTPC reference back) and ra8_mipi_dsi_exit_stop() re-sets it. The flag exists so that deinit() is idempotent: calling it on an already-de-initialized driver returns k_ra8_ok instead of letting ra8_mstp_disable() underflow its reference count and surface k_ra8_err_invalid_state. HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C", p 446 only describes the gate bit; the reference-count discipline is a software invariant maintained by libs/ra8_hal/src/ra8_mstp.c.
Definition at line 223 of file ra8_mipi_dsi.c.
| void* s_mipi_dsi_event_ctx |
Single definition of the shared IRQ callback context.
Opaque context handed back to the IRQ callback.
Declared extern (with the full contract) in ra8_mipi_dsi_internal.h. Lifetime is owned by the caller of ra8_mipi_dsi_attach_handler.
Single definition lives in ra8_mipi_dsi.c. Lifetime is owned by the caller of ra8_mipi_dsi_attach_handler.
Definition at line 121 of file ra8_mipi_dsi.c.
Referenced by internal_ra8_mipi_dsi_call_user(), ra8_mipi_dsi_attach_handler(), ra8_mipi_dsi_deinit(), and ra8_mipi_dsi_init().
| ra8_mipi_dsi_event_fn_t s_mipi_dsi_event_fn |
Single definition of the shared IRQ callback pointer.
Currently registered IRQ callback, or nullptr.
Declared extern (with the full contract) in ra8_mipi_dsi_internal.h and read from IRQ context in ra8_mipi_dsi_dispatch.c. Mutated only from the single-threaded init / deinit / attach-handler call sites.
Single definition lives in ra8_mipi_dsi.c. Mutated from the single-threaded init / deinit / attach-handler call sites; read from IRQ context inside ra8_mipi_dsi_dispatch.c.
Definition at line 106 of file ra8_mipi_dsi.c.
Referenced by internal_ra8_mipi_dsi_call_user(), ra8_mipi_dsi_attach_handler(), ra8_mipi_dsi_deinit(), and ra8_mipi_dsi_init().
| uint8_t* s_mipi_dsi_pending_rx_buffer |
Single definition of the shared pending receive buffer.
Buffer the caller passed to ra8_mipi_dsi_read_packet().
Declared extern (with the full contract) in ra8_mipi_dsi_internal.h. The receive ISR in ra8_mipi_dsi_dispatch.c copies long-packet payload bytes from RXPPD0..3R into this buffer once the response arrives, then clears it to avoid stale-pointer use.
Single definition lives in ra8_mipi_dsi.c. The receive ISR in ra8_mipi_dsi_dispatch.c copies long-packet payload bytes into this buffer once the response arrives and then clears it to avoid stale-pointer use.
Definition at line 180 of file ra8_mipi_dsi.c.
Referenced by ra8_mipi_dsi_deinit(), ra8_mipi_dsi_dispatch_receive(), ra8_mipi_dsi_init(), ra8_mipi_dsi_read_packet(), and ra8_mipi_dsi_send_command().
| uint16_t s_mipi_dsi_pending_rx_len |
Single definition of the shared pending receive capacity.
Capacity of s_mipi_dsi_pending_rx_buffer in bytes.
Declared extern (with the full contract) in ra8_mipi_dsi_internal.h. Cleared to zero once the response is consumed by the RX dispatch.
Single definition lives in ra8_mipi_dsi.c. Cleared to zero once the response is consumed by the RX dispatch.
Definition at line 195 of file ra8_mipi_dsi.c.
Referenced by ra8_mipi_dsi_deinit(), ra8_mipi_dsi_dispatch_receive(), ra8_mipi_dsi_init(), ra8_mipi_dsi_read_packet(), and ra8_mipi_dsi_send_command().
|
static |
Component tag used by the ra8_log_* family.
Static so the linker keeps it confined to this TU. Same convention as every other ra8_hal driver (see ra8_glcdc.c, ra8_doc.c).
Definition at line 90 of file ra8_mipi_dsi.c.