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

MIPI D-PHY driver – HUM timing tables and table-driven setup. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_err.h"
#include "ra8_mipi_phy.h"
#include "ra8_mipi_phy_internal.h"
#include "ra8_mipi_phy_regs.h"
Include dependency graph for ra8_mipi_phy_timing.c:

Go to the source code of this file.

Data Structures

struct  mipi_phy_table_row_t
 One row of HUM Tables 64.2 / 64.3 with the rate ceiling. More...

Enumerations

enum  mipi_pll_frac_t : uint16_t {
  k_mipi_pll_percent_scale = 100U ,
  k_mipi_nf_x100_33 = 33U ,
  k_mipi_nf_x100_66 = 66U ,
  k_mipi_nf_x100_50 = 50U
}
 PLL fixed-point (hundredths) scale and NF fractional table. More...
enum  ra8_mipi_phy_table_szlim_t : uint8_t {
  k_ra8_mipi_phy_table_pclka_125 = 125U ,
  k_ra8_mipi_phy_table_pclka_120 = 120U ,
  k_ra8_mipi_phy_table_pclka_100 = 100U ,
  k_ra8_mipi_phy_table_pclka_80 = 80U ,
  k_ra8_mipi_phy_table_pclka_75 = 75U ,
  k_ra8_mipi_phy_table_pclka_50 = 50U ,
  k_ra8_mipi_phy_table_pclka_40 = 40U
}
 Static lookup-table cardinalities. More...

Functions

static const ra8_mipi_phy_timing_tinternal_mipi_phy_lookup_timing (const mipi_phy_table_row_t *tbl, uint32_t n, uint8_t pclka, uint16_t rate_mbps, uint8_t mode_flag)
 Lookup helper – linear scan picks the first row whose rate_max is >= the requested rate within a matching PCLKA bucket.
uint32_t priv_mipi_phy_compute_freq (const ra8_mipi_phy_pll_t *pll, uint8_t mosc_mhz)
 Compute the PLL output frequency for a (mosc, pll) tuple.
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 *const out_timing)
 Look up an HUM Table 64.2 / 64.3 row and apply the timing.

Variables

static const mipi_phy_table_row_t s_dsi_table []
 HUM Table 64.2 D-PHY timing setting DSI mode (p 3831-3834).
static const mipi_phy_table_row_t s_csi_table []
 HUM Table 64.3 D-PHY timing setting CSI mode (p 3835-3836).

Detailed Description

MIPI D-PHY driver – HUM timing tables and table-driven setup.

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

This translation unit holds the bulky portion of the MIPI D-PHY driver that ra8_mipi_phy.c delegates to so that neither file exceeds the scripts/checks/check_file_size.py cap. It owns:

  • The flattened representations of HUM Table 64.2 (D-PHY timing setting DSI mode, p 3831-3834) and HUM Table 64.3 (D-PHY timing setting CSI mode, p 3835-3836) as static lookup tables.
  • The linear-scan lookup walker that picks the correct row for a requested (mode, pclka, rate) tuple.
  • ra8_mipi_phy_select_timing, the public table-driven entry point that selects a row and programs DPHYTIM1..6.
  • priv_mipi_phy_compute_freq, the HUM 64.2.2 PLL-frequency arithmetic helper consumed by ra8_mipi_phy_validate_pll_band in ra8_mipi_phy.c.

The register-write path used by ra8_mipi_phy_select_timing lives in ra8_mipi_phy.c (priv_mipi_phy_write_timing) and is reached through ra8_mipi_phy_internal.h.

Since
0.1.0

Definition in file ra8_mipi_phy_timing.c.

Enumeration Type Documentation

◆ mipi_pll_frac_t

enum mipi_pll_frac_t : uint16_t

PLL fixed-point (hundredths) scale and NF fractional table.

Enumerator
k_mipi_pll_percent_scale 

Hundredths fixed-point scale.

k_mipi_nf_x100_33 

NF = 0.33 (x100).

k_mipi_nf_x100_66 

NF = 0.66 (x100).

k_mipi_nf_x100_50 

NF = 0.50 (x100).

Definition at line 42 of file ra8_mipi_phy_timing.c.

