Add U-Boot support for MediaTek SoCs - MT7623n & MT7629
Subsystems (12)
v2 cover Add U-Boot support for MediaTek SoCs - MT7623n & MT7629
Hello,
This is the new round to add U-Boot support for MediaTek SoCs - MT7623n & MT7629, and the most of the drivers are based on mainline Linux, such as clock, timer, mmc, pinctrl, watchdog, power domain and device tree.
The following are the major differences between mainline Linux and U-Boot:
- Modify the drivers to adapt the U-Boot DM framework.
- Remove unneeded DT nodes as they don't have proper drivers in U-Boot yet.
- Just add the basic functions (step-by-step) so that we can monitor the size.
- Reuse UART driver ns16550.c but add a highspeed register for MediaTek chips.
- Add a whole new MT7629 SNOR driver which is based on SPI framework.
Our current progress:
The MT7623n (BananaPi R2) which has already been supported in mainline Linux.
- Boot from eMMC or SD card.
- Boot flow: ROM -> MediaTek's preloder -> U-Boot ...
- An open development board called BananaPi R2 [1].
The MT7629 is NOT supported yet in mainline Linux, but I will add it soon.
- Boot from SNOR currently.
- Boot flow: ROM -> (boot header parsing sequence) -> SPL -> U-Boot ...
[1] http://wiki.banana-pi.org/Banana_Pi_BPI-R2
Current implementation was validated via the FIT image.
Thanks,
Ryder
Changes since v2:
- Squash defconfig parts into other patches.
- Drop unneeded definitions in include/configs/*.
- Add a MT7629 qspi driver in the series.
Changes since v1:
- Fix new blank line at EOF and indentation.
- Revise commit message.
- Add missing sgmiisys device nodes.
- Add Tested-by tags from Matthias.
- Drop MT7629 qspi driver in the series, and we will implement another one based on the spi-mem framework.
Guochun Mao (1):
spi: mtk_qspi: add qspi driver for MT7629 SoC
Ryder Lee (15):
tools: MediaTek: add MTK boot header generation to mkimage
arm: dts: MediaTek: add device tree for MT7629
arm: dts: MediaTek: add device tree for MT7623
arm: MediaTek: add basic support for MT7629 boards
clk: MediaTek: add clock driver for MT7629 SoC.
clk: MediaTek: add clock driver for MT7623 SoC.
timer: MediaTek: add timer driver for MediaTek SoCs
watchdog: MediaTek: add watchdog driver for MediaTek SoCs
pinctrl: MediaTek: add pinctrl driver for MT7629 SoC
pinctrl: MediaTek: add pinctrl driver for MT7623 SoC power domain: MediaTek: add power domain driver for MT7629 SoC power domain: MediaTek: add power domain driver for MT7623 SoC
serial: 16550: allow the driver to support MediaTek serial
ram: MediaTek: add DDR3 driver for MT7629 SoC
MAINTAINERS: add an entry for MediaTek
Weijie Gao (2):
arm: MediaTek: add basic support for MT7623 boards
mmc: mtk-sd: add SD/MMC host controller driver for MT7623 SoC
MAINTAINERS | 18 + Makefile | 22 + arch/arm/Kconfig | 14 + arch/arm/Makefile | 1 + arch/arm/dts/Makefile | 4 + arch/arm/dts/mt7623.dtsi | 255 +++++ arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | 207 ++++ arch/arm/dts/mt7629-rfb.dts | 71 ++ arch/arm/dts/mt7629.dtsi | 244 +++++ arch/arm/include/asm/arch-mediatek/gpio.h | 9 + arch/arm/include/asm/arch-mediatek/misc.h | 17 + arch/arm/mach-mediatek/Kconfig | 32 + arch/arm/mach-mediatek/Makefile | 7 + arch/arm/mach-mediatek/cpu.c | 34 + arch/arm/mach-mediatek/init.h | 11 + arch/arm/mach-mediatek/mt7623/Makefile | 4 + arch/arm/mach-mediatek/mt7623/init.c | 54 + arch/arm/mach-mediatek/mt7623/lowlevel_init.S | 22 + arch/arm/mach-mediatek/mt7623/preloader.h | 99 ++ arch/arm/mach-mediatek/mt7629/Makefile | 4 + arch/arm/mach-mediatek/mt7629/init.c | 131 +++ arch/arm/mach-mediatek/mt7629/lowlevel_init.S | 50 + arch/arm/mach-mediatek/spl.c | 43 + board/mediatek/mt7623/Kconfig | 13 + board/mediatek/mt7623/MAINTAINERS | 7 + board/mediatek/mt7623/Makefile | 3 + board/mediatek/mt7623/mt7623_rfb.c | 16 + board/mediatek/mt7629/Kconfig | 17 + board/mediatek/mt7629/MAINTAINERS | 7 + board/mediatek/mt7629/Makefile | 3 + board/mediatek/mt7629/mt7629_rfb.c | 16 + common/image.c | 1 + configs/mt7623n_bpir2_defconfig | 53 + configs/mt7629_rfb_defconfig | 73 ++ drivers/clk/Makefile | 1 + drivers/clk/mediatek/Makefile | 7 + drivers/clk/mediatek/clk-mt7623.c | 870 ++++++++++++++++ drivers/clk/mediatek/clk-mt7629.c | 709 +++++++++++++ drivers/clk/mediatek/clk-mtk.c | 492 +++++++++ drivers/clk/mediatek/clk-mtk.h | 153 +++ drivers/mmc/Kconfig | 9 + drivers/mmc/Makefile | 1 + drivers/mmc/mtk-sd.c | 1331 +++++++++++++++++++++++++ drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/mediatek/Kconfig | 15 + drivers/pinctrl/mediatek/Makefile | 7 + drivers/pinctrl/mediatek/pinctrl-mt7623.c | 1284 ++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mt7629.c | 488 +++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 552 ++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 183 ++++ drivers/power/domain/Kconfig | 7 + drivers/power/domain/Makefile | 1 + drivers/power/domain/mtk-power-domain.c | 406 ++++++++ drivers/ram/Makefile | 1 + drivers/ram/mediatek/Makefile | 7 + drivers/ram/mediatek/ddr3-mt7629.c | 766 ++++++++++++++ drivers/serial/ns16550.c | 10 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mtk_qspi.c | 359 +++++++ drivers/timer/Kconfig | 7 + drivers/timer/Makefile | 1 + drivers/timer/mtk_timer.c | 85 ++ drivers/watchdog/Kconfig | 8 + drivers/watchdog/Makefile | 1 + drivers/watchdog/mtk_wdt.c | 135 +++ include/configs/mt7623.h | 61 ++ include/configs/mt7629.h | 62 ++ include/dt-bindings/clock/mt7623-clk.h | 413 ++++++++ include/dt-bindings/clock/mt7629-clk.h | 206 ++++ include/dt-bindings/power/mt7623-power.h | 19 + include/dt-bindings/power/mt7629-power.h | 13 + include/image.h | 1 + scripts/Makefile.spl | 11 + tools/Makefile | 1 + tools/mtkimage.c | 749 ++++++++++++++ tools/mtkimage.h | 199 ++++ 78 files changed, 11203 insertions(+) create mode 100644 arch/arm/dts/mt7623.dtsi create mode 100644 arch/arm/dts/mt7623n-bananapi-bpi-r2.dts create mode 100644 arch/arm/dts/mt7629-rfb.dts create mode 100644 arch/arm/dts/mt7629.dtsi create mode 100644 arch/arm/include/asm/arch-mediatek/gpio.h create mode 100644 arch/arm/include/asm/arch-mediatek/misc.h create mode 100644 arch/arm/mach-mediatek/Kconfig create mode 100644 arch/arm/mach-mediatek/Makefile create mode 100644 arch/arm/mach-mediatek/cpu.c create mode 100644 arch/arm/mach-mediatek/init.h create mode 100644 arch/arm/mach-mediatek/mt7623/Makefile create mode 100644 arch/arm/mach-mediatek/mt7623/init.c create mode 100644 arch/arm/mach-mediatek/mt7623/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/mt7623/preloader.h create mode 100644 arch/arm/mach-mediatek/mt7629/Makefile create mode 100644 arch/arm/mach-mediatek/mt7629/init.c create mode 100644 arch/arm/mach-mediatek/mt7629/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/spl.c create mode 100644 board/mediatek/mt7623/Kconfig create mode 100644 board/mediatek/mt7623/MAINTAINERS create mode 100644 board/mediatek/mt7623/Makefile create mode 100644 board/mediatek/mt7623/mt7623_rfb.c create mode 100644 board/mediatek/mt7629/Kconfig create mode 100644 board/mediatek/mt7629/MAINTAINERS create mode 100644 board/mediatek/mt7629/Makefile create mode 100644 board/mediatek/mt7629/mt7629_rfb.c create mode 100644 configs/mt7623n_bpir2_defconfig create mode 100644 configs/mt7629_rfb_defconfig create mode 100644 drivers/clk/mediatek/Makefile create mode 100644 drivers/clk/mediatek/clk-mt7623.c create mode 100644 drivers/clk/mediatek/clk-mt7629.c create mode 100644 drivers/clk/mediatek/clk-mtk.c create mode 100644 drivers/clk/mediatek/clk-mtk.h create mode 100644 drivers/mmc/mtk-sd.c create mode 100644 drivers/pinctrl/mediatek/Kconfig create mode 100644 drivers/pinctrl/mediatek/Makefile create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7623.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7629.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.h create mode 100644 drivers/power/domain/mtk-power-domain.c create mode 100644 drivers/ram/mediatek/Makefile create mode 100644 drivers/ram/mediatek/ddr3-mt7629.c create mode 100644 drivers/spi/mtk_qspi.c create mode 100644 drivers/timer/mtk_timer.c create mode 100644 drivers/watchdog/mtk_wdt.c create mode 100644 include/configs/mt7623.h create mode 100644 include/configs/mt7629.h create mode 100644 include/dt-bindings/clock/mt7623-clk.h create mode 100644 include/dt-bindings/clock/mt7629-clk.h create mode 100644 include/dt-bindings/power/mt7623-power.h create mode 100644 include/dt-bindings/power/mt7629-power.h create mode 100644 tools/mtkimage.c create mode 100644 tools/mtkimage.h
Signature · 1 line
1.9.1
PATCH v2 1/18 tools: MediaTek: add MTK boot header generation to mkimage
This patch adds support for MTK boot image generation.
--- Makefile | 22 ++ common/image.c | 1 + include/image.h | 1 + scripts/Makefile.spl | 11 + tools/Makefile | 1 + tools/mtkimage.c | 749 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/mtkimage.h | 199 ++++++++++++++ 7 files changed, 984 insertions(+) create mode 100644 tools/mtkimage.c create mode 100644 tools/mtkimage.h
Makefile +22 -0
@@ -852,6 +852,8 @@ ALL-y += u-boot-tegra.bin u-boot-nodtb-tegra.bin ALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb-tegra.bin endif +ALL-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin + # Add optional build target if defined in board/cpu/soc headers ifneq ($(CONFIG_BUILD_TARGET),) ALL-y += $(CONFIG_BUILD_TARGET:"%"=%)
@@ -1357,6 +1359,26 @@ u-boot.elf: u-boot.bin $(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< u-boot-elf.o $(call if_changed,u-boot-elf) +# MediaTek's ARM-based u-boot needs a header to contains its load address +# which is parsed by the BootROM. +# If the SPL build is enabled, the header will be added to the spl binary, +# and the spl binary and the u-boot.img will be combined into one file. +# Otherwise the header will be added to the u-boot.bin directly. + +ifeq ($(CONFIG_SPL),y) +OBJCOPYFLAGS_u-boot-mtk.bin = -I binary -O binary \ + --pad-to=$(CONFIG_SPL_PAD_TO) +u-boot-mtk.bin: spl/u-boot-spl-mtk.bin u-boot.img FORCE + $(call if_changed,pad_cat) +else +MKIMAGEFLAGS_u-boot-mtk.bin = -T mtkimage \ + -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \ + -n "$(patsubst "%",%,$(CONFIG_MTK_BROM_HEADER_INFO))" + +u-boot-mtk.bin: u-boot.bin FORCE + $(call if_changed,mkimage) +endif + ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(ARCH)/Makefile.postlink) # Rule to link u-boot
common/image.c +1 -0
@@ -165,6 +165,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_FIRMWARE_IVT, "firmware_ivt", "Firmware with HABv4 IVT" }, { IH_TYPE_PMMC, "pmmc", "TI Power Management Micro-Controller Firmware",}, { IH_TYPE_STM32IMAGE, "stm32image", "STMicroelectronics STM32 Image" }, + { IH_TYPE_MTKIMAGE, "mtkimage", "MeidaTek BootROM loadable Image" }, { -1, "", "", }, };
include/image.h +1 -0
@@ -277,6 +277,7 @@ enum {IH_TYPE_PMMC ,/* TI Power Management Micro-Controller Firmware */ IH_TYPE_STM32IMAGE ,/* STMicroelectronics STM32 Image */ IH_TYPE_SOCFPGAIMAGE_V1 ,/* Altera SOCFPGA A10 Preloader */ +IH_TYPE_MTKIMAGE ,/* MeidaTek BootROM loadable Image */ IH_TYPE_COUNT, /* Number of image types */ };
scripts/Makefile.spl +11 -0
@@ -219,6 +219,8 @@ ALL-$(CONFIG_SPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-16bit-spl.bin ALL-$(CONFIG_ARCH_ZYNQ) += $(obj)/boot.bin ALL-$(CONFIG_ARCH_ZYNQMP) += $(obj)/boot.bin +ALL-$(CONFIG_ARCH_MEDIATEK) += $(obj)/u-boot-spl-mtk.bin + all: $(ALL-y) quiet_cmd_cat = CAT $@
@@ -349,6 +351,15 @@ cmd_sunxi_spl_image_builder = $(objtree)/tools/sunxi-spl-image-builder \ $(obj)/sunxi-spl-with-ecc.bin: $(obj)/sunxi-spl.bin $(call if_changed,sunxi_spl_image_builder) + +# MediaTek's specific SPL build +MKIMAGEFLAGS_u-boot-spl-mtk.bin = -T mtkimage \ + -a $(CONFIG_SPL_TEXT_BASE) -e $(CONFIG_SPL_TEXT_BASE) \ + -n "$(patsubst "%",%,$(CONFIG_MTK_BROM_HEADER_INFO))" + +$(obj)/u-boot-spl-mtk.bin: $(obj)/u-boot-spl.bin FORCE + $(call if_changed,mkimage) + # Rule to link u-boot-spl # May be overridden by arch/$(ARCH)/config.mk quiet_cmd_u-boot-spl ?= LD $@
tools/Makefile +1 -0
@@ -115,6 +115,7 @@ dumpimage-mkimage-objs := aisimage.o \ $(LIBFDT_OBJS) \ gpimage.o \ gpimage-common.o \ + mtkimage.o \ $(RSA_OBJS-y) dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
tools/mtkimage.c new file +749 -0
749 lines not on this page · raw message
tools/mtkimage.h new file +199 -0
199 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 1/18 tools: MediaTek: add MTK boot header generation to mkimage
Hi Ryder,
Quoted 4 lines · Ryder Lee
This patch adds support for MTK boot image generation.
Signed-off-by Weijie Gao <[email protected]>Signed-off-by Ryder Lee <[email protected]>
Quoted 11 lines
--- Makefile | 22 ++ common/image.c | 1 + include/image.h | 1 + scripts/Makefile.spl | 11 + tools/Makefile | 1 + tools/mtkimage.c | 749 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/mtkimage.h | 199 ++++++++++++++ 7 files changed, 984 insertions(+) create mode 100644 tools/mtkimage.c create mode 100644 tools/mtkimage.h
The mkimage stuff looks fine.
But can you use binman for the pad/cat part of this? See for example sunxi. - sunxi-u-boot.dtsi
Also mtkimage.c is too close to mkimage.c - how about mtk_image.c ?
Regards,
Simon
PATCH v2 1/18 tools: MediaTek: add MTK boot header generation to mkimage
Quoted 19 lines · Simon Glass
Hi Ryder,
Quoted 4 lines · Ryder Lee
This patch adds support for MTK boot image generation.
Signed-off-by Weijie Gao <[email protected]>Signed-off-by Ryder Lee <[email protected]>Quoted 11 lines
--- Makefile | 22 ++ common/image.c | 1 + include/image.h | 1 + scripts/Makefile.spl | 11 + tools/Makefile | 1 + tools/mtkimage.c | 749 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/mtkimage.h | 199 ++++++++++++++ 7 files changed, 984 insertions(+) create mode 100644 tools/mtkimage.c create mode 100644 tools/mtkimage.h
Quoted 7 lines
The mkimage stuff looks fine.
But can you use binman for the pad/cat part of this? See for example sunxi. -
sunxi-u-boot.dtsiAlso
mtkimage.cis too close tomkimage.c- how aboutmtk_image.c?
This looks great. I will switch to use binman in v3.
Thanks
Ryder
PATCH v2 2/18 arm: dts: MediaTek: add device tree for MT7629
In reply to Ryder LeeThis patch adds MT7629 device tree and the includes it needs.
--- arch/arm/dts/Makefile | 3 + arch/arm/dts/mt7629-rfb.dts | 71 +++++++++ arch/arm/dts/mt7629.dtsi | 244 +++++++++++++++++++++++++++++++ include/dt-bindings/clock/mt7629-clk.h | 206 ++++++++++++++++++++++++++ include/dt-bindings/power/mt7629-power.h | 13 ++ 5 files changed, 537 insertions(+) create mode 100644 arch/arm/dts/mt7629-rfb.dts create mode 100644 arch/arm/dts/mt7629.dtsi create mode 100644 include/dt-bindings/clock/mt7629-clk.h create mode 100644 include/dt-bindings/power/mt7629-power.h
arch/arm/dts/Makefile +3 -0
@@ -555,6 +555,9 @@ dtb-$(CONFIG_TARGET_STM32MP1) += \ dtb-$(CONFIG_SOC_K3_AM6) += k3-am654-base-board.dtb +dtb-$(CONFIG_ARCH_MEDIATEK) += \ + mt7629-rfb.dtb + targets += $(dtb-y) # Add any required device tree compiler flags here
arch/arm/dts/mt7629-rfb.dts new file +71 -0
71 lines not on this page · raw message
arch/arm/dts/mt7629.dtsi new file +244 -0
244 lines not on this page · raw message
include/dt-bindings/clock/mt7629-clk.h new file +206 -0
206 lines not on this page · raw message
include/dt-bindings/power/mt7629-power.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef _DT_BINDINGS_MT7629_POWER_H +#define _DT_BINDINGS_MT7629_POWER_H + +#define MT7629_POWER_DOMAIN_ETHSYS 0 +#define MT7629_POWER_DOMAIN_HIF0 1 +#define MT7629_POWER_DOMAIN_HIF1 2 + +#endif /* _DT_BINDINGS_MT7629_POWER_H */
Signature · 1 line
1.9.1
PATCH v2 2/18 arm: dts: MediaTek: add device tree for MT7629
Quoted 14 lines · Ryder Lee
This patch adds MT7629 device tree and the includes it needs.
Signed-off-by Ryder Lee <[email protected]>--- arch/arm/dts/Makefile | 3 + arch/arm/dts/mt7629-rfb.dts | 71 +++++++++ arch/arm/dts/mt7629.dtsi | 244 +++++++++++++++++++++++++++++++ include/dt-bindings/clock/mt7629-clk.h | 206 ++++++++++++++++++++++++++ include/dt-bindings/power/mt7629-power.h | 13 ++ 5 files changed, 537 insertions(+) create mode 100644 arch/arm/dts/mt7629-rfb.dts create mode 100644 arch/arm/dts/mt7629.dtsi create mode 100644 include/dt-bindings/clock/mt7629-clk.h create mode 100644 include/dt-bindings/power/mt7629-power.h
PATCH v2 3/18 arm: dts: MediaTek: add device tree for MT7623
In reply to Ryder LeeThis adds device tree for MT7623 development board - Bananapi R2 Detailed hardware information for BPI-R2 which could be found on
http://wiki.banana-pi.org/Banana_Pi_BPI-R2.
--- arch/arm/dts/Makefile | 1 + arch/arm/dts/mt7623.dtsi | 255 +++++++++++++++++++ arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | 207 ++++++++++++++++ include/dt-bindings/clock/mt7623-clk.h | 413 +++++++++++++++++++++++++++++++ include/dt-bindings/power/mt7623-power.h | 19 ++ 5 files changed, 895 insertions(+) create mode 100644 arch/arm/dts/mt7623.dtsi create mode 100644 arch/arm/dts/mt7623n-bananapi-bpi-r2.dts create mode 100644 include/dt-bindings/clock/mt7623-clk.h create mode 100644 include/dt-bindings/power/mt7623-power.h
arch/arm/dts/Makefile +1 -0
@@ -556,6 +556,7 @@ dtb-$(CONFIG_TARGET_STM32MP1) += \ dtb-$(CONFIG_SOC_K3_AM6) += k3-am654-base-board.dtb dtb-$(CONFIG_ARCH_MEDIATEK) += \ + mt7623n-bananapi-bpi-r2.dtb \ mt7629-rfb.dtb targets += $(dtb-y)
arch/arm/dts/mt7623.dtsi new file +255 -0
255 lines not on this page · raw message
arch/arm/dts/mt7623n-bananapi-bpi-r2.dts new file +207 -0
207 lines not on this page · raw message
include/dt-bindings/clock/mt7623-clk.h new file +413 -0
413 lines not on this page · raw message
include/dt-bindings/power/mt7623-power.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef _DT_BINDINGS_MT7623_POWER_H +#define _DT_BINDINGS_MT7623_POWER_H + +#define MT7623_POWER_DOMAIN_CONN 0 +#define MT7623_POWER_DOMAIN_DISP 1 +#define MT7623_POWER_DOMAIN_MFG 2 +#define MT7623_POWER_DOMAIN_VDEC 3 +#define MT7623_POWER_DOMAIN_ISP 4 +#define MT7623_POWER_DOMAIN_BDP 5 +#define MT7623_POWER_DOMAIN_ETH 6 +#define MT7623_POWER_DOMAIN_HIF 7 +#define MT7623_POWER_DOMAIN_IFR_MSC 8 + +#endif /* _DT_BINDINGS_MT7623_POWER_H */
Signature · 1 line
1.9.1
PATCH v2 3/18 arm: dts: MediaTek: add device tree for MT7623
Quoted 6 lines · Ryder Lee
This adds device tree for MT7623 development board - Bananapi R2 Detailed hardware information for BPI-R2 which could be found on
http://wiki.banana-pi.org/Banana_Pi_BPI-R2.Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>
Quoted 11 lines
--- arch/arm/dts/Makefile | 1 + arch/arm/dts/mt7623.dtsi | 255 +++++++++++++++++++ arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | 207 ++++++++++++++++ include/dt-bindings/clock/mt7623-clk.h | 413 +++++++++++++++++++++++++++++++ include/dt-bindings/power/mt7623-power.h | 19 ++ 5 files changed, 895 insertions(+) create mode 100644 arch/arm/dts/mt7623.dtsi create mode 100644 arch/arm/dts/mt7623n-bananapi-bpi-r2.dts create mode 100644 include/dt-bindings/clock/mt7623-clk.h create mode 100644 include/dt-bindings/power/mt7623-power.h
PATCH v2 4/18 arm: MediaTek: add basic support for MT7629 boards
In reply to Ryder LeeThis adds a general board file based on MT7629 SoCs from MediaTek.
Apart from the generic parts (cpu) we add some low level init codes and initialize the early clocks.
--- arch/arm/Kconfig | 14 +++ arch/arm/Makefile | 1 + arch/arm/include/asm/arch-mediatek/misc.h | 17 ++++ arch/arm/mach-mediatek/Kconfig | 24 +++++ arch/arm/mach-mediatek/Makefile | 6 ++ arch/arm/mach-mediatek/cpu.c | 34 +++++++ arch/arm/mach-mediatek/init.h | 11 +++ arch/arm/mach-mediatek/mt7629/Makefile | 4 + arch/arm/mach-mediatek/mt7629/init.c | 131 ++++++++++++++++++++++++++ arch/arm/mach-mediatek/mt7629/lowlevel_init.S | 50 ++++++++++ arch/arm/mach-mediatek/spl.c | 43 +++++++++ board/mediatek/mt7629/Kconfig | 17 ++++ board/mediatek/mt7629/MAINTAINERS | 7 ++ board/mediatek/mt7629/Makefile | 3 + board/mediatek/mt7629/mt7629_rfb.c | 16 ++++ configs/mt7629_rfb_defconfig | 73 ++++++++++++++ include/configs/mt7629.h | 62 ++++++++++++ 17 files changed, 513 insertions(+) create mode 100644 arch/arm/include/asm/arch-mediatek/misc.h create mode 100644 arch/arm/mach-mediatek/Kconfig create mode 100644 arch/arm/mach-mediatek/Makefile create mode 100644 arch/arm/mach-mediatek/cpu.c create mode 100644 arch/arm/mach-mediatek/init.h create mode 100644 arch/arm/mach-mediatek/mt7629/Makefile create mode 100644 arch/arm/mach-mediatek/mt7629/init.c create mode 100644 arch/arm/mach-mediatek/mt7629/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/spl.c create mode 100644 board/mediatek/mt7629/Kconfig create mode 100644 board/mediatek/mt7629/MAINTAINERS create mode 100644 board/mediatek/mt7629/Makefile create mode 100644 board/mediatek/mt7629/mt7629_rfb.c create mode 100644 configs/mt7629_rfb_defconfig create mode 100644 include/configs/mt7629.h
arch/arm/Kconfig +14 -0
@@ -668,6 +668,18 @@ config ARCH_MESON targeted at media players and tablet computers. We currently support the S905 (GXBaby) 64-bit SoC. +config ARCH_MEDIATEK + bool "MediaTek SoCs" + select DM + select OF_CONTROL + select SPL_DM if SPL + select SPL_LIBCOMMON_SUPPORT if SPL + select SPL_LIBGENERIC_SUPPORT if SPL + select SPL_OF_CONTROL if SPL + select SUPPORT_SPL + help + Support for the MediaTek SoCs family. + config ARCH_MX8M bool "NXP i.MX8M platform" select ARM64
@@ -1423,6 +1435,8 @@ source "arch/arm/mach-rmobile/Kconfig" source "arch/arm/mach-meson/Kconfig" +source "arch/arm/mach-mediatek/Kconfig" + source "arch/arm/mach-qemu/Kconfig" source "arch/arm/mach-rockchip/Kconfig"
arch/arm/Makefile +1 -0
@@ -62,6 +62,7 @@ machine-$(CONFIG_ARCH_K3) += k3 machine-$(CONFIG_ARCH_KEYSTONE) += keystone # TODO: rename CONFIG_KIRKWOOD -> CONFIG_ARCH_KIRKWOOD machine-$(CONFIG_KIRKWOOD) += kirkwood +machine-$(CONFIG_ARCH_MEDIATEK) += mediatek machine-$(CONFIG_ARCH_MESON) += meson machine-$(CONFIG_ARCH_MVEBU) += mvebu # TODO: rename CONFIG_TEGRA -> CONFIG_ARCH_TEGRA
arch/arm/include/asm/arch-mediatek/misc.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef __MEDIATEK_MISC_H_ +#define __MEDIATEK_MISC_H_ + +#define VER_BASE 0x08000000 +#define VER_SIZE 0x10 + +#define APHW_CODE 0x00 +#define APHW_SUBCODE 0x04 +#define APHW_VER 0x08 +#define APSW_VER 0x0c + +#endif /* __MEDIATEK_MISC_H_ */
arch/arm/mach-mediatek/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +if ARCH_MEDIATEK + +config SYS_SOC + default "mediatek" + +config SYS_VENDOR + default "mediatek" + +choice + prompt "MediaTek board select" + +config TARGET_MT7629 + bool "MediaTek MT7629 SoC" + select CPU_V7A + select SPL + select ARCH_MISC_INIT + help + Support MediaTek MT7629 SoC. + +endchoice + +source "board/mediatek/mt7629/Kconfig" + +endif
arch/arm/mach-mediatek/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += cpu.o +obj-$(CONFIG_SPL_BUILD) += spl.o + +obj-$(CONFIG_TARGET_MT7629) += mt7629/
arch/arm/mach-mediatek/cpu.c new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#include <common.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#include <wdt.h> + +int arch_misc_init (void ) +{ +struct udevice *wdt; +int ret; + + ret =uclass_get_device (UCLASS_WDT ,0 , &wdt); +if (!ret) +wdt_stop (wdt); + +return 0 ; +} + +int arch_cpu_init (void ) +{ +icache_enable (); + +return 0 ; +} + +void enable_caches (void ) +{ +/* Enable D-cache. I-cache is already enabled in start.S */ +dcache_enable (); +}
arch/arm/mach-mediatek/init.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef __MEDIATEK_INIT_H_ +#define __MEDIATEK_INIT_H_ + +extern int mtk_soc_early_init (void ); + +#endif /* __MEDIATEK_INIT_H_ */
arch/arm/mach-mediatek/mt7629/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += init.o +obj-y += lowlevel_init.o
arch/arm/mach-mediatek/mt7629/init.c new file +131 -0
131 lines not on this page · raw message
arch/arm/mach-mediatek/mt7629/lowlevel_init.S new file +50 -0
50 lines not on this page · raw message
arch/arm/mach-mediatek/spl.c new file +43 -0
43 lines not on this page · raw message
board/mediatek/mt7629/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +if TARGET_MT7629 + +config SYS_BOARD + default "mt7629" + +config SYS_CONFIG_NAME + default "mt7629" + +config MTK_SPL_PAD_SIZE + hex + default 0x10000 + +config MTK_BROM_HEADER_INFO + string + default "media=nor" + +endif
board/mediatek/mt7629/MAINTAINERS new file +7 -0
@@ -0,0 +1,7 @@ +MT7629 +M: Ryder Lee <[email protected]> +M: Weijie Gao <[email protected]> +S: Maintained +F: board/mediatek/mt7629 +F: include/configs/mt7629.h +F: configs/mt7629_rfb_defconfig
board/mediatek/mt7629/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += mt7629_rfb.o
board/mediatek/mt7629/mt7629_rfb.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#include <common.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int board_init (void ) +{ +/* address of boot parameters */ + gd->bd->bi_boot_params =CONFIG_SYS_SDRAM_BASE +0x100 ; + +return 0 ; +}
configs/mt7629_rfb_defconfig new file +73 -0
73 lines not on this page · raw message
include/configs/mt7629.h new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 4/18 arm: MediaTek: add basic support for MT7629 boards
Hi Ryder,
Quoted 33 lines · Ryder Lee
This adds a general board file based on MT7629 SoCs from MediaTek.
Apart from the generic parts (cpu) we add some low level init codes and initialize the early clocks.
Signed-off-by Ryder Lee <[email protected]>Signed-off-by Weijie Gao <[email protected]>--- arch/arm/Kconfig | 14 +++ arch/arm/Makefile | 1 + arch/arm/include/asm/arch-mediatek/misc.h | 17 ++++ arch/arm/mach-mediatek/Kconfig | 24 +++++ arch/arm/mach-mediatek/Makefile | 6 ++ arch/arm/mach-mediatek/cpu.c | 34 +++++++ arch/arm/mach-mediatek/init.h | 11 +++ arch/arm/mach-mediatek/mt7629/Makefile | 4 + arch/arm/mach-mediatek/mt7629/init.c | 131 ++++++++++++++++++++++++++ arch/arm/mach-mediatek/mt7629/lowlevel_init.S | 50 ++++++++++ arch/arm/mach-mediatek/spl.c | 43 +++++++++ board/mediatek/mt7629/Kconfig | 17 ++++ board/mediatek/mt7629/MAINTAINERS | 7 ++ board/mediatek/mt7629/Makefile | 3 + board/mediatek/mt7629/mt7629_rfb.c | 16 ++++ configs/mt7629_rfb_defconfig | 73 ++++++++++++++ include/configs/mt7629.h | 62 ++++++++++++ 17 files changed, 513 insertions(+) create mode 100644 arch/arm/include/asm/arch-mediatek/misc.h create mode 100644 arch/arm/mach-mediatek/Kconfig create mode 100644 arch/arm/mach-mediatek/Makefile create mode 100644 arch/arm/mach-mediatek/cpu.c create mode 100644 arch/arm/mach-mediatek/init.h create mode 100644 arch/arm/mach-mediatek/mt7629/Makefile create mode 100644 arch/arm/mach-mediatek/mt7629/init.c
Quoted 8 lines
create mode 100644 arch/arm/mach-mediatek/mt7629/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/spl.c create mode 100644 board/mediatek/mt7629/Kconfig create mode 100644 board/mediatek/mt7629/MAINTAINERS create mode 100644 board/mediatek/mt7629/Makefile create mode 100644 board/mediatek/mt7629/mt7629_rfb.c create mode 100644 configs/mt7629_rfb_defconfig create mode 100644 include/configs/mt7629.h
Looks good. A few nits below
Quoted 10 lines
arch/arm/Kconfig +1
-0@@ -668,6 +668,18 @@ config ARCH_MESON targeted at media players and tablet computers. We currently support the S905 (GXBaby) 64-bit SoC. +config ARCH_MEDIATEK
arch/arm/Kconfig config ARCH_MESON · line 681
Quoted 10 lines
arch/arm/Kconfig +10
-0+ bool "MediaTek SoCs" + select DM + select OF_CONTROL + select SPL_DM if SPL + select SPL_LIBCOMMON_SUPPORT if SPL + select SPL_LIBGENERIC_SUPPORT if SPL + select SPL_OF_CONTROL if SPL + select SUPPORT_SPL + help + Support for the MediaTek SoCs family.
Please add more info. What type of SoCs are these? What are the capabilities? Link to web site? datasheets? wiki? Or maybe point to a doc/README.mediatek?
Quoted 62 lines
arch/arm/Kconfig +3
-0+ config ARCH_MX8M bool "NXP i.MX8M platform" select ARM64@@ -1423,6 +1435,8 @@ source "arch/arm/mach-rmobile/Kconfig" source "arch/arm/mach-meson/Kconfig" +source "arch/arm/mach-mediatek/Kconfig" + source "arch/arm/mach-qemu/Kconfig" source "arch/arm/mach-rockchip/Kconfig"arch/arm/Makefile +1
-0@@ -62,6 +62,7 @@ machine-$(CONFIG_ARCH_K3) += k3 machine-$(CONFIG_ARCH_KEYSTONE) += keystone # TODO: rename CONFIG_KIRKWOOD -> CONFIG_ARCH_KIRKWOOD machine-$(CONFIG_KIRKWOOD) += kirkwood +machine-$(CONFIG_ARCH_MEDIATEK) += mediatek machine-$(CONFIG_ARCH_MESON) += meson machine-$(CONFIG_ARCH_MVEBU) += mvebu # TODO: rename CONFIG_TEGRA -> CONFIG_ARCH_TEGRAarch/arm/include/asm/arch-mediatek/misc.h new file +17
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef __MEDIATEK_MISC_H_ +#define __MEDIATEK_MISC_H_ + +#define VER_BASE 0x08000000 +#define VER_SIZE 0x10 + +#define APHW_CODE 0x00 +#define APHW_SUBCODE 0x04 +#define APHW_VER 0x08 +#define APSW_VER 0x0c + +#endif /* __MEDIATEK_MISC_H_ */ arch/arm/mach-mediatek/Kconfig new file +8
-0@@ -0,0 +1,24 @@ +if ARCH_MEDIATEK + +config SYS_SOC + default "mediatek" + +config SYS_VENDOR + default "mediatek" +
arch/arm/mach-mediatek/Kconfig line 18
Quoted 10 lines
arch/arm/mach-mediatek/Kconfig new file +10
-0+choice + prompt "MediaTek board select" + +config TARGET_MT7629 + bool "MediaTek MT7629 SoC" + select CPU_V7A + select SPL + select ARCH_MISC_INIT + help + Support MediaTek MT7629 SoC.
Please describe the features of this SoC.
Quoted 24 lines
arch/arm/mach-mediatek/Kconfig new file +6
-0+ +endchoice + +source "board/mediatek/mt7629/Kconfig" + +endifarch/arm/mach-mediatek/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += cpu.o +obj-$(CONFIG_SPL_BUILD) += spl.o + +obj-$(CONFIG_TARGET_MT7629) += mt7629/arch/arm/mach-mediatek/cpu.c new file +0
-0
arch/arm/mach-mediatek/cpu.c line 9
Quoted 9 lines
arch/arm/mach-mediatek/cpu.c new file +9
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#include <common.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#include <wdt.h>
dm/ goes after wdt.h
Quoted 63 lines
arch/arm/mach-mediatek/cpu.c new file +25
-0+ +int arch_misc_init (void ) +{ +struct udevice *wdt; +int ret; + + ret =uclass_get_device (UCLASS_WDT ,0 , &wdt); +if (!ret) +wdt_stop (wdt); + +return 0 ; +} + +int arch_cpu_init (void ) +{ +icache_enable (); + +return 0 ; +} + +void enable_caches (void ) +{ +/* Enable D-cache. I-cache is already enabled in start.S */ +dcache_enable (); +}arch/arm/mach-mediatek/init.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef __MEDIATEK_INIT_H_ +#define __MEDIATEK_INIT_H_ + +extern int mtk_soc_early_init (void ); + +#endif /* __MEDIATEK_INIT_H_ */ arch/arm/mach-mediatek/mt7629/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += init.o +obj-y += lowlevel_init.oarch/arm/mach-mediatek/mt7629/init.c new file +5
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +* Author: Ryder Lee <[email protected]> +*/
arch/arm/mach-mediatek/mt7629/init.c line 15
Quoted 10 lines
arch/arm/mach-mediatek/mt7629/init.c new file +10
-0+ +#include <clk.h> +#include <common.h> +#include <dm.h> +#include <dm/uclass.h> +#include <fdtdec.h> +#include <linux/io.h> +#include <ram.h> +#include <asm/arch/misc.h> +#include <asm/sections.h>
fix ordering
Quoted 49 lines
arch/arm/mach-mediatek/mt7629/init.c new file +49
-0+ +#include <dt-bindings/clock/mt7629-clk.h> + +#define L2_SHARE_CFG_MP0 0x7f0 +#define L2_SHARE_MODE_OFF BIT(8) + +DECLARE_GLOBAL_DATA_PTR ; + +int mtk_pll_early_init (void ) +{ +unsigned long pll_rates[] = { + [CLK_APMIXED_ARMPLL ] =1250000000 , + [CLK_APMIXED_MAINPLL ] =1120000000 , + [CLK_APMIXED_UNIV2PLL ] =1200000000 , + [CLK_APMIXED_ETH1PLL ] =500000000 , + [CLK_APMIXED_ETH2PLL ] =700000000 , + [CLK_APMIXED_SGMIPLL ] =650000000 , + }; +struct udevice *dev; +int ret, i; + + ret =uclass_get_device_by_driver (UCLASS_CLK , +DM_GET_DRIVER (mtk_clk_apmixedsys), &dev); +if (ret) +return ret; + +/* configure default rate then enable apmixedsys */ +for (i =0 ; i <ARRAY_SIZE (pll_rates); i++) { +struct clk clk = { .id = i, .dev = dev }; + + ret =clk_set_rate (&clk, pll_rates[i]); +if (ret) +return ret; + + ret =clk_enable (&clk); +if (ret) +return ret; + } + +/* setup mcu bus */ + ret =uclass_get_device_by_driver (UCLASS_SYSCON , +DM_GET_DRIVER (mtk_mcucfg), &dev); +if (ret) +return ret; + +return 0 ; +} + +int mtk_soc_early_init (void )
arch/arm/mach-mediatek/mt7629/init.c line 74
Quoted 10 lines
arch/arm/mach-mediatek/mt7629/init.c new file +10
-0+{ +struct udevice *dev; +int ret; + +/* initialize early clocks */ + ret =mtk_pll_early_init (); +if (ret) +return ret; + + ret =uclass_get_device (UCLASS_RAM ,0 , &dev);
Consider uclass_first_device_err(). Same elsewhere.
arch/arm/mach-mediatek/mt7629/init.c line 87
Quoted 13 lines
arch/arm/mach-mediatek/mt7629/init.c new file +13
-0+if (ret) +return ret; + +return 0 ; +} + +int mach_cpu_init (void ) +{ +void __iomem *base; +int node; + + node =fdt_node_offset_by_compatible (gd->fdt_blob,-1 , +"mediatek,mt7629-mcucfg" );
Add a driver fopr this - don't access it directly. This could be a syscon device perhaps?
arch/arm/mach-mediatek/mt7629/init.c line 88
Quoted 1 line
arch/arm/mach-mediatek/mt7629/init.c new file +1
-0+ base = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, node,"reg" );
dev_read_addr(). Please use the live tree functions.
Quoted 43 lines
arch/arm/mach-mediatek/mt7629/init.c new file +43
-0+if (!base) +return -ENOENT ; + +/* disable L2C shared mode */ +writel (L2_SHARE_MODE_OFF , base +L2_SHARE_CFG_MP0 ); + +return 0 ; +} + +int dram_init (void ) +{ +struct ram_info ram; +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_RAM ,0 , &dev); +if (ret) +return ret; + + ret =ram_get_info (dev, &ram); +if (ret) +return ret; + +debug ("RAM init base=%lx, size=%x\n" , ram.base, ram.size); + + gd->ram_size = ram.size; + +return 0 ; +} + +int print_cpuinfo (void ) +{ +void __iomem *chipid; +u32 hwcode, swver; + + chipid =ioremap (VER_BASE ,VER_SIZE ); + hwcode =readl (chipid +APHW_CODE ); + swver =readl (chipid +APSW_VER ); + +printf ("CPU: MediaTek MT%04x E%d\n" , hwcode, (swver &0xf ) +1 ); + +return 0 ; +}
[..]
Quoted 17 lines
new file mode 100644
index 0000000..83ccbbaboard/mediatek/mt7629/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += mt7629_rfb.oboard/mediatek/mt7629/mt7629_rfb.c new file +3
-0@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc.
board/mediatek/mt7629/mt7629_rfb.c line 13
Quoted 10 lines
board/mediatek/mt7629/mt7629_rfb.c new file +10
-0+*/ + +#include <common.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int board_init (void ) +{ +/* address of boot parameters */ + gd->bd->bi_boot_params =CONFIG_SYS_SDRAM_BASE +0x100 ;
Do we need these?
Quoted 3 lines
board/mediatek/mt7629/mt7629_rfb.c new file +3
-0+ +return 0 ; +}
[..]
Quoted 52 lines
include/configs/mt7629.h new file +46
-0@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Configuration for MediaTek MT7629 SoC +* +* Copyright (C) 2018 MediaTek Inc. +* Author: Ryder Lee <[email protected]> +*/ + +#ifndef __MT7629_H +#define __MT7629_H + +#include <linux/sizes.h> + +/* Miscellaneous configurable options */ +#define CONFIG_SETUP_MEMORY_TAGS +#define CONFIG_INITRD_TAG +#define CONFIG_CMDLINE_TAG + +#define CONFIG_SYS_MAXARGS 8 +#define CONFIG_SYS_BOOTM_LEN SZ_64M +#define CONFIG_SYS_CBSIZE SZ_1K +#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \ + sizeof(CONFIG_SYS_PROMPT) + 16) + +/* Size of malloc() pool */ +#define CONFIG_SYS_MALLOC_LEN SZ_4M + +/* Environment */ +#define CONFIG_ENV_SIZE SZ_4K +/* Allow to overwrite serial and ethaddr */ +#define CONFIG_ENV_OVERWRITE + +/* Defines for SPL */ +#define CONFIG_SPL_STACK 0x106000 +#define CONFIG_SPL_TEXT_BASE 0x201000 +#define CONFIG_SPL_MAX_SIZE SZ_64K +#define CONFIG_SPL_MAX_FOOTPRINT SZ_64K +#define CONFIG_SPL_PAD_TO 0x10000 + +#define CONFIG_SPI_ADDR 0x30000000 +#define CONFIG_SYS_SPI_U_BOOT_OFFS CONFIG_SPL_PAD_TO +#define CONFIG_SYS_UBOOT_BASE (CONFIG_SPI_ADDR + CONFIG_SPL_PAD_TO) + +/* SPL -> Uboot */ +#define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE +#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_TEXT_BASE + SZ_2M - \
include/configs/mt7629.h line 56
Quoted 10 lines
include/configs/mt7629.h new file +10
-0+ GENERATED_GBL_DATA_SIZE) + +/* UBoot -> Kernel */ +#define CONFIG_SYS_SPL_ARGS_ADDR 0x40000000 +#define CONFIG_LOADADDR 0x42007f1c +#define CONFIG_SYS_LOAD_ADDR CONFIG_LOADADDR + +/* Serial device */ +#define CONFIG_SYS_NS16550_CLK 40000000 +#define CONFIG_SYS_NS16550_MEM32
Can you use the device tree for this?
Quoted 9 lines
include/configs/mt7629.h new file +6
-1+#define CONFIG_BAUDRATE 115200 + +/* DRAM */ +#define CONFIG_SYS_SDRAM_BASE 0x40000000 + +#endif --1.9.1
Regards,
Simon
PATCH v2 4/18 arm: MediaTek: add basic support for MT7629 boards
Quoted 491 lines · Simon Glass
Hi Ryder,
Quoted 33 lines · Ryder Lee
This adds a general board file based on MT7629 SoCs from MediaTek.
Apart from the generic parts (cpu) we add some low level init codes and initialize the early clocks.
Signed-off-by Ryder Lee <[email protected]>Signed-off-by Weijie Gao <[email protected]>--- arch/arm/Kconfig | 14 +++ arch/arm/Makefile | 1 + arch/arm/include/asm/arch-mediatek/misc.h | 17 ++++ arch/arm/mach-mediatek/Kconfig | 24 +++++ arch/arm/mach-mediatek/Makefile | 6 ++ arch/arm/mach-mediatek/cpu.c | 34 +++++++ arch/arm/mach-mediatek/init.h | 11 +++ arch/arm/mach-mediatek/mt7629/Makefile | 4 + arch/arm/mach-mediatek/mt7629/init.c | 131 ++++++++++++++++++++++++++ arch/arm/mach-mediatek/mt7629/lowlevel_init.S | 50 ++++++++++ arch/arm/mach-mediatek/spl.c | 43 +++++++++ board/mediatek/mt7629/Kconfig | 17 ++++ board/mediatek/mt7629/MAINTAINERS | 7 ++ board/mediatek/mt7629/Makefile | 3 + board/mediatek/mt7629/mt7629_rfb.c | 16 ++++ configs/mt7629_rfb_defconfig | 73 ++++++++++++++ include/configs/mt7629.h | 62 ++++++++++++ 17 files changed, 513 insertions(+) create mode 100644 arch/arm/include/asm/arch-mediatek/misc.h create mode 100644 arch/arm/mach-mediatek/Kconfig create mode 100644 arch/arm/mach-mediatek/Makefile create mode 100644 arch/arm/mach-mediatek/cpu.c create mode 100644 arch/arm/mach-mediatek/init.h create mode 100644 arch/arm/mach-mediatek/mt7629/Makefile create mode 100644 arch/arm/mach-mediatek/mt7629/init.cQuoted 8 lines
create mode 100644 arch/arm/mach-mediatek/mt7629/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/spl.c create mode 100644 board/mediatek/mt7629/Kconfig create mode 100644 board/mediatek/mt7629/MAINTAINERS create mode 100644 board/mediatek/mt7629/Makefile create mode 100644 board/mediatek/mt7629/mt7629_rfb.c create mode 100644 configs/mt7629_rfb_defconfig create mode 100644 include/configs/mt7629.hLooks good. A few nits below
Quoted 10 lines
arch/arm/Kconfig +1
-0@@ -668,6 +668,18 @@ config ARCH_MESON targeted at media players and tablet computers. We currently support the S905 (GXBaby) 64-bit SoC. +config ARCH_MEDIATEKarch/arm/Kconfig config ARCH_MESON · line 681
Quoted 10 lines
arch/arm/Kconfig +10
-0+ bool "MediaTek SoCs" + select DM + select OF_CONTROL + select SPL_DM if SPL + select SPL_LIBCOMMON_SUPPORT if SPL + select SPL_LIBGENERIC_SUPPORT if SPL + select SPL_OF_CONTROL if SPL + select SUPPORT_SPL + help + Support for the MediaTek SoCs family.Please add more info. What type of SoCs are these? What are the capabilities? Link to web site? datasheets? wiki? Or maybe point to a doc/README.mediatek?
Quoted 62 lines
arch/arm/Kconfig +3
-0+ config ARCH_MX8M bool "NXP i.MX8M platform" select ARM64@@ -1423,6 +1435,8 @@ source "arch/arm/mach-rmobile/Kconfig" source "arch/arm/mach-meson/Kconfig" +source "arch/arm/mach-mediatek/Kconfig" + source "arch/arm/mach-qemu/Kconfig" source "arch/arm/mach-rockchip/Kconfig"arch/arm/Makefile +1
-0@@ -62,6 +62,7 @@ machine-$(CONFIG_ARCH_K3) += k3 machine-$(CONFIG_ARCH_KEYSTONE) += keystone # TODO: rename CONFIG_KIRKWOOD -> CONFIG_ARCH_KIRKWOOD machine-$(CONFIG_KIRKWOOD) += kirkwood +machine-$(CONFIG_ARCH_MEDIATEK) += mediatek machine-$(CONFIG_ARCH_MESON) += meson machine-$(CONFIG_ARCH_MVEBU) += mvebu # TODO: rename CONFIG_TEGRA -> CONFIG_ARCH_TEGRAarch/arm/include/asm/arch-mediatek/misc.h new file +17
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef __MEDIATEK_MISC_H_ +#define __MEDIATEK_MISC_H_ + +#define VER_BASE 0x08000000 +#define VER_SIZE 0x10 + +#define APHW_CODE 0x00 +#define APHW_SUBCODE 0x04 +#define APHW_VER 0x08 +#define APSW_VER 0x0c + +#endif /* __MEDIATEK_MISC_H_ */ arch/arm/mach-mediatek/Kconfig new file +8
-0@@ -0,0 +1,24 @@ +if ARCH_MEDIATEK + +config SYS_SOC + default "mediatek" + +config SYS_VENDOR + default "mediatek" +arch/arm/mach-mediatek/Kconfig line 18
Quoted 10 lines
arch/arm/mach-mediatek/Kconfig new file +10
-0+choice + prompt "MediaTek board select" + +config TARGET_MT7629 + bool "MediaTek MT7629 SoC" + select CPU_V7A + select SPL + select ARCH_MISC_INIT + help + Support MediaTek MT7629 SoC.Please describe the features of this SoC.
Quoted 24 lines
arch/arm/mach-mediatek/Kconfig new file +6
-0+ +endchoice + +source "board/mediatek/mt7629/Kconfig" + +endifarch/arm/mach-mediatek/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += cpu.o +obj-$(CONFIG_SPL_BUILD) += spl.o + +obj-$(CONFIG_TARGET_MT7629) += mt7629/arch/arm/mach-mediatek/cpu.c new file +0
-0arch/arm/mach-mediatek/cpu.c line 9
Quoted 9 lines
arch/arm/mach-mediatek/cpu.c new file +9
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#include <common.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#include <wdt.h> dm/ goes after
wdt.hQuoted 63 lines
arch/arm/mach-mediatek/cpu.c new file +25
-0+ +int arch_misc_init (void ) +{ +struct udevice *wdt; +int ret; + + ret =uclass_get_device (UCLASS_WDT ,0 , &wdt); +if (!ret) +wdt_stop (wdt); + +return 0 ; +} + +int arch_cpu_init (void ) +{ +icache_enable (); + +return 0 ; +} + +void enable_caches (void ) +{ +/* Enable D-cache. I-cache is already enabled in start.S */ +dcache_enable (); +}arch/arm/mach-mediatek/init.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef __MEDIATEK_INIT_H_ +#define __MEDIATEK_INIT_H_ + +extern int mtk_soc_early_init (void ); + +#endif /* __MEDIATEK_INIT_H_ */ arch/arm/mach-mediatek/mt7629/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += init.o +obj-y += lowlevel_init.oarch/arm/mach-mediatek/mt7629/init.c new file +5
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +* Author: Ryder Lee <[email protected]> +*/ arch/arm/mach-mediatek/mt7629/init.c line 15
Quoted 10 lines
arch/arm/mach-mediatek/mt7629/init.c new file +10
-0+ +#include <clk.h> +#include <common.h> +#include <dm.h> +#include <dm/uclass.h> +#include <fdtdec.h> +#include <linux/io.h> +#include <ram.h> +#include <asm/arch/misc.h> +#include <asm/sections.h> fix ordering
Quoted 49 lines
arch/arm/mach-mediatek/mt7629/init.c new file +49
-0+ +#include <dt-bindings/clock/mt7629-clk.h> + +#define L2_SHARE_CFG_MP0 0x7f0 +#define L2_SHARE_MODE_OFF BIT(8) + +DECLARE_GLOBAL_DATA_PTR ; + +int mtk_pll_early_init (void ) +{ +unsigned long pll_rates[] = { + [CLK_APMIXED_ARMPLL ] =1250000000 , + [CLK_APMIXED_MAINPLL ] =1120000000 , + [CLK_APMIXED_UNIV2PLL ] =1200000000 , + [CLK_APMIXED_ETH1PLL ] =500000000 , + [CLK_APMIXED_ETH2PLL ] =700000000 , + [CLK_APMIXED_SGMIPLL ] =650000000 , + }; +struct udevice *dev; +int ret, i; + + ret =uclass_get_device_by_driver (UCLASS_CLK , +DM_GET_DRIVER (mtk_clk_apmixedsys), &dev); +if (ret) +return ret; + +/* configure default rate then enable apmixedsys */ +for (i =0 ; i <ARRAY_SIZE (pll_rates); i++) { +struct clk clk = { .id = i, .dev = dev }; + + ret =clk_set_rate (&clk, pll_rates[i]); +if (ret) +return ret; + + ret =clk_enable (&clk); +if (ret) +return ret; + } + +/* setup mcu bus */ + ret =uclass_get_device_by_driver (UCLASS_SYSCON , +DM_GET_DRIVER (mtk_mcucfg), &dev); +if (ret) +return ret; + +return 0 ; +} + +int mtk_soc_early_init (void )arch/arm/mach-mediatek/mt7629/init.c line 74
Quoted 10 lines
arch/arm/mach-mediatek/mt7629/init.c new file +10
-0+{ +struct udevice *dev; +int ret; + +/* initialize early clocks */ + ret =mtk_pll_early_init (); +if (ret) +return ret; + + ret =uclass_get_device (UCLASS_RAM ,0 , &dev);Consider
uclass_first_device_err(). Same elsewhere.arch/arm/mach-mediatek/mt7629/init.c line 87
Quoted 13 lines
arch/arm/mach-mediatek/mt7629/init.c new file +13
-0+if (ret) +return ret; + +return 0 ; +} + +int mach_cpu_init (void ) +{ +void __iomem *base; +int node; + + node =fdt_node_offset_by_compatible (gd->fdt_blob,-1 , +"mediatek,mt7629-mcucfg" );Add a driver fopr this - don't access it directly. This could be a syscon device perhaps?
arch/arm/mach-mediatek/mt7629/init.c line 88
Quoted 1 line
arch/arm/mach-mediatek/mt7629/init.c new file +1
-0+ base = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, node,"reg" );
dev_read_addr(). Please use the live tree functions.Quoted 43 lines
arch/arm/mach-mediatek/mt7629/init.c new file +43
-0+if (!base) +return -ENOENT ; + +/* disable L2C shared mode */ +writel (L2_SHARE_MODE_OFF , base +L2_SHARE_CFG_MP0 ); + +return 0 ; +} + +int dram_init (void ) +{ +struct ram_info ram; +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_RAM ,0 , &dev); +if (ret) +return ret; + + ret =ram_get_info (dev, &ram); +if (ret) +return ret; + +debug ("RAM init base=%lx, size=%x\n" , ram.base, ram.size); + + gd->ram_size = ram.size; + +return 0 ; +} + +int print_cpuinfo (void ) +{ +void __iomem *chipid; +u32 hwcode, swver; + + chipid =ioremap (VER_BASE ,VER_SIZE ); + hwcode =readl (chipid +APHW_CODE ); + swver =readl (chipid +APSW_VER ); + +printf ("CPU: MediaTek MT%04x E%d\n" , hwcode, (swver &0xf ) +1 ); + +return 0 ; +}[..]
Quoted 17 lines
new file mode 100644
index 0000000..83ccbbaboard/mediatek/mt7629/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += mt7629_rfb.oboard/mediatek/mt7629/mt7629_rfb.c new file +3
-0@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. board/mediatek/mt7629/mt7629_rfb.c line 13
Quoted 10 lines
board/mediatek/mt7629/mt7629_rfb.c new file +10
-0+*/ + +#include <common.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int board_init (void ) +{ +/* address of boot parameters */ + gd->bd->bi_boot_params =CONFIG_SYS_SDRAM_BASE +0x100 ;Do we need these?
Quoted 3 lines
board/mediatek/mt7629/mt7629_rfb.c new file +3
-0+ +return 0 ; +}[..]
Quoted 52 lines
include/configs/mt7629.h new file +46
-0@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Configuration for MediaTek MT7629 SoC +* +* Copyright (C) 2018 MediaTek Inc. +* Author: Ryder Lee <[email protected]> +*/ + +#ifndef __MT7629_H +#define __MT7629_H + +#include <linux/sizes.h> + +/* Miscellaneous configurable options */ +#define CONFIG_SETUP_MEMORY_TAGS +#define CONFIG_INITRD_TAG +#define CONFIG_CMDLINE_TAG + +#define CONFIG_SYS_MAXARGS 8 +#define CONFIG_SYS_BOOTM_LEN SZ_64M +#define CONFIG_SYS_CBSIZE SZ_1K +#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \ + sizeof(CONFIG_SYS_PROMPT) + 16) + +/* Size of malloc() pool */ +#define CONFIG_SYS_MALLOC_LEN SZ_4M + +/* Environment */ +#define CONFIG_ENV_SIZE SZ_4K +/* Allow to overwrite serial and ethaddr */ +#define CONFIG_ENV_OVERWRITE + +/* Defines for SPL */ +#define CONFIG_SPL_STACK 0x106000 +#define CONFIG_SPL_TEXT_BASE 0x201000 +#define CONFIG_SPL_MAX_SIZE SZ_64K +#define CONFIG_SPL_MAX_FOOTPRINT SZ_64K +#define CONFIG_SPL_PAD_TO 0x10000 + +#define CONFIG_SPI_ADDR 0x30000000 +#define CONFIG_SYS_SPI_U_BOOT_OFFS CONFIG_SPL_PAD_TO +#define CONFIG_SYS_UBOOT_BASE (CONFIG_SPI_ADDR + CONFIG_SPL_PAD_TO) + +/* SPL -> Uboot */ +#define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE +#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_TEXT_BASE + SZ_2M - \include/configs/mt7629.h line 56
Quoted 10 lines
include/configs/mt7629.h new file +10
-0+ GENERATED_GBL_DATA_SIZE) + +/* UBoot -> Kernel */ +#define CONFIG_SYS_SPL_ARGS_ADDR 0x40000000 +#define CONFIG_LOADADDR 0x42007f1c +#define CONFIG_SYS_LOAD_ADDR CONFIG_LOADADDR + +/* Serial device */ +#define CONFIG_SYS_NS16550_CLK 40000000 +#define CONFIG_SYS_NS16550_MEM32 Can you use the device tree for this?
Quoted 9 lines
Quoted 9 lines
include/configs/mt7629.h new file +6
-1+#define CONFIG_BAUDRATE 115200 + +/* DRAM */ +#define CONFIG_SYS_SDRAM_BASE 0x40000000 + +#endif --1.9.1
I will fix these in v3.
Ryder
PATCH v2 5/18 arm: MediaTek: add basic support for MT7623 boards
In reply to Ryder LeeFrom: Weijie Gao <[email protected]>
This adds a general board file based on MT7623 SoCs from MediaTek.
As this u-boot is loaded by preloader, there is no low level initializtion codes.
--- arch/arm/mach-mediatek/Kconfig | 8 +++ arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7623/Makefile | 4 ++ arch/arm/mach-mediatek/mt7623/init.c | 54 +++++++++++++++ arch/arm/mach-mediatek/mt7623/lowlevel_init.S | 22 ++++++ arch/arm/mach-mediatek/mt7623/preloader.h | 99 +++++++++++++++++++++++++++ board/mediatek/mt7623/Kconfig | 13 ++++ board/mediatek/mt7623/MAINTAINERS | 7 ++ board/mediatek/mt7623/Makefile | 3 + board/mediatek/mt7623/mt7623_rfb.c | 16 +++++ configs/mt7623n_bpir2_defconfig | 53 ++++++++++++++ include/configs/mt7623.h | 61 +++++++++++++++++ 12 files changed, 341 insertions(+) create mode 100644 arch/arm/mach-mediatek/mt7623/Makefile create mode 100644 arch/arm/mach-mediatek/mt7623/init.c create mode 100644 arch/arm/mach-mediatek/mt7623/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/mt7623/preloader.h create mode 100644 board/mediatek/mt7623/Kconfig create mode 100644 board/mediatek/mt7623/MAINTAINERS create mode 100644 board/mediatek/mt7623/Makefile create mode 100644 board/mediatek/mt7623/mt7623_rfb.c create mode 100644 configs/mt7623n_bpir2_defconfig create mode 100644 include/configs/mt7623.h
arch/arm/mach-mediatek/Kconfig +8 -0
@@ -9,6 +9,13 @@ config SYS_VENDOR choice prompt "MediaTek board select" +config TARGET_MT7623 + bool "MediaTek MT7623 SoC" + select CPU_V7A + select ARCH_MISC_INIT + help + Support MediaTek MT7623 SoC. + config TARGET_MT7629 bool "MediaTek MT7629 SoC" select CPU_V7A
@@ -19,6 +26,7 @@ config TARGET_MT7629 endchoice +source "board/mediatek/mt7623/Kconfig" source "board/mediatek/mt7629/Kconfig" endif
arch/arm/mach-mediatek/Makefile +1 -0
@@ -3,4 +3,5 @@ obj-y += cpu.o obj-$(CONFIG_SPL_BUILD) += spl.o +obj-$(CONFIG_TARGET_MT7623) += mt7623/ obj-$(CONFIG_TARGET_MT7629) += mt7629/
arch/arm/mach-mediatek/mt7623/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += init.o +obj-y += lowlevel_init.o
arch/arm/mach-mediatek/mt7623/init.c new file +54 -0
54 lines not on this page · raw message
arch/arm/mach-mediatek/mt7623/lowlevel_init.S new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2018 MediaTek Inc. + */ + +#include <linux/linkage.h> + +.extern preloader_param + +ENTRY(save_boot_params) + ldr r6, =preloader_param + str r4, [r6] + b save_boot_params_ret +ENDPROC(save_boot_params) + +ENTRY(lowlevel_init) + /* enable SMP bit */ + mrc p15, 0, r0, c1, c0, 1 + orr r0, r0, #0x40 + mcr p15, 0, r0, c1, c0, 1 + mov pc, lr +ENDPROC(lowlevel_init)
arch/arm/mach-mediatek/mt7623/preloader.h new file +99 -0
99 lines not on this page · raw message
board/mediatek/mt7623/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +if TARGET_MT7623 + +config SYS_BOARD + default "mt7623" + +config SYS_CONFIG_NAME + default "mt7623" + +config MTK_BROM_HEADER_INFO + string + default "lk=1" + +endif
board/mediatek/mt7623/MAINTAINERS new file +7 -0
@@ -0,0 +1,7 @@ +MT7623 +M: Ryder Lee <[email protected]> +M: Weijie Gao <[email protected]> +S: Maintained +F: board/mediatek/mt7623 +F: include/configs/mt7623.h +F: configs/mt7623n_bpir2_defconfig
board/mediatek/mt7623/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += mt7623_rfb.o
board/mediatek/mt7623/mt7623_rfb.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#include <common.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int board_init (void ) +{ +/* address of boot parameters */ + gd->bd->bi_boot_params =CONFIG_SYS_SDRAM_BASE +0x100 ; + +return 0 ; +}
configs/mt7623n_bpir2_defconfig new file +53 -0
53 lines not on this page · raw message
include/configs/mt7623.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 5/18 arm: MediaTek: add basic support for MT7623 boards
Hi,
Quoted 26 lines · Ryder Lee
From: Weijie Gao <[email protected]>
This adds a general board file based on MT7623 SoCs from MediaTek.
As this u-boot is loaded by preloader, there is no low level initializtion codes.
Signed-off-by Weijie Gao <[email protected]>Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- arch/arm/mach-mediatek/Kconfig | 8 +++ arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7623/Makefile | 4 ++ arch/arm/mach-mediatek/mt7623/init.c | 54 +++++++++++++++ arch/arm/mach-mediatek/mt7623/lowlevel_init.S | 22 ++++++ arch/arm/mach-mediatek/mt7623/preloader.h | 99 +++++++++++++++++++++++++++ board/mediatek/mt7623/Kconfig | 13 ++++ board/mediatek/mt7623/MAINTAINERS | 7 ++ board/mediatek/mt7623/Makefile | 3 + board/mediatek/mt7623/mt7623_rfb.c | 16 +++++ configs/mt7623n_bpir2_defconfig | 53 ++++++++++++++ include/configs/mt7623.h | 61 +++++++++++++++++ 12 files changed, 341 insertions(+) create mode 100644 arch/arm/mach-mediatek/mt7623/Makefile create mode 100644 arch/arm/mach-mediatek/mt7623/init.c
Quoted 9 lines
create mode 100644 arch/arm/mach-mediatek/mt7623/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/mt7623/preloader.h create mode 100644 board/mediatek/mt7623/Kconfig create mode 100644 board/mediatek/mt7623/MAINTAINERS create mode 100644 board/mediatek/mt7623/Makefile create mode 100644 board/mediatek/mt7623/mt7623_rfb.c create mode 100644 configs/mt7623n_bpir2_defconfig create mode 100644 include/configs/mt7623.h
There is a new SPL handoff and bloblist feature that I hope will land in the next release. Can you please look at using this instead of an SoC-specififc mechanism?
See u-boot-dm/spl-working
Regards,
Simon
PATCH v2 5/18 arm: MediaTek: add basic support for MT7623 boards
Quoted 39 lines · Simon Glass
Hi,
Quoted 26 lines · Ryder Lee
From: Weijie Gao <[email protected]>
This adds a general board file based on MT7623 SoCs from MediaTek.
As this u-boot is loaded by preloader, there is no low level initializtion codes.
Signed-off-by Weijie Gao <[email protected]>Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- arch/arm/mach-mediatek/Kconfig | 8 +++ arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7623/Makefile | 4 ++ arch/arm/mach-mediatek/mt7623/init.c | 54 +++++++++++++++ arch/arm/mach-mediatek/mt7623/lowlevel_init.S | 22 ++++++ arch/arm/mach-mediatek/mt7623/preloader.h | 99 +++++++++++++++++++++++++++ board/mediatek/mt7623/Kconfig | 13 ++++ board/mediatek/mt7623/MAINTAINERS | 7 ++ board/mediatek/mt7623/Makefile | 3 + board/mediatek/mt7623/mt7623_rfb.c | 16 +++++ configs/mt7623n_bpir2_defconfig | 53 ++++++++++++++ include/configs/mt7623.h | 61 +++++++++++++++++ 12 files changed, 341 insertions(+) create mode 100644 arch/arm/mach-mediatek/mt7623/Makefile create mode 100644 arch/arm/mach-mediatek/mt7623/init.cQuoted 9 lines
create mode 100644 arch/arm/mach-mediatek/mt7623/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/mt7623/preloader.h create mode 100644 board/mediatek/mt7623/Kconfig create mode 100644 board/mediatek/mt7623/MAINTAINERS create mode 100644 board/mediatek/mt7623/Makefile create mode 100644 board/mediatek/mt7623/mt7623_rfb.c create mode 100644 configs/mt7623n_bpir2_defconfig create mode 100644 include/configs/mt7623.h
Quoted 5 lines
There is a new SPL handoff and bloblist feature that I hope will land in the next release. Can you please look at using this instead of an SoC-specififc mechanism?
See u-boot-dm/spl-working
Okay, I will take a look at this.
Ryder
PATCH v2 6/18 clk: MediaTek: add clock driver for MT7629 SoC.
In reply to Ryder LeeThis patch adds clock modules for MediaTek SoCs:
- Shared part: a common driver which contains the general operations for plls, muxes, dividers and gates so that we can reuse it in future.
- Specific SoC part: the group of structures used to hold the hardware configuration for each SoC.
We take MT7629 as an example to demonstrate how to implement driver if any other MediaTek chips would like to use it.
--- drivers/clk/Makefile | 1 + drivers/clk/mediatek/Makefile | 6 + drivers/clk/mediatek/clk-mt7629.c | 709 ++++++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.c | 492 ++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 153 ++++++++ 5 files changed, 1361 insertions(+) create mode 100644 drivers/clk/mediatek/Makefile create mode 100644 drivers/clk/mediatek/clk-mt7629.c create mode 100644 drivers/clk/mediatek/clk-mtk.c create mode 100644 drivers/clk/mediatek/clk-mtk.h
drivers/clk/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_$(SPL_TPL_)CLK) += clk-uclass.o clk_fixed_rate.o obj-y += tegra/ obj-$(CONFIG_ARCH_ASPEED) += aspeed/ obj-$(CONFIG_ARCH_MESON) += clk_meson.o +obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ obj-$(CONFIG_ARCH_SOCFPGA) += altera/ obj-$(CONFIG_CLK_AT91) += at91/
drivers/clk/mediatek/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# Core +obj-$(CONFIG_ARCH_MEDIATEK) += clk-mtk.o + +# SoC Drivers +obj-$(CONFIG_TARGET_MT7629) += clk-mt7629.o
drivers/clk/mediatek/clk-mt7629.c new file +709 -0
709 lines not on this page · raw message
drivers/clk/mediatek/clk-mtk.c new file +492 -0
492 lines not on this page · raw message
drivers/clk/mediatek/clk-mtk.h new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 6/18 clk: MediaTek: add clock driver for MT7629 SoC.
Hi Ryder,
Quoted 11 lines · Ryder Lee
This patch adds clock modules for MediaTek SoCs:
- Shared part: a common driver which contains the general operations for plls, muxes, dividers and gates so that we can reuse it in future.- Specific SoC part: the group of structures used to hold the hardware configuration for each SoC.
We take MT7629 as an example to demonstrate how to implement driver if any other MediaTek chips would like to use it.
Signed-off-by Ryder Lee <[email protected]>
Quoted 11 lines
--- drivers/clk/Makefile | 1 + drivers/clk/mediatek/Makefile | 6 + drivers/clk/mediatek/clk-mt7629.c | 709 ++++++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.c | 492 ++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 153 ++++++++ 5 files changed, 1361 insertions(+) create mode 100644 drivers/clk/mediatek/Makefile create mode 100644 drivers/clk/mediatek/clk-mt7629.c create mode 100644 drivers/clk/mediatek/clk-mtk.c create mode 100644 drivers/clk/mediatek/clk-mtk.h
Looks good except for a few things below.
[..]
drivers/clk/mediatek/clk-mtk.c line 471
Quoted 13 lines
drivers/clk/mediatek/clk-mtk.c new file +13
-0+const struct clk_ops mtk_clk_gate_ops = { + .enable = mtk_clk_gate_enable, + .disable = mtk_clk_gate_disable, + .get_rate = mtk_clk_gate_get_rate, +}; + +int mtk_clk_init (struct udevice *dev,const struct mtk_clk_tree *tree) +{ +struct mtk_clk_priv *priv =dev_get_priv (dev); + + priv->base =dev_read_addr_ptr (dev); +if (!priv->base) +return -ENOENT ;
Why do you export these two functions? Devices should be probed in the normal DM way.
Quoted 11 lines
drivers/clk/mediatek/clk-mtk.c new file +11
-0+ + priv->tree = tree; + +return 0 ; +} + +int mtk_clk_gate_init (struct udevice *dev, +const struct mtk_clk_tree *tree, +const struct mtk_gate *gates) +{ +struct mtk_cg_priv *priv =dev_get_priv (dev);
drivers/clk/mediatek/clk-mtk.c line 492
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.c new file +10
-0+ + priv->base =dev_read_addr_ptr (dev); +if (!priv->base) +return -ENOENT ; + + priv->tree = tree; + priv->gates = gates; + +return 0 ; +}
[...]
Regards,
Simon
PATCH v2 6/18 clk: MediaTek: add clock driver for MT7629 SoC.
Quoted 30 lines · Simon Glass
Hi Ryder,
Quoted 11 lines · Ryder Lee
This patch adds clock modules for MediaTek SoCs:
- Shared part: a common driver which contains the general operations for plls, muxes, dividers and gates so that we can reuse it in future.- Specific SoC part: the group of structures used to hold the hardware configuration for each SoC.
We take MT7629 as an example to demonstrate how to implement driver if any other MediaTek chips would like to use it.
Signed-off-by Ryder Lee <[email protected]>Quoted 11 lines
--- drivers/clk/Makefile | 1 + drivers/clk/mediatek/Makefile | 6 + drivers/clk/mediatek/clk-mt7629.c | 709 ++++++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.c | 492 ++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 153 ++++++++ 5 files changed, 1361 insertions(+) create mode 100644 drivers/clk/mediatek/Makefile create mode 100644 drivers/clk/mediatek/clk-mt7629.c create mode 100644 drivers/clk/mediatek/clk-mtk.c create mode 100644 drivers/clk/mediatek/clk-mtk.hLooks good except for a few things below.
[..]
Quoted 16 lines
drivers/clk/mediatek/clk-mtk.c line 471
Quoted 13 lines
drivers/clk/mediatek/clk-mtk.c new file +13
-0+const struct clk_ops mtk_clk_gate_ops = { + .enable = mtk_clk_gate_enable, + .disable = mtk_clk_gate_disable, + .get_rate = mtk_clk_gate_get_rate, +}; + +int mtk_clk_init (struct udevice *dev,const struct mtk_clk_tree *tree) +{ +struct mtk_clk_priv *priv =dev_get_priv (dev); + + priv->base =dev_read_addr_ptr (dev); +if (!priv->base) +return -ENOENT ;Why do you export these two functions? Devices should be probed in the normal DM way.
Yes, they are probed in the normal way. These functions are used by several clock blocks and MTK SoCs. so I put the common parts here to keep the code as clean as possible.
ex:
static int mt7629_apmixedsys_probe(struct udevice *dev)
{
...
ret = mtk_clk_init(...);
/* reduce clock square disable time */
writel(...);
...}
static int mt7629_topckgen_probe(struct udevice *dev)
{
return mtk_clk_init(...);
}Quoted 26 lines
Quoted 11 lines
drivers/clk/mediatek/clk-mtk.c new file +11
-0+ + priv->tree = tree; + +return 0 ; +} + +int mtk_clk_gate_init (struct udevice *dev, +const struct mtk_clk_tree *tree, +const struct mtk_gate *gates) +{ +struct mtk_cg_priv *priv =dev_get_priv (dev);drivers/clk/mediatek/clk-mtk.c line 492
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.c new file +10
-0+ + priv->base =dev_read_addr_ptr (dev); +if (!priv->base) +return -ENOENT ; + + priv->tree = tree; + priv->gates = gates; + +return 0 ; +}[...]
Regards,
Simon
PATCH v2 6/18 clk: MediaTek: add clock driver for MT7629 SoC.
Hi Ryder,
Quoted 48 lines · Ryder Lee
Quoted 30 lines · Simon Glass
Hi Ryder,
Quoted 11 lines · Ryder Lee
This patch adds clock modules for MediaTek SoCs:
- Shared part: a common driver which contains the general operations for plls, muxes, dividers and gates so that we can reuse it in future.- Specific SoC part: the group of structures used to hold the hardware configuration for each SoC.
We take MT7629 as an example to demonstrate how to implement driver if any other MediaTek chips would like to use it.
Signed-off-by Ryder Lee <[email protected]>Quoted 11 lines
--- drivers/clk/Makefile | 1 + drivers/clk/mediatek/Makefile | 6 + drivers/clk/mediatek/clk-mt7629.c | 709 ++++++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.c | 492 ++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 153 ++++++++ 5 files changed, 1361 insertions(+) create mode 100644 drivers/clk/mediatek/Makefile create mode 100644 drivers/clk/mediatek/clk-mt7629.c create mode 100644 drivers/clk/mediatek/clk-mtk.c create mode 100644 drivers/clk/mediatek/clk-mtk.hLooks good except for a few things below.
[..]
Quoted 16 lines
drivers/clk/mediatek/clk-mtk.c line 471
Quoted 13 lines
drivers/clk/mediatek/clk-mtk.c new file +13
-0+const struct clk_ops mtk_clk_gate_ops = { + .enable = mtk_clk_gate_enable, + .disable = mtk_clk_gate_disable, + .get_rate = mtk_clk_gate_get_rate, +}; + +int mtk_clk_init (struct udevice *dev,const struct mtk_clk_tree *tree) +{ +struct mtk_clk_priv *priv =dev_get_priv (dev); + + priv->base =dev_read_addr_ptr (dev); +if (!priv->base) +return -ENOENT ;Why do you export these two functions? Devices should be probed in the normal DM way.
Quoted 3 lines
Yes, they are probed in the normal way. These functions are used by several clock blocks and MTK SoCs. so I put the common parts here to keep the code as clean as possible.
OK I see, thank you. How about a _common suffix on the function to make this clear?
Regards,
Simon
PATCH v2 7/18 clk: MediaTek: add clock driver for MT7623 SoC.
In reply to Ryder LeeThis patch adds a driver for MT7623 clock blocks.
--- drivers/clk/mediatek/Makefile | 1 + drivers/clk/mediatek/clk-mt7623.c | 870 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 871 insertions(+) create mode 100644 drivers/clk/mediatek/clk-mt7623.c
drivers/clk/mediatek/Makefile +1 -0
@@ -3,4 +3,5 @@ obj-$(CONFIG_ARCH_MEDIATEK) += clk-mtk.o # SoC Drivers +obj-$(CONFIG_TARGET_MT7623) += clk-mt7623.o obj-$(CONFIG_TARGET_MT7629) += clk-mt7629.o
drivers/clk/mediatek/clk-mt7623.c new file +870 -0
870 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 7/18 clk: MediaTek: add clock driver for MT7623 SoC.
Quoted 9 lines · Ryder Lee
This patch adds a driver for MT7623 clock blocks.
Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- drivers/clk/mediatek/Makefile | 1 + drivers/clk/mediatek/clk-mt7623.c | 870 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 871 insertions(+) create mode 100644 drivers/clk/mediatek/clk-mt7623.c
PATCH v2 8/18 timer: MediaTek: add timer driver for MediaTek SoCs
In reply to Ryder LeeThis patch adds clock source and clock event for the timer found on the Mediatek SoCs.
--- drivers/timer/Kconfig | 7 ++++ drivers/timer/Makefile | 1 + drivers/timer/mtk_timer.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 drivers/timer/mtk_timer.c
drivers/timer/Kconfig +7 -0
@@ -147,4 +147,11 @@ config MPC83XX_TIMER Select this to enable support for the timer found on devices based on the MPC83xx family of SoCs. +config MTK_TIMER + bool "MediaTek timer support" + depends on TIMER + help + Select this to enable support for the timer found on + MediaTek devices. + endmenu
drivers/timer/Makefile +1 -0
@@ -18,3 +18,4 @@ obj-$(CONFIG_SANDBOX_TIMER) += sandbox_timer.o obj-$(CONFIG_STI_TIMER) += sti-timer.o obj-$(CONFIG_STM32_TIMER) += stm32_timer.o obj-$(CONFIG_X86_TSC_TIMER) += tsc_timer.o +obj-$(CONFIG_MTK_TIMER) += mtk_timer.o
drivers/timer/mtk_timer.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 8/18 timer: MediaTek: add timer driver for MediaTek SoCs
Quoted 11 lines · Ryder Lee
This patch adds clock source and clock event for the timer found on the Mediatek SoCs.
Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- drivers/timer/Kconfig | 7 ++++ drivers/timer/Makefile | 1 + drivers/timer/mtk_timer.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 drivers/timer/mtk_timer.c
Consider supporting the early timer too so you can use bootstage.
PATCH v2 9/18 watchdog: MediaTek: add watchdog driver for MediaTek SoCs
In reply to Ryder LeeThis patch adds a common driver for the Mediatek SoC integrated watchdog.
--- drivers/watchdog/Kconfig | 8 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/mtk_wdt.c | 135 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 drivers/watchdog/mtk_wdt.c
drivers/watchdog/Kconfig +8 -0
@@ -103,6 +103,14 @@ config WDT_CDNS Select this to enable Cadence watchdog timer, which can be found on some Xilinx Microzed Platform. +config WDT_MTK + bool "MediaTek watchdog timer support" + depends on WDT && ARCH_MEDIATEK + help + Select this to enable watchdog timer for MediaTek SoCs. + The watchdog timer is stopped when initialized. + It performs full SoC reset. + config XILINX_TB_WATCHDOG bool "Xilinx Axi watchdog timer support" depends on WDT
drivers/watchdog/Makefile +1 -0
@@ -23,3 +23,4 @@ obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o obj-$(CONFIG_MPC8xx_WATCHDOG) += mpc8xx_wdt.o +obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
drivers/watchdog/mtk_wdt.c new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 9/18 watchdog: MediaTek: add watchdog driver for MediaTek SoCs
Quoted 11 lines · Ryder Lee
This patch adds a common driver for the Mediatek SoC integrated watchdog.
Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- drivers/watchdog/Kconfig | 8 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/mtk_wdt.c | 135 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 drivers/watchdog/mtk_wdt.c
PATCH v2 10/18 pinctrl: MediaTek: add pinctrl driver for MT7629 SoC
In reply to Ryder LeeThis patch adds pinctrl support for MT7629 SoC. The IO core found on the SoC has the registers for pinctrl, pinconf and gpio mixed up in the same register range. Hence the driver also implements the gpio functionality through UCLASS_GPIO.
This also creates a common file as there might be other chips that use the same binding and driver, then being a little more abstract could help in the long run.
--- arch/arm/include/asm/arch-mediatek/gpio.h | 9 + drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/mediatek/Kconfig | 11 + drivers/pinctrl/mediatek/Makefile | 6 + drivers/pinctrl/mediatek/pinctrl-mt7629.c | 488 +++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 552 ++++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 182 +++++++++ 8 files changed, 1250 insertions(+) create mode 100644 arch/arm/include/asm/arch-mediatek/gpio.h create mode 100644 drivers/pinctrl/mediatek/Kconfig create mode 100644 drivers/pinctrl/mediatek/Makefile create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7629.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.h
arch/arm/include/asm/arch-mediatek/gpio.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 MediaTek Inc. +*/ + +#ifndef __MEDIATEK_GPIO_H +#define __MEDIATEK_GPIO_H + +#endif /* __MEDIATEK_GPIO_H */
drivers/pinctrl/Kconfig +1 -0
@@ -301,6 +301,7 @@ config ASPEED_AST2500_PINCTRL endif source "drivers/pinctrl/meson/Kconfig" +source "drivers/pinctrl/mediatek/Kconfig" source "drivers/pinctrl/nxp/Kconfig" source "drivers/pinctrl/renesas/Kconfig" source "drivers/pinctrl/uniphier/Kconfig"
drivers/pinctrl/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_PINCTRL_UNIPHIER) += uniphier/ obj-$(CONFIG_PINCTRL_PIC32) += pinctrl_pic32.o obj-$(CONFIG_PINCTRL_EXYNOS) += exynos/ obj-$(CONFIG_PINCTRL_MESON) += meson/ +obj-$(CONFIG_PINCTRL_MTK) += mediatek/ obj-$(CONFIG_ARCH_MVEBU) += mvebu/ obj-$(CONFIG_PINCTRL_SINGLE) += pinctrl-single.o obj-$(CONFIG_PINCTRL_STI) += pinctrl-sti.o
drivers/pinctrl/mediatek/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +if ARCH_MEDIATEK + +config PINCTRL_MTK + depends on PINCTRL_GENERIC + bool + +config PINCTRL_MT7629 + bool "MT7629 SoC pinctrl driver" + select PINCTRL_MTK + +endif
drivers/pinctrl/mediatek/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# Core +obj-$(CONFIG_PINCTRL_MTK) += pinctrl-mtk-common.o + +# SoC Drivers +obj-$(CONFIG_PINCTRL_MT7629) += pinctrl-mt7629.o
drivers/pinctrl/mediatek/pinctrl-mt7629.c new file +488 -0
488 lines not on this page · raw message
drivers/pinctrl/mediatek/pinctrl-mtk-common.c new file +552 -0
552 lines not on this page · raw message
drivers/pinctrl/mediatek/pinctrl-mtk-common.h new file +182 -0
182 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 10/18 pinctrl: MediaTek: add pinctrl driver for MT7629 SoC
Hi Ryder,
Quoted 27 lines · Ryder Lee
This patch adds pinctrl support for MT7629 SoC. The IO core found on the SoC has the registers for pinctrl, pinconf and gpio mixed up in the same register range. Hence the driver also implements the gpio functionality through
UCLASS_GPIO.This also creates a common file as there might be other chips that use the same binding and driver, then being a little more abstract could help in the long run.
Signed-off-by Ryder Lee <[email protected]>--- arch/arm/include/asm/arch-mediatek/gpio.h | 9 + drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/mediatek/Kconfig | 11 + drivers/pinctrl/mediatek/Makefile | 6 + drivers/pinctrl/mediatek/pinctrl-mt7629.c | 488 +++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 552 ++++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 182 +++++++++ 8 files changed, 1250 insertions(+) create mode 100644 arch/arm/include/asm/arch-mediatek/gpio.h create mode 100644 drivers/pinctrl/mediatek/Kconfig create mode 100644 drivers/pinctrl/mediatek/Makefile create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7629.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.h
[..]
Quoted 7 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c new file +7
-0+int mtk_pinctrl_probe (struct udevice *dev,struct mtk_pinctrl_soc *soc) +{ +struct mtk_pinctrl_priv *priv =dev_get_priv (dev); +int ret; + + priv->base =dev_read_addr_ptr (dev); +if (priv->base == (void *)FDT_ADDR_T_NONE )
drivers/pinctrl/mediatek/pinctrl-mtk-common.c line 552
Quoted 10 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c new file +10
-0+return -EINVAL ; + + priv->soc = soc; + + ret =mtk_gpiochip_register (dev); +if (ret) +return ret; + +return 0 ; +}
How come this function is exported? It should be probed like any other driver.
Regards,
Simon
PATCH v2 10/18 pinctrl: MediaTek: add pinctrl driver for MT7629 SoC
Hi Simon,
Quoted 44 lines · Simon Glass
Hi Ryder,
Quoted 27 lines · Ryder Lee
This patch adds pinctrl support for MT7629 SoC. The IO core found on the SoC has the registers for pinctrl, pinconf and gpio mixed up in the same register range. Hence the driver also implements the gpio functionality through
UCLASS_GPIO.This also creates a common file as there might be other chips that use the same binding and driver, then being a little more abstract could help in the long run.
Signed-off-by Ryder Lee <[email protected]>--- arch/arm/include/asm/arch-mediatek/gpio.h | 9 + drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/mediatek/Kconfig | 11 + drivers/pinctrl/mediatek/Makefile | 6 + drivers/pinctrl/mediatek/pinctrl-mt7629.c | 488 +++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 552 ++++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 182 +++++++++ 8 files changed, 1250 insertions(+) create mode 100644 arch/arm/include/asm/arch-mediatek/gpio.h create mode 100644 drivers/pinctrl/mediatek/Kconfig create mode 100644 drivers/pinctrl/mediatek/Makefile create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7629.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.h[..]
Quoted 11 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c new file +11
-0+int mtk_pinctrl_probe (struct udevice *dev,struct mtk_pinctrl_soc *soc) +{ +struct mtk_pinctrl_priv *priv =dev_get_priv (dev); +int ret; + + priv->base =dev_read_addr_ptr (dev); +if (priv->base == (void *)FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->soc = soc; +
Quoted 8 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c line 552
Quoted 6 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c new file +6
-0+ ret =mtk_gpiochip_register (dev); +if (ret) +return ret; + +return 0 ; +}How come this function is exported? It should be probed like any other driver.
It makes no difference. We could reuse it for other MTK chips in this way.
In pinctrl-mt7623.c (patch 11/18):
static int mtk_pinctrl_mt7623_probe(struct udevice *dev) {
//common probed function
mtk_pinctrl_probe(dev, &mt7623_data);
//proprietary operations for the chip....
mt7623_bonding_disable(dev);
....
}The similar usage is meson_pinctrl_probe() in pinctrl-meson.c
Ryder
PATCH v2 10/18 pinctrl: MediaTek: add pinctrl driver for MT7629 SoC
Hi Ryder,
Quoted 65 lines · Ryder Lee
Hi Simon,
Quoted 44 lines · Simon Glass
Hi Ryder,
Quoted 27 lines · Ryder Lee
This patch adds pinctrl support for MT7629 SoC. The IO core found on the SoC has the registers for pinctrl, pinconf and gpio mixed up in the same register range. Hence the driver also implements the gpio functionality through
UCLASS_GPIO.This also creates a common file as there might be other chips that use the same binding and driver, then being a little more abstract could help in the long run.
Signed-off-by Ryder Lee <[email protected]>--- arch/arm/include/asm/arch-mediatek/gpio.h | 9 + drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/mediatek/Kconfig | 11 + drivers/pinctrl/mediatek/Makefile | 6 + drivers/pinctrl/mediatek/pinctrl-mt7629.c | 488 +++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 552 ++++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 182 +++++++++ 8 files changed, 1250 insertions(+) create mode 100644 arch/arm/include/asm/arch-mediatek/gpio.h create mode 100644 drivers/pinctrl/mediatek/Kconfig create mode 100644 drivers/pinctrl/mediatek/Makefile create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7629.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-common.h[..]
Quoted 11 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c new file +11
-0+int mtk_pinctrl_probe (struct udevice *dev,struct mtk_pinctrl_soc *soc) +{ +struct mtk_pinctrl_priv *priv =dev_get_priv (dev); +int ret; + + priv->base =dev_read_addr_ptr (dev); +if (priv->base == (void *)FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->soc = soc; +Quoted 8 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c line 552
Quoted 6 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common.c new file +6
-0+ ret =mtk_gpiochip_register (dev); +if (ret) +return ret; + +return 0 ; +}How come this function is exported? It should be probed like any other driver.
It makes no difference. We could reuse it for other MTK chips in this way.
In
pinctrl-mt7623.c(patch 11/18):static int
mtk_pinctrl_mt7623_probe(struct udevice *dev){//common probed function
Quoted 8 lines
mtk_pinctrl_probe(dev, &mt7623_data);//proprietary operations for the chip....
mt7623_bonding_disable(dev); .... }The similar usage is
meson_pinctrl_probe()inpinctrl-meson.c
OK I see, so it is a common function called by all probe functions?
In that case, can it have a _common suffix?
Regards,
Simon
PATCH v2 11/18 pinctrl: MediaTek: add pinctrl driver for MT7623 SoC
In reply to Ryder LeeThis patch adds pinctrl support for MT7623 SoC. And most of the structures are used to hold the hardware configuration for each pin.
--- drivers/pinctrl/mediatek/Kconfig | 4 + drivers/pinctrl/mediatek/Makefile | 1 + drivers/pinctrl/mediatek/pinctrl-mt7623.c | 1284 +++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 1 + 4 files changed, 1290 insertions(+) create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7623.c
drivers/pinctrl/mediatek/Kconfig +4 -0
@@ -4,6 +4,10 @@ config PINCTRL_MTK depends on PINCTRL_GENERIC bool +config PINCTRL_MT7623 + bool "MT7623 SoC pinctrl driver" + select PINCTRL_MTK + config PINCTRL_MT7629 bool "MT7629 SoC pinctrl driver" select PINCTRL_MTK
drivers/pinctrl/mediatek/Makefile +1 -0
@@ -3,4 +3,5 @@ obj-$(CONFIG_PINCTRL_MTK) += pinctrl-mtk-common.o # SoC Drivers +obj-$(CONFIG_PINCTRL_MT7623) += pinctrl-mt7623.o obj-$(CONFIG_PINCTRL_MT7629) += pinctrl-mt7629.o
drivers/pinctrl/mediatek/pinctrl-mt7623.c new file +1284 -0
1,284 lines not on this page · raw message
drivers/pinctrl/mediatek/pinctrl-mtk-common.h +1 -0
@@ -176,6 +176,7 @@ struct mtk_pinctrl_priv {extern const struct pinctrl_ops mtk_pinctrl_ops; +void mtk_rmw (struct udevice *dev,u32 reg,u32 mask,u32 set);int mtk_pinctrl_probe (struct udevice *dev,struct mtk_pinctrl_soc *soc);
Signature · 1 line
1.9.1
PATCH v2 11/18 pinctrl: MediaTek: add pinctrl driver for MT7623 SoC
Hi Ryder,
Quoted 13 lines · Ryder Lee
This patch adds pinctrl support for MT7623 SoC. And most of the structures are used to hold the hardware configuration for each pin.
Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- drivers/pinctrl/mediatek/Kconfig | 4 + drivers/pinctrl/mediatek/Makefile | 1 + drivers/pinctrl/mediatek/pinctrl-mt7623.c | 1284 +++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 1 + 4 files changed, 1290 insertions(+) create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7623.c
[..]
Quoted 1 line
+void
mtk_rmw(struct udevice *dev, u32 reg, u32 mask, u32 set);
What is this for? It has no comment and is an exported function. We should not export things from drivers unless there is a good reason.
Regards,
Simon
PATCH v2 11/18 pinctrl: MediaTek: add pinctrl driver for MT7623 SoC
Quoted 17 lines · Simon Glass
Hi Ryder,
Quoted 6 lines · Ryder Lee
This patch adds pinctrl support for MT7623 SoC. And most of the structures are used to hold the hardware configuration for each pin.
Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>Quoted 7 lines
--- drivers/pinctrl/mediatek/Kconfig | 4 + drivers/pinctrl/mediatek/Makefile | 1 + drivers/pinctrl/mediatek/pinctrl-mt7623.c | 1284 +++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 1 + 4 files changed, 1290 insertions(+) create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7623.c
Quoted 6 lines
[..]
Quoted 1 line
+void
mtk_rmw(struct udevice *dev, u32 reg, u32 mask, u32 set);What is this for? It has no comment and is an exported function. We should not export things from drivers unless there is a good reason.
This is a common 'read-modify-write' helper. I think we could export it in this shared header?
Quoted 2 lines
Regards,
Simon
PATCH v2 11/18 pinctrl: MediaTek: add pinctrl driver for MT7623 SoC
Hi Ryder,
Quoted 20 lines · Ryder Lee
Quoted 19 lines · Simon Glass
Hi Ryder,
Quoted 13 lines · Ryder Lee
This patch adds pinctrl support for MT7623 SoC. And most of the structures are used to hold the hardware configuration for each pin.
Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- drivers/pinctrl/mediatek/Kconfig | 4 + drivers/pinctrl/mediatek/Makefile | 1 + drivers/pinctrl/mediatek/pinctrl-mt7623.c | 1284 +++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mtk-common.h | 1 + 4 files changed, 1290 insertions(+) create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7623.c[..]
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+void
mtk_rmw(struct udevice *dev, u32 reg, u32 mask, u32 set);What is this for? It has no comment and is an exported function. We should not export things from drivers unless there is a good reason.
This is a common 'read-modify-write' helper. I think we could export it in this shared header?
OK I see, fair enough. Please add a comment to the function.
Regards,
Simon
PATCH v2 12/18 power domain: MediaTek: add power domain driver for MT7629 SoC
In reply to Ryder LeeThis adds a power domain driver for the Mediatek SCPSYS unit.
The System Control Processor System (SCPSYS) has several power management related tasks in the system. The tasks include thermal measurement, dynamic voltage frequency scaling (DVFS), interrupt filter and lowlevel sleep control. The System Power Manager (SPM) inside the SCPSYS is for the MTCMOS power domain control.
For now this driver only adds power domain support.
--- drivers/power/domain/Kconfig | 7 + drivers/power/domain/Makefile | 1 + drivers/power/domain/mtk-power-domain.c | 326 ++++++++++++++++++++++++++++++++ 3 files changed, 334 insertions(+) create mode 100644 drivers/power/domain/mtk-power-domain.c
drivers/power/domain/Kconfig +7 -0
@@ -16,6 +16,13 @@ config BCM6328_POWER_DOMAIN Enable support for manipulating BCM6345 power domains via MMIO mapped registers. +config MTK_POWER_DOMAIN + bool "Enable the MediaTek power domain driver" + depends on POWER_DOMAIN && ARCH_MEDIATEK + help + Enable support for manipulating MediaTek power domains via MMIO + mapped registers. + config MESON_GX_VPU_POWER_DOMAIN bool "Enable Amlogic Meson GX VPU power domain driver" depends on ARCH_MESON
drivers/power/domain/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_$(SPL_)POWER_DOMAIN) += power-domain-uclass.o obj-$(CONFIG_BCM6328_POWER_DOMAIN) += bcm6328-power-domain.o +obj-$(CONFIG_MTK_POWER_DOMAIN) += mtk-power-domain.o obj-$(CONFIG_MESON_GX_VPU_POWER_DOMAIN) += meson-gx-pwrc-vpu.o obj-$(CONFIG_SANDBOX_POWER_DOMAIN) += sandbox-power-domain.o obj-$(CONFIG_SANDBOX_POWER_DOMAIN) += sandbox-power-domain-test.o
drivers/power/domain/mtk-power-domain.c new file +326 -0
326 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 12/18 power domain: MediaTek: add power domain driver for MT7629 SoC
Quoted 10 lines · Ryder Lee
This adds a power domain driver for the Mediatek SCPSYS unit.
The System Control Processor System (SCPSYS) has several power management related tasks in the system. The tasks include thermal measurement, dynamic voltage frequency scaling (DVFS), interrupt filter and lowlevel sleep control. The System Power Manager (SPM) inside the SCPSYS is for the MTCMOS power domain control.
For now this driver only adds power domain support.
Quoted 7 lines
Signed-off-by Ryder Lee <[email protected]>--- drivers/power/domain/Kconfig | 7 + drivers/power/domain/Makefile | 1 + drivers/power/domain/mtk-power-domain.c | 326 ++++++++++++++++++++++++++++++++ 3 files changed, 334 insertions(+) create mode 100644 drivers/power/domain/mtk-power-domain.c
PATCH v2 13/18 power domain: MediaTek: add power domain driver for MT7623 SoC
In reply to Ryder LeeThis adds power domain (scpsys) support for MT7623 SoC.
--- drivers/power/domain/mtk-power-domain.c | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
drivers/power/domain/mtk-power-domain.c +80 -0
@@ -14,8 +14,18 @@#include <asm/processor.h> #include <linux/iopoll.h> +#include <dt-bindings/power/mt7623-power.h> #include <dt-bindings/power/mt7629-power.h> +#define SPM_VDE_PWR_CON 0x0210 +#define SPM_MFG_PWR_CON 0x0214 +#define SPM_ISP_PWR_CON 0x0238 +#define SPM_DIS_PWR_CON 0x023c +#define SPM_CONN_PWR_CON 0x0280 +#define SPM_BDP_PWR_CON 0x029c +#define SPM_ETH_PWR_CON 0x02a0 +#define SPM_HIF_PWR_CON 0x02a4 +#define SPM_IFR_MSC_PWR_CON 0x02a8#define SPM_ETHSYS_PWR_CON 0x2e0#define SPM_HIF0_PWR_CON 0x2e4#define SPM_HIF1_PWR_CON 0x2e8
@@ -28,6 +38,15 @@#define PWR_ON_2ND_BIT BIT(3)#define PWR_CLK_DIS_BIT BIT(4) +#define PWR_STATUS_CONN BIT(1) +#define PWR_STATUS_DISP BIT(3) +#define PWR_STATUS_MFG BIT(4) +#define PWR_STATUS_ISP BIT(5) +#define PWR_STATUS_VDEC BIT(7) +#define PWR_STATUS_BDP BIT(14) +#define PWR_STATUS_ETH BIT(15) +#define PWR_STATUS_HIF BIT(16) +#define PWR_STATUS_IFR_MSC BIT(17)#define PWR_STATUS_ETHSYS BIT(24)#define PWR_STATUS_HIF0 BIT(25)#define PWR_STATUS_HIF1 BIT(26)
@@ -40,6 +59,7 @@#define DCM_TOP_EN BIT(0)enum scp_domain_type { +SCPSYS_MT7623 ,SCPSYS_MT7629 , };
@@ -61,6 +81,59 @@ struct scp_domain {struct scp_domain_data *data; }; +static struct scp_domain_data scp_domain_mt7623[] = { + [MT7623_POWER_DOMAIN_CONN ] = { + .sta_mask =PWR_STATUS_CONN , + .ctl_offs =SPM_CONN_PWR_CON , + .bus_prot_mask =BIT (8 ) |BIT (2 ), + }, + [MT7623_POWER_DOMAIN_DISP ] = { + .sta_mask =PWR_STATUS_DISP , + .ctl_offs =SPM_DIS_PWR_CON , + .sram_pdn_bits =GENMASK (11 ,8 ), + .bus_prot_mask =BIT (2 ), + }, + [MT7623_POWER_DOMAIN_MFG ] = { + .sta_mask =PWR_STATUS_MFG , + .ctl_offs =SPM_MFG_PWR_CON , + .sram_pdn_bits =GENMASK (11 ,8 ), + .sram_pdn_ack_bits =GENMASK (12 ,12 ), + }, + [MT7623_POWER_DOMAIN_VDEC ] = { + .sta_mask =PWR_STATUS_VDEC , + .ctl_offs =SPM_VDE_PWR_CON , + .sram_pdn_bits =GENMASK (11 ,8 ), + .sram_pdn_ack_bits =GENMASK (12 ,12 ), + }, + [MT7623_POWER_DOMAIN_ISP ] = { + .sta_mask =PWR_STATUS_ISP , + .ctl_offs =SPM_ISP_PWR_CON , + .sram_pdn_bits =GENMASK (11 ,8 ), + .sram_pdn_ack_bits =GENMASK (13 ,12 ), + }, + [MT7623_POWER_DOMAIN_BDP ] = { + .sta_mask =PWR_STATUS_BDP , + .ctl_offs =SPM_BDP_PWR_CON , + .sram_pdn_bits =GENMASK (11 ,8 ), + }, + [MT7623_POWER_DOMAIN_ETH ] = { + .sta_mask =PWR_STATUS_ETH , + .ctl_offs =SPM_ETH_PWR_CON , + .sram_pdn_bits =GENMASK (11 ,8 ), + .sram_pdn_ack_bits =GENMASK (15 ,12 ), + }, + [MT7623_POWER_DOMAIN_HIF ] = { + .sta_mask =PWR_STATUS_HIF , + .ctl_offs =SPM_HIF_PWR_CON , + .sram_pdn_bits =GENMASK (11 ,8 ), + .sram_pdn_ack_bits =GENMASK (15 ,12 ), + }, + [MT7623_POWER_DOMAIN_IFR_MSC ] = { + .sta_mask =PWR_STATUS_IFR_MSC , + .ctl_offs =SPM_IFR_MSC_PWR_CON , + }, +}; +static struct scp_domain_data scp_domain_mt7629[] = { [MT7629_POWER_DOMAIN_ETHSYS ] = { .sta_mask =PWR_STATUS_ETHSYS ,
@@ -252,6 +325,9 @@ static int mtk_power_domain_hook(struct udevice *dev) scpd->type = (enum scp_domain_type )dev_get_driver_data (dev);switch (scpd->type) { +case SCPSYS_MT7623 : + scpd->data = scp_domain_mt7623; +break ;case SCPSYS_MT7629 : scpd->data = scp_domain_mt7629;break ;
@@ -303,6 +379,10 @@ static int mtk_power_domain_probe(struct udevice *dev)static const struct udevice_id mtk_power_domain_ids[] = { { + .compatible ="mediatek,mt7623-scpsys" , + .data =SCPSYS_MT7623 , + }, + { .compatible ="mediatek,mt7629-scpsys" , .data =SCPSYS_MT7629 , },
Signature · 1 line
1.9.1
PATCH v2 13/18 power domain: MediaTek: add power domain driver for MT7623 SoC
Quoted 6 lines · Ryder Lee
This adds power domain (scpsys) support for MT7623 SoC.
Signed-off-by Ryder Lee <[email protected]>--- drivers/power/domain/mtk-power-domain.c | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
PATCH v2 14/18 serial: 16550: allow the driver to support MediaTek serial
In reply to Ryder LeeThis patch adds an extra operation in ns16550.c to suuport MediaTek SoCs as we have a highspeed register which influences the calcualtion of the divisor.
Note that we don't support the baudrate greater than 115200 currently.
--- drivers/serial/ns16550.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/serial/ns16550.c +10 -0
@@ -148,6 +148,13 @@ int ns16550_calc_divisor(NS16550_t port, int clock, int baudrate)static void NS16550_setbrg (NS16550_t com_port,int baud_divisor) { +#ifdef CONFIG_ARCH_MEDIATEK +/* +* MediaTek UARTs has an extra highspeed register. +* We need to clear it if baudrate <= 115200. +*/ +serial_out (0 , &com_port->reg9); +#endif serial_out (UART_LCR_BKSE |UART_LCRVAL , &com_port->lcr);serial_out (baud_divisor &0xff , &com_port->dll);serial_out ((baud_divisor >>8 ) &0xff , &com_port->dlm);
@@ -261,6 +268,9 @@ static inline void _debug_uart_init(void)serial_dout (&com_port->mcr,UART_MCRVAL );serial_dout (&com_port->fcr,UART_FCR_DEFVAL ); +#ifdef CONFIG_ARCH_MEDIATEK +serial_dout (&com_port->reg9,0 ); +#endif serial_dout (&com_port->lcr,UART_LCR_BKSE |UART_LCRVAL );serial_dout (&com_port->dll, baud_divisor &0xff );serial_dout (&com_port->dlm, (baud_divisor >>8 ) &0xff );
Signature · 1 line
1.9.1
PATCH v2 14/18 serial: 16550: allow the driver to support MediaTek serial
Quoted 4 lines · Ryder Lee
This patch adds an extra operation in
ns16550.cto suuport MediaTek SoCs as we have a highspeed register which influences the calcualtion of the divisor.
Quoted 8 lines
Note that we don't support the baudrate greater than 115200 currently.
Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>--- drivers/serial/ns16550.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
PATCH v2 15/18 ram: MediaTek: add DDR3 driver for MT7629 SoC
In reply to Ryder LeeThis patch adds a DDR3 driver for MT7629 SoC.
--- drivers/ram/Makefile | 1 + drivers/ram/mediatek/Makefile | 7 + drivers/ram/mediatek/ddr3-mt7629.c | 766 +++++++++++++++++++++++++++++++++++++ 3 files changed, 774 insertions(+) create mode 100644 drivers/ram/mediatek/Makefile create mode 100644 drivers/ram/mediatek/ddr3-mt7629.c
drivers/ram/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_STM32_SDRAM) += stm32_sdram.o obj-$(CONFIG_ARCH_BMIPS) += bmips_ram.o obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ +obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
drivers/ram/mediatek/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Copyright (c) 2018 MediaTek Inc. +# +# SPDX-License-Identifier: GPL-2.0 +# + +obj-$(CONFIG_TARGET_MT7629) = ddr3-mt7629.o
drivers/ram/mediatek/ddr3-mt7629.c new file +766 -0
766 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 15/18 ram: MediaTek: add DDR3 driver for MT7629 SoC
Quoted 11 lines · Ryder Lee
This patch adds a DDR3 driver for MT7629 SoC.
Signed-off-by Wu Zou <[email protected]>Signed-off-by Ryder Lee <[email protected]>--- drivers/ram/Makefile | 1 + drivers/ram/mediatek/Makefile | 7 + drivers/ram/mediatek/ddr3-mt7629.c | 766 +++++++++++++++++++++++++++++++++++++ 3 files changed, 774 insertions(+) create mode 100644 drivers/ram/mediatek/Makefile create mode 100644 drivers/ram/mediatek/ddr3-mt7629.c
Thoughts below.
[..]
drivers/ram/mediatek/ddr3-mt7629.c line 23
Quoted 2 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +2
-0+#define DDRPHY_PLL1 0x0000 +#define DDRPHY_PLL2 0x0004
Why not use a C struct for these registers?
[..]
drivers/ram/mediatek/ddr3-mt7629.c line 590
Quoted 5 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +5
-0+writel (0x400 , priv->dramc_ao +DRAMC_MRS ); +writel (0x1d7000 , priv->dramc_ao +DRAMC_MRS ); +writel (0x1 , priv->dramc_ao +DRAMC_SPCMD ); +writel (0x0 , priv->dramc_ao +DRAMC_SPCMD ); +udelay (100 );
Are these delays specified in a datasheet? Why did you chose 100? Perhaps add an enum for this value? Is there a way to check for when the hardware is ready, e.g. by reading a registers in a loop?
[..]
Quoted 24 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +24
-0+static int mtk_ddr3_probe (struct udevice *dev) +{ +struct mtk_ddr3_priv *priv =dev_get_priv (dev); + + priv->emi =dev_read_addr_index (dev,0 ); +if (priv->emi ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->ddrphy =dev_read_addr_index (dev,1 ); +if (priv->ddrphy ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->dramc_ao =dev_read_addr_index (dev,2 ); +if (priv->dramc_ao ==FDT_ADDR_T_NONE ) +return -EINVAL ; + +#ifdef CONFIG_SPL_BUILD +int ret; + + ret =clk_get_by_index (dev,0 , &priv->phy); +if (ret) +return ret; + + ret =clk_get_by_index (dev,1 , &priv->phy_mux);
drivers/ram/mediatek/ddr3-mt7629.c line 714
Quoted 10 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +10
-0+if (ret) +return ret; + + ret =clk_get_by_index (dev,2 , &priv->mem); +if (ret) +return ret; + + ret =clk_get_by_index (dev,3 , &priv->mem_mux); +if (ret) +return ret;
Do you have phandles for these clocks? I only worry that it is a bit brittle to have them numbered.
drivers/ram/mediatek/ddr3-mt7629.c line 722
Quoted 8 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +8
-0+ + ret =mtk_ddr3_init (dev); +if (ret) +return ret; +#endif +return 0 ; +} +
Regards,
Simon
PATCH v2 15/18 ram: MediaTek: add DDR3 driver for MT7629 SoC
Quoted 15 lines · Simon Glass
Quoted 11 lines · Ryder Lee
This patch adds a DDR3 driver for MT7629 SoC.
Signed-off-by Wu Zou <[email protected]>Signed-off-by Ryder Lee <[email protected]>--- drivers/ram/Makefile | 1 + drivers/ram/mediatek/Makefile | 7 + drivers/ram/mediatek/ddr3-mt7629.c | 766 +++++++++++++++++++++++++++++++++++++ 3 files changed, 774 insertions(+) create mode 100644 drivers/ram/mediatek/Makefile create mode 100644 drivers/ram/mediatek/ddr3-mt7629.cReviewed-by Simon Glass <[email protected]>
Quoted 8 lines
Thoughts below.
[..]
drivers/ram/mediatek/ddr3-mt7629.c line 23
Quoted 2 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +2
-0+#define DDRPHY_PLL1 0x0000 +#define DDRPHY_PLL2 0x0004Why not use a C struct for these registers?
These are copy-n-paste from our SDK. I've considered converting these into C struct but it will take me a while. Just let it be.
But, I could do that if you insist.
Quoted 11 lines
[..]
drivers/ram/mediatek/ddr3-mt7629.c line 590
Quoted 5 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +5
-0+writel (0x400 , priv->dramc_ao +DRAMC_MRS ); +writel (0x1d7000 , priv->dramc_ao +DRAMC_MRS ); +writel (0x1 , priv->dramc_ao +DRAMC_SPCMD ); +writel (0x0 , priv->dramc_ao +DRAMC_SPCMD ); +udelay (100 );Are these delays specified in a datasheet? Why did you chose 100? Perhaps add an enum for this value? Is there a way to check for when the hardware is ready, e.g. by reading a registers in a loop?
Rule of thumb. There is no registers to read here, but I can try to reduce the delay time.
Quoted 31 lines
[..]
Quoted 29 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +29
-0+static int mtk_ddr3_probe (struct udevice *dev) +{ +struct mtk_ddr3_priv *priv =dev_get_priv (dev); + + priv->emi =dev_read_addr_index (dev,0 ); +if (priv->emi ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->ddrphy =dev_read_addr_index (dev,1 ); +if (priv->ddrphy ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->dramc_ao =dev_read_addr_index (dev,2 ); +if (priv->dramc_ao ==FDT_ADDR_T_NONE ) +return -EINVAL ; + +#ifdef CONFIG_SPL_BUILD +int ret; + + ret =clk_get_by_index (dev,0 , &priv->phy); +if (ret) +return ret; + + ret =clk_get_by_index (dev,1 , &priv->phy_mux); +if (ret) +return ret; + + ret =clk_get_by_index (dev,2 , &priv->mem); +if (ret)
Quoted 8 lines
drivers/ram/mediatek/ddr3-mt7629.c line 714
Quoted 5 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +5
-0+return ret; + + ret =clk_get_by_index (dev,3 , &priv->mem_mux); +if (ret) +return ret;Do you have phandles for these clocks? I only worry that it is a bit brittle to have them numbered.
Yes. I choose clk_get_by_index() here as I stripped the 'clock-names' via CONFIG_OF_SPL_REMOVE_PROPS to reduce the size .
Also I don't understand why we cannot use clk_set_defaults() in pre-relocate state?
Ryder
Quoted 11 lines
drivers/ram/mediatek/ddr3-mt7629.c line 722
Quoted 8 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +8
-0+ + ret =mtk_ddr3_init (dev); +if (ret) +return ret; +#endif +return 0 ; +} +Regards,
Simon
PATCH v2 15/18 ram: MediaTek: add DDR3 driver for MT7629 SoC
Hi Ryder,
Quoted 25 lines · Ryder Lee
Quoted 15 lines · Simon Glass
Quoted 11 lines · Ryder Lee
This patch adds a DDR3 driver for MT7629 SoC.
Signed-off-by Wu Zou <[email protected]>Signed-off-by Ryder Lee <[email protected]>--- drivers/ram/Makefile | 1 + drivers/ram/mediatek/Makefile | 7 + drivers/ram/mediatek/ddr3-mt7629.c | 766 +++++++++++++++++++++++++++++++++++++ 3 files changed, 774 insertions(+) create mode 100644 drivers/ram/mediatek/Makefile create mode 100644 drivers/ram/mediatek/ddr3-mt7629.cReviewed-by Simon Glass <[email protected]>Quoted 8 lines
Thoughts below.
[..]
drivers/ram/mediatek/ddr3-mt7629.c line 23
Quoted 2 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +2
-0+#define DDRPHY_PLL1 0x0000 +#define DDRPHY_PLL2 0x0004Why not use a C struct for these registers?
Quoted 4 lines
These are copy-n-paste from our SDK. I've considered converting these into C struct but it will take me a while. Just let it be.
But, I could do that if you insist.
OK we can leave it.
Quoted 9 lines
Quoted 9 lines
[..]
Quoted 5 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +5
-0+writel (0x400 , priv->dramc_ao +DRAMC_MRS ); +writel (0x1d7000 , priv->dramc_ao +DRAMC_MRS ); +writel (0x1 , priv->dramc_ao +DRAMC_SPCMD ); +writel (0x0 , priv->dramc_ao +DRAMC_SPCMD ); +udelay (100 );
Quoted 6 lines
Quoted 3 lines
Are these delays specified in a datasheet? Why did you chose 100? Perhaps add an enum for this value? Is there a way to check for when the hardware is ready, e.g. by reading a registers in a loop?
Rule of thumb. There is no registers to read here, but I can try to reduce the delay time.
We often end up worrying about delays later so any comments about how you came to those values are useful.
Quoted 41 lines
Quoted 32 lines
[..]
Quoted 29 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +29
-0+static int mtk_ddr3_probe (struct udevice *dev) +{ +struct mtk_ddr3_priv *priv =dev_get_priv (dev); + + priv->emi =dev_read_addr_index (dev,0 ); +if (priv->emi ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->ddrphy =dev_read_addr_index (dev,1 ); +if (priv->ddrphy ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->dramc_ao =dev_read_addr_index (dev,2 ); +if (priv->dramc_ao ==FDT_ADDR_T_NONE ) +return -EINVAL ; + +#ifdef CONFIG_SPL_BUILD +int ret; + + ret =clk_get_by_index (dev,0 , &priv->phy); +if (ret) +return ret; + + ret =clk_get_by_index (dev,1 , &priv->phy_mux); +if (ret) +return ret; + + ret =clk_get_by_index (dev,2 , &priv->mem); +if (ret)Quoted 8 lines
drivers/ram/mediatek/ddr3-mt7629.c line 714
Quoted 5 lines
drivers/ram/mediatek/ddr3-mt7629.c new file +5
-0+return ret; + + ret =clk_get_by_index (dev,3 , &priv->mem_mux); +if (ret) +return ret;Do you have phandles for these clocks? I only worry that it is a bit brittle to have them numbered.
Quoted 2 lines
Yes. I choose
clk_get_by_index()here as I stripped the 'clock-names' viaCONFIG_OF_SPL_REMOVE_PROPSto reduce the size .
OK
Quoted 3 lines
Also I don't understand why we cannot use
clk_set_defaults()in pre-relocate state?
I don't know either. It should be possible.
Regards,
Simon
PATCH v2 16/18 mmc: mtk-sd: add SD/MMC host controller driver for MT7623 SoC
In reply to Ryder LeeFrom: Weijie Gao <[email protected]>
This patch adds MT7623 host controller driver for accessing SD/MMC.
--- drivers/mmc/Kconfig | 9 + drivers/mmc/Makefile | 1 + drivers/mmc/mtk-sd.c | 1331 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1341 insertions(+) create mode 100644 drivers/mmc/mtk-sd.c
drivers/mmc/Kconfig +9 -0
@@ -598,6 +598,15 @@ config FTSDC010_SDIO help This can enable ftsdc010 sdio function. +config MMC_MTK + bool "MediaTek SD/MMC Card Interface support" + default n + help + This selects the MediaTek(R) Secure digital and Multimedia card Interface. + If you have a machine with a integrated SD/MMC card reader, say Y or M here. + This is needed if support for any SD/SDIO/MMC devices is required. + If unsure, say N. + endif config TEGRA124_MMC_DISABLE_EXT_LOOPBACK
drivers/mmc/Makefile +1 -0
@@ -65,3 +65,4 @@ obj-$(CONFIG_MMC_SUNXI) += sunxi_mmc.o obj-$(CONFIG_MMC_UNIPHIER) += tmio-common.o uniphier-sd.o obj-$(CONFIG_RENESAS_SDHI) += tmio-common.o renesas-sdhi.o obj-$(CONFIG_MMC_BCM2835) += bcm2835_sdhost.o +obj-$(CONFIG_MMC_MTK) += mtk-sd.o
drivers/mmc/mtk-sd.c new file +1331 -0
1,331 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 16/18 mmc: mtk-sd: add SD/MMC host controller driver for MT7623 SoC
Hi Ryder.
Quoted 8 lines · Ryder Lee
From: Weijie Gao <[email protected]>
This patch adds MT7623 host controller driver for accessing SD/MMC.
Cc Jaehoon Chung <[email protected]>Signed-off-by Weijie Gao <[email protected]>Signed-off-by Ryder Lee <[email protected]>Tested-by Matthias Brugger <[email protected]>
Quoted 6 lines
--- drivers/mmc/Kconfig | 9 + drivers/mmc/Makefile | 1 + drivers/mmc/mtk-sd.c | 1331 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1341 insertions(+) create mode 100644 drivers/mmc/mtk-sd.c
nits below
drivers/mmc/Kconfig config FTSDC010_SDIO · line 603
Quoted 12 lines
drivers/mmc/Kconfig +3
-0@@ -598,6 +598,15 @@ config FTSDC010_SDIO help This can enable ftsdc010 sdio function. +config MMC_MTK + bool "MediaTek SD/MMC Card Interface support" + default n
You should be able to omit this since it is the default.
Quoted 34 lines
drivers/mmc/Kconfig +6
-0+ help + This selects the MediaTek(R) Secure digital and Multimedia card Interface. + If you have a machine with a integrated SD/MMC card reader, say Y or M here. + This is needed if support for any SD/SDIO/MMC devices is required. + If unsure, say N. + endif config TEGRA124_MMC_DISABLE_EXT_LOOPBACKdrivers/mmc/Makefile +1
-0@@ -65,3 +65,4 @@ obj-$(CONFIG_MMC_SUNXI) += sunxi_mmc.o obj-$(CONFIG_MMC_UNIPHIER) += tmio-common.o uniphier-sd.o obj-$(CONFIG_RENESAS_SDHI) += tmio-common.o renesas-sdhi.o obj-$(CONFIG_MMC_BCM2835) += bcm2835_sdhost.o +obj-$(CONFIG_MMC_MTK) += mtk-sd.odrivers/mmc/mtk-sd.c new file +10
-0@@ -0,0 +1,1331 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* MediaTek SD/MMC Card Interface driver +* +* Copyright (C) 2018 MediaTek Inc. +* Author: Weijie Gao <[email protected]> +*/ + +#include <clk.h> +#include <common.h>
drivers/mmc/mtk-sd.c line 20
Quoted 10 lines
drivers/mmc/mtk-sd.c new file +10
-0+#include <dm.h> +#include <dm/pinctrl.h> +#include <errno.h> +#include <stdbool.h> +#include <malloc.h> +#include <mmc.h> +#include <asm/gpio.h> +#include <linux/bitops.h> +#include <linux/io.h> +#include <linux/iopoll.h>
Please check include-file order on all these patches.
drivers/mmc/mtk-sd.c line 32
Quoted 12 lines
drivers/mmc/mtk-sd.c new file +12
-0+ +#define MSDC_CFG 0x0 +#define MSDC_CFG_HS400_CK_MODE_EXT BIT(22) +#define MSDC_CFG_CKMOD_EXT_M 0x03 +#define MSDC_CFG_CKMOD_EXT_S 20 +#define MSDC_CFG_CKDIV_EXT_M 0xfff +#define MSDC_CFG_CKDIV_EXT_S 8 +#define MSDC_CFG_HS400_CK_MODE BIT(18) +#define MSDC_CFG_CKMOD_M 0x03 +#define MSDC_CFG_CKMOD_S 16 +#define MSDC_CFG_CKDIV_M 0xff +#define MSDC_CFG_CKDIV_S 8
We mostly use shifted masks in U-Boot since they are easier to use:
+#define MSDC_CFG_CKDIV_S 8 +#define MSDC_CFG_CKDIV_M (0xff << MSDC_CFG_CKDIV_S)
Quoted 179 lines
drivers/mmc/mtk-sd.c new file +179
-0+#define MSDC_CFG_CKSTB BIT(7) +#define MSDC_CFG_PIO BIT(3) +#define MSDC_CFG_RST BIT(2) +#define MSDC_CFG_CKPDN BIT(1) +#define MSDC_CFG_MODE BIT(0) + +#define MSDC_IOCON 0x04 +#define MSDC_IOCON_W_DSPL BIT(8) +#define MSDC_IOCON_DSPL BIT(2) +#define MSDC_IOCON_RSPL BIT(1) + +#define MSDC_PS 0x08 +#define MSDC_PS_DAT0 BIT(16) +#define MSDC_PS_CDEN BIT(0) + +#define MSDC_INT 0x0c +#define MSDC_INTEN 0x10 +#define MSDC_INT_ACMDRDY BIT(3) +#define MSDC_INT_ACMDTMO BIT(4) +#define MSDC_INT_ACMDCRCERR BIT(5) +#define MSDC_INT_CMDRDY BIT(8) +#define MSDC_INT_CMDTMO BIT(9) +#define MSDC_INT_RSPCRCERR BIT(10) +#define MSDC_INT_XFER_COMPL BIT(12) +#define MSDC_INT_DATTMO BIT(14) +#define MSDC_INT_DATCRCERR BIT(15) + +#define MSDC_FIFOCS 0x14 +#define MSDC_FIFOCS_CLR BIT(31) +#define MSDC_FIFOCS_TXCNT_M 0xff +#define MSDC_FIFOCS_TXCNT_S 16 +#define MSDC_FIFOCS_RXCNT_M 0xff +#define MSDC_FIFOCS_RXCNT_S 0 + +#define MSDC_TXDATA 0x18 +#define MSDC_RXDATA 0x1c + +#define SDC_CFG 0x30 +#define SDC_CFG_DTOC_M 0xff +#define SDC_CFG_DTOC_S 24 +#define SDC_CFG_SDIOIDE BIT(20) +#define SDC_CFG_SDIO BIT(19) +#define SDC_CFG_BUSWIDTH_M 0x03 +#define SDC_CFG_BUSWIDTH_S 16 + +#define SDC_CMD 0x34 +#define SDC_CMD_BLK_LEN_M 0xfff +#define SDC_CMD_BLK_LEN_S 16 +#define SDC_CMD_STOP BIT(14) +#define SDC_CMD_WR BIT(13) +#define SDC_CMD_DTYPE_M 0x03 +#define SDC_CMD_DTYPE_S 11 +#define SDC_CMD_RSPTYP_M 0x07 +#define SDC_CMD_RSPTYP_S 7 +#define SDC_CMD_CMD_M 0x3f +#define SDC_CMD_CMD_S 0 + +#define SDC_ARG 0x38 + +#define SDC_STS 0x3c +#define SDC_STS_CMDBUSY BIT(1) +#define SDC_STS_SDCBUSY BIT(0) + +#define SDC_RESP0 0x40 +#define SDC_RESP1 0x44 +#define SDC_RESP2 0x48 +#define SDC_RESP3 0x4c + +#define SDC_BLK_NUM 0x50 + +#define SDC_ADV_CFG0 0x64 +#define SDC_RX_ENHANCE_EN BIT(20) + +#define MSDC_PATCH_BIT 0xb0 +#define MSDC_INT_DAT_LATCH_CK_SEL_M 0x07 +#define MSDC_INT_DAT_LATCH_CK_SEL_S 7 + +#define MSDC_PATCH_BIT1 0xb4 +#define MSDC_PB1_STOP_DLY_M 0x0f +#define MSDC_PB1_STOP_DLY_S 8 + +#define MSDC_PATCH_BIT2 0xb8 +#define MSDC_PB2_CRCSTSENSEL_M 0x07 +#define MSDC_PB2_CRCSTSENSEL_S 29 +#define MSDC_PB2_CFGCRCSTS BIT(28) +#define MSDC_PB2_RESPSTSENSEL_M 0x07 +#define MSDC_PB2_RESPSTSENSEL_S 16 +#define MSDC_PB2_CFGRESP BIT(15) +#define MSDC_PB2_RESPWAIT_M 0x03 +#define MSDC_PB2_RESPWAIT_S 2 + +#define MSDC_PAD_TUNE 0xec +#define MSDC_PAD_TUNE_CMDRRDLY_M 0x1f +#define MSDC_PAD_TUNE_CMDRRDLY_S 22 +#define MSDC_PAD_TUNE_CMD_SEL BIT(21) +#define MSDC_PAD_TUNE_CMDRDLY_M 0x1f +#define MSDC_PAD_TUNE_CMDRDLY_S 16 +#define MSDC_PAD_TUNE_RXDLYSEL BIT(15) +#define MSDC_PAD_TUNE_RD_SEL BIT(13) +#define MSDC_PAD_TUNE_DATRRDLY_M 0x1f +#define MSDC_PAD_TUNE_DATRRDLY_S 8 +#define MSDC_PAD_TUNE_DATWRDLY_M 0x1f +#define MSDC_PAD_TUNE_DATWRDLY_S 0 + +#define MSDC_PAD_TUNE0 0xf0 + +#define PAD_DS_TUNE 0x188 + +#define EMMC50_CFG0 0x208 +#define EMMC50_CFG_CFCSTS_SEL BIT(4) + +#define SDC_FIFO_CFG 0x228 +#define SDC_FIFO_CFG_WRVALIDSEL BIT(24) +#define SDC_FIFO_CFG_RDVALIDSEL BIT(25) + +/* SDC_CFG_BUSWIDTH */ +#define MSDC_BUS_1BITS 0x0 +#define MSDC_BUS_4BITS 0x1 +#define MSDC_BUS_8BITS 0x2 + +#define MSDC_FIFO_SIZE 128 + +#define PAD_DELAY_MAX 32 + +#define CMD_INTS_MASK \ + (MSDC_INT_CMDRDY | MSDC_INT_RSPCRCERR | MSDC_INT_CMDTMO) + +#define DATA_INTS_MASK \ + (MSDC_INT_XFER_COMPL | MSDC_INT_DATTMO | MSDC_INT_DATCRCERR) + +struct msdc_compatible { +u8 clk_div_bits; +bool pad_tune0; +bool async_fifo; +bool data_tune; +bool busy_check; +bool stop_clk_fix; +bool enhance_rx; +}; + +struct msdc_delay_phase { +u8 maxlen; +u8 start; +u8 final_phase; +}; + +struct msdc_plat { +struct mmc_config cfg; +struct mmc mmc; +}; + +struct msdc_tune_para { +u32 iocon; +u32 pad_tune; +}; + +struct msdc_host { +void __iomem *base; +struct mmc *mmc; + +struct msdc_compatible *dev_comp; + +struct clk src_clk; +struct clk h_clk; + +u32 mclk; +u32 src_clk_freq; +u32 sclk; + +u32 timeout_ns; +u32 timeout_clks; + +u32 hs400_ds_delay; +u32 hs200_cmd_int_delay; +u32 hs200_write_int_delay; +u32 latch_ck; +u32 r_smpl; +bool hs400_mode; +
drivers/mmc/mtk-sd.c line 221
Quoted 10 lines
drivers/mmc/mtk-sd.c new file +10
-0+struct gpio_desc gpio_wp; +struct gpio_desc gpio_cd; + +uint last_resp_type; +uint last_data_write; + +enum bus_mode timing; + +struct msdc_tune_para def_tune_para; +struct msdc_tune_para saved_tune_para;
This struct needs comments.
Quoted 113 lines
drivers/mmc/mtk-sd.c new file +113
-0+}; + +static void msdc_reset_hw (struct msdc_host *host) +{ +u32 reg; + +setbits_le32 (host->base +MSDC_CFG ,MSDC_CFG_RST ); + +readl_poll_timeout (host->base +MSDC_CFG , reg, + !(reg &MSDC_CFG_RST ),1000000 ); +} + +static void msdc_fifo_clr (struct msdc_host *host) +{ +u32 reg; + +setbits_le32 (host->base +MSDC_FIFOCS ,MSDC_FIFOCS_CLR ); + +readl_poll_timeout (host->base +MSDC_FIFOCS , reg, + !(reg &MSDC_FIFOCS_CLR ),1000000 ); +} + +static u32 msdc_fifo_rx_bytes (struct msdc_host *host) +{ +return (readl (host->base +MSDC_FIFOCS ) >>MSDC_FIFOCS_RXCNT_S ) & +MSDC_FIFOCS_RXCNT_M ; +} + +static u32 msdc_fifo_tx_bytes (struct msdc_host *host) +{ +return (readl (host->base +MSDC_FIFOCS ) >>MSDC_FIFOCS_TXCNT_S ) & +MSDC_FIFOCS_TXCNT_M ; +} + +static u32 msdc_cmd_find_resp (struct msdc_host *host,struct mmc_cmd *cmd) +{ +u32 resp; + +switch (cmd->resp_type) { +/* Actually, R1, R5, R6, R7 are the same */ +case MMC_RSP_R1 : + resp =0x1 ; +break ; +case MMC_RSP_R1b: + resp =0x7 ; +break ; +case MMC_RSP_R2 : + resp =0x2 ; +break ; +case MMC_RSP_R3 : + resp =0x3 ; +break ; +case MMC_RSP_NONE : +default : + resp =0x0 ; +break ; + } + +return resp; +} + +static u32 msdc_cmd_prepare_raw_cmd (struct msdc_host *host, +struct mmc_cmd *cmd, +struct mmc_data *data) +{ +u32 opcode = cmd->cmdidx; +u32 resp_type =msdc_cmd_find_resp (host, cmd); +uint blocksize =0 ; +u32 dtype =0 ; +u32 rawcmd =0 ; + +switch (opcode) { +case MMC_CMD_WRITE_MULTIPLE_BLOCK : +case MMC_CMD_READ_MULTIPLE_BLOCK : + dtype =2 ; +break ; +case MMC_CMD_WRITE_SINGLE_BLOCK : +case MMC_CMD_READ_SINGLE_BLOCK : +case SD_CMD_APP_SEND_SCR : + dtype =1 ; +break ; +case SD_CMD_SWITCH_FUNC :/* same as MMC_CMD_SWITCH */ +case SD_CMD_SEND_IF_COND :/* same as MMC_CMD_SEND_EXT_CSD */ +case SD_CMD_APP_SD_STATUS :/* same as MMC_CMD_SEND_STATUS */ +if (data) + dtype =1 ; + } + +if (data) { +if (data->flags ==MMC_DATA_WRITE ) + rawcmd |=SDC_CMD_WR ; + +if (data->blocks >1 ) + dtype =2 ; + + blocksize = data->blocksize; + } + + rawcmd |= ((opcode &SDC_CMD_CMD_M ) <<SDC_CMD_CMD_S ) | + ((resp_type &SDC_CMD_RSPTYP_M ) <<SDC_CMD_RSPTYP_S ) | + ((blocksize &SDC_CMD_BLK_LEN_M ) <<SDC_CMD_BLK_LEN_S ) | + ((dtype &SDC_CMD_DTYPE_M ) <<SDC_CMD_DTYPE_S ); + +if (opcode ==MMC_CMD_STOP_TRANSMISSION ) + rawcmd |=SDC_CMD_STOP ; + +return rawcmd; +} + +static int msdc_cmd_done (struct msdc_host *host,int events, +struct mmc_cmd *cmd) +{ +u32 *rsp = cmd->response;
drivers/mmc/mtk-sd.c line 344
Quoted 10 lines
drivers/mmc/mtk-sd.c new file +10
-0+int ret =0 ; + +if (cmd->resp_type &MMC_RSP_PRESENT ) { +if (cmd->resp_type &MMC_RSP_136 ) { + rsp[0 ] =readl (host->base +SDC_RESP3 ); + rsp[1 ] =readl (host->base +SDC_RESP2 ); + rsp[2 ] =readl (host->base +SDC_RESP1 ); + rsp[3 ] =readl (host->base +SDC_RESP0 ); + }else { + rsp[0 ] =readl (host->base +SDC_RESP0 );
Use a C struct instead of all this base +_ xxx stuff?
[..]
Quoted 7 lines
drivers/mmc/mtk-sd.c new file +7
-0+static int msdc_drv_probe (struct udevice *dev) +{ +struct mmc_uclass_priv *upriv =dev_get_uclass_priv (dev); +struct msdc_plat *plat =dev_get_platdata (dev); +struct msdc_host *host =dev_get_priv (dev); +struct mmc_config *cfg = &plat->cfg; +int ret;
drivers/mmc/mtk-sd.c line 1241
Quoted 10 lines
drivers/mmc/mtk-sd.c new file +10
-0+ + cfg->name = dev->name; + + host->base = (void *)dev_read_addr (dev); +if (!host->base) +return -EINVAL ; + + ret =mmc_of_parse (dev, cfg); +if (ret) +return ret;
Normally we read the DT in the ofdata_to_platdata() method.
[..]
Regards,
Simon
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
In reply to Ryder LeeFrom: Guochun Mao <[email protected]>
This patch adds MT7629 qspi driver for accessing SPI NOR flash.
---
change since v2:
- Drop flash commands in the driver.
--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mtk_qspi.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 drivers/spi/mtk_qspi.c
drivers/spi/Kconfig +7 -0
@@ -124,6 +124,13 @@ config MT7621_SPI the SPI NOR flash on platforms embedding this Ralink / MediaTek SPI core, like MT7621/7628/7688. +config MTK_QSPI + bool "Mediatek QSPI driver" + help + Enable the Mediatek QSPI driver. This driver can be + used to access the SPI NOR flash on platforms embedding this + Mediatek QSPI IP core. + config MVEBU_A3700_SPI bool "Marvell Armada 3700 SPI driver" select CLK_ARMADA_3720
drivers/spi/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o +obj-$(CONFIG_MTK_QSPI) += mtk_qspi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o obj-$(CONFIG_MXC_SPI) += mxc_spi.o
drivers/spi/mtk_qspi.c new file +359 -0
359 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Quoted 9 lines · Ryder Lee
From: Guochun Mao <[email protected]>
This patch adds MT7629 qspi driver for accessing SPI NOR flash.
Cc Jagan Teki <[email protected]>Signed-off-by Guochun Mao <[email protected]>---
change since v2:
- Drop flash commands in the driver.
Quoted 7 lines
--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mtk_qspi.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 drivers/spi/mtk_qspi.c
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
In reply to Ryder LeeQuoted 8 lines · Ryder Lee
From: Guochun Mao <[email protected]>
This patch adds MT7629 qspi driver for accessing SPI NOR flash.
Cc Jagan Teki <[email protected]>Signed-off-by Guochun Mao <[email protected]>---
Few spaces need to add, will fix while applying.
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
In reply to Ryder LeeQuoted 123 lines · Ryder Lee
From: Guochun Mao <[email protected]>
This patch adds MT7629 qspi driver for accessing SPI NOR flash.
Cc Jagan Teki <[email protected]>Signed-off-by Guochun Mao <[email protected]>---
change since v2:
- Drop flash commands in the driver.--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mtk_qspi.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 drivers/spi/mtk_qspi.cdrivers/spi/Kconfig +7
-0@@ -124,6 +124,13 @@ config MT7621_SPI the SPI NOR flash on platforms embedding this Ralink / MediaTek SPI core, like MT7621/7628/7688. +config MTK_QSPI + bool "Mediatek QSPI driver" + help + Enable the Mediatek QSPI driver. This driver can be + used to access the SPI NOR flash on platforms embedding this + Mediatek QSPI IP core. + config MVEBU_A3700_SPI bool "Marvell Armada 3700 SPI driver" select CLK_ARMADA_3720drivers/spi/Makefile +1
-0@@ -33,6 +33,7 @@ obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o +obj-$(CONFIG_MTK_QSPI) += mtk_qspi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o obj-$(CONFIG_MXC_SPI) += mxc_spi.odrivers/spi/mtk_qspi.c new file +70
-0@@ -0,0 +1,359 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018 MediaTek, Inc. +* Author : Guochun.Mao at mediatek.com +*/ + +#include <common.h> +#include <dm.h> +#include <malloc.h> +#include <spi.h> +#include <asm/io.h> +#include <linux/iopoll.h> +#include <linux/ioport.h> + +/* Register Offset */ +struct mtk_qspi_regs { +u32 cmd; +u32 cnt; +u32 rdsr; +u32 rdata; +u32 radr[3 ]; +u32 wdata; +u32 prgdata[6 ]; +u32 shreg[10 ]; +u32 cfg[2 ]; +u32 shreg10; +u32 mode_mon; +u32 status[4 ]; +u32 flash_time; +u32 flash_cfg; +u32 reserved_0[3 ]; +u32 sf_time; +u32 pp_dw_data; +u32 reserved_1; +u32 delsel_0[2 ]; +u32 intrstus; +u32 intren; +u32 reserved_2; +u32 cfg3; +u32 reserved_3; +u32 chksum; +u32 aaicmd; +u32 wrprot; +u32 radr3; +u32 dual; +u32 delsel_1[3 ]; +}; + +struct mtk_qspi_platdata { +fdt_addr_t reg_base; +fdt_addr_t mem_base; +}; + +struct mtk_qspi_priv { +struct mtk_qspi_regs *regs; +unsigned long *mem_base; +u8 op; +u8 tx[3 ];/* only record max 3 bytes paras, when it's address. */ +u32 txlen;/* dout buffer length - op code length */ +u8 *rx; +u32 rxlen; +}; + +#define MTK_QSPI_CMD_POLLINGREG_US 500000 +#define MTK_QSPI_WRBUF_SIZE 256 +#define MTK_QSPI_COMMAND_ENABLE 0x30 + +/* NOR flash controller commands */ +#define MTK_QSPI_RD_TRIGGER BIT(0) +#define MTK_QSPI_READSTATUS BIT(1)
drivers/spi/mtk_qspi.c line 80
Quoted 10 lines
drivers/spi/mtk_qspi.c new file +10
-0+#define MTK_QSPI_PRG_CMD BIT(2) +#define MTK_QSPI_WR_TRIGGER BIT(4) +#define MTK_QSPI_WRITESTATUS BIT(5) +#define MTK_QSPI_AUTOINC BIT(7) + +#define MTK_QSPI_MAX_RX_TX_SHIFT 0x6 +#define MTK_QSPI_MAX_SHIFT 0x8 + +#define MTK_QSPI_WR_BUF_ENABLE 0x1 +#define MTK_QSPI_WR_BUF_DISABLE 0x0
All these bits look flash handling bit's , aren't ?
Quoted 30 lines
drivers/spi/mtk_qspi.c new file +30
-0+ +static int mtk_qspi_execute_cmd (struct mtk_qspi_priv *priv,u8 cmd) +{ +u8 tmp; +u8 val = cmd & ~MTK_QSPI_AUTOINC ; + +writeb (cmd, &priv->regs->cmd); + +return readb_poll_timeout (&priv->regs->cmd, tmp, !(val & tmp), +MTK_QSPI_CMD_POLLINGREG_US ); +} + +static int mtk_qspi_tx_rx (struct mtk_qspi_priv *priv) +{ +int len =1 + priv->txlen + priv->rxlen; +int i, ret, idx; + +if (len >MTK_QSPI_MAX_SHIFT ) +return -ERR_INVAL ; + +writeb (len *8 , &priv->regs->cnt); + +/* start at PRGDATA5, go down to PRGDATA0 */ + idx =MTK_QSPI_MAX_RX_TX_SHIFT -1 ; + +/* opcode */ +writeb (priv->op, &priv->regs->prgdata[idx]); + idx--; + +/* program TX data */
drivers/spi/mtk_qspi.c line 120
Quoted 10 lines
drivers/spi/mtk_qspi.c new file +10
-0+for (i =0 ; i < priv->txlen; i++, idx--) +writeb (priv->tx[i], &priv->regs->prgdata[idx]); + +/* clear out rest of TX registers */ +while (idx >=0 ) { +writeb (0 , &priv->regs->prgdata[idx]); + idx--; + } + + ret =mtk_qspi_execute_cmd (priv,MTK_QSPI_PRG_CMD );
What does this execute do? does it intiate the controller register based flash command or so?
Do you have Linux driver on the controller?
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Quoted 171 lines · Jagan Teki
Quoted 123 lines · Ryder Lee
From: Guochun Mao <[email protected]>
This patch adds MT7629 qspi driver for accessing SPI NOR flash.
Cc Jagan Teki <[email protected]>Signed-off-by Guochun Mao <[email protected]>---
change since v2:
- Drop flash commands in the driver.--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mtk_qspi.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 drivers/spi/mtk_qspi.cdrivers/spi/Kconfig +7
-0@@ -124,6 +124,13 @@ config MT7621_SPI the SPI NOR flash on platforms embedding this Ralink / MediaTek SPI core, like MT7621/7628/7688. +config MTK_QSPI + bool "Mediatek QSPI driver" + help + Enable the Mediatek QSPI driver. This driver can be + used to access the SPI NOR flash on platforms embedding this + Mediatek QSPI IP core. + config MVEBU_A3700_SPI bool "Marvell Armada 3700 SPI driver" select CLK_ARMADA_3720drivers/spi/Makefile +1
-0@@ -33,6 +33,7 @@ obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o +obj-$(CONFIG_MTK_QSPI) += mtk_qspi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o obj-$(CONFIG_MXC_SPI) += mxc_spi.odrivers/spi/mtk_qspi.c new file +70
-0@@ -0,0 +1,359 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018 MediaTek, Inc. +* Author : Guochun.Mao at mediatek.com +*/ + +#include <common.h> +#include <dm.h> +#include <malloc.h> +#include <spi.h> +#include <asm/io.h> +#include <linux/iopoll.h> +#include <linux/ioport.h> + +/* Register Offset */ +struct mtk_qspi_regs { +u32 cmd; +u32 cnt; +u32 rdsr; +u32 rdata; +u32 radr[3 ]; +u32 wdata; +u32 prgdata[6 ]; +u32 shreg[10 ]; +u32 cfg[2 ]; +u32 shreg10; +u32 mode_mon; +u32 status[4 ]; +u32 flash_time; +u32 flash_cfg; +u32 reserved_0[3 ]; +u32 sf_time; +u32 pp_dw_data; +u32 reserved_1; +u32 delsel_0[2 ]; +u32 intrstus; +u32 intren; +u32 reserved_2; +u32 cfg3; +u32 reserved_3; +u32 chksum; +u32 aaicmd; +u32 wrprot; +u32 radr3; +u32 dual; +u32 delsel_1[3 ]; +}; + +struct mtk_qspi_platdata { +fdt_addr_t reg_base; +fdt_addr_t mem_base; +}; + +struct mtk_qspi_priv { +struct mtk_qspi_regs *regs; +unsigned long *mem_base; +u8 op; +u8 tx[3 ];/* only record max 3 bytes paras, when it's address. */ +u32 txlen;/* dout buffer length - op code length */ +u8 *rx; +u32 rxlen; +}; + +#define MTK_QSPI_CMD_POLLINGREG_US 500000 +#define MTK_QSPI_WRBUF_SIZE 256 +#define MTK_QSPI_COMMAND_ENABLE 0x30 + +/* NOR flash controller commands */ +#define MTK_QSPI_RD_TRIGGER BIT(0) +#define MTK_QSPI_READSTATUS BIT(1)drivers/spi/mtk_qspi.c line 80
Quoted 10 lines
drivers/spi/mtk_qspi.c new file +10
-0+#define MTK_QSPI_PRG_CMD BIT(2) +#define MTK_QSPI_WR_TRIGGER BIT(4) +#define MTK_QSPI_WRITESTATUS BIT(5) +#define MTK_QSPI_AUTOINC BIT(7) + +#define MTK_QSPI_MAX_RX_TX_SHIFT 0x6 +#define MTK_QSPI_MAX_SHIFT 0x8 + +#define MTK_QSPI_WR_BUF_ENABLE 0x1 +#define MTK_QSPI_WR_BUF_DISABLE 0x0All these bits look flash handling bit's , aren't ?
Quoted 34 lines
drivers/spi/mtk_qspi.c new file +34
-0+ +static int mtk_qspi_execute_cmd (struct mtk_qspi_priv *priv,u8 cmd) +{ +u8 tmp; +u8 val = cmd & ~MTK_QSPI_AUTOINC ; + +writeb (cmd, &priv->regs->cmd); + +return readb_poll_timeout (&priv->regs->cmd, tmp, !(val & tmp), +MTK_QSPI_CMD_POLLINGREG_US ); +} + +static int mtk_qspi_tx_rx (struct mtk_qspi_priv *priv) +{ +int len =1 + priv->txlen + priv->rxlen; +int i, ret, idx; + +if (len >MTK_QSPI_MAX_SHIFT ) +return -ERR_INVAL ; + +writeb (len *8 , &priv->regs->cnt); + +/* start at PRGDATA5, go down to PRGDATA0 */ + idx =MTK_QSPI_MAX_RX_TX_SHIFT -1 ; + +/* opcode */ +writeb (priv->op, &priv->regs->prgdata[idx]); + idx--; + +/* program TX data */ +for (i =0 ; i < priv->txlen; i++, idx--) +writeb (priv->tx[i], &priv->regs->prgdata[idx]); + +/* clear out rest of TX registers */
Quoted 8 lines
drivers/spi/mtk_qspi.c line 120
Quoted 6 lines
drivers/spi/mtk_qspi.c new file +6
-0+while (idx >=0 ) { +writeb (0 , &priv->regs->prgdata[idx]); + idx--; + } + + ret =mtk_qspi_execute_cmd (priv,MTK_QSPI_PRG_CMD );What does this execute do?
It send command to flash, and latch data if need.
Quoted 2 lines
does it intiate the controller register
based flash command or so?
No, it doesn't.
Quoted 2 lines
Do you have Linux driver on the controller?
Yes, it's drivers/mtd/spi-nor/mtk-quadspi.c
BR,
Guochun
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Quoted 183 lines · Guochun Mao
Quoted 171 lines · Jagan Teki
Quoted 123 lines · Ryder Lee
From: Guochun Mao <[email protected]>
This patch adds MT7629 qspi driver for accessing SPI NOR flash.
Cc Jagan Teki <[email protected]>Signed-off-by Guochun Mao <[email protected]>---
change since v2:
- Drop flash commands in the driver.--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mtk_qspi.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 drivers/spi/mtk_qspi.cdrivers/spi/Kconfig +7
-0@@ -124,6 +124,13 @@ config MT7621_SPI the SPI NOR flash on platforms embedding this Ralink / MediaTek SPI core, like MT7621/7628/7688. +config MTK_QSPI + bool "Mediatek QSPI driver" + help + Enable the Mediatek QSPI driver. This driver can be + used to access the SPI NOR flash on platforms embedding this + Mediatek QSPI IP core. + config MVEBU_A3700_SPI bool "Marvell Armada 3700 SPI driver" select CLK_ARMADA_3720drivers/spi/Makefile +1
-0@@ -33,6 +33,7 @@ obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o +obj-$(CONFIG_MTK_QSPI) += mtk_qspi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o obj-$(CONFIG_MXC_SPI) += mxc_spi.odrivers/spi/mtk_qspi.c new file +70
-0@@ -0,0 +1,359 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2018 MediaTek, Inc. +* Author : Guochun.Mao at mediatek.com +*/ + +#include <common.h> +#include <dm.h> +#include <malloc.h> +#include <spi.h> +#include <asm/io.h> +#include <linux/iopoll.h> +#include <linux/ioport.h> + +/* Register Offset */ +struct mtk_qspi_regs { +u32 cmd; +u32 cnt; +u32 rdsr; +u32 rdata; +u32 radr[3 ]; +u32 wdata; +u32 prgdata[6 ]; +u32 shreg[10 ]; +u32 cfg[2 ]; +u32 shreg10; +u32 mode_mon; +u32 status[4 ]; +u32 flash_time; +u32 flash_cfg; +u32 reserved_0[3 ]; +u32 sf_time; +u32 pp_dw_data; +u32 reserved_1; +u32 delsel_0[2 ]; +u32 intrstus; +u32 intren; +u32 reserved_2; +u32 cfg3; +u32 reserved_3; +u32 chksum; +u32 aaicmd; +u32 wrprot; +u32 radr3; +u32 dual; +u32 delsel_1[3 ]; +}; + +struct mtk_qspi_platdata { +fdt_addr_t reg_base; +fdt_addr_t mem_base; +}; + +struct mtk_qspi_priv { +struct mtk_qspi_regs *regs; +unsigned long *mem_base; +u8 op; +u8 tx[3 ];/* only record max 3 bytes paras, when it's address. */ +u32 txlen;/* dout buffer length - op code length */ +u8 *rx; +u32 rxlen; +}; + +#define MTK_QSPI_CMD_POLLINGREG_US 500000 +#define MTK_QSPI_WRBUF_SIZE 256 +#define MTK_QSPI_COMMAND_ENABLE 0x30 + +/* NOR flash controller commands */ +#define MTK_QSPI_RD_TRIGGER BIT(0) +#define MTK_QSPI_READSTATUS BIT(1)drivers/spi/mtk_qspi.c line 80
Quoted 10 lines
drivers/spi/mtk_qspi.c new file +10
-0+#define MTK_QSPI_PRG_CMD BIT(2) +#define MTK_QSPI_WR_TRIGGER BIT(4) +#define MTK_QSPI_WRITESTATUS BIT(5) +#define MTK_QSPI_AUTOINC BIT(7) + +#define MTK_QSPI_MAX_RX_TX_SHIFT 0x6 +#define MTK_QSPI_MAX_SHIFT 0x8 + +#define MTK_QSPI_WR_BUF_ENABLE 0x1 +#define MTK_QSPI_WR_BUF_DISABLE 0x0All these bits look flash handling bit's , aren't ?
Quoted 34 lines
drivers/spi/mtk_qspi.c new file +34
-0+ +static int mtk_qspi_execute_cmd (struct mtk_qspi_priv *priv,u8 cmd) +{ +u8 tmp; +u8 val = cmd & ~MTK_QSPI_AUTOINC ; + +writeb (cmd, &priv->regs->cmd); + +return readb_poll_timeout (&priv->regs->cmd, tmp, !(val & tmp), +MTK_QSPI_CMD_POLLINGREG_US ); +} + +static int mtk_qspi_tx_rx (struct mtk_qspi_priv *priv) +{ +int len =1 + priv->txlen + priv->rxlen; +int i, ret, idx; + +if (len >MTK_QSPI_MAX_SHIFT ) +return -ERR_INVAL ; + +writeb (len *8 , &priv->regs->cnt); + +/* start at PRGDATA5, go down to PRGDATA0 */ + idx =MTK_QSPI_MAX_RX_TX_SHIFT -1 ; + +/* opcode */ +writeb (priv->op, &priv->regs->prgdata[idx]); + idx--; + +/* program TX data */ +for (i =0 ; i < priv->txlen; i++, idx--) +writeb (priv->tx[i], &priv->regs->prgdata[idx]); + +/* clear out rest of TX registers */ Quoted 8 lines
drivers/spi/mtk_qspi.c line 120
Quoted 6 lines
drivers/spi/mtk_qspi.c new file +6
-0+while (idx >=0 ) { +writeb (0 , &priv->regs->prgdata[idx]); + idx--; + } + + ret =mtk_qspi_execute_cmd (priv,MTK_QSPI_PRG_CMD );What does this execute do?
It send command to flash, and latch data if need.
Quoted 7 lines
Quoted 2 lines
does it intiate the controller register
based flash command or so?No, it doesn't.
Quoted 2 lines
Do you have Linux driver on the controller?
Yes, it's
drivers/mtd/spi-nor/mtk-quadspi.c
This sounds more specific to flash controller rather than spi driver. Can you try to write driver in mtd side itself, like Linux spi-nor. use UCLASS_SPI_FLASH
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Hi Jagan,
Quoted 37 lines · Jagan Teki
Quoted 37 lines
Quoted 22 lines
Quoted 22 lines
drivers/spi/mtk_qspi.c new file +22
-0+static int mtk_qspi_tx_rx (struct mtk_qspi_priv *priv) +{ +int len =1 + priv->txlen + priv->rxlen; +int i, ret, idx; + +if (len >MTK_QSPI_MAX_SHIFT ) +return -ERR_INVAL ; + +writeb (len *8 , &priv->regs->cnt); + +/* start at PRGDATA5, go down to PRGDATA0 */ + idx =MTK_QSPI_MAX_RX_TX_SHIFT -1 ; + +/* opcode */ +writeb (priv->op, &priv->regs->prgdata[idx]); + idx--; + +/* program TX data */ +for (i =0 ; i < priv->txlen; i++, idx--) +writeb (priv->tx[i], &priv->regs->prgdata[idx]); + +/* clear out rest of TX registers */ Quoted 8 lines
drivers/spi/mtk_qspi.c line 120
Quoted 6 lines
drivers/spi/mtk_qspi.c new file +6
-0+while (idx >=0 ) { +writeb (0 , &priv->regs->prgdata[idx]); + idx--; + } + + ret =mtk_qspi_execute_cmd (priv,MTK_QSPI_PRG_CMD );What does this execute do?
It send command to flash, and latch data if need.
Quoted 2 lines
does it intiate the controller register
based flash command or so?No, it doesn't.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Do you have Linux driver on the controller?
Yes, it's
drivers/mtd/spi-nor/mtk-quadspi.cThis sounds more specific to flash controller rather than spi driver. Can you try to write driver in mtd side itself, like Linux spi-nor. use
UCLASS_SPI_FLASH
Sorry, I'm a little confused.
There are many files(***qspi.c) those that used for accessing spi flash under folder drivers/spi/.
However, there's no specific flash controller driver implemented under drives/mtd, only common spi_flash framework. It's different with kernel. It seems that we only need implement the spi control logic of spi-flash-controller(this part not based on flash, it only do data-xfer), and spi_flash framework will work well base on it. Isn't that the purpose of this architecture?
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Quoted 49 lines · Guochun Mao
Hi Jagan,
Quoted 37 lines · Jagan Teki
Quoted 37 lines
Quoted 22 lines
Quoted 22 lines
drivers/spi/mtk_qspi.c new file +22
-0+static int mtk_qspi_tx_rx (struct mtk_qspi_priv *priv) +{ +int len =1 + priv->txlen + priv->rxlen; +int i, ret, idx; + +if (len >MTK_QSPI_MAX_SHIFT ) +return -ERR_INVAL ; + +writeb (len *8 , &priv->regs->cnt); + +/* start at PRGDATA5, go down to PRGDATA0 */ + idx =MTK_QSPI_MAX_RX_TX_SHIFT -1 ; + +/* opcode */ +writeb (priv->op, &priv->regs->prgdata[idx]); + idx--; + +/* program TX data */ +for (i =0 ; i < priv->txlen; i++, idx--) +writeb (priv->tx[i], &priv->regs->prgdata[idx]); + +/* clear out rest of TX registers */ Quoted 8 lines
drivers/spi/mtk_qspi.c line 120
Quoted 6 lines
drivers/spi/mtk_qspi.c new file +6
-0+while (idx >=0 ) { +writeb (0 , &priv->regs->prgdata[idx]); + idx--; + } + + ret =mtk_qspi_execute_cmd (priv,MTK_QSPI_PRG_CMD );What does this execute do?
It send command to flash, and latch data if need.
Quoted 2 lines
does it intiate the controller register
based flash command or so?No, it doesn't.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Do you have Linux driver on the controller?
Yes, it's
drivers/mtd/spi-nor/mtk-quadspi.cThis sounds more specific to flash controller rather than spi driver. Can you try to write driver in mtd side itself, like Linux spi-nor. use
UCLASS_SPI_FLASH
Quoted 9 lines
Sorry, I'm a little confused.
There are manyfiles(***qspi.c)those that used for accessing spi flash under folderdrivers/spi/.
However, there's no specific flash controller driver implemented under drives/mtd, only commonspi_flashframework. It's different with kernel. It seems that we only need implement the spi control logic of spi-flash-controller(this part not based on flash, it only do data-xfer), andspi_flashframework will work well base on it. Isn't that the purpose of this architecture?
Understand your point, to be precise the driver may a fall in trouble after sometime, if there is an additional flash specific features will attach in future. ie reason few of flash controllers in drivers/spi were unable to move further to add their features. and ie also reason for your driver in Linux which resides in spi-nor.
You can directly write UCLASS_SPI_FLASH like sf_dataflash, I can help if any issues with probing setup etc.
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Quoted 60 lines · Jagan Teki
Quoted 49 lines · Guochun Mao
Hi Jagan,
Quoted 37 lines · Jagan Teki
Quoted 37 lines
Quoted 22 lines
Quoted 22 lines
drivers/spi/mtk_qspi.c new file +22
-0+static int mtk_qspi_tx_rx (struct mtk_qspi_priv *priv) +{ +int len =1 + priv->txlen + priv->rxlen; +int i, ret, idx; + +if (len >MTK_QSPI_MAX_SHIFT ) +return -ERR_INVAL ; + +writeb (len *8 , &priv->regs->cnt); + +/* start at PRGDATA5, go down to PRGDATA0 */ + idx =MTK_QSPI_MAX_RX_TX_SHIFT -1 ; + +/* opcode */ +writeb (priv->op, &priv->regs->prgdata[idx]); + idx--; + +/* program TX data */ +for (i =0 ; i < priv->txlen; i++, idx--) +writeb (priv->tx[i], &priv->regs->prgdata[idx]); + +/* clear out rest of TX registers */ Quoted 8 lines
drivers/spi/mtk_qspi.c line 120
Quoted 6 lines
drivers/spi/mtk_qspi.c new file +6
-0+while (idx >=0 ) { +writeb (0 , &priv->regs->prgdata[idx]); + idx--; + } + + ret =mtk_qspi_execute_cmd (priv,MTK_QSPI_PRG_CMD );What does this execute do?
It send command to flash, and latch data if need.
Quoted 2 lines
does it intiate the controller register
based flash command or so?No, it doesn't.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Do you have Linux driver on the controller?
Yes, it's
drivers/mtd/spi-nor/mtk-quadspi.cThis sounds more specific to flash controller rather than spi driver. Can you try to write driver in mtd side itself, like Linux spi-nor. use
UCLASS_SPI_FLASHQuoted 9 lines
Sorry, I'm a little confused.
There are manyfiles(***qspi.c)those that used for accessing spi flash under folderdrivers/spi/.
However, there's no specific flash controller driver implemented under drives/mtd, only commonspi_flashframework. It's different with kernel. It seems that we only need implement the spi control logic of spi-flash-controller(this part not based on flash, it only do data-xfer), andspi_flashframework will work well base on it. Isn't that the purpose of this architecture?
Quoted 8 lines
Understand your point, to be precise the driver may a fall in trouble after sometime, if there is an additional flash specific features will attach in future. ie reason few of flash controllers in
drivers/spiwere unable to move further to add their features. and ie also reason for your driver in Linux which resides in spi-nor.You can directly write
UCLASS_SPI_FLASHlikesf_dataflash, I can help if any issues with probing setup etc.
Hi Jagan,
Could you reconsider this driver?
The code can match our needs for a considerable time, it's simple and doesn't disrupt current architecture.
If we switched to MTD_SPI_FLASH, there will inevitably be some duplicated codes. The current version of code adopts the sf/spi framework, it can guarantee compatibility and code reusability ratio.
If spi-mem or spi-nor was introduced to uboot in future, we can quickly implement new version code.
Thanks.
BR,
Guochun
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Quoted 78 lines · Guochun Mao
Quoted 60 lines · Jagan Teki
Quoted 49 lines · Guochun Mao
Hi Jagan,
Quoted 37 lines · Jagan Teki
Quoted 37 lines
Quoted 22 lines
Quoted 22 lines
(quoted diff) +22
-0+static int mtk_qspi_tx_rx(struct mtk_qspi_priv *priv) +{ + int len = 1 + priv->txlen + priv->rxlen; + int i, ret, idx; + + if (len > MTK_QSPI_MAX_SHIFT) + return -ERR_INVAL; + + writeb(len * 8, &priv->regs->cnt); + + /* start at PRGDATA5, go down to PRGDATA0 */ + idx = MTK_QSPI_MAX_RX_TX_SHIFT - 1; + + /* opcode */ + writeb(priv->op, &priv->regs->prgdata[idx]); + idx--; + + /* program TX data */ + for (i = 0; i < priv->txlen; i++, idx--) + writeb(priv->tx[i], &priv->regs->prgdata[idx]); + + /* clear out rest of TX registers */Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ while (idx >= 0) { + writeb(0, &priv->regs->prgdata[idx]); + idx--; + } + + ret = mtk_qspi_execute_cmd(priv, MTK_QSPI_PRG_CMD);What does this execute do?
It send command to flash, and latch data if need.
Quoted 2 lines
does it intiate the controller register
based flash command or so?No, it doesn't.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Do you have Linux driver on the controller?
Yes, it's
drivers/mtd/spi-nor/mtk-quadspi.cThis sounds more specific to flash controller rather than spi driver. Can you try to write driver in mtd side itself, like Linux spi-nor. use
UCLASS_SPI_FLASHQuoted 9 lines
Sorry, I'm a little confused.
There are manyfiles(***qspi.c)those that used for accessing spi flash under folderdrivers/spi/.
However, there's no specific flash controller driver implemented under drives/mtd, only commonspi_flashframework. It's different with kernel. It seems that we only need implement the spi control logic of spi-flash-controller(this part not based on flash, it only do data-xfer), andspi_flashframework will work well base on it. Isn't that the purpose of this architecture?Quoted 8 lines
Understand your point, to be precise the driver may a fall in trouble after sometime, if there is an additional flash specific features will attach in future. ie reason few of flash controllers in
drivers/spiwere unable to move further to add their features. and ie also reason for your driver in Linux which resides in spi-nor.You can directly write
UCLASS_SPI_FLASHlikesf_dataflash, I can help if any issues with probing setup etc.Hi Jagan,
Could you reconsider this driver?
The code can match our needs for a considerable time, it's simple and doesn't disrupt current architecture.
Quoted 6 lines
If we switched to
MTD_SPI_FLASH, there will inevitably be some duplicated codes. The current version of code adopts the sf/spi framework, it can guarantee compatibility and code reusability ratio.If spi-mem or spi-nor was introduced to uboot in future, we can quickly implement new version code.
Thanks.
Applied to u-boot-spi/master
PATCH v2 17/18 spi: mtk_qspi: add qspi driver for MT7629 SoC
Quoted 83 lines · Jagan Teki
Quoted 82 lines · Guochun Mao
Quoted 60 lines · Jagan Teki
Quoted 49 lines · Guochun Mao
Hi Jagan,
Quoted 37 lines · Jagan Teki
Quoted 37 lines
Quoted 22 lines
Quoted 22 lines
(quoted diff) +22
-0+static int mtk_qspi_tx_rx(struct mtk_qspi_priv *priv) +{ + int len = 1 + priv->txlen + priv->rxlen; + int i, ret, idx; + + if (len > MTK_QSPI_MAX_SHIFT) + return -ERR_INVAL; + + writeb(len * 8, &priv->regs->cnt); + + /* start at PRGDATA5, go down to PRGDATA0 */ + idx = MTK_QSPI_MAX_RX_TX_SHIFT - 1; + + /* opcode */ + writeb(priv->op, &priv->regs->prgdata[idx]); + idx--; + + /* program TX data */ + for (i = 0; i < priv->txlen; i++, idx--) + writeb(priv->tx[i], &priv->regs->prgdata[idx]); + + /* clear out rest of TX registers */Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ while (idx >= 0) { + writeb(0, &priv->regs->prgdata[idx]); + idx--; + } + + ret = mtk_qspi_execute_cmd(priv, MTK_QSPI_PRG_CMD);What does this execute do?
It send command to flash, and latch data if need.
Quoted 2 lines
does it intiate the controller register
based flash command or so?No, it doesn't.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Do you have Linux driver on the controller?
Yes, it's
drivers/mtd/spi-nor/mtk-quadspi.cThis sounds more specific to flash controller rather than spi driver. Can you try to write driver in mtd side itself, like Linux spi-nor. use
UCLASS_SPI_FLASHQuoted 9 lines
Sorry, I'm a little confused.
There are manyfiles(***qspi.c)those that used for accessing spi flash under folderdrivers/spi/.
However, there's no specific flash controller driver implemented under drives/mtd, only commonspi_flashframework. It's different with kernel. It seems that we only need implement the spi control logic of spi-flash-controller(this part not based on flash, it only do data-xfer), andspi_flashframework will work well base on it. Isn't that the purpose of this architecture?Quoted 8 lines
Understand your point, to be precise the driver may a fall in trouble after sometime, if there is an additional flash specific features will attach in future. ie reason few of flash controllers in
drivers/spiwere unable to move further to add their features. and ie also reason for your driver in Linux which resides in spi-nor.You can directly write
UCLASS_SPI_FLASHlikesf_dataflash, I can help if any issues with probing setup etc.Hi Jagan,
Could you reconsider this driver?
The code can match our needs for a considerable time, it's simple and doesn't disrupt current architecture.
If we switched to
MTD_SPI_FLASH, there will inevitably be some duplicated codes. The current version of code adopts the sf/spi framework, it can guarantee compatibility and code reusability ratio.
Quoted 6 lines
Quoted 2 lines
If spi-mem or spi-nor was introduced to uboot in future, we can quickly implement new version code.
Thanks.
Applied to u-boot-spi/master
Thanks for your great effort for the review.
Guochun
PATCH v2 18/18 MAINTAINERS: add an entry for MediaTek
In reply to Ryder LeeThis patch adds an entry for MediaTek.
--- MAINTAINERS | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
MAINTAINERS +18 -0
@@ -157,6 +157,24 @@ T: git git://git.denx.de/u-boot-pxa.git F: arch/arm/cpu/pxa/ F: arch/arm/include/asm/arch-pxa/ +ARM MEDIATEK +M: Ryder Lee <[email protected]> +M: Weijie Gao <[email protected]> +S: Maintained +F: arch/arm/mach-mediatek/ +F: arch/arm/include/asm/arch-mediatek/ +F: board/mediatek/ +F: drivers/clk/mediatek/ +F: drivers/mmc/mtk-sd.c +F: drivers/pinctrl/mediatek/ +F: drivers/power/domain/mtk-power-domain.c +F: drivers/ram/mediatek/ +F: drivers/spi/mtk_qspi.c +F: drivers/timer/mtk_timer.c +F: drivers/watchdog/mtk_wdt.c +F: tools/mtkimage.c +N: mediatek + ARM OWL M: Manivannan Sadhasivam <[email protected]> S: Maintained
Signature · 1 line
1.9.1
PATCH v2 18/18 MAINTAINERS: add an entry for MediaTek
Quoted 6 lines · Ryder Lee
This patch adds an entry for MediaTek.
Signed-off-by Ryder Lee <[email protected]>--- MAINTAINERS | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Please also add something like README.mediatek explaining what boards are supported and how to build and put on a board (or two).