Patch-Source: https://gitlab.com/a-wai/u-boot-pinenote/-/commit/9275d23e62aa31787b27bf601a78f761e9afb6a9
From 7103630cff3316df12c8abc633e2a25b4ed78ccb Mon Sep 17 00:00:00 2001
From: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Date: Thu, 23 Mar 2023 15:14:56 +0100
Subject: [PATCH] board: rockchip: Add Pine64 PineNote

The PineNote is an e-ink tablet by PINE64. It is built around a Rockchip
RK3566 SoC and has the following specifications:
- 4GB LPDDR4
- 128GB eMMC
- 10.3" 1404x1872 e-ink display

This board is very similar to other RK356x-based boards, with the
exception that its download-mode "key" (actually a Hall sensor) is on
ADC channel 0 instead of 1.

As such, this patch is heavily based on the evb_3568 board
implementation with the addition of a simple board setup code, meant to
account for the above difference.

Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 arch/arm/dts/rk3566-pinenote-u-boot.dtsi      | 42 +++++++++
 arch/arm/dts/rk3566-pinenote-v1.1-u-boot.dtsi |  6 ++
 arch/arm/dts/rk3566-pinenote-v1.2-u-boot.dtsi |  6 ++
 arch/arm/mach-rockchip/rk3568/Kconfig         |  7 ++
 board/pine64/pinenote-rk3566/Kconfig          | 15 ++++
 board/pine64/pinenote-rk3566/MAINTAINERS      |  7 ++
 board/pine64/pinenote-rk3566/Makefile         |  7 ++
 .../pine64/pinenote-rk3566/pinenote-rk3566.c  | 26 ++++++
 configs/pinenote-rk3566_defconfig             | 89 +++++++++++++++++++
 doc/board/rockchip/rockchip.rst               |  1 +
 10 files changed, 206 insertions(+)
 create mode 100644 arch/arm/dts/rk3566-pinenote-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3566-pinenote-v1.1-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3566-pinenote-v1.2-u-boot.dtsi
 create mode 100644 board/pine64/pinenote-rk3566/Kconfig
 create mode 100644 board/pine64/pinenote-rk3566/MAINTAINERS
 create mode 100644 board/pine64/pinenote-rk3566/Makefile
 create mode 100644 board/pine64/pinenote-rk3566/pinenote-rk3566.c
 create mode 100644 configs/pinenote-rk3566_defconfig

diff --git a/arch/arm/dts/rk3566-pinenote-u-boot.dtsi b/arch/arm/dts/rk3566-pinenote-u-boot.dtsi
new file mode 100644
index 00000000000..bd6797f25a3
--- /dev/null
+++ b/arch/arm/dts/rk3566-pinenote-u-boot.dtsi
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2023 Collabora Ltd.
+ */
+
+#include "rk356x-u-boot.dtsi"
+
+/ {
+	chosen {
+		u-boot,spl-boot-order = "same-as-spl", &sdhci;
+	};
+};
+
+&i2c0 {
+	bootph-pre-ram;
+};
+
+&i2c0_xfer {
+	bootph-pre-ram;
+};
+
+&i2s1m0_mclk {
+	bootph-pre-ram;
+};
+
+&pmic_int_l {
+	bootph-pre-ram;
+};
+
+&pmic_sleep {
+	bootph-pre-ram;
+};
+
+&rk817 {
+	regulators {
+		bootph-pre-ram;
+	};
+};
+
+&sdhci {
+	cap-mmc-highspeed;
+};
diff --git a/arch/arm/dts/rk3566-pinenote-v1.1-u-boot.dtsi b/arch/arm/dts/rk3566-pinenote-v1.1-u-boot.dtsi
new file mode 100644
index 00000000000..8e86ad67bf0
--- /dev/null
+++ b/arch/arm/dts/rk3566-pinenote-v1.1-u-boot.dtsi
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2023 Collabora Ltd.
+ */
+
+#include "rk3566-pinenote-u-boot.dtsi"
diff --git a/arch/arm/dts/rk3566-pinenote-v1.2-u-boot.dtsi b/arch/arm/dts/rk3566-pinenote-v1.2-u-boot.dtsi
new file mode 100644
index 00000000000..8e86ad67bf0
--- /dev/null
+++ b/arch/arm/dts/rk3566-pinenote-v1.2-u-boot.dtsi
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2023 Collabora Ltd.
+ */
+
+#include "rk3566-pinenote-u-boot.dtsi"
diff --git a/arch/arm/mach-rockchip/rk3568/Kconfig b/arch/arm/mach-rockchip/rk3568/Kconfig
index c589fd58699..fd351aa7bf3 100644
--- a/arch/arm/mach-rockchip/rk3568/Kconfig
+++ b/arch/arm/mach-rockchip/rk3568/Kconfig
@@ -27,6 +27,12 @@ config TARGET_ODROID_M1S_RK3566
 	help
 	  Hardkernel ODROID-M1S single board computer with a RK3566 SoC.
 
