ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_mipi_phy_ops.h File Reference

MIPI D-PHY driver – runtime operations prototypes. More...

#include <stdint.h>
#include "ra8_err.h"
#include "ra8_mipi_phy_regs.h"
#include "ra8_mipi_phy_types.h"
Include dependency graph for ra8_mipi_phy_ops.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ra8_err_t ra8_mipi_phy_set_lane_speed (const ra8_mipi_phy_pll_t *pll)
 Reprogram the PLL coefficients (DPHYPLFCR) at runtime.
ra8_err_t ra8_mipi_phy_switch_mode (ra8_mipi_phy_mode_t mode)
 Switch the PHY between DSI host and CSI device mode.
ra8_err_t ra8_mipi_phy_set_lane_count (ra8_mipi_phy_lane_count_t count)
 Configure the active lane count.
ra8_mipi_phy_lane_count_t ra8_mipi_phy_get_lane_count (void)
 Read back the lane count last configured.
ra8_err_t ra8_mipi_phy_set_lane_enable (ra8_mipi_phy_lane_id_t lane, bool enable)
 Enable or disable a single data lane.
bool ra8_mipi_phy_is_lane_enabled (ra8_mipi_phy_lane_id_t lane)
 Query whether the given lane is currently enabled.
ra8_err_t ra8_mipi_phy_set_clock_mode (ra8_mipi_phy_clk_mode_t mode)
 Set the HS clock-lane mode (continuous vs non-continuous).
ra8_mipi_phy_clk_mode_t ra8_mipi_phy_get_clock_mode (void)
 Query the HS clock-lane mode last configured.
ra8_err_t ra8_mipi_phy_set_eotp (ra8_mipi_phy_eotp_t eotp)
 Set the EoTP packet emission preference (DSI host only).
ra8_mipi_phy_eotp_t ra8_mipi_phy_get_eotp (void)
 Query the EoTP setting last configured.
ra8_err_t ra8_mipi_phy_set_pclka_freq (uint8_t mhz)
 Update DPHYREFCR.RFREQ at runtime.
ra8_err_t ra8_mipi_phy_set_escape_divisor (uint8_t escdiv)
 Update DPHYESCCR.ESCDIV at runtime.
ra8_err_t ra8_mipi_phy_select_timing (ra8_mipi_phy_mode_t mode, uint8_t pclka_mhz, uint16_t rate_mbps, ra8_mipi_phy_timing_t *out_timing)
 Look up an HUM Table 64.2 / 64.3 row and apply the timing.
ra8_err_t ra8_mipi_phy_validate_pll_band (const ra8_mipi_phy_pll_t *pll, uint8_t mosc_mhz)
 Validate a PLL coefficient block against HUM 64.2.2 p 3823-3824.
ra8_err_t ra8_mipi_phy_compute_pll_freq (const ra8_mipi_phy_pll_t *pll, uint8_t mosc_mhz, uint32_t *out_mhz)
 Compute approximate PLL output frequency for a coefficient block.
ra8_err_t ra8_mipi_phy_lookup_timing (ra8_mipi_phy_mode_t mode, uint8_t pclka_mhz, uint16_t rate_mbps, ra8_mipi_phy_timing_t *out_timing)
 Look up an HUM Table 64.2 / 64.3 row WITHOUT writing the regs.
ra8_err_t ra8_mipi_phy_get_status_decoded (ra8_mipi_phy_status_decoded_t *out)
 Read DPHYSFR and decode it into a ra8_mipi_phy_status_decoded_t.
ra8_mipi_phy_state_t ra8_mipi_phy_get_state (void)
 Read the cached lifecycle state.
ra8_mipi_phy_mode_t ra8_mipi_phy_get_active_mode (void)
 Read the most recently configured operating mode.
ra8_err_t ra8_mipi_phy_set_dual_mode (ra8_mipi_phy_dual_mode_t mode)
 Set the dual-mode arbitration policy.
ra8_mipi_phy_dual_mode_t ra8_mipi_phy_get_dual_mode (void)
 Read back the dual-mode arbitration policy last configured.
bool ra8_mipi_phy_dual_mode_can_acquire (ra8_mipi_phy_mode_t requestor)
 Test whether a (mode, policy) request is currently allowed.
