sunxi: update sun8i-emac driver and A64 DTs
Subsystems (8)
v2 cover sunxi: update sun8i-emac driver and A64 DTs
This patch set updates the latest device trees for Allwinner A64 based boards from Linux. In contrast to v1 I now took the actual 4.13-rc1 DTs from Linux, which restructures the patch set a bit.
The big advantage of having the very same DTs in U-Boot
is that we can use UEFI boot much more easily, because U-Boot can just pass on its own DT, without having to find and load some external version. This makes UEFI based installers boot out of the box, which is a big relief. Linux 4.13-rc1 saw the addition of the sun8i-emac Ethernet driver, for which U-Boot has a driver for quite a while, but with a slightly different binding, so this series makes it compatible.
Patch 1/6 adds some missing compatible strings, it was on the list before, but I add it to this series because it is a prerequisite for the following patches. Patches 2 till 4 add some code to be able to parse the new pinctrl bindings that newer Allwinner DTs use.
Patch 5 extends U-Boot sun8i-emac driver to be able to properly parse the DT binding used by the new Linux driver as well.
Patch 6 then actually replaces the DTs for A64 boards with the exact version as of the Linux tree (v4.13-rc1).
This allows us to *almost* get rid of out *-u-boot.dtsi kludge, but we still need the alias, which the Linux version doesn't have, so this file still contains this one line, effectively.
I am still not convinced that having a full featured pinctrl driver in U-Boot is the right thing, so I cheekily ignore this part of the comments. If people consider this a requirement, we can have a look at this, but I don't see any reply since the first patch was posted some months ago, so I guess this takes much more time.
Also my apologies for not having looked at the syscon driver change Simon asked. It looks like a reasonable change, but I am about to leave for holidays and didn't want to postpone an updated version any longer.
Cheers,
Andre.
Andre Przywara (6):
sunxi: gpio: add missing compatible strings
libfdt: add fdtdec_lookup_phandle_index()
sunxi: GPIO: introduce sunxi_gpio_setup_dt_pins()
net: sun8i-emac: use new, generic GPIO setup routine
net: sun8i-emac: add support for new DT binding
sunxi: A64: update Linux DTs
arch/arm/dts/sun50i-a64-bananapi-m64-u-boot.dtsi | 5 + arch/arm/dts/sun50i-a64-bananapi-m64.dts | 16 ++- arch/arm/dts/sun50i-a64-orangepi-win.dts | 7 +- arch/arm/dts/sun50i-a64-pine64-plus-u-boot.dtsi | 45 ------- arch/arm/dts/sun50i-a64-pine64-plus.dts | 17 ++- arch/arm/dts/sun50i-a64-pine64.dts | 57 +++++++++ arch/arm/dts/sun50i-a64.dtsi | 142 ++++++++++++++++++++--- arch/arm/include/asm/arch-sunxi/gpio.h | 3 + arch/arm/mach-sunxi/pinmux.c | 79 +++++++++++++ drivers/gpio/sunxi_gpio.c | 4 + drivers/net/sun8i_emac.c | 105 +++++++++-------- include/dt-bindings/clock/sun8i-r-ccu.h | 59 ++++++++++ include/fdtdec.h | 12 ++ lib/fdtdec.c | 16 ++- 14 files changed, 441 insertions(+), 126 deletions(-) create mode 100644 arch/arm/dts/sun50i-a64-bananapi-m64-u-boot.dtsi create mode 100644 include/dt-bindings/clock/sun8i-r-ccu.h
Signature · 1 line
2.8.2
PATCH v2 1/6 sunxi: gpio: add missing compatible strings
The sunxi GPIO driver is missing some compatible strings for recent SoCs. While most of the sunxi GPIO code seems to not rely on this (and so works anyway), the sunxi_name_to_gpio() function does and fails at the moment (for instance when resolving the MMC CD pin name). Add the compatible strings for the A64, H5 and V3s, which were missing from the list. This now covers all pinctrl nodes in our own DTs. Strictly speaking the V3s has only ports B, C, E, F and G, but I think the other SoCs have gaps in there as well and for the pin number computation this does not matter.
--- drivers/gpio/sunxi_gpio.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpio/sunxi_gpio.c +4 -0
@@ -353,12 +353,16 @@ static const struct udevice_id sunxi_gpio_ids[] = {ID ("allwinner,sun8i-a83t-pinctrl" , a_all),ID ("allwinner,sun8i-h3-pinctrl" , a_all),ID ("allwinner,sun8i-r40-pinctrl" , a_all), +ID ("allwinner,sun8i-v3s-pinctrl" , a_all),ID ("allwinner,sun9i-a80-pinctrl" , a_all), +ID ("allwinner,sun50i-a64-pinctrl" , a_all), +ID ("allwinner,sun50i-h5-pinctrl" , a_all),ID ("allwinner,sun6i-a31-r-pinctrl" , l_2),ID ("allwinner,sun8i-a23-r-pinctrl" , l_1),ID ("allwinner,sun8i-a83t-r-pinctrl" , l_1),ID ("allwinner,sun8i-h3-r-pinctrl" , l_1),ID ("allwinner,sun9i-a80-r-pinctrl" , l_3), + ID("allwinner,sun50i-a64-r-pinctrl", l_1), { } };
Signature · 1 line
2.8.2
PATCH v2 2/6 libfdt: add fdtdec_lookup_phandle_index()
In reply to Andre PrzywaraIn some bindings a property points to multiple nodes, using a list of phandles. A prominent example are UART pinctrl nodes, which use one node to contain the RX/TX pins and another node to describe the lines used for the hardware handshake.
The current fdtdec_lookup_phandle() helper function to chase a phandle is quite convienent, but can only lookup the first of those handles.
Introduce an extra function fdtdec_lookup_phandle_index() to take an index parameter and implement fdtdec_lookup_phandle() as a special case of that.
--- include/fdtdec.h | 12 ++++++++++++ lib/fdtdec.c | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)
include/fdtdec.h +12 -0
@@ -650,6 +650,18 @@ int fdtdec_get_chosen_node(const void *blob, const char *name);*/ const char *fdtdec_get_compatible (enum fdt_compat_id id); +/* Look up a phandle with a given index and follow it to its node. +* Then return the offset of that node. +* +* @param blob FDT blob +* @param node node to examine +* @param prop_name name of property to find +* @param index index of the desired phandle in the list +* @return node offset if found, -ve error code on error +*/ +int fdtdec_lookup_phandle_index (const void *blob,int node, +const char *prop_name,int index); +/* Look up a phandle and follow it to its node. Then return the offset * of that node. *
lib/fdtdec.c +12 -4
@@ -618,20 +618,28 @@ int fdtdec_prepare_fdt(void)return 0 ; } -int fdtdec_lookup_phandle (const void *blob,int node,const char *prop_name) +int fdtdec_lookup_phandle_index (const void *blob,int node, +const char *prop_name,int index) {const u32 *phandle;int lookup; +int length;debug ("%s: %s\n" , __func__, prop_name); - phandle =fdt_getprop (blob, node, prop_name,NULL ); -if (!phandle) + phandle =fdt_getprop (blob, node, prop_name, &length); +if (!phandle || index *4 >= length)return -FDT_ERR_NOTFOUND ; - lookup =fdt_node_offset_by_phandle (blob,fdt32_to_cpu (*phandle)); + lookup =fdt_node_offset_by_phandle (blob, +fdt32_to_cpu (phandle[index]));return lookup; } +int fdtdec_lookup_phandle (const void *blob,int node,const char *prop_name) +{ +return fdtdec_lookup_phandle_index (blob, node, prop_name,0 ); +} +/** * Look up a property in a node and check that it has a minimum length. *
Signature · 1 line
2.8.2
PATCH v2 3/6 sunxi: GPIO: introduce sunxi_gpio_setup_dt_pins()
In reply to Andre PrzywaraInstead of hard-coding GPIO pins used for a certain peripheral, we should just use the pinctrl information from the DT. The sun8i-emac driver has some simple implementation of that, so let's just generalize this and copy the code to a more common location.
On the way we add support for the new, generic pinctrl binding now used by all Allwinner SoCs.
--- arch/arm/include/asm/arch-sunxi/gpio.h | 3 ++ arch/arm/mach-sunxi/pinmux.c | 79 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+)
arch/arm/include/asm/arch-sunxi/gpio.h +3 -0
@@ -240,4 +240,7 @@ int axp_gpio_init(void);static inline int axp_gpio_init (void ) {return 0 ; }#endif +int sunxi_gpio_setup_dt_pins (const void *volatile fdt_blob,int node, +int mux_sel); +#endif /* _SUNXI_GPIO_H */
arch/arm/mach-sunxi/pinmux.c +79 -0
88 lines not on this page · raw message
Signature · 1 line
2.8.2
PATCH v2 4/6 net: sun8i-emac: use new, generic GPIO setup routine
In reply to Andre PrzywaraInstead of open-coding the fairly generic pinmux setup in the sun8i-emac driver, let's just use the new common implementation of that. This has also the advantage of supporting the new, generic pinctrl bindings, so the driver can cope with the upstream Linux DTs.
--- drivers/net/sun8i_emac.c | 54 +++++++----------------------------------------- 1 file changed, 8 insertions(+), 46 deletions(-)
drivers/net/sun8i_emac.c +8 -46
@@ -451,50 +451,6 @@ static int _sun8i_emac_eth_init(struct emac_eth_dev *priv, u8 *enetaddr)return 0 ; } -static int parse_phy_pins (struct udevice *dev) -{ -int offset; -const char *pin_name; -int drive, pull, i; - - offset =fdtdec_lookup_phandle (gd->fdt_blob,dev_of_offset (dev), -"pinctrl-0" ); -if (offset <0 ) { -printf ("WARNING: emac: cannot find pinctrl-0 node\n" ); -return offset; - } - - 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 ); -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 ) -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 (!i) { -printf ("WARNING: emac: cannot find allwinner,pins property\n" ); -return -2 ; - } - -return 0 ; -} -static int _sun8i_eth_recv (struct emac_eth_dev *priv,uchar **packetp) {u32 status, desc_num = priv->rx_currdescnum;
@@ -816,8 +772,14 @@ static int sun8i_emac_eth_ofdata_to_platdata(struct udevice *dev) priv->interface = pdata->phy_interface; -if (!priv->use_internal_phy) -parse_phy_pins (dev); +if (!priv->use_internal_phy) { + ret =sunxi_gpio_setup_dt_pins (gd->fdt_blob,dev_of_offset (dev), +SUN8I_GPD8_GMAC ); +if (ret <0 ) { +printf ("%s: cannot setup pinmuxes\n" , __func__); +return -EINVAL ; + } + }#ifdef CONFIG_DM_GPIO if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
Signature · 1 line
2.8.2
PATCH v2 5/6 net: sun8i-emac: add support for new DT binding
In reply to Andre PrzywaraThe Ethernet MAC used in newer Allwinner SoCs (H3, A64, H5) is about to get an upstream Linux driver very soon (it's already lurking in -next). This one uses a slightly different binding from the original one used by the U-Boot driver.
The differences to the old binding are:
- The "syscon" address is held in a separate node, referenced via a phandle in the "syscon" property.
- The reference to the PHY is held in a property called "phy-handle", not "phy".
- The PHY register is at offset 0x30 in the syscon device, not at 0.
- The internal PHY is activated when a capable SoC selects MII mode.
Teach the U-Boot driver how to find its resources in a "new-style" DT, so that we can use a Linux kernel compatible DT for U-Boot as well. This keeps support for the old binding (for now?), to allow a smooth transition.
--- drivers/net/sun8i_emac.c | 51 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-)
drivers/net/sun8i_emac.c +44 -7
@@ -278,7 +278,7 @@ static int sun8i_emac_set_syscon(struct emac_eth_dev *priv)int ret;u32 reg; - reg =readl (priv->sysctl_reg); + reg =readl (priv->sysctl_reg +0x30 );if (priv->variant ==H3_EMAC ) { ret =sun8i_emac_set_syscon_ephy (priv, ®);
@@ -309,7 +309,7 @@ static int sun8i_emac_set_syscon(struct emac_eth_dev *priv)return -EINVAL ; } -writel (reg, priv->sysctl_reg); +writel (reg, priv->sysctl_reg +0x30 );return 0 ; }
@@ -733,17 +733,50 @@ static int sun8i_emac_eth_ofdata_to_platdata(struct udevice *dev)#endif pdata->iobase =devfdt_get_addr_name (dev,"emac" ); +if (pdata->iobase ==FDT_ADDR_T_NONE ) + pdata->iobase =devfdt_get_addr (dev); +if (pdata->iobase ==FDT_ADDR_T_NONE ) { +debug ("%s: Cannot find MAC base address\n" , __func__); +return -EINVAL ; + } + priv->sysctl_reg =devfdt_get_addr_name (dev,"syscon" ); +if (priv->sysctl_reg ==FDT_ADDR_T_NONE ) { +const fdt32_t *reg; + + offset =fdtdec_lookup_phandle (gd->fdt_blob, node,"syscon" ); +if (offset <0 ) { +debug ("%s: cannot find syscon node\n" , __func__); +return -EINVAL ; + } + reg =fdt_getprop (gd->fdt_blob, offset,"reg" ,NULL ); +if (!reg) { +debug ("%s: cannot find reg property in syscon node\n" , + __func__); +return -EINVAL ; + } + priv->sysctl_reg =fdt_translate_address ((void *)gd->fdt_blob, + offset, reg); + }else + priv->sysctl_reg -=0x30 ; +if (priv->sysctl_reg ==FDT_ADDR_T_NONE ) { +debug ("%s: Cannot find syscon base address\n" , __func__); +return -EINVAL ; + } pdata->phy_interface =-1 ; priv->phyaddr =-1 ; priv->use_internal_phy = false; - offset =fdtdec_lookup_phandle (gd->fdt_blob, node, -"phy" ); -if (offset >0 ) - priv->phyaddr =fdtdec_get_int (gd->fdt_blob, offset,"reg" , --1 ); + offset =fdtdec_lookup_phandle (gd->fdt_blob, node,"phy" ); +if (offset <0 ) + offset =fdtdec_lookup_phandle (gd->fdt_blob, node, +"phy-handle" ); +if (offset <0 ) { +debug ("%s: Cannot find PHY address\n" , __func__); +return -EINVAL ; + } + priv->phyaddr =fdtdec_get_int (gd->fdt_blob, offset,"reg" ,-1 ); phy_mode =fdt_getprop (gd->fdt_blob, node,"phy-mode" ,NULL );
@@ -768,6 +801,10 @@ static int sun8i_emac_eth_ofdata_to_platdata(struct udevice *dev)if (fdt_getprop (gd->fdt_blob, node,"allwinner,use-internal-phy" ,NULL )) priv->use_internal_phy = true; +else { +if (pdata->phy_interface ==PHY_INTERFACE_MODE_MII ) + priv->use_internal_phy = true; + } } priv->interface = pdata->phy_interface;
Signature · 1 line
2.8.2
PATCH v2 6/6 sunxi: A64: update Linux DTs
In reply to Andre PrzywaraAn Ethernet driver for the sun8i-emac IP has reached the Linux kernel, so the DT in there have been updated.
Since U-Boot's EMAC driver can now cope with the slightly different kernel DT binding as well, let's copy the .dtsi and .dts files as of commit bdecc9cb214e from the kernel.
This allows us to get *almost* rid of our sun50i-a64-pine64-plus-u-boot.dtsi file, which was just there to add the Ethernet nodes.
We still need the one line for the Ethernet alias, though.
Also this enables Ethernet on the BananaPi-M64, since the Linux DT has the respective nodes.
--- arch/arm/dts/sun50i-a64-bananapi-m64-u-boot.dtsi | 5 + arch/arm/dts/sun50i-a64-bananapi-m64.dts | 16 ++- arch/arm/dts/sun50i-a64-orangepi-win.dts | 7 +- arch/arm/dts/sun50i-a64-pine64-plus-u-boot.dtsi | 45 ------- arch/arm/dts/sun50i-a64-pine64-plus.dts | 17 ++- arch/arm/dts/sun50i-a64-pine64.dts | 57 +++++++++ arch/arm/dts/sun50i-a64.dtsi | 142 ++++++++++++++++++++--- include/dt-bindings/clock/sun8i-r-ccu.h | 59 ++++++++++ 8 files changed, 279 insertions(+), 69 deletions(-) create mode 100644 arch/arm/dts/sun50i-a64-bananapi-m64-u-boot.dtsi create mode 100644 include/dt-bindings/clock/sun8i-r-ccu.h
arch/arm/dts/sun50i-a64-bananapi-m64-u-boot.dtsi new file +5 -0
@@ -0,0 +1,5 @@ +/ { + aliases { + ethernet0 = &emac; + }; +};
arch/arm/dts/sun50i-a64-bananapi-m64.dts +15 -1
@@ -1,6 +1,5 @@ /* * Copyright (c) 2016 ARM Ltd. - * Copyright (C) 2017 Jagan Teki <[email protected]> * * This file is dual-licensed: you can use it either under the terms * of the GPL or the X11 license, at your option. Note that this dual
@@ -68,6 +67,14 @@ }; }; +&emac { + pinctrl-names = "default"; + pinctrl-0 = <&rgmii_pins>; + phy-mode = "rgmii"; + phy-handle = <&ext_rgmii_phy>; + status = "okay"; +}; + &i2c1 { pinctrl-names = "default"; pinctrl-0 = <&i2c1_pins>;
@@ -78,6 +85,13 @@ bias-pull-up; }; +&mdio { + ext_rgmii_phy: ethernet-phy at 1 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <1>; + }; +}; + &mmc0 { pinctrl-names = "default"; pinctrl-0 = <&mmc0_pins>;
arch/arm/dts/sun50i-a64-orangepi-win.dts +4 -3
@@ -67,7 +67,7 @@ }; &ehci1 { - status = "okay"; + status = "okay"; }; &mmc0 {
@@ -80,7 +80,7 @@ }; &ohci1 { - status = "okay"; + status = "okay"; }; &uart0 {
@@ -90,5 +90,6 @@ }; &usbphy { - status = "okay"; + status = "okay"; }; +
arch/arm/dts/sun50i-a64-pine64-plus-u-boot.dtsi +0 -45
49 lines not on this page · raw message
arch/arm/dts/sun50i-a64-pine64-plus.dts +16 -1
@@ -46,5 +46,20 @@ model = "Pine64+"; compatible = "pine64,pine64-plus", "allwinner,sun50i-a64"; - /* TODO: Camera, Ethernet PHY, touchscreen, etc. */ + /* TODO: Camera, touchscreen, etc. */ +}; + +&emac { + pinctrl-names = "default"; + pinctrl-0 = <&rgmii_pins>; + phy-mode = "rgmii"; + phy-handle = <&ext_rgmii_phy>; + status = "okay"; +}; + +&mdio { + ext_rgmii_phy: ethernet-phy at 1 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <1>; + }; };
arch/arm/dts/sun50i-a64-pine64.dts +57 -0
95 lines not on this page · raw message
arch/arm/dts/sun50i-a64.dtsi +123 -19
240 lines not on this page · raw message
include/dt-bindings/clock/sun8i-r-ccu.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.8.2
v2 cover sunxi: update sun8i-emac driver and A64 DTs
In reply to Andre PrzywaraQuoted 36 lines · Andre Przywara
This patch set updates the latest device trees for Allwinner A64 based boards from Linux. In contrast to v1 I now took the actual 4.13-rc1 DTs from Linux, which restructures the patch set a bit.
The big advantage of having the very same DTs in U-Boot
is that we can use UEFI boot much more easily, because U-Boot can just pass on its own DT, without having to find and load some external version. This makes UEFI based installers boot out of the box, which is a big relief. Linux 4.13-rc1 saw the addition of the sun8i-emac Ethernet driver, for which U-Boot has a driver for quite a while, but with a slightly different binding, so this series makes it compatible.
Patch 1/6 adds some missing compatible strings, it was on the list before, but I add it to this series because it is a prerequisite for the following patches. Patches 2 till 4 add some code to be able to parse the new pinctrl bindings that newer Allwinner DTs use.
Patch 5 extends U-Boot sun8i-emac driver to be able to properly parse the DT binding used by the new Linux driver as well.
Patch 6 then actually replaces the DTs for A64 boards with the exact version as of the Linux tree (v4.13-rc1).
This allows us to *almost* get rid of out *-u-boot.dtsi kludge, but we still need the alias, which the Linux version doesn't have, so this file still contains this one line, effectively.I am still not convinced that having a full featured pinctrl driver in U-Boot is the right thing, so I cheekily ignore this part of the comments. If people consider this a requirement, we can have a look at this, but I don't see any reply since the first patch was posted some months ago, so I guess this takes much more time.
Also my apologies for not having looked at the syscon driver change Simon asked. It looks like a reasonable change, but I am about to leave for holidays and didn't want to postpone an updated version any longer.
Cheers,
Andre.
Quoted 7 lines
Andre Przywara (6):
sunxi: gpio: add missing compatible strings
libfdt: addfdtdec_lookup_phandle_index()
sunxi: GPIO: introducesunxi_gpio_setup_dt_pins()
net: sun8i-emac: use new, generic GPIO setup routine
net: sun8i-emac: add support for new DT binding
sunxi: A64: update Linux DTs
This series look OK, to me. Will test emac and update. Meanwhile any comments please let me know.
thanks!
Signature · 4 lines
Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India.