Skip to content

Commit

Permalink
Enable ums mode when TinkerBoard is connected to PC. This is needed t…
Browse files Browse the repository at this point in the history
…o flash image directly to eMMC. Removing ethaddr setting since it's deprecated and few other small fixes.
  • Loading branch information
igorpecovnik committed Jun 29, 2018
1 parent 46d754f commit bb2ce93
Show file tree
Hide file tree
Showing 9 changed files with 757 additions and 4 deletions.
1 change: 0 additions & 1 deletion config/bootenv/rockchip-default.txt
@@ -1,2 +1 @@
verbosity=1
ethaddr=06:e6:ad:01:68:3c
@@ -0,0 +1,115 @@
From 550e15099408decc58fb439edcd2e320570b8bf4 Mon Sep 17 00:00:00 2001
From: jamess_huang <Jamess_Huang@asus.com>
Date: Fri, 11 Aug 2017 17:47:45 +0800
Subject: [PATCH 17/50] Fix HDMI some issues

This patch:
use 1080P display_timing when connect 4K HDMI screen.
correct rockchip_mpll_config & rockchip_phy_config .mpixelclock.
add some hdmi-to-vga support

Change-Id: Ic7faf4dd7ea490051493397058aa5bad1d8788c1
---
common/Kconfig | 2 +-
drivers/video/dw_hdmi.c | 8 ++++----
drivers/video/rockchip/rk_vop.c | 14 ++++++++++++++
include/dw_hdmi.h | 4 ++--
4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig

index 361346b092..355e816c9d 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -245,7 +245,7 @@ endmenu

config BOOTDELAY
int "delay in seconds before automatically booting"
- default 2
+ default 5
depends on AUTOBOOT
help
Delay before automatically running bootcmd;
diff --git a/drivers/video/dw_hdmi.c b/drivers/video/dw_hdmi.c
index 6039d676c5..0d7a7c228d 100644
--- a/drivers/video/dw_hdmi.c
+++ b/drivers/video/dw_hdmi.c
@@ -340,7 +340,7 @@ static int hdmi_phy_configure(struct dw_hdmi *hdmi, u32 mpixelclock)

hdmi_phy_i2c_write(hdmi, hdmi->mpll_cfg[i].cpce, PHY_OPMODE_PLLCFG);
hdmi_phy_i2c_write(hdmi, hdmi->mpll_cfg[i].gmp, PHY_PLLGMPCTRL);
- hdmi_phy_i2c_write(hdmi, hdmi->mpll_cfg[i].curr, PHY_PLLCURRCTRL);
+ hdmi_phy_i2c_write(hdmi, 0x0000, PHY_PLLCURRCTRL);

hdmi_phy_i2c_write(hdmi, 0x0000, PHY_PLLPHBYCTRL);
hdmi_phy_i2c_write(hdmi, 0x0006, PHY_PLLCLKBISTPHASE);
@@ -560,8 +560,8 @@ static int hdmi_read_edid(struct dw_hdmi *hdmi, int block, u8 *buff)
u32 n;

/* set ddc i2c clk which devided from ddc_clk to 100khz */
- hdmi_write(hdmi, hdmi->i2c_clk_high, HDMI_I2CM_SS_SCL_HCNT_0_ADDR);
- hdmi_write(hdmi, hdmi->i2c_clk_low, HDMI_I2CM_SS_SCL_LCNT_0_ADDR);
+ //hdmi_write(hdmi, hdmi->i2c_clk_high, HDMI_I2CM_SS_SCL_HCNT_0_ADDR);
+ //hdmi_write(hdmi, hdmi->i2c_clk_low, HDMI_I2CM_SS_SCL_LCNT_0_ADDR);
hdmi_mod(hdmi, HDMI_I2CM_DIV, HDMI_I2CM_DIV_FAST_STD_MODE,
HDMI_I2CM_DIV_STD_MODE);

@@ -663,7 +663,7 @@ int dw_hdmi_phy_wait_for_hpd(struct dw_hdmi *hdmi)
if (hdmi_get_plug_in_status(hdmi))
return 0;
udelay(100);
- } while (get_timer(start) < 300);
+ } while (get_timer(start) < 5000);

return -1;
}
diff --git a/drivers/video/rockchip/rk_vop.c b/drivers/video/rockchip/rk_vop.c
index c979049b5b..7bcc3df69b 100644
--- a/drivers/video/rockchip/rk_vop.c
+++ b/drivers/video/rockchip/rk_vop.c
@@ -277,6 +277,20 @@ static int rk_display_init(struct udevice *dev, ulong fbbase, int ep_node)
return ret;
}

+ /* Use 1080p display_timing when connect 4K HDMI screen */
+ if (timing.hactive.typ >= 3840) {
+ timing.pixelclock.typ = 148500000;
+ timing.hactive.typ = 1920;
+ timing.vactive.typ = 1080;
+ timing.hsync_len.typ = 44;
+ timing.hback_porch.typ = 148;
+ timing.vsync_len.typ = 5;
+ timing.vback_porch.typ = 36;
+ timing.hfront_porch.typ = 88;
+ timing.vfront_porch.typ = 4;
+ debug("Use default 1080P settings \n");
+ }
+
ret = clk_get_by_index(dev, 1, &clk);
if (!ret)
ret = clk_set_rate(&clk, timing.pixelclock.typ);
diff --git a/include/dw_hdmi.h b/include/dw_hdmi.h
index 902abd4d44..c1f1fbff6a 100644
--- a/include/dw_hdmi.h
+++ b/include/dw_hdmi.h
@@ -448,7 +448,7 @@ enum {
};