ra8_err_t ra8_mipi_phy_set_pclka_freq_hz (uint32_t hz)
 Update DPHYREFCR.RFREQ from a PCLKA frequency in Hz.
ra8_err_t ra8_mipi_phy_compute_lane_rate_mbps (const ra8_mipi_phy_pll_t *pll, uint8_t mosc_mhz, uint32_t *out_mbps)
 Compute (mosc, pll) -> approximate per-lane line rate.

Detailed Description

MIPI D-PHY driver – runtime operations prototypes.

Tag
[Ring 3 / HAL] {World: NS}

Runtime operation entry points for the RA8D2 MIPI PHY block (HUM Ch 64, p 3822-3838): lane-speed re-tune, mode switching, lane and clock configuration, EoTP, PCLKA / escape-divisor updates, timing lookup, PLL math helpers, status decode, and dual-mode arbitration. The enums, structs, and callback typedef these prototypes reference live in ra8_mipi_phy_types.h, which this header includes. The lifecycle / status / interrupt / power prototypes live in ra8_mipi_phy_api.h. All three are re-exported by the thin umbrella ra8_mipi_phy.h.

Since
0.1.0

Definition in file ra8_mipi_phy_ops.h.

Function Documentation

◆ ra8_mipi_phy_compute_lane_rate_mbps()

ra8_err_t ra8_mipi_phy_compute_lane_rate_mbps ( const ra8_mipi_phy_pll_t * pll,
uint8_t mosc_mhz,
uint32_t * out_mbps )
nodiscard

Compute (mosc, pll) -> approximate per-lane line rate.

Helper for callers that want to verify a PLL coefficient set matches a target lane rate. Returns f_pll / 2 per HUM Ch 64.2.2 p 3824 ("Line rate per lane = PLL output / 2").

Parameters
[in]pllNon-NULL PLL coefficients.
[in]mosc_mhzMOSC frequency in MHz.
[out]out_mbpsReceives the per-lane line rate in Mbps.
Returns
ra8_err_t error code.
Return values
k_ra8_ok*out_mbps updated.
k_ra8_err_null_ptrEither pointer was NULL.
k_ra8_err_invalid_argmosc_mhz outside 8..48.
Precondition
pll and out_mbps are non-NULL.
mosc_mhz is between 8 and 48.
Postcondition
Hardware state is unchanged.
Note
Pure helper – safe from any context.
Since
0.1.0

◆ ra8_mipi_phy_compute_pll_freq()

ra8_err_t ra8_mipi_phy_compute_pll_freq ( const ra8_mipi_phy_pll_t * pll,
uint8_t mosc_mhz,
uint32_t * out_mhz )
nodiscard

Compute approximate PLL output frequency for a coefficient block.

Pure helper – evaluates the HUM Ch 64.2.2 p 3823 formula f = fMAIN * I * (NF + N) * P and returns the result in MHz. Hardware state is unchanged. Used by ra8_mipi_phy_validate_pll_band and by the ra8_mipi_phy_compute_pll_for_rate helper – exposed publicly so drivers that need to derive a line rate from a PLL snapshot can re-use the computation.

Parameters
[in]pllNon-NULL PLL coefficient block.
[in]mosc_mhzMOSC frequency, MHz (8..48).
[out]out_mhzReceives the computed output frequency in MHz.
Returns
ra8_err_t error code.
Return values
k_ra8_ok*out_mhz updated.
k_ra8_err_null_ptrpll or out_mhz was NULL.
k_ra8_err_invalid_argmosc_mhz outside 8..48.
Precondition
pll is non-NULL.
out_mhz is non-NULL.
Postcondition
*out_mhz reflects the formula result (not pinned to band).
Note
Pure function – safe from any context.
Since
0.1.0

◆ ra8_mipi_phy_dual_mode_can_acquire()

bool ra8_mipi_phy_dual_mode_can_acquire ( ra8_mipi_phy_mode_t requestor)

Test whether a (mode, policy) request is currently allowed.

Implements the policy table:

  • dual_off – accept any request.
  • dual_alternate – accept any request (caller switches modes).
  • dual_dsi_priority – accept DSI; reject CSI when mode != CSI.
  • dual_csi_priority – accept CSI; reject DSI when mode != DSI.
