Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Modification to Buildroot 2017.02 to have Ethernet and WiFi supported in Orange Pi Zero

608 views
Skip to first unread message

Wojciech Zabołotny

unread,
Apr 1, 2017, 9:03:21 PM4/1/17
to
The attached sources allow to compile Buildroot 2017.02 for Orange Pi Zero
with Ethenet and WiFi support.

To compile the code it is enough to unpack the sources in an empty directory
(with unshar), and then run the "build.sh". It should download the BR
2017.02, patch it, configure and compile.
The resulting image is produced in output/images.
You can copy it to the SD card with: (Double check what is the SD card
device file for the SD card in your system! If you make a mistake, you may
damage the data on your hard disk! In my case it was /dev/sdb, but to avoid
destroying the data by somebode who acts without reading all the info, I
have changed it to the unlikely value /dev/sdX)

# dd if=sdcard.img of=/dev/sdX

After placing the SD card in your Orange Pi Zero, it should boot (please
remember that you should use the serial port (UART) to communicate with the
board e.g. va minicom).

To start Ethernet, you should make (on the Orange Pi Zero):

# modprobe sun8i-emac

Then to configure IP address, you should either start dhcp:

# udhcpc -i eth0

Or set the IP manually (the IP address should be probably modified to match your
network configuration)

# ifconfig eth0 172.19.1.2 up

You can also start WiFi and view the list of available networks:

# modprobe xradio_wlan
# ifconfig wlan0 up
# iwlist wlan0 scanning

DISCLAIMER: I DO NOT PROVIDE ANY WARRANTY. THE ABOVE MODIFICATION WORKED
FOR ME, BUT YOU CAN USE IT ONLY ON YOUR OWN RISK!
MAYBE IN CERTAIN CONDITIONS IT MAY DESTROY YOUR HARDWARE OR CAUSE OTHER
DAMAGE.

Good luck!
With best regards,
Wojtek

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.15.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the '#!/bin/sh' line above, then type 'sh FILE'.
#
lock_dir=_sh22328
# Made on 2017-04-02 02:55 CEST by <wzab@wzab>.
# Source directory was '/home/wzab/OrangePi0/lata3'.
#
# Existing files will *not* be overwritten, unless '-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 336 -rw-r--r-- sun8i-emac-module/Config.in
# 651 -rw-r--r-- sun8i-emac-module/sun8i-emac-module.mk
# 230 -rw-r--r-- boot.cmd
# 1630 -rw-r--r-- orangepi_zero_defconfig
# 510 -rw-r--r-- genimage.cfg
# 391 -rw-r--r-- xradio-module/xradio-module.mk
# 270 -rw-r--r-- xradio-module/Config.in
# 2688 -rw-r--r-- kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch
# 2636 -rw-r--r-- kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch
# 525 -rw-r--r-- sun8i/Makefile
# 49845 -rw-r--r-- sun8i/sun8i-emac.c
# 165 -rw-r--r-- menu.txt
# 3529 -rw-r--r-- kernel.config
# 1170 -rwxr--r-- build.sh
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
if test "X$1" = "X-c"
then keep_file=''
else keep_file=true
fi
echo=echo
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=
locale_dir=
set_echo=false

for dir in $PATH
do
if test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir
set_echo=true
break ;;
esac
fi
done

if ${set_echo}
then
set_echo=false
for dir in $PATH
do
if test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
set_echo=true
break
fi
done

if ${set_echo}
then
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
fi
IFS="$save_IFS"
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and
installing GNU '\''touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir} ; then :
else ${echo} "lock directory ${lock_dir} exists"
exit 1
fi
if mkdir ${lock_dir}
then ${echo} "x - created lock directory ${lock_dir}."
else ${echo} "x - failed to create lock directory ${lock_dir}."
exit 1
fi
# ============= sun8i-emac-module/Config.in ==============
if test ! -d 'sun8i-emac-module'; then
mkdir 'sun8i-emac-module'
if test $? -eq 0
then ${echo} "x - created directory sun8i-emac-module."
else ${echo} "x - failed to create directory sun8i-emac-module."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'sun8i-emac-module/Config.in'
then
${echo} "x - SKIPPING sun8i-emac-module/Config.in (file already exists)"

else
${echo} "x - extracting sun8i-emac-module/Config.in (text)"
sed 's/^X//' << 'SHAR_EOF' > 'sun8i-emac-module/Config.in' &&
config BR2_PACKAGE_SUN8I_EMAC_MODULE
X bool "sun8i-emac-module"
X depends on BR2_LINUX_KERNEL
X help
X Driver for Ethernet in H3 bridge.
X
X https://github.com/montjoie/linux/blob/sun8i-emac-wip/drivers/net/ethernet/allwinner/sun8i-emac.c
X
comment "sun8i-emac-module needs a Linux kernel to be built"
X depends on !BR2_LINUX_KERNEL
SHAR_EOF
(set 20 16 12 10 00 44 37 'sun8i-emac-module/Config.in'
eval "${shar_touch}") && \
chmod 0644 'sun8i-emac-module/Config.in'
if test $? -ne 0
then ${echo} "restore of sun8i-emac-module/Config.in failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'sun8i-emac-module/Config.in': 'MD5 check failed'
) << \SHAR_EOF
d80df9e39ccd94fe3dd70f6664bbdc0a sun8i-emac-module/Config.in
SHAR_EOF

else
test `LC_ALL=C wc -c < 'sun8i-emac-module/Config.in'` -ne 336 && \
${echo} "restoration warning: size of 'sun8i-emac-module/Config.in' is not 336"
fi
fi
# ============= sun8i-emac-module/sun8i-emac-module.mk ==============
if test ! -d 'sun8i-emac-module'; then
mkdir 'sun8i-emac-module'
if test $? -eq 0
then ${echo} "x - created directory sun8i-emac-module."
else ${echo} "x - failed to create directory sun8i-emac-module."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'sun8i-emac-module/sun8i-emac-module.mk'
then
${echo} "x - SKIPPING sun8i-emac-module/sun8i-emac-module.mk (file already exists)"

else
${echo} "x - extracting sun8i-emac-module/sun8i-emac-module.mk (text)"
sed 's/^X//' << 'SHAR_EOF' > 'sun8i-emac-module/sun8i-emac-module.mk' &&
################################################################################
#
# SUN8I_EMAC-module
#
################################################################################
X
SUN8I_EMAC_MODULE_VERSION = 1.0
SUN8I_EMAC_MODULE_SITE = $(TOPDIR)/../sun8i
SUN8I_EMAC_MODULE_SITE_METHOD = local
SUN8I_EMAC_MODULES_LICENSE = LGPLv2.1/GPLv2
X
SUN8I_EMAC_MODULE_DEPENDENCIES = linux
X
define SUN8I_EMAC_MODULE_BUILD_CMDS
X $(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNELDIR=$(LINUX_DIR)
endef
X
define SUN8I_EMAC_MODULE_INSTALL_TARGET_CMDS
X $(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNELDIR=$(LINUX_DIR) modules_install
endef
X
$(eval $(generic-package))
SHAR_EOF
(set 20 16 12 10 00 23 17 'sun8i-emac-module/sun8i-emac-module.mk'
eval "${shar_touch}") && \
chmod 0644 'sun8i-emac-module/sun8i-emac-module.mk'
if test $? -ne 0
then ${echo} "restore of sun8i-emac-module/sun8i-emac-module.mk failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'sun8i-emac-module/sun8i-emac-module.mk': 'MD5 check failed'
) << \SHAR_EOF
575bfa239ba5dfe2947cb0934d54fa45 sun8i-emac-module/sun8i-emac-module.mk
SHAR_EOF

else
test `LC_ALL=C wc -c < 'sun8i-emac-module/sun8i-emac-module.mk'` -ne 651 && \
${echo} "restoration warning: size of 'sun8i-emac-module/sun8i-emac-module.mk' is not 651"
fi
fi
# ============= boot.cmd ==============
if test -n "${keep_file}" && test -f 'boot.cmd'
then
${echo} "x - SKIPPING boot.cmd (file already exists)"

else
${echo} "x - extracting boot.cmd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'boot.cmd' &&
setenv fdt_high ffffffff
X
setenv bootargs console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rootwait
X
fatload mmc 0 $kernel_addr_r zImage
fatload mmc 0 $fdt_addr_r sun8i-h3-orangepi-zero.dtb
X
bootz $kernel_addr_r - $fdt_addr_r
SHAR_EOF
(set 20 17 04 02 01 24 27 'boot.cmd'
eval "${shar_touch}") && \
chmod 0644 'boot.cmd'
if test $? -ne 0
then ${echo} "restore of boot.cmd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'boot.cmd': 'MD5 check failed'
) << \SHAR_EOF
88253a71bd548c6429097d462ad1d234 boot.cmd
SHAR_EOF

else
test `LC_ALL=C wc -c < 'boot.cmd'` -ne 230 && \
${echo} "restoration warning: size of 'boot.cmd' is not 230"
fi
fi
# ============= orangepi_zero_defconfig ==============
if test -n "${keep_file}" && test -f 'orangepi_zero_defconfig'
then
${echo} "x - SKIPPING orangepi_zero_defconfig (file already exists)"

else
${echo} "x - extracting orangepi_zero_defconfig (text)"
sed 's/^X//' << 'SHAR_EOF' > 'orangepi_zero_defconfig' &&
BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_VFPV4=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TARGET_GENERIC_HOSTNAME="OrangePi_Zero"
BR2_TARGET_GENERIC_ISSUE="Welcome to Buildroot for the Orange Pi Zero"
BR2_ROOTFS_OVERLAY="../overlay"
BR2_ROOTFS_POST_BUILD_SCRIPT="board/orangepi/orangepi-zero/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/orangepi/orangepi-zero/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.9"
BR2_LINUX_KERNEL_PATCH="../kernel_patches"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="../kernel.config"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="sun8i-h3-orangepi-zero"
BR2_PACKAGE_OPENSSL=y
BR2_PACKAGE_OPENSSL_BIN=y
BR2_PACKAGE_DROPBEAR=y
BR2_PACKAGE_IW=y
BR2_PACKAGE_WIRELESS_TOOLS=y
BR2_PACKAGE_WIRELESS_TOOLS_LIB=y
BR2_PACKAGE_WPA_SUPPLICANT=y
BR2_PACKAGE_WPA_SUPPLICANT_AP_SUPPORT=y
BR2_PACKAGE_WPA_SUPPLICANT_WIFI_DISPLAY=y
BR2_PACKAGE_WPA_SUPPLICANT_MESH_NETWORKING=y
BR2_PACKAGE_SUN8I_EMAC_MODULE=y
BR2_PACKAGE_XRADIO_MODULE=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_INITRAMFS=y
# BR2_TARGET_ROOTFS_TAR is not set
BR2_TARGET_UBOOT=y
BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y
BR2_TARGET_UBOOT_CUSTOM_VERSION=y
BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2016.11"
BR2_TARGET_UBOOT_BOARD_DEFCONFIG="orangepi_one"
BR2_TARGET_UBOOT_NEEDS_DTC=y
BR2_TARGET_UBOOT_FORMAT_CUSTOM=y
BR2_TARGET_UBOOT_FORMAT_CUSTOM_NAME="u-boot-sunxi-with-spl.bin"
BR2_PACKAGE_HOST_DOSFSTOOLS=y
BR2_PACKAGE_HOST_GENIMAGE=y
BR2_PACKAGE_HOST_MTOOLS=y
BR2_PACKAGE_HOST_UBOOT_TOOLS=y
SHAR_EOF
(set 20 17 04 02 01 39 52 'orangepi_zero_defconfig'
eval "${shar_touch}") && \
chmod 0644 'orangepi_zero_defconfig'
if test $? -ne 0
then ${echo} "restore of orangepi_zero_defconfig failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'orangepi_zero_defconfig': 'MD5 check failed'
) << \SHAR_EOF
ff3471aef33c929ea5a87a449627fac4 orangepi_zero_defconfig
SHAR_EOF

else
test `LC_ALL=C wc -c < 'orangepi_zero_defconfig'` -ne 1630 && \
${echo} "restoration warning: size of 'orangepi_zero_defconfig' is not 1630"
fi
fi
# ============= genimage.cfg ==============
if test -n "${keep_file}" && test -f 'genimage.cfg'
then
${echo} "x - SKIPPING genimage.cfg (file already exists)"

else
${echo} "x - extracting genimage.cfg (text)"
sed 's/^X//' << 'SHAR_EOF' > 'genimage.cfg' &&
# Minimal SD card image for the OrangePi PC
#
image boot.vfat {
X vfat {
X files = {
X "zImage",
X "sun8i-h3-orangepi-zero.dtb",
X "boot.scr"
X }
X }
X size = 10M
}
X
image sdcard.img {
X hdimage {
X }
X
X partition u-boot {
X in-partition-table = "no"
X image = "u-boot-sunxi-with-spl.bin"
X offset = 8192
X size = 1040384 # 1MB - 8192
X }
X
X partition boot {
X partition-type = 0xC
X bootable = "true"
X image = "boot.vfat"
X }
X
X partition rootfs {
X partition-type = 0x83
X image = "rootfs.ext4"
X size = 512M
X }
}
SHAR_EOF
(set 20 17 04 02 00 05 41 'genimage.cfg'
eval "${shar_touch}") && \
chmod 0644 'genimage.cfg'
if test $? -ne 0
then ${echo} "restore of genimage.cfg failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'genimage.cfg': 'MD5 check failed'
) << \SHAR_EOF
9a20e190b3736daec02d450881518e72 genimage.cfg
SHAR_EOF

