User:Oogwaymaki
Summary:
After following these steps:
- You'll have a Custom UBOOT (Crust ENABLED) that allows MultiBOOT Using 3 different OS's depending on key combo of volume up / volume down or none pressing on boot - You'll be able to experiment on SD Card without Touching your EMMC - You'll learn how to take a part a PINE PHONE IMAGE (most, and put each OS On one partition
=============================================================================================
All the information here, has been discussed in the open source community on web sites. I have simply developed a process on how to do this on the pine phone.
We use utilities such as Cross Compilation, Uboot, Patches, which will be credited.
First step, make sure you have a cross compiler for your Computer, for particularly the arm device, you will need to download a few packages, I assume we're using Debian Linux (if your using another OS you can find similar commands by searching on the web or to make it simpler download a docker Debian image, and install the pre-requisites which I will list here for Debian)
You an also use vagrant/virtual box VMware or other virtualization platforms.
First please install these Dependencies:
apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential autoconf libtool cmake pkg-config git python-dev swig3.0 libpcre3-dev nodejs-dev crossbuild-essential-arm64 git
The following main sources are needed:
This will download quite a few sources needed for Uboot and existing OS's available to PinePhone
https://github.com/crust-firmware/meta.git
We will also apply this patch:
https://megous.com/git/u-boot/patch/?id=0ab6225154c3d8b74f06fb3b181b52a9a64b4602
(I will attach the one I used I had to modify the above patch to work with the code.)
The crust-firmware also says you need to download the or1k compiler:
https://musl.cc/or1k-linux-musl-cross.tgz
I suggest untarring this in the /opt folder.
1. Once you have these dependency:
- cd /usr/src
- git clone https://github.com/crust-firmware/meta.git
- cd /usr/src/meta
Edit the following file Make file
- Cross compiler
CROSS_aarch64 = aarch64-linux-musl- CROSS_or1k = or1k-linux-musl-
- General options
DEBUG ?= 0 REPRODUCIBLE ?= 0
- Board selection
BOARD ?= pinebook
Example:
- Cross compiler
CROSS_aarch64 = /usr/bin/aarch64-linux-gnu- CROSS_or1k = /opt/or1k-linux-musl-cross/bin/or1k-linux-musl-
- General options
DEBUG ?= 0 REPRODUCIBLE ?= 0
- Board selection
BOARD ?= pinephone
- make
(this should take a 10-30 mins depending on speed..I hope less than 30 mins!!)
After making apply the patch..
Sites Referenced/Inspiration:
https://www.96boards.org/documentation/iot/ https://github.com/dreemurrs-embedded/Jumpdrive https://github.com/dreemurrs-embedded/Pineloader https://www.thegeekstuff.com/2014/12/patch-command-examples/ https://stackoverflow.com/questions/9980186/how-to-create-a-patch-for-a-whole-directory-to-update-it
patch from the link above to work:
Binary files /src/meta/u-boot/.git/index and ./u-boot/.git/index differ diff -ruN /src/meta/u-boot/.git/logs/HEAD ./u-boot/.git/logs/HEAD --- /src/meta/u-boot/.git/logs/HEAD 2020-06-23 03:16:48.487289000 +0000 +++ ./u-boot/.git/logs/HEAD 2020-06-25 23:16:49.879090000 +0000 @@ -1 +1 @@ -0000000000000000000000000000000000000000 139397e64e17241f74dad09ea850c1edbb75d803 root <root@dd0f8cc09d17.(none)> 1592882208 +0000 clone: from https://github.com/crust-firmware/u-boot +0000000000000000000000000000000000000000 139397e64e17241f74dad09ea850c1edbb75d803 root <root@dd0f8cc09d17.(none)> 1593127009 +0000 clone: from https://github.com/crust-firmware/u-boot diff -ruN /src/meta/u-boot/.git/logs/refs/heads/crust ./u-boot/.git/logs/refs/heads/crust --- /src/meta/u-boot/.git/logs/refs/heads/crust 2020-06-23 03:16:48.487289000 +0000 +++ ./u-boot/.git/logs/refs/heads/crust 2020-06-25 23:16:49.879090000 +0000 @@ -1 +1 @@ -0000000000000000000000000000000000000000 139397e64e17241f74dad09ea850c1edbb75d803 root <root@dd0f8cc09d17.(none)> 1592882208 +0000 clone: from https://github.com/crust-firmware/u-boot +0000000000000000000000000000000000000000 139397e64e17241f74dad09ea850c1edbb75d803 root <root@dd0f8cc09d17.(none)> 1593127009 +0000 clone: from https://github.com/crust-firmware/u-boot diff -ruN /src/meta/u-boot/.git/logs/refs/remotes/origin/HEAD ./u-boot/.git/logs/refs/remotes/origin/HEAD --- /src/meta/u-boot/.git/logs/refs/remotes/origin/HEAD 2020-06-23 03:16:48.486289000 +0000 +++ ./u-boot/.git/logs/refs/remotes/origin/HEAD 2020-06-25 23:16:49.878090000 +0000 @@ -1 +1 @@ -0000000000000000000000000000000000000000 139397e64e17241f74dad09ea850c1edbb75d803 root <root@dd0f8cc09d17.(none)> 1592882208 +0000 clone: from https://github.com/crust-firmware/u-boot +0000000000000000000000000000000000000000 139397e64e17241f74dad09ea850c1edbb75d803 root <root@dd0f8cc09d17.(none)> 1593127009 +0000 clone: from https://github.com/crust-firmware/u-boot Binary files /src/meta/u-boot/.git/objects/pack/pack-3218e3429c37fdc4cecbad96d991289088857a99.idx and ./u-boot/.git/objects/pack/pack-3218e3429c37fdc4cecbad96d991289088857a99.idx differ Binary files /src/meta/u-boot/.git/objects/pack/pack-3218e3429c37fdc4cecbad96d991289088857a99.pack and ./u-boot/.git/objects/pack/pack-3218e3429c37fdc4cecbad96d991289088857a99.pack differ Binary files /src/meta/u-boot/.git/objects/pack/pack-4226e7694f44c85876868652dfd7446a40535fd4.idx and ./u-boot/.git/objects/pack/pack-4226e7694f44c85876868652dfd7446a40535fd4.idx differ Binary files /src/meta/u-boot/.git/objects/pack/pack-4226e7694f44c85876868652dfd7446a40535fd4.pack and ./u-boot/.git/objects/pack/pack-4226e7694f44c85876868652dfd7446a40535fd4.pack differ diff -ruN /src/meta/u-boot/board/pinephonevolume.patch ./u-boot/board/pinephonevolume.patch --- /src/meta/u-boot/board/pinephonevolume.patch 2020-06-25 08:40:08.398880000 +0000 +++ ./u-boot/board/pinephonevolume.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,179 +0,0 @@ -bplist00?_WebMainResource? - _ebResourceTextEncodingName^WebResourceURL_WebResourceFrameName_WebResourceData_WebResourceMIMETypeUUTF-8_Phttps://megous.com/git/u-boot/patch/?id=0ab6225154c3d8b74f06fb3b181b52a9a64b4602PO?<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 0ab6225154c3d8b74f06fb3b181b52a9a64b4602 Mon Sep 17 00:00:00 2001 -From: Ondrej Jirman -Date: Tue, 11 Feb 2020 14:10:05 +0100 -Subject: pinephone: Add volume_key environment variable - -When the user has a volume key pressed volume_key variable will -contain either value 'down' or 'up', otherwise it will be empty. - -Signed-off-by: Ondrej Jirman <megous@megous.com> ---- - board/sunxi/Makefile | 1 + - board/sunxi/board.c | 18 ++++++++++++ - board/sunxi/lradc.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ - board/sunxi/lradc.h | 11 +++++++ - 4 files changed, 111 insertions(+) - create mode 100644 board/sunxi/lradc.c - create mode 100644 board/sunxi/lradc.h - -diff --git a/board/sunxi/Makefile b/board/sunxi/Makefile -index c4e13f8c38..6a8a2f5b42 100644 ---- a/board/sunxi/Makefile -+++ b/board/sunxi/Makefile -@@ -11,3 +11,4 @@ obj-$(CONFIG_SUN7I_GMAC) += gmac.o - obj-$(CONFIG_MACH_SUN4I) += dram_sun4i_auto.o - obj-$(CONFIG_MACH_SUN5I) += dram_sun5i_auto.o - obj-$(CONFIG_MACH_SUN7I) += dram_sun5i_auto.o -+obj-$(CONFIG_MACH_SUN50I) += lradc.o -diff --git a/board/sunxi/board.c b/board/sunxi/board.c -index 6de4b53b11..2bedf7a16a 100644 ---- a/board/sunxi/board.c -+++ b/board/sunxi/board.c -@@ -39,6 +39,7 @@ - #include <spl.h> - #include <sy8106a.h> - #include <asm/setup.h> -+#include "lradc.h" - - #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) - /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ -@@ -622,6 +623,12 @@ void sunxi_board_init(void) - { - int power_failed = 0; - -+#ifdef CONFIG_MACH_SUN50I -+ // we init the lradc in SPL to get the ADC started early to have -+ // a valid sample when U-Boot main binary gets executed. -+ lradc_enable(); -+#endif -+ - #ifdef CONFIG_PINEPHONE_LEDS - /* PD18:G PD19:R PD20:B */ - gpio_request(SUNXI_GPD(18), "led:green"); -@@ -905,6 +912,17 @@ int misc_init_r(void) - env_set("mmc_bootdev", "1"); - } - -+#ifdef CONFIG_MACH_SUN50I -+ int key = lradc_get_pressed_key(); -+ if (key == KEY_VOLUMEDOWN) -+ env_set("volume_key", "down"); -+ else if (key == KEY_VOLUMEUP) -+ env_set("volume_key", "up"); -+ -+ // no longer needed -+ lradc_disable(); -+#endif -+ - setup_environment(gd->fdt_blob); - - #ifdef CONFIG_USB_ETHER -diff --git a/board/sunxi/lradc.c b/board/sunxi/lradc.c -new file mode 100644 -index 0000000000..693b198e25 ---- /dev/null -+++ b/board/sunxi/lradc.c -@@ -0,0 +1,81 @@ -+#include <common.h> -+#include <asm/io.h> -+#include "lradc.h" -+ -+#define LRADC_BASE 0x1c21800 -+ -+#define LRADC_CTRL (LRADC_BASE + 0x00) -+#define LRADC_INTC (LRADC_BASE + 0x04) -+#define LRADC_INTS (LRADC_BASE + 0x08) -+#define LRADC_DATA0 (LRADC_BASE + 0x0c) -+#define LRADC_DATA1 (LRADC_BASE + 0x10) -+ -+/* LRADC_CTRL bits */ -+#define FIRST_CONVERT_DLY(x) ((x) << 24) /* 8 bits */ -+#define CHAN_SELECT(x) ((x) << 22) /* 2 bits */ -+#define CONTINUE_TIME_SEL(x) ((x) << 16) /* 4 bits */ -+#define KEY_MODE_SEL(x) ((x) << 12) /* 2 bits */ -+#define LEVELA_B_CNT(x) ((x) << 8) /* 4 bits */ -+#define HOLD_KEY_EN(x) ((x) << 7) -+#define HOLD_EN(x) ((x) << 6) -+#define LEVELB_VOL(x) ((x) << 4) /* 2 bits */ -+#define SAMPLE_RATE(x) ((x) << 2) /* 2 bits */ -+#define ENABLE(x) ((x) << 0) -+ -+/* LRADC_INTC and LRADC_INTS bits */ -+#define CHAN1_KEYUP_IRQ BIT(12) -+#define CHAN1_ALRDY_HOLD_IRQ BIT(11) -+#define CHAN1_HOLD_IRQ BIT(10) -+#define CHAN1_KEYDOWN_IRQ BIT(9) -+#define CHAN1_DATA_IRQ BIT(8) -+#define CHAN0_KEYUP_IRQ BIT(4) -+#define CHAN0_ALRDY_HOLD_IRQ BIT(3) -+#define CHAN0_HOLD_IRQ BIT(2) -+#define CHAN0_KEYDOWN_IRQ BIT(1) -+#define CHAN0_DATA_IRQ BIT(0) -+ -+// this is for PinePhone only -+ -+int lradc_get_pressed_key(void) -+{ -+ uint32_t val; -+ uint32_t vref = 3000000 * 2 / 3; -+ -+ val = readl(LRADC_DATA0) & 0x3f; -+ val = val * vref / 63; -+ -+// printf("lradc=%u\n", val); -+ -+ if (val < 200000) // 158730 -+ return KEY_VOLUMEUP; -+ else if (val < 400000) // 349206 -+ return KEY_VOLUMEDOWN; -+ -+ return 0; -+} -+ -+void lradc_enable(void) -+{ -+ // aldo3 is always on and defaults to 3V -+ -+ writel(0xffffffff, LRADC_INTS); -+ writel(0, LRADC_INTC); -+ -+ /* -+ * Set sample time to 4 ms / 250 Hz. Wait 2 * 4 ms for key to -+ * stabilize on press, wait (1 + 1) * 4 ms for key release -+ */ -+ writel(FIRST_CONVERT_DLY(0) | LEVELA_B_CNT(0) | HOLD_EN(0) | -+ SAMPLE_RATE(0) | ENABLE(1), LRADC_CTRL); -+ -+} -+ -+void lradc_disable(void) -+{ -+ writel(0xffffffff, LRADC_INTS); -+ writel(0, LRADC_INTC); -+ -+ /* Disable lradc, leave other settings unchanged */ -+ writel(FIRST_CONVERT_DLY(2) | LEVELA_B_CNT(1) | HOLD_EN(1) | -+ SAMPLE_RATE(2), LRADC_CTRL); -+} -diff --git a/board/sunxi/lradc.h b/board/sunxi/lradc.h -new file mode 100644 -index 0000000000..c908401b5b ---- /dev/null -+++ b/board/sunxi/lradc.h -@@ -0,0 +1,11 @@ -+#pragma once -+ -+enum { -+ KEY_NONE = 0, -+ KEY_VOLUMEDOWN = 1, -+ KEY_VOLUMEUP = 2, -+}; -+ -+int lradc_get_pressed_key(void); -+void lradc_enable(void); -+void lradc_disable(void); --- -cgit v1.2.3 - -
</body></html>Ztext/plain
? (FUl~????? \ No newline at end of file diff -ruN /src/meta/u-boot/board/sunxi/Makefile ./u-boot/board/sunxi/Makefile --- /src/meta/u-boot/board/sunxi/Makefile 2020-06-25 08:41:18.140731000 +0000 +++ ./u-boot/board/sunxi/Makefile 2020-06-25 23:16:52.460090000 +0000 @@ -11,4 +11,3 @@
obj-$(CONFIG_MACH_SUN4I) += dram_sun4i_auto.o obj-$(CONFIG_MACH_SUN5I) += dram_sun5i_auto.o obj-$(CONFIG_MACH_SUN7I) += dram_sun5i_auto.o
-obj-$(CONFIG_MACH_SUN50I) += lradc.o diff -ruN /src/meta/u-boot/board/sunxi/board.c ./u-boot/board/sunxi/board.c --- /src/meta/u-boot/board/sunxi/board.c 2020-06-25 09:02:37.104020000 +0000 +++ ./u-boot/board/sunxi/board.c 2020-06-25 23:16:52.461090000 +0000 @@ -44,10 +44,8 @@
#include <spl.h> #include <sy8106a.h> #include <asm/setup.h>
-#include "lradc.h"
#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
-
/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ int soft_i2c_gpio_sda; int soft_i2c_gpio_scl;
@@ -641,10 +639,6 @@
void sunxi_board_init(void) { int power_failed = 0;
-#ifdef CONFIG_MACH_SUN50I - lradc_enable(); -#endif -
#ifdef CONFIG_SY8106A_POWER power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
@@ -905,20 +899,6 @@
env_set("fdtfile", str); }
- - -#ifdef CONFIG_MACH_SUN50I - int key = lradc_get_pressed_key(); - if (key == KEY_VOLUMEDOWN) - env_set("volume_key", "down"); - else if (key == KEY_VOLUMEUP) - env_set("volume_key", "up"); - - // no longer needed - lradc_disable(); -#endif - -
setup_environment(gd->fdt_blob); #ifdef CONFIG_USB_ETHER
diff -ruN /src/meta/u-boot/board/sunxi/lradc.c ./u-boot/board/sunxi/lradc.c --- /src/meta/u-boot/board/sunxi/lradc.c 2020-06-25 09:12:37.560760000 +0000 +++ ./u-boot/board/sunxi/lradc.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,81 +0,0 @@ -#include <common.h> -#include <asm/io.h> -#include "lradc.h" - -#define LRADC_BASE 0x1c21800 - -#define LRADC_CTRL (LRADC_BASE + 0x00) -#define LRADC_INTC (LRADC_BASE + 0x04) -#define LRADC_INTS (LRADC_BASE + 0x08) -#define LRADC_DATA0 (LRADC_BASE + 0x0c) -#define LRADC_DATA1 (LRADC_BASE + 0x10) - -/* LRADC_CTRL bits */ -#define FIRST_CONVERT_DLY(x) ((x) << 24) /* 8 bits */ -#define CHAN_SELECT(x) ((x) << 22) /* 2 bits */ -#define CONTINUE_TIME_SEL(x) ((x) << 16) /* 4 bits */ -#define KEY_MODE_SEL(x) ((x) << 12) /* 2 bits */ -#define LEVELA_B_CNT(x) ((x) << 8) /* 4 bits */ -#define HOLD_KEY_EN(x) ((x) << 7) -#define HOLD_EN(x) ((x) << 6) -#define LEVELB_VOL(x) ((x) << 4) /* 2 bits */ -#define SAMPLE_RATE(x) ((x) << 2) /* 2 bits */ -#define ENABLE(x) ((x) << 0) - -/* LRADC_INTC and LRADC_INTS bits */ -#define CHAN1_KEYUP_IRQ BIT(12) -#define CHAN1_ALRDY_HOLD_IRQ BIT(11) -#define CHAN1_HOLD_IRQ BIT(10) -#define CHAN1_KEYDOWN_IRQ BIT(9) -#define CHAN1_DATA_IRQ BIT(8) -#define CHAN0_KEYUP_IRQ BIT(4) -#define CHAN0_ALRDY_HOLD_IRQ BIT(3) -#define CHAN0_HOLD_IRQ BIT(2) -#define CHAN0_KEYDOWN_IRQ BIT(1) -#define CHAN0_DATA_IRQ BIT(0) - -// this is for PinePhone only - -int lradc_get_pressed_key(void) -{ - uint32_t val; - uint32_t vref = 3000000 * 2 / 3; - - val = readl(LRADC_DATA0) & 0x3f; - val = val * vref / 63; - -// printf("lradc=%u\n", val); - - if (val < 200000) // 158730 - return KEY_VOLUMEUP; - else if (val < 400000) // 349206 - return KEY_VOLUMEDOWN; - - return 0; -} - -void lradc_enable(void) -{ - // aldo3 is always on and defaults to 3V - - writel(0xffffffff, LRADC_INTS); - writel(0, LRADC_INTC); - - /* - * Set sample time to 4 ms / 250 Hz. Wait 2 * 4 ms for key to - * stabilize on press, wait (1 + 1) * 4 ms for key release - */ - writel(FIRST_CONVERT_DLY(0) | LEVELA_B_CNT(0) | HOLD_EN(0) | - SAMPLE_RATE(0) | ENABLE(1), LRADC_CTRL); - -} - -void lradc_disable(void) -{ - writel(0xffffffff, LRADC_INTS); - writel(0, LRADC_INTC); - - /* Disable lradc, leave other settings unchanged */ - writel(FIRST_CONVERT_DLY(2) | LEVELA_B_CNT(1) | HOLD_EN(1) | - SAMPLE_RATE(2), LRADC_CTRL); -} diff -ruN /src/meta/u-boot/board/sunxi/lradc.h ./u-boot/board/sunxi/lradc.h --- /src/meta/u-boot/board/sunxi/lradc.h 2020-06-25 08:41:18.146731000 +0000 +++ ./u-boot/board/sunxi/lradc.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ -#pragma once - -enum { - KEY_NONE = 0, - KEY_VOLUMEDOWN = 1, - KEY_VOLUMEUP = 2, -}; - -int lradc_get_pressed_key(void); -void lradc_enable(void); -void lradc_disable(void); diff -ruN /src/meta/u-boot/include/config/uboot.release ./u-boot/include/config/uboot.release --- /src/meta/u-boot/include/config/uboot.release 2020-06-25 09:03:05.577923000 +0000 +++ ./u-boot/include/config/uboot.release 2020-06-25 23:17:06.876958000 +0000 @@ -1 +1 @@ -2020.07-rc4""-18358-g139397e64e-dirty +2020.07-rc4""-18358-g139397e64e diff -ruN /src/meta/u-boot/include/generated/timestamp_autogenerated.h ./u-boot/include/generated/timestamp_autogenerated.h --- /src/meta/u-boot/include/generated/timestamp_autogenerated.h 2020-06-24 05:31:52.865232000 +0000 +++ ./u-boot/include/generated/timestamp_autogenerated.h 2020-06-25 23:17:06.968958000 +0000 @@ -1,5 +1,5 @@ -#define U_BOOT_DATE "Jun 23 2020" -#define U_BOOT_TIME "03:14:42" +#define U_BOOT_DATE "Jun 25 2020" +#define U_BOOT_TIME "23:14:54"
#define U_BOOT_TZ "+0000"
-#define U_BOOT_DMI_DATE "06/23/2020" -#define U_BOOT_BUILD_DATE 0x20200623 +#define U_BOOT_DMI_DATE "06/25/2020" +#define U_BOOT_BUILD_DATE 0x20200625 diff -ruN /src/meta/u-boot/include/generated/version_autogenerated.h ./u-boot/include/generated/version_autogenerated.h --- /src/meta/u-boot/include/generated/version_autogenerated.h 2020-06-25 09:03:05.598923000 +0000 +++ ./u-boot/include/generated/version_autogenerated.h 2020-06-25 23:17:06.930958000 +0000 @@ -1,4 +1,4 @@ -#define PLAIN_VERSION "2020.07-rc4-18358-g139397e64e-dirty" +#define PLAIN_VERSION "2020.07-rc4-18358-g139397e64e"
#define U_BOOT_VERSION "U-Boot " PLAIN_VERSION #define CC_VERSION_STRING "aarch64-linux-gnu-gcc (Debian 8.3.0-2) 8.3.0" #define LD_VERSION_STRING "GNU ld (GNU Binutils for Debian) 2.31.1"
diff -ruN /src/meta/u-boot/pinephonevolume.patch ./u-boot/pinephonevolume.patch --- /src/meta/u-boot/pinephonevolume.patch 2020-06-25 08:38:59.272827000 +0000 +++ ./u-boot/pinephonevolume.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,179 +0,0 @@ -bplist00?_WebMainResource? -
_ebResourceTextEncodingName^WebResourceURL_WebResourceFrameName_WebResourceData_WebResourceMIMETypeUUTF-8_Phttps://megous.com/git/u-boot/patch/?id=0ab6225154c3d8b74f06fb3b181b52a9a64b4602PO?<html><head></head><body>
From 0ab6225154c3d8b74f06fb3b181b52a9a64b4602 Mon Sep 17 00:00:00 2001 -From: Ondrej Jirman -Date: Tue, 11 Feb 2020 14:10:05 +0100 -Subject: pinephone: Add volume_key environment variable - -When the user has a volume key pressed volume_key variable will -contain either value 'down' or 'up', otherwise it will be empty. - -Signed-off-by: Ondrej Jirman <megous@megous.com> ---- - board/sunxi/Makefile | 1 + - board/sunxi/board.c | 18 ++++++++++++ - board/sunxi/lradc.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ - board/sunxi/lradc.h | 11 +++++++ - 4 files changed, 111 insertions(+) - create mode 100644 board/sunxi/lradc.c - create mode 100644 board/sunxi/lradc.h - -diff --git a/board/sunxi/Makefile b/board/sunxi/Makefile -index c4e13f8c38..6a8a2f5b42 100644 ---- a/board/sunxi/Makefile -+++ b/board/sunxi/Makefile -@@ -11,3 +11,4 @@ obj-$(CONFIG_SUN7I_GMAC) += gmac.o - obj-$(CONFIG_MACH_SUN4I) += dram_sun4i_auto.o - obj-$(CONFIG_MACH_SUN5I) += dram_sun5i_auto.o - obj-$(CONFIG_MACH_SUN7I) += dram_sun5i_auto.o -+obj-$(CONFIG_MACH_SUN50I) += lradc.o -diff --git a/board/sunxi/board.c b/board/sunxi/board.c -index 6de4b53b11..2bedf7a16a 100644 ---- a/board/sunxi/board.c -+++ b/board/sunxi/board.c -@@ -39,6 +39,7 @@ - #include <spl.h> - #include <sy8106a.h> - #include <asm/setup.h> -+#include "lradc.h" - - #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) - /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ -@@ -622,6 +623,12 @@ void sunxi_board_init(void) - { - int power_failed = 0; - -+#ifdef CONFIG_MACH_SUN50I -+ // we init the lradc in SPL to get the ADC started early to have -+ // a valid sample when U-Boot main binary gets executed. -+ lradc_enable(); -+#endif -+ - #ifdef CONFIG_PINEPHONE_LEDS - /* PD18:G PD19:R PD20:B */ - gpio_request(SUNXI_GPD(18), "led:green"); -@@ -905,6 +912,17 @@ int misc_init_r(void) - env_set("mmc_bootdev", "1"); - } - -+#ifdef CONFIG_MACH_SUN50I -+ int key = lradc_get_pressed_key(); -+ if (key == KEY_VOLUMEDOWN) -+ env_set("volume_key", "down"); -+ else if (key == KEY_VOLUMEUP) -+ env_set("volume_key", "up"); -+ -+ // no longer needed -+ lradc_disable(); -+#endif -+ - setup_environment(gd->fdt_blob); - - #ifdef CONFIG_USB_ETHER -diff --git a/board/sunxi/lradc.c b/board/sunxi/lradc.c -new file mode 100644 -index 0000000000..693b198e25 ---- /dev/null -+++ b/board/sunxi/lradc.c -@@ -0,0 +1,81 @@ -+#include <common.h> -+#include <asm/io.h> -+#include "lradc.h" -+ -+#define LRADC_BASE 0x1c21800 -+ -+#define LRADC_CTRL (LRADC_BASE + 0x00) -+#define LRADC_INTC (LRADC_BASE + 0x04) -+#define LRADC_INTS (LRADC_BASE + 0x08) -+#define LRADC_DATA0 (LRADC_BASE + 0x0c) -+#define LRADC_DATA1 (LRADC_BASE + 0x10) -+ -+/* LRADC_CTRL bits */ -+#define FIRST_CONVERT_DLY(x) ((x) << 24) /* 8 bits */ -+#define CHAN_SELECT(x) ((x) << 22) /* 2 bits */ -+#define CONTINUE_TIME_SEL(x) ((x) << 16) /* 4 bits */ -+#define KEY_MODE_SEL(x) ((x) << 12) /* 2 bits */ -+#define LEVELA_B_CNT(x) ((x) << 8) /* 4 bits */ -+#define HOLD_KEY_EN(x) ((x) << 7) -+#define HOLD_EN(x) ((x) << 6) -+#define LEVELB_VOL(x) ((x) << 4) /* 2 bits */ -+#define SAMPLE_RATE(x) ((x) << 2) /* 2 bits */ -+#define ENABLE(x) ((x) << 0) -+ -+/* LRADC_INTC and LRADC_INTS bits */ -+#define CHAN1_KEYUP_IRQ BIT(12) -+#define CHAN1_ALRDY_HOLD_IRQ BIT(11) -+#define CHAN1_HOLD_IRQ BIT(10) -+#define CHAN1_KEYDOWN_IRQ BIT(9) -+#define CHAN1_DATA_IRQ BIT(8) -+#define CHAN0_KEYUP_IRQ BIT(4) -+#define CHAN0_ALRDY_HOLD_IRQ BIT(3) -+#define CHAN0_HOLD_IRQ BIT(2) -+#define CHAN0_KEYDOWN_IRQ BIT(1) -+#define CHAN0_DATA_IRQ BIT(0) -+ -+// this is for PinePhone only -+ -+int lradc_get_pressed_key(void) -+{ -+ uint32_t val; -+ uint32_t vref = 3000000 * 2 / 3; -+ -+ val = readl(LRADC_DATA0) & 0x3f; -+ val = val * vref / 63; -+ -+// printf("lradc=%u\n", val); -+ -+ if (val < 200000) // 158730 -+ return KEY_VOLUMEUP; -+ else if (val < 400000) // 349206 -+ return KEY_VOLUMEDOWN; -+ -+ return 0; -+} -+ -+void lradc_enable(void) -+{ -+ // aldo3 is always on and defaults to 3V -+ -+ writel(0xffffffff, LRADC_INTS); -+ writel(0, LRADC_INTC); -+ -+ /* -+ * Set sample time to 4 ms / 250 Hz. Wait 2 * 4 ms for key to -+ * stabilize on press, wait (1 + 1) * 4 ms for key release -+ */ -+ writel(FIRST_CONVERT_DLY(0) | LEVELA_B_CNT(0) | HOLD_EN(0) | -+ SAMPLE_RATE(0) | ENABLE(1), LRADC_CTRL); -+ -+} -+ -+void lradc_disable(void) -+{ -+ writel(0xffffffff, LRADC_INTS); -+ writel(0, LRADC_INTC); -+ -+ /* Disable lradc, leave other settings unchanged */ -+ writel(FIRST_CONVERT_DLY(2) | LEVELA_B_CNT(1) | HOLD_EN(1) | -+ SAMPLE_RATE(2), LRADC_CTRL); -+} -diff --git a/board/sunxi/lradc.h b/board/sunxi/lradc.h -new file mode 100644 -index 0000000000..c908401b5b ---- /dev/null -+++ b/board/sunxi/lradc.h -@@ -0,0 +1,11 @@ -+#pragma once -+ -+enum { -+ KEY_NONE = 0, -+ KEY_VOLUMEDOWN = 1, -+ KEY_VOLUMEUP = 2, -+}; -+ -+int lradc_get_pressed_key(void); -+void lradc_enable(void); -+void lradc_disable(void); --- -cgit v1.2.3 - -
</body></html>Ztext/plain
? (FUl~????? \ No newline at end of file