Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing stm32 MDIO driver #71012

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions boards/st/nucleo_h563zi/nucleo_h563zi.dts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@

&mac {
status = "okay";
pinctrl-0 = <&eth_mdc_pc1
&eth_rxd0_pc4
pinctrl-0 = <&eth_rxd0_pc4
&eth_rxd1_pc5
&eth_ref_clk_pa1
&eth_mdio_pa2
&eth_crs_dv_pa7
&eth_tx_en_pg11
&eth_txd0_pg13
&eth_txd1_pb15>;
pinctrl-names = "default";
};

&mdio {
status = "okay";
pinctrl-0 = <&eth_mdio_pa2 &eth_mdc_pc1>;
pinctrl-names = "default";

ethernet-phy@0 {
compatible = "ethernet-phy";
reg = <0x00>;
status = "okay";
};
};
14 changes: 12 additions & 2 deletions boards/st/nucleo_h723zg/nucleo_h723zg.dts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@
&mac {
status = "okay";
pinctrl-0 = <&eth_ref_clk_pa1
&eth_mdio_pa2
&eth_crs_dv_pa7
&eth_mdc_pc1
&eth_rxd0_pc4
&eth_rxd1_pc5
&eth_tx_en_pg11
Expand All @@ -171,6 +169,18 @@
pinctrl-names = "default";
};

&mdio {
status = "okay";
pinctrl-0 = <&eth_mdio_pa2 &eth_mdc_pc1>;
pinctrl-names = "default";

phy: ethernet-phy@0 {
compatible = "ethernet-phy";
reg = <0>;
status = "okay";
};
};