else
test `LC_ALL=C wc -c < 'genimage.cfg'` -ne 510 && \
${echo} "restoration warning: size of 'genimage.cfg' is not 510"
fi
fi
# ============= xradio-module/xradio-module.mk ==============
if test ! -d 'xradio-module'; then
mkdir 'xradio-module'
if test $? -eq 0
then ${echo} "x - created directory xradio-module."
else ${echo} "x - failed to create directory xradio-module."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'xradio-module/xradio-module.mk'
then
${echo} "x - SKIPPING xradio-module/xradio-module.mk (file already exists)"

else
${echo} "x - extracting xradio-module/xradio-module.mk (text)"
sed 's/^X//' << 'SHAR_EOF' > 'xradio-module/xradio-module.mk' &&
################################################################################
#
# XRADIO-module
#
################################################################################
X
XXRADIO_MODULE_VERSION = 1.0
XXRADIO_MODULE_SITE = $(TOPDIR)/../xradio-master
XXRADIO_MODULE_SITE_METHOD = local
XXRADIO_MODULES_LICENSE = LGPLv2.1/GPLv2
X
$(eval $(kernel-module))
$(eval $(generic-package))
SHAR_EOF
(set 20 17 04 02 02 53 04 'xradio-module/xradio-module.mk'
eval "${shar_touch}") && \
chmod 0644 'xradio-module/xradio-module.mk'
if test $? -ne 0
then ${echo} "restore of xradio-module/xradio-module.mk failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'xradio-module/xradio-module.mk': 'MD5 check failed'
) << \SHAR_EOF
20e4655ff97618a9e606bc73a002ef2a xradio-module/xradio-module.mk
SHAR_EOF

else
test `LC_ALL=C wc -c < 'xradio-module/xradio-module.mk'` -ne 391 && \
${echo} "restoration warning: size of 'xradio-module/xradio-module.mk' is not 391"
fi
fi
# ============= xradio-module/Config.in ==============
if test ! -d 'xradio-module'; then
mkdir 'xradio-module'
if test $? -eq 0
then ${echo} "x - created directory xradio-module."
else ${echo} "x - failed to create directory xradio-module."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'xradio-module/Config.in'
then
${echo} "x - SKIPPING xradio-module/Config.in (file already exists)"

else
${echo} "x - extracting xradio-module/Config.in (text)"
sed 's/^X//' << 'SHAR_EOF' > 'xradio-module/Config.in' &&
config BR2_PACKAGE_XRADIO_MODULE
X bool "xradio-module"
X depends on BR2_LINUX_KERNEL
X help
X Driver for XR819 WiFi in Orange Pi Zero.
X
X https://github.com/fifteenhex/xradio
X
comment "xradio-module needs a Linux kernel to be built"
X depends on !BR2_LINUX_KERNEL
SHAR_EOF
(set 20 17 04 01 23 07 20 'xradio-module/Config.in'
eval "${shar_touch}") && \
chmod 0644 'xradio-module/Config.in'
if test $? -ne 0
then ${echo} "restore of xradio-module/Config.in failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'xradio-module/Config.in': 'MD5 check failed'
) << \SHAR_EOF
35f5cf339d884be8e408595928d43798 xradio-module/Config.in
SHAR_EOF

else
test `LC_ALL=C wc -c < 'xradio-module/Config.in'` -ne 270 && \
${echo} "restoration warning: size of 'xradio-module/Config.in' is not 270"
fi
fi
# ============= kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch ==============
if test ! -d 'kernel_patches'; then
mkdir 'kernel_patches'
if test $? -eq 0
then ${echo} "x - created directory kernel_patches."
else ${echo} "x - failed to create directory kernel_patches."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch'
then
${echo} "x - SKIPPING kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch (file already exists)"