+config TARGET_PINENOTE_RK3566
+	bool "Pinenote"
+	help
+	  Pinenote is an eInk tablet based on the Rockchip RK3566 SoC
+	  with 4Gb RAM, onboard eMMC and a 10.3" (1404x1872) screen.
+
 config TARGET_POWKIDDY_X55_RK3566
 	bool "Powkiddy X55"
 	help
@@ -78,6 +84,7 @@ source "board/rockchip/evb_rk3568/Kconfig"
 source "board/anbernic/rgxx3_rk3566/Kconfig"
 source "board/hardkernel/odroid_m1/Kconfig"
 source "board/hardkernel/odroid_m1s/Kconfig"
+source "board/pine64/pinenote-rk3566/Kconfig"
 source "board/pine64/quartz64_rk3566/Kconfig"
 source "board/powkiddy/x55/Kconfig"
 source "board/qnap/ts433/Kconfig"
diff --git a/board/pine64/pinenote-rk3566/Kconfig b/board/pine64/pinenote-rk3566/Kconfig
new file mode 100644
index 00000000000..ac4d77538ba
--- /dev/null
+++ b/board/pine64/pinenote-rk3566/Kconfig
@@ -0,0 +1,15 @@
+if TARGET_PINENOTE_RK3566
+
+config SYS_BOARD
+	default "pinenote-rk3566"
+
+config SYS_VENDOR
+	default "pine64"
+
+config SYS_CONFIG_NAME
+	default "evb_rk3568"
+
+config BOARD_SPECIFIC_OPTIONS
+	def_bool y
+
+endif
diff --git a/board/pine64/pinenote-rk3566/MAINTAINERS b/board/pine64/pinenote-rk3566/MAINTAINERS
new file mode 100644
index 00000000000..60c93887518
--- /dev/null
+++ b/board/pine64/pinenote-rk3566/MAINTAINERS
@@ -0,0 +1,7 @@
+PINENOTE-RK3566
+M:	Arnaud Ferraris <arnaud.ferraris@collabora.com>
+S:	Maintained
+F:	board/pine64/pinenote-rk3566
+F:	include/configs/pinenote-rk3566.h
+F:	configs/pinenote-rk3566_defconfig
+F:	arch/arm/dts/rk3566-pinenote*
diff --git a/board/pine64/pinenote-rk3566/Makefile b/board/pine64/pinenote-rk3566/Makefile
new file mode 100644
index 00000000000..8baf80c48b1
--- /dev/null
+++ b/board/pine64/pinenote-rk3566/Makefile
@@ -0,0 +1,7 @@
+#
+# (C) Copyright 2023 Collabora Ltd
+#
+# SPDX-License-Identifier: GPL-2.0
+#
+
+obj-y	+= pinenote-rk3566.o
diff --git a/board/pine64/pinenote-rk3566/pinenote-rk3566.c b/board/pine64/pinenote-rk3566/pinenote-rk3566.c
new file mode 100644
index 00000000000..aa4beb46697
--- /dev/null
+++ b/board/pine64/pinenote-rk3566/pinenote-rk3566.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019 Rockchip Electronics Co., Ltd
+ * (C) Copyright 2023 Collabora Ltd
+ */
+
+#include <adc.h>
+#include <stdio.h>
+
+#define KEY_DOWN_MIN_VAL        0
+#define KEY_DOWN_MAX_VAL        30
+
+int rockchip_dnl_key_pressed(void)
+{
+	unsigned int val;
+
+	if (adc_channel_single_shot("saradc@fe720000", 0, &val)) {
+		printf("%s read adc key val failed\n", __func__);
+		return false;
+	}
+
+	if (val >= KEY_DOWN_MIN_VAL && val <= KEY_DOWN_MAX_VAL)
+		return true;
+	else
+		return false;
+}
diff --git a/configs/pinenote-rk3566_defconfig b/configs/pinenote-rk3566_defconfig
new file mode 100644
index 00000000000..aec403708b0
--- /dev/null
+++ b/configs/pinenote-rk3566_defconfig
@@ -0,0 +1,89 @@
+CONFIG_ARM=y
+CONFIG_SKIP_LOWLEVEL_INIT=y
+CONFIG_COUNTER_FREQUENCY=24000000
+CONFIG_ARCH_ROCKCHIP=y
+CONFIG_DEFAULT_DEVICE_TREE="rockchip/rk3566-pinenote-v1.2"
+CONFIG_ROCKCHIP_RK3568=y
+CONFIG_ROCKCHIP_RK8XX_DISABLE_BOOT_ON_POWERON=y
+CONFIG_SPL_SERIAL=y
+CONFIG_TARGET_PINENOTE_RK3566=y
+CONFIG_SYS_LOAD_ADDR=0xc00800
+CONFIG_DEBUG_UART_BASE=0xFE660000
+CONFIG_DEBUG_UART_CLOCK=24000000
+CONFIG_DEBUG_UART=y
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_SPL_FIT_SIGNATURE=y
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_LEGACY_IMAGE_FORMAT=y
+CONFIG_DEFAULT_FDT_FILE="rockchip/rk3566-pinenote-v1.2.dtb"
+# CONFIG_DISPLAY_CPUINFO is not set
+CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_SPL_MAX_SIZE=0x40000
+CONFIG_SPL_PAD_TO=0x7f8000
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+CONFIG_SPL_I2C=y
+CONFIG_SPL_POWER=y
+CONFIG_SPL_ATF=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_GPT=y
+CONFIG_CMD_I2C=y
+CONFIG_CMD_MMC=y
+CONFIG_CMD_POWEROFF=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_ROCKUSB=y
+CONFIG_CMD_USB_MASS_STORAGE=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_PMIC=y
+CONFIG_CMD_REGULATOR=y
+# CONFIG_SPL_DOS_PARTITION is not set
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_OF_LIVE=y
+CONFIG_OF_LIST="rockchip/rk3566-pinenote-v1.1 rockchip/rk3566-pinenote-v1.2"
+CONFIG_OF_SPL_REMOVE_PROPS="clock-names interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
+CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_NO_NET=y
+CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_SPL_REGMAP=y
+CONFIG_SPL_SYSCON=y
+CONFIG_BUTTON=y
+CONFIG_BUTTON_ADC=y
+CONFIG_BUTTON_GPIO=y
+CONFIG_SPL_CLK=y
+# CONFIG_USB_FUNCTION_FASTBOOT is not set
+CONFIG_ROCKCHIP_GPIO=y
+CONFIG_SYS_I2C_ROCKCHIP=y
+CONFIG_LED=y
+CONFIG_LED_GPIO=y
+CONFIG_MISC=y
+CONFIG_SUPPORT_EMMC_RPMB=y
+CONFIG_MMC_DW=y
+CONFIG_MMC_DW_ROCKCHIP=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_SDMA=y
+CONFIG_MMC_SDHCI_ROCKCHIP=y
+CONFIG_PHY_ROCKCHIP_INNO_USB2=y
+CONFIG_PHY_ROCKCHIP_NANENG_COMBOPHY=y
+CONFIG_SPL_PINCTRL=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_RK8XX=y
+CONFIG_SPL_PMIC_RK8XX=y
+CONFIG_REGULATOR_RK8XX=y
+CONFIG_SPL_RAM=y
+CONFIG_BAUDRATE=1500000
+CONFIG_DEBUG_UART_SHIFT=2
+CONFIG_SYS_NS16550_MEM32=y
+CONFIG_SYSRESET=y
+CONFIG_SYSRESET_PSCI=y
+CONFIG_USB=y
+CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GENERIC=y
+CONFIG_USB_HOST_ETHER=y
+CONFIG_USB_ETHER_ASIX=y
+CONFIG_USB_ETHER_ASIX88179=y
+CONFIG_USB_ETHER_RTL8152=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_DOWNLOAD=y
+CONFIG_USB_FUNCTION_ROCKUSB=y
+CONFIG_ERRNO_STR=y
diff --git a/doc/board/rockchip/rockchip.rst.orig b/doc/board/rockchip/rockchip.rst
index b88299cbba..a1cb20e73f 100644
--- a/doc/board/rockchip/rockchip.rst.orig
+++ b/doc/board/rockchip/rockchip.rst
@@ -108,6 +108,7 @@ List of mainline supported Rockchip boards:
      - FriendlyElec NanoPi R3S (nanopi-r3s-rk3566)
      - Hardkernel ODROID-M1S (odroid-m1s-rk3566)
      - LCKFB TaishanPi (lckfb-tspi-rk3566)
+     - Pine64 PineNote (pinenote-rk3566)
      - Pine64 PineTab2 (pinetab2-rk3566)
      - Pine64 Quartz64-A Board (quartz64-a-rk3566)
      - Pine64 Quartz64-B Board (quartz64-b-rk3566)