Parameters
[in]requestorMode the caller wants to enter.
Returns
true if the request is permitted, false if blocked.
Return values
truePolicy permits requestor to acquire the PHY.
falsePolicy blocks requestor (priority owner is active).
Precondition
Driver init is not required; the test is purely software policy.
requestor is a valid ra8_mipi_phy_mode_t value.
Postcondition
Hardware state is unchanged.
Cached dual-mode policy is unchanged.
Note
Thread safety: read-only over a software shadow.
Since
0.1.0

◆ ra8_mipi_phy_get_active_mode()

ra8_mipi_phy_mode_t ra8_mipi_phy_get_active_mode ( void )

Read the most recently configured operating mode.

Returns the cached DPHYMDC.MASTEREN choice – the bit is set during ra8_mipi_phy_init and cleared when ra8_mipi_phy_deinit runs.

Returns
Cached ra8_mipi_phy_mode_t. Defaults to k_ra8_mipi_phy_mode_csi_device (matches DPHYMDC reset value 0 – HUM Ch 64.2.14 p 3837).
Return values
k_ra8_mipi_phy_mode_dsi_hostDSI host – TX path.
k_ra8_mipi_phy_mode_csi_deviceCSI sink – RX path.
Precondition
– (no preconditions; safe before init).
Caller has access to driver state.
Postcondition
Hardware state is unchanged.
Cached active-mode value is unchanged.
Note
Thread safety: read-only.
Since
0.1.0

◆ ra8_mipi_phy_get_clock_mode()

ra8_mipi_phy_clk_mode_t ra8_mipi_phy_get_clock_mode ( void )

Query the HS clock-lane mode last configured.

Returns the cached clock-lane mode set by ra8_mipi_phy_set_clock_mode. Per HUM Ch 64.3 p 3837, the PHY does not store the choice itself – the DSI host gates HS-CLK based on this software shadow.

Returns
Active clock mode (defaults to non-continuous).
Return values
k_ra8_mipi_phy_clk_mode_continuousHS clock free-runs.
k_ra8_mipi_phy_clk_mode_non_continuousHS clock gated when idle.
Precondition
– (no preconditions; safe before init).
ra8_mipi_phy_set_clock_mode may or may not have been called.
Postcondition
Hardware state is unchanged.
Cached clock-mode value is unchanged.
Note
Thread safety: read-only.
Since
0.1.0

Definition at line 758 of file ra8_mipi_phy.c.

References s_clk_mode.

◆ ra8_mipi_phy_get_dual_mode()

ra8_mipi_phy_dual_mode_t ra8_mipi_phy_get_dual_mode ( void )

Read back the dual-mode arbitration policy last configured.

Returns the cached arbitration policy set by ra8_mipi_phy_set_dual_mode. Higher-level stacks consult this when deciding whether to switch the shared D-PHY between DSI and CSI.

Returns
Active dual-mode setting (defaults to k_ra8_mipi_phy_dual_off).
Return values
k_ra8_mipi_phy_dual_offNo arbitration – single owner.
k_ra8_mipi_phy_dual_alternateCooperative time-multiplexing.
k_ra8_mipi_phy_dual_dsi_priorityDSI wins contention.
k_ra8_mipi_phy_dual_csi_priorityCSI wins contention.
Precondition
– (no preconditions; safe before init).
Caller has access to driver state.
Postcondition
Hardware state is unchanged.
Cached dual-mode policy is unchanged.
Note
Thread safety: read-only.
Since
0.1.0

◆ ra8_mipi_phy_get_eotp()

ra8_mipi_phy_eotp_t ra8_mipi_phy_get_eotp ( void )

Query the EoTP setting last configured.

Returns the cached End-of-Transmission-Packet preference last set via ra8_mipi_phy_set_eotp. The DSI host honours this when emitting the optional EoTP at the end of HS bursts.

Returns
Active EoTP setting (defaults to disabled).
Return values
k_ra8_mipi_phy_eotp_disabledEoTP suppression – legacy peripherals.
k_ra8_mipi_phy_eotp_enabledEoTP appended – spec-compliant.
Precondition
– (no preconditions; safe before init).
ra8_mipi_phy_set_eotp may or may not have been called.
Postcondition
Hardware state is unchanged.
Cached EoTP value is unchanged.
Note
Thread safety: read-only.
Since
0.1.0