else
${echo} "x - extracting kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch (text)"
sed 's/^X//' << 'SHAR_EOF' > 'kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch' &&
XFrom 3be82b73493e87b0a85adcc66de4b8cccdcc7120 Mon Sep 17 00:00:00 2001
XFrom: "Wojciech M. Zabolotny" <wza...@gmail.com>
Date: Fri, 31 Mar 2017 09:54:28 +0200
Subject: [PATCH] Added support for Ethernet in OrangePI Zero
X
---
X arch/arm/boot/dts/sun8i-h3-orangepi-one.dts | 11 ++++++++++
X arch/arm/boot/dts/sun8i-h3.dtsi | 34 +++++++++++++++++++++++++++++
X 2 files changed, 45 insertions(+)
X
diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
index 5c9b5bf..7c9335d 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-one.dts
@@ -94,6 +94,17 @@
X status = "okay";
X };
X
+&emac {
+ phy = <&phy1>;
+ phy-mode = "mii";
+ allwinner,use-internal-phy;
+ allwinner,leds-active-low;
+ status = "okay";
+ phy1: ethernet-phy@1 {
+ reg = <1>;
+ };
+};
+
X &mmc0 {
X pinctrl-names = "default";
X pinctrl-0 = <&mmc0_pins_a>, <&mmc0_cd_pin>;
diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index f4ba088..364a1ab 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -50,6 +50,10 @@
X / {
X interrupt-parent = <&gic>;
X
+ aliases {
+ ethernet0 = &emac;
+ };
+
X cpus {
X #address-cells = <1>;
X #size-cells = <0>;
@@ -140,6 +144,11 @@
X #size-cells = <1>;
X ranges;
X
+ syscon: syscon@01c00000 {
+ compatible = "allwinner,sun8i-h3-syscon","syscon";
+ reg = <0x01c00000 0x34>;
+ };
+
X dma: dma-controller@01c02000 {
X compatible = "allwinner,sun8i-h3-dma";
X reg = <0x01c02000 0x1000>;
@@ -348,6 +357,17 @@
X allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
X };
X
+ emac_rgmii_pins: emac0@0 {
+ allwinner,pins = "PD0", "PD1", "PD2", "PD3",
+ "PD4", "PD5", "PD7",
+ "PD8", "PD9", "PD10",
+ "PD12", "PD13", "PD15",
+ "PD16", "PD17";
+ allwinner,function = "emac";
+ allwinner,drive = <SUN4I_PINCTRL_40_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
+ };
+
X mmc0_pins_a: mmc0@0 {
X allwinner,pins = "PF0", "PF1", "PF2", "PF3",
X "PF4", "PF5";
@@ -491,6 +511,20 @@
X status = "disabled";
X };
X
+ emac: ethernet@1c30000 {
+ compatible = "allwinner,sun8i-h3-emac";
+ reg = <0x01c30000 0x104>, <0x01c00030 0x4>;
+ reg-names = "emac", "syscon";
+ interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>;
+ resets = <&ccu RST_BUS_EMAC>, <&ccu RST_BUS_EPHY>;
+ reset-names = "ahb", "ephy";
+ clocks = <&ccu CLK_BUS_EMAC>, <&ccu CLK_BUS_EPHY>;
+ clock-names = "ahb", "ephy";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "disabled";
+ };
+
X i2c0: i2c@01c2ac00 {
X compatible = "allwinner,sun6i-a31-i2c";
X reg = <0x01c2ac00 0x400>;
--
2.11.0
X
SHAR_EOF
(set 20 17 03 31 09 54 54 'kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch'
eval "${shar_touch}") && \
chmod 0644 'kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch'
if test $? -ne 0
then ${echo} "restore of kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch': 'MD5 check failed'
) << \SHAR_EOF
4e8acee795e76d9780ea199aefe60006 kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch
SHAR_EOF

else
test `LC_ALL=C wc -c < 'kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch'` -ne 2688 && \
${echo} "restoration warning: size of 'kernel_patches/0001-Added-support-for-Ethernet-in-OrangePI-Zero.patch' is not 2688"
fi
fi
# ============= kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch ==============
if test ! -d 'kernel_patches'; then
mkdir 'kernel_patches'
if test $? -eq 0
then ${echo} "x - created directory kernel_patches."
else ${echo} "x - failed to create directory kernel_patches."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch'
then
${echo} "x - SKIPPING kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch (file already exists)"

else
${echo} "x - extracting kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch (text)"
sed 's/^X//' << 'SHAR_EOF' > 'kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch' &&
XFrom ae3167efc7b0133f339d364220f8577ac80cb2fa Mon Sep 17 00:00:00 2001
XFrom: "Wojciech M. Zabolotny" <wza...@gmail.com>
Date: Sat, 1 Apr 2017 23:33:10 +0200
Subject: [PATCH] Added DTS for Orange Pi Zero with WiFi
X
The DTS for Orange Pi Zero with WiFi was taken from
https://github.com/igorpecovnik/lib/blob/master/patch/kernel/sun8i-dev/add-opi-zero-dts-with-wireless.patch
---
X arch/arm/boot/dts/sun8i-h3-orangepi-zero.dts | 77 ++++++++++++++++++++++++++++
X 1 file changed, 77 insertions(+)
X create mode 100644 arch/arm/boot/dts/sun8i-h3-orangepi-zero.dts
X
diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-zero.dts b/arch/arm/boot/dts/sun8i-h3-orangepi-zero.dts
new file mode 100644
index 0000000..bab2536
--- /dev/null
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-zero.dts
@@ -0,0 +1,77 @@
+#include "sun8i-h3-orangepi-one.dts"
+
+/ {
+ model = "Xunlong Orange Pi Zero";
+ compatible = "xunlong,orangepi-zero", "allwinner,sun8i-h2plus", "allwinner,sun8i-h3";
+
+ aliases {
+ ethernet1 = &xr819wifi;
+ };
+
+ leds {
+ pinctrl-names = "default";
+ pinctrl-0 = <&leds_r_opc>;
+
+ /delete-node/ status_led;
+ };
+
+ vdd_wifi: vdd_wifi@0 {
+ compatible = "regulator-fixed";
+ regulator-name = "wifi";
+ regulator-min-microvolt = <1800000>;
+ regulator-max-microvolt = <1800000>;
+ gpio = <&pio 0 20 GPIO_ACTIVE_HIGH>;
+ startup-delay-us = <70000>;
+ enable-active-high;
+ };
+
+ wifi_pwrseq: wifi_pwrseq {
+ compatible = "mmc-pwrseq-simple";
+ pinctrl-names = "default";
+ pinctrl-0 = <&wifi_pwrseq_pin_orangepi>;
+ reset-gpios = <&r_pio 0 7 GPIO_ACTIVE_LOW>;
+ post-power-on-delay-ms = <50>;
+ };
+};
+
+&mmc1 {
+ pinctrl-names = "default";
+ pinctrl-0 = <&mmc1_pins_a>;
+ vmmc-supply = <&reg_vcc3v3>;
+ vqmmc-supply = <&vdd_wifi>;
+ mmc-pwrseq = <&wifi_pwrseq>;
+ bus-width = <4>;
+ non-removable;
+ status = "okay";
+
+ xr819wifi: xr819wifi@1 {
+ reg = <1>;
+ compatible = "xradio,xr819";
+ pinctrl-names = "default";
+ pinctrl-0 = <&wifi_wake>;
+ interrupt-parent = <&pio>;
+ interrupts = <6 10 IRQ_TYPE_EDGE_RISING>;
+ interrupt-names = "host-wake";
+ local-mac-address = [dc 44 6d c0 ff ee];
+ };
+};
+
+&pio {
+ /delete-node/ leds_opc;
+
+ wifi_wake: wifi_wake@0 {
+ allwinner,pins = "PG10";
+ allwinner,function = "irq";
+ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
+ };
+};
+
+&r_pio {
+ wifi_pwrseq_pin_orangepi: wifi_pwrseq_pin@0 {
+ allwinner,pins = "PL7";
+ allwinner,function = "gpio_out";
+ allwinner,drive = <SUN4I_PINCTRL_10_MA>;
+ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
+ };
+};
+
--
2.11.0
X
SHAR_EOF
(set 20 17 04 01 23 34 28 'kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch'
eval "${shar_touch}") && \
chmod 0644 'kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch'
if test $? -ne 0
then ${echo} "restore of kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch': 'MD5 check failed'
) << \SHAR_EOF
5edc358952b079bc6a9117e0c71dca7b kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch
SHAR_EOF

else
test `LC_ALL=C wc -c < 'kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch'` -ne 2636 && \
${echo} "restoration warning: size of 'kernel_patches/0002-Added-DTS-for-Orange-Pi-Zero-with-WiFi.patch' is not 2636"
fi
fi
# ============= sun8i/Makefile ==============
if test ! -d 'sun8i'; then
mkdir 'sun8i'
if test $? -eq 0
then ${echo} "x - created directory sun8i."
else ${echo} "x - failed to create directory sun8i."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'sun8i/Makefile'
then
${echo} "x - SKIPPING sun8i/Makefile (file already exists)"

else
${echo} "x - extracting sun8i/Makefile (text)"
sed 's/^X//' << 'SHAR_EOF' > 'sun8i/Makefile' &&
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
X obj-m := sun8i-emac.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
X KERNELDIR ?= /lib/modules/$(shell uname -r)/build
X PWD := $(shell pwd)
default:
X $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
X
modules_install:
X $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
X
clean:
X $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
X
endif
X
SHAR_EOF
(set 20 16 12 10 00 19 54 'sun8i/Makefile'
eval "${shar_touch}") && \
chmod 0644 'sun8i/Makefile'
if test $? -ne 0
then ${echo} "restore of sun8i/Makefile failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'sun8i/Makefile': 'MD5 check failed'
) << \SHAR_EOF
282e309dfc573669bd5846e44d7a82bd sun8i/Makefile
SHAR_EOF

else
test `LC_ALL=C wc -c < 'sun8i/Makefile'` -ne 525 && \
${echo} "restoration warning: size of 'sun8i/Makefile' is not 525"
fi
fi
# ============= sun8i/sun8i-emac.c ==============
if test ! -d 'sun8i'; then
mkdir 'sun8i'
if test $? -eq 0
then ${echo} "x - created directory sun8i."
else ${echo} "x - failed to create directory sun8i."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'sun8i/sun8i-emac.c'
then
${echo} "x - SKIPPING sun8i/sun8i-emac.c (file already exists)"

else
${echo} "x - extracting sun8i/sun8i-emac.c (text)"
sed 's/^X//' << 'SHAR_EOF' > 'sun8i/sun8i-emac.c' &&
/*
X * sun8i-emac driver
X *
X * Copyright (C) 2015-2016 Corentin LABBE <clabb...@gmail.com>
X *
X * This is the driver for Allwinner Ethernet MAC found in H3/A83T/A64 SoC
X *
X * TODO:
X * - NAPI
X * - MAC filtering
X * - Jumbo frame
X * - features rx-all (NETIF_F_RXALL_BIT)
X */
#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/etherdevice.h>
#include <linux/interrupt.h>
#include <linux/iopoll.h>
#include <linux/mii.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/of_device.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include <linux/phy.h>
#include <linux/pinctrl/consumer.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/reset.h>
#include <linux/scatterlist.h>
#include <linux/skbuff.h>
X
#define SUN8I_EMAC_BASIC_CTL0 0x00
#define SUN8I_EMAC_BASIC_CTL1 0x04
X
#define SUN8I_EMAC_MDIO_CMD 0x48
#define SUN8I_EMAC_MDIO_DATA 0x4C
X
#define SUN8I_EMAC_RX_CTL0 0x24
#define SUN8I_EMAC_RX_CTL1 0x28
X
#define SUN8I_EMAC_TX_CTL0 0x10
#define SUN8I_EMAC_TX_CTL1 0x14
X
#define SUN8I_EMAC_TX_FLOW_CTL 0x1C
X
#define SUN8I_EMAC_RX_FRM_FLT 0x38
X
#define SUN8I_EMAC_INT_STA 0x08
#define SUN8I_EMAC_INT_EN 0x0C
#define SUN8I_EMAC_RGMII_STA 0xD0
X
#define SUN8I_EMAC_TX_DMA_STA 0xB0
#define SUN8I_EMAC_TX_CUR_DESC 0xB4
#define SUN8I_EMAC_TX_CUR_BUF 0xB8
#define SUN8I_EMAC_RX_DMA_STA 0xC0
X
#define MDIO_CMD_MII_BUSY BIT(0)
#define MDIO_CMD_MII_WRITE BIT(1)
#define MDIO_CMD_MII_PHY_REG_ADDR_MASK GENMASK(8, 4)
#define MDIO_CMD_MII_PHY_REG_ADDR_SHIFT 4
#define MDIO_CMD_MII_PHY_ADDR_MASK GENMASK(16, 12)
#define MDIO_CMD_MII_PHY_ADDR_SHIFT 12
X
#define SUN8I_EMAC_MACADDR_HI 0x50
#define SUN8I_EMAC_MACADDR_LO 0x54
X
#define SUN8I_EMAC_RX_DESC_LIST 0x34
#define SUN8I_EMAC_TX_DESC_LIST 0x20
X
#define SUN8I_EMAC_TX_DO_CRC (BIT(27) | BIT(28))
#define SUN8I_EMAC_RX_DO_CRC BIT(27)
#define SUN8I_EMAC_RX_STRIP_FCS BIT(28)
X
#define SUN8I_COULD_BE_USED_BY_DMA BIT(31)
X
#define FLOW_RX 1
#define FLOW_TX 2
X
/* describe how data from skb are DMA mapped */
#define MAP_SINGLE 1
#define MAP_PAGE 2
X
enum emac_variant {
X A83T_EMAC,
X H3_EMAC,
X A64_EMAC,
};
X
struct ethtool_str {
X char name[ETH_GSTRING_LEN];
};
X
static const struct ethtool_str estats_str[] = {
X /* errors */
X { "rx_payload_error" },
X { "rx_CRC_error" },
X { "rx_phy_error" },
X { "rx_length_error" },
X { "rx_col_error" },
X { "rx_header_error" },
X { "rx_overflow_error" },
X { "rx_saf_error" },
X { "rx_daf_error" },
X { "rx_buf_error" },
X /* misc infos */
X { "tx_stop_queue" },
X { "rx_dma_ua" },
X { "rx_dma_stop" },
X { "tx_dma_ua" },
X { "tx_dma_stop" },
X { "rx_hw_csum" },
X { "tx_hw_csum" },
X /* interrupts */
X { "rx_early_int" },
X { "tx_early_int" },
X { "tx_underflow_int" },
X /* debug */
X { "tx_used_desc" },
};
X
struct sun8i_emac_stats {
X u64 rx_payload_error;
X u64 rx_crc_error;
X u64 rx_phy_error;
X u64 rx_length_error;
X u64 rx_col_error;
X u64 rx_header_error;
X u64 rx_overflow_error;
X u64 rx_saf_fail;
X u64 rx_daf_fail;
X u64 rx_buf_error;
X
X u64 tx_stop_queue;
X u64 rx_dma_ua;
X u64 rx_dma_stop;
X u64 tx_dma_ua;
X u64 tx_dma_stop;
X u64 rx_hw_csum;
X u64 tx_hw_csum;
X
X u64 rx_early_int;
X u64 tx_early_int;
X u64 tx_underflow_int;
X u64 tx_used_desc;
};
X
/* The datasheet said that each descriptor can transfers up to 4096bytes
X * But latter, a register documentation reduce that value to 2048
X * Anyway using 2048 cause strange behaviours and even BSP driver use 2047
X */
#define DESC_BUF_MAX 2044
#if (DESC_BUF_MAX < (ETH_FRAME_LEN + 4))
#error "DESC_BUF_MAX must be set at minimum to ETH_FRAME_LEN + 4"
#endif
X
/* MAGIC value for knowing if a descriptor is available or not */
#define DCLEAN (BIT(16) | BIT(14) | BIT(12) | BIT(10) | BIT(9))
X
/* Structure of DMA descriptor used by the hardware */
struct dma_desc {
X u32 status; /* status of the descriptor */
X u32 st; /* Information on the frame */
X u32 buf_addr; /* physical address of the frame data */
X u32 next; /* physical address of next dma_desc */
} __packed __aligned(4);
X
/* Benched on OPIPC with 100M, setting more than 256 does not give any
X * perf boost
X */
static int nbdesc_tx = 256;
module_param(nbdesc_tx, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(nbdesc_tx, "Number of descriptors in the TX list");
static int nbdesc_rx = 128;
module_param(nbdesc_rx, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(nbdesc_rx, "Number of descriptors in the RX list");
X
struct sun8i_emac_priv {
X void __iomem *base;
X void __iomem *syscon;
X int irq;
X struct device *dev;
X struct net_device *ndev;
X struct mii_bus *mdio;
X spinlock_t lock;/* for adjust_link */
X spinlock_t tx_lock;/* control the access of transmit descriptors */
X int duplex;
X int speed;
X int link;
X int phy_interface;
X enum emac_variant variant;
X struct device_node *phy_node;
X struct clk *ahb_clk;
X struct clk *ephy_clk;
X struct regulator *regulator;
X struct regulator *regulator_io;
X bool use_internal_phy;
X
X struct reset_control *rst;
X struct reset_control *rst_ephy;
X
X struct dma_desc *dd_rx __aligned(4);
X dma_addr_t dd_rx_phy __aligned(4);
X struct dma_desc *dd_tx __aligned(4);
X dma_addr_t dd_tx_phy __aligned(4);
X struct sk_buff **rx_sk;
X struct sk_buff **tx_sk;
X int *tx_map;
X
X int tx_slot;
X int tx_dirty;
X int rx_dirty;
X struct sun8i_emac_stats estats;
X u32 msg_enable;
X int flow_ctrl;
X int pause;
};
X
static void rb_inc(int *p, const int max)
{
X (*p)++;
X if (*p >= max)
X *p = 0;
}
X
/* Return the number of contiguous free descriptors
X * starting from tx_slot
X */
static int rb_tx_numfreedesc(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X if (priv->tx_slot < priv->tx_dirty)
X return priv->tx_dirty - priv->tx_slot;
X
X return (nbdesc_tx - priv->tx_slot) + priv->tx_dirty;
}
X
/* Allocate a skb in a DMA descriptor
X *
X * @i index of slot to fill
*/
static int sun8i_emac_rx_sk(struct net_device *ndev, int i)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct dma_desc *ddesc;
X struct sk_buff *sk;
X
X ddesc = priv->dd_rx + i;
X
X ddesc->st = 0;
X
X sk = netdev_alloc_skb_ip_align(ndev, DESC_BUF_MAX);
X if (!sk)
X return -ENOMEM;
X
X /* should not happen */
X if (unlikely(priv->rx_sk[i]))
X dev_warn(priv->dev, "BUG: Leaking a skbuff\n");
X
X priv->rx_sk[i] = sk;
X
X ddesc->buf_addr = dma_map_single(priv->dev, sk->data,
X DESC_BUF_MAX, DMA_FROM_DEVICE);
X if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
X dev_err(priv->dev, "ERROR: Cannot dma_map RX buffer\n");
X dev_kfree_skb(sk);
X return -EFAULT;
X }
X ddesc->st |= DESC_BUF_MAX;
X ddesc->status = BIT(31);
X
X return 0;
}
X
/* Set MAC address for slot index
X * @addr: the MAC address to set
X * @index: The index of slot where to set address.
X * The slot 0 is the main MACaddr
X */
static void sun8i_emac_set_macaddr(struct sun8i_emac_priv *priv,
X const u8 *addr, int index)
{
X u32 v;
X
X dev_info(priv->dev, "device MAC address slot %d %02x:%02x:%02x:%02x:%02x:%02x\n",
X index, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
X
X v = (addr[5] << 8) | addr[4];
X writel(v, priv->base + SUN8I_EMAC_MACADDR_HI + index * 8);
X v = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
X writel(v, priv->base + SUN8I_EMAC_MACADDR_LO + index * 8);
}
X
static void sun8i_emac_set_link_mode(struct sun8i_emac_priv *priv)
{
X u32 v;
X
X v = readl(priv->base + SUN8I_EMAC_BASIC_CTL0);
X
X if (priv->duplex)
X v |= BIT(0);
X else
X v &= ~BIT(0);
X
X v &= ~0x0C;
X switch (priv->speed) {
X case 1000:
X break;
X case 100:
X v |= BIT(2);
X v |= BIT(3);
X break;
X case 10:
X v |= BIT(3);
X break;
X }
X
X writel(v, priv->base + SUN8I_EMAC_BASIC_CTL0);
}
X
static void sun8i_emac_flow_ctrl(struct sun8i_emac_priv *priv, int duplex,
X int fc, int pause)
{
X u32 flow = 0;
X
X netif_dbg(priv, link, priv->ndev, "%s %d %d %d\n", __func__,
X duplex, fc, pause);
X
X flow = readl(priv->base + SUN8I_EMAC_RX_CTL0);
X if (fc & FLOW_RX)
X flow |= BIT(16);
X else
X flow &= ~BIT(16);
X writel(flow, priv->base + SUN8I_EMAC_RX_CTL0);
X
X flow = readl(priv->base + SUN8I_EMAC_TX_FLOW_CTL);
X if (fc & FLOW_TX)
X flow |= BIT(0);
X else
X flow &= ~BIT(0);
X writel(flow, priv->base + SUN8I_EMAC_TX_FLOW_CTL);
}
X
/* Grab a frame into a skb from descriptor number i */
static int sun8i_emac_rx_from_ddesc(struct net_device *ndev, int i)
{
X struct sk_buff *skb;
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct dma_desc *ddesc = priv->dd_rx + i;
X int frame_len;
X int crc_checked = 0;
X
X if (ndev->features & NETIF_F_RXCSUM)
X crc_checked = 1;
X
X /* bit0/bit7 work only on IPv4/IPv6 TCP traffic,
X * (not on ARP for example) so we dont raise rx_errors/discard frame
X */
X /* the checksum or length of received frame's payload is wrong*/
X if (ddesc->status & BIT(0)) {
X priv->estats.rx_payload_error++;
X crc_checked = 0;
X }
X if (ddesc->status & BIT(1)) {
X priv->ndev->stats.rx_errors++;
X priv->ndev->stats.rx_crc_errors++;
X priv->estats.rx_crc_error++;
X goto discard_frame;
X }
X if ((ddesc->status & BIT(3))) {
X priv->ndev->stats.rx_errors++;
X priv->estats.rx_phy_error++;
X goto discard_frame;
X }
X if ((ddesc->status & BIT(4))) {
X priv->ndev->stats.rx_errors++;
X priv->ndev->stats.rx_length_errors++;
X priv->estats.rx_length_error++;
X goto discard_frame;
X }
X if ((ddesc->status & BIT(6))) {
X priv->ndev->stats.rx_errors++;
X priv->estats.rx_col_error++;
X goto discard_frame;
X }
X if ((ddesc->status & BIT(7))) {
X priv->estats.rx_header_error++;
X crc_checked = 0;
X }
X if ((ddesc->status & BIT(11))) {
X priv->ndev->stats.rx_over_errors++;
X priv->estats.rx_overflow_error++;
X goto discard_frame;
X }
X if ((ddesc->status & BIT(14))) {
X priv->ndev->stats.rx_errors++;
X priv->estats.rx_buf_error++;
X goto discard_frame;
X }
X
X if ((ddesc->status & BIT(9)) == 0) {
X /* begin of a Jumbo frame */
X dev_warn(priv->dev, "This should not happen\n");
X goto discard_frame;
X }
X frame_len = (ddesc->status >> 16) & 0x3FFF;
X if (!(ndev->features & NETIF_F_RXFCS))
X frame_len -= ETH_FCS_LEN;
X
X skb = priv->rx_sk[i];
X
X netif_dbg(priv, rx_status, priv->ndev,
X "%s from %02d %pad len=%d status=%x st=%x\n",
X __func__, i, &ddesc, frame_len, ddesc->status, ddesc->st);
X
X skb_put(skb, frame_len);
X
X dma_unmap_single(priv->dev, ddesc->buf_addr, DESC_BUF_MAX,
X DMA_FROM_DEVICE);
X skb->protocol = eth_type_trans(skb, priv->ndev);
X if (crc_checked) {
X skb->ip_summed = CHECKSUM_UNNECESSARY;
X priv->estats.rx_hw_csum++;
X } else {
X skb->ip_summed = CHECKSUM_PARTIAL;
X }
X skb->dev = priv->ndev;
X
X priv->ndev->stats.rx_packets++;
X priv->ndev->stats.rx_bytes += frame_len;
X priv->rx_sk[i] = NULL;
X
X /* this frame is not the last */
X if ((ddesc->status & BIT(8)) == 0) {
X dev_warn(priv->dev, "Multi frame not implemented currlen=%d\n",
X frame_len);
X }
X
X sun8i_emac_rx_sk(ndev, i);
X
X netif_rx(skb);
X
X return 0;
X /* If the frame need to be dropped, we simply reuse the buffer */
discard_frame:
X ddesc->st = DESC_BUF_MAX;
X ddesc->status = BIT(31);
X return 0;
}
X
/* Cycle over RX DMA descriptors for finding frame to receive
X */
static int sun8i_emac_receive_all(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct dma_desc *ddesc;
X
X ddesc = priv->dd_rx + priv->rx_dirty;
X while (!(ddesc->status & BIT(31))) {
X sun8i_emac_rx_from_ddesc(ndev, priv->rx_dirty);
X rb_inc(&priv->rx_dirty, nbdesc_rx);
X ddesc = priv->dd_rx + priv->rx_dirty;
X };
X
X return 0;
}
X
/* iterate over dma_desc for finding completed xmit.
X * Called from interrupt context, so no need to spinlock tx
X *
X * The problem is: how to know that a descriptor is sent and not just in
X * preparation.
X * Need to have status=0 and st set but this is the state of first frame just
X * before setting the own-by-DMA bit.
X * The solution is to used the artificial value DCLEAN.
X */
static int sun8i_emac_complete_xmit(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct dma_desc *ddesc;
X int frame_len;
X
X do {
X ddesc = priv->dd_tx + priv->tx_dirty;
X
X if (ddesc->status & BIT(31)) {
X dev_info(priv->dev, "BUG: DMA still set %d %d\n",
X priv->tx_dirty, priv->tx_slot);
X return 0;
X }
X
X if (ddesc->status == DCLEAN)
X return 0;
X
X if (ddesc->status == 0 && !ddesc->st) {
X dev_info(priv->dev, "BUG: reached the void %d %d\n",
X priv->tx_dirty, priv->tx_slot);
X return 0;
X }
X
X /* TX_UNDERFLOW_ERR */
X if (ddesc->status & BIT(1))
X priv->ndev->stats.tx_errors++;
X /* TX_DEFER_ERR */
X if (ddesc->status & BIT(2))
X priv->ndev->stats.tx_errors++;
X /* BIT 6:3 numbers of collisions */
X if (ddesc->status & 0x78)
X priv->ndev->stats.collisions +=
X (ddesc->status & 0x78) >> 3;
X /* TX_COL_ERR_1 */
X if (ddesc->status & BIT(8))
X priv->ndev->stats.tx_errors++;
X /* TX_COL_ERR_0 */
X if (ddesc->status & BIT(9))
X priv->ndev->stats.tx_errors++;
X /* TX_CRS_ERR */
X if (ddesc->status & BIT(10))
X priv->ndev->stats.tx_carrier_errors++;
X /* TX_PAYLOAD_ERR */
X if (ddesc->status & BIT(12))
X priv->ndev->stats.tx_errors++;
X /* TX_LENGTH_ERR */
X if (ddesc->status & BIT(14))
X priv->ndev->stats.tx_errors++;
X /* TX_HEADER_ERR */
X if (ddesc->status & BIT(16))
X priv->ndev->stats.tx_errors++;
X frame_len = ddesc->st & 0x3FFF;
X if (priv->tx_map[priv->tx_dirty] == MAP_SINGLE)
X dma_unmap_single(priv->dev, ddesc->buf_addr,
X frame_len, DMA_TO_DEVICE);
X else
X dma_unmap_page(priv->dev, ddesc->buf_addr,
X frame_len, DMA_TO_DEVICE);
X /* we can free skb only on last frame */
X if (priv->tx_sk[priv->tx_dirty] && (ddesc->st & BIT(30)))
X dev_kfree_skb_irq(priv->tx_sk[priv->tx_dirty]);
X
X priv->tx_sk[priv->tx_dirty] = NULL;
X priv->tx_map[priv->tx_dirty] = 0;
X ddesc->status = DCLEAN;
X ddesc->st = 0;
X
X rb_inc(&priv->tx_dirty, nbdesc_tx);
X ddesc = priv->dd_tx + priv->tx_dirty;
X } while (ddesc->st && !(ddesc->status & BIT(31)));
X
X if (netif_queue_stopped(ndev) &&
X rb_tx_numfreedesc(ndev) > MAX_SKB_FRAGS + 1)
X netif_wake_queue(ndev);
X
X return 0;
}
X
static int sun8i_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg)
{
X struct net_device *ndev = bus->priv;
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X int err;
X u32 reg;
X
X err = readl_poll_timeout(priv->base + SUN8I_EMAC_MDIO_CMD, reg,
X !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
X if (err) {
X dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
X return err;
X }
X
X reg &= ~MDIO_CMD_MII_WRITE;
X reg &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
X reg |= (phy_reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
X MDIO_CMD_MII_PHY_REG_ADDR_MASK;
X
X reg &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
X
X reg |= (phy_addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
X MDIO_CMD_MII_PHY_ADDR_MASK;
X
X reg |= MDIO_CMD_MII_BUSY;
X
X writel(reg, priv->base + SUN8I_EMAC_MDIO_CMD);
X
X err = readl_poll_timeout(priv->base + SUN8I_EMAC_MDIO_CMD, reg,
X !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
X
X if (err) {
X dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
X return err;
X }
X
X return readl(priv->base + SUN8I_EMAC_MDIO_DATA);
}
X
static int sun8i_mdio_write(struct mii_bus *bus, int phy_addr, int phy_reg,
X u16 data)
{
X struct net_device *ndev = bus->priv;
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X u32 reg;
X int err;
X
X err = readl_poll_timeout(priv->base + SUN8I_EMAC_MDIO_CMD, reg,
X !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
X if (err) {
X dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
X return err;
X }
X
X reg &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
X reg |= (phy_reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
X MDIO_CMD_MII_PHY_REG_ADDR_MASK;
X
X reg &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
X reg |= (phy_addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
X MDIO_CMD_MII_PHY_ADDR_MASK;
X
X reg |= MDIO_CMD_MII_WRITE;
X reg |= MDIO_CMD_MII_BUSY;
X
X writel(reg, priv->base + SUN8I_EMAC_MDIO_CMD);
X writel(data, priv->base + SUN8I_EMAC_MDIO_DATA);
X dev_dbg(priv->dev, "%s %d %d %x %x\n", __func__, phy_addr, phy_reg,
X reg, data);
X
X err = readl_poll_timeout(priv->base + SUN8I_EMAC_MDIO_CMD, reg,
X !(reg & MDIO_CMD_MII_BUSY), 100, 10000);
X if (err) {
X dev_err(priv->dev, "%s timeout %x\n", __func__, reg);
X return err;
X }
X
X return 0;
}
X
static int sun8i_emac_mdio_register(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct mii_bus *bus;
X int ret;
X
X bus = devm_mdiobus_alloc(priv->dev);
X if (!bus) {
X netdev_err(ndev, "Failed to allocate new mdio bus\n");
X return -ENOMEM;
X }
X
X bus->name = dev_name(priv->dev);
X bus->read = &sun8i_mdio_read;
X bus->write = &sun8i_mdio_write;
X snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%x", bus->name, 0);
X
X bus->parent = priv->dev;
X bus->priv = ndev;
X
X ret = of_mdiobus_register(bus, priv->dev->of_node);
X if (ret) {
X netdev_err(ndev, "Could not register as MDIO bus: %d\n", ret);
X return ret;
X }
X
X priv->mdio = bus;
X
X return 0;
}
X
static void sun8i_emac_adjust_link(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct phy_device *phydev = ndev->phydev;
X unsigned long flags;
X int new_state = 0;
X
X netif_dbg(priv, link, priv->ndev,
X "%s link=%x duplex=%x speed=%x\n", __func__,
X phydev->link, phydev->duplex, phydev->speed);
X if (!phydev)
X return;
X
X spin_lock_irqsave(&priv->lock, flags);
X
X if (phydev->link) {
X if (phydev->duplex != priv->duplex) {
X new_state = 1;
X priv->duplex = phydev->duplex;
X }
X if (phydev->pause)
X sun8i_emac_flow_ctrl(priv, phydev->duplex,
X priv->flow_ctrl, priv->pause);
X
X if (phydev->speed != priv->speed) {
X new_state = 1;
X priv->speed = phydev->speed;
X }
X
X if (priv->link == 0) {
X new_state = 1;
X priv->link = phydev->link;
X }
X
X netif_dbg(priv, link, priv->ndev,
X "%s new=%d link=%d pause=%d\n",
X __func__, new_state, priv->link, phydev->pause);
X if (new_state)
X sun8i_emac_set_link_mode(priv);
X } else if (priv->link != phydev->link) {
X new_state = 1;
X priv->link = 0;
X priv->speed = 0;
X priv->duplex = -1;
X }
X
X if (new_state)
X phy_print_status(phydev);
X
X spin_unlock_irqrestore(&priv->lock, flags);
}
X
/* H3 specific bits for EPHY */
#define H3_EPHY_ADDR_SHIFT 20
#define H3_EPHY_LED_POL BIT(17) /* 1: active low, 0: active high */
#define H3_EPHY_SHUTDOWN BIT(16) /* 1: shutdown, 0: power up */
#define H3_EPHY_SELECT BIT(15) /* 1: internal PHY, 0: external PHY */
#define H3_EPHY_DEFAULT_VALUE 0x58000
#define H3_EPHY_DEFAULT_MASK GENMASK(31, 15)
X
/* H3/A64 specific bits */
#define SC_RMII_EN BIT(13) /* 1: enable RMII (overrides EPIT) */
X
/* Generic system control EMAC_CLK bits */
#define SC_ETXDC_MASK GENMASK(2, 0)
#define SC_ETXDC_SHIFT 10
#define SC_ERXDC_MASK GENMASK(4, 0)
#define SC_ERXDC_SHIFT 5
#define SC_EPIT BIT(2) /* 1: RGMII, 0: MII */
#define SC_ETCS_MASK GENMASK(1, 0)
#define SC_ETCS_MII 0x0
#define SC_ETCS_EXT_GMII 0x1
#define SC_ETCS_INT_GMII 0x2
X
static int sun8i_emac_set_syscon_ephy(struct net_device *ndev, u32 *reg)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct device_node *node = priv->dev->of_node;
X int ret;
X
X *reg &= ~H3_EPHY_DEFAULT_MASK;
X *reg |= H3_EPHY_DEFAULT_VALUE;
X
X if (!priv->use_internal_phy) {
X /* switch to external PHY interface */
X *reg &= ~H3_EPHY_SELECT;
X return 0;
X }
X
X if (priv->phy_interface != PHY_INTERFACE_MODE_MII) {
X netdev_warn(ndev,
X "Internal PHY requested, forcing MII mode.\n");
X priv->phy_interface = PHY_INTERFACE_MODE_MII;
X }
X
X *reg |= H3_EPHY_SELECT;
X *reg &= ~H3_EPHY_SHUTDOWN;
X
X if (of_property_read_bool(node, "allwinner,leds-active-low"))
X *reg |= H3_EPHY_LED_POL;
X
X ret = of_mdio_parse_addr(priv->dev, priv->phy_node);
X if (ret < 0)
X return ret;
X
X /* of_mdio_parse_addr returns a valid (0 ~ 31) PHY
X * address. No need to mask it again.
X */
X *reg |= ret << H3_EPHY_ADDR_SHIFT;
X
X return 0;
}
X
static int sun8i_emac_set_syscon(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct device_node *node = priv->dev->of_node;
X int ret;
X u32 reg, val;
X
X reg = readl(priv->syscon);
X
X if (priv->variant == H3_EMAC) {
X ret = sun8i_emac_set_syscon_ephy(ndev, &reg);
X if (ret)
X return ret;
X }
X
X if (!of_property_read_u32(node, "allwinner,tx-delay", &val)) {
X if (val <= SC_ETXDC_MASK) {
X reg &= ~(SC_ETXDC_MASK << SC_ETXDC_SHIFT);
X reg |= (val << SC_ETXDC_SHIFT);
X } else {
X netdev_warn(ndev, "invalid TX clock delay: %d\n", val);
X }
X }
X
X if (!of_property_read_u32(node, "allwinner,rx-delay", &val)) {
X if (val <= SC_ERXDC_MASK) {
X reg &= ~(SC_ERXDC_MASK << SC_ERXDC_SHIFT);
X reg |= (val << SC_ERXDC_SHIFT);
X } else {
X netdev_warn(ndev, "invalid RX clock delay: %d\n", val);
X }
X }
X
X /* Clear interface mode bits */
X reg &= ~(SC_ETCS_MASK | SC_EPIT);
X if (priv->variant == H3_EMAC || priv->variant == A64_EMAC)
X reg &= ~SC_RMII_EN;
X
X switch (priv->phy_interface) {
X case PHY_INTERFACE_MODE_MII:
X /* default */
X break;
X case PHY_INTERFACE_MODE_RGMII:
X reg |= SC_EPIT | SC_ETCS_INT_GMII;
X break;
X case PHY_INTERFACE_MODE_RMII:
X if (priv->variant == H3_EMAC || priv->variant == A64_EMAC) {
X reg |= SC_RMII_EN | SC_ETCS_EXT_GMII;
X break;
X }
X /* RMII not supported on A83T */
X default:
X netdev_err(ndev, "unsupported interface mode: %s",
X phy_modes(priv->phy_interface));
X return -EINVAL;
X }
X
X writel(reg, priv->syscon);
X
X return 0;
}
X
static void sun8i_emac_unset_syscon(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X u32 reg = 0;
X
X if (priv->variant == H3_EMAC)
X reg = H3_EPHY_DEFAULT_VALUE;
X
X writel(reg, priv->syscon);
}
X
static void sun8i_emac_set_mdc(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X unsigned long rate;
X u32 reg;
X
X rate = clk_get_rate(priv->ahb_clk);
X if (rate > 160000000)
X reg = 0x3 << 20; /* AHB / 128 */
X else if (rate > 80000000)
X reg = 0x2 << 20; /* AHB / 64 */
X else if (rate > 40000000)
X reg = 0x1 << 20; /* AHB / 32 */
X else
X reg = 0x0 << 20; /* AHB / 16 */
X netif_dbg(priv, link, ndev, "MDC auto : %x\n", reg);
X writel(reg, priv->base + SUN8I_EMAC_MDIO_CMD);
}
X
static int sun8i_emac_init(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct device_node *node = priv->dev->of_node;
X const u8 *addr;
X int ret;
X
X /* Try to get MAC address from DT, or assign a random one */
X addr = of_get_mac_address(node);
X if (addr)
X ether_addr_copy(ndev->dev_addr, addr);
X else
X eth_hw_addr_random(ndev);
X
X priv->phy_node = of_parse_phandle(node, "phy", 0);
X if (!priv->phy_node) {
X netdev_err(ndev, "no associated PHY\n");
X return -ENODEV;
X }
X
X priv->phy_interface = of_get_phy_mode(node);
X if (priv->phy_interface < 0) {
X netdev_err(ndev, "PHY interface mode node unspecified\n");
X return priv->phy_interface;
X }
X
X /* Set interface mode (and configure internal PHY on H3) */
X ret = sun8i_emac_set_syscon(ndev);
X if (ret)
X return ret;
X
X ret = clk_prepare_enable(priv->ahb_clk);
X if (ret) {
X netdev_err(ndev, "Could not enable ahb clock\n");
X goto err_clk;
X }
X
X if (priv->rst) {
X ret = reset_control_deassert(priv->rst);
X if (ret) {
X netdev_err(ndev, "Could not deassert reset\n");
X goto err_reset;
X }
X }
X
X if (priv->ephy_clk) {
X ret = clk_prepare_enable(priv->ephy_clk);
X if (ret) {
X netdev_err(ndev, "Could not enable EPHY clock\n");
X goto err_ephy_clk;
X }
X }
X
X if (priv->rst_ephy) {
X ret = reset_control_deassert(priv->rst_ephy);
X if (ret) {
X netdev_err(ndev, "Could not deassert EPHY reset\n");
X goto err_ephy_reset;
X }
X }
X
X if (priv->regulator) {
X ret = regulator_enable(priv->regulator);
X if (ret)
X goto err_regulator;
X }
X
X if (priv->regulator_io) {
X ret = regulator_enable(priv->regulator_io);
X if (ret)
X goto err_regulator_io;
X }
X
X sun8i_emac_set_mdc(ndev);
X
X ret = sun8i_emac_mdio_register(ndev);
X if (ret)
X goto err_mdio_register;
X
X return 0;
X
err_mdio_register:
X if (priv->regulator_io)
X regulator_disable(priv->regulator_io);
err_regulator_io:
X if (priv->regulator)
X regulator_disable(priv->regulator);
err_regulator:
X if (priv->rst_ephy)
X reset_control_assert(priv->rst_ephy);
err_ephy_reset:
X if (priv->ephy_clk)
X clk_disable_unprepare(priv->ephy_clk);
err_ephy_clk:
X if (priv->rst)
X reset_control_assert(priv->rst);
err_reset:
X clk_disable_unprepare(priv->ahb_clk);
err_clk:
X sun8i_emac_unset_syscon(ndev);
X return ret;
}
X
static void sun8i_emac_uninit(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X mdiobus_unregister(priv->mdio);
X
X if (priv->regulator_io)
X regulator_disable(priv->regulator_io);
X
X if (priv->regulator)
X regulator_disable(priv->regulator);
X
X if (priv->rst_ephy)
X reset_control_assert(priv->rst_ephy);
X
X if (priv->ephy_clk)
X clk_disable_unprepare(priv->ephy_clk);
X
X if (priv->rst)
X reset_control_assert(priv->rst);
X
X clk_disable_unprepare(priv->ahb_clk);
X
X sun8i_emac_unset_syscon(ndev);
}
X
static int sun8i_emac_mdio_probe(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct phy_device *phydev = NULL;
X
X phydev = of_phy_connect(ndev, priv->phy_node, &sun8i_emac_adjust_link,
X 0, priv->phy_interface);
X
X if (!phydev) {
X netdev_err(ndev, "Could not attach to PHY\n");
X return -ENODEV;
X }
X
X phy_attached_info(phydev);
X
X /* mask with MAC supported features */
X phydev->supported &= PHY_GBIT_FEATURES;
X phydev->advertising = phydev->supported;
X
X priv->link = 0;
X priv->speed = 0;
X priv->duplex = -1;
X
X return 0;
}
X
static int sun8i_emac_open(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X int err;
X u32 v;
X struct dma_desc *ddesc;
X int i;
X
X if (nbdesc_tx < MAX_SKB_FRAGS + 1) {
X dev_err(priv->dev, "The number of TX descriptors is too low");
X return -EINVAL;
X }
X
X err = sun8i_emac_mdio_probe(ndev);
X if (err)
X return err;
X
X /* Do SOFT RST */
X v = readl(priv->base + SUN8I_EMAC_BASIC_CTL1);
X writel(v | 0x01, priv->base + SUN8I_EMAC_BASIC_CTL1);
X
X err = readl_poll_timeout(priv->base + SUN8I_EMAC_BASIC_CTL1, v,
X !(v & 0x01), 100, 10000);
X if (err) {
X dev_err(priv->dev, "EMAC reset timeout\n");
X err = -EFAULT;
X goto err_emac_timeout;
X }
X
X sun8i_emac_set_mdc(ndev);
X
X /* DMA */
X v = (8 << 24);/* burst len */
X writel(v, priv->base + SUN8I_EMAC_BASIC_CTL1);
X
X /* it seems that hardware complety ignore interrupt configuration */
#define RX_INT BIT(8)
#define TX_INT BIT(0)
#define TX_UNF_INT BIT(4)
X writel(RX_INT | TX_INT | TX_UNF_INT, priv->base + SUN8I_EMAC_INT_EN);
X
X v = readl(priv->base + SUN8I_EMAC_RX_CTL0);
X /* CHECK_CRC */
X if (ndev->features & NETIF_F_RXCSUM)
X v |= SUN8I_EMAC_RX_DO_CRC;
X else
X v &= ~SUN8I_EMAC_RX_DO_CRC;
X /* STRIP_FCS */
X if (ndev->features & NETIF_F_RXFCS)
X v &= ~SUN8I_EMAC_RX_STRIP_FCS;
X else
X v |= SUN8I_EMAC_RX_STRIP_FCS;
X writel(v, priv->base + SUN8I_EMAC_RX_CTL0);
X
X v = readl(priv->base + SUN8I_EMAC_TX_CTL1);
X /* TX_MD Transmission starts after a full frame located in TX DMA FIFO*/
X v |= BIT(1);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL1);
X
X v = readl(priv->base + SUN8I_EMAC_RX_CTL1);
X /* RX_MD RX DMA reads data from RX DMA FIFO to host memory after a
X * complete frame has been written to RX DMA FIFO
X */
X v |= BIT(1);
X writel(v, priv->base + SUN8I_EMAC_RX_CTL1);
X
X sun8i_emac_set_macaddr(priv, ndev->dev_addr, 0);
X
X priv->tx_slot = 0;
X priv->tx_dirty = 0;
X priv->rx_dirty = 0;
X
X priv->rx_sk = kcalloc(nbdesc_rx, sizeof(struct sk_buff *), GFP_KERNEL);
X if (!priv->rx_sk) {
X err = -ENOMEM;
X goto rx_sk_error;
X }
X priv->tx_sk = kcalloc(nbdesc_tx, sizeof(struct sk_buff *), GFP_KERNEL);
X if (!priv->tx_sk) {
X err = -ENOMEM;
X goto tx_sk_error;
X }
X priv->tx_map = kcalloc(nbdesc_tx, sizeof(int), GFP_KERNEL);
X if (!priv->tx_map) {
X err = -ENOMEM;
X goto tx_map_error;
X }
X
X priv->dd_rx = dma_alloc_coherent(priv->dev,
X nbdesc_rx * sizeof(struct dma_desc),
X &priv->dd_rx_phy,
X GFP_KERNEL);
X if (!priv->dd_rx) {
X dev_err(priv->dev, "ERROR: cannot DMA RX");
X err = -ENOMEM;
X goto dma_rx_error;
X }
X memset(priv->dd_rx, 0, nbdesc_rx * sizeof(struct dma_desc));
X ddesc = priv->dd_rx;
X for (i = 0; i < nbdesc_rx; i++) {
X sun8i_emac_rx_sk(ndev, i);
X ddesc->next = (u32)priv->dd_rx_phy + (i + 1)
X * sizeof(struct dma_desc);
X ddesc++;
X }
X /* last descriptor point back to first one */
X ddesc--;
X ddesc->next = (u32)priv->dd_rx_phy;
X
X priv->dd_tx = dma_alloc_coherent(priv->dev,
X nbdesc_tx * sizeof(struct dma_desc),
X &priv->dd_tx_phy,
X GFP_KERNEL);
X if (!priv->dd_tx) {
X dev_err(priv->dev, "ERROR: cannot DMA TX");
X err = -ENOMEM;
X goto dma_tx_error;
X }
X memset(priv->dd_tx, 0, nbdesc_tx * sizeof(struct dma_desc));
X ddesc = priv->dd_tx;
X for (i = 0; i < nbdesc_tx; i++) {
X ddesc->status = DCLEAN;
X ddesc->st = 0;
X ddesc->next = (u32)(priv->dd_tx_phy + (i + 1)
X * sizeof(struct dma_desc));
X ddesc++;
X }
X /* last descriptor point back to first one */
X ddesc--;
X ddesc->next = (u32)priv->dd_tx_phy;
X i--;
X
X if (ndev->phydev)
X phy_start(ndev->phydev);
X
X /* write start of rx ring descriptor */
X writel(priv->dd_rx_phy, priv->base + SUN8I_EMAC_RX_DESC_LIST);
X /* start RX DMA */
X v = readl(priv->base + SUN8I_EMAC_RX_CTL1);
X v |= BIT(30);
X writel(v, priv->base + SUN8I_EMAC_RX_CTL1);
X
X /* write start of tx ring descriptor */
X writel(priv->dd_tx_phy, priv->base + SUN8I_EMAC_TX_DESC_LIST);
X /* start TX DMA */
X v = readl(priv->base + SUN8I_EMAC_TX_CTL1);
X v |= BIT(30);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL1);
X
X /* activate transmitter */
X v = readl(priv->base + SUN8I_EMAC_TX_CTL0);
X v |= BIT(31);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL0);
X
X /* activate receiver */
X v = readl(priv->base + SUN8I_EMAC_RX_CTL0);
X v |= BIT(31);
X writel(v, priv->base + SUN8I_EMAC_RX_CTL0);
X
X netif_start_queue(ndev);
X
X return 0;
dma_tx_error:
X dma_free_coherent(priv->dev, nbdesc_rx * sizeof(struct dma_desc),
X priv->dd_rx, priv->dd_rx_phy);
dma_rx_error:
X kfree(priv->tx_map);
tx_map_error:
X kfree(priv->tx_sk);
tx_sk_error:
X kfree(priv->rx_sk);
rx_sk_error:
err_emac_timeout:
X phy_disconnect(ndev->phydev);
X return err;
}
X
/* Clean the tx ring of any accepted skb for xmit */
static void sun8i_emac_tx_clean(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X int i;
X struct dma_desc *ddesc;
X int frame_len;
X
X spin_lock(&priv->tx_lock);
X
X for (i = 0; i < nbdesc_tx; i++) {
X if (priv->tx_sk[i]) {
X ddesc = priv->dd_tx + i;
X frame_len = ddesc->st & 0x3FFF;
X switch (priv->tx_map[i]) {
X case MAP_SINGLE:
X dma_unmap_single(priv->dev, ddesc->buf_addr,
X frame_len, DMA_TO_DEVICE);
X break;
X case MAP_PAGE:
X dma_unmap_page(priv->dev, ddesc->buf_addr,
X frame_len, DMA_TO_DEVICE);
X break;
X default:
X dev_err(priv->dev, "Trying to free an empty slot\n");
X continue;
X }
X dev_kfree_skb_any(priv->tx_sk[i]);
X priv->tx_sk[i] = NULL;
X ddesc->st = 0;
X ddesc->status = DCLEAN;
X }
X }
X priv->tx_slot = 0;
X priv->tx_dirty = 0;
X
X spin_unlock(&priv->tx_lock);
}
X
static int sun8i_emac_stop(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X int i;
X struct dma_desc *ddesc;
X
X /* Stop receiver */
X writel(0, priv->base + SUN8I_EMAC_RX_CTL0);
X writel(0, priv->base + SUN8I_EMAC_RX_CTL1);
X /* Stop transmitter */
X writel(0, priv->base + SUN8I_EMAC_TX_CTL0);
X writel(0, priv->base + SUN8I_EMAC_TX_CTL1);
X
X netif_stop_queue(ndev);
X netif_carrier_off(ndev);
X
X phy_stop(ndev->phydev);
X phy_disconnect(ndev->phydev);
X
X /* clean RX ring */
X for (i = 0; i < nbdesc_rx; i++)
X if (priv->rx_sk[i]) {
X ddesc = priv->dd_rx + i;
X dma_unmap_single(priv->dev, ddesc->buf_addr,
X DESC_BUF_MAX, DMA_FROM_DEVICE);
X dev_kfree_skb_any(priv->rx_sk[i]);
X priv->rx_sk[i] = NULL;
X }
X sun8i_emac_tx_clean(ndev);
X
X kfree(priv->rx_sk);
X kfree(priv->tx_sk);
X kfree(priv->tx_map);
X
X dma_free_coherent(priv->dev, nbdesc_rx * sizeof(struct dma_desc),
X priv->dd_rx, priv->dd_rx_phy);
X dma_free_coherent(priv->dev, nbdesc_tx * sizeof(struct dma_desc),
X priv->dd_tx, priv->dd_tx_phy);
X
X return 0;
}
X
static netdev_tx_t sun8i_emac_xmit(struct sk_buff *skb, struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct dma_desc *ddesc;
X struct dma_desc *first;
X int i = 0, rbd_first;
X unsigned int len, fraglen;
X u32 v;
X int n;
X int nf;
X const skb_frag_t *frag;
X int do_csum = 0;
X
X len = skb_headlen(skb);
X if (len < ETH_ZLEN) {
X if (skb_padto(skb, ETH_ZLEN))
X return NETDEV_TX_OK;
X len = ETH_ZLEN;
X }
X n = skb_shinfo(skb)->nr_frags;
X
X if (skb->ip_summed == CHECKSUM_PARTIAL) {
X do_csum = 1;
X priv->estats.tx_hw_csum++;
X }
X netif_dbg(priv, tx_queued, ndev, "%s len=%u skblen=%u %x\n", __func__,
X len, skb->len,
X (skb->ip_summed == CHECKSUM_PARTIAL));
X
X spin_lock(&priv->tx_lock);
X
X /* check for contigous space
X * We need at least 1(skb->data) + n(numfrags) + 1(one clean slot)
X */
X if (rb_tx_numfreedesc(ndev) < n + 2) {
X dev_err_ratelimited(priv->dev, "BUG!: TX is full %d %d\n",
X priv->tx_dirty, priv->tx_slot);
X netif_stop_queue(ndev);
X spin_unlock(&priv->tx_lock);
X return NETDEV_TX_BUSY;
X }
X i = priv->tx_slot;
X
X ddesc = priv->dd_tx + i;
X first = priv->dd_tx + i;
X rbd_first = i;
X
X priv->tx_slot = (i + 1 + n) % nbdesc_tx;
X
X ddesc->buf_addr = dma_map_single(priv->dev, skb->data, len,
X DMA_TO_DEVICE);
X if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
X dev_err(priv->dev, "ERROR: Cannot dmamap buf\n");
X goto xmit_error;
X }
X priv->tx_map[i] = MAP_SINGLE;
X priv->tx_sk[i] = skb;
X priv->ndev->stats.tx_packets++;
X priv->ndev->stats.tx_bytes += len;
X
X ddesc->st = len;
X /* undocumented bit that make it works */
X ddesc->st |= BIT(24);
X if (do_csum)
X ddesc->st |= SUN8I_EMAC_TX_DO_CRC;
X
X /* handle fragmented skb, one descriptor per fragment */
X for (nf = 0; nf < n; nf++) {
X frag = &skb_shinfo(skb)->frags[nf];
X rb_inc(&i, nbdesc_tx);
X priv->tx_sk[i] = skb;
X ddesc = priv->dd_tx + i;
X fraglen = skb_frag_size(frag);
X ddesc->st = fraglen;
X priv->ndev->stats.tx_bytes += fraglen;
X ddesc->st |= BIT(24);
X if (do_csum)
X ddesc->st |= SUN8I_EMAC_TX_DO_CRC;
X
X ddesc->buf_addr = skb_frag_dma_map(priv->dev, frag, 0,
X fraglen, DMA_TO_DEVICE);
X if (dma_mapping_error(priv->dev, ddesc->buf_addr)) {
X dev_err(priv->dev, "DMA MAP ERROR\n");
X goto xmit_error;
X }
X priv->tx_map[i] = MAP_PAGE;
X ddesc->status = BIT(31);
X }
X
X /* frame end */
X ddesc->st |= BIT(30);
X /* We want an interrupt after transmission */
X ddesc->st |= BIT(31);
X
X rb_inc(&i, nbdesc_tx);
X
X /* frame begin */
X first->st |= BIT(29);
X first->status = BIT(31);
X priv->tx_slot = i;
X
X /* Trying to optimize this (recording DMA start/stop) seems
X * to lead to errors. So we always start DMA.
X */
X v = readl(priv->base + SUN8I_EMAC_TX_CTL1);
X /* TX DMA START */
X v |= BIT(31);
X /* Start an run DMA */
X v |= BIT(30);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL1);
X
X if (rb_tx_numfreedesc(ndev) < MAX_SKB_FRAGS + 1) {
X netif_stop_queue(ndev);
X priv->estats.tx_stop_queue++;
X }
X priv->estats.tx_used_desc = rb_tx_numfreedesc(ndev);
X
X spin_unlock(&priv->tx_lock);
X
X return NETDEV_TX_OK;
X
xmit_error:
X /* destroy skb and return TX OK Documentation/DMA-API-HOWTO.txt */
X /* clean descritors from rbd_first to i */
X ddesc->st = 0;
X ddesc->status = DCLEAN;
X do {
X ddesc = priv->dd_tx + rbd_first;
X ddesc->st = 0;
X ddesc->status = DCLEAN;
X rb_inc(&rbd_first, nbdesc_tx);
X } while (rbd_first != i);
X spin_unlock(&priv->tx_lock);
X dev_kfree_skb_any(skb);
X return NETDEV_TX_OK;
}
X
static int sun8i_emac_change_mtu(struct net_device *ndev, int new_mtu)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X int max_mtu;
X
X dev_info(priv->dev, "%s set MTU to %d\n", __func__, new_mtu);
X
X if (netif_running(ndev)) {
X dev_err(priv->dev, "%s: must be stopped to change its MTU\n",
X ndev->name);
X return -EBUSY;
X }
X
X max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
X
X if ((new_mtu < 68) || (new_mtu > max_mtu)) {
X dev_err(priv->dev, "%s: invalid MTU, max MTU is: %d\n",
X ndev->name, max_mtu);
X return -EINVAL;
X }
X
X ndev->mtu = new_mtu;
X netdev_update_features(ndev);
X return 0;
}
X
static netdev_features_t sun8i_emac_fix_features(struct net_device *ndev,
X netdev_features_t features)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X netif_dbg(priv, drv, ndev, "%s %llx\n", __func__, features);
X return features;
}
X
static int sun8i_emac_set_features(struct net_device *ndev,
X netdev_features_t features)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X u32 v;
X
X v = readl(priv->base + SUN8I_EMAC_BASIC_CTL0);
X if (features & NETIF_F_LOOPBACK && netif_running(ndev)) {
X netif_info(priv, hw, ndev, "Set loopback features");
X v |= BIT(1);
X } else {
X netif_info(priv, hw, ndev, "Unset loopback features");
X v &= ~BIT(1);
X }
X writel(v, priv->base + SUN8I_EMAC_BASIC_CTL0);
X
X v = readl(priv->base + SUN8I_EMAC_RX_CTL0);
X if (features & NETIF_F_RXCSUM) {
X v |= SUN8I_EMAC_RX_DO_CRC;
X netif_info(priv, hw, ndev, "Doing RX CRC check by hardware");
X } else {
X v &= ~SUN8I_EMAC_RX_DO_CRC;
X netif_info(priv, hw, ndev, "No RX CRC check by hardware");
X }
X if (features & NETIF_F_RXFCS) {
X v &= ~SUN8I_EMAC_RX_STRIP_FCS;
X netif_info(priv, hw, ndev, "Keep FCS");
X } else {
X v |= SUN8I_EMAC_RX_STRIP_FCS;
X netif_info(priv, hw, ndev, "Strip FCS");
X }
X writel(v, priv->base + SUN8I_EMAC_RX_CTL0);
X
X netif_dbg(priv, drv, ndev, "%s %llx %x\n", __func__, features, v);
X
X return 0;
}
X
static void sun8i_emac_set_rx_mode(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X u32 v = 0;
X int i = 0;
X struct netdev_hw_addr *ha;
X
X /* Receive all multicast frames */
X v |= BIT(16);
X /* Receive all control frames */
X v |= BIT(13);
X if (ndev->flags & IFF_PROMISC)
X v |= BIT(1);
X if (netdev_uc_count(ndev) > 7) {
X v |= BIT(1);
X } else {
X netdev_for_each_uc_addr(ha, ndev) {
X i++;
X sun8i_emac_set_macaddr(priv, ha->addr, i);
X }
X }
X writel(v, priv->base + SUN8I_EMAC_RX_FRM_FLT);
}
X
static void sun8i_emac_tx_timeout(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X u32 v;
X
X dev_info(priv->dev, "%s\n", __func__);
X netif_stop_queue(ndev);
X
X v = readl(priv->base + SUN8I_EMAC_TX_CTL0);
X v &= ~BIT(31);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL0);
X
X v = readl(priv->base + SUN8I_EMAC_TX_CTL1);
X v &= ~BIT(31);
X v &= ~BIT(30);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL1);
X
X sun8i_emac_tx_clean(ndev);
X
X /* write start of tx ring descriptor */
X writel(priv->dd_tx_phy, priv->base + SUN8I_EMAC_TX_DESC_LIST);
X
X v = readl(priv->base + SUN8I_EMAC_TX_CTL0);
X v |= BIT(31);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL0);
X
X v = readl(priv->base + SUN8I_EMAC_TX_CTL1);
X v |= BIT(31);
X v |= BIT(30);
X writel(v, priv->base + SUN8I_EMAC_TX_CTL1);
X
X netdev_reset_queue(ndev);
X
X ndev->stats.tx_errors++;
X netif_wake_queue(ndev);
}
X
static int sun8i_emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
{
X struct phy_device *phydev = ndev->phydev;
X
X if (!netif_running(ndev))
X return -EINVAL;
X
X if (!phydev)
X return -ENODEV;
X
X return phy_mii_ioctl(phydev, rq, cmd);
}
X
static int sun8i_emac_check_if_running(struct net_device *ndev)
{
X if (!netif_running(ndev))
X return -EBUSY;
X return 0;
}
X
static int sun8i_emac_get_sset_count(struct net_device *ndev, int sset)
{
X switch (sset) {
X case ETH_SS_STATS:
X return ARRAY_SIZE(estats_str);
X }
X return -EOPNOTSUPP;
}
X
static int sun8i_emac_ethtool_get_settings(struct net_device *ndev,
X struct ethtool_cmd *cmd)
{
X struct phy_device *phy = ndev->phydev;
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X if (!phy) {
X netdev_err(ndev, "%s: %s: PHY is not registered\n",
X __func__, ndev->name);
X return -ENODEV;
X }
X
X if (!netif_running(ndev)) {
X dev_err(priv->dev, "interface disabled: we cannot track link speed / duplex setting\n");
X return -EBUSY;
X }
X
X cmd->transceiver = XCVR_INTERNAL;
X return phy_ethtool_gset(phy, cmd);
}
X
static int sun8i_emac_ethtool_set_settings(struct net_device *ndev,
X struct ethtool_cmd *cmd)
{
X struct phy_device *phy = ndev->phydev;
X
X return phy_ethtool_sset(phy, cmd);
}
X
static void sun8i_emac_ethtool_getdrvinfo(struct net_device *ndev,
X struct ethtool_drvinfo *info)
{
X strlcpy(info->driver, "sun8i_emac", sizeof(info->driver));
X strcpy(info->version, "00");
X info->fw_version[0] = '\0';
}
X
static void sun8i_emac_ethtool_stats(struct net_device *ndev,
X struct ethtool_stats *dummy, u64 *data)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X memcpy(data, &priv->estats,
X sun8i_emac_get_sset_count(ndev, ETH_SS_STATS) * sizeof(u64));
}
X
static void sun8i_emac_ethtool_strings(struct net_device *dev, u32 stringset,
X u8 *buffer)
{
X switch (stringset) {
X case ETH_SS_STATS:
X memcpy(buffer, &estats_str,
X sun8i_emac_get_sset_count(dev, ETH_SS_STATS) *
X sizeof(struct ethtool_str));
X break;
X }
}
X
static u32 sun8i_emac_ethtool_getmsglevel(struct net_device *ndev)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X return priv->msg_enable;
}
X
static void sun8i_emac_ethtool_setmsglevel(struct net_device *ndev, u32 level)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X priv->msg_enable = level;
}
X
static void sun8i_emac_get_pauseparam(struct net_device *ndev,
X struct ethtool_pauseparam *pause)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X
X pause->rx_pause = 0;
X pause->tx_pause = 0;
X pause->autoneg = ndev->phydev->autoneg;
X
X if (priv->flow_ctrl & FLOW_RX)
X pause->rx_pause = 1;
X if (priv->flow_ctrl & FLOW_TX)
X pause->tx_pause = 1;
}
X
static int sun8i_emac_set_pauseparam(struct net_device *ndev,
X struct ethtool_pauseparam *pause)
{
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X struct phy_device *phy = ndev->phydev;
X int new_pause = 0;
X int ret = 0;
X
X if (pause->rx_pause)
X new_pause |= FLOW_RX;
X if (pause->tx_pause)
X new_pause |= FLOW_TX;
X
X priv->flow_ctrl = new_pause;
X phy->autoneg = pause->autoneg;
X
X if (phy->autoneg) {
X if (netif_running(ndev))
X ret = phy_start_aneg(phy);
X } else {
X sun8i_emac_flow_ctrl(priv, phy->duplex, priv->flow_ctrl,
X priv->pause);
X }
X return ret;
}
X
static const struct ethtool_ops sun8i_emac_ethtool_ops = {
X .begin = sun8i_emac_check_if_running,
X .get_settings = sun8i_emac_ethtool_get_settings,
X .set_settings = sun8i_emac_ethtool_set_settings,
X .get_link = ethtool_op_get_link,
X .get_pauseparam = sun8i_emac_get_pauseparam,
X .set_pauseparam = sun8i_emac_set_pauseparam,
X .get_ethtool_stats = sun8i_emac_ethtool_stats,
X .get_strings = sun8i_emac_ethtool_strings,
X .get_wol = NULL,
X .set_wol = NULL,
X .get_sset_count = sun8i_emac_get_sset_count,
X .get_drvinfo = sun8i_emac_ethtool_getdrvinfo,
X .get_msglevel = sun8i_emac_ethtool_getmsglevel,
X .set_msglevel = sun8i_emac_ethtool_setmsglevel,
};
X
static const struct net_device_ops sun8i_emac_netdev_ops = {
X .ndo_init = sun8i_emac_init,
X .ndo_uninit = sun8i_emac_uninit,
X .ndo_open = sun8i_emac_open,
X .ndo_start_xmit = sun8i_emac_xmit,
X .ndo_stop = sun8i_emac_stop,
X .ndo_change_mtu = sun8i_emac_change_mtu,
X .ndo_fix_features = sun8i_emac_fix_features,
X .ndo_set_rx_mode = sun8i_emac_set_rx_mode,
X .ndo_tx_timeout = sun8i_emac_tx_timeout,
X .ndo_do_ioctl = sun8i_emac_ioctl,
X .ndo_set_mac_address = eth_mac_addr,
X .ndo_set_features = sun8i_emac_set_features,
};
X
static irqreturn_t sun8i_emac_dma_interrupt(int irq, void *dev_id)
{
X struct net_device *ndev = (struct net_device *)dev_id;
X struct sun8i_emac_priv *priv = netdev_priv(ndev);
X u32 v, u;
X
X v = readl(priv->base + SUN8I_EMAC_INT_STA);
X
X netif_info(priv, intr, ndev, "%s %x\n", __func__, v);
X
X /* When this bit is asserted, a frame transmission is completed. */
X if (v & BIT(0))
X sun8i_emac_complete_xmit(ndev);
X
X /* When this bit is asserted, the TX DMA FSM is stopped. */
X if (v & BIT(1))
X priv->estats.tx_dma_stop++;
X
X /* When this asserted, the TX DMA can not acquire next TX descriptor
X * and TX DMA FSM is suspended.
X */
X if (v & BIT(2))
X priv->estats.tx_dma_ua++;
X
X if (v & BIT(3))
X netif_dbg(priv, intr, ndev, "Unhandled interrupt TX TIMEOUT\n");
X
X if (v & BIT(4)) {
X netif_dbg(priv, intr, ndev, "Unhandled interrupt TX underflow\n");
X priv->estats.tx_underflow_int++;
X }
X
X /* When this bit asserted , the frame is transmitted to FIFO totally. */
X if (v & BIT(5)) {
X netif_dbg(priv, intr, ndev, "Unhandled interrupt TX_EARLY_INT\n");
X priv->estats.tx_early_int++;
X }
X
X /* When this bit is asserted, a frame reception is completed */
X if (v & BIT(8))
X sun8i_emac_receive_all(ndev);
X
X /* When this asserted, the RX DMA can not acquire next TX descriptor
X * and RX DMA FSM is suspended.
X */
X if (v & BIT(9)) {
X u = readl(priv->base + SUN8I_EMAC_RX_CTL1);
X dev_info(priv->dev, "Re-run RX DMA %x\n", u);
X writel(u | BIT(31), priv->base + SUN8I_EMAC_RX_CTL1);
X priv->estats.rx_dma_ua++;
X }
X
X if (v & BIT(10)) {
X netif_dbg(priv, intr, ndev, "Unhandled interrupt RX_DMA_STOPPED_INT\n");
X priv->estats.rx_dma_stop++;
X }
X if (v & BIT(11))
X netif_dbg(priv, intr, ndev, "Unhandled interrupt RX_TIMEOUT\n");
X if (v & BIT(12))
X netif_dbg(priv, intr, ndev, "Unhandled interrupt RX OVERFLOW\n");
X if (v & BIT(13)) {
X netif_dbg(priv, intr, ndev, "Unhandled interrupt RX EARLY\n");
X priv->estats.rx_early_int++;
X }
X if (v & BIT(16))
X netif_dbg(priv, intr, ndev, "Unhandled interrupt RGMII\n");
X
X /* the datasheet state those register as read-only
X * but nothing work without writing to it
X */
X writel(v & 0x3FFF, priv->base + SUN8I_EMAC_INT_STA);
X
X return IRQ_HANDLED;
}
X
static int sun8i_emac_probe(struct platform_device *pdev)
{
X struct resource *res;
X struct device_node *np = pdev->dev.of_node;
X struct sun8i_emac_priv *priv;
X struct net_device *ndev;
X int ret;
X
X ndev = alloc_etherdev(sizeof(*priv));
X if (!ndev)
X return -ENOMEM;
X
X SET_NETDEV_DEV(ndev, &pdev->dev);
X priv = netdev_priv(ndev);
X platform_set_drvdata(pdev, ndev);
X
X priv->variant = (enum emac_variant)of_device_get_match_data(&pdev->dev);
X
X res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
X priv->base = devm_ioremap_resource(&pdev->dev, res);
X if (IS_ERR(priv->base)) {
X ret = PTR_ERR(priv->base);
X dev_err(&pdev->dev, "Cannot request MMIO: %d\n", ret);
X goto probe_err;
X }
X
X res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscon");
X priv->syscon = devm_ioremap_resource(&pdev->dev, res);
X if (IS_ERR(priv->syscon)) {
X ret = PTR_ERR(priv->syscon);
X dev_err(&pdev->dev,
X "Cannot map system control registers: %d\n", ret);
X goto probe_err;
X }
X
X priv->irq = platform_get_irq(pdev, 0);
X if (priv->irq < 0) {
X ret = priv->irq;
X dev_err(&pdev->dev, "Cannot claim IRQ: %d\n", ret);
X goto probe_err;
X }
X
X ret = devm_request_irq(&pdev->dev, priv->irq, sun8i_emac_dma_interrupt,
X 0, dev_name(&pdev->dev), ndev);
X if (ret) {
X dev_err(&pdev->dev, "Cannot request IRQ: %d\n", ret);
X goto probe_err;
X }
X
X priv->ahb_clk = devm_clk_get(&pdev->dev, "ahb");
X if (IS_ERR(priv->ahb_clk)) {
X ret = PTR_ERR(priv->ahb_clk);
X dev_err(&pdev->dev, "Cannot get AHB clock err=%d\n", ret);
X goto probe_err;
X }
X
X priv->rst = devm_reset_control_get_optional(&pdev->dev, "ahb");
X if (IS_ERR(priv->rst)) {
X ret = PTR_ERR(priv->rst);
X if (ret == -EPROBE_DEFER)
X return -EPROBE_DEFER;
X dev_info(&pdev->dev, "no mac reset control found %d\n", ret);
X priv->rst = NULL;
X }
X
X if (priv->variant == H3_EMAC)
X priv->use_internal_phy =
X of_property_read_bool(np, "allwinner,use-internal-phy");
X
X if (priv->use_internal_phy) {
X priv->ephy_clk = devm_clk_get(&pdev->dev, "ephy");
X if (IS_ERR(priv->ephy_clk)) {
X ret = PTR_ERR(priv->ephy_clk);
X dev_err(&pdev->dev, "Cannot get EPHY clock err=%d\n",
X ret);
X goto probe_err;
X }
X
X priv->rst_ephy = devm_reset_control_get_optional(&pdev->dev,
X "ephy");
X if (IS_ERR(priv->rst_ephy)) {
X ret = PTR_ERR(priv->rst_ephy);
X if (ret == -EPROBE_DEFER)
X goto probe_err;
X dev_info(&pdev->dev,
X "no EPHY reset control found %d\n", ret);
X priv->rst_ephy = NULL;
X }
X }
X
X /* Optional regulator for PHY */
X priv->regulator = devm_regulator_get_optional(&pdev->dev, "phy");
X if (IS_ERR(priv->regulator)) {
X if (PTR_ERR(priv->regulator) == -EPROBE_DEFER) {
X ret = -EPROBE_DEFER;
X goto probe_err;
X }
X dev_dbg(&pdev->dev, "no PHY regulator found\n");
X priv->regulator = NULL;
X } else {
X dev_info(&pdev->dev, "PHY regulator found\n");
X }
X
X /* Optional regulator for PHY I/O */
X priv->regulator_io = devm_regulator_get_optional(&pdev->dev, "phy_io");
X if (IS_ERR(priv->regulator_io)) {
X if (PTR_ERR(priv->regulator_io) == -EPROBE_DEFER) {
X ret = -EPROBE_DEFER;
X goto probe_err;
X }
X dev_dbg(&pdev->dev, "no PHY I/O regulator found\n");
X priv->regulator_io = NULL;
X } else {
X dev_info(&pdev->dev, "PHY IO regulator found\n");
X }
X
X spin_lock_init(&priv->lock);
X spin_lock_init(&priv->tx_lock);
X
X ndev->netdev_ops = &sun8i_emac_netdev_ops;
X ndev->ethtool_ops = &sun8i_emac_ethtool_ops;
X
X priv->ndev = ndev;
X priv->dev = &pdev->dev;
X
X ndev->base_addr = (unsigned long)priv->base;
X ndev->irq = priv->irq;
X
X ndev->hw_features = NETIF_F_SG | NETIF_F_HIGHDMA;
X ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
X NETIF_F_RXCSUM;
X ndev->features |= ndev->hw_features;
X ndev->hw_features |= NETIF_F_RXFCS;
X ndev->hw_features |= NETIF_F_RXALL;
X ndev->hw_features |= NETIF_F_LOOPBACK;
X ndev->priv_flags |= IFF_UNICAST_FLT;
X
X ndev->watchdog_timeo = msecs_to_jiffies(5000);
X
X ret = register_netdev(ndev);
X if (ret) {
X dev_err(&pdev->dev, "ERROR: Register %s failed\n", ndev->name);
X goto probe_err;
X }
X
X return 0;
X
probe_err:
X free_netdev(ndev);
X return ret;
}
X
static int sun8i_emac_remove(struct platform_device *pdev)
{
X struct net_device *ndev = platform_get_drvdata(pdev);
X
X unregister_netdev(ndev);
X platform_set_drvdata(pdev, NULL);
X free_netdev(ndev);
X
X return 0;
}
X
static const struct of_device_id sun8i_emac_of_match_table[] = {
X { .compatible = "allwinner,sun8i-a83t-emac",
X .data = (void *)A83T_EMAC },
X { .compatible = "allwinner,sun8i-h3-emac",
X .data = (void *)H3_EMAC },
X { .compatible = "allwinner,sun50i-a64-emac",
X .data = (void *)A64_EMAC },
X {}
};
MODULE_DEVICE_TABLE(of, sun8i_emac_of_match_table);
X
static struct platform_driver sun8i_emac_driver = {
X .probe = sun8i_emac_probe,
X .remove = sun8i_emac_remove,
X .driver = {
X .name = "sun8i-emac",
X .of_match_table = sun8i_emac_of_match_table,
X },
};
X
module_platform_driver(sun8i_emac_driver);
X
MODULE_DESCRIPTION("sun8i Ethernet driver");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("LABBE Corentin <clabb...@gmail.com");
SHAR_EOF
(set 20 16 12 09 23 58 27 'sun8i/sun8i-emac.c'
eval "${shar_touch}") && \
chmod 0644 'sun8i/sun8i-emac.c'
if test $? -ne 0
then ${echo} "restore of sun8i/sun8i-emac.c failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'sun8i/sun8i-emac.c': 'MD5 check failed'
) << \SHAR_EOF
b5fcdc2bf01ffc38d23dc7f24a6ba60b sun8i/sun8i-emac.c
SHAR_EOF

