Skip to content

Commit f77a850

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 62ac0c6 commit f77a850

File tree

12 files changed

+51
-434
lines changed

12 files changed

+51
-434
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ if(CONFIG_USE_RA_FSP_SDHI)
8181
)
8282
endif()
8383

84+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_ETHER_PHY
85+
fsp/src/r_ether_phy/r_ether_phy.c)
86+
8487
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_ETHER
8588
fsp/src/r_ether/r_ether.c)
86-
87-
if (CONFIG_USE_RA_FSP_ETHER)
88-
file(GLOB ether_phy_srcs
89-
"fsp/src/r_ether_phy/r_ether_phy.c"
90-
"fsp/src/r_ether_phy/targets/*/*.c")
91-
zephyr_sources(${ether_phy_srcs})
92-
endif()

drivers/ra/README

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,18 @@ Patch List:
6262
* Remove the static definition in SDHI
6363
Impacted files:
6464
drivers/ra/fsp/src/r_sdhi/r_sdhi.c
65+
66+
* 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.
67+
Add phy link speed to Ethernet controller driver instance control.
68+
Remove static definition of some internal function is ethernet driver to allow their usage in Zephyr side
69+
Add phy_lsi_address to Ethernet phy instance control to allow the control of phy address as input.
70+
Remove the phy target settings as they are not used.
71+
Impacted files:
72+
drivers/ra/fsp/src/r_ether/r_ether.c
73+
drivers/ra/fsp/src/r_ether_phy/r_ether_phy.c
74+
drivers/ra/fsp/src/r_ether_phy/targets/DP83620/r_ether_phy_target_dp83620.c
75+
drivers/ra/fsp/src/r_ether_phy/targets/ICS1894/r_ether_phy_target_ics1894.c
76+
drivers/ra/fsp/src/r_ether_phy/targets/KSZ8041/r_ether_phy_target_ksz8041.c
77+
drivers/ra/fsp/src/r_ether_phy/targets/KSZ8091RNB/r_ether_phy_target_ksz8091rnb.c
78+
drivers/ra/fsp/inc/instances/r_ether_phy.h
79+
drivers/ra/fsp/inc/instances/r_ether.h

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ typedef struct st_ether_instance_ctrl
105105
ether_link_change_t link_change; ///< status of link change
106106
ether_magic_packet_t magic_packet; ///< status of magic packet detection
107107
ether_link_establish_status_t link_establish_status; ///< Current Link status
108+
uint32_t link_speed_duplex; ///< Current Link speed and duplex status
108109

