Add FU740 chip and HiFive Unmatched board support
Subsystems (7)
v7 cover Add FU740 chip and HiFive Unmatched board support
This patch set is to add SiFive fu740 chip and HiFive Unmatched board support. Patches are split into several parts:
- [PATCH v7 1/8] support for fu740 cpu
- [PATCH v7 2/8] support for fu740 clk driver
- [PATCH v7 3/8] rename and support for fu740 ram driver
- [PATCH v7 4/8] add pcie driver
- [PATCH v7 5/8] dts for SiFive fu740
- [PATCH v7 6/8] dts for SiFive Unmatched board
- [PATCH v7 7/8] add Unmatched board support
- [PATCH v7 8/8] add fu740 support to macb driver
Description
- For fu740 cpu support, reuse most of fu540 cpu.
- For prci driver, add one abstract layer to separate fu540 and fu740. Move orignal fu540 code to separate files.
- For pcie driver, it depends on gpio, prci, clk and reset drivers to do init&reset works. Also based on pcie_dw_common.c
- Align with Linux DT file.
Tests and patch checks
- Able to boot both unmatched and unleashed boards.
- PCIe tests
. M.2 NVMe SSD
. e1000 compatibale ethernet adapter (ping&tftpboot) . pci-to-usb adapter(usb mass storage)
- checkpatch is performed. To keep code derived from other boards the same, ignore some warnings/errors in [PATCH 7/8].
Changlogs
- V7
. Rebase to latest master branch
. Moved dts for fu740 patch [v6 1/7] to [v7 5/8] and seperate dts of
Unmatched board from [v6 6/7] into [v7 6/8]
. Applied PCIe refactoring patch to base on the common code in
pcie_dw_common.c
- V6
. Remove redundant DT string for 1.2GHz CPU clock and squash to
[1/7]
- V5
. Fix unleashed build error in patch [6/8]
. Append one more set for 1.2GHz CPU speed
. Add "#include <asm/global_data.h>" back to sifive_ddr.c . Add Reviewed-by to [4/8] and [7/8]
- V4
. fixed incorrect file name in ./board/sifive/unmatched/Makefile . fixed link in doc/board/sifive/index.rst, passed 'make htmldocs'
- V3
. Rebase to unleashed rename v2 patch
. Rename
doc/board/sifive/unmatched.rst board/sifive/unmatched/unmatched.c
. Fix tail whitespace
. Add 'git mv' info to ram driver and merge patch back to one . Add comment to macb driver for PLL hardware quirk
. Add reviewed-by to patch [6/7]
. Add 'gpio-poweroff' node for upcoming opensbi integration
- V2
. Rebase to unleashed rename patch
. remove unnessaary fu540 changes
. split ram driver patch into 2 to keep 'git mv' info
. use a shorter name for unmatched support
. Remove redundant&incorrect temperature-sensor in DT
. Remove unnecessary USB EHCI & OHCI from defconfig
. Revised fu740 doc
. Fixed year of copyright
. Add reviewed-by received in v1 patch
David Abdurachmanov (1):
drivers: net: macb: add fu740 support
Green Wan (7):
riscv: cpu: fu740: Add support for cpu fu740
drivers: clk: add fu740 support
drivers: ram: sifive: rename fu540_ddr and add fu740 support
drivers: pci: add pcie support for fu740
riscv: dts: add fu740 support
riscv: dts: add SiFive Unmatched board support
board: sifive: add HiFive Unmatched board support
arch/riscv/Kconfig | 5 +
arch/riscv/cpu/fu740/Kconfig | 37 +
arch/riscv/cpu/fu740/Makefile | 12 +
arch/riscv/cpu/fu740/cache.c | 55 +
arch/riscv/cpu/fu740/cpu.c | 22 +
arch/riscv/cpu/fu740/dram.c | 38 +
arch/riscv/cpu/fu740/spl.c | 23 +
arch/riscv/dts/Makefile | 1 +
arch/riscv/dts/fu740-c000-u-boot.dtsi | 105 ++
arch/riscv/dts/fu740-c000.dtsi | 329 ++++
.../dts/fu740-hifive-unmatched-a00-ddr.dtsi | 1489 +++++++++++++++++
.../dts/hifive-unmatched-a00-u-boot.dtsi | 40 +
arch/riscv/dts/hifive-unmatched-a00.dts | 259 +++
arch/riscv/include/asm/arch-fu740/cache.h | 14 +
arch/riscv/include/asm/arch-fu740/clk.h | 14 +
arch/riscv/include/asm/arch-fu740/gpio.h | 38 +
arch/riscv/include/asm/arch-fu740/reset.h | 13 +
arch/riscv/include/asm/arch-fu740/spl.h | 14 +
arch/riscv/lib/sifive_clint.c | 1 -
board/sifive/unleashed/Kconfig | 1 +
board/sifive/unmatched/Kconfig | 50 +
board/sifive/unmatched/MAINTAINERS | 9 +
board/sifive/unmatched/Makefile | 9 +
board/sifive/unmatched/spl.c | 85 +
board/sifive/unmatched/unmatched.c | 24 +
common/spl/Kconfig | 4 +-
configs/sifive_unleashed_defconfig | 1 +
configs/sifive_unmatched_defconfig | 54 +
doc/board/sifive/index.rst | 1 +
doc/board/sifive/unmatched.rst | 536 ++++++
drivers/clk/sifive/Kconfig | 8 +-
drivers/clk/sifive/Makefile | 4 +-
drivers/clk/sifive/fu540-prci.c | 769 +--------
drivers/clk/sifive/fu540-prci.h | 22 +
drivers/clk/sifive/fu740-prci.c | 158 ++
drivers/clk/sifive/fu740-prci.h | 22 +
drivers/clk/sifive/sifive-prci.c | 733 ++++++++
drivers/clk/sifive/sifive-prci.h | 323 ++++
drivers/net/macb.c | 13 +-
drivers/pci/Kconfig | 10 +
drivers/pci/Makefile | 1 +
drivers/pci/pcie_dw_sifive.c | 508 ++++++
drivers/ram/sifive/Kconfig | 8 +-
drivers/ram/sifive/Makefile | 2 +-
.../ram/sifive/{fu540_ddr.c => sifive_ddr.c} | 89 +-
drivers/reset/Kconfig | 2 +-
include/configs/sifive-unmatched.h | 85 +
include/dt-bindings/clock/sifive-fu740-prci.h | 25 +
include/dt-bindings/reset/sifive-fu740-prci.h | 19 +
49 files changed, 5277 insertions(+), 807 deletions(-)
create mode 100644 arch/riscv/cpu/fu740/Kconfig
create mode 100644 arch/riscv/cpu/fu740/Makefile
create mode 100644 arch/riscv/cpu/fu740/cache.c
create mode 100644 arch/riscv/cpu/fu740/cpu.c
create mode 100644 arch/riscv/cpu/fu740/dram.c
create mode 100644 arch/riscv/cpu/fu740/spl.c
create mode 100644 arch/riscv/dts/fu740-c000-u-boot.dtsi
create mode 100644 arch/riscv/dts/fu740-c000.dtsi
create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr.dtsi
create mode 100644 arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi
create mode 100644 arch/riscv/dts/hifive-unmatched-a00.dts
create mode 100644 arch/riscv/include/asm/arch-fu740/cache.h
create mode 100644 arch/riscv/include/asm/arch-fu740/clk.h
create mode 100644 arch/riscv/include/asm/arch-fu740/gpio.h
create mode 100644 arch/riscv/include/asm/arch-fu740/reset.h
create mode 100644 arch/riscv/include/asm/arch-fu740/spl.h
create mode 100644 board/sifive/unmatched/Kconfig
create mode 100644 board/sifive/unmatched/MAINTAINERS
create mode 100644 board/sifive/unmatched/Makefile
create mode 100644 board/sifive/unmatched/spl.c
create mode 100644 board/sifive/unmatched/unmatched.c
create mode 100644 configs/sifive_unmatched_defconfig
create mode 100644 doc/board/sifive/unmatched.rst
create mode 100644 drivers/clk/sifive/fu540-prci.h
create mode 100644 drivers/clk/sifive/fu740-prci.c
create mode 100644 drivers/clk/sifive/fu740-prci.h
create mode 100644 drivers/clk/sifive/sifive-prci.c
create mode 100644 drivers/clk/sifive/sifive-prci.h
create mode 100644 drivers/pci/pcie_dw_sifive.c
rename drivers/ram/sifive/{fu540_ddr.c => sifive_ddr.c} (81%)
create mode 100644 include/configs/sifive-unmatched.h
create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h
create mode 100644 include/dt-bindings/reset/sifive-fu740-prci.hSignature · 1 line
2.31.0
PATCH v7 1/8 riscv: cpu: fu740: Add support for cpu fu740
Add SiFive fu740 cpu to support RISC-V arch
--- arch/riscv/Kconfig | 1 + arch/riscv/cpu/fu740/Kconfig | 37 +++++++++++++++ arch/riscv/cpu/fu740/Makefile | 12 +++++ arch/riscv/cpu/fu740/cache.c | 55 +++++++++++++++++++++++ arch/riscv/cpu/fu740/cpu.c | 22 +++++++++ arch/riscv/cpu/fu740/dram.c | 38 ++++++++++++++++ arch/riscv/cpu/fu740/spl.c | 23 ++++++++++ arch/riscv/include/asm/arch-fu740/cache.h | 14 ++++++ arch/riscv/include/asm/arch-fu740/clk.h | 14 ++++++ arch/riscv/include/asm/arch-fu740/gpio.h | 38 ++++++++++++++++ arch/riscv/include/asm/arch-fu740/reset.h | 13 ++++++ arch/riscv/include/asm/arch-fu740/spl.h | 14 ++++++ arch/riscv/lib/sifive_clint.c | 1 - 13 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/cpu/fu740/Kconfig create mode 100644 arch/riscv/cpu/fu740/Makefile create mode 100644 arch/riscv/cpu/fu740/cache.c create mode 100644 arch/riscv/cpu/fu740/cpu.c create mode 100644 arch/riscv/cpu/fu740/dram.c create mode 100644 arch/riscv/cpu/fu740/spl.c create mode 100644 arch/riscv/include/asm/arch-fu740/cache.h create mode 100644 arch/riscv/include/asm/arch-fu740/clk.h create mode 100644 arch/riscv/include/asm/arch-fu740/gpio.h create mode 100644 arch/riscv/include/asm/arch-fu740/reset.h create mode 100644 arch/riscv/include/asm/arch-fu740/spl.h
arch/riscv/Kconfig +1 -0
@@ -61,6 +61,7 @@ source "board/sipeed/maix/Kconfig" # platform-specific options below source "arch/riscv/cpu/ax25/Kconfig" source "arch/riscv/cpu/fu540/Kconfig" +source "arch/riscv/cpu/fu740/Kconfig" source "arch/riscv/cpu/generic/Kconfig" # architecture-specific options below
arch/riscv/cpu/fu740/Kconfig new file +37 -0
@@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2020-2021 SiFive, Inc +# Pragnesh Patel <[email protected]> + +config SIFIVE_FU740 + bool + select ARCH_EARLY_INIT_R + select RAM + select SPL_RAM if SPL + imply CPU + imply CPU_RISCV + imply RISCV_TIMER if (RISCV_SMODE || SPL_RISCV_SMODE) + imply SIFIVE_CLINT if (RISCV_MMODE || SPL_RISCV_MMODE) + imply CMD_CPU + imply SPL_CPU + imply SPL_OPENSBI + imply SPL_LOAD_FIT + imply SMP + imply CLK_SIFIVE + imply CLK_SIFIVE_PRCI + imply SIFIVE_SERIAL + imply MACB + imply MII + imply SPI + imply SPI_SIFIVE + imply MMC + imply MMC_SPI + imply MMC_BROKEN_CD + imply CMD_MMC + imply DM_GPIO + imply SIFIVE_GPIO + imply CMD_GPIO + imply MISC + imply SIFIVE_OTP + imply DM_PWM + imply PWM_SIFIVE
arch/riscv/cpu/fu740/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2020-2021 SiFive, Inc +# Pragnesh Patel <[email protected]> + +ifeq ($(CONFIG_SPL_BUILD),y) +obj-y += spl.o +else +obj-y += dram.o +obj-y += cpu.o +obj-y += cache.o +endif
arch/riscv/cpu/fu740/cache.c new file +55 -0
55 lines not on this page · raw message
arch/riscv/cpu/fu740/cpu.c new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018, Bin Meng <[email protected]> +*/ + +#include <irq_func.h> +#include <asm/cache.h> + +/* +* cleanup_before_linux() is called just before we call linux +* it prepares the processor for linux +* +* we disable interrupt and caches. +*/ +int cleanup_before_linux (void ) +{ +disable_interrupts (); + +cache_flush (); + +return 0 ; +}
arch/riscv/cpu/fu740/dram.c new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018, Bin Meng <[email protected]> +*/ + +#include <common.h> +#include <fdtdec.h> +#include <init.h> +#include <linux/sizes.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int dram_init (void ) +{ +return fdtdec_setup_mem_size_base (); +} + +int dram_init_banksize (void ) +{ +return fdtdec_setup_memory_banksize (); +} + +ulong board_get_usable_ram_top (ulong total_size) +{ +#ifdef CONFIG_64BIT +/* +* Ensure that we run from first 4GB so that all +* addresses used by U-Boot are 32bit addresses. +* +* This in-turn ensures that 32bit DMA capable +* devices work fine because DMA mapping APIs will +* provide 32bit DMA addresses only. +*/ +if (gd->ram_top >SZ_4G ) +return SZ_4G ; +#endif +return gd->ram_top; +}
arch/riscv/cpu/fu740/spl.c new file +23 -0
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2020-201 SiFive, Inc +* Pragnesh Patel <[email protected]> +*/ + +#include <dm.h> +#include <log.h> + +int spl_soc_init (void ) +{ +int ret; +struct udevice *dev; + +/* DDR init */ + ret =uclass_get_device (UCLASS_RAM ,0 , &dev); +if (ret) { +debug ("DRAM init failed: %d\n" , ret); +return ret; + } + +return 0 ; +}
arch/riscv/include/asm/arch-fu740/cache.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#ifndef _CACHE_SIFIVE_H +#define _CACHE_SIFIVE_H + +int cache_enable_ways (void ); + +#endif /* _CACHE_SIFIVE_H */
arch/riscv/include/asm/arch-fu740/clk.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c) 2020-2021 SiFive Inc +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#ifndef __CLK_SIFIVE_H +#define __CLK_SIFIVE_H + +/* Note: This is a placeholder header for driver compilation. */ + +#endif
arch/riscv/include/asm/arch-fu740/gpio.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +*/ + +#ifndef _GPIO_SIFIVE_H +#define _GPIO_SIFIVE_H + +#define GPIO_INPUT_VAL 0x00 +#define GPIO_INPUT_EN 0x04 +#define GPIO_OUTPUT_EN 0x08 +#define GPIO_OUTPUT_VAL 0x0C +#define GPIO_RISE_IE 0x18 +#define GPIO_RISE_IP 0x1C +#define GPIO_FALL_IE 0x20 +#define GPIO_FALL_IP 0x24 +#define GPIO_HIGH_IE 0x28 +#define GPIO_HIGH_IP 0x2C +#define GPIO_LOW_IE 0x30 +#define GPIO_LOW_IP 0x34 +#define GPIO_OUTPUT_XOR 0x40 + +#define NR_GPIOS 16 + +enum gpio_state { +LOW , +HIGH +}; + +/* Details about a GPIO bank */ +struct sifive_gpio_plat { +void *base;/* address of registers in physical memory */ +}; + +#define SIFIVE_GENERIC_GPIO_NR (port, index) \ + (((port) * NR_GPIOS) + ((index) & (NR_GPIOS - 1))) + +#endif /* _GPIO_SIFIVE_H */
arch/riscv/include/asm/arch-fu740/reset.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c) 2020-2021 SiFive, Inc. +* +* Author: Sagar Kadam <[email protected]> +*/ + +#ifndef __RESET_SIFIVE_H +#define __RESET_SIFIVE_H + +int sifive_reset_bind (struct udevice *dev,ulong count); + +#endif
arch/riscv/include/asm/arch-fu740/spl.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#ifndef _SPL_SIFIVE_H +#define _SPL_SIFIVE_H + +int spl_soc_init (void ); + +#endif /* _SPL_SIFIVE_H */
arch/riscv/lib/sifive_clint.c +0 -1
@@ -10,7 +10,6 @@#include <common.h> #include <dm.h> -#include <asm/global_data.h> #include <asm/io.h> #include <asm/smp.h> #include <linux/err.h>
Signature · 1 line
2.31.0
A message that is not in the archive (sent off-list or not yet received): CADWks+bKP1zF_ffZ6kE4qbrtG3wbCs5_7UA7MQOymnmTMicsxQ@mail.gmail.com
PATCH v7 1/8 riscv: cpu: fu740: Add support for cpu fu740
(resending to the list after subscribing)
Hi,
Quoted 395 lines · Green Wan
Add SiFive fu740 cpu to support RISC-V arch
Signed-off-by Green Wan <[email protected]>Reviewed-by Bin Meng <[email protected]>--- arch/riscv/Kconfig | 1 + arch/riscv/cpu/fu740/Kconfig | 37 +++++++++++++++ arch/riscv/cpu/fu740/Makefile | 12 +++++ arch/riscv/cpu/fu740/cache.c | 55 +++++++++++++++++++++++ arch/riscv/cpu/fu740/cpu.c | 22 +++++++++ arch/riscv/cpu/fu740/dram.c | 38 ++++++++++++++++ arch/riscv/cpu/fu740/spl.c | 23 ++++++++++ arch/riscv/include/asm/arch-fu740/cache.h | 14 ++++++ arch/riscv/include/asm/arch-fu740/clk.h | 14 ++++++ arch/riscv/include/asm/arch-fu740/gpio.h | 38 ++++++++++++++++ arch/riscv/include/asm/arch-fu740/reset.h | 13 ++++++ arch/riscv/include/asm/arch-fu740/spl.h | 14 ++++++ arch/riscv/lib/sifive_clint.c | 1 - 13 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/cpu/fu740/Kconfig create mode 100644 arch/riscv/cpu/fu740/Makefile create mode 100644 arch/riscv/cpu/fu740/cache.c create mode 100644 arch/riscv/cpu/fu740/cpu.c create mode 100644 arch/riscv/cpu/fu740/dram.c create mode 100644 arch/riscv/cpu/fu740/spl.c create mode 100644 arch/riscv/include/asm/arch-fu740/cache.h create mode 100644 arch/riscv/include/asm/arch-fu740/clk.h create mode 100644 arch/riscv/include/asm/arch-fu740/gpio.h create mode 100644 arch/riscv/include/asm/arch-fu740/reset.h create mode 100644 arch/riscv/include/asm/arch-fu740/spl.harch/riscv/Kconfig +1
-0@@ -61,6 +61,7 @@ source "board/sipeed/maix/Kconfig" # platform-specific options below source "arch/riscv/cpu/ax25/Kconfig" source "arch/riscv/cpu/fu540/Kconfig" +source "arch/riscv/cpu/fu740/Kconfig" source "arch/riscv/cpu/generic/Kconfig" # architecture-specific options belowarch/riscv/cpu/fu740/Kconfig new file +37
-0@@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2020-2021 SiFive, Inc +# Pragnesh Patel <[email protected]> + +config SIFIVE_FU740 + bool + select ARCH_EARLY_INIT_R + select RAM + select SPL_RAM if SPL + imply CPU + imply CPU_RISCV + imply RISCV_TIMER if (RISCV_SMODE || SPL_RISCV_SMODE) + imply SIFIVE_CLINT if (RISCV_MMODE || SPL_RISCV_MMODE) + imply CMD_CPU + imply SPL_CPU + imply SPL_OPENSBI + imply SPL_LOAD_FIT + imply SMP + imply CLK_SIFIVE + imply CLK_SIFIVE_PRCI + imply SIFIVE_SERIAL + imply MACB + imply MII + imply SPI + imply SPI_SIFIVE + imply MMC + imply MMC_SPI + imply MMC_BROKEN_CD + imply CMD_MMC + imply DM_GPIO + imply SIFIVE_GPIO + imply CMD_GPIO + imply MISC + imply SIFIVE_OTP + imply DM_PWM + imply PWM_SIFIVEarch/riscv/cpu/fu740/Makefile new file +12
-0@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2020-2021 SiFive, Inc +# Pragnesh Patel <[email protected]> + +ifeq ($(CONFIG_SPL_BUILD),y) +obj-y += spl.o +else +obj-y += dram.o +obj-y += cpu.o +obj-y += cache.o +endifarch/riscv/cpu/fu740/cache.c new file +55
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2020-2021 SiFive, Inc +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#include <common.h> +#include <asm/io.h> +#include <linux/bitops.h> +#include <asm/global_data.h> + +/* Register offsets */ +#define L2_CACHE_CONFIG 0x000 +#define L2_CACHE_ENABLE 0x008 + +#define MASK_NUM_WAYS GENMASK(15, 8) +#define NUM_WAYS_SHIFT 8 + +DECLARE_GLOBAL_DATA_PTR ; + +int cache_enable_ways (void ) +{ +const void *blob = gd->fdt_blob; +int node; +fdt_addr_t base; +u32 config; +u32 ways; + +volatile u32 *enable; + + node =fdt_node_offset_by_compatible (blob,-1 , +"sifive,fu740-c000-ccache" ); + +if (node <0 ) +return node; + + base =fdtdec_get_addr_size_auto_parent (blob,0 , node,"reg" ,0 , +NULL , false); +if (base ==FDT_ADDR_T_NONE ) +return FDT_ADDR_T_NONE ; + + config =readl ((volatile u32 *)base +L2_CACHE_CONFIG ); + ways = (config &MASK_NUM_WAYS ) >>NUM_WAYS_SHIFT ; + + enable = (volatile u32 *)(base +L2_CACHE_ENABLE ); + +/* memory barrier */ +mb (); + (*enable) = ways -1 ; +/* memory barrier */ +mb (); +return 0 ; +}arch/riscv/cpu/fu740/cpu.c new file +22
-0@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018, Bin Meng <[email protected]> +*/ + +#include <irq_func.h> +#include <asm/cache.h> + +/* +* cleanup_before_linux() is called just before we call linux +* it prepares the processor for linux +* +* we disable interrupt and caches. +*/ +int cleanup_before_linux (void ) +{ +disable_interrupts (); + +cache_flush (); + +return 0 ; +}arch/riscv/cpu/fu740/dram.c new file +38
-0@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018, Bin Meng <[email protected]> +*/ + +#include <common.h> +#include <fdtdec.h> +#include <init.h> +#include <linux/sizes.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int dram_init (void ) +{ +return fdtdec_setup_mem_size_base (); +} + +int dram_init_banksize (void ) +{ +return fdtdec_setup_memory_banksize (); +} + +ulong board_get_usable_ram_top (ulong total_size) +{ +#ifdef CONFIG_64BIT +/* +* Ensure that we run from first 4GB so that all +* addresses used by U-Boot are 32bit addresses. +* +* This in-turn ensures that 32bit DMA capable +* devices work fine because DMA mapping APIs will +* provide 32bit DMA addresses only. +*/ +if (gd->ram_top >SZ_4G ) +return SZ_4G ; +#endif +return gd->ram_top; +}arch/riscv/cpu/fu740/spl.c new file +23
-0@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2020-201 SiFive, Inc +* Pragnesh Patel <[email protected]> +*/ + +#include <dm.h> +#include <log.h> + +int spl_soc_init (void ) +{ +int ret; +struct udevice *dev; + +/* DDR init */ + ret =uclass_get_device (UCLASS_RAM ,0 , &dev); +if (ret) { +debug ("DRAM init failed: %d\n" , ret); +return ret; + } + +return 0 ; +}arch/riscv/include/asm/arch-fu740/cache.h new file +14
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#ifndef _CACHE_SIFIVE_H +#define _CACHE_SIFIVE_H + +int cache_enable_ways (void ); + +#endif /* _CACHE_SIFIVE_H */ arch/riscv/include/asm/arch-fu740/clk.h new file +14
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c) 2020-2021 SiFive Inc +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#ifndef __CLK_SIFIVE_H +#define __CLK_SIFIVE_H + +/* Note: This is a placeholder header for driver compilation. */ + +#endif arch/riscv/include/asm/arch-fu740/gpio.h new file +38
-0@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +*/ + +#ifndef _GPIO_SIFIVE_H +#define _GPIO_SIFIVE_H + +#define GPIO_INPUT_VAL 0x00 +#define GPIO_INPUT_EN 0x04 +#define GPIO_OUTPUT_EN 0x08 +#define GPIO_OUTPUT_VAL 0x0C +#define GPIO_RISE_IE 0x18 +#define GPIO_RISE_IP 0x1C +#define GPIO_FALL_IE 0x20 +#define GPIO_FALL_IP 0x24 +#define GPIO_HIGH_IE 0x28 +#define GPIO_HIGH_IP 0x2C +#define GPIO_LOW_IE 0x30 +#define GPIO_LOW_IP 0x34 +#define GPIO_OUTPUT_XOR 0x40 + +#define NR_GPIOS 16 + +enum gpio_state { +LOW , +HIGH +}; + +/* Details about a GPIO bank */ +struct sifive_gpio_plat { +void *base;/* address of registers in physical memory */ +}; + +#define SIFIVE_GENERIC_GPIO_NR (port, index) \ + (((port) * NR_GPIOS) + ((index) & (NR_GPIOS - 1))) + +#endif /* _GPIO_SIFIVE_H */ arch/riscv/include/asm/arch-fu740/reset.h new file +13
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c) 2020-2021 SiFive, Inc. +* +* Author: Sagar Kadam <[email protected]> +*/ + +#ifndef __RESET_SIFIVE_H +#define __RESET_SIFIVE_H + +int sifive_reset_bind (struct udevice *dev,ulong count); + +#endif arch/riscv/include/asm/arch-fu740/spl.h new file +14
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#ifndef _SPL_SIFIVE_H +#define _SPL_SIFIVE_H + +int spl_soc_init (void ); + +#endif /* _SPL_SIFIVE_H */ arch/riscv/lib/sifive_clint.c +0
-0
arch/riscv/lib/sifive_clint.c line 15
Quoted 7 lines
arch/riscv/lib/sifive_clint.c +0
-1@@ -10,7 +10,6 @@#include <common.h> #include <dm.h> -#include <asm/global_data.h> #include <asm/io.h> #include <asm/smp.h> #include <linux/err.h>
Why is this include being removed? As far as I can tell the file does use things from asm/global_data.h i.e. a little further down it does
...DECLARE_GLOBAL_DATA_PTR;
...gd->arch.clint
Which come from asm/global_data.h header. Am I missing something?
--
Regards,
Dimitri.
Signature · 3 lines
Regards, Dimitri.
PATCH v7 2/8 drivers: clk: add fu740 support
In reply to Green WanAdd fu740 support. One abstract layer is added for supporting multiple chips such as fu540 and fu740.
--- drivers/clk/sifive/Kconfig | 8 +- drivers/clk/sifive/Makefile | 4 +- drivers/clk/sifive/fu540-prci.c | 769 +------------------------------ drivers/clk/sifive/fu540-prci.h | 22 + drivers/clk/sifive/fu740-prci.c | 158 +++++++ drivers/clk/sifive/fu740-prci.h | 22 + drivers/clk/sifive/sifive-prci.c | 733 +++++++++++++++++++++++++++++ drivers/clk/sifive/sifive-prci.h | 323 +++++++++++++ 8 files changed, 1286 insertions(+), 753 deletions(-) create mode 100644 drivers/clk/sifive/fu540-prci.h create mode 100644 drivers/clk/sifive/fu740-prci.c create mode 100644 drivers/clk/sifive/fu740-prci.h create mode 100644 drivers/clk/sifive/sifive-prci.c create mode 100644 drivers/clk/sifive/sifive-prci.h
drivers/clk/sifive/Kconfig +4 -4
@@ -6,11 +6,11 @@ config CLK_SIFIVE help SoC drivers for SiFive Linux-capable SoCs. -config CLK_SIFIVE_FU540_PRCI - bool "PRCI driver for SiFive FU540 SoCs" +config CLK_SIFIVE_PRCI + bool "PRCI driver for SiFive SoCs" depends on CLK_SIFIVE select CLK_ANALOGBITS_WRPLL_CLN28HPC help Supports the Power Reset Clock interface (PRCI) IP block found in - FU540 SoCs. If this kernel is meant to run on a SiFive FU540 SoC, - enable this driver. + FU540/FU740 SoCs. If this kernel is meant to run on a SiFive FU540/ + FU740 SoCs, enable this driver.
drivers/clk/sifive/Makefile +3 -1
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ -obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI) += fu540-prci.o +obj-y += sifive-prci.o + +obj-$(CONFIG_CLK_SIFIVE_PRCI) += fu540-prci.o fu740-prci.o
drivers/clk/sifive/fu540-prci.c +21 -748
807 lines not on this page · raw message
drivers/clk/sifive/fu540-prci.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_FU540_PRCI_H +#define __SIFIVE_CLK_FU540_PRCI_H + +#include "sifive-prci.h" + +#define NUM_CLOCK_FU540 4 + +extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540 ]; + +static const struct prci_clk_desc prci_clk_fu540 = { + .clks = __prci_init_clocks_fu540, + .num_clks =ARRAY_SIZE (__prci_init_clocks_fu540), +}; + +#endif /* __SIFIVE_CLK_FU540_PRCI_H */
drivers/clk/sifive/fu740-prci.c new file +158 -0
158 lines not on this page · raw message
drivers/clk/sifive/fu740-prci.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_FU740_PRCI_H +#define __SIFIVE_CLK_FU740_PRCI_H + +#include "sifive-prci.h" + +#define NUM_CLOCK_FU740 9 + +extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740 ]; + +static const struct prci_clk_desc prci_clk_fu740 = { + .clks = __prci_init_clocks_fu740, + .num_clks =ARRAY_SIZE (__prci_init_clocks_fu740), +}; + +#endif /* __SIFIVE_CLK_FU740_PRCI_H */
drivers/clk/sifive/sifive-prci.c new file +733 -0
733 lines not on this page · raw message
drivers/clk/sifive/sifive-prci.h new file +323 -0
323 lines not on this page · raw message
Signature · 1 line
2.31.0
A message that is not in the archive (sent off-list or not yet received): CADWks+a=RMyzgSGp4JH-DjyKqgse0HUJgkaxwgcMh8kYD0BWWA@mail.gmail.com
PATCH v7 2/8 drivers: clk: add fu740 support
(resending to the list after subscribing)
Hi,
Quoted 26 lines · Green Wan
Add fu740 support. One abstract layer is added for supporting multiple chips such as fu540 and fu740.
Signed-off-by Green Wan <[email protected]>--- drivers/clk/sifive/Kconfig | 8 +- drivers/clk/sifive/Makefile | 4 +- drivers/clk/sifive/fu540-prci.c | 769 +------------------------------ drivers/clk/sifive/fu540-prci.h | 22 + drivers/clk/sifive/fu740-prci.c | 158 +++++++ drivers/clk/sifive/fu740-prci.h | 22 + drivers/clk/sifive/sifive-prci.c | 733 +++++++++++++++++++++++++++++ drivers/clk/sifive/sifive-prci.h | 323 +++++++++++++ 8 files changed, 1286 insertions(+), 753 deletions(-) create mode 100644 drivers/clk/sifive/fu540-prci.h create mode 100644 drivers/clk/sifive/fu740-prci.c create mode 100644 drivers/clk/sifive/fu740-prci.h create mode 100644 drivers/clk/sifive/sifive-prci.c create mode 100644 drivers/clk/sifive/sifive-prci.hdrivers/clk/sifive/Kconfig +0
-0
drivers/clk/sifive/Kconfig config CLK_SIFIVE · line 11
Quoted 8 lines
drivers/clk/sifive/Kconfig +2
-2@@ -6,11 +6,11 @@ config CLK_SIFIVE help SoC drivers for SiFive Linux-capable SoCs. -config CLK_SIFIVE_FU540_PRCI - bool "PRCI driver for SiFive FU540 SoCs" +config CLK_SIFIVE_PRCI + bool "PRCI driver for SiFive SoCs" depends on CLK_SIFIVE
Since the above is done in this patch, I would expect to remove all references to the CLK_SIFIVE_FU540_PRCI config option at the same time. Specifically:
$ git grep CLK_SIFIVE_FU540_PRCI arch/riscv/cpu/fu540/Kconfig: imply CLK_SIFIVE_FU540_PRCI drivers/reset/Kconfig: depends on DM_RESET && CLK_SIFIVE_FU540_PRCI && TARGET_SIFIVE_UNLEASHED
If above references were fixed, it remove the need to manually add "CONFIG_CLK_SIFIVE_PRCI=y" to unleashed config in the "board: sifive:
add HiFive Unmatched board support" patch.
Leaving left over references to the removed config options is confusing, and makes the patch not self contained.
Quoted 2,121 lines
drivers/clk/sifive/Kconfig +2
-2select CLK_ANALOGBITS_WRPLL_CLN28HPC help Supports the Power Reset Clock interface (PRCI) IP block found in - FU540 SoCs. If this kernel is meant to run on a SiFive FU540 SoC, - enable this driver. + FU540/FU740 SoCs. If this kernel is meant to run on a SiFive FU540/ + FU740 SoCs, enable this driver.drivers/clk/sifive/Makefile +3
-1@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ -obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI) += fu540-prci.o +obj-y += sifive-prci.o + +obj-$(CONFIG_CLK_SIFIVE_PRCI) += fu540-prci.o fu740-prci.odrivers/clk/sifive/fu540-prci.c +21
-748@@ -5,6 +5,8 @@* Copyright (C) 2018 SiFive, Inc. * Wesley Terpstra * Paul Walmsley +* Zong Li +* Pragnesh Patel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -15,632 +17,48 @@* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * -* The FU540 PRCI implements clock and reset control for the SiFive -* FU540-C000 chip. This driver assumes that it has sole control -* over all PRCI resources. -* -* This driver is based on the PRCI driver written by Wesley Terpstra. -* -* Refer, commit 999529edf517ed75b56659d456d221b2ee56bb60 of: -* https://github.com/riscv/riscv-linux -* * References: * - SiFive FU540-C000 manual v1p0, Chapter 7 "Clocking and Reset" */ -#include <common.h> -#include <clk-uclass.h> -#include <clk.h> -#include <div64.h> -#include <dm.h> -#include <dm/device.h> -#include <dm/device_compat.h> -#include <dm/uclass.h> #include <dt-bindings/clock/sifive-fu540-prci.h> -#include <dt-bindings/reset/sifive-fu540-prci.h> -#include <errno.h> -#include <reset-uclass.h> -#include <asm/io.h> -#include <asm/arch/reset.h> -#include <linux/delay.h> -#include <linux/err.h> -#include <linux/math64.h> -#include <linux/clk/analogbits-wrpll-cln28hpc.h> - -/* -* EXPECTED_CLK_PARENT_COUNT: how many parent clocks this driver expects: -* hfclk and rtcclk -*/ -#define EXPECTED_CLK_PARENT_COUNT 2 - -/* -* Register offsets and bitmasks -*/ - -/* COREPLLCFG0 */ -#define PRCI_COREPLLCFG0_OFFSET 0x4 -#define PRCI_COREPLLCFG0_DIVR_SHIFT 0 -#define PRCI_COREPLLCFG0_DIVR_MASK (0x3f << PRCI_COREPLLCFG0_DIVR_SHIFT) -#define PRCI_COREPLLCFG0_DIVF_SHIFT 6 -#define PRCI_COREPLLCFG0_DIVF_MASK (0x1ff << PRCI_COREPLLCFG0_DIVF_SHIFT) -#define PRCI_COREPLLCFG0_DIVQ_SHIFT 15 -#define PRCI_COREPLLCFG0_DIVQ_MASK (0x7 << PRCI_COREPLLCFG0_DIVQ_SHIFT) -#define PRCI_COREPLLCFG0_RANGE_SHIFT 18 -#define PRCI_COREPLLCFG0_RANGE_MASK (0x7 << PRCI_COREPLLCFG0_RANGE_SHIFT) -#define PRCI_COREPLLCFG0_BYPASS_SHIFT 24 -#define PRCI_COREPLLCFG0_BYPASS_MASK (0x1 << PRCI_COREPLLCFG0_BYPASS_SHIFT) -#define PRCI_COREPLLCFG0_FSE_SHIFT 25 -#define PRCI_COREPLLCFG0_FSE_MASK (0x1 << PRCI_COREPLLCFG0_FSE_SHIFT) -#define PRCI_COREPLLCFG0_LOCK_SHIFT 31 -#define PRCI_COREPLLCFG0_LOCK_MASK (0x1 << PRCI_COREPLLCFG0_LOCK_SHIFT) - -/* COREPLLCFG1 */ -#define PRCI_COREPLLCFG1_OFFSET 0x8 -#define PRCI_COREPLLCFG1_CKE_SHIFT 31 -#define PRCI_COREPLLCFG1_CKE_MASK (0x1 << PRCI_COREPLLCFG1_CKE_SHIFT) - -/* DDRPLLCFG0 */ -#define PRCI_DDRPLLCFG0_OFFSET 0xc -#define PRCI_DDRPLLCFG0_DIVR_SHIFT 0 -#define PRCI_DDRPLLCFG0_DIVR_MASK (0x3f << PRCI_DDRPLLCFG0_DIVR_SHIFT) -#define PRCI_DDRPLLCFG0_DIVF_SHIFT 6 -#define PRCI_DDRPLLCFG0_DIVF_MASK (0x1ff << PRCI_DDRPLLCFG0_DIVF_SHIFT) -#define PRCI_DDRPLLCFG0_DIVQ_SHIFT 15 -#define PRCI_DDRPLLCFG0_DIVQ_MASK (0x7 << PRCI_DDRPLLCFG0_DIVQ_SHIFT) -#define PRCI_DDRPLLCFG0_RANGE_SHIFT 18 -#define PRCI_DDRPLLCFG0_RANGE_MASK (0x7 << PRCI_DDRPLLCFG0_RANGE_SHIFT) -#define PRCI_DDRPLLCFG0_BYPASS_SHIFT 24 -#define PRCI_DDRPLLCFG0_BYPASS_MASK (0x1 << PRCI_DDRPLLCFG0_BYPASS_SHIFT) -#define PRCI_DDRPLLCFG0_FSE_SHIFT 25 -#define PRCI_DDRPLLCFG0_FSE_MASK (0x1 << PRCI_DDRPLLCFG0_FSE_SHIFT) -#define PRCI_DDRPLLCFG0_LOCK_SHIFT 31 -#define PRCI_DDRPLLCFG0_LOCK_MASK (0x1 << PRCI_DDRPLLCFG0_LOCK_SHIFT) - -/* DDRPLLCFG1 */ -#define PRCI_DDRPLLCFG1_OFFSET 0x10 -#define PRCI_DDRPLLCFG1_CKE_SHIFT 31 -#define PRCI_DDRPLLCFG1_CKE_MASK (0x1 << PRCI_DDRPLLCFG1_CKE_SHIFT) - -/* GEMGXLPLLCFG0 */ -#define PRCI_GEMGXLPLLCFG0_OFFSET 0x1c -#define PRCI_GEMGXLPLLCFG0_DIVR_SHIFT 0 -#define PRCI_GEMGXLPLLCFG0_DIVR_MASK \ - (0x3f << PRCI_GEMGXLPLLCFG0_DIVR_SHIFT) -#define PRCI_GEMGXLPLLCFG0_DIVF_SHIFT 6 -#define PRCI_GEMGXLPLLCFG0_DIVF_MASK \ - (0x1ff << PRCI_GEMGXLPLLCFG0_DIVF_SHIFT) -#define PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT 15 -#define PRCI_GEMGXLPLLCFG0_DIVQ_MASK (0x7 << PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT) -#define PRCI_GEMGXLPLLCFG0_RANGE_SHIFT 18 -#define PRCI_GEMGXLPLLCFG0_RANGE_MASK \ - (0x7 << PRCI_GEMGXLPLLCFG0_RANGE_SHIFT) -#define PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT 24 -#define PRCI_GEMGXLPLLCFG0_BYPASS_MASK \ - (0x1 << PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT) -#define PRCI_GEMGXLPLLCFG0_FSE_SHIFT 25 -#define PRCI_GEMGXLPLLCFG0_FSE_MASK \ - (0x1 << PRCI_GEMGXLPLLCFG0_FSE_SHIFT) -#define PRCI_GEMGXLPLLCFG0_LOCK_SHIFT 31 -#define PRCI_GEMGXLPLLCFG0_LOCK_MASK (0x1 << PRCI_GEMGXLPLLCFG0_LOCK_SHIFT) - -/* GEMGXLPLLCFG1 */ -#define PRCI_GEMGXLPLLCFG1_OFFSET 0x20 -#define PRCI_GEMGXLPLLCFG1_CKE_SHIFT 31 -#define PRCI_GEMGXLPLLCFG1_CKE_MASK (0x1 << PRCI_GEMGXLPLLCFG1_CKE_SHIFT) - -/* CORECLKSEL */ -#define PRCI_CORECLKSEL_OFFSET 0x24 -#define PRCI_CORECLKSEL_CORECLKSEL_SHIFT 0 -#define PRCI_CORECLKSEL_CORECLKSEL_MASK \ - (0x1 << PRCI_CORECLKSEL_CORECLKSEL_SHIFT) - -/* DEVICESRESETREG */ -#define PRCI_DEVICESRESETREG_OFFSET 0x28 -#define PRCI_DEVICERESETCNT 5 - -#define PRCI_DEVICESRESETREG_DDR_CTRL_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_CTRL_N) -#define PRCI_DEVICESRESETREG_DDR_AXI_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_AXI_N) -#define PRCI_DEVICESRESETREG_DDR_AHB_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_AHB_N) -#define PRCI_DEVICESRESETREG_DDR_PHY_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_PHY_N) -#define PRCI_DEVICESRESETREG_GEMGXL_RST_N_MASK \ - (0x1 << PRCI_RST_GEMGXL_N) - -/* CLKMUXSTATUSREG */ -#define PRCI_CLKMUXSTATUSREG_OFFSET 0x2c -#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT 1 -#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK \ - (0x1 << PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT) - -/* PROCMONCFG */ -#define PRCI_PROCMONCFG_OFFSET 0xF0 -#define PRCI_PROCMONCFG_CORE_CLOCK_SHIFT 24 -#define PRCI_PROCMONCFG_CORE_CLOCK_MASK \ - (0x1 << PRCI_PROCMONCFG_CORE_CLOCK_SHIFT) - -/* -* Private structures -*/ - -/** -* struct __prci_data - per-device-instance data -* @va: base virtual address of the PRCI IP block -* @parent: parent clk instance -* -* PRCI per-device instance data -*/ -struct __prci_data { -void *va; -struct clk parent_hfclk; -struct clk parent_rtcclk; -}; - -/** -* struct __prci_wrpll_data - WRPLL configuration and integration data -* @c: WRPLL current configuration record -* @enable_bypass: fn ptr to code to bypass the WRPLL (if applicable; else NULL) -* @disable_bypass: fn ptr to code to not bypass the WRPLL (or NULL) -* @cfg0_offs: WRPLL CFG0 register offset (in bytes) from the PRCI base address -* @cfg1_offs: WRPLL CFG1 register offset (in bytes) from the PRCI base address -* @release_reset: fn ptr to code to release clock reset -* -* @enable_bypass and @disable_bypass are used for WRPLL instances -* that contain a separate external glitchless clock mux downstream -* from the PLL. The WRPLL internal bypass mux is not glitchless. -*/ -struct __prci_wrpll_data { -struct wrpll_cfg c; -void (*enable_bypass)(struct __prci_data *pd); -void (*disable_bypass)(struct __prci_data *pd); -u8 cfg0_offs; -u8 cfg1_offs; -void (*release_reset)(struct __prci_data *pd); -}; - -struct __prci_clock ; - -/* struct __prci_clock_ops - clock operations */ -struct __prci_clock_ops { -int (*set_rate)(struct __prci_clock *pc, -unsigned long rate, -unsigned long parent_rate); -unsigned long (*round_rate)(struct __prci_clock *pc, -unsigned long rate, -unsigned long *parent_rate); -unsigned long (*recalc_rate)(struct __prci_clock *pc, -unsigned long parent_rate); -int (*enable_clk)(struct __prci_clock *pc,bool enable); -}; - -/** -* struct __prci_clock - describes a clock device managed by PRCI -* @name: user-readable clock name string - should match the manual -* @parent_name: parent name for this clock -* @ops: struct __prci_clock_ops for control -* @pwd: WRPLL-specific data, associated with this clock (if not NULL) -* @pd: PRCI-specific data associated with this clock (if not NULL) -* -* PRCI clock data. Used by the PRCI driver to register PRCI-provided -* clocks to the Linux clock infrastructure. -*/ -struct __prci_clock { -const char *name; -const char *parent_name; -const struct __prci_clock_ops *ops; -struct __prci_wrpll_data *pwd; -struct __prci_data *pd; -}; - -/* -* Private functions -*/ - -/** -* __prci_readl() - read from a PRCI register -* @pd: PRCI context -* @offs: register offset to read from (in bytes, from PRCI base address) -* -* Read the register located at offset @offs from the base virtual -* address of the PRCI register target described by @pd, and return -* the value to the caller. -* -* Context: Any context. -* -* Return: the contents of the register described by @pd and @offs. -*/ -static u32 __prci_readl (struct __prci_data *pd,u32 offs) -{ -return readl (pd->va + offs); -} - -static void __prci_writel (u32 v,u32 offs,struct __prci_data *pd) -{ -writel (v, pd->va + offs); -} - -/* WRPLL-related private functions */ - -/** -* __prci_wrpll_unpack() - unpack WRPLL configuration registers into parameters -* @c: ptr to a struct wrpll_cfg record to write config into -* @r: value read from the PRCI PLL configuration register -* -* Given a value @r read from an FU540 PRCI PLL configuration register, -* split it into fields and populate it into the WRPLL configuration record -* pointed to by @c. -* -* The COREPLLCFG0 macros are used below, but the other *PLLCFG0 macros -* have the same register layout. -* -* Context: Any context. -*/ -static void __prci_wrpll_unpack (struct wrpll_cfg *c,u32 r) -{ -u32 v; - - v = r &PRCI_COREPLLCFG0_DIVR_MASK ; - v >>=PRCI_COREPLLCFG0_DIVR_SHIFT ; - c->divr = v; - - v = r &PRCI_COREPLLCFG0_DIVF_MASK ; - v >>=PRCI_COREPLLCFG0_DIVF_SHIFT ; - c->divf = v; - - v = r &PRCI_COREPLLCFG0_DIVQ_MASK ; - v >>=PRCI_COREPLLCFG0_DIVQ_SHIFT ; - c->divq = v; - - v = r &PRCI_COREPLLCFG0_RANGE_MASK ; - v >>=PRCI_COREPLLCFG0_RANGE_SHIFT ; - c->range = v; - - c->flags &= (WRPLL_FLAGS_INT_FEEDBACK_MASK | -WRPLL_FLAGS_EXT_FEEDBACK_MASK ); - -/* external feedback mode not supported */ - c->flags |=WRPLL_FLAGS_INT_FEEDBACK_MASK ; -} - -/** -* __prci_wrpll_pack() - pack PLL configuration parameters into a register value -* @c: pointer to a struct wrpll_cfg record containing the PLL's cfg -* -* Using a set of WRPLL configuration values pointed to by @c, -* assemble a PRCI PLL configuration register value, and return it to -* the caller. -* -* Context: Any context. Caller must ensure that the contents of the -* record pointed to by @c do not change during the execution -* of this function. -* -* Returns: a value suitable for writing into a PRCI PLL configuration -* register -*/ -static u32 __prci_wrpll_pack (const struct wrpll_cfg *c) -{ -u32 r =0 ; - - r |= c->divr <<PRCI_COREPLLCFG0_DIVR_SHIFT ; - r |= c->divf <<PRCI_COREPLLCFG0_DIVF_SHIFT ; - r |= c->divq <<PRCI_COREPLLCFG0_DIVQ_SHIFT ; - r |= c->range <<PRCI_COREPLLCFG0_RANGE_SHIFT ; - -/* external feedback mode not supported */ - r |=PRCI_COREPLLCFG0_FSE_MASK ; - -return r; -} - -/** -* __prci_wrpll_read_cfg0() - read the WRPLL configuration from the PRCI -* @pd: PRCI context -* @pwd: PRCI WRPLL metadata -* -* Read the current configuration of the PLL identified by @pwd from -* the PRCI identified by @pd, and store it into the local configuration -* cache in @pwd. -* -* Context: Any context. Caller must prevent the records pointed to by -* @pd and @pwd from changing during execution. -*/ -static void __prci_wrpll_read_cfg0 (struct __prci_data *pd, -struct __prci_wrpll_data *pwd) -{ -__prci_wrpll_unpack (&pwd->c,__prci_readl (pd, pwd->cfg0_offs)); -} - -/** -* __prci_wrpll_write_cfg0() - write WRPLL configuration into the PRCI -* @pd: PRCI context -* @pwd: PRCI WRPLL metadata -* @c: WRPLL configuration record to write -* -* Write the WRPLL configuration described by @c into the WRPLL -* configuration register identified by @pwd in the PRCI instance -* described by @c. Make a cached copy of the WRPLL's current -* configuration so it can be used by other code. -* -* Context: Any context. Caller must prevent the records pointed to by -* @pd and @pwd from changing during execution. -*/ -static void __prci_wrpll_write_cfg0 (struct __prci_data *pd, -struct __prci_wrpll_data *pwd, -struct wrpll_cfg *c) -{ -__prci_writel (__prci_wrpll_pack (c), pwd->cfg0_offs, pd); - -memcpy (&pwd->c, c,sizeof (*c)); -} - -/** -* __prci_wrpll_write_cfg1() - write Clock enable/disable configuration -* into the PRCI -* @pd: PRCI context -* @pwd: PRCI WRPLL metadata -* @enable: Clock enable or disable value -*/ -static void __prci_wrpll_write_cfg1 (struct __prci_data *pd, -struct __prci_wrpll_data *pwd, -u32 enable) -{ -__prci_writel (enable, pwd->cfg1_offs, pd); -} - -/* Core clock mux control */ - -/** -* __prci_coreclksel_use_hfclk() - switch the CORECLK mux to output HFCLK -* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg -* -* Switch the CORECLK mux to the HFCLK input source; return once complete. -* -* Context: Any context. Caller must prevent concurrent changes to the -* PRCI_CORECLKSEL_OFFSET register. -*/ -static void __prci_coreclksel_use_hfclk (struct __prci_data *pd) -{ -u32 r; - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); - r |=PRCI_CORECLKSEL_CORECLKSEL_MASK ; -__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ -} - -/** -* __prci_coreclksel_use_corepll() - switch the CORECLK mux to output COREPLL -* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg -* -* Switch the CORECLK mux to the PLL output clock; return once complete. -* -* Context: Any context. Caller must prevent concurrent changes to the -* PRCI_CORECLKSEL_OFFSET register. -*/ -static void __prci_coreclksel_use_corepll (struct __prci_data *pd) -{ -u32 r; - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); - r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK ; -__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ -} - -static unsigned long sifive_fu540_prci_wrpll_recalc_rate ( -struct __prci_clock *pc, -unsigned long parent_rate) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -return wrpll_calc_output_rate (&pwd->c, parent_rate); -} - -static unsigned long sifive_fu540_prci_wrpll_round_rate ( -struct __prci_clock *pc, -unsigned long rate, -unsigned long *parent_rate) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -struct wrpll_cfg c; - -memcpy (&c, &pwd->c,sizeof (c)); - -wrpll_configure_for_rate (&c, rate, *parent_rate); - -return wrpll_calc_output_rate (&c, *parent_rate); -} - -static int sifive_fu540_prci_wrpll_set_rate (struct __prci_clock *pc, -unsigned long rate, -unsigned long parent_rate) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -struct __prci_data *pd = pc->pd; -int r; - - r =wrpll_configure_for_rate (&pwd->c, rate, parent_rate); -if (r) -return r; - -if (pwd->enable_bypass) - pwd->enable_bypass (pd); - -__prci_wrpll_write_cfg0 (pd, pwd, &pwd->c); - -udelay (wrpll_calc_max_lock_us (&pwd->c)); - -if (pwd->disable_bypass) - pwd->disable_bypass (pd); - -return 0 ; -} - -static int sifive_fu540_prci_clock_enable (struct __prci_clock *pc,bool enable) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -struct __prci_data *pd = pc->pd; - -if (enable) { -__prci_wrpll_write_cfg1 (pd, pwd,PRCI_COREPLLCFG1_CKE_MASK ); - -if (pwd->release_reset) - pwd->release_reset (pd); - }else { -u32 r; - - r =__prci_readl (pd, pwd->cfg1_offs); - r &= ~PRCI_COREPLLCFG1_CKE_MASK ; - -__prci_wrpll_write_cfg1 (pd, pwd, r); - } - -return 0 ; -} - -static const struct __prci_clock_ops sifive_fu540_prci_wrpll_clk_ops = { - .set_rate = sifive_fu540_prci_wrpll_set_rate, - .round_rate = sifive_fu540_prci_wrpll_round_rate, - .recalc_rate = sifive_fu540_prci_wrpll_recalc_rate, - .enable_clk = sifive_fu540_prci_clock_enable, -}; - -/* TLCLKSEL clock integration */ - -static unsigned long sifive_fu540_prci_tlclksel_recalc_rate ( -struct __prci_clock *pc, -unsigned long parent_rate) -{ -struct __prci_data *pd = pc->pd; -u32 v; -u8 div; - - v =__prci_readl (pd,PRCI_CLKMUXSTATUSREG_OFFSET ); - v &=PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK ; - div = v ?1 :2 ; - -return div_u64 (parent_rate, div); -} - -static const struct __prci_clock_ops sifive_fu540_prci_tlclksel_clk_ops = { - .recalc_rate = sifive_fu540_prci_tlclksel_recalc_rate, -}; - -static int __prci_consumer_reset (const char *rst_name,bool trigger) -{ -struct udevice *dev; -struct reset_ctl rst_sig; -int ret; - - ret =uclass_get_device_by_driver (UCLASS_RESET , -DM_DRIVER_GET (sifive_reset), - &dev); -if (ret) { -dev_err (dev,"Reset driver not found: %d\n" , ret); -return ret; - } - - ret =reset_get_by_name (dev, rst_name, &rst_sig); -if (ret) { -dev_err (dev,"failed to get %s reset\n" , rst_name); -return ret; - } - -if (reset_valid (&rst_sig)) { -if (trigger) - ret =reset_deassert (&rst_sig); -else - ret =reset_assert (&rst_sig); -if (ret) { -dev_err (dev,"failed to trigger reset id = %ld\n" , - rst_sig.id); -return ret; - } - } - -return ret; -} - -/** -* __prci_ddr_release_reset() - Release DDR reset -* @pd: struct __prci_data * for the PRCI containing the DDRCLK mux reg -* -*/ -static void __prci_ddr_release_reset (struct __prci_data *pd) -{ -/* Release DDR ctrl reset */ -__prci_consumer_reset ("ddr_ctrl" , true); - -/* HACK to get the '1 full controller clock cycle'. */ - asmvolatile ("fence" ); - -/* Release DDR AXI reset */ -__prci_consumer_reset ("ddr_axi" , true); - -/* Release DDR AHB reset */ -__prci_consumer_reset ("ddr_ahb" , true); - -/* Release DDR PHY reset */ -__prci_consumer_reset ("ddr_phy" , true); - -/* HACK to get the '1 full controller clock cycle'. */ - asmvolatile ("fence" ); - -/* -* These take like 16 cycles to actually propagate. We can't go sending -* stuff before they come out of reset. So wait. -*/ -for (int i =0 ; i <256 ; i++) - asmvolatile ("nop" ); -} - -/** -* __prci_ethernet_release_reset() - Release ethernet reset -* @pd: struct __prci_data * for the PRCI containing the Ethernet CLK mux reg -* -*/ -static void __prci_ethernet_release_reset (struct __prci_data *pd) -{ -/* Release GEMGXL reset */ -__prci_consumer_reset ("gemgxl_reset" , true); - -/* Procmon => core clock */ -__prci_writel (PRCI_PROCMONCFG_CORE_CLOCK_MASK ,PRCI_PROCMONCFG_OFFSET , - pd); -} - -/* -* PRCI integration data for each WRPLL instance -*/ +#include "sifive-prci.h" +/* PRCI integration data for each WRPLL instance */ static struct __prci_wrpll_data __prci_corepll_data = { .cfg0_offs =PRCI_COREPLLCFG0_OFFSET , .cfg1_offs =PRCI_COREPLLCFG1_OFFSET , - .enable_bypass = __prci_coreclksel_use_hfclk, - .disable_bypass = __prci_coreclksel_use_corepll, + .enable_bypass = sifive_prci_coreclksel_use_hfclk, + .disable_bypass = sifive_prci_coreclksel_use_corepll, };static struct __prci_wrpll_data __prci_ddrpll_data = { .cfg0_offs =PRCI_DDRPLLCFG0_OFFSET , .cfg1_offs =PRCI_DDRPLLCFG1_OFFSET , - .release_reset = __prci_ddr_release_reset, + .release_reset = sifive_prci_ddr_release_reset, };static struct __prci_wrpll_data __prci_gemgxlpll_data = { .cfg0_offs =PRCI_GEMGXLPLLCFG0_OFFSET , .cfg1_offs =PRCI_GEMGXLPLLCFG1_OFFSET , - .release_reset = __prci_ethernet_release_reset, + .release_reset = sifive_prci_ethernet_release_reset, }; -/* -* List of clock controls provided by the PRCI -*/ +/* Linux clock framework integration */ +static const struct __prci_clock_ops sifive_fu540_prci_wrpll_clk_ops = { + .set_rate = sifive_prci_wrpll_set_rate, + .round_rate = sifive_prci_wrpll_round_rate, + .recalc_rate = sifive_prci_wrpll_recalc_rate, + .enable_clk = sifive_prci_clock_enable, +}; -static struct __prci_clock __prci_init_clocks[] = { +static const struct __prci_clock_ops sifive_fu540_prci_tlclksel_clk_ops = { + .recalc_rate = sifive_prci_tlclksel_recalc_rate, +}; + +/* List of clock controls provided by the PRCI */ +struct __prci_clock __prci_init_clocks_fu540[] = { [PRCI_CLK_COREPLL ] = { .name ="corepll" , .parent_name ="hfclk" ,@@ -665,148 +83,3 @@ static struct __prci_clock __prci_init_clocks[] = { .ops = &sifive_fu540_prci_tlclksel_clk_ops, }, }; - -static ulong sifive_fu540_prci_parent_rate (struct __prci_clock *pc) -{ -ulong parent_rate; -struct __prci_clock *p; - -if (strcmp (pc->parent_name,"corepll" ) ==0 ) { - p = &__prci_init_clocks[PRCI_CLK_COREPLL ]; -if (!p->pd || !p->ops->recalc_rate) -return -ENXIO ; - -return p->ops->recalc_rate (p,sifive_fu540_prci_parent_rate (p)); - } - -if (strcmp (pc->parent_name,"rtcclk" ) ==0 ) - parent_rate =clk_get_rate (&pc->pd->parent_rtcclk); -else - parent_rate =clk_get_rate (&pc->pd->parent_hfclk); - -return parent_rate; -} - -static ulong sifive_fu540_prci_get_rate (struct clk *clk) -{ -struct __prci_clock *pc; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd || !pc->ops->recalc_rate) -return -ENXIO ; - -return pc->ops->recalc_rate (pc,sifive_fu540_prci_parent_rate (pc)); -} - -static ulong sifive_fu540_prci_set_rate (struct clk *clk,ulong rate) -{ -int err; -struct __prci_clock *pc; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd || !pc->ops->set_rate) -return -ENXIO ; - - err = pc->ops->set_rate (pc, rate,sifive_fu540_prci_parent_rate (pc)); -if (err) -return err; - -return rate; -} - -static int sifive_fu540_prci_enable (struct clk *clk) -{ -struct __prci_clock *pc; -int ret =0 ; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd) -return -ENXIO ; - -if (pc->ops->enable_clk) - ret = pc->ops->enable_clk (pc,1 ); - -return ret; -} - -static int sifive_fu540_prci_disable (struct clk *clk) -{ -struct __prci_clock *pc; -int ret =0 ; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd) -return -ENXIO ; - -if (pc->ops->enable_clk) - ret = pc->ops->enable_clk (pc,0 ); - -return ret; -} - -static int sifive_fu540_prci_probe (struct udevice *dev) -{ -int i, err; -struct __prci_clock *pc; -struct __prci_data *pd =dev_get_priv (dev); - - pd->va = (void *)dev_read_addr (dev); -if (IS_ERR (pd->va)) -return PTR_ERR (pd->va); - - err =clk_get_by_index (dev,0 , &pd->parent_hfclk); -if (err) -return err; - - err =clk_get_by_index (dev,1 , &pd->parent_rtcclk); -if (err) -return err; - -for (i =0 ; i <ARRAY_SIZE (__prci_init_clocks); ++i) { - pc = &__prci_init_clocks[i]; - pc->pd = pd; -if (pc->pwd) -__prci_wrpll_read_cfg0 (pd, pc->pwd); - } - -return 0 ; -} - -static struct clk_ops sifive_fu540_prci_ops = { - .set_rate = sifive_fu540_prci_set_rate, - .get_rate = sifive_fu540_prci_get_rate, - .enable = sifive_fu540_prci_enable, - .disable = sifive_fu540_prci_disable, -}; - -static int sifive_fu540_clk_bind (struct udevice *dev) -{ -return sifive_reset_bind (dev,PRCI_DEVICERESETCNT ); -} - -static const struct udevice_id sifive_fu540_prci_ids[] = { - { .compatible ="sifive,fu540-c000-prci" }, - { } -}; - -U_BOOT_DRIVER (sifive_fu540_prci) = { - .name ="sifive-fu540-prci" , - .id =UCLASS_CLK , - .of_match = sifive_fu540_prci_ids, - .probe = sifive_fu540_prci_probe, - .ops = &sifive_fu540_prci_ops, - .priv_auto =sizeof (struct __prci_data ), - .bind = sifive_fu540_clk_bind, -};drivers/clk/sifive/fu540-prci.h new file +22
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_FU540_PRCI_H +#define __SIFIVE_CLK_FU540_PRCI_H + +#include "sifive-prci.h" + +#define NUM_CLOCK_FU540 4 + +extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540 ]; + +static const struct prci_clk_desc prci_clk_fu540 = { + .clks = __prci_init_clocks_fu540, + .num_clks =ARRAY_SIZE (__prci_init_clocks_fu540), +}; + +#endif /* __SIFIVE_CLK_FU540_PRCI_H */ drivers/clk/sifive/fu740-prci.c new file +158
-0@@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2021 SiFive, Inc. +* Wesley Terpstra +* Paul Walmsley +* Zong Li +* Pragnesh Patel +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <dt-bindings/clock/sifive-fu740-prci.h> +#include "sifive-prci.h" +#include <asm/io.h> + +int sifive_prci_fu740_pciauxclk_enable (struct __prci_clock *pc,bool enable) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct __prci_data *pd = pc->pd; +u32 v; + +if (pwd->cfg1_offs !=PRCI_PCIEAUXCFG1_OFFSET ) +return -EINVAL ; + + v =readl (pd->va + pwd->cfg1_offs); + v = enable ? (v |PRCI_PCIEAUXCFG1_MASK ) : (v & ~PRCI_PCIEAUXCFG1_MASK ); +writel (v, pd->va + pwd->cfg1_offs); + +return 0 ; +} + +/* PRCI integration data for each WRPLL instance */ +static struct __prci_wrpll_data __prci_corepll_data = { + .cfg0_offs =PRCI_COREPLLCFG0_OFFSET , + .cfg1_offs =PRCI_COREPLLCFG1_OFFSET , + .enable_bypass = sifive_prci_coreclksel_use_hfclk, + .disable_bypass = sifive_prci_coreclksel_use_final_corepll, +}; + +static struct __prci_wrpll_data __prci_ddrpll_data = { + .cfg0_offs =PRCI_DDRPLLCFG0_OFFSET , + .cfg1_offs =PRCI_DDRPLLCFG1_OFFSET , + .release_reset = sifive_prci_ddr_release_reset, +}; + +static struct __prci_wrpll_data __prci_gemgxlpll_data = { + .cfg0_offs =PRCI_GEMGXLPLLCFG0_OFFSET , + .cfg1_offs =PRCI_GEMGXLPLLCFG1_OFFSET , + .release_reset = sifive_prci_ethernet_release_reset, +}; + +static struct __prci_wrpll_data __prci_dvfscorepll_data = { + .cfg0_offs =PRCI_DVFSCOREPLLCFG0_OFFSET , + .cfg1_offs =PRCI_DVFSCOREPLLCFG1_OFFSET , + .enable_bypass = sifive_prci_corepllsel_use_corepll, + .disable_bypass = sifive_prci_corepllsel_use_dvfscorepll, +}; + +static struct __prci_wrpll_data __prci_hfpclkpll_data = { + .cfg0_offs =PRCI_HFPCLKPLLCFG0_OFFSET , + .cfg1_offs =PRCI_HFPCLKPLLCFG1_OFFSET , + .enable_bypass = sifive_prci_hfpclkpllsel_use_hfclk, + .disable_bypass = sifive_prci_hfpclkpllsel_use_hfpclkpll, +}; + +static struct __prci_wrpll_data __prci_cltxpll_data = { + .cfg0_offs =PRCI_CLTXPLLCFG0_OFFSET , + .cfg1_offs =PRCI_CLTXPLLCFG1_OFFSET , + .release_reset = sifive_prci_cltx_release_reset, +}; + +static struct __prci_wrpll_data __prci_pcieaux_data = { + .cfg1_offs =PRCI_PCIEAUXCFG1_OFFSET , +}; + +/* Linux clock framework integration */ + +static const struct __prci_clock_ops sifive_fu740_prci_wrpll_clk_ops = { + .set_rate = sifive_prci_wrpll_set_rate, + .round_rate = sifive_prci_wrpll_round_rate, + .recalc_rate = sifive_prci_wrpll_recalc_rate, + .enable_clk = sifive_prci_clock_enable, +}; + +static const struct __prci_clock_ops sifive_fu740_prci_tlclksel_clk_ops = { + .recalc_rate = sifive_prci_tlclksel_recalc_rate, +}; + +static const struct __prci_clock_ops sifive_fu740_prci_hfpclkplldiv_clk_ops = { + .recalc_rate = sifive_prci_hfpclkplldiv_recalc_rate, +}; + +static const struct __prci_clock_ops sifive_fu740_prci_pcieaux_clk_ops = { + .enable_clk = sifive_prci_fu740_pciauxclk_enable, +}; + +/* List of clock controls provided by the PRCI */ +struct __prci_clock __prci_init_clocks_fu740[] = { + [PRCI_CLK_COREPLL ] = { + .name ="corepll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_corepll_data, + }, + [PRCI_CLK_DDRPLL ] = { + .name ="ddrpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_ddrpll_data, + }, + [PRCI_CLK_GEMGXLPLL ] = { + .name ="gemgxlpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_gemgxlpll_data, + }, + [PRCI_CLK_DVFSCOREPLL ] = { + .name ="dvfscorepll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_dvfscorepll_data, + }, + [PRCI_CLK_HFPCLKPLL ] = { + .name ="hfpclkpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_hfpclkpll_data, + }, + [PRCI_CLK_CLTXPLL ] = { + .name ="cltxpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_cltxpll_data, + }, + [PRCI_CLK_TLCLK ] = { + .name ="tlclk" , + .parent_name ="corepll" , + .ops = &sifive_fu740_prci_tlclksel_clk_ops, + }, + [PRCI_CLK_PCLK ] = { + .name ="pclk" , + .parent_name ="hfpclkpll" , + .ops = &sifive_fu740_prci_hfpclkplldiv_clk_ops, + }, + [PRCI_CLK_PCIEAUX] { + .name ="pciaux" , + .parent_name ="" , + .ops = &sifive_fu740_prci_pcieaux_clk_ops, + .pwd = &__prci_pcieaux_data, + } +};drivers/clk/sifive/fu740-prci.h new file +22
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_FU740_PRCI_H +#define __SIFIVE_CLK_FU740_PRCI_H + +#include "sifive-prci.h" + +#define NUM_CLOCK_FU740 9 + +extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740 ]; + +static const struct prci_clk_desc prci_clk_fu740 = { + .clks = __prci_init_clocks_fu740, + .num_clks =ARRAY_SIZE (__prci_init_clocks_fu740), +}; + +#endif /* __SIFIVE_CLK_FU740_PRCI_H */ drivers/clk/sifive/sifive-prci.c new file +733
-0@@ -0,0 +1,733 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2021 SiFive, Inc. +* Wesley Terpstra +* Paul Walmsley +* Zong Li +* Pragnesh Patel +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* The PRCI implements clock and reset control for the SiFive chip. +* This driver assumes that it has sole control over all PRCI resources. +* +* This driver is based on the PRCI driver written by Wesley Terpstra: +* https://github.com/riscv/riscv-linux/commit/999529edf517ed75b56659d456d221b2ee56bb60 +*/ + +#include <common.h> +#include <clk-uclass.h> +#include <clk.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <reset.h> +#include <asm/io.h> +#include <asm/arch/reset.h> +#include <linux/delay.h> +#include <linux/math64.h> +#include <dt-bindings/clock/sifive-fu740-prci.h> + +#include "fu540-prci.h" +#include "fu740-prci.h" + +/* +* Private functions +*/ + +/** +* __prci_readl() - read from a PRCI register +* @pd: PRCI context +* @offs: register offset to read from (in bytes, from PRCI base address) +* +* Read the register located at offset @offs from the base virtual +* address of the PRCI register target described by @pd, and return +* the value to the caller. +* +* Context: Any context. +* +* Return: the contents of the register described by @pd and @offs. +*/ +static u32 __prci_readl (struct __prci_data *pd,u32 offs) +{ +return readl (pd->va + offs); +} + +static void __prci_writel (u32 v,u32 offs,struct __prci_data *pd) +{ +writel (v, pd->va + offs); +} + +/* WRPLL-related private functions */ + +/** +* __prci_wrpll_unpack() - unpack WRPLL configuration registers into parameters +* @c: ptr to a struct wrpll_cfg record to write config into +* @r: value read from the PRCI PLL configuration register +* +* Given a value @r read from an FU540 PRCI PLL configuration register, +* split it into fields and populate it into the WRPLL configuration record +* pointed to by @c. +* +* The COREPLLCFG0 macros are used below, but the other *PLLCFG0 macros +* have the same register layout. +* +* Context: Any context. +*/ +static void __prci_wrpll_unpack (struct wrpll_cfg *c,u32 r) +{ +u32 v; + + v = r &PRCI_COREPLLCFG0_DIVR_MASK ; + v >>=PRCI_COREPLLCFG0_DIVR_SHIFT ; + c->divr = v; + + v = r &PRCI_COREPLLCFG0_DIVF_MASK ; + v >>=PRCI_COREPLLCFG0_DIVF_SHIFT ; + c->divf = v; + + v = r &PRCI_COREPLLCFG0_DIVQ_MASK ; + v >>=PRCI_COREPLLCFG0_DIVQ_SHIFT ; + c->divq = v; + + v = r &PRCI_COREPLLCFG0_RANGE_MASK ; + v >>=PRCI_COREPLLCFG0_RANGE_SHIFT ; + c->range = v; + + c->flags &= (WRPLL_FLAGS_INT_FEEDBACK_MASK | +WRPLL_FLAGS_EXT_FEEDBACK_MASK ); + +/* external feedback mode not supported */ + c->flags |=WRPLL_FLAGS_INT_FEEDBACK_MASK ; +} + +/** +* __prci_wrpll_pack() - pack PLL configuration parameters into a register value +* @c: pointer to a struct wrpll_cfg record containing the PLL's cfg +* +* Using a set of WRPLL configuration values pointed to by @c, +* assemble a PRCI PLL configuration register value, and return it to +* the caller. +* +* Context: Any context. Caller must ensure that the contents of the +* record pointed to by @c do not change during the execution +* of this function. +* +* Returns: a value suitable for writing into a PRCI PLL configuration +* register +*/ +static u32 __prci_wrpll_pack (const struct wrpll_cfg *c) +{ +u32 r =0 ; + + r |= c->divr <<PRCI_COREPLLCFG0_DIVR_SHIFT ; + r |= c->divf <<PRCI_COREPLLCFG0_DIVF_SHIFT ; + r |= c->divq <<PRCI_COREPLLCFG0_DIVQ_SHIFT ; + r |= c->range <<PRCI_COREPLLCFG0_RANGE_SHIFT ; + +/* external feedback mode not supported */ + r |=PRCI_COREPLLCFG0_FSE_MASK ; + +return r; +} + +/** +* __prci_wrpll_read_cfg0() - read the WRPLL configuration from the PRCI +* @pd: PRCI context +* @pwd: PRCI WRPLL metadata +* +* Read the current configuration of the PLL identified by @pwd from +* the PRCI identified by @pd, and store it into the local configuration +* cache in @pwd. +* +* Context: Any context. Caller must prevent the records pointed to by +* @pd and @pwd from changing during execution. +*/ +static void __prci_wrpll_read_cfg0 (struct __prci_data *pd, +struct __prci_wrpll_data *pwd) +{ +__prci_wrpll_unpack (&pwd->c,__prci_readl (pd, pwd->cfg0_offs)); +} + +/** +* __prci_wrpll_write_cfg0() - write WRPLL configuration into the PRCI +* @pd: PRCI context +* @pwd: PRCI WRPLL metadata +* @c: WRPLL configuration record to write +* +* Write the WRPLL configuration described by @c into the WRPLL +* configuration register identified by @pwd in the PRCI instance +* described by @c. Make a cached copy of the WRPLL's current +* configuration so it can be used by other code. +* +* Context: Any context. Caller must prevent the records pointed to by +* @pd and @pwd from changing during execution. +*/ +static void __prci_wrpll_write_cfg0 (struct __prci_data *pd, +struct __prci_wrpll_data *pwd, +struct wrpll_cfg *c) +{ +__prci_writel (__prci_wrpll_pack (c), pwd->cfg0_offs, pd); + +memcpy (&pwd->c, c,sizeof (*c)); +} + +/** +* __prci_wrpll_write_cfg1() - write Clock enable/disable configuration +* into the PRCI +* @pd: PRCI context +* @pwd: PRCI WRPLL metadata +* @enable: Clock enable or disable value +*/ +static void __prci_wrpll_write_cfg1 (struct __prci_data *pd, +struct __prci_wrpll_data *pwd, +u32 enable) +{ +__prci_writel (enable, pwd->cfg1_offs, pd); +} + +unsigned long sifive_prci_wrpll_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate) +{ +struct __prci_wrpll_data *pwd = pc->pwd; + +return wrpll_calc_output_rate (&pwd->c, parent_rate); +} + +unsigned long sifive_prci_wrpll_round_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long *parent_rate) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct wrpll_cfg c; + +memcpy (&c, &pwd->c,sizeof (c)); + +wrpll_configure_for_rate (&c, rate, *parent_rate); + +return wrpll_calc_output_rate (&c, *parent_rate); +} + +int sifive_prci_wrpll_set_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long parent_rate) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct __prci_data *pd = pc->pd; +int r; + + r =wrpll_configure_for_rate (&pwd->c, rate, parent_rate); +if (r) +return r; + +if (pwd->enable_bypass) + pwd->enable_bypass (pd); + +__prci_wrpll_write_cfg0 (pd, pwd, &pwd->c); + +udelay (wrpll_calc_max_lock_us (&pwd->c)); + +return 0 ; +} + +int sifive_prci_clock_enable (struct __prci_clock *pc,bool enable) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct __prci_data *pd = pc->pd; + +if (enable) { +__prci_wrpll_write_cfg1 (pd, pwd,PRCI_COREPLLCFG1_CKE_MASK ); + +if (pwd->disable_bypass) + pwd->disable_bypass (pd); + +if (pwd->release_reset) + pwd->release_reset (pd); + }else { +u32 r; + +if (pwd->enable_bypass) + pwd->enable_bypass (pd); + + r =__prci_readl (pd, pwd->cfg1_offs); + r &= ~PRCI_COREPLLCFG1_CKE_MASK ; + +__prci_wrpll_write_cfg1 (pd, pwd, r); + } + +return 0 ; +} + +/* TLCLKSEL clock integration */ + +unsigned long sifive_prci_tlclksel_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate) +{ +struct __prci_data *pd = pc->pd; +u32 v; +u8 div; + + v =__prci_readl (pd,PRCI_CLKMUXSTATUSREG_OFFSET ); + v &=PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK ; + div = v ?1 :2 ; + +return div_u64 (parent_rate, div); +} + +/* HFPCLK clock integration */ + +unsigned long sifive_prci_hfpclkplldiv_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate) +{ +struct __prci_data *pd = pc->pd; +u32 div =__prci_readl (pd,PRCI_HFPCLKPLLDIV_OFFSET ); + +return div_u64 (parent_rate, div +2 ); +} + +/** +* sifive_prci_coreclksel_use_final_corepll() - switch the CORECLK mux to output +* FINAL_COREPLL +* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg +* +* Switch the CORECLK mux to the final COREPLL output clock; return once +* complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_CORECLKSEL_OFFSET register. +*/ +void sifive_prci_coreclksel_use_final_corepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); + r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK ; +__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_corepllsel_use_dvfscorepll() - switch the COREPLL mux to +* output DVFS_COREPLL +* @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg +* +* Switch the COREPLL mux to the DVFSCOREPLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_COREPLLSEL_OFFSET register. +*/ +void sifive_prci_corepllsel_use_dvfscorepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET ); + r |=PRCI_COREPLLSEL_COREPLLSEL_MASK ; +__prci_writel (r,PRCI_COREPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_corepllsel_use_corepll() - switch the COREPLL mux to +* output COREPLL +* @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg +* +* Switch the COREPLL mux to the COREPLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_COREPLLSEL_OFFSET register. +*/ +void sifive_prci_corepllsel_use_corepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET ); + r &= ~PRCI_COREPLLSEL_COREPLLSEL_MASK ; +__prci_writel (r,PRCI_COREPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_hfpclkpllsel_use_hfclk() - switch the HFPCLKPLL mux to +* output HFCLK +* @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg +* +* Switch the HFPCLKPLL mux to the HFCLK input source; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_HFPCLKPLLSEL_OFFSET register. +*/ +void sifive_prci_hfpclkpllsel_use_hfclk (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET ); + r |=PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK ; +__prci_writel (r,PRCI_HFPCLKPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_hfpclkpllsel_use_hfpclkpll() - switch the HFPCLKPLL mux to +* output HFPCLKPLL +* @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg +* +* Switch the HFPCLKPLL mux to the HFPCLKPLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_HFPCLKPLLSEL_OFFSET register. +*/ +void sifive_prci_hfpclkpllsel_use_hfpclkpll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET ); + r &= ~PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK ; +__prci_writel (r,PRCI_HFPCLKPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET );/* barrier */ +} + +static int __prci_consumer_reset (const char *rst_name,bool trigger) +{ +struct udevice *dev; +struct reset_ctl rst_sig; +int ret; + + ret =uclass_get_device_by_driver (UCLASS_RESET , +DM_DRIVER_GET (sifive_reset), + &dev); +if (ret) { +dev_err (dev,"Reset driver not found: %d\n" , ret); +return ret; + } + + ret =reset_get_by_name (dev, rst_name, &rst_sig); +if (ret) { +dev_err (dev,"failed to get %s reset\n" , rst_name); +return ret; + } + +if (reset_valid (&rst_sig)) { +if (trigger) + ret =reset_deassert (&rst_sig); +else + ret =reset_assert (&rst_sig); +if (ret) { +dev_err (dev,"failed to trigger reset id = %ld\n" , + rst_sig.id); +return ret; + } + } + +return ret; +} + +/** +* sifive_prci_ddr_release_reset() - Release DDR reset +* @pd: struct __prci_data * for the PRCI containing the DDRCLK mux reg +* +*/ +void sifive_prci_ddr_release_reset (struct __prci_data *pd) +{ +/* Release DDR ctrl reset */ +__prci_consumer_reset ("ddr_ctrl" , true); + +/* HACK to get the '1 full controller clock cycle'. */ + asmvolatile ("fence" ); + +/* Release DDR AXI reset */ +__prci_consumer_reset ("ddr_axi" , true); + +/* Release DDR AHB reset */ +__prci_consumer_reset ("ddr_ahb" , true); + +/* Release DDR PHY reset */ +__prci_consumer_reset ("ddr_phy" , true); + +/* HACK to get the '1 full controller clock cycle'. */ + asmvolatile ("fence" ); + +/* +* These take like 16 cycles to actually propagate. We can't go sending +* stuff before they come out of reset. So wait. +*/ +for (int i =0 ; i <256 ; i++) + asmvolatile ("nop" ); +} + +/** +* sifive_prci_ethernet_release_reset() - Release ethernet reset +* @pd: struct __prci_data * for the PRCI containing the Ethernet CLK mux reg +* +*/ +void sifive_prci_ethernet_release_reset (struct __prci_data *pd) +{ +/* Release GEMGXL reset */ +__prci_consumer_reset ("gemgxl_reset" , true); + +/* Procmon => core clock */ +__prci_writel (PRCI_PROCMONCFG_CORE_CLOCK_MASK ,PRCI_PROCMONCFG_OFFSET , + pd); + +/* Release Chiplink reset */ +__prci_consumer_reset ("cltx_reset" , true); +} + +/** +* sifive_prci_cltx_release_reset() - Release cltx reset +* @pd: struct __prci_data * for the PRCI containing the Ethernet CLK mux reg +* +*/ +void sifive_prci_cltx_release_reset (struct __prci_data *pd) +{ +/* Release CLTX reset */ +__prci_consumer_reset ("cltx_reset" , true); +} + +/* Core clock mux control */ + +/** +* sifive_prci_coreclksel_use_hfclk() - switch the CORECLK mux to output HFCLK +* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg +* +* Switch the CORECLK mux to the HFCLK input source; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_CORECLKSEL_OFFSET register. +*/ +void sifive_prci_coreclksel_use_hfclk (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); + r |=PRCI_CORECLKSEL_CORECLKSEL_MASK ; +__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_coreclksel_use_corepll() - switch the CORECLK mux to output COREPLL +* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg +* +* Switch the CORECLK mux to the PLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_CORECLKSEL_OFFSET register. +*/ +void sifive_prci_coreclksel_use_corepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); + r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK ; +__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ +} + +static ulong sifive_prci_parent_rate (struct __prci_clock *pc,struct prci_clk_desc *data) +{ +ulong parent_rate; +ulong i; +struct __prci_clock *p; + +if (strcmp (pc->parent_name,"corepll" ) ==0 || +strcmp (pc->parent_name,"hfpclkpll" ) ==0 ) { +for (i =0 ; i < data->num_clks; i++) { +if (strcmp (pc->parent_name, data->clks[i].name) ==0 ) +break ; + } + +if (i >= data->num_clks) +return -ENXIO ; + + p = &data->clks[i]; +if (!p->pd || !p->ops->recalc_rate) +return -ENXIO ; + +return p->ops->recalc_rate (p,sifive_prci_parent_rate (p, data)); + } + +if (strcmp (pc->parent_name,"rtcclk" ) ==0 ) + parent_rate =clk_get_rate (&pc->pd->parent_rtcclk); +else + parent_rate =clk_get_rate (&pc->pd->parent_hfclk); + +return parent_rate; +} + +static ulong sifive_prci_get_rate (struct clk *clk) +{ +struct __prci_clock *pc; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd || !pc->ops->recalc_rate) +return -ENXIO ; + +return pc->ops->recalc_rate (pc,sifive_prci_parent_rate (pc, data)); +} + +static ulong sifive_prci_set_rate (struct clk *clk,ulong rate) +{ +int err; +struct __prci_clock *pc; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd || !pc->ops->set_rate) +return -ENXIO ; + + err = pc->ops->set_rate (pc, rate,sifive_prci_parent_rate (pc, data)); +if (err) +return err; + +return rate; +} + +static int sifive_prci_enable (struct clk *clk) +{ +struct __prci_clock *pc; +int ret =0 ; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd) +return -ENXIO ; + +if (pc->ops->enable_clk) + ret = pc->ops->enable_clk (pc,1 ); + +return ret; +} + +static int sifive_prci_disable (struct clk *clk) +{ +struct __prci_clock *pc; +int ret =0 ; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd) +return -ENXIO ; + +if (pc->ops->enable_clk) + ret = pc->ops->enable_clk (pc,0 ); + +return ret; +} + +static int sifive_prci_probe (struct udevice *dev) +{ +int i, err; +struct __prci_clock *pc; +struct __prci_data *pd =dev_get_priv (dev); + +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (dev); + + pd->va = (void *)dev_read_addr (dev); +if (IS_ERR (pd->va)) +return PTR_ERR (pd->va); + + err =clk_get_by_index (dev,0 , &pd->parent_hfclk); +if (err) +return err; + + err =clk_get_by_index (dev,1 , &pd->parent_rtcclk); +if (err) +return err; + +for (i =0 ; i < data->num_clks; ++i) { + pc = &data->clks[i]; + pc->pd = pd; +if (pc->pwd) +__prci_wrpll_read_cfg0 (pd, pc->pwd); + } + +if (IS_ENABLED (CONFIG_SPL_BUILD )) { +if (device_is_compatible (dev,"sifive,fu740-c000-prci" )) { +u32 prci_pll_reg; +unsigned long parent_rate; + + prci_pll_reg =readl (pd->va +PRCI_PRCIPLL_OFFSET ); + +if (prci_pll_reg &PRCI_PRCIPLL_HFPCLKPLL ) { +/* +* Only initialize the HFPCLK PLL. In this +* case the design uses hfpclk to drive +* Chiplink +*/ + pc = &data->clks[PRCI_CLK_HFPCLKPLL ]; + parent_rate =sifive_prci_parent_rate (pc, data); +sifive_prci_wrpll_set_rate (pc,260000000 , + parent_rate); + pc->ops->enable_clk (pc,1 ); + }else if (prci_pll_reg &PRCI_PRCIPLL_CLTXPLL ) { +/* CLTX pll init */ + pc = &data->clks[PRCI_CLK_CLTXPLL ]; + parent_rate =sifive_prci_parent_rate (pc, data); +sifive_prci_wrpll_set_rate (pc,260000000 , + parent_rate); + pc->ops->enable_clk (pc,1 ); + } + } + } + +return 0 ; +} + +static struct clk_ops sifive_prci_ops = { + .set_rate = sifive_prci_set_rate, + .get_rate = sifive_prci_get_rate, + .enable = sifive_prci_enable, + .disable = sifive_prci_disable, +}; + +static int sifive_clk_bind (struct udevice *dev) +{ +return sifive_reset_bind (dev,PRCI_DEVICERESETCNT ); +} + +static const struct udevice_id sifive_prci_ids[] = { + { .compatible ="sifive,fu540-c000-prci" , .data = (ulong)&prci_clk_fu540 }, + { .compatible ="sifive,fu740-c000-prci" , .data = (ulong)&prci_clk_fu740 }, + { } +}; + +U_BOOT_DRIVER (sifive_prci) = { + .name ="sifive-prci" , + .id =UCLASS_CLK , + .of_match = sifive_prci_ids, + .probe = sifive_prci_probe, + .ops = &sifive_prci_ops, + .priv_auto =sizeof (struct __prci_data ), + .bind = sifive_clk_bind, +};drivers/clk/sifive/sifive-prci.h new file +323
-1@@ -0,0 +1,323 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Wesley Terpstra +* Paul Walmsley +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_SIFIVE_PRCI_H +#define __SIFIVE_CLK_SIFIVE_PRCI_H + +#include <clk.h> +#include <linux/clk/analogbits-wrpll-cln28hpc.h> + +/* +* EXPECTED_CLK_PARENT_COUNT: how many parent clocks this driver expects: +* hfclk and rtcclk +*/ +#define EXPECTED_CLK_PARENT_COUNT 2 + +/* +* Register offsets and bitmasks +*/ + +/* COREPLLCFG0 */ +#define PRCI_COREPLLCFG0_OFFSET 0x4 +#define PRCI_COREPLLCFG0_DIVR_SHIFT 0 +#define PRCI_COREPLLCFG0_DIVR_MASK (0x3f << PRCI_COREPLLCFG0_DIVR_SHIFT) +#define PRCI_COREPLLCFG0_DIVF_SHIFT 6 +#define PRCI_COREPLLCFG0_DIVF_MASK (0x1ff << PRCI_COREPLLCFG0_DIVF_SHIFT) +#define PRCI_COREPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_COREPLLCFG0_DIVQ_MASK (0x7 << PRCI_COREPLLCFG0_DIVQ_SHIFT) +#define PRCI_COREPLLCFG0_RANGE_SHIFT 18 +#define PRCI_COREPLLCFG0_RANGE_MASK (0x7 << PRCI_COREPLLCFG0_RANGE_SHIFT) +#define PRCI_COREPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_COREPLLCFG0_BYPASS_MASK (0x1 << PRCI_COREPLLCFG0_BYPASS_SHIFT) +#define PRCI_COREPLLCFG0_FSE_SHIFT 25 +#define PRCI_COREPLLCFG0_FSE_MASK (0x1 << PRCI_COREPLLCFG0_FSE_SHIFT) +#define PRCI_COREPLLCFG0_LOCK_SHIFT 31 +#define PRCI_COREPLLCFG0_LOCK_MASK (0x1 << PRCI_COREPLLCFG0_LOCK_SHIFT) + +/* COREPLLCFG1 */ +#define PRCI_COREPLLCFG1_OFFSET 0x8 +#define PRCI_COREPLLCFG1_CKE_SHIFT 31 +#define PRCI_COREPLLCFG1_CKE_MASK (0x1 << PRCI_COREPLLCFG1_CKE_SHIFT) + +/* DDRPLLCFG0 */ +#define PRCI_DDRPLLCFG0_OFFSET 0xc +#define PRCI_DDRPLLCFG0_DIVR_SHIFT 0 +#define PRCI_DDRPLLCFG0_DIVR_MASK (0x3f << PRCI_DDRPLLCFG0_DIVR_SHIFT) +#define PRCI_DDRPLLCFG0_DIVF_SHIFT 6 +#define PRCI_DDRPLLCFG0_DIVF_MASK (0x1ff << PRCI_DDRPLLCFG0_DIVF_SHIFT) +#define PRCI_DDRPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_DDRPLLCFG0_DIVQ_MASK (0x7 << PRCI_DDRPLLCFG0_DIVQ_SHIFT) +#define PRCI_DDRPLLCFG0_RANGE_SHIFT 18 +#define PRCI_DDRPLLCFG0_RANGE_MASK (0x7 << PRCI_DDRPLLCFG0_RANGE_SHIFT) +#define PRCI_DDRPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_DDRPLLCFG0_BYPASS_MASK (0x1 << PRCI_DDRPLLCFG0_BYPASS_SHIFT) +#define PRCI_DDRPLLCFG0_FSE_SHIFT 25 +#define PRCI_DDRPLLCFG0_FSE_MASK (0x1 << PRCI_DDRPLLCFG0_FSE_SHIFT) +#define PRCI_DDRPLLCFG0_LOCK_SHIFT 31 +#define PRCI_DDRPLLCFG0_LOCK_MASK (0x1 << PRCI_DDRPLLCFG0_LOCK_SHIFT) + +/* DDRPLLCFG1 */ +#define PRCI_DDRPLLCFG1_OFFSET 0x10 +#define PRCI_DDRPLLCFG1_CKE_SHIFT 31 +#define PRCI_DDRPLLCFG1_CKE_MASK (0x1 << PRCI_DDRPLLCFG1_CKE_SHIFT) + +/* PCIEAUXCFG1 */ +#define PRCI_PCIEAUXCFG1_OFFSET 0x14 +#define PRCI_PCIEAUXCFG1_SHIFT 0 +#define PRCI_PCIEAUXCFG1_MASK (0x1 << PRCI_PCIEAUXCFG1_SHIFT) + +/* GEMGXLPLLCFG0 */ +#define PRCI_GEMGXLPLLCFG0_OFFSET 0x1c +#define PRCI_GEMGXLPLLCFG0_DIVR_SHIFT 0 +#define PRCI_GEMGXLPLLCFG0_DIVR_MASK \ + (0x3f << PRCI_GEMGXLPLLCFG0_DIVR_SHIFT) +#define PRCI_GEMGXLPLLCFG0_DIVF_SHIFT 6 +#define PRCI_GEMGXLPLLCFG0_DIVF_MASK \ + (0x1ff << PRCI_GEMGXLPLLCFG0_DIVF_SHIFT) +#define PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_GEMGXLPLLCFG0_DIVQ_MASK (0x7 << PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT) +#define PRCI_GEMGXLPLLCFG0_RANGE_SHIFT 18 +#define PRCI_GEMGXLPLLCFG0_RANGE_MASK \ + (0x7 << PRCI_GEMGXLPLLCFG0_RANGE_SHIFT) +#define PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_GEMGXLPLLCFG0_BYPASS_MASK \ + (0x1 << PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT) +#define PRCI_GEMGXLPLLCFG0_FSE_SHIFT 25 +#define PRCI_GEMGXLPLLCFG0_FSE_MASK \ + (0x1 << PRCI_GEMGXLPLLCFG0_FSE_SHIFT) +#define PRCI_GEMGXLPLLCFG0_LOCK_SHIFT 31 +#define PRCI_GEMGXLPLLCFG0_LOCK_MASK (0x1 << PRCI_GEMGXLPLLCFG0_LOCK_SHIFT) + +/* GEMGXLPLLCFG1 */ +#define PRCI_GEMGXLPLLCFG1_OFFSET 0x20 +#define PRCI_GEMGXLPLLCFG1_CKE_SHIFT 31 +#define PRCI_GEMGXLPLLCFG1_CKE_MASK (0x1 << PRCI_GEMGXLPLLCFG1_CKE_SHIFT) + +/* CORECLKSEL */ +#define PRCI_CORECLKSEL_OFFSET 0x24 +#define PRCI_CORECLKSEL_CORECLKSEL_SHIFT 0 +#define PRCI_CORECLKSEL_CORECLKSEL_MASK \ + (0x1 << PRCI_CORECLKSEL_CORECLKSEL_SHIFT) + +/* DEVICESRESETREG */ +#define PRCI_DEVICESRESETREG_OFFSET 0x28 +#define PRCI_DEVICERESETCNT 6 + +/* CLKMUXSTATUSREG */ +#define PRCI_CLKMUXSTATUSREG_OFFSET 0x2c +#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT 1 +#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK \ + (0x1 << PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT) + +/* CLTXPLLCFG0 */ +#define PRCI_CLTXPLLCFG0_OFFSET 0x30 +#define PRCI_CLTXPLLCFG0_DIVR_SHIFT 0 +#define PRCI_CLTXPLLCFG0_DIVR_MASK (0x3f << PRCI_CLTXPLLCFG0_DIVR_SHIFT) +#define PRCI_CLTXPLLCFG0_DIVF_SHIFT 6 +#define PRCI_CLTXPLLCFG0_DIVF_MASK (0x1ff << PRCI_CLTXPLLCFG0_DIVF_SHIFT) +#define PRCI_CLTXPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_CLTXPLLCFG0_DIVQ_MASK (0x7 << PRCI_CLTXPLLCFG0_DIVQ_SHIFT) +#define PRCI_CLTXPLLCFG0_RANGE_SHIFT 18 +#define PRCI_CLTXPLLCFG0_RANGE_MASK (0x7 << PRCI_CLTXPLLCFG0_RANGE_SHIFT) +#define PRCI_CLTXPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_CLTXPLLCFG0_BYPASS_MASK (0x1 << PRCI_CLTXPLLCFG0_BYPASS_SHIFT) +#define PRCI_CLTXPLLCFG0_FSE_SHIFT 25 +#define PRCI_CLTXPLLCFG0_FSE_MASK (0x1 << PRCI_CLTXPLLCFG0_FSE_SHIFT) +#define PRCI_CLTXPLLCFG0_LOCK_SHIFT 31 +#define PRCI_CLTXPLLCFG0_LOCK_MASK (0x1 << PRCI_CLTXPLLCFG0_LOCK_SHIFT) + +/* CLTXPLLCFG1 */ +#define PRCI_CLTXPLLCFG1_OFFSET 0x34 +#define PRCI_CLTXPLLCFG1_CKE_SHIFT 24 +#define PRCI_CLTXPLLCFG1_CKE_MASK (0x1 << PRCI_CLTXPLLCFG1_CKE_SHIFT) + +/* DVFSCOREPLLCFG0 */ +#define PRCI_DVFSCOREPLLCFG0_OFFSET 0x38 + +/* DVFSCOREPLLCFG1 */ +#define PRCI_DVFSCOREPLLCFG1_OFFSET 0x3c +#define PRCI_DVFSCOREPLLCFG1_CKE_SHIFT 24 +#define PRCI_DVFSCOREPLLCFG1_CKE_MASK (0x1 << PRCI_DVFSCOREPLLCFG1_CKE_SHIFT) + +/* COREPLLSEL */ +#define PRCI_COREPLLSEL_OFFSET 0x40 +#define PRCI_COREPLLSEL_COREPLLSEL_SHIFT 0 +#define PRCI_COREPLLSEL_COREPLLSEL_MASK \ + (0x1 << PRCI_COREPLLSEL_COREPLLSEL_SHIFT) + +/* HFPCLKPLLCFG0 */ +#define PRCI_HFPCLKPLLCFG0_OFFSET 0x50 +#define PRCI_HFPCLKPLL_CFG0_DIVR_SHIFT 0 +#define PRCI_HFPCLKPLL_CFG0_DIVR_MASK \ + (0x3f << PRCI_HFPCLKPLLCFG0_DIVR_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_DIVF_SHIFT 6 +#define PRCI_HFPCLKPLL_CFG0_DIVF_MASK \ + (0x1ff << PRCI_HFPCLKPLLCFG0_DIVF_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_DIVQ_SHIFT 15 +#define PRCI_HFPCLKPLL_CFG0_DIVQ_MASK \ + (0x7 << PRCI_HFPCLKPLLCFG0_DIVQ_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_RANGE_SHIFT 18 +#define PRCI_HFPCLKPLL_CFG0_RANGE_MASK \ + (0x7 << PRCI_HFPCLKPLLCFG0_RANGE_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_BYPASS_SHIFT 24 +#define PRCI_HFPCLKPLL_CFG0_BYPASS_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG0_BYPASS_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_FSE_SHIFT 25 +#define PRCI_HFPCLKPLL_CFG0_FSE_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG0_FSE_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_LOCK_SHIFT 31 +#define PRCI_HFPCLKPLL_CFG0_LOCK_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG0_LOCK_SHIFT) + +/* HFPCLKPLLCFG1 */ +#define PRCI_HFPCLKPLLCFG1_OFFSET 0x54 +#define PRCI_HFPCLKPLLCFG1_CKE_SHIFT 24 +#define PRCI_HFPCLKPLLCFG1_CKE_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG1_CKE_SHIFT) + +/* HFPCLKPLLSEL */ +#define PRCI_HFPCLKPLLSEL_OFFSET 0x58 +#define PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_SHIFT 0 +#define PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK \ + (0x1 << PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_SHIFT) + +/* HFPCLKPLLDIV */ +#define PRCI_HFPCLKPLLDIV_OFFSET 0x5c + +/* PRCIPLL */ +#define PRCI_PRCIPLL_OFFSET 0xe0 + +#define PRCI_PRCIPLL_CLTXPLL (0x1 << 0) +#define PRCI_PRCIPLL_GEMGXLPLL (0x1 << 1) +#define PRCI_PRCIPLL_DDRPLL (0x1 << 2) +#define PRCI_PRCIPLL_HFPCLKPLL (0x1 << 3) +#define PRCI_PRCIPLL_DVFSCOREPLL (0x1 << 4) +#define PRCI_PRCIPLL_COREPLL (0x1 << 5) + +/* PROCMONCFG */ +#define PRCI_PROCMONCFG_OFFSET 0xF0 +#define PRCI_PROCMONCFG_CORE_CLOCK_SHIFT 24 +#define PRCI_PROCMONCFG_CORE_CLOCK_MASK \ + (0x1 << PRCI_PROCMONCFG_CORE_CLOCK_SHIFT) + +/* +* Private structures +*/ + +/** +* struct __prci_data - per-device-instance data +* @va: base virtual address of the PRCI IP block +* @parent: parent clk instance +* +* PRCI per-device instance data +*/ +struct __prci_data { +void *va; +struct clk parent_hfclk; +struct clk parent_rtcclk; +}; + +/** +* struct __prci_wrpll_data - WRPLL configuration and integration data +* @c: WRPLL current configuration record +* @enable_bypass: fn ptr to code to bypass the WRPLL (if applicable; else NULL) +* @disable_bypass: fn ptr to code to not bypass the WRPLL (or NULL) +* @cfg0_offs: WRPLL CFG0 register offset (in bytes) from the PRCI base address +* @cfg1_offs: WRPLL CFG1 register offset (in bytes) from the PRCI base address +* @release_reset: fn ptr to code to release clock reset +* +* @enable_bypass and @disable_bypass are used for WRPLL instances +* that contain a separate external glitchless clock mux downstream +* from the PLL. The WRPLL internal bypass mux is not glitchless. +*/ +struct __prci_wrpll_data { +struct wrpll_cfg c; +void (*enable_bypass)(struct __prci_data *pd); +void (*disable_bypass)(struct __prci_data *pd); +u8 cfg0_offs; +u8 cfg1_offs; +void (*release_reset)(struct __prci_data *pd); +}; + +/** +* struct __prci_clock - describes a clock device managed by PRCI +* @name: user-readable clock name string - should match the manual +* @parent_name: parent name for this clock +* @ops: struct __prci_clock_ops for control +* @pwd: WRPLL-specific data, associated with this clock (if not NULL) +* @pd: PRCI-specific data associated with this clock (if not NULL) +* +* PRCI clock data. Used by the PRCI driver to register PRCI-provided +* clocks to the Linux clock infrastructure. +*/ +struct __prci_clock { +const char *name; +const char *parent_name; +const struct __prci_clock_ops *ops; +struct __prci_wrpll_data *pwd; +struct __prci_data *pd; +}; + +/* struct __prci_clock_ops - clock operations */ +struct __prci_clock_ops { +int (*set_rate)(struct __prci_clock *pc, +unsigned long rate, +unsigned long parent_rate); +unsigned long (*round_rate)(struct __prci_clock *pc, +unsigned long rate, +unsigned long *parent_rate); +unsigned long (*recalc_rate)(struct __prci_clock *pc, +unsigned long parent_rate); +int (*enable_clk)(struct __prci_clock *pc,bool enable); +}; + +/* +* struct prci_clk_desc - describes the information of clocks of each SoCs +* @clks: point to a array of __prci_clock +* @num_clks: the number of element of clks +*/ +struct prci_clk_desc { +struct __prci_clock *clks; +size_t num_clks; +}; + +void sifive_prci_ethernet_release_reset (struct __prci_data *pd); +void sifive_prci_ddr_release_reset (struct __prci_data *pd); +void sifive_prci_cltx_release_reset (struct __prci_data *pd); + +/* Core clock mux control */ +void sifive_prci_coreclksel_use_hfclk (struct __prci_data *pd); +void sifive_prci_coreclksel_use_corepll (struct __prci_data *pd); +void sifive_prci_coreclksel_use_final_corepll (struct __prci_data *pd); +void sifive_prci_corepllsel_use_dvfscorepll (struct __prci_data *pd); +void sifive_prci_corepllsel_use_corepll (struct __prci_data *pd); +void sifive_prci_hfpclkpllsel_use_hfclk (struct __prci_data *pd); +void sifive_prci_hfpclkpllsel_use_hfpclkpll (struct __prci_data *pd); + +unsigned long sifive_prci_wrpll_round_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long *parent_rate); + +/* Linux clock framework integration */ +int sifive_prci_wrpll_set_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long parent_rate); + +unsigned long sifive_prci_wrpll_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate); + +unsigned long sifive_prci_tlclksel_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate); + +unsigned long sifive_prci_hfpclkplldiv_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate); + +int sifive_prci_clock_enable (struct __prci_clock *pc,bool enable); + +#endif /* __SIFIVE_CLK_SIFIVE_PRCI_H */ --
Quoted 2 lines
2.31.0
--
Regards,
Dimitri.
Signature · 3 lines
Regards, Dimitri.
PATCH v7 2/8 drivers: clk: add fu740 support
In reply to a message not in the archiveThanks, I'll check the dependency.
Quoted 2,185 lines · Dimitri John Ledkov
"Hi,
Quoted 26 lines · Green Wan
Add fu740 support. One abstract layer is added for supporting multiple chips such as fu540 and fu740.
Signed-off-by Green Wan <[email protected]>--- drivers/clk/sifive/Kconfig | 8 +- drivers/clk/sifive/Makefile | 4 +- drivers/clk/sifive/fu540-prci.c | 769 +------------------------------ drivers/clk/sifive/fu540-prci.h | 22 + drivers/clk/sifive/fu740-prci.c | 158 +++++++ drivers/clk/sifive/fu740-prci.h | 22 + drivers/clk/sifive/sifive-prci.c | 733 +++++++++++++++++++++++++++++ drivers/clk/sifive/sifive-prci.h | 323 +++++++++++++ 8 files changed, 1286 insertions(+), 753 deletions(-) create mode 100644 drivers/clk/sifive/fu540-prci.h create mode 100644 drivers/clk/sifive/fu740-prci.c create mode 100644 drivers/clk/sifive/fu740-prci.h create mode 100644 drivers/clk/sifive/sifive-prci.c create mode 100644 drivers/clk/sifive/sifive-prci.hdrivers/clk/sifive/Kconfig +0
-0drivers/clk/sifive/Kconfig config CLK_SIFIVE · line 11
Quoted 8 lines
drivers/clk/sifive/Kconfig +2
-2@@ -6,11 +6,11 @@ config CLK_SIFIVE help SoC drivers for SiFive Linux-capable SoCs. -config CLK_SIFIVE_FU540_PRCI - bool "PRCI driver for SiFive FU540 SoCs" +config CLK_SIFIVE_PRCI + bool "PRCI driver for SiFive SoCs" depends on CLK_SIFIVESince the above is done in this patch, I would expect to remove all references to the
CLK_SIFIVE_FU540_PRCIconfig option at the same time. Specifically:$ git grep CLK_SIFIVE_FU540_PRCI arch/riscv/cpu/fu540/Kconfig: imply CLK_SIFIVE_FU540_PRCI drivers/reset/Kconfig: depends on DM_RESET && CLK_SIFIVE_FU540_PRCI && TARGET_SIFIVE_UNLEASHEDIf above references were fixed, it remove the need to manually add "
CONFIG_CLK_SIFIVE_PRCI=y" to unleashed config in the "board: sifive:
add HiFive Unmatched board support" patch.Leaving left over references to the removed config options is confusing, and makes the patch not self contained.
Quoted 2,121 lines
drivers/clk/sifive/Kconfig +2
-2select CLK_ANALOGBITS_WRPLL_CLN28HPC help Supports the Power Reset Clock interface (PRCI) IP block found in - FU540 SoCs. If this kernel is meant to run on a SiFive FU540 SoC, - enable this driver. + FU540/FU740 SoCs. If this kernel is meant to run on a SiFive FU540/ + FU740 SoCs, enable this driver.drivers/clk/sifive/Makefile +3
-1@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ -obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI) += fu540-prci.o +obj-y += sifive-prci.o + +obj-$(CONFIG_CLK_SIFIVE_PRCI) += fu540-prci.o fu740-prci.odrivers/clk/sifive/fu540-prci.c +21
-748@@ -5,6 +5,8 @@* Copyright (C) 2018 SiFive, Inc. * Wesley Terpstra * Paul Walmsley +* Zong Li +* Pragnesh Patel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -15,632 +17,48 @@* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * -* The FU540 PRCI implements clock and reset control for the SiFive -* FU540-C000 chip. This driver assumes that it has sole control -* over all PRCI resources. -* -* This driver is based on the PRCI driver written by Wesley Terpstra. -* -* Refer, commit 999529edf517ed75b56659d456d221b2ee56bb60 of: -* https://github.com/riscv/riscv-linux -* * References: * - SiFive FU540-C000 manual v1p0, Chapter 7 "Clocking and Reset" */ -#include <common.h> -#include <clk-uclass.h> -#include <clk.h> -#include <div64.h> -#include <dm.h> -#include <dm/device.h> -#include <dm/device_compat.h> -#include <dm/uclass.h> #include <dt-bindings/clock/sifive-fu540-prci.h> -#include <dt-bindings/reset/sifive-fu540-prci.h> -#include <errno.h> -#include <reset-uclass.h> -#include <asm/io.h> -#include <asm/arch/reset.h> -#include <linux/delay.h> -#include <linux/err.h> -#include <linux/math64.h> -#include <linux/clk/analogbits-wrpll-cln28hpc.h> - -/* -* EXPECTED_CLK_PARENT_COUNT: how many parent clocks this driver expects: -* hfclk and rtcclk -*/ -#define EXPECTED_CLK_PARENT_COUNT 2 - -/* -* Register offsets and bitmasks -*/ - -/* COREPLLCFG0 */ -#define PRCI_COREPLLCFG0_OFFSET 0x4 -#define PRCI_COREPLLCFG0_DIVR_SHIFT 0 -#define PRCI_COREPLLCFG0_DIVR_MASK (0x3f << PRCI_COREPLLCFG0_DIVR_SHIFT) -#define PRCI_COREPLLCFG0_DIVF_SHIFT 6 -#define PRCI_COREPLLCFG0_DIVF_MASK (0x1ff << PRCI_COREPLLCFG0_DIVF_SHIFT) -#define PRCI_COREPLLCFG0_DIVQ_SHIFT 15 -#define PRCI_COREPLLCFG0_DIVQ_MASK (0x7 << PRCI_COREPLLCFG0_DIVQ_SHIFT) -#define PRCI_COREPLLCFG0_RANGE_SHIFT 18 -#define PRCI_COREPLLCFG0_RANGE_MASK (0x7 << PRCI_COREPLLCFG0_RANGE_SHIFT) -#define PRCI_COREPLLCFG0_BYPASS_SHIFT 24 -#define PRCI_COREPLLCFG0_BYPASS_MASK (0x1 << PRCI_COREPLLCFG0_BYPASS_SHIFT) -#define PRCI_COREPLLCFG0_FSE_SHIFT 25 -#define PRCI_COREPLLCFG0_FSE_MASK (0x1 << PRCI_COREPLLCFG0_FSE_SHIFT) -#define PRCI_COREPLLCFG0_LOCK_SHIFT 31 -#define PRCI_COREPLLCFG0_LOCK_MASK (0x1 << PRCI_COREPLLCFG0_LOCK_SHIFT) - -/* COREPLLCFG1 */ -#define PRCI_COREPLLCFG1_OFFSET 0x8 -#define PRCI_COREPLLCFG1_CKE_SHIFT 31 -#define PRCI_COREPLLCFG1_CKE_MASK (0x1 << PRCI_COREPLLCFG1_CKE_SHIFT) - -/* DDRPLLCFG0 */ -#define PRCI_DDRPLLCFG0_OFFSET 0xc -#define PRCI_DDRPLLCFG0_DIVR_SHIFT 0 -#define PRCI_DDRPLLCFG0_DIVR_MASK (0x3f << PRCI_DDRPLLCFG0_DIVR_SHIFT) -#define PRCI_DDRPLLCFG0_DIVF_SHIFT 6 -#define PRCI_DDRPLLCFG0_DIVF_MASK (0x1ff << PRCI_DDRPLLCFG0_DIVF_SHIFT) -#define PRCI_DDRPLLCFG0_DIVQ_SHIFT 15 -#define PRCI_DDRPLLCFG0_DIVQ_MASK (0x7 << PRCI_DDRPLLCFG0_DIVQ_SHIFT) -#define PRCI_DDRPLLCFG0_RANGE_SHIFT 18 -#define PRCI_DDRPLLCFG0_RANGE_MASK (0x7 << PRCI_DDRPLLCFG0_RANGE_SHIFT) -#define PRCI_DDRPLLCFG0_BYPASS_SHIFT 24 -#define PRCI_DDRPLLCFG0_BYPASS_MASK (0x1 << PRCI_DDRPLLCFG0_BYPASS_SHIFT) -#define PRCI_DDRPLLCFG0_FSE_SHIFT 25 -#define PRCI_DDRPLLCFG0_FSE_MASK (0x1 << PRCI_DDRPLLCFG0_FSE_SHIFT) -#define PRCI_DDRPLLCFG0_LOCK_SHIFT 31 -#define PRCI_DDRPLLCFG0_LOCK_MASK (0x1 << PRCI_DDRPLLCFG0_LOCK_SHIFT) - -/* DDRPLLCFG1 */ -#define PRCI_DDRPLLCFG1_OFFSET 0x10 -#define PRCI_DDRPLLCFG1_CKE_SHIFT 31 -#define PRCI_DDRPLLCFG1_CKE_MASK (0x1 << PRCI_DDRPLLCFG1_CKE_SHIFT) - -/* GEMGXLPLLCFG0 */ -#define PRCI_GEMGXLPLLCFG0_OFFSET 0x1c -#define PRCI_GEMGXLPLLCFG0_DIVR_SHIFT 0 -#define PRCI_GEMGXLPLLCFG0_DIVR_MASK \ - (0x3f << PRCI_GEMGXLPLLCFG0_DIVR_SHIFT) -#define PRCI_GEMGXLPLLCFG0_DIVF_SHIFT 6 -#define PRCI_GEMGXLPLLCFG0_DIVF_MASK \ - (0x1ff << PRCI_GEMGXLPLLCFG0_DIVF_SHIFT) -#define PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT 15 -#define PRCI_GEMGXLPLLCFG0_DIVQ_MASK (0x7 << PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT) -#define PRCI_GEMGXLPLLCFG0_RANGE_SHIFT 18 -#define PRCI_GEMGXLPLLCFG0_RANGE_MASK \ - (0x7 << PRCI_GEMGXLPLLCFG0_RANGE_SHIFT) -#define PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT 24 -#define PRCI_GEMGXLPLLCFG0_BYPASS_MASK \ - (0x1 << PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT) -#define PRCI_GEMGXLPLLCFG0_FSE_SHIFT 25 -#define PRCI_GEMGXLPLLCFG0_FSE_MASK \ - (0x1 << PRCI_GEMGXLPLLCFG0_FSE_SHIFT) -#define PRCI_GEMGXLPLLCFG0_LOCK_SHIFT 31 -#define PRCI_GEMGXLPLLCFG0_LOCK_MASK (0x1 << PRCI_GEMGXLPLLCFG0_LOCK_SHIFT) - -/* GEMGXLPLLCFG1 */ -#define PRCI_GEMGXLPLLCFG1_OFFSET 0x20 -#define PRCI_GEMGXLPLLCFG1_CKE_SHIFT 31 -#define PRCI_GEMGXLPLLCFG1_CKE_MASK (0x1 << PRCI_GEMGXLPLLCFG1_CKE_SHIFT) - -/* CORECLKSEL */ -#define PRCI_CORECLKSEL_OFFSET 0x24 -#define PRCI_CORECLKSEL_CORECLKSEL_SHIFT 0 -#define PRCI_CORECLKSEL_CORECLKSEL_MASK \ - (0x1 << PRCI_CORECLKSEL_CORECLKSEL_SHIFT) - -/* DEVICESRESETREG */ -#define PRCI_DEVICESRESETREG_OFFSET 0x28 -#define PRCI_DEVICERESETCNT 5 - -#define PRCI_DEVICESRESETREG_DDR_CTRL_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_CTRL_N) -#define PRCI_DEVICESRESETREG_DDR_AXI_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_AXI_N) -#define PRCI_DEVICESRESETREG_DDR_AHB_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_AHB_N) -#define PRCI_DEVICESRESETREG_DDR_PHY_RST_N_MASK \ - (0x1 << PRCI_RST_DDR_PHY_N) -#define PRCI_DEVICESRESETREG_GEMGXL_RST_N_MASK \ - (0x1 << PRCI_RST_GEMGXL_N) - -/* CLKMUXSTATUSREG */ -#define PRCI_CLKMUXSTATUSREG_OFFSET 0x2c -#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT 1 -#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK \ - (0x1 << PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT) - -/* PROCMONCFG */ -#define PRCI_PROCMONCFG_OFFSET 0xF0 -#define PRCI_PROCMONCFG_CORE_CLOCK_SHIFT 24 -#define PRCI_PROCMONCFG_CORE_CLOCK_MASK \ - (0x1 << PRCI_PROCMONCFG_CORE_CLOCK_SHIFT) - -/* -* Private structures -*/ - -/** -* struct __prci_data - per-device-instance data -* @va: base virtual address of the PRCI IP block -* @parent: parent clk instance -* -* PRCI per-device instance data -*/ -struct __prci_data { -void *va; -struct clk parent_hfclk; -struct clk parent_rtcclk; -}; - -/** -* struct __prci_wrpll_data - WRPLL configuration and integration data -* @c: WRPLL current configuration record -* @enable_bypass: fn ptr to code to bypass the WRPLL (if applicable; else NULL) -* @disable_bypass: fn ptr to code to not bypass the WRPLL (or NULL) -* @cfg0_offs: WRPLL CFG0 register offset (in bytes) from the PRCI base address -* @cfg1_offs: WRPLL CFG1 register offset (in bytes) from the PRCI base address -* @release_reset: fn ptr to code to release clock reset -* -* @enable_bypass and @disable_bypass are used for WRPLL instances -* that contain a separate external glitchless clock mux downstream -* from the PLL. The WRPLL internal bypass mux is not glitchless. -*/ -struct __prci_wrpll_data { -struct wrpll_cfg c; -void (*enable_bypass)(struct __prci_data *pd); -void (*disable_bypass)(struct __prci_data *pd); -u8 cfg0_offs; -u8 cfg1_offs; -void (*release_reset)(struct __prci_data *pd); -}; - -struct __prci_clock ; - -/* struct __prci_clock_ops - clock operations */ -struct __prci_clock_ops { -int (*set_rate)(struct __prci_clock *pc, -unsigned long rate, -unsigned long parent_rate); -unsigned long (*round_rate)(struct __prci_clock *pc, -unsigned long rate, -unsigned long *parent_rate); -unsigned long (*recalc_rate)(struct __prci_clock *pc, -unsigned long parent_rate); -int (*enable_clk)(struct __prci_clock *pc,bool enable); -}; - -/** -* struct __prci_clock - describes a clock device managed by PRCI -* @name: user-readable clock name string - should match the manual -* @parent_name: parent name for this clock -* @ops: struct __prci_clock_ops for control -* @pwd: WRPLL-specific data, associated with this clock (if not NULL) -* @pd: PRCI-specific data associated with this clock (if not NULL) -* -* PRCI clock data. Used by the PRCI driver to register PRCI-provided -* clocks to the Linux clock infrastructure. -*/ -struct __prci_clock { -const char *name; -const char *parent_name; -const struct __prci_clock_ops *ops; -struct __prci_wrpll_data *pwd; -struct __prci_data *pd; -}; - -/* -* Private functions -*/ - -/** -* __prci_readl() - read from a PRCI register -* @pd: PRCI context -* @offs: register offset to read from (in bytes, from PRCI base address) -* -* Read the register located at offset @offs from the base virtual -* address of the PRCI register target described by @pd, and return -* the value to the caller. -* -* Context: Any context. -* -* Return: the contents of the register described by @pd and @offs. -*/ -static u32 __prci_readl (struct __prci_data *pd,u32 offs) -{ -return readl (pd->va + offs); -} - -static void __prci_writel (u32 v,u32 offs,struct __prci_data *pd) -{ -writel (v, pd->va + offs); -} - -/* WRPLL-related private functions */ - -/** -* __prci_wrpll_unpack() - unpack WRPLL configuration registers into parameters -* @c: ptr to a struct wrpll_cfg record to write config into -* @r: value read from the PRCI PLL configuration register -* -* Given a value @r read from an FU540 PRCI PLL configuration register, -* split it into fields and populate it into the WRPLL configuration record -* pointed to by @c. -* -* The COREPLLCFG0 macros are used below, but the other *PLLCFG0 macros -* have the same register layout. -* -* Context: Any context. -*/ -static void __prci_wrpll_unpack (struct wrpll_cfg *c,u32 r) -{ -u32 v; - - v = r &PRCI_COREPLLCFG0_DIVR_MASK ; - v >>=PRCI_COREPLLCFG0_DIVR_SHIFT ; - c->divr = v; - - v = r &PRCI_COREPLLCFG0_DIVF_MASK ; - v >>=PRCI_COREPLLCFG0_DIVF_SHIFT ; - c->divf = v; - - v = r &PRCI_COREPLLCFG0_DIVQ_MASK ; - v >>=PRCI_COREPLLCFG0_DIVQ_SHIFT ; - c->divq = v; - - v = r &PRCI_COREPLLCFG0_RANGE_MASK ; - v >>=PRCI_COREPLLCFG0_RANGE_SHIFT ; - c->range = v; - - c->flags &= (WRPLL_FLAGS_INT_FEEDBACK_MASK | -WRPLL_FLAGS_EXT_FEEDBACK_MASK ); - -/* external feedback mode not supported */ - c->flags |=WRPLL_FLAGS_INT_FEEDBACK_MASK ; -} - -/** -* __prci_wrpll_pack() - pack PLL configuration parameters into a register value -* @c: pointer to a struct wrpll_cfg record containing the PLL's cfg -* -* Using a set of WRPLL configuration values pointed to by @c, -* assemble a PRCI PLL configuration register value, and return it to -* the caller. -* -* Context: Any context. Caller must ensure that the contents of the -* record pointed to by @c do not change during the execution -* of this function. -* -* Returns: a value suitable for writing into a PRCI PLL configuration -* register -*/ -static u32 __prci_wrpll_pack (const struct wrpll_cfg *c) -{ -u32 r =0 ; - - r |= c->divr <<PRCI_COREPLLCFG0_DIVR_SHIFT ; - r |= c->divf <<PRCI_COREPLLCFG0_DIVF_SHIFT ; - r |= c->divq <<PRCI_COREPLLCFG0_DIVQ_SHIFT ; - r |= c->range <<PRCI_COREPLLCFG0_RANGE_SHIFT ; - -/* external feedback mode not supported */ - r |=PRCI_COREPLLCFG0_FSE_MASK ; - -return r; -} - -/** -* __prci_wrpll_read_cfg0() - read the WRPLL configuration from the PRCI -* @pd: PRCI context -* @pwd: PRCI WRPLL metadata -* -* Read the current configuration of the PLL identified by @pwd from -* the PRCI identified by @pd, and store it into the local configuration -* cache in @pwd. -* -* Context: Any context. Caller must prevent the records pointed to by -* @pd and @pwd from changing during execution. -*/ -static void __prci_wrpll_read_cfg0 (struct __prci_data *pd, -struct __prci_wrpll_data *pwd) -{ -__prci_wrpll_unpack (&pwd->c,__prci_readl (pd, pwd->cfg0_offs)); -} - -/** -* __prci_wrpll_write_cfg0() - write WRPLL configuration into the PRCI -* @pd: PRCI context -* @pwd: PRCI WRPLL metadata -* @c: WRPLL configuration record to write -* -* Write the WRPLL configuration described by @c into the WRPLL -* configuration register identified by @pwd in the PRCI instance -* described by @c. Make a cached copy of the WRPLL's current -* configuration so it can be used by other code. -* -* Context: Any context. Caller must prevent the records pointed to by -* @pd and @pwd from changing during execution. -*/ -static void __prci_wrpll_write_cfg0 (struct __prci_data *pd, -struct __prci_wrpll_data *pwd, -struct wrpll_cfg *c) -{ -__prci_writel (__prci_wrpll_pack (c), pwd->cfg0_offs, pd); - -memcpy (&pwd->c, c,sizeof (*c)); -} - -/** -* __prci_wrpll_write_cfg1() - write Clock enable/disable configuration -* into the PRCI -* @pd: PRCI context -* @pwd: PRCI WRPLL metadata -* @enable: Clock enable or disable value -*/ -static void __prci_wrpll_write_cfg1 (struct __prci_data *pd, -struct __prci_wrpll_data *pwd, -u32 enable) -{ -__prci_writel (enable, pwd->cfg1_offs, pd); -} - -/* Core clock mux control */ - -/** -* __prci_coreclksel_use_hfclk() - switch the CORECLK mux to output HFCLK -* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg -* -* Switch the CORECLK mux to the HFCLK input source; return once complete. -* -* Context: Any context. Caller must prevent concurrent changes to the -* PRCI_CORECLKSEL_OFFSET register. -*/ -static void __prci_coreclksel_use_hfclk (struct __prci_data *pd) -{ -u32 r; - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); - r |=PRCI_CORECLKSEL_CORECLKSEL_MASK ; -__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ -} - -/** -* __prci_coreclksel_use_corepll() - switch the CORECLK mux to output COREPLL -* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg -* -* Switch the CORECLK mux to the PLL output clock; return once complete. -* -* Context: Any context. Caller must prevent concurrent changes to the -* PRCI_CORECLKSEL_OFFSET register. -*/ -static void __prci_coreclksel_use_corepll (struct __prci_data *pd) -{ -u32 r; - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); - r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK ; -__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); - - r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ -} - -static unsigned long sifive_fu540_prci_wrpll_recalc_rate ( -struct __prci_clock *pc, -unsigned long parent_rate) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -return wrpll_calc_output_rate (&pwd->c, parent_rate); -} - -static unsigned long sifive_fu540_prci_wrpll_round_rate ( -struct __prci_clock *pc, -unsigned long rate, -unsigned long *parent_rate) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -struct wrpll_cfg c; - -memcpy (&c, &pwd->c,sizeof (c)); - -wrpll_configure_for_rate (&c, rate, *parent_rate); - -return wrpll_calc_output_rate (&c, *parent_rate); -} - -static int sifive_fu540_prci_wrpll_set_rate (struct __prci_clock *pc, -unsigned long rate, -unsigned long parent_rate) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -struct __prci_data *pd = pc->pd; -int r; - - r =wrpll_configure_for_rate (&pwd->c, rate, parent_rate); -if (r) -return r; - -if (pwd->enable_bypass) - pwd->enable_bypass (pd); - -__prci_wrpll_write_cfg0 (pd, pwd, &pwd->c); - -udelay (wrpll_calc_max_lock_us (&pwd->c)); - -if (pwd->disable_bypass) - pwd->disable_bypass (pd); - -return 0 ; -} - -static int sifive_fu540_prci_clock_enable (struct __prci_clock *pc,bool enable) -{ -struct __prci_wrpll_data *pwd = pc->pwd; -struct __prci_data *pd = pc->pd; - -if (enable) { -__prci_wrpll_write_cfg1 (pd, pwd,PRCI_COREPLLCFG1_CKE_MASK ); - -if (pwd->release_reset) - pwd->release_reset (pd); - }else { -u32 r; - - r =__prci_readl (pd, pwd->cfg1_offs); - r &= ~PRCI_COREPLLCFG1_CKE_MASK ; - -__prci_wrpll_write_cfg1 (pd, pwd, r); - } - -return 0 ; -} - -static const struct __prci_clock_ops sifive_fu540_prci_wrpll_clk_ops = { - .set_rate = sifive_fu540_prci_wrpll_set_rate, - .round_rate = sifive_fu540_prci_wrpll_round_rate, - .recalc_rate = sifive_fu540_prci_wrpll_recalc_rate, - .enable_clk = sifive_fu540_prci_clock_enable, -}; - -/* TLCLKSEL clock integration */ - -static unsigned long sifive_fu540_prci_tlclksel_recalc_rate ( -struct __prci_clock *pc, -unsigned long parent_rate) -{ -struct __prci_data *pd = pc->pd; -u32 v; -u8 div; - - v =__prci_readl (pd,PRCI_CLKMUXSTATUSREG_OFFSET ); - v &=PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK ; - div = v ?1 :2 ; - -return div_u64 (parent_rate, div); -} - -static const struct __prci_clock_ops sifive_fu540_prci_tlclksel_clk_ops = { - .recalc_rate = sifive_fu540_prci_tlclksel_recalc_rate, -}; - -static int __prci_consumer_reset (const char *rst_name,bool trigger) -{ -struct udevice *dev; -struct reset_ctl rst_sig; -int ret; - - ret =uclass_get_device_by_driver (UCLASS_RESET , -DM_DRIVER_GET (sifive_reset), - &dev); -if (ret) { -dev_err (dev,"Reset driver not found: %d\n" , ret); -return ret; - } - - ret =reset_get_by_name (dev, rst_name, &rst_sig); -if (ret) { -dev_err (dev,"failed to get %s reset\n" , rst_name); -return ret; - } - -if (reset_valid (&rst_sig)) { -if (trigger) - ret =reset_deassert (&rst_sig); -else - ret =reset_assert (&rst_sig); -if (ret) { -dev_err (dev,"failed to trigger reset id = %ld\n" , - rst_sig.id); -return ret; - } - } - -return ret; -} - -/** -* __prci_ddr_release_reset() - Release DDR reset -* @pd: struct __prci_data * for the PRCI containing the DDRCLK mux reg -* -*/ -static void __prci_ddr_release_reset (struct __prci_data *pd) -{ -/* Release DDR ctrl reset */ -__prci_consumer_reset ("ddr_ctrl" , true); - -/* HACK to get the '1 full controller clock cycle'. */ - asmvolatile ("fence" ); - -/* Release DDR AXI reset */ -__prci_consumer_reset ("ddr_axi" , true); - -/* Release DDR AHB reset */ -__prci_consumer_reset ("ddr_ahb" , true); - -/* Release DDR PHY reset */ -__prci_consumer_reset ("ddr_phy" , true); - -/* HACK to get the '1 full controller clock cycle'. */ - asmvolatile ("fence" ); - -/* -* These take like 16 cycles to actually propagate. We can't go sending -* stuff before they come out of reset. So wait. -*/ -for (int i =0 ; i <256 ; i++) - asmvolatile ("nop" ); -} - -/** -* __prci_ethernet_release_reset() - Release ethernet reset -* @pd: struct __prci_data * for the PRCI containing the Ethernet CLK mux reg -* -*/ -static void __prci_ethernet_release_reset (struct __prci_data *pd) -{ -/* Release GEMGXL reset */ -__prci_consumer_reset ("gemgxl_reset" , true); - -/* Procmon => core clock */ -__prci_writel (PRCI_PROCMONCFG_CORE_CLOCK_MASK ,PRCI_PROCMONCFG_OFFSET , - pd); -} - -/* -* PRCI integration data for each WRPLL instance -*/ +#include "sifive-prci.h" +/* PRCI integration data for each WRPLL instance */ static struct __prci_wrpll_data __prci_corepll_data = { .cfg0_offs =PRCI_COREPLLCFG0_OFFSET , .cfg1_offs =PRCI_COREPLLCFG1_OFFSET , - .enable_bypass = __prci_coreclksel_use_hfclk, - .disable_bypass = __prci_coreclksel_use_corepll, + .enable_bypass = sifive_prci_coreclksel_use_hfclk, + .disable_bypass = sifive_prci_coreclksel_use_corepll, };static struct __prci_wrpll_data __prci_ddrpll_data = { .cfg0_offs =PRCI_DDRPLLCFG0_OFFSET , .cfg1_offs =PRCI_DDRPLLCFG1_OFFSET , - .release_reset = __prci_ddr_release_reset, + .release_reset = sifive_prci_ddr_release_reset, };static struct __prci_wrpll_data __prci_gemgxlpll_data = { .cfg0_offs =PRCI_GEMGXLPLLCFG0_OFFSET , .cfg1_offs =PRCI_GEMGXLPLLCFG1_OFFSET , - .release_reset = __prci_ethernet_release_reset, + .release_reset = sifive_prci_ethernet_release_reset, }; -/* -* List of clock controls provided by the PRCI -*/ +/* Linux clock framework integration */ +static const struct __prci_clock_ops sifive_fu540_prci_wrpll_clk_ops = { + .set_rate = sifive_prci_wrpll_set_rate, + .round_rate = sifive_prci_wrpll_round_rate, + .recalc_rate = sifive_prci_wrpll_recalc_rate, + .enable_clk = sifive_prci_clock_enable, +}; -static struct __prci_clock __prci_init_clocks[] = { +static const struct __prci_clock_ops sifive_fu540_prci_tlclksel_clk_ops = { + .recalc_rate = sifive_prci_tlclksel_recalc_rate, +}; + +/* List of clock controls provided by the PRCI */ +struct __prci_clock __prci_init_clocks_fu540[] = { [PRCI_CLK_COREPLL ] = { .name ="corepll" , .parent_name ="hfclk" ,@@ -665,148 +83,3 @@ static struct __prci_clock __prci_init_clocks[] = { .ops = &sifive_fu540_prci_tlclksel_clk_ops, }, }; - -static ulong sifive_fu540_prci_parent_rate (struct __prci_clock *pc) -{ -ulong parent_rate; -struct __prci_clock *p; - -if (strcmp (pc->parent_name,"corepll" ) ==0 ) { - p = &__prci_init_clocks[PRCI_CLK_COREPLL ]; -if (!p->pd || !p->ops->recalc_rate) -return -ENXIO ; - -return p->ops->recalc_rate (p,sifive_fu540_prci_parent_rate (p)); - } - -if (strcmp (pc->parent_name,"rtcclk" ) ==0 ) - parent_rate =clk_get_rate (&pc->pd->parent_rtcclk); -else - parent_rate =clk_get_rate (&pc->pd->parent_hfclk); - -return parent_rate; -} - -static ulong sifive_fu540_prci_get_rate (struct clk *clk) -{ -struct __prci_clock *pc; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd || !pc->ops->recalc_rate) -return -ENXIO ; - -return pc->ops->recalc_rate (pc,sifive_fu540_prci_parent_rate (pc)); -} - -static ulong sifive_fu540_prci_set_rate (struct clk *clk,ulong rate) -{ -int err; -struct __prci_clock *pc; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd || !pc->ops->set_rate) -return -ENXIO ; - - err = pc->ops->set_rate (pc, rate,sifive_fu540_prci_parent_rate (pc)); -if (err) -return err; - -return rate; -} - -static int sifive_fu540_prci_enable (struct clk *clk) -{ -struct __prci_clock *pc; -int ret =0 ; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd) -return -ENXIO ; - -if (pc->ops->enable_clk) - ret = pc->ops->enable_clk (pc,1 ); - -return ret; -} - -static int sifive_fu540_prci_disable (struct clk *clk) -{ -struct __prci_clock *pc; -int ret =0 ; - -if (ARRAY_SIZE (__prci_init_clocks) <= clk->id) -return -ENXIO ; - - pc = &__prci_init_clocks[clk->id]; -if (!pc->pd) -return -ENXIO ; - -if (pc->ops->enable_clk) - ret = pc->ops->enable_clk (pc,0 ); - -return ret; -} - -static int sifive_fu540_prci_probe (struct udevice *dev) -{ -int i, err; -struct __prci_clock *pc; -struct __prci_data *pd =dev_get_priv (dev); - - pd->va = (void *)dev_read_addr (dev); -if (IS_ERR (pd->va)) -return PTR_ERR (pd->va); - - err =clk_get_by_index (dev,0 , &pd->parent_hfclk); -if (err) -return err; - - err =clk_get_by_index (dev,1 , &pd->parent_rtcclk); -if (err) -return err; - -for (i =0 ; i <ARRAY_SIZE (__prci_init_clocks); ++i) { - pc = &__prci_init_clocks[i]; - pc->pd = pd; -if (pc->pwd) -__prci_wrpll_read_cfg0 (pd, pc->pwd); - } - -return 0 ; -} - -static struct clk_ops sifive_fu540_prci_ops = { - .set_rate = sifive_fu540_prci_set_rate, - .get_rate = sifive_fu540_prci_get_rate, - .enable = sifive_fu540_prci_enable, - .disable = sifive_fu540_prci_disable, -}; - -static int sifive_fu540_clk_bind (struct udevice *dev) -{ -return sifive_reset_bind (dev,PRCI_DEVICERESETCNT ); -} - -static const struct udevice_id sifive_fu540_prci_ids[] = { - { .compatible ="sifive,fu540-c000-prci" }, - { } -}; - -U_BOOT_DRIVER (sifive_fu540_prci) = { - .name ="sifive-fu540-prci" , - .id =UCLASS_CLK , - .of_match = sifive_fu540_prci_ids, - .probe = sifive_fu540_prci_probe, - .ops = &sifive_fu540_prci_ops, - .priv_auto =sizeof (struct __prci_data ), - .bind = sifive_fu540_clk_bind, -};drivers/clk/sifive/fu540-prci.h new file +22
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_FU540_PRCI_H +#define __SIFIVE_CLK_FU540_PRCI_H + +#include "sifive-prci.h" + +#define NUM_CLOCK_FU540 4 + +extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540 ]; + +static const struct prci_clk_desc prci_clk_fu540 = { + .clks = __prci_init_clocks_fu540, + .num_clks =ARRAY_SIZE (__prci_init_clocks_fu540), +}; + +#endif /* __SIFIVE_CLK_FU540_PRCI_H */ drivers/clk/sifive/fu740-prci.c new file +158
-0@@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2021 SiFive, Inc. +* Wesley Terpstra +* Paul Walmsley +* Zong Li +* Pragnesh Patel +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <dt-bindings/clock/sifive-fu740-prci.h> +#include "sifive-prci.h" +#include <asm/io.h> + +int sifive_prci_fu740_pciauxclk_enable (struct __prci_clock *pc,bool enable) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct __prci_data *pd = pc->pd; +u32 v; + +if (pwd->cfg1_offs !=PRCI_PCIEAUXCFG1_OFFSET ) +return -EINVAL ; + + v =readl (pd->va + pwd->cfg1_offs); + v = enable ? (v |PRCI_PCIEAUXCFG1_MASK ) : (v & ~PRCI_PCIEAUXCFG1_MASK ); +writel (v, pd->va + pwd->cfg1_offs); + +return 0 ; +} + +/* PRCI integration data for each WRPLL instance */ +static struct __prci_wrpll_data __prci_corepll_data = { + .cfg0_offs =PRCI_COREPLLCFG0_OFFSET , + .cfg1_offs =PRCI_COREPLLCFG1_OFFSET , + .enable_bypass = sifive_prci_coreclksel_use_hfclk, + .disable_bypass = sifive_prci_coreclksel_use_final_corepll, +}; + +static struct __prci_wrpll_data __prci_ddrpll_data = { + .cfg0_offs =PRCI_DDRPLLCFG0_OFFSET , + .cfg1_offs =PRCI_DDRPLLCFG1_OFFSET , + .release_reset = sifive_prci_ddr_release_reset, +}; + +static struct __prci_wrpll_data __prci_gemgxlpll_data = { + .cfg0_offs =PRCI_GEMGXLPLLCFG0_OFFSET , + .cfg1_offs =PRCI_GEMGXLPLLCFG1_OFFSET , + .release_reset = sifive_prci_ethernet_release_reset, +}; + +static struct __prci_wrpll_data __prci_dvfscorepll_data = { + .cfg0_offs =PRCI_DVFSCOREPLLCFG0_OFFSET , + .cfg1_offs =PRCI_DVFSCOREPLLCFG1_OFFSET , + .enable_bypass = sifive_prci_corepllsel_use_corepll, + .disable_bypass = sifive_prci_corepllsel_use_dvfscorepll, +}; + +static struct __prci_wrpll_data __prci_hfpclkpll_data = { + .cfg0_offs =PRCI_HFPCLKPLLCFG0_OFFSET , + .cfg1_offs =PRCI_HFPCLKPLLCFG1_OFFSET , + .enable_bypass = sifive_prci_hfpclkpllsel_use_hfclk, + .disable_bypass = sifive_prci_hfpclkpllsel_use_hfpclkpll, +}; + +static struct __prci_wrpll_data __prci_cltxpll_data = { + .cfg0_offs =PRCI_CLTXPLLCFG0_OFFSET , + .cfg1_offs =PRCI_CLTXPLLCFG1_OFFSET , + .release_reset = sifive_prci_cltx_release_reset, +}; + +static struct __prci_wrpll_data __prci_pcieaux_data = { + .cfg1_offs =PRCI_PCIEAUXCFG1_OFFSET , +}; + +/* Linux clock framework integration */ + +static const struct __prci_clock_ops sifive_fu740_prci_wrpll_clk_ops = { + .set_rate = sifive_prci_wrpll_set_rate, + .round_rate = sifive_prci_wrpll_round_rate, + .recalc_rate = sifive_prci_wrpll_recalc_rate, + .enable_clk = sifive_prci_clock_enable, +}; + +static const struct __prci_clock_ops sifive_fu740_prci_tlclksel_clk_ops = { + .recalc_rate = sifive_prci_tlclksel_recalc_rate, +}; + +static const struct __prci_clock_ops sifive_fu740_prci_hfpclkplldiv_clk_ops = { + .recalc_rate = sifive_prci_hfpclkplldiv_recalc_rate, +}; + +static const struct __prci_clock_ops sifive_fu740_prci_pcieaux_clk_ops = { + .enable_clk = sifive_prci_fu740_pciauxclk_enable, +}; + +/* List of clock controls provided by the PRCI */ +struct __prci_clock __prci_init_clocks_fu740[] = { + [PRCI_CLK_COREPLL ] = { + .name ="corepll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_corepll_data, + }, + [PRCI_CLK_DDRPLL ] = { + .name ="ddrpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_ddrpll_data, + }, + [PRCI_CLK_GEMGXLPLL ] = { + .name ="gemgxlpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_gemgxlpll_data, + }, + [PRCI_CLK_DVFSCOREPLL ] = { + .name ="dvfscorepll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_dvfscorepll_data, + }, + [PRCI_CLK_HFPCLKPLL ] = { + .name ="hfpclkpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_hfpclkpll_data, + }, + [PRCI_CLK_CLTXPLL ] = { + .name ="cltxpll" , + .parent_name ="hfclk" , + .ops = &sifive_fu740_prci_wrpll_clk_ops, + .pwd = &__prci_cltxpll_data, + }, + [PRCI_CLK_TLCLK ] = { + .name ="tlclk" , + .parent_name ="corepll" , + .ops = &sifive_fu740_prci_tlclksel_clk_ops, + }, + [PRCI_CLK_PCLK ] = { + .name ="pclk" , + .parent_name ="hfpclkpll" , + .ops = &sifive_fu740_prci_hfpclkplldiv_clk_ops, + }, + [PRCI_CLK_PCIEAUX] { + .name ="pciaux" , + .parent_name ="" , + .ops = &sifive_fu740_prci_pcieaux_clk_ops, + .pwd = &__prci_pcieaux_data, + } +};drivers/clk/sifive/fu740-prci.h new file +22
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_FU740_PRCI_H +#define __SIFIVE_CLK_FU740_PRCI_H + +#include "sifive-prci.h" + +#define NUM_CLOCK_FU740 9 + +extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740 ]; + +static const struct prci_clk_desc prci_clk_fu740 = { + .clks = __prci_init_clocks_fu740, + .num_clks =ARRAY_SIZE (__prci_init_clocks_fu740), +}; + +#endif /* __SIFIVE_CLK_FU740_PRCI_H */ drivers/clk/sifive/sifive-prci.c new file +733
-0@@ -0,0 +1,733 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2021 SiFive, Inc. +* Wesley Terpstra +* Paul Walmsley +* Zong Li +* Pragnesh Patel +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* The PRCI implements clock and reset control for the SiFive chip. +* This driver assumes that it has sole control over all PRCI resources. +* +* This driver is based on the PRCI driver written by Wesley Terpstra: +* https://github.com/riscv/riscv-linux/commit/999529edf517ed75b56659d456d221b2ee56bb60 +*/ + +#include <common.h> +#include <clk-uclass.h> +#include <clk.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <reset.h> +#include <asm/io.h> +#include <asm/arch/reset.h> +#include <linux/delay.h> +#include <linux/math64.h> +#include <dt-bindings/clock/sifive-fu740-prci.h> + +#include "fu540-prci.h" +#include "fu740-prci.h" + +/* +* Private functions +*/ + +/** +* __prci_readl() - read from a PRCI register +* @pd: PRCI context +* @offs: register offset to read from (in bytes, from PRCI base address) +* +* Read the register located at offset @offs from the base virtual +* address of the PRCI register target described by @pd, and return +* the value to the caller. +* +* Context: Any context. +* +* Return: the contents of the register described by @pd and @offs. +*/ +static u32 __prci_readl (struct __prci_data *pd,u32 offs) +{ +return readl (pd->va + offs); +} + +static void __prci_writel (u32 v,u32 offs,struct __prci_data *pd) +{ +writel (v, pd->va + offs); +} + +/* WRPLL-related private functions */ + +/** +* __prci_wrpll_unpack() - unpack WRPLL configuration registers into parameters +* @c: ptr to a struct wrpll_cfg record to write config into +* @r: value read from the PRCI PLL configuration register +* +* Given a value @r read from an FU540 PRCI PLL configuration register, +* split it into fields and populate it into the WRPLL configuration record +* pointed to by @c. +* +* The COREPLLCFG0 macros are used below, but the other *PLLCFG0 macros +* have the same register layout. +* +* Context: Any context. +*/ +static void __prci_wrpll_unpack (struct wrpll_cfg *c,u32 r) +{ +u32 v; + + v = r &PRCI_COREPLLCFG0_DIVR_MASK ; + v >>=PRCI_COREPLLCFG0_DIVR_SHIFT ; + c->divr = v; + + v = r &PRCI_COREPLLCFG0_DIVF_MASK ; + v >>=PRCI_COREPLLCFG0_DIVF_SHIFT ; + c->divf = v; + + v = r &PRCI_COREPLLCFG0_DIVQ_MASK ; + v >>=PRCI_COREPLLCFG0_DIVQ_SHIFT ; + c->divq = v; + + v = r &PRCI_COREPLLCFG0_RANGE_MASK ; + v >>=PRCI_COREPLLCFG0_RANGE_SHIFT ; + c->range = v; + + c->flags &= (WRPLL_FLAGS_INT_FEEDBACK_MASK | +WRPLL_FLAGS_EXT_FEEDBACK_MASK ); + +/* external feedback mode not supported */ + c->flags |=WRPLL_FLAGS_INT_FEEDBACK_MASK ; +} + +/** +* __prci_wrpll_pack() - pack PLL configuration parameters into a register value +* @c: pointer to a struct wrpll_cfg record containing the PLL's cfg +* +* Using a set of WRPLL configuration values pointed to by @c, +* assemble a PRCI PLL configuration register value, and return it to +* the caller. +* +* Context: Any context. Caller must ensure that the contents of the +* record pointed to by @c do not change during the execution +* of this function. +* +* Returns: a value suitable for writing into a PRCI PLL configuration +* register +*/ +static u32 __prci_wrpll_pack (const struct wrpll_cfg *c) +{ +u32 r =0 ; + + r |= c->divr <<PRCI_COREPLLCFG0_DIVR_SHIFT ; + r |= c->divf <<PRCI_COREPLLCFG0_DIVF_SHIFT ; + r |= c->divq <<PRCI_COREPLLCFG0_DIVQ_SHIFT ; + r |= c->range <<PRCI_COREPLLCFG0_RANGE_SHIFT ; + +/* external feedback mode not supported */ + r |=PRCI_COREPLLCFG0_FSE_MASK ; + +return r; +} + +/** +* __prci_wrpll_read_cfg0() - read the WRPLL configuration from the PRCI +* @pd: PRCI context +* @pwd: PRCI WRPLL metadata +* +* Read the current configuration of the PLL identified by @pwd from +* the PRCI identified by @pd, and store it into the local configuration +* cache in @pwd. +* +* Context: Any context. Caller must prevent the records pointed to by +* @pd and @pwd from changing during execution. +*/ +static void __prci_wrpll_read_cfg0 (struct __prci_data *pd, +struct __prci_wrpll_data *pwd) +{ +__prci_wrpll_unpack (&pwd->c,__prci_readl (pd, pwd->cfg0_offs)); +} + +/** +* __prci_wrpll_write_cfg0() - write WRPLL configuration into the PRCI +* @pd: PRCI context +* @pwd: PRCI WRPLL metadata +* @c: WRPLL configuration record to write +* +* Write the WRPLL configuration described by @c into the WRPLL +* configuration register identified by @pwd in the PRCI instance +* described by @c. Make a cached copy of the WRPLL's current +* configuration so it can be used by other code. +* +* Context: Any context. Caller must prevent the records pointed to by +* @pd and @pwd from changing during execution. +*/ +static void __prci_wrpll_write_cfg0 (struct __prci_data *pd, +struct __prci_wrpll_data *pwd, +struct wrpll_cfg *c) +{ +__prci_writel (__prci_wrpll_pack (c), pwd->cfg0_offs, pd); + +memcpy (&pwd->c, c,sizeof (*c)); +} + +/** +* __prci_wrpll_write_cfg1() - write Clock enable/disable configuration +* into the PRCI +* @pd: PRCI context +* @pwd: PRCI WRPLL metadata +* @enable: Clock enable or disable value +*/ +static void __prci_wrpll_write_cfg1 (struct __prci_data *pd, +struct __prci_wrpll_data *pwd, +u32 enable) +{ +__prci_writel (enable, pwd->cfg1_offs, pd); +} + +unsigned long sifive_prci_wrpll_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate) +{ +struct __prci_wrpll_data *pwd = pc->pwd; + +return wrpll_calc_output_rate (&pwd->c, parent_rate); +} + +unsigned long sifive_prci_wrpll_round_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long *parent_rate) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct wrpll_cfg c; + +memcpy (&c, &pwd->c,sizeof (c)); + +wrpll_configure_for_rate (&c, rate, *parent_rate); + +return wrpll_calc_output_rate (&c, *parent_rate); +} + +int sifive_prci_wrpll_set_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long parent_rate) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct __prci_data *pd = pc->pd; +int r; + + r =wrpll_configure_for_rate (&pwd->c, rate, parent_rate); +if (r) +return r; + +if (pwd->enable_bypass) + pwd->enable_bypass (pd); + +__prci_wrpll_write_cfg0 (pd, pwd, &pwd->c); + +udelay (wrpll_calc_max_lock_us (&pwd->c)); + +return 0 ; +} + +int sifive_prci_clock_enable (struct __prci_clock *pc,bool enable) +{ +struct __prci_wrpll_data *pwd = pc->pwd; +struct __prci_data *pd = pc->pd; + +if (enable) { +__prci_wrpll_write_cfg1 (pd, pwd,PRCI_COREPLLCFG1_CKE_MASK ); + +if (pwd->disable_bypass) + pwd->disable_bypass (pd); + +if (pwd->release_reset) + pwd->release_reset (pd); + }else { +u32 r; + +if (pwd->enable_bypass) + pwd->enable_bypass (pd); + + r =__prci_readl (pd, pwd->cfg1_offs); + r &= ~PRCI_COREPLLCFG1_CKE_MASK ; + +__prci_wrpll_write_cfg1 (pd, pwd, r); + } + +return 0 ; +} + +/* TLCLKSEL clock integration */ + +unsigned long sifive_prci_tlclksel_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate) +{ +struct __prci_data *pd = pc->pd; +u32 v; +u8 div; + + v =__prci_readl (pd,PRCI_CLKMUXSTATUSREG_OFFSET ); + v &=PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK ; + div = v ?1 :2 ; + +return div_u64 (parent_rate, div); +} + +/* HFPCLK clock integration */ + +unsigned long sifive_prci_hfpclkplldiv_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate) +{ +struct __prci_data *pd = pc->pd; +u32 div =__prci_readl (pd,PRCI_HFPCLKPLLDIV_OFFSET ); + +return div_u64 (parent_rate, div +2 ); +} + +/** +* sifive_prci_coreclksel_use_final_corepll() - switch the CORECLK mux to output +* FINAL_COREPLL +* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg +* +* Switch the CORECLK mux to the final COREPLL output clock; return once +* complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_CORECLKSEL_OFFSET register. +*/ +void sifive_prci_coreclksel_use_final_corepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); + r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK ; +__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_corepllsel_use_dvfscorepll() - switch the COREPLL mux to +* output DVFS_COREPLL +* @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg +* +* Switch the COREPLL mux to the DVFSCOREPLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_COREPLLSEL_OFFSET register. +*/ +void sifive_prci_corepllsel_use_dvfscorepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET ); + r |=PRCI_COREPLLSEL_COREPLLSEL_MASK ; +__prci_writel (r,PRCI_COREPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_corepllsel_use_corepll() - switch the COREPLL mux to +* output COREPLL +* @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg +* +* Switch the COREPLL mux to the COREPLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_COREPLLSEL_OFFSET register. +*/ +void sifive_prci_corepllsel_use_corepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET ); + r &= ~PRCI_COREPLLSEL_COREPLLSEL_MASK ; +__prci_writel (r,PRCI_COREPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_COREPLLSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_hfpclkpllsel_use_hfclk() - switch the HFPCLKPLL mux to +* output HFCLK +* @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg +* +* Switch the HFPCLKPLL mux to the HFCLK input source; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_HFPCLKPLLSEL_OFFSET register. +*/ +void sifive_prci_hfpclkpllsel_use_hfclk (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET ); + r |=PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK ; +__prci_writel (r,PRCI_HFPCLKPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_hfpclkpllsel_use_hfpclkpll() - switch the HFPCLKPLL mux to +* output HFPCLKPLL +* @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg +* +* Switch the HFPCLKPLL mux to the HFPCLKPLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_HFPCLKPLLSEL_OFFSET register. +*/ +void sifive_prci_hfpclkpllsel_use_hfpclkpll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET ); + r &= ~PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK ; +__prci_writel (r,PRCI_HFPCLKPLLSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_HFPCLKPLLSEL_OFFSET );/* barrier */ +} + +static int __prci_consumer_reset (const char *rst_name,bool trigger) +{ +struct udevice *dev; +struct reset_ctl rst_sig; +int ret; + + ret =uclass_get_device_by_driver (UCLASS_RESET , +DM_DRIVER_GET (sifive_reset), + &dev); +if (ret) { +dev_err (dev,"Reset driver not found: %d\n" , ret); +return ret; + } + + ret =reset_get_by_name (dev, rst_name, &rst_sig); +if (ret) { +dev_err (dev,"failed to get %s reset\n" , rst_name); +return ret; + } + +if (reset_valid (&rst_sig)) { +if (trigger) + ret =reset_deassert (&rst_sig); +else + ret =reset_assert (&rst_sig); +if (ret) { +dev_err (dev,"failed to trigger reset id = %ld\n" , + rst_sig.id); +return ret; + } + } + +return ret; +} + +/** +* sifive_prci_ddr_release_reset() - Release DDR reset +* @pd: struct __prci_data * for the PRCI containing the DDRCLK mux reg +* +*/ +void sifive_prci_ddr_release_reset (struct __prci_data *pd) +{ +/* Release DDR ctrl reset */ +__prci_consumer_reset ("ddr_ctrl" , true); + +/* HACK to get the '1 full controller clock cycle'. */ + asmvolatile ("fence" ); + +/* Release DDR AXI reset */ +__prci_consumer_reset ("ddr_axi" , true); + +/* Release DDR AHB reset */ +__prci_consumer_reset ("ddr_ahb" , true); + +/* Release DDR PHY reset */ +__prci_consumer_reset ("ddr_phy" , true); + +/* HACK to get the '1 full controller clock cycle'. */ + asmvolatile ("fence" ); + +/* +* These take like 16 cycles to actually propagate. We can't go sending +* stuff before they come out of reset. So wait. +*/ +for (int i =0 ; i <256 ; i++) + asmvolatile ("nop" ); +} + +/** +* sifive_prci_ethernet_release_reset() - Release ethernet reset +* @pd: struct __prci_data * for the PRCI containing the Ethernet CLK mux reg +* +*/ +void sifive_prci_ethernet_release_reset (struct __prci_data *pd) +{ +/* Release GEMGXL reset */ +__prci_consumer_reset ("gemgxl_reset" , true); + +/* Procmon => core clock */ +__prci_writel (PRCI_PROCMONCFG_CORE_CLOCK_MASK ,PRCI_PROCMONCFG_OFFSET , + pd); + +/* Release Chiplink reset */ +__prci_consumer_reset ("cltx_reset" , true); +} + +/** +* sifive_prci_cltx_release_reset() - Release cltx reset +* @pd: struct __prci_data * for the PRCI containing the Ethernet CLK mux reg +* +*/ +void sifive_prci_cltx_release_reset (struct __prci_data *pd) +{ +/* Release CLTX reset */ +__prci_consumer_reset ("cltx_reset" , true); +} + +/* Core clock mux control */ + +/** +* sifive_prci_coreclksel_use_hfclk() - switch the CORECLK mux to output HFCLK +* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg +* +* Switch the CORECLK mux to the HFCLK input source; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_CORECLKSEL_OFFSET register. +*/ +void sifive_prci_coreclksel_use_hfclk (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); + r |=PRCI_CORECLKSEL_CORECLKSEL_MASK ; +__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ +} + +/** +* sifive_prci_coreclksel_use_corepll() - switch the CORECLK mux to output COREPLL +* @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg +* +* Switch the CORECLK mux to the PLL output clock; return once complete. +* +* Context: Any context. Caller must prevent concurrent changes to the +* PRCI_CORECLKSEL_OFFSET register. +*/ +void sifive_prci_coreclksel_use_corepll (struct __prci_data *pd) +{ +u32 r; + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET ); + r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK ; +__prci_writel (r,PRCI_CORECLKSEL_OFFSET , pd); + + r =__prci_readl (pd,PRCI_CORECLKSEL_OFFSET );/* barrier */ +} + +static ulong sifive_prci_parent_rate (struct __prci_clock *pc,struct prci_clk_desc *data) +{ +ulong parent_rate; +ulong i; +struct __prci_clock *p; + +if (strcmp (pc->parent_name,"corepll" ) ==0 || +strcmp (pc->parent_name,"hfpclkpll" ) ==0 ) { +for (i =0 ; i < data->num_clks; i++) { +if (strcmp (pc->parent_name, data->clks[i].name) ==0 ) +break ; + } + +if (i >= data->num_clks) +return -ENXIO ; + + p = &data->clks[i]; +if (!p->pd || !p->ops->recalc_rate) +return -ENXIO ; + +return p->ops->recalc_rate (p,sifive_prci_parent_rate (p, data)); + } + +if (strcmp (pc->parent_name,"rtcclk" ) ==0 ) + parent_rate =clk_get_rate (&pc->pd->parent_rtcclk); +else + parent_rate =clk_get_rate (&pc->pd->parent_hfclk); + +return parent_rate; +} + +static ulong sifive_prci_get_rate (struct clk *clk) +{ +struct __prci_clock *pc; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd || !pc->ops->recalc_rate) +return -ENXIO ; + +return pc->ops->recalc_rate (pc,sifive_prci_parent_rate (pc, data)); +} + +static ulong sifive_prci_set_rate (struct clk *clk,ulong rate) +{ +int err; +struct __prci_clock *pc; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd || !pc->ops->set_rate) +return -ENXIO ; + + err = pc->ops->set_rate (pc, rate,sifive_prci_parent_rate (pc, data)); +if (err) +return err; + +return rate; +} + +static int sifive_prci_enable (struct clk *clk) +{ +struct __prci_clock *pc; +int ret =0 ; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd) +return -ENXIO ; + +if (pc->ops->enable_clk) + ret = pc->ops->enable_clk (pc,1 ); + +return ret; +} + +static int sifive_prci_disable (struct clk *clk) +{ +struct __prci_clock *pc; +int ret =0 ; +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (clk->dev); + +if (data->num_clks <= clk->id) +return -ENXIO ; + + pc = &data->clks[clk->id]; +if (!pc->pd) +return -ENXIO ; + +if (pc->ops->enable_clk) + ret = pc->ops->enable_clk (pc,0 ); + +return ret; +} + +static int sifive_prci_probe (struct udevice *dev) +{ +int i, err; +struct __prci_clock *pc; +struct __prci_data *pd =dev_get_priv (dev); + +struct prci_clk_desc *data = + (struct prci_clk_desc *)dev_get_driver_data (dev); + + pd->va = (void *)dev_read_addr (dev); +if (IS_ERR (pd->va)) +return PTR_ERR (pd->va); + + err =clk_get_by_index (dev,0 , &pd->parent_hfclk); +if (err) +return err; + + err =clk_get_by_index (dev,1 , &pd->parent_rtcclk); +if (err) +return err; + +for (i =0 ; i < data->num_clks; ++i) { + pc = &data->clks[i]; + pc->pd = pd; +if (pc->pwd) +__prci_wrpll_read_cfg0 (pd, pc->pwd); + } + +if (IS_ENABLED (CONFIG_SPL_BUILD )) { +if (device_is_compatible (dev,"sifive,fu740-c000-prci" )) { +u32 prci_pll_reg; +unsigned long parent_rate; + + prci_pll_reg =readl (pd->va +PRCI_PRCIPLL_OFFSET ); + +if (prci_pll_reg &PRCI_PRCIPLL_HFPCLKPLL ) { +/* +* Only initialize the HFPCLK PLL. In this +* case the design uses hfpclk to drive +* Chiplink +*/ + pc = &data->clks[PRCI_CLK_HFPCLKPLL ]; + parent_rate =sifive_prci_parent_rate (pc, data); +sifive_prci_wrpll_set_rate (pc,260000000 , + parent_rate); + pc->ops->enable_clk (pc,1 ); + }else if (prci_pll_reg &PRCI_PRCIPLL_CLTXPLL ) { +/* CLTX pll init */ + pc = &data->clks[PRCI_CLK_CLTXPLL ]; + parent_rate =sifive_prci_parent_rate (pc, data); +sifive_prci_wrpll_set_rate (pc,260000000 , + parent_rate); + pc->ops->enable_clk (pc,1 ); + } + } + } + +return 0 ; +} + +static struct clk_ops sifive_prci_ops = { + .set_rate = sifive_prci_set_rate, + .get_rate = sifive_prci_get_rate, + .enable = sifive_prci_enable, + .disable = sifive_prci_disable, +}; + +static int sifive_clk_bind (struct udevice *dev) +{ +return sifive_reset_bind (dev,PRCI_DEVICERESETCNT ); +} + +static const struct udevice_id sifive_prci_ids[] = { + { .compatible ="sifive,fu540-c000-prci" , .data = (ulong)&prci_clk_fu540 }, + { .compatible ="sifive,fu740-c000-prci" , .data = (ulong)&prci_clk_fu740 }, + { } +}; + +U_BOOT_DRIVER (sifive_prci) = { + .name ="sifive-prci" , + .id =UCLASS_CLK , + .of_match = sifive_prci_ids, + .probe = sifive_prci_probe, + .ops = &sifive_prci_ops, + .priv_auto =sizeof (struct __prci_data ), + .bind = sifive_clk_bind, +};drivers/clk/sifive/sifive-prci.h new file +323
-1@@ -0,0 +1,323 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Wesley Terpstra +* Paul Walmsley +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __SIFIVE_CLK_SIFIVE_PRCI_H +#define __SIFIVE_CLK_SIFIVE_PRCI_H + +#include <clk.h> +#include <linux/clk/analogbits-wrpll-cln28hpc.h> + +/* +* EXPECTED_CLK_PARENT_COUNT: how many parent clocks this driver expects: +* hfclk and rtcclk +*/ +#define EXPECTED_CLK_PARENT_COUNT 2 + +/* +* Register offsets and bitmasks +*/ + +/* COREPLLCFG0 */ +#define PRCI_COREPLLCFG0_OFFSET 0x4 +#define PRCI_COREPLLCFG0_DIVR_SHIFT 0 +#define PRCI_COREPLLCFG0_DIVR_MASK (0x3f << PRCI_COREPLLCFG0_DIVR_SHIFT) +#define PRCI_COREPLLCFG0_DIVF_SHIFT 6 +#define PRCI_COREPLLCFG0_DIVF_MASK (0x1ff << PRCI_COREPLLCFG0_DIVF_SHIFT) +#define PRCI_COREPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_COREPLLCFG0_DIVQ_MASK (0x7 << PRCI_COREPLLCFG0_DIVQ_SHIFT) +#define PRCI_COREPLLCFG0_RANGE_SHIFT 18 +#define PRCI_COREPLLCFG0_RANGE_MASK (0x7 << PRCI_COREPLLCFG0_RANGE_SHIFT) +#define PRCI_COREPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_COREPLLCFG0_BYPASS_MASK (0x1 << PRCI_COREPLLCFG0_BYPASS_SHIFT) +#define PRCI_COREPLLCFG0_FSE_SHIFT 25 +#define PRCI_COREPLLCFG0_FSE_MASK (0x1 << PRCI_COREPLLCFG0_FSE_SHIFT) +#define PRCI_COREPLLCFG0_LOCK_SHIFT 31 +#define PRCI_COREPLLCFG0_LOCK_MASK (0x1 << PRCI_COREPLLCFG0_LOCK_SHIFT) + +/* COREPLLCFG1 */ +#define PRCI_COREPLLCFG1_OFFSET 0x8 +#define PRCI_COREPLLCFG1_CKE_SHIFT 31 +#define PRCI_COREPLLCFG1_CKE_MASK (0x1 << PRCI_COREPLLCFG1_CKE_SHIFT) + +/* DDRPLLCFG0 */ +#define PRCI_DDRPLLCFG0_OFFSET 0xc +#define PRCI_DDRPLLCFG0_DIVR_SHIFT 0 +#define PRCI_DDRPLLCFG0_DIVR_MASK (0x3f << PRCI_DDRPLLCFG0_DIVR_SHIFT) +#define PRCI_DDRPLLCFG0_DIVF_SHIFT 6 +#define PRCI_DDRPLLCFG0_DIVF_MASK (0x1ff << PRCI_DDRPLLCFG0_DIVF_SHIFT) +#define PRCI_DDRPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_DDRPLLCFG0_DIVQ_MASK (0x7 << PRCI_DDRPLLCFG0_DIVQ_SHIFT) +#define PRCI_DDRPLLCFG0_RANGE_SHIFT 18 +#define PRCI_DDRPLLCFG0_RANGE_MASK (0x7 << PRCI_DDRPLLCFG0_RANGE_SHIFT) +#define PRCI_DDRPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_DDRPLLCFG0_BYPASS_MASK (0x1 << PRCI_DDRPLLCFG0_BYPASS_SHIFT) +#define PRCI_DDRPLLCFG0_FSE_SHIFT 25 +#define PRCI_DDRPLLCFG0_FSE_MASK (0x1 << PRCI_DDRPLLCFG0_FSE_SHIFT) +#define PRCI_DDRPLLCFG0_LOCK_SHIFT 31 +#define PRCI_DDRPLLCFG0_LOCK_MASK (0x1 << PRCI_DDRPLLCFG0_LOCK_SHIFT) + +/* DDRPLLCFG1 */ +#define PRCI_DDRPLLCFG1_OFFSET 0x10 +#define PRCI_DDRPLLCFG1_CKE_SHIFT 31 +#define PRCI_DDRPLLCFG1_CKE_MASK (0x1 << PRCI_DDRPLLCFG1_CKE_SHIFT) + +/* PCIEAUXCFG1 */ +#define PRCI_PCIEAUXCFG1_OFFSET 0x14 +#define PRCI_PCIEAUXCFG1_SHIFT 0 +#define PRCI_PCIEAUXCFG1_MASK (0x1 << PRCI_PCIEAUXCFG1_SHIFT) + +/* GEMGXLPLLCFG0 */ +#define PRCI_GEMGXLPLLCFG0_OFFSET 0x1c +#define PRCI_GEMGXLPLLCFG0_DIVR_SHIFT 0 +#define PRCI_GEMGXLPLLCFG0_DIVR_MASK \ + (0x3f << PRCI_GEMGXLPLLCFG0_DIVR_SHIFT) +#define PRCI_GEMGXLPLLCFG0_DIVF_SHIFT 6 +#define PRCI_GEMGXLPLLCFG0_DIVF_MASK \ + (0x1ff << PRCI_GEMGXLPLLCFG0_DIVF_SHIFT) +#define PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_GEMGXLPLLCFG0_DIVQ_MASK (0x7 << PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT) +#define PRCI_GEMGXLPLLCFG0_RANGE_SHIFT 18 +#define PRCI_GEMGXLPLLCFG0_RANGE_MASK \ + (0x7 << PRCI_GEMGXLPLLCFG0_RANGE_SHIFT) +#define PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_GEMGXLPLLCFG0_BYPASS_MASK \ + (0x1 << PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT) +#define PRCI_GEMGXLPLLCFG0_FSE_SHIFT 25 +#define PRCI_GEMGXLPLLCFG0_FSE_MASK \ + (0x1 << PRCI_GEMGXLPLLCFG0_FSE_SHIFT) +#define PRCI_GEMGXLPLLCFG0_LOCK_SHIFT 31 +#define PRCI_GEMGXLPLLCFG0_LOCK_MASK (0x1 << PRCI_GEMGXLPLLCFG0_LOCK_SHIFT) + +/* GEMGXLPLLCFG1 */ +#define PRCI_GEMGXLPLLCFG1_OFFSET 0x20 +#define PRCI_GEMGXLPLLCFG1_CKE_SHIFT 31 +#define PRCI_GEMGXLPLLCFG1_CKE_MASK (0x1 << PRCI_GEMGXLPLLCFG1_CKE_SHIFT) + +/* CORECLKSEL */ +#define PRCI_CORECLKSEL_OFFSET 0x24 +#define PRCI_CORECLKSEL_CORECLKSEL_SHIFT 0 +#define PRCI_CORECLKSEL_CORECLKSEL_MASK \ + (0x1 << PRCI_CORECLKSEL_CORECLKSEL_SHIFT) + +/* DEVICESRESETREG */ +#define PRCI_DEVICESRESETREG_OFFSET 0x28 +#define PRCI_DEVICERESETCNT 6 + +/* CLKMUXSTATUSREG */ +#define PRCI_CLKMUXSTATUSREG_OFFSET 0x2c +#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT 1 +#define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK \ + (0x1 << PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT) + +/* CLTXPLLCFG0 */ +#define PRCI_CLTXPLLCFG0_OFFSET 0x30 +#define PRCI_CLTXPLLCFG0_DIVR_SHIFT 0 +#define PRCI_CLTXPLLCFG0_DIVR_MASK (0x3f << PRCI_CLTXPLLCFG0_DIVR_SHIFT) +#define PRCI_CLTXPLLCFG0_DIVF_SHIFT 6 +#define PRCI_CLTXPLLCFG0_DIVF_MASK (0x1ff << PRCI_CLTXPLLCFG0_DIVF_SHIFT) +#define PRCI_CLTXPLLCFG0_DIVQ_SHIFT 15 +#define PRCI_CLTXPLLCFG0_DIVQ_MASK (0x7 << PRCI_CLTXPLLCFG0_DIVQ_SHIFT) +#define PRCI_CLTXPLLCFG0_RANGE_SHIFT 18 +#define PRCI_CLTXPLLCFG0_RANGE_MASK (0x7 << PRCI_CLTXPLLCFG0_RANGE_SHIFT) +#define PRCI_CLTXPLLCFG0_BYPASS_SHIFT 24 +#define PRCI_CLTXPLLCFG0_BYPASS_MASK (0x1 << PRCI_CLTXPLLCFG0_BYPASS_SHIFT) +#define PRCI_CLTXPLLCFG0_FSE_SHIFT 25 +#define PRCI_CLTXPLLCFG0_FSE_MASK (0x1 << PRCI_CLTXPLLCFG0_FSE_SHIFT) +#define PRCI_CLTXPLLCFG0_LOCK_SHIFT 31 +#define PRCI_CLTXPLLCFG0_LOCK_MASK (0x1 << PRCI_CLTXPLLCFG0_LOCK_SHIFT) + +/* CLTXPLLCFG1 */ +#define PRCI_CLTXPLLCFG1_OFFSET 0x34 +#define PRCI_CLTXPLLCFG1_CKE_SHIFT 24 +#define PRCI_CLTXPLLCFG1_CKE_MASK (0x1 << PRCI_CLTXPLLCFG1_CKE_SHIFT) + +/* DVFSCOREPLLCFG0 */ +#define PRCI_DVFSCOREPLLCFG0_OFFSET 0x38 + +/* DVFSCOREPLLCFG1 */ +#define PRCI_DVFSCOREPLLCFG1_OFFSET 0x3c +#define PRCI_DVFSCOREPLLCFG1_CKE_SHIFT 24 +#define PRCI_DVFSCOREPLLCFG1_CKE_MASK (0x1 << PRCI_DVFSCOREPLLCFG1_CKE_SHIFT) + +/* COREPLLSEL */ +#define PRCI_COREPLLSEL_OFFSET 0x40 +#define PRCI_COREPLLSEL_COREPLLSEL_SHIFT 0 +#define PRCI_COREPLLSEL_COREPLLSEL_MASK \ + (0x1 << PRCI_COREPLLSEL_COREPLLSEL_SHIFT) + +/* HFPCLKPLLCFG0 */ +#define PRCI_HFPCLKPLLCFG0_OFFSET 0x50 +#define PRCI_HFPCLKPLL_CFG0_DIVR_SHIFT 0 +#define PRCI_HFPCLKPLL_CFG0_DIVR_MASK \ + (0x3f << PRCI_HFPCLKPLLCFG0_DIVR_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_DIVF_SHIFT 6 +#define PRCI_HFPCLKPLL_CFG0_DIVF_MASK \ + (0x1ff << PRCI_HFPCLKPLLCFG0_DIVF_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_DIVQ_SHIFT 15 +#define PRCI_HFPCLKPLL_CFG0_DIVQ_MASK \ + (0x7 << PRCI_HFPCLKPLLCFG0_DIVQ_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_RANGE_SHIFT 18 +#define PRCI_HFPCLKPLL_CFG0_RANGE_MASK \ + (0x7 << PRCI_HFPCLKPLLCFG0_RANGE_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_BYPASS_SHIFT 24 +#define PRCI_HFPCLKPLL_CFG0_BYPASS_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG0_BYPASS_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_FSE_SHIFT 25 +#define PRCI_HFPCLKPLL_CFG0_FSE_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG0_FSE_SHIFT) +#define PRCI_HFPCLKPLL_CFG0_LOCK_SHIFT 31 +#define PRCI_HFPCLKPLL_CFG0_LOCK_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG0_LOCK_SHIFT) + +/* HFPCLKPLLCFG1 */ +#define PRCI_HFPCLKPLLCFG1_OFFSET 0x54 +#define PRCI_HFPCLKPLLCFG1_CKE_SHIFT 24 +#define PRCI_HFPCLKPLLCFG1_CKE_MASK \ + (0x1 << PRCI_HFPCLKPLLCFG1_CKE_SHIFT) + +/* HFPCLKPLLSEL */ +#define PRCI_HFPCLKPLLSEL_OFFSET 0x58 +#define PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_SHIFT 0 +#define PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK \ + (0x1 << PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_SHIFT) + +/* HFPCLKPLLDIV */ +#define PRCI_HFPCLKPLLDIV_OFFSET 0x5c + +/* PRCIPLL */ +#define PRCI_PRCIPLL_OFFSET 0xe0 + +#define PRCI_PRCIPLL_CLTXPLL (0x1 << 0) +#define PRCI_PRCIPLL_GEMGXLPLL (0x1 << 1) +#define PRCI_PRCIPLL_DDRPLL (0x1 << 2) +#define PRCI_PRCIPLL_HFPCLKPLL (0x1 << 3) +#define PRCI_PRCIPLL_DVFSCOREPLL (0x1 << 4) +#define PRCI_PRCIPLL_COREPLL (0x1 << 5) + +/* PROCMONCFG */ +#define PRCI_PROCMONCFG_OFFSET 0xF0 +#define PRCI_PROCMONCFG_CORE_CLOCK_SHIFT 24 +#define PRCI_PROCMONCFG_CORE_CLOCK_MASK \ + (0x1 << PRCI_PROCMONCFG_CORE_CLOCK_SHIFT) + +/* +* Private structures +*/ + +/** +* struct __prci_data - per-device-instance data +* @va: base virtual address of the PRCI IP block +* @parent: parent clk instance +* +* PRCI per-device instance data +*/ +struct __prci_data { +void *va; +struct clk parent_hfclk; +struct clk parent_rtcclk; +}; + +/** +* struct __prci_wrpll_data - WRPLL configuration and integration data +* @c: WRPLL current configuration record +* @enable_bypass: fn ptr to code to bypass the WRPLL (if applicable; else NULL) +* @disable_bypass: fn ptr to code to not bypass the WRPLL (or NULL) +* @cfg0_offs: WRPLL CFG0 register offset (in bytes) from the PRCI base address +* @cfg1_offs: WRPLL CFG1 register offset (in bytes) from the PRCI base address +* @release_reset: fn ptr to code to release clock reset +* +* @enable_bypass and @disable_bypass are used for WRPLL instances +* that contain a separate external glitchless clock mux downstream +* from the PLL. The WRPLL internal bypass mux is not glitchless. +*/ +struct __prci_wrpll_data { +struct wrpll_cfg c; +void (*enable_bypass)(struct __prci_data *pd); +void (*disable_bypass)(struct __prci_data *pd); +u8 cfg0_offs; +u8 cfg1_offs; +void (*release_reset)(struct __prci_data *pd); +}; + +/** +* struct __prci_clock - describes a clock device managed by PRCI +* @name: user-readable clock name string - should match the manual +* @parent_name: parent name for this clock +* @ops: struct __prci_clock_ops for control +* @pwd: WRPLL-specific data, associated with this clock (if not NULL) +* @pd: PRCI-specific data associated with this clock (if not NULL) +* +* PRCI clock data. Used by the PRCI driver to register PRCI-provided +* clocks to the Linux clock infrastructure. +*/ +struct __prci_clock { +const char *name; +const char *parent_name; +const struct __prci_clock_ops *ops; +struct __prci_wrpll_data *pwd; +struct __prci_data *pd; +}; + +/* struct __prci_clock_ops - clock operations */ +struct __prci_clock_ops { +int (*set_rate)(struct __prci_clock *pc, +unsigned long rate, +unsigned long parent_rate); +unsigned long (*round_rate)(struct __prci_clock *pc, +unsigned long rate, +unsigned long *parent_rate); +unsigned long (*recalc_rate)(struct __prci_clock *pc, +unsigned long parent_rate); +int (*enable_clk)(struct __prci_clock *pc,bool enable); +}; + +/* +* struct prci_clk_desc - describes the information of clocks of each SoCs +* @clks: point to a array of __prci_clock +* @num_clks: the number of element of clks +*/ +struct prci_clk_desc { +struct __prci_clock *clks; +size_t num_clks; +}; + +void sifive_prci_ethernet_release_reset (struct __prci_data *pd); +void sifive_prci_ddr_release_reset (struct __prci_data *pd); +void sifive_prci_cltx_release_reset (struct __prci_data *pd); + +/* Core clock mux control */ +void sifive_prci_coreclksel_use_hfclk (struct __prci_data *pd); +void sifive_prci_coreclksel_use_corepll (struct __prci_data *pd); +void sifive_prci_coreclksel_use_final_corepll (struct __prci_data *pd); +void sifive_prci_corepllsel_use_dvfscorepll (struct __prci_data *pd); +void sifive_prci_corepllsel_use_corepll (struct __prci_data *pd); +void sifive_prci_hfpclkpllsel_use_hfclk (struct __prci_data *pd); +void sifive_prci_hfpclkpllsel_use_hfpclkpll (struct __prci_data *pd); + +unsigned long sifive_prci_wrpll_round_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long *parent_rate); + +/* Linux clock framework integration */ +int sifive_prci_wrpll_set_rate (struct __prci_clock *pc, +unsigned long rate, +unsigned long parent_rate); + +unsigned long sifive_prci_wrpll_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate); + +unsigned long sifive_prci_tlclksel_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate); + +unsigned long sifive_prci_hfpclkplldiv_recalc_rate (struct __prci_clock *pc, +unsigned long parent_rate); + +int sifive_prci_clock_enable (struct __prci_clock *pc,bool enable); + +#endif /* __SIFIVE_CLK_SIFIVE_PRCI_H */ --Quoted 2 lines
2.31.0
--
Regards,Dimitri.
PATCH v7 3/8 drivers: ram: sifive: rename fu540_ddr and add fu740 support
In reply to Green WanRename fu540_ddr.c to sifive_ddr.c and add fu740 support
---
drivers/ram/sifive/Kconfig | 8 +-
drivers/ram/sifive/Makefile | 2 +-
.../ram/sifive/{fu540_ddr.c => sifive_ddr.c} | 89 ++++++++++---------
3 files changed, 50 insertions(+), 49 deletions(-)
rename drivers/ram/sifive/{fu540_ddr.c => sifive_ddr.c} (81%)drivers/ram/sifive/Kconfig +4 -4
@@ -5,9 +5,9 @@ config RAM_SIFIVE help This enables support for ram drivers of SiFive SoCs. -config SIFIVE_FU540_DDR - bool "SiFive FU540 DDR driver" +config SIFIVE_DDR + bool "SiFive DDR driver" depends on RAM_SIFIVE - default y if TARGET_SIFIVE_UNLEASHED + default y if TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED help - This enables DDR support for the platforms based on SiFive FU540 SoC. + This enables DDR support for the platforms based on SiFive SoC.
drivers/ram/sifive/Makefile +1 -1
@@ -3,4 +3,4 @@ # Copyright (c) 2020 SiFive, Inc # -obj-$(CONFIG_SIFIVE_FU540_DDR) += fu540_ddr.o +obj-$(CONFIG_SIFIVE_DDR) += sifive_ddr.o
drivers/ram/sifive/sifive_ddr.c renamed from drivers/ram/sifive/fu540_ddr.c +45 -44
231 lines not on this page · raw message
Signature · 1 line
2.31.0
PATCH v7 4/8 drivers: pci: add pcie support for fu740
In reply to Green WanAdd pcie driver for SiFive fu740, the driver depends on fu740 gpio, clk and reset driver to do init. Force running at Gen1 for better capatible enumeration.
Several devices are tested:
a) M.2 NVMe SSD
b) USB-to-PCI adapter
c) Ethernet adapter (E1000 compatible)
--- drivers/pci/Kconfig | 10 + drivers/pci/Makefile | 1 + drivers/pci/pcie_dw_sifive.c | 508 +++++++++++++++++++++++++++++++++++ 3 files changed, 519 insertions(+) create mode 100644 drivers/pci/pcie_dw_sifive.c
drivers/pci/Kconfig +10 -0
@@ -97,6 +97,16 @@ config PCIE_DW_MVEBU Armada-8K SoCs. The PCIe controller on Armada-8K is based on DesignWare hardware. +config PCIE_DW_SIFIVE + bool "Enable SiFive FU740 PCIe" + depends on CLK_SIFIVE_PRCI + depends on RESET_SIFIVE + depends on SIFIVE_GPIO + select PCIE_DW_COMMON + help + Say Y here if you want to enable PCIe controller support on + FU740. + config PCIE_FSL bool "FSL PowerPC PCIe support" depends on DM_PCI
drivers/pci/Makefile +1 -0
@@ -53,3 +53,4 @@ obj-$(CONFIG_PCIE_DW_ROCKCHIP) += pcie_dw_rockchip.o obj-$(CONFIG_PCIE_DW_MESON) += pcie_dw_meson.o obj-$(CONFIG_PCI_BRCMSTB) += pcie_brcmstb.o obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o +obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
drivers/pci/pcie_dw_sifive.c new file +508 -0
508 lines not on this page · raw message
Signature · 1 line
2.31.0
PATCH v7 4/8 drivers: pci: add pcie support for fu740
Quoted 539 lines · Green Wan
Add pcie driver for SiFive fu740, the driver depends on fu740 gpio, clk and reset driver to do init. Force running at Gen1 for better capatible enumeration.
Several devices are tested:
a) M.2 NVMe SSD
b) USB-to-PCI adapter
c) Ethernet adapter (E1000 compatible)Signed-off-by Green Wan <[email protected]>--- drivers/pci/Kconfig | 10 + drivers/pci/Makefile | 1 + drivers/pci/pcie_dw_sifive.c | 508 +++++++++++++++++++++++++++++++++++ 3 files changed, 519 insertions(+) create mode 100644 drivers/pci/pcie_dw_sifive.cdrivers/pci/Kconfig +10
-0@@ -97,6 +97,16 @@ config PCIE_DW_MVEBU Armada-8K SoCs. The PCIe controller on Armada-8K is based on DesignWare hardware. +config PCIE_DW_SIFIVE + bool "Enable SiFive FU740 PCIe" + depends on CLK_SIFIVE_PRCI + depends on RESET_SIFIVE + depends on SIFIVE_GPIO + select PCIE_DW_COMMON + help + Say Y here if you want to enable PCIe controller support on + FU740. + config PCIE_FSL bool "FSL PowerPC PCIe support" depends on DM_PCIdrivers/pci/Makefile +1
-0@@ -53,3 +53,4 @@ obj-$(CONFIG_PCIE_DW_ROCKCHIP) += pcie_dw_rockchip.o obj-$(CONFIG_PCIE_DW_MESON) += pcie_dw_meson.o obj-$(CONFIG_PCI_BRCMSTB) += pcie_brcmstb.o obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o +obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.odrivers/pci/pcie_dw_sifive.c new file +486
-0@@ -0,0 +1,508 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* SiFive FU740 DesignWare PCIe Controller +* +* Copyright (C) 2020-2021 SiFive, Inc. +* +* Based in early part on the i.MX6 PCIe host controller shim which is: +* +* Copyright (C) 2013 Kosagi +* http://www.kosagi.com +* +* Based on driver from author: Alan Mikhak <[email protected]> +*/ +#include <asm/io.h> +#include <asm-generic/gpio.h> +#include <clk.h> +#include <common.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <generic-phy.h> +#include <linux/bitops.h> +#include <linux/log2.h> +#include <pci.h> +#include <pci_ep.h> +#include <pci_ids.h> +#include <regmap.h> +#include <reset.h> +#include <syscon.h> + +#include "pcie_dw_common.h" + +struct pcie_sifive { +/* Must be first member of the struct */ +struct pcie_dw dw; + +/* private control regs */ +void __iomem *priv_base; + +/* reset, power, clock resources */ +int sys_int_pin; +struct gpio_desc pwren_gpio; +struct gpio_desc reset_gpio; +struct clk aux_ck; +struct reset_ctl reset; +}; + +enum pcie_sifive_devtype { +SV_PCIE_UNKNOWN_TYPE =0 , +SV_PCIE_ENDPOINT_TYPE =1 , +SV_PCIE_HOST_TYPE =3 +}; + +#define ASSERTION_DELAY 100 +#define PCIE_PERST_ASSERT 0x0 +#define PCIE_PERST_DEASSERT 0x1 +#define PCIE_PHY_RESET 0x1 +#define PCIE_PHY_RESET_DEASSERT 0x0 +#define GPIO_LOW 0x0 +#define GPIO_HIGH 0x1 +#define PCIE_PHY_SEL 0x1 + +#define sv_info(sv, fmt, arg...) printf(fmt, ## arg) +#define sv_warn(sv, fmt, arg...) printf(fmt, ## arg) +#define sv_debug(sv, fmt, arg...) debug(fmt, ## arg) +#define sv_err(sv, fmt, arg...) printf(fmt, ## arg) + +/* Doorbell Interface */ +#define DBI_OFFSET 0x0 +#define DBI_SIZE 0x1000 + +#define PL_OFFSET 0x700 + +#define PHY_DEBUG_R0 (PL_OFFSET + 0x28) + +#define PHY_DEBUG_R1 (PL_OFFSET + 0x2c) +#define PHY_DEBUG_R1_LINK_UP (0x1 << 4) +#define PHY_DEBUG_R1_LINK_IN_TRAINING (0x1 << 29) + +#define PCIE_MISC_CONTROL_1 0x8bc +#define DBI_RO_WR_EN BIT(0) + +/* pcie reset */ +#define PCIEX8MGMT_PERST_N 0x0 + +/* LTSSM */ +#define PCIEX8MGMT_APP_LTSSM_ENABLE 0x10 +#define LTSSM_ENABLE_BIT BIT(0) + +/* phy reset */ +#define PCIEX8MGMT_APP_HOLD_PHY_RST 0x18 + +/* device type */ +#define PCIEX8MGMT_DEVICE_TYPE 0x708 +#define DEVICE_TYPE_EP 0x0 +#define DEVICE_TYPE_RC 0x4 + +/* phy control registers*/ +#define PCIEX8MGMT_PHY0_CR_PARA_ADDR 0x860 +#define PCIEX8MGMT_PHY0_CR_PARA_RD_EN 0x870 +#define PCIEX8MGMT_PHY0_CR_PARA_RD_DATA 0x878 +#define PCIEX8MGMT_PHY0_CR_PARA_SEL 0x880 +#define PCIEX8MGMT_PHY0_CR_PARA_WR_DATA 0x888 +#define PCIEX8MGMT_PHY0_CR_PARA_WR_EN 0x890 +#define PCIEX8MGMT_PHY0_CR_PARA_ACK 0x898 +#define PCIEX8MGMT_PHY1_CR_PARA_ADDR 0x8a0 +#define PCIEX8MGMT_PHY1_CR_PARA_RD_EN 0x8b0 +#define PCIEX8MGMT_PHY1_CR_PARA_RD_DATA 0x8b8 +#define PCIEX8MGMT_PHY1_CR_PARA_SEL 0x8c0 +#define PCIEX8MGMT_PHY1_CR_PARA_WR_DATA 0x8c8 +#define PCIEX8MGMT_PHY1_CR_PARA_WR_EN 0x8d0 +#define PCIEX8MGMT_PHY1_CR_PARA_ACK 0x8d8 + +#define PCIEX8MGMT_LANE_NUM 8 +#define PCIEX8MGMT_LANE 0x1008 +#define PCIEX8MGMT_LANE_OFF 0x100 +#define PCIEX8MGMT_TERM_MODE 0x0e21 + +#define PCIE_CAP_BASE 0x70 +#define PCI_CONFIG (r) (DBI_OFFSET + (r)) +#define PCIE_CAPABILITIES (r) PCI_CONFIG(PCIE_CAP_BASE + (r)) + +/* Link capability */ +#define PF0_PCIE_CAP_LINK_CAP PCIE_CAPABILITIES(0xc) +#define PCIE_LINK_CAP_MAX_SPEED_MASK 0xf +#define PCIE_LINK_CAP_MAX_SPEED_GEN1 BIT(0) +#define PCIE_LINK_CAP_MAX_SPEED_GEN2 BIT(1) +#define PCIE_LINK_CAP_MAX_SPEED_GEN3 BIT(2) +#define PCIE_LINK_CAP_MAX_SPEED_GEN4 BIT(3) + +static enum pcie_sifive_devtype pcie_sifive_get_devtype (struct pcie_sifive *sv) +{ +u32 val; + + val =readl (sv->priv_base +PCIEX8MGMT_DEVICE_TYPE ); +switch (val) { +case DEVICE_TYPE_RC : +return SV_PCIE_HOST_TYPE ; +case DEVICE_TYPE_EP : +return SV_PCIE_ENDPOINT_TYPE ; +default : +return SV_PCIE_UNKNOWN_TYPE ; + } +} + +static void pcie_sifive_priv_set_state (struct pcie_sifive *sv,u32 reg, +u32 bits,int state) +{ +u32 val; + + val =readl (sv->priv_base + reg); + val = state ? (val | bits) : (val & !bits); +writel (val, sv->priv_base + reg); +} + +static void pcie_sifive_assert_reset (struct pcie_sifive *sv) +{ +dm_gpio_set_value (&sv->reset_gpio,GPIO_LOW ); +writel (PCIE_PERST_ASSERT , sv->priv_base +PCIEX8MGMT_PERST_N ); +mdelay (ASSERTION_DELAY ); +} + +static void pcie_sifive_power_on (struct pcie_sifive *sv) +{ +dm_gpio_set_value (&sv->pwren_gpio,GPIO_HIGH ); +mdelay (ASSERTION_DELAY ); +} + +static void pcie_sifive_deassert_reset (struct pcie_sifive *sv) +{ +writel (PCIE_PERST_DEASSERT , sv->priv_base +PCIEX8MGMT_PERST_N ); +dm_gpio_set_value (&sv->reset_gpio,GPIO_HIGH ); +mdelay (ASSERTION_DELAY ); +} + +static int pcie_sifive_setphy (const u8 phy,const u8 write, +const u16 addr,const u16 wrdata, +u16 *rddata,struct pcie_sifive *sv) +{ +unsigned char ack =0 ; + +if (!(phy ==0 || phy ==1 )) +return -2 ; + +/* setup phy para */ +writel (addr, sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_ADDR : +PCIEX8MGMT_PHY0_CR_PARA_ADDR )); + +if (write) +writel (wrdata, sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_WR_DATA : +PCIEX8MGMT_PHY0_CR_PARA_WR_DATA )); + +/* enable access if write */ +if (write) +writel (1 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_WR_EN : +PCIEX8MGMT_PHY0_CR_PARA_WR_EN )); +else +writel (1 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_RD_EN : +PCIEX8MGMT_PHY0_CR_PARA_RD_EN )); + +/* wait for wait_idle */ +do { +u32 val; + + val =readl (sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_ACK : +PCIEX8MGMT_PHY0_CR_PARA_ACK )); +if (val) { + ack =1 ; +if (!write) +readl (sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_RD_DATA : +PCIEX8MGMT_PHY0_CR_PARA_RD_DATA )); +mdelay (1 ); + } + }while (!ack); + +/* clear */ +if (write) +writel (0 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_WR_EN : +PCIEX8MGMT_PHY0_CR_PARA_WR_EN )); +else +writel (0 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_RD_EN : +PCIEX8MGMT_PHY0_CR_PARA_RD_EN )); + +while (readl (sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_ACK : +PCIEX8MGMT_PHY0_CR_PARA_ACK ))) { +/* wait for ~wait_idle */ + } + +return 0 ; +} + +static void pcie_sifive_init_phy (struct pcie_sifive *sv) +{ +int lane; + +/* enable phy cr_para_sel interfaces */ +writel (PCIE_PHY_SEL , sv->priv_base +PCIEX8MGMT_PHY0_CR_PARA_SEL ); +writel (PCIE_PHY_SEL , sv->priv_base +PCIEX8MGMT_PHY1_CR_PARA_SEL ); +mdelay (1 ); + +/* set PHY AC termination mode */ +for (lane =0 ; lane <PCIEX8MGMT_LANE_NUM ; lane++) { +pcie_sifive_setphy (0 ,1 , +PCIEX8MGMT_LANE + + (PCIEX8MGMT_LANE_OFF * lane), +PCIEX8MGMT_TERM_MODE ,NULL , sv); +pcie_sifive_setphy (1 ,1 , +PCIEX8MGMT_LANE + + (PCIEX8MGMT_LANE_OFF * lane), +PCIEX8MGMT_TERM_MODE ,NULL , sv); + } +} + +static int pcie_sifive_check_link (struct pcie_sifive *sv) +{ +u32 val; + + val =readl (sv->dw.dbi_base +PHY_DEBUG_R1 ); +return (val &PHY_DEBUG_R1_LINK_UP ) && + !(val &PHY_DEBUG_R1_LINK_IN_TRAINING ); +} + +static void pcie_sifive_force_gen1 (struct pcie_sifive *sv) +{ +u32 val, linkcap; + +/* +* Force Gen1 operation when starting the link. In case the link is +* started in Gen2 mode, there is a possibility the devices on the +* bus will not be detected at all. This happens with PCIe switches. +*/ + +/* ctrl_ro_wr_enable */ + val =readl (sv->dw.dbi_base +PCIE_MISC_CONTROL_1 ); + val |=DBI_RO_WR_EN ; +writel (val, sv->dw.dbi_base +PCIE_MISC_CONTROL_1 ); + +/* configure link cap */ + linkcap =readl (sv->dw.dbi_base +PF0_PCIE_CAP_LINK_CAP ); + linkcap |=PCIE_LINK_CAP_MAX_SPEED_MASK ; +writel (linkcap, sv->dw.dbi_base +PF0_PCIE_CAP_LINK_CAP ); + +/* ctrl_ro_wr_disable */ + val &= ~DBI_RO_WR_EN ; +writel (val, sv->dw.dbi_base +PCIE_MISC_CONTROL_1 ); +} + +static void pcie_sifive_print_phy_debug (struct pcie_sifive *sv) +{ +sv_err (sv,"PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n" , +readl (sv->dw.dbi_base +PHY_DEBUG_R0 ), +readl (sv->dw.dbi_base +PHY_DEBUG_R1 )); +} + +static int pcie_sifive_wait_for_link (struct pcie_sifive *sv) +{ +u32 val; +int timeout; + +/* Wait for the link to train */ +mdelay (20 ); + timeout =20 ; + +do { +mdelay (1 ); + }while (--timeout && !pcie_sifive_check_link (sv)); + + val =readl (sv->dw.dbi_base +PHY_DEBUG_R1 ); +if (!(val &PHY_DEBUG_R1_LINK_UP ) || + (val &PHY_DEBUG_R1_LINK_IN_TRAINING )) { +sv_info (sv,"Failed to negotiate PCIe link!\n" ); +pcie_sifive_print_phy_debug (sv); +writel (PCIE_PHY_RESET , + sv->priv_base +PCIEX8MGMT_APP_HOLD_PHY_RST ); +return -ETIMEDOUT ; + } + +return 0 ; +} + +static int pcie_sifive_start_link (struct pcie_sifive *sv) +{ +if (pcie_sifive_check_link (sv)) +return -EALREADY ; + +pcie_sifive_force_gen1 (sv); + +/* set ltssm */ +pcie_sifive_priv_set_state (sv,PCIEX8MGMT_APP_LTSSM_ENABLE , +LTSSM_ENABLE_BIT ,1 ); +return 0 ; +} + +static int pcie_sifive_init_port (struct udevice *dev, +enum pcie_sifive_devtype mode) +{ +struct pcie_sifive *sv =dev_get_priv (dev); +int ret; + +/* Power on reset */ +pcie_sifive_assert_reset (sv); +pcie_sifive_power_on (sv); +pcie_sifive_deassert_reset (sv); + +/* Enable pcieauxclk */ + ret =clk_enable (&sv->aux_ck); +if (ret) +dev_err (dev,"unable to enable pcie_aux clock\n" ); + +/* +* assert hold_phy_rst (hold the controller LTSSM in reset +* after power_up_rst_n for register programming with cr_para) +*/ +writel (PCIE_PHY_RESET , sv->priv_base +PCIEX8MGMT_APP_HOLD_PHY_RST ); + +/* deassert power_up_rst_n */ + ret =reset_deassert (&sv->reset); +if (ret <0 ) { +dev_err (dev,"failed to deassert reset" ); +return -EINVAL ; + } + +pcie_sifive_init_phy (sv); + +/* disable pcieauxclk */ +clk_disable (&sv->aux_ck); + +/* deassert hold_phy_rst */ +writel (PCIE_PHY_RESET_DEASSERT , + sv->priv_base +PCIEX8MGMT_APP_HOLD_PHY_RST ); + +/* enable pcieauxclk */ +clk_enable (&sv->aux_ck); + +/* Set desired mode while core is not operational */ +if (mode ==SV_PCIE_HOST_TYPE ) +writel (DEVICE_TYPE_RC , + sv->priv_base +PCIEX8MGMT_DEVICE_TYPE ); +else +writel (DEVICE_TYPE_EP , + sv->priv_base +PCIEX8MGMT_DEVICE_TYPE ); + +/* Confirm desired mode from operational core */ +if (pcie_sifive_get_devtype (sv) != mode) +return -EINVAL ; + +pcie_dw_setup_host (&sv->dw); + +if (pcie_sifive_start_link (sv) == -EALREADY ) +sv_info (sv,"PCIe link is already up\n" ); +else if (pcie_sifive_wait_for_link (sv) == -ETIMEDOUT ) +return -ETIMEDOUT ; + +return 0 ; +} + +static int pcie_sifive_probe (struct udevice *dev) +{ +struct pcie_sifive *sv =dev_get_priv (dev); +struct udevice *parent =pci_get_controller (dev); +struct pci_controller *hose =dev_get_uclass_priv (parent); +int err; + + sv->dw.first_busno =dev_seq (dev); + sv->dw.dev = dev; + + err =pcie_sifive_init_port (dev,SV_PCIE_HOST_TYPE ); +if (err) { +sv_info (sv,"Failed to init port.\n" ); +return err; + } + +printf ("PCIE-%d: Link up (Gen%d-x%d, Bus%d)\n" , +dev_seq (dev),pcie_dw_get_link_speed (&sv->dw), +pcie_dw_get_link_width (&sv->dw), + hose->first_busno); + +return pcie_dw_prog_outbound_atu_unroll (&sv->dw, +PCIE_ATU_REGION_INDEX0 , +PCIE_ATU_TYPE_MEM , + sv->dw.mem.phys_start, + sv->dw.mem.bus_start, + sv->dw.mem.size); +} + +static void __iomem *get_fdt_addr (struct udevice *dev,const char *name) +{ +fdt_addr_t addr; + + addr =dev_read_addr_name (dev, name); + +return (addr ==FDT_ADDR_T_NONE ) ?NULL : (void __iomem *)addr; +} + +static int pcie_sifive_of_to_plat (struct udevice *dev) +{ +struct pcie_sifive *sv =dev_get_priv (dev); +int err; + +/* get designware DBI base addr */ + sv->dw.dbi_base =get_fdt_addr (dev,"dbi" ); +if (!sv->dw.dbi_base) +return -EINVAL ; + +/* get private control base addr */ + sv->priv_base =get_fdt_addr (dev,"mgmt" ); +if (!sv->priv_base) +return -EINVAL ; + +gpio_request_by_name (dev,"pwren-gpios" ,0 , &sv->pwren_gpio, +GPIOD_IS_OUT ); + +if (!dm_gpio_is_valid (&sv->pwren_gpio)) { +sv_info (sv,"pwren_gpio is invalid\n" ); +return -EINVAL ; + } + +gpio_request_by_name (dev,"reset-gpios" ,0 , &sv->reset_gpio, +GPIOD_IS_OUT ); + +if (!dm_gpio_is_valid (&sv->reset_gpio)) { +sv_info (sv,"reset_gpio is invalid\n" ); +return -EINVAL ; + } + + err =clk_get_by_index (dev,0 , &sv->aux_ck); +if (err) { +sv_info (sv,"clk_get_by_index(aux_ck) failed: %d\n" , err); +return err; + } + + err =reset_get_by_index (dev,0 , &sv->reset); +if (err) { +sv_info (sv,"reset_get_by_index(reset) failed: %d\n" , err); +return err; + } + +return 0 ;
drivers/pci/pcie_dw_sifive.c line 496
Quoted 10 lines
drivers/pci/pcie_dw_sifive.c new file +10
-0+} + +static const struct dm_pci_ops pcie_sifive_ops = { + .read_config = pcie_dw_read_config, + .write_config = pcie_dw_write_config, +}; + +static const struct udevice_id pcie_sifive_ids[] = { + { .compatible ="sifive,fu740-pcie" }, + { .compatible ="sifive,fu740-pcie-ecam" },
Are you sure the controller in ECAM mode should use this driver ? The Linux bindings only declare "sifive,fu740-pcie"
drivers/pci/pcie_dw_sifive.c line 508
Quoted 13 lines
drivers/pci/pcie_dw_sifive.c new file +12
-0+ {} +}; + +U_BOOT_DRIVER (pcie_sifive) = { + .name ="pcie_sifive" , + .id =UCLASS_PCI , + .of_match = pcie_sifive_ids, + .ops = &pcie_sifive_ops, + .of_to_plat = pcie_sifive_of_to_plat, + .probe = pcie_sifive_probe, + .priv_auto =sizeof (struct pcie_sifive ), +};
otherwise,
Neil
PATCH v7 4/8 drivers: pci: add pcie support for fu740
Quoted 546 lines · Neil Armstrong
Quoted 544 lines · Green Wan
Add pcie driver for SiFive fu740, the driver depends on fu740 gpio, clk and reset driver to do init. Force running at Gen1 for better capatible enumeration.
Several devices are tested:
a) M.2 NVMe SSD
b) USB-to-PCI adapter
c) Ethernet adapter (E1000 compatible)Signed-off-by Green Wan <[email protected]>--- drivers/pci/Kconfig | 10 + drivers/pci/Makefile | 1 + drivers/pci/pcie_dw_sifive.c | 508 +++++++++++++++++++++++++++++++++++ 3 files changed, 519 insertions(+) create mode 100644 drivers/pci/pcie_dw_sifive.cdrivers/pci/Kconfig +10
-0@@ -97,6 +97,16 @@ config PCIE_DW_MVEBU Armada-8K SoCs. The PCIe controller on Armada-8K is based on DesignWare hardware. +config PCIE_DW_SIFIVE + bool "Enable SiFive FU740 PCIe" + depends on CLK_SIFIVE_PRCI + depends on RESET_SIFIVE + depends on SIFIVE_GPIO + select PCIE_DW_COMMON + help + Say Y here if you want to enable PCIe controller support on + FU740. + config PCIE_FSL bool "FSL PowerPC PCIe support" depends on DM_PCIdrivers/pci/Makefile +1
-0@@ -53,3 +53,4 @@ obj-$(CONFIG_PCIE_DW_ROCKCHIP) += pcie_dw_rockchip.o obj-$(CONFIG_PCIE_DW_MESON) += pcie_dw_meson.o obj-$(CONFIG_PCI_BRCMSTB) += pcie_brcmstb.o obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o +obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.odrivers/pci/pcie_dw_sifive.c new file +491
-0@@ -0,0 +1,508 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* SiFive FU740 DesignWare PCIe Controller +* +* Copyright (C) 2020-2021 SiFive, Inc. +* +* Based in early part on the i.MX6 PCIe host controller shim which is: +* +* Copyright (C) 2013 Kosagi +* http://www.kosagi.com +* +* Based on driver from author: Alan Mikhak <[email protected]> +*/ +#include <asm/io.h> +#include <asm-generic/gpio.h> +#include <clk.h> +#include <common.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <generic-phy.h> +#include <linux/bitops.h> +#include <linux/log2.h> +#include <pci.h> +#include <pci_ep.h> +#include <pci_ids.h> +#include <regmap.h> +#include <reset.h> +#include <syscon.h> + +#include "pcie_dw_common.h" + +struct pcie_sifive { +/* Must be first member of the struct */ +struct pcie_dw dw; + +/* private control regs */ +void __iomem *priv_base; + +/* reset, power, clock resources */ +int sys_int_pin; +struct gpio_desc pwren_gpio; +struct gpio_desc reset_gpio; +struct clk aux_ck; +struct reset_ctl reset; +}; + +enum pcie_sifive_devtype { +SV_PCIE_UNKNOWN_TYPE =0 , +SV_PCIE_ENDPOINT_TYPE =1 , +SV_PCIE_HOST_TYPE =3 +}; + +#define ASSERTION_DELAY 100 +#define PCIE_PERST_ASSERT 0x0 +#define PCIE_PERST_DEASSERT 0x1 +#define PCIE_PHY_RESET 0x1 +#define PCIE_PHY_RESET_DEASSERT 0x0 +#define GPIO_LOW 0x0 +#define GPIO_HIGH 0x1 +#define PCIE_PHY_SEL 0x1 + +#define sv_info(sv, fmt, arg...) printf(fmt, ## arg) +#define sv_warn(sv, fmt, arg...) printf(fmt, ## arg) +#define sv_debug(sv, fmt, arg...) debug(fmt, ## arg) +#define sv_err(sv, fmt, arg...) printf(fmt, ## arg) + +/* Doorbell Interface */ +#define DBI_OFFSET 0x0 +#define DBI_SIZE 0x1000 + +#define PL_OFFSET 0x700 + +#define PHY_DEBUG_R0 (PL_OFFSET + 0x28) + +#define PHY_DEBUG_R1 (PL_OFFSET + 0x2c) +#define PHY_DEBUG_R1_LINK_UP (0x1 << 4) +#define PHY_DEBUG_R1_LINK_IN_TRAINING (0x1 << 29) + +#define PCIE_MISC_CONTROL_1 0x8bc +#define DBI_RO_WR_EN BIT(0) + +/* pcie reset */ +#define PCIEX8MGMT_PERST_N 0x0 + +/* LTSSM */ +#define PCIEX8MGMT_APP_LTSSM_ENABLE 0x10 +#define LTSSM_ENABLE_BIT BIT(0) + +/* phy reset */ +#define PCIEX8MGMT_APP_HOLD_PHY_RST 0x18 + +/* device type */ +#define PCIEX8MGMT_DEVICE_TYPE 0x708 +#define DEVICE_TYPE_EP 0x0 +#define DEVICE_TYPE_RC 0x4 + +/* phy control registers*/ +#define PCIEX8MGMT_PHY0_CR_PARA_ADDR 0x860 +#define PCIEX8MGMT_PHY0_CR_PARA_RD_EN 0x870 +#define PCIEX8MGMT_PHY0_CR_PARA_RD_DATA 0x878 +#define PCIEX8MGMT_PHY0_CR_PARA_SEL 0x880 +#define PCIEX8MGMT_PHY0_CR_PARA_WR_DATA 0x888 +#define PCIEX8MGMT_PHY0_CR_PARA_WR_EN 0x890 +#define PCIEX8MGMT_PHY0_CR_PARA_ACK 0x898 +#define PCIEX8MGMT_PHY1_CR_PARA_ADDR 0x8a0 +#define PCIEX8MGMT_PHY1_CR_PARA_RD_EN 0x8b0 +#define PCIEX8MGMT_PHY1_CR_PARA_RD_DATA 0x8b8 +#define PCIEX8MGMT_PHY1_CR_PARA_SEL 0x8c0 +#define PCIEX8MGMT_PHY1_CR_PARA_WR_DATA 0x8c8 +#define PCIEX8MGMT_PHY1_CR_PARA_WR_EN 0x8d0 +#define PCIEX8MGMT_PHY1_CR_PARA_ACK 0x8d8 + +#define PCIEX8MGMT_LANE_NUM 8 +#define PCIEX8MGMT_LANE 0x1008 +#define PCIEX8MGMT_LANE_OFF 0x100 +#define PCIEX8MGMT_TERM_MODE 0x0e21 + +#define PCIE_CAP_BASE 0x70 +#define PCI_CONFIG (r) (DBI_OFFSET + (r)) +#define PCIE_CAPABILITIES (r) PCI_CONFIG(PCIE_CAP_BASE + (r)) + +/* Link capability */ +#define PF0_PCIE_CAP_LINK_CAP PCIE_CAPABILITIES(0xc) +#define PCIE_LINK_CAP_MAX_SPEED_MASK 0xf +#define PCIE_LINK_CAP_MAX_SPEED_GEN1 BIT(0) +#define PCIE_LINK_CAP_MAX_SPEED_GEN2 BIT(1) +#define PCIE_LINK_CAP_MAX_SPEED_GEN3 BIT(2) +#define PCIE_LINK_CAP_MAX_SPEED_GEN4 BIT(3) + +static enum pcie_sifive_devtype pcie_sifive_get_devtype (struct pcie_sifive *sv) +{ +u32 val; + + val =readl (sv->priv_base +PCIEX8MGMT_DEVICE_TYPE ); +switch (val) { +case DEVICE_TYPE_RC : +return SV_PCIE_HOST_TYPE ; +case DEVICE_TYPE_EP : +return SV_PCIE_ENDPOINT_TYPE ; +default : +return SV_PCIE_UNKNOWN_TYPE ; + } +} + +static void pcie_sifive_priv_set_state (struct pcie_sifive *sv,u32 reg, +u32 bits,int state) +{ +u32 val; + + val =readl (sv->priv_base + reg); + val = state ? (val | bits) : (val & !bits); +writel (val, sv->priv_base + reg); +} + +static void pcie_sifive_assert_reset (struct pcie_sifive *sv) +{ +dm_gpio_set_value (&sv->reset_gpio,GPIO_LOW ); +writel (PCIE_PERST_ASSERT , sv->priv_base +PCIEX8MGMT_PERST_N ); +mdelay (ASSERTION_DELAY ); +} + +static void pcie_sifive_power_on (struct pcie_sifive *sv) +{ +dm_gpio_set_value (&sv->pwren_gpio,GPIO_HIGH ); +mdelay (ASSERTION_DELAY ); +} + +static void pcie_sifive_deassert_reset (struct pcie_sifive *sv) +{ +writel (PCIE_PERST_DEASSERT , sv->priv_base +PCIEX8MGMT_PERST_N ); +dm_gpio_set_value (&sv->reset_gpio,GPIO_HIGH ); +mdelay (ASSERTION_DELAY ); +} + +static int pcie_sifive_setphy (const u8 phy,const u8 write, +const u16 addr,const u16 wrdata, +u16 *rddata,struct pcie_sifive *sv) +{ +unsigned char ack =0 ; + +if (!(phy ==0 || phy ==1 )) +return -2 ; + +/* setup phy para */ +writel (addr, sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_ADDR : +PCIEX8MGMT_PHY0_CR_PARA_ADDR )); + +if (write) +writel (wrdata, sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_WR_DATA : +PCIEX8MGMT_PHY0_CR_PARA_WR_DATA )); + +/* enable access if write */ +if (write) +writel (1 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_WR_EN : +PCIEX8MGMT_PHY0_CR_PARA_WR_EN )); +else +writel (1 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_RD_EN : +PCIEX8MGMT_PHY0_CR_PARA_RD_EN )); + +/* wait for wait_idle */ +do { +u32 val; + + val =readl (sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_ACK : +PCIEX8MGMT_PHY0_CR_PARA_ACK )); +if (val) { + ack =1 ; +if (!write) +readl (sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_RD_DATA : +PCIEX8MGMT_PHY0_CR_PARA_RD_DATA )); +mdelay (1 ); + } + }while (!ack); + +/* clear */ +if (write) +writel (0 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_WR_EN : +PCIEX8MGMT_PHY0_CR_PARA_WR_EN )); +else +writel (0 , sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_RD_EN : +PCIEX8MGMT_PHY0_CR_PARA_RD_EN )); + +while (readl (sv->priv_base + + (phy ?PCIEX8MGMT_PHY1_CR_PARA_ACK : +PCIEX8MGMT_PHY0_CR_PARA_ACK ))) { +/* wait for ~wait_idle */ + } + +return 0 ; +} + +static void pcie_sifive_init_phy (struct pcie_sifive *sv) +{ +int lane; + +/* enable phy cr_para_sel interfaces */ +writel (PCIE_PHY_SEL , sv->priv_base +PCIEX8MGMT_PHY0_CR_PARA_SEL ); +writel (PCIE_PHY_SEL , sv->priv_base +PCIEX8MGMT_PHY1_CR_PARA_SEL ); +mdelay (1 ); + +/* set PHY AC termination mode */ +for (lane =0 ; lane <PCIEX8MGMT_LANE_NUM ; lane++) { +pcie_sifive_setphy (0 ,1 , +PCIEX8MGMT_LANE + + (PCIEX8MGMT_LANE_OFF * lane), +PCIEX8MGMT_TERM_MODE ,NULL , sv); +pcie_sifive_setphy (1 ,1 , +PCIEX8MGMT_LANE + + (PCIEX8MGMT_LANE_OFF * lane), +PCIEX8MGMT_TERM_MODE ,NULL , sv); + } +} + +static int pcie_sifive_check_link (struct pcie_sifive *sv) +{ +u32 val; + + val =readl (sv->dw.dbi_base +PHY_DEBUG_R1 ); +return (val &PHY_DEBUG_R1_LINK_UP ) && + !(val &PHY_DEBUG_R1_LINK_IN_TRAINING ); +} + +static void pcie_sifive_force_gen1 (struct pcie_sifive *sv) +{ +u32 val, linkcap; + +/* +* Force Gen1 operation when starting the link. In case the link is +* started in Gen2 mode, there is a possibility the devices on the +* bus will not be detected at all. This happens with PCIe switches. +*/ + +/* ctrl_ro_wr_enable */ + val =readl (sv->dw.dbi_base +PCIE_MISC_CONTROL_1 ); + val |=DBI_RO_WR_EN ; +writel (val, sv->dw.dbi_base +PCIE_MISC_CONTROL_1 ); + +/* configure link cap */ + linkcap =readl (sv->dw.dbi_base +PF0_PCIE_CAP_LINK_CAP ); + linkcap |=PCIE_LINK_CAP_MAX_SPEED_MASK ; +writel (linkcap, sv->dw.dbi_base +PF0_PCIE_CAP_LINK_CAP ); + +/* ctrl_ro_wr_disable */ + val &= ~DBI_RO_WR_EN ; +writel (val, sv->dw.dbi_base +PCIE_MISC_CONTROL_1 ); +} + +static void pcie_sifive_print_phy_debug (struct pcie_sifive *sv) +{ +sv_err (sv,"PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n" , +readl (sv->dw.dbi_base +PHY_DEBUG_R0 ), +readl (sv->dw.dbi_base +PHY_DEBUG_R1 )); +} + +static int pcie_sifive_wait_for_link (struct pcie_sifive *sv) +{ +u32 val; +int timeout; + +/* Wait for the link to train */ +mdelay (20 ); + timeout =20 ; + +do { +mdelay (1 ); + }while (--timeout && !pcie_sifive_check_link (sv)); + + val =readl (sv->dw.dbi_base +PHY_DEBUG_R1 ); +if (!(val &PHY_DEBUG_R1_LINK_UP ) || + (val &PHY_DEBUG_R1_LINK_IN_TRAINING )) { +sv_info (sv,"Failed to negotiate PCIe link!\n" ); +pcie_sifive_print_phy_debug (sv); +writel (PCIE_PHY_RESET , + sv->priv_base +PCIEX8MGMT_APP_HOLD_PHY_RST ); +return -ETIMEDOUT ; + } + +return 0 ; +} + +static int pcie_sifive_start_link (struct pcie_sifive *sv) +{ +if (pcie_sifive_check_link (sv)) +return -EALREADY ; + +pcie_sifive_force_gen1 (sv); + +/* set ltssm */ +pcie_sifive_priv_set_state (sv,PCIEX8MGMT_APP_LTSSM_ENABLE , +LTSSM_ENABLE_BIT ,1 ); +return 0 ; +} + +static int pcie_sifive_init_port (struct udevice *dev, +enum pcie_sifive_devtype mode) +{ +struct pcie_sifive *sv =dev_get_priv (dev); +int ret; + +/* Power on reset */ +pcie_sifive_assert_reset (sv); +pcie_sifive_power_on (sv); +pcie_sifive_deassert_reset (sv); + +/* Enable pcieauxclk */ + ret =clk_enable (&sv->aux_ck); +if (ret) +dev_err (dev,"unable to enable pcie_aux clock\n" ); + +/* +* assert hold_phy_rst (hold the controller LTSSM in reset +* after power_up_rst_n for register programming with cr_para) +*/ +writel (PCIE_PHY_RESET , sv->priv_base +PCIEX8MGMT_APP_HOLD_PHY_RST ); + +/* deassert power_up_rst_n */ + ret =reset_deassert (&sv->reset); +if (ret <0 ) { +dev_err (dev,"failed to deassert reset" ); +return -EINVAL ; + } + +pcie_sifive_init_phy (sv); + +/* disable pcieauxclk */ +clk_disable (&sv->aux_ck); + +/* deassert hold_phy_rst */ +writel (PCIE_PHY_RESET_DEASSERT , + sv->priv_base +PCIEX8MGMT_APP_HOLD_PHY_RST ); + +/* enable pcieauxclk */ +clk_enable (&sv->aux_ck); + +/* Set desired mode while core is not operational */ +if (mode ==SV_PCIE_HOST_TYPE ) +writel (DEVICE_TYPE_RC , + sv->priv_base +PCIEX8MGMT_DEVICE_TYPE ); +else +writel (DEVICE_TYPE_EP , + sv->priv_base +PCIEX8MGMT_DEVICE_TYPE ); + +/* Confirm desired mode from operational core */ +if (pcie_sifive_get_devtype (sv) != mode) +return -EINVAL ; + +pcie_dw_setup_host (&sv->dw); + +if (pcie_sifive_start_link (sv) == -EALREADY ) +sv_info (sv,"PCIe link is already up\n" ); +else if (pcie_sifive_wait_for_link (sv) == -ETIMEDOUT ) +return -ETIMEDOUT ; + +return 0 ; +} + +static int pcie_sifive_probe (struct udevice *dev) +{ +struct pcie_sifive *sv =dev_get_priv (dev); +struct udevice *parent =pci_get_controller (dev); +struct pci_controller *hose =dev_get_uclass_priv (parent); +int err; + + sv->dw.first_busno =dev_seq (dev); + sv->dw.dev = dev; + + err =pcie_sifive_init_port (dev,SV_PCIE_HOST_TYPE ); +if (err) { +sv_info (sv,"Failed to init port.\n" ); +return err; + } + +printf ("PCIE-%d: Link up (Gen%d-x%d, Bus%d)\n" , +dev_seq (dev),pcie_dw_get_link_speed (&sv->dw), +pcie_dw_get_link_width (&sv->dw), + hose->first_busno); + +return pcie_dw_prog_outbound_atu_unroll (&sv->dw, +PCIE_ATU_REGION_INDEX0 , +PCIE_ATU_TYPE_MEM , + sv->dw.mem.phys_start, + sv->dw.mem.bus_start, + sv->dw.mem.size); +} + +static void __iomem *get_fdt_addr (struct udevice *dev,const char *name) +{ +fdt_addr_t addr; + + addr =dev_read_addr_name (dev, name); + +return (addr ==FDT_ADDR_T_NONE ) ?NULL : (void __iomem *)addr; +} + +static int pcie_sifive_of_to_plat (struct udevice *dev) +{ +struct pcie_sifive *sv =dev_get_priv (dev); +int err; + +/* get designware DBI base addr */ + sv->dw.dbi_base =get_fdt_addr (dev,"dbi" ); +if (!sv->dw.dbi_base) +return -EINVAL ; + +/* get private control base addr */ + sv->priv_base =get_fdt_addr (dev,"mgmt" ); +if (!sv->priv_base) +return -EINVAL ; + +gpio_request_by_name (dev,"pwren-gpios" ,0 , &sv->pwren_gpio, +GPIOD_IS_OUT ); + +if (!dm_gpio_is_valid (&sv->pwren_gpio)) { +sv_info (sv,"pwren_gpio is invalid\n" ); +return -EINVAL ; + } + +gpio_request_by_name (dev,"reset-gpios" ,0 , &sv->reset_gpio, +GPIOD_IS_OUT ); + +if (!dm_gpio_is_valid (&sv->reset_gpio)) { +sv_info (sv,"reset_gpio is invalid\n" ); +return -EINVAL ; + } + + err =clk_get_by_index (dev,0 , &sv->aux_ck); +if (err) { +sv_info (sv,"clk_get_by_index(aux_ck) failed: %d\n" , err); +return err; + } + + err =reset_get_by_index (dev,0 , &sv->reset); +if (err) { +sv_info (sv,"reset_get_by_index(reset) failed: %d\n" , err); +return err; + } + +return 0 ; +} + +static const struct dm_pci_ops pcie_sifive_ops = { + .read_config = pcie_dw_read_config, + .write_config = pcie_dw_write_config,
Quoted 9 lines
drivers/pci/pcie_dw_sifive.c line 496
Quoted 5 lines
drivers/pci/pcie_dw_sifive.c new file +5
-0+}; + +static const struct udevice_id pcie_sifive_ids[] = { + { .compatible ="sifive,fu740-pcie" }, + { .compatible ="sifive,fu740-pcie-ecam" },Are you sure the controller in ECAM mode should use this driver ? The Linux bindings only declare "sifive,fu740-pcie"
You are right. I should remove it. Thanks.
- Green
Quoted 19 lines
drivers/pci/pcie_dw_sifive.c line 508
Quoted 13 lines
drivers/pci/pcie_dw_sifive.c new file +12
-0+ {} +}; + +U_BOOT_DRIVER (pcie_sifive) = { + .name ="pcie_sifive" , + .id =UCLASS_PCI , + .of_match = pcie_sifive_ids, + .ops = &pcie_sifive_ops, + .of_to_plat = pcie_sifive_of_to_plat, + .probe = pcie_sifive_probe, + .priv_auto =sizeof (struct pcie_sifive ), +};otherwise,
Reviewed-by Neil Armstrong <[email protected]>Neil
PATCH v7 5/8 riscv: dts: add fu740 support
In reply to Green WanAdd dts support for fu740. The HiFive Unmatched support is based on fu740 cpu and drivers in following patch set.
--- arch/riscv/dts/fu740-c000-u-boot.dtsi | 105 ++++++ arch/riscv/dts/fu740-c000.dtsi | 329 ++++++++++++++++++ include/dt-bindings/clock/sifive-fu740-prci.h | 25 ++ include/dt-bindings/reset/sifive-fu740-prci.h | 19 + 4 files changed, 478 insertions(+) create mode 100644 arch/riscv/dts/fu740-c000-u-boot.dtsi create mode 100644 arch/riscv/dts/fu740-c000.dtsi create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h create mode 100644 include/dt-bindings/reset/sifive-fu740-prci.h
arch/riscv/dts/fu740-c000-u-boot.dtsi new file +105 -0
@@ -0,0 +1,105 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * (C) Copyright 2020-2021 SiFive, Inc + */ + +#include <dt-bindings/reset/sifive-fu740-prci.h> + +/ { + cpus { + assigned-clocks = <&prci PRCI_CLK_COREPLL>; + assigned-clock-rates = <1200000000>; + u-boot,dm-spl; + cpu0: cpu at 0 { + clocks = <&prci PRCI_CLK_COREPLL>; + u-boot,dm-spl; + status = "okay"; + cpu0_intc: interrupt-controller { + u-boot,dm-spl; + }; + }; + cpu1: cpu at 1 { + clocks = <&prci PRCI_CLK_COREPLL>; + u-boot,dm-spl; + cpu1_intc: interrupt-controller { + u-boot,dm-spl; + }; + }; + cpu2: cpu at 2 { + clocks = <&prci PRCI_CLK_COREPLL>; + u-boot,dm-spl; + cpu2_intc: interrupt-controller { + u-boot,dm-spl; + }; + }; + cpu3: cpu at 3 { + clocks = <&prci PRCI_CLK_COREPLL>; + u-boot,dm-spl; + cpu3_intc: interrupt-controller { + u-boot,dm-spl; + }; + }; + cpu4: cpu at 4 { + clocks = <&prci PRCI_CLK_COREPLL>; + u-boot,dm-spl; + cpu4_intc: interrupt-controller { + u-boot,dm-spl; + }; + }; + }; + + soc { + u-boot,dm-spl; + clint: clint at 2000000 { + compatible = "riscv,clint0"; + interrupts-extended = <&cpu0_intc 3 &cpu0_intc 7 + &cpu1_intc 3 &cpu1_intc 7 + &cpu2_intc 3 &cpu2_intc 7 + &cpu3_intc 3 &cpu3_intc 7 + &cpu4_intc 3 &cpu4_intc 7>; + reg = <0x0 0x2000000 0x0 0x10000>; + u-boot,dm-spl; + }; + prci: clock-controller at 10000000 { + #reset-cells = <1>; + resets = <&prci PRCI_RST_DDR_CTRL_N>, + <&prci PRCI_RST_DDR_AXI_N>, + <&prci PRCI_RST_DDR_AHB_N>, + <&prci PRCI_RST_DDR_PHY_N>, + <&prci PRCI_RST_GEMGXL_N>, + <&prci PRCI_RST_CLTX_N>; + reset-names = "ddr_ctrl", "ddr_axi", "ddr_ahb", + "ddr_phy", "gemgxl_reset", "cltx_reset"; + }; + dmc: dmc at 100b0000 { + compatible = "sifive,fu740-c000-ddr"; + reg = <0x0 0x100b0000 0x0 0x0800 + 0x0 0x100b2000 0x0 0x2000 + 0x0 0x100b8000 0x0 0x1000>; + clocks = <&prci PRCI_CLK_DDRPLL>; + clock-frequency = <933333324>; + u-boot,dm-spl; + }; + }; +}; + +&prci { + u-boot,dm-spl; +}; + +&uart0 { + u-boot,dm-spl; +}; + +&spi0 { + u-boot,dm-spl; +}; + +ð0 { + assigned-clocks = <&prci PRCI_CLK_GEMGXLPLL>; + assigned-clock-rates = <125125000>; +}; + +&ccache { + status = "okay"; +};
arch/riscv/dts/fu740-c000.dtsi new file +329 -0
329 lines not on this page · raw message
include/dt-bindings/clock/sifive-fu740-prci.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* +* Copyright (C) 2020-2021 SiFive, Inc. +* Wesley Terpstra +* Paul Walmsley +* Zong Li +* Pragnesh Patel +*/ + +#ifndef __DT_BINDINGS_CLOCK_SIFIVE_FU740_PRCI_H +#define __DT_BINDINGS_CLOCK_SIFIVE_FU740_PRCI_H + +/* Clock indexes for use by Device Tree data and the PRCI driver */ + +#define PRCI_CLK_COREPLL 0 +#define PRCI_CLK_DDRPLL 1 +#define PRCI_CLK_GEMGXLPLL 2 +#define PRCI_CLK_DVFSCOREPLL 3 +#define PRCI_CLK_HFPCLKPLL 4 +#define PRCI_CLK_CLTXPLL 5 +#define PRCI_CLK_TLCLK 6 +#define PRCI_CLK_PCLK 7 +#define PRCI_CLK_PCIEAUX 8 + +#endif
include/dt-bindings/reset/sifive-fu740-prci.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* +* Copyright (C) 2020-2021 Sifive, Inc. +* Author: Pragnesh Patel <[email protected]> +*/ + +#ifndef __DT_BINDINGS_RESET_SIFIVE_FU740_PRCI_H +#define __DT_BINDINGS_RESET_SIFIVE_FU740_PRCI_H + +/* Reset indexes for use by device tree data and the PRCI driver */ +#define PRCI_RST_DDR_CTRL_N 0 +#define PRCI_RST_DDR_AXI_N 1 +#define PRCI_RST_DDR_AHB_N 2 +#define PRCI_RST_DDR_PHY_N 3 +#define PRCI_RST_PCIE_POWER_UP_N 4 +#define PRCI_RST_GEMGXL_N 5 +#define PRCI_RST_CLTX_N 6 + +#endif
Signature · 1 line
2.31.0
PATCH v7 6/8 riscv: dts: add SiFive Unmatched board support
In reply to Green WanAdd dts files for SiFive Unmatched board.
--- arch/riscv/dts/Makefile | 1 + .../dts/fu740-hifive-unmatched-a00-ddr.dtsi | 1489 +++++++++++++++++ .../dts/hifive-unmatched-a00-u-boot.dtsi | 40 + arch/riscv/dts/hifive-unmatched-a00.dts | 259 +++ 4 files changed, 1789 insertions(+) create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00.dts
arch/riscv/dts/Makefile +1 -0
@@ -2,6 +2,7 @@ dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb dtb-$(CONFIG_TARGET_SIFIVE_UNLEASHED) += hifive-unleashed-a00.dtb +dtb-$(CONFIG_TARGET_SIFIVE_UNMATCHED) += hifive-unmatched-a00.dtb dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
arch/riscv/dts/fu740-hifive-unmatched-a00-ddr.dtsi new file +1489 -0
1,489 lines not on this page · raw message
arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * Copyright (C) 2020-2021 SiFive, Inc + */ + +#include "fu740-c000-u-boot.dtsi" +#include "fu740-hifive-unmatched-a00-ddr.dtsi" + +/ { + aliases { + spi0 = &spi0; + }; + + memory at 80000000 { + u-boot,dm-spl; + }; + + hfclk { + u-boot,dm-spl; + }; + + rtcclk { + u-boot,dm-spl; + }; + +}; + +&clint { + clocks = <&rtcclk>; +}; + +&spi0 { + mmc at 0 { + u-boot,dm-spl; + }; +}; + +&gpio { + u-boot,dm-spl; +};
arch/riscv/dts/hifive-unmatched-a00.dts new file +259 -0
259 lines not on this page · raw message
Signature · 1 line
2.31.0
PATCH v7 7/8 board: sifive: add HiFive Unmatched board support
In reply to Green WanAdd defconfig and board support for HiFive Unmatched.
--- arch/riscv/Kconfig | 4 + board/sifive/unleashed/Kconfig | 1 + board/sifive/unmatched/Kconfig | 50 +++ board/sifive/unmatched/MAINTAINERS | 9 + board/sifive/unmatched/Makefile | 9 + board/sifive/unmatched/spl.c | 85 +++++ board/sifive/unmatched/unmatched.c | 24 ++ common/spl/Kconfig | 4 +- configs/sifive_unleashed_defconfig | 1 + configs/sifive_unmatched_defconfig | 54 +++ doc/board/sifive/index.rst | 1 + doc/board/sifive/unmatched.rst | 536 +++++++++++++++++++++++++++++ drivers/reset/Kconfig | 2 +- include/configs/sifive-unmatched.h | 85 +++++ 14 files changed, 862 insertions(+), 3 deletions(-) create mode 100644 board/sifive/unmatched/Kconfig create mode 100644 board/sifive/unmatched/MAINTAINERS create mode 100644 board/sifive/unmatched/Makefile create mode 100644 board/sifive/unmatched/spl.c create mode 100644 board/sifive/unmatched/unmatched.c create mode 100644 configs/sifive_unmatched_defconfig create mode 100644 doc/board/sifive/unmatched.rst create mode 100644 include/configs/sifive-unmatched.h
arch/riscv/Kconfig +4 -0
@@ -20,6 +20,9 @@ config TARGET_QEMU_VIRT config TARGET_SIFIVE_UNLEASHED bool "Support SiFive Unleashed Board" +config TARGET_SIFIVE_UNMATCHED + bool "Support SiFive Unmatched Board" + config TARGET_SIPEED_MAIX bool "Support Sipeed Maix Board"
@@ -56,6 +59,7 @@ source "board/AndesTech/ax25-ae350/Kconfig" source "board/emulation/qemu-riscv/Kconfig" source "board/microchip/mpfs_icicle/Kconfig" source "board/sifive/unleashed/Kconfig" +source "board/sifive/unmatched/Kconfig" source "board/sipeed/maix/Kconfig" # platform-specific options below
board/sifive/unleashed/Kconfig +1 -0
@@ -27,6 +27,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy def_bool y select SIFIVE_FU540 select ENV_IS_IN_SPI_FLASH + select RESET_SIFIVE imply CMD_DHCP imply CMD_EXT2 imply CMD_EXT4
board/sifive/unmatched/Kconfig new file +50 -0
50 lines not on this page · raw message
board/sifive/unmatched/MAINTAINERS new file +9 -0
@@ -0,0 +1,9 @@ +SiFive HiFive Unmatched FU740 BOARD +M: Paul Walmsley <[email protected]> +M: Pragnesh Patel <[email protected]> +M: Green Wan <[email protected]> +S: Maintained +F: board/sifive/unmatched/ +F: doc/board/sifive/hifive-unmatched-fu740.rst +F: include/configs/sifive-unmatched.h +F: configs/sifive_unmatched_defconfig
board/sifive/unmatched/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2020-2021 SiFive, Inc + +obj-y += unmatched.o + +ifdef CONFIG_SPL_BUILD +obj-y += spl.o +endif
board/sifive/unmatched/spl.c new file +85 -0
85 lines not on this page · raw message
board/sifive/unmatched/unmatched.c new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (c) 2020-2021, SiFive Inc +* +* Authors: +* Pragnesh Patel <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <asm/arch/cache.h> + +int board_init (void ) +{ +int ret; + +/* enable all cache ways */ + ret =cache_enable_ways (); +if (ret) { +debug ("%s: could not enable cache ways\n" , __func__); +return ret; + } +return 0 ; +}
common/spl/Kconfig +2 -2
@@ -331,7 +331,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR ARCH_ROCKCHIP || ARCH_MVEBU || ARCH_SOCFPGA || \ ARCH_AT91 || ARCH_ZYNQ || ARCH_KEYSTONE || OMAP34XX || \ OMAP44XX || OMAP54XX || AM33XX || AM43XX || \ - TARGET_SIFIVE_UNLEASHED + TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED help Use sector number for specifying U-Boot location on MMC/SD in raw mode.
@@ -348,7 +348,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR default 0x300 if ARCH_ZYNQ || ARCH_KEYSTONE || OMAP34XX || OMAP44XX || \ OMAP54XX || AM33XX || AM43XX || ARCH_K3 default 0x4000 if ARCH_ROCKCHIP - default 0x822 if TARGET_SIFIVE_UNLEASHED + default 0x822 if TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED help Address on the MMC to load U-Boot from, when the MMC is being used in raw mode. Units: MMC sectors (1 sector = 512 bytes).
configs/sifive_unleashed_defconfig +1 -0
@@ -27,3 +27,4 @@ CONFIG_SPL_DM_SEQ_ALIAS=y CONFIG_SPL_CLK=y CONFIG_DM_MTD=y CONFIG_DM_RESET=y +CONFIG_CLK_SIFIVE_PRCI=y
configs/sifive_unmatched_defconfig new file +54 -0
54 lines not on this page · raw message
doc/board/sifive/index.rst +1 -0
@@ -7,3 +7,4 @@ SiFive :maxdepth: 2 unleashed + unmatched
doc/board/sifive/unmatched.rst new file +536 -0
536 lines not on this page · raw message
drivers/reset/Kconfig +1 -1
@@ -166,7 +166,7 @@ config RESET_IPQ419 config RESET_SIFIVE bool "Reset Driver for SiFive SoC's" - depends on DM_RESET && CLK_SIFIVE_FU540_PRCI && TARGET_SIFIVE_UNLEASHED + depends on DM_RESET && CLK_SIFIVE_FU540_PRCI && (TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED) default y help PRCI module within SiFive SoC's provides mechanism to reset
include/configs/sifive-unmatched.h new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.31.0
PATCH v7 8/8 drivers: net: macb: add fu740 support
In reply to Green WanFrom: David Abdurachmanov <[email protected]>
Add fu740 support to macb ethernet driver
There is a PLL HW quirk in FU740. The VSC8541XMV-02 specification requires 125 +/-0.0125 Mhz. But the most close value can be output by PLL is 125.125 MHz and out of VSC8541XMV-02 spec.
--- drivers/net/macb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/macb.c +12 -1
@@ -591,8 +591,17 @@ static int macb_sifive_clk_init(struct udevice *dev, ulong rate)* 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic * and output clock on GMII output signal GTX_CLK * 1 = MII mode. Use MII input signal TX_CLK in TX logic +* +* FU740 have a PLL HW quirk. The 125.125 Mhz is actually out of +* VSC8541XMV-02 specification. The tolerance level is +/-100ppm. +* Which means the range should be in between 125MHz +/-0.0125. +* But the most close value can be output by PLL is 125.125 MHz. */ -writel (rate !=125000000 , gemgxl_regs); +if (device_is_compatible (dev,"sifive,fu540-c000-gem" )) +writel (rate !=125000000 , gemgxl_regs); +else if (device_is_compatible (dev,"sifive,fu740-c000-gem" )) +writel (rate !=125125000 , gemgxl_regs); +return 0 ; }
@@ -1507,6 +1516,8 @@ static const struct udevice_id macb_eth_ids[] = { { .compatible = "cdns,zynq-gem" }, { .compatible = "sifive,fu540-c000-gem", .data = (ulong)&sifive_config }, + { .compatible = "sifive,fu740-c000-gem", + .data = (ulong)&sifive_config }, { .compatible = "microchip,mpfs-mss-gem", .data = (ulong)µchip_config }, { }
Signature · 1 line
2.31.0
A message that is not in the archive (sent off-list or not yet received): CADWks+arqeOw7AuuVv_2V4buyvXmk_99hjvHU=LZ7Fki4NC4Fw@mail.gmail.com
PATCH v7 8/8 drivers: net: macb: add fu740 support
(resending to list after subscribing)
Hi,
Quoted 9 lines · Green Wan
From: David Abdurachmanov <[email protected]>
Add fu740 support to macb ethernet driver
There is a PLL HW quirk in FU740. The VSC8541XMV-02 specification requires 125 +/-0.0125 Mhz. But the most close value can be output by PLL is 125.125 MHz and out of VSC8541XMV-02 spec.
In the Linux kernel driver for this drivers/net/ethernet/cadence/macb_main.c it is not marked as compatible with "sifive,fu740-c000-gem" and it does not have a similar fix (and appears to use 125.0 MHz).
Should a similar fix be contributed to the Linux kernel?
As otherwise at the moment, one cannot pass the dtb from u-boot to linux, as that leads to loss of network since the kernel doesn't know about "sifive,fu740-c000-gem". If linux kernel contribution is not forthcoming, would it be possible to have u-boot dtb to be compatible with _both_ "sifive,fu540-c000-gem" and "sifive,fu740-c000-gem" on unmatched boards, such that if one (mistakenly) uses u-boots dtb with vanilla linux kernel networking still works? And then adjust the test to check for "sifive,fu740-c000-gem" compatible string first.
Quoted 41 lines
Signed-off-by David Abdurachmanov <[email protected]>Signed-off-by Green Wan <[email protected]>Reviewed-by Ramon Fried <[email protected]>Reviewed-by Bin Meng <[email protected]>--- drivers/net/macb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/net/macb.c +12
-2@@ -591,8 +591,17 @@ static int macb_sifive_clk_init(struct udevice *dev, ulong rate)* 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic * and output clock on GMII output signal GTX_CLK * 1 = MII mode. Use MII input signal TX_CLK in TX logic +* +* FU740 have a PLL HW quirk. The 125.125 Mhz is actually out of +* VSC8541XMV-02 specification. The tolerance level is +/-100ppm. +* Which means the range should be in between 125MHz +/-0.0125. +* But the most close value can be output by PLL is 125.125 MHz. */ -writel (rate !=125000000 , gemgxl_regs); +if (device_is_compatible (dev,"sifive,fu540-c000-gem" )) +writel (rate !=125000000 , gemgxl_regs); +else if (device_is_compatible (dev,"sifive,fu740-c000-gem" )) +writel (rate !=125125000 , gemgxl_regs); +return 0 ; }@@ -1507,6 +1516,8 @@ static const struct udevice_id macb_eth_ids[] = { { .compatible = "cdns,zynq-gem" }, { .compatible = "sifive,fu540-c000-gem", .data = (ulong)&sifive_config }, + { .compatible = "sifive,fu740-c000-gem", + .data = (ulong)&sifive_config }, { .compatible = "microchip,mpfs-mss-gem", .data = (ulong)µchip_config }, { } --
Quoted 2 lines
2.31.0
--
Regards,
Dimitri.
Signature · 3 lines
Regards, Dimitri.
PATCH v7 8/8 drivers: net: macb: add fu740 support
In reply to a message not in the archiveHi Dimitri,
Thanks for looking into this.
Quoted 14 lines · Dimitri John Ledkov
Hi,
Quoted 9 lines · Green Wan
From: David Abdurachmanov <[email protected]>
Add fu740 support to macb ethernet driver
There is a PLL HW quirk in FU740. The VSC8541XMV-02 specification requires 125 +/-0.0125 Mhz. But the most close value can be output by PLL is 125.125 MHz and out of VSC8541XMV-02 spec.
Quoted 5 lines
In the Linux kernel driver for this
drivers/net/ethernet/cadence/macb_main.cit is not marked as compatible with "sifive,fu740-c000-gem" and it does not have a similar fix (and appears to use 125.0 MHz).
Should a similar fix be contributed to the Linux kernel?
You're right. We also notice some refinement should be made here. We're working on the way to solve it.
Quoted 10 lines
As otherwise at the moment, one cannot pass the dtb from u-boot to linux, as that leads to loss of network since the kernel doesn't know about "sifive,fu740-c000-gem". If linux kernel contribution is not forthcoming, would it be possible to have u-boot dtb to be compatible with _both_ "sifive,fu540-c000-gem" and "sifive,fu740-c000-gem" on unmatched boards, such that if one (mistakenly) uses u-boots dtb with vanilla linux kernel networking still works? And then adjust the test to check for "sifive,fu740-c000-gem" compatible string first.
Not sure whether I get it correct. I think the best case is to have Linux driver support both compatible string. And I'm a bit reluctant to handle incorrect DTB passed situations. It might end up with propagating issues and harder to trace back the root cause. I'll check with colleagues and see if we can resolve that concern.
Thanks,
Quoted 49 lines
Quoted 41 lines
Signed-off-by David Abdurachmanov <[email protected]>Signed-off-by Green Wan <[email protected]>Reviewed-by Ramon Fried <[email protected]>Reviewed-by Bin Meng <[email protected]>--- drivers/net/macb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/net/macb.c +12
-2@@ -591,8 +591,17 @@ static int macb_sifive_clk_init(struct udevice *dev, ulong rate)* 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic * and output clock on GMII output signal GTX_CLK * 1 = MII mode. Use MII input signal TX_CLK in TX logic +* +* FU740 have a PLL HW quirk. The 125.125 Mhz is actually out of +* VSC8541XMV-02 specification. The tolerance level is +/-100ppm. +* Which means the range should be in between 125MHz +/-0.0125. +* But the most close value can be output by PLL is 125.125 MHz. */ -writel (rate !=125000000 , gemgxl_regs); +if (device_is_compatible (dev,"sifive,fu540-c000-gem" )) +writel (rate !=125000000 , gemgxl_regs); +else if (device_is_compatible (dev,"sifive,fu740-c000-gem" )) +writel (rate !=125125000 , gemgxl_regs); +return 0 ; }@@ -1507,6 +1516,8 @@ static const struct udevice_id macb_eth_ids[] = { { .compatible = "cdns,zynq-gem" }, { .compatible = "sifive,fu540-c000-gem", .data = (ulong)&sifive_config }, + { .compatible = "sifive,fu740-c000-gem", + .data = (ulong)&sifive_config }, { .compatible = "microchip,mpfs-mss-gem", .data = (ulong)µchip_config }, { } --Quoted 2 lines
2.31.0
--
Regards,Dimitri.
PATCH v7 8/8 drivers: net: macb: add fu740 support
Quoted 41 lines · Green Wan
Hi Dimitri,
Thanks for looking into this.
Quoted 14 lines · Dimitri John Ledkov
Hi,
Quoted 9 lines · Green Wan
From: David Abdurachmanov <[email protected]>
Add fu740 support to macb ethernet driver
There is a PLL HW quirk in FU740. The VSC8541XMV-02 specification requires 125 +/-0.0125 Mhz. But the most close value can be output by PLL is 125.125 MHz and out of VSC8541XMV-02 spec.
Quoted 5 lines
In the Linux kernel driver for this
drivers/net/ethernet/cadence/macb_main.cit is not marked as compatible with "sifive,fu740-c000-gem" and it does not have a similar fix (and appears to use 125.0 MHz).
Should a similar fix be contributed to the Linux kernel?You're right. We also notice some refinement should be made here. We're working on the way to solve it.
Quoted 10 lines
As otherwise at the moment, one cannot pass the dtb from u-boot to linux, as that leads to loss of network since the kernel doesn't know about "sifive,fu740-c000-gem". If linux kernel contribution is not forthcoming, would it be possible to have u-boot dtb to be compatible with _both_ "sifive,fu540-c000-gem" and "sifive,fu740-c000-gem" on unmatched boards, such that if one (mistakenly) uses u-boots dtb with vanilla linux kernel networking still works? And then adjust the test to check for "sifive,fu740-c000-gem" compatible string first.
Quoted 2 lines
Not sure whether I get it correct. I think the best case is to have Linux driver support both compatible string.
That is my desired outcome too. Please just do that.
Quoted 5 lines
And I'm a bit reluctant
to handle incorrect DTB passed situations. It might end up with propagating issues and harder to trace back the root cause. I'll check with colleagues and see if we can resolve that concern.
Writing / handling / handing-over incorrect DTB is not nice.
Quoted 51 lines
Thanks,
Quoted 49 lines
Quoted 41 lines
Signed-off-by David Abdurachmanov <[email protected]>Signed-off-by Green Wan <[email protected]>Reviewed-by Ramon Fried <[email protected]>Reviewed-by Bin Meng <[email protected]>--- drivers/net/macb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/net/macb.c +12
-2@@ -591,8 +591,17 @@ static int macb_sifive_clk_init(struct udevice *dev, ulong rate)* 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic * and output clock on GMII output signal GTX_CLK * 1 = MII mode. Use MII input signal TX_CLK in TX logic +* +* FU740 have a PLL HW quirk. The 125.125 Mhz is actually out of +* VSC8541XMV-02 specification. The tolerance level is +/-100ppm. +* Which means the range should be in between 125MHz +/-0.0125. +* But the most close value can be output by PLL is 125.125 MHz. */ -writel (rate !=125000000 , gemgxl_regs); +if (device_is_compatible (dev,"sifive,fu540-c000-gem" )) +writel (rate !=125000000 , gemgxl_regs); +else if (device_is_compatible (dev,"sifive,fu740-c000-gem" )) +writel (rate !=125125000 , gemgxl_regs); +return 0 ; }@@ -1507,6 +1516,8 @@ static const struct udevice_id macb_eth_ids[] = { { .compatible = "cdns,zynq-gem" }, { .compatible = "sifive,fu540-c000-gem", .data = (ulong)&sifive_config }, + { .compatible = "sifive,fu740-c000-gem", + .data = (ulong)&sifive_config }, { .compatible = "microchip,mpfs-mss-gem", .data = (ulong)µchip_config }, { } --Quoted 2 lines
2.31.0
--
Regards,Dimitri.
Signature · 3 lines
Regards, Dimitri.
Re: [PATCH v7 8/8] drivers: net: macb: add fu740 support
In reply to Green WanHi,
Quoted 9 lines · Green Wan
From: David Abdurachmanov <[email protected]>
Add fu740 support to macb ethernet driver
There is a PLL HW quirk in FU740. The VSC8541XMV-02 specification requires 125 +/-0.0125 Mhz. But the most close value can be output by PLL is 125.125 MHz and out of VSC8541XMV-02 spec.
Quoted 8 lines
Signed-off-by David Abdurachmanov <[email protected]>Signed-off-by Green Wan <[email protected]>Reviewed-by Ramon Fried <[email protected]>Reviewed-by Bin Meng <[email protected]>--- drivers/net/macb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
It looks this patch was never applied. Both U-Boot and Linux drivers do not have the "sifive,fu740-c000-gem" codes.
Not sure what the current upstream status of this?
Regards,
Bin
Palmer Dabbelt
maintainerv7 cover Add FU740 chip and HiFive Unmatched board support
In reply to Green WanQuoted 11 lines · green.wan at sifive.com
This patch set is to add SiFive fu740 chip and HiFive Unmatched board support. Patches are split into several parts:
- [PATCH v7 1/8] support for fu740 cpu
- [PATCH v7 2/8] support for fu740 clk driver
- [PATCH v7 3/8] rename and support for fu740 ram driver
- [PATCH v7 4/8] add pcie driver
- [PATCH v7 5/8] dts for SiFive fu740
- [PATCH v7 6/8] dts for SiFive Unmatched board
- [PATCH v7 7/8] add Unmatched board support
- [PATCH v7 8/8] add fu740 support to macb driver
I've got a bunch of versions of this in my inbox, but I always have an arbitrary subset of the patches. This generally LGTM, but it's kind of hard to figure out what goes where when patch sets are split between trees like this.
IMO the drivers don't need to be in my tree for the DTS files to get merged, we just need the bindings to be agreed upon. Can you send a version of this with just the patches that haven't otherwise been merged and are relevant for the RISC-V tree?
Quoted 154 lines
Description
- For fu740 cpu support, reuse most of fu540 cpu.
- For prci driver, add one abstract layer to separate fu540 and fu740. Move orignal fu540 code to separate files.
- For pcie driver, it depends on gpio, prci, clk and reset drivers to do init&reset works. Also based onpcie_dw_common.c
- Align with Linux DT file.Tests and patch checks
- Able to boot both unmatched and unleashed boards.
- PCIe tests
. M.2 NVMe SSD
. e1000 compatibale ethernet adapter (ping&tftpboot) . pci-to-usb adapter(usb mass storage)
- checkpatch is performed. To keep code derived from other boards the same, ignore some warnings/errors in [PATCH 7/8].Changlogs
- V7
. Rebase to latest master branch
. Moved dts for fu740 patch [v6 1/7] to [v7 5/8] and seperate dts of
Unmatched board from [v6 6/7] into [v7 6/8]
. Applied PCIe refactoring patch to base on the common code in
pcie_dw_common.c
- V6
. Remove redundant DT string for 1.2GHz CPU clock and squash to
[1/7]
- V5
. Fix unleashed build error in patch [6/8]
. Append one more set for 1.2GHz CPU speed
. Add "#include <asm/global_data.h>" back tosifive_ddr.c. Add Reviewed-by to [4/8] and [7/8]
- V4
. fixed incorrect file name in ./board/sifive/unmatched/Makefile . fixed link indoc/board/sifive/index.rst, passed 'make htmldocs'
- V3
. Rebase to unleashed rename v2 patch
. Rename
doc/board/sifive/unmatched.rstboard/sifive/unmatched/unmatched.c
. Fix tail whitespace
. Add 'git mv' info to ram driver and merge patch back to one . Add comment to macb driver for PLL hardware quirk
. Add reviewed-by to patch [6/7]
. Add 'gpio-poweroff' node for upcoming opensbi integration
- V2
. Rebase to unleashed rename patch
. remove unnessaary fu540 changes
. split ram driver patch into 2 to keep 'git mv' info
. use a shorter name for unmatched support
. Remove redundant&incorrect temperature-sensor in DT
. Remove unnecessary USB EHCI & OHCI from defconfig
. Revised fu740 doc
. Fixed year of copyright
. Add reviewed-by received in v1 patchDavid Abdurachmanov (1):
drivers: net: macb: add fu740 supportGreen Wan (7):
riscv: cpu: fu740: Add support for cpu fu740
drivers: clk: add fu740 support
drivers: ram: sifive: renamefu540_ddrand add fu740 support
drivers: pci: add pcie support for fu740
riscv: dts: add fu740 support
riscv: dts: add SiFive Unmatched board support
board: sifive: add HiFive Unmatched board supportarch/riscv/Kconfig | 5 + arch/riscv/cpu/fu740/Kconfig | 37 + arch/riscv/cpu/fu740/Makefile | 12 + arch/riscv/cpu/fu740/cache.c | 55 + arch/riscv/cpu/fu740/cpu.c | 22 + arch/riscv/cpu/fu740/dram.c | 38 + arch/riscv/cpu/fu740/spl.c | 23 + arch/riscv/dts/Makefile | 1 + arch/riscv/dts/fu740-c000-u-boot.dtsi | 105 ++ arch/riscv/dts/fu740-c000.dtsi | 329 ++++ .../dts/fu740-hifive-unmatched-a00-ddr.dtsi | 1489 +++++++++++++++++ .../dts/hifive-unmatched-a00-u-boot.dtsi | 40 + arch/riscv/dts/hifive-unmatched-a00.dts | 259 +++ arch/riscv/include/asm/arch-fu740/cache.h | 14 + arch/riscv/include/asm/arch-fu740/clk.h | 14 + arch/riscv/include/asm/arch-fu740/gpio.h | 38 + arch/riscv/include/asm/arch-fu740/reset.h | 13 + arch/riscv/include/asm/arch-fu740/spl.h | 14 + arch/riscv/lib/sifive_clint.c | 1 - board/sifive/unleashed/Kconfig | 1 + board/sifive/unmatched/Kconfig | 50 + board/sifive/unmatched/MAINTAINERS | 9 + board/sifive/unmatched/Makefile | 9 + board/sifive/unmatched/spl.c | 85 + board/sifive/unmatched/unmatched.c | 24 + common/spl/Kconfig | 4 +- configs/sifive_unleashed_defconfig | 1 + configs/sifive_unmatched_defconfig | 54 + doc/board/sifive/index.rst | 1 + doc/board/sifive/unmatched.rst | 536 ++++++ drivers/clk/sifive/Kconfig | 8 +- drivers/clk/sifive/Makefile | 4 +- drivers/clk/sifive/fu540-prci.c | 769 +-------- drivers/clk/sifive/fu540-prci.h | 22 + drivers/clk/sifive/fu740-prci.c | 158 ++ drivers/clk/sifive/fu740-prci.h | 22 + drivers/clk/sifive/sifive-prci.c | 733 ++++++++ drivers/clk/sifive/sifive-prci.h | 323 ++++ drivers/net/macb.c | 13 +- drivers/pci/Kconfig | 10 + drivers/pci/Makefile | 1 + drivers/pci/pcie_dw_sifive.c | 508 ++++++ drivers/ram/sifive/Kconfig | 8 +- drivers/ram/sifive/Makefile | 2 +- .../ram/sifive/{fu540_ddr.c => sifive_ddr.c} | 89 +- drivers/reset/Kconfig | 2 +- include/configs/sifive-unmatched.h | 85 + include/dt-bindings/clock/sifive-fu740-prci.h | 25 + include/dt-bindings/reset/sifive-fu740-prci.h | 19 + 49 files changed, 5277 insertions(+), 807 deletions(-) create mode 100644 arch/riscv/cpu/fu740/Kconfig create mode 100644 arch/riscv/cpu/fu740/Makefile create mode 100644 arch/riscv/cpu/fu740/cache.c create mode 100644 arch/riscv/cpu/fu740/cpu.c create mode 100644 arch/riscv/cpu/fu740/dram.c create mode 100644 arch/riscv/cpu/fu740/spl.c create mode 100644 arch/riscv/dts/fu740-c000-u-boot.dtsi create mode 100644 arch/riscv/dts/fu740-c000.dtsi create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00.dts create mode 100644 arch/riscv/include/asm/arch-fu740/cache.h create mode 100644 arch/riscv/include/asm/arch-fu740/clk.h create mode 100644 arch/riscv/include/asm/arch-fu740/gpio.h create mode 100644 arch/riscv/include/asm/arch-fu740/reset.h create mode 100644 arch/riscv/include/asm/arch-fu740/spl.h create mode 100644 board/sifive/unmatched/Kconfig create mode 100644 board/sifive/unmatched/MAINTAINERS create mode 100644 board/sifive/unmatched/Makefile create mode 100644 board/sifive/unmatched/spl.c create mode 100644 board/sifive/unmatched/unmatched.c create mode 100644 configs/sifive_unmatched_defconfig create mode 100644 doc/board/sifive/unmatched.rst create mode 100644 drivers/clk/sifive/fu540-prci.h create mode 100644 drivers/clk/sifive/fu740-prci.c create mode 100644 drivers/clk/sifive/fu740-prci.h create mode 100644 drivers/clk/sifive/sifive-prci.c create mode 100644 drivers/clk/sifive/sifive-prci.h create mode 100644 drivers/pci/pcie_dw_sifive.c rename drivers/ram/sifive/{fu540_ddr.c => sifive_ddr.c} (81%) create mode 100644 include/configs/sifive-unmatched.h create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h create mode 100644 include/dt-bindings/reset/sifive-fu740-prci.h
Palmer Dabbelt
maintainerv7 cover Add FU740 chip and HiFive Unmatched board support
Quoted 18 lines · Palmer Dabbelt
Quoted 11 lines · green.wan at sifive.com
This patch set is to add SiFive fu740 chip and HiFive Unmatched board support. Patches are split into several parts:
- [PATCH v7 1/8] support for fu740 cpu
- [PATCH v7 2/8] support for fu740 clk driver
- [PATCH v7 3/8] rename and support for fu740 ram driver
- [PATCH v7 4/8] add pcie driver
- [PATCH v7 5/8] dts for SiFive fu740
- [PATCH v7 6/8] dts for SiFive Unmatched board
- [PATCH v7 7/8] add Unmatched board support
- [PATCH v7 8/8] add fu740 support to macb driverI've got a bunch of versions of this in my inbox, but I always have an arbitrary subset of the patches. This generally LGTM, but it's kind of hard to figure out what goes where when patch sets are split between trees like this.
Quoted 4 lines
IMO the drivers don't need to be in my tree for the DTS files to get merged, we just need the bindings to be agreed upon. Can you send a version of this with just the patches that haven't otherwise been merged and are relevant for the RISC-V tree?
Ah, sorry, I'm lost here -- I thought this was a Linux patch set. That probably explains why I can't follow the thread... ;)
Quoted 155 lines
Quoted 155 lines
Description
- For fu740 cpu support, reuse most of fu540 cpu.
- For prci driver, add one abstract layer to separate fu540 and fu740. Move orignal fu540 code to separate files.
- For pcie driver, it depends on gpio, prci, clk and reset drivers to do init&reset works. Also based onpcie_dw_common.c
- Align with Linux DT file.Tests and patch checks
- Able to boot both unmatched and unleashed boards.
- PCIe tests
. M.2 NVMe SSD
. e1000 compatibale ethernet adapter (ping&tftpboot) . pci-to-usb adapter(usb mass storage)
- checkpatch is performed. To keep code derived from other boards the same, ignore some warnings/errors in [PATCH 7/8].Changlogs
- V7
. Rebase to latest master branch
. Moved dts for fu740 patch [v6 1/7] to [v7 5/8] and seperate dts of
Unmatched board from [v6 6/7] into [v7 6/8]
. Applied PCIe refactoring patch to base on the common code in
pcie_dw_common.c
- V6
. Remove redundant DT string for 1.2GHz CPU clock and squash to
[1/7]
- V5
. Fix unleashed build error in patch [6/8]
. Append one more set for 1.2GHz CPU speed
. Add "#include <asm/global_data.h>" back tosifive_ddr.c. Add Reviewed-by to [4/8] and [7/8]
- V4
. fixed incorrect file name in ./board/sifive/unmatched/Makefile . fixed link indoc/board/sifive/index.rst, passed 'make htmldocs'
- V3
. Rebase to unleashed rename v2 patch
. Rename
doc/board/sifive/unmatched.rstboard/sifive/unmatched/unmatched.c
. Fix tail whitespace
. Add 'git mv' info to ram driver and merge patch back to one . Add comment to macb driver for PLL hardware quirk
. Add reviewed-by to patch [6/7]
. Add 'gpio-poweroff' node for upcoming opensbi integration
- V2
. Rebase to unleashed rename patch
. remove unnessaary fu540 changes
. split ram driver patch into 2 to keep 'git mv' info
. use a shorter name for unmatched support
. Remove redundant&incorrect temperature-sensor in DT
. Remove unnecessary USB EHCI & OHCI from defconfig
. Revised fu740 doc
. Fixed year of copyright
. Add reviewed-by received in v1 patchDavid Abdurachmanov (1):
drivers: net: macb: add fu740 supportGreen Wan (7):
riscv: cpu: fu740: Add support for cpu fu740
drivers: clk: add fu740 support
drivers: ram: sifive: renamefu540_ddrand add fu740 support
drivers: pci: add pcie support for fu740
riscv: dts: add fu740 support
riscv: dts: add SiFive Unmatched board support
board: sifive: add HiFive Unmatched board supportarch/riscv/Kconfig | 5 + arch/riscv/cpu/fu740/Kconfig | 37 + arch/riscv/cpu/fu740/Makefile | 12 + arch/riscv/cpu/fu740/cache.c | 55 + arch/riscv/cpu/fu740/cpu.c | 22 + arch/riscv/cpu/fu740/dram.c | 38 + arch/riscv/cpu/fu740/spl.c | 23 + arch/riscv/dts/Makefile | 1 + arch/riscv/dts/fu740-c000-u-boot.dtsi | 105 ++ arch/riscv/dts/fu740-c000.dtsi | 329 ++++ .../dts/fu740-hifive-unmatched-a00-ddr.dtsi | 1489 +++++++++++++++++ .../dts/hifive-unmatched-a00-u-boot.dtsi | 40 + arch/riscv/dts/hifive-unmatched-a00.dts | 259 +++ arch/riscv/include/asm/arch-fu740/cache.h | 14 + arch/riscv/include/asm/arch-fu740/clk.h | 14 + arch/riscv/include/asm/arch-fu740/gpio.h | 38 + arch/riscv/include/asm/arch-fu740/reset.h | 13 + arch/riscv/include/asm/arch-fu740/spl.h | 14 + arch/riscv/lib/sifive_clint.c | 1 - board/sifive/unleashed/Kconfig | 1 + board/sifive/unmatched/Kconfig | 50 + board/sifive/unmatched/MAINTAINERS | 9 + board/sifive/unmatched/Makefile | 9 + board/sifive/unmatched/spl.c | 85 + board/sifive/unmatched/unmatched.c | 24 + common/spl/Kconfig | 4 +- configs/sifive_unleashed_defconfig | 1 + configs/sifive_unmatched_defconfig | 54 + doc/board/sifive/index.rst | 1 + doc/board/sifive/unmatched.rst | 536 ++++++ drivers/clk/sifive/Kconfig | 8 +- drivers/clk/sifive/Makefile | 4 +- drivers/clk/sifive/fu540-prci.c | 769 +-------- drivers/clk/sifive/fu540-prci.h | 22 + drivers/clk/sifive/fu740-prci.c | 158 ++ drivers/clk/sifive/fu740-prci.h | 22 + drivers/clk/sifive/sifive-prci.c | 733 ++++++++ drivers/clk/sifive/sifive-prci.h | 323 ++++ drivers/net/macb.c | 13 +- drivers/pci/Kconfig | 10 + drivers/pci/Makefile | 1 + drivers/pci/pcie_dw_sifive.c | 508 ++++++ drivers/ram/sifive/Kconfig | 8 +- drivers/ram/sifive/Makefile | 2 +- .../ram/sifive/{fu540_ddr.c => sifive_ddr.c} | 89 +- drivers/reset/Kconfig | 2 +- include/configs/sifive-unmatched.h | 85 + include/dt-bindings/clock/sifive-fu740-prci.h | 25 + include/dt-bindings/reset/sifive-fu740-prci.h | 19 + 49 files changed, 5277 insertions(+), 807 deletions(-) create mode 100644 arch/riscv/cpu/fu740/Kconfig create mode 100644 arch/riscv/cpu/fu740/Makefile create mode 100644 arch/riscv/cpu/fu740/cache.c create mode 100644 arch/riscv/cpu/fu740/cpu.c create mode 100644 arch/riscv/cpu/fu740/dram.c create mode 100644 arch/riscv/cpu/fu740/spl.c create mode 100644 arch/riscv/dts/fu740-c000-u-boot.dtsi create mode 100644 arch/riscv/dts/fu740-c000.dtsi create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00.dts create mode 100644 arch/riscv/include/asm/arch-fu740/cache.h create mode 100644 arch/riscv/include/asm/arch-fu740/clk.h create mode 100644 arch/riscv/include/asm/arch-fu740/gpio.h create mode 100644 arch/riscv/include/asm/arch-fu740/reset.h create mode 100644 arch/riscv/include/asm/arch-fu740/spl.h create mode 100644 board/sifive/unmatched/Kconfig create mode 100644 board/sifive/unmatched/MAINTAINERS create mode 100644 board/sifive/unmatched/Makefile create mode 100644 board/sifive/unmatched/spl.c create mode 100644 board/sifive/unmatched/unmatched.c create mode 100644 configs/sifive_unmatched_defconfig create mode 100644 doc/board/sifive/unmatched.rst create mode 100644 drivers/clk/sifive/fu540-prci.h create mode 100644 drivers/clk/sifive/fu740-prci.c create mode 100644 drivers/clk/sifive/fu740-prci.h create mode 100644 drivers/clk/sifive/sifive-prci.c create mode 100644 drivers/clk/sifive/sifive-prci.h create mode 100644 drivers/pci/pcie_dw_sifive.c rename drivers/ram/sifive/{fu540_ddr.c => sifive_ddr.c} (81%) create mode 100644 include/configs/sifive-unmatched.h create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h create mode 100644 include/dt-bindings/reset/sifive-fu740-prci.h
v7 cover Add FU740 chip and HiFive Unmatched board support
In reply to Green WanHi Bin,
How should this patch set be proceeded?
To summary the major changes,
- I've rebased to mainstream and merged pcie refactoring code which based on pcie_dw_common.c
- separate unmatched dts into separated patch.
Thanks,
- Green
Quoted 170 lines · Green Wan
This patch set is to add SiFive fu740 chip and HiFive Unmatched board support. Patches are split into several parts:
- [PATCH v7 1/8] support for fu740 cpu
- [PATCH v7 2/8] support for fu740 clk driver
- [PATCH v7 3/8] rename and support for fu740 ram driver
- [PATCH v7 4/8] add pcie driver
- [PATCH v7 5/8] dts for SiFive fu740
- [PATCH v7 6/8] dts for SiFive Unmatched board
- [PATCH v7 7/8] add Unmatched board support
- [PATCH v7 8/8] add fu740 support to macb driverDescription
- For fu740 cpu support, reuse most of fu540 cpu.
- For prci driver, add one abstract layer to separate fu540 and fu740. Move orignal fu540 code to separate files.
- For pcie driver, it depends on gpio, prci, clk and reset drivers to do init&reset works. Also based onpcie_dw_common.c
- Align with Linux DT file.Tests and patch checks
- Able to boot both unmatched and unleashed boards.
- PCIe tests
. M.2 NVMe SSD
. e1000 compatibale ethernet adapter (ping&tftpboot) . pci-to-usb adapter(usb mass storage)
- checkpatch is performed. To keep code derived from other boards the same, ignore some warnings/errors in [PATCH 7/8].Changlogs
- V7
. Rebase to latest master branch
. Moved dts for fu740 patch [v6 1/7] to [v7 5/8] and seperate dts of
Unmatched board from [v6 6/7] into [v7 6/8]
. Applied PCIe refactoring patch to base on the common code in
pcie_dw_common.c
- V6
. Remove redundant DT string for 1.2GHz CPU clock and squash to
[1/7]
- V5
. Fix unleashed build error in patch [6/8]
. Append one more set for 1.2GHz CPU speed
. Add "#include <asm/global_data.h>" back tosifive_ddr.c. Add Reviewed-by to [4/8] and [7/8]
- V4
. fixed incorrect file name in ./board/sifive/unmatched/Makefile . fixed link indoc/board/sifive/index.rst, passed 'make htmldocs'
- V3
. Rebase to unleashed rename v2 patch
. Rename
doc/board/sifive/unmatched.rstboard/sifive/unmatched/unmatched.c
. Fix tail whitespace
. Add 'git mv' info to ram driver and merge patch back to one . Add comment to macb driver for PLL hardware quirk
. Add reviewed-by to patch [6/7]
. Add 'gpio-poweroff' node for upcoming opensbi integration
- V2
. Rebase to unleashed rename patch
. remove unnessaary fu540 changes
. split ram driver patch into 2 to keep 'git mv' info
. use a shorter name for unmatched support
. Remove redundant&incorrect temperature-sensor in DT
. Remove unnecessary USB EHCI & OHCI from defconfig
. Revised fu740 doc
. Fixed year of copyright
. Add reviewed-by received in v1 patchDavid Abdurachmanov (1):
drivers: net: macb: add fu740 supportGreen Wan (7):
riscv: cpu: fu740: Add support for cpu fu740
drivers: clk: add fu740 support
drivers: ram: sifive: renamefu540_ddrand add fu740 support
drivers: pci: add pcie support for fu740
riscv: dts: add fu740 support
riscv: dts: add SiFive Unmatched board support
board: sifive: add HiFive Unmatched board supportarch/riscv/Kconfig | 5 + arch/riscv/cpu/fu740/Kconfig | 37 + arch/riscv/cpu/fu740/Makefile | 12 + arch/riscv/cpu/fu740/cache.c | 55 + arch/riscv/cpu/fu740/cpu.c | 22 + arch/riscv/cpu/fu740/dram.c | 38 + arch/riscv/cpu/fu740/spl.c | 23 + arch/riscv/dts/Makefile | 1 + arch/riscv/dts/fu740-c000-u-boot.dtsi | 105 ++ arch/riscv/dts/fu740-c000.dtsi | 329 ++++ .../dts/fu740-hifive-unmatched-a00-ddr.dtsi | 1489 +++++++++++++++++ .../dts/hifive-unmatched-a00-u-boot.dtsi | 40 + arch/riscv/dts/hifive-unmatched-a00.dts | 259 +++ arch/riscv/include/asm/arch-fu740/cache.h | 14 + arch/riscv/include/asm/arch-fu740/clk.h | 14 + arch/riscv/include/asm/arch-fu740/gpio.h | 38 + arch/riscv/include/asm/arch-fu740/reset.h | 13 + arch/riscv/include/asm/arch-fu740/spl.h | 14 + arch/riscv/lib/sifive_clint.c | 1 - board/sifive/unleashed/Kconfig | 1 + board/sifive/unmatched/Kconfig | 50 + board/sifive/unmatched/MAINTAINERS | 9 + board/sifive/unmatched/Makefile | 9 + board/sifive/unmatched/spl.c | 85 + board/sifive/unmatched/unmatched.c | 24 + common/spl/Kconfig | 4 +- configs/sifive_unleashed_defconfig | 1 + configs/sifive_unmatched_defconfig | 54 + doc/board/sifive/index.rst | 1 + doc/board/sifive/unmatched.rst | 536 ++++++ drivers/clk/sifive/Kconfig | 8 +- drivers/clk/sifive/Makefile | 4 +- drivers/clk/sifive/fu540-prci.c | 769 +-------- drivers/clk/sifive/fu540-prci.h | 22 + drivers/clk/sifive/fu740-prci.c | 158 ++ drivers/clk/sifive/fu740-prci.h | 22 + drivers/clk/sifive/sifive-prci.c | 733 ++++++++ drivers/clk/sifive/sifive-prci.h | 323 ++++ drivers/net/macb.c | 13 +- drivers/pci/Kconfig | 10 + drivers/pci/Makefile | 1 + drivers/pci/pcie_dw_sifive.c | 508 ++++++ drivers/ram/sifive/Kconfig | 8 +- drivers/ram/sifive/Makefile | 2 +- .../ram/sifive/{fu540_ddr.c => sifive_ddr.c} | 89 +- drivers/reset/Kconfig | 2 +- include/configs/sifive-unmatched.h | 85 + include/dt-bindings/clock/sifive-fu740-prci.h | 25 + include/dt-bindings/reset/sifive-fu740-prci.h | 19 + 49 files changed, 5277 insertions(+), 807 deletions(-) create mode 100644 arch/riscv/cpu/fu740/Kconfig create mode 100644 arch/riscv/cpu/fu740/Makefile create mode 100644 arch/riscv/cpu/fu740/cache.c create mode 100644 arch/riscv/cpu/fu740/cpu.c create mode 100644 arch/riscv/cpu/fu740/dram.c create mode 100644 arch/riscv/cpu/fu740/spl.c create mode 100644 arch/riscv/dts/fu740-c000-u-boot.dtsi create mode 100644 arch/riscv/dts/fu740-c000.dtsi create mode 100644 arch/riscv/dts/fu740-hifive-unmatched-a00-ddr.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi create mode 100644 arch/riscv/dts/hifive-unmatched-a00.dts create mode 100644 arch/riscv/include/asm/arch-fu740/cache.h create mode 100644 arch/riscv/include/asm/arch-fu740/clk.h create mode 100644 arch/riscv/include/asm/arch-fu740/gpio.h create mode 100644 arch/riscv/include/asm/arch-fu740/reset.h create mode 100644 arch/riscv/include/asm/arch-fu740/spl.h create mode 100644 board/sifive/unmatched/Kconfig create mode 100644 board/sifive/unmatched/MAINTAINERS create mode 100644 board/sifive/unmatched/Makefile create mode 100644 board/sifive/unmatched/spl.c create mode 100644 board/sifive/unmatched/unmatched.c create mode 100644 configs/sifive_unmatched_defconfig create mode 100644 doc/board/sifive/unmatched.rst create mode 100644 drivers/clk/sifive/fu540-prci.h create mode 100644 drivers/clk/sifive/fu740-prci.c create mode 100644 drivers/clk/sifive/fu740-prci.h create mode 100644 drivers/clk/sifive/sifive-prci.c create mode 100644 drivers/clk/sifive/sifive-prci.h create mode 100644 drivers/pci/pcie_dw_sifive.c rename drivers/ram/sifive/{fu540_ddr.c => sifive_ddr.c} (81%) create mode 100644 include/configs/sifive-unmatched.h create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h create mode 100644 include/dt-bindings/reset/sifive-fu740-prci.h--
2.31.0
v7 cover Add FU740 chip and HiFive Unmatched board support
Hi Green,
Quoted 10 lines · Green Wan
Hi Bin,
How should this patch set be proceeded?
To summary the major changes,
- I've rebased to mainstream and merged pcie refactoring code which based onpcie_dw_common.c
- separate unmatched dts into separated patch.
I don't have specific comments. Rick should pick this up via the riscv tree. Thanks!
Regards,
Bin
v7 cover Add FU740 chip and HiFive Unmatched board support
Thanks, Bin.
Hi Rick,
Not sure whether you have a chance to pick it up. Or let me know if any part needs change.
Thanks,
- Green
Quoted 20 lines · Bin Meng
Hi Green,
Quoted 10 lines · Green Wan
Hi Bin,
How should this patch set be proceeded?
To summary the major changes,
- I've rebased to mainstream and merged pcie refactoring code which based onpcie_dw_common.c
- separate unmatched dts into separated patch.I don't have specific comments. Rick should pick this up via the riscv tree. Thanks!
Regards,
Bin
A message that is not in the archive (sent off-list or not yet received): [email protected]
v7 cover Add FU740 chip and HiFive Unmatched board support
Hi Green,
I did not sign the Reviewed-by for this patch "board: sifive: add HiFive Unmatched board support" from v1 to v6.
But it just has been tagged in [v7,7/8] board: sifive: add HiFive Unmatched board support by yourself.
[v6,6/7] board: sifive: add HiFive Unmatched board support
https://patchwork.ozlabs.org/project/uboot/patch/20210408134020.238658-7-green.wan at sifive.com/
[v7,7/8] board: sifive: add HiFive Unmatched board support
https://patchwork.ozlabs.org/project/uboot/patch/20210422091202.396956-8-green.wan at sifive.com/
Actually I don't like this patch that you mix every things (arch/, drivers/, common/, doc/)together in this patch.
But it is OK for now.
BTW, in [PATCH v7 1/8] riscv: cpu: fu740: Add support for cpu fu740 I found that arch/riscv/cpu/fu740/cpu.c and arch/riscv/fu540/cpu.c are 100% the same.
And about spl.c, they are only different in the annotation of Copyright diff fu540/spl.c fu740/spl.c
3c3
< * Copyright (C) 2020 SiFive, Inc
---
Quoted 1 line
* Copyright (C) 2020-201 SiFive, Inc
About the cache.c, they are just different in one character
diff fu540/cache.c fu740/cache.c
3c3
< * Copyright (C) 2020 SiFive, Inc
---
Quoted 1 line
* Copyright (C) 2020-2021 SiFive, Inc
10d9
< #include <asm/global_data.h>
12a12
Quoted 1 line
#include <
asm/global_data.h>
34c34
< "sifive,fu540-c000-ccache");
---
Quoted 1 line
"sifive,fu740-c000-ccache");
Originally, I am considering to tell you to re-use the same code base instead of just copy and create.
After a few days of consideration, I feel it's OK for now.
About
[PATCH v7 2/8] drivers: clk: add fu740 support and [PATCH v7 4/8] drivers: pci: add pcie support for fu740, there are still not get any Reviewed-by till now.
For me, it will be better if someone can tag a Reviewed-by here.
Principally, it will be suggested to split drivers from RISC-V relevant, do not mix them together as Palmer said.
Thanks,
Rick
Quoted 24 lines
From: Bin Meng <[email protected]>
Sent: Thursday, April 29, 2021 8:27 PM
To: Green Wan <[email protected]>
Cc: Rick Jian-Zhi Chen(???) <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Anup Patel <[email protected]>; Atish Patra <[email protected]>; Lukasz Majewski <[email protected]>; Joe Hershberger <[email protected]>; Ramon Fried <[email protected]>; U-Boot Mailing List <[email protected]>
Subject: Re: [PATCH v7 0/8] Add FU740 chip and HiFive Unmatched board supportHi Green,
Quoted 10 lines · Green Wan
Hi Bin,
How should this patch set be proceeded?
To summary the major changes,
- I've rebased to mainstream and merged pcie refactoring code which based onpcie_dw_common.c
- separate unmatched dts into separated patch.I don't have specific comments. Rick should pick this up via the riscv tree. Thanks!
Regards,
Bin
v7 cover Add FU740 chip and HiFive Unmatched board support
Hi Rick,
Thanks for quick response. See my reply below.
Quoted 8 lines · Rick Chen
Hi Green,
I did not sign the Reviewed-by for this patch "board: sifive: add HiFive Unmatched board support" from v1 to v6.
But it just has been tagged in [v7,7/8] board: sifive: add HiFive Unmatched board support by yourself.
Sorry, I might have a quick conclusion when Reviewed-by is on our previous discussion in [v6 1/7]. We ended up splitting dts into two. One for fu740 and the other for Unmatched board specifically. And put them closer. Then, I added the review-by to them.
---- Here is the previous discussion. ----
"Makefile need the dts file, but it is not exist in this patch. It doesn't make sense.
Maybe you can combine with the dts relative files in [PATCH v6 6/7] into one patch and name as :
riscv: dts: ...
LGTM.
Other than that,
"It is OK.
You may arrange them nearby as below:
6/x riscv: dts: support fu740
7/x riscv: dst: support HiFive Unmatched board
Thanks,
Rick"
Quoted 10 lines
[v6,6/7] board: sifive: add HiFive Unmatched board support
https://patchwork.ozlabs.org/project/uboot/patch/20210408134020.238658-7-green.wan at sifive.com/[v7,7/8] board: sifive: add HiFive Unmatched board support
https://patchwork.ozlabs.org/project/uboot/patch/20210422091202.396956-8-green.wan at sifive.com/Actually I don't like this patch that you mix every things (
arch/,drivers/, common/, doc/)together in this patch.
But it is OK for now.
Noted. Thanks for reminding me.
Quoted 26 lines
BTW, in [PATCH v7 1/8] riscv: cpu: fu740: Add support for cpu fu740 I found that
arch/riscv/cpu/fu740/cpu.candarch/riscv/fu540/cpu.care 100% the same.And about
spl.c, they are only different in the annotation of Copyright difffu540/spl.cfu740/spl.c
3c3
< * Copyright (C) 2020 SiFive, Inc
---Quoted 1 line
* Copyright (C) 2020-201 SiFive, Inc
About the
cache.c, they are just different in one characterdiff
fu540/cache.cfu740/cache.c
3c3
< * Copyright (C) 2020 SiFive, Inc
---Quoted 1 line
* Copyright (C) 2020-2021 SiFive, Inc
10d9
< #include <asm/global_data.h>
12a12Quoted 1 line
#include <
asm/global_data.h>34c34
< "sifive,fu540-c000-ccache");
---
Quoted 7 lines
Quoted 1 line
"sifive,fu740-c000-ccache");Originally, I am considering to tell you to re-use the same code base instead of just copy and create.
After a few days of consideration, I feel it's OK for now.
You're right. As you mentioned, I also considered having common code. But I conservatively decided to keep separated files to handle possible differences among chips.
Quoted 8 lines
About
[PATCH v7 2/8] drivers: clk: add fu740 support and [PATCH v7 4/8] drivers: pci: add pcie support for fu740, there are still not get any Reviewed-by till now.
For me, it will be better if someone can tag a Reviewed-by here.Principally, it will be suggested to split drivers from RISC-V relevant, do not mix them together as Palmer said.
Not sure whether we'll have the driver reviewers very quick. What do you think of moving forward? I can try to ping some driver maintainers and see if we have someone to review them. =]
Thanks,
Quoted 28 lines
Thanks,
RickQuoted 24 lines
From: Bin Meng <[email protected]>
Sent: Thursday, April 29, 2021 8:27 PM
To: Green Wan <[email protected]>
Cc: Rick Jian-Zhi Chen(???) <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Anup Patel <[email protected]>; Atish Patra <[email protected]>; Lukasz Majewski <[email protected]>; Joe Hershberger <[email protected]>; Ramon Fried <[email protected]>; U-Boot Mailing List <[email protected]>
Subject: Re: [PATCH v7 0/8] Add FU740 chip and HiFive Unmatched board supportHi Green,
Quoted 10 lines · Green Wan
Hi Bin,
How should this patch set be proceeded?
To summary the major changes,
- I've rebased to mainstream and merged pcie refactoring code which based onpcie_dw_common.c
- separate unmatched dts into separated patch.I don't have specific comments. Rick should pick this up via the riscv tree. Thanks!
Regards,
Bin
v7 cover Add FU740 chip and HiFive Unmatched board support
Hi Green,
Quoted 97 lines
Hi Rick,
Thanks for quick response. See my reply below.
Quoted 8 lines · Rick Chen
Hi Green,
I did not sign the Reviewed-by for this patch "board: sifive: add HiFive Unmatched board support" from v1 to v6.
But it just has been tagged in [v7,7/8] board: sifive: add HiFive Unmatched board support by yourself.Sorry, I might have a quick conclusion when Reviewed-by is on our previous discussion in [v6 1/7]. We ended up splitting dts into two. One for fu740 and the other for Unmatched board specifically. And put them closer. Then, I added the review-by to them.
---- Here is the previous discussion. ----
"Makefileneed the dts file, but it is not exist in this patch. It doesn't make sense.Maybe you can combine with the dts relative files in [PATCH v6 6/7] into one patch and name as :
riscv: dts: ...LGTM.
Other than that,Reviewed-by Rick Chen <[email protected]> ""It is OK.
You may arrange them nearby as below:
6/x riscv: dts: support fu740
7/x riscv: dst: support HiFive Unmatched boardThanks,
Rick"Quoted 10 lines
[v6,6/7] board: sifive: add HiFive Unmatched board support
https://patchwork.ozlabs.org/project/uboot/patch/20210408134020.238658-7-green.wan at sifive.com/[v7,7/8] board: sifive: add HiFive Unmatched board support
https://patchwork.ozlabs.org/project/uboot/patch/20210422091202.396956-8-green.wan at sifive.com/Actually I don't like this patch that you mix every things (
arch/,drivers/, common/, doc/)together in this patch.
But it is OK for now.Noted. Thanks for reminding me.
Quoted 26 lines
BTW, in [PATCH v7 1/8] riscv: cpu: fu740: Add support for cpu fu740 I found that
arch/riscv/cpu/fu740/cpu.candarch/riscv/fu540/cpu.care 100% the same.And about
spl.c, they are only different in the annotation of Copyright difffu540/spl.cfu740/spl.c
3c3
< * Copyright (C) 2020 SiFive, Inc
---Quoted 1 line
* Copyright (C) 2020-201 SiFive, Inc
About the
cache.c, they are just different in one characterdiff
fu540/cache.cfu740/cache.c
3c3
< * Copyright (C) 2020 SiFive, Inc
---Quoted 1 line
* Copyright (C) 2020-2021 SiFive, Inc
10d9
< #include <asm/global_data.h>
12a12Quoted 1 line
#include <
asm/global_data.h>34c34
< "sifive,fu540-c000-ccache");
---Quoted 7 lines
Quoted 1 line
"sifive,fu740-c000-ccache");Originally, I am considering to tell you to re-use the same code base instead of just copy and create.
After a few days of consideration, I feel it's OK for now.You're right. As you mentioned, I also considered having common code. But I conservatively decided to keep separated files to handle possible differences among chips.
Quoted 6 lines
About
[PATCH v7 2/8] drivers: clk: add fu740 support and [PATCH v7 4/8] drivers: pci: add pcie support for fu740, there are still not get any Reviewed-by till now.
For me, it will be better if someone can tag a Reviewed-by here.
Quoted 6 lines
Quoted 2 lines
Principally, it will be suggested to split drivers from RISC-V relevant, do not mix them together as Palmer said.
Not sure whether we'll have the driver reviewers very quick. What do you think of moving forward? I can try to ping some driver maintainers and see if we have someone to review them. =]
OK.
Maybe let's just wait for a period of time, if it still no furthermore response. I can help to pull them via riscv tree.
Thanks,
Rick
Quoted 33 lines
Thanks,
Quoted 28 lines
Thanks,
RickQuoted 24 lines
From: Bin Meng <[email protected]>
Sent: Thursday, April 29, 2021 8:27 PM
To: Green Wan <[email protected]>
Cc: Rick Jian-Zhi Chen(???) <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Anup Patel <[email protected]>; Atish Patra <[email protected]>; Lukasz Majewski <[email protected]>; Joe Hershberger <[email protected]>; Ramon Fried <[email protected]>; U-Boot Mailing List <[email protected]>
Subject: Re: [PATCH v7 0/8] Add FU740 chip and HiFive Unmatched board supportHi Green,
Quoted 10 lines · Green Wan
Hi Bin,
How should this patch set be proceeded?
To summary the major changes,
- I've rebased to mainstream and merged pcie refactoring code which based onpcie_dw_common.c
- separate unmatched dts into separated patch.I don't have specific comments. Rick should pick this up via the riscv tree. Thanks!
Regards,
Bin