else
test `LC_ALL=C wc -c < 'sun8i/sun8i-emac.c'` -ne 49845 && \
${echo} "restoration warning: size of 'sun8i/sun8i-emac.c' is not 49845"
fi
fi
# ============= menu.txt ==============
if test -n "${keep_file}" && test -f 'menu.txt'
then
${echo} "x - SKIPPING menu.txt (file already exists)"

else
${echo} "x - extracting menu.txt (text)"
sed 's/^X//' << 'SHAR_EOF' > 'menu.txt' &&
X
menu "OrangePi Zero Ethernet and WiFi support"
X source "package/sun8i-emac-module/Config.in"
X source "package/xradio-module/Config.in"
endmenu
X
menu "Firmware"
SHAR_EOF
(set 20 17 04 02 02 07 50 'menu.txt'
eval "${shar_touch}") && \
chmod 0644 'menu.txt'
if test $? -ne 0
then ${echo} "restore of menu.txt failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'menu.txt': 'MD5 check failed'
) << \SHAR_EOF
c2d03a53e9f1a03e0afc050c1a668747 menu.txt
SHAR_EOF

else
test `LC_ALL=C wc -c < 'menu.txt'` -ne 165 && \
${echo} "restoration warning: size of 'menu.txt' is not 165"
fi
fi
# ============= kernel.config ==============
if test -n "${keep_file}" && test -f 'kernel.config'
then
${echo} "x - SKIPPING kernel.config (file already exists)"

