Skip to content

Commit b6bf846

Browse files
duynguyenxaKhiemNguyenT
authored andcommitted
hal: ra: Add source code for supporting custom eth phy driver
This update is for Ethernet driver to better fit into Zephyr standard. Add in ETHER_CFG_USE_CUSTOM_PHY_DRIVER to Ethernet controller driver to skip the phy control and allow the use of Zephyr phy driver. Add phy link speed to Ethernet controller driver instance control. Add phy_lsi_address to Ethernet phy instance control to allow the control of phy address as input Signed-off-by: Duy Nguyen <[email protected]>
1 parent dcd3e85 commit b6bf846

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

drivers/ra/fsp/inc/instances/r_ether.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ typedef struct st_ether_instance_ctrl
144144
ether_link_change_t link_change; ///< status of link change
145145
ether_magic_packet_t magic_packet; ///< status of magic packet detection
146146
ether_link_establish_status_t link_establish_status; ///< Current Link status
147+
uint32_t link_speed_duplex; ///< Current Link speed and duplex status
147148

148149
/* Pointer to callback and optional working memory */
149150
void (* p_callback)(ether_callback_args_t *);

drivers/ra/fsp/src/r_ether/r_ether.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static void ether_enable_icu(ether_instance_ctrl_t * const p_instance_ctrl)
190190
static void ether_disable_icu(ether_instance_ctrl_t * const p_instance_ctrl);
191191
static void ether_reset_mac(R_ETHERC_EDMAC_Type * const p_reg);
192192
static void ether_init_descriptors(ether_instance_ctrl_t * const p_instance_ctrl);
193-
static void ether_init_buffers(ether_instance_ctrl_t * const p_instance_ctrl);
193+
void ether_init_buffers(ether_instance_ctrl_t * const p_instance_ctrl);
194194
static fsp_err_t ether_buffer_get(ether_instance_ctrl_t * const p_instance_ctrl,
195195
void ** const p_buffer,
196196
uint32_t * p_buffer_size);
@@ -199,10 +199,10 @@ static void ether_pause_resolution(uint32_t const local_ability,
199199
uint32_t const partner_ability,
200200
uint32_t * ptx_pause,
201201
uint32_t * prx_pause);
202-
static void ether_configure_mac(ether_instance_ctrl_t * const p_instance_ctrl,
202+
void ether_configure_mac(ether_instance_ctrl_t * const p_instance_ctrl,
203203
const uint8_t mac_addr[],
204204
const uint8_t mode);
205-
static fsp_err_t ether_do_link(ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode);
205+
fsp_err_t ether_do_link(ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode);
206206
static fsp_err_t ether_link_status_check(ether_instance_ctrl_t const * const p_instance_ctrl);
207207
static uint8_t ether_check_magic_packet_detection_bit(ether_instance_ctrl_t const * const p_instance_ctrl);
208208
static void ether_configure_padding(ether_instance_ctrl_t * const p_instance_ctrl);
@@ -346,14 +346,13 @@ fsp_err_t R_ETHER_Open (ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p
346346
p_instance_ctrl->p_context = p_cfg->p_context;
347347
p_instance_ctrl->p_callback_memory = NULL;
348348

349-
R_BSP_MODULE_START(FSP_IP_ETHER, p_instance_ctrl->p_ether_cfg->channel);
350-
351349
/* Software reset */
352350
ether_reset_mac(p_instance_ctrl->p_reg_edmac);
353351

354352
/* Setting the padding function */
355353
ether_configure_padding(p_instance_ctrl);
356354

355+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
357356
/* Software reset the PHY */
358357
phy_ret = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->open(
359358
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
@@ -369,11 +368,16 @@ fsp_err_t R_ETHER_Open (ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p
369368
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_cfg);
370369
}
371370
#endif
371+
#else
372+
phy_ret = FSP_SUCCESS;
373+
#endif
372374

373375
if (FSP_SUCCESS == phy_ret)
374376
{
377+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
375378
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->startAutoNegotiate(
376379
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
380+
#endif
377381

378382
/* Clear all ETHERC status BFR, PSRTO, LCHNG, MPD, ICD */
379383
p_reg_etherc->ECSR = ETHER_ETHERC_INTERRUPT_FACTOR_ALL;
@@ -437,8 +441,10 @@ fsp_err_t R_ETHER_Close (ether_ctrl_t * const p_ctrl)
437441
/* Disable Ethernet interrupt. */
438442
ether_disable_icu(p_instance_ctrl);
439443

444+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
440445
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->close(
441446
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
447+
#endif
442448

443449
p_reg_etherc->ECSIPR_b.LCHNGIP = 0;
444450
p_reg_edmac->EESIPR_b.ECIIP = 0;
@@ -1367,7 +1373,7 @@ static void ether_init_descriptors (ether_instance_ctrl_t * const p_instance_ctr
13671373
* ETHERC control block.
13681374
* Return Value : none
13691375
***********************************************************************************************************************/
1370-
static void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
1376+
void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
13711377
{
13721378
uint32_t i;
13731379
uint32_t buffer_num;
@@ -1586,7 +1592,7 @@ static void ether_pause_resolution (uint32_t const local_ability,
15861592
* USE_MAGIC_PACKET_DETECT (1) - Magic packet detection mode
15871593
* Return Value : none
15881594
***********************************************************************************************************************/
1589-
static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
1595+
void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
15901596
const uint8_t mac_addr[],
15911597
const uint8_t mode)
15921598
{
@@ -1642,7 +1648,7 @@ static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
16421648
* or result of Auto-negotiation is abnormal.
16431649
*
16441650
***********************************************************************************************************************/
1645-
static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
1651+
fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
16461652
{
16471653
fsp_err_t err;
16481654
R_ETHERC0_Type * p_reg_etherc;
@@ -1664,12 +1670,17 @@ static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, c
16641670
p_reg_etherc = (R_ETHERC0_Type *) p_instance_ctrl->p_reg_etherc;
16651671
p_reg_edmac = (R_ETHERC_EDMAC_Type *) p_instance_ctrl->p_reg_edmac;
16661672

1673+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
16671674
/* Set the link status */
16681675
link_result = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkPartnerAbilityGet(
16691676
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
16701677
&link_speed_duplex,
16711678
&local_pause_bits,
16721679
&partner_pause_bits);
1680+
#else
1681+
link_result = FSP_SUCCESS;
1682+
link_speed_duplex = p_instance_ctrl->link_speed_duplex;
1683+
#endif
16731684

16741685
if (FSP_SUCCESS == link_result)
16751686
{
@@ -1846,11 +1857,15 @@ static uint8_t ether_check_magic_packet_detection_bit (ether_instance_ctrl_t con
18461857
**********************************************************************************************************************/
18471858
static fsp_err_t ether_link_status_check (ether_instance_ctrl_t const * const p_instance_ctrl)
18481859
{
1849-
fsp_err_t err = FSP_SUCCESS;
1860+
fsp_err_t err;
18501861
fsp_err_t link_status;
18511862

1863+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
18521864
link_status = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkStatusGet(
18531865
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
1866+
#else
1867+
link_status = FSP_SUCCESS;
1868+
#endif
18541869

18551870
if (FSP_ERR_ETHER_PHY_ERROR_LINK == link_status)
18561871
{

drivers/ra/fsp/src/r_ether_phy/r_ether_phy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ fsp_err_t R_ETHER_PHY_Open (ether_phy_ctrl_t * const p_ctrl, ether_phy_cfg_t con
218218
/* Initialize configuration of ethernet phy module. */
219219
p_instance_ctrl->p_ether_phy_cfg = p_cfg;
220220

221-
/* Configure pins for MII or RMII. Set PHYMODE0 if MII is selected. */
222-
R_PMISC->PFENET = (uint8_t) ((ETHER_PHY_MII_TYPE_MII == p_cfg->mii_type) << R_PMISC_PFENET_PHYMODE0_Pos);
221+
R_BSP_MODULE_START(FSP_IP_ETHER, p_instance_ctrl->p_ether_phy_cfg->channel);
223222

224223
#if ETHER_PHY_CFG_INIT_PHY_LSI_AUTOMATIC
225224
uint32_t reg = 0;

0 commit comments

Comments
 (0)