drivers: mdio: Initial support for renesas RA mdio driver
Add support for mdio driver for Renesas RA MCU series This support utilize the r_ether_phy driver in hal renesas to support mdio write and read function Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
This commit is contained in:
parent
f5285be7f1
commit
f9705969b7
6 changed files with 156 additions and 0 deletions
|
|
@ -16,3 +16,4 @@ zephyr_library_sources_ifdef(CONFIG_MDIO_ST_STM32_HAL mdio_stm32_hal.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_MDIO_INFINEON_XMC4XXX mdio_xmc4xxx.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MDIO_NXP_ENET_QOS mdio_nxp_enet_qos.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MDIO_DWCXGMAC mdio_dwcxgmac.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MDIO_RENESAS_RA mdio_renesas_ra.c)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ source "drivers/mdio/Kconfig.stm32_hal"
|
|||
source "drivers/mdio/Kconfig.xmc4xxx"
|
||||
source "drivers/mdio/Kconfig.nxp_enet_qos"
|
||||
source "drivers/mdio/Kconfig.dwcxgmac"
|
||||
source "drivers/mdio/Kconfig.renesas_ra"
|
||||
|
||||
config MDIO_INIT_PRIORITY
|
||||
int "Init priority"
|
||||
|
|
|
|||
11
drivers/mdio/Kconfig.renesas_ra
Normal file
11
drivers/mdio/Kconfig.renesas_ra
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Copyright (c) 2024 Renesas Electronics Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config MDIO_RENESAS_RA
|
||||
bool "RENESAS MDIO controller driver"
|
||||
default y
|
||||
depends on DT_HAS_RENESAS_RA_MDIO_ENABLED
|
||||
select PINCTRL
|
||||
select USE_RA_FSP_ETHER_PHY
|
||||
help
|
||||
Enable RENESAS MDIO support.
|
||||
123
drivers/mdio/mdio_renesas_ra.c
Normal file
123
drivers/mdio/mdio_renesas_ra.c
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Renesas Electronics Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
#include <zephyr/drivers/mdio.h>
|
||||
#include <zephyr/net/ethernet.h>
|
||||
#include <zephyr/net/mdio.h>
|
||||
#include "r_ether_phy.h"
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_REGISTER(renesas_ra_mdio, CONFIG_MDIO_LOG_LEVEL);
|
||||
|
||||
#define DT_DRV_COMPAT renesas_ra_mdio
|
||||
|
||||
struct renesas_ra_mdio_config {
|
||||
const struct pinctrl_dev_config *pincfg;
|
||||
uint8_t instance;
|
||||
};
|
||||
|
||||
struct renesas_ra_mdio_data {
|
||||
struct k_mutex rw_mutex;
|
||||
struct st_ether_phy_cfg ether_phy_cfg;
|
||||
struct st_ether_phy_instance_ctrl ether_phy_ctrl;
|
||||
};
|
||||
|
||||
static int renesas_ra_mdio_read(const struct device *dev, uint8_t prtad, uint8_t regad,
|
||||
uint16_t *data)
|
||||
{
|
||||
struct renesas_ra_mdio_data *dev_data = dev->data;
|
||||
uint32_t read;
|
||||
fsp_err_t err;
|
||||
|
||||
dev_data->ether_phy_ctrl.phy_lsi_address = prtad;
|
||||
|
||||
k_mutex_lock(&dev_data->rw_mutex, K_FOREVER);
|
||||
|
||||
err = R_ETHER_PHY_Read(&dev_data->ether_phy_ctrl, regad, &read);
|
||||
|
||||
k_mutex_unlock(&dev_data->rw_mutex);
|
||||
|
||||
if (err != FSP_SUCCESS) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
*data = read & UINT16_MAX;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int renesas_ra_mdio_write(const struct device *dev, uint8_t prtad, uint8_t regad,
|
||||
uint16_t data)
|
||||
{
|
||||
struct renesas_ra_mdio_data *dev_data = dev->data;
|
||||
fsp_err_t err;
|
||||
|
||||
dev_data->ether_phy_ctrl.phy_lsi_address = prtad;
|
||||
|
||||
k_mutex_lock(&dev_data->rw_mutex, K_FOREVER);
|
||||
|
||||
err = R_ETHER_PHY_Write(&dev_data->ether_phy_ctrl, regad, data);
|
||||
|
||||
k_mutex_unlock(&dev_data->rw_mutex);
|
||||
|
||||
if (err != FSP_SUCCESS) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int renesas_ra_mdio_initialize(const struct device *dev)
|
||||
{
|
||||
struct renesas_ra_mdio_data *data = dev->data;
|
||||
const struct renesas_ra_mdio_config *cfg = dev->config;
|
||||
int err;
|
||||
fsp_err_t fsp_err;
|
||||
|
||||
err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
fsp_err = R_ETHER_PHY_Open(&data->ether_phy_ctrl, &data->ether_phy_cfg);
|
||||
|
||||
if (fsp_err != FSP_SUCCESS) {
|
||||
LOG_ERR("Failed to init mdio driver - R_ETHER_PHY_Open fail");
|
||||
}
|
||||
|
||||
k_mutex_init(&data->rw_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DEVICE_API(mdio, renesas_ra_mdio_api) = {
|
||||
.read = renesas_ra_mdio_read,
|
||||
.write = renesas_ra_mdio_write,
|
||||
};
|
||||
|
||||
#define RENSAS_RA_MDIO_INSTANCE_DEFINE(node) \
|
||||
PINCTRL_DT_INST_DEFINE(node); \
|
||||
static struct renesas_ra_mdio_data renesas_ra_mdio##node##_data = { \
|
||||
.ether_phy_cfg = { \
|
||||
.channel = 0, \
|
||||
.phy_reset_wait_time = 0x00020000, \
|
||||
.mii_bit_access_wait_time = 8, \
|
||||
.phy_lsi_type = ETHER_PHY_LSI_TYPE_CUSTOM, \
|
||||
.flow_control = ETHER_PHY_FLOW_CONTROL_DISABLE, \
|
||||
}}; \
|
||||
static const struct renesas_ra_mdio_config renesas_ra_mdio##node##_cfg = { \
|
||||
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(node)}; \
|
||||
DEVICE_DT_INST_DEFINE(node, &renesas_ra_mdio_initialize, NULL, \
|
||||
&renesas_ra_mdio##node##_data, &renesas_ra_mdio##node##_cfg, \
|
||||
POST_KERNEL, CONFIG_MDIO_INIT_PRIORITY, &renesas_ra_mdio_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(RENSAS_RA_MDIO_INSTANCE_DEFINE)
|
||||
15
dts/bindings/mdio/renesas,ra-mdio.yaml
Normal file
15
dts/bindings/mdio/renesas,ra-mdio.yaml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2024 Renesas Electronics Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: Renesas RA External MDIO controller
|
||||
|
||||
compatible: "renesas,ra-mdio"
|
||||
|
||||
include: [mdio-controller.yaml, pinctrl-device.yaml]
|
||||
|
||||
properties:
|
||||
pinctrl-0:
|
||||
required: true
|
||||
|
||||
pinctrl-names:
|
||||
required: true
|
||||
|
|
@ -81,4 +81,9 @@ config USE_RA_FSP_CANFD
|
|||
help
|
||||
Enable RA FSP CANFD driver
|
||||
|
||||
config USE_RA_FSP_ETHER_PHY
|
||||
bool
|
||||
help
|
||||
Enable RA FSP Ethernet phy driver
|
||||
|
||||
endif # HAS_RENESAS_RA_FSP
|
||||
|
|
|
|||
Loading…
Reference in a new issue