Dash:
[t2-trunk.git] / architecture / riscv64 / package / u-boot / 0006-board-sifive-Add-an-interface-to-get-PCB-revision.patch
blob2ea374016ef944717333f4fd78669dd6f06473d3
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>
12 ---
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
19 new file mode 100644
20 index 0000000..0e1220e
21 --- /dev/null
22 +++ b/arch/riscv/include/asm/arch-fu740/eeprom.h
23 @@ -0,0 +1,15 @@
24 +/* SPDX-License-Identifier: GPL-2.0 */
25 +/*
26 + * Copyright (C) 2021 SiFive, Inc.
27 + *
28 + * Zong Li <zong.li@sifve.com>
29 + */
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)
45 return 0;
48 +/**
49 + * get_pcb_revision_from_eeprom - get the PCB revision
50 + *
51 + * Read the EEPROM to determine the board revision.
52 + *
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.
55 + */
56 +u8 get_pcb_revision_from_eeprom(void)
58 + struct __attribute__ ((__packed__)) board_eeprom {
59 + u8 magic[MAGIC_NUMBER_BYTES];
60 + u8 format_ver;
61 + u16 product_id;
62 + u8 pcb_revision;
63 + } be;
65 + int ret;
66 + struct udevice *dev;
68 + ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
69 + CONFIG_SYS_I2C_EEPROM_ADDR,
70 + 1,
71 + &dev);
73 + if (!ret)
74 + dm_i2c_read(dev, 0, (void *)&be,
75 + sizeof(struct board_eeprom));
77 + return be.pcb_revision;
79 --
80 2.7.4