Definition at line 772 of file ra8_mipi_phy.c.

References s_eotp.

◆ ra8_mipi_phy_get_lane_count()

ra8_mipi_phy_lane_count_t ra8_mipi_phy_get_lane_count ( void )

Read back the lane count last configured.

Returns the cached lane-count value last written via ra8_mipi_phy_set_lane_count. The PHY itself has no lane-count register (HUM Ch 64.1 Table 64.1 p 3822); this is a software shadow consulted by ra8_mipi_phy_set_lane_enable.

Returns
Active lane count (defaults to k_ra8_mipi_phy_lane_count_2).
Return values
k_ra8_mipi_phy_lane_count_1Single-lane mode.
k_ra8_mipi_phy_lane_count_2Dual-lane (default).
Precondition
– (no preconditions; safe before init).
ra8_mipi_phy_set_lane_count may or may not have been called.
Postcondition
Hardware state is unchanged.
Cached lane-count value is unchanged.
Note
Thread safety: read-only.
Since
0.1.0

Definition at line 693 of file ra8_mipi_phy.c.

References s_lane_count.

◆ ra8_mipi_phy_get_state()

ra8_mipi_phy_state_t ra8_mipi_phy_get_state ( void )

Read the cached lifecycle state.

The state is updated by every public function that performs a register write. Useful for higher-level stacks that need to assert "PHY is in pll_run state before issuing a burst".

Returns
Cached ra8_mipi_phy_state_t – defaults to k_ra8_mipi_phy_state_off after reset / first init.
Return values
k_ra8_mipi_phy_state_offPHY powered down.
k_ra8_mipi_phy_state_ldo_readyLDO stabilised.
k_ra8_mipi_phy_state_pll_runPLL locked and running.
Precondition
– (no preconditions; safe before init).
Caller has access to driver state (no IRQ guard required).
Postcondition
Hardware state is unchanged.
Cached lifecycle state is unchanged.
Note
Thread safety: read-only.
Since
0.1.0

◆ ra8_mipi_phy_get_status_decoded()

ra8_err_t ra8_mipi_phy_get_status_decoded ( ra8_mipi_phy_status_decoded_t * out)
nodiscard

Read DPHYSFR and decode it into a ra8_mipi_phy_status_decoded_t.

Parameters
[out]outNon-NULL decoded snapshot.
Returns
ra8_err_t error code.
Return values
k_ra8_ok*out populated.
k_ra8_err_null_ptrout was NULL.
Precondition
out is non-NULL.
Postcondition
*out reflects the live DPHYSFR contents at call time.
Note
Read-only access – safe under simple races.
Since
0.1.0

◆ ra8_mipi_phy_is_lane_enabled()

bool ra8_mipi_phy_is_lane_enabled ( ra8_mipi_phy_lane_id_t lane)

Query whether the given lane is currently enabled.

Returns the cached enable bit for lane set by ra8_mipi_phy_set_lane_enable. The DSI / CSI host driver consults this when programming its own lane gate.

Parameters
[in]laneLane identifier (clk, d0, d1).
Returns
true if enabled (default for clk + d0 + d1), else false.
Return values
trueLane is software-enabled.
falseLane is software-disabled or out of range.
Precondition
– (no preconditions; safe before init).
lane is a valid ra8_mipi_phy_lane_id_t value.
Postcondition
Hardware state is unchanged.
Cached lane state is unchanged.
Note
Thread safety: read-only.
Since
0.1.0

Definition at line 730 of file ra8_mipi_phy.c.

References k_ra8_mipi_phy_lane_bit_clk, k_ra8_mipi_phy_lane_bit_d0, k_ra8_mipi_phy_lane_bit_d1, k_ra8_mipi_phy_lane_clk, k_ra8_mipi_phy_lane_d0, k_ra8_mipi_phy_lane_d1, and s_lane_enable_mask.

◆ ra8_mipi_phy_lookup_timing()

ra8_err_t ra8_mipi_phy_lookup_timing ( ra8_mipi_phy_mode_t mode,
uint8_t pclka_mhz,
uint16_t rate_mbps,
ra8_mipi_phy_timing_t * out_timing )
nodiscard

