Skip to content

Commit 2f44752

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 93ea8e0 commit 2f44752

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

drivers/ra/README

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ Patch List:
7575
* 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.
7676
Add phy link speed to Ethernet controller driver instance control.
7777
Remove static definition of some internal function is ethernet driver to allow their usage in Zephyr side
78-
Add phy_lsi_address to Ethernet phy instance control to allow the control of phy address as input.
7978
Remove the phy target settings as they are not used.
8079
Impacted files:
8180
drivers/ra/fsp/src/r_ether/r_ether.c
@@ -84,7 +83,6 @@ Patch List:
8483
drivers/ra/fsp/src/r_ether_phy/targets/ICS1894/r_ether_phy_target_ics1894.c
8584
drivers/ra/fsp/src/r_ether_phy/targets/KSZ8041/r_ether_phy_target_ksz8041.c
8685
drivers/ra/fsp/src/r_ether_phy/targets/KSZ8091RNB/r_ether_phy_target_ksz8091rnb.c
87-
drivers/ra/fsp/inc/instances/r_ether_phy.h
8886
drivers/ra/fsp/inc/instances/r_ether.h
8987

9088
* Create new USB device support for Zephyr HAL (do not use current FSP USB stack)

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 & 8 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,14 @@ 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);
350349

351350
/* Software reset */
352351
ether_reset_mac(p_instance_ctrl->p_reg_edmac);
353352

354353
/* Setting the padding function */
355354
ether_configure_padding(p_instance_ctrl);
356355

356+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
357357
/* Software reset the PHY */
358358
phy_ret = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->open(
359359
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
@@ -369,11 +369,16 @@ fsp_err_t R_ETHER_Open (ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p
369369
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_cfg);
370370
}
371371
#endif
372+
#else
373+
phy_ret = FSP_SUCCESS;
374+
#endif
372375

373376
if (FSP_SUCCESS == phy_ret)
374377
{
378+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
375379
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->startAutoNegotiate(
376380
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
381+
#endif
377382

378383
/* Clear all ETHERC status BFR, PSRTO, LCHNG, MPD, ICD */
379384
p_reg_etherc->ECSR = ETHER_ETHERC_INTERRUPT_FACTOR_ALL;
@@ -437,8 +442,10 @@ fsp_err_t R_ETHER_Close (ether_ctrl_t * const p_ctrl)
437442
/* Disable Ethernet interrupt. */
438443
ether_disable_icu(p_instance_ctrl);
439444

445+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
440446
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->close(
441447
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
448+
#endif
442449

443450
p_reg_etherc->ECSIPR_b.LCHNGIP = 0;
444451
p_reg_edmac->EESIPR_b.ECIIP = 0;
@@ -1367,7 +1374,7 @@ static void ether_init_descriptors (ether_instance_ctrl_t * const p_instance_ctr
13671374
* ETHERC control block.
13681375
* Return Value : none
13691376
***********************************************************************************************************************/
1370-
static void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
1377+
void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
13711378
{
13721379
uint32_t i;
13731380
uint32_t buffer_num;
@@ -1586,7 +1593,7 @@ static void ether_pause_resolution (uint32_t const local_ability,
15861593
* USE_MAGIC_PACKET_DETECT (1) - Magic packet detection mode
15871594
* Return Value : none
15881595
***********************************************************************************************************************/
1589-
static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
1596+
void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
15901597
const uint8_t mac_addr[],
15911598
const uint8_t mode)
15921599
{
@@ -1642,7 +1649,7 @@ static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
16421649
* or result of Auto-negotiation is abnormal.
16431650
*
16441651
***********************************************************************************************************************/
1645-
static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
1652+
fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
16461653
{
16471654
fsp_err_t err;
16481655
R_ETHERC0_Type * p_reg_etherc;
@@ -1664,12 +1671,17 @@ static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, c
16641671
p_reg_etherc = (R_ETHERC0_Type *) p_instance_ctrl->p_reg_etherc;
16651672
p_reg_edmac = (R_ETHERC_EDMAC_Type *) p_instance_ctrl->p_reg_edmac;
16661673

1674+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
16671675
/* Set the link status */
16681676
link_result = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkPartnerAbilityGet(
16691677
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
16701678
&link_speed_duplex,
16711679
&local_pause_bits,
16721680
&partner_pause_bits);
1681+
#else
1682+
link_result = FSP_SUCCESS;
1683+
link_speed_duplex = p_instance_ctrl->link_speed_duplex;
1684+
#endif
16731685

16741686
if (FSP_SUCCESS == link_result)
16751687
{
@@ -1846,11 +1858,15 @@ static uint8_t ether_check_magic_packet_detection_bit (ether_instance_ctrl_t con
18461858
**********************************************************************************************************************/
18471859
static fsp_err_t ether_link_status_check (ether_instance_ctrl_t const * const p_instance_ctrl)
18481860
{
1849-
fsp_err_t err = FSP_SUCCESS;
1861+
fsp_err_t err;
18501862
fsp_err_t link_status;
18511863

1864+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
18521865
link_status = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkStatusGet(
18531866
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
1867+
#else
1868+
link_status = FSP_SUCCESS;
1869+
#endif
18541870

18551871
if (FSP_ERR_ETHER_PHY_ERROR_LINK == link_status)
18561872
{

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)