zephyr_udc0: &usbotg_hs {
pinctrl-0 = <&usb_otg_hs_dm_pa11 &usb_otg_hs_dp_pa12>;
pinctrl-names = "default";
Expand Down
16 changes: 13 additions & 3 deletions boards/st/nucleo_h743zi/nucleo_h743zi.dts
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,28 @@ zephyr_udc0: &usbotg_fs {
*/
&mac {
status = "okay";
pinctrl-0 = <&eth_mdc_pc1
&eth_rxd0_pc4
pinctrl-0 = <&eth_rxd0_pc4
&eth_rxd1_pc5
&eth_ref_clk_pa1
&eth_mdio_pa2
&eth_crs_dv_pa7
&eth_tx_en_pg11
&eth_txd0_pg13
&eth_txd1_pb13>;
pinctrl-names = "default";
};

&mdio {
status = "okay";
pinctrl-0 = <&eth_mdio_pa2 &eth_mdc_pc1>;
pinctrl-names = "default";

ethernet-phy@0 {
compatible = "ethernet-phy";
reg = <0x00>;
status = "okay";
};
};

&spi1 {
status = "okay";
pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pb5>;
Expand Down
14 changes: 12 additions & 2 deletions boards/st/nucleo_h745zi_q/nucleo_h745zi_q_stm32h745xx_m7.dts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@
&mac {
status = "okay";
pinctrl-0 = <&eth_ref_clk_pa1
&eth_mdio_pa2
&eth_crs_dv_pa7
&eth_mdc_pc1
&eth_rxd0_pc4
&eth_rxd1_pc5
&eth_tx_en_pg11
Expand All @@ -118,6 +116,18 @@
pinctrl-names = "default";
};

&mdio {
status = "okay";
pinctrl-0 = <&eth_mdio_pa2 &eth_mdc_pc1>;
pinctrl-names = "default";

ethernet-phy@0 {
compatible = "ethernet-phy";
reg = <0x00>;
status = "okay";
};
};

&rng {
status = "okay";
};
Expand Down
16 changes: 13 additions & 3 deletions boards/st/nucleo_h753zi/nucleo_h753zi.dts
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,28 @@ zephyr_udc0: &usbotg_fs {
*/
&mac {
status = "okay";
pinctrl-0 = <&eth_mdc_pc1
&eth_rxd0_pc4
pinctrl-0 = <&eth_rxd0_pc4
&eth_rxd1_pc5
&eth_ref_clk_pa1
&eth_mdio_pa2
&eth_crs_dv_pa7
&eth_tx_en_pg11
&eth_txd0_pg13
&eth_txd1_pb13>;
pinctrl-names = "default";
};

&mdio {
status = "okay";
pinctrl-0 = <&eth_mdio_pa2 &eth_mdc_pc1>;
pinctrl-names = "default";

ethernet-phy@0 {
compatible = "ethernet-phy";
reg = <0x00>;
status = "okay";
};
};

&spi1 {
status = "okay";
pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pb5>;
Expand Down
16 changes: 13 additions & 3 deletions boards/st/stm32h573i_dk/stm32h573i_dk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,28 @@

&mac {
status = "okay";
pinctrl-0 = <&eth_mdc_pc1
&eth_rxd0_pc4
pinctrl-0 = <&eth_rxd0_pc4
&eth_rxd1_pc5
&eth_ref_clk_pa1
&eth_mdio_pa2
&eth_crs_dv_pa7
&eth_tx_en_pg11
&eth_txd0_pg13
&eth_txd1_pg12>;
pinctrl-names = "default";
};

&mdio {
status = "okay";
pinctrl-0 = <&eth_mdio_pa2 &eth_mdc_pc1>;
pinctrl-names = "default";

ethernet-phy@0 {
compatible = "ethernet-phy";
reg = <0x00>;
status = "okay";
};
};

&flash0 {
partitions {
compatible = "fixed-partitions";
Expand Down
16 changes: 13 additions & 3 deletions boards/st/stm32h735g_disco/stm32h735g_disco.dts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@
};

&mac {
pinctrl-0 = <&eth_mdc_pc1
&eth_rxd0_pc4
pinctrl-0 = <&eth_rxd0_pc4
&eth_rxd1_pc5
&eth_ref_clk_pa1
&eth_mdio_pa2
&eth_crs_dv_pa7
&eth_tx_en_pb11
&eth_txd0_pb12
Expand All @@ -143,6 +141,18 @@
status = "okay";
};

&mdio {
status = "okay";
pinctrl-0 = <&eth_mdio_pa2 &eth_mdc_pc1>;
pinctrl-names = "default";

ethernet-phy@0 {
compatible = "ethernet-phy";
reg = <0x00>;
status = "okay";
};
};

&sdmmc1 {
pinctrl-0 = <&sdmmc1_d0_pc8
&sdmmc1_d1_pc9
Expand Down
1 change: 1 addition & 0 deletions drivers/ethernet/Kconfig.stm32_hal
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ menuconfig ETH_STM32_HAL
select NOCACHE_MEMORY if SOC_SERIES_STM32H7X && CPU_CORTEX_M7
select HWINFO
select ETH_DSA_SUPPORT
select MDIO if SOC_SERIES_STM32H5X || SOC_SERIES_STM32H7X
imply CRC
help
Enable STM32 HAL based Ethernet driver. It is available for
Expand Down
12 changes: 9 additions & 3 deletions drivers/ethernet/eth_stm32_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr/net/net_pkt.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/ethernet.h>
#include <zephyr/net/phy.h>
#include <ethernet/eth_stats.h>
#include <soc.h>
#include <zephyr/sys/printk.h>
Expand Down Expand Up @@ -57,6 +58,11 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32H5X)

#define DEVICE_PHY_BY_NAME(n) \
DEVICE_DT_GET(DT_CHILD(DT_INST_CHILD(n, mdio), ethernet_phy_0))

static const struct device *eth_stm32_phy_dev = DEVICE_PHY_BY_NAME(0);

#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */
#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */

Expand Down Expand Up @@ -211,8 +217,9 @@ static HAL_StatusTypeDef read_eth_phy_register(ETH_HandleTypeDef *heth,
uint32_t PHYReg,
uint32_t *RegVal)
{
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32H5X) || \
defined(CONFIG_ETH_STM32_HAL_API_V2)
#if defined(CONFIG_MDIO)
return phy_read(eth_stm32_phy_dev, PHYReg, RegVal);
#elif defined(CONFIG_ETH_STM32_HAL_API_V2)
return HAL_ETH_ReadPHYRegister(heth, PHYAddr, PHYReg, RegVal);
#else
ARG_UNUSED(PHYAddr);
Expand Down Expand Up @@ -1225,7 +1232,6 @@ static int eth_initialize(const struct device *dev)
setup_mac_filter(heth);



LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x",
dev_data->mac_addr[0], dev_data->mac_addr[1],
dev_data->mac_addr[2], dev_data->mac_addr[3],
Expand Down
4 changes: 1 addition & 3 deletions drivers/ethernet/phy/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ config PHY_GENERIC_MII
config PHY_ADIN2111
bool "ADIN2111 PHY driver"
default y
depends on DT_HAS_ADI_ADIN2111_PHY_ENABLED
depends on ETH_ADIN2111
depends on MDIO_ADIN2111
depends on DT_HAS_ADI_ADIN2111_PHY_ENABLED || DT_HAS_ADI_ADIN1100_PHY_ENABLED
help
Enable ADIN2111 PHY driver.

Expand Down
Loading
Loading