1 From cdecb59564d7b2f2f0a53a41e6933f63badb2def Mon Sep 17 00:00:00 2001
2 From: Zong Li <zong.li@sifive.com>
3 Date: Wed, 30 Jun 2021 23:23:48 +0800
4 Subject: [PATCH 06/16] board: sifive: Add an interface to get PCB revision
6 There are different DDR parameter settings for different board
7 revisions. Add a new interface to get the PCB revision to determine
8 which DT should be selected at runtime.
10 Signed-off-by: Zong Li <zong.li@sifive.com>
11 Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
13 arch/riscv/include/asm/arch-fu740/eeprom.h | 15 ++++++++++
14 .../sifive/unmatched/hifive-platform-i2c-eeprom.c | 32 ++++++++++++++++++++++
15 2 files changed, 47 insertions(+)
16 create mode 100644 arch/riscv/include/asm/arch-fu740/eeprom.h
18 diff --git a/arch/riscv/include/asm/arch-fu740/eeprom.h b/arch/riscv/include/asm/arch-fu740/eeprom.h
20 index 0000000..0e1220e
22 +++ b/arch/riscv/include/asm/arch-fu740/eeprom.h
24 +/* SPDX-License-Identifier: GPL-2.0 */
26 + * Copyright (C) 2021 SiFive, Inc.
28 + * Zong Li <zong.li@sifve.com>
31 +#ifndef _ASM_RISCV_EEPROM_H
32 +#define _ASM_RISCV_EEPROM_H
34 +#define PCB_REVISION_REV3 0x3
36 +u8 get_pcb_revision_from_eeprom(void);
38 +#endif /* _ASM_RISCV_EEPROM_H */
39 diff --git a/board/sifive/unmatched/hifive-platform-i2c-eeprom.c b/board/sifive/unmatched/hifive-platform-i2c-eeprom.c
40 index 9a62d32..a2151f1 100644
41 --- a/board/sifive/unmatched/hifive-platform-i2c-eeprom.c
42 +++ b/board/sifive/unmatched/hifive-platform-i2c-eeprom.c
43 @@ -540,3 +540,35 @@ int mac_read_from_eeprom(void)
49 + * get_pcb_revision_from_eeprom - get the PCB revision
51 + * Read the EEPROM to determine the board revision.
53 + * This function is called before relocation, so we need to read a private
54 + * copy of the EEPROM into a local variable on the stack.
56 +u8 get_pcb_revision_from_eeprom(void)
58 + struct __attribute__ ((__packed__)) board_eeprom {
59 + u8 magic[MAGIC_NUMBER_BYTES];
66 + struct udevice *dev;
68 + ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
69 + CONFIG_SYS_I2C_EEPROM_ADDR,
74 + dm_i2c_read(dev, 0, (void *)&be,
75 + sizeof(struct board_eeprom));
77 + return be.pcb_revision;