Skip to content

Commit 2d91793

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 1858d20 commit 2d91793

File tree

8 files changed

+28
-411
lines changed

8 files changed

+28
-411
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/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
@@ -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);
@@ -350,14 +350,14 @@ fsp_err_t R_ETHER_Open (ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p
350350
p_instance_ctrl->p_context = p_cfg->p_context;
351351
p_instance_ctrl->p_callback_memory = NULL;
352352

353-
R_BSP_MODULE_START(FSP_IP_ETHER, p_instance_ctrl->p_ether_cfg->channel);
354353

355354
/* Software reset */
356355
ether_reset_mac(p_instance_ctrl->p_reg_edmac);
357356

358357
/* Setting the padding function */
359358
ether_configure_padding(p_instance_ctrl);
360359

360+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
361361
/* Software reset the PHY */
362362
phy_ret = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->open(
363363
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
@@ -373,11 +373,16 @@ fsp_err_t R_ETHER_Open (ether_ctrl_t * const p_ctrl, ether_cfg_t const * const p
373373
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_cfg);
374374
}
375375
#endif
376+
#else
377+
phy_ret = FSP_SUCCESS;
378+
#endif
376379

377380
if (FSP_SUCCESS == phy_ret)
378381
{
382+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
379383
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->startAutoNegotiate(
380384
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
385+
#endif
381386

382387
/* Clear all ETHERC status BFR, PSRTO, LCHNG, MPD, ICD */
383388
p_reg_etherc->ECSR = ETHER_ETHERC_INTERRUPT_FACTOR_ALL;
@@ -441,8 +446,10 @@ fsp_err_t R_ETHER_Close (ether_ctrl_t * const p_ctrl)
441446
/* Disable Ethernet interrupt. */
442447
ether_disable_icu(p_instance_ctrl);
443448

449+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
444450
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->close(
445451
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
452+
#endif
446453

447454
p_reg_etherc->ECSIPR_b.LCHNGIP = 0;
448455
p_reg_edmac->EESIPR_b.ECIIP = 0;
@@ -1371,7 +1378,7 @@ static void ether_init_descriptors (ether_instance_ctrl_t * const p_instance_ctr
13711378
* ETHERC control block.
13721379
* Return Value : none
13731380
***********************************************************************************************************************/
1374-
static void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
1381+
void ether_init_buffers (ether_instance_ctrl_t * const p_instance_ctrl)
13751382
{
13761383
uint32_t i;
13771384
uint32_t buffer_num;
@@ -1590,7 +1597,7 @@ static void ether_pause_resolution (uint32_t const local_ability,
15901597
* USE_MAGIC_PACKET_DETECT (1) - Magic packet detection mode
15911598
* Return Value : none
15921599
***********************************************************************************************************************/
1593-
static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
1600+
void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
15941601
const uint8_t mac_addr[],
15951602
const uint8_t mode)
15961603
{
@@ -1646,7 +1653,7 @@ static void ether_configure_mac (ether_instance_ctrl_t * const p_instance_ctrl,
16461653
* or result of Auto-negotiation is abnormal.
16471654
*
16481655
***********************************************************************************************************************/
1649-
static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
1656+
fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, const uint8_t mode)
16501657
{
16511658
fsp_err_t err;
16521659
R_ETHERC0_Type * p_reg_etherc;
@@ -1668,12 +1675,17 @@ static fsp_err_t ether_do_link (ether_instance_ctrl_t * const p_instance_ctrl, c
16681675
p_reg_etherc = (R_ETHERC0_Type *) p_instance_ctrl->p_reg_etherc;
16691676
p_reg_edmac = (R_ETHERC_EDMAC_Type *) p_instance_ctrl->p_reg_edmac;
16701677

1678+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
16711679
/* Set the link status */
16721680
link_result = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkPartnerAbilityGet(
16731681
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl,
16741682
&link_speed_duplex,
16751683
&local_pause_bits,
16761684
&partner_pause_bits);
1685+
#else
1686+
link_result = FSP_SUCCESS;
1687+
link_speed_duplex = p_instance_ctrl->link_speed_duplex;
1688+
#endif
16771689

16781690
if (FSP_SUCCESS == link_result)
16791691
{
@@ -1850,11 +1862,15 @@ static uint8_t ether_check_magic_packet_detection_bit (ether_instance_ctrl_t con
18501862
**********************************************************************************************************************/
18511863
static fsp_err_t ether_link_status_check (ether_instance_ctrl_t const * const p_instance_ctrl)
18521864
{
1853-
fsp_err_t err = FSP_SUCCESS;
1865+
fsp_err_t err;
18541866
fsp_err_t link_status;
18551867

1868+
#if !ETHER_CFG_USE_CUSTOM_PHY_DRIVER
18561869
link_status = p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_api->linkStatusGet(
18571870
p_instance_ctrl->p_ether_cfg->p_ether_phy_instance->p_ctrl);
1871+
#else
1872+
link_status = FSP_SUCCESS;
1873+
#endif
18581874

18591875
if (FSP_ERR_ETHER_PHY_ERROR_LINK == link_status)
18601876
{

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.

drivers/ra/fsp/src/r_ether_phy/targets/ICS1894/r_ether_phy_target_ics1894.c

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

0 commit comments

Comments
 (0)