else
${echo} "x - extracting kernel.config (text)"
sed 's/^X//' << 'SHAR_EOF' > 'kernel.config' &&
CONFIG_NO_HZ=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_CGROUPS=y
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="${BR_BINARIES_DIR}/rootfs.cpio"
CONFIG_PERF_EVENTS=y
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_ARCH_SUNXI=y
CONFIG_SMP=y
CONFIG_NR_CPUS=8
CONFIG_AEABI=y
CONFIG_HIGHMEM=y
CONFIG_ARM_APPENDED_DTB=y
CONFIG_ARM_ATAG_DTB_COMPAT=y
CONFIG_CPU_FREQ=y
CONFIG_CPUFREQ_DT=y
CONFIG_VFP=y
CONFIG_NEON=y
CONFIG_NET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
CONFIG_INET=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
CONFIG_IP_PNP_BOOTP=y
# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
# CONFIG_INET_XFRM_MODE_TUNNEL is not set
# CONFIG_INET_XFRM_MODE_BEET is not set
# CONFIG_INET_DIAG is not set
# CONFIG_IPV6 is not set
CONFIG_CAN=y
CONFIG_CAN_SUN4I=y
CONFIG_CFG80211=m
CONFIG_CFG80211_WEXT=y
CONFIG_MAC80211=m
CONFIG_MAC80211_MESH=y
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
CONFIG_BLK_DEV_SD=y
CONFIG_ATA=y
CONFIG_AHCI_SUNXI=y
CONFIG_NETDEVICES=y
CONFIG_SUN4I_EMAC=y
# CONFIG_NET_VENDOR_ARC is not set
# CONFIG_NET_CADENCE is not set
# CONFIG_NET_VENDOR_BROADCOM is not set
# CONFIG_NET_VENDOR_CIRRUS is not set
# CONFIG_NET_VENDOR_FARADAY is not set
# CONFIG_NET_VENDOR_INTEL is not set
# CONFIG_NET_VENDOR_MARVELL is not set
# CONFIG_NET_VENDOR_MICREL is not set
# CONFIG_NET_VENDOR_MICROCHIP is not set
# CONFIG_NET_VENDOR_NATSEMI is not set
# CONFIG_NET_VENDOR_SAMSUNG is not set
# CONFIG_NET_VENDOR_SEEQ is not set
# CONFIG_NET_VENDOR_SMSC is not set
CONFIG_STMMAC_ETH=y
# CONFIG_NET_VENDOR_VIA is not set
# CONFIG_NET_VENDOR_WIZNET is not set
# CONFIG_WLAN is not set
# CONFIG_INPUT_MOUSEDEV is not set
CONFIG_INPUT_EVDEV=y
CONFIG_KEYBOARD_SUN4I_LRADC=y
# CONFIG_INPUT_MOUSE is not set
CONFIG_INPUT_TOUCHSCREEN=y
CONFIG_TOUCHSCREEN_SUN4I=y
CONFIG_INPUT_MISC=y
CONFIG_INPUT_AXP20X_PEK=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_8250_NR_UARTS=8
CONFIG_SERIAL_8250_RUNTIME_UARTS=8
CONFIG_SERIAL_8250_DW=y
CONFIG_SERIAL_OF_PLATFORM=y
# CONFIG_HW_RANDOM is not set
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_MV64XXX=y
CONFIG_I2C_SUN6I_P2WI=y
CONFIG_SPI=y
CONFIG_SPI_SUN4I=y
CONFIG_SPI_SUN6I=y
CONFIG_GPIO_SYSFS=y
CONFIG_POWER_SUPPLY=y
CONFIG_AXP20X_POWER=y
CONFIG_THERMAL=y
CONFIG_CPU_THERMAL=y
CONFIG_WATCHDOG=y
CONFIG_SUNXI_WATCHDOG=y
CONFIG_MFD_AXP20X_I2C=y
CONFIG_MFD_AXP20X_RSB=y
CONFIG_REGULATOR=y
CONFIG_REGULATOR_FIXED_VOLTAGE=y
CONFIG_REGULATOR_AXP20X=y
CONFIG_REGULATOR_GPIO=y
CONFIG_MEDIA_SUPPORT=y
CONFIG_MEDIA_RC_SUPPORT=y
CONFIG_RC_DEVICES=y
CONFIG_IR_SUNXI=y
CONFIG_DRM=y
CONFIG_DRM_SUN4I=y
CONFIG_FB_SIMPLE=y
CONFIG_SOUND=y
CONFIG_SND=y
CONFIG_SND_SOC=y
CONFIG_SND_SUN4I_CODEC=y
CONFIG_USB=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_HCD_PLATFORM=y
CONFIG_USB_OHCI_HCD=y
CONFIG_USB_OHCI_HCD_PLATFORM=y
CONFIG_USB_MUSB_HDRC=y
CONFIG_USB_MUSB_SUNXI=y
CONFIG_NOP_USB_XCEIV=y
CONFIG_USB_GADGET=y
CONFIG_MMC=y
CONFIG_MMC_SUNXI=y
CONFIG_NEW_LEDS=y
CONFIG_LEDS_CLASS=y
CONFIG_LEDS_GPIO=y
CONFIG_LEDS_TRIGGERS=y
CONFIG_LEDS_TRIGGER_HEARTBEAT=y
CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
CONFIG_RTC_CLASS=y
# CONFIG_RTC_INTF_SYSFS is not set
# CONFIG_RTC_INTF_PROC is not set
CONFIG_RTC_DRV_SUNXI=y
CONFIG_DMADEVICES=y
CONFIG_DMA_SUN6I=y
# CONFIG_IOMMU_SUPPORT is not set
CONFIG_EXTCON=y
CONFIG_PWM=y
CONFIG_PWM_SUN4I=y
CONFIG_PHY_SUN4I_USB=y
CONFIG_PHY_SUN9I_USB=y
CONFIG_NVMEM=y
CONFIG_NVMEM_SUNXI_SID=y
CONFIG_EXT4_FS=y
CONFIG_VFAT_FS=y
CONFIG_TMPFS=y
CONFIG_NFS_FS=y
CONFIG_NFS_V3_ACL=y
CONFIG_NFS_V4=y
CONFIG_ROOT_NFS=y
CONFIG_NLS_CODEPAGE_437=y
CONFIG_NLS_ISO8859_1=y
CONFIG_PRINTK_TIME=y
CONFIG_DEBUG_FS=y
CONFIG_CRYPTO_DEV_SUN4I_SS=y
SHAR_EOF
(set 20 17 04 02 01 33 00 'kernel.config'
eval "${shar_touch}") && \
chmod 0644 'kernel.config'
if test $? -ne 0
then ${echo} "restore of kernel.config failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'kernel.config': 'MD5 check failed'
) << \SHAR_EOF
cffb4b9fd88176d51c8ee5bc19ccb969 kernel.config
SHAR_EOF