Look up an HUM Table 64.2 / 64.3 row WITHOUT writing the regs.

Same selection logic as ra8_mipi_phy_select_timing but stops short of touching DPHYTIM1..6 – useful for unit tests, dry runs, and callers that want to inspect a candidate timing block before committing.

Parameters
[in]modeActive mode.
[in]pclka_mhzPCLKA frequency, MHz.
[in]rate_mbpsPer-lane line rate, Mbps.
[out]out_timingReceives the matching timing row.
Returns
ra8_err_t error code.
Return values
k_ra8_okRow found, *out_timing filled.
k_ra8_err_null_ptrout_timing was NULL.
k_ra8_err_invalid_argrate_mbps outside 80..720 or mode outside the enum.
k_ra8_err_not_supportedPCLKA does not match any row.
Precondition
out_timing is non-NULL.
mode is one of the enumerator values.
Postcondition
Hardware state is unchanged.
Note
Pure lookup – thread-safe across the lookup table.
Since
0.1.0

◆ ra8_mipi_phy_select_timing()

ra8_err_t ra8_mipi_phy_select_timing ( ra8_mipi_phy_mode_t mode,
uint8_t pclka_mhz,
uint16_t rate_mbps,
ra8_mipi_phy_timing_t * out_timing )
nodiscard

Look up an HUM Table 64.2 / 64.3 row and apply the timing.

Tables 64.2 (DSI mode, p 3831-3834) and 64.3 (CSI mode, p 3835-3836) map (PCLKA, lane_rate_mbps) to a ready-made set of DPHYTIMx field values. This helper picks the closest row, fills in a ra8_mipi_phy_timing_t, and writes DPHYTIM1..6.

Parameters
[in]modeActive mode (DSI vs CSI uses different tables).
[in]pclka_mhzPCLKA frequency in MHz.
[in]rate_mbpsPer-lane line rate in Mbps.
[out]out_timingOptional non-NULL pointer to receive the applied timing block (skip with NULL).
Returns
ra8_err_t error code.
Return values
k_ra8_okTiming applied.
k_ra8_err_invalid_argrate_mbps outside 80..720 or mode outside the enum.
k_ra8_err_not_supportedPCLKA does not match any table row.
Precondition
Module-stop is cleared.
Postcondition
DPHYTIM1..6 hold the looked-up values.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 900 of file ra8_mipi_phy_timing.c.

References internal_mipi_phy_lookup_timing(), k_ra8_err_invalid_arg, k_ra8_err_not_supported, k_ra8_mipi_phy_line_rate_max_mbps, k_ra8_mipi_phy_line_rate_min_mbps, k_ra8_mipi_phy_mode_csi_device, k_ra8_mipi_phy_mode_dsi_host, k_ra8_ok, priv_mipi_phy_write_timing(), s_csi_table, and s_dsi_table.

◆ ra8_mipi_phy_set_clock_mode()

ra8_err_t ra8_mipi_phy_set_clock_mode ( ra8_mipi_phy_clk_mode_t mode)
nodiscard

Set the HS clock-lane mode (continuous vs non-continuous).

Parameters
[in]modeClock-lane mode.
Returns
ra8_err_t error code.
Return values
k_ra8_okStored.
k_ra8_err_invalid_argmode outside the enum.
Precondition
– (no preconditions).
Postcondition
ra8_mipi_phy_get_clock_mode returns mode on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 749 of file ra8_mipi_phy.c.

References k_ra8_err_invalid_arg, k_ra8_mipi_phy_clk_continuous, k_ra8_mipi_phy_clk_noncontinuous, k_ra8_ok, and s_clk_mode.

◆ ra8_mipi_phy_set_dual_mode()

ra8_err_t ra8_mipi_phy_set_dual_mode ( ra8_mipi_phy_dual_mode_t mode)
nodiscard

Set the dual-mode arbitration policy.

RA8D2 silicon physically multiplexes one D-PHY between DSI and CSI (HUM Ch 64.2.14 p 3837 – DPHYMDC.MASTEREN is a single bit). This helper records the caller's preferred policy so the higher-level stack can decide arbitration without re-reading the spec.

