Add support for MediaTek MT7981/MT7986 SoCs - v3
Subsystems (14)
v3 cover Add support for MediaTek MT7981/MT7986 SoCs - v3
This patch series add support for MediaTek MT7981/MT7986 SoCs with their reference boards and related drivers.
This patch series add basic boot support on eMMC/SD/SPI-NOR/SPI-NAND for these boards. The clock, pinctrl drivers and the SoC initializaton code are also included.
Product spec for MT7986:
https://www.mediatek.com/products/home-networking/mediatek-filogic-830
Changes of v3:
- Use regmap for cpu driver to access hwver registers
Changes of v2:
- Add cpu driver for print_cpuinfo()
- Fix NULL pointer dereference in mtk_image
- Fix coding style
- Minor changes
Weijie Gao (32):
arm: mediatek: add support for MediaTek MT7986 SoC
arm: mediatek: add support for MediaTek MT7981 SoC
board: mediatek: add MT7986 reference boards
board: mediatek: add MT7981 reference boards
mmc: mediatek: add support for MediaTek MT7891/MT7986 SoCs
net: mediatek: use a struct to cover variations of all SoCs
net: mediatek: stop using bitfileds for DMA descriptors
net: mediatek: add support for PDMA v2
net: mediatek: add support for MediaTek MT7981/MT7986
serial: mtk: add support for using dynamic baud clock souce
arm: dts: mt7622: force high-speed mode for uart
pwm: mtk: add support for MediaTek MT7986 SoC
pwm: mtk: add support for MediaTek MT7981 SoC
timer: mtk: add support for MediaTek MT7981/MT7986 SoCs
watchdog: mediatek: add support for MediaTek MT7986 SoC
spi: add support for MediaTek spi-mem controller
i2c: add support for MediaTek I2C interface
arm: dts: mt7622: add i2c support
dt-bindings: pinctrl: mediatek: add a header for common pinconf
parameters
pinctrl: mediatek: add pinctrl driver for MT7981 SoC
pinctrl: mediatek: add pinctrl driver for MT7986 SoC
clk: mediatek: add CLK_BYPASS_XTAL flag to allow bypassing searching
clock parent of xtal clock
clk: mediatek: add support to configure clock driver parent
clk: mediatek: add infrasys clock mux support
clk: mediatek: add CLK_XTAL support for clock driver
clk: mediatek: add clock driver support for MediaTek MT7986 SoC
clk: mediatek: add clock driver support for MediaTek MT7981 SoC
cpu: add basic cpu driver for MediaTek ARM chips
tools: mtk_image: split gfh header verification into a new function
tools: mtk_image: split the code of generating NAND header into a new
file
tools: mtk_image: add support for nand headers used by newer chips
MAINTAINERS: update maintainer for MediaTek ARM platform
MAINTAINERS | 6 + arch/arm/dts/Makefile | 9 + arch/arm/dts/mt7622-rfb.dts | 18 + arch/arm/dts/mt7622.dtsi | 25 + arch/arm/dts/mt7981-emmc-rfb.dts | 139 +++ arch/arm/dts/mt7981-rfb.dts | 173 +++ arch/arm/dts/mt7981-sd-rfb.dts | 139 +++ arch/arm/dts/mt7981.dtsi | 295 +++++ arch/arm/dts/mt7986-u-boot.dtsi | 33 + arch/arm/dts/mt7986.dtsi | 350 ++++++ arch/arm/dts/mt7986a-emmc-rfb.dts | 16 + arch/arm/dts/mt7986a-rfb.dts | 218 ++++ arch/arm/dts/mt7986a-sd-rfb.dts | 177 +++ arch/arm/dts/mt7986b-emmc-rfb.dts | 16 + arch/arm/dts/mt7986b-rfb.dts | 204 ++++ arch/arm/dts/mt7986b-sd-rfb.dts | 173 +++ arch/arm/mach-mediatek/Kconfig | 23 + arch/arm/mach-mediatek/Makefile | 2 + arch/arm/mach-mediatek/mt7981/Makefile | 4 + arch/arm/mach-mediatek/mt7981/init.c | 45 + arch/arm/mach-mediatek/mt7981/lowlevel_init.S | 32 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 45 + arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 32 + board/mediatek/mt7981/MAINTAINERS | 10 + board/mediatek/mt7981/Makefile | 3 + board/mediatek/mt7981/mt7981_rfb.c | 10 + board/mediatek/mt7986/MAINTAINERS | 10 + board/mediatek/mt7986/Makefile | 3 + board/mediatek/mt7986/mt7986_rfb.c | 10 + configs/mt7981_emmc_rfb_defconfig | 64 + configs/mt7981_rfb_defconfig | 69 ++ configs/mt7981_sd_rfb_defconfig | 64 + configs/mt7986_rfb_defconfig | 66 ++ configs/mt7986a_bpir3_emmc_defconfig | 64 + configs/mt7986a_bpir3_sd_defconfig | 64 + drivers/clk/mediatek/Makefile | 2 + drivers/clk/mediatek/clk-mt7981.c | 683 +++++++++++ drivers/clk/mediatek/clk-mt7986.c | 672 +++++++++++ drivers/clk/mediatek/clk-mtk.c | 156 ++- drivers/clk/mediatek/clk-mtk.h | 13 +- drivers/cpu/Makefile | 1 + drivers/cpu/mtk_cpu.c | 86 ++ drivers/i2c/Kconfig | 9 + drivers/i2c/Makefile | 1 + drivers/i2c/mtk_i2c.c | 822 +++++++++++++ drivers/mmc/mtk-sd.c | 68 +- drivers/net/mtk_eth.c | 261 ++-- drivers/net/mtk_eth.h | 101 +- drivers/pinctrl/mediatek/Kconfig | 8 + drivers/pinctrl/mediatek/Makefile | 2 + drivers/pinctrl/mediatek/pinctrl-mt7981.c | 1049 +++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-mt7986.c | 775 ++++++++++++ drivers/pwm/pwm-mtk.c | 40 +- drivers/serial/serial_mtk.c | 80 +- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/mtk_spim.c | 701 +++++++++++ drivers/timer/mtk_timer.c | 59 +- drivers/watchdog/mtk_wdt.c | 1 + include/configs/mt7981.h | 26 + include/configs/mt7986.h | 26 + include/dt-bindings/clock/mt7981-clk.h | 267 +++++ include/dt-bindings/clock/mt7986-clk.h | 249 ++++ include/dt-bindings/pinctrl/mt65xx.h | 41 + tools/Makefile | 1 + tools/mtk_image.c | 377 ++---- tools/mtk_image.h | 25 - tools/mtk_nand_headers.c | 668 +++++++++++ tools/mtk_nand_headers.h | 165 +++ 70 files changed, 9511 insertions(+), 548 deletions(-) create mode 100644 arch/arm/dts/mt7981-emmc-rfb.dts create mode 100644 arch/arm/dts/mt7981-rfb.dts create mode 100644 arch/arm/dts/mt7981-sd-rfb.dts create mode 100644 arch/arm/dts/mt7981.dtsi create mode 100644 arch/arm/dts/mt7986-u-boot.dtsi create mode 100644 arch/arm/dts/mt7986.dtsi create mode 100644 arch/arm/dts/mt7986a-emmc-rfb.dts create mode 100644 arch/arm/dts/mt7986a-rfb.dts create mode 100644 arch/arm/dts/mt7986a-sd-rfb.dts create mode 100644 arch/arm/dts/mt7986b-emmc-rfb.dts create mode 100644 arch/arm/dts/mt7986b-rfb.dts create mode 100644 arch/arm/dts/mt7986b-sd-rfb.dts create mode 100644 arch/arm/mach-mediatek/mt7981/Makefile create mode 100644 arch/arm/mach-mediatek/mt7981/init.c create mode 100644 arch/arm/mach-mediatek/mt7981/lowlevel_init.S create mode 100644 arch/arm/mach-mediatek/mt7986/Makefile create mode 100644 arch/arm/mach-mediatek/mt7986/init.c create mode 100644 arch/arm/mach-mediatek/mt7986/lowlevel_init.S create mode 100644 board/mediatek/mt7981/MAINTAINERS create mode 100644 board/mediatek/mt7981/Makefile create mode 100644 board/mediatek/mt7981/mt7981_rfb.c create mode 100644 board/mediatek/mt7986/MAINTAINERS create mode 100644 board/mediatek/mt7986/Makefile create mode 100644 board/mediatek/mt7986/mt7986_rfb.c create mode 100644 configs/mt7981_emmc_rfb_defconfig create mode 100644 configs/mt7981_rfb_defconfig create mode 100644 configs/mt7981_sd_rfb_defconfig create mode 100644 configs/mt7986_rfb_defconfig create mode 100644 configs/mt7986a_bpir3_emmc_defconfig create mode 100644 configs/mt7986a_bpir3_sd_defconfig create mode 100644 drivers/clk/mediatek/clk-mt7981.c create mode 100644 drivers/clk/mediatek/clk-mt7986.c create mode 100644 drivers/cpu/mtk_cpu.c create mode 100644 drivers/i2c/mtk_i2c.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7981.c create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7986.c create mode 100644 drivers/spi/mtk_spim.c create mode 100644 include/configs/mt7981.h create mode 100644 include/configs/mt7986.h create mode 100644 include/dt-bindings/clock/mt7981-clk.h create mode 100644 include/dt-bindings/clock/mt7986-clk.h create mode 100644 include/dt-bindings/pinctrl/mt65xx.h create mode 100644 tools/mtk_nand_headers.c create mode 100644 tools/mtk_nand_headers.h
Signature · 1 line
2.17.1
PATCH v3 1/32 arm: mediatek: add support for MediaTek MT7986 SoC
This patch adds basic support for MediaTek MT7986 SoC. This include the file that will initialize the SoC after boot and its device tree.
---
v3 changes:
Add syscon to hwver node
Add reference of hwver to cpu nodes
v2 changes:
Sort include lines
Add reference link for armv8_el2_to_aarch32 in lowlevel_init.S Remove print_cpuinfo and use cpu driver instead
--- arch/arm/dts/mt7986-u-boot.dtsi | 33 ++ arch/arm/dts/mt7986.dtsi | 350 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 12 + arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 45 +++ arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 32 ++ 7 files changed, 477 insertions(+) create mode 100644 arch/arm/dts/mt7986-u-boot.dtsi create mode 100644 arch/arm/dts/mt7986.dtsi create mode 100644 arch/arm/mach-mediatek/mt7986/Makefile create mode 100644 arch/arm/mach-mediatek/mt7986/init.c create mode 100644 arch/arm/mach-mediatek/mt7986/lowlevel_init.S
arch/arm/dts/mt7986-u-boot.dtsi new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 MediaTek Inc. + * Author: Sam Shih <[email protected]> + */ + +&topckgen { + u-boot,dm-pre-reloc; +}; + +&pericfg { + u-boot,dm-pre-reloc; +}; + +&apmixedsys { + u-boot,dm-pre-reloc; +}; + +&timer0 { + u-boot,dm-pre-reloc; +}; + +&uart0 { + u-boot,dm-pre-reloc; +}; + +&snand { + u-boot,dm-pre-reloc; +}; + +&pinctrl { + u-boot,dm-pre-reloc; +};
arch/arm/dts/mt7986.dtsi new file +350 -0
350 lines not on this page · raw message
arch/arm/mach-mediatek/Kconfig +12 -0
@@ -40,6 +40,15 @@ config TARGET_MT7629 including DDR3, crypto engine, 3x3 11n/ac Wi-Fi, Gigabit Ethernet, switch, USB3.0, PCIe, UART, SPI, I2C and PWM. +config TARGET_MT7986 + bool "MediaTek MT7986 SoC" + select ARM64 + select CPU + help + The MediaTek MT7986 is a ARM64-based SoC with a quad-core Cortex-A53. + including UART, SPI, SPI flash, USB3.0, MMC, NAND, SNFI, PWM, PCIe, + Gigabit Ethernet, I2C, built-in 4x4 Wi-Fi, and PCIe. + config TARGET_MT8183 bool "MediaTek MT8183 SoC" select ARM64
@@ -84,6 +93,7 @@ config SYS_BOARD default "mt7622" if TARGET_MT7622 default "mt7623" if TARGET_MT7623 default "mt7629" if TARGET_MT7629 + default "mt7986" if TARGET_MT7986 default "mt8183" if TARGET_MT8183 default "mt8512" if TARGET_MT8512 default "mt8516" if TARGET_MT8516
@@ -99,6 +109,7 @@ config SYS_CONFIG_NAME default "mt7622" if TARGET_MT7622 default "mt7623" if TARGET_MT7623 default "mt7629" if TARGET_MT7629 + default "mt7986" if TARGET_MT7986 default "mt8183" if TARGET_MT8183 default "mt8512" if TARGET_MT8512 default "mt8516" if TARGET_MT8516
@@ -113,6 +124,7 @@ config MTK_BROM_HEADER_INFO string default "media=nor" if TARGET_MT8518 || TARGET_MT8512 || TARGET_MT7629 || TARGET_MT7622 default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183 + default "media=snand;nandinfo=2k+64" if TARGET_MT7986 default "lk=1" if TARGET_MT7623 endif
arch/arm/mach-mediatek/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_MT8512) += mt8512/ obj-$(CONFIG_TARGET_MT7622) += mt7622/ obj-$(CONFIG_TARGET_MT7623) += mt7623/ obj-$(CONFIG_TARGET_MT7629) += mt7629/ +obj-$(CONFIG_TARGET_MT7986) += mt7986/ obj-$(CONFIG_TARGET_MT8183) += mt8183/ obj-$(CONFIG_TARGET_MT8516) += mt8516/ obj-$(CONFIG_TARGET_MT8518) += mt8518/
arch/arm/mach-mediatek/mt7986/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/mt7986/init.c new file +45 -0
45 lines not on this page · raw message
arch/arm/mach-mediatek/mt7986/lowlevel_init.S new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022 MediaTek Inc. + * Author: Sam Shih <[email protected]> + */ + +/* + * Switch from AArch64 EL2 to AArch32 EL2 + * @param inputs: + * x0: argument, zero + * x1: machine nr + * x2: fdt address + * x3: input argument + * x4: kernel entry point + * @param outputs for secure firmware: + * x0: function id + * x1: kernel entry point + * x2: machine nr + * x3: fdt address + * + * [1] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/mediatek/common/mtk_sip_svc.c +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 /* MTK_SIP_KERNEL_BOOT_AARCH32 */ + SMC #0 + ret
Signature · 1 line
2.17.1
PATCH v3 2/32 arm: mediatek: add support for MediaTek MT7981 SoC
In reply to Weijie GaoThis patch adds basic support for MediaTek MT7981 SoC. This include the file that will initialize the SoC after boot and its device tree.
---
v3 changes:
Add syscon to hwver node
Add reference of hwver to cpu nodes
v2 changes:
Sort include lines
Add reference link for armv8_el2_to_aarch32 in lowlevel_init.S Remove print_cpuinfo and use cpu driver instead
--- arch/arm/dts/mt7981.dtsi | 295 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 13 +- arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7981/Makefile | 4 + arch/arm/mach-mediatek/mt7981/init.c | 45 +++ arch/arm/mach-mediatek/mt7981/lowlevel_init.S | 32 ++ 6 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 arch/arm/dts/mt7981.dtsi create mode 100644 arch/arm/mach-mediatek/mt7981/Makefile create mode 100644 arch/arm/mach-mediatek/mt7981/init.c create mode 100644 arch/arm/mach-mediatek/mt7981/lowlevel_init.S
arch/arm/dts/mt7981.dtsi new file +295 -0
@@ -0,0 +1,295 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 MediaTek Inc. + * Author: Sam Shih <[email protected]> + */ + +#include <dt-bindings/interrupt-controller/irq.h> +#include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/clock/mt7981-clk.h> +#include <dt-bindings/reset/mt7629-reset.h> +#include <dt-bindings/pinctrl/mt65xx.h> + +/ { + compatible = "mediatek,mt7981"; + interrupt-parent = <&gic>; + #address-cells = <1>; + #size-cells = <1>; + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x0>; + mediatek,hwver = <&hwver>; + }; + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + mediatek,hwver = <&hwver>; + }; + }; + + gpt_clk: gpt_dummy20m { + compatible = "fixed-clock"; + clock-frequency = <13000000>; + #clock-cells = <0>; + u-boot,dm-pre-reloc; + }; + + hwver: hwver { + compatible = "mediatek,hwver", "syscon"; + reg = <0x8000000 0x1000>; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupt-parent = <&gic>; + clock-frequency = <13000000>; + interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, + <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>, + <GIC_PPI 11 IRQ_TYPE_LEVEL_LOW>, + <GIC_PPI 10 IRQ_TYPE_LEVEL_LOW>; + arm,cpu-registers-not-fw-configured; + }; + + timer0: timer@10008000 { + compatible = "mediatek,mt7986-timer"; + reg = <0x10008000 0x1000>; + interrupts = <GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&gpt_clk>; + clock-names = "gpt-clk"; + u-boot,dm-pre-reloc; + }; + + watchdog: watchdog@1001c000 { + compatible = "mediatek,mt7986-wdt"; + reg = <0x1001c000 0x1000>; + interrupts = <GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>; + #reset-cells = <1>; + status = "disabled"; + }; + + gic: interrupt-controller@c000000 { + compatible = "arm,gic-v3"; + #interrupt-cells = <3>; + interrupt-parent = <&gic>; + interrupt-controller; + reg = <0x0c000000 0x40000>, /* GICD */ + <0x0c080000 0x200000>; /* GICR */ + + interrupts = <GIC_PPI 9 IRQ_TYPE_LEVEL_HIGH>; + }; + + fixed_plls: apmixedsys@1001e000 { + compatible = "mediatek,mt7981-fixed-plls"; + reg = <0x1001e000 0x1000>; + #clock-cells = <1>; + u-boot,dm-pre-reloc; + }; + + topckgen: topckgen@1001b000 { + compatible = "mediatek,mt7981-topckgen"; + reg = <0x1001b000 0x1000>; + clock-parent = <&fixed_plls>; + #clock-cells = <1>; + u-boot,dm-pre-reloc; + }; + + infracfg_ao: infracfg_ao@10001000 { + compatible = "mediatek,mt7981-infracfg_ao"; + reg = <0x10001000 0x80>; + clock-parent = <&infracfg>; + #clock-cells = <1>; + u-boot,dm-pre-reloc; + }; + + infracfg: infracfg@10001000 { + compatible = "mediatek,mt7981-infracfg"; + reg = <0x10001000 0x30>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + u-boot,dm-pre-reloc; + }; + + pinctrl: pinctrl@11d00000 { + compatible = "mediatek,mt7981-pinctrl"; + reg = <0x11d00000 0x1000>, + <0x11c00000 0x1000>, + <0x11c10000 0x1000>, + <0x11d20000 0x1000>, + <0x11e00000 0x1000>, + <0x11e20000 0x1000>, + <0x11f00000 0x1000>, + <0x11f10000 0x1000>, + <0x1000b000 0x1000>; + reg-names = "gpio_base", "iocfg_rt_base", "iocfg_rm_base", + "iocfg_rb_base", "iocfg_lb_base", "iocfg_bl_base", + "iocfg_tm_base", "iocfg_tl_base", "eint"; + gpio: gpio-controller { + gpio-controller; + #gpio-cells = <2>; + }; + }; + + pwm: pwm@10048000 { + compatible = "mediatek,mt7981-pwm"; + reg = <0x10048000 0x1000>; + #clock-cells = <1>; + #pwm-cells = <2>; + interrupts = <GIC_SPI 137 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&infracfg CK_INFRA_PWM>, + <&infracfg_ao CK_INFRA_PWM_BSEL>, + <&infracfg_ao CK_INFRA_PWM1_CK>, + <&infracfg_ao CK_INFRA_PWM2_CK>, + /* FIXME */ + <&infracfg_ao CK_INFRA_PWM2_CK>; + assigned-clocks = <&topckgen CK_TOP_PWM_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_CKSQ_40M>; + clock-names = "top", "main", "pwm1", "pwm2", "pwm3"; + status = "disabled"; + }; + + uart0: serial@11002000 { + compatible = "mediatek,hsuart"; + reg = <0x11002000 0x400>; + interrupts = <GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&infracfg_ao CK_INFRA_UART0_CK>; + assigned-clocks = <&topckgen CK_TOP_UART_SEL>, + <&infracfg_ao CK_INFRA_UART0_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_CKSQ_40M>, + <&infracfg CK_INFRA_UART>; + mediatek,force-highspeed; + status = "disabled"; + u-boot,dm-pre-reloc; + }; + + uart1: serial@11003000 { + compatible = "mediatek,hsuart"; + reg = <0x11003000 0x400>; + interrupts = <GIC_SPI 124 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&infracfg_ao CK_INFRA_UART1_CK>; + assigned-clocks = <&topckgen CK_TOP_UART_SEL>, + <&infracfg_ao CK_INFRA_UART1_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_CKSQ_40M>, + <&infracfg CK_INFRA_UART>; + mediatek,force-highspeed; + status = "disabled"; + }; + + uart2: serial@11004000 { + compatible = "mediatek,hsuart"; + reg = <0x11004000 0x400>; + interrupts = <GIC_SPI 124 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&infracfg_ao CK_INFRA_UART2_CK>; + assigned-clocks = <&topckgen CK_TOP_UART_SEL>, + <&infracfg_ao CK_INFRA_UART2_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_CKSQ_40M>, + <&infracfg CK_INFRA_UART>; + mediatek,force-highspeed; + status = "disabled"; + }; + + snand: snand@11005000 { + compatible = "mediatek,mt7986-snand"; + reg = <0x11005000 0x1000>, + <0x11006000 0x1000>; + reg-names = "nfi", "ecc"; + clocks = <&infracfg_ao CK_INFRA_SPINFI1_CK>, + <&infracfg_ao CK_INFRA_NFI1_CK>, + <&infracfg_ao CK_INFRA_NFI_HCK_CK>; + clock-names = "pad_clk", "nfi_clk", "nfi_hclk"; + assigned-clocks = <&topckgen CK_TOP_SPINFI_SEL>, + <&topckgen CK_TOP_NFI1X_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_M_D8>, + <&topckgen CK_TOP_CB_M_D8>; + status = "disabled"; + }; + + ethsys: syscon@15000000 { + compatible = "mediatek,mt7981-ethsys", "syscon"; + reg = <0x15000000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + + eth: ethernet@15100000 { + compatible = "mediatek,mt7981-eth", "syscon"; + reg = <0x15100000 0x20000>; + resets = <ðsys ETHSYS_FE_RST>; + reset-names = "fe"; + mediatek,ethsys = <ðsys>; + mediatek,sgmiisys = <&sgmiisys0>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + sgmiisys0: syscon@10060000 { + compatible = "mediatek,mt7986-sgmiisys", "syscon"; + reg = <0x10060000 0x1000>; + pn_swap; + #clock-cells = <1>; + }; + + sgmiisys1: syscon@10070000 { + compatible = "mediatek,mt7986-sgmiisys", "syscon"; + reg = <0x10070000 0x1000>; + #clock-cells = <1>; + }; + + spi0: spi@1100a000 { + compatible = "mediatek,ipm-spi"; + reg = <0x1100a000 0x100>; + clocks = <&infracfg_ao CK_INFRA_SPI0_CK>, + <&topckgen CK_TOP_SPI_SEL>; + assigned-clocks = <&topckgen CK_TOP_SPI_SEL>, + <&infracfg CK_INFRA_SPI0_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_M_D2>, + <&topckgen CK_INFRA_ISPI0>; + clock-names = "sel-clk", "spi-clk"; + interrupts = <GIC_SPI 140 IRQ_TYPE_LEVEL_HIGH>; + status = "disabled"; + }; + + spi1: spi@1100b000 { + compatible = "mediatek,ipm-spi"; + reg = <0x1100b000 0x100>; + interrupts = <GIC_SPI 141 IRQ_TYPE_LEVEL_HIGH>; + status = "disabled"; + }; + + spi2: spi@11009000 { + compatible = "mediatek,ipm-spi"; + reg = <0x11009000 0x100>; + clocks = <&infracfg_ao CK_INFRA_SPI0_CK>, + <&topckgen CK_TOP_SPI_SEL>; + assigned-clocks = <&topckgen CK_TOP_SPI_SEL>, + <&infracfg CK_INFRA_SPI0_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_M_D2>, + <&topckgen CK_INFRA_ISPI0>; + clock-names = "sel-clk", "spi-clk"; + interrupts = <GIC_SPI 142 IRQ_TYPE_LEVEL_HIGH>; + status = "disabled"; + }; + + mmc0: mmc@11230000 { + compatible = "mediatek,mt7981-mmc"; + reg = <0x11230000 0x1000>, + <0x11C20000 0x1000>; + interrupts = <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&topckgen CK_TOP_EMMC_400M>, + <&topckgen CK_TOP_EMMC_208M>, + <&infracfg_ao CK_INFRA_MSDC_CK>; + assigned-clocks = <&topckgen CK_TOP_EMMC_400M_SEL>, + <&topckgen CK_TOP_EMMC_208M_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_NET2_D2>, + <&topckgen CK_TOP_CB_M_D2>; + clock-names = "source", "hclk", "source_cg"; + status = "disabled"; + }; + +};
arch/arm/mach-mediatek/Kconfig +12 -1
@@ -40,6 +40,15 @@ config TARGET_MT7629 including DDR3, crypto engine, 3x3 11n/ac Wi-Fi, Gigabit Ethernet, switch, USB3.0, PCIe, UART, SPI, I2C and PWM. +config TARGET_MT7981 + bool "MediaTek MT7981 SoC" + select ARM64 + select CPU + help + The MediaTek MT7981 is a ARM64-based SoC with a dual-core Cortex-A53. + including UART, SPI, USB, NAND, SNFI, PWM, Gigabit Ethernet, I2C, + built-in Wi-Fi, and PCIe. + config TARGET_MT7986 bool "MediaTek MT7986 SoC" select ARM64
@@ -93,6 +102,7 @@ config SYS_BOARD default "mt7622" if TARGET_MT7622 default "mt7623" if TARGET_MT7623 default "mt7629" if TARGET_MT7629 + default "mt7981" if TARGET_MT7981 default "mt7986" if TARGET_MT7986 default "mt8183" if TARGET_MT8183 default "mt8512" if TARGET_MT8512
@@ -109,6 +119,7 @@ config SYS_CONFIG_NAME default "mt7622" if TARGET_MT7622 default "mt7623" if TARGET_MT7623 default "mt7629" if TARGET_MT7629 + default "mt7981" if TARGET_MT7981 default "mt7986" if TARGET_MT7986 default "mt8183" if TARGET_MT8183 default "mt8512" if TARGET_MT8512
@@ -124,7 +135,7 @@ config MTK_BROM_HEADER_INFO string default "media=nor" if TARGET_MT8518 || TARGET_MT8512 || TARGET_MT7629 || TARGET_MT7622 default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183 - default "media=snand;nandinfo=2k+64" if TARGET_MT7986 + default "media=snand;nandinfo=2k+64" if TARGET_MT7981 || TARGET_MT7986 default "lk=1" if TARGET_MT7623 endif
arch/arm/mach-mediatek/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_MT8512) += mt8512/ obj-$(CONFIG_TARGET_MT7622) += mt7622/ obj-$(CONFIG_TARGET_MT7623) += mt7623/ obj-$(CONFIG_TARGET_MT7629) += mt7629/ +obj-$(CONFIG_TARGET_MT7981) += mt7981/ obj-$(CONFIG_TARGET_MT7986) += mt7986/ obj-$(CONFIG_TARGET_MT8183) += mt8183/ obj-$(CONFIG_TARGET_MT8516) += mt8516/
arch/arm/mach-mediatek/mt7981/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/mt7981/init.c new file +45 -0
45 lines not on this page · raw message
arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022 MediaTek Inc. + * Author: Sam Shih <[email protected]> + */ + +/* + * Switch from AArch64 EL2 to AArch32 EL2 + * @param inputs: + * x0: argument, zero + * x1: machine nr + * x2: fdt address + * x3: input argument + * x4: kernel entry point + * @param outputs for secure firmware: + * x0: function id + * x1: kernel entry point + * x2: machine nr + * x3: fdt address + * + * [1] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/mediatek/common/mtk_sip_svc.c +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 /* MTK_SIP_KERNEL_BOOT_AARCH32 */ + SMC #0 + ret
Signature · 1 line
2.17.1
PATCH v3 3/32 board: mediatek: add MT7986 reference boards
In reply to Weijie GaoAdd general board files based on MT7986 SoCs.
MT7986 uses one mmc controller for booting from both SD and eMMC. Both MT7986A and MT7986B use the same pins for spi controller.
Configs for various boot types:
1. mt7986_rfb_defconfig - SPI-NOR and SPI-NAND for MT7986A/B
2. mt7986a_bpir3_emmc_defconfig - eMMC for MT7986A only
3. mt7986a_bpir3_sd_defconfig - SD for MT7986A only
---
v3 changes: none
v2 changes:
Rename mt7986a_emmc_rfb_defconfig to mt7986a_bpir3_emmc_defconfig Rename mt7986a_sd_rfb_defconfig to mt7986a_bpir3_sd_defconfig Remove mt7986b defconfig
--- arch/arm/dts/Makefile | 6 + arch/arm/dts/mt7986a-emmc-rfb.dts | 16 ++ arch/arm/dts/mt7986a-rfb.dts | 218 +++++++++++++++++++++++++++ arch/arm/dts/mt7986a-sd-rfb.dts | 177 ++++++++++++++++++++++ arch/arm/dts/mt7986b-emmc-rfb.dts | 16 ++ arch/arm/dts/mt7986b-rfb.dts | 204 +++++++++++++++++++++++++ arch/arm/dts/mt7986b-sd-rfb.dts | 173 +++++++++++++++++++++ board/mediatek/mt7986/MAINTAINERS | 10 ++ board/mediatek/mt7986/Makefile | 3 + board/mediatek/mt7986/mt7986_rfb.c | 10 ++ configs/mt7986_rfb_defconfig | 66 ++++++++ configs/mt7986a_bpir3_emmc_defconfig | 64 ++++++++ configs/mt7986a_bpir3_sd_defconfig | 64 ++++++++ include/configs/mt7986.h | 26 ++++ 14 files changed, 1053 insertions(+) create mode 100644 arch/arm/dts/mt7986a-emmc-rfb.dts create mode 100644 arch/arm/dts/mt7986a-rfb.dts create mode 100644 arch/arm/dts/mt7986a-sd-rfb.dts create mode 100644 arch/arm/dts/mt7986b-emmc-rfb.dts create mode 100644 arch/arm/dts/mt7986b-rfb.dts create mode 100644 arch/arm/dts/mt7986b-sd-rfb.dts create mode 100644 board/mediatek/mt7986/MAINTAINERS create mode 100644 board/mediatek/mt7986/Makefile create mode 100644 board/mediatek/mt7986/mt7986_rfb.c create mode 100644 configs/mt7986_rfb_defconfig create mode 100644 configs/mt7986a_bpir3_emmc_defconfig create mode 100644 configs/mt7986a_bpir3_sd_defconfig create mode 100644 include/configs/mt7986.h
arch/arm/dts/Makefile +6 -0
@@ -1230,6 +1230,12 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \ mt7622-bananapi-bpi-r64.dtb \ mt7623n-bananapi-bpi-r2.dtb \ mt7629-rfb.dtb \ + mt7986a-rfb.dtb \ + mt7986b-rfb.dtb \ + mt7986a-sd-rfb.dtb \ + mt7986b-sd-rfb.dtb \ + mt7986a-emmc-rfb.dtb \ + mt7986b-emmc-rfb.dtb \ mt8183-pumpkin.dtb \ mt8512-bm1-emmc.dtb \ mt8516-pumpkin.dtb \
arch/arm/dts/mt7986a-emmc-rfb.dts new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 MediaTek Inc. + * Author: Sam Shih <[email protected]> + */ + +/dts-v1/; +#include "mt7986a-rfb.dts" + +/ { + compatible = "mediatek,mt7986", "mediatek,mt7986-rfb", + "mediatek,mt7986-emmc-rfb"; + bl2_verify { + bl2_compatible = "emmc"; + }; +};
arch/arm/dts/mt7986a-rfb.dts new file +218 -0
218 lines not on this page · raw message
arch/arm/dts/mt7986a-sd-rfb.dts new file +177 -0
177 lines not on this page · raw message
arch/arm/dts/mt7986b-emmc-rfb.dts new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 MediaTek Inc. + * Author: Sam Shih <[email protected]> + */ + +/dts-v1/; +#include "mt7986a-rfb.dts" + +/ { + compatible = "mediatek,mt7986", "mediatek,mt7986-rfb", + "mediatek,mt7986-emmc-rfb"; + bl2_verify { + bl2_compatible = "emmc"; + }; +};
arch/arm/dts/mt7986b-rfb.dts new file +204 -0
204 lines not on this page · raw message
arch/arm/dts/mt7986b-sd-rfb.dts new file +173 -0
173 lines not on this page · raw message
board/mediatek/mt7986/MAINTAINERS new file +10 -0
@@ -0,0 +1,10 @@ +MT7986 +M: Sam Shih <[email protected]> +S: Maintained +F: board/mediatek/mt7986 +F: include/configs/mt7986.h +F: configs/mt7986_rfb_defconfig +F: configs/mt7986a_emmc_rfb_defconfig +F: configs/mt7986a_sd_rfb_defconfig +F: configs/mt7986b_emmc_rfb_defconfig +F: configs/mt7986b_sd_rfb_defconfig
board/mediatek/mt7986/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += mt7986_rfb.o
board/mediatek/mt7986/mt7986_rfb.c new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +int board_init (void ) +{ +return 0 ; +}
configs/mt7986_rfb_defconfig new file +66 -0
66 lines not on this page · raw message
configs/mt7986a_bpir3_emmc_defconfig new file +64 -0
64 lines not on this page · raw message
configs/mt7986a_bpir3_sd_defconfig new file +64 -0
64 lines not on this page · raw message
include/configs/mt7986.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Configuration for MediaTek MT7986 SoC +* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#ifndef __MT7986_H +#define __MT7986_H + +#include <linux/sizes.h> + +#define CONFIG_SYS_NONCACHED_MEMORY SZ_1M +#define CONFIG_SYS_MMC_ENV_DEV 0 + +/* Uboot definition */ +#define CONFIG_SYS_UBOOT_BASE CONFIG_SYS_TEXT_BASE + +/* SPL -> Uboot */ +#define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE + +/* DRAM */ +#define CONFIG_SYS_SDRAM_BASE 0x40000000 + +#endif
Signature · 1 line
2.17.1
PATCH v3 4/32 board: mediatek: add MT7981 reference boards
In reply to Weijie GaoThis patch adds general board files based on MT7981 SoCs.
MT7981 uses one mmc controller for booting from both SD and eMMC, and the pins of mmc controller are also shared with spi controller. So three configs are need for these boot types:
1. mt7981_rfb_defconfig - SPI-NOR and SPI-NAND
2. mt7981_emmc_rfb_defconfig - eMMC only
3. mt7981_sd_rfb_defconfig - SD only
---
v3 changes: none
v2 changes:
Remove mt7981_spim_nand_rfb_defconfig and mt7981_spim_nor_rfb_defconfig
--- arch/arm/dts/Makefile | 3 + arch/arm/dts/mt7981-emmc-rfb.dts | 139 +++++++++++++++++++++++ arch/arm/dts/mt7981-rfb.dts | 173 +++++++++++++++++++++++++++++ arch/arm/dts/mt7981-sd-rfb.dts | 139 +++++++++++++++++++++++ board/mediatek/mt7981/MAINTAINERS | 10 ++ board/mediatek/mt7981/Makefile | 3 + board/mediatek/mt7981/mt7981_rfb.c | 10 ++ configs/mt7981_emmc_rfb_defconfig | 64 +++++++++++ configs/mt7981_rfb_defconfig | 69 ++++++++++++ configs/mt7981_sd_rfb_defconfig | 64 +++++++++++ include/configs/mt7981.h | 26 +++++ 11 files changed, 700 insertions(+) create mode 100644 arch/arm/dts/mt7981-emmc-rfb.dts create mode 100644 arch/arm/dts/mt7981-rfb.dts create mode 100644 arch/arm/dts/mt7981-sd-rfb.dts create mode 100644 board/mediatek/mt7981/MAINTAINERS create mode 100644 board/mediatek/mt7981/Makefile create mode 100644 board/mediatek/mt7981/mt7981_rfb.c create mode 100644 configs/mt7981_emmc_rfb_defconfig create mode 100644 configs/mt7981_rfb_defconfig create mode 100644 configs/mt7981_sd_rfb_defconfig create mode 100644 include/configs/mt7981.h
arch/arm/dts/Makefile +3 -0
@@ -1230,6 +1230,9 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \ mt7622-bananapi-bpi-r64.dtb \ mt7623n-bananapi-bpi-r2.dtb \ mt7629-rfb.dtb \ + mt7981-rfb.dtb \ + mt7981-emmc-rfb.dtb \ + mt7981-sd-rfb.dtb \ mt7986a-rfb.dtb \ mt7986b-rfb.dtb \ mt7986a-sd-rfb.dtb \
arch/arm/dts/mt7981-emmc-rfb.dts new file +139 -0
139 lines not on this page · raw message
arch/arm/dts/mt7981-rfb.dts new file +173 -0
173 lines not on this page · raw message
arch/arm/dts/mt7981-sd-rfb.dts new file +139 -0
139 lines not on this page · raw message
board/mediatek/mt7981/MAINTAINERS new file +10 -0
@@ -0,0 +1,10 @@ +MT7981 +M: Sam Shih <[email protected]> +S: Maintained +F: board/mediatek/mt7981 +F: include/configs/mt7981.h +F: configs/mt7981_emmc_rfb_defconfig +F: configs/mt7981_rfb_defconfig +F: configs/mt7981_sd_rfb_defconfig +F: configs/mt7981_spim_nand_rfb_defconfig +F: configs/mt7981_spim_nor_rfb_defconfig
board/mediatek/mt7981/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y += mt7981_rfb.o
board/mediatek/mt7981/mt7981_rfb.c new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +int board_init (void ) +{ +return 0 ; +}
configs/mt7981_emmc_rfb_defconfig new file +64 -0
64 lines not on this page · raw message
configs/mt7981_rfb_defconfig new file +69 -0
69 lines not on this page · raw message
configs/mt7981_sd_rfb_defconfig new file +64 -0
64 lines not on this page · raw message
include/configs/mt7981.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Configuration for MediaTek MT7981 SoC +* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#ifndef __MT7981_H +#define __MT7981_H + +#include <linux/sizes.h> + +#define CONFIG_SYS_NONCACHED_MEMORY SZ_1M +#define CONFIG_SYS_MMC_ENV_DEV 0 + +/* Uboot definition */ +#define CONFIG_SYS_UBOOT_BASE CONFIG_SYS_TEXT_BASE + +/* SPL -> Uboot */ +#define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE + +/* DRAM */ +#define CONFIG_SYS_SDRAM_BASE 0x40000000 + +#endif
Signature · 1 line
2.17.1
PATCH v3 5/32 mmc: mediatek: add support for MediaTek MT7891/MT7986 SoCs
In reply to Weijie GaoAdd eMMC and SDXC support for MediaTek MT7981/MT7986 SoCs Both chips support SDXC and eMMC 4.5. MT7986A supports eMMC 5.1.
---
v3 changes: none
v2 changes: none
--- drivers/mmc/mtk-sd.c | 68 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 15 deletions(-)
drivers/mmc/mtk-sd.c +53 -15
@@ -1496,7 +1496,12 @@ static void msdc_init_hw(struct msdc_host *host)/* Enable data & cmd interrupts */ writel (DATA_INTS_MASK |CMD_INTS_MASK , &host->base->msdc_inten); -writel (0 , tune_reg); +if (host->top_base) { +writel (0 , &host->top_base->emmc_top_control); +writel (0 , &host->top_base->emmc_top_cmd); + }else { +writel (0 , tune_reg); + }writel (0 , &host->base->msdc_iocon);if (host->r_smpl)
@@ -1507,9 +1512,14 @@ static void msdc_init_hw(struct msdc_host *host)writel (0x403c0046 , &host->base->patch_bit0);writel (0xffff4089 , &host->base->patch_bit1); -if (host->dev_comp->stop_clk_fix) +if (host->dev_comp->stop_clk_fix) {clrsetbits_le32 (&host->base->patch_bit1,MSDC_PB1_STOP_DLY_M ,3 <<MSDC_PB1_STOP_DLY_S ); +clrbits_le32 (&host->base->sdc_fifo_cfg, +SDC_FIFO_CFG_WRVALIDSEL ); +clrbits_le32 (&host->base->sdc_fifo_cfg, +SDC_FIFO_CFG_RDVALIDSEL ); + }if (host->dev_comp->busy_check)clrbits_le32 (&host->base->patch_bit1, (1 <<7 ));
@@ -1544,15 +1554,28 @@ static void msdc_init_hw(struct msdc_host *host) }if (host->dev_comp->data_tune) { -setbits_le32 (tune_reg, -MSDC_PAD_TUNE_RD_SEL |MSDC_PAD_TUNE_CMD_SEL ); -clrsetbits_le32 (&host->base->patch_bit0, -MSDC_INT_DAT_LATCH_CK_SEL_M , - host->latch_ck << -MSDC_INT_DAT_LATCH_CK_SEL_S ); +if (host->top_base) { +setbits_le32 (&host->top_base->emmc_top_control, +PAD_DAT_RD_RXDLY_SEL ); +clrbits_le32 (&host->top_base->emmc_top_control, +DATA_K_VALUE_SEL ); +setbits_le32 (&host->top_base->emmc_top_cmd, +PAD_CMD_RD_RXDLY_SEL ); + }else { +setbits_le32 (tune_reg, +MSDC_PAD_TUNE_RD_SEL |MSDC_PAD_TUNE_CMD_SEL ); +clrsetbits_le32 (&host->base->patch_bit0, +MSDC_INT_DAT_LATCH_CK_SEL_M , + host->latch_ck << +MSDC_INT_DAT_LATCH_CK_SEL_S ); + } }else {/* choose clock tune */ -setbits_le32 (tune_reg,MSDC_PAD_TUNE_RXDLYSEL ); +if (host->top_base) +setbits_le32 (&host->top_base->emmc_top_control, +PAD_RXDLY_SEL ); +else +setbits_le32 (tune_reg,MSDC_PAD_TUNE_RXDLYSEL ); }if (host->dev_comp->builtin_pad_ctrl) {
@@ -1604,12 +1627,6 @@ static void msdc_init_hw(struct msdc_host *host)clrsetbits_le32 (&host->base->sdc_cfg,SDC_CFG_DTOC_M ,3 <<SDC_CFG_DTOC_S ); -if (host->dev_comp->stop_clk_fix) { -clrbits_le32 (&host->base->sdc_fifo_cfg, -SDC_FIFO_CFG_WRVALIDSEL ); -clrbits_le32 (&host->base->sdc_fifo_cfg, -SDC_FIFO_CFG_RDVALIDSEL ); - } host->def_tune_para.iocon =readl (&host->base->msdc_iocon); host->def_tune_para.pad_tune =readl (&host->base->pad_tune);
@@ -1792,6 +1809,25 @@ static const struct msdc_compatible mt7623_compat = { .enhance_rx = false }; +static const struct msdc_compatible mt7986_compat = { + .clk_div_bits =12 , + .pad_tune0 = true, + .async_fifo = true, + .data_tune = true, + .busy_check = true, + .stop_clk_fix = true, + .enhance_rx = true, +}; + +static const struct msdc_compatible mt7981_compat = { + .clk_div_bits =12 , + .pad_tune0 = true, + .async_fifo = true, + .data_tune = true, + .busy_check = true, + .stop_clk_fix = true, +}; +static const struct msdc_compatible mt8512_compat = { .clk_div_bits =12 , .pad_tune0 = true,
@@ -1824,6 +1860,8 @@ static const struct udevice_id msdc_ids[] = { { .compatible = "mediatek,mt7621-mmc", .data = (ulong)&mt7621_compat }, { .compatible = "mediatek,mt7622-mmc", .data = (ulong)&mt7622_compat }, { .compatible = "mediatek,mt7623-mmc", .data = (ulong)&mt7623_compat }, + { .compatible = "mediatek,mt7986-mmc", .data = (ulong)&mt7986_compat }, + { .compatible = "mediatek,mt7981-mmc", .data = (ulong)&mt7981_compat }, { .compatible = "mediatek,mt8512-mmc", .data = (ulong)&mt8512_compat }, { .compatible = "mediatek,mt8516-mmc", .data = (ulong)&mt8516_compat }, { .compatible = "mediatek,mt8183-mmc", .data = (ulong)&mt8183_compat },
Signature · 1 line
2.17.1
PATCH v3 7/32 net: mediatek: stop using bitfileds for DMA descriptors
In reply to Weijie GaoThis patch is a preparation for adding a new version of PDMA of which the DMA descriptor fields has changed. Using bitfields will result in a complex modification. Convert bitfields to u32 units can solve this problem easily.
---
v3 changes: none
v2 changes:
Fix typo in commit message
--- drivers/net/mtk_eth.c | 144 ++++++++++++++---------------------------- drivers/net/mtk_eth.h | 32 ++++++++++ 2 files changed, 80 insertions(+), 96 deletions(-)
drivers/net/mtk_eth.c +48 -96
@@ -65,77 +65,6 @@ (DP_DISCARD << MC_DP_S) | \ (DP_DISCARD << UN_DP_S)) -struct pdma_rxd_info1 { -u32 PDP0; -}; - -struct pdma_rxd_info2 { -u32 PLEN1 :14 ; -u32 LS1 :1 ; -u32 UN_USED :1 ; -u32 PLEN0 :14 ; -u32 LS0 :1 ; -u32 DDONE :1 ; -}; - -struct pdma_rxd_info3 { -u32 PDP1; -}; - -struct pdma_rxd_info4 { -u32 FOE_ENTRY :14 ; -u32 CRSN :5 ; -u32 SP :3 ; -u32 L4F :1 ; -u32 L4VLD :1 ; -u32 TACK :1 ; -u32 IP4F :1 ; -u32 IP4 :1 ; -u32 IP6 :1 ; -u32 UN_USED :4 ; -}; - -struct pdma_rxdesc { -struct pdma_rxd_info1 rxd_info1; -struct pdma_rxd_info2 rxd_info2; -struct pdma_rxd_info3 rxd_info3; -struct pdma_rxd_info4 rxd_info4; -}; - -struct pdma_txd_info1 { -u32 SDP0; -}; - -struct pdma_txd_info2 { -u32 SDL1 :14 ; -u32 LS1 :1 ; -u32 BURST :1 ; -u32 SDL0 :14 ; -u32 LS0 :1 ; -u32 DDONE :1 ; -}; - -struct pdma_txd_info3 { -u32 SDP1; -}; - -struct pdma_txd_info4 { -u32 VLAN_TAG :16 ; -u32 INS :1 ; -u32 RESV :2 ; -u32 UDF :6 ; -u32 FPORT :3 ; -u32 TSO :1 ; -u32 TUI_CO :3 ; -}; - -struct pdma_txdesc { -struct pdma_txd_info1 txd_info1; -struct pdma_txd_info2 txd_info2; -struct pdma_txd_info3 txd_info3; -struct pdma_txd_info4 txd_info4; -}; - enum mtk_switch { SW_NONE, SW_MT7530,
@@ -151,13 +80,15 @@ enum mtk_switch {struct mtk_soc_data {u32 caps;u32 ana_rgc3; +u32 txd_size; +u32 rxd_size; };struct mtk_eth_priv {char pkt_pool[TOTAL_PKT_BUF_SIZE ]__aligned(ARCH_DMA_MINALIGN) ; -struct pdma_txdesc *tx_ring_noc; -struct pdma_rxdesc *rx_ring_noc; +void *tx_ring_noc; +void *rx_ring_noc;int rx_dma_owner_idx0;int tx_cpu_owner_idx0;
@@ -1202,14 +1133,16 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)static void mtk_eth_fifo_init (struct mtk_eth_priv *priv) {char *pkt_base = priv->pkt_pool; +struct mtk_tx_dma *txd; +struct mtk_rx_dma *rxd;int i;mtk_pdma_rmw (priv,PDMA_GLO_CFG_REG ,0xffff0000 ,0 );udelay (500 ); -memset (priv->tx_ring_noc,0 ,NUM_TX_DESC *sizeof (struct pdma_txdesc )); -memset (priv->rx_ring_noc,0 ,NUM_RX_DESC *sizeof (struct pdma_rxdesc )); -memset (priv->pkt_pool,0 ,TOTAL_PKT_BUF_SIZE ); +memset (priv->tx_ring_noc,0 ,NUM_TX_DESC * priv->soc->txd_size); +memset (priv->rx_ring_noc,0 ,NUM_RX_DESC * priv->soc->rxd_size); +memset (priv->pkt_pool,0xff ,TOTAL_PKT_BUF_SIZE );flush_dcache_range ((ulong )pkt_base, (ulong)(pkt_base +TOTAL_PKT_BUF_SIZE ));
@@ -1218,17 +1151,21 @@ static void mtk_eth_fifo_init(struct mtk_eth_priv *priv) priv->tx_cpu_owner_idx0 =0 ;for (i =0 ; i <NUM_TX_DESC ; i++) { - priv->tx_ring_noc[i].txd_info2.LS0 =1 ; - priv->tx_ring_noc[i].txd_info2.DDONE =1 ; - priv->tx_ring_noc[i].txd_info4.FPORT = priv->gmac_id +1 ; + txd = priv->tx_ring_noc + i * priv->soc->txd_size; + + txd->txd1 =virt_to_phys (pkt_base); + txd->txd2 =PDMA_TXD2_DDONE |PDMA_TXD2_LS0 ; + txd->txd4 =PDMA_TXD4_FPORT_SET (priv->gmac_id +1 ); - priv->tx_ring_noc[i].txd_info1.SDP0 =virt_to_phys (pkt_base); pkt_base +=PKTSIZE_ALIGN ; }for (i =0 ; i <NUM_RX_DESC ; i++) { - priv->rx_ring_noc[i].rxd_info2.PLEN0 =PKTSIZE_ALIGN ; - priv->rx_ring_noc[i].rxd_info1.PDP0 =virt_to_phys (pkt_base); + rxd = priv->rx_ring_noc + i * priv->soc->rxd_size; + + rxd->rxd1 =virt_to_phys (pkt_base); + rxd->rxd2 =PDMA_RXD2_PLEN0_SET (PKTSIZE_ALIGN ); + pkt_base +=PKTSIZE_ALIGN ; }
@@ -1315,20 +1252,22 @@ static int mtk_eth_send(struct udevice *dev, void *packet, int length) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->tx_cpu_owner_idx0; +struct mtk_tx_dma *txd;void *pkt_base; -if (!priv->tx_ring_noc[idx].txd_info2.DDONE) { + txd = priv->tx_ring_noc + idx * priv->soc->txd_size; + +if (!(txd->txd2 &PDMA_TXD2_DDONE )) {debug ("mtk-eth: TX DMA descriptor ring is full\n" );return -EPERM ; } - pkt_base = (void *)phys_to_virt (priv->tx_ring_noc[idx].txd_info1.SDP0); + pkt_base = (void *)phys_to_virt (txd->txd1);memcpy (pkt_base, packet, length);flush_dcache_range ((ulong )pkt_base, (ulong )pkt_base +roundup (length,ARCH_DMA_MINALIGN )); - priv->tx_ring_noc[idx].txd_info2.SDL0 = length; - priv->tx_ring_noc[idx].txd_info2.DDONE =0 ; + txd->txd2 =PDMA_TXD2_LS0 |PDMA_TXD2_SDL0_SET (length); priv->tx_cpu_owner_idx0 = (priv->tx_cpu_owner_idx0 +1 ) %NUM_TX_DESC ;mtk_pdma_write (priv,TX_CTX_IDX_REG (0 ), priv->tx_cpu_owner_idx0);
@@ -1340,16 +1279,20 @@ static int mtk_eth_recv(struct udevice *dev, int flags, uchar **packetp) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->rx_dma_owner_idx0; +struct mtk_rx_dma *rxd;uchar *pkt_base;u32 length; -if (!priv->rx_ring_noc[idx].rxd_info2.DDONE) { + rxd = priv->rx_ring_noc + idx * priv->soc->rxd_size; + +if (!(rxd->rxd2 &PDMA_RXD2_DDONE )) {debug ("mtk-eth: RX DMA descriptor ring is empty\n" );return -EAGAIN ; } - length = priv->rx_ring_noc[idx].rxd_info2.PLEN0; - pkt_base = (void *)phys_to_virt (priv->rx_ring_noc[idx].rxd_info1.PDP0); + length =PDMA_RXD2_PLEN0_GET (rxd->rxd2); + + pkt_base = (void *)phys_to_virt (rxd->rxd1);invalidate_dcache_range ((ulong )pkt_base, (ulong )pkt_base +roundup (length,ARCH_DMA_MINALIGN ));
@@ -1363,10 +1306,11 @@ static int mtk_eth_free_pkt(struct udevice *dev, uchar *packet, int length) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->rx_dma_owner_idx0; +struct mtk_rx_dma *rxd; + + rxd = priv->rx_ring_noc + idx * priv->soc->rxd_size; - priv->rx_ring_noc[idx].rxd_info2.DDONE =0 ; - priv->rx_ring_noc[idx].rxd_info2.LS0 =0 ; - priv->rx_ring_noc[idx].rxd_info2.PLEN0 =PKTSIZE_ALIGN ; + rxd->rxd2 =PDMA_RXD2_PLEN0_SET (PKTSIZE_ALIGN );mtk_pdma_write (priv,RX_CRX_IDX_REG (0 ), idx); priv->rx_dma_owner_idx0 = (priv->rx_dma_owner_idx0 +1 ) %NUM_RX_DESC ;
@@ -1393,11 +1337,11 @@ static int mtk_eth_probe(struct udevice *dev)return ret;/* Prepare for tx/rx rings */ - priv->tx_ring_noc = (struct pdma_txdesc *) -noncached_alloc (sizeof (struct pdma_txdesc ) *NUM_TX_DESC , + priv->tx_ring_noc = (void *) +noncached_alloc (priv->soc->txd_size *NUM_TX_DESC ,ARCH_DMA_MINALIGN ); - priv->rx_ring_noc = (struct pdma_rxdesc *) -noncached_alloc (sizeof (struct pdma_rxdesc ) *NUM_RX_DESC , + priv->rx_ring_noc = (void *) +noncached_alloc (priv->soc->rxd_size *NUM_RX_DESC ,ARCH_DMA_MINALIGN );/* Set MAC mode */
@@ -1554,18 +1498,26 @@ static int mtk_eth_of_to_plat(struct udevice *dev)static const struct mtk_soc_data mt7629_data = { .ana_rgc3 =0x128 , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7623_data = { .caps =MT7623_CAPS , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7622_data = { .ana_rgc3 =0x2028 , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7621_data = { .caps =MT7621_CAPS , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct udevice_id mtk_eth_ids[] = {
drivers/net/mtk_eth.h +32 -0
@@ -10,6 +10,7 @@#define _MTK_ETH_H_#include <linux/bitops.h> +#include <linux/bitfield.h> enum mkt_eth_capabilities {MTK_TRGMII_BIT ,
@@ -435,4 +436,35 @@ enum mkt_eth_capabilities {#define PHY_POWER_SAVING_M 0x300#define PHY_POWER_SAVING_TX 0x0 +/* PDMA descriptors */ +struct mtk_rx_dma { +unsigned int rxd1; +unsigned int rxd2; +unsigned int rxd3; +unsigned int rxd4; +} __packed__aligned(4) ; + +struct mtk_tx_dma { +unsigned int txd1; +unsigned int txd2; +unsigned int txd3; +unsigned int txd4; +} __packed__aligned(4) ; + +/* PDMA TXD fields */ +#define PDMA_TXD2_DDONE BIT(31) +#define PDMA_TXD2_LS0 BIT(30) +#define PDMA_TXD2_SDL0_M GENMASK(29, 16) +#define PDMA_TXD2_SDL0_SET (_v) FIELD_PREP(PDMA_TXD2_SDL0_M, (_v)) + +#define PDMA_TXD4_FPORT_M GENMASK(27, 25) +#define PDMA_TXD4_FPORT_SET (_v) FIELD_PREP(PDMA_TXD4_FPORT_M, (_v)) + +/* PDMA RXD fields */ +#define PDMA_RXD2_DDONE BIT(31) +#define PDMA_RXD2_LS0 BIT(30) +#define PDMA_RXD2_PLEN0_M GENMASK(29, 16) +#define PDMA_RXD2_PLEN0_GET (_v) FIELD_GET(PDMA_RXD2_PLEN0_M, (_v)) +#define PDMA_RXD2_PLEN0_SET (_v) FIELD_PREP(PDMA_RXD2_PLEN0_M, (_v)) +#endif /* _MTK_ETH_H_ */
Signature · 1 line
2.17.1
PATCH v3 6/32 net: mediatek: use a struct to cover variations of all SoCs
In reply to Weijie GaoUsing a single soc id to control different initialization and TX/RX flow for all SoCs is not extensible if more hardware variations are added in the future.
This patch introduces a struct to replace the original mtk_soc to allow the driver be able handle newer hardwares.
---
v3 changes: none
v2 changes:
Add description for new struct
--- drivers/net/mtk_eth.c | 56 ++++++++++++++++++++++++++++++------------- drivers/net/mtk_eth.h | 25 ++++++++++++++++++- 2 files changed, 64 insertions(+), 17 deletions(-)
drivers/net/mtk_eth.c +40 -16
@@ -142,11 +142,15 @@ enum mtk_switch {SW_MT7531 }; -enum mtk_soc { -SOC_MT7623 , -SOC_MT7629 , -SOC_MT7622 , -SOC_MT7621 +/* struct mtk_soc_data - This is the structure holding all differences +* among various plaforms +* @caps Flags shown the extra capability for the SoC +* @ana_rgc3: The offset for register ANA_RGC3 related to +* sgmiisys syscon +*/ +struct mtk_soc_data { +u32 caps; +u32 ana_rgc3; };struct mtk_eth_priv {
@@ -171,7 +175,7 @@ struct mtk_eth_priv {int (*mmd_write)(struct mtk_eth_priv *priv,u8 addr,u8 devad,u16 reg,u16 val); -enum mtk_soc soc; +const struct mtk_soc_data *soc;int gmac_id;int force_mode;int speed;
@@ -679,7 +683,7 @@ static int mt7530_setup(struct mtk_eth_priv *priv)u32 val, txdrv;int i; -if (priv->soc !=SOC_MT7621 ) { +if (!MTK_HAS_CAPS (priv->soc->caps,MTK_TRGMII_MT7621_CLK )) {/* Select 250MHz clk for RGMII mode */ mtk_ethsys_rmw (priv,ETHSYS_CLKCFG0_REG ,ETHSYS_TRGMII_CLK_SEL362_5 ,0 );
@@ -1108,9 +1112,8 @@ static int mtk_phy_probe(struct udevice *dev)static void mtk_sgmii_init (struct mtk_eth_priv *priv) {/* Set SGMII GEN2 speed(2.5G) */ -clrsetbits_le32 (priv->sgmii_base + ((priv->soc ==SOC_MT7622 ) ? -SGMSYS_GEN2_SPEED :SGMSYS_GEN2_SPEED_V2 ), -SGMSYS_SPEED_2500 ,SGMSYS_SPEED_2500 ); +setbits_le32 (priv->sgmii_base + priv->soc->ana_rgc3, +SGMSYS_SPEED_2500 );/* Disable SGMII AN */ clrsetbits_le32(priv->sgmii_base + SGMSYS_PCS_CONTROL_1,
@@ -1182,7 +1185,8 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)mtk_gmac_write (priv,GMAC_PORT_MCR (priv->gmac_id), mcr); } -if (priv->soc ==SOC_MT7623 ) { +if (MTK_HAS_CAPS (priv->soc->caps,MTK_GMAC1_TRGMII ) && + !MTK_HAS_CAPS (priv->soc->caps,MTK_TRGMII_MT7621_CLK )) {/* Lower Tx Driving for TRGMII path */ for (i =0 ; i <NUM_TRGMII_CTRL ; i++) mtk_gmac_write(priv, GMAC_TRGMII_TD_ODT(i),
@@ -1431,7 +1435,11 @@ static int mtk_eth_of_to_plat(struct udevice *dev)ofnode subnode;int ret; - priv->soc =dev_get_driver_data (dev); + priv->soc = (const struct mtk_soc_data *)dev_get_driver_data (dev); +if (!priv->soc) { +dev_err (dev,"missing soc compatible data\n" ); +return -EINVAL ; + } pdata->iobase = (phys_addr_t )dev_remap_addr (dev);
@@ -1544,11 +1552,27 @@ static int mtk_eth_of_to_plat(struct udevice *dev)return 0 ; } +static const struct mtk_soc_data mt7629_data = { + .ana_rgc3 =0x128 , +}; + +static const struct mtk_soc_data mt7623_data = { + .caps =MT7623_CAPS , +}; + +static const struct mtk_soc_data mt7622_data = { + .ana_rgc3 =0x2028 , +}; + +static const struct mtk_soc_data mt7621_data = { + .caps =MT7621_CAPS , +}; +static const struct udevice_id mtk_eth_ids[] = { - { .compatible ="mediatek,mt7629-eth" , .data =SOC_MT7629 }, - { .compatible ="mediatek,mt7623-eth" , .data =SOC_MT7623 }, - { .compatible ="mediatek,mt7622-eth" , .data =SOC_MT7622 }, - { .compatible ="mediatek,mt7621-eth" , .data =SOC_MT7621 }, + { .compatible ="mediatek,mt7629-eth" , .data = (ulong)&mt7629_data }, + { .compatible ="mediatek,mt7623-eth" , .data = (ulong)&mt7623_data }, + { .compatible ="mediatek,mt7622-eth" , .data = (ulong)&mt7622_data }, + { .compatible ="mediatek,mt7621-eth" , .data = (ulong)&mt7621_data }, {} };
drivers/net/mtk_eth.h +24 -1
@@ -9,8 +9,31 @@#ifndef _MTK_ETH_H_#define _MTK_ETH_H_ -/* Frame Engine Register Bases */ #include <linux/bitops.h> + +enum mkt_eth_capabilities { +MTK_TRGMII_BIT , +MTK_TRGMII_MT7621_CLK_BIT , + +/* PATH BITS */ +MTK_ETH_PATH_GMAC1_TRGMII_BIT , +}; + +#define MTK_TRGMII BIT(MTK_TRGMII_BIT) +#define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT) + +/* Supported path present on SoCs */ +#define MTK_ETH_PATH_GMAC1_TRGMII BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT) + +#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII) + +#define MTK_HAS_CAPS (caps, _x) (((caps) & (_x)) == (_x)) + +#define MT7621_CAPS (MTK_GMAC1_TRGMII | MTK_TRGMII_MT7621_CLK) + +#define MT7623_CAPS (MTK_GMAC1_TRGMII) + +/* Frame Engine Register Bases */ #define PDMA_BASE 0x0800#define GDMA1_BASE 0x0500#define GDMA2_BASE 0x1500
Signature · 1 line
2.17.1
PATCH v3 8/32 net: mediatek: add support for PDMA v2
In reply to Weijie GaoThis patch adds support for PDMA v2 hardware. The PDMA v2 has extended the DMA descriptor to 8-words, and some of its fields have changed comparing to the v1 hardware.
---
v3 changes: none
v2 changes:
Add description for new fields
--- drivers/net/mtk_eth.c | 54 ++++++++++++++++++++++++++++++++----------- drivers/net/mtk_eth.h | 53 +++++++++++++++++++++++++++++++++++------- 2 files changed, 86 insertions(+), 21 deletions(-)
drivers/net/mtk_eth.c +41 -13
@@ -76,10 +76,14 @@ enum mtk_switch {* @caps Flags shown the extra capability for the SoC * @ana_rgc3: The offset for register ANA_RGC3 related to * sgmiisys syscon +* @pdma_base: Register base of PDMA block +* @txd_size: Tx DMA descriptor size. +* @rxd_size: Rx DMA descriptor size. */ struct mtk_soc_data {u32 caps;u32 ana_rgc3; +u32 pdma_base;u32 txd_size;u32 rxd_size; };
@@ -130,13 +134,13 @@ struct mtk_eth_priv {static void mtk_pdma_write (struct mtk_eth_priv *priv,u32 reg,u32 val) { -writel (val, priv->fe_base +PDMA_BASE + reg); +writel (val, priv->fe_base + priv->soc->pdma_base + reg); }static void mtk_pdma_rmw (struct mtk_eth_priv *priv,u32 reg,u32 clr,u32 set) { -clrsetbits_le32 (priv->fe_base +PDMA_BASE + reg, clr, set); +clrsetbits_le32 (priv->fe_base + priv->soc->pdma_base + reg, clr, set); } static void mtk_gdma_write(struct mtk_eth_priv *priv, int no, u32 reg,
@@ -1133,8 +1137,8 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)static void mtk_eth_fifo_init (struct mtk_eth_priv *priv) {char *pkt_base = priv->pkt_pool; -struct mtk_tx_dma *txd; -struct mtk_rx_dma *rxd; +struct mtk_tx_dma_v2 *txd; +struct mtk_rx_dma_v2 *rxd;int i;mtk_pdma_rmw (priv,PDMA_GLO_CFG_REG ,0xffff0000 ,0 );
@@ -1155,7 +1159,11 @@ static void mtk_eth_fifo_init(struct mtk_eth_priv *priv) txd->txd1 =virt_to_phys (pkt_base); txd->txd2 =PDMA_TXD2_DDONE |PDMA_TXD2_LS0 ; - txd->txd4 =PDMA_TXD4_FPORT_SET (priv->gmac_id +1 ); + +if (MTK_HAS_CAPS (priv->soc->caps,MTK_NETSYS_V2 )) + txd->txd5 =PDMA_V2_TXD5_FPORT_SET (priv->gmac_id +1 ); +else + txd->txd4 =PDMA_V1_TXD4_FPORT_SET (priv->gmac_id +1 ); pkt_base +=PKTSIZE_ALIGN ; }
@@ -1164,7 +1172,11 @@ static void mtk_eth_fifo_init(struct mtk_eth_priv *priv) rxd = priv->rx_ring_noc + i * priv->soc->rxd_size; rxd->rxd1 =virt_to_phys (pkt_base); - rxd->rxd2 =PDMA_RXD2_PLEN0_SET (PKTSIZE_ALIGN ); + +if (MTK_HAS_CAPS (priv->soc->caps,MTK_NETSYS_V2 )) + rxd->rxd2 =PDMA_V2_RXD2_PLEN0_SET (PKTSIZE_ALIGN ); +else + rxd->rxd2 =PDMA_V1_RXD2_PLEN0_SET (PKTSIZE_ALIGN ); pkt_base +=PKTSIZE_ALIGN ; }
@@ -1193,6 +1205,9 @@ static int mtk_eth_start(struct udevice *dev)reset_deassert (&priv->rst_fe);mdelay (10 ); +if (MTK_HAS_CAPS (priv->soc->caps,MTK_NETSYS_V2 )) +setbits_le32 (priv->fe_base +FE_GLO_MISC_REG ,PDMA_VER_V2 ); +/* Packets forward to PDMA */ mtk_gdma_write (priv, priv->gmac_id,GDMA_IG_CTRL_REG ,GDMA_FWD_TO_CPU );
@@ -1227,7 +1242,7 @@ static void mtk_eth_stop(struct udevice *dev) TX_WB_DDONE | RX_DMA_EN | TX_DMA_EN, 0);udelay (500 ); -wait_for_bit_le32 (priv->fe_base +PDMA_BASE +PDMA_GLO_CFG_REG , +wait_for_bit_le32 (priv->fe_base + priv->soc->pdma_base +PDMA_GLO_CFG_REG ,RX_DMA_BUSY |TX_DMA_BUSY ,0 ,5000 ,0 ); }
@@ -1252,7 +1267,7 @@ static int mtk_eth_send(struct udevice *dev, void *packet, int length) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->tx_cpu_owner_idx0; -struct mtk_tx_dma *txd; +struct mtk_tx_dma_v2 *txd;void *pkt_base; txd = priv->tx_ring_noc + idx * priv->soc->txd_size;
@@ -1267,7 +1282,10 @@ static int mtk_eth_send(struct udevice *dev, void *packet, int length)flush_dcache_range ((ulong )pkt_base, (ulong )pkt_base +roundup (length,ARCH_DMA_MINALIGN )); - txd->txd2 =PDMA_TXD2_LS0 |PDMA_TXD2_SDL0_SET (length); +if (MTK_HAS_CAPS (priv->soc->caps,MTK_NETSYS_V2 )) + txd->txd2 =PDMA_TXD2_LS0 |PDMA_V2_TXD2_SDL0_SET (length); +else + txd->txd2 =PDMA_TXD2_LS0 |PDMA_V1_TXD2_SDL0_SET (length); priv->tx_cpu_owner_idx0 = (priv->tx_cpu_owner_idx0 +1 ) %NUM_TX_DESC ;mtk_pdma_write (priv,TX_CTX_IDX_REG (0 ), priv->tx_cpu_owner_idx0);
@@ -1279,7 +1297,7 @@ static int mtk_eth_recv(struct udevice *dev, int flags, uchar **packetp) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->rx_dma_owner_idx0; -struct mtk_rx_dma *rxd; +struct mtk_rx_dma_v2 *rxd;uchar *pkt_base;u32 length;
@@ -1290,7 +1308,10 @@ static int mtk_eth_recv(struct udevice *dev, int flags, uchar **packetp)return -EAGAIN ; } - length =PDMA_RXD2_PLEN0_GET (rxd->rxd2); +if (MTK_HAS_CAPS (priv->soc->caps,MTK_NETSYS_V2 )) + length =PDMA_V2_RXD2_PLEN0_GET (rxd->rxd2); +else + length =PDMA_V1_RXD2_PLEN0_GET (rxd->rxd2); pkt_base = (void *)phys_to_virt (rxd->rxd1); invalidate_dcache_range((ulong)pkt_base, (ulong)pkt_base +
@@ -1306,11 +1327,14 @@ static int mtk_eth_free_pkt(struct udevice *dev, uchar *packet, int length) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->rx_dma_owner_idx0; -struct mtk_rx_dma *rxd; +struct mtk_rx_dma_v2 *rxd; rxd = priv->rx_ring_noc + idx * priv->soc->rxd_size; - rxd->rxd2 =PDMA_RXD2_PLEN0_SET (PKTSIZE_ALIGN ); +if (MTK_HAS_CAPS (priv->soc->caps,MTK_NETSYS_V2 )) + rxd->rxd2 =PDMA_V2_RXD2_PLEN0_SET (PKTSIZE_ALIGN ); +else + rxd->rxd2 =PDMA_V1_RXD2_PLEN0_SET (PKTSIZE_ALIGN );mtk_pdma_write (priv,RX_CRX_IDX_REG (0 ), idx); priv->rx_dma_owner_idx0 = (priv->rx_dma_owner_idx0 +1 ) %NUM_RX_DESC ;
@@ -1498,24 +1522,28 @@ static int mtk_eth_of_to_plat(struct udevice *dev)static const struct mtk_soc_data mt7629_data = { .ana_rgc3 =0x128 , + .pdma_base =PDMA_V1_BASE , .txd_size =sizeof (struct mtk_tx_dma ), .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7623_data = { .caps =MT7623_CAPS , + .pdma_base =PDMA_V1_BASE , .txd_size =sizeof (struct mtk_tx_dma ), .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7622_data = { .ana_rgc3 =0x2028 , + .pdma_base =PDMA_V1_BASE , .txd_size =sizeof (struct mtk_tx_dma ), .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7621_data = { .caps =MT7621_CAPS , + .pdma_base =PDMA_V1_BASE , .txd_size =sizeof (struct mtk_tx_dma ), .rxd_size =sizeof (struct mtk_rx_dma ), };
drivers/net/mtk_eth.h +45 -8
96 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 10/32 serial: mtk: add support for using dynamic baud clock souce
In reply to Weijie GaoThe baud clock on some platform may change due to assigned-clock-parent set in DT. In current flow the baud clock is only retrieved during probe stage. If the parent of the source clock changes after probe stage, the setbrg will set wrong baudrate.
To get the right clock rate, this patch records the baud clk struct to the driver's priv, and changes the driver's flow to get the clock rate before calling _mtk_serial_setbrg().
---
v3 changes: none
v2 changes:
Add description for priv struct
Fix the type of clk_rate
--- drivers/serial/serial_mtk.c | 80 ++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 33 deletions(-)
drivers/serial/serial_mtk.c +47 -33
@@ -10,6 +10,7 @@#include <common.h> #include <div64.h> #include <dm.h> +#include <dm/device_compat.h> #include <errno.h> #include <log.h> #include <serial.h>
@@ -70,27 +71,37 @@ struct mtk_serial_regs {#define BAUD_ALLOW_MAX (baud) ((baud) + (baud) * 3 / 100)#define BAUD_ALLOW_MIX (baud) ((baud) - (baud) * 3 / 100) +/* struct mtk_serial_priv - Structure holding all information used by the +* driver +* @regs: Register base of the serial port +* @clk: The baud clock device +* @fixed_clk_rate: Fallback fixed baud clock rate if baud clock +* device is not specified +* @force_highspeed: Force using high-speed mode +*/ struct mtk_serial_priv {struct mtk_serial_regs __iomem *regs; -u32 clock; +struct clk clk; +u32 fixed_clk_rate;bool force_highspeed; }; -static void _mtk_serial_setbrg (struct mtk_serial_priv *priv,int baud) +static void _mtk_serial_setbrg (struct mtk_serial_priv *priv,int baud, +uint clk_rate) {u32 quot, realbaud, samplecount =1 ;/* Special case for low baud clock */ -if (baud <=115200 && priv->clock <=12000000 ) { +if (baud <=115200 && clk_rate ==12000000 ) {writel (3 , &priv->regs->highspeed); - quot =DIV_ROUND_CLOSEST (priv->clock,256 * baud); + quot =DIV_ROUND_CLOSEST (clk_rate,256 * baud);if (quot ==0 ) quot =1 ; - samplecount =DIV_ROUND_CLOSEST (priv->clock, quot * baud); + samplecount =DIV_ROUND_CLOSEST (clk_rate, quot * baud); - realbaud = priv->clock / samplecount / quot; + realbaud = clk_rate / samplecount / quot;if (realbaud >BAUD_ALLOW_MAX (baud) || realbaud <BAUD_ALLOW_MIX (baud)) {pr_info ("baud %d can't be handled\n" , baud);
@@ -104,7 +115,7 @@ static void _mtk_serial_setbrg(struct mtk_serial_priv *priv, int baud)if (baud <=115200 ) {writel (0 , &priv->regs->highspeed); - quot =DIV_ROUND_CLOSEST (priv->clock,16 * baud); + quot =DIV_ROUND_CLOSEST (clk_rate,16 * baud); }else if (baud <=576000 ) {writel (2 , &priv->regs->highspeed);
@@ -112,13 +123,13 @@ static void _mtk_serial_setbrg(struct mtk_serial_priv *priv, int baud)if ((baud ==500000 ) || (baud ==576000 )) baud =460800 ; - quot =DIV_ROUND_UP (priv->clock,4 * baud); + quot =DIV_ROUND_UP (clk_rate,4 * baud); }else { use_hs3:writel (3 , &priv->regs->highspeed); - quot =DIV_ROUND_UP (priv->clock,256 * baud); - samplecount =DIV_ROUND_CLOSEST (priv->clock, quot * baud); + quot =DIV_ROUND_UP (clk_rate,256 * baud); + samplecount =DIV_ROUND_CLOSEST (clk_rate, quot * baud); } set_baud:
@@ -167,8 +178,13 @@ static int _mtk_serial_pending(struct mtk_serial_priv *priv, bool input)static int mtk_serial_setbrg (struct udevice *dev,int baudrate) {struct mtk_serial_priv *priv =dev_get_priv (dev); +u32 clk_rate; + + clk_rate =clk_get_rate (&priv->clk); +if (IS_ERR_VALUE (clk_rate) || clk_rate ==0 ) + clk_rate = priv->fixed_clk_rate; -_mtk_serial_setbrg (priv, baudrate); +_mtk_serial_setbrg (priv, baudrate, clk_rate);return 0 ; }
@@ -211,7 +227,6 @@ static int mtk_serial_of_to_plat(struct udevice *dev) {struct mtk_serial_priv *priv =dev_get_priv (dev);fdt_addr_t addr; -struct clk clk;int err; addr =dev_read_addr (dev);
@@ -220,22 +235,19 @@ static int mtk_serial_of_to_plat(struct udevice *dev) priv->regs =map_physmem (addr,0 ,MAP_NOCACHE ); - err =clk_get_by_index (dev,0 , &clk); -if (!err) { - err =clk_get_rate (&clk); -if (!IS_ERR_VALUE (err)) - priv->clock = err; - }else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS ) { -debug ("mtk_serial: failed to get clock\n" ); -return err; - } - -if (!priv->clock) - priv->clock =dev_read_u32_default (dev,"clock-frequency" ,0 ); - -if (!priv->clock) { -debug ("mtk_serial: clock not defined\n" ); -return -EINVAL ; + err =clk_get_by_index (dev,0 , &priv->clk); +if (err) { + err =dev_read_u32 (dev,"clock-frequency" , &priv->fixed_clk_rate); +if (err) { +dev_err (dev,"baud clock not defined\n" ); +return -EINVAL ; + } + }else { + err =clk_get_rate (&priv->clk); +if (IS_ERR_VALUE (err)) { +dev_err (dev,"invalid baud clock\n" ); +return -EINVAL ; + } } priv->force_highspeed =dev_read_bool (dev,"mediatek,force-highspeed" );
@@ -273,7 +285,7 @@ DECLARE_GLOBAL_DATA_PTR;#define DECLARE_HSUART_PRIV (port) \ static struct mtk_serial_priv mtk_hsuart##port = { \ .regs = (struct mtk_serial_regs *)CONFIG_SYS_NS16550_COM##port, \ - .clock = CONFIG_SYS_NS16550_CLK \ + .fixed_clk_rate = CONFIG_SYS_NS16550_CLK \ };#define DECLARE_HSUART_FUNCTIONS (port) \
@@ -282,12 +294,14 @@ DECLARE_GLOBAL_DATA_PTR; writel(0, &mtk_hsuart##port.regs->ier); \ writel(UART_MCRVAL, &mtk_hsuart##port.regs->mcr); \ writel(UART_FCRVAL, &mtk_hsuart##port.regs->fcr); \ - _mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate); \ + _mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate, \ + mtk_hsuart##port.fixed_clk_rate); \ return 0 ; \ } \ static void mtk_serial##port##_setbrg(void) \ { \ - _mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate); \ + _mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate, \ + mtk_hsuart##port.fixed_clk_rate); \ } \ static int mtk_serial##port##_getc(void) \ { \
@@ -427,13 +441,13 @@ static inline void _debug_uart_init(void)struct mtk_serial_priv priv; priv.regs = (void *)CONFIG_VAL (DEBUG_UART_BASE ); - priv.clock =CONFIG_DEBUG_UART_CLOCK ; + priv.fixed_clk_rate =CONFIG_DEBUG_UART_CLOCK ;writel (0 , &priv.regs->ier);writel (UART_MCRVAL , &priv.regs->mcr);writel (UART_FCRVAL , &priv.regs->fcr); -_mtk_serial_setbrg (&priv,CONFIG_BAUDRATE ); +_mtk_serial_setbrg (&priv,CONFIG_BAUDRATE , priv.fixed_clk_rate); }static inline void _debug_uart_putc (int ch)
Signature · 1 line
2.17.1
PATCH v3 9/32 net: mediatek: add support for MediaTek MT7981/MT7986
In reply to Weijie GaoThis patch adds support for MediaTek MT7981 and MT7986. Both chips uses PDMA v2.
---
v3 changes: none
v2 changes: none
--- drivers/net/mtk_eth.c | 27 +++++++++++++++++++++++++++ drivers/net/mtk_eth.h | 5 +++++ 2 files changed, 32 insertions(+)
drivers/net/mtk_eth.c +27 -0
@@ -115,6 +115,7 @@ struct mtk_eth_priv {int force_mode;int speed;int duplex; +bool pn_swap;struct phy_device *phydev;int phy_interface;
@@ -1057,6 +1058,12 @@ static void mtk_sgmii_init(struct mtk_eth_priv *priv)/* SGMII force mode setting */ writel (SGMII_FORCE_MODE , priv->sgmii_base +SGMSYS_SGMII_MODE ); +/* SGMII PN SWAP setting */ +if (priv->pn_swap) { +setbits_le32 (priv->sgmii_base +SGMSYS_QPHY_WRAP_CTRL , +SGMII_PN_SWAP_TX_RX ); + } +/* Release PHYA power down state */ clrsetbits_le32 (priv->sgmii_base +SGMSYS_QPHY_PWR_STATE_CTRL ,SGMII_PHYA_PWD ,0 );
@@ -1470,6 +1477,8 @@ static int mtk_eth_of_to_plat(struct udevice *dev)dev_err (dev,"Unable to find sgmii\n" );return -ENODEV ; } + + priv->pn_swap =ofnode_read_bool (args.node,"pn_swap" ); }/* check for switch first, otherwise phy will be used */
@@ -1520,6 +1529,22 @@ static int mtk_eth_of_to_plat(struct udevice *dev)return 0 ; } +static const struct mtk_soc_data mt7986_data = { + .caps =MT7986_CAPS , + .ana_rgc3 =0x128 , + .pdma_base =PDMA_V2_BASE , + .txd_size =sizeof (struct mtk_tx_dma_v2 ), + .rxd_size =sizeof (struct mtk_rx_dma_v2 ), +}; + +static const struct mtk_soc_data mt7981_data = { + .caps =MT7986_CAPS , + .ana_rgc3 =0x128 , + .pdma_base =PDMA_V2_BASE , + .txd_size =sizeof (struct mtk_tx_dma_v2 ), + .rxd_size =sizeof (struct mtk_rx_dma_v2 ), +}; +static const struct mtk_soc_data mt7629_data = { .ana_rgc3 =0x128 , .pdma_base =PDMA_V1_BASE ,
@@ -1549,6 +1574,8 @@ static const struct mtk_soc_data mt7621_data = { };static const struct udevice_id mtk_eth_ids[] = { + { .compatible ="mediatek,mt7986-eth" , .data = (ulong)&mt7986_data }, + { .compatible ="mediatek,mt7981-eth" , .data = (ulong)&mt7981_data }, { .compatible ="mediatek,mt7629-eth" , .data = (ulong)&mt7629_data }, { .compatible ="mediatek,mt7623-eth" , .data = (ulong)&mt7623_data }, { .compatible ="mediatek,mt7622-eth" , .data = (ulong)&mt7622_data },
drivers/net/mtk_eth.h +5 -0
@@ -36,6 +36,8 @@ enum mkt_eth_capabilities {#define MT7623_CAPS (MTK_GMAC1_TRGMII) +#define MT7986_CAPS (MTK_NETSYS_V2) +/* Frame Engine Register Bases */ #define PDMA_V1_BASE 0x0800#define PDMA_V2_BASE 0x6000
@@ -72,6 +74,9 @@ enum mkt_eth_capabilities {#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8#define SGMII_PHYA_PWD BIT(4) +#define SGMSYS_QPHY_WRAP_CTRL 0xec +#define SGMII_PN_SWAP_TX_RX 0x03 +#define SGMSYS_GEN2_SPEED 0x2028#define SGMSYS_GEN2_SPEED_V2 0x128#define SGMSYS_SPEED_2500 BIT(2)
Signature · 1 line
2.17.1
PATCH v3 12/32 pwm: mtk: add support for MediaTek MT7986 SoC
In reply to Weijie GaoThis patch adds PWM support for MediaTek MT7986 SoC.
---
v3 changes: none
v2 changes: none
--- drivers/pwm/pwm-mtk.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/pwm/pwm-mtk.c +6 -0
@@ -171,10 +171,16 @@ static const struct mtk_pwm_soc mt7629_data = { .pwm45_fixup = false, }; +static const struct mtk_pwm_soc mt7986_data = { + .num_pwms =2 , + .pwm45_fixup = false, +}; +static const struct udevice_id mtk_pwm_ids[] = { { .compatible ="mediatek,mt7622-pwm" , .data = (ulong)&mt7622_data }, { .compatible ="mediatek,mt7623-pwm" , .data = (ulong)&mt7623_data }, { .compatible ="mediatek,mt7629-pwm" , .data = (ulong)&mt7629_data }, + { .compatible ="mediatek,mt7986-pwm" , .data = (ulong)&mt7986_data }, { } };
Signature · 1 line
2.17.1
PATCH v3 11/32 arm: dts: mt7622: force high-speed mode for uart
In reply to Weijie GaoThe input clock for uart is too slow (25MHz) which introduces frequent data error on both receiving and transmitting even if the baudrate is 115200.
Using high-speed can significantly solve this issue.
---
v3 changes: none
v2 changes: none
--- arch/arm/dts/mt7622.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm/dts/mt7622.dtsi +1 -0
@@ -175,6 +175,7 @@ status = "disabled"; assigned-clocks = <&topckgen CLK_TOP_AXI_SEL>; assigned-clock-parents = <&topckgen CLK_TOP_SYSPLL1_D2>; + mediatek,force-highspeed; }; mmc0: mmc@11230000 {
Signature · 1 line
2.17.1
PATCH v3 13/32 pwm: mtk: add support for MediaTek MT7981 SoC
In reply to Weijie GaoThis patch adds PWM support for MediaTek MT7981 SoC.
MT7981 uses a different register offset so we have to add a version field to indicate the IP core version.
---
v3 changes: none
v2 changes: none
--- drivers/pwm/pwm-mtk.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
drivers/pwm/pwm-mtk.c +32 -2
@@ -29,13 +29,23 @@#define NSEC_PER_SEC 1000000000L -static const unsigned int mtk_pwm_reg_offset[] = { +enum mtk_pwm_reg_ver { +PWM_REG_V1 , +PWM_REG_V2 , +}; + +static const unsigned int mtk_pwm_reg_offset_v1[] = {0x0010 ,0x0050 ,0x0090 ,0x00d0 ,0x0110 ,0x0150 ,0x0190 ,0x0220 }; +static const unsigned int mtk_pwm_reg_offset_v2[] = { +0x0080 ,0x00c0 ,0x0100 ,0x0140 ,0x0180 ,0x01c0 ,0x0200 ,0x0240 +}; +struct mtk_pwm_soc {unsigned int num_pwms;bool pwm45_fixup; +enum mtk_pwm_reg_ver reg_ver; };struct mtk_pwm_priv {
@@ -49,7 +59,16 @@ struct mtk_pwm_priv {static void mtk_pwm_w32 (struct udevice *dev,uint channel,uint reg,uint val) {struct mtk_pwm_priv *priv =dev_get_priv (dev); -u32 offset = mtk_pwm_reg_offset[channel]; +u32 offset; + +switch (priv->soc->reg_ver) { +case PWM_REG_V2 : + offset = mtk_pwm_reg_offset_v2[channel]; +break ; + +default : + offset = mtk_pwm_reg_offset_v1[channel]; + }writel (val, priv->base + offset + reg); }
@@ -159,27 +178,38 @@ static const struct pwm_ops mtk_pwm_ops = {static const struct mtk_pwm_soc mt7622_data = { .num_pwms =6 , .pwm45_fixup = false, + .reg_ver =PWM_REG_V1 , };static const struct mtk_pwm_soc mt7623_data = { .num_pwms =5 , .pwm45_fixup = true, + .reg_ver =PWM_REG_V1 , };static const struct mtk_pwm_soc mt7629_data = { .num_pwms =1 , .pwm45_fixup = false, + .reg_ver =PWM_REG_V1 , +}; + +static const struct mtk_pwm_soc mt7981_data = { + .num_pwms =2 , + .pwm45_fixup = false, + .reg_ver =PWM_REG_V2 , };static const struct mtk_pwm_soc mt7986_data = { .num_pwms =2 , .pwm45_fixup = false, + .reg_ver =PWM_REG_V1 , };static const struct udevice_id mtk_pwm_ids[] = { { .compatible ="mediatek,mt7622-pwm" , .data = (ulong)&mt7622_data }, { .compatible ="mediatek,mt7623-pwm" , .data = (ulong)&mt7623_data }, { .compatible ="mediatek,mt7629-pwm" , .data = (ulong)&mt7629_data }, + { .compatible ="mediatek,mt7981-pwm" , .data = (ulong)&mt7981_data }, { .compatible ="mediatek,mt7986-pwm" , .data = (ulong)&mt7986_data }, { } };
Signature · 1 line
2.17.1
PATCH v3 14/32 timer: mtk: add support for MediaTek MT7981/MT7986 SoCs
In reply to Weijie GaoThis patch add general-purpose timer support for MediaTek MT7981/MT7986. These two SoCs uses a newer version of timer with its register definition slightly changed.
---
v3 changes: none
v2 changes: none
--- drivers/timer/mtk_timer.c | 59 ++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 22 deletions(-)
drivers/timer/mtk_timer.c +37 -22
@@ -13,24 +13,32 @@#include <asm/io.h> #include <linux/bitops.h> -#define MTK_GPT4_CTRL 0x40 -#define MTK_GPT4_CLK 0x44 -#define MTK_GPT4_CNT 0x48 +#define MTK_GPT4_OFFSET_V1 0x40 +#define MTK_GPT4_OFFSET_V2 0x80 -#define GPT4_ENABLE BIT(0) -#define GPT4_CLEAR BIT(1) -#define GPT4_FREERUN GENMASK(5, 4) -#define GPT4_CLK_SYS 0x0 -#define GPT4_CLK_DIV1 0x0 +#define MTK_GPT_CON 0x0 +#define MTK_GPT_V1_CLK 0x4 +#define MTK_GPT_CNT 0x8 + +#define GPT_ENABLE BIT(0) +#define GPT_CLEAR BIT(1) +#define GPT_V1_FREERUN GENMASK(5, 4) +#define GPT_V2_FREERUN GENMASK(6, 5) + +enum mtk_gpt_ver { +MTK_GPT_V1 , +MTK_GPT_V2 +};struct mtk_timer_priv {void __iomem *base; +unsigned int gpt4_offset; };static u64 mtk_timer_get_count (struct udevice *dev) {struct mtk_timer_priv *priv =dev_get_priv (dev); -u32 val =readl (priv->base +MTK_GPT4_CNT ); +u32 val =readl (priv->base + priv->gpt4_offset +MTK_GPT_CNT );return timer_conv_64 (val); }
@@ -40,12 +48,27 @@ static int mtk_timer_probe(struct udevice *dev)struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);struct mtk_timer_priv *priv =dev_get_priv (dev);struct clk clk, parent; -int ret; +int ret, gpt_ver; priv->base =dev_read_addr_ptr (dev); + gpt_ver =dev_get_driver_data (dev); +if (!priv->base)return -ENOENT ; +if (gpt_ver ==MTK_GPT_V2 ) { + priv->gpt4_offset =MTK_GPT4_OFFSET_V2 ; + +writel (GPT_V2_FREERUN |GPT_CLEAR |GPT_ENABLE , + priv->base + priv->gpt4_offset +MTK_GPT_CON ); + }else { + priv->gpt4_offset =MTK_GPT4_OFFSET_V1 ; + +writel (GPT_V1_FREERUN |GPT_CLEAR |GPT_ENABLE , + priv->base + priv->gpt4_offset +MTK_GPT_CON ); +writel (0 , priv->base + priv->gpt4_offset +MTK_GPT_V1_CLK ); + } + ret =clk_get_by_index (dev,0 , &clk);if (ret)return ret;
@@ -61,16 +84,6 @@ static int mtk_timer_probe(struct udevice *dev)if (!uc_priv->clock_rate)return -EINVAL ; -/* -* Initialize the timer: -* 1. set clock source to system clock with clock divider setting to 1 -* 2. set timer mode to free running -* 3. reset timer counter to 0 then enable the timer -*/ -writel (GPT4_CLK_SYS |GPT4_CLK_DIV1 , priv->base +MTK_GPT4_CLK ); -writel (GPT4_FREERUN |GPT4_CLEAR |GPT4_ENABLE , - priv->base +MTK_GPT4_CTRL ); -return 0 ; }
@@ -79,8 +92,10 @@ static const struct timer_ops mtk_timer_ops = { };static const struct udevice_id mtk_timer_ids[] = { - { .compatible ="mediatek,timer" }, - { .compatible ="mediatek,mt6577-timer" }, + { .compatible ="mediatek,timer" , .data =MTK_GPT_V1 }, + { .compatible ="mediatek,mt6577-timer" , .data =MTK_GPT_V1 }, + { .compatible ="mediatek,mt7981-timer" , .data =MTK_GPT_V2 }, + { .compatible ="mediatek,mt7986-timer" , .data =MTK_GPT_V2 }, { } };
Signature · 1 line
2.17.1
PATCH v3 15/32 watchdog: mediatek: add support for MediaTek MT7986 SoC
In reply to Weijie GaoAdd watchdog support for MediaTek MT7986 SoC
---
v3 changes: none
v2 changes: none
--- drivers/watchdog/mtk_wdt.c | 1 + 1 file changed, 1 insertion(+)
drivers/watchdog/mtk_wdt.c +1 -0
@@ -145,6 +145,7 @@ static const struct wdt_ops mtk_wdt_ops = {static const struct udevice_id mtk_wdt_ids[] = { { .compatible ="mediatek,wdt" }, { .compatible ="mediatek,mt6589-wdt" }, + { .compatible ="mediatek,mt7986-wdt" }, {} };
Signature · 1 line
2.17.1
PATCH v3 17/32 i2c: add support for MediaTek I2C interface
In reply to Weijie GaoThis patch adds support for MediaTek I2C interface
---
v3 changes: none
v2 changes:
Reorganize code to reduce duplicated code Rename mtk_i2c_ofdata_to_platdata to mtk_i2c_of_to_plat
--- drivers/i2c/Kconfig | 9 + drivers/i2c/Makefile | 1 + drivers/i2c/mtk_i2c.c | 822 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 832 insertions(+) create mode 100644 drivers/i2c/mtk_i2c.c
drivers/i2c/Kconfig +9 -0
@@ -261,6 +261,15 @@ config SYS_I2C_MESON internal buffer holding up to 8 bytes for transfers and supports both 7-bit and 10-bit addresses. +config SYS_I2C_MTK + bool "MediaTek I2C driver" + help + This selects the MediaTek Integrated Inter Circuit bus driver. + The I2C bus adapter is the base for some other I2C client, + eg: touch, sensors. + If you want to use MediaTek I2C interface, say Y here. + If unsure, say N. + config SYS_I2C_MICROCHIP bool "Microchip I2C driver" help
drivers/i2c/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_SYS_I2C_MICROCHIP) += i2c-microchip.o obj-$(CONFIG_SYS_I2C_MV) += mv_i2c.o obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o +obj-$(CONFIG_SYS_I2C_MTK) += mtk_i2c.o obj-$(CONFIG_SYS_I2C_NEXELL) += nx_i2c.o obj-$(CONFIG_SYS_I2C_NPCM) += npcm_i2c.o obj-$(CONFIG_SYS_I2C_OCORES) += ocores_i2c.o
drivers/i2c/mtk_i2c.c new file +822 -0
822 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 18/32 arm: dts: mt7622: add i2c support
In reply to Weijie GaoAdd both hardware and software i2c support for mt7622.
---
v3 changes: none
v2 changes: none
--- arch/arm/dts/mt7622-rfb.dts | 18 ++++++++++++++++++ arch/arm/dts/mt7622.dtsi | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
arch/arm/dts/mt7622-rfb.dts +18 -0
@@ -159,6 +159,14 @@ }; }; + + i2c1_pins_default: i2c1-default { + mux { + function = "i2c"; + groups = "i2c1_0"; + }; + }; + }; &snfi {
@@ -242,3 +250,13 @@ &u3phy { status = "okay"; }; + +&soft_i2c { + status = "disabled"; +}; + +&i2c1 { + pinctrl-names = "default"; + pinctrl-0 = <&i2c1_pins_default>; + status = "okay"; +};
arch/arm/dts/mt7622.dtsi +24 -0
@@ -424,4 +424,28 @@ status = "disabled"; }; + soft_i2c: soft_i2c@0 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "i2c-gpio"; + gpios = <&gpio 56 GPIO_ACTIVE_HIGH>, /* SDA */ + <&gpio 55 GPIO_ACTIVE_HIGH>; /* CLK */ + i2c-gpio,delay-us = <5>; + status = "disabled"; + }; + + i2c1: i2c@11008000 { + compatible = "mediatek,mt7622-i2c"; + reg = <0x11008000 0x90>, + <0x11000180 0x80>; + interrupts = <GIC_SPI 85 IRQ_TYPE_LEVEL_LOW>; + clock-div = <16>; + clocks = <&pericfg CLK_PERI_I2C1_PD>, + <&pericfg CLK_PERI_AP_DMA_PD>; + clock-names = "main", "dma"; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + };
Signature · 1 line
2.17.1
PATCH v3 16/32 spi: add support for MediaTek spi-mem controller
In reply to Weijie GaoThis patch adds support for spi-mem controller found on newer MediaTek SoCs This controller supports Single/Dual/Quad SPI mode.
---
v3 changes: none
v2 changes:
Remove unused code
Fix coding style
Add description for struct fields
--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/mtk_spim.c | 701 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 710 insertions(+) create mode 100644 drivers/spi/mtk_spim.c
drivers/spi/Kconfig +8 -0
@@ -276,6 +276,14 @@ config MTK_SNFI_SPI used to access SPI memory devices like SPI-NOR or SPI-NAND on platforms embedding this IP core, like MT7622/M7629. +config MTK_SPIM + bool "Mediatek SPI-MEM master controller driver" + depends on SPI_MEM + help + Enable MediaTek SPI-MEM master controller driver. This driver mainly + supports SPI flashes. You can use single, dual or quad mode + transmission on this controller. + config MVEBU_A3700_SPI bool "Marvell Armada 3700 SPI driver" select CLK_ARMADA_3720
drivers/spi/Makefile +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o obj-$(CONFIG_MTK_SNFI_SPI) += mtk_snfi_spi.o obj-$(CONFIG_MTK_SNOR) += mtk_snor.o +obj-$(CONFIG_MTK_SPIM) += mtk_spim.o obj-$(CONFIG_MT7620_SPI) += mt7620_spi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o obj-$(CONFIG_MSCC_BB_SPI) += mscc_bb_spi.o
drivers/spi/mtk_spim.c new file +701 -0
701 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 19/32 dt-bindings: pinctrl: mediatek: add a header for common pinconf parameters
In reply to Weijie GaoThis patch adds a pinctrl header for common pinconf parameters such as pull-up/pull-down resistors and drive strengths.
---
v3 changes: none
v2 changes: none
--- include/dt-bindings/pinctrl/mt65xx.h | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/dt-bindings/pinctrl/mt65xx.h
include/dt-bindings/pinctrl/mt65xx.h new file +41 -0
@@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2022 MediaTek Inc. +* Author: Hongzhou.Yang <[email protected]> +*/ + +#ifndef _DT_BINDINGS_PINCTRL_MT65XX_H +#define _DT_BINDINGS_PINCTRL_MT65XX_H + +#define MTK_PIN_NO (x) ((x) << 8) +#define MTK_GET_PIN_NO (x) ((x) >> 8) +#define MTK_GET_PIN_FUNC (x) ((x) & 0xf) + +#define MTK_PUPD_SET_R1R0_00 100 +#define MTK_PUPD_SET_R1R0_01 101 +#define MTK_PUPD_SET_R1R0_10 102 +#define MTK_PUPD_SET_R1R0_11 103 + +#define MTK_PULL_SET_RSEL_000 200 +#define MTK_PULL_SET_RSEL_001 201 +#define MTK_PULL_SET_RSEL_010 202 +#define MTK_PULL_SET_RSEL_011 203 +#define MTK_PULL_SET_RSEL_100 204 +#define MTK_PULL_SET_RSEL_101 205 +#define MTK_PULL_SET_RSEL_110 206 +#define MTK_PULL_SET_RSEL_111 207 + +#define MTK_DRIVE_2mA 2 +#define MTK_DRIVE_4mA 4 +#define MTK_DRIVE_6mA 6 +#define MTK_DRIVE_8mA 8 +#define MTK_DRIVE_10mA 10 +#define MTK_DRIVE_12mA 12 +#define MTK_DRIVE_14mA 14 +#define MTK_DRIVE_16mA 16 +#define MTK_DRIVE_20mA 20 +#define MTK_DRIVE_24mA 24 +#define MTK_DRIVE_28mA 28 +#define MTK_DRIVE_32mA 32 + +#endif /* _DT_BINDINGS_PINCTRL_MT65XX_H */
Signature · 1 line
2.17.1
PATCH v3 22/32 clk: mediatek: add CLK_BYPASS_XTAL flag to allow bypassing searching clock parent of xtal clock
In reply to Weijie GaoThe mtk clock framework in u-boot uses array index for searching clock parent (kernel uses strings for search), so we need to specify a special clock with ID=0 for CLK_XTAL in u-boot.
In the mt7622/mt7629 clock tree, the clocks with ID=0 never call mtk_topckgen_get_mux_rate, adn return xtal clock directly. This what we expected.
However for newer chips, they may have some clocks with ID=0 not representing the xtal clock and still needs mtk_topckgen_get_mux_rate be called. Current logic will make entire clock driver not working.
This patch adds a flag to indicate that whether a clock driver needs clocks with ID=0 to call mtk_topckgen_get_mux_rate.
---
v3 changes: none
v2 changes:
Add comment for flags
Fix the if condition of CLK_BYPASS_XTAL
--- drivers/clk/mediatek/clk-mtk.c | 4 +++- drivers/clk/mediatek/clk-mtk.h | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/clk/mediatek/clk-mtk.c +3 -1
@@ -319,7 +319,9 @@ static ulong mtk_topckgen_get_mux_rate(struct clk *clk, u32 off) index &= mux->mux_mask << mux->mux_shift; index = index >> mux->mux_shift; -if (mux->parent[index]) +if (mux->parent[index] >0 || + (mux->parent[index] ==CLK_XTAL && + priv->tree->flags &CLK_BYPASS_XTAL ))return mtk_clk_find_parent_rate (clk, mux->parent[index],NULL );
drivers/clk/mediatek/clk-mtk.h +6 -0
@@ -11,6 +11,11 @@#define CLK_XTAL 0#define MHZ (1000 * 1000) +/* flags in struct mtk_clk_tree */ + +/* clk id == 0 doesn't mean it's xtal clk */ +#define CLK_BYPASS_XTAL BIT(0) +#define HAVE_RST_BAR BIT(0)#define CLK_DOMAIN_SCPSYS BIT(0)#define CLK_MUX_SETCLR_UPD BIT(1)
@@ -197,6 +202,7 @@ struct mtk_clk_tree {const struct mtk_fixed_clk *fclks;const struct mtk_fixed_factor *fdivs;const struct mtk_composite *muxes; +u32 flags; };struct mtk_clk_priv {
Signature · 1 line
2.17.1
PATCH v3 21/32 pinctrl: mediatek: add pinctrl driver for MT7986 SoC
In reply to Weijie GaoThis patch adds pinctrl and gpio support for MT7986 SoC
---
v3 changes: none
v2 changes: none
--- drivers/pinctrl/mediatek/Kconfig | 4 + drivers/pinctrl/mediatek/Makefile | 1 + drivers/pinctrl/mediatek/pinctrl-mt7986.c | 775 ++++++++++++++++++++++ 3 files changed, 780 insertions(+) create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7986.c
drivers/pinctrl/mediatek/Kconfig +4 -0
@@ -20,6 +20,10 @@ config PINCTRL_MT7981 bool "MT7981 SoC pinctrl driver" select PINCTRL_MTK +config PINCTRL_MT7986 + bool "MT7986 SoC pinctrl driver" + select PINCTRL_MTK + config PINCTRL_MT8512 bool "MT8512 SoC pinctrl driver" select PINCTRL_MTK
drivers/pinctrl/mediatek/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_PINCTRL_MT7622) += pinctrl-mt7622.o obj-$(CONFIG_PINCTRL_MT7623) += pinctrl-mt7623.o obj-$(CONFIG_PINCTRL_MT7629) += pinctrl-mt7629.o obj-$(CONFIG_PINCTRL_MT7981) += pinctrl-mt7981.o +obj-$(CONFIG_PINCTRL_MT7986) += pinctrl-mt7986.o obj-$(CONFIG_PINCTRL_MT8512) += pinctrl-mt8512.o obj-$(CONFIG_PINCTRL_MT8516) += pinctrl-mt8516.o obj-$(CONFIG_PINCTRL_MT8518) += pinctrl-mt8518.o
drivers/pinctrl/mediatek/pinctrl-mt7986.c new file +775 -0
775 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 23/32 clk: mediatek: add support to configure clock driver parent
In reply to Weijie GaoThis patch adds support for a clock node to configure its parent clock where possible.
---
v3 changes: none
v2 changes: none
--- drivers/clk/mediatek/clk-mtk.c | 79 ++++++++++++++++++++-------------- drivers/clk/mediatek/clk-mtk.h | 2 + 2 files changed, 48 insertions(+), 33 deletions(-)
drivers/clk/mediatek/clk-mtk.c +46 -33
@@ -42,20 +42,14 @@* the accurate frequency. */ static ulong mtk_clk_find_parent_rate (struct clk *clk,int id, -const struct driver *drv) +struct udevice *pdev) {struct clk parent = { .id = id, }; -if (drv) { -struct udevice *dev; - -if (uclass_get_device_by_driver (UCLASS_CLK , drv, &dev)) -return -ENODEV ; - - parent.dev = dev; - }else { +if (pdev) + parent.dev = pdev; +else parent.dev = clk->dev; - }return clk_get_rate (&parent); }
@@ -296,7 +290,7 @@ static ulong mtk_topckgen_get_factor_rate(struct clk *clk, u32 off)switch (fdiv->flags &CLK_PARENT_MASK ) {case CLK_PARENT_APMIXED : rate =mtk_clk_find_parent_rate (clk, fdiv->parent, -DM_DRIVER_GET (mtk_clk_apmixedsys)); + priv->parent);break ;case CLK_PARENT_TOPCKGEN : rate =mtk_clk_find_parent_rate (clk, fdiv->parent,NULL );
@@ -321,9 +315,18 @@ static ulong mtk_topckgen_get_mux_rate(struct clk *clk, u32 off)if (mux->parent[index] >0 || (mux->parent[index] ==CLK_XTAL && - priv->tree->flags &CLK_BYPASS_XTAL )) -return mtk_clk_find_parent_rate (clk, mux->parent[index], -NULL ); + priv->tree->flags &CLK_BYPASS_XTAL )) { +switch (mux->flags &CLK_PARENT_MASK ) { +case CLK_PARENT_APMIXED : +return mtk_clk_find_parent_rate (clk, mux->parent[index], + priv->parent); +break ; +default : +return mtk_clk_find_parent_rate (clk, mux->parent[index], +NULL ); +break ; + } + }return priv->tree->xtal_rate; }
@@ -342,7 +345,7 @@ static ulong mtk_topckgen_get_rate(struct clk *clk) priv->tree->muxes_offs); } -static int mtk_topckgen_enable (struct clk *clk) +static int mtk_clk_mux_enable (struct clk *clk) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);const struct mtk_composite *mux;
@@ -375,7 +378,7 @@ static int mtk_topckgen_enable(struct clk *clk)return 0 ; } -static int mtk_topckgen_disable (struct clk *clk) +static int mtk_clk_mux_disable (struct clk *clk) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);const struct mtk_composite *mux;
@@ -401,7 +404,7 @@ static int mtk_topckgen_disable(struct clk *clk)return 0 ; } -static int mtk_topckgen_set_parent (struct clk *clk,struct clk *parent) +static int mtk_common_clk_set_parent (struct clk *clk,struct clk *parent) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);
@@ -473,19 +476,7 @@ static ulong mtk_clk_gate_get_rate(struct clk *clk)struct mtk_cg_priv *priv =dev_get_priv (clk->dev);const struct mtk_gate *gate = &priv->gates[clk->id]; -switch (gate->flags &CLK_PARENT_MASK ) { -case CLK_PARENT_APMIXED : -return mtk_clk_find_parent_rate (clk, gate->parent, -DM_DRIVER_GET (mtk_clk_apmixedsys)); -break ; -case CLK_PARENT_TOPCKGEN : -return mtk_clk_find_parent_rate (clk, gate->parent, -DM_DRIVER_GET (mtk_clk_topckgen)); -break ; - -default : -return priv->tree->xtal_rate; - } +return mtk_clk_find_parent_rate (clk, gate->parent, priv->parent); }const struct clk_ops mtk_clk_apmixedsys_ops = {
@@ -496,10 +487,10 @@ const struct clk_ops mtk_clk_apmixedsys_ops = { };const struct clk_ops mtk_clk_topckgen_ops = { - .enable = mtk_topckgen_enable, - .disable = mtk_topckgen_disable, + .enable = mtk_clk_mux_enable, + .disable = mtk_clk_mux_disable, .get_rate = mtk_topckgen_get_rate, - .set_parent = mtk_topckgen_set_parent, + .set_parent = mtk_common_clk_set_parent, };const struct clk_ops mtk_clk_gate_ops = {
@@ -512,11 +503,22 @@ int mtk_common_clk_init(struct udevice *dev, const struct mtk_clk_tree *tree) {struct mtk_clk_priv *priv =dev_get_priv (dev); +struct udevice *parent; +int ret; priv->base =dev_read_addr_ptr (dev);if (!priv->base)return -ENOENT ; + ret =uclass_get_device_by_phandle (UCLASS_CLK , dev,"clock-parent" , &parent); +if (ret || !parent) { + ret =uclass_get_device_by_driver (UCLASS_CLK , +DM_DRIVER_GET (mtk_clk_apmixedsys), &parent); +if (ret || !parent) +return -ENOENT ; + } + + priv->parent = parent; priv->tree = tree;return 0 ;
@@ -527,11 +529,22 @@ int mtk_common_clk_gate_init(struct udevice *dev, const struct mtk_gate *gates) {struct mtk_cg_priv *priv =dev_get_priv (dev); +struct udevice *parent; +int ret; priv->base =dev_read_addr_ptr (dev);if (!priv->base)return -ENOENT ; + ret =uclass_get_device_by_phandle (UCLASS_CLK , dev,"clock-parent" , &parent); +if (ret || !parent) { + ret =uclass_get_device_by_driver (UCLASS_CLK , +DM_DRIVER_GET (mtk_clk_topckgen), &parent); +if (ret || !parent) +return -ENOENT ; + } + + priv->parent = parent; priv->tree = tree; priv->gates = gates;
drivers/clk/mediatek/clk-mtk.h +2 -0
@@ -206,11 +206,13 @@ struct mtk_clk_tree { };struct mtk_clk_priv { +struct udevice *parent;void __iomem *base;const struct mtk_clk_tree *tree; };struct mtk_cg_priv { +struct udevice *parent;void __iomem *base;const struct mtk_clk_tree *tree;const struct mtk_gate *gates;
Signature · 1 line
2.17.1
PATCH v3 25/32 clk: mediatek: add CLK_XTAL support for clock driver
In reply to Weijie GaoThis adds the CLK_XTAL macro/flag to allow modeling clocks which are directly connected to the xtal clock.
---
v3 changes: none
v2 changes:
Fix incorrect fallback in mtk_infrasys_get_factor_rate Fix commit description
--- drivers/clk/mediatek/clk-mtk.c | 4 ++++ drivers/clk/mediatek/clk-mtk.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/clk/mediatek/clk-mtk.c +4 -0
@@ -296,6 +296,7 @@ static ulong mtk_topckgen_get_factor_rate(struct clk *clk, u32 off) rate =mtk_clk_find_parent_rate (clk, fdiv->parent,NULL );break ; +case CLK_PARENT_XTAL :default : rate = priv->tree->xtal_rate; }
@@ -314,6 +315,9 @@ static ulong mtk_infrasys_get_factor_rate(struct clk *clk, u32 off) rate =mtk_clk_find_parent_rate (clk, fdiv->parent, priv->parent);break ; +case CLK_PARENT_XTAL : + rate = priv->tree->xtal_rate; +break ;default : rate =mtk_clk_find_parent_rate (clk, fdiv->parent,NULL ); }
drivers/clk/mediatek/clk-mtk.h +2 -1
@@ -29,7 +29,8 @@#define CLK_PARENT_APMIXED BIT(4)#define CLK_PARENT_TOPCKGEN BIT(5)#define CLK_PARENT_INFRASYS BIT(6) -#define CLK_PARENT_MASK GENMASK(6, 4) +#define CLK_PARENT_XTAL BIT(7) +#define CLK_PARENT_MASK GENMASK(7, 4)#define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34
Signature · 1 line
2.17.1
PATCH v3 24/32 clk: mediatek: add infrasys clock mux support
In reply to Weijie GaoThis patch adds infrasys clock mux support for mediatek clock drivers.
---
v3 changes: none
v2 changes:
Fix the if condition of CLK_BYPASS_XTAL
--- drivers/clk/mediatek/clk-mtk.c | 71 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 4 +- 2 files changed, 74 insertions(+), 1 deletion(-)
drivers/clk/mediatek/clk-mtk.c +71 -0
@@ -303,6 +303,24 @@ static ulong mtk_topckgen_get_factor_rate(struct clk *clk, u32 off)return mtk_factor_recalc_rate (fdiv, rate); } +static ulong mtk_infrasys_get_factor_rate (struct clk *clk,u32 off) +{ +struct mtk_clk_priv *priv =dev_get_priv (clk->dev); +const struct mtk_fixed_factor *fdiv = &priv->tree->fdivs[off]; +ulong rate; + +switch (fdiv->flags &CLK_PARENT_MASK ) { +case CLK_PARENT_TOPCKGEN : + rate =mtk_clk_find_parent_rate (clk, fdiv->parent, + priv->parent); +break ; +default : + rate =mtk_clk_find_parent_rate (clk, fdiv->parent,NULL ); + } + +return mtk_factor_recalc_rate (fdiv, rate); +} +static ulong mtk_topckgen_get_mux_rate (struct clk *clk,u32 off) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);
@@ -331,6 +349,33 @@ static ulong mtk_topckgen_get_mux_rate(struct clk *clk, u32 off)return priv->tree->xtal_rate; } +static ulong mtk_infrasys_get_mux_rate (struct clk *clk,u32 off) +{ +struct mtk_clk_priv *priv =dev_get_priv (clk->dev); +const struct mtk_composite *mux = &priv->tree->muxes[off]; +u32 index; + + index =readl (priv->base + mux->mux_reg); + index &= mux->mux_mask << mux->mux_shift; + index = index >> mux->mux_shift; + +if (mux->parent[index] >0 || + (mux->parent[index] ==CLK_XTAL && + priv->tree->flags &CLK_BYPASS_XTAL )) { +switch (mux->flags &CLK_PARENT_MASK ) { +case CLK_PARENT_TOPCKGEN : +return mtk_clk_find_parent_rate (clk, mux->parent[index], + priv->parent); +break ; +default : +return mtk_clk_find_parent_rate (clk, mux->parent[index], +NULL ); +break ; + } + } +return 0 ; +} +static ulong mtk_topckgen_get_rate (struct clk *clk) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);
@@ -345,6 +390,25 @@ static ulong mtk_topckgen_get_rate(struct clk *clk) priv->tree->muxes_offs); } +static ulong mtk_infrasys_get_rate (struct clk *clk) +{ +struct mtk_clk_priv *priv =dev_get_priv (clk->dev); + +ulong rate; + +if (clk->id < priv->tree->fdivs_offs) { + rate = priv->tree->fclks[clk->id].rate; + }else if (clk->id < priv->tree->muxes_offs) { + rate =mtk_infrasys_get_factor_rate (clk, clk->id - + priv->tree->fdivs_offs); + }else { + rate =mtk_infrasys_get_mux_rate (clk, clk->id - + priv->tree->muxes_offs); + } + +return rate; +} +static int mtk_clk_mux_enable (struct clk *clk) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);
@@ -493,6 +557,13 @@ const struct clk_ops mtk_clk_topckgen_ops = { .set_parent = mtk_common_clk_set_parent, }; +const struct clk_ops mtk_clk_infrasys_ops = { + .enable = mtk_clk_mux_enable, + .disable = mtk_clk_mux_disable, + .get_rate = mtk_infrasys_get_rate, + .set_parent = mtk_common_clk_set_parent, +}; +const struct clk_ops mtk_clk_gate_ops = { .enable = mtk_clk_gate_enable, .disable = mtk_clk_gate_disable,
drivers/clk/mediatek/clk-mtk.h +3 -1
@@ -28,7 +28,8 @@#define CLK_PARENT_APMIXED BIT(4)#define CLK_PARENT_TOPCKGEN BIT(5) -#define CLK_PARENT_MASK GENMASK(5, 4) +#define CLK_PARENT_INFRASYS BIT(6) +#define CLK_PARENT_MASK GENMASK(6, 4)#define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34
@@ -220,6 +221,7 @@ struct mtk_cg_priv {extern const struct clk_ops mtk_clk_apmixedsys_ops;extern const struct clk_ops mtk_clk_topckgen_ops; +extern const struct clk_ops mtk_clk_infrasys_ops;extern const struct clk_ops mtk_clk_gate_ops; int mtk_common_clk_init(struct udevice *dev,
Signature · 1 line
2.17.1
PATCH v3 20/32 pinctrl: mediatek: add pinctrl driver for MT7981 SoC
In reply to Weijie GaoThis patch adds pinctrl and gpio support for MT7981 SoC
---
v3 changes: none
v2 changes: none
--- drivers/pinctrl/mediatek/Kconfig | 4 + drivers/pinctrl/mediatek/Makefile | 1 + drivers/pinctrl/mediatek/pinctrl-mt7981.c | 1049 +++++++++++++++++++++ 3 files changed, 1054 insertions(+) create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7981.c
drivers/pinctrl/mediatek/Kconfig +4 -0
@@ -16,6 +16,10 @@ config PINCTRL_MT7629 bool "MT7629 SoC pinctrl driver" select PINCTRL_MTK +config PINCTRL_MT7981 + bool "MT7981 SoC pinctrl driver" + select PINCTRL_MTK + config PINCTRL_MT8512 bool "MT8512 SoC pinctrl driver" select PINCTRL_MTK
drivers/pinctrl/mediatek/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_PINCTRL_MTK) += pinctrl-mtk-common.o obj-$(CONFIG_PINCTRL_MT7622) += pinctrl-mt7622.o obj-$(CONFIG_PINCTRL_MT7623) += pinctrl-mt7623.o obj-$(CONFIG_PINCTRL_MT7629) += pinctrl-mt7629.o +obj-$(CONFIG_PINCTRL_MT7981) += pinctrl-mt7981.o obj-$(CONFIG_PINCTRL_MT8512) += pinctrl-mt8512.o obj-$(CONFIG_PINCTRL_MT8516) += pinctrl-mt8516.o obj-$(CONFIG_PINCTRL_MT8518) += pinctrl-mt8518.o
drivers/pinctrl/mediatek/pinctrl-mt7981.c new file +1049 -0
1,049 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 26/32 clk: mediatek: add clock driver support for MediaTek MT7986 SoC
In reply to Weijie GaoThis patch adds clock driver support for MediaTek MT7986 SoC
---
v3 changes: none
v2 changes:
Fix coding style
--- drivers/clk/mediatek/Makefile | 1 + drivers/clk/mediatek/clk-mt7986.c | 672 +++++++++++++++++++++++++ include/dt-bindings/clock/mt7986-clk.h | 249 +++++++++ 3 files changed, 922 insertions(+) create mode 100644 drivers/clk/mediatek/clk-mt7986.c create mode 100644 include/dt-bindings/clock/mt7986-clk.h
drivers/clk/mediatek/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_MT8512) += clk-mt8512.o obj-$(CONFIG_TARGET_MT7623) += clk-mt7623.o obj-$(CONFIG_TARGET_MT7622) += clk-mt7622.o obj-$(CONFIG_TARGET_MT7629) += clk-mt7629.o +obj-$(CONFIG_TARGET_MT7986) += clk-mt7986.o obj-$(CONFIG_TARGET_MT8183) += clk-mt8183.o obj-$(CONFIG_TARGET_MT8516) += clk-mt8516.o obj-$(CONFIG_TARGET_MT8518) += clk-mt8518.o
drivers/clk/mediatek/clk-mt7986.c new file +672 -0
672 lines not on this page · raw message
include/dt-bindings/clock/mt7986-clk.h new file +249 -0
249 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 28/32 cpu: add basic cpu driver for MediaTek ARM chips
In reply to Weijie GaoAdd basic CPU driver used to retrieve CPU model information.
---
v3 changes:
Use regmap to read hwver registers
v2 changes: new
--- drivers/cpu/Makefile | 1 + drivers/cpu/mtk_cpu.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 drivers/cpu/mtk_cpu.c
drivers/cpu/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_CPU) += cpu-uclass.o obj-$(CONFIG_ARCH_BMIPS) += bmips_cpu.o obj-$(CONFIG_ARCH_IMX8) += imx8_cpu.o obj-$(CONFIG_ARCH_AT91) += at91_cpu.o +obj-$(CONFIG_ARCH_MEDIATEK) += mtk_cpu.o obj-$(CONFIG_CPU_MPC83XX) += mpc83xx_cpu.o obj-$(CONFIG_CPU_RISCV) += riscv_cpu.o obj-$(CONFIG_CPU_MICROBLAZE) += microblaze_cpu.o
drivers/cpu/mtk_cpu.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 29/32 tools: mtk_image: split gfh header verification into a new function
In reply to Weijie GaoThe verification code of gfh header for NAND and non-NAND are identical. It's better to define a individual function to reduce redundancy.
---
v3 changes: none
v2 changes: none
--- tools/mtk_image.c | 51 +++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 30 deletions(-)
tools/mtk_image.c +21 -30
@@ -480,6 +480,25 @@ static int mtk_image_vrec_header(struct image_tool_params *params,return SHA256_SUM_LEN ; } +static int mtk_image_verify_gfh (struct gfh_header *gfh,uint32_t type,int print) +{ +if (strcmp (gfh->file_info.name,GFH_FILE_INFO_NAME )) +return -1 ; + +if (le32_to_cpu (gfh->file_info.flash_type) != type) +return -1 ; + +if (print) +printf ("Load Address: %08x\n" , +le32_to_cpu (gfh->file_info.load_addr) + +le32_to_cpu (gfh->file_info.jump_offset)); + +if (print) +printf ("Architecture: %s\n" , is_arm64_image ?"ARM64" :"ARM" ); + +return 0 ; +} +static int mtk_image_verify_gen_header (const uint8_t *ptr,int print) {union gen_boot_header *gbh = (union gen_boot_header *)ptr;
@@ -542,21 +561,7 @@ static int mtk_image_verify_gen_header(const uint8_t *ptr, int print) gfh = (struct gfh_header *)(ptr + gfh_offset); -if (strcmp (gfh->file_info.name,GFH_FILE_INFO_NAME )) -return -1 ; - -if (le32_to_cpu (gfh->file_info.flash_type) !=GFH_FLASH_TYPE_GEN ) -return -1 ; - -if (print) -printf ("Load Address: %08x\n" , -le32_to_cpu (gfh->file_info.load_addr) + -le32_to_cpu (gfh->file_info.jump_offset)); - -if (print) -printf ("Architecture: %s\n" , is_arm64_image ?"ARM64" :"ARM" ); - -return 0 ; +return mtk_image_verify_gfh (gfh,GFH_FLASH_TYPE_GEN , print); }static int mtk_image_verify_nand_header (const uint8_t *ptr,int print)
@@ -610,21 +615,7 @@ static int mtk_image_verify_nand_header(const uint8_t *ptr, int print) gfh = (struct gfh_header *)(ptr +2 *le16_to_cpu (nh->pagesize)); -if (strcmp (gfh->file_info.name,GFH_FILE_INFO_NAME )) -return -1 ; - -if (le32_to_cpu (gfh->file_info.flash_type) !=GFH_FLASH_TYPE_NAND ) -return -1 ; - -if (print) -printf ("Load Address: %08x\n" , -le32_to_cpu (gfh->file_info.load_addr) + -le32_to_cpu (gfh->file_info.jump_offset)); - -if (print) -printf ("Architecture: %s\n" , is_arm64_image ?"ARM64" :"ARM" ); - -return 0 ; +return mtk_image_verify_gfh (gfh,GFH_FLASH_TYPE_NAND , print); }static uint32_t crc32be_cal (const void *data,size_t length)
Signature · 1 line
2.17.1
PATCH v3 32/32 MAINTAINERS: update maintainer for MediaTek ARM platform
In reply to Weijie GaoAdd new files for MediaTek ARM platform
---
v3 changes:
v2 changes:
Add cpu driver file
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -355,20 +355,26 @@ F: doc/device-tree-bindings/phy/phy-mtk-* F: doc/device-tree-bindings/usb/mediatek,* F: doc/README.mediatek F: drivers/clk/mediatek/ +F: drivers/cpu/mtk_cpu.c +F: drivers/i2c/mtk_i2c.c F: drivers/mmc/mtk-sd.c F: drivers/phy/phy-mtk-* F: drivers/pinctrl/mediatek/ F: drivers/power/domain/mtk-power-domain.c F: drivers/ram/mediatek/ F: drivers/spi/mtk_snfi_spi.c +F: drivers/spi/mtk_spim.c F: drivers/timer/mtk_timer.c F: drivers/usb/host/xhci-mtk.c F: drivers/usb/mtu3/ F: drivers/watchdog/mtk_wdt.c F: drivers/net/mtk_eth.c +F: drivers/net/mtk_eth.h F: drivers/reset/reset-mediatek.c F: tools/mtk_image.c F: tools/mtk_image.h +F: tools/mtk_nand_headers.c +F: tools/mtk_nand_headers.h N: mediatek ARM METHODE SUPPORT
Signature · 1 line
2.17.1
PATCH v3 27/32 clk: mediatek: add clock driver support for MediaTek MT7981 SoC
In reply to Weijie GaoThis patch adds clock driver support for MediaTek MT7981 SoC
---
v3 changes: none
v2 changes:
Fix coding style
--- drivers/clk/mediatek/Makefile | 1 + drivers/clk/mediatek/clk-mt7981.c | 683 +++++++++++++++++++++++++ include/dt-bindings/clock/mt7981-clk.h | 267 ++++++++++ 3 files changed, 951 insertions(+) create mode 100644 drivers/clk/mediatek/clk-mt7981.c create mode 100644 include/dt-bindings/clock/mt7981-clk.h
drivers/clk/mediatek/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_TARGET_MT7623) += clk-mt7623.o obj-$(CONFIG_TARGET_MT7622) += clk-mt7622.o obj-$(CONFIG_TARGET_MT7629) += clk-mt7629.o obj-$(CONFIG_TARGET_MT7986) += clk-mt7986.o +obj-$(CONFIG_TARGET_MT7981) += clk-mt7981.o obj-$(CONFIG_TARGET_MT8183) += clk-mt8183.o obj-$(CONFIG_TARGET_MT8516) += clk-mt8516.o obj-$(CONFIG_TARGET_MT8518) += clk-mt8518.o
drivers/clk/mediatek/clk-mt7981.c new file +683 -0
683 lines not on this page · raw message
include/dt-bindings/clock/mt7981-clk.h new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 31/32 tools: mtk_image: add support for nand headers used by newer chips
In reply to Weijie GaoThis patch adds more nand headers in two new types:
1. HSM header, used for spi-nand thru SNFI interface
2. SPIM header, used for spi-nand thru spi-mem interface
The original nand header is renamed to AP header.
---
v3 changes: none
v2 changes: none
--- tools/mtk_image.c | 23 ++- tools/mtk_nand_headers.c | 422 +++++++++++++++++++++++++++++++++++++-- tools/mtk_nand_headers.h | 110 +++++++++- 3 files changed, 525 insertions(+), 30 deletions(-)
tools/mtk_image.c +16 -7
@@ -33,6 +33,9 @@ static const struct brom_img_type { }, { .name = "snand", .type = BRLYT_TYPE_SNAND + }, { + .name = "spim-nand", + .type = BRLYT_TYPE_SNAND } };
@@ -54,7 +57,7 @@ static char lk_name[32] = "U-Boot";static uint32_t crc32tbl[256 ];/* NAND header selected by user */ -static const union nand_boot_header *hdr_nand; +static const struct nand_header_type *hdr_nand;static uint32_t hdr_nand_size;/* GFH header + 2 * 4KB pages of NAND */
@@ -366,20 +369,26 @@ static int mtk_image_verify_nand_header(const uint8_t *ptr, int print)if (ret <0 )return ret; - bh = (struct brom_layout_header *)(ptr + info.page_size); +if (!ret) { + bh = (struct brom_layout_header *)(ptr + info.page_size); -if (strcmp (bh->name,BRLYT_NAME )) -return -1 ; +if (strcmp (bh->name,BRLYT_NAME )) +return -1 ; + +if (le32_to_cpu (bh->magic) !=BRLYT_MAGIC ) +return -1 ; -if (le32_to_cpu (bh->magic) !=BRLYT_MAGIC ) { -return -1 ; - }else {if (le32_to_cpu (bh->type) ==BRLYT_TYPE_NAND ) bootmedia ="Parallel NAND" ;else if (le32_to_cpu (bh->type) ==BRLYT_TYPE_SNAND ) bootmedia ="Serial NAND (SNFI/AP)" ;else return -1 ; + }else { +if (info.snfi) + bootmedia ="Serial NAND (SNFI/HSM)" ; +else + bootmedia ="Serial NAND (SPIM)" ; }if (print) {
tools/mtk_nand_headers.c +402 -20
485 lines not on this page · raw message
tools/mtk_nand_headers.h +107 -3
134 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 30/32 tools: mtk_image: split the code of generating NAND header into a new file
In reply to Weijie GaoThe predefined NAND headers take too much spaces in the mtk_image.c. Moving them into a new file can significantly improve the readability of both mtk_image.c and the new mtk_nand_headers.c.
This is a preparation for adding more NAND headers.
---
v3 changes: none
v2 changes:
Add comments
Call mtk_nand_header_size only for NAND/SNAND to avoid NULL pointer access
--- tools/Makefile | 1 + tools/mtk_image.c | 305 ++++++--------------------------------- tools/mtk_image.h | 25 ---- tools/mtk_nand_headers.c | 286 ++++++++++++++++++++++++++++++++++++ tools/mtk_nand_headers.h | 61 ++++++++ 5 files changed, 389 insertions(+), 289 deletions(-) create mode 100644 tools/mtk_nand_headers.c create mode 100644 tools/mtk_nand_headers.h
tools/Makefile +1 -0
@@ -147,6 +147,7 @@ dumpimage-mkimage-objs := aisimage.o \ gpimage.o \ gpimage-common.o \ mtk_image.o \ + mtk_nand_headers.o \ $(ECDSA_OBJS-y) \ $(RSA_OBJS-y) \ $(AES_OBJS-y)
tools/mtk_image.c +41 -264
388 lines not on this page · raw message
tools/mtk_image.h +0 -25
@@ -26,31 +26,6 @@ union gen_boot_header {#define SF_BOOT_NAME "SF_BOOT"#define SDMMC_BOOT_NAME "SDMMC_BOOT" -/* Header for NAND */ -union nand_boot_header { -struct { -char name[12 ]; -char version[4 ]; -char id[8 ]; -uint16_t ioif; -uint16_t pagesize; -uint16_t addrcycles; -uint16_t oobsize; -uint16_t pages_of_block; -uint16_t numblocks; -uint16_t writesize_shift; -uint16_t erasesize_shift; -uint8_t dummy[60 ]; -uint8_t ecc_parity[28 ]; - }; - -uint8_t data[0x80 ]; -}; - -#define NAND_BOOT_NAME "BOOTLOADER!" -#define NAND_BOOT_VERSION "V006" -#define NAND_BOOT_ID "NFIINFO" -/* BootROM layout header */ struct brom_layout_header {char name[8 ];
tools/mtk_nand_headers.c new file +286 -0
286 lines not on this page · raw message
tools/mtk_nand_headers.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 28/32] cpu: add basic cpu driver for MediaTek ARM chips
In reply to Weijie GaoQuoted 9 lines · Weijie Gao
Add basic CPU driver used to retrieve CPU model information.
Tested-by Daniel Golle <[email protected]>Signed-off-by Weijie Gao <[email protected]>---
v3 changes:
Use regmap to read hwver registers
v2 changes: new
Quoted 6 lines
--- drivers/cpu/Makefile | 1 + drivers/cpu/mtk_cpu.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 drivers/cpu/mtk_cpu.c
Re: [PATCH v3 06/32] net: mediatek: use a struct to cover variations of all SoCs
In reply to Weijie GaoQuoted 168 lines · Weijie Gao
Using a single soc id to control different initialization and TX/RX flow for all SoCs is not extensible if more hardware variations are added in the future.
This patch introduces a struct to replace the original
mtk_socto allow the driver be able handle newer hardwares.Reviewed-by Simon Glass <[email protected]>Tested-by Daniel Golle <[email protected]>Signed-off-by Weijie Gao <[email protected]>---
v3 changes: none
v2 changes:
Add description for new struct--- drivers/net/mtk_eth.c | 56 ++++++++++++++++++++++++++++++------------- drivers/net/mtk_eth.h | 25 ++++++++++++++++++- 2 files changed, 64 insertions(+), 17 deletions(-)drivers/net/mtk_eth.c +40
-16@@ -142,11 +142,15 @@ enum mtk_switch {SW_MT7531 }; -enum mtk_soc { -SOC_MT7623 , -SOC_MT7629 , -SOC_MT7622 , -SOC_MT7621 +/* struct mtk_soc_data - This is the structure holding all differences +* among various plaforms +* @caps Flags shown the extra capability for the SoC +* @ana_rgc3: The offset for register ANA_RGC3 related to +* sgmiisys syscon +*/ +struct mtk_soc_data { +u32 caps; +u32 ana_rgc3; };struct mtk_eth_priv {@@ -171,7 +175,7 @@ struct mtk_eth_priv {int (*mmd_write)(struct mtk_eth_priv *priv,u8 addr,u8 devad,u16 reg,u16 val); -enum mtk_soc soc; +const struct mtk_soc_data *soc;int gmac_id;int force_mode;int speed;@@ -679,7 +683,7 @@ static int mt7530_setup(struct mtk_eth_priv *priv)u32 val, txdrv;int i; -if (priv->soc !=SOC_MT7621 ) { +if (!MTK_HAS_CAPS (priv->soc->caps,MTK_TRGMII_MT7621_CLK )) {/* Select 250MHz clk for RGMII mode */ mtk_ethsys_rmw (priv,ETHSYS_CLKCFG0_REG ,ETHSYS_TRGMII_CLK_SEL362_5 ,0 );@@ -1108,9 +1112,8 @@ static int mtk_phy_probe(struct udevice *dev)static void mtk_sgmii_init (struct mtk_eth_priv *priv) {/* Set SGMII GEN2 speed(2.5G) */ -clrsetbits_le32 (priv->sgmii_base + ((priv->soc ==SOC_MT7622 ) ? -SGMSYS_GEN2_SPEED :SGMSYS_GEN2_SPEED_V2 ), -SGMSYS_SPEED_2500 ,SGMSYS_SPEED_2500 ); +setbits_le32 (priv->sgmii_base + priv->soc->ana_rgc3, +SGMSYS_SPEED_2500 );/* Disable SGMII AN */ clrsetbits_le32(priv->sgmii_base + SGMSYS_PCS_CONTROL_1,@@ -1182,7 +1185,8 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)mtk_gmac_write (priv,GMAC_PORT_MCR (priv->gmac_id), mcr); } -if (priv->soc ==SOC_MT7623 ) { +if (MTK_HAS_CAPS (priv->soc->caps,MTK_GMAC1_TRGMII ) && + !MTK_HAS_CAPS (priv->soc->caps,MTK_TRGMII_MT7621_CLK )) {/* Lower Tx Driving for TRGMII path */ for (i =0 ; i <NUM_TRGMII_CTRL ; i++) mtk_gmac_write(priv, GMAC_TRGMII_TD_ODT(i),@@ -1431,7 +1435,11 @@ static int mtk_eth_of_to_plat(struct udevice *dev)ofnode subnode;int ret; - priv->soc =dev_get_driver_data (dev); + priv->soc = (const struct mtk_soc_data *)dev_get_driver_data (dev); +if (!priv->soc) { +dev_err (dev,"missing soc compatible data\n" ); +return -EINVAL ; + } pdata->iobase = (phys_addr_t )dev_remap_addr (dev);@@ -1544,11 +1552,27 @@ static int mtk_eth_of_to_plat(struct udevice *dev)return 0 ; } +static const struct mtk_soc_data mt7629_data = { + .ana_rgc3 =0x128 , +}; + +static const struct mtk_soc_data mt7623_data = { + .caps =MT7623_CAPS , +}; + +static const struct mtk_soc_data mt7622_data = { + .ana_rgc3 =0x2028 , +}; + +static const struct mtk_soc_data mt7621_data = { + .caps =MT7621_CAPS , +}; +static const struct udevice_id mtk_eth_ids[] = { - { .compatible ="mediatek,mt7629-eth" , .data =SOC_MT7629 }, - { .compatible ="mediatek,mt7623-eth" , .data =SOC_MT7623 }, - { .compatible ="mediatek,mt7622-eth" , .data =SOC_MT7622 }, - { .compatible ="mediatek,mt7621-eth" , .data =SOC_MT7621 }, + { .compatible ="mediatek,mt7629-eth" , .data = (ulong)&mt7629_data }, + { .compatible ="mediatek,mt7623-eth" , .data = (ulong)&mt7623_data }, + { .compatible ="mediatek,mt7622-eth" , .data = (ulong)&mt7622_data }, + { .compatible ="mediatek,mt7621-eth" , .data = (ulong)&mt7621_data }, {} };drivers/net/mtk_eth.h +24
-2@@ -9,8 +9,31 @@#ifndef _MTK_ETH_H_#define _MTK_ETH_H_ -/* Frame Engine Register Bases */ #include <linux/bitops.h> + +enum mkt_eth_capabilities { +MTK_TRGMII_BIT , +MTK_TRGMII_MT7621_CLK_BIT , + +/* PATH BITS */ +MTK_ETH_PATH_GMAC1_TRGMII_BIT , +}; + +#define MTK_TRGMII BIT(MTK_TRGMII_BIT) +#define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT) + +/* Supported path present on SoCs */ +#define MTK_ETH_PATH_GMAC1_TRGMII BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT) + +#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII) + +#define MTK_HAS_CAPS (caps, _x) (((caps) & (_x)) == (_x)) + +#define MT7621_CAPS (MTK_GMAC1_TRGMII | MTK_TRGMII_MT7621_CLK) + +#define MT7623_CAPS (MTK_GMAC1_TRGMII) + +/* Frame Engine Register Bases */ #define PDMA_BASE 0x0800#define GDMA1_BASE 0x0500#define GDMA2_BASE 0x1500 --
Quoted 2 lines
2.17.1
Re: [PATCH v3 07/32] net: mediatek: stop using bitfileds for DMA descriptors
In reply to Weijie GaoQuoted 323 lines · Weijie Gao
This patch is a preparation for adding a new version of PDMA of which the DMA descriptor fields has changed. Using bitfields will result in a complex modification. Convert bitfields to u32 units can solve this problem easily.
Reviewed-by Simon Glass <[email protected]>Tested-by Daniel Golle <[email protected]>Signed-off-by Weijie Gao <[email protected]>---
v3 changes: none
v2 changes:
Fix typo in commit message--- drivers/net/mtk_eth.c | 144 ++++++++++++++---------------------------- drivers/net/mtk_eth.h | 32 ++++++++++ 2 files changed, 80 insertions(+), 96 deletions(-)drivers/net/mtk_eth.c +48
-96@@ -65,77 +65,6 @@ (DP_DISCARD << MC_DP_S) | \ (DP_DISCARD << UN_DP_S)) -struct pdma_rxd_info1 { -u32 PDP0; -}; - -struct pdma_rxd_info2 { -u32 PLEN1 :14 ; -u32 LS1 :1 ; -u32 UN_USED :1 ; -u32 PLEN0 :14 ; -u32 LS0 :1 ; -u32 DDONE :1 ; -}; - -struct pdma_rxd_info3 { -u32 PDP1; -}; - -struct pdma_rxd_info4 { -u32 FOE_ENTRY :14 ; -u32 CRSN :5 ; -u32 SP :3 ; -u32 L4F :1 ; -u32 L4VLD :1 ; -u32 TACK :1 ; -u32 IP4F :1 ; -u32 IP4 :1 ; -u32 IP6 :1 ; -u32 UN_USED :4 ; -}; - -struct pdma_rxdesc { -struct pdma_rxd_info1 rxd_info1; -struct pdma_rxd_info2 rxd_info2; -struct pdma_rxd_info3 rxd_info3; -struct pdma_rxd_info4 rxd_info4; -}; - -struct pdma_txd_info1 { -u32 SDP0; -}; - -struct pdma_txd_info2 { -u32 SDL1 :14 ; -u32 LS1 :1 ; -u32 BURST :1 ; -u32 SDL0 :14 ; -u32 LS0 :1 ; -u32 DDONE :1 ; -}; - -struct pdma_txd_info3 { -u32 SDP1; -}; - -struct pdma_txd_info4 { -u32 VLAN_TAG :16 ; -u32 INS :1 ; -u32 RESV :2 ; -u32 UDF :6 ; -u32 FPORT :3 ; -u32 TSO :1 ; -u32 TUI_CO :3 ; -}; - -struct pdma_txdesc { -struct pdma_txd_info1 txd_info1; -struct pdma_txd_info2 txd_info2; -struct pdma_txd_info3 txd_info3; -struct pdma_txd_info4 txd_info4; -}; - enum mtk_switch { SW_NONE, SW_MT7530,@@ -151,13 +80,15 @@ enum mtk_switch {struct mtk_soc_data {u32 caps;u32 ana_rgc3; +u32 txd_size; +u32 rxd_size; };struct mtk_eth_priv {char pkt_pool[TOTAL_PKT_BUF_SIZE ]__aligned(ARCH_DMA_MINALIGN) ; -struct pdma_txdesc *tx_ring_noc; -struct pdma_rxdesc *rx_ring_noc; +void *tx_ring_noc; +void *rx_ring_noc;int rx_dma_owner_idx0;int tx_cpu_owner_idx0;@@ -1202,14 +1133,16 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)static void mtk_eth_fifo_init (struct mtk_eth_priv *priv) {char *pkt_base = priv->pkt_pool; +struct mtk_tx_dma *txd; +struct mtk_rx_dma *rxd;int i;mtk_pdma_rmw (priv,PDMA_GLO_CFG_REG ,0xffff0000 ,0 );udelay (500 ); -memset (priv->tx_ring_noc,0 ,NUM_TX_DESC *sizeof (struct pdma_txdesc )); -memset (priv->rx_ring_noc,0 ,NUM_RX_DESC *sizeof (struct pdma_rxdesc )); -memset (priv->pkt_pool,0 ,TOTAL_PKT_BUF_SIZE ); +memset (priv->tx_ring_noc,0 ,NUM_TX_DESC * priv->soc->txd_size); +memset (priv->rx_ring_noc,0 ,NUM_RX_DESC * priv->soc->rxd_size); +memset (priv->pkt_pool,0xff ,TOTAL_PKT_BUF_SIZE );flush_dcache_range ((ulong )pkt_base, (ulong)(pkt_base +TOTAL_PKT_BUF_SIZE ));@@ -1218,17 +1151,21 @@ static void mtk_eth_fifo_init(struct mtk_eth_priv *priv) priv->tx_cpu_owner_idx0 =0 ;for (i =0 ; i <NUM_TX_DESC ; i++) { - priv->tx_ring_noc[i].txd_info2.LS0 =1 ; - priv->tx_ring_noc[i].txd_info2.DDONE =1 ; - priv->tx_ring_noc[i].txd_info4.FPORT = priv->gmac_id +1 ; + txd = priv->tx_ring_noc + i * priv->soc->txd_size; + + txd->txd1 =virt_to_phys (pkt_base); + txd->txd2 =PDMA_TXD2_DDONE |PDMA_TXD2_LS0 ; + txd->txd4 =PDMA_TXD4_FPORT_SET (priv->gmac_id +1 ); - priv->tx_ring_noc[i].txd_info1.SDP0 =virt_to_phys (pkt_base); pkt_base +=PKTSIZE_ALIGN ; }for (i =0 ; i <NUM_RX_DESC ; i++) { - priv->rx_ring_noc[i].rxd_info2.PLEN0 =PKTSIZE_ALIGN ; - priv->rx_ring_noc[i].rxd_info1.PDP0 =virt_to_phys (pkt_base); + rxd = priv->rx_ring_noc + i * priv->soc->rxd_size; + + rxd->rxd1 =virt_to_phys (pkt_base); + rxd->rxd2 =PDMA_RXD2_PLEN0_SET (PKTSIZE_ALIGN ); + pkt_base +=PKTSIZE_ALIGN ; }@@ -1315,20 +1252,22 @@ static int mtk_eth_send(struct udevice *dev, void *packet, int length) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->tx_cpu_owner_idx0; +struct mtk_tx_dma *txd;void *pkt_base; -if (!priv->tx_ring_noc[idx].txd_info2.DDONE) { + txd = priv->tx_ring_noc + idx * priv->soc->txd_size; + +if (!(txd->txd2 &PDMA_TXD2_DDONE )) {debug ("mtk-eth: TX DMA descriptor ring is full\n" );return -EPERM ; } - pkt_base = (void *)phys_to_virt (priv->tx_ring_noc[idx].txd_info1.SDP0); + pkt_base = (void *)phys_to_virt (txd->txd1);memcpy (pkt_base, packet, length);flush_dcache_range ((ulong )pkt_base, (ulong )pkt_base +roundup (length,ARCH_DMA_MINALIGN )); - priv->tx_ring_noc[idx].txd_info2.SDL0 = length; - priv->tx_ring_noc[idx].txd_info2.DDONE =0 ; + txd->txd2 =PDMA_TXD2_LS0 |PDMA_TXD2_SDL0_SET (length); priv->tx_cpu_owner_idx0 = (priv->tx_cpu_owner_idx0 +1 ) %NUM_TX_DESC ;mtk_pdma_write (priv,TX_CTX_IDX_REG (0 ), priv->tx_cpu_owner_idx0);@@ -1340,16 +1279,20 @@ static int mtk_eth_recv(struct udevice *dev, int flags, uchar **packetp) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->rx_dma_owner_idx0; +struct mtk_rx_dma *rxd;uchar *pkt_base;u32 length; -if (!priv->rx_ring_noc[idx].rxd_info2.DDONE) { + rxd = priv->rx_ring_noc + idx * priv->soc->rxd_size; + +if (!(rxd->rxd2 &PDMA_RXD2_DDONE )) {debug ("mtk-eth: RX DMA descriptor ring is empty\n" );return -EAGAIN ; } - length = priv->rx_ring_noc[idx].rxd_info2.PLEN0; - pkt_base = (void *)phys_to_virt (priv->rx_ring_noc[idx].rxd_info1.PDP0); + length =PDMA_RXD2_PLEN0_GET (rxd->rxd2); + + pkt_base = (void *)phys_to_virt (rxd->rxd1);invalidate_dcache_range ((ulong )pkt_base, (ulong )pkt_base +roundup (length,ARCH_DMA_MINALIGN ));@@ -1363,10 +1306,11 @@ static int mtk_eth_free_pkt(struct udevice *dev, uchar *packet, int length) {struct mtk_eth_priv *priv =dev_get_priv (dev);u32 idx = priv->rx_dma_owner_idx0; +struct mtk_rx_dma *rxd; + + rxd = priv->rx_ring_noc + idx * priv->soc->rxd_size; - priv->rx_ring_noc[idx].rxd_info2.DDONE =0 ; - priv->rx_ring_noc[idx].rxd_info2.LS0 =0 ; - priv->rx_ring_noc[idx].rxd_info2.PLEN0 =PKTSIZE_ALIGN ; + rxd->rxd2 =PDMA_RXD2_PLEN0_SET (PKTSIZE_ALIGN );mtk_pdma_write (priv,RX_CRX_IDX_REG (0 ), idx); priv->rx_dma_owner_idx0 = (priv->rx_dma_owner_idx0 +1 ) %NUM_RX_DESC ;@@ -1393,11 +1337,11 @@ static int mtk_eth_probe(struct udevice *dev)return ret;/* Prepare for tx/rx rings */ - priv->tx_ring_noc = (struct pdma_txdesc *) -noncached_alloc (sizeof (struct pdma_txdesc ) *NUM_TX_DESC , + priv->tx_ring_noc = (void *) +noncached_alloc (priv->soc->txd_size *NUM_TX_DESC ,ARCH_DMA_MINALIGN ); - priv->rx_ring_noc = (struct pdma_rxdesc *) -noncached_alloc (sizeof (struct pdma_rxdesc ) *NUM_RX_DESC , + priv->rx_ring_noc = (void *) +noncached_alloc (priv->soc->rxd_size *NUM_RX_DESC ,ARCH_DMA_MINALIGN );/* Set MAC mode */ @@ -1554,18 +1498,26 @@ static int mtk_eth_of_to_plat(struct udevice *dev)static const struct mtk_soc_data mt7629_data = { .ana_rgc3 =0x128 , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7623_data = { .caps =MT7623_CAPS , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7622_data = { .ana_rgc3 =0x2028 , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct mtk_soc_data mt7621_data = { .caps =MT7621_CAPS , + .txd_size =sizeof (struct mtk_tx_dma ), + .rxd_size =sizeof (struct mtk_rx_dma ), };static const struct udevice_id mtk_eth_ids[] = {drivers/net/mtk_eth.h +32
-1@@ -10,6 +10,7 @@#define _MTK_ETH_H_#include <linux/bitops.h> +#include <linux/bitfield.h> enum mkt_eth_capabilities {MTK_TRGMII_BIT ,@@ -435,4 +436,35 @@ enum mkt_eth_capabilities {#define PHY_POWER_SAVING_M 0x300#define PHY_POWER_SAVING_TX 0x0 +/* PDMA descriptors */ +struct mtk_rx_dma { +unsigned int rxd1; +unsigned int rxd2; +unsigned int rxd3; +unsigned int rxd4; +} __packed__aligned(4) ; + +struct mtk_tx_dma { +unsigned int txd1; +unsigned int txd2; +unsigned int txd3; +unsigned int txd4; +} __packed__aligned(4) ; + +/* PDMA TXD fields */ +#define PDMA_TXD2_DDONE BIT(31) +#define PDMA_TXD2_LS0 BIT(30) +#define PDMA_TXD2_SDL0_M GENMASK(29, 16) +#define PDMA_TXD2_SDL0_SET (_v) FIELD_PREP(PDMA_TXD2_SDL0_M, (_v)) + +#define PDMA_TXD4_FPORT_M GENMASK(27, 25) +#define PDMA_TXD4_FPORT_SET (_v) FIELD_PREP(PDMA_TXD4_FPORT_M, (_v)) + +/* PDMA RXD fields */ +#define PDMA_RXD2_DDONE BIT(31) +#define PDMA_RXD2_LS0 BIT(30) +#define PDMA_RXD2_PLEN0_M GENMASK(29, 16) +#define PDMA_RXD2_PLEN0_GET (_v) FIELD_GET(PDMA_RXD2_PLEN0_M, (_v)) +#define PDMA_RXD2_PLEN0_SET (_v) FIELD_PREP(PDMA_RXD2_PLEN0_M, (_v)) +#endif /* _MTK_ETH_H_ */ --
Quoted 2 lines
2.17.1
Quoted 8 lines · Weijie Gao
This patch series add support for MediaTek MT7981/MT7986 SoCs with their reference boards and related drivers.
This patch series add basic boot support on eMMC/SD/SPI-NOR/SPI-NAND for these boards. The clock, pinctrl drivers and the SoC initializaton code are also included.
[...]
Applied to u-boot/next, thanks!
Signature · 1 line
Tom