From be387aa1c2d4387a3e8f13e9a64aa39adfad5800 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Sat, 12 Mar 2022 23:22:48 -0300 Subject: [PATCH] drivers: eth: Update sam/sam0 eth drivers to use pinctrl This update Atmel sam and sam0 ethernet gmac and mdio drivers to use pinctrl driver and API. It updates all boards with new pinctrl groups format. Signed-off-by: Gerson Fernando Budke --- .../atsame54_xpro/atsame54_xpro-pinctrl.dtsi | 20 ++++++++++++++ boards/arm/atsame54_xpro/atsame54_xpro.dts | 6 +++++ boards/arm/atsame54_xpro/pinmux.c | 13 --------- boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi | 27 +++++++++++++++++++ boards/arm/sam4e_xpro/sam4e_xpro.dts | 7 +++++ .../sam_e70_xplained-common.dtsi | 6 +++++ .../sam_e70_xplained-pinctrl.dtsi | 20 ++++++++++++++ .../arm/sam_v71_xult/sam_v71_xult-common.dtsi | 6 +++++ .../sam_v71_xult/sam_v71_xult-pinctrl.dtsi | 20 ++++++++++++++ drivers/ethernet/eth_sam_gmac.c | 15 +++++------ drivers/ethernet/eth_sam_gmac_priv.h | 3 +-- drivers/mdio/mdio_sam.c | 10 ++++++- dts/arm/atmel/sam4e.dtsi | 10 ------- dts/arm/atmel/same70.dtsi | 6 ----- dts/bindings/ethernet/atmel,gmac-common.yaml | 25 +++-------------- dts/bindings/mdio/atmel,sam-mdio.yaml | 14 +++------- 16 files changed, 135 insertions(+), 73 deletions(-) diff --git a/boards/arm/atsame54_xpro/atsame54_xpro-pinctrl.dtsi b/boards/arm/atsame54_xpro/atsame54_xpro-pinctrl.dtsi index ab982c306fa..59f6915821d 100644 --- a/boards/arm/atsame54_xpro/atsame54_xpro-pinctrl.dtsi +++ b/boards/arm/atsame54_xpro/atsame54_xpro-pinctrl.dtsi @@ -12,6 +12,26 @@ }; }; + gmac_rmii: gmac_rmii { + group1 { + pinmux = , + , + , + , + , + , + , + ; + }; + }; + + mdio_default: mdio_default { + group1 { + pinmux = , + ; + }; + }; + sercom7_i2c_default: sercom7_i2c_default { group1 { pinmux = , diff --git a/boards/arm/atsame54_xpro/atsame54_xpro.dts b/boards/arm/atsame54_xpro/atsame54_xpro.dts index 7930fe98192..79c3a0d4a93 100644 --- a/boards/arm/atsame54_xpro/atsame54_xpro.dts +++ b/boards/arm/atsame54_xpro/atsame54_xpro.dts @@ -119,6 +119,9 @@ zephyr_udc0: &usb0 { status = "okay"; zephyr,random-mac-address; + pinctrl-0 = <&gmac_rmii>; + pinctrl-names = "default"; + phy: phy { compatible = "ethernet-phy"; status = "okay"; @@ -129,4 +132,7 @@ zephyr_udc0: &usb0 { &mdio { status = "okay"; + + pinctrl-0 = <&mdio_default>; + pinctrl-names = "default"; }; diff --git a/boards/arm/atsame54_xpro/pinmux.c b/boards/arm/atsame54_xpro/pinmux.c index 86b15099e08..867355136ce 100644 --- a/boards/arm/atsame54_xpro/pinmux.c +++ b/boards/arm/atsame54_xpro/pinmux.c @@ -30,19 +30,6 @@ static int board_pinmux_init(const struct device *dev) return -ENXIO; } -#if (DT_NODE_HAS_STATUS(DT_NODELABEL(gmac), okay) && CONFIG_ETH_SAM_GMAC) - pinmux_pin_set(muxa, 14, PINMUX_FUNC_L); /* PA14 = GTXCK */ - pinmux_pin_set(muxa, 17, PINMUX_FUNC_L); /* PA17 = GTXEN */ - pinmux_pin_set(muxa, 18, PINMUX_FUNC_L); /* PA18 = GTX0 */ - pinmux_pin_set(muxa, 19, PINMUX_FUNC_L); /* PA19 = GTX1 */ - pinmux_pin_set(muxc, 20, PINMUX_FUNC_L); /* PC20 = GRXDV */ - pinmux_pin_set(muxa, 13, PINMUX_FUNC_L); /* PA13 = GRX0 */ - pinmux_pin_set(muxa, 12, PINMUX_FUNC_L); /* PA12 = GRX1 */ - pinmux_pin_set(muxa, 15, PINMUX_FUNC_L); /* PA15 = GRXER */ - pinmux_pin_set(muxc, 11, PINMUX_FUNC_L); /* PC11 = GMDC */ - pinmux_pin_set(muxc, 12, PINMUX_FUNC_L); /* PC12 = GMDIO */ -#endif - return 0; } diff --git a/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi b/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi index 880c02af5ec..64a362b5dd6 100644 --- a/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi +++ b/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi @@ -6,6 +6,33 @@ #include &pinctrl { + gmac_mii: gmac_mii { + group1 { + pinmux = , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + }; + }; + + mdio_default: mdio_default { + group1 { + pinmux = , + ; + }; + }; + spi0_default: spi0_default { group1 { pinmux = , diff --git a/boards/arm/sam4e_xpro/sam4e_xpro.dts b/boards/arm/sam4e_xpro/sam4e_xpro.dts index d2bed1bca81..5fc829234c6 100644 --- a/boards/arm/sam4e_xpro/sam4e_xpro.dts +++ b/boards/arm/sam4e_xpro/sam4e_xpro.dts @@ -165,6 +165,10 @@ &gmac { status = "okay"; + + pinctrl-0 = <&gmac_mii>; + pinctrl-names = "default"; + zephyr,random-mac-address; phy: phy { @@ -177,6 +181,9 @@ &mdio { status = "okay"; + + pinctrl-0 = <&mdio_default>; + pinctrl-names = "default"; }; &wdt { diff --git a/boards/arm/sam_e70_xplained/sam_e70_xplained-common.dtsi b/boards/arm/sam_e70_xplained/sam_e70_xplained-common.dtsi index e401a41d6f1..c14985126a5 100644 --- a/boards/arm/sam_e70_xplained/sam_e70_xplained-common.dtsi +++ b/boards/arm/sam_e70_xplained/sam_e70_xplained-common.dtsi @@ -112,6 +112,9 @@ zephyr_udc0: &usbhs { &gmac { status = "okay"; + pinctrl-0 = <&gmac_rmii>; + pinctrl-names = "default"; + phy: phy { compatible = "ethernet-phy"; status = "okay"; @@ -122,6 +125,9 @@ zephyr_udc0: &usbhs { &mdio { status = "okay"; + + pinctrl-0 = <&mdio_default>; + pinctrl-names = "default"; }; &pwm0 { diff --git a/boards/arm/sam_e70_xplained/sam_e70_xplained-pinctrl.dtsi b/boards/arm/sam_e70_xplained/sam_e70_xplained-pinctrl.dtsi index 11037a4120e..fe28000d122 100644 --- a/boards/arm/sam_e70_xplained/sam_e70_xplained-pinctrl.dtsi +++ b/boards/arm/sam_e70_xplained/sam_e70_xplained-pinctrl.dtsi @@ -27,6 +27,26 @@ }; }; + gmac_rmii: gmac_rmii { + group1 { + pinmux = , + , + , + , + , + , + , + ; + }; + }; + + mdio_default: mdio_default { + group1 { + pinmux = , + ; + }; + }; + pwm_default: pwm_default { group1 { pinmux = , diff --git a/boards/arm/sam_v71_xult/sam_v71_xult-common.dtsi b/boards/arm/sam_v71_xult/sam_v71_xult-common.dtsi index 6c315fb4b62..c84107ceb14 100644 --- a/boards/arm/sam_v71_xult/sam_v71_xult-common.dtsi +++ b/boards/arm/sam_v71_xult/sam_v71_xult-common.dtsi @@ -220,6 +220,9 @@ zephyr_udc0: &usbhs { &gmac { status = "okay"; + pinctrl-0 = <&gmac_rmii>; + pinctrl-names = "default"; + phy: phy { compatible = "ethernet-phy"; status = "okay"; @@ -230,6 +233,9 @@ zephyr_udc0: &usbhs { &mdio { status = "okay"; + + pinctrl-0 = <&mdio_default>; + pinctrl-names = "default"; }; &pwm0 { diff --git a/boards/arm/sam_v71_xult/sam_v71_xult-pinctrl.dtsi b/boards/arm/sam_v71_xult/sam_v71_xult-pinctrl.dtsi index e07427db07c..328d68762f8 100644 --- a/boards/arm/sam_v71_xult/sam_v71_xult-pinctrl.dtsi +++ b/boards/arm/sam_v71_xult/sam_v71_xult-pinctrl.dtsi @@ -27,6 +27,26 @@ }; }; + gmac_rmii: gmac_rmii { + group1 { + pinmux = , + , + , + , + , + , + , + ; + }; + }; + + mdio_default: mdio_default { + group1 { + pinmux = , + ; + }; + }; + pwm_default: pwm_default { group1 { pinmux = , diff --git a/drivers/ethernet/eth_sam_gmac.c b/drivers/ethernet/eth_sam_gmac.c index 104615dab1d..5e68cbad176 100644 --- a/drivers/ethernet/eth_sam_gmac.c +++ b/drivers/ethernet/eth_sam_gmac.c @@ -42,6 +42,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include #include +#include #include #include "eth_sam_gmac_priv.h" @@ -1767,6 +1768,7 @@ static void queue5_isr(const struct device *dev) static int eth_initialize(const struct device *dev) { const struct eth_sam_dev_cfg *const cfg = dev->config; + int retval; cfg->config_func(); @@ -1774,15 +1776,15 @@ static int eth_initialize(const struct device *dev) /* Enable GMAC module's clock */ soc_pmc_peripheral_enable(cfg->periph_id); - /* Connect pins to the peripheral */ - soc_gpio_list_configure(cfg->pin_list, cfg->pin_list_size); #else /* Enable MCLK clock on GMAC */ MCLK->AHBMASK.reg |= MCLK_AHBMASK_GMAC; *MCLK_GMAC |= MCLK_GMAC_MASK; #endif + /* Connect pins to the peripheral */ + retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); - return 0; + return retval; } #ifdef CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM @@ -2203,16 +2205,13 @@ static void eth0_irq_config(void) #endif } -#ifdef CONFIG_SOC_FAMILY_SAM -static const struct soc_gpio_pin pins_eth0[] = ATMEL_SAM_DT_INST_PINS(0); -#endif +PINCTRL_DT_INST_DEFINE(0); static const struct eth_sam_dev_cfg eth0_config = { .regs = (Gmac *)DT_INST_REG_ADDR(0), + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), #ifdef CONFIG_SOC_FAMILY_SAM .periph_id = DT_INST_PROP_OR(0, peripheral_id, 0), - .pin_list = pins_eth0, - .pin_list_size = ARRAY_SIZE(pins_eth0), #endif .config_func = eth0_irq_config, #if DT_NODE_EXISTS(DT_CHILD(DT_DRV_INST(0), phy)) diff --git a/drivers/ethernet/eth_sam_gmac_priv.h b/drivers/ethernet/eth_sam_gmac_priv.h index 0a4a7c9f549..78e7dee96bd 100644 --- a/drivers/ethernet/eth_sam_gmac_priv.h +++ b/drivers/ethernet/eth_sam_gmac_priv.h @@ -261,10 +261,9 @@ struct gmac_queue { /* Device constant configuration parameters */ struct eth_sam_dev_cfg { Gmac *regs; + const struct pinctrl_dev_config *pcfg; #ifdef CONFIG_SOC_FAMILY_SAM uint32_t periph_id; - const struct soc_gpio_pin *pin_list; - uint32_t pin_list_size; #endif void (*config_func)(void); const struct device *phy_dev; diff --git a/drivers/mdio/mdio_sam.c b/drivers/mdio/mdio_sam.c index 5fd016f6e4d..9313f24e120 100644 --- a/drivers/mdio/mdio_sam.c +++ b/drivers/mdio/mdio_sam.c @@ -11,6 +11,7 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(mdio_sam, CONFIG_MDIO_LOG_LEVEL); @@ -28,6 +29,7 @@ struct mdio_sam_dev_data { struct mdio_sam_dev_config { Gmac * const regs; + const struct pinctrl_dev_config *pcfg; int protocol; }; @@ -109,11 +111,15 @@ static void mdio_sam_bus_disable(const struct device *dev) static int mdio_sam_initialize(const struct device *dev) { + const struct mdio_sam_dev_config *const cfg = dev->config; struct mdio_sam_dev_data *const data = dev->data; + int retval; k_sem_init(&data->sem, 1, 1); - return 0; + retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + + return retval; } static const struct mdio_driver_api mdio_sam_driver_api = { @@ -126,10 +132,12 @@ static const struct mdio_driver_api mdio_sam_driver_api = { #define MDIO_SAM_CONFIG(n) \ static const struct mdio_sam_dev_config mdio_sam_dev_config_##n = { \ .regs = (Gmac *)DT_REG_ADDR(DT_INST_PARENT(n)), \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ .protocol = DT_INST_ENUM_IDX(n, protocol), \ }; #define MDIO_SAM_DEVICE(n) \ + PINCTRL_DT_INST_DEFINE(n); \ MDIO_SAM_CONFIG(n); \ static struct mdio_sam_dev_data mdio_sam_dev_data##n; \ DEVICE_DT_INST_DEFINE(n, \ diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 8d44674630d..dabae074ac1 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -151,16 +151,6 @@ phy-connection-type = "mii"; label = "GMAC"; status = "disabled"; - /* Default to MII config */ - pinctrl-0 = <&pd0a_gmac_gtxck &pd1a_gmac_gtxen - &pd2a_gmac_gtx0 &pd3a_gmac_gtx1 - &pd15a_gmac_gtx2 &pd16a_gmac_gtx3 - &pd4a_gmac_grxdv &pd7a_gmac_grxer - &pd14a_gmac_grxck &pd5a_gmac_grx0 - &pd6a_gmac_grx1 &pd11a_gmac_grx2 - &pd12a_gmac_grx3 &pd13a_gmac_gcol - &pd10a_gmac_gcrs &pd8a_gmac_gmdc - &pd9a_gmac_gmdio>; mdio: mdio { compatible = "atmel,sam-mdio"; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 334b73fe1cc..d3b12f552e2 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -347,17 +347,11 @@ local-mac-address = [00 00 00 00 00 00]; label = "GMAC"; status = "disabled"; - /* Default to RMII config */ - pinctrl-0 = <&pd0a_gmac_gtxck &pd1a_gmac_gtxen - &pd2a_gmac_gtx0 &pd3a_gmac_gtx1 - &pd4a_gmac_grxdv &pd5a_gmac_grx0 - &pd6a_gmac_grx1 &pd7a_gmac_grxer>; mdio: mdio { compatible = "atmel,sam-mdio"; label = "MDIO"; status = "disabled"; - pinctrl-0 = <&pd8a_gmac_gmdc &pd9a_gmac_gmdio>; }; }; diff --git a/dts/bindings/ethernet/atmel,gmac-common.yaml b/dts/bindings/ethernet/atmel,gmac-common.yaml index 70a8b3559f3..9cb7071310f 100644 --- a/dts/bindings/ethernet/atmel,gmac-common.yaml +++ b/dts/bindings/ethernet/atmel,gmac-common.yaml @@ -2,7 +2,9 @@ # Copyright (c) 2020-2021 Gerson Fernando Budke # SPDX-License-Identifier: Apache-2.0 -include: ethernet.yaml +include: + - name: ethernet.yaml + - name: pinctrl-device.yaml properties: reg: @@ -50,24 +52,3 @@ properties: represents Reduced Media-Independent Interface (RMII) mode. This property must be used with pinctrl-0. - - pinctrl-0: - type: phandles - required: false - description: | - PIO pin configuration for the various GMAC signals that include GTXCK, - GTXEN, GTX[3..0], GTXER, GRXCK, GRXDV, GRX[3..0], GRXER, GCRS, GCOL, - GMDC, and GMDIO. Which signals are used vary based on if the PHY - connection is MII or RMII (see datasheet for more details). We expect - that the phandles will reference pinctrl nodes. These nodes will have - a nodelabel that matches the Atmel SoC HAL defines and be of the form - p__. - - For example the GMAC on SAME7x would be for RMII - pinctrl-0 = <&pd0a_gmac_gtxck &pd1a_gmac_gtxen - &pd2a_gmac_gtx0 &pd3a_gmac_gtx1 - &pd4a_gmac_grxdv &pd5a_gmac_grx0 - &pd6a_gmac_grx1 &pd7a_gmac_grxer - &pd8a_gmac_gmdc &pd9a_gmac_gmdio>; - - This property must be used with phy-connection-type. diff --git a/dts/bindings/mdio/atmel,sam-mdio.yaml b/dts/bindings/mdio/atmel,sam-mdio.yaml index 9e4f8b605f6..4b7a45615db 100644 --- a/dts/bindings/mdio/atmel,sam-mdio.yaml +++ b/dts/bindings/mdio/atmel,sam-mdio.yaml @@ -5,14 +5,6 @@ description: Atmel SAM Family MDIO Driver node compatible: "atmel,sam-mdio" -include: mdio-controller.yaml - -properties: - pinctrl-0: - type: phandles - required: false - description: | - PIO pin configuration for MDC, and MDIO signals. - - For example the GMAC on SAME7x would be - pinctrl-0 = <&pd8a_gmac_gmdc &pd9a_gmac_gmdio>; +include: + - name: mdio-controller.yaml + - name: pinctrl-device.yaml