else
test `LC_ALL=C wc -c < 'kernel.config'` -ne 3529 && \
${echo} "restoration warning: size of 'kernel.config' is not 3529"
fi
fi
# ============= build.sh ==============
if test -n "${keep_file}" && test -f 'build.sh'
then
${echo} "x - SKIPPING build.sh (file already exists)"

else
${echo} "x - extracting build.sh (text)"
sed 's/^X//' << 'SHAR_EOF' > 'build.sh' &&
#!/bin/bash
#Delete possibly incompletely downloaded archive
set -e
rm -rf buildroot-2017.02.tar.bz2
wget https://buildroot.org/downloads/buildroot-2017.02.tar.bz2
tar -xjf buildroot-2017.02.tar.bz2
#Download the XR819 driver sources
wget https://github.com/fifteenhex/xradio/archive/master.zip
unzip master.zip
#Download XR819 firmware files
(
X cd overlay/lib/firmware/xr819
X wget https://github.com/igorpecovnik/lib/raw/master/bin/firmware-overlay/xr819/boot_xr819.bin
X wget https://github.com/igorpecovnik/lib/raw/master/bin/firmware-overlay/xr819/fw_xr819.bin
X wget https://github.com/igorpecovnik/lib/raw/master/bin/firmware-overlay/xr819/sdd_xr819.bin
)
#Add our additions to the Buildroot
(
X #Prepare the Buildroot for compilation
X cd buildroot-2017.02
X cp -a ../sun8i-emac-module package
X cp -a ../xradio-module package
X cp -a ../orangepi_zero_defconfig configs
X cp -a board/orangepi/orangepi-one board/orangepi/orangepi-zero
X cp ../genimage.cfg board/orangepi/orangepi-zero
X cp ../boot.cmd board/orangepi/orangepi-zero
X awk -i inplace '/menu "Firmware"/{system("cat ../menu.txt");next}1' package/Config.in
X make orangepi_zero_defconfig
X make
)
X
SHAR_EOF
(set 20 17 04 02 02 52 45 'build.sh'
eval "${shar_touch}") && \
chmod 0744 'build.sh'
if test $? -ne 0
then ${echo} "restore of build.sh failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'build.sh': 'MD5 check failed'
) << \SHAR_EOF
0d6c546b0e62a8648fca13af6c7ce407 build.sh
SHAR_EOF

