public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 03/20] net: sun8i-emac: support new pinctrl DT bindings
Date: Fri,  2 Mar 2018 00:56:42 +0000	[thread overview]
Message-ID: <20180302005659.28728-4-andre.przywara@arm.com> (raw)
In-Reply-To: <20180302005659.28728-1-andre.przywara@arm.com>

The Linux kernel driver for the Allwinner pin controller gained support
for generic properties, which are now also used in the DTs.
The sun8i-emac Ethernet driver for new Allwinner MACs reads the pins from
the DT, but so far only supported the old binding.
Update the parsing routine to cope with both the old and new bindings,
so that the newer DTs can be used with U-Boot and its Ethernet driver.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/net/sun8i_emac.c | 52 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 13 deletions(-)

diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
index 3ccc6b0bb6..df2b857310 100644
--- a/drivers/net/sun8i_emac.c
+++ b/drivers/net/sun8i_emac.c
@@ -21,6 +21,7 @@
 #include <malloc.h>
 #include <miiphy.h>
 #include <net.h>
+#include <dt-bindings/pinctrl/sun4i-a10.h>
 #ifdef CONFIG_DM_GPIO
 #include <asm-generic/gpio.h>
 #endif
@@ -465,30 +466,55 @@ static int parse_phy_pins(struct udevice *dev)
 	}
 
 	drive = fdt_getprop_u32_default_node(gd->fdt_blob, offset, 0,
-					     "allwinner,drive", 4);
-	pull = fdt_getprop_u32_default_node(gd->fdt_blob, offset, 0,
-					    "allwinner,pull", 0);
+					     "drive-strength", ~0);
+	if (drive != ~0) {
+		if (drive <= 10)
+			drive = SUN4I_PINCTRL_10_MA;
+		else if (drive <= 20)
+			drive = SUN4I_PINCTRL_20_MA;
+		else if (drive <= 30)
+			drive = SUN4I_PINCTRL_30_MA;
+		else
+			drive = SUN4I_PINCTRL_40_MA;
+	} else {
+		drive = fdt_getprop_u32_default_node(gd->fdt_blob, offset, 0,
+						     "allwinner,drive", 4);
+	}
+
+	if (fdt_get_property(gd->fdt_blob, offset, "bias-pull-up", NULL))
+		pull = SUN4I_PINCTRL_PULL_UP;
+	else if (fdt_get_property(gd->fdt_blob, offset, "bias-disable", NULL))
+		pull = SUN4I_PINCTRL_NO_PULL;
+	else if (fdt_get_property(gd->fdt_blob, offset, "bias-pull-down", NULL))
+		pull = SUN4I_PINCTRL_PULL_DOWN;
+	else
+		pull = fdt_getprop_u32_default_node(gd->fdt_blob, offset, 0,
+						    "allwinner,pull", 0);
 	for (i = 0; ; i++) {
 		int pin;
 
 		pin_name = fdt_stringlist_get(gd->fdt_blob, offset,
 					      "allwinner,pins", i, NULL);
-		if (!pin_name)
-			break;
-		if (pin_name[0] != 'P')
-			continue;
-		pin = (pin_name[1] - 'A') << 5;
-		if (pin >= 26 << 5)
+		if (!pin_name) {
+			pin_name = fdt_stringlist_get(gd->fdt_blob, offset,
+						      "pins", i, NULL);
+			if (!pin_name)
+				break;
+		}
+
+		pin = sunxi_name_to_gpio(pin_name);
+		if (pin < 0)
 			continue;
-		pin += simple_strtol(&pin_name[2], NULL, 10);
 
 		sunxi_gpio_set_cfgpin(pin, SUN8I_GPD8_GMAC);
-		sunxi_gpio_set_drv(pin, drive);
-		sunxi_gpio_set_pull(pin, pull);
+		if (drive != ~0)
+			sunxi_gpio_set_drv(pin, drive);
+		if (pull != ~0)
+			sunxi_gpio_set_pull(pin, pull);
 	}
 
 	if (!i) {
-		printf("WARNING: emac: cannot find allwinner,pins property\n");
+		printf("WARNING: emac: cannot find pins property\n");
 		return -2;
 	}
 
-- 
2.14.1

  parent reply	other threads:[~2018-03-02  0:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-02  0:56 [U-Boot] [PATCH v3 00/20] sunxi: sync H3, H5, A64 DTs from mainline Linux Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 01/20] sunxi: README.sunxi64: Add hint about non-debug of ARM Trusted Firmware Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 02/20] sunxi: gpio: add missing compatible strings Andre Przywara
2018-03-02  0:56 ` Andre Przywara [this message]
2018-03-02  0:56 ` [U-Boot] [PATCH v3 04/20] net: sun8i-emac: add support for new EMAC DT binding Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 05/20] arm: dts: sunxi: update A64 to new EMAC binding Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 06/20] arm: dts: sunxi: update H3 " Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 07/20] arm: dts: sunxi: update H5 " Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 08/20] net: sun8i-emac: remove support for old binding Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 09/20] sunxi: disable direct MMC environment for 64 bit boards Andre Przywara
2018-03-02 15:56   ` Maxime Ripard
2018-03-02 16:00     ` Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 10/20] sunxi: revert disabling of features Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 11/20] sunxi: DT: A64: update device tree file for Allwinner A64 SoC Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 12/20] sunxi: DT: A64: update board .dts files from Linux Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 13/20] Revert: arm64: allwinner: a64: pine64: Use dcdc1 regulator for mmc0 Andre Przywara
2018-03-02 15:58   ` Maxime Ripard
2018-03-02 16:24     ` Andre Przywara
2018-03-02 16:32       ` [U-Boot] [linux-sunxi] " Vincent Legoll
2018-03-02 16:42         ` Andre Przywara
2018-03-03 14:59       ` [U-Boot] " Emmanuel Vadot
2018-03-09  9:50       ` Maxime Ripard
2018-03-02  0:56 ` [U-Boot] [PATCH v3 14/20] sunxi: dts: A64 boards: Use fixed " Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 15/20] sunxi: DT: update device tree files for Allwinner H3 and H5 SoCs Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 16/20] sunxi: DT: H5: update board .dts files from Linux Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 17/20] sunxi: DT: H3: " Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 18/20] sunxi: DT: H3: update libre-cc board .dts file Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 19/20] sunxi: DT: H2+: update Opi-zero .dts Andre Przywara
2018-03-02  0:56 ` [U-Boot] [PATCH v3 20/20] sunxi: DT: A64: add proper SoPine baseboard device tree Andre Przywara
2018-03-02 15:59 ` [U-Boot] [PATCH v3 00/20] sunxi: sync H3, H5, A64 DTs from mainline Linux Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180302005659.28728-4-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox