From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Piotr Szczepanik Date: Sun, 3 May 2020 20:42:50 +0200 Subject: [ARCHEOLOGY] Added rk3328 efuse driver and stable secondary mac address to u-boot (#1939) > X-Git-Archeology: - Revision 7113913be8597cd269f61a7f8fd82da41d7b03a4: https://github.com/armbian/build/commit/7113913be8597cd269f61a7f8fd82da41d7b03a4 > X-Git-Archeology: Date: Sun, 03 May 2020 20:42:50 +0200 > X-Git-Archeology: From: Piotr Szczepanik > X-Git-Archeology: Subject: Added rk3328 efuse driver and stable secondary mac address to u-boot (#1939) > X-Git-Archeology: > X-Git-Archeology: - Revision 88a585a3fe56bf9eb8c1df8993fe34830597ca77: https://github.com/armbian/build/commit/88a585a3fe56bf9eb8c1df8993fe34830597ca77 > X-Git-Archeology: Date: Sat, 18 Jul 2020 00:06:01 +0200 > X-Git-Archeology: From: Piotr Szczepanik > X-Git-Archeology: Subject: Update mainline u-boot for rockchip64 / rk3399 to v2020.07 (#2086) > X-Git-Archeology: > X-Git-Archeology: - Revision 86abac1fd4e169712a44d245cf7adef4ee17c420: https://github.com/armbian/build/commit/86abac1fd4e169712a44d245cf7adef4ee17c420 > X-Git-Archeology: Date: Tue, 26 Oct 2021 22:14:41 +0200 > X-Git-Archeology: From: Piotr Szczepanik > X-Git-Archeology: Subject: Cleanup u-boot configurations for rockchip64 derivatives (#3150) > X-Git-Archeology: > X-Git-Archeology: - Revision 71ff7b3b989dcb7e86b7e1c00a408a2f53744ea0: https://github.com/armbian/build/commit/71ff7b3b989dcb7e86b7e1c00a408a2f53744ea0 > X-Git-Archeology: Date: Thu, 11 Nov 2021 23:49:52 +0100 > X-Git-Archeology: From: Piotr Szczepanik > X-Git-Archeology: Subject: Switched rockchip64 u-boot to v2021.07 (#3233) > X-Git-Archeology: > X-Git-Archeology: - Revision 2813365dd25e3ad110936cbf014b95b38d7090ec: https://github.com/armbian/build/commit/2813365dd25e3ad110936cbf014b95b38d7090ec > X-Git-Archeology: Date: Mon, 07 Nov 2022 21:29:00 +0100 > X-Git-Archeology: From: Igor Pecovnik > X-Git-Archeology: Subject: Move known non working rockhip64 boards to previous boot loader (#4392) > X-Git-Archeology: --- drivers/misc/rockchip-efuse.c | 85 +++++++++- include/configs/rk3328_common.h | 4 + 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c index 083ee65e0a..40a7db6278 100644 --- a/drivers/misc/rockchip-efuse.c +++ b/drivers/misc/rockchip-efuse.c @@ -13,8 +13,18 @@ #include #include #include +#include #include +#define RK3328_INT_STATUS 0x0018 +#define RK3328_DOUT 0x0020 +#define RK3328_AUTO_CTRL 0x0024 +#define RK3328_INT_FINISH BIT(0) +#define RK3328_AUTO_ENB BIT(0) +#define RK3328_AUTO_RD BIT(1) +#define RK3328_NO_SECURE_BYTES 32 +#define RK3328_SECURE_BYTES 96 + #define RK3399_A_SHIFT 16 #define RK3399_A_MASK 0x3ff #define RK3399_NFUSES 32 @@ -27,6 +37,9 @@ #define RK3399_STROBE BIT(1) #define RK3399_CSB BIT(0) +typedef int (*EFUSE_READ)(struct udevice *dev, int offset, void *buf, + int size); + struct rockchip_efuse_regs { u32 ctrl; /* 0x00 efuse control register */ u32 dout; /* 0x04 efuse data out register */ @@ -35,6 +48,10 @@ struct rockchip_efuse_regs { u32 jtag_pass; /* 0x10 JTAG password */ u32 strobe_finish_ctrl; /* 0x14 efuse strobe finish control register */ + u32 int_status;/* 0x18 */ + u32 reserved; /* 0x1c */ + u32 dout2; /* 0x20 */ + u32 auto_ctrl; /* 0x24 */ }; struct rockchip_efuse_plat { @@ -83,6 +100,57 @@ U_BOOT_CMD( ); #endif +static int rockchip_rk3328_efuse_read(struct udevice *dev, int offset, + void *buf, int size) +{ + struct rockchip_efuse_plat *plat = dev_get_plat(dev); + struct rockchip_efuse_regs *efuse = + (struct rockchip_efuse_regs *)plat->base; + unsigned int addr_start, addr_end, addr_offset, addr_len; + u32 out_value, status; + u8 *buffer; + int ret = 0, i = 0, j = 0; + + /* Max non-secure Byte */ + if (size > RK3328_NO_SECURE_BYTES) + size = RK3328_NO_SECURE_BYTES; + + /* 128 Byte efuse, 96 Byte for secure, 32 Byte for non-secure */ + offset += RK3328_SECURE_BYTES; + addr_start = rounddown(offset, RK3399_BYTES_PER_FUSE) / + RK3399_BYTES_PER_FUSE; + addr_end = roundup(offset + size, RK3399_BYTES_PER_FUSE) / + RK3399_BYTES_PER_FUSE; + addr_offset = offset % RK3399_BYTES_PER_FUSE; + addr_len = addr_end - addr_start; + + buffer = calloc(1, sizeof(*buffer) * addr_len * RK3399_BYTES_PER_FUSE); + if (!buffer) + return -ENOMEM; + + for (j = 0; j < addr_len; j++) { + writel(RK3328_AUTO_RD | RK3328_AUTO_ENB | + ((addr_start++ & RK3399_A_MASK) << RK3399_A_SHIFT), + &efuse->auto_ctrl); + udelay(5); + status = readl(&efuse->int_status); + if (!(status & RK3328_INT_FINISH)) { + ret = -EIO; + goto err; + } + out_value = readl(&efuse->dout2); + writel(RK3328_INT_FINISH, &efuse->int_status); + + memcpy(&buffer[i], &out_value, RK3399_BYTES_PER_FUSE); + i += RK3399_BYTES_PER_FUSE; + } + memcpy(buf, buffer + addr_offset, size); +err: + free(buffer); + + return ret; +} + static int rockchip_rk3399_efuse_read(struct udevice *dev, int offset, void *buf, int size) { @@ -130,7 +198,13 @@ static int rockchip_rk3399_efuse_read(struct udevice *dev, int offset, static int rockchip_efuse_read(struct udevice *dev, int offset, void *buf, int size) { - return rockchip_rk3399_efuse_read(dev, offset, buf, size); + EFUSE_READ efuse_read = NULL; + + efuse_read = (EFUSE_READ)dev_get_driver_data(dev); + if (!efuse_read) + return -EINVAL; + + return (*efuse_read)(dev, offset, buf, size); } static const struct misc_ops rockchip_efuse_ops = { @@ -146,7 +220,14 @@ static int rockchip_efuse_of_to_plat(struct udevice *dev) } static const struct udevice_id rockchip_efuse_ids[] = { - { .compatible = "rockchip,rk3399-efuse" }, + { + .compatible = "rockchip,rk3328-efuse", + .data = (ulong)&rockchip_rk3328_efuse_read, + }, + { + .compatible = "rockchip,rk3399-efuse", + .data = (ulong)&rockchip_rk3399_efuse_read, + }, {} }; diff --git a/include/configs/rk3328_common.h b/include/configs/rk3328_common.h index c1e26a019b..67a951673a 100644 --- a/include/configs/rk3328_common.h +++ b/include/configs/rk3328_common.h @@ -21,6 +21,10 @@ #define CONFIG_SPL_BSS_START_ADDR 0x2000000 #define CONFIG_SPL_BSS_MAX_SIZE 0x2000 +#define CONFIG_MISC 1 +#define CONFIG_MISC_INIT_R 1 +#define CONFIG_ROCKCHIP_EFUSE 1 + #define CONFIG_SYS_BOOTM_LEN (64 << 20) /* 64M */ /* FAT sd card locations. */ -- Armbian