◆ ra8_mipi_phy_table_szlim_t

Static lookup-table cardinalities.

Enumerator
k_ra8_mipi_phy_table_pclka_125 

PCLKA 125 MHz bucket.

k_ra8_mipi_phy_table_pclka_120 

PCLKA 120 MHz bucket.

k_ra8_mipi_phy_table_pclka_100 

PCLKA 100 MHz bucket.

k_ra8_mipi_phy_table_pclka_80 

PCLKA 80 MHz bucket.

k_ra8_mipi_phy_table_pclka_75 

PCLKA 75 MHz bucket.

k_ra8_mipi_phy_table_pclka_50 

PCLKA 50 MHz bucket.

k_ra8_mipi_phy_table_pclka_40 

PCLKA 40 MHz bucket.

Definition at line 79 of file ra8_mipi_phy_timing.c.

Function Documentation

◆ internal_mipi_phy_lookup_timing()

const ra8_mipi_phy_timing_t * internal_mipi_phy_lookup_timing ( const mipi_phy_table_row_t * tbl,
uint32_t n,
uint8_t pclka,
uint16_t rate_mbps,
uint8_t mode_flag )
static

Lookup helper – linear scan picks the first row whose rate_max is >= the requested rate within a matching PCLKA bucket.

Definition at line 865 of file ra8_mipi_phy_timing.c.

References mipi_phy_table_row_t::t.

Referenced by ra8_mipi_phy_select_timing().

◆ priv_mipi_phy_compute_freq()

uint32_t priv_mipi_phy_compute_freq ( const ra8_mipi_phy_pll_t * pll,
uint8_t mosc_mhz )

Compute the PLL output frequency for a (mosc, pll) tuple.

Defined in ra8_mipi_phy_timing.c and shared with ra8_mipi_phy_validate_pll_band in ra8_mipi_phy.c. Implements the HUM Ch 64.2.2 p 3823 relation f = fMAIN * I * (NF + N) * P using hundredths fixed-point arithmetic.

Parameters
[in]pllPLL coefficient block (IDIV / NFMUL / PMUL / NMUL).
[in]mosc_mhzMain-oscillator frequency in MHz.
Returns
PLL output frequency in MHz, or 0 if the divisor product is 0.
Return values
0The composed divisor product was zero.
otherComputed PLL output frequency in MHz.
Precondition
pll is a valid, non-NULL ra8_mipi_phy_pll_t.
mosc_mhz is a non-zero main-oscillator frequency.
Postcondition
No register or shared state is modified by this helper.
The return value is a pure function of the two arguments.
Note
Internal helper. Not thread-safe; caller provides synchronisation.
Since
0.1.0

Definition at line 880 of file ra8_mipi_phy_timing.c.

References ra8_mipi_phy_pll_t::idiv, k_mipi_nf_x100_33, k_mipi_nf_x100_50, k_mipi_nf_x100_66, k_mipi_pll_percent_scale, ra8_mipi_phy_pll_t::nfmul, ra8_mipi_phy_pll_t::nmul_int, and ra8_mipi_phy_pll_t::pmul.

Referenced by ra8_mipi_phy_validate_pll_band().

◆ 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.

Variable Documentation

◆ s_csi_table

const mipi_phy_table_row_t s_csi_table[]
static

HUM Table 64.3 D-PHY timing setting CSI mode (p 3835-3836).

CSI rows only constrain TINIT, TCLKMISS, TCLKSETT, THSSETT, TCLKPREP, THSPREP – the high-speed lane fields are not used in device mode (the host side drives them). The struct fields not listed in the table are left zero-filled.

Definition at line 734 of file ra8_mipi_phy_timing.c.

Referenced by ra8_mipi_phy_select_timing().

◆ s_dsi_table

const mipi_phy_table_row_t s_dsi_table[]
static

HUM Table 64.2 D-PHY timing setting DSI mode (p 3831-3834).

Rows are ordered by (PCLKA descending, rate ascending). Lookup picks the row with matching PCLKA whose rate_max is the smallest value >= the requested rate.

Definition at line 98 of file ra8_mipi_phy_timing.c.

Referenced by ra8_mipi_phy_select_timing().