else
test `LC_ALL=C wc -c < 'build.sh'` -ne 1170 && \
${echo} "restoration warning: size of 'build.sh' is not 1170"
fi
fi
if rm -fr ${lock_dir}
then ${echo} "x - removed lock directory ${lock_dir}."
else ${echo} "x - failed to remove lock directory ${lock_dir}."
exit 1
fi
exit 0


Wojciech Zabołotny

unread,
Apr 1, 2017, 9:18:17 PM4/1/17
to
The previous version didn't restore correctly the lib/firmware/xr819
directory, that lead to compilation error.
This is the corrected version.

The attached sources allow to compile Buildroot 2017.02 for Orange Pi Zero
with Ethernet and WiFi support.
lock_dir=_sh02709
# Made on 2017-04-02 03:14 CEST by <wzab@wzab>.
# Source directory was '/home/wzab/OrangePi0/lata3'.
#
# Existing files will *not* be overwritten, unless '-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 18 -rw-r--r-- overlay/lib/firmware/xr819/README
# ============= overlay/lib/firmware/xr819/README ==============
if test ! -d 'overlay'; then
mkdir 'overlay'
if test $? -eq 0
then ${echo} "x - created directory overlay."
else ${echo} "x - failed to create directory overlay."
exit 1
fi
fi
if test ! -d 'overlay/lib'; then
mkdir 'overlay/lib'
if test $? -eq 0
then ${echo} "x - created directory overlay/lib."
else ${echo} "x - failed to create directory overlay/lib."
exit 1
fi
fi
if test ! -d 'overlay/lib/firmware'; then
mkdir 'overlay/lib/firmware'
if test $? -eq 0
then ${echo} "x - created directory overlay/lib/firmware."
else ${echo} "x - failed to create directory overlay/lib/firmware."
exit 1
fi
fi
if test ! -d 'overlay/lib/firmware/xr819'; then
mkdir 'overlay/lib/firmware/xr819'
if test $? -eq 0
then ${echo} "x - created directory overlay/lib/firmware/xr819."
else ${echo} "x - failed to create directory overlay/lib/firmware/xr819."
exit 1
fi
fi
if test -n "${keep_file}" && test -f 'overlay/lib/firmware/xr819/README'
then
${echo} "x - SKIPPING overlay/lib/firmware/xr819/README (file already exists)"