109110
/* Pointer to callback and optional working memory */
110111
void (* p_callback)(ether_callback_args_t *);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef enum e_ether_phy_interface_status
4242
typedef struct st_ether_phy_instance_ctrl
4343
{
4444
uint32_t open; ///< Used to determine if the channel is configured
45+
uint8_t phy_lsi_address; ///< Address of PHY-LSI
4546

4647
/* Configuration of Ethernet PHY-LSI module. */
4748
ether_phy_cfg_t const * p_ether_phy_cfg; ///< Pointer to initial configurations.

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static void ether_enable_icu(ether_instance_ctrl_t * const p_instance_ctrl)
161161
static void ether_disable_icu(ether_instance_ctrl_t * const p_instance_ctrl);
162162
static void ether_reset_mac(R_ETHERC_EDMAC_Type * const p_reg);
163163
static void ether_init_descriptors(ether_instance_ctrl_t * const p_instance_ctrl);
164-
static void ether_init_buffers(ether_instance_ctrl_t * const p_instance_ctrl);
164+
void ether_init_buffers(ether_instance_ctrl_t * const p_instance_ctrl);
165165
static fsp_err_t ether_buffer_get(ether_instance_ctrl_t * const p_instance_ctrl,
166166
void ** const p_buffer,
167167
uint32_t * p_buffer_size);
@@ -170,10 +170,10 @@ static void ether_pause_resolution(uint32_t const local_ability,
170170
uint32_t const partner_ability,
171171
uint32_t * ptx_pause,
172172
uint32_t * prx_pause);
173-
static void ether_configure_mac(ether_instance_ctrl_t * const p_instance_ctrl,
173+
void ether_configure_mac(ether_instance_ctrl_t * const p_instance_ctrl,
174174
const uint8_t mac_addr[],
175175
const uint8_t mode);
176-
static fsp_err_t ether_do_link(ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode);
176+
fsp_err_t ether_do_link(ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode);
177177
static fsp_err_t ether_link_status_check(ether_instance_ctrl_t const * const p_instance_ctrl);
178178
static uint8_t ether_check_magic_packet_detection_bit(ether_instance_ctrl_t const * const p_instance_ctrl);
179179
static void ether_configure_padding(ether_instance_ctrl_t * const p_instance_ctrl);
@@ -307,14 +307,14 @@ fsp_err_t R_ETHER_Open (ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p
307307
p_instance_ctrl->p_context = p_cfg->p_context;
308308
p_instance_ctrl->p_callback_memory = NULL;
309309

310-
R_BSP_MODULE_START(FSP_IP_ETHER, p_instance_ctrl->p_ether_cfg->channel);
311310

312311
/* Software reset */
313312
ether_reset_mac(p_instance_ctrl->p_reg_edmac);
314313

315314
/* Setting the padding function */
316315
ether_configure_padding(p_instance_ctrl);
317316

317+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
318318
/* Software reset the PHY */
319319
phy_ret = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->open(
320320
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
@@ -330,11 +330,16 @@ fsp_err_t R_ETHER_Open (ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p
330330
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_cfg);
331331
}
332332
#endif
333+
#else
334+
phy_ret = FSP_SUCCESS;
335+
#endif
333336

334337
if (FSP_SUCCESS == phy_ret)
335338
{
339+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
336340
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->startAutoNegotiate(
337341
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
342+
#endif
338343

339344
/* Clear all ETHERC status BFR, PSRTO, LCHNG, MPD, ICD */
340345
p_reg_etherc->ECSR = ETHER_ETHERC_INTERRUPT_FACTOR_ALL;
@@ -398,8 +403,10 @@ fsp_err_t R_ETHER_Close (ether_ctrl_t * const p_ctrl)
398403
/* Disable Ethernet interrupt. */
399404
ether_disable_icu(p_instance_ctrl);
400405

406+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
401407
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->close(
402408
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
409+
#endif
403410

404411
p_reg_etherc->ECSIPR_b.LCHNGIP = 0;
405412
p_reg_edmac->EESIPR_b.ECIIP = 0;
@@ -1328,7 +1335,7 @@ static void ether_init_descriptors (ether_instance_ctrl_t * const p_instance_ctr
13281335
* ETHERC control block.
13291336
* Return Value : none
13301337
***********************************************************************************************************************/
1331-
static void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
1338+
void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
13321339
{
13331340
uint32_t i;
13341341
uint32_t buffer_num;
@@ -1547,7 +1554,7 @@ static void ether_pause_resolution (uint32_t const local_ability,
15471554
* USE_MAGIC_PACKET_DETECT (1) - Magic packet detection mode
15481555
* Return Value : none
15491556
***********************************************************************************************************************/
1550-
static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
1557+
void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
15511558
const uint8_t mac_addr[],
15521559
const uint8_t mode)
15531560
{
@@ -1603,7 +1610,7 @@ static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
16031610
* or result of Auto-negotiation is abnormal.
16041611
*
16051612
***********************************************************************************************************************/
1606-
static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
1613+
fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
16071614
{
16081615
fsp_err_t err;
16091616
R_ETHERC0_Type * p_reg_etherc;
@@ -1625,12 +1632,17 @@ static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, c
16251632
p_reg_etherc = (R_ETHERC0_Type *) p_instance_ctrl->p_reg_etherc;
16261633
p_reg_edmac = (R_ETHERC_EDMAC_Type *) p_instance_ctrl->p_reg_edmac;
16271634

1635+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
16281636
/* Set the link status */
16291637
link_result = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkPartnerAbilityGet(
16301638
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
16311639
&link_speed_duplex,
16321640
&local_pause_bits,
16331641
&partner_pause_bits);
1642+
#else
1643+
link_result = FSP_SUCCESS;
1644+
link_speed_duplex = p_instance_ctrl->link_speed_duplex;
1645+
#endif
16341646

16351647
if (FSP_SUCCESS == link_result)
16361648
{
@@ -1807,11 +1819,15 @@ static uint8_t ether_check_magic_packet_detection_bit (ether_instance_ctrl_t con
18071819
**********************************************************************************************************************/
18081820
static fsp_err_t ether_link_status_check (ether_instance_ctrl_t const * const p_instance_ctrl)
18091821
{
1810-
fsp_err_t err = FSP_SUCCESS;
1822+
fsp_err_t err;
18111823
fsp_err_t link_status;
18121824

1825+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
18131826
link_status = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkStatusGet(
18141827
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
1828+
#else
1829+
link_status = FSP_SUCCESS;
1830+
#endif
18151831

18161832
if (FSP_ERR_ETHER_PHY_ERROR_LINK == link_status)
18171833
{

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ fsp_err_t R_ETHER_PHY_Open (ether_phy_ctrl_t * const p_ctrl, ether_phy_cfg_t con
213213
/* Initialize configuration of ethernet phy module. */
214214
p_instance_ctrl->p_ether_phy_cfg = p_cfg;
215215

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

219218
#if ETHER_PHY_CFG_INIT_PHY_LSI_AUTOMATIC
220219
uint32_t reg = 0;
@@ -670,7 +669,7 @@ static void ether_phy_reg_set (ether_phy_instance_ctrl_t * p_instance_ctrl, uint
670669
data |= (ETHER_PHY_MII_WRITE << 12); /* OP code(WT) */
671670
}
672671

673-
data |= (uint32_t) (p_instance_ctrl->p_ether_phy_cfg->phy_lsi_address << 7); /* PHY Address */
672+
data |= (uint32_t) (p_instance_ctrl->phy_lsi_address << 7); /* PHY Address */
674673

675674
data |= (reg_addr << 2); /* Reg Address */
676675

drivers/ra/fsp/src/r_ether_phy/targets/DP83620/r_ether_phy_target_dp83620.c

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)