Parameters
[in]modeNew arbitration policy.
Returns
ra8_err_t error code.
Return values
k_ra8_okStored.
k_ra8_err_invalid_argmode outside the enum.
Precondition
– (no preconditions).
Postcondition
ra8_mipi_phy_get_dual_mode returns mode on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

◆ ra8_mipi_phy_set_eotp()

ra8_err_t ra8_mipi_phy_set_eotp ( ra8_mipi_phy_eotp_t eotp)
nodiscard

Set the EoTP packet emission preference (DSI host only).

Parameters
[in]eotpDesired EoTP setting.
Returns
ra8_err_t error code.
Return values
k_ra8_okStored.
k_ra8_err_invalid_argeotp outside the enum.
Precondition
– (no preconditions).
Postcondition
ra8_mipi_phy_get_eotp returns eotp on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 763 of file ra8_mipi_phy.c.

References k_ra8_err_invalid_arg, k_ra8_mipi_phy_eotp_disabled, k_ra8_mipi_phy_eotp_enabled, k_ra8_ok, and s_eotp.

◆ ra8_mipi_phy_set_escape_divisor()

ra8_err_t ra8_mipi_phy_set_escape_divisor ( uint8_t escdiv)
nodiscard

Update DPHYESCCR.ESCDIV at runtime.

HUM Ch 64.2.4 p 3825: ESCDIV[4:0] must be written while DPHYPLOCR.PLLSTP = 1. This helper enforces that by stopping the PLL, writing the divisor, and restarting the PLL.

Parameters
[in]escdivNew escape divisor (0..31).
Returns
ra8_err_t error code.
Return values
k_ra8_okDivisor updated and PLL re-locked.
k_ra8_err_invalid_argescdiv > 31.
k_ra8_err_hw_timeoutPLL did not re-lock within budget.
Precondition
ra8_mipi_phy_init ran successfully (host mode).
Postcondition
DPHYESCCR.ESCDIV equals escdiv on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 791 of file ra8_mipi_phy.c.

References internal_mipi_phy_wait_set(), k_ra8_err_invalid_arg, k_ra8_mipi_phy_esccr_escdiv_mask, k_ra8_mipi_phy_escdiv_max, k_ra8_mipi_phy_off_esccr, k_ra8_mipi_phy_off_plocr, k_ra8_mipi_phy_off_sfr, k_ra8_mipi_phy_plocr_pllstp, k_ra8_mipi_phy_sfr_pllsf, and ra8_mipi_phy_reg32().

◆ ra8_mipi_phy_set_lane_count()

ra8_err_t ra8_mipi_phy_set_lane_count ( ra8_mipi_phy_lane_count_t count)
nodiscard

Configure the active lane count.

The PHY has no lane-count register of its own (the DSI / CSI host drivers gate individual lanes), so this helper only validates the argument against the silicon limit and stores it for later inspection through ra8_mipi_phy_get_lane_count. The value is also used by ra8_mipi_phy_set_lane_enable to bound checks.

Parameters
[in]countDesired lane count.
Returns
ra8_err_t error code.
Return values
k_ra8_okStored.
k_ra8_err_invalid_argcount outside 1..4 enum.
k_ra8_err_not_supportedcount is 3 or 4 (silicon max 2, HUM Ch 64.1 Table 64.1 p 3822).
Precondition
– (no preconditions).
Postcondition
ra8_mipi_phy_get_lane_count returns count on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 673 of file ra8_mipi_phy.c.

References k_ra8_err_invalid_arg, k_ra8_err_not_supported, k_ra8_mipi_phy_lane_bit_d1, k_ra8_mipi_phy_lane_count_1, k_ra8_mipi_phy_lane_count_2, k_ra8_mipi_phy_lane_count_3, k_ra8_mipi_phy_lane_count_4, k_ra8_ok, s_lane_count, and s_lane_enable_mask.

◆ ra8_mipi_phy_set_lane_enable()

ra8_err_t ra8_mipi_phy_set_lane_enable ( ra8_mipi_phy_lane_id_t lane,
bool enable )
nodiscard

Enable or disable a single data lane.

Mirrors the per-lane gate that the DSI / CSI host drivers expose. The PHY itself has no per-lane register, so this helper only validates the index and stashes the request – the higher-level driver consults ra8_mipi_phy_is_lane_enabled when configuring its own lane gate.