struct hdmi_mpll_config {
- u64 mpixelclock;
+ u32 mpixelclock;
/* Mode of Operation and PLL Dividers Control Register */
u32 cpce;
/* PLL Gmp Control Register */
@@ -458,7 +458,7 @@ struct hdmi_mpll_config {
};

struct hdmi_phy_config {
- u64 mpixelclock;
+ u32 mpixelclock;
u32 sym_ctr; /* clock symbol and transmitter control */
u32 term; /* transmission termination value */
u32 vlev_ctr; /* voltage level control */
--
2.17.1

@@ -0,0 +1,70 @@
From d0d5938a3f8a524a884c460c5870c0c966daf152 Mon Sep 17 00:00:00 2001
From: jamess_huang <Jamess_Huang@asus.com>
Date: Fri, 11 Aug 2017 18:10:22 +0800
Subject: [PATCH 18/50] pmic: enable LDO2 vcc33_mipi at bootup

power up camera module to prevent i2c-2 SDA pulled low

Change-Id: I199bef9c8aa4385dbda33117e2ca0c64dc7a13d4
---
board/rockchip/tinker_rk3288/tinker-rk3288.c | 38 ++++++++++++++++++++
1 file changed, 38 insertions(+)
mode change 100644 => 100755 board/rockchip/tinker_rk3288/tinker-rk3288.c

diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c b/board/rockchip/tinker_rk3288/tinker-rk3288.c
index c2872e7330..5618bd9923 100644
--- a/board/rockchip/tinker_rk3288/tinker-rk3288.c
+++ b/board/rockchip/tinker_rk3288/tinker-rk3288.c
@@ -8,6 +8,8 @@
#include <dm.h>
#include <i2c_eeprom.h>
#include <netdev.h>
+#include <power/regulator.h>
+

static int get_ethaddr_from_eeprom(u8 *addr)
{
@@ -33,3 +35,39 @@ int rk_board_late_init(void)

return 0;
}
+
+
+#ifdef CONFIG_DM_PMIC
+static int rockchip_set_regulator_on(const char *name, uint uv)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = regulator_get_by_platname(name, &dev);
+ if (ret) {
+ debug("%s: Cannot find regulator %s\n", __func__, name);
+ return ret;
+ }
+ ret = regulator_set_value(dev, uv);
+ if (ret) {
+ debug("%s: Cannot set regulator %s\n", __func__, name);
+ return ret;
+ }
+ ret = regulator_set_enable(dev, 1);
+ if (ret) {
+ debug("%s: Cannot enable regulator %s\n", __func__, name);
+ return ret;
+ }
+
+ return 0;
+}
+
+int power_init_board(void)
+{
+ int ret = rockchip_set_regulator_on("vcc33_mipi", 3300000);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+#endif
\ No newline at end of file
--
2.17.1

@@ -0,0 +1,206 @@
From 11b9e1141895e719e2ad4421f746c4b5359c671b Mon Sep 17 00:00:00 2001
From: jamess_huang <Jamess_Huang@asus.com>
Date: Thu, 12 Oct 2017 11:47:27 +0800
Subject: [PATCH 36/50] auto enable ums mode when TinkerBoard is connected to
PC

Change-Id: Ice3f37906ab1ae0428c1d23867a58c5c720aa8ab
---
arch/arm/include/asm/arch-rockchip/gpio.h | 22 ++++++++
arch/arm/mach-rockchip/rk3288-board.c | 62 +++++++++++++++++++++++
cmd/usb_mass_storage.c | 2 +-
common/autoboot.c | 17 +++++++
common/board_r.c | 1 +
include/common.h | 1 +
6 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-rockchip/gpio.h b/arch/arm/include/asm/arch-rockchip/gpio.h
index e39218d0a9..10f4f41e67 100644
--- a/arch/arm/include/asm/arch-rockchip/gpio.h
+++ b/arch/arm/include/asm/arch-rockchip/gpio.h
@@ -25,4 +25,26 @@ struct rockchip_gpio_regs {
};
check_member(rockchip_gpio_regs, ls_sync, 0x60);

+/*
+ * RK3288 IO memory map:
+ *
+ */
+#define RKIO_GPIO0_PHYS 0xFF750000
+#define RKIO_GRF_PHYS 0xFF770000
+#define RKIO_GPIO1_PHYS 0xFF780000
+#define RKIO_GPIO2_PHYS 0xFF790000
+#define RKIO_GPIO3_PHYS 0xFF7A0000
+#define RKIO_GPIO4_PHYS 0xFF7B0000
+#define RKIO_GPIO5_PHYS 0xFF7C0000
+#define RKIO_GPIO6_PHYS 0xFF7D0000
+
+/* gpio power down/up control */
+#define GRF_GPIO2A_P 0x150
+#define GRF_GPIO6A_P 0x190
+
+/* gpio input/output control */
+#define GPIO_SWPORT_DR 0x00
+#define GPIO_SWPORT_DDR 0x04
+#define GPIO_EXT_PORT 0x50
+
#endif
diff --git a/arch/arm/mach-rockchip/rk3288-board.c b/arch/arm/mach-rockchip/rk3288-board.c
index f1569e62b6..32f70a5920 100644
--- a/arch/arm/mach-rockchip/rk3288-board.c
+++ b/arch/arm/mach-rockchip/rk3288-board.c
@@ -22,6 +22,19 @@

DECLARE_GLOBAL_DATA_PTR;

+enum project_id {
+ TinkerBoardS = 0,
+ TinkerBoard = 7,
+};
+
+enum pcb_id {
+ SR,
+ ER,
+ PR,
+};
+
+extern bool force_ums;
+
__weak int rk_board_late_init(void)
{
return 0;
@@ -91,6 +104,55 @@ int board_late_init(void)
return rk_board_late_init();
}

+int check_force_enter_ums_mode(void)
+{
+ int tmp;
+ enum pcb_id pcbid;
+ enum project_id projectid;
+
+ // GPIO2_A1/GPIO2_A2/GPIO2_A3 pull up enable
+ // please check TRM V1.2 part1 page 152
+ tmp = readl(RKIO_GRF_PHYS + GRF_GPIO2A_P);
+ writel((tmp&~(0x03F<<2)) | 0x3F<<(16 + 2) | 0x15<<2, RKIO_GRF_PHYS + GRF_GPIO2A_P);
+
+ // GPIO2_A1/GPIO2_A2/GPIO2_A3/GPIO2_B0/GPIO2_B1/GPIO2_B2 set to input
+ tmp = readl(RKIO_GPIO2_PHYS + GPIO_SWPORT_DDR);
+ writel(tmp & ~(0x70E), RKIO_GPIO2_PHYS + GPIO_SWPORT_DDR);
+
+ // GPIO6_A5 pull up/down disable
+ tmp = readl(RKIO_GRF_PHYS + GRF_GPIO6A_P);
+ writel((tmp&~(0x03<<10)) | 0x03<<(16 + 10), RKIO_GRF_PHYS + GRF_GPIO6A_P);
+
+ // GPIO6_A5 set to input
+ tmp = readl(RKIO_GPIO6_PHYS + GPIO_SWPORT_DDR);
+ writel(tmp & ~(0x20), RKIO_GPIO6_PHYS + GPIO_SWPORT_DDR);
+
+ mdelay(10);
+
+ // read GPIO2_A1/GPIO2_A2/GPIO2_A3 value
+ projectid = (readl(RKIO_GPIO2_PHYS + GPIO_EXT_PORT) & 0x0E) >>1;
+
+ // read GPIO2_B0/GPIO2_B1/GPIO2_B2 value
+ pcbid = (readl(RKIO_GPIO2_PHYS + GPIO_EXT_PORT) & 0x700) >> 8;
+
+ // only Tinker Board S and the PR stage PCB has this function
+ if(projectid!=TinkerBoard && pcbid >= ER){
+ printf("PC event = 0x%x\n", readl(RKIO_GPIO6_PHYS + GPIO_EXT_PORT)&0x20);
+ if((readl(RKIO_GPIO6_PHYS + GPIO_EXT_PORT)&0x20)==0x20) {
+ // SDP detected, enable EMMC and unlock usb current limit
+ printf("usb connected to SDP, force enter ums mode\n");
+ force_ums = true;
+ // unlock usb current limit and re-enable EMMC
+ // set GPIO6_A6, GPIO6_A7 to high
+ tmp = readl(RKIO_GPIO6_PHYS + GPIO_SWPORT_DR);
+ writel(tmp | 0xc0, RKIO_GPIO6_PHYS + GPIO_SWPORT_DR);
+ tmp = readl(RKIO_GPIO6_PHYS + GPIO_SWPORT_DDR);
+ writel(tmp | 0xc0, RKIO_GPIO6_PHYS + GPIO_SWPORT_DDR);
+ }
+ }
+ return 0;
+}
+
#if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
static int veyron_init(void)
{
diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c
index 3353f95c74..cb5260b558 100644
--- a/cmd/usb_mass_storage.c
+++ b/cmd/usb_mass_storage.c
@@ -133,7 +133,7 @@ cleanup:
return ret;
}

-static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
+int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
const char *usb_controller;
diff --git a/common/autoboot.c b/common/autoboot.c
index c52bad84a4..d63a4d7e79 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -28,6 +28,8 @@ DECLARE_GLOBAL_DATA_PTR;
/* Stored value of bootdelay, used by autoboot_command() */
static int stored_bootdelay;

+bool force_ums = false;
+
#if defined(CONFIG_AUTOBOOT_KEYED)
#if defined(CONFIG_AUTOBOOT_STOP_STR_SHA256)

@@ -339,10 +341,25 @@ const char *bootdelay_process(void)
return s;
}

+extern int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
void autoboot_command(const char *s)
{
debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");

+ if (force_ums) {
+ // force to enter ums mode
+ char *local_args[4];
+ char str1[]="ums", str2[]="1", str3[]="mmc", str4[]="0";
+
+ local_args[0]=str1;
+ local_args[1]=str2;
+ local_args[2]=str3;
+ local_args[3]=str4;
+ do_usb_mass_storage(NULL, 0, 4, local_args);
+ return;
+ }
+
if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) {
#if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC)
int prev = disable_ctrlc(1); /* disable Control C checking */
diff --git a/common/board_r.c b/common/board_r.c
index ecca1edb04..77b3a05693 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -800,6 +800,7 @@ static init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_CMD_ONENAND
initr_onenand,
#endif
+ check_force_enter_ums_mode,
#ifdef CONFIG_MMC
initr_mmc,
#endif
diff --git a/include/common.h b/include/common.h
index 751665f8a4..13a6e563c3 100644
--- a/include/common.h
+++ b/include/common.h
@@ -418,6 +418,7 @@ extern ssize_t spi_write (uchar *, int, uchar *, int);
int board_early_init_f (void);
int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */
int board_late_init (void);
+int check_force_enter_ums_mode (void);
int board_postclk_init (void); /* after clocks/timebase, before env/serial */
int board_early_init_r (void);
void board_poweroff (void);
--
2.17.1

0 comments on commit bb2ce93

Please sign in to comment.