else
${echo} "x - extracting overlay/lib/firmware/xr819/README (text)"
sed 's/^X//' << 'SHAR_EOF' > 'overlay/lib/firmware/xr819/README' &&
Firmware for XR819
SHAR_EOF
(set 20 17 04 02 03 13 36 'overlay/lib/firmware/xr819/README'
eval "${shar_touch}") && \
chmod 0644 'overlay/lib/firmware/xr819/README'
if test $? -ne 0
then ${echo} "restore of overlay/lib/firmware/xr819/README failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'overlay/lib/firmware/xr819/README': 'MD5 check failed'
) << \SHAR_EOF
df11f4d8ae51b299955bc5248ccffd71 overlay/lib/firmware/xr819/README
SHAR_EOF

else
test `LC_ALL=C wc -c < 'overlay/lib/firmware/xr819/README'` -ne 18 && \
${echo} "restoration warning: size of 'overlay/lib/firmware/xr819/README' is not 18"
fi

wza...@gmail.com

unread,
Apr 13, 2017, 6:30:29 AM4/13/17
to
Hi,
unfortunately, the last commit (aimed on compilation of xradio with kernel 4.11) has broken compatibility with earlier kernels.
Therefore, the "build.sh" script should be changed.

============== new version of the build.sh =====================
#!/bin/bash
#Delete possibly incompletely downloaded archive
set -e
rm -rf buildroot-2017.02.tar.bz2
wget https://buildroot.org/downloads/buildroot-2017.02.tar.bz2
tar -xjf buildroot-2017.02.tar.bz2
#Download the XR819 driver sources, but not the last commit!
XRADIO_VER=9d27fae40c57ffa133d6553ebf45e8290569e355
wget https://github.com/fifteenhex/xradio/archive/${XRADIO_VER}.zip
unzip ${XRADIO_VER}.zip
#Rename the version, pretending that it was the master branch
mv xradio-${XRADIO_VER} xradio-master
#Download XR819 firmware files
(
cd overlay/lib/firmware/xr819
wget https://github.com/igorpecovnik/lib/raw/master/bin/firmware-overlay/xr819/boot_xr819.bin
wget https://github.com/igorpecovnik/lib/raw/master/bin/firmware-overlay/xr819/fw_xr819.bin
#Prepare the Buildroot for compilation
cd buildroot-2017.02
cp -a ../sun8i-emac-module package
cp -a ../xradio-module package
cp -a ../orangepi_zero_defconfig configs
cp -a board/orangepi/orangepi-one board/orangepi/orangepi-zero
cp ../genimage.cfg board/orangepi/orangepi-zero
cp ../boot.cmd board/orangepi/orangepi-zero
awk -i inplace '/menu "Firmware"/{system("cat ../menu.txt");next}1' package/Config.in
make orangepi_zero_defconfig
make
)
====================== end of build.sh ============================


Regards,
Wojtek

0 new messages