Parameters
[in]laneLane identifier.
[in]enabletrue to enable, false to disable.
Returns
ra8_err_t error code.
Return values
k_ra8_okStored.
k_ra8_err_invalid_arglane outside the enum or beyond the configured lane_count.
k_ra8_err_not_supportedLane >= 2 (silicon max).
Precondition
– (no preconditions).
Postcondition
ra8_mipi_phy_is_lane_enabled returns enable on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 698 of file ra8_mipi_phy.c.

References k_ra8_err_invalid_arg, k_ra8_err_not_supported, k_ra8_mipi_phy_lane_bit_clk, k_ra8_mipi_phy_lane_bit_d0, k_ra8_mipi_phy_lane_bit_d1, k_ra8_mipi_phy_lane_clk, k_ra8_mipi_phy_lane_count_1, k_ra8_mipi_phy_lane_d0, k_ra8_mipi_phy_lane_d1, k_ra8_mipi_phy_lane_d2, k_ra8_mipi_phy_lane_d3, k_ra8_ok, s_lane_count, and s_lane_enable_mask.

◆ ra8_mipi_phy_set_lane_speed()

ra8_err_t ra8_mipi_phy_set_lane_speed ( const ra8_mipi_phy_pll_t * pll)
nodiscard

Reprogram the PLL coefficients (DPHYPLFCR) at runtime.

HUM Ch 64.2.2 p 3824: DPHYPLFCR may only be written while DPHYPLOCR.PLLSTP = 1. This helper sets PLLSTP, writes DPHYPLFCR from pll, clears PLLSTP, and spins until DPHYSFR.PLLSF re-asserts. The D-PHY enable bit (DPHYOCR.DPHYEN) is left as it was on entry; callers transmitting active video should disable the lane outputs first.

Parameters
[in]pllNon-NULL PLL coefficient block.
Returns
ra8_err_t error code.
Return values
k_ra8_okPLL re-locked.
k_ra8_err_null_ptrpll was NULL.
k_ra8_err_invalid_argpll->nmul_int outside 40..375 (HUM 64.2.2 p 3823) or band mismatch.
k_ra8_err_hw_timeoutPLL did not relock within the spin budget.
Precondition
pll is non-NULL.
ra8_mipi_phy_init has already run successfully.
Postcondition
On success, the PLL output frequency reflects the new coefficients and DPHYSFR.PLLSF reads 1.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 639 of file ra8_mipi_phy.c.

