|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Reduced-MAC (RMAC) PHY driver – off-chip PHY for the GMAC-FPI. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_rmac_phy_io_t |
| Pluggable MDIO bus. More... | |
| struct | ra8_rmac_phy_link_t |
| Resolved PHY link status snapshot. More... | |
| struct | ra8_rmac_phy_cfg_t |
| Configuration descriptor. More... | |
Enumerations | |
| enum | ra8_rmac_phy_lsi_t : uint8_t { k_ra8_rmac_phy_lsi_default = 0U , k_ra8_rmac_phy_lsi_ksz8091rnb = 1U , k_ra8_rmac_phy_lsi_ksz8041 = 2U , k_ra8_rmac_phy_lsi_dp83620 = 3U , k_ra8_rmac_phy_lsi_ics1894 = 4U , k_ra8_rmac_phy_lsi_gpy111 = 5U , k_ra8_rmac_phy_lsi_vsc8541 = 6U , k_ra8_rmac_phy_lsi_custom = 7U , k_ra8_rmac_phy_lsi_count = 8U } |
| Supported PHY-LSI identifiers. More... | |
| enum | ra8_rmac_phy_speed_t : uint8_t { k_ra8_rmac_phy_speed_no_link = 0U , k_ra8_rmac_phy_speed_10h = 1U , k_ra8_rmac_phy_speed_10f = 2U , k_ra8_rmac_phy_speed_100h = 3U , k_ra8_rmac_phy_speed_100f = 4U , k_ra8_rmac_phy_speed_1000h = 5U , k_ra8_rmac_phy_speed_1000f = 6U } |
| Negotiated link speed. More... | |
| enum | ra8_rmac_phy_addr_limit_t : uint8_t { k_ra8_rmac_phy_addr_max = 31U , k_ra8_rmac_phy_reg_max = 31U } |
| MDIO address constraints. More... | |
Functions | |
| ra8_err_t | ra8_rmac_phy_open (const ra8_rmac_phy_cfg_t *cfg) |
| Open the PHY and run a soft-reset sequence. | |
| ra8_err_t | ra8_rmac_phy_close (void) |
| Close the driver. | |
| ra8_err_t | ra8_rmac_phy_mdio_read (uint8_t reg_addr, uint16_t *out_data) |
| Read a Clause-22 register on the off-chip PHY. | |
| ra8_err_t | ra8_rmac_phy_mdio_write (uint8_t reg_addr, uint16_t data) |
| Write a Clause-22 register on the off-chip PHY. | |
| ra8_err_t | ra8_rmac_phy_auto_negotiate_start (void) |
| Restart auto-negotiation on the PHY. | |
| ra8_err_t | ra8_rmac_phy_link_status_get (ra8_rmac_phy_link_t *out) |
| Read BMSR + partner ability and resolve speed/duplex. | |
| ra8_err_t | ra8_rmac_phy_lsi_get (ra8_rmac_phy_lsi_t *out) |
| Get the currently-bound PHY-LSI identifier. | |
Reduced-MAC (RMAC) PHY driver – off-chip PHY for the GMAC-FPI.
Mirrors the FSP r_rmac_phy API shape. The RMAC peripheral sits inside the RA8D2 (HUM Ch 33) and talks to an off-chip PHY over MII / RMII / GMII / RGMII. This driver is the per-PHY companion to ra8_rmac.c and handles:
Reference: FSP r_rmac_phy driver shape, IEEE 802.3 Clause 22 / Clause 28A (auto-neg), IEEE 802.3-2018 Annex 28B.
Definition in file ra8_rmac_phy.h.
| enum ra8_rmac_phy_addr_limit_t : uint8_t |
MDIO address constraints.
| Enumerator | |
|---|---|
| k_ra8_rmac_phy_addr_max | RA8 rmac PHY address maximum. |
| k_ra8_rmac_phy_reg_max | RA8 rmac PHY register maximum. |
Definition at line 72 of file ra8_rmac_phy.h.
| enum ra8_rmac_phy_lsi_t : uint8_t |
Supported PHY-LSI identifiers.
Definition at line 42 of file ra8_rmac_phy.h.
| enum ra8_rmac_phy_speed_t : uint8_t |
Negotiated link speed.
Definition at line 58 of file ra8_rmac_phy.h.
|
nodiscard |
Restart auto-negotiation on the PHY.
| k_ra8_ok | AN restarted. |
| k_ra8_err_not_initialized | Not opened. |
Restart auto-negotiation on the PHY.
{ANE | ANR}.
Sets the AN-enable + AN-restart bits in the IEEE 802.3 Clause-22 BMCR (register 0). Useful after the link partner changes or after the local advertisement masks were updated.
| k_ra8_ok | Restart command issued. |
| k_ra8_err_not_initialized | ra8_rmac_phy_open not called. |
Definition at line 411 of file ra8_rmac_phy.c.
References k_ra8_err_not_initialized, k_ra8_rmac_phy_bmcr_an_enable, k_ra8_rmac_phy_bmcr_an_restart, k_ra8_rmac_phy_reg_control, and s_state.
|
nodiscard |
Close the driver.
| k_ra8_ok | Closed. |
| k_ra8_err_invalid_state | Not opened. |
Close the driver.
Marks the driver as closed so subsequent IO calls return k_ra8_err_not_initialized. The PHY itself is left in its current state (the caller may issue another reset via ra8_rmac_phy_open later).
| k_ra8_ok | Driver state cleared. |
| k_ra8_err_invalid_state | Driver was not open. |
Definition at line 307 of file ra8_rmac_phy.c.
References k_ra8_err_invalid_state, k_ra8_ok, and s_state.
|
nodiscard |
Read BMSR + partner ability and resolve speed/duplex.
| [out] | out | Receives the snapshot. Must not be nullptr. |
| k_ra8_ok | Snapshot copied. |
| k_ra8_err_null_ptr | out NULL. |
| k_ra8_err_not_initialized | Not opened. |
Read BMSR + partner ability and resolve speed/duplex.
Reads BMSR (IEEE 802.3 register 1), then – if AN is complete and the link is up – consults the gigabit controller/peripheral status (MSR, register 10) and the partner ability (LPA, register 5) to map the advertised speeds to ra8_rmac_phy_speed_t.
| [out] | out | Receives the decoded link snapshot. |
| k_ra8_ok | *out populated. |
| k_ra8_err_null_ptr | out was NULL. |
| k_ra8_err_not_initialized | Driver not open. |
Definition at line 500 of file ra8_rmac_phy.c.
References ra8_rmac_phy_link_t::auto_neg_done, ra8_rmac_phy_link_t::bmsr, internal_resolve_speed(), k_ra8_err_not_initialized, k_ra8_ok, k_ra8_rmac_phy_bmsr_an_complete, k_ra8_rmac_phy_bmsr_link_up, k_ra8_rmac_phy_reg_status, k_ra8_rmac_phy_speed_no_link, ra8_rmac_phy_link_t::link_up, ra8_rmac_phy_link_t::partner_ability, RA8_CHECK_NULL_PTR, s_state, s_tag, and ra8_rmac_phy_link_t::speed.
|
nodiscard |
Get the currently-bound PHY-LSI identifier.
| [out] | out | Receives the LSI id. Must not be nullptr. |
| k_ra8_ok | Returned. |
| k_ra8_err_null_ptr | out NULL. |
| k_ra8_err_not_initialized | Not opened. |
Get the currently-bound PHY-LSI identifier.
Echoes back the cached ra8_rmac_phy_lsi_t so higher-level stacks can branch on the on-board PHY model without re-querying MDIO.
| [out] | out | Receives the cached LSI tag. |
| k_ra8_ok | *out populated. |
| k_ra8_err_null_ptr | out was NULL. |
| k_ra8_err_not_initialized | Driver not open. |
Definition at line 548 of file ra8_rmac_phy.c.
References k_ra8_err_not_initialized, k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
|
nodiscard |
Read a Clause-22 register on the off-chip PHY.
| [in] | reg_addr | Register index (0..31). |
| [out] | out_data | Receives the 16-bit register value. |
| k_ra8_ok | Read completed. |
| k_ra8_err_null_ptr | out_data NULL. |
| k_ra8_err_invalid_arg | reg_addr > 31. |
| k_ra8_err_not_initialized | Not opened. |
Read a Clause-22 register on the off-chip PHY.
Forwards the read to the injected io.read callback so the caller controls the actual MDIO transport. reg_addr must be in 0..31 (Clause-22 5-bit register space).
| [in] | reg_addr | Clause-22 register index 0..31. |
| [out] | out_data | Receives the 16-bit register value. |
| k_ra8_ok | Read completed. |
| k_ra8_err_null_ptr | out_data was NULL. |
| k_ra8_err_not_initialized | ra8_rmac_phy_open not called. |
| k_ra8_err_invalid_arg | reg_addr > 31. |
Definition at line 342 of file ra8_rmac_phy.c.
References k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_rmac_phy_reg_max, RA8_CHECK_NULL_PTR, s_state, and s_tag.
|
nodiscard |
Write a Clause-22 register on the off-chip PHY.
| [in] | reg_addr | Register index (0..31). |
| [in] | data | 16-bit value. |
| k_ra8_ok | Write completed. |
| k_ra8_err_invalid_arg | reg_addr > 31. |
| k_ra8_err_not_initialized | Not opened. |
Write a Clause-22 register on the off-chip PHY.
Forwards the write to the injected io.write callback. The PHY may treat the write as set-and-forget or as a self-clearing strobe depending on the register (e.g. BMCR.RESET).
| [in] | reg_addr | Clause-22 register index 0..31. |
| [in] | data | Value to write. |
| k_ra8_ok | Write completed. |
| k_ra8_err_not_initialized | ra8_rmac_phy_open not called. |
| k_ra8_err_invalid_arg | reg_addr > 31. |
Definition at line 379 of file ra8_rmac_phy.c.
References k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_rmac_phy_reg_max, and s_state.
|
nodiscard |
Open the PHY and run a soft-reset sequence.
Mirrors R_RMAC_PHY_Open. Issues BMCR.RESET, polls until self-clear, then writes the local advertisement register and (if gbit_advertise != 0) the 1000BASE-T control register so the next auto-neg round picks them up.
| [in] | cfg | Configuration. Must not be nullptr. |
| k_ra8_ok | PHY initialized. |
| k_ra8_err_null_ptr | cfg or required IO callback NULL. |
| k_ra8_err_invalid_arg | phy_address > 31 or lsi_type invalid. |
| k_ra8_err_exists | Already opened. |
| k_ra8_err_hw_timeout | BMCR.RESET never cleared. |
Open the PHY and run a soft-reset sequence.
Validates the caller-supplied configuration, captures the MDIO IO seam (read/write function pointers) into module-private state, issues a soft reset over MDIO and polls BMCR.RESET to clear, then programs the advertised abilities into ANAR (and 1000BASE-T control where the LSI supports gigabit). Subsequent ra8_rmac_phy_* calls operate against the cached state; only one open instance is permitted at a time.
Algorithm:
| [in] | cfg | PHY configuration: IO seam, MDIO address (0..31), LSI family, advertised abilities, and reset poll budget. Must not be nullptr; cfg->io.read and cfg->io.write must be non-null. |
| k_ra8_ok | PHY reset and advertise programmed. |
| k_ra8_err_invalid_arg | cfg/io pointers null, phy_address out of range, or unknown lsi_type. |
| k_ra8_err_exists | Driver already opened; close first. |
| k_ra8_err_io | MDIO write to BMCR/ANAR failed. |
| k_ra8_err_timeout | BMCR.RESET did not clear within budget. |
Definition at line 251 of file ra8_rmac_phy.c.
References ra8_rmac_phy_cfg_t::gbit_advertise, internal_open_validate(), internal_program_advertise(), internal_reset_and_wait(), ra8_rmac_phy_cfg_t::io, k_ra8_err_exists, k_ra8_ok, k_ra8_rmac_phy_reset_poll_max, ra8_rmac_phy_cfg_t::local_advertise, ra8_rmac_phy_cfg_t::lsi_type, ra8_rmac_phy_cfg_t::phy_address, ra8_log_info_val, ra8_rmac_phy_cfg_t::reset_poll_max, s_state, and s_tag.