References internal_mipi_phy_pack_plfcr(), internal_mipi_phy_validate_pll(), internal_mipi_phy_wait_set(), k_ra8_mipi_phy_off_plfcr, k_ra8_mipi_phy_off_plocr, k_ra8_mipi_phy_off_sfr, k_ra8_mipi_phy_plocr_pllstp, k_ra8_mipi_phy_sfr_pllsf, RA8_CHECK_NULL_PTR, ra8_mipi_phy_reg32(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_mipi_phy_set_pclka_freq()

ra8_err_t ra8_mipi_phy_set_pclka_freq ( uint8_t mhz)
nodiscard

Update DPHYREFCR.RFREQ at runtime.

Parameters
[in]mhzNew PCLKA frequency, MHz (40..125).
Returns
ra8_err_t error code.
Return values
k_ra8_okRFREQ updated.
k_ra8_err_invalid_argmhz outside 40..125 (HUM Ch 64.2.1 p 3822).
Precondition
Module-stop is cleared.
Postcondition
DPHYREFCR.RFREQ equals mhz on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 777 of file ra8_mipi_phy.c.

References k_ra8_err_invalid_arg, k_ra8_mipi_phy_off_refcr, k_ra8_mipi_phy_pclka_max_mhz, k_ra8_mipi_phy_pclka_min_mhz, k_ra8_mipi_phy_refcr_rfreq_bias, k_ra8_mipi_phy_refcr_rfreq_mask, k_ra8_ok, and ra8_mipi_phy_reg32().

◆ ra8_mipi_phy_set_pclka_freq_hz()

ra8_err_t ra8_mipi_phy_set_pclka_freq_hz ( uint32_t hz)
nodiscard

Update DPHYREFCR.RFREQ from a PCLKA frequency in Hz.

Convenience wrapper around ra8_mipi_phy_set_pclka_freq that accepts the rounded MHz value of an arbitrary Hz input – mirrors the FSP code path which calls R_FSP_SystemClockHzGet(PCLKA) and divides by 1_000_000.

Parameters
[in]hzPCLKA frequency in Hz (40_000_000.. 125_000_000).
Returns
ra8_err_t error code (see ra8_mipi_phy_set_pclka_freq).
Precondition
hz is at least 1_000_000 (so the floor doesn't underflow).
Postcondition
DPHYREFCR.RFREQ holds floor(hz / 1_000_000) on success.
Note
Thread safety: not thread-safe.
Since
0.1.0

◆ ra8_mipi_phy_switch_mode()

ra8_err_t ra8_mipi_phy_switch_mode ( ra8_mipi_phy_mode_t mode)
nodiscard

Switch the PHY between DSI host and CSI device mode.

HUM Ch 64.2.14 p 3836: DPHYMDC.MASTEREN selects host vs device. Switching modes requires the D-PHY to be disabled first; this helper clears DPHYEN, rewrites DPHYMDC, and lets the caller re-enable the D-PHY (typically via ra8_mipi_phy_pll_start for host or directly setting DPHYEN for device).

Parameters
[in]modeTarget mode.
Returns
ra8_err_t error code.
Return values
k_ra8_okMode switched.
k_ra8_err_invalid_argmode outside the enum.
Precondition
– (DPHYEN may be 0 or 1 – the helper clears it as needed).
Postcondition
DPHYMDC.MASTEREN reflects mode.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 660 of file ra8_mipi_phy.c.

References k_ra8_err_invalid_arg, k_ra8_mipi_phy_mdc_hosten, k_ra8_mipi_phy_mode_csi_device, k_ra8_mipi_phy_mode_dsi_host, k_ra8_mipi_phy_off_mdc, k_ra8_mipi_phy_off_ocr, k_ra8_ok, and ra8_mipi_phy_reg32().

◆ ra8_mipi_phy_validate_pll_band()

ra8_err_t ra8_mipi_phy_validate_pll_band ( const ra8_mipi_phy_pll_t * pll,
uint8_t mosc_mhz )
nodiscard

Validate a PLL coefficient block against HUM 64.2.2 p 3823-3824.

Checks the integer N range (40..375), then verifies the resulting PLL output frequency lies within the band selected by PMUL[1:0] (P=1: 960..1440, P=1/2: 480..1440, P=1/4: 240..750, P=1/8: 120..375). The MOSC frequency is taken from the parameter mosc_mhz so the check works without consulting the live CGC state.

Parameters
[in]pllNon-NULL PLL coefficient block.
[in]mosc_mhzMOSC frequency, MHz (8..48).
Returns
ra8_err_t error code.
Return values
k_ra8_okCoefficients are within spec.
k_ra8_err_null_ptrpll was NULL.
k_ra8_err_invalid_argOut-of-spec coefficient.
Precondition
pll is non-NULL.
mosc_mhz is between 8 and 48.
Postcondition
Hardware state is unchanged.
Note
Pure function – safe to call from any context.
Since
0.1.0

Definition at line 808 of file ra8_mipi_phy.c.

References internal_mipi_phy_validate_pll(), k_ra8_err_invalid_arg, k_ra8_mipi_phy_mosc_max_mhz, k_ra8_mipi_phy_mosc_min_mhz, k_ra8_mipi_phy_pll_p1_max, k_ra8_mipi_phy_pll_p1_min, k_ra8_mipi_phy_pll_p2_max, k_ra8_mipi_phy_pll_p2_min, k_ra8_mipi_phy_pll_p4_max, k_ra8_mipi_phy_pll_p4_min, k_ra8_mipi_phy_pll_p8_max, k_ra8_mipi_phy_pll_p8_min, k_ra8_mipi_phy_pmul_1, k_ra8_mipi_phy_pmul_2, k_ra8_mipi_phy_pmul_4, k_ra8_mipi_phy_pmul_8, k_ra8_ok, ra8_mipi_phy_pll_t::pmul, priv_mipi_phy_compute_freq(), RA8_CHECK_NULL_PTR, RA8_RETURN_ON_ERROR, and s_tag.