Add support for MediaTek MT7981/MT7986 SoCs
Subsystems (14)
cover Add support for MediaTek MT7981/MT7986 SoCs
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
Weijie Gao (31):
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
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 | 5 + 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 | 133 +++ arch/arm/dts/mt7981-sd-rfb.dts | 139 +++ arch/arm/dts/mt7981-spim-nand-rfb.dts | 138 +++ arch/arm/dts/mt7981-spim-nor-rfb.dts | 133 +++ arch/arm/dts/mt7981.dtsi | 288 +++++ arch/arm/dts/mt7986-u-boot.dtsi | 33 + arch/arm/dts/mt7986.dtsi | 341 ++++++ arch/arm/dts/mt7986a-rfb.dts | 218 ++++ arch/arm/dts/mt7986a-sd-rfb.dts | 177 +++ arch/arm/dts/mt7986b-rfb.dts | 204 ++++ arch/arm/dts/mt7986b-sd-rfb.dts | 173 +++ arch/arm/mach-mediatek/Kconfig | 21 + arch/arm/mach-mediatek/Makefile | 2 + arch/arm/mach-mediatek/mt7981/Makefile | 4 + arch/arm/mach-mediatek/mt7981/init.c | 52 + arch/arm/mach-mediatek/mt7981/lowlevel_init.S | 30 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 53 + arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 30 + 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 | 65 + configs/mt7981_sd_rfb_defconfig | 64 + configs/mt7981_spim_nand_rfb_defconfig | 59 + configs/mt7981_spim_nor_rfb_defconfig | 70 ++ configs/mt7986_rfb_defconfig | 66 ++ configs/mt7986a_emmc_rfb_defconfig | 64 + configs/mt7986a_sd_rfb_defconfig | 64 + configs/mt7986b_emmc_rfb_defconfig | 64 + configs/mt7986b_sd_rfb_defconfig | 64 + drivers/clk/mediatek/Makefile | 2 + drivers/clk/mediatek/clk-mt7981.c | 682 +++++++++++ drivers/clk/mediatek/clk-mt7986.c | 671 +++++++++++ drivers/clk/mediatek/clk-mtk.c | 157 ++- drivers/clk/mediatek/clk-mtk.h | 10 +- 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 | 252 ++-- 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 | 72 +- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/mtk_spim.c | 705 +++++++++++ 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 | 376 ++---- tools/mtk_image.h | 25 - tools/mtk_nand_headers.c | 668 +++++++++++ tools/mtk_nand_headers.h | 156 +++ 72 files changed, 9841 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-spim-nand-rfb.dts create mode 100644 arch/arm/dts/mt7981-spim-nor-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-rfb.dts create mode 100644 arch/arm/dts/mt7986a-sd-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/mt7981_spim_nand_rfb_defconfig create mode 100644 configs/mt7981_spim_nor_rfb_defconfig create mode 100644 configs/mt7986_rfb_defconfig create mode 100644 configs/mt7986a_emmc_rfb_defconfig create mode 100644 configs/mt7986a_sd_rfb_defconfig create mode 100644 configs/mt7986b_emmc_rfb_defconfig create mode 100644 configs/mt7986b_sd_rfb_defconfig create mode 100644 drivers/clk/mediatek/clk-mt7981.c create mode 100644 drivers/clk/mediatek/clk-mt7986.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 1/31 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.
--- arch/arm/dts/mt7986-u-boot.dtsi | 33 ++ arch/arm/dts/mt7986.dtsi | 341 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 11 + arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 53 +++ arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 30 ++ 7 files changed, 473 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
(quoted diff) +0 -0
b/arch/arm/dts/mt7986-u-boot.dtsi
new file mode 100644
index 0000000000..95671f8afa
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 +341 -0
341 lines not on this page · raw message
arch/arm/mach-mediatek/Kconfig +11 -0
@@ -40,6 +40,14 @@ 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 + 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 +92,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 +108,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 +123,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
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/Makefile
index 0f5b0c16d2..fe5c3a837c 100644
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/
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/mt7986/Makefile
new file mode 100644
index 0000000000..007eb4a367
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
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/mt7986/init.c
new file mode 100644
index 0000000000..4884cbdc67
arch/arm/mach-mediatek/mt7986/init.c new file +53 -0
53 lines not on this page · raw message
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/mt7986/lowlevel_init.S
new file mode 100644
index 0000000000..244d2c1385
arch/arm/mach-mediatek/mt7986/lowlevel_init.S new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 + SMC #0 + ret
Signature · 1 line
2.17.1
Re: [PATCH 01/31] arm: mediatek: add support for MediaTek MT7986 SoC
Hi Weijie,
happy to see this series posted!
Trying to apply it unfortunately fails due to errornous line-breaks, supposedly inserted by your MUA, see below.
I didn't go beyond the first patch and it'd be nice if you report the whole series without the wrong line-breaks.
Cheers
Daniel
Quoted 21 lines · Weijie Gao
This patch adds basic support for MediaTek MT7986 SoC. This include the file that will initialize the SoC after boot and its device tree.
Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7986-u-boot.dtsi | 33 ++ arch/arm/dts/mt7986.dtsi | 341 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 11 + arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 53 +++ arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 30 ++ 7 files changed, 473 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
Review
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/dts/mt7986-u-boot.dtsi
The above two lines should be a single line.
Quoted 421 lines
new file mode 100644
index 0000000000..95671f8afaarch/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 +341
-0@@ -0,0 +1,341 @@ +// 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/phy/phy.h> +#include <dt-bindings/clock/mt7986-clk.h> +#include <dt-bindings/reset/mt7629-reset.h> +#include <dt-bindings/pinctrl/mt65xx.h> + +/ { + compatible = "mediatek,mt7986"; + interrupt-parent = <&gic>; + #address-cells = <1>; + #size-cells = <1>; + + config { + u-boot,mmc-env-partition = "u-boot-env"; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x0>; + }; + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu2: cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu3: cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + }; + + dummy_clk: dummy12m { + compatible = "fixed-clock"; + clock-frequency = <12000000>; + #clock-cells = <0>; + /* must need this line, or uart uanable to get dummy_clk */ + u-boot,dm-pre-reloc; + }; + + 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 = <&infracfg CK_INFRA_CK_F26M>; + 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,mt7986-fixed-plls"; + reg = <0x1001E000 0x1000>; + #clock-cells = <1>; + }; + + topckgen: topckgen@1001B000 { + compatible = "mediatek,mt7986-topckgen"; + reg = <0x1001B000 0x1000>; + clock-parent = <&fixed_plls>; + #clock-cells = <1>; + }; + + infracfg_ao: infracfg_ao@10001000 { + compatible = "mediatek,mt7986-infracfg_ao"; + reg = <0x10001000 0x68>; + clock-parent = <&infracfg>; + #clock-cells = <1>; + }; + + infracfg: infracfg@10001040 { + compatible = "mediatek,mt7986-infracfg"; + reg = <0x10001000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + }; + + pinctrl: pinctrl@1001f000 { + compatible = "mediatek,mt7986-pinctrl"; + reg = <0x1001f000 0x1000>, + <0x11c30000 0x1000>, + <0x11c40000 0x1000>, + <0x11e20000 0x1000>, + <0x11e30000 0x1000>, + <0x11f00000 0x1000>, + <0x11f10000 0x1000>, + <0x1000b000 0x1000>; + reg-names = "gpio_base", "iocfg_rt_base", "iocfg_rb_base", + "iocfg_lt_base", "iocfg_lb_base", "iocfg_tr_base", + "iocfg_tl_base", "eint"; + gpio: gpio-controller { + gpio-controller; + #gpio-cells = <2>; + }; + }; + + pwm: pwm@10048000 { + compatible = "mediatek,mt7986-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>; + assigned-clocks = <&topckgen CK_TOP_PWM_SEL>, + <&infracfg CK_INFRA_PWM_BSEL>, + <&infracfg CK_INFRA_PWM1_SEL>, + <&infracfg CK_INFRA_PWM2_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_M_D4>, + <&infracfg CK_INFRA_PWM>, + <&infracfg CK_INFRA_PWM>, + <&infracfg CK_INFRA_PWM>; + clock-names = "top", "main", "pwm1", "pwm2"; + status = "disabled"; + u-boot,dm-pre-reloc; + }; + + 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 = <&infracfg CK_INFRA_UART1_SEL>; + assigned-clock-parents = <&infracfg CK_INFRA_CK_F26M>; + 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 = <&infracfg CK_INFRA_UART2_SEL>; + assigned-clock-parents = <&infracfg CK_INFRA_CK_F26M>; + 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,mt7986-ethsys", "syscon"; + reg = <0x15000000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + + eth: ethernet@15100000 { + compatible = "mediatek,mt7986-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>; + #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"; + }; + + mmc0: mmc@11230000 { + compatible = "mediatek,mt7986-mmc"; + reg = <0x11230000 0x1000>, + <0x11C20000 0x1000>; + interrupts = <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&topckgen CK_TOP_EMMC_416M>, + <&topckgen CK_TOP_EMMC_250M>, + <&infracfg_ao CK_INFRA_MSDC_CK>; + assigned-clocks = <&topckgen CK_TOP_EMMC_416M_SEL>, + <&topckgen CK_TOP_EMMC_250M_SEL>; + assigned-clock-parents = <&topckgen CK_TOP_CB_M_416M>, + <&topckgen CK_TOP_NET1_D5_D2>; + clock-names = "source", "hclk", "source_cg"; + status = "disabled"; + }; + + xhci: xhci@11200000 { + compatible = "mediatek,mt7986-xhci", + "mediatek,mtk-xhci"; + reg = <0x11200000 0x2e00>, + <0x11203e00 0x0100>; + reg-names = "mac", "ippc"; + interrupts = <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>; + phys = <&u2port0 PHY_TYPE_USB2>, + <&u3port0 PHY_TYPE_USB3>, + <&u2port1 PHY_TYPE_USB2>; + clocks = <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>; + clock-names = "sys_ck", + "xhci_ck", + "ref_ck", + "mcu_ck", + "dma_ck"; + tpl-support; + status = "okay"; + }; + + usbtphy: usb-phy@11e10000 { + compatible = "mediatek,mt7986", + "mediatek,generic-tphy-v2"; + #address-cells = <1>; + #size-cells = <1>; + status = "okay"; + + u2port0: usb-phy@11e10000 { + reg = <0x11e10000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u3port0: usb-phy@11e10700 { + reg = <0x11e10700 0x900>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u2port1: usb-phy@11e11000 { + reg = <0x11e11000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + }; +};arch/arm/mach-mediatek/Kconfig +10
-0@@ -40,6 +40,14 @@ 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 + 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 +92,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 +108,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
arch/arm/mach-mediatek/Kconfig config MTK_BROM_HEADER_INFO · line 125
Quoted 3 lines
arch/arm/mach-mediatek/Kconfig +0
-0@@ -113,6 +123,7 @@ config MTK_BROM_HEADER_INFO string default "media=nor" if TARGET_MT8518 || TARGET_MT8512 || TARGET_MT7629 || TARGET_MT7622
Same here.
Review
Quoted 7 lines
arch/arm/mach-mediatek/Kconfig +1
-0default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183 + default "media=snand;nandinfo=2k+64" if TARGET_MT7986 default "lk=1" if TARGET_MT7623endif
(quoted diff) +0
-0b/arch/arm/mach-mediatek/Makefile
And here.
Review
Quoted 13 lines
index
0f5b0c16d2..fe5c3a837c100644arch/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/(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/Makefile
And here.
Review
Quoted 11 lines
new file mode 100644
index 0000000000..007eb4a367arch/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(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/init.c
And here again.
Quoted 59 lines
new file mode 100644
index 0000000000..4884cbdc67arch/arm/mach-mediatek/mt7986/init.c new file +53
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h> +#include <asm/armv8/mmu.h> +#include <init.h> +#include <asm/system.h> +#include <asm/global_data.h> +#include <linux/sizes.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void ) +{ +printf ("CPU: MediaTek MT7986\n" ); +return 0 ; +} + +int dram_init (void ) +{ + gd->ram_size =get_ram_size ((void *)CONFIG_SYS_SDRAM_BASE ,SZ_2G ); + +return 0 ; +} + +void reset_cpu (ulong addr) +{ +psci_system_reset (); +} + +static struct mm_region mt7986_mem_map[] = { + { +/* DDR */ + .virt =0x40000000UL , + .phys =0x40000000UL , + .size =0x80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) |PTE_BLOCK_OUTER_SHARE , + }, { + .virt =0x00000000UL , + .phys =0x00000000UL , + .size =0x40000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { +0 , + } +}; + +struct mm_region *mem_map = mt7986_mem_map;
Review
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/lowlevel_init.S
And here.
Quoted 38 lines
new file mode 100644
index 0000000000..244d2c1385arch/arm/mach-mediatek/mt7986/lowlevel_init.S new file +30
-0@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 + SMC #0 + retSignature · 1 line
2.17.1
Re: [PATCH 01/31] arm: mediatek: add support for MediaTek MT7986 SoC
Hi Daniel,
Thanks for the reminder.
I found more errornous line-breaks in other patches... I'll find a way to fix that.
Best Regards,
Weijie
Quoted 636 lines · Daniel Golle
Hi Weijie,
happy to see this series posted!
Trying to apply it unfortunately fails due to errornous line-breaks, supposedly inserted by your MUA, see below.I didn't go beyond the first patch and it'd be nice if you report the whole series without the wrong line-breaks.
Cheers
Daniel
Quoted 23 lines · Weijie Gao
This patch adds basic support for MediaTek MT7986 SoC. This include the file that will initialize the SoC after boot and its
device tree.Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7986-u-boot.dtsi | 33 ++ arch/arm/dts/mt7986.dtsi | 341 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 11 + arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 53 +++ arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 30 ++ 7 files changed, 473 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.SReview
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/dts/mt7986-u-boot.dtsiThe above two lines should be a single line.
Quoted 444 lines
new file mode 100644
index 0000000000..95671f8afaarch/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 +53
-0@@ -0,0 +1,341 @@ +// 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/phy/phy.h> +#include <dt-bindings/clock/mt7986-clk.h> +#include <dt-bindings/reset/mt7629-reset.h> +#include <dt-bindings/pinctrl/mt65xx.h> + +/ { + compatible = "mediatek,mt7986"; + interrupt-parent = <&gic>; + #address-cells = <1>; + #size-cells = <1>; + + config { + u-boot,mmc-env-partition = "u-boot-env"; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x0>; + }; + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu2: cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu3: cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + }; + + dummy_clk: dummy12m { + compatible = "fixed-clock"; + clock-frequency = <12000000>; + #clock-cells = <0>; + /* must need this line, or uart uanable to get
dummy_clk*/arch/arm/dts/mt7986.dtsi new file +80
-0+ u-boot,dm-pre-reloc; + }; + + 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 = <&infracfg CK_INFRA_CK_F26M>; + 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,mt7986-fixed-plls"; + reg = <0x1001E000 0x1000>; + #clock-cells = <1>; + }; + + topckgen: topckgen@1001B000 { + compatible = "mediatek,mt7986-topckgen"; + reg = <0x1001B000 0x1000>; + clock-parent = <&fixed_plls>; + #clock-cells = <1>; + }; + + infracfg_ao: infracfg_ao@10001000 { + compatible = "mediatek,mt7986-infracfg_ao"; + reg = <0x10001000 0x68>; + clock-parent = <&infracfg>; + #clock-cells = <1>; + }; + + infracfg: infracfg@10001040 { + compatible = "mediatek,mt7986-infracfg"; + reg = <0x10001000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + }; + + pinctrl: pinctrl@1001f000 { + compatible = "mediatek,mt7986-pinctrl"; + reg = <0x1001f000 0x1000>, + <0x11c30000 0x1000>, + <0x11c40000 0x1000>, + <0x11e20000 0x1000>, + <0x11e30000 0x1000>, + <0x11f00000 0x1000>, + <0x11f10000 0x1000>, + <0x1000b000 0x1000>; + reg-names = "gpio_base", "iocfg_rt_base","
iocfg_rb_base",arch/arm/dts/mt7986.dtsi new file +1
-0+ "iocfg_lt_base", "iocfg_lb_base","
iocfg_tr_base",arch/arm/dts/mt7986.dtsi new file +22
-0+ "iocfg_tl_base", "eint"; + gpio: gpio-controller { + gpio-controller; + #gpio-cells = <2>; + }; + }; + + pwm: pwm@10048000 { + compatible = "mediatek,mt7986-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>; + assigned-clocks = <&topckgen CK_TOP_PWM_SEL>, + <&infracfg CK_INFRA_PWM_BSEL>, + <&infracfg CK_INFRA_PWM1_SEL>, + <&infracfg CK_INFRA_PWM2_SEL>; + assigned-clock-parents = <&topckgen
CK_TOP_CB_M_D4>,arch/arm/dts/mt7986.dtsi new file +15
-0+ <&infracfg CK_INFRA_PWM>, + <&infracfg CK_INFRA_PWM>, + <&infracfg CK_INFRA_PWM>; + clock-names = "top", "main", "pwm1", "pwm2"; + status = "disabled"; + u-boot,dm-pre-reloc; + }; + + 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>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_CKSQ_40M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_UART>;arch/arm/dts/mt7986.dtsi new file +12
-0+ 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 = <&infracfg CK_INFRA_UART1_SEL>; + assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +11
-0+ 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 = <&infracfg CK_INFRA_UART2_SEL>; + assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +16
-0+ 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>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_CB_M_D8>;arch/arm/dts/mt7986.dtsi new file +43
-0+ status = "disabled"; + }; + + ethsys: syscon@15000000 { + compatible = "mediatek,mt7986-ethsys", "syscon"; + reg = <0x15000000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + + eth: ethernet@15100000 { + compatible = "mediatek,mt7986-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>; + #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>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_INFRA_ISPI0>;arch/arm/dts/mt7986.dtsi new file +21
-0+ 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"; + }; + + mmc0: mmc@11230000 { + compatible = "mediatek,mt7986-mmc"; + reg = <0x11230000 0x1000>, + <0x11C20000 0x1000>; + interrupts = <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&topckgen CK_TOP_EMMC_416M>, + <&topckgen CK_TOP_EMMC_250M>, + <&infracfg_ao CK_INFRA_MSDC_CK>; + assigned-clocks = <&topckgen
CK_TOP_EMMC_416M_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_EMMC_250M_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_M_416M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_NET1_D5_D2>;arch/arm/dts/mt7986.dtsi new file +60
-0+ clock-names = "source", "hclk", "source_cg"; + status = "disabled"; + }; + + xhci: xhci@11200000 { + compatible = "mediatek,mt7986-xhci", + "mediatek,mtk-xhci"; + reg = <0x11200000 0x2e00>, + <0x11203e00 0x0100>; + reg-names = "mac", "ippc"; + interrupts = <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>; + phys = <&u2port0 PHY_TYPE_USB2>, + <&u3port0 PHY_TYPE_USB3>, + <&u2port1 PHY_TYPE_USB2>; + clocks = <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>; + clock-names = "sys_ck", + "xhci_ck", + "ref_ck", + "mcu_ck", + "dma_ck"; + tpl-support; + status = "okay"; + }; + + usbtphy: usb-phy@11e10000 { + compatible = "mediatek,mt7986", + "mediatek,generic-tphy-v2"; + #address-cells = <1>; + #size-cells = <1>; + status = "okay"; + + u2port0: usb-phy@11e10000 { + reg = <0x11e10000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u3port0: usb-phy@11e10700 { + reg = <0x11e10700 0x900>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u2port1: usb-phy@11e11000 { + reg = <0x11e11000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + }; +};arch/arm/mach- renamed from arch/arm/mach-mediatek/Kconfig +0
-0mediatek/Kconfig
indexf79a5c62cd..e059a013db100644arch/arm/mach-mediatek/Kconfig +5
-0@@ -40,6 +40,14 @@ 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 + help + The MediaTek MT7986 is a ARM64-based SoC with a quad-core Cortex-A53.
arch/arm/mach-mediatek/Kconfig +1
-0+ including UART, SPI, SPI flash, USB3.0, MMC, NAND, SNFI,PWM, PCIe,
arch/arm/mach-mediatek/Kconfig +4
-0+ Gigabit Ethernet, I2C, built-in 4x4 Wi-Fi, and PCIe. + config TARGET_MT8183 bool "MediaTek MT8183 SoC" select ARM64@@ -84,6 +92,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 +108,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 +123,7 @@ config MTK_BROM_HEADER_INFO string default "media=nor" if TARGET_MT8518 || TARGET_MT8512 ||Quoted 2 lines
TARGET_MT7629||
TARGET_MT7622Same here.
Review
Quoted 8 lines
default "media=emmc" if
TARGET_MT8516||TARGET_MT8365||TARGET_MT8183arch/arm/mach-mediatek/Kconfig +1
-0+ default "media=snand;nandinfo=2k+64" if TARGET_MT7986 default "lk=1" if TARGET_MT7623 endif(quoted diff) +0
-0b/arch/arm/mach-mediatek/MakefileAnd here.
Review
Quoted 13 lines
index
0f5b0c16d2..fe5c3a837c100644arch/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/(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/MakefileAnd here.
Review
Quoted 11 lines
new file mode 100644
index 0000000000..007eb4a367arch/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(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/init.cAnd here again.
Quoted 61 lines
new file mode 100644
index 0000000000..4884cbdc67arch/arm/mach-mediatek/mt7986/init.c new file +24
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h> +#include <asm/armv8/mmu.h> +#include <init.h> +#include <asm/system.h> +#include <asm/global_data.h> +#include <linux/sizes.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void ) +{ +printf ("CPU: MediaTek MT7986\n" ); +return 0 ; +} + +int dram_init (void ) +{ + gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
SZ_2G);arch/arm/mach-mediatek/mt7986/init.c new file +16
-0+ +return 0 ; +} + +void reset_cpu (ulong addr) +{ +psci_system_reset (); +} + +static struct mm_region mt7986_mem_map[] = { + { +/* DDR */ + .virt =0x40000000UL , + .phys =0x40000000UL , + .size =0x80000000UL , + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
PTE_BLOCK_OUTER_SHARE,arch/arm/mach-mediatek/mt7986/init.c new file +13
-0+ }, { + .virt = 0x00000000UL, + .phys = 0x00000000UL, + .size = 0x40000000UL, + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | + PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + 0, + } +}; + +struct mm_region *mem_map = mt7986_mem_map;Review
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/lowlevel_init.SAnd here.
Quoted 38 lines
new file mode 100644
index 0000000000..244d2c1385arch/arm/mach-mediatek/mt7986/lowlevel_init.S new file +30
-0@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 + SMC #0 + retSignature · 1 line
2.17.1
Re: [PATCH 01/31] arm: mediatek: add support for MediaTek MT7986 SoC
Hi Daniel,
It turns out that this was caused by a setting change of company's mail gateway.
I'll send v2 later.
Best Regards,
Weijie
Quoted 659 lines · Weijie Gao
Hi Daniel,
Thanks for the reminder.
I found more errornous line-breaks in other patches... I'll find a way to fix that.Best Regards,
WeijieQuoted 649 lines · Daniel Golle
Hi Weijie,
happy to see this series posted!
Trying to apply it unfortunately fails due to errornous line- breaks,
supposedly inserted by your MUA, see below.I didn't go beyond the first patch and it'd be nice if you report the
whole series without the wrong line-breaks.Cheers
Daniel
Quoted 23 lines · Weijie Gao
This patch adds basic support for MediaTek MT7986 SoC. This include the file that will initialize the SoC after boot and its
device tree.Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7986-u-boot.dtsi | 33 ++ arch/arm/dts/mt7986.dtsi | 341 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 11 + arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 53 +++ arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 30 ++ 7 files changed, 473 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.SReview
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/dts/mt7986-u-boot.dtsiThe above two lines should be a single line.
Quoted 453 lines
new file mode 100644
index 0000000000..95671f8afaarch/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 +53
-0@@ -0,0 +1,341 @@ +// 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/phy/phy.h> +#include <dt-bindings/clock/mt7986-clk.h> +#include <dt-bindings/reset/mt7629-reset.h> +#include <dt-bindings/pinctrl/mt65xx.h> + +/ { + compatible = "mediatek,mt7986"; + interrupt-parent = <&gic>; + #address-cells = <1>; + #size-cells = <1>; + + config { + u-boot,mmc-env-partition = "u-boot-env"; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x0>; + }; + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu2: cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu3: cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + }; + + dummy_clk: dummy12m { + compatible = "fixed-clock"; + clock-frequency = <12000000>; + #clock-cells = <0>; + /* must need this line, or uart uanable to get
dummy_clk*/arch/arm/dts/mt7986.dtsi new file +80
-0+ u-boot,dm-pre-reloc; + }; + + 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 = <&infracfg CK_INFRA_CK_F26M>; + 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,mt7986-fixed-plls"; + reg = <0x1001E000 0x1000>; + #clock-cells = <1>; + }; + + topckgen: topckgen@1001B000 { + compatible = "mediatek,mt7986-topckgen"; + reg = <0x1001B000 0x1000>; + clock-parent = <&fixed_plls>; + #clock-cells = <1>; + }; + + infracfg_ao: infracfg_ao@10001000 { + compatible = "mediatek,mt7986-infracfg_ao"; + reg = <0x10001000 0x68>; + clock-parent = <&infracfg>; + #clock-cells = <1>; + }; + + infracfg: infracfg@10001040 { + compatible = "mediatek,mt7986-infracfg"; + reg = <0x10001000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + }; + + pinctrl: pinctrl@1001f000 { + compatible = "mediatek,mt7986-pinctrl"; + reg = <0x1001f000 0x1000>, + <0x11c30000 0x1000>, + <0x11c40000 0x1000>, + <0x11e20000 0x1000>, + <0x11e30000 0x1000>, + <0x11f00000 0x1000>, + <0x11f10000 0x1000>, + <0x1000b000 0x1000>; + reg-names = "gpio_base", "iocfg_rt_base","
iocfg_rb_base",arch/arm/dts/mt7986.dtsi new file +1
-0+ "iocfg_lt_base", "iocfg_lb_base","
iocfg_tr_base",arch/arm/dts/mt7986.dtsi new file +22
-0+ "iocfg_tl_base", "eint"; + gpio: gpio-controller { + gpio-controller; + #gpio-cells = <2>; + }; + }; + + pwm: pwm@10048000 { + compatible = "mediatek,mt7986-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>; + assigned-clocks = <&topckgen CK_TOP_PWM_SEL>, + <&infracfg CK_INFRA_PWM_BSEL>, + <&infracfg CK_INFRA_PWM1_SEL>, + <&infracfg CK_INFRA_PWM2_SEL>; + assigned-clock-parents = <&topckgen
CK_TOP_CB_M_D4>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>;arch/arm/dts/mt7986.dtsi new file +12
-0+ clock-names = "top", "main", "pwm1", "pwm2"; + status = "disabled"; + u-boot,dm-pre-reloc; + }; + + 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>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_CKSQ_40M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_UART>;arch/arm/dts/mt7986.dtsi new file +11
-0+ 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 = <&infracfg
CK_INFRA_UART1_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +10
-0+ 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 = <&infracfg
CK_INFRA_UART2_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +16
-0+ 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>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_CB_M_D8>;arch/arm/dts/mt7986.dtsi new file +25
-0+ status = "disabled"; + }; + + ethsys: syscon@15000000 { + compatible = "mediatek,mt7986-ethsys", "syscon"; + reg = <0x15000000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + + eth: ethernet@15100000 { + compatible = "mediatek,mt7986-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";
arch/arm/dts/mt7986.dtsi new file +6
-0+ reg = <0x10060000 0x1000>; + #clock-cells = <1>; + }; + + sgmiisys1: syscon@10070000 { + compatible = "mediatek,mt7986-sgmiisys","syscon";
arch/arm/dts/mt7986.dtsi new file +12
-0+ 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>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_INFRA_ISPI0>;arch/arm/dts/mt7986.dtsi new file +21
-0+ 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"; + }; + + mmc0: mmc@11230000 { + compatible = "mediatek,mt7986-mmc"; + reg = <0x11230000 0x1000>, + <0x11C20000 0x1000>; + interrupts = <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&topckgen CK_TOP_EMMC_416M>, + <&topckgen CK_TOP_EMMC_250M>, + <&infracfg_ao CK_INFRA_MSDC_CK>; + assigned-clocks = <&topckgen
CK_TOP_EMMC_416M_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_EMMC_250M_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_M_416M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_NET1_D5_D2>;arch/arm/dts/mt7986.dtsi new file +60
-0+ clock-names = "source", "hclk", "source_cg"; + status = "disabled"; + }; + + xhci: xhci@11200000 { + compatible = "mediatek,mt7986-xhci", + "mediatek,mtk-xhci"; + reg = <0x11200000 0x2e00>, + <0x11203e00 0x0100>; + reg-names = "mac", "ippc"; + interrupts = <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>; + phys = <&u2port0 PHY_TYPE_USB2>, + <&u3port0 PHY_TYPE_USB3>, + <&u2port1 PHY_TYPE_USB2>; + clocks = <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>; + clock-names = "sys_ck", + "xhci_ck", + "ref_ck", + "mcu_ck", + "dma_ck"; + tpl-support; + status = "okay"; + }; + + usbtphy: usb-phy@11e10000 { + compatible = "mediatek,mt7986", + "mediatek,generic-tphy-v2"; + #address-cells = <1>; + #size-cells = <1>; + status = "okay"; + + u2port0: usb-phy@11e10000 { + reg = <0x11e10000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u3port0: usb-phy@11e10700 { + reg = <0x11e10700 0x900>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u2port1: usb-phy@11e11000 { + reg = <0x11e11000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + }; +};arch/arm/mach- renamed from arch/arm/mach-mediatek/Kconfig +0
-0mediatek/Kconfig
indexf79a5c62cd..e059a013db100644arch/arm/mach-mediatek/Kconfig +0
-0@@ -40,6 +40,14 @@ config TARGET_MT7629 including DDR3, crypto engine, 3x3 11n/ac Wi-Fi,Gigabit
Ethernet,arch/arm/mach-mediatek/Kconfig +5
-0switch, USB3.0, PCIe, UART, SPI, I2C and PWM. +config TARGET_MT7986 + bool "MediaTek MT7986 SoC" + select ARM64 + help + The MediaTek MT7986 is a ARM64-based SoC with a quad-core Cortex-A53.
arch/arm/mach-mediatek/Kconfig +1
-0+ including UART, SPI, SPI flash, USB3.0, MMC, NAND,SNFI,
PWM, PCIe,arch/arm/mach-mediatek/Kconfig +4
-0+ Gigabit Ethernet, I2C, built-in 4x4 Wi-Fi, and PCIe. + config TARGET_MT8183 bool "MediaTek MT8183 SoC" select ARM64@@ -84,6 +92,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 +108,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 +123,7 @@ config MTK_BROM_HEADER_INFO string default "media=nor" if TARGET_MT8518 || TARGET_MT8512 ||Quoted 2 lines
TARGET_MT7629||
TARGET_MT7622Same here.
Review
Quoted 9 lines
default "media=emmc" if
TARGET_MT8516||TARGET_MT8365
||TARGET_MT8183arch/arm/mach-mediatek/Kconfig +1
-0+ default "media=snand;nandinfo=2k+64" if TARGET_MT7986 default "lk=1" if TARGET_MT7623 endif(quoted diff) +0
-0b/arch/arm/mach-mediatek/MakefileAnd here.
Review
Quoted 13 lines
index
0f5b0c16d2..fe5c3a837c100644arch/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/(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/MakefileAnd here.
Review
Quoted 11 lines
new file mode 100644
index 0000000000..007eb4a367arch/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(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/init.cAnd here again.
Quoted 62 lines
new file mode 100644
index 0000000000..4884cbdc67arch/arm/mach-mediatek/mt7986/init.c new file +24
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h> +#include <asm/armv8/mmu.h> +#include <init.h> +#include <asm/system.h> +#include <asm/global_data.h> +#include <linux/sizes.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void ) +{ +printf ("CPU: MediaTek MT7986\n" ); +return 0 ; +} + +int dram_init (void ) +{ + gd->ram_size = get_ram_size((void*)CONFIG_SYS_SDRAM_BASE,
SZ_2G);arch/arm/mach-mediatek/mt7986/init.c new file +16
-0+ +return 0 ; +} + +void reset_cpu (ulong addr) +{ +psci_system_reset (); +} + +static struct mm_region mt7986_mem_map[] = { + { +/* DDR */ + .virt =0x40000000UL , + .phys =0x40000000UL , + .size =0x80000000UL , + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
PTE_BLOCK_OUTER_SHARE,arch/arm/mach-mediatek/mt7986/init.c new file +13
-0+ }, { + .virt = 0x00000000UL, + .phys = 0x00000000UL, + .size = 0x40000000UL, + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | + PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + 0, + } +}; + +struct mm_region *mem_map = mt7986_mem_map;Review
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/lowlevel_init.SAnd here.
Quoted 38 lines
new file mode 100644
index 0000000000..244d2c1385arch/arm/mach-mediatek/mt7986/lowlevel_init.S new file +30
-0@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 + SMC #0 + retSignature · 1 line
2.17.1
Re: [PATCH 01/31] arm: mediatek: add support for MediaTek MT7986 SoC
Hi Weijie,
I manually fixed the last 3 patches in the series adding support for newer SoCs to mkimage/mtk_image.
On my BPi-R3 (mt7986a) I was now trying to use mkimage instead of bromimage in the same way you introduced that option for mt7622[1]:
The resulting bl2.img works fine on SPI-NAND and eMMC, however, booting from SPI-NOR or SD card doesn't work.
On SPI-NOR:
F0: 102B 0000
FA: 0000 0000
V0: 7027 6006 [0001]
00: 1017 0000
FA: 5100 0000
01: 102A 0001
02: 5100 0000
BP: 2000 00C0 [0001]
EC: 0000 0000 [0000]
T0: 0000 0213 [010F]
System halt!
On SD card:
F0: 102B 0000
FA: 1040 0000
FA: 1040 0000 [0200]
F9: 103F 0000
F3: 1001 0000 [0200]
F3: 1001 0000
F6: 300C 0028
F5: 0000 0000
L0: 8005 0000 [0001]
00: 1012 0000
BP: 2000 00C0 [0001]
EC: 0000 0000 [3000]
T0: 0000 00E8 [010F]
System halt!
All generate image headers also differ from the ones generated by bromimage, however, for SPI-NAND and eMMC they still work.
hexdiff of SD card bl2.img
@@ -65,7 +65,7 @@
00004420 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| *
00004600 42 52 4c 59 54 00 00 00 01 00 00 00 00 4a 00 00 |BRLYT........J..| -00004610 88 51 03 00 42 42 42 42 08 00 01 00 00 06 00 00 |.Q..BBBB........| +00004610 88 51 03 00 42 42 42 42 08 00 01 00 00 4a 00 00 |.Q..BBBB.....J..| 00004620 88 51 03 00 ff ff ff ff ff ff ff ff ff ff ff ff |.Q..............| 00004630 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| * @@ -73,15 +73,15 @@ 00004a10 4f 00 00 00 01 00 00 00 01 00 05 01 00 0d 20 00 |O............. .| 00004a20 88 07 03 00 88 0d 03 00 00 03 00 00 20 00 00 00 |............ ...| 00004a30 00 03 00 00 01 00 00 00 4d 4d 4d 01 0c 00 01 00 |........MMM.....| -00004a40 01 00 00 00 4d 4d 4d 01 14 00 02 00 00 00 00 00 |....MMM.........| -00004a50 10 00 00 00 80 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....| -00004a60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| -* -00004c60 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 03 |............MMM.| -00004c70 64 00 07 00 90 11 00 00 00 00 00 00 00 00 00 00 |d...............| -00004c80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00004a40 01 00 00 00 4d 4d 4d 03 64 00 07 00 90 11 00 00 |....MMM.d.......| +00004a50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * -00004cc0 00 64 00 00 88 13 00 00 00 00 00 00 00 00 00 00 |.d..............| +00004a90 00 00 00 00 00 00 00 00 00 64 00 00 88 13 00 00 |.........d......| +00004aa0 00 00 00 00 00 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....| +00004ab0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +* +00004cb0 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 01 |............MMM.| +00004cc0 14 00 02 00 00 00 00 00 10 00 00 00 80 00 00 00 |................| 00004cd0 4d 4d 4d 01 30 00 08 00 03 00 00 00 00 00 00 00 |MMM.0...........| 00004ce0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
hexdiff of SPI-NOR bl2.img
@@ -11,15 +11,15 @@
00000610 4f 00 00 00 01 00 00 00 01 00 05 01 00 0d 20 00 |O............. .| 00000620 70 0a 03 00 70 10 03 00 00 03 00 00 20 00 00 00 |p...p....... ...| 00000630 00 03 00 00 01 00 00 00 4d 4d 4d 01 0c 00 01 00 |........MMM.....| -00000640 01 00 00 00 4d 4d 4d 03 64 00 07 00 90 11 00 00 |....MMM.d.......| -00000650 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000640 01 00 00 00 4d 4d 4d 01 14 00 02 00 00 00 00 00 |....MMM.........| +00000650 10 00 00 00 80 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....| +00000660 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * -00000690 00 00 00 00 00 00 00 00 00 64 00 00 88 13 00 00 |.........d......| -000006a0 00 00 00 00 00 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....| -000006b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000860 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 03 |............MMM.| +00000870 64 00 07 00 90 11 00 00 00 00 00 00 00 00 00 00 |d...............| +00000880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * -000008b0 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 01 |............MMM.| -000008c0 14 00 02 00 00 00 00 00 10 00 00 00 80 00 00 00 |................| +000008c0 00 64 00 00 88 13 00 00 00 00 00 00 00 00 00 00 |.d..............| 000008d0 4d 4d 4d 01 30 00 08 00 03 00 00 00 00 00 00 00 |MMM.0...........| 000008e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
I'll try to have a look at this more deepply in the next days, but if you already spot the error I'd also be glad ;)
Cheers
Daniel
[1]: https://github.com/dangowrt/arm-trusted-firmware/commit/3b8a17bd847d864379fe9953a82991b522f64add
Quoted 670 lines · Weijie Gao
Hi Daniel,
It turns out that this was caused by a setting change of company's mail gateway.
I'll send v2 later.Best Regards,
Weijie
Quoted 659 lines · Weijie Gao
Hi Daniel,
Thanks for the reminder.
I found more errornous line-breaks in other patches... I'll find a way to fix that.Best Regards,
WeijieQuoted 649 lines · Daniel Golle
Hi Weijie,
happy to see this series posted!
Trying to apply it unfortunately fails due to errornous line- breaks,
supposedly inserted by your MUA, see below.I didn't go beyond the first patch and it'd be nice if you report the
whole series without the wrong line-breaks.Cheers
Daniel
Quoted 23 lines · Weijie Gao
This patch adds basic support for MediaTek MT7986 SoC. This include the file that will initialize the SoC after boot and its
device tree.Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7986-u-boot.dtsi | 33 ++ arch/arm/dts/mt7986.dtsi | 341 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 11 + arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 53 +++ arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 30 ++ 7 files changed, 473 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.SReview
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/dts/mt7986-u-boot.dtsiThe above two lines should be a single line.
Quoted 453 lines
new file mode 100644
index 0000000000..95671f8afaarch/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 +53
-0@@ -0,0 +1,341 @@ +// 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/phy/phy.h> +#include <dt-bindings/clock/mt7986-clk.h> +#include <dt-bindings/reset/mt7629-reset.h> +#include <dt-bindings/pinctrl/mt65xx.h> + +/ { + compatible = "mediatek,mt7986"; + interrupt-parent = <&gic>; + #address-cells = <1>; + #size-cells = <1>; + + config { + u-boot,mmc-env-partition = "u-boot-env"; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x0>; + }; + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu2: cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu3: cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + }; + + dummy_clk: dummy12m { + compatible = "fixed-clock"; + clock-frequency = <12000000>; + #clock-cells = <0>; + /* must need this line, or uart uanable to get
dummy_clk*/arch/arm/dts/mt7986.dtsi new file +80
-0+ u-boot,dm-pre-reloc; + }; + + 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 = <&infracfg CK_INFRA_CK_F26M>; + 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,mt7986-fixed-plls"; + reg = <0x1001E000 0x1000>; + #clock-cells = <1>; + }; + + topckgen: topckgen@1001B000 { + compatible = "mediatek,mt7986-topckgen"; + reg = <0x1001B000 0x1000>; + clock-parent = <&fixed_plls>; + #clock-cells = <1>; + }; + + infracfg_ao: infracfg_ao@10001000 { + compatible = "mediatek,mt7986-infracfg_ao"; + reg = <0x10001000 0x68>; + clock-parent = <&infracfg>; + #clock-cells = <1>; + }; + + infracfg: infracfg@10001040 { + compatible = "mediatek,mt7986-infracfg"; + reg = <0x10001000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + }; + + pinctrl: pinctrl@1001f000 { + compatible = "mediatek,mt7986-pinctrl"; + reg = <0x1001f000 0x1000>, + <0x11c30000 0x1000>, + <0x11c40000 0x1000>, + <0x11e20000 0x1000>, + <0x11e30000 0x1000>, + <0x11f00000 0x1000>, + <0x11f10000 0x1000>, + <0x1000b000 0x1000>; + reg-names = "gpio_base", "iocfg_rt_base","
iocfg_rb_base",arch/arm/dts/mt7986.dtsi new file +1
-0+ "iocfg_lt_base", "iocfg_lb_base","
iocfg_tr_base",arch/arm/dts/mt7986.dtsi new file +22
-0+ "iocfg_tl_base", "eint"; + gpio: gpio-controller { + gpio-controller; + #gpio-cells = <2>; + }; + }; + + pwm: pwm@10048000 { + compatible = "mediatek,mt7986-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>; + assigned-clocks = <&topckgen CK_TOP_PWM_SEL>, + <&infracfg CK_INFRA_PWM_BSEL>, + <&infracfg CK_INFRA_PWM1_SEL>, + <&infracfg CK_INFRA_PWM2_SEL>; + assigned-clock-parents = <&topckgen
CK_TOP_CB_M_D4>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>;arch/arm/dts/mt7986.dtsi new file +12
-0+ clock-names = "top", "main", "pwm1", "pwm2"; + status = "disabled"; + u-boot,dm-pre-reloc; + }; + + 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>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_CKSQ_40M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_UART>;arch/arm/dts/mt7986.dtsi new file +11
-0+ 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 = <&infracfg
CK_INFRA_UART1_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +10
-0+ 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 = <&infracfg
CK_INFRA_UART2_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +16
-0+ 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>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_CB_M_D8>;arch/arm/dts/mt7986.dtsi new file +25
-0+ status = "disabled"; + }; + + ethsys: syscon@15000000 { + compatible = "mediatek,mt7986-ethsys", "syscon"; + reg = <0x15000000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + + eth: ethernet@15100000 { + compatible = "mediatek,mt7986-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";
arch/arm/dts/mt7986.dtsi new file +6
-0+ reg = <0x10060000 0x1000>; + #clock-cells = <1>; + }; + + sgmiisys1: syscon@10070000 { + compatible = "mediatek,mt7986-sgmiisys","syscon";
arch/arm/dts/mt7986.dtsi new file +12
-0+ 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>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_INFRA_ISPI0>;arch/arm/dts/mt7986.dtsi new file +21
-0+ 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"; + }; + + mmc0: mmc@11230000 { + compatible = "mediatek,mt7986-mmc"; + reg = <0x11230000 0x1000>, + <0x11C20000 0x1000>; + interrupts = <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&topckgen CK_TOP_EMMC_416M>, + <&topckgen CK_TOP_EMMC_250M>, + <&infracfg_ao CK_INFRA_MSDC_CK>; + assigned-clocks = <&topckgen
CK_TOP_EMMC_416M_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_EMMC_250M_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_M_416M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_NET1_D5_D2>;arch/arm/dts/mt7986.dtsi new file +60
-0+ clock-names = "source", "hclk", "source_cg"; + status = "disabled"; + }; + + xhci: xhci@11200000 { + compatible = "mediatek,mt7986-xhci", + "mediatek,mtk-xhci"; + reg = <0x11200000 0x2e00>, + <0x11203e00 0x0100>; + reg-names = "mac", "ippc"; + interrupts = <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>; + phys = <&u2port0 PHY_TYPE_USB2>, + <&u3port0 PHY_TYPE_USB3>, + <&u2port1 PHY_TYPE_USB2>; + clocks = <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>; + clock-names = "sys_ck", + "xhci_ck", + "ref_ck", + "mcu_ck", + "dma_ck"; + tpl-support; + status = "okay"; + }; + + usbtphy: usb-phy@11e10000 { + compatible = "mediatek,mt7986", + "mediatek,generic-tphy-v2"; + #address-cells = <1>; + #size-cells = <1>; + status = "okay"; + + u2port0: usb-phy@11e10000 { + reg = <0x11e10000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u3port0: usb-phy@11e10700 { + reg = <0x11e10700 0x900>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u2port1: usb-phy@11e11000 { + reg = <0x11e11000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + }; +};arch/arm/mach- renamed from arch/arm/mach-mediatek/Kconfig +0
-0mediatek/Kconfig
indexf79a5c62cd..e059a013db100644arch/arm/mach-mediatek/Kconfig +0
-0@@ -40,6 +40,14 @@ config TARGET_MT7629 including DDR3, crypto engine, 3x3 11n/ac Wi-Fi,Gigabit
Ethernet,arch/arm/mach-mediatek/Kconfig +5
-0switch, USB3.0, PCIe, UART, SPI, I2C and PWM. +config TARGET_MT7986 + bool "MediaTek MT7986 SoC" + select ARM64 + help + The MediaTek MT7986 is a ARM64-based SoC with a quad-core Cortex-A53.
arch/arm/mach-mediatek/Kconfig +1
-0+ including UART, SPI, SPI flash, USB3.0, MMC, NAND,SNFI,
PWM, PCIe,arch/arm/mach-mediatek/Kconfig +4
-0+ Gigabit Ethernet, I2C, built-in 4x4 Wi-Fi, and PCIe. + config TARGET_MT8183 bool "MediaTek MT8183 SoC" select ARM64@@ -84,6 +92,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 +108,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 +123,7 @@ config MTK_BROM_HEADER_INFO string default "media=nor" if TARGET_MT8518 || TARGET_MT8512 ||Quoted 2 lines
TARGET_MT7629||
TARGET_MT7622Same here.
Review
Quoted 9 lines
default "media=emmc" if
TARGET_MT8516||TARGET_MT8365
||TARGET_MT8183arch/arm/mach-mediatek/Kconfig +1
-0+ default "media=snand;nandinfo=2k+64" if TARGET_MT7986 default "lk=1" if TARGET_MT7623 endif(quoted diff) +0
-0b/arch/arm/mach-mediatek/MakefileAnd here.
Review
Quoted 13 lines
index
0f5b0c16d2..fe5c3a837c100644arch/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/(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/MakefileAnd here.
Review
Quoted 11 lines
new file mode 100644
index 0000000000..007eb4a367arch/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(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/init.cAnd here again.
Quoted 62 lines
new file mode 100644
index 0000000000..4884cbdc67arch/arm/mach-mediatek/mt7986/init.c new file +24
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h> +#include <asm/armv8/mmu.h> +#include <init.h> +#include <asm/system.h> +#include <asm/global_data.h> +#include <linux/sizes.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void ) +{ +printf ("CPU: MediaTek MT7986\n" ); +return 0 ; +} + +int dram_init (void ) +{ + gd->ram_size = get_ram_size((void*)CONFIG_SYS_SDRAM_BASE,
SZ_2G);arch/arm/mach-mediatek/mt7986/init.c new file +16
-0+ +return 0 ; +} + +void reset_cpu (ulong addr) +{ +psci_system_reset (); +} + +static struct mm_region mt7986_mem_map[] = { + { +/* DDR */ + .virt =0x40000000UL , + .phys =0x40000000UL , + .size =0x80000000UL , + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
PTE_BLOCK_OUTER_SHARE,arch/arm/mach-mediatek/mt7986/init.c new file +13
-0+ }, { + .virt = 0x00000000UL, + .phys = 0x00000000UL, + .size = 0x40000000UL, + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | + PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + 0, + } +}; + +struct mm_region *mem_map = mt7986_mem_map;Review
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/lowlevel_init.SAnd here.
Quoted 38 lines
new file mode 100644
index 0000000000..244d2c1385arch/arm/mach-mediatek/mt7986/lowlevel_init.S new file +30
-0@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 + SMC #0 + retSignature · 1 line
2.17.1
Re: [PATCH 01/31] arm: mediatek: add support for MediaTek MT7986 SoC
Hi Daniel,
There is a design change between MT7986(and later chips) and MT7622:
The bootrom of MT7622 requires the device header offset be set to the absolute address of the BL2 in the flash device. For SPI-NOR/SPI-NAND and eMMC, the offset is always zero. But for SD devices, BL2 is stored in the first active MBR partition which apparently has non-zero offset.
So in platform.mk from mt7622, there's one line for sd-booting:DEVICE_HEADER_OFFSET ?= 0x80000
and the corresponding commandline for mkimage:
hdroffset=$(DEVICE_HEADER_OFFSET)
However, since MT7986, the bootrom requires the device header offset be set to the relative offset of the BL2 in its partition. For SPI-NOR/SPI-NAND and eMMC, the offset is still zero. For SD devices, BL2 is stored in the first bootable GPT partition, and its offset related to the partition is also zero.
So the following line in platform.mk from mt7986 must be removed:DEVICE_HEADER_OFFSET ?= 0x4400
and the following mkimage commandline must also be removed:
hdroffset=$(DEVICE_HEADER_OFFSET)
BTW, I don't know the exact version of atf you're using. I'll upload new atf to github with all boot device tested, including spi-nor.
Best Regards,
Weijie
Quoted 876 lines · Daniel Golle
Hi Weijie,
I manually fixed the last 3 patches in the series adding support for newer SoCs to mkimage/mtk_image.
On my BPi-R3 (mt7986a) I was now trying to use mkimage instead of bromimage in the same way you introduced that option for mt7622[1]:
The resulting bl2.img works fine on SPI-NAND and eMMC, however, booting from SPI-NOR or SD card doesn't work.
On SPI-NOR:
F0: 102B 0000
FA: 0000 0000
V0: 7027 6006 [0001]
00: 1017 0000
FA: 5100 0000
01: 102A 0001
02: 5100 0000
BP: 2000 00C0 [0001]
EC: 0000 0000 [0000]
T0: 0000 0213 [010F]
System halt!On SD card:
F0: 102B 0000
FA: 1040 0000
FA: 1040 0000 [0200]
F9: 103F 0000
F3: 1001 0000 [0200]
F3: 1001 0000
F6: 300C 0028
F5: 0000 0000
L0: 8005 0000 [0001]
00: 1012 0000
BP: 2000 00C0 [0001]
EC: 0000 0000 [3000]
T0: 0000 00E8 [010F]
System halt!All generate image headers also differ from the ones generated by bromimage, however, for SPI-NAND and eMMC they still work.
hexdiff of SD card bl2.img
(quoted diff) +0
-0@@ -65,7 +65,7 @@ 00004420 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff |................|
*
00004600 42 52 4c 59 54 00 00 00 01 00 00 00 00 4a 00
00 |BRLYT........J..|
-00004610 88 51 03 00 42 42 42 42 08 00 01 00 00 06 00 00 |.Q..BBBB........|
+00004610 88 51 03 00 42 42 42 42 08 00 01 00 00 4a 00 00 |.Q..BBBB.....J..|
00004620 88 51 03 00 ff ff ff ff ff ff ff ff ff ff ff
ff |.Q..............|
00004630 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff |................|
*(quoted diff) +0
-0@@ -73,15 +73,15 @@ 00004a10 4f 00 00 00 01 00 00 00 01 00 05 01 00 0d 2000 |O............. .|
00004a2088 07 03 00 88 0d 03 00 00 03 00 00 20 00 00
00 |............ ...|
00004a3000 03 00 00 01 00 00 00 4d 4d 4d 01 0c 00 01
00 |........MMM.....|
-00004a40 01 00 00 00 4d 4d 4d 01 14 00 02 00 00 00 00 00 |....MMM.........|
-00004a50 10 00 00 00 80 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....|
-00004a60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
-*
-00004c60 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 03 |............MMM.|
-00004c70 64 00 07 00 90 11 00 00 00 00 00 00 00 00 00 00 |d...............|
-00004c80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
+00004a40 01 00 00 00 4d 4d 4d 03 64 00 07 00 90 11 00 00 |....MMM.d.......|
+00004a50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
-00004cc0 00 64 00 00 88 13 00 00 00 00 00 00 00 00 00 00 |.d..............|
+00004a90 00 00 00 00 00 00 00 00 00 64 00 00 88 13 00 00 |.........d......|
+00004aa0 00 00 00 00 00 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....|
+00004ab0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
+*
+00004cb0 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 01 |............MMM.|
+00004cc0 14 00 02 00 00 00 00 00 10 00 00 00 80 00 00 00 |................|
00004cd04d 4d 4d 01 30 00 08 00 03 00 00 00 00 00 00
00 |MMM.0...........|
00004ce000 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 |................|
*hexdiff of SPI-NOR bl2.img
(quoted diff) +0
-0@@ -11,15 +11,15 @@ 00000610 4f 00 00 00 01 00 00 00 01 00 05 01 00 0d 2000 |O............. .|
00000620 70 0a 03 00 70 10 03 00 00 03 00 00 20 00 00
00 |p...p....... ...|
00000630 00 03 00 00 01 00 00 00 4d 4d 4d 01 0c 00 01
00 |........MMM.....|
-00000640 01 00 00 00 4d 4d 4d 03 64 00 07 00 90 11 00 00 |....MMM.d.......|
-00000650 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
+00000640 01 00 00 00 4d 4d 4d 01 14 00 02 00 00 00 00 00 |....MMM.........|
+00000650 10 00 00 00 80 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....|
+00000660 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
-00000690 00 00 00 00 00 00 00 00 00 64 00 00 88 13 00 00 |.........d......|
-000006a0 00 00 00 00 00 00 00 00 4d 4d 4d 01 14 02 03 00 |........MMM.....|
-000006b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
+00000860 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 03 |............MMM.|
+00000870 64 00 07 00 90 11 00 00 00 00 00 00 00 00 00 00 |d...............|
+00000880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
-000008b0 00 00 00 00 00 00 00 00 00 00 00 00 4d 4d 4d 01 |............MMM.|
-000008c0 14 00 02 00 00 00 00 00 10 00 00 00 80 00 00 00 |................|
+000008c0 00 64 00 00 88 13 00 00 00 00 00 00 00 00 00 00 |.d..............|
000008d04d 4d 4d 01 30 00 08 00 03 00 00 00 00 00 00
00 |MMM.0...........|
000008e000 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 |................|
*I'll try to have a look at this more deepply in the next days, but if you already spot the error I'd also be glad ;)
Cheers
Daniel
[1]: https://urldefense.com/v3/__https://github.com/dangowrt/arm-trus
ted- firmware/commit/3b8a17bd847d864379fe9953a82991b522f64add__;!!CTRNKA9w Mg0ARbw!ybxbFXd18o_0NK- 33rzQvf0llAa6qqjA78WFMYoGoSAQ7S5t5wgDu6RHzvV2Id4F6w$Quoted 711 lines · Weijie Gao
Hi Daniel,
It turns out that this was caused by a setting change of company's mail
gateway.
I'll send v2 later.Best Regards,
Weijie
Quoted 699 lines · Weijie Gao
Hi Daniel,
Thanks for the reminder.
I found more errornous line-breaks in other patches... I'll find a way to fix that.Best Regards,
WeijieQuoted 689 lines · Daniel Golle
Hi Weijie,
happy to see this series posted!
Trying to apply it unfortunately fails due to errornous line- breaks,
supposedly inserted by your MUA, see below.I didn't go beyond the first patch and it'd be nice if you report
the
whole series without the wrong line-breaks.Cheers
Daniel
Quoted 25 lines · Weijie Gao
This patch adds basic support for MediaTek MT7986 SoC. This include the file that will initialize the SoC after boot and
its
device tree.Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7986-u-boot.dtsi | 33 ++ arch/arm/dts/mt7986.dtsi | 341 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 11 + arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7986/Makefile | 4 + arch/arm/mach-mediatek/mt7986/init.c | 53 +++ arch/arm/mach-mediatek/mt7986/lowlevel_init.S | 30 ++ 7 files changed, 473 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.SReview
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/dts/mt7986-u-boot.dtsiThe above two lines should be a single line.
Quoted 487 lines
new file mode 100644
index 0000000000..95671f8afaarch/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 +53
-0@@ -0,0 +1,341 @@ +// 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/phy/phy.h> +#include <dt-bindings/clock/mt7986-clk.h> +#include <dt-bindings/reset/mt7629-reset.h> +#include <dt-bindings/pinctrl/mt65xx.h> + +/ { + compatible = "mediatek,mt7986"; + interrupt-parent = <&gic>; + #address-cells = <1>; + #size-cells = <1>; + + config { + u-boot,mmc-env-partition = "u-boot-env"; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x0>; + }; + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu2: cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + cpu3: cpu@3 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + }; + + dummy_clk: dummy12m { + compatible = "fixed-clock"; + clock-frequency = <12000000>; + #clock-cells = <0>; + /* must need this line, or uart uanable toget
dummy_clk*/arch/arm/dts/mt7986.dtsi new file +8
-0+ u-boot,dm-pre-reloc; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupt-parent = <&gic>; + clock-frequency = <13000000>; + interrupts = <GIC_PPI 13
IRQ_TYPE_LEVEL_LOW>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <GIC_PPI 14
IRQ_TYPE_LEVEL_LOW>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <GIC_PPI 11
IRQ_TYPE_LEVEL_LOW>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <GIC_PPI 10
IRQ_TYPE_LEVEL_LOW>;arch/arm/dts/mt7986.dtsi new file +7
-0+ arm,cpu-registers-not-fw-configured; + }; + + timer0: timer@10008000 { + compatible = "mediatek,mt7986-timer"; + reg = <0x10008000 0x1000>; + interrupts = <GIC_SPI 130
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +9
-0+ clocks = <&infracfg CK_INFRA_CK_F26M>; + 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>;arch/arm/dts/mt7986.dtsi new file +13
-0+ #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>;arch/arm/dts/mt7986.dtsi new file +40
-0+ }; + + fixed_plls: apmixedsys@1001E000 { + compatible = "mediatek,mt7986-fixed-plls"; + reg = <0x1001E000 0x1000>; + #clock-cells = <1>; + }; + + topckgen: topckgen@1001B000 { + compatible = "mediatek,mt7986-topckgen"; + reg = <0x1001B000 0x1000>; + clock-parent = <&fixed_plls>; + #clock-cells = <1>; + }; + + infracfg_ao: infracfg_ao@10001000 { + compatible = "mediatek,mt7986-infracfg_ao"; + reg = <0x10001000 0x68>; + clock-parent = <&infracfg>; + #clock-cells = <1>; + }; + + infracfg: infracfg@10001040 { + compatible = "mediatek,mt7986-infracfg"; + reg = <0x10001000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + }; + + pinctrl: pinctrl@1001f000 { + compatible = "mediatek,mt7986-pinctrl"; + reg = <0x1001f000 0x1000>, + <0x11c30000 0x1000>, + <0x11c40000 0x1000>, + <0x11e20000 0x1000>, + <0x11e30000 0x1000>, + <0x11f00000 0x1000>, + <0x11f10000 0x1000>, + <0x1000b000 0x1000>; + reg-names = "gpio_base", "iocfg_rt_base","
iocfg_rb_base",arch/arm/dts/mt7986.dtsi new file +1
-0+ "iocfg_lt_base","
iocfg_lb_base",
"iocfg_tr_base",arch/arm/dts/mt7986.dtsi new file +13
-0+ "iocfg_tl_base", "eint"; + gpio: gpio-controller { + gpio-controller; + #gpio-cells = <2>; + }; + }; + + pwm: pwm@10048000 { + compatible = "mediatek,mt7986-pwm"; + reg = <0x10048000 0x1000>; + #clock-cells = <1>; + #pwm-cells = <2>; + interrupts = <GIC_SPI 137
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +5
-0+ clocks = <&infracfg CK_INFRA_PWM>, + <&infracfg_ao CK_INFRA_PWM_BSEL>, + <&infracfg_ao CK_INFRA_PWM1_CK>, + <&infracfg_ao CK_INFRA_PWM2_CK>; + assigned-clocks = <&topckgen
CK_TOP_PWM_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM_BSEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM1_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM2_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_M_D4>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_PWM>;arch/arm/dts/mt7986.dtsi new file +9
-0+ clock-names = "top", "main", "pwm1", "pwm2"; + status = "disabled"; + u-boot,dm-pre-reloc; + }; + + uart0: serial@11002000 { + compatible = "mediatek,hsuart"; + reg = <0x11002000 0x400>; + interrupts = <GIC_SPI 123
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +2
-0+ clocks = <&infracfg_ao CK_INFRA_UART0_CK>; + assigned-clocks = <&topckgen
CK_TOP_UART_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg_ao
CK_INFRA_UART0_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_CKSQ_40M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_UART>;arch/arm/dts/mt7986.dtsi new file +9
-0+ 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>;arch/arm/dts/mt7986.dtsi new file +2
-0+ clocks = <&infracfg_ao CK_INFRA_UART1_CK>; + assigned-clocks = <&infracfg
CK_INFRA_UART1_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +8
-0+ mediatek,force-highspeed; + status = "disabled"; + }; + + uart2: serial@11004000 { + compatible = "mediatek,hsuart"; + reg = <0x11004000 0x400>; + interrupts = <GIC_SPI 124
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +2
-0+ clocks = <&infracfg_ao CK_INFRA_UART2_CK>; + assigned-clocks = <&infracfg
CK_INFRA_UART2_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&infracfg
CK_INFRA_CK_F26M>;arch/arm/dts/mt7986.dtsi new file +13
-0+ 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";arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clocks = <&topckgen
CK_TOP_SPINFI_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_NFI1X_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_M_D8>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_CB_M_D8>;arch/arm/dts/mt7986.dtsi new file +5
-0+ status = "disabled"; + }; + + ethsys: syscon@15000000 { + compatible = "mediatek,mt7986-ethsys","syscon";
arch/arm/dts/mt7986.dtsi new file +8
-0+ reg = <0x15000000 0x1000>; + clock-parent = <&topckgen>; + #clock-cells = <1>; + #reset-cells = <1>; + }; + + eth: ethernet@15100000 { + compatible = "mediatek,mt7986-eth","syscon";
arch/arm/dts/mt7986.dtsi new file +12
-0+ 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";
arch/arm/dts/mt7986.dtsi new file +6
-0+ reg = <0x10060000 0x1000>; + #clock-cells = <1>; + }; + + sgmiisys1: syscon@10070000 { + compatible = "mediatek,mt7986-sgmiisys","syscon";
arch/arm/dts/mt7986.dtsi new file +10
-0+ 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>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&infracfg
CK_INFRA_SPI0_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_M_D2>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_INFRA_ISPI0>;arch/arm/dts/mt7986.dtsi new file +2
-0+ clock-names = "sel-clk", "spi-clk"; + interrupts = <GIC_SPI 140
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +7
-0+ status = "disabled"; + }; + + spi1: spi@1100b000 { + compatible = "mediatek,ipm-spi"; + reg = <0x1100b000 0x100>; + interrupts = <GIC_SPI 141
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +8
-0+ status = "disabled"; + }; + + mmc0: mmc@11230000 { + compatible = "mediatek,mt7986-mmc"; + reg = <0x11230000 0x1000>, + <0x11C20000 0x1000>; + interrupts = <GIC_SPI 143
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +4
-0+ clocks = <&topckgen CK_TOP_EMMC_416M>, + <&topckgen CK_TOP_EMMC_250M>, + <&infracfg_ao CK_INFRA_MSDC_CK>; + assigned-clocks = <&topckgen
CK_TOP_EMMC_416M_SEL>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_EMMC_250M_SEL>;arch/arm/dts/mt7986.dtsi new file +1
-0+ assigned-clock-parents = <&topckgen
CK_TOP_CB_M_416M>,arch/arm/dts/mt7986.dtsi new file +1
-0+ <&topckgen
CK_TOP_NET1_D5_D2>;arch/arm/dts/mt7986.dtsi new file +11
-0+ clock-names = "source", "hclk", "source_cg"; + status = "disabled"; + }; + + xhci: xhci@11200000 { + compatible = "mediatek,mt7986-xhci", + "mediatek,mtk-xhci"; + reg = <0x11200000 0x2e00>, + <0x11203e00 0x0100>; + reg-names = "mac", "ippc"; + interrupts = <GIC_SPI 173
IRQ_TYPE_LEVEL_HIGH>;arch/arm/dts/mt7986.dtsi new file +49
-0+ phys = <&u2port0 PHY_TYPE_USB2>, + <&u3port0 PHY_TYPE_USB3>, + <&u2port1 PHY_TYPE_USB2>; + clocks = <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>, + <&dummy_clk>; + clock-names = "sys_ck", + "xhci_ck", + "ref_ck", + "mcu_ck", + "dma_ck"; + tpl-support; + status = "okay"; + }; + + usbtphy: usb-phy@11e10000 { + compatible = "mediatek,mt7986", + "mediatek,generic-tphy-v2"; + #address-cells = <1>; + #size-cells = <1>; + status = "okay"; + + u2port0: usb-phy@11e10000 { + reg = <0x11e10000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u3port0: usb-phy@11e10700 { + reg = <0x11e10700 0x900>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + + u2port1: usb-phy@11e11000 { + reg = <0x11e11000 0x700>; + clocks = <&dummy_clk>; + clock-names = "ref"; + #phy-cells = <1>; + status = "okay"; + }; + }; +};arch/arm/mach- renamed from arch/arm/mach-mediatek/Kconfig +0
-0mediatek/Kconfig
indexf79a5c62cd..e059a013db100644arch/arm/mach-mediatek/Kconfig +0
-0@@ -40,6 +40,14 @@ config TARGET_MT7629 including DDR3, crypto engine, 3x3 11n/ac Wi-Fi,Gigabit
Ethernet,arch/arm/mach-mediatek/Kconfig +5
-0switch, USB3.0, PCIe, UART, SPI, I2C and PWM. +config TARGET_MT7986 + bool "MediaTek MT7986 SoC" + select ARM64 + help + The MediaTek MT7986 is a ARM64-based SoC with aquad-
core Cortex-A53.arch/arm/mach-mediatek/Kconfig +1
-0+ including UART, SPI, SPI flash, USB3.0, MMC, NAND,SNFI,
PWM, PCIe,arch/arm/mach-mediatek/Kconfig +1
-0+ Gigabit Ethernet, I2C, built-in 4x4 Wi-Fi, andPCIe.
arch/arm/mach-mediatek/Kconfig +3
-0+ config TARGET_MT8183 bool "MediaTek MT8183 SoC" select ARM64@@ -84,6 +92,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 +108,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 +123,7 @@ config MTK_BROM_HEADER_INFO string default "media=nor" if TARGET_MT8518 ||TARGET_MT8512 || TARGET_MT7629 ||Quoted 1 line
TARGET_MT7622Same here.
Review
Quoted 12 lines
default "media=emmc" if
TARGET_MT8516||TARGET_MT8365Quoted 1 line
Quoted 1 line
TARGET_MT8183arch/arm/mach-mediatek/Kconfig +1
-0+ default "media=snand;nandinfo=2k+64" if
TARGET_MT7986arch/arm/mach-mediatek/Kconfig +0
-0default "lk=1" if TARGET_MT7623 endif(quoted diff) +0
-0b/arch/arm/mach-mediatek/MakefileAnd here.
Review
Quoted 13 lines
index
0f5b0c16d2..fe5c3a837c100644arch/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/(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/MakefileAnd here.
Review
Quoted 11 lines
new file mode 100644
index 0000000000..007eb4a367arch/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(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/init.cAnd here again.
Quoted 63 lines
new file mode 100644
index 0000000000..4884cbdc67arch/arm/mach-mediatek/mt7986/init.c new file +24
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h> +#include <asm/armv8/mmu.h> +#include <init.h> +#include <asm/system.h> +#include <asm/global_data.h> +#include <linux/sizes.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void ) +{ +printf ("CPU: MediaTek MT7986\n" ); +return 0 ; +} + +int dram_init (void ) +{ + gd->ram_size = get_ram_size((void*)CONFIG_SYS_SDRAM_BASE,
SZ_2G);arch/arm/mach-mediatek/mt7986/init.c new file +16
-0+ +return 0 ; +} + +void reset_cpu (ulong addr) +{ +psci_system_reset (); +} + +static struct mm_region mt7986_mem_map[] = { + { +/* DDR */ + .virt =0x40000000UL , + .phys =0x40000000UL , + .size =0x80000000UL , + .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
PTE_BLOCK_OUTER_SHARE,arch/arm/mach-mediatek/mt7986/init.c new file +5
-0+ }, { + .virt = 0x00000000UL, + .phys = 0x00000000UL, + .size =0x40000000UL , + .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE)|
arch/arm/mach-mediatek/mt7986/init.c new file +8
-0+ PTE_BLOCK_NON_SHARE | + PTE_BLOCK_PXN | PTE_BLOCK_UXN + }, { + 0, + } +}; + +struct mm_region *mem_map = mt7986_mem_map;Review
Quoted 1 line
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7986/lowlevel_init.SAnd here.
Quoted 38 lines
new file mode 100644
index 0000000000..244d2c1385arch/arm/mach-mediatek/mt7986/lowlevel_init.S new file +30
-0@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 + SMC #0 + retSignature · 1 line
2.17.1
PATCH 2/31 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.
--- arch/arm/dts/mt7981.dtsi | 288 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 12 +- arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7981/Makefile | 4 + arch/arm/mach-mediatek/mt7981/init.c | 52 ++++ arch/arm/mach-mediatek/mt7981/lowlevel_init.S | 30 ++ 6 files changed, 386 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 +288 -0
@@ -0,0 +1,288 @@ +// 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>; + }; + cpu1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a53"; + reg = <0x1>; + }; + }; + + gpt_clk: gpt_dummy20m { + compatible = "fixed-clock"; + clock-frequency = <13000000>; + #clock-cells = <0>; + u-boot,dm-pre-reloc; + }; + + 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 +11 -1
@@ -40,6 +40,14 @@ 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 + 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
@@ -92,6 +100,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
@@ -108,6 +117,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
@@ -123,7 +133,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
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/Makefile
index fe5c3a837c..fc85293f71 100644
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/
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/mt7981/Makefile
new file mode 100644
index 0000000000..007eb4a367
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
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/mt7981/init.c
new file mode 100644
index 0000000000..f503bb804b
arch/arm/mach-mediatek/mt7981/init.c new file +52 -0
52 lines not on this page · raw message
(quoted diff) +0 -0
b/arch/arm/mach-mediatek/mt7981/lowlevel_init.S
new file mode 100644
index 0000000000..244d2c1385
arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +30 -0
@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200 + SMC #0 + ret
Signature · 1 line
2.17.1
Re: [PATCH 02/31] arm: mediatek: add support for MediaTek MT7981 SoC
Hi Weijie,
Quoted 19 lines · Weijie Gao
This patch adds basic support for MediaTek MT7981 SoC. This include the file that will initialize the SoC after boot and its device tree.
Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7981.dtsi | 288 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 12 +- arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7981/Makefile | 4 + arch/arm/mach-mediatek/mt7981/init.c | 52 ++++ arch/arm/mach-mediatek/mt7981/lowlevel_init.S | 30 ++ 6 files changed, 386 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
[..]
Quoted 7 lines
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7981/init.cnew file mode 100644
index 0000000000..f503bb804b
arch/arm/mach-mediatek/mt7981/init.c line 7
Quoted 7 lines
arch/arm/mach-mediatek/mt7981/init.c new file +7
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h>
Do you need that?
arch/arm/mach-mediatek/mt7981/init.c line 9
Quoted 2 lines
arch/arm/mach-mediatek/mt7981/init.c new file +2
-0+#include <asm/armv8/mmu.h> +#include <init.h>
Move up one
arch/arm/mach-mediatek/mt7981/init.c line 15
Quoted 6 lines
arch/arm/mach-mediatek/mt7981/init.c new file +6
-0+#include <asm/system.h> +#include <asm/global_data.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void )
Can you use the CPU uclass and DISPLAY_CPUINFO instead/
Quoted 5 lines
arch/arm/mach-mediatek/mt7981/init.c new file +5
-0+{ +printf ("CPU: MediaTek MT7981\n" ); +return 0 ; +} +
[..]
Quoted 25 lines
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7981/lowlevel_init.Snew file mode 100644
index 0000000000..244d2c1385arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +18
-0@@ -0,0 +1,30 @@ +/* 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
arch/arm/mach-mediatek/mt7981/lowlevel_init.S line 28
Quoted 10 lines
arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +10
-0+ * x3: fdt address +*/ + +.global armv8_el2_to_aarch32 +armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200
Please comment or add a symbol for this
Quoted 5 lines
arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +2
-1+ SMC #0 + ret --2.17.1
Regards,
Simon
Re: [PATCH 02/31] arm: mediatek: add support for MediaTek MT7981 SoC
Quoted 29 lines · Simon Glass
Hi Weijie,
Quoted 21 lines · Weijie Gao
This patch adds basic support for MediaTek MT7981 SoC. This include the file that will initialize the SoC after boot and its
device tree.Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7981.dtsi | 288 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 12 +- arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7981/Makefile | 4 + arch/arm/mach-mediatek/mt7981/init.c | 52 ++++ arch/arm/mach-mediatek/mt7981/lowlevel_init.S | 30 ++ 6 files changed, 386 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[..]
Quoted 16 lines
Quoted 7 lines
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7981/init.cnew file mode 100644
index 0000000000..f503bb804barch/arm/mach-mediatek/mt7981/init.c line 7
Quoted 7 lines
arch/arm/mach-mediatek/mt7981/init.c new file +7
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h> Do you need that?
This was used during testing, and should be remove now.
Quoted 5 lines
arch/arm/mach-mediatek/mt7981/init.c line 9
Quoted 3 lines
arch/arm/mach-mediatek/mt7981/init.c new file +2
-0+#include <asm/armv8/mmu.h> +#include <init.h> Move up one
ok.
Quoted 9 lines
arch/arm/mach-mediatek/mt7981/init.c line 15
Quoted 7 lines
arch/arm/mach-mediatek/mt7981/init.c new file +6
-0+#include <asm/system.h> +#include <asm/global_data.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void )Can you use the CPU uclass and
DISPLAY_CPUINFOinstead/
Basically there's nothing to do for print_cpuinfo other than printing a fixed CPU model string. Not sure if it's worth using a CPU uclass.
Besides, Using a cpu uclass involves modifying other chips, and some of them cann't be tested by me.
Quoted 38 lines
Quoted 6 lines
arch/arm/mach-mediatek/mt7981/init.c new file +5
-0+{ +printf ("CPU: MediaTek MT7981\n" ); +return 0 ; +} +[..]
Quoted 29 lines
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7981/lowlevel_init.Snew file mode 100644
index 0000000000..244d2c1385arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +22
-0@@ -0,0 +1,30 @@ +/* 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 +*/ + +.global armv8_el2_to_aarch32
Quoted 8 lines
arch/arm/mach-mediatek/mt7981/lowlevel_init.S line 28
Quoted 6 lines
arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +6
-0+armv8_el2_to_aarch32: + mov x3, x2 + mov x2, x1 + mov x1, x4 + mov x4, #0 + ldr x0, =0x82000200Please comment or add a symbol for this
I can add the following link as a comment:
https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/m
ediatek/common/mtk_sip_svc.c#n73
Quoted 9 lines
Quoted 6 lines
arch/arm/mach-mediatek/mt7981/lowlevel_init.S new file +2
-1+ SMC #0 + ret --2.17.1
Regards,
Simon
Re: [PATCH 02/31] arm: mediatek: add support for MediaTek MT7981 SoC
Hi Weijie,
Quoted 68 lines · Weijie Gao
Quoted 29 lines · Simon Glass
Hi Weijie,
Quoted 21 lines · Weijie Gao
This patch adds basic support for MediaTek MT7981 SoC. This include the file that will initialize the SoC after boot and its
device tree.Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7981.dtsi | 288 ++++++++++++++++++ arch/arm/mach-mediatek/Kconfig | 12 +- arch/arm/mach-mediatek/Makefile | 1 + arch/arm/mach-mediatek/mt7981/Makefile | 4 + arch/arm/mach-mediatek/mt7981/init.c | 52 ++++ arch/arm/mach-mediatek/mt7981/lowlevel_init.S | 30 ++ 6 files changed, 386 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[..]
Quoted 16 lines
Quoted 7 lines
(quoted diff) +0
-0b/arch/arm/mach-mediatek/mt7981/init.cnew file mode 100644
index 0000000000..f503bb804barch/arm/mach-mediatek/mt7981/init.c line 7
Quoted 7 lines
arch/arm/mach-mediatek/mt7981/init.c new file +7
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <fdtdec.h> Do you need that?
This was used during testing, and should be remove now.
Quoted 5 lines
arch/arm/mach-mediatek/mt7981/init.c line 9
Quoted 3 lines
arch/arm/mach-mediatek/mt7981/init.c new file +2
-0+#include <asm/armv8/mmu.h> +#include <init.h> Move up one
ok.
Quoted 9 lines
arch/arm/mach-mediatek/mt7981/init.c line 15
Quoted 7 lines
arch/arm/mach-mediatek/mt7981/init.c new file +6
-0+#include <asm/system.h> +#include <asm/global_data.h> + +DECLARE_GLOBAL_DATA_PTR ; + +int print_cpuinfo (void )Can you use the CPU uclass and
DISPLAY_CPUINFOinstead/
Quoted 5 lines
Basically there's nothing to do for
print_cpuinfoother than printing a fixed CPU model string. Not sure if it's worth using a CPU uclass.Besides, Using a cpu uclass involves modifying other chips, and some of them cann't be tested by me.
Something to consider for the future as it is nice to list the CPUs and their status. You can enable CONFIG_CPU for one Soc and not another.
Regards,
Simon
PATCH 3/31 board: mediatek: add MT7986 reference boards
In reply to Weijie GaoThis patch adds general board files based on MT7986 SoCs.
The SD/eMMC controller on MT7986A and MT7986B have different pin configurations so that four different reference board configs has to be added.
--- arch/arm/dts/Makefile | 4 + arch/arm/dts/mt7986a-rfb.dts | 218 +++++++++++++++++++++++++++++ arch/arm/dts/mt7986a-sd-rfb.dts | 177 +++++++++++++++++++++++ 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_emmc_rfb_defconfig | 64 +++++++++ configs/mt7986a_sd_rfb_defconfig | 64 +++++++++ configs/mt7986b_emmc_rfb_defconfig | 64 +++++++++ configs/mt7986b_sd_rfb_defconfig | 64 +++++++++ include/configs/mt7986.h | 26 ++++ 14 files changed, 1147 insertions(+) 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-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_emmc_rfb_defconfig create mode 100644 configs/mt7986a_sd_rfb_defconfig create mode 100644 configs/mt7986b_emmc_rfb_defconfig create mode 100644 configs/mt7986b_sd_rfb_defconfig create mode 100644 include/configs/mt7986.h
arch/arm/dts/Makefile +4 -0
@@ -1226,6 +1226,10 @@ 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 \ mt8183-pumpkin.dtb \ mt8512-bm1-emmc.dtb \ mt8516-pumpkin.dtb \
arch/arm/dts/mt7986a-rfb.dts new file +218 -0
218 lines not on this page · raw message
(quoted diff) +0 -0
b/arch/arm/dts/mt7986a-sd-rfb.dts
new file mode 100644
index 0000000000..5807c5d5cc
arch/arm/dts/mt7986a-sd-rfb.dts new file +177 -0
177 lines not on this page · raw message
arch/arm/dts/mt7986b-rfb.dts new file +204 -0
204 lines not on this page · raw message
(quoted diff) +0 -0
b/arch/arm/dts/mt7986b-sd-rfb.dts
new file mode 100644
index 0000000000..48f9320e7a
arch/arm/dts/mt7986b-sd-rfb.dts new file +173 -0
173 lines not on this page · raw message
(quoted diff) +0 -0
b/board/mediatek/mt7986/MAINTAINERS
new file mode 100644
index 0000000000..fddee20001
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
(quoted diff) +0 -0
b/board/mediatek/mt7986/mt7986_rfb.c
new file mode 100644
index 0000000000..846c715ca0
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
(quoted diff) +0 -0
b/configs/mt7986a_emmc_rfb_defconfig
new file mode 100644
index 0000000000..3e368b68de
configs/mt7986a_emmc_rfb_defconfig new file +64 -0
64 lines not on this page · raw message
(quoted diff) +0 -0
b/configs/mt7986a_sd_rfb_defconfig
new file mode 100644
index 0000000000..b9a69a3d3d
configs/mt7986a_sd_rfb_defconfig new file +64 -0
64 lines not on this page · raw message
(quoted diff) +0 -0
b/configs/mt7986b_emmc_rfb_defconfig
new file mode 100644
index 0000000000..c3a72a342a
configs/mt7986b_emmc_rfb_defconfig new file +64 -0
64 lines not on this page · raw message
(quoted diff) +0 -0
b/configs/mt7986b_sd_rfb_defconfig
new file mode 100644
index 0000000000..0e5ab55ab5
configs/mt7986b_sd_rfb_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
Re: [PATCH 03/31] board: mediatek: add MT7986 reference boards
Quoted 29 lines · Weijie Gao
This patch adds general board files based on MT7986 SoCs.
The SD/eMMC controller on MT7986A and MT7986B have different pin configurations so that four different reference board configs has to be added.
Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/Makefile | 4 + arch/arm/dts/mt7986a-rfb.dts | 218 +++++++++++++++++++++++++++++ arch/arm/dts/mt7986a-sd-rfb.dts | 177 +++++++++++++++++++++++ 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_emmc_rfb_defconfig | 64 +++++++++ configs/mt7986a_sd_rfb_defconfig | 64 +++++++++ configs/mt7986b_emmc_rfb_defconfig | 64 +++++++++ configs/mt7986b_sd_rfb_defconfig | 64 +++++++++ include/configs/mt7986.h | 26 ++++ 14 files changed, 1147 insertions(+) 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-rfb.dts create mode 100644 arch/arm/dts/mt7986b-sd-rfb.dts create mode 100644 board/mediatek/mt7986/MAINTAINERS
Quoted 9 lines
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_emmc_rfb_defconfig create mode 100644 configs/mt7986a_sd_rfb_defconfig create mode 100644 configs/mt7986b_emmc_rfb_defconfig create mode 100644 configs/mt7986b_sd_rfb_defconfig create mode 100644 include/configs/mt7986.h
Re: [PATCH 03/31] board: mediatek: add MT7986 reference boards
In reply to Weijie GaoHi Weijie,
Quoted 18 lines · Weijie Gao
This patch adds general board files based on MT7986 SoCs.
The SD/eMMC controller on MT7986A and MT7986B have different pin configurations so that four different reference board configs has to be added.
Signed-off-by Weijie Gao <[email protected]>---
[...]include/configs/mt7986.h new file +3
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Configuration for MediaTek MT7986 SoC
include/configs/mt7986.h line 13
Quoted 10 lines
include/configs/mt7986.h new file +10
-0+* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#ifndef __MT7986_H +#define __MT7986_H + +#include <linux/sizes.h> +
In the SDK sources I found also
#define CONFIG_SYS_BOOTM_LEN SZ_128M
here which is actually needed to boot any image with uncompressed kernel larger than 8MiB. As for ARM64 this size is easily exceeded and we got plenty of RAM, I suggest to also include a more generous CONFIG_SYS_BOOTM_LEN in your submission to upstream U-Boot.
Quoted 16 lines
include/configs/mt7986.h new file +13
-0+#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
Re: [PATCH 03/31] board: mediatek: add MT7986 reference boards
Quoted 33 lines · Daniel Golle
Hi Weijie,
Quoted 19 lines · Weijie Gao
This patch adds general board files based on MT7986 SoCs.
The SD/eMMC controller on MT7986A and MT7986B have different pin configurations so that four different reference board configs has to be
added.Signed-off-by Weijie Gao <[email protected]>---
[...]include/configs/mt7986.h new file +3
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Configuration for MediaTek MT7986 SoC include/configs/mt7986.h line 13
Quoted 10 lines
include/configs/mt7986.h new file +10
-0+* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#ifndef __MT7986_H +#define __MT7986_H + +#include <linux/sizes.h> +
Quoted 7 lines
In the SDK sources I found also
#defineCONFIG_SYS_BOOTM_LENSZ_128M
here which is actually needed to boot any image with uncompressed kernel larger than 8MiB. As for ARM64 this size is easily exceeded and
we got plenty of RAM, I suggest to also include a more generousCONFIG_SYS_BOOTM_LENin your submission to upstream U-Boot.
CONFIG_SYS_BOOTM_LEN is now a Kconfig symbol. It will no be defined in this header.
Instead, the default value of this symbol is 0x4000000 (64M) for ARM64 which is enough for an ARM64 kernel.
Quoted 18 lines
Quoted 18 lines
include/configs/mt7986.h new file +13
-0+#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
Re: [PATCH 03/31] board: mediatek: add MT7986 reference boards
Quoted 42 lines · Weijie Gao
Quoted 33 lines · Daniel Golle
Hi Weijie,
Quoted 19 lines · Weijie Gao
This patch adds general board files based on MT7986 SoCs.
The SD/eMMC controller on MT7986A and MT7986B have different pin configurations so that four different reference board configs has to be
added.Signed-off-by Weijie Gao <[email protected]>---
[...]include/configs/mt7986.h new file +3
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Configuration for MediaTek MT7986 SoC include/configs/mt7986.h line 13
Quoted 10 lines
include/configs/mt7986.h new file +10
-0+* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#ifndef __MT7986_H +#define __MT7986_H + +#include <linux/sizes.h> +Quoted 7 lines
In the SDK sources I found also
#defineCONFIG_SYS_BOOTM_LENSZ_128M
here which is actually needed to boot any image with uncompressed kernel larger than 8MiB. As for ARM64 this size is easily exceeded and
we got plenty of RAM, I suggest to also include a more generousCONFIG_SYS_BOOTM_LENin your submission to upstream U-Boot.
Quoted 4 lines
CONFIG_SYS_BOOTM_LENis now aKconfigsymbol. It will no be defined in this header.
Instead, the default value of this symbol is0x4000000(64M) for ARM64 which is enough for an ARM64 kernel.
Sorry, I missed c45568cc4e ("Convert CONFIG_SYS_BOOTM_LEN to Kconfig") and was trying the series on top of U-Boot 2022.07 (for inclusion in OpenWrt) locally.
I've tested the whole series with Bananapi BPi-R3 (MT7986A) board.
U-Boot itself works great with all 4 boot media options. The only remaining problem is BootROM header generation using mkimage/mtk_image for SPI-NOR:
TF-A and U-Boot ithemselves both work well with SPI-NOR when using 'bromutil' to generate the image. When using 'mkimage -T mtk_image' instead of 'bromutil' the resulting bl2.img doesn't work:
F0: 102B 0000
FA: 0000 0000
V0: 7027 6006 [0001]
00: 1017 0000
FA: 5100 0000
01: 102A 0001
02: 5100 0000
BP: 2000 00C0 [0001]
EC: 0000 0000 [0000]
T0: 0000 0213 [010F]
System halt!
Cheers
Daniel
PATCH 4/31 board: mediatek: add MT7981 reference boards
In reply to Weijie GaoThis patch adds general board files based on MT7981 SoCs.
--- arch/arm/dts/Makefile | 5 + arch/arm/dts/mt7981-emmc-rfb.dts | 139 +++++++++++++++++++++++++ arch/arm/dts/mt7981-rfb.dts | 133 +++++++++++++++++++++++ arch/arm/dts/mt7981-sd-rfb.dts | 139 +++++++++++++++++++++++++ arch/arm/dts/mt7981-spim-nand-rfb.dts | 138 ++++++++++++++++++++++++ arch/arm/dts/mt7981-spim-nor-rfb.dts | 133 +++++++++++++++++++++++ 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 | 65 ++++++++++++ configs/mt7981_sd_rfb_defconfig | 64 ++++++++++++ configs/mt7981_spim_nand_rfb_defconfig | 59 +++++++++++ configs/mt7981_spim_nor_rfb_defconfig | 70 +++++++++++++ include/configs/mt7981.h | 26 +++++ 15 files changed, 1058 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 arch/arm/dts/mt7981-spim-nand-rfb.dts create mode 100644 arch/arm/dts/mt7981-spim-nor-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 configs/mt7981_spim_nand_rfb_defconfig create mode 100644 configs/mt7981_spim_nor_rfb_defconfig create mode 100644 include/configs/mt7981.h
arch/arm/dts/Makefile +5 -0
@@ -1226,6 +1226,11 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \ mt7622-bananapi-bpi-r64.dtb \ mt7623n-bananapi-bpi-r2.dtb \ mt7629-rfb.dtb \ + mt7981-rfb.dtb \ + mt7981-spim-nand-rfb.dtb \ + mt7981-spim-nor-rfb.dtb \ + mt7981-emmc-rfb.dtb \ + mt7981-sd-rfb.dtb \ mt7986a-rfb.dtb \ mt7986b-rfb.dtb \ mt7986a-sd-rfb.dtb \
(quoted diff) +0 -0
b/arch/arm/dts/mt7981-emmc-rfb.dts
new file mode 100644
index 0000000000..2b7eae99ce
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 +133 -0
133 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
(quoted diff) +0 -0
b/arch/arm/dts/mt7981-spim-nand-rfb.dts
new file mode 100644
index 0000000000..205f6deb30
arch/arm/dts/mt7981-spim-nand-rfb.dts new file +138 -0
138 lines not on this page · raw message
(quoted diff) +0 -0
b/arch/arm/dts/mt7981-spim-nor-rfb.dts
new file mode 100644
index 0000000000..ff521c38b2
arch/arm/dts/mt7981-spim-nor-rfb.dts new file +133 -0
133 lines not on this page · raw message
(quoted diff) +0 -0
b/board/mediatek/mt7981/MAINTAINERS
new file mode 100644
index 0000000000..e7592a7a54
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
(quoted diff) +0 -0
b/board/mediatek/mt7981/mt7981_rfb.c
new file mode 100644
index 0000000000..846c715ca0
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 ; +}
(quoted diff) +0 -0
b/configs/mt7981_emmc_rfb_defconfig
new file mode 100644
index 0000000000..5f9f6d8582
configs/mt7981_emmc_rfb_defconfig new file +64 -0
64 lines not on this page · raw message
configs/mt7981_rfb_defconfig new file +65 -0
65 lines not on this page · raw message
(quoted diff) +0 -0
b/configs/mt7981_sd_rfb_defconfig
new file mode 100644
index 0000000000..b5c765bd7c
configs/mt7981_sd_rfb_defconfig new file +64 -0
64 lines not on this page · raw message
(quoted diff) +0 -0
b/configs/mt7981_spim_nand_rfb_defconfig
new file mode 100644
index 0000000000..9673c3727d
configs/mt7981_spim_nand_rfb_defconfig new file +59 -0
59 lines not on this page · raw message
(quoted diff) +0 -0
b/configs/mt7981_spim_nor_rfb_defconfig
new file mode 100644
index 0000000000..e16bc40c39
configs/mt7981_spim_nor_rfb_defconfig new file +70 -0
70 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
Re: [PATCH 04/31] board: mediatek: add MT7981 reference boards
Hi Weijie,
Quoted 2 lines · Weijie Gao
This patch adds general board files based on MT7981 SoCs.
"Add general board files..." - same for other patches.
Are the dts files from a particular Linux version?
Quoted 25 lines
Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/Makefile | 5 + arch/arm/dts/mt7981-emmc-rfb.dts | 139 +++++++++++++++++++++++++ arch/arm/dts/mt7981-rfb.dts | 133 +++++++++++++++++++++++ arch/arm/dts/mt7981-sd-rfb.dts | 139 +++++++++++++++++++++++++ arch/arm/dts/mt7981-spim-nand-rfb.dts | 138 ++++++++++++++++++++++++ arch/arm/dts/mt7981-spim-nor-rfb.dts | 133 +++++++++++++++++++++++ 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 | 65 ++++++++++++ configs/mt7981_sd_rfb_defconfig | 64 ++++++++++++ configs/mt7981_spim_nand_rfb_defconfig | 59 +++++++++++ configs/mt7981_spim_nor_rfb_defconfig | 70 +++++++++++++ include/configs/mt7981.h | 26 +++++ 15 files changed, 1058 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 arch/arm/dts/mt7981-spim-nand-rfb.dts create mode 100644 arch/arm/dts/mt7981-spim-nor-rfb.dts create mode 100644 board/mediatek/mt7981/MAINTAINERS
Quoted 9 lines
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 configs/mt7981_spim_nand_rfb_defconfig create mode 100644 configs/mt7981_spim_nor_rfb_defconfig create mode 100644 include/configs/mt7981.h
Regards,
Simon
PATCH 5/31 mmc: mediatek: add support for MediaTek MT7891/MT7986 SoCs
In reply to Weijie GaoThis patch adds eMMC and SDXC support for MediaTek MT7981/MT7986 SoCs
--- 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
Re: [PATCH 05/31] mmc: mediatek: add support for MediaTek MT7891/MT7986 SoCs
Hi Weijie,
Quoted 2 lines · Weijie Gao
This patch adds eMMC and SDXC support for MediaTek MT7981/MT7986 SoCs
Add eMMC and SDXC support for MediaTek MT7981/MT7986 SoCs.
(describe your changes in imperative mood)
Quoted 6 lines
Signed-off-by Weijie Gao <[email protected]>--- drivers/mmc/mtk-sd.c | 68 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 15 deletions(-)
Regards,
Simon
Re: [PATCH 05/31] mmc: mediatek: add support for MediaTek MT7891/MT7986 SoCs
Quoted 11 lines · Simon Glass
Hi Weijie,
Quoted 3 lines · Weijie Gao
This patch adds eMMC and SDXC support for MediaTek MT7981/MT7986 SoCs
Add eMMC and SDXC support for MediaTek MT7981/MT7986 SoCs.
(describe your changes in imperative mood)
I'll change it in v2
Quoted 13 lines
Quoted 8 lines
Signed-off-by Weijie Gao <[email protected]>--- drivers/mmc/mtk-sd.c | 68 ++++++++++++++++++++++++++++++++++---- ------ 1 file changed, 53 insertions(+), 15 deletions(-)Reviewed-by Simon Glass <[email protected]>Regards,
Simon
RE: [PATCH 05/31] mmc: mediatek: add support for MediaTek MT7891/MT7986 SoCs
In reply to Weijie GaoQuoted 9 lines
-----Original Message-----
From: Weijie Gao [mailto:[email protected]]
Sent: Thursday, August 4, 2022 12:35 PM
To: [email protected]
Cc:GSS_MTK_Uboot_upstream; Peng Fan; Jaehoon Chung; Weijie Gao
Subject: [PATCH 05/31] mmc: mediatek: add support for MediaTek MT7891/MT7986 SoCs
Quoted 3 lines
This patch adds eMMC and SDXC support for MediaTek MT7981/MT7986 SoCs
Signed-off-by Weijie Gao <[email protected]>
Best Regards,
Jaehoon Chung
Quoted 124 lines
--- drivers/mmc/mtk-sd.c | 68 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 15 deletions(-)drivers/mmc/mtk-sd.c +53
-16@@ -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 }, --2.17.1
PATCH 6/31 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.
--- drivers/net/mtk_eth.c | 50 +++++++++++++++++++++++++++++-------------- drivers/net/mtk_eth.h | 25 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 17 deletions(-)
drivers/net/mtk_eth.c +34 -16
@@ -142,11 +142,9 @@ enum mtk_switch {SW_MT7531 }; -enum mtk_soc { -SOC_MT7623 , -SOC_MT7629 , -SOC_MT7622 , -SOC_MT7621 +struct mtk_soc_data { +u32 caps; +u32 ana_rgc3; };struct mtk_eth_priv {
@@ -171,7 +169,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 +677,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 +1106,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 +1179,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 +1429,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 +1546,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
Re: [PATCH 06/31] net: mediatek: use a struct to cover variations of all SoCs
Hi Weijie,
Quoted 5 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.
Quoted 8 lines
This patch introduces a struct to replace the original
mtk_socto allow the driver be able handle newer hardwares.Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 50 +++++++++++++++++++++++++++++-------------- drivers/net/mtk_eth.h | 25 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 17 deletions(-)
Quoted 7 lines
drivers/net/mtk_eth.c +0
-0@@ -142,11 +142,9 @@ enum mtk_switch {SW_MT7531
drivers/net/mtk_eth.c enum mtk_switch { · line 147
Quoted 10 lines
drivers/net/mtk_eth.c +3
-5}; -enum mtk_soc { -SOC_MT7623 , -SOC_MT7629 , -SOC_MT7622 , -SOC_MT7621 +struct mtk_soc_data { +u32 caps; +u32 ana_rgc3;
please comment these
[..]
Regards,
Simon
Re: [PATCH 06/31] net: mediatek: use a struct to cover variations of all SoCs
Quoted 33 lines · Simon Glass
Hi Weijie,
Quoted 11 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.Quoted 6 lines
Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 50 +++++++++++++++++++++++++++++-------- ------ drivers/net/mtk_eth.h | 25 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 17 deletions(-)Reviewed-by Simon Glass <[email protected]>Quoted 9 lines
drivers/net/mtk_eth.c +0
-0@@ -142,11 +142,9 @@ enum mtk_switch { SW_MT7531 };
Quoted 11 lines
drivers/net/mtk_eth.c enum mtk_switch { · line 147
Quoted 8 lines
drivers/net/mtk_eth.c +3
-5-enum mtk_soc { -SOC_MT7623 , -SOC_MT7629 , -SOC_MT7622 , -SOC_MT7621 +struct mtk_soc_data { +u32 caps; +u32 ana_rgc3;please comment these
[..]
OK.
Quoted 3 lines
Regards,
Simon
PATCH 7/31 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.
--- drivers/net/mtk_eth.c | 144 ++++++++++++++---------------------------- drivers/net/mtk_eth.h | 32 ++++++++++ 2 files changed, 80 insertions(+), 96 deletions(-)
drivers/net/mtk_eth.c +19 -82
@@ -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,
@@ -145,13 +74,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;
@@ -1196,14 +1127,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 ));
@@ -1212,17 +1145,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 ; }
@@ -1309,20 +1246,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);
@@ -1334,16 +1273,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));
@@ -1357,10 +1300,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;
@@ -1387,11 +1331,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 */
@@ -1548,18 +1492,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
Re: [PATCH 07/31] net: mediatek: stop using bitfileds for DMA descriptors
Quoted 10 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.
Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 144 ++++++++++++++---------------------------- drivers/net/mtk_eth.h | 32 ++++++++++ 2 files changed, 80 insertions(+), 96 deletions(-)
Re: [PATCH 07/31] net: mediatek: stop using bitfileds for DMA descriptors
In reply to Weijie GaoQuoted 321 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.
Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 144 ++++++++++++++---------------------------- drivers/net/mtk_eth.h | 32 ++++++++++ 2 files changed, 80 insertions(+), 96 deletions(-)drivers/net/mtk_eth.c +25
-86@@ -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,@@ -145,13 +74,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;@@ -1196,14 +1127,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 ));@@ -1212,17 +1145,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 ; }@@ -1309,20 +1246,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);drivers/net/mtk_eth.c +11
-6@@ -1334,16 +1273,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 ));@@ -1357,10 +1300,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;drivers/net/mtk_eth.c +12
-4@@ -1387,11 +1331,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 */ @@ -1548,18 +1492,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
Commit topic has typo in fields
Re: [PATCH 07/31] net: mediatek: stop using bitfileds for DMA descriptors
Quoted 351 lines · Ramon Fried
Quoted 349 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.Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 144 ++++++++++++++---------------------- ------ drivers/net/mtk_eth.h | 32 ++++++++++ 2 files changed, 80 insertions(+), 96 deletions(-)drivers/net/mtk_eth.c +4
-73@@ -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,@@ -145,13 +74,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;drivers/net/mtk_eth.c +3
-3@@ -1196,14 +1127,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-Quoted 1 line
txd_size);+ memset(priv->rx_ring_noc, 0,
NUM_RX_DESC* priv->soc-Quoted 1 line
rxd_size);drivers/net/mtk_eth.c +1
-0+memset (priv->pkt_pool,0xff ,TOTAL_PKT_BUF_SIZE );flush_dcache_range ((ulong )pkt_base, (ulong)(pkt_base +TOTAL_PKT_BUF_SIZE ));@@ -1212,17 +1145,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++) {drivers/net/mtk_eth.c +0
-3- 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-Quoted 1 line
gmac_id+ 1;drivers/net/mtk_eth.c +5
-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);drivers/net/mtk_eth.c +11
-4+ 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 ; }@@ -1309,20 +1246,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-Quoted 1 line
tx_cpu_owner_idx0);drivers/net/mtk_eth.c +4
-3@@ -1334,16 +1273,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-Quoted 1 line
rx_ring_noc[idx].rxd_info1.PDP0);
drivers/net/mtk_eth.c +3
-0+ 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));drivers/net/mtk_eth.c +4
-3@@ -1357,10 +1300,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;drivers/net/mtk_eth.c +4
-4@@ -1387,11 +1331,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 */drivers/net/mtk_eth.c +8
-0@@ -1548,18 +1492,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_idmtk_eth_ids[] = {drivers/net/mtk_eth.h +30
-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
Quoted 8 lines
Quoted 6 lines
PDMA_RXD2_PLEN0_SET(_v)FIELD_PREP(PDMA_RXD2_PLEN0_M, (_v))
+
#endif /* _MTK_ETH_H_ */
--
2.17.1Commit topic has typo in fields
That's a mistake. I'll fix it in v2.
PATCH 8/31 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.
--- drivers/net/mtk_eth.c | 51 ++++++++++++++++++++++++++++++----------- drivers/net/mtk_eth.h | 53 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 83 insertions(+), 21 deletions(-)
drivers/net/mtk_eth.c +10 -5
@@ -74,6 +74,7 @@ enum mtk_switch {struct mtk_soc_data {u32 caps;u32 ana_rgc3; +u32 pdma_base;u32 txd_size;u32 rxd_size; };
@@ -124,13 +125,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,
@@ -1127,8 +1128,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 );
@@ -1149,7 +1150,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 ;
}
@@ -1158,7 +1163,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;
}
@@ -1187,6 +1196,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);
@@ -1221,7 +1233,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);
}
@@ -1246,7 +1258,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;
@@ -1261,7 +1273,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);
@@ -1273,7 +1288,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;
@@ -1284,7 +1299,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 +
@@ -1300,11 +1318,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;
@@ -1492,24 +1513,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
Re: [PATCH 08/31] net: mediatek: add support for PDMA v2
Quoted 10 lines · Weijie Gao
This 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.
Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 51 ++++++++++++++++++++++++++++++----------- drivers/net/mtk_eth.h | 53 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 83 insertions(+), 21 deletions(-)
Ramon Fried
Reviewed-byRe: [PATCH 08/31] net: mediatek: add support for PDMA v2
Quoted 7 lines · Simon Glass
Quoted 5 lines · Weijie Gao
This 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.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 51 ++++++++++++++++++++++++++++++----------- drivers/net/mtk_eth.h | 53 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 83 insertions(+), 21 deletions(-)Reviewed-by Simon Glass <[email protected]>
PATCH 9/31 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.
--- drivers/net/mtk_eth.c | 27 +++++++++++++++++++++++++++ drivers/net/mtk_eth.h | 5 +++++ 2 files changed, 32 insertions(+)
drivers/net/mtk_eth.c +27 -0
@@ -106,6 +106,7 @@ struct mtk_eth_priv {int force_mode;int speed;int duplex; +bool pn_swap;struct phy_device *phydev;int phy_interface;
@@ -1048,6 +1049,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 );
@@ -1461,6 +1468,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 */
@@ -1511,6 +1520,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 ,
@@ -1540,6 +1565,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
Re: [PATCH 09/31] net: mediatek: add support for MediaTek MT7981/MT7986
Quoted 100 lines · Weijie Gao
This patch adds support for MediaTek MT7981 and MT7986. Both chips uses PDMA v2.
Signed-off-by Weijie Gao <[email protected]>--- drivers/net/mtk_eth.c | 27 +++++++++++++++++++++++++++ drivers/net/mtk_eth.h | 5 +++++ 2 files changed, 32 insertions(+)drivers/net/mtk_eth.c +27
-0@@ -106,6 +106,7 @@ struct mtk_eth_priv {int force_mode;int speed;int duplex; +bool pn_swap;struct phy_device *phydev;int phy_interface;@@ -1048,6 +1049,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 );@@ -1461,6 +1468,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 */ @@ -1511,6 +1520,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 ,@@ -1540,6 +1565,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
-1@@ -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) --
Quoted 2 lines
2.17.1
PATCH 10/31 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().
--- drivers/serial/serial_mtk.c | 72 ++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 33 deletions(-)
drivers/serial/serial_mtk.c +10 -7
@@ -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>
@@ -72,25 +73,27 @@ struct mtk_serial_regs {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, +u32 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 +107,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 +115,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 +170,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 +219,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 +227,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 +277,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 +286,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 +433,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
Re: [PATCH 10/31] serial: mtk: add support for using dynamic baud clock souce
Hi Weijie,
Quoted 6 lines · Weijie Gao
The 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.
Quoted 8 lines
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().Signed-off-by Weijie Gao <[email protected]>--- drivers/serial/serial_mtk.c | 72 ++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 33 deletions(-)
please see below
Quoted 14 lines
drivers/serial/serial_mtk.c +1
-0@@ -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>
drivers/serial/serial_mtk.c struct mtk_serial_regs { · line 74
Quoted 2 lines
drivers/serial/serial_mtk.c +0
-0@@ -72,25 +73,27 @@ struct mtk_serial_regs {struct mtk_serial_priv {
please add a full comment for this struct
drivers/serial/serial_mtk.c struct mtk_serial_regs { · line 82
Quoted 10 lines
drivers/serial/serial_mtk.c +4
-2struct 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, +u32 clk_rate)
Why u32? Can you use uint? Generally it is better for parameters to use natural types unless there is a good reason.
[..]
Regards,
Simon
Re: [PATCH 10/31] serial: mtk: add support for using dynamic baud clock souce
Quoted 45 lines · Simon Glass
Hi Weijie,
Quoted 15 lines · Weijie Gao
The 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().Quoted 5 lines
Signed-off-by Weijie Gao <[email protected]>--- drivers/serial/serial_mtk.c | 72 ++++++++++++++++++++------------- ---- 1 file changed, 39 insertions(+), 33 deletions(-)Reviewed-by Simon Glass <[email protected]>please see below
Quoted 16 lines
drivers/serial/serial_mtk.c +1
-0@@ -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> @@ -72,25 +73,27 @@ struct mtk_serial_regs {
Quoted 3 lines
drivers/serial/serial_mtk.c struct mtk_serial_regs { · line 74
Quoted 1 line
drivers/serial/serial_mtk.c +0
-0struct mtk_serial_priv {please add a full comment for this struct
OK.
Quoted 8 lines
Quoted 8 lines
drivers/serial/serial_mtk.c +2
-1struct mtk_serial_regs __iomem *regs; -u32 clock; +struct clk clk; +u32 fixed_clk_rate;bool force_highspeed; };
Quoted 8 lines
drivers/serial/serial_mtk.c struct mtk_serial_regs { · line 84
Quoted 5 lines
drivers/serial/serial_mtk.c +2
-1-static void _mtk_serial_setbrg(struct mtk_serial_priv *priv, int baud) +static void _mtk_serial_setbrg(struct mtk_serial_priv *priv, int baud, +u32 clk_rate)Why u32? Can you use uint? Generally it is better for parameters to use natural types unless there is a good reason.
In fact u32 is identical to uint.
<asm-generic/int-ll64.h>: typedef __u32 u32; <asm-generic/int-ll64.h>: typedef unsigned int __u32;
<linux/types.h>: typedef unsigned int uint;
Quoted 5 lines
[..]
Regards,
Simon
Re: [PATCH 10/31] serial: mtk: add support for using dynamic baud clock souce
Hi Weijie,
Quoted 70 lines · Weijie Gao
Quoted 45 lines · Simon Glass
Hi Weijie,
Quoted 15 lines · Weijie Gao
The 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().Quoted 5 lines
Signed-off-by Weijie Gao <[email protected]>--- drivers/serial/serial_mtk.c | 72 ++++++++++++++++++++------------- ---- 1 file changed, 39 insertions(+), 33 deletions(-)Reviewed-by Simon Glass <[email protected]>please see below
Quoted 16 lines
drivers/serial/serial_mtk.c +1
-0@@ -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> @@ -72,25 +73,27 @@ struct mtk_serial_regs {Quoted 3 lines
drivers/serial/serial_mtk.c struct mtk_serial_regs { · line 74
Quoted 1 line
drivers/serial/serial_mtk.c +0
-0struct mtk_serial_priv {please add a full comment for this struct
OK.
Quoted 8 lines
Quoted 8 lines
drivers/serial/serial_mtk.c +2
-1struct mtk_serial_regs __iomem *regs; -u32 clock; +struct clk clk; +u32 fixed_clk_rate;bool force_highspeed; };Quoted 8 lines
drivers/serial/serial_mtk.c struct mtk_serial_regs { · line 84
Quoted 5 lines
drivers/serial/serial_mtk.c +2
-1-static void _mtk_serial_setbrg(struct mtk_serial_priv *priv, int baud) +static void _mtk_serial_setbrg(struct mtk_serial_priv *priv, int baud, +u32 clk_rate)Why u32? Can you use uint? Generally it is better for parameters to use natural types unless there is a good reason.
Quoted 6 lines
In fact u32 is identical to uint.
<
asm-generic/int-ll64.h>: typedef__u32u32; <asm-generic/int-ll64.h>: typedef unsigned int__u32;<
linux/types.h>: typedef unsigned int uint;
It's not about the eventual type...if u32 is the same as uint, why not just use uint? It is simpler and does the right thing on 64-bit, where u32 is different. The clock interface uses long. In some cases the compiler must mask the values so it adds to code size.
Regards,
SImon
PATCH 11/31 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.
--- 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
Re: [PATCH 11/31] arm: dts: mt7622: force high-speed mode for uart
Quoted 10 lines · Weijie Gao
The 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.
Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7622.dtsi | 1 + 1 file changed, 1 insertion(+)
PATCH 12/31 pwm: mtk: add support for MediaTek MT7986 SoC
In reply to Weijie GaoThis patch adds PWM support for MediaTek MT7986 SoC.
--- 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
Re: [PATCH 12/31] pwm: mtk: add support for MediaTek MT7986 SoC
Quoted 7 lines · Weijie Gao
This patch adds PWM support for MediaTek MT7986 SoC.
Signed-off-by Weijie Gao <[email protected]>--- drivers/pwm/pwm-mtk.c | 6 ++++++ 1 file changed, 6 insertions(+)
PATCH 13/31 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.
--- drivers/pwm/pwm-mtk.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
drivers/pwm/pwm-mtk.c +21 -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
Re: [PATCH 13/31] pwm: mtk: add support for MediaTek MT7981 SoC
Quoted 9 lines · Weijie Gao
This 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.Signed-off-by Weijie Gao <[email protected]>--- drivers/pwm/pwm-mtk.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
PATCH 14/31 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.
--- 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
Re: [PATCH 14/31] timer: mtk: add support for MediaTek MT7981/MT7986 SoCs
Quoted 10 lines · Weijie Gao
This 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.
Signed-off-by Weijie Gao <[email protected]>--- drivers/timer/mtk_timer.c | 59 ++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 22 deletions(-)
PATCH 15/31 watchdog: mediatek: add support for MediaTek MT7986 SoC
In reply to Weijie GaoThis patch adds watchdog support for MediaTek MT7986 SoC
--- 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
Re: [PATCH 15/31] watchdog: mediatek: add support for MediaTek MT7986 SoC
Quoted 7 lines · Weijie Gao
This patch adds watchdog support for MediaTek MT7986 SoC
Signed-off-by Weijie Gao <[email protected]>--- drivers/watchdog/mtk_wdt.c | 1 + 1 file changed, 1 insertion(+)
PATCH 16/31 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.
--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/mtk_spim.c | 705 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 714 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 +620 -0
620 lines not on this page · raw message
*dev)
+{
+ int ret;
+
+ priv->hw_cap.need_pad_sel = dev_read_bool(dev, "need_pad_sel");
+ priv->hw_cap.must_tx = dev_read_bool(dev, "must_tx");
+ priv->hw_cap.enhance_timing = dev_read_bool(dev, "enhance_timing");
+ priv->hw_cap.dma_ext = dev_read_bool(dev, "dma_ext");
+ priv->hw_cap.ipm_design = dev_read_bool(dev, "ipm_design");
+ priv->hw_cap.support_quad = dev_read_bool(dev, "support_quad");
+
+ ret = dev_read_u32(dev, "tick_dly", &priv->tick_dly);
+ if (ret < 0)
+ dev_err(priv->dev, "tick dly not set.\n");
+
+ ret = dev_read_u32(dev, "sample_sel", &priv->sample_sel);
+ if (ret < 0)
+ dev_err(priv->dev, "sample sel not set.\n");
+
+ return ret;
+}
+
+static int mtk_spim_probe(struct udevice *dev)
+{
+ struct mtk_spim_priv *priv = dev_get_priv(dev);
+ int ret;
+
+ priv->base = (void __iomem *)devfdt_get_addr(dev);
+ if (!priv->base)
+ return -EINVAL;
+
+ mtk_spim_get_attr(priv, dev);
+
+ ret = clk_get_by_name(dev, "sel-clk", &priv->sel_clk);
+ if (ret < 0) {
+ dev_err(dev, "failed to get sel-clk\n");
+ return ret;
+ }
+
+ ret = clk_get_by_name(dev, "spi-clk", &priv->spi_clk);
+ if (ret < 0) {
+ dev_err(dev, "failed to get spi-clk\n");
+ return ret;
+ }
+
+ clk_enable(&priv->sel_clk);
+ clk_enable(&priv->spi_clk);
+
+ return 0;
+}
+
+static int mtk_spim_set_speed(struct udevice *dev, uint speed) +{
+ return 0;
+}
+
+static int mtk_spim_set_mode(struct udevice *dev, uint mode) +{
+ return 0;
+}
+
+static const struct spi_controller_mem_ops mtk_spim_mem_ops = {
+ .adjust_op_size = mtk_spim_adjust_op_size,
+ .supports_op = mtk_spim_supports_op,
+ .exec_op = mtk_spim_exec_op
+};
+
+static const struct dm_spi_ops mtk_spim_ops = {
+ .mem_ops = &mtk_spim_mem_ops,
+ .set_speed = mtk_spim_set_speed,
+ .set_mode = mtk_spim_set_mode,
+};
+
+static const struct udevice_id mtk_spim_ids[] = {
+ { .compatible = "mediatek,ipm-spi" },
+ {}
+};
+
+U_BOOT_DRIVER(mtk_spim) = {
+ .name = "mtk_spim",
+ .id = UCLASS_SPI,
+ .of_match = mtk_spim_ids,
+ .ops = &mtk_spim_ops,
+ .priv_auto = sizeof(struct mtk_spim_priv),
+ .probe = mtk_spim_probe,
+};
Signature · 1 line
2.17.1
Re: [PATCH 16/31] spi: add support for MediaTek spi-mem controller
Hi Weijie,
Quoted 11 lines · Weijie Gao
This patch adds support for spi-mem controller found on newer MediaTek SoCs This controller supports Single/Dual/Quad SPI mode.
Signed-off-by SkyLake.Huang <[email protected]>--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/mtk_spim.c | 705 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 714 insertions(+) create mode 100644 drivers/spi/mtk_spim.c
[..]
Quoted 20 lines
drivers/spi/mtk_spim.c new file +14
-0@@ -0,0 +1,705 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 MediaTek Inc. All Rights Reserved. +* +* Author: SkyLake.Huang <[email protected]> +*/ + +#include <clk.h> +#include <cpu_func.h> +#include <div64.h> +#include <dm.h> +#include <dm/device.h> +#include <dm/device_compat.h> +#include <dm/devres.h>
drivers/spi/mtk_spim.c line 24
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+#include <dm/pinctrl.h> +#include <linux/bitops.h> +#include <linux/completion.h> +#include <linux/dma-mapping.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <spi.h> +#include <spi-mem.h> +#include <stdbool.h> +#include <watchdog.h>
Please check header order:
https://u-boot.readthedocs.io/en/latest/develop/codingstyle.html#include-files
Quoted 97 lines
drivers/spi/mtk_spim.c new file +97
-0+ +#define SPI_CFG0_REG 0x0000 +#define SPI_CFG1_REG 0x0004 +#define SPI_TX_SRC_REG 0x0008 +#define SPI_RX_DST_REG 0x000c +#define SPI_TX_DATA_REG 0x0010 +#define SPI_RX_DATA_REG 0x0014 +#define SPI_CMD_REG 0x0018 +#define SPI_IRQ_REG 0x001c +#define SPI_STATUS_REG 0x0020 +#define SPI_PAD_SEL_REG 0x0024 +#define SPI_CFG2_REG 0x0028 +#define SPI_TX_SRC_REG_64 0x002c +#define SPI_RX_DST_REG_64 0x0030 +#define SPI_CFG3_IPM_REG 0x0040 + +#define SPI_CFG0_SCK_HIGH_OFFSET 0 +#define SPI_CFG0_SCK_LOW_OFFSET 8 +#define SPI_CFG0_CS_HOLD_OFFSET 16 +#define SPI_CFG0_CS_SETUP_OFFSET 24 +#define SPI_ADJUST_CFG0_CS_HOLD_OFFSET 0 +#define SPI_ADJUST_CFG0_CS_SETUP_OFFSET 16 + +#define SPI_CFG1_CS_IDLE_OFFSET 0 +#define SPI_CFG1_PACKET_LOOP_OFFSET 8 +#define SPI_CFG1_PACKET_LENGTH_OFFSET 16 +#define SPI_CFG1_GET_TICKDLY_OFFSET 29 + +#define SPI_CFG1_GET_TICKDLY_MASK GENMASK(31, 29) +#define SPI_CFG1_CS_IDLE_MASK 0xff +#define SPI_CFG1_PACKET_LOOP_MASK 0xff00 +#define SPI_CFG1_PACKET_LENGTH_MASK 0x3ff0000 +#define SPI_CFG1_IPM_PACKET_LENGTH_MASK GENMASK(31, 16) +#define SPI_CFG2_SCK_HIGH_OFFSET 0 +#define SPI_CFG2_SCK_LOW_OFFSET 16 +#define SPI_CFG2_SCK_HIGH_MASK GENMASK(15, 0) +#define SPI_CFG2_SCK_LOW_MASK GENMASK(31, 16) + +#define SPI_CMD_ACT BIT(0) +#define SPI_CMD_RESUME BIT(1) +#define SPI_CMD_RST BIT(2) +#define SPI_CMD_PAUSE_EN BIT(4) +#define SPI_CMD_DEASSERT BIT(5) +#define SPI_CMD_SAMPLE_SEL BIT(6) +#define SPI_CMD_CS_POL BIT(7) +#define SPI_CMD_CPHA BIT(8) +#define SPI_CMD_CPOL BIT(9) +#define SPI_CMD_RX_DMA BIT(10) +#define SPI_CMD_TX_DMA BIT(11) +#define SPI_CMD_TXMSBF BIT(12) +#define SPI_CMD_RXMSBF BIT(13) +#define SPI_CMD_RX_ENDIAN BIT(14) +#define SPI_CMD_TX_ENDIAN BIT(15) +#define SPI_CMD_FINISH_IE BIT(16) +#define SPI_CMD_PAUSE_IE BIT(17) +#define SPI_CMD_IPM_NONIDLE_MODE BIT(19) +#define SPI_CMD_IPM_SPIM_LOOP BIT(21) +#define SPI_CMD_IPM_GET_TICKDLY_OFFSET 22 + +#define SPI_CMD_IPM_GET_TICKDLY_MASK GENMASK(24, 22) + +#define PIN_MODE_CFG (x) ((x) / 2) + +#define SPI_CFG3_IPM_PIN_MODE_OFFSET 0 +#define SPI_CFG3_IPM_HALF_DUPLEX_DIR BIT(2) +#define SPI_CFG3_IPM_HALF_DUPLEX_EN BIT(3) +#define SPI_CFG3_IPM_XMODE_EN BIT(4) +#define SPI_CFG3_IPM_NODATA_FLAG BIT(5) +#define SPI_CFG3_IPM_CMD_BYTELEN_OFFSET 8 +#define SPI_CFG3_IPM_ADDR_BYTELEN_OFFSET 12 +#define SPI_CFG3_IPM_DUMMY_BYTELEN_OFFSET 16 + +#define SPI_CFG3_IPM_CMD_PIN_MODE_MASK GENMASK(1, 0) +#define SPI_CFG3_IPM_CMD_BYTELEN_MASK GENMASK(11, 8) +#define SPI_CFG3_IPM_ADDR_BYTELEN_MASK GENMASK(15, 12) +#define SPI_CFG3_IPM_DUMMY_BYTELEN_MASK GENMASK(19, 16) + +#define MT8173_SPI_MAX_PAD_SEL 3 + +#define MTK_SPI_PAUSE_INT_STATUS 0x2 + +#define MTK_SPI_IDLE 0 +#define MTK_SPI_PAUSED 1 + +#define MTK_SPI_MAX_FIFO_SIZE 32U +#define MTK_SPI_PACKET_SIZE 1024 +#define MTK_SPI_IPM_PACKET_SIZE SZ_64K +#define MTK_SPI_IPM_PACKET_LOOP SZ_256 + +#define MTK_SPI_32BITS_MASK 0xffffffff + +#define DMA_ADDR_EXT_BITS 36 +#define DMA_ADDR_DEF_BITS 32 + +#define CLK_TO_US (freq, clkcnt) DIV_ROUND_UP((clkcnt), (freq) / 1000000) + +struct mtk_spim_capability {
drivers/spi/mtk_spim.c line 131
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+bool need_pad_sel; +/* Must explicitly send dummy Tx bytes to do Rx only transfer */ +bool must_tx; +/* some IC design adjust cfg register to enhance time accuracy */ +bool enhance_timing; +/* some IC support DMA addr extension */ +bool dma_ext; +/* the IPM IP design improve some feature, and support dual/quad mode */ +bool ipm_design; +bool support_quad;
comment?
drivers/spi/mtk_spim.c line 134
Quoted 3 lines
drivers/spi/mtk_spim.c new file +3
-0+}; + +struct mtk_spim_priv {
Needs comments
Quoted 19 lines
drivers/spi/mtk_spim.c new file +19
-0+void __iomem *base; +u32 state; +int pad_num; +u32 *pad_sel; +struct clk sel_clk, spi_clk; +struct spi_transfer *cur_transfer; +u32 xfer_len; +u32 num_xfered; +struct scatterlist *tx_sgl, *rx_sgl; +u32 tx_sgl_len, rx_sgl_len; +struct mtk_spim_capability hw_cap; +u32 tick_dly; +u32 sample_sel; + +struct completion spimem_done; +bool use_spimem; +struct device *dev; +dma_addr_t tx_dma; +dma_addr_t rx_dma;
drivers/spi/mtk_spim.c line 163
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+}; + +static void mtk_spim_reset (struct mtk_spim_priv *priv) +{ +u32 reg_val; + +/* set the software reset bit in SPI_CMD_REG. */ + reg_val =readl (priv->base +SPI_CMD_REG ); + reg_val |=SPI_CMD_RST ; +writel (reg_val, priv->base +SPI_CMD_REG );
set_le32()
drivers/spi/mtk_spim.c line 166
Quoted 3 lines
drivers/spi/mtk_spim.c new file +3
-0+ + reg_val =readl (priv->base +SPI_CMD_REG ); + reg_val &= ~SPI_CMD_RST ;
clear_le32()
Quoted 54 lines
drivers/spi/mtk_spim.c new file +54
-0+writel (reg_val, priv->base +SPI_CMD_REG ); +} + +static int mtk_spim_hw_init (struct spi_slave *slave) +{ +struct udevice *bus =dev_get_parent (slave->dev); +struct mtk_spim_priv *priv =dev_get_priv (bus); +u16 cpha, cpol; +u32 reg_val; + + cpha = slave->mode &SPI_CPHA ?1 :0 ; + cpol = slave->mode &SPI_CPOL ?1 :0 ; + +if (priv->hw_cap.enhance_timing) { +if (priv->hw_cap.ipm_design) { +/* CFG3 reg only used for spi-mem, +* here write to default value +*/ +writel (0x0 , priv->base +SPI_CFG3_IPM_REG ); + + reg_val =readl (priv->base +SPI_CMD_REG ); + reg_val &= ~SPI_CMD_IPM_GET_TICKDLY_MASK ; + reg_val |= priv->tick_dly + <<SPI_CMD_IPM_GET_TICKDLY_OFFSET ; +writel (reg_val, priv->base +SPI_CMD_REG ); + }else { + reg_val =readl (priv->base +SPI_CFG1_REG ); + reg_val &= ~SPI_CFG1_GET_TICKDLY_MASK ; + reg_val |= priv->tick_dly + <<SPI_CFG1_GET_TICKDLY_OFFSET ; +writel (reg_val, priv->base +SPI_CFG1_REG ); + } + } + + reg_val =readl (priv->base +SPI_CMD_REG ); +if (priv->hw_cap.ipm_design) { +/* SPI transfer without idle time until packet length done */ + reg_val |=SPI_CMD_IPM_NONIDLE_MODE ; +if (slave->mode &SPI_LOOP ) + reg_val |=SPI_CMD_IPM_SPIM_LOOP ; +else + reg_val &= ~SPI_CMD_IPM_SPIM_LOOP ; + } + +if (cpha) + reg_val |=SPI_CMD_CPHA ; +else + reg_val &= ~SPI_CMD_CPHA ; +if (cpol) + reg_val |=SPI_CMD_CPOL ; +else + reg_val &= ~SPI_CMD_CPOL ; + +/* set the mlsbx and mlsbtx */
drivers/spi/mtk_spim.c line 230
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+if (slave->mode &SPI_LSB_FIRST ) { + reg_val &= ~SPI_CMD_TXMSBF ; + reg_val &= ~SPI_CMD_RXMSBF ; + }else { + reg_val |=SPI_CMD_TXMSBF ; + reg_val |=SPI_CMD_RXMSBF ; + } + +/* set the tx/rx endian */ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
Can this be done with the compatible string?
Quoted 19 lines
drivers/spi/mtk_spim.c new file +19
-0+ reg_val &= ~SPI_CMD_TX_ENDIAN ; + reg_val &= ~SPI_CMD_RX_ENDIAN ; +#else + reg_val |=SPI_CMD_TX_ENDIAN ; + reg_val |=SPI_CMD_RX_ENDIAN ; +#endif + +if (priv->hw_cap.enhance_timing) { +/* set CS polarity */ +if (slave->mode &SPI_CS_HIGH ) + reg_val |=SPI_CMD_CS_POL ; +else + reg_val &= ~SPI_CMD_CS_POL ; + +if (priv->sample_sel) + reg_val |=SPI_CMD_SAMPLE_SEL ; +else + reg_val &= ~SPI_CMD_SAMPLE_SEL ; + }
drivers/spi/mtk_spim.c line 259
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+ +/* disable dma mode */ + reg_val &= ~(SPI_CMD_TX_DMA |SPI_CMD_RX_DMA ); + +/* disable deassert mode */ + reg_val &= ~SPI_CMD_DEASSERT ; + +writel (reg_val, priv->base +SPI_CMD_REG ); + +#if !CONFIG_IS_ENABLED (DM_SPI )
Should use DM_SPI always
Quoted 16 lines
drivers/spi/mtk_spim.c new file +16
-0+/* pad select, we don't need this in IPM design. */ +if (priv->hw_cap.need_pad_sel) +writel (priv->pad_sel[slave->cs], + priv->base +SPI_PAD_SEL_REG ); +#endif + +return 0 ; +} + +static void mtk_spim_prepare_transfer (struct mtk_spim_priv *priv, +u32 speed_hz) +{ +u32 spi_clk_hz, div, sck_time, cs_time, reg_val; + + spi_clk_hz =clk_get_rate (&priv->spi_clk); +if (speed_hz <= spi_clk_hz /4 )
drivers/spi/mtk_spim.c line 285
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+ div =DIV_ROUND_UP (spi_clk_hz, speed_hz); + else + div =4 ; + + sck_time = (div +1 ) /2 ; + cs_time = sck_time *2 ; + +if (priv->hw_cap.enhance_timing) { + reg_val = (((sck_time -1 ) &0xffff ) + <<SPI_CFG2_SCK_HIGH_OFFSET );
Drop outer brackets, and below also
Quoted 14 lines
drivers/spi/mtk_spim.c new file +14
-0+ reg_val |= (((sck_time -1 ) &0xffff ) + <<SPI_CFG2_SCK_LOW_OFFSET ); +writel (reg_val, priv->base +SPI_CFG2_REG ); + reg_val = (((cs_time -1 ) &0xffff ) + <<SPI_ADJUST_CFG0_CS_HOLD_OFFSET ); + reg_val |= (((cs_time -1 ) &0xffff ) + <<SPI_ADJUST_CFG0_CS_SETUP_OFFSET ); +writel (reg_val, priv->base +SPI_CFG0_REG ); + }else { + reg_val = (((sck_time -1 ) &0xff ) + <<SPI_CFG0_SCK_HIGH_OFFSET ); + reg_val |= (((sck_time -1 ) &0xff ) <<SPI_CFG0_SCK_LOW_OFFSET ); + reg_val |= (((cs_time -1 ) &0xff ) <<SPI_CFG0_CS_HOLD_OFFSET ); + reg_val |= (((cs_time -1 ) &0xff ) <<SPI_CFG0_CS_SETUP_OFFSET );
drivers/spi/mtk_spim.c line 309
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+writel (reg_val, priv->base +SPI_CFG0_REG ); + } + + reg_val =readl (priv->base +SPI_CFG1_REG ); + reg_val &= ~SPI_CFG1_CS_IDLE_MASK ; + reg_val |= (((cs_time -1 ) &0xff ) <<SPI_CFG1_CS_IDLE_OFFSET ); +writel (reg_val, priv->base +SPI_CFG1_REG ); +} + +static void mtk_spim_setup_packet (struct mtk_spim_priv *priv)
comment? What doe sthis function do?
Quoted 63 lines
drivers/spi/mtk_spim.c new file +63
-0+{ +u32 packet_size, packet_loop, reg_val; + +if (priv->hw_cap.ipm_design) + packet_size =min_t (u32, + priv->xfer_len, +MTK_SPI_IPM_PACKET_SIZE ); +else + packet_size =min_t (u32, + priv->xfer_len, +MTK_SPI_PACKET_SIZE ); + + packet_loop = priv->xfer_len / packet_size; + + reg_val =readl (priv->base +SPI_CFG1_REG ); +if (priv->hw_cap.ipm_design) + reg_val &= ~SPI_CFG1_IPM_PACKET_LENGTH_MASK ; +else + reg_val &= ~SPI_CFG1_PACKET_LENGTH_MASK ; + + reg_val |= (packet_size -1 ) <<SPI_CFG1_PACKET_LENGTH_OFFSET ; + + reg_val &= ~SPI_CFG1_PACKET_LOOP_MASK ; + + reg_val |= (packet_loop -1 ) <<SPI_CFG1_PACKET_LOOP_OFFSET ; + +writel (reg_val, priv->base +SPI_CFG1_REG ); +} + +static void mtk_spim_enable_transfer (struct mtk_spim_priv *priv) +{ +u32 cmd; + + cmd =readl (priv->base +SPI_CMD_REG ); +if (priv->state ==MTK_SPI_IDLE ) + cmd |=SPI_CMD_ACT ; +else + cmd |=SPI_CMD_RESUME ; +writel (cmd, priv->base +SPI_CMD_REG ); +} + +static bool mtk_spim_supports_op (struct spi_slave *slave, +const struct spi_mem_op *op) +{ +if (op->cmd.buswidth ==0 || op->cmd.buswidth >4 || + op->addr.buswidth >4 || op->dummy.buswidth >4 || + op->data.buswidth >4 ) +return false; + +if (op->addr.nbytes && op->dummy.nbytes && + op->addr.buswidth != op->dummy.buswidth) +return false; + +if (op->addr.nbytes + op->dummy.nbytes >16 ) +return false; + +if (op->data.nbytes >MTK_SPI_IPM_PACKET_SIZE ) { +if (op->data.nbytes /MTK_SPI_IPM_PACKET_SIZE > +MTK_SPI_IPM_PACKET_LOOP || + op->data.nbytes %MTK_SPI_IPM_PACKET_SIZE !=0 ) +return false; + } +
drivers/spi/mtk_spim.c line 382
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+return true; +} + +static void mtk_spim_setup_dma_xfer (struct mtk_spim_priv *priv, +const struct spi_mem_op *op) +{ +writel ((u32)(priv->tx_dma &MTK_SPI_32BITS_MASK ), + priv->base +SPI_TX_SRC_REG ); + +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
I'm not sure if there is a way to avoid an #ifdef here?
Quoted 132 lines
drivers/spi/mtk_spim.c new file +132
-0+if (priv->dev_comp->dma_ext) +writel ((u32)(priv->tx_dma >>32 ), + priv->base +SPI_TX_SRC_REG_64 ); +#endif + +if (op->data.dir ==SPI_MEM_DATA_IN ) { +writel ((u32)(priv->rx_dma &MTK_SPI_32BITS_MASK ), + priv->base +SPI_RX_DST_REG ); +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT +if (priv->dev_comp->dma_ext) +writel ((u32)(priv->rx_dma >>32 ), + priv->base +SPI_RX_DST_REG_64 ); +#endif + } +} + +static int mtk_spim_transfer_wait (struct spi_slave *slave, +const struct spi_mem_op *op) +{ +struct udevice *bus =dev_get_parent (slave->dev); +struct mtk_spim_priv *priv =dev_get_priv (bus); +u32 sck_l, sck_h, spi_bus_clk, clk_count, reg; +ulong us =1 ; +int ret =0 ; + +if (op->data.dir ==SPI_MEM_NO_DATA ) + clk_count =32 ; +else + clk_count = op->data.nbytes; + + spi_bus_clk =clk_get_rate (&priv->spi_clk); + sck_l =readl (priv->base +SPI_CFG2_REG ) >>SPI_CFG2_SCK_LOW_OFFSET ; + sck_h =readl (priv->base +SPI_CFG2_REG ) &SPI_CFG2_SCK_HIGH_MASK ; +do_div (spi_bus_clk, sck_l + sck_h +2 ); + + us =CLK_TO_US (spi_bus_clk, clk_count *8 ); + us +=1000 *1000 ;/* 1s tolerance */ + +if (us >UINT_MAX ) + us =UINT_MAX ; + + ret =readl_poll_timeout (priv->base +SPI_STATUS_REG , reg, + reg &0x1 , us); +if (ret <0 ) { +dev_err (priv->dev,"transfer timeout, val: 0x%lx\n" , us); +return -ETIMEDOUT ; + } + +return 0 ; +} + +static int mtk_spim_exec_op (struct spi_slave *slave, +const struct spi_mem_op *op) +{ +struct udevice *bus =dev_get_parent (slave->dev); +struct mtk_spim_priv *priv =dev_get_priv (bus); +u32 reg_val, nio =1 , tx_size; +char *tx_tmp_buf; +char *rx_tmp_buf; +int i, ret =0 ; + + priv->use_spimem = true; + +mtk_spim_reset (priv); +mtk_spim_hw_init (slave); +mtk_spim_prepare_transfer (priv, slave->max_hz); + + reg_val =readl (priv->base +SPI_CFG3_IPM_REG ); +/* opcode byte len */ + reg_val &= ~SPI_CFG3_IPM_CMD_BYTELEN_MASK ; + reg_val |=1 <<SPI_CFG3_IPM_CMD_BYTELEN_OFFSET ; + +/* addr & dummy byte len */ +if (op->addr.nbytes || op->dummy.nbytes) + reg_val |= (op->addr.nbytes + op->dummy.nbytes) << +SPI_CFG3_IPM_ADDR_BYTELEN_OFFSET ; + +/* data byte len */ +if (!op->data.nbytes) { + reg_val |=SPI_CFG3_IPM_NODATA_FLAG ; +writel (0 , priv->base +SPI_CFG1_REG ); + }else { + reg_val &= ~SPI_CFG3_IPM_NODATA_FLAG ; + priv->xfer_len = op->data.nbytes; +mtk_spim_setup_packet (priv); + } + +if (op->addr.nbytes || op->dummy.nbytes) { +if (op->addr.buswidth ==1 || op->dummy.buswidth ==1 ) + reg_val |=SPI_CFG3_IPM_XMODE_EN ; +else + reg_val &= ~SPI_CFG3_IPM_XMODE_EN ; + } + +if (op->addr.buswidth ==2 || + op->dummy.buswidth ==2 || + op->data.buswidth ==2 ) + nio =2 ; +else if (op->addr.buswidth ==4 || + op->dummy.buswidth ==4 || + op->data.buswidth ==4 ) + nio =4 ; + + reg_val &= ~SPI_CFG3_IPM_CMD_PIN_MODE_MASK ; + reg_val |=PIN_MODE_CFG (nio) <<SPI_CFG3_IPM_PIN_MODE_OFFSET ; + + reg_val |=SPI_CFG3_IPM_HALF_DUPLEX_EN ; +if (op->data.dir ==SPI_MEM_DATA_IN ) + reg_val |=SPI_CFG3_IPM_HALF_DUPLEX_DIR ; +else + reg_val &= ~SPI_CFG3_IPM_HALF_DUPLEX_DIR ; +writel (reg_val, priv->base +SPI_CFG3_IPM_REG ); + + tx_size =1 + op->addr.nbytes + op->dummy.nbytes; +if (op->data.dir ==SPI_MEM_DATA_OUT ) + tx_size += op->data.nbytes; + + tx_size =max (tx_size, (u32 )32 ); + +/* Fill up tx data*/ + tx_tmp_buf =kzalloc (tx_size,GFP_KERNEL ); +if (!tx_tmp_buf) { + ret = -ENOMEM ; + goto exit; + } + + tx_tmp_buf[0 ] = op->cmd.opcode; + +if (op->addr.nbytes) { +for (i =0 ; i < op->addr.nbytes; i++) + tx_tmp_buf[i +1 ] = op->addr.val >> + (8 * (op->addr.nbytes - i -1 ));
drivers/spi/mtk_spim.c line 524
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+ } + +if (op->dummy.nbytes) +memset (tx_tmp_buf + op->addr.nbytes +1 ,0xff , + op->dummy.nbytes); + +if (op->data.nbytes && op->data.dir ==SPI_MEM_DATA_OUT ) +memcpy (tx_tmp_buf + op->dummy.nbytes + op->addr.nbytes +1 , + op->data.buf.out, op->data.nbytes); +/* Finish filling up tx data*/
space before */
Quoted 87 lines
drivers/spi/mtk_spim.c new file +87
-0+ + priv->tx_dma =dma_map_single (tx_tmp_buf, tx_size,DMA_TO_DEVICE ); +if (dma_mapping_error (priv->dev, priv->tx_dma)) { + ret = -ENOMEM ; + goto tx_free; + } + +if (op->data.dir ==SPI_MEM_DATA_IN ) { +if (!IS_ALIGNED ((size_t )op->data.buf.in,4 )) { + rx_tmp_buf =kzalloc (op->data.nbytes,GFP_KERNEL ); +if (!rx_tmp_buf) { + ret = -ENOMEM ; + goto tx_unmap; + } + }else { + rx_tmp_buf = op->data.buf.in; + } + + priv->rx_dma =dma_map_single (rx_tmp_buf, op->data.nbytes, +DMA_FROM_DEVICE ); +if (dma_mapping_error (priv->dev, priv->rx_dma)) { + ret = -ENOMEM ; + goto rx_free; + } + } + + reg_val =readl (priv->base +SPI_CMD_REG ); + reg_val |=SPI_CMD_TX_DMA ; +if (op->data.dir ==SPI_MEM_DATA_IN ) + reg_val |=SPI_CMD_RX_DMA ; + +writel (reg_val, priv->base +SPI_CMD_REG ); + +mtk_spim_setup_dma_xfer (priv, op); + +mtk_spim_enable_transfer (priv); + +/* Wait for the interrupt. */ + ret =mtk_spim_transfer_wait (slave, op); +if (ret) + goto rx_unmap; + +if (op->data.dir ==SPI_MEM_DATA_IN && + !IS_ALIGNED ((size_t )op->data.buf.in,4 )) +memcpy (op->data.buf.in, rx_tmp_buf, op->data.nbytes); + +rx_unmap: +/* spi disable dma */ + reg_val =readl (priv->base +SPI_CMD_REG ); + reg_val &= ~SPI_CMD_TX_DMA ; +if (op->data.dir ==SPI_MEM_DATA_IN ) + reg_val &= ~SPI_CMD_RX_DMA ; +writel (reg_val, priv->base +SPI_CMD_REG ); + +writel (0 , priv->base +SPI_TX_SRC_REG ); +writel (0 , priv->base +SPI_RX_DST_REG ); + +if (op->data.dir ==SPI_MEM_DATA_IN ) +dma_unmap_single (priv->rx_dma, + op->data.nbytes,DMA_FROM_DEVICE ); +rx_free: +if (op->data.dir ==SPI_MEM_DATA_IN && + !IS_ALIGNED ((size_t )op->data.buf.in,4 )) +kfree (rx_tmp_buf); +tx_unmap: +dma_unmap_single (priv->tx_dma, + tx_size,DMA_TO_DEVICE ); +tx_free: +kfree (tx_tmp_buf); +exit: + priv->use_spimem = false; + +return ret; +} + +static int mtk_spim_adjust_op_size (struct spi_slave *slave, +struct spi_mem_op *op) +{ +int opcode_len; + +if (!op->data.nbytes) +return 0 ; + +if (op->data.dir !=SPI_MEM_NO_DATA ) { + opcode_len =1 + op->addr.nbytes + op->dummy.nbytes; +if (opcode_len + op->data.nbytes >MTK_SPI_IPM_PACKET_SIZE ) { + op->data.nbytes =MTK_SPI_IPM_PACKET_SIZE - opcode_len;
drivers/spi/mtk_spim.c
Quoted 10 lines
drivers/spi/mtk_spim.c new file +9
-0+/* force data buffer dma-aligned. */ + op->data.nbytes -= op->data.nbytes %4 ; + } + } + +return 0 ; +} + +static int mtk_spim_get_attr (struct mtk_spim_priv *priv,struct udevice *dev)
Can this use the of_to_plat() method?
Quoted 25 lines
drivers/spi/mtk_spim.c new file +25
-0+{ +int ret; + + priv->hw_cap.need_pad_sel =dev_read_bool (dev,"need_pad_sel" ); + priv->hw_cap.must_tx =dev_read_bool (dev,"must_tx" ); + priv->hw_cap.enhance_timing =dev_read_bool (dev,"enhance_timing" ); + priv->hw_cap.dma_ext =dev_read_bool (dev,"dma_ext" ); + priv->hw_cap.ipm_design =dev_read_bool (dev,"ipm_design" ); + priv->hw_cap.support_quad =dev_read_bool (dev,"support_quad" ); + + ret =dev_read_u32 (dev,"tick_dly" , &priv->tick_dly); +if (ret <0 ) +dev_err (priv->dev,"tick dly not set.\n" ); + + ret =dev_read_u32 (dev,"sample_sel" , &priv->sample_sel); +if (ret <0 ) +dev_err (priv->dev,"sample sel not set.\n" ); + +return ret; +} + +static int mtk_spim_probe (struct udevice *dev) +{ +struct mtk_spim_priv *priv =dev_get_priv (dev); +int ret;
drivers/spi/mtk_spim.c
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+ + priv->base = (void __iomem *)devfdt_get_addr (dev); +if (!priv->base) +return -EINVAL ; + +mtk_spim_get_attr (priv, dev); + + ret =clk_get_by_name (dev,"sel-clk" , &priv->sel_clk); +if (ret <0 ) { +dev_err (dev,"failed to get sel-clk\n" );
For code size, do you want this string? Could be a debug message since it shouldn't happen in production code.
Quoted 5 lines
drivers/spi/mtk_spim.c new file +5
-0+return ret; + } + + ret =clk_get_by_name (dev,"spi-clk" , &priv->spi_clk); +if (ret <0 ) {
drivers/spi/mtk_spim.c line 616
Quoted 10 lines
drivers/spi/mtk_spim.c new file +10
-0+dev_err (dev,"failed to get spi-clk\n" ); +return ret; + } + +clk_enable (&priv->sel_clk); +clk_enable (&priv->spi_clk); + +return 0 ; +} +
[..]
Regards,
Simon
PATCH 17/31 i2c: add support for MediaTek I2C interface
In reply to Weijie GaoThis patch adds support for MediaTek I2C interface
--- 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 +199 -0
199 lines not on this page · raw message
IC */
+ enum mtk_trans_op op; /* operation mode */
+ bool zero_len; /* Only transfer slave address, no data */
+ bool pushpull; /* push pull mode or open drain mode */
+ bool filter_msg; /* filter msg error log */
+ bool auto_restart; /* restart mode */
+ bool ignore_restart_irq; /* ignore restart IRQ */
+ uint speed; /* i2c speed, unit: hz */
+};
+
+static inline void i2c_writel(struct mtk_i2c_priv *priv, uint reg, uint
value)
+{
+ u32 offset = priv->soc_data->regs[reg];
+
+ writel(value, priv->base + offset);
+}
+
+static inline uint i2c_readl(struct mtk_i2c_priv *priv, uint offset) +{
+ return readl(priv->base + priv->soc_data->regs[offset]);
+}
+
+static int mtk_i2c_clk_enable(struct mtk_i2c_priv *priv)
+{
+ int ret;
+
+ ret = clk_enable(&priv->clk_main);
+ if (ret)
+ return log_msg_ret("enable clk_main", ret);
+
+ ret = clk_enable(&priv->clk_dma);
+ if (ret)
+ return log_msg_ret("enable clk_dma", ret);
+
+ return 0;
+}
+
+static int mtk_i2c_clk_disable(struct mtk_i2c_priv *priv) +{
+ int ret;
+
+ ret = clk_disable(&priv->clk_dma);
+ if (ret)
+ return log_msg_ret("disable clk_dma", ret);
+
+ ret = clk_disable(&priv->clk_main);
+ if (ret)
+ return log_msg_ret("disable clk_main", ret);
+
+ return 0;
+}
+
+static void mtk_i2c_init_hw(struct mtk_i2c_priv *priv)
+{
+ uint control_reg;
+
+ writel(I2C_DMA_HARD_RST, priv->pdmabase + REG_RST);
+ writel(I2C_DMA_CLR_FLAG, priv->pdmabase + REG_RST);
+ i2c_writel(priv, REG_SOFTRESET, I2C_SOFT_RST);
+ /* set ioconfig */
+ if (priv->pushpull)
+ i2c_writel(priv, REG_IO_CONFIG, I2C_IO_CONFIG_PUSH_PULL);
+ else
+ i2c_writel(priv, REG_IO_CONFIG, I2C_IO_CONFIG_OPEN_DRAIN);
+
+ i2c_writel(priv, REG_DCM_EN, I2C_DCM_DISABLE);
+ control_reg = I2C_CONTROL_ACKERR_DET_EN | I2C_CONTROL_CLK_EXT_EN;
+ if (priv->soc_data->dma_sync)
+ control_reg |= I2C_CONTROL_DMAACK | I2C_CONTROL_ASYNC;
+ i2c_writel(priv, REG_CONTROL, control_reg);
+ i2c_writel(priv, REG_DELAY_LEN, I2C_DELAY_LEN);
+}
+
+/*
+ * Calculate i2c port speed
+ *
+ * Hardware design:
+ * i2c_bus_freq = parent_clk / (clock_div * 2 * sample_cnt * step_cnt)
+ * clock_div: fixed in hardware, but may be various in different SoCs
+ *
+ * The calculation want to pick the highest bus frequency that is still
+ * less than or equal to target_speed. The calculation try to get
+ * sample_cnt and step_cn
+ * @param[in]
+ * clk_src: i2c clock source
+ * @param[out]
+ * timing_step_cnt: step cnt calculate result
+ * @param[out]
+ * timing_sample_cnt: sample cnt calculate result
+ * @return
+ * 0, set speed successfully.
+ * -EINVAL, Unsupported speed.
+ */
+static int mtk_i2c_calculate_speed(uint clk_src,
+ uint target_speed, + uint *timing_step_cnt, + uint *timing_sample_cnt)
+{
+ uint base_sample_cnt = MAX_SAMPLE_CNT_DIV;
+ uint base_step_cnt;
+ uint max_step_cnt;
+ uint sample_cnt;
+ uint step_cnt;
+ uint opt_div;
+ uint best_mul;
+ uint cnt_mul;
+
+ if (target_speed > MAX_HS_MODE_SPEED)
+ target_speed = MAX_HS_MODE_SPEED;
+
+ if (target_speed > MAX_FS_MODE_SPEED)
+ max_step_cnt = MAX_HS_STEP_CNT_DIV;
+ else
+ max_step_cnt = MAX_STEP_CNT_DIV;
+
+ base_step_cnt = max_step_cnt;
+ /* Find the best combination */
+ opt_div = DIV_ROUND_UP(clk_src >> 1, target_speed);
+ best_mul = MAX_SAMPLE_CNT_DIV * max_step_cnt;
+
+ /*
+ * Search for the best pair (sample_cnt, step_cnt) with
+ * 0 < sample_cnt < MAX_SAMPLE_CNT_DIV
+ * 0 < step_cnt < max_step_cnt
+ * sample_cnt * step_cnt >= opt_div
+ * optimizing for sample_cnt * step_cnt being minimal
+ */
+ for (sample_cnt = 1; sample_cnt <= MAX_SAMPLE_CNT_DIV; sample_cnt++) {
+ step_cnt = DIV_ROUND_UP(opt_div, sample_cnt);
+ cnt_mul = step_cnt * sample_cnt;
+ if (step_cnt > max_step_cnt)
+ continue;
+
+ if (cnt_mul < best_mul) {
+ best_mul = cnt_mul;
+ base_sample_cnt = sample_cnt;
+ base_step_cnt = step_cnt;
+ if (best_mul == opt_div)
+ break;
+ }
+ }
+
+ sample_cnt = base_sample_cnt;
+ step_cnt = base_step_cnt;
+
+ if ((clk_src / (2 * sample_cnt * step_cnt)) > target_speed) {
+ /*
+ * In this case, hardware can't support such
+ * low i2c_bus_freq
+ */
+ debug("Unsupported speed(%uhz)\n", target_speed);
+ return log_msg_ret("calculate speed", -EINVAL);
+ }
+
+ *timing_step_cnt = step_cnt - 1;
+ *timing_sample_cnt = sample_cnt - 1;
+
+ return 0;
+}
+
+/*
+ * mtk_i2c_set_speed
+ *
+ * @par Description
+ * Calculate i2c speed and write sample_cnt, step_cnt to TIMING
register.
+ * @param[in]
+ * dev: udevice pointer, struct udevice contains i2c source clock,
+ * clock divide and speed.
+ * @return
+ * 0, set speed successfully.\n
+ * error code from mtk_i2c_calculate_speed().
+ */
+static int mtk_i2c_set_speed(struct udevice *dev, uint speed) +{
+ struct mtk_i2c_priv *priv = dev_get_priv(dev);
+ uint high_speed_reg;
+ uint sample_cnt;
+ uint timing_reg;
+ uint step_cnt;
+ uint clk_src;
+ int ret = 0;
+
+ priv->speed = speed;
+ if (mtk_i2c_clk_enable(priv))
+ return log_msg_ret("set_speed enable clk", -1);
+
+ clk_src = clk_get_rate(&priv->clk_main) / I2C_DEFAULT_CLK_DIV;
+ i2c_writel(priv, REG_CLOCK_DIV, (I2C_DEFAULT_CLK_DIV - 1));
+ if (priv->speed > MAX_FS_MODE_SPEED) {
+ /* Set master code speed register */
+ ret = mtk_i2c_calculate_speed(clk_src, MAX_FS_MODE_SPEED,
+ &step_cnt, &sample_cnt);
+ if (ret < 0)
+ goto exit;
+
+ timing_reg = (sample_cnt << TIMING_SAMPLE_OFFSET) | step_cnt;
+ i2c_writel(priv, REG_TIMING, timing_reg);
+ /* Set the high speed mode register */
+ ret = mtk_i2c_calculate_speed(clk_src, priv->speed,
+ &step_cnt, &sample_cnt);
+ if (ret < 0)
+ goto exit;
+
+ high_speed_reg = I2C_TIME_DEFAULT_VALUE |
+ (sample_cnt << HS_SAMPLE_OFFSET) |
+ (step_cnt << HS_STEP_OFFSET);
+ i2c_writel(priv, REG_HS, high_speed_reg);
+ } else {
+ ret = mtk_i2c_calculate_speed(clk_src, priv->speed,
+ &step_cnt, &sample_cnt);
+ if (ret < 0)
+ goto exit;
+
+ timing_reg = (sample_cnt << TIMING_SAMPLE_OFFSET) | step_cnt;
+ /* Disable the high speed transaction */
+ high_speed_reg = I2C_TIME_CLR_VALUE;
+ i2c_writel(priv, REG_TIMING, timing_reg);
+ i2c_writel(priv, REG_HS, high_speed_reg);
+ }
+exit:
+ if (mtk_i2c_clk_disable(priv))
+ return log_msg_ret("set_speed disable clk", -1);
+
+ return ret;
+}
+
+/*
+ * mtk_i2c_do_transfer
+ *
+ * @par Description
+ * Configure i2c register and trigger transfer.
+ * @param[in]
+ * priv: mtk_i2cmtk_i2c_priv pointer, struct mtk_i2c_priv contains
register base\n
+ * address, operation mode, interrupt status and i2c driver data.
+ * @param[in]
+ * msgs: i2c_msg pointer, struct i2c_msg contains slave\n
+ * address, operation mode, msg length and data buffer.
+ * @param[in]
+ * num: i2c_msg number.
+ * @param[in]
+ * left_num: left i2c_msg number.
+ * @return
+ * 0, i2c transfer successfully.\n + * -ETIMEDOUT, i2c transfer timeout.\n + * -EREMOTEIO, i2c transfer ack error.
+ */
+static int mtk_i2c_do_transfer(struct mtk_i2c_priv *priv,
+ struct i2c_msg *msgs,
+ int num, int left_num)
+{
+ uint restart_flag = 0;
+ uint trans_error = 0;
+ uint irq_stat = 0;
+ uint tmo_poll = 0;
+ uint control_reg;
+ bool tmo = false;
+ uint start_reg;
+ uint addr_reg;
+ int ret = 0;
+
+ if (priv->auto_restart)
+ restart_flag = I2C_RS_TRANSFER;
+
+ control_reg = i2c_readl(priv, REG_CONTROL) &
+ ~(I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS);
+
+ if (priv->speed > MAX_FS_MODE_SPEED || num > 1)
+ control_reg |= I2C_CONTROL_RS;
+
+ if (priv->op == I2C_MASTER_WRRD)
+ control_reg |= I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS;
+
+ control_reg |= I2C_CONTROL_DMA_EN;
+ i2c_writel(priv, REG_CONTROL, control_reg);
+
+ /* set start condition */
+ if (priv->speed <= MAX_ST_MODE_SPEED)
+ i2c_writel(priv, REG_EXT_CONF, I2C_ST_START_CON);
+ else
+ i2c_writel(priv, REG_EXT_CONF, I2C_FS_START_CON);
+
+ addr_reg = msgs->addr << 1;
+ if (priv->op == I2C_MASTER_RD)
+ addr_reg |= I2C_M_RD;
+ if (priv->zero_len)
+ i2c_writel(priv, REG_SLAVE_ADDR, addr_reg | TRANS_ADDR_ONLY);
+ else
+ i2c_writel(priv, REG_SLAVE_ADDR, addr_reg);
+
+ /* clear interrupt status */
+ i2c_writel(priv, REG_INTR_STAT, restart_flag | I2C_HS_NACKERR |
+ I2C_ACKERR | I2C_TRANSAC_COMP);
+ i2c_writel(priv, REG_FIFO_ADDR_CLR, I2C_FIFO_ADDR_CLR);
+
+ /* enable interrupt */
+ i2c_writel(priv, REG_INTR_MASK, restart_flag | I2C_HS_NACKERR |
+ I2C_ACKERR | I2C_TRANSAC_COMP);
+
+ /* set transfer and transaction len */
+ if (priv->op == I2C_MASTER_WRRD) {
+ i2c_writel(priv, REG_TRANSFER_LEN, msgs->len);
+ i2c_writel(priv, REG_TRANSFER_LEN_AUX, (msgs + 1)->len);
+ i2c_writel(priv, REG_TRANSAC_LEN, I2C_WRRD_TRANAC_VALUE);
+ } else {
+ i2c_writel(priv, REG_TRANSFER_LEN, msgs->len);
+ i2c_writel(priv, REG_TRANSAC_LEN, num);
+ }
+
+ /*
+ * prepare buffer data to start transfer
+ * three cases here: read, write, write then read
+ */
+ if (priv->op == I2C_MASTER_RD) {
+ /* Clear DMA interrupt flag*/
+ writel(I2C_DMA_INT_FLAG_NONE, priv->pdmabase + REG_INT_FLAG);
+ /* Set DMA direction RX*/
+ writel(I2C_DMA_CON_RX, priv->pdmabase + REG_CON);
+ flush_cache((ulong)msgs->buf, msgs->len);
+ /* Write the rx buffer address to dma register*/
+ writel((ulong)msgs->buf, priv->pdmabase + REG_RX_MEM_ADDR);
+ /* Write the rx length to dma register*/
+ writel(msgs->len, priv->pdmabase + REG_RX_LEN);
+ } else if (priv->op == I2C_MASTER_WR) {
+ /* Clear DMA interrupt flag*/
+ writel(I2C_DMA_INT_FLAG_NONE, priv->pdmabase + REG_INT_FLAG);
+ /* Set DMA direction TX*/
+ writel(I2C_DMA_CON_TX, priv->pdmabase + REG_CON);
+ flush_cache((ulong)msgs->buf, msgs->len);
+ /* Write the tx buffer address to dma register*/
+ writel((ulong)msgs->buf, priv->pdmabase + REG_TX_MEM_ADDR);
+ /* Write the tx length to dma register*/
+ writel(msgs->len, priv->pdmabase + REG_TX_LEN);
+ } else {
+ /* Clear DMA interrupt flag*/
+ writel(I2C_DMA_INT_FLAG_NONE, priv->pdmabase + REG_INT_FLAG);
+ /* Set DMA direction TX and RX*/
+ writel(I2C_DMA_TX_RX, priv->pdmabase + REG_CON);
+ flush_cache((ulong)msgs->buf, msgs->len);
+ flush_cache((ulong)(msgs + 1)->buf, (msgs + 1)->len);
+ /* Write the tx buffer address to dma register*/
+ writel((ulong)msgs->buf, priv->pdmabase + REG_TX_MEM_ADDR);
+ /* Write the tx buffer address to dma register*/
+ writel((ulong)(msgs + 1)->buf, priv->pdmabase + REG_RX_MEM_ADDR);
+ /* Write the tx length to dma register*/
+ writel(msgs->len, priv->pdmabase + REG_TX_LEN);
+ /* Write the rx length to dma register*/
+ writel((msgs + 1)->len, priv->pdmabase + REG_RX_LEN);
+ }
+
+ writel(I2C_DMA_START_EN, priv->pdmabase + REG_EN);
+
+ if (!priv->auto_restart) {
+ start_reg = I2C_TRANSAC_START;
+ } else {
+ start_reg = I2C_TRANSAC_START | I2C_RS_MUL_TRIG;
+ if (left_num >= 1)
+ start_reg |= I2C_RS_MUL_CNFG;
+ }
+ i2c_writel(priv, REG_START, start_reg);
+
+ for (;;) {
+ irq_stat = i2c_readl(priv, REG_INTR_STAT);
+
+ /* ignore the first restart irq after the master code */
+ if (priv->ignore_restart_irq && (irq_stat | restart_flag)) {
+ priv->ignore_restart_irq = false;
+ irq_stat = 0;
+ writel(I2C_RS_MUL_CNFG | I2C_RS_MUL_TRIG |
+ I2C_TRANSAC_START, priv->base + REG_START);
+ }
+
+ if (irq_stat & (I2C_TRANSAC_COMP | restart_flag)) {
+ tmo = false;
+ if (irq_stat & (I2C_HS_NACKERR | I2C_ACKERR))
+ trans_error = 1;
+
+ break;
+ }
+ udelay(1);
+ if (tmo_poll++ >= TRANSFER_TIMEOUT) {
+ tmo = true;
+ break;
+ }
+ }
+
+ /* clear interrupt mask */
+ i2c_writel(priv, REG_INTR_MASK, ~(restart_flag | I2C_HS_NACKERR |
+ I2C_ACKERR | I2C_TRANSAC_COMP));
+
+ if (!tmo && trans_error != 0) {
+ if (tmo) {
+ ret = -ETIMEDOUT;
+ if (!priv->filter_msg)
+ debug("I2C timeout! addr: 0x%x,\n", msgs->addr);
+ } else {
+ ret = -EREMOTEIO;
+ if (!priv->filter_msg)
+ debug("I2C ACKERR! addr: 0x%x,IRQ:0x%x\n",
+ msgs->addr, irq_stat);
+ }
+ mtk_i2c_init_hw(priv);
+ }
+
+ return ret;
+}
+
+/*
+ * mtk_i2c_transfer
+ *
+ * @par Description
+ * Common i2c transfer API. Set i2c transfer mode according to
i2c_msg\n
+ * information, then call mtk_i2c_do_transfer() to configure i2c
register\n
+ * and trigger transfer.
+ * @param[in]
+ * dev: udevice pointer, struct udevice contains struct mtk_i2c_priv,
\n
+ * struct mtk_i2c_priv contains register base\n
+ * address, operation mode, interrupt status and i2c driver data.
+ * @param[in]
+ * msgs: i2c_msg pointer, struct i2c_msg contains slave\n
+ * address, operation mode, msg length and data buffer.
+ * @param[in]
+ * num: i2c_msg number.
+ * @return
+ * i2c_msg number, i2c transfer successfully.\n + * -EINVAL, msg length is more than 16\n + * use DMA MODE or slave address more than 0x7f.\n + * error code from mtk_i2c_init_base().\n + * error code from mtk_i2c_set_speed().\n + * error code from mtk_i2c_do_transfer().
+ */
+static int mtk_i2c_transfer(struct udevice *dev, struct i2c_msg *msg,
+ int nmsgs)
+{
+ struct mtk_i2c_priv *priv = dev_get_priv(dev);
+ int left_num;
+ uint num_cnt;
+ int ret;
+
+ priv->auto_restart = true;
+ left_num = nmsgs;
+ if (mtk_i2c_clk_enable(priv))
+ return log_msg_ret("transfer enable clk", -1);
+
+ for (num_cnt = 0; num_cnt < nmsgs; num_cnt++) {
+ if (((msg + num_cnt)->addr) > MAX_I2C_ADDR) {
+ ret = -EINVAL;
+ goto err_exit;
+ }
+ if ((msg + num_cnt)->len > MAX_I2C_LEN) {
+ ret = -EINVAL;
+ goto err_exit;
+ }
+ }
+
+ /* check if we can skip restart and optimize using WRRD mode */
+ if (priv->auto_restart && nmsgs == 2) {
+ if (!(msg[0].flags & I2C_M_RD) && (msg[1].flags & I2C_M_RD) &&
+ msg[0].addr == msg[1].addr) {
+ priv->auto_restart = false;
+ }
+ }
+
+ if (priv->auto_restart && nmsgs >= 2 && priv->speed > MAX_FS_MODE_SPEED)
+ /* ignore the first restart irq after the master code,
+ * otherwise the first transfer will be discarded.
+ */
+ priv->ignore_restart_irq = true;
+ else
+ priv->ignore_restart_irq = false;
+
+ while (left_num--) {
+ /* transfer slave address only to support devices detect */
+ if (!msg->buf)
+ priv->zero_len = true;
+ else
+ priv->zero_len = false;
+
+ if (msg->flags & I2C_M_RD)
+ priv->op = I2C_MASTER_RD;
+ else
+ priv->op = I2C_MASTER_WR;
+
+ if (!priv->auto_restart) {
+ if (nmsgs > 1) {
+ /* combined two messages into one transaction */
+ priv->op = I2C_MASTER_WRRD;
+ left_num--;
+ }
+ }
+ ret = mtk_i2c_do_transfer(priv, msg, nmsgs, left_num);
+ if (ret < 0)
+ goto err_exit;
+ msg++;
+ }
+ ret = 0;
+
+err_exit:
+ if (mtk_i2c_clk_disable(priv))
+ return log_msg_ret("transfer disable clk", -1);
+
+ return ret;
+}
+
+static int mtk_i2c_ofdata_to_platdata(struct udevice *dev) +{
+ struct mtk_i2c_priv *priv = dev_get_priv(dev);
+ int ret;
+
+ priv->base = dev_remap_addr_index(dev, 0);
+ priv->pdmabase = dev_remap_addr_index(dev, 1);
+ ret = clk_get_by_index(dev, 0, &priv->clk_main);
+ if (ret)
+ return log_msg_ret("clk_get_by_index 0", ret);
+
+ ret = clk_get_by_index(dev, 1, &priv->clk_dma);
+
+ return ret;
+}
+
+static int mtk_i2c_probe(struct udevice *dev)
+{
+ struct mtk_i2c_priv *priv = dev_get_priv(dev);
+
+ priv->soc_data = (struct mtk_i2c_soc_data *)dev_get_driver_data(dev);
+
+ if (mtk_i2c_clk_enable(priv))
+ return log_msg_ret("probe enable clk", -1);
+
+ mtk_i2c_init_hw(priv);
+
+ if (mtk_i2c_clk_disable(priv))
+ return log_msg_ret("probe disable clk", -1);
+
+ return 0;
+}
+
+static int mtk_i2c_deblock(struct udevice *dev)
+{
+ struct mtk_i2c_priv *priv = dev_get_priv(dev);
+
+ if (mtk_i2c_clk_enable(priv))
+ return log_msg_ret("deblock enable clk", -1);
+
+ mtk_i2c_init_hw(priv);
+
+ if (mtk_i2c_clk_disable(priv))
+ return log_msg_ret("deblock disable clk", -1);
+
+ return 0;
+}
+
+static const struct mtk_i2c_soc_data mt76xx_soc_data = {
+ .regs = mt_i2c_regs_v1,
+ .dma_sync = 0,
+};
+
+static const struct mtk_i2c_soc_data mt7981_soc_data = {
+ .regs = mt_i2c_regs_v1,
+ .dma_sync = 1,
+};
+
+static const struct mtk_i2c_soc_data mt7986_soc_data = {
+ .regs = mt_i2c_regs_v1,
+ .dma_sync = 1,
+};
+
+static const struct mtk_i2c_soc_data mt8183_soc_data = {
+ .regs = mt_i2c_regs_v2,
+ .dma_sync = 1,
+};
+
+static const struct mtk_i2c_soc_data mt8518_soc_data = {
+ .regs = mt_i2c_regs_v1,
+ .dma_sync = 0,
+};
+
+static const struct mtk_i2c_soc_data mt8512_soc_data = {
+ .regs = mt_i2c_regs_v1,
+ .dma_sync = 1,
+};
+
+static const struct dm_i2c_ops mtk_i2c_ops = {
+ .xfer = mtk_i2c_transfer,
+ .set_bus_speed = mtk_i2c_set_speed,
+ .deblock = mtk_i2c_deblock,
+};
+
+static const struct udevice_id mtk_i2c_ids[] = {
+ {
+ .compatible = "mediatek,mt7622-i2c",
+ .data = (ulong)&mt76xx_soc_data,
+ }, {
+ .compatible = "mediatek,mt7623-i2c",
+ .data = (ulong)&mt76xx_soc_data,
+ }, {
+ .compatible = "mediatek,mt7629-i2c",
+ .data = (ulong)&mt76xx_soc_data,
+ }, {
+ .compatible = "mediatek,mt7981-i2c",
+ .data = (ulong)&mt7981_soc_data,
+ }, {
+ .compatible = "mediatek,mt7986-i2c",
+ .data = (ulong)&mt7986_soc_data,
+ }, {
+ .compatible = "mediatek,mt8183-i2c",
+ .data = (ulong)&mt8183_soc_data,
+ }, {
+ .compatible = "mediatek,mt8512-i2c",
+ .data = (ulong)&mt8512_soc_data,
+ }, {
+ .compatible = "mediatek,mt8518-i2c",
+ .data = (ulong)&mt8518_soc_data,
+ }
+};
+
+U_BOOT_DRIVER(mtk_i2c) = {
+ .name = "mtk_i2c",
+ .id = UCLASS_I2C,
+ .of_match = mtk_i2c_ids,
+ .of_to_plat = mtk_i2c_ofdata_to_platdata,
+ .probe = mtk_i2c_probe,
+ .priv_auto = sizeof(struct mtk_i2c_priv),
+ .ops = &mtk_i2c_ops,
+};
Signature · 1 line
2.17.1
Re: [PATCH 17/31] i2c: add support for MediaTek I2C interface
Hi Weijie,
Quoted 11 lines · Weijie Gao
This patch adds support for MediaTek I2C interface
Signed-off-by Weijie Gao <[email protected]>--- 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
[..]
Quoted 25 lines
drivers/i2c/mtk_i2c.c new file +19
-0@@ -0,0 +1,822 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2022 MediaTek Inc. All Rights Reserved. +* +* Author: Mingming Lee <[email protected]> +* +* MediaTek I2C Interface driver +*/ + +#include <clk.h> +#include <cpu_func.h> +#include <dm.h> +#include <i2c.h> +#include <log.h> +#include <asm/cache.h> +#include <asm/io.h> +#include <linux/delay.h> +#include <linux/errno.h> +
[..]
drivers/i2c/mtk_i2c.c
Quoted 6 lines
drivers/i2c/mtk_i2c.c new file +6
-0+ +U_BOOT_DRIVER (mtk_i2c) = { + .name ="mtk_i2c" , + .id =UCLASS_I2C , + .of_match = mtk_i2c_ids, + .of_to_plat = mtk_i2c_ofdata_to_platdata,
mtk_i2c_of_to_plat (for consistency)
Quoted 7 lines
drivers/i2c/mtk_i2c.c new file +4
-1+ .probe = mtk_i2c_probe, + .priv_auto = sizeof(struct mtk_i2c_priv), + .ops = &mtk_i2c_ops, +}; --2.17.1
Regards,
Simon
Re: [PATCH 17/31] i2c: add support for MediaTek I2C interface
Quoted 49 lines · Simon Glass
Hi Weijie,
Quoted 12 lines · Weijie Gao
This patch adds support for MediaTek I2C interface
Signed-off-by Weijie Gao <[email protected]>--- 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.cReviewed-by Simon Glass <[email protected]>[..]
Quoted 25 lines
drivers/i2c/mtk_i2c.c new file +19
-0@@ -0,0 +1,822 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2022 MediaTek Inc. All Rights Reserved. +* +* Author: Mingming Lee <[email protected]> +* +* MediaTek I2C Interface driver +*/ + +#include <clk.h> +#include <cpu_func.h> +#include <dm.h> +#include <i2c.h> +#include <log.h> +#include <asm/cache.h> +#include <asm/io.h> +#include <linux/delay.h> +#include <linux/errno.h> +[..]
Quoted 8 lines
drivers/i2c/mtk_i2c.c
Quoted 6 lines
drivers/i2c/mtk_i2c.c new file +6
-0+ +U_BOOT_DRIVER (mtk_i2c) = { + .name ="mtk_i2c" , + .id =UCLASS_I2C , + .of_match = mtk_i2c_ids, + .of_to_plat = mtk_i2c_ofdata_to_platdata,
mtk_i2c_of_to_plat(for consistency)
OK.
Quoted 11 lines
Quoted 8 lines
drivers/i2c/mtk_i2c.c new file +4
-1+ .probe = mtk_i2c_probe, + .priv_auto = sizeof(struct mtk_i2c_priv), + .ops = &mtk_i2c_ops, +}; --2.17.1
Regards,
Simon
Re: [PATCH 17/31] i2c: add support for MediaTek I2C interface
In reply to Weijie GaoHello Weijie Gao,
Quoted 9 lines · Weijie Gao
This patch adds support for MediaTek I2C interface
Signed-off-by Weijie Gao <[email protected]>--- 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
beside comment from Simon
Thanks!
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: [email protected]
Re: [PATCH 17/31] i2c: add support for MediaTek I2C interface
In reply to Weijie GaoHi
Quoted 576 lines · Weijie Gao
This patch adds support for MediaTek I2C interface
Signed-off-by Weijie Gao <[email protected]>--- 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.cdrivers/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" helpdrivers/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.odrivers/i2c/mtk_i2c.c new file +523
-0@@ -0,0 +1,822 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2022 MediaTek Inc. All Rights Reserved. +* +* Author: Mingming Lee <[email protected]> +* +* MediaTek I2C Interface driver +*/ + +#include <clk.h> +#include <cpu_func.h> +#include <dm.h> +#include <i2c.h> +#include <log.h> +#include <asm/cache.h> +#include <asm/io.h> +#include <linux/delay.h> +#include <linux/errno.h> + +#define I2C_RS_TRANSFER BIT(4) +#define I2C_HS_NACKERR BIT(2) +#define I2C_ACKERR BIT(1) +#define I2C_TRANSAC_COMP BIT(0) +#define I2C_TRANSAC_START BIT(0) +#define I2C_RS_MUL_CNFG BIT(15) +#define I2C_RS_MUL_TRIG BIT(14) +#define I2C_DCM_DISABLE 0x0000 +#define I2C_IO_CONFIG_OPEN_DRAIN 0x0003 +#define I2C_IO_CONFIG_PUSH_PULL 0x0000 +#define I2C_SOFT_RST 0x0001 +#define I2C_FIFO_ADDR_CLR 0x0001 +#define I2C_DELAY_LEN 0x0002 +#define I2C_ST_START_CON 0x8001 +#define I2C_FS_START_CON 0x1800 +#define I2C_TIME_CLR_VALUE 0x0000 +#define I2C_TIME_DEFAULT_VALUE 0x0003 +#define I2C_WRRD_TRANAC_VALUE 0x0002 +#define I2C_RD_TRANAC_VALUE 0x0001 + +#define I2C_DMA_CON_TX 0x0000 +#define I2C_DMA_CON_RX 0x0001 +#define I2C_DMA_START_EN 0x0001 +#define I2C_DMA_INT_FLAG_NONE 0x0000 +#define I2C_DMA_CLR_FLAG 0x0000 +#define I2C_DMA_TX_RX 0x0000 +#define I2C_DMA_HARD_RST 0x0002 + +#define MAX_ST_MODE_SPEED 100000 +#define MAX_FS_MODE_SPEED 400000 +#define MAX_HS_MODE_SPEED 3400000 +#define MAX_SAMPLE_CNT_DIV 8 +#define MAX_STEP_CNT_DIV 64 +#define MAX_HS_STEP_CNT_DIV 8 +#define I2C_DEFAULT_CLK_DIV 4 + +#define MAX_I2C_ADDR 0x7f +#define MAX_I2C_LEN 0xff +#define TRANS_ADDR_ONLY BIT(8) +#define TRANSFER_TIMEOUT 50000/* us */ +#define I2C_FIFO_STAT1_MASK 0x001f +#define TIMING_SAMPLE_OFFSET 8 +#define HS_SAMPLE_OFFSET 12 +#define HS_STEP_OFFSET 8 + +#define I2C_CONTROL_WRAPPER BIT(0) +#define I2C_CONTROL_RS BIT(1) +#define I2C_CONTROL_DMA_EN BIT(2) +#define I2C_CONTROL_CLK_EXT_EN BIT(3) +#define I2C_CONTROL_DIR_CHANGE BIT(4) +#define I2C_CONTROL_ACKERR_DET_EN BIT(5) +#define I2C_CONTROL_TRANSFER_LEN_CHANGE BIT(6) +#define I2C_CONTROL_DMAACK BIT(8) +#define I2C_CONTROL_ASYNC BIT(9) + +enum I2C_REGS_OFFSET { +REG_PORT , +REG_SLAVE_ADDR , +REG_INTR_MASK , +REG_INTR_STAT , +REG_CONTROL , +REG_TRANSFER_LEN , +REG_TRANSAC_LEN , +REG_DELAY_LEN , +REG_TIMING , +REG_START , +REG_EXT_CONF , +REG_FIFO_STAT1 , +REG_LTIMING , +REG_FIFO_STAT , +REG_FIFO_THRESH , +REG_FIFO_ADDR_CLR , +REG_IO_CONFIG , +REG_RSV_DEBUG , +REG_HS , +REG_SOFTRESET , +REG_DCM_EN , +REG_PATH_DIR , +REG_DEBUGSTAT , +REG_DEBUGCTRL , +REG_TRANSFER_LEN_AUX , +REG_CLOCK_DIV , +REG_SCL_HL_RATIO , +REG_SCL_HS_HL_RATIO , +REG_SCL_MIS_COMP_POINT , +REG_STA_STOP_AC_TIME , +REG_HS_STA_STOP_AC_TIME , +REG_DATA_TIME , +}; + +enum DMA_REGS_OFFSET { +REG_INT_FLAG =0x0 , +REG_INT_EN =0x04 , +REG_EN =0x08 , +REG_RST =0x0c , +REG_CON =0x18 , +REG_TX_MEM_ADDR =0x1c , +REG_RX_MEM_ADDR =0x20 , +REG_TX_LEN =0x24 , +REG_RX_LEN =0x28 , +}; + +static const uint mt_i2c_regs_v1[] = { + [REG_PORT ] =0x0 , + [REG_SLAVE_ADDR ] =0x4 , + [REG_INTR_MASK ] =0x8 , + [REG_INTR_STAT ] =0xc , + [REG_CONTROL ] =0x10 , + [REG_TRANSFER_LEN ] =0x14 , + [REG_TRANSAC_LEN ] =0x18 , + [REG_DELAY_LEN ] =0x1c , + [REG_TIMING ] =0x20 , + [REG_START ] =0x24 , + [REG_EXT_CONF ] =0x28 , + [REG_FIFO_STAT1 ] =0x2c , + [REG_FIFO_STAT ] =0x30 , + [REG_FIFO_THRESH ] =0x34 , + [REG_FIFO_ADDR_CLR ] =0x38 , + [REG_IO_CONFIG ] =0x40 , + [REG_RSV_DEBUG ] =0x44 , + [REG_HS ] =0x48 , + [REG_SOFTRESET ] =0x50 , + [REG_SOFTRESET ] =0x50 , + [REG_DCM_EN ] =0x54 , + [REG_DEBUGSTAT ] =0x64 , + [REG_DEBUGCTRL ] =0x68 , + [REG_TRANSFER_LEN_AUX ] =0x6c , + [REG_CLOCK_DIV ] =0x70 , + [REG_SCL_HL_RATIO ] =0x74 , + [REG_SCL_HS_HL_RATIO ] =0x78 , + [REG_SCL_MIS_COMP_POINT ] =0x7c , + [REG_STA_STOP_AC_TIME ] =0x80 , + [REG_HS_STA_STOP_AC_TIME ] =0x84 , + [REG_DATA_TIME ] =0x88 , +}; + +static const uint mt_i2c_regs_v2[] = { + [REG_PORT ] =0x0 , + [REG_SLAVE_ADDR ] =0x4 , + [REG_INTR_MASK ] =0x8 , + [REG_INTR_STAT ] =0xc , + [REG_CONTROL ] =0x10 , + [REG_TRANSFER_LEN ] =0x14 , + [REG_TRANSAC_LEN ] =0x18 , + [REG_DELAY_LEN ] =0x1c , + [REG_TIMING ] =0x20 , + [REG_START ] =0x24 , + [REG_EXT_CONF ] =0x28 , + [REG_LTIMING ] =0x2c , + [REG_HS ] =0x30 , + [REG_IO_CONFIG ] =0x34 , + [REG_FIFO_ADDR_CLR ] =0x38 , + [REG_TRANSFER_LEN_AUX ] =0x44 , + [REG_CLOCK_DIV ] =0x48 , + [REG_SOFTRESET ] =0x50 , + [REG_DEBUGSTAT ] =0xe0 , + [REG_DEBUGCTRL ] =0xe8 , + [REG_FIFO_STAT ] =0xf4 , + [REG_FIFO_THRESH ] =0xf8 , + [REG_DCM_EN ] =0xf88 , +}; + +enum mtk_trans_op { +I2C_MASTER_WR =1 , +I2C_MASTER_RD , +I2C_MASTER_WRRD , +}; + +struct mtk_i2c_soc_data { +const uint *regs; +uint dma_sync:1 ; +}; + +struct mtk_i2c_priv { +/* set in i2c probe */ +void __iomem *base;/* i2c base addr */ +void __iomem *pdmabase;/* dma base address*/ +struct clk clk_main;/* main clock for i2c bus */ +struct clk clk_dma;/* DMA clock for i2c via DMA */ +const struct mtk_i2c_soc_data *soc_data;/* Compatible data for different IC */ +enum mtk_trans_op op;/* operation mode */ +bool zero_len;/* Only transfer slave address, no data */ +bool pushpull;/* push pull mode or open drain mode */ +bool filter_msg;/* filter msg error log */ +bool auto_restart;/* restart mode */ +bool ignore_restart_irq;/* ignore restart IRQ */ +uint speed;/* i2c speed, unit: hz */ +}; + +static inline void i2c_writel (struct mtk_i2c_priv *priv,uint reg,uint value) +{ +u32 offset = priv->soc_data->regs[reg]; + +writel (value, priv->base + offset); +} + +static inline uint i2c_readl (struct mtk_i2c_priv *priv,uint offset) +{ +return readl (priv->base + priv->soc_data->regs[offset]); +} + +static int mtk_i2c_clk_enable (struct mtk_i2c_priv *priv) +{ +int ret; + + ret =clk_enable (&priv->clk_main); +if (ret) +return log_msg_ret ("enable clk_main" , ret); + + ret =clk_enable (&priv->clk_dma); +if (ret) +return log_msg_ret ("enable clk_dma" , ret); + +return 0 ; +} + +static int mtk_i2c_clk_disable (struct mtk_i2c_priv *priv) +{ +int ret; + + ret =clk_disable (&priv->clk_dma); +if (ret) +return log_msg_ret ("disable clk_dma" , ret); + + ret =clk_disable (&priv->clk_main); +if (ret) +return log_msg_ret ("disable clk_main" , ret); + +return 0 ; +} + +static void mtk_i2c_init_hw (struct mtk_i2c_priv *priv) +{ +uint control_reg; + +writel (I2C_DMA_HARD_RST , priv->pdmabase +REG_RST ); +writel (I2C_DMA_CLR_FLAG , priv->pdmabase +REG_RST ); +i2c_writel (priv,REG_SOFTRESET ,I2C_SOFT_RST ); +/* set ioconfig */ +if (priv->pushpull) +i2c_writel (priv,REG_IO_CONFIG ,I2C_IO_CONFIG_PUSH_PULL ); +else +i2c_writel (priv,REG_IO_CONFIG ,I2C_IO_CONFIG_OPEN_DRAIN ); + +i2c_writel (priv,REG_DCM_EN ,I2C_DCM_DISABLE ); + control_reg =I2C_CONTROL_ACKERR_DET_EN |I2C_CONTROL_CLK_EXT_EN ; +if (priv->soc_data->dma_sync) + control_reg |=I2C_CONTROL_DMAACK |I2C_CONTROL_ASYNC ; +i2c_writel (priv,REG_CONTROL , control_reg); +i2c_writel (priv,REG_DELAY_LEN ,I2C_DELAY_LEN ); +} + +/* +* Calculate i2c port speed +* +* Hardware design: +* i2c_bus_freq = parent_clk / (clock_div * 2 * sample_cnt * step_cnt) +* clock_div: fixed in hardware, but may be various in different SoCs +* +* The calculation want to pick the highest bus frequency that is still +* less than or equal to target_speed. The calculation try to get +* sample_cnt and step_cn +* @param[in] +* clk_src: i2c clock source +* @param[out] +* timing_step_cnt: step cnt calculate result +* @param[out] +* timing_sample_cnt: sample cnt calculate result +* @return +* 0, set speed successfully. +* -EINVAL, Unsupported speed. +*/ +static int mtk_i2c_calculate_speed (uint clk_src, +uint target_speed, +uint *timing_step_cnt, +uint *timing_sample_cnt) +{ +uint base_sample_cnt =MAX_SAMPLE_CNT_DIV ; +uint base_step_cnt; +uint max_step_cnt; +uint sample_cnt; +uint step_cnt; +uint opt_div; +uint best_mul; +uint cnt_mul; + +if (target_speed >MAX_HS_MODE_SPEED ) + target_speed =MAX_HS_MODE_SPEED ; + +if (target_speed >MAX_FS_MODE_SPEED ) + max_step_cnt =MAX_HS_STEP_CNT_DIV ; +else + max_step_cnt =MAX_STEP_CNT_DIV ; + + base_step_cnt = max_step_cnt; +/* Find the best combination */ + opt_div =DIV_ROUND_UP (clk_src >>1 , target_speed); + best_mul =MAX_SAMPLE_CNT_DIV * max_step_cnt; + +/* +* Search for the best pair (sample_cnt, step_cnt) with +* 0 < sample_cnt < MAX_SAMPLE_CNT_DIV +* 0 < step_cnt < max_step_cnt +* sample_cnt * step_cnt >= opt_div +* optimizing for sample_cnt * step_cnt being minimal +*/ +for (sample_cnt =1 ; sample_cnt <=MAX_SAMPLE_CNT_DIV ; sample_cnt++) { + step_cnt =DIV_ROUND_UP (opt_div, sample_cnt); + cnt_mul = step_cnt * sample_cnt; +if (step_cnt > max_step_cnt) +continue ; + +if (cnt_mul < best_mul) { + best_mul = cnt_mul; + base_sample_cnt = sample_cnt; + base_step_cnt = step_cnt; +if (best_mul == opt_div) +break ; + } + } + + sample_cnt = base_sample_cnt; + step_cnt = base_step_cnt; + +if ((clk_src / (2 * sample_cnt * step_cnt)) > target_speed) { +/* +* In this case, hardware can't support such +* low i2c_bus_freq +*/ +debug ("Unsupported speed(%uhz)\n" , target_speed); +return log_msg_ret ("calculate speed" , -EINVAL ); + } + + *timing_step_cnt = step_cnt -1 ; + *timing_sample_cnt = sample_cnt -1 ; + +return 0 ; +} + +/* +* mtk_i2c_set_speed +* +* @par Description +* Calculate i2c speed and write sample_cnt, step_cnt to TIMING register. +* @param[in] +* dev: udevice pointer, struct udevice contains i2c source clock, +* clock divide and speed. +* @return +* 0, set speed successfully.\n +* error code from mtk_i2c_calculate_speed(). +*/ +static int mtk_i2c_set_speed (struct udevice *dev,uint speed) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); +uint high_speed_reg; +uint sample_cnt; +uint timing_reg; +uint step_cnt; +uint clk_src; +int ret =0 ; + + priv->speed = speed; +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("set_speed enable clk" ,-1 ); + + clk_src =clk_get_rate (&priv->clk_main) /I2C_DEFAULT_CLK_DIV ; +i2c_writel (priv,REG_CLOCK_DIV , (I2C_DEFAULT_CLK_DIV -1 )); +if (priv->speed >MAX_FS_MODE_SPEED ) { +/* Set master code speed register */ + ret =mtk_i2c_calculate_speed (clk_src,MAX_FS_MODE_SPEED , + &step_cnt, &sample_cnt); +if (ret <0 ) + goto exit; + + timing_reg = (sample_cnt <<TIMING_SAMPLE_OFFSET ) | step_cnt; +i2c_writel (priv,REG_TIMING , timing_reg); +/* Set the high speed mode register */ + ret =mtk_i2c_calculate_speed (clk_src, priv->speed, + &step_cnt, &sample_cnt); +if (ret <0 ) + goto exit; + + high_speed_reg =I2C_TIME_DEFAULT_VALUE | + (sample_cnt <<HS_SAMPLE_OFFSET ) | + (step_cnt <<HS_STEP_OFFSET ); +i2c_writel (priv,REG_HS , high_speed_reg); + }else { + ret =mtk_i2c_calculate_speed (clk_src, priv->speed, + &step_cnt, &sample_cnt); +if (ret <0 ) + goto exit; + + timing_reg = (sample_cnt <<TIMING_SAMPLE_OFFSET ) | step_cnt; +/* Disable the high speed transaction */ + high_speed_reg =I2C_TIME_CLR_VALUE ; +i2c_writel (priv,REG_TIMING , timing_reg); +i2c_writel (priv,REG_HS , high_speed_reg); + } +exit: +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("set_speed disable clk" ,-1 ); + +return ret; +} + +/* +* mtk_i2c_do_transfer +* +* @par Description +* Configure i2c register and trigger transfer. +* @param[in] +* priv: mtk_i2cmtk_i2c_priv pointer, struct mtk_i2c_priv contains register base\n +* address, operation mode, interrupt status and i2c driver data. +* @param[in] +* msgs: i2c_msg pointer, struct i2c_msg contains slave\n +* address, operation mode, msg length and data buffer. +* @param[in] +* num: i2c_msg number. +* @param[in] +* left_num: left i2c_msg number. +* @return +* 0, i2c transfer successfully.\n +* -ETIMEDOUT, i2c transfer timeout.\n +* -EREMOTEIO, i2c transfer ack error. +*/ +static int mtk_i2c_do_transfer (struct mtk_i2c_priv *priv, +struct i2c_msg *msgs, +int num,int left_num) +{ +uint restart_flag =0 ; +uint trans_error =0 ; +uint irq_stat =0 ; +uint tmo_poll =0 ; +uint control_reg; +bool tmo = false; +uint start_reg; +uint addr_reg; +int ret =0 ; + +if (priv->auto_restart) + restart_flag =I2C_RS_TRANSFER ; + + control_reg =i2c_readl (priv,REG_CONTROL ) & + ~(I2C_CONTROL_DIR_CHANGE |I2C_CONTROL_RS ); + +if (priv->speed >MAX_FS_MODE_SPEED || num >1 ) + control_reg |=I2C_CONTROL_RS ; + +if (priv->op ==I2C_MASTER_WRRD ) + control_reg |=I2C_CONTROL_DIR_CHANGE |I2C_CONTROL_RS ; + + control_reg |=I2C_CONTROL_DMA_EN ; +i2c_writel (priv,REG_CONTROL , control_reg); + +/* set start condition */ +if (priv->speed <=MAX_ST_MODE_SPEED ) +i2c_writel (priv,REG_EXT_CONF ,I2C_ST_START_CON ); +else +i2c_writel (priv,REG_EXT_CONF ,I2C_FS_START_CON ); + + addr_reg = msgs->addr <<1 ; +if (priv->op ==I2C_MASTER_RD ) + addr_reg |=I2C_M_RD ; +if (priv->zero_len) +i2c_writel (priv,REG_SLAVE_ADDR , addr_reg |TRANS_ADDR_ONLY ); +else +i2c_writel (priv,REG_SLAVE_ADDR , addr_reg); + +/* clear interrupt status */ +i2c_writel (priv,REG_INTR_STAT , restart_flag |I2C_HS_NACKERR | +I2C_ACKERR |I2C_TRANSAC_COMP ); +i2c_writel (priv,REG_FIFO_ADDR_CLR ,I2C_FIFO_ADDR_CLR ); + +/* enable interrupt */ +i2c_writel (priv,REG_INTR_MASK , restart_flag |I2C_HS_NACKERR | +I2C_ACKERR |I2C_TRANSAC_COMP ); + +/* set transfer and transaction len */ +if (priv->op ==I2C_MASTER_WRRD ) { +i2c_writel (priv,REG_TRANSFER_LEN , msgs->len); +i2c_writel (priv,REG_TRANSFER_LEN_AUX , (msgs +1 )->len); +i2c_writel (priv,REG_TRANSAC_LEN ,I2C_WRRD_TRANAC_VALUE ); + }else { +i2c_writel (priv,REG_TRANSFER_LEN , msgs->len); +i2c_writel (priv,REG_TRANSAC_LEN , num); + } + +/* +* prepare buffer data to start transfer +* three cases here: read, write, write then read +*/ +if (priv->op ==I2C_MASTER_RD ) { +/* Clear DMA interrupt flag*/ +writel (I2C_DMA_INT_FLAG_NONE , priv->pdmabase +REG_INT_FLAG ); +/* Set DMA direction RX*/ +writel (I2C_DMA_CON_RX , priv->pdmabase +REG_CON ); +flush_cache ((ulong )msgs->buf, msgs->len); +/* Write the rx buffer address to dma register*/ +writel ((ulong )msgs->buf, priv->pdmabase +REG_RX_MEM_ADDR ); +/* Write the rx length to dma register*/ +writel (msgs->len, priv->pdmabase +REG_RX_LEN ); + }else if (priv->op ==I2C_MASTER_WR ) { +/* Clear DMA interrupt flag*/ +writel (I2C_DMA_INT_FLAG_NONE , priv->pdmabase +REG_INT_FLAG );
drivers/i2c/mtk_i2c.c
Quoted 10 lines
drivers/i2c/mtk_i2c.c new file +10
-0+/* Set DMA direction TX*/ +writel (I2C_DMA_CON_TX , priv->pdmabase +REG_CON ); +flush_cache ((ulong )msgs->buf, msgs->len); +/* Write the tx buffer address to dma register*/ +writel ((ulong )msgs->buf, priv->pdmabase +REG_TX_MEM_ADDR ); +/* Write the tx length to dma register*/ +writel (msgs->len, priv->pdmabase +REG_TX_LEN ); + }else { +/* Clear DMA interrupt flag*/ +writel (I2C_DMA_INT_FLAG_NONE , priv->pdmabase +REG_INT_FLAG );
I think you can use a switch. Clear can be moved out. You can use a bit more smarter direction flag
in order to flush dcache when needed etc. Your code will be less duplicate and will be much clean
Michael
Quoted 38 lines
drivers/i2c/mtk_i2c.c new file +38
-0+/* Set DMA direction TX and RX*/ +writel (I2C_DMA_TX_RX , priv->pdmabase +REG_CON ); +flush_cache ((ulong )msgs->buf, msgs->len); +flush_cache ((ulong)(msgs +1 )->buf, (msgs +1 )->len); +/* Write the tx buffer address to dma register*/ +writel ((ulong )msgs->buf, priv->pdmabase +REG_TX_MEM_ADDR ); +/* Write the tx buffer address to dma register*/ +writel ((ulong)(msgs +1 )->buf, priv->pdmabase +REG_RX_MEM_ADDR ); +/* Write the tx length to dma register*/ +writel (msgs->len, priv->pdmabase +REG_TX_LEN ); +/* Write the rx length to dma register*/ +writel ((msgs +1 )->len, priv->pdmabase +REG_RX_LEN ); + } + +writel (I2C_DMA_START_EN , priv->pdmabase +REG_EN ); + +if (!priv->auto_restart) { + start_reg =I2C_TRANSAC_START ; + }else { + start_reg =I2C_TRANSAC_START |I2C_RS_MUL_TRIG ; +if (left_num >=1 ) + start_reg |=I2C_RS_MUL_CNFG ; + } +i2c_writel (priv,REG_START , start_reg); + +for (;;) { + irq_stat =i2c_readl (priv,REG_INTR_STAT ); + +/* ignore the first restart irq after the master code */ +if (priv->ignore_restart_irq && (irq_stat | restart_flag)) { + priv->ignore_restart_irq = false; + irq_stat =0 ; +writel (I2C_RS_MUL_CNFG |I2C_RS_MUL_TRIG | +I2C_TRANSAC_START , priv->base +REG_START ); + } + +if (irq_stat & (I2C_TRANSAC_COMP | restart_flag)) { + tmo = false;
drivers/i2c/mtk_i2c.c
Quoted 10 lines
drivers/i2c/mtk_i2c.c new file +10
-0+if (irq_stat & (I2C_HS_NACKERR |I2C_ACKERR )) + trans_error =1 ; + +break ; + } +udelay (1 ); +if (tmo_poll++ >=TRANSFER_TIMEOUT ) { + tmo = true; +break ; + }
I think we have already better function to wait a condition in uboot
Quoted 247 lines
drivers/i2c/mtk_i2c.c new file +241
-1+ } + +/* clear interrupt mask */ +i2c_writel (priv,REG_INTR_MASK , ~(restart_flag |I2C_HS_NACKERR | +I2C_ACKERR |I2C_TRANSAC_COMP )); + +if (!tmo && trans_error !=0 ) { +if (tmo) { + ret = -ETIMEDOUT ; +if (!priv->filter_msg) +debug ("I2C timeout! addr: 0x%x,\n" , msgs->addr); + }else { + ret = -EREMOTEIO ; +if (!priv->filter_msg) +debug ("I2C ACKERR! addr: 0x%x,IRQ:0x%x\n" , + msgs->addr, irq_stat); + } +mtk_i2c_init_hw (priv); + } + +return ret; +} + +/* +* mtk_i2c_transfer +* +* @par Description +* Common i2c transfer API. Set i2c transfer mode according to i2c_msg\n +* information, then call mtk_i2c_do_transfer() to configure i2c register\n +* and trigger transfer. +* @param[in] +* dev: udevice pointer, struct udevice contains struct mtk_i2c_priv, \n +* struct mtk_i2c_priv contains register base\n +* address, operation mode, interrupt status and i2c driver data. +* @param[in] +* msgs: i2c_msg pointer, struct i2c_msg contains slave\n +* address, operation mode, msg length and data buffer. +* @param[in] +* num: i2c_msg number. +* @return +* i2c_msg number, i2c transfer successfully.\n +* -EINVAL, msg length is more than 16\n +* use DMA MODE or slave address more than 0x7f.\n +* error code from mtk_i2c_init_base().\n +* error code from mtk_i2c_set_speed().\n +* error code from mtk_i2c_do_transfer(). +*/ +static int mtk_i2c_transfer (struct udevice *dev,struct i2c_msg *msg, +int nmsgs) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); +int left_num; +uint num_cnt; +int ret; + + priv->auto_restart = true; + left_num = nmsgs; +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("transfer enable clk" ,-1 ); + +for (num_cnt =0 ; num_cnt < nmsgs; num_cnt++) { +if (((msg + num_cnt)->addr) >MAX_I2C_ADDR ) { + ret = -EINVAL ; + goto err_exit; + } +if ((msg + num_cnt)->len >MAX_I2C_LEN ) { + ret = -EINVAL ; + goto err_exit; + } + } + +/* check if we can skip restart and optimize using WRRD mode */ +if (priv->auto_restart && nmsgs ==2 ) { +if (!(msg[0 ].flags &I2C_M_RD ) && (msg[1 ].flags &I2C_M_RD ) && + msg[0 ].addr == msg[1 ].addr) { + priv->auto_restart = false; + } + } + +if (priv->auto_restart && nmsgs >=2 && priv->speed >MAX_FS_MODE_SPEED ) +/* ignore the first restart irq after the master code, +* otherwise the first transfer will be discarded. +*/ + priv->ignore_restart_irq = true; +else + priv->ignore_restart_irq = false; + +while (left_num--) { +/* transfer slave address only to support devices detect */ +if (!msg->buf) + priv->zero_len = true; +else + priv->zero_len = false; + +if (msg->flags &I2C_M_RD ) + priv->op =I2C_MASTER_RD ; +else + priv->op =I2C_MASTER_WR ; + +if (!priv->auto_restart) { +if (nmsgs >1 ) { +/* combined two messages into one transaction */ + priv->op =I2C_MASTER_WRRD ; + left_num--; + } + } + ret =mtk_i2c_do_transfer (priv, msg, nmsgs, left_num); +if (ret <0 ) + goto err_exit; + msg++; + } + ret =0 ; + +err_exit: +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("transfer disable clk" ,-1 ); + +return ret; +} + +static int mtk_i2c_ofdata_to_platdata (struct udevice *dev) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); +int ret; + + priv->base =dev_remap_addr_index (dev,0 ); + priv->pdmabase =dev_remap_addr_index (dev,1 ); + ret =clk_get_by_index (dev,0 , &priv->clk_main); +if (ret) +return log_msg_ret ("clk_get_by_index 0" , ret); + + ret =clk_get_by_index (dev,1 , &priv->clk_dma); + +return ret; +} + +static int mtk_i2c_probe (struct udevice *dev) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); + + priv->soc_data = (struct mtk_i2c_soc_data *)dev_get_driver_data (dev); + +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("probe enable clk" ,-1 ); + +mtk_i2c_init_hw (priv); + +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("probe disable clk" ,-1 ); + +return 0 ; +} + +static int mtk_i2c_deblock (struct udevice *dev) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); + +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("deblock enable clk" ,-1 ); + +mtk_i2c_init_hw (priv); + +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("deblock disable clk" ,-1 ); + +return 0 ; +} + +static const struct mtk_i2c_soc_data mt76xx_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =0 , +}; + +static const struct mtk_i2c_soc_data mt7981_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =1 , +}; + +static const struct mtk_i2c_soc_data mt7986_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =1 , +}; + +static const struct mtk_i2c_soc_data mt8183_soc_data = { + .regs = mt_i2c_regs_v2, + .dma_sync =1 , +}; + +static const struct mtk_i2c_soc_data mt8518_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =0 , +}; + +static const struct mtk_i2c_soc_data mt8512_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =1 , +}; + +static const struct dm_i2c_ops mtk_i2c_ops = { + .xfer = mtk_i2c_transfer, + .set_bus_speed = mtk_i2c_set_speed, + .deblock = mtk_i2c_deblock, +}; + +static const struct udevice_id mtk_i2c_ids[] = { + { + .compatible ="mediatek,mt7622-i2c" , + .data = (ulong)&mt76xx_soc_data, + }, { + .compatible ="mediatek,mt7623-i2c" , + .data = (ulong)&mt76xx_soc_data, + }, { + .compatible ="mediatek,mt7629-i2c" , + .data = (ulong)&mt76xx_soc_data, + }, { + .compatible ="mediatek,mt7981-i2c" , + .data = (ulong)&mt7981_soc_data, + }, { + .compatible ="mediatek,mt7986-i2c" , + .data = (ulong)&mt7986_soc_data, + }, { + .compatible ="mediatek,mt8183-i2c" , + .data = (ulong)&mt8183_soc_data, + }, { + .compatible ="mediatek,mt8512-i2c" , + .data = (ulong)&mt8512_soc_data, + }, { + .compatible ="mediatek,mt8518-i2c" , + .data = (ulong)&mt8518_soc_data, + } +}; + +U_BOOT_DRIVER (mtk_i2c) = { + .name ="mtk_i2c" , + .id =UCLASS_I2C , + .of_match = mtk_i2c_ids, + .of_to_plat = mtk_i2c_ofdata_to_platdata, + .probe = mtk_i2c_probe, + .priv_auto =sizeof (struct mtk_i2c_priv ), + .ops = &mtk_i2c_ops, +}; --2.17.1
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
Re: [PATCH 17/31] i2c: add support for MediaTek I2C interface
Quoted 634 lines · Michael Nazzareno Trimarchi
Hi
Quoted 628 lines · Weijie Gao
This patch adds support for MediaTek I2C interface
Signed-off-by Weijie Gao <[email protected]>--- 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.cdrivers/i2c/Kconfig +0
-0@@ -261,6 +261,15 @@ config SYS_I2C_MESON internal buffer holding up to 8 bytes for transfers andsupports
both 7-bit and 10-bit addresses.drivers/i2c/Kconfig +4
-0+config SYS_I2C_MTK + bool "MediaTek I2C driver" + help + This selects the MediaTek Integrated Inter Circuit busdriver.
+ The I2C bus adapter is the base for some other I2C
client,drivers/i2c/Kconfig +4
-0+ 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" helpdrivers/i2c/Makefile +0
-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.odrivers/i2c/Makefile +1
-0+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.odrivers/i2c/mtk_i2c.c new file +197
-0@@ -0,0 +1,822 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2022 MediaTek Inc. All Rights Reserved. +* +* Author: Mingming Lee <[email protected]> +* +* MediaTek I2C Interface driver +*/ + +#include <clk.h> +#include <cpu_func.h> +#include <dm.h> +#include <i2c.h> +#include <log.h> +#include <asm/cache.h> +#include <asm/io.h> +#include <linux/delay.h> +#include <linux/errno.h> + +#define I2C_RS_TRANSFER BIT(4) +#define I2C_HS_NACKERR BIT(2) +#define I2C_ACKERR BIT(1) +#define I2C_TRANSAC_COMP BIT(0) +#define I2C_TRANSAC_START BIT(0) +#define I2C_RS_MUL_CNFG BIT(15) +#define I2C_RS_MUL_TRIG BIT(14) +#define I2C_DCM_DISABLE 0x0000 +#define I2C_IO_CONFIG_OPEN_DRAIN 0x0003 +#define I2C_IO_CONFIG_PUSH_PULL 0x0000 +#define I2C_SOFT_RST 0x0001 +#define I2C_FIFO_ADDR_CLR 0x0001 +#define I2C_DELAY_LEN 0x0002 +#define I2C_ST_START_CON 0x8001 +#define I2C_FS_START_CON 0x1800 +#define I2C_TIME_CLR_VALUE 0x0000 +#define I2C_TIME_DEFAULT_VALUE 0x0003 +#define I2C_WRRD_TRANAC_VALUE 0x0002 +#define I2C_RD_TRANAC_VALUE 0x0001 + +#define I2C_DMA_CON_TX 0x0000 +#define I2C_DMA_CON_RX 0x0001 +#define I2C_DMA_START_EN 0x0001 +#define I2C_DMA_INT_FLAG_NONE 0x0000 +#define I2C_DMA_CLR_FLAG 0x0000 +#define I2C_DMA_TX_RX 0x0000 +#define I2C_DMA_HARD_RST 0x0002 + +#define MAX_ST_MODE_SPEED 100000 +#define MAX_FS_MODE_SPEED 400000 +#define MAX_HS_MODE_SPEED 3400000 +#define MAX_SAMPLE_CNT_DIV 8 +#define MAX_STEP_CNT_DIV 64 +#define MAX_HS_STEP_CNT_DIV 8 +#define I2C_DEFAULT_CLK_DIV 4 + +#define MAX_I2C_ADDR 0x7f +#define MAX_I2C_LEN 0xff +#define TRANS_ADDR_ONLY BIT(8) +#define TRANSFER_TIMEOUT 50000/* us */ +#define I2C_FIFO_STAT1_MASK 0x001f +#define TIMING_SAMPLE_OFFSET 8 +#define HS_SAMPLE_OFFSET 12 +#define HS_STEP_OFFSET 8 + +#define I2C_CONTROL_WRAPPER BIT(0) +#define I2C_CONTROL_RS BIT(1) +#define I2C_CONTROL_DMA_EN BIT(2) +#define I2C_CONTROL_CLK_EXT_EN BIT(3) +#define I2C_CONTROL_DIR_CHANGE BIT(4) +#define I2C_CONTROL_ACKERR_DET_EN BIT(5) +#define I2C_CONTROL_TRANSFER_LEN_CHANGE BIT(6) +#define I2C_CONTROL_DMAACK BIT(8) +#define I2C_CONTROL_ASYNC BIT(9) + +enum I2C_REGS_OFFSET { +REG_PORT , +REG_SLAVE_ADDR , +REG_INTR_MASK , +REG_INTR_STAT , +REG_CONTROL , +REG_TRANSFER_LEN , +REG_TRANSAC_LEN , +REG_DELAY_LEN , +REG_TIMING , +REG_START , +REG_EXT_CONF , +REG_FIFO_STAT1 , +REG_LTIMING , +REG_FIFO_STAT , +REG_FIFO_THRESH , +REG_FIFO_ADDR_CLR , +REG_IO_CONFIG , +REG_RSV_DEBUG , +REG_HS , +REG_SOFTRESET , +REG_DCM_EN , +REG_PATH_DIR , +REG_DEBUGSTAT , +REG_DEBUGCTRL , +REG_TRANSFER_LEN_AUX , +REG_CLOCK_DIV , +REG_SCL_HL_RATIO , +REG_SCL_HS_HL_RATIO , +REG_SCL_MIS_COMP_POINT , +REG_STA_STOP_AC_TIME , +REG_HS_STA_STOP_AC_TIME , +REG_DATA_TIME , +}; + +enum DMA_REGS_OFFSET { +REG_INT_FLAG =0x0 , +REG_INT_EN =0x04 , +REG_EN =0x08 , +REG_RST =0x0c , +REG_CON =0x18 , +REG_TX_MEM_ADDR =0x1c , +REG_RX_MEM_ADDR =0x20 , +REG_TX_LEN =0x24 , +REG_RX_LEN =0x28 , +}; + +static const uint mt_i2c_regs_v1[] = { + [REG_PORT ] =0x0 , + [REG_SLAVE_ADDR ] =0x4 , + [REG_INTR_MASK ] =0x8 , + [REG_INTR_STAT ] =0xc , + [REG_CONTROL ] =0x10 , + [REG_TRANSFER_LEN ] =0x14 , + [REG_TRANSAC_LEN ] =0x18 , + [REG_DELAY_LEN ] =0x1c , + [REG_TIMING ] =0x20 , + [REG_START ] =0x24 , + [REG_EXT_CONF ] =0x28 , + [REG_FIFO_STAT1 ] =0x2c , + [REG_FIFO_STAT ] =0x30 , + [REG_FIFO_THRESH ] =0x34 , + [REG_FIFO_ADDR_CLR ] =0x38 , + [REG_IO_CONFIG ] =0x40 , + [REG_RSV_DEBUG ] =0x44 , + [REG_HS ] =0x48 , + [REG_SOFTRESET ] =0x50 , + [REG_SOFTRESET ] =0x50 , + [REG_DCM_EN ] =0x54 , + [REG_DEBUGSTAT ] =0x64 , + [REG_DEBUGCTRL ] =0x68 , + [REG_TRANSFER_LEN_AUX ] =0x6c , + [REG_CLOCK_DIV ] =0x70 , + [REG_SCL_HL_RATIO ] =0x74 , + [REG_SCL_HS_HL_RATIO ] =0x78 , + [REG_SCL_MIS_COMP_POINT ] =0x7c , + [REG_STA_STOP_AC_TIME ] =0x80 , + [REG_HS_STA_STOP_AC_TIME ] =0x84 , + [REG_DATA_TIME ] =0x88 , +}; + +static const uint mt_i2c_regs_v2[] = { + [REG_PORT ] =0x0 , + [REG_SLAVE_ADDR ] =0x4 , + [REG_INTR_MASK ] =0x8 , + [REG_INTR_STAT ] =0xc , + [REG_CONTROL ] =0x10 , + [REG_TRANSFER_LEN ] =0x14 , + [REG_TRANSAC_LEN ] =0x18 , + [REG_DELAY_LEN ] =0x1c , + [REG_TIMING ] =0x20 , + [REG_START ] =0x24 , + [REG_EXT_CONF ] =0x28 , + [REG_LTIMING ] =0x2c , + [REG_HS ] =0x30 , + [REG_IO_CONFIG ] =0x34 , + [REG_FIFO_ADDR_CLR ] =0x38 , + [REG_TRANSFER_LEN_AUX ] =0x44 , + [REG_CLOCK_DIV ] =0x48 , + [REG_SOFTRESET ] =0x50 , + [REG_DEBUGSTAT ] =0xe0 , + [REG_DEBUGCTRL ] =0xe8 , + [REG_FIFO_STAT ] =0xf4 , + [REG_FIFO_THRESH ] =0xf8 , + [REG_DCM_EN ] =0xf88 , +}; + +enum mtk_trans_op { +I2C_MASTER_WR =1 , +I2C_MASTER_RD , +I2C_MASTER_WRRD , +}; + +struct mtk_i2c_soc_data { +const uint *regs; +uint dma_sync:1 ; +}; + +struct mtk_i2c_priv { +/* set in i2c probe */ +void __iomem *base;/* i2c base addr */ +void __iomem *pdmabase;/* dma base address*/ +struct clk clk_main;/* main clock for i2c bus */
+ struct clkclk_dma; /* DMA clock for i2c via
DMA */
+ const structmtk_i2c_soc_data*soc_data; /* Compatible data
for different
IC */drivers/i2c/mtk_i2c.c new file +2
-0+enum mtk_trans_op op;/* operation mode */ +bool zero_len;/* Only transfer slave address, no data */
+ bool pushpull; /* push pull mode or open
drain mode */drivers/i2c/mtk_i2c.c new file +7
-0+bool filter_msg;/* filter msg error log */ +bool auto_restart;/* restart mode */ +bool ignore_restart_irq;/* ignore restart IRQ */ +uint speed;/* i2c speed, unit: hz */ +}; + +static inline void i2c_writel(struct mtk_i2c_priv *priv, uint reg,uint
value)drivers/i2c/mtk_i2c.c new file +7
-0+{ +u32 offset = priv->soc_data->regs[reg]; + +writel (value, priv->base + offset); +} + +static inline uint i2c_readl(struct mtk_i2c_priv *priv, uintoffset)
drivers/i2c/mtk_i2c.c new file +44
-0+{ +return readl (priv->base + priv->soc_data->regs[offset]); +} + +static int mtk_i2c_clk_enable (struct mtk_i2c_priv *priv) +{ +int ret; + + ret =clk_enable (&priv->clk_main); +if (ret) +return log_msg_ret ("enable clk_main" , ret); + + ret =clk_enable (&priv->clk_dma); +if (ret) +return log_msg_ret ("enable clk_dma" , ret); + +return 0 ; +} + +static int mtk_i2c_clk_disable (struct mtk_i2c_priv *priv) +{ +int ret; + + ret =clk_disable (&priv->clk_dma); +if (ret) +return log_msg_ret ("disable clk_dma" , ret); + + ret =clk_disable (&priv->clk_main); +if (ret) +return log_msg_ret ("disable clk_main" , ret); + +return 0 ; +} + +static void mtk_i2c_init_hw (struct mtk_i2c_priv *priv) +{ +uint control_reg; + +writel (I2C_DMA_HARD_RST , priv->pdmabase +REG_RST ); +writel (I2C_DMA_CLR_FLAG , priv->pdmabase +REG_RST ); +i2c_writel (priv,REG_SOFTRESET ,I2C_SOFT_RST ); +/* set ioconfig */ +if (priv->pushpull) + i2c_writel(priv, REG_IO_CONFIG,
I2C_IO_CONFIG_PUSH_PULL);drivers/i2c/mtk_i2c.c new file +2
-0+else + i2c_writel(priv, REG_IO_CONFIG,
I2C_IO_CONFIG_OPEN_DRAIN);drivers/i2c/mtk_i2c.c new file +3
-0+ +i2c_writel (priv,REG_DCM_EN ,I2C_DCM_DISABLE ); + control_reg = I2C_CONTROL_ACKERR_DET_EN |
I2C_CONTROL_CLK_EXT_EN;drivers/i2c/mtk_i2c.c new file +2
-0+if (priv->soc_data->dma_sync) + control_reg |= I2C_CONTROL_DMAACK |
I2C_CONTROL_ASYNC;drivers/i2c/mtk_i2c.c new file +9
-0+i2c_writel (priv,REG_CONTROL , control_reg); +i2c_writel (priv,REG_DELAY_LEN ,I2C_DELAY_LEN ); +} + +/* +* Calculate i2c port speed +* +* Hardware design: +* i2c_bus_freq = parent_clk / (clock_div * 2 * sample_cnt *
step_cnt)
+ *clock_div: fixed in hardware, but may be various in different SoCs
+ *
+ * The calculation want to pick the highest bus frequency that is still
+ * less than or equal totarget_speed. The calculation try to get
+ *sample_cntandstep_cn
+ * @param[in]
+ *clk_src: i2c clock source
+ * @param[out]
+ *timing_step_cnt: step cnt calculate result
+ * @param[out]
+ *timing_sample_cnt: sample cnt calculate result
+ * @return
+ * 0, set speed successfully.
+ *-EINVAL, Unsupported speed.
+ */drivers/i2c/mtk_i2c.c new file +35
-0+static int mtk_i2c_calculate_speed (uint clk_src, +uint target_speed, +uint *timing_step_cnt, +uint *timing_sample_cnt) +{ +uint base_sample_cnt =MAX_SAMPLE_CNT_DIV ; +uint base_step_cnt; +uint max_step_cnt; +uint sample_cnt; +uint step_cnt; +uint opt_div; +uint best_mul; +uint cnt_mul; + +if (target_speed >MAX_HS_MODE_SPEED ) + target_speed =MAX_HS_MODE_SPEED ; + +if (target_speed >MAX_FS_MODE_SPEED ) + max_step_cnt =MAX_HS_STEP_CNT_DIV ; +else + max_step_cnt =MAX_STEP_CNT_DIV ; + + base_step_cnt = max_step_cnt; +/* Find the best combination */ + opt_div =DIV_ROUND_UP (clk_src >>1 , target_speed); + best_mul =MAX_SAMPLE_CNT_DIV * max_step_cnt; + +/* +* Search for the best pair (sample_cnt, step_cnt) with +* 0 < sample_cnt < MAX_SAMPLE_CNT_DIV +* 0 < step_cnt < max_step_cnt +* sample_cnt * step_cnt >= opt_div +* optimizing for sample_cnt * step_cnt being minimal +*/ + for (sample_cnt = 1; sample_cnt <= MAX_SAMPLE_CNT_DIV;sample_cnt++) {
drivers/i2c/mtk_i2c.c new file +18
-0+ step_cnt =DIV_ROUND_UP (opt_div, sample_cnt); + cnt_mul = step_cnt * sample_cnt; +if (step_cnt > max_step_cnt) +continue ; + +if (cnt_mul < best_mul) { + best_mul = cnt_mul; + base_sample_cnt = sample_cnt; + base_step_cnt = step_cnt; +if (best_mul == opt_div) +break ; + } + } + + sample_cnt = base_sample_cnt; + step_cnt = base_step_cnt; + +if ((clk_src / (2 * sample_cnt * step_cnt)) > target_speed){
drivers/i2c/mtk_i2c.c new file +19
-0+/* +* In this case, hardware can't support such +* low i2c_bus_freq +*/ +debug ("Unsupported speed(%uhz)\n" , target_speed); +return log_msg_ret ("calculate speed" , -EINVAL ); + } + + *timing_step_cnt = step_cnt -1 ; + *timing_sample_cnt = sample_cnt -1 ; + +return 0 ; +} + +/* +* mtk_i2c_set_speed +* +* @par Description +* Calculate i2c speed and write sample_cnt, step_cnt to TIMING
register.
+ * @param[in]
+ * dev: udevice pointer, struct udevice contains i2c source
clock,
+ * clock divide and speed.
+ * @return
+ * 0, set speed successfully.\n
+ * error code frommtk_i2c_calculate_speed().
+ */drivers/i2c/mtk_i2c.c new file +15
-0+static int mtk_i2c_set_speed (struct udevice *dev,uint speed) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); +uint high_speed_reg; +uint sample_cnt; +uint timing_reg; +uint step_cnt; +uint clk_src; +int ret =0 ; + + priv->speed = speed; +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("set_speed enable clk" ,-1 ); + + clk_src = clk_get_rate(&priv->clk_main) /
I2C_DEFAULT_CLK_DIV;drivers/i2c/mtk_i2c.c new file +4
-0+i2c_writel (priv,REG_CLOCK_DIV , (I2C_DEFAULT_CLK_DIV -1 )); +if (priv->speed >MAX_FS_MODE_SPEED ) { +/* Set master code speed register */ + ret = mtk_i2c_calculate_speed(clk_src,
MAX_FS_MODE_SPEED,
+&step_cnt,&sample_cnt);drivers/i2c/mtk_i2c.c new file +4
-0+if (ret <0 ) + goto exit; + + timing_reg = (sample_cnt << TIMING_SAMPLE_OFFSET) |
step_cnt;drivers/i2c/mtk_i2c.c new file +4
-0+i2c_writel (priv,REG_TIMING , timing_reg); +/* Set the high speed mode register */ + ret = mtk_i2c_calculate_speed(clk_src, priv->speed, + &step_cnt,
&sample_cnt);drivers/i2c/mtk_i2c.c new file +10
-0+if (ret <0 ) + goto exit; + + high_speed_reg =I2C_TIME_DEFAULT_VALUE | + (sample_cnt <<HS_SAMPLE_OFFSET ) | + (step_cnt <<HS_STEP_OFFSET ); +i2c_writel (priv,REG_HS , high_speed_reg); + }else { + ret = mtk_i2c_calculate_speed(clk_src, priv->speed, + &step_cnt,
&sample_cnt);drivers/i2c/mtk_i2c.c new file +4
-0+if (ret <0 ) + goto exit; + + timing_reg = (sample_cnt << TIMING_SAMPLE_OFFSET) |
step_cnt;drivers/i2c/mtk_i2c.c new file +19
-0+/* Disable the high speed transaction */ + high_speed_reg =I2C_TIME_CLR_VALUE ; +i2c_writel (priv,REG_TIMING , timing_reg); +i2c_writel (priv,REG_HS , high_speed_reg); + } +exit: +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("set_speed disable clk" ,-1 ); + +return ret; +} + +/* +* mtk_i2c_do_transfer +* +* @par Description +* Configure i2c register and trigger transfer. +* @param[in] +* priv: mtk_i2cmtk_i2c_priv pointer, struct mtk_i2c_priv contains
register base\n
+ * address, operation mode, interrupt status and i2c driver
data.
+ * @param[in]
+ * msgs:i2c_msgpointer, structi2c_msgcontains slave\n
+ * address, operation mode, msg length and data buffer.
+ * @param[in]
+ * num:i2c_msgnumber.
+ * @param[in]
+ *left_num: lefti2c_msgnumber.
+ * @return+ * 0, i2c transfer successfully.\n + * -ETIMEDOUT, i2c transfer timeout.\n + * -EREMOTEIO, i2c transfer ack error.+ */
drivers/i2c/mtk_i2c.c new file +25
-0+static int mtk_i2c_do_transfer (struct mtk_i2c_priv *priv, +struct i2c_msg *msgs, +int num,int left_num) +{ +uint restart_flag =0 ; +uint trans_error =0 ; +uint irq_stat =0 ; +uint tmo_poll =0 ; +uint control_reg; +bool tmo = false; +uint start_reg; +uint addr_reg; +int ret =0 ; + +if (priv->auto_restart) + restart_flag =I2C_RS_TRANSFER ; + + control_reg =i2c_readl (priv,REG_CONTROL ) & + ~(I2C_CONTROL_DIR_CHANGE |I2C_CONTROL_RS ); + +if (priv->speed >MAX_FS_MODE_SPEED || num >1 ) + control_reg |=I2C_CONTROL_RS ; + +if (priv->op ==I2C_MASTER_WRRD ) + control_reg |= I2C_CONTROL_DIR_CHANGE |
I2C_CONTROL_RS;drivers/i2c/mtk_i2c.c new file +15
-0+ + control_reg |=I2C_CONTROL_DMA_EN ; +i2c_writel (priv,REG_CONTROL , control_reg); + +/* set start condition */ +if (priv->speed <=MAX_ST_MODE_SPEED ) +i2c_writel (priv,REG_EXT_CONF ,I2C_ST_START_CON ); +else +i2c_writel (priv,REG_EXT_CONF ,I2C_FS_START_CON ); + + addr_reg = msgs->addr <<1 ; +if (priv->op ==I2C_MASTER_RD ) + addr_reg |=I2C_M_RD ; +if (priv->zero_len) + i2c_writel(priv, REG_SLAVE_ADDR, addr_reg |
TRANS_ADDR_ONLY);drivers/i2c/mtk_i2c.c new file +5
-0+else +i2c_writel (priv,REG_SLAVE_ADDR , addr_reg); + +/* clear interrupt status */ + i2c_writel(priv, REG_INTR_STAT, restart_flag |
I2C_HS_NACKERR|drivers/i2c/mtk_i2c.c new file +5
-0+ I2C_ACKERR | I2C_TRANSAC_COMP); +i2c_writel (priv,REG_FIFO_ADDR_CLR ,I2C_FIFO_ADDR_CLR ); + +/* enable interrupt */ + i2c_writel(priv, REG_INTR_MASK, restart_flag |
I2C_HS_NACKERR|drivers/i2c/mtk_i2c.c new file +6
-0+ I2C_ACKERR | I2C_TRANSAC_COMP); + +/* set transfer and transaction len */ +if (priv->op ==I2C_MASTER_WRRD ) { +i2c_writel (priv,REG_TRANSFER_LEN , msgs->len); + i2c_writel(priv, REG_TRANSFER_LEN_AUX, (msgs + 1)-Quoted 1 line
len);
+ i2c_writel(priv,
REG_TRANSAC_LEN,I2C_WRRD_TRANAC_VALUE);drivers/i2c/mtk_i2c.c new file +12
-0+ }else { +i2c_writel (priv,REG_TRANSFER_LEN , msgs->len); +i2c_writel (priv,REG_TRANSAC_LEN , num); + } + +/* +* prepare buffer data to start transfer +* three cases here: read, write, write then read +*/ +if (priv->op ==I2C_MASTER_RD ) { +/* Clear DMA interrupt flag*/ + writel(I2C_DMA_INT_FLAG_NONE, priv->pdmabase +
REG_INT_FLAG);drivers/i2c/mtk_i2c.c new file +5
-0+/* Set DMA direction RX*/ +writel (I2C_DMA_CON_RX , priv->pdmabase +REG_CON ); +flush_cache ((ulong )msgs->buf, msgs->len); +/* Write the rx buffer address to dma register*/ + writel((ulong)msgs->buf, priv->pdmabase +
REG_RX_MEM_ADDR);drivers/i2c/mtk_i2c.c new file +5
-0+/* Write the rx length to dma register*/ +writel (msgs->len, priv->pdmabase +REG_RX_LEN ); + }else if (priv->op ==I2C_MASTER_WR ) { +/* Clear DMA interrupt flag*/ + writel(I2C_DMA_INT_FLAG_NONE, priv->pdmabase +
REG_INT_FLAG);drivers/i2c/mtk_i2c.c new file +5
-0+/* Set DMA direction TX*/ +writel (I2C_DMA_CON_TX , priv->pdmabase +REG_CON ); +flush_cache ((ulong )msgs->buf, msgs->len); +/* Write the tx buffer address to dma register*/ + writel((ulong)msgs->buf, priv->pdmabase +
REG_TX_MEM_ADDR);drivers/i2c/mtk_i2c.c new file +5
-0+/* Write the tx length to dma register*/ +writel (msgs->len, priv->pdmabase +REG_TX_LEN ); + }else { +/* Clear DMA interrupt flag*/ + writel(I2C_DMA_INT_FLAG_NONE, priv->pdmabase +Quoted 1 line
REG_INT_FLAG);
Quoted 6 lines
I think you can use a switch. Clear can be moved out. You can use a bit more smarter direction flag
in order to flush dcache when needed etc. Your code will be less duplicate and will be much cleanMichael
OK. I'll reorganize this part.
Quoted 51 lines
Quoted 51 lines
drivers/i2c/mtk_i2c.c new file +4
-0+/* Set DMA direction TX and RX*/ +writel (I2C_DMA_TX_RX , priv->pdmabase +REG_CON ); +flush_cache ((ulong )msgs->buf, msgs->len); + flush_cache((ulong)(msgs + 1)->buf, (msgs + 1)-Quoted 1 line
len);
drivers/i2c/mtk_i2c.c new file +2
-0+/* Write the tx buffer address to dma register*/ + writel((ulong)msgs->buf, priv->pdmabase +
REG_TX_MEM_ADDR);drivers/i2c/mtk_i2c.c new file +2
-0+/* Write the tx buffer address to dma register*/ + writel((ulong)(msgs + 1)->buf, priv->pdmabase +
REG_RX_MEM_ADDR);drivers/i2c/mtk_i2c.c new file +4
-0+/* Write the tx length to dma register*/ +writel (msgs->len, priv->pdmabase +REG_TX_LEN ); +/* Write the rx length to dma register*/ + writel((msgs + 1)->len, priv->pdmabase +
REG_RX_LEN);drivers/i2c/mtk_i2c.c new file +17
-0+ } + +writel (I2C_DMA_START_EN , priv->pdmabase +REG_EN ); + +if (!priv->auto_restart) { + start_reg =I2C_TRANSAC_START ; + }else { + start_reg =I2C_TRANSAC_START |I2C_RS_MUL_TRIG ; +if (left_num >=1 ) + start_reg |=I2C_RS_MUL_CNFG ; + } +i2c_writel (priv,REG_START , start_reg); + +for (;;) { + irq_stat =i2c_readl (priv,REG_INTR_STAT ); + +/* ignore the first restart irq after the master code */
+ if (priv->ignore_restart_irq&& (irq_stat|restart_flag)) {drivers/i2c/mtk_i2c.c new file +4
-0+ priv->ignore_restart_irq = false; + irq_stat =0 ; + writel(I2C_RS_MUL_CNFG | I2C_RS_MUL_TRIG | + I2C_TRANSAC_START, priv->base +
REG_START);drivers/i2c/mtk_i2c.c new file +5
-0+ } + +if (irq_stat & (I2C_TRANSAC_COMP | restart_flag)) { + tmo = false; + if (irq_stat & (I2C_HS_NACKERR |
I2C_ACKERR))drivers/i2c/mtk_i2c.c new file +3
-0+ trans_error =1 ; + +break ;
Quoted 8 lines
drivers/i2c/mtk_i2c.c
Quoted 6 lines
drivers/i2c/mtk_i2c.c new file +6
-0+ } +udelay (1 ); +if (tmo_poll++ >=TRANSFER_TIMEOUT ) { + tmo = true; +break ; + }I think we have already better function to wait a condition in uboot
I didn't find such a function that can handle this complex condition. wait_for_bit_xx can only wait for bits set unconditionally.
Quoted 265 lines
Quoted 263 lines
drivers/i2c/mtk_i2c.c new file +4
-0+ } + +/* clear interrupt mask */ + i2c_writel(priv, REG_INTR_MASK, ~(restart_flag |
I2C_HS_NACKERR|drivers/i2c/mtk_i2c.c new file +7
-0+ I2C_ACKERR | I2C_TRANSAC_COMP)); + +if (!tmo && trans_error !=0 ) { +if (tmo) { + ret = -ETIMEDOUT ; +if (!priv->filter_msg) + debug("I2C timeout! addr: 0x%x,\n",
msgs->addr);drivers/i2c/mtk_i2c.c new file +4
-0+ }else { + ret = -EREMOTEIO ; +if (!priv->filter_msg) + debug("I2C ACKERR! addr:0x%x,IRQ:0x%x\n",
drivers/i2c/mtk_i2c.c new file +14
-0+ msgs->addr, irq_stat); + } +mtk_i2c_init_hw (priv); + } + +return ret; +} + +/* +* mtk_i2c_transfer +* +* @par Description +* Common i2c transfer API. Set i2c transfer mode according to i2c_msg\n +* information, then call mtk_i2c_do_transfer() to configure i2c
register\n
+ * and trigger transfer.
+ * @param[in]
+ * dev: udevice pointer, struct udevice contains structmtk_i2c_priv,
\n
+ * structmtk_i2c_privcontains register base\n
+ * address, operation mode, interrupt status and i2c driver
data.
+ * @param[in]
+ * msgs:i2c_msgpointer, structi2c_msgcontains slave\n
+ * address, operation mode, msg length and data buffer.
+ * @param[in]
+ * num:i2c_msgnumber.
+ * @return+ * i2c_msg number, i2c transfer successfully.\n + * -EINVAL, msg length is more than 16\n + * use DMA MODE or slave address more than 0x7f.\n + * error code from mtk_i2c_init_base().\n + * error code from mtk_i2c_set_speed().\n + * error code from mtk_i2c_do_transfer().+ */
+static int mtk_i2c_transfer(struct udevice *dev, structi2c_msg*msg,drivers/i2c/mtk_i2c.c new file +24
-0+ int nmsgs) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); +int left_num; +uint num_cnt; +int ret; + + priv->auto_restart = true; + left_num = nmsgs; +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("transfer enable clk" ,-1 ); + +for (num_cnt =0 ; num_cnt < nmsgs; num_cnt++) { +if (((msg + num_cnt)->addr) >MAX_I2C_ADDR ) { + ret = -EINVAL ; + goto err_exit; + } +if ((msg + num_cnt)->len >MAX_I2C_LEN ) { + ret = -EINVAL ; + goto err_exit; + } + } + +/* check if we can skip restart and optimize using WRRD mode */
drivers/i2c/mtk_i2c.c new file +2
-0+if (priv->auto_restart && nmsgs ==2 ) { + if (!(msg[0].flags & I2C_M_RD) && (msg[1].flags &
I2C_M_RD) &&drivers/i2c/mtk_i2c.c new file +6
-0+ msg[0].addr == msg[1].addr) { + priv->auto_restart = false; + } + } + + if (priv->auto_restart && nmsgs >= 2 && priv->speed >
MAX_FS_MODE_SPEED)
+ /* ignore the first restart irq after the master
code,drivers/i2c/mtk_i2c.c new file +8
-0+* otherwise the first transfer will be discarded. +*/ + priv->ignore_restart_irq = true; + else + priv->ignore_restart_irq = false; + +while (left_num--) { +/* transfer slave address only to support devices detect */
drivers/i2c/mtk_i2c.c new file +13
-0+if (!msg->buf) + priv->zero_len = true; +else + priv->zero_len = false; + +if (msg->flags &I2C_M_RD ) + priv->op =I2C_MASTER_RD ; +else + priv->op =I2C_MASTER_WR ; + +if (!priv->auto_restart) { +if (nmsgs >1 ) { +/* combined two messages into one transaction */
drivers/i2c/mtk_i2c.c new file +5
-0+ priv->op =I2C_MASTER_WRRD ; + left_num--; + } + } + ret = mtk_i2c_do_transfer(priv, msg, nmsgs,
left_num);drivers/i2c/mtk_i2c.c new file +34
-0+if (ret <0 ) + goto err_exit; + msg++; + } + ret =0 ; + +err_exit: +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("transfer disable clk" ,-1 ); + +return ret; +} + +static int mtk_i2c_ofdata_to_platdata (struct udevice *dev) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); +int ret; + + priv->base =dev_remap_addr_index (dev,0 ); + priv->pdmabase =dev_remap_addr_index (dev,1 ); + ret =clk_get_by_index (dev,0 , &priv->clk_main); +if (ret) +return log_msg_ret ("clk_get_by_index 0" , ret); + + ret =clk_get_by_index (dev,1 , &priv->clk_dma); + +return ret; +} + +static int mtk_i2c_probe (struct udevice *dev) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); + + priv->soc_data = (struct mtk_i2c_soc_data*)dev_get_driver_data(dev);
drivers/i2c/mtk_i2c.c new file +100
-1+ +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("probe enable clk" ,-1 ); + +mtk_i2c_init_hw (priv); + +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("probe disable clk" ,-1 ); + +return 0 ; +} + +static int mtk_i2c_deblock (struct udevice *dev) +{ +struct mtk_i2c_priv *priv =dev_get_priv (dev); + +if (mtk_i2c_clk_enable (priv)) +return log_msg_ret ("deblock enable clk" ,-1 ); + +mtk_i2c_init_hw (priv); + +if (mtk_i2c_clk_disable (priv)) +return log_msg_ret ("deblock disable clk" ,-1 ); + +return 0 ; +} + +static const struct mtk_i2c_soc_data mt76xx_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =0 , +}; + +static const struct mtk_i2c_soc_data mt7981_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =1 , +}; + +static const struct mtk_i2c_soc_data mt7986_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =1 , +}; + +static const struct mtk_i2c_soc_data mt8183_soc_data = { + .regs = mt_i2c_regs_v2, + .dma_sync =1 , +}; + +static const struct mtk_i2c_soc_data mt8518_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =0 , +}; + +static const struct mtk_i2c_soc_data mt8512_soc_data = { + .regs = mt_i2c_regs_v1, + .dma_sync =1 , +}; + +static const struct dm_i2c_ops mtk_i2c_ops = { + .xfer = mtk_i2c_transfer, + .set_bus_speed = mtk_i2c_set_speed, + .deblock = mtk_i2c_deblock, +}; + +static const struct udevice_id mtk_i2c_ids[] = { + { + .compatible ="mediatek,mt7622-i2c" , + .data = (ulong)&mt76xx_soc_data, + }, { + .compatible ="mediatek,mt7623-i2c" , + .data = (ulong)&mt76xx_soc_data, + }, { + .compatible ="mediatek,mt7629-i2c" , + .data = (ulong)&mt76xx_soc_data, + }, { + .compatible ="mediatek,mt7981-i2c" , + .data = (ulong)&mt7981_soc_data, + }, { + .compatible ="mediatek,mt7986-i2c" , + .data = (ulong)&mt7986_soc_data, + }, { + .compatible ="mediatek,mt8183-i2c" , + .data = (ulong)&mt8183_soc_data, + }, { + .compatible ="mediatek,mt8512-i2c" , + .data = (ulong)&mt8512_soc_data, + }, { + .compatible ="mediatek,mt8518-i2c" , + .data = (ulong)&mt8518_soc_data, + } +}; + +U_BOOT_DRIVER (mtk_i2c) = { + .name ="mtk_i2c" , + .id =UCLASS_I2C , + .of_match = mtk_i2c_ids, + .of_to_plat = mtk_i2c_ofdata_to_platdata, + .probe = mtk_i2c_probe, + .priv_auto =sizeof (struct mtk_i2c_priv ), + .ops = &mtk_i2c_ops, +}; --2.17.1
PATCH 18/31 arm: dts: mt7622: add i2c support
In reply to Weijie GaoAdd both hardware and software i2c support for mt7622.
--- 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
Re: [PATCH 18/31] arm: dts: mt7622: add i2c support
Quoted 8 lines · Weijie Gao
Add both hardware and software i2c support for mt7622.
Signed-off-by Weijie Gao <[email protected]>--- arch/arm/dts/mt7622-rfb.dts | 18 ++++++++++++++++++ arch/arm/dts/mt7622.dtsi | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
PATCH 19/31 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.
--- include/dt-bindings/pinctrl/mt65xx.h | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/dt-bindings/pinctrl/mt65xx.h
(quoted diff) +0 -0
b/include/dt-bindings/pinctrl/mt65xx.h
new file mode 100644
index 0000000000..fbea8d35bc
include/dt-bindings/pinctrl/mt65xx.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 19/31] dt-bindings: pinctrl: mediatek: add a header for common pinconf parameters
Quoted 9 lines · Weijie Gao
This patch adds a pinctrl header for common pinconf parameters such as pull-up/pull-down resistors and drive strengths.
Signed-off-by Weijie Gao <[email protected]>--- include/dt-bindings/pinctrl/mt65xx.h | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/dt-bindings/pinctrl/mt65xx.h
PATCH 20/31 pinctrl: mediatek: add pinctrl driver for MT7981 SoC
In reply to Weijie GaoThis patch adds pinctrl and gpio support for MT7981 SoC
--- 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
(quoted diff) +0 -0
b/drivers/pinctrl/mediatek/Kconfig
index 58df508d7e..aceec9277d 100644
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
(quoted diff) +0 -0
b/drivers/pinctrl/mediatek/Makefile
index d7e8cf1727..1879d7ae2a 100644
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
(quoted diff) +0 -0
b/drivers/pinctrl/mediatek/pinctrl-mt7981.c
new file mode 100644
index 0000000000..d8875241cb
drivers/pinctrl/mediatek/pinctrl-mt7981.c new file +18 -0
@@ -0,0 +1,1049 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* The MT7981 driver based on Linux generic pinctrl binding. +* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <dm.h> +#include "pinctrl-mtk-common.h" + +#define MT7981_TYPE0_PIN (_number, _name) \ + MTK_TYPED_PIN(_number, _name, DRV_GRP4, IO_TYPE_GRP0) + +#define MT7981_TYPE1_PIN (_number, _name) \ + MTK_TYPED_PIN(_number, _name, DRV_GRP4, IO_TYPE_GRP1) + +#define PIN_FIELD_GPIO (_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits)
\
+ PIN_FIELD_BASE_CALC(_s_pin, _e_pin, GPIO_BASE, _s_addr, _x_addrs, \
+ _s_bit, _x_bits, 32, 0)
+
+#define PIN_FIELD_BASE(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, _s_bit,
\
+ _x_bits) \
+ PIN_FIELD_BASE_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, _s_bit, \
+ _x_bits, 32, 0)
+
+/**
+ * enum - Locking variants of the iocfg bases
+ *
+ * MT7981 have multiple bases to program pin configuration listed as the below:
+ * iocfg_rt:0x11c00000, iocfg_rm:0x11c10000, iocfg_rb:0x11d20000,
+ * iocfg_lb:0x11e00000, iocfg_bl:0x11e20000, iocfg_tm:0x11f00000,
+ * iocfg_tl:0x11f10000,
+ * _i_based could be used to indicate what base the pin should be mapped into.
+ *
+ * Each iocfg register base control different group of pads on the SoC
+ *
+ *
+ * chip carrier
+ *
+ * A B C D E F G H
+ * +------------------------+ + * 8 | o o o o o o o o | + * 7 | o o o o o o o o | + * 6 | o o o o o o o o | + * 5 | o o o o o o o o | + * 4 | o o o o o o o o | + * 3 | o o o o o o o o | + * 2 | o o o o o o o o | + * 1 | o o o o o o o o | + * +------------------------+
+ *
+ * inside Chip carrier
+ *
+ * A B C D E F G H
+ * +------------------------+ + * 8 | | + * 7 | TL TM | + * 6 | +---------+ | + * 5 | | | RT | + * 4 | | | RM | + * 3 | LB | | RB | + * 2 | +---------+ | + * 1 | BL | + * +------------------------+
+ *
+ */
+
+enum {
+ GPIO_BASE,
+ IOCFG_RT_BASE,
+ IOCFG_RM_BASE,
+ IOCFG_RB_BASE,
+ IOCFG_LB_BASE,
+ IOCFG_BL_BASE,
+ IOCFG_TM_BASE,
+ IOCFG_TL_BASE,
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_mode_range[] = {
+ PIN_FIELD_GPIO(0, 56, 0x300, 0x10, 0, 4),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_dir_range[] = {
+ PIN_FIELD_GPIO(0, 56, 0x0, 0x10, 0, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_di_range[] = {
+ PIN_FIELD_GPIO(0, 56, 0x200, 0x10, 0, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_do_range[] = {
+ PIN_FIELD_GPIO(0, 56, 0x100, 0x10, 0, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_ies_range[] = {
+ PIN_FIELD_BASE(0, 0, 1, 0x10, 0x10, 1, 1),
+ PIN_FIELD_BASE(1, 1, 1, 0x10, 0x10, 0, 1),
+ PIN_FIELD_BASE(2, 2, 5, 0x20, 0x10, 6, 1),
+ PIN_FIELD_BASE(3, 3, 4, 0x20, 0x10, 6, 1),
+ PIN_FIELD_BASE(4, 4, 4, 0x20, 0x10, 2, 1),
+ PIN_FIELD_BASE(5, 5, 4, 0x20, 0x10, 1, 1),
+ PIN_FIELD_BASE(6, 6, 4, 0x20, 0x10, 3, 1),
+ PIN_FIELD_BASE(7, 7, 4, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(8, 8, 4, 0x20, 0x10, 4, 1),
+ PIN_FIELD_BASE(9, 9, 4, 0x20, 0x10, 9, 1),
+
+ PIN_FIELD_BASE(10, 10, 5, 0x20, 0x10, 8, 1),
+ PIN_FIELD_BASE(11, 11, 5, 0x40, 0x10, 10, 1),
+ PIN_FIELD_BASE(12, 12, 5, 0x20, 0x10, 7, 1),
+ PIN_FIELD_BASE(13, 13, 5, 0x20, 0x10, 11, 1),
+
+ PIN_FIELD_BASE(14, 14, 4, 0x20, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(15, 15, 2, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(16, 16, 2, 0x20, 0x10, 1, 1),
+ PIN_FIELD_BASE(17, 17, 2, 0x20, 0x10, 5, 1),
+ PIN_FIELD_BASE(18, 18, 2, 0x20, 0x10, 4, 1),
+ PIN_FIELD_BASE(19, 19, 2, 0x20, 0x10, 2, 1),
+ PIN_FIELD_BASE(20, 20, 2, 0x20, 0x10, 3, 1),
+ PIN_FIELD_BASE(21, 21, 2, 0x20, 0x10, 6, 1),
+ PIN_FIELD_BASE(22, 22, 2, 0x20, 0x10, 7, 1),
+ PIN_FIELD_BASE(23, 23, 2, 0x20, 0x10, 10, 1),
+ PIN_FIELD_BASE(24, 24, 2, 0x20, 0x10, 9, 1),
+ PIN_FIELD_BASE(25, 25, 2, 0x20, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(26, 26, 5, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(27, 27, 5, 0x20, 0x10, 4, 1),
+ PIN_FIELD_BASE(28, 28, 5, 0x20, 0x10, 3, 1),
+ PIN_FIELD_BASE(29, 29, 5, 0x20, 0x10, 1, 1),
+ PIN_FIELD_BASE(30, 30, 5, 0x20, 0x10, 2, 1),
+ PIN_FIELD_BASE(31, 31, 5, 0x20, 0x10, 5, 1),
+
+ PIN_FIELD_BASE(32, 32, 1, 0x10, 0x10, 2, 1),
+ PIN_FIELD_BASE(33, 33, 1, 0x10, 0x10, 3, 1),
+
+ PIN_FIELD_BASE(34, 34, 4, 0x20, 0x10, 5, 1),
+ PIN_FIELD_BASE(35, 35, 4, 0x20, 0x10, 7, 1),
+
+ PIN_FIELD_BASE(36, 36, 3, 0x10, 0x10, 2, 1),
+ PIN_FIELD_BASE(37, 37, 3, 0x10, 0x10, 3, 1),
+ PIN_FIELD_BASE(38, 38, 3, 0x10, 0x10, 0, 1),
+ PIN_FIELD_BASE(39, 39, 3, 0x10, 0x10, 1, 1),
+
+ PIN_FIELD_BASE(40, 40, 7, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(41, 41, 7, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(42, 42, 7, 0x30, 0x10, 9, 1),
+ PIN_FIELD_BASE(43, 43, 7, 0x30, 0x10, 7, 1),
+ PIN_FIELD_BASE(44, 44, 7, 0x30, 0x10, 8, 1),
+ PIN_FIELD_BASE(45, 45, 7, 0x30, 0x10, 3, 1),
+ PIN_FIELD_BASE(46, 46, 7, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(47, 47, 7, 0x30, 0x10, 5, 1),
+ PIN_FIELD_BASE(48, 48, 7, 0x30, 0x10, 6, 1),
+ PIN_FIELD_BASE(49, 49, 7, 0x30, 0x10, 2, 1),
+
+ PIN_FIELD_BASE(50, 50, 6, 0x10, 0x10, 0, 1),
+ PIN_FIELD_BASE(51, 51, 6, 0x10, 0x10, 2, 1),
+ PIN_FIELD_BASE(52, 52, 6, 0x10, 0x10, 3, 1),
+ PIN_FIELD_BASE(53, 53, 6, 0x10, 0x10, 4, 1),
+ PIN_FIELD_BASE(54, 54, 6, 0x10, 0x10, 5, 1),
+ PIN_FIELD_BASE(55, 55, 6, 0x10, 0x10, 6, 1),
+ PIN_FIELD_BASE(56, 56, 6, 0x10, 0x10, 1, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_smt_range[] = {
+ PIN_FIELD_BASE(0, 0, 1, 0x60, 0x10, 1, 1),
+ PIN_FIELD_BASE(1, 1, 1, 0x60, 0x10, 0, 1),
+ PIN_FIELD_BASE(2, 2, 5, 0x90, 0x10, 6, 1),
+ PIN_FIELD_BASE(3, 3, 4, 0x80, 0x10, 6, 1),
+ PIN_FIELD_BASE(4, 4, 4, 0x80, 0x10, 2, 1),
+ PIN_FIELD_BASE(5, 5, 4, 0x80, 0x10, 1, 1),
+ PIN_FIELD_BASE(6, 6, 4, 0x80, 0x10, 3, 1),
+ PIN_FIELD_BASE(7, 7, 4, 0x80, 0x10, 0, 1),
+ PIN_FIELD_BASE(8, 8, 4, 0x80, 0x10, 4, 1),
+ PIN_FIELD_BASE(9, 9, 4, 0x80, 0x10, 9, 1),
+
+ PIN_FIELD_BASE(10, 10, 5, 0x90, 0x10, 8, 1),
+ PIN_FIELD_BASE(11, 11, 5, 0x90, 0x10, 10, 1),
+ PIN_FIELD_BASE(12, 12, 5, 0x90, 0x10, 7, 1),
+ PIN_FIELD_BASE(13, 13, 5, 0x90, 0x10, 11, 1),
+
+ PIN_FIELD_BASE(14, 14, 4, 0x80, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(15, 15, 2, 0x90, 0x10, 0, 1),
+ PIN_FIELD_BASE(16, 16, 2, 0x90, 0x10, 1, 1),
+ PIN_FIELD_BASE(17, 17, 2, 0x90, 0x10, 5, 1),
+ PIN_FIELD_BASE(18, 18, 2, 0x90, 0x10, 4, 1),
+ PIN_FIELD_BASE(19, 19, 2, 0x90, 0x10, 2, 1),
+ PIN_FIELD_BASE(20, 20, 2, 0x90, 0x10, 3, 1),
+ PIN_FIELD_BASE(21, 21, 2, 0x90, 0x10, 6, 1),
+ PIN_FIELD_BASE(22, 22, 2, 0x90, 0x10, 7, 1),
+ PIN_FIELD_BASE(23, 23, 2, 0x90, 0x10, 10, 1),
+ PIN_FIELD_BASE(24, 24, 2, 0x90, 0x10, 9, 1),
+ PIN_FIELD_BASE(25, 25, 2, 0x90, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(26, 26, 5, 0x90, 0x10, 0, 1),
+ PIN_FIELD_BASE(27, 27, 5, 0x90, 0x10, 4, 1),
+ PIN_FIELD_BASE(28, 28, 5, 0x90, 0x10, 3, 1),
+ PIN_FIELD_BASE(29, 29, 5, 0x90, 0x10, 1, 1),
+ PIN_FIELD_BASE(30, 30, 5, 0x90, 0x10, 2, 1),
+ PIN_FIELD_BASE(31, 31, 5, 0x90, 0x10, 5, 1),
+
+ PIN_FIELD_BASE(32, 32, 1, 0x60, 0x10, 2, 1),
+ PIN_FIELD_BASE(33, 33, 1, 0x60, 0x10, 3, 1),
+
+ PIN_FIELD_BASE(34, 34, 4, 0x80, 0x10, 5, 1),
+ PIN_FIELD_BASE(35, 35, 4, 0x80, 0x10, 7, 1),
+
+ PIN_FIELD_BASE(36, 36, 3, 0x60, 0x10, 2, 1),
+ PIN_FIELD_BASE(37, 37, 3, 0x60, 0x10, 3, 1),
+ PIN_FIELD_BASE(38, 38, 3, 0x60, 0x10, 0, 1),
+ PIN_FIELD_BASE(39, 39, 3, 0x60, 0x10, 1, 1),
+
+ PIN_FIELD_BASE(40, 40, 7, 0x70, 0x10, 1, 1),
+ PIN_FIELD_BASE(41, 41, 7, 0x70, 0x10, 0, 1),
+ PIN_FIELD_BASE(42, 42, 7, 0x70, 0x10, 9, 1),
+ PIN_FIELD_BASE(43, 43, 7, 0x70, 0x10, 7, 1),
+ PIN_FIELD_BASE(44, 44, 7, 0x30, 0x10, 8, 1),
+ PIN_FIELD_BASE(45, 45, 7, 0x70, 0x10, 3, 1),
+ PIN_FIELD_BASE(46, 46, 7, 0x70, 0x10, 4, 1),
+ PIN_FIELD_BASE(47, 47, 7, 0x70, 0x10, 5, 1),
+ PIN_FIELD_BASE(48, 48, 7, 0x70, 0x10, 6, 1),
+ PIN_FIELD_BASE(49, 49, 7, 0x70, 0x10, 2, 1),
+
+ PIN_FIELD_BASE(50, 50, 6, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(51, 51, 6, 0x50, 0x10, 2, 1),
+ PIN_FIELD_BASE(52, 52, 6, 0x50, 0x10, 3, 1),
+ PIN_FIELD_BASE(53, 53, 6, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(54, 54, 6, 0x50, 0x10, 5, 1),
+ PIN_FIELD_BASE(55, 55, 6, 0x50, 0x10, 6, 1),
+ PIN_FIELD_BASE(56, 56, 6, 0x50, 0x10, 1, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_pu_range[] = {
+ PIN_FIELD_BASE(40, 40, 7, 0x50, 0x10, 1, 1),
+ PIN_FIELD_BASE(41, 41, 7, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(42, 42, 7, 0x50, 0x10, 9, 1),
+ PIN_FIELD_BASE(43, 43, 7, 0x50, 0x10, 7, 1),
+ PIN_FIELD_BASE(44, 44, 7, 0x50, 0x10, 8, 1),
+ PIN_FIELD_BASE(45, 45, 7, 0x50, 0x10, 3, 1),
+ PIN_FIELD_BASE(46, 46, 7, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(47, 47, 7, 0x50, 0x10, 5, 1),
+ PIN_FIELD_BASE(48, 48, 7, 0x50, 0x10, 6, 1),
+ PIN_FIELD_BASE(49, 49, 7, 0x50, 0x10, 2, 1),
+
+ PIN_FIELD_BASE(50, 50, 6, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(51, 51, 6, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(52, 52, 6, 0x30, 0x10, 3, 1),
+ PIN_FIELD_BASE(53, 53, 6, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(54, 54, 6, 0x30, 0x10, 5, 1),
+ PIN_FIELD_BASE(55, 55, 6, 0x30, 0x10, 6, 1),
+ PIN_FIELD_BASE(56, 56, 6, 0x30, 0x10, 1, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_pd_range[] = {
+ PIN_FIELD_BASE(40, 40, 7, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(41, 41, 7, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(42, 42, 7, 0x40, 0x10, 9, 1),
+ PIN_FIELD_BASE(43, 43, 7, 0x40, 0x10, 7, 1),
+ PIN_FIELD_BASE(44, 44, 7, 0x40, 0x10, 8, 1),
+ PIN_FIELD_BASE(45, 45, 7, 0x40, 0x10, 3, 1),
+ PIN_FIELD_BASE(46, 46, 7, 0x40, 0x10, 4, 1),
+ PIN_FIELD_BASE(47, 47, 7, 0x40, 0x10, 5, 1),
+ PIN_FIELD_BASE(48, 48, 7, 0x40, 0x10, 6, 1),
+ PIN_FIELD_BASE(49, 49, 7, 0x40, 0x10, 2, 1),
+
+ PIN_FIELD_BASE(50, 50, 6, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(51, 51, 6, 0x20, 0x10, 2, 1),
+ PIN_FIELD_BASE(52, 52, 6, 0x20, 0x10, 3, 1),
+ PIN_FIELD_BASE(53, 53, 6, 0x20, 0x10, 4, 1),
+ PIN_FIELD_BASE(54, 54, 6, 0x20, 0x10, 5, 1),
+ PIN_FIELD_BASE(55, 55, 6, 0x20, 0x10, 6, 1),
+ PIN_FIELD_BASE(56, 56, 6, 0x20, 0x10, 1, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_drv_range[] = {
+ PIN_FIELD_BASE(0, 0, 1, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(1, 1, 1, 0x00, 0x10, 0, 3),
+
+ PIN_FIELD_BASE(2, 2, 5, 0x00, 0x10, 18, 3),
+
+ PIN_FIELD_BASE(3, 3, 4, 0x00, 0x10, 18, 1),
+ PIN_FIELD_BASE(4, 4, 4, 0x00, 0x10, 6, 1),
+ PIN_FIELD_BASE(5, 5, 4, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(6, 6, 4, 0x00, 0x10, 9, 3),
+ PIN_FIELD_BASE(7, 7, 4, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(8, 8, 4, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(9, 9, 4, 0x00, 0x10, 27, 3),
+
+ PIN_FIELD_BASE(10, 10, 5, 0x00, 0x10, 24, 3),
+ PIN_FIELD_BASE(11, 11, 5, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(12, 12, 5, 0x00, 0x10, 21, 3),
+ PIN_FIELD_BASE(13, 13, 5, 0x00, 0x10, 3, 3),
+
+ PIN_FIELD_BASE(14, 14, 4, 0x00, 0x10, 27, 3),
+
+ PIN_FIELD_BASE(15, 15, 2, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(16, 16, 2, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(17, 17, 2, 0x00, 0x10, 15, 3),
+ PIN_FIELD_BASE(18, 18, 2, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(19, 19, 2, 0x00, 0x10, 6, 3),
+ PIN_FIELD_BASE(20, 20, 2, 0x00, 0x10, 9, 3),
+ PIN_FIELD_BASE(21, 21, 2, 0x00, 0x10, 18, 3),
+ PIN_FIELD_BASE(22, 22, 2, 0x00, 0x10, 21, 3),
+ PIN_FIELD_BASE(23, 23, 2, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(24, 24, 2, 0x00, 0x10, 27, 3),
+ PIN_FIELD_BASE(25, 25, 2, 0x00, 0x10, 24, 3),
+
+ PIN_FIELD_BASE(26, 26, 5, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(27, 27, 5, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(28, 28, 5, 0x00, 0x10, 9, 3),
+ PIN_FIELD_BASE(29, 29, 5, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(30, 30, 5, 0x00, 0x10, 6, 3),
+ PIN_FIELD_BASE(31, 31, 5, 0x00, 0x10, 15, 3),
+
+ PIN_FIELD_BASE(32, 32, 1, 0x00, 0x10, 9, 3),
+ PIN_FIELD_BASE(33, 33, 1, 0x00, 0x10, 12, 3),
+
+ PIN_FIELD_BASE(34, 34, 4, 0x00, 0x10, 15, 3),
+ PIN_FIELD_BASE(35, 35, 4, 0x00, 0x10, 21, 3),
+
+ PIN_FIELD_BASE(36, 36, 3, 0x00, 0x10, 6, 3),
+ PIN_FIELD_BASE(37, 37, 3, 0x00, 0x10, 9, 3),
+ PIN_FIELD_BASE(38, 38, 3, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(39, 39, 3, 0x00, 0x10, 3, 3),
+
+ PIN_FIELD_BASE(40, 40, 7, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(41, 41, 7, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(42, 42, 7, 0x00, 0x10, 27, 3),
+ PIN_FIELD_BASE(43, 43, 7, 0x00, 0x10, 21, 3),
+ PIN_FIELD_BASE(44, 44, 7, 0x00, 0x10, 24, 3),
+ PIN_FIELD_BASE(45, 45, 7, 0x00, 0x10, 9, 3),
+ PIN_FIELD_BASE(46, 46, 7, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(47, 47, 7, 0x00, 0x10, 15, 3),
+ PIN_FIELD_BASE(48, 48, 7, 0x00, 0x10, 18, 3),
+ PIN_FIELD_BASE(49, 49, 7, 0x00, 0x10, 6, 3),
+
+ PIN_FIELD_BASE(50, 50, 6, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(51, 51, 6, 0x00, 0x10, 6, 3),
+ PIN_FIELD_BASE(52, 52, 6, 0x00, 0x10, 9, 3),
+ PIN_FIELD_BASE(53, 53, 6, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(54, 54, 6, 0x00, 0x10, 15, 3),
+ PIN_FIELD_BASE(55, 55, 6, 0x00, 0x10, 18, 3),
+ PIN_FIELD_BASE(56, 56, 6, 0x00, 0x10, 3, 3),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_pupd_range[] = {
+ PIN_FIELD_BASE(0, 0, 1, 0x20, 0x10, 1, 1),
+ PIN_FIELD_BASE(1, 1, 1, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(2, 2, 5, 0x30, 0x10, 6, 1),
+ PIN_FIELD_BASE(3, 3, 4, 0x30, 0x10, 6, 1),
+ PIN_FIELD_BASE(4, 4, 4, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(5, 5, 4, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(6, 6, 4, 0x30, 0x10, 3, 1),
+ PIN_FIELD_BASE(7, 7, 4, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(8, 8, 4, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(9, 9, 4, 0x30, 0x10, 9, 1),
+
+ PIN_FIELD_BASE(10, 10, 5, 0x30, 0x10, 8, 1),
+ PIN_FIELD_BASE(11, 11, 5, 0x30, 0x10, 10, 1),
+ PIN_FIELD_BASE(12, 12, 5, 0x30, 0x10, 7, 1),
+ PIN_FIELD_BASE(13, 13, 5, 0x30, 0x10, 11, 1),
+
+ PIN_FIELD_BASE(14, 14, 4, 0x30, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(15, 15, 2, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(16, 16, 2, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(17, 17, 2, 0x30, 0x10, 5, 1),
+ PIN_FIELD_BASE(18, 18, 2, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(19, 19, 2, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(20, 20, 2, 0x90, 0x10, 3, 1),
+ PIN_FIELD_BASE(21, 21, 2, 0x30, 0x10, 6, 1),
+ PIN_FIELD_BASE(22, 22, 2, 0x30, 0x10, 7, 1),
+ PIN_FIELD_BASE(23, 23, 2, 0x30, 0x10, 10, 1),
+ PIN_FIELD_BASE(24, 24, 2, 0x30, 0x10, 9, 1),
+ PIN_FIELD_BASE(25, 25, 2, 0x30, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(26, 26, 5, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(27, 27, 5, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(28, 28, 5, 0x30, 0x10, 3, 1),
+ PIN_FIELD_BASE(29, 29, 5, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(30, 30, 5, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(31, 31, 5, 0x30, 0x10, 5, 1),
+
+ PIN_FIELD_BASE(32, 32, 1, 0x20, 0x10, 2, 1),
+ PIN_FIELD_BASE(33, 33, 1, 0x20, 0x10, 3, 1),
+
+ PIN_FIELD_BASE(34, 34, 4, 0x30, 0x10, 5, 1),
+ PIN_FIELD_BASE(35, 35, 4, 0x30, 0x10, 7, 1),
+
+ PIN_FIELD_BASE(36, 36, 3, 0x20, 0x10, 2, 1),
+ PIN_FIELD_BASE(37, 37, 3, 0x20, 0x10, 3, 1),
+ PIN_FIELD_BASE(38, 38, 3, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(39, 39, 3, 0x20, 0x10, 1, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_r0_range[] = {
+ PIN_FIELD_BASE(0, 0, 1, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(1, 1, 1, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(2, 2, 5, 0x40, 0x10, 6, 1),
+ PIN_FIELD_BASE(3, 3, 4, 0x40, 0x10, 6, 1),
+ PIN_FIELD_BASE(4, 4, 4, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(5, 5, 4, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(6, 6, 4, 0x40, 0x10, 3, 1),
+ PIN_FIELD_BASE(7, 7, 4, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(8, 8, 4, 0x40, 0x10, 4, 1),
+ PIN_FIELD_BASE(9, 9, 4, 0x40, 0x10, 9, 1),
+
+ PIN_FIELD_BASE(10, 10, 5, 0x40, 0x10, 8, 1),
+ PIN_FIELD_BASE(11, 11, 5, 0x40, 0x10, 10, 1),
+ PIN_FIELD_BASE(12, 12, 5, 0x40, 0x10, 7, 1),
+ PIN_FIELD_BASE(13, 13, 5, 0x40, 0x10, 11, 1),
+
+ PIN_FIELD_BASE(14, 14, 4, 0x40, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(15, 15, 2, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(16, 16, 2, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(17, 17, 2, 0x40, 0x10, 5, 1),
+ PIN_FIELD_BASE(18, 18, 2, 0x40, 0x10, 4, 1),
+ PIN_FIELD_BASE(19, 19, 2, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(20, 20, 2, 0x40, 0x10, 3, 1),
+ PIN_FIELD_BASE(21, 21, 2, 0x40, 0x10, 6, 1),
+ PIN_FIELD_BASE(22, 22, 2, 0x40, 0x10, 7, 1),
+ PIN_FIELD_BASE(23, 23, 2, 0x40, 0x10, 10, 1),
+ PIN_FIELD_BASE(24, 24, 2, 0x40, 0x10, 9, 1),
+ PIN_FIELD_BASE(25, 25, 2, 0x40, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(26, 26, 5, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(27, 27, 5, 0x40, 0x10, 4, 1),
+ PIN_FIELD_BASE(28, 28, 5, 0x40, 0x10, 3, 1),
+ PIN_FIELD_BASE(29, 29, 5, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(30, 30, 5, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(31, 31, 5, 0x40, 0x10, 5, 1),
+
+ PIN_FIELD_BASE(32, 32, 1, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(33, 33, 1, 0x30, 0x10, 3, 1),
+
+ PIN_FIELD_BASE(34, 34, 4, 0x40, 0x10, 5, 1),
+ PIN_FIELD_BASE(35, 35, 4, 0x40, 0x10, 7, 1),
+
+ PIN_FIELD_BASE(36, 36, 3, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(37, 37, 3, 0x30, 0x10, 3, 1),
+ PIN_FIELD_BASE(38, 38, 3, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(39, 39, 3, 0x30, 0x10, 1, 1),
+};
+
+static const struct mtk_pin_field_calc mt7981_pin_r1_range[] = {
+ PIN_FIELD_BASE(0, 0, 1, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(1, 1, 1, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(2, 2, 5, 0x50, 0x10, 6, 1),
+ PIN_FIELD_BASE(3, 3, 4, 0x50, 0x10, 6, 1),
+ PIN_FIELD_BASE(4, 4, 4, 0x50, 0x10, 2, 1),
+ PIN_FIELD_BASE(5, 5, 4, 0x50, 0x10, 1, 1),
+ PIN_FIELD_BASE(6, 6, 4, 0x50, 0x10, 3, 1),
+ PIN_FIELD_BASE(7, 7, 4, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(8, 8, 4, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(9, 9, 4, 0x50, 0x10, 9, 1),
+
+ PIN_FIELD_BASE(10, 10, 5, 0x50, 0x10, 8, 1),
+ PIN_FIELD_BASE(11, 11, 5, 0x50, 0x10, 10, 1),
+ PIN_FIELD_BASE(12, 12, 5, 0x50, 0x10, 7, 1),
+ PIN_FIELD_BASE(13, 13, 5, 0x50, 0x10, 11, 1),
+
+ PIN_FIELD_BASE(14, 14, 4, 0x50, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(15, 15, 2, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(16, 16, 2, 0x50, 0x10, 1, 1),
+ PIN_FIELD_BASE(17, 17, 2, 0x50, 0x10, 5, 1),
+ PIN_FIELD_BASE(18, 18, 2, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(19, 19, 2, 0x50, 0x10, 2, 1),
+ PIN_FIELD_BASE(20, 20, 2, 0x50, 0x10, 3, 1),
+ PIN_FIELD_BASE(21, 21, 2, 0x50, 0x10, 6, 1),
+ PIN_FIELD_BASE(22, 22, 2, 0x50, 0x10, 7, 1),
+ PIN_FIELD_BASE(23, 23, 2, 0x50, 0x10, 10, 1),
+ PIN_FIELD_BASE(24, 24, 2, 0x50, 0x10, 9, 1),
+ PIN_FIELD_BASE(25, 25, 2, 0x50, 0x10, 8, 1),
+
+ PIN_FIELD_BASE(26, 26, 5, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(27, 27, 5, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(28, 28, 5, 0x50, 0x10, 3, 1),
+ PIN_FIELD_BASE(29, 29, 5, 0x50, 0x10, 1, 1),
+ PIN_FIELD_BASE(30, 30, 5, 0x50, 0x10, 2, 1),
+ PIN_FIELD_BASE(31, 31, 5, 0x50, 0x10, 5, 1),
+
+ PIN_FIELD_BASE(32, 32, 1, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(33, 33, 1, 0x40, 0x10, 3, 1),
+
+ PIN_FIELD_BASE(34, 34, 4, 0x50, 0x10, 5, 1),
+ PIN_FIELD_BASE(35, 35, 4, 0x50, 0x10, 7, 1),
+
+ PIN_FIELD_BASE(36, 36, 3, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(37, 37, 3, 0x40, 0x10, 3, 1),
+ PIN_FIELD_BASE(38, 38, 3, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(39, 39, 3, 0x40, 0x10, 1, 1),
+};
+
+static const struct mtk_pin_reg_calc mt7981_reg_cals[] = {
+ [PINCTRL_PIN_REG_MODE] = MTK_RANGE(mt7981_pin_mode_range),
+ [PINCTRL_PIN_REG_DIR] = MTK_RANGE(mt7981_pin_dir_range),
+ [PINCTRL_PIN_REG_DI] = MTK_RANGE(mt7981_pin_di_range),
+ [PINCTRL_PIN_REG_DO] = MTK_RANGE(mt7981_pin_do_range),
+ [PINCTRL_PIN_REG_SMT] = MTK_RANGE(mt7981_pin_smt_range),
+ [PINCTRL_PIN_REG_IES] = MTK_RANGE(mt7981_pin_ies_range),
+ [PINCTRL_PIN_REG_PU] = MTK_RANGE(mt7981_pin_pu_range),
+ [PINCTRL_PIN_REG_PD] = MTK_RANGE(mt7981_pin_pd_range),
+ [PINCTRL_PIN_REG_DRV] = MTK_RANGE(mt7981_pin_drv_range),
+ [PINCTRL_PIN_REG_PUPD] = MTK_RANGE(mt7981_pin_pupd_range),
+ [PINCTRL_PIN_REG_R0] = MTK_RANGE(mt7981_pin_r0_range),
+ [PINCTRL_PIN_REG_R1] = MTK_RANGE(mt7981_pin_r1_range),
+};
+
+static const struct mtk_pin_desc mt7981_pins[] = {
+ MT7981_TYPE0_PIN(0, "GPIO_WPS"),
+ MT7981_TYPE0_PIN(1, "GPIO_RESET"),
+ MT7981_TYPE0_PIN(2, "SYS_WATCHDOG"),
+ MT7981_TYPE0_PIN(3, "PCIE_PERESET_N"),
+ MT7981_TYPE0_PIN(4, "JTAG_JTDO"),
+ MT7981_TYPE0_PIN(5, "JTAG_JTDI"),
+ MT7981_TYPE0_PIN(6, "JTAG_JTMS"),
+ MT7981_TYPE0_PIN(7, "JTAG_JTCLK"),
+ MT7981_TYPE0_PIN(8, "JTAG_JTRST_N"),
+ MT7981_TYPE0_PIN(9, "WO_JTAG_JTDO"),
+ MT7981_TYPE0_PIN(10, "WO_JTAG_JTDI"),
+ MT7981_TYPE0_PIN(11, "WO_JTAG_JTMS"),
+ MT7981_TYPE0_PIN(12, "WO_JTAG_JTCLK"),
+ MT7981_TYPE0_PIN(13, "WO_JTAG_JTRST_N"),
+ MT7981_TYPE0_PIN(14, "USB_VBUS"),
+ MT7981_TYPE0_PIN(15, "PWM0"),
+ MT7981_TYPE0_PIN(16, "SPI0_CLK"),
+ MT7981_TYPE0_PIN(17, "SPI0_MOSI"),
+ MT7981_TYPE0_PIN(18, "SPI0_MISO"),
+ MT7981_TYPE0_PIN(19, "SPI0_CS"),
+ MT7981_TYPE0_PIN(20, "SPI0_HOLD"),
+ MT7981_TYPE0_PIN(21, "SPI0_WP"),
+ MT7981_TYPE0_PIN(22, "SPI1_CLK"),
+ MT7981_TYPE0_PIN(23, "SPI1_MOSI"),
+ MT7981_TYPE0_PIN(24, "SPI1_MISO"),
+ MT7981_TYPE0_PIN(25, "SPI1_CS"),
+ MT7981_TYPE0_PIN(26, "SPI2_CLK"),
+ MT7981_TYPE0_PIN(27, "SPI2_MOSI"),
+ MT7981_TYPE0_PIN(28, "SPI2_MISO"),
+ MT7981_TYPE0_PIN(29, "SPI2_CS"),
+ MT7981_TYPE0_PIN(30, "SPI2_HOLD"),
+ MT7981_TYPE0_PIN(31, "SPI2_WP"),
+ MT7981_TYPE0_PIN(32, "UART0_RXD"),
+ MT7981_TYPE0_PIN(33, "UART0_TXD"),
+ MT7981_TYPE0_PIN(34, "PCIE_CLK_REQ"),
+ MT7981_TYPE0_PIN(35, "PCIE_WAKE_N"),
+ MT7981_TYPE0_PIN(36, "SMI_MDC"),
+ MT7981_TYPE0_PIN(37, "SMI_MDIO"),
+ MT7981_TYPE0_PIN(38, "GBE_INT"),
+ MT7981_TYPE0_PIN(39, "GBE_RESET"),
+ MT7981_TYPE1_PIN(40, "WF_DIG_RESETB"),
+ MT7981_TYPE1_PIN(41, "WF_CBA_RESETB"),
+ MT7981_TYPE1_PIN(42, "WF_XO_REQ"),
+ MT7981_TYPE1_PIN(43, "WF_TOP_CLK"),
+ MT7981_TYPE1_PIN(44, "WF_TOP_DATA"),
+ MT7981_TYPE1_PIN(45, "WF_HB1"),
+ MT7981_TYPE1_PIN(46, "WF_HB2"),
+ MT7981_TYPE1_PIN(47, "WF_HB3"),
+ MT7981_TYPE1_PIN(48, "WF_HB4"),
+ MT7981_TYPE1_PIN(49, "WF_HB0"),
+ MT7981_TYPE1_PIN(50, "WF_HB0_B"),
+ MT7981_TYPE1_PIN(51, "WF_HB5"),
+ MT7981_TYPE1_PIN(52, "WF_HB6"),
+ MT7981_TYPE1_PIN(53, "WF_HB7"),
+ MT7981_TYPE1_PIN(54, "WF_HB8"),
+ MT7981_TYPE1_PIN(55, "WF_HB9"),
+ MT7981_TYPE1_PIN(56, "WF_HB10"),
+};
+
+/* WA_AICE */
+static int mt7981_wa_aice1_pins[] = { 0, 1, };
+static int mt7981_wa_aice1_funcs[] = { 2, 2, };
+
+static int mt7981_wa_aice2_pins[] = { 0, 1, };
+static int mt7981_wa_aice2_funcs[] = { 3, 3, };
+
+static int mt7981_wa_aice3_pins[] = { 28, 29, };
+static int mt7981_wa_aice3_funcs[] = { 3, 3, };
+
+static int mt7981_wm_aice1_pins[] = { 9, 10, };
+static int mt7981_wm_aice1_funcs[] = { 2, 2, };
+
+static int mt7981_wm_aice2_pins[] = { 30, 31, };
+static int mt7981_wm_aice2_funcs[] = { 5, 5, };
+
+/* WM_UART */
+static int mt7981_wm_uart_0_pins[] = { 0, 1, };
+static int mt7981_wm_uart_0_funcs[] = { 5, 5, };
+
+static int mt7981_wm_uart_1_pins[] = { 20, 21, };
+static int mt7981_wm_uart_1_funcs[] = { 4, 4, };
+
+static int mt7981_wm_uart_2_pins[] = { 30, 31, };
+static int mt7981_wm_uart_2_funcs[] = { 3, 3, };
+
+/* DFD */
+static int mt7981_dfd_pins[] = { 0, 1, 4, 5, };
+static int mt7981_dfd_funcs[] = { 5, 5, 6, 6, };
+
+/* SYS_WATCHDOG */
+static int mt7981_watchdog_pins[] = { 2, };
+static int mt7981_watchdog_funcs[] = { 1, };
+
+static int mt7981_watchdog1_pins[] = { 13, };
+static int mt7981_watchdog1_funcs[] = { 5, };
+
+/* PCIE_PERESET_N */
+static int mt7981_pcie_pereset_pins[] = { 3, };
+static int mt7981_pcie_pereset_funcs[] = { 1, };
+
+/* JTAG */
+static int mt7981_jtag_pins[] = { 4, 5, 6, 7, 8, };
+static int mt7981_jtag_funcs[] = { 1, 1, 1, 1, 1, };
+
+/* WM_JTAG */
+static int mt7981_wm_jtag_0_pins[] = { 4, 5, 6, 7, 8, }; +static int mt7981_wm_jtag_0_funcs[] = { 2, 2, 2, 2, 2, };
+
+static int mt7981_wm_jtag_1_pins[] = { 20, 21, 22, 23, 24, }; +static int mt7981_wm_jtag_1_funcs[] = { 5, 5, 5, 5, 5, };
+
+/* WO0_JTAG */
+static int mt7981_wo0_jtag_0_pins[] = { 9, 10, 11, 12, 13, }; +static int mt7981_wo0_jtag_0_funcs[] = { 1, 1, 1, 1, 1, };
+
+static int mt7981_wo0_jtag_1_pins[] = { 25, 26, 27, 28, 29, }; +static int mt7981_wo0_jtag_1_funcs[] = { 5, 5, 5, 5, 5, };
+
+/* UART2 */
+static int mt7981_uart2_0_pins[] = { 4, 5, 6, 7, };
+static int mt7981_uart2_0_funcs[] = { 3, 3, 3, 3, };
+
+/* GBE_LED0 */
+static int mt7981_gbe_led0_pins[] = { 8, };
+static int mt7981_gbe_led0_funcs[] = { 3, };
+
+/* PTA_EXT */
+static int mt7981_pta_ext_0_pins[] = { 4, 5, 6, };
+static int mt7981_pta_ext_0_funcs[] = { 4, 4, 4, };
+
+static int mt7981_pta_ext_1_pins[] = { 22, 23, 24, };
+static int mt7981_pta_ext_1_funcs[] = { 4, 4, 4, };
+
+/* PWM2 */
+static int mt7981_pwm2_pins[] = { 7, };
+static int mt7981_pwm2_funcs[] = { 4, };
+
+/* NET_WO0_UART_TXD */
+static int mt7981_net_wo0_uart_txd_0_pins[] = { 8, };
+static int mt7981_net_wo0_uart_txd_0_funcs[] = { 4, };
+
+static int mt7981_net_wo0_uart_txd_1_pins[] = { 14, };
+static int mt7981_net_wo0_uart_txd_1_funcs[] = { 3, };
+
+static int mt7981_net_wo0_uart_txd_2_pins[] = { 15, };
+static int mt7981_net_wo0_uart_txd_2_funcs[] = { 4, };
+
+/* SPI1 */
+static int mt7981_spi1_0_pins[] = { 4, 5, 6, 7, };
+static int mt7981_spi1_0_funcs[] = { 5, 5, 5, 5, };
+
+/* I2C */
+static int mt7981_i2c0_0_pins[] = { 6, 7, };
+static int mt7981_i2c0_0_funcs[] = { 6, 6, };
+
+static int mt7981_i2c0_1_pins[] = { 30, 31, };
+static int mt7981_i2c0_1_funcs[] = { 4, 4, };
+
+static int mt7981_i2c0_2_pins[] = { 36, 37, };
+static int mt7981_i2c0_2_funcs[] = { 2, 2, };
+
+static int mt7981_u2_phy_i2c_pins[] = { 30, 31, };
+static int mt7981_u2_phy_i2c_funcs[] = { 6, 6, };
+
+static int mt7981_u3_phy_i2c_pins[] = { 32, 33, };
+static int mt7981_u3_phy_i2c_funcs[] = { 3, 3, };
+
+static int mt7981_sgmii1_phy_i2c_pins[] = { 32, 33, };
+static int mt7981_sgmii1_phy_i2c_funcs[] = { 2, 2, };
+
+static int mt7981_sgmii0_phy_i2c_pins[] = { 32, 33, };
+static int mt7981_sgmii0_phy_i2c_funcs[] = { 5, 5, };
+
+/* DFD_NTRST */
+static int mt7981_dfd_ntrst_pins[] = { 8, };
+static int mt7981_dfd_ntrst_funcs[] = { 6, };
+
+/* PWM0 */
+static int mt7981_pwm0_0_pins[] = { 13, };
+static int mt7981_pwm0_0_funcs[] = { 2, };
+
+static int mt7981_pwm0_1_pins[] = { 15, };
+static int mt7981_pwm0_1_funcs[] = { 1, };
+
+/* PWM1 */
+static int mt7981_pwm1_0_pins[] = { 14, };
+static int mt7981_pwm1_0_funcs[] = { 2, };
+
+static int mt7981_pwm1_1_pins[] = { 15, };
+static int mt7981_pwm1_1_funcs[] = { 3, };
+
+/* GBE_LED1 */
+static int mt7981_gbe_led1_pins[] = { 13, };
+static int mt7981_gbe_led1_funcs[] = { 3, };
+
+/* PCM */
+static int mt7981_pcm_pins[] = { 9, 10, 11, 12, 13, 25 }; +static int mt7981_pcm_funcs[] = { 4, 4, 4, 4, 4, 4, };
+
+/* UDI */
+static int mt7981_udi_pins[] = { 9, 10, 11, 12, 13, };
+static int mt7981_udi_funcs[] = { 6, 6, 6, 6, 6, };
+
+/* DRV_VBUS */
+static int mt7981_drv_vbus_pins[] = { 14, };
+static int mt7981_drv_vbus_funcs[] = { 1, };
+
+/* EMMC */
+static int mt7981_emmc_45_pins[] = { 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, };
+static int mt7981_emmc_45_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, }; +
+/* SNFI */
+static int mt7981_snfi_pins[] = { 16, 17, 18, 19, 20, 21, }; +static int mt7981_snfi_funcs[] = { 3, 3, 3, 3, 3, 3, };
+
+/* SPI0 */
+static int mt7981_spi0_pins[] = { 16, 17, 18, 19, };
+static int mt7981_spi0_funcs[] = { 1, 1, 1, 1, };
+
+/* SPI0 */
+static int mt7981_spi0_wp_hold_pins[] = { 20, 21, };
+static int mt7981_spi0_wp_hold_funcs[] = { 1, 1, };
+
+/* SPI1 */
+static int mt7981_spi1_1_pins[] = { 22, 23, 24, 25, };
+static int mt7981_spi1_1_funcs[] = { 1, 1, 1, 1, };
+
+/* SPI2 */
+static int mt7981_spi2_pins[] = { 26, 27, 28, 29, };
+static int mt7981_spi2_funcs[] = { 1, 1, 1, 1, };
+
+/* SPI2 */
+static int mt7981_spi2_wp_hold_pins[] = { 30, 31, };
+static int mt7981_spi2_wp_hold_funcs[] = { 1, 1, };
+
+/* UART1 */
+static int mt7981_uart1_0_pins[] = { 16, 17, 18, 19, };
+static int mt7981_uart1_0_funcs[] = { 4, 4, 4, 4, };
+
+static int mt7981_uart1_1_pins[] = { 26, 27, 28, 29, };
+static int mt7981_uart1_1_funcs[] = { 2, 2, 2, 2, };
+
+/* UART2 */
+static int mt7981_uart2_1_pins[] = { 22, 23, 24, 25, };
+static int mt7981_uart2_1_funcs[] = { 3, 3, 3, 3, };
+
+/* UART0 */
+static int mt7981_uart0_pins[] = { 32, 33, };
+static int mt7981_uart0_funcs[] = { 1, 1, };
+
+/* PCIE_CLK_REQ */
+static int mt7981_pcie_clk_pins[] = { 34, };
+static int mt7981_pcie_clk_funcs[] = { 2, };
+
+/* PCIE_WAKE_N */
+static int mt7981_pcie_wake_pins[] = { 35, };
+static int mt7981_pcie_wake_funcs[] = { 2, };
+
+/* MDC_MDIO */
+static int mt7981_smi_mdc_mdio_pins[] = { 36, 37, };
+static int mt7981_smi_mdc_mdio_funcs[] = { 1, 1, };
+
+static int mt7981_gbe_ext_mdc_mdio_pins[] = { 36, 37, }; +static int mt7981_gbe_ext_mdc_mdio_funcs[] = { 3, 3, };
+
+/* WF0_MODE1 */
+static int mt7981_wf0_mode1_pins[] = { 40, 41, 42, 43, 44, 45, 46, 47, 48,
49,
+ 50, 51, 52, 53, 54, 55, 56 };
+static int mt7981_wf0_mode1_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,
+ 1, 1, 1, 1 };
+
+/* WF0_MODE3 */
+static int mt7981_wf0_mode3_pins[] = { 45, 46, 47, 48, 49, 51 }; +static int mt7981_wf0_mode3_funcs[] = { 2, 2, 2, 2, 2, 2 };
+
+/* WF2G_LED */
+static int mt7981_wf2g_led0_pins[] = { 30, };
+static int mt7981_wf2g_led0_funcs[] = { 2, };
+
+static int mt7981_wf2g_led1_pins[] = { 34, };
+static int mt7981_wf2g_led1_funcs[] = { 1, };
+
+/* WF5G_LED */
+static int mt7981_wf5g_led0_pins[] = { 31, };
+static int mt7981_wf5g_led0_funcs[] = { 2, };
+
+static int mt7981_wf5g_led1_pins[] = { 35, };
+static int mt7981_wf5g_led1_funcs[] = { 1, };
+
+/* MT7531_INT */
+static int mt7981_mt7531_int_pins[] = { 38, };
+static int mt7981_mt7531_int_funcs[] = { 1, };
+
+/* ANT_SEL */
+static int mt7981_ant_sel_pins[] = { 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 34, 35 };
+static int mt7981_ant_sel_funcs[] = { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }; +
+static const struct mtk_group_desc mt7981_groups[] = {
+ /* @GPIO(0,1): WA_AICE(2) */
+ PINCTRL_PIN_GROUP("wa_aice1", mt7981_wa_aice1),
+ /* @GPIO(0,1): WA_AICE(3) */
+ PINCTRL_PIN_GROUP("wa_aice2", mt7981_wa_aice2),
+ /* @GPIO(0,1): WM_UART(5) */
+ PINCTRL_PIN_GROUP("wm_uart_0", mt7981_wm_uart_0),
+ /* @GPIO(0,1,4,5): DFD(6) */
+ PINCTRL_PIN_GROUP("dfd", mt7981_dfd),
+ /* @GPIO(2): SYS_WATCHDOG(1) */
+ PINCTRL_PIN_GROUP("watchdog", mt7981_watchdog),
+ /* @GPIO(3): PCIE_PERESET_N(1) */
+ PINCTRL_PIN_GROUP("pcie_pereset", mt7981_pcie_pereset),
+ /* @GPIO(4,8) JTAG(1) */
+ PINCTRL_PIN_GROUP("jtag", mt7981_jtag),
+ /* @GPIO(4,8) WM_JTAG(2) */
+ PINCTRL_PIN_GROUP("wm_jtag_0", mt7981_wm_jtag_0),
+ /* @GPIO(9,13) WO0_JTAG(1) */
+ PINCTRL_PIN_GROUP("wo0_jtag_0", mt7981_wo0_jtag_0),
+ /* @GPIO(4,7) WM_JTAG(3) */
+ PINCTRL_PIN_GROUP("uart2_0", mt7981_uart2_0),
+ /* @GPIO(8) GBE_LED0(3) */
+ PINCTRL_PIN_GROUP("gbe_led0", mt7981_gbe_led0),
+ /* @GPIO(4,6) PTA_EXT(4) */
+ PINCTRL_PIN_GROUP("pta_ext_0", mt7981_pta_ext_0),
+ /* @GPIO(7) PWM2(4) */
+ PINCTRL_PIN_GROUP("pwm2", mt7981_pwm2),
+ /* @GPIO(8) NET_WO0_UART_TXD(4) */
+ PINCTRL_PIN_GROUP("net_wo0_uart_txd_0", mt7981_net_wo0_uart_txd_0),
+ /* @GPIO(4,7) SPI1(5) */
+ PINCTRL_PIN_GROUP("spi1_0", mt7981_spi1_0),
+ /* @GPIO(6,7) I2C(5) */
+ PINCTRL_PIN_GROUP("i2c0_0", mt7981_i2c0_0),
+ /* @GPIO(8): DFD_NTRST(6) */
+ PINCTRL_PIN_GROUP("dfd_ntrst", mt7981_dfd_ntrst),
+ /* @GPIO(9,10): WM_AICE(2) */
+ PINCTRL_PIN_GROUP("wm_aice1", mt7981_wm_aice1),
+ /* @GPIO(13): PWM0(2) */
+ PINCTRL_PIN_GROUP("pwm0_0", mt7981_pwm0_0),
+ /* @GPIO(15): PWM0(1) */
+ PINCTRL_PIN_GROUP("pwm0_1", mt7981_pwm0_1),
+ /* @GPIO(14): PWM1(2) */
+ PINCTRL_PIN_GROUP("pwm1_0", mt7981_pwm1_0),
+ /* @GPIO(15): PWM1(3) */
+ PINCTRL_PIN_GROUP("pwm1_1", mt7981_pwm1_1),
+ /* @GPIO(14) NET_WO0_UART_TXD(3) */
+ PINCTRL_PIN_GROUP("net_wo0_uart_txd_1", mt7981_net_wo0_uart_txd_1),
+ /* @GPIO(15) NET_WO0_UART_TXD(4) */
+ PINCTRL_PIN_GROUP("net_wo0_uart_txd_2", mt7981_net_wo0_uart_txd_2),
+ /* @GPIO(13) GBE_LED0(3) */
+ PINCTRL_PIN_GROUP("gbe_led1", mt7981_gbe_led1),
+ /* @GPIO(9,13) PCM(4) */
+ PINCTRL_PIN_GROUP("pcm", mt7981_pcm),
+ /* @GPIO(13): SYS_WATCHDOG1(5) */
+ PINCTRL_PIN_GROUP("watchdog1", mt7981_watchdog1),
+ /* @GPIO(9,13) UDI(4) */
+ PINCTRL_PIN_GROUP("udi", mt7981_udi),
+ /* @GPIO(14) DRV_VBUS(1) */
+ PINCTRL_PIN_GROUP("drv_vbus", mt7981_drv_vbus),
+ /* @GPIO(15,25): EMMC(2) */
+ PINCTRL_PIN_GROUP("emmc_45", mt7981_emmc_45),
+ /* @GPIO(16,21): SNFI(3) */
+ PINCTRL_PIN_GROUP("snfi", mt7981_snfi),
+ /* @GPIO(16,19): SPI0(1) */
+ PINCTRL_PIN_GROUP("spi0", mt7981_spi0),
+ /* @GPIO(20,21): SPI0(1) */
+ PINCTRL_PIN_GROUP("spi0_wp_hold", mt7981_spi0_wp_hold),
+ /* @GPIO(22,25) SPI1(1) */
+ PINCTRL_PIN_GROUP("spi1_1", mt7981_spi1_1),
+ /* @GPIO(26,29): SPI2(1) */
+ PINCTRL_PIN_GROUP("spi2", mt7981_spi2),
+ /* @GPIO(30,31): SPI2(1) */
+ PINCTRL_PIN_GROUP("spi2_wp_hold", mt7981_spi2_wp_hold),
+ /* @GPIO(16,19): UART1(4) */
+ PINCTRL_PIN_GROUP("uart1_0", mt7981_uart1_0),
+ /* @GPIO(26,29): UART1(2) */
+ PINCTRL_PIN_GROUP("uart1_1", mt7981_uart1_1),
+ /* @GPIO(22,25): UART2(3) */
+ PINCTRL_PIN_GROUP("uart2_0", mt7981_uart2_1),
+ /* @GPIO(22,24) PTA_EXT(4) */
+ PINCTRL_PIN_GROUP("pta_ext_1", mt7981_pta_ext_1),
+ /* @GPIO(20,21): WM_UART(4) */
+ PINCTRL_PIN_GROUP("wm_aurt_1", mt7981_wm_uart_1),
+ /* @GPIO(30,31): WM_UART(3) */
+ PINCTRL_PIN_GROUP("wm_aurt_2", mt7981_wm_uart_2),
+ /* @GPIO(20,24) WM_JTAG(5) */
+ PINCTRL_PIN_GROUP("wm_jtag_1", mt7981_wm_jtag_1),
+ /* @GPIO(25,29) WO0_JTAG(5) */
+ PINCTRL_PIN_GROUP("wo0_jtag_1", mt7981_wo0_jtag_1),
+ /* @GPIO(28,29): WA_AICE(3) */
+ PINCTRL_PIN_GROUP("wa_aice3", mt7981_wa_aice3),
+ /* @GPIO(30,31): WM_AICE(5) */
+ PINCTRL_PIN_GROUP("wm_aice2", mt7981_wm_aice2),
+ /* @GPIO(30,31): I2C(4) */
+ PINCTRL_PIN_GROUP("i2c0_1", mt7981_i2c0_1),
+ /* @GPIO(30,31): I2C(6) */
+ PINCTRL_PIN_GROUP("u2_phy_i2c", mt7981_u2_phy_i2c),
+ /* @GPIO(32,33): I2C(1) */
+ PINCTRL_PIN_GROUP("uart0", mt7981_uart0),
+ /* @GPIO(32,33): I2C(2) */
+ PINCTRL_PIN_GROUP("sgmii1_phy_i2c", mt7981_sgmii1_phy_i2c),
+ /* @GPIO(32,33): I2C(3) */
+ PINCTRL_PIN_GROUP("u3_phy_i2c", mt7981_u3_phy_i2c),
+ /* @GPIO(32,33): I2C(5) */
+ PINCTRL_PIN_GROUP("sgmii0_phy_i2c", mt7981_sgmii0_phy_i2c),
+ /* @GPIO(34): PCIE_CLK_REQ(2) */
+ PINCTRL_PIN_GROUP("pcie_clk", mt7981_pcie_clk),
+ /* @GPIO(35): PCIE_WAKE_N(2) */
+ PINCTRL_PIN_GROUP("pcie_wake", mt7981_pcie_wake),
+ /* @GPIO(36,37): I2C(2) */
+ PINCTRL_PIN_GROUP("i2c0_2", mt7981_i2c0_2),
+ /* @GPIO(36,37): MDC_MDIO(1) */
+ PINCTRL_PIN_GROUP("smi_mdc_mdio", mt7981_smi_mdc_mdio),
+ /* @GPIO(36,37): MDC_MDIO(3) */
+ PINCTRL_PIN_GROUP("gbe_ext_mdc_mdio", mt7981_gbe_ext_mdc_mdio),
+ /* @GPIO(40,56): WF0_MODE1(1) */
+ PINCTRL_PIN_GROUP("wf0_mode1", mt7981_wf0_mode1),
+ /* @GPIO(45,46,47,48,49,51): WF0_MODE3(3) */
+ PINCTRL_PIN_GROUP("wf0_mode3", mt7981_wf0_mode3),
+ /* @GPIO(30): WF2G_LED(2) */
+ PINCTRL_PIN_GROUP("wf2g_led0", mt7981_wf2g_led0),
+ /* @GPIO(34): WF2G_LED(1) */
+ PINCTRL_PIN_GROUP("wf2g_led1", mt7981_wf2g_led1),
+ /* @GPIO(31): WF5G_LED(2) */
+ PINCTRL_PIN_GROUP("wf5g_led0", mt7981_wf5g_led0),
+ /* @GPIO(35): WF5G_LED(1) */
+ PINCTRL_PIN_GROUP("wf5g_led1", mt7981_wf5g_led1),
+ /* @GPIO(38): MT7531_INT(1) */
+ PINCTRL_PIN_GROUP("mt7531_int", mt7981_mt7531_int),
+ /* @GPIO(14,15,26,17,18,19,20,21,22,23,24,25,34,35): ANT_SEL(1) */
+ PINCTRL_PIN_GROUP("ant_sel", mt7981_ant_sel),
+};
+
+static const struct mtk_io_type_desc mt7981_io_type_desc[] = {
+ [IO_TYPE_GRP0] = {
+ .name = "18OD33",
+ .bias_set = mtk_pinconf_bias_set_pupd_r1_r0,
+ .drive_set = mtk_pinconf_drive_set_v1,
+ .input_enable = mtk_pinconf_input_enable_v1,
+ },
+ [IO_TYPE_GRP1] = {
+ .name = "18A01",
+ .bias_set = mtk_pinconf_bias_set_pu_pd,
+ .drive_set = mtk_pinconf_drive_set_v1,
+ .input_enable = mtk_pinconf_input_enable_v1,
+ },
+};
+
+/* Joint those groups owning the same capability in user point of view
which
+ * allows that people tend to use through the device tree.
+ */
+static const char *const mt7981_wa_aice_groups[] = { "wa_aice1",
"wa_aice2",
+ "wm_aice1_1", "wa_aice3", "wm_aice1_2", };
+static const char *const mt7981_uart_groups[] = { "wm_uart_0", "uart2_0",
+ "net_wo0_uart_txd_0", "net_wo0_uart_txd_1", "net_wo0_uart_txd_2",
+ "uart1_0", "uart1_1", "uart2_0", "wm_aurt_1", "wm_aurt_2", "uart0", };
+static const char *const mt7981_dfd_groups[] = { "dfd", "dfd_ntrst", }; +static const char *const mt7981_wdt_groups[] = { "watchdog", "watchdog1",
};
+static const char *const mt7981_pcie_groups[] = { "pcie_pereset",
"pcie_clk",
+ "pcie_wake", };
+static const char *const mt7981_jtag_groups[] = { "jtag", "wm_jtag_0",
+ "wo0_jtag_0", "wo0_jtag_1", "wm_jtag_1", };
+static const char *const mt7981_led_groups[] = { "gbe_led0", "gbe_led1",
+ "wf2g_led0", "wf2g_led1", "wf5g_led0", "wf5g_led1", };
+static const char *const mt7981_pta_groups[] = { "pta_ext_0", "pta_ext_1",
};
+static const char *const mt7981_pwm_groups[] = { "pwm2", "pwm0_0",
"pwm0_1",
+ "pwm1_0", "pwm1_1", };
+static const char *const mt7981_spi_groups[] = { "spi1_0", "spi0",
+ "spi0_wp_hold", "spi1_1", "spi2", "spi2_wp_hold", };
+static const char *const mt7981_i2c_groups[] = { "i2c0_0", "i2c0_1",
+ "u2_phy_i2c", "sgmii1_phy_i2c", "u3_phy_i2c", "sgmii0_phy_i2c",
+ "i2c0_2", };
+static const char *const mt7981_pcm_groups[] = { "pcm", }; +static const char *const mt7981_udi_groups[] = { "udi", }; +static const char *const mt7981_usb_groups[] = { "drv_vbus", }; +static const char *const mt7981_flash_groups[] = { "emmc_45", "snfi", }; +static const char *const mt7981_ethernet_groups[] = { "smi_mdc_mdio",
+ "gbe_ext_mdc_mdio", "wf0_mode1", "wf0_mode3", "mt7531_int", };
+static const char *const mt7981_ant_groups[] = { "ant_sel", }; +
+static const struct mtk_function_desc mt7981_functions[] = {
+ {"wa_aice", mt7981_wa_aice_groups, ARRAY_SIZE(mt7981_wa_aice_groups)},
+ {"dfd", mt7981_dfd_groups, ARRAY_SIZE(mt7981_dfd_groups)},
+ {"jtag", mt7981_jtag_groups, ARRAY_SIZE(mt7981_jtag_groups)},
+ {"pta", mt7981_pta_groups, ARRAY_SIZE(mt7981_pta_groups)},
+ {"pcm", mt7981_pcm_groups, ARRAY_SIZE(mt7981_pcm_groups)},
+ {"udi", mt7981_udi_groups, ARRAY_SIZE(mt7981_udi_groups)},
+ {"usb", mt7981_usb_groups, ARRAY_SIZE(mt7981_usb_groups)},
+ {"ant", mt7981_ant_groups, ARRAY_SIZE(mt7981_ant_groups)},
+ {"eth", mt7981_ethernet_groups, ARRAY_SIZE(mt7981_ethernet_groups)},
+ {"i2c", mt7981_i2c_groups, ARRAY_SIZE(mt7981_i2c_groups)},
+ {"led", mt7981_led_groups, ARRAY_SIZE(mt7981_led_groups)},
+ {"pwm", mt7981_pwm_groups, ARRAY_SIZE(mt7981_pwm_groups)},
+ {"spi", mt7981_spi_groups, ARRAY_SIZE(mt7981_spi_groups)},
+ {"uart", mt7981_uart_groups, ARRAY_SIZE(mt7981_uart_groups)},
+ {"watchdog", mt7981_wdt_groups, ARRAY_SIZE(mt7981_wdt_groups)},
+ {"flash", mt7981_flash_groups, ARRAY_SIZE(mt7981_flash_groups)},
+ {"pcie", mt7981_pcie_groups, ARRAY_SIZE(mt7981_pcie_groups)},
+};
+
+static const char *const mt7981_pinctrl_register_base_names[] = {
+ "gpio_base", "iocfg_rt_base", "iocfg_rm_base", "iocfg_rb_base",
+ "iocfg_lb_base", "iocfg_bl_base", "iocfg_tm_base", "iocfg_tl_base",
+};
+
+static struct mtk_pinctrl_soc mt7981_data = {
+ .name = "mt7981_pinctrl",
+ .reg_cal = mt7981_reg_cals,
+ .pins = mt7981_pins,
+ .npins = ARRAY_SIZE(mt7981_pins),
+ .grps = mt7981_groups,
+ .ngrps = ARRAY_SIZE(mt7981_groups),
+ .funcs = mt7981_functions,
+ .nfuncs = ARRAY_SIZE(mt7981_functions),
+ .io_type = mt7981_io_type_desc,
+ .ntype = ARRAY_SIZE(mt7981_io_type_desc),
+ .gpio_mode = 0,
+ .base_names = mt7981_pinctrl_register_base_names,
+ .nbase_names = ARRAY_SIZE(mt7981_pinctrl_register_base_names),
+ .base_calc = 1,
+};
+
+static int mtk_pinctrl_mt7981_probe(struct udevice *dev)
+{
+ return mtk_pinctrl_common_probe(dev, &mt7981_data);
+}
+
+static const struct udevice_id mt7981_pctrl_match[] = {
+ {.compatible = "mediatek,mt7981-pinctrl"},
+ { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(mt7981_pinctrl) = {
+ .name = "mt7981_pinctrl",
+ .id = UCLASS_PINCTRL,
+ .of_match = mt7981_pctrl_match,
+ .ops = &mtk_pinctrl_ops,
+ .probe = mtk_pinctrl_mt7981_probe,
+ .priv_auto = sizeof(struct mtk_pinctrl_priv),
+};
Signature · 1 line
2.17.1
Re: [PATCH 20/31] pinctrl: mediatek: add pinctrl driver for MT7981 SoC
Quoted 10 lines · Weijie Gao
This patch adds pinctrl and gpio support for MT7981 SoC
Signed-off-by Weijie Gao <[email protected]>--- 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
PATCH 21/31 pinctrl: mediatek: add pinctrl driver for MT7986 SoC
In reply to Weijie GaoThis patch adds pinctrl and gpio support for MT7986 SoC
--- 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
(quoted diff) +0 -0
b/drivers/pinctrl/mediatek/Kconfig
index aceec9277d..27e8998e59 100644
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
(quoted diff) +0 -0
b/drivers/pinctrl/mediatek/Makefile
index 1879d7ae2a..6e733759f5 100644
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
(quoted diff) +0 -0
b/drivers/pinctrl/mediatek/pinctrl-mt7986.c
new file mode 100644
index 0000000000..449e5adcd9
drivers/pinctrl/mediatek/pinctrl-mt7986.c new file +18 -0
@@ -0,0 +1,775 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* The MT7986 driver based on Linux generic pinctrl binding. +* +* Copyright (C) 2022 MediaTek Inc. +* Author: Sam Shih <[email protected]> +*/ + +#include <dm.h> +#include "pinctrl-mtk-common.h" + +#define MT7986_TYPE0_PIN (_number, _name) \ + MTK_TYPED_PIN(_number, _name, DRV_GRP4, IO_TYPE_GRP0) + +#define MT7986_TYPE1_PIN (_number, _name) \ + MTK_TYPED_PIN(_number, _name, DRV_GRP4, IO_TYPE_GRP1) + +#define PIN_FIELD_GPIO (_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits)
\
+ PIN_FIELD_BASE_CALC(_s_pin, _e_pin, GPIO_BASE, _s_addr, _x_addrs, \
+ _s_bit, _x_bits, 32, 0)
+
+#define PIN_FIELD_BASE(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, _s_bit,
\
+ _x_bits) \
+ PIN_FIELD_BASE_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, _s_bit, \
+ _x_bits, 32, 0)
+
+/**
+ * enum - Locking variants of the iocfg bases
+ *
+ * MT7986 have multiple bases to program pin configuration listed as the below:
+ * iocfg_rt:0x11c30000, iocfg_rb:0x11c40000, iocfg_lt:0x11e20000,
+ * iocfg_lb:0x11e30000, iocfg_tr:0x11f00000, iocfg_tl:0x11f10000,
+ * _i_based could be used to indicate what base the pin should be mapped into.
+ *
+ * Each iocfg register base control different group of pads on the SoC
+ *
+ *
+ * chip carrier
+ *
+ * A B C D E F G H
+ * +------------------------+ + * 8 | o o o o o o o o | + * 7 | o o o o o o o o | + * 6 | o o o o o o o o | + * 5 | o o o o o o o o | + * 4 | o o o o o o o o | + * 3 | o o o o o o o o | + * 2 | o o o o o o o o | + * 1 | o o o o o o o o | + * +------------------------+
+ *
+ * inside Chip carrier
+ *
+ * A B C D E F G H
+ * +------------------------+ + * 8 | | + * 7 | TL TR | + * 6 | +---------+ | + * 5 | LT | | RT | + * 4 | | | | + * 3 | LB | | RB | + * 2 | +---------+ | + * 1 | | + * +------------------------+
+ *
+ */
+
+enum {
+ GPIO_BASE,
+ IOCFG_RT_BASE,
+ IOCFG_RB_BASE,
+ IOCFG_LT_BASE,
+ IOCFG_LB_BASE,
+ IOCFG_TR_BASE,
+ IOCFG_TL_BASE,
+};
+
+static const char *const mt7986_pinctrl_register_base_names[] = {
+ "gpio", "iocfg_rt", "iocfg_rb", "iocfg_lt", "iocfg_lb", "iocfg_tr",
+ "iocfg_tl",
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_mode_range[] = {
+ PIN_FIELD_GPIO(0, 100, 0x300, 0x10, 0, 4),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_dir_range[] = {
+ PIN_FIELD_GPIO(0, 100, 0x0, 0x10, 0, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_di_range[] = {
+ PIN_FIELD_GPIO(0, 100, 0x200, 0x10, 0, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_do_range[] = {
+ PIN_FIELD_GPIO(0, 100, 0x100, 0x10, 0, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_ies_range[] = {
+ PIN_FIELD_BASE(0, 0, IOCFG_RB_BASE, 0x40, 0x10, 17, 1),
+ PIN_FIELD_BASE(1, 2, IOCFG_LT_BASE, 0x20, 0x10, 10, 1),
+ PIN_FIELD_BASE(3, 4, IOCFG_LB_BASE, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(5, 6, IOCFG_RB_BASE, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(7, 10, IOCFG_LT_BASE, 0x20, 0x10, 0, 1),
+ PIN_FIELD_BASE(11, 14, IOCFG_RB_BASE, 0x40, 0x10, 8, 1),
+ PIN_FIELD_BASE(15, 20, IOCFG_RB_BASE, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(21, 23, IOCFG_RT_BASE, 0x30, 0x10, 12, 1),
+ PIN_FIELD_BASE(24, 24, IOCFG_RT_BASE, 0x30, 0x10, 18, 1),
+ PIN_FIELD_BASE(25, 25, IOCFG_RT_BASE, 0x30, 0x10, 17, 1),
+ PIN_FIELD_BASE(26, 27, IOCFG_RT_BASE, 0x30, 0x10, 15, 1),
+ PIN_FIELD_BASE(28, 29, IOCFG_RT_BASE, 0x30, 0x10, 19, 1),
+ PIN_FIELD_BASE(30, 30, IOCFG_RT_BASE, 0x30, 0x10, 23, 1),
+ PIN_FIELD_BASE(31, 31, IOCFG_RT_BASE, 0x30, 0x10, 22, 1),
+ PIN_FIELD_BASE(32, 32, IOCFG_RT_BASE, 0x30, 0x10, 21, 1),
+ PIN_FIELD_BASE(33, 33, IOCFG_LT_BASE, 0x20, 0x10, 4, 1),
+ PIN_FIELD_BASE(34, 34, IOCFG_LT_BASE, 0x20, 0x10, 8, 1),
+ PIN_FIELD_BASE(35, 35, IOCFG_LT_BASE, 0x20, 0x10, 7, 1),
+ PIN_FIELD_BASE(36, 37, IOCFG_LT_BASE, 0x20, 0x10, 5, 1),
+ PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x20, 0x10, 9, 1),
+ PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0x40, 0x10, 18, 1),
+ PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x40, 0x10, 12, 1),
+ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x40, 0x10, 22, 1),
+ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x40, 0x10, 20, 1),
+ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x40, 0x10, 26, 1),
+ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x40, 0x10, 24, 1),
+ PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(60, 61, IOCFG_RT_BASE, 0x30, 0x10, 10, 1),
+ PIN_FIELD_BASE(62, 62, IOCFG_RB_BASE, 0x40, 0x10, 15, 1),
+ PIN_FIELD_BASE(63, 63, IOCFG_RB_BASE, 0x40, 0x10, 14, 1),
+ PIN_FIELD_BASE(64, 64, IOCFG_RB_BASE, 0x40, 0x10, 13, 1),
+ PIN_FIELD_BASE(65, 65, IOCFG_RB_BASE, 0x40, 0x10, 16, 1),
+ PIN_FIELD_BASE(66, 68, IOCFG_LB_BASE, 0x20, 0x10, 2, 1),
+ PIN_FIELD_BASE(69, 69, IOCFG_TR_BASE, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(70, 70, IOCFG_TR_BASE, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(71, 71, IOCFG_TR_BASE, 0x30, 0x10, 16, 1),
+ PIN_FIELD_BASE(72, 73, IOCFG_TR_BASE, 0x30, 0x10, 14, 1),
+ PIN_FIELD_BASE(74, 74, IOCFG_TR_BASE, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(75, 77, IOCFG_TR_BASE, 0x30, 0x10, 6, 1),
+ PIN_FIELD_BASE(78, 79, IOCFG_TR_BASE, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(80, 84, IOCFG_TR_BASE, 0x30, 0x10, 9, 1),
+ PIN_FIELD_BASE(85, 85, IOCFG_TR_BASE, 0x30, 0x10, 5, 1),
+ PIN_FIELD_BASE(86, 86, IOCFG_TL_BASE, 0x30, 0x10, 1, 1),
+ PIN_FIELD_BASE(87, 87, IOCFG_TL_BASE, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(88, 88, IOCFG_TL_BASE, 0x30, 0x10, 14, 1),
+ PIN_FIELD_BASE(89, 90, IOCFG_TL_BASE, 0x30, 0x10, 12, 1),
+ PIN_FIELD_BASE(91, 94, IOCFG_TL_BASE, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(95, 96, IOCFG_TL_BASE, 0x30, 0x10, 2, 1),
+ PIN_FIELD_BASE(97, 100, IOCFG_TL_BASE, 0x30, 0x10, 8, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_smt_range[] = {
+ PIN_FIELD_BASE(0, 0, IOCFG_RB_BASE, 0xf0, 0x10, 17, 1),
+ PIN_FIELD_BASE(1, 2, IOCFG_LT_BASE, 0x90, 0x10, 10, 1),
+ PIN_FIELD_BASE(3, 4, IOCFG_LB_BASE, 0x90, 0x10, 0, 1),
+ PIN_FIELD_BASE(5, 6, IOCFG_RB_BASE, 0xf0, 0x10, 0, 1),
+ PIN_FIELD_BASE(7, 10, IOCFG_LT_BASE, 0x90, 0x10, 0, 1),
+ PIN_FIELD_BASE(11, 14, IOCFG_RB_BASE, 0xf0, 0x10, 8, 1),
+ PIN_FIELD_BASE(15, 20, IOCFG_RB_BASE, 0xf0, 0x10, 2, 1),
+ PIN_FIELD_BASE(21, 23, IOCFG_RT_BASE, 0xc0, 0x10, 12, 1),
+ PIN_FIELD_BASE(24, 24, IOCFG_RT_BASE, 0xc0, 0x10, 18, 1),
+ PIN_FIELD_BASE(25, 25, IOCFG_RT_BASE, 0xc0, 0x10, 17, 1),
+ PIN_FIELD_BASE(26, 27, IOCFG_RT_BASE, 0xc0, 0x10, 15, 1),
+ PIN_FIELD_BASE(28, 29, IOCFG_RT_BASE, 0xc0, 0x10, 19, 1),
+ PIN_FIELD_BASE(30, 30, IOCFG_RT_BASE, 0xc0, 0x10, 23, 1),
+ PIN_FIELD_BASE(31, 31, IOCFG_RT_BASE, 0xc0, 0x10, 22, 1),
+ PIN_FIELD_BASE(32, 32, IOCFG_RT_BASE, 0xc0, 0x10, 21, 1),
+ PIN_FIELD_BASE(33, 33, IOCFG_LT_BASE, 0x90, 0x10, 4, 1),
+ PIN_FIELD_BASE(34, 34, IOCFG_LT_BASE, 0x90, 0x10, 8, 1),
+ PIN_FIELD_BASE(35, 35, IOCFG_LT_BASE, 0x90, 0x10, 7, 1),
+ PIN_FIELD_BASE(36, 37, IOCFG_LT_BASE, 0x90, 0x10, 5, 1),
+ PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x90, 0x10, 9, 1),
+ PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0xf0, 0x10, 18, 1),
+ PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0xf0, 0x10, 12, 1),
+ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0xf0, 0x10, 22, 1),
+ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0xf0, 0x10, 20, 1),
+ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0xf0, 0x10, 26, 1),
+ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0xf0, 0x10, 24, 1),
+ PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0xc0, 0x10, 2, 1),
+ PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0xc0, 0x10, 1, 1),
+ PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0xc0, 0x10, 0, 1),
+ PIN_FIELD_BASE(60, 61, IOCFG_RT_BASE, 0xc0, 0x10, 10, 1),
+ PIN_FIELD_BASE(62, 62, IOCFG_RB_BASE, 0xf0, 0x10, 15, 1),
+ PIN_FIELD_BASE(63, 63, IOCFG_RB_BASE, 0xf0, 0x10, 14, 1),
+ PIN_FIELD_BASE(64, 64, IOCFG_RB_BASE, 0xf0, 0x10, 13, 1),
+ PIN_FIELD_BASE(65, 65, IOCFG_RB_BASE, 0xf0, 0x10, 16, 1),
+ PIN_FIELD_BASE(66, 68, IOCFG_LB_BASE, 0x90, 0x10, 2, 1),
+ PIN_FIELD_BASE(69, 69, IOCFG_TR_BASE, 0x80, 0x10, 1, 1),
+ PIN_FIELD_BASE(70, 70, IOCFG_TR_BASE, 0x80, 0x10, 0, 1),
+ PIN_FIELD_BASE(71, 71, IOCFG_TR_BASE, 0x80, 0x10, 16, 1),
+ PIN_FIELD_BASE(72, 73, IOCFG_TR_BASE, 0x80, 0x10, 14, 1),
+ PIN_FIELD_BASE(74, 74, IOCFG_TR_BASE, 0x80, 0x10, 4, 1),
+ PIN_FIELD_BASE(75, 77, IOCFG_TR_BASE, 0x80, 0x10, 6, 1),
+ PIN_FIELD_BASE(78, 79, IOCFG_TR_BASE, 0x80, 0x10, 2, 1),
+ PIN_FIELD_BASE(80, 84, IOCFG_TR_BASE, 0x80, 0x10, 9, 1),
+ PIN_FIELD_BASE(85, 85, IOCFG_TR_BASE, 0x80, 0x10, 5, 1),
+ PIN_FIELD_BASE(86, 86, IOCFG_TL_BASE, 0x70, 0x10, 1, 1),
+ PIN_FIELD_BASE(87, 87, IOCFG_TL_BASE, 0x70, 0x10, 0, 1),
+ PIN_FIELD_BASE(88, 88, IOCFG_TL_BASE, 0x70, 0x10, 14, 1),
+ PIN_FIELD_BASE(89, 90, IOCFG_TL_BASE, 0x70, 0x10, 12, 1),
+ PIN_FIELD_BASE(91, 94, IOCFG_TL_BASE, 0x70, 0x10, 4, 1),
+ PIN_FIELD_BASE(95, 96, IOCFG_TL_BASE, 0x70, 0x10, 2, 1),
+ PIN_FIELD_BASE(97, 100, IOCFG_TL_BASE, 0x70, 0x10, 8, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_pu_range[] = {
+ PIN_FIELD_BASE(69, 69, IOCFG_TR_BASE, 0x50, 0x10, 1, 1),
+ PIN_FIELD_BASE(70, 70, IOCFG_TR_BASE, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(71, 71, IOCFG_TR_BASE, 0x50, 0x10, 16, 1),
+ PIN_FIELD_BASE(72, 73, IOCFG_TR_BASE, 0x50, 0x10, 14, 1),
+ PIN_FIELD_BASE(74, 74, IOCFG_TR_BASE, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(75, 77, IOCFG_TR_BASE, 0x50, 0x10, 6, 1),
+ PIN_FIELD_BASE(78, 79, IOCFG_TR_BASE, 0x50, 0x10, 2, 1),
+ PIN_FIELD_BASE(80, 84, IOCFG_TR_BASE, 0x50, 0x10, 9, 1),
+ PIN_FIELD_BASE(85, 85, IOCFG_TR_BASE, 0x50, 0x10, 5, 1),
+ PIN_FIELD_BASE(86, 86, IOCFG_TL_BASE, 0x50, 0x10, 1, 1),
+ PIN_FIELD_BASE(87, 87, IOCFG_TL_BASE, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(88, 88, IOCFG_TL_BASE, 0x50, 0x10, 14, 1),
+ PIN_FIELD_BASE(89, 90, IOCFG_TL_BASE, 0x50, 0x10, 12, 1),
+ PIN_FIELD_BASE(91, 94, IOCFG_TL_BASE, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(95, 96, IOCFG_TL_BASE, 0x50, 0x10, 2, 1),
+ PIN_FIELD_BASE(97, 100, IOCFG_TL_BASE, 0x50, 0x10, 8, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_pd_range[] = {
+ PIN_FIELD_BASE(69, 69, IOCFG_TR_BASE, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(70, 70, IOCFG_TR_BASE, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(71, 71, IOCFG_TR_BASE, 0x40, 0x10, 16, 1),
+ PIN_FIELD_BASE(72, 73, IOCFG_TR_BASE, 0x40, 0x10, 14, 1),
+ PIN_FIELD_BASE(74, 74, IOCFG_TR_BASE, 0x40, 0x10, 4, 1),
+ PIN_FIELD_BASE(75, 77, IOCFG_TR_BASE, 0x40, 0x10, 6, 1),
+ PIN_FIELD_BASE(78, 79, IOCFG_TR_BASE, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(80, 84, IOCFG_TR_BASE, 0x40, 0x10, 9, 1),
+ PIN_FIELD_BASE(85, 85, IOCFG_TR_BASE, 0x40, 0x10, 5, 1),
+ PIN_FIELD_BASE(86, 86, IOCFG_TL_BASE, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(87, 87, IOCFG_TL_BASE, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(88, 88, IOCFG_TL_BASE, 0x40, 0x10, 14, 1),
+ PIN_FIELD_BASE(89, 90, IOCFG_TL_BASE, 0x40, 0x10, 12, 1),
+ PIN_FIELD_BASE(91, 94, IOCFG_TL_BASE, 0x40, 0x10, 4, 1),
+ PIN_FIELD_BASE(95, 96, IOCFG_TL_BASE, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(97, 100, IOCFG_TL_BASE, 0x40, 0x10, 8, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_drv_range[] = {
+ PIN_FIELD_BASE(0, 0, IOCFG_RB_BASE, 0x10, 0x10, 21, 3),
+ PIN_FIELD_BASE(1, 2, IOCFG_LT_BASE, 0x10, 0x10, 0, 3),
+ PIN_FIELD_BASE(3, 4, IOCFG_LB_BASE, 0x00, 0x10, 0, 1),
+ PIN_FIELD_BASE(5, 5, IOCFG_RB_BASE, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(6, 6, IOCFG_RB_BASE, 0x00, 0x10, 21, 3),
+ PIN_FIELD_BASE(7, 10, IOCFG_LT_BASE, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(11, 12, IOCFG_RB_BASE, 0x00, 0x10, 24, 3),
+ PIN_FIELD_BASE(13, 14, IOCFG_RB_BASE, 0x10, 0x10, 0, 3),
+ PIN_FIELD_BASE(15, 20, IOCFG_RB_BASE, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(21, 23, IOCFG_RT_BASE, 0x10, 0x10, 6, 3),
+ PIN_FIELD_BASE(24, 24, IOCFG_RT_BASE, 0x10, 0x10, 24, 3),
+ PIN_FIELD_BASE(25, 25, IOCFG_RT_BASE, 0x10, 0x10, 21, 3),
+ PIN_FIELD_BASE(26, 27, IOCFG_RT_BASE, 0x10, 0x10, 15, 3),
+ PIN_FIELD_BASE(28, 28, IOCFG_RT_BASE, 0x10, 0x10, 27, 3),
+ PIN_FIELD_BASE(29, 29, IOCFG_RT_BASE, 0x20, 0x10, 0, 3),
+ PIN_FIELD_BASE(30, 30, IOCFG_RT_BASE, 0x20, 0x10, 9, 3),
+ PIN_FIELD_BASE(31, 31, IOCFG_RT_BASE, 0x20, 0x10, 6, 3),
+ PIN_FIELD_BASE(32, 32, IOCFG_RT_BASE, 0x20, 0x10, 3, 3),
+ PIN_FIELD_BASE(33, 33, IOCFG_LT_BASE, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(34, 34, IOCFG_LT_BASE, 0x00, 0x10, 24, 3),
+ PIN_FIELD_BASE(35, 35, IOCFG_LT_BASE, 0x00, 0x10, 21, 3),
+ PIN_FIELD_BASE(36, 37, IOCFG_LT_BASE, 0x00, 0x10, 15, 3),
+ PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x00, 0x10, 27, 3),
+ PIN_FIELD_BASE(39, 39, IOCFG_RB_BASE, 0x10, 0x10, 27, 3),
+ PIN_FIELD_BASE(40, 40, IOCFG_RB_BASE, 0x20, 0x10, 0, 3),
+ PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x10, 0x10, 6, 3),
+ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x20, 0x10, 9, 3),
+ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x20, 0x10, 3, 3),
+ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x20, 0x10, 21, 3),
+ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x20, 0x10, 15, 3),
+ PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x00, 0x10, 6, 3),
+ PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(60, 61, IOCFG_RT_BASE, 0x10, 0x10, 0, 3),
+ PIN_FIELD_BASE(62, 62, IOCFG_RB_BASE, 0x10, 0x10, 15, 3),
+ PIN_FIELD_BASE(63, 63, IOCFG_RB_BASE, 0x10, 0x10, 12, 3),
+ PIN_FIELD_BASE(64, 64, IOCFG_RB_BASE, 0x10, 0x10, 9, 3),
+ PIN_FIELD_BASE(65, 65, IOCFG_RB_BASE, 0x10, 0x10, 18, 3),
+ PIN_FIELD_BASE(66, 68, IOCFG_LB_BASE, 0x00, 0x10, 2, 3),
+ PIN_FIELD_BASE(69, 69, IOCFG_TR_BASE, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(70, 70, IOCFG_TR_BASE, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(71, 71, IOCFG_TR_BASE, 0x10, 0x10, 18, 3),
+ PIN_FIELD_BASE(72, 73, IOCFG_TR_BASE, 0x10, 0x10, 12, 3),
+ PIN_FIELD_BASE(74, 77, IOCFG_TR_BASE, 0x00, 0x10, 15, 3),
+ PIN_FIELD_BASE(78, 79, IOCFG_TR_BASE, 0x00, 0x10, 6, 3),
+ PIN_FIELD_BASE(80, 80, IOCFG_TR_BASE, 0x00, 0x10, 27, 3),
+ PIN_FIELD_BASE(81, 84, IOCFG_TR_BASE, 0x10, 0x10, 0, 3),
+ PIN_FIELD_BASE(85, 85, IOCFG_TR_BASE, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(86, 86, IOCFG_TL_BASE, 0x00, 0x10, 3, 3),
+ PIN_FIELD_BASE(87, 87, IOCFG_TL_BASE, 0x00, 0x10, 0, 3),
+ PIN_FIELD_BASE(88, 88, IOCFG_TL_BASE, 0x10, 0x10, 12, 3),
+ PIN_FIELD_BASE(89, 90, IOCFG_TL_BASE, 0x10, 0x10, 6, 3),
+ PIN_FIELD_BASE(91, 94, IOCFG_TL_BASE, 0x00, 0x10, 12, 3),
+ PIN_FIELD_BASE(95, 96, IOCFG_TL_BASE, 0x00, 0x10, 6, 3),
+ PIN_FIELD_BASE(97, 98, IOCFG_TL_BASE, 0x00, 0x10, 24, 3),
+ PIN_FIELD_BASE(99, 100, IOCFG_TL_BASE, 0x10, 0x10, 2, 3),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_pupd_range[] = {
+ PIN_FIELD_BASE(0, 0, IOCFG_RB_BASE, 0x60, 0x10, 17, 1),
+ PIN_FIELD_BASE(1, 2, IOCFG_LT_BASE, 0x30, 0x10, 10, 1),
+ PIN_FIELD_BASE(3, 4, IOCFG_LB_BASE, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(5, 6, IOCFG_RB_BASE, 0x60, 0x10, 0, 1),
+ PIN_FIELD_BASE(7, 10, IOCFG_LT_BASE, 0x30, 0x10, 0, 1),
+ PIN_FIELD_BASE(11, 14, IOCFG_RB_BASE, 0x60, 0x10, 8, 1),
+ PIN_FIELD_BASE(15, 20, IOCFG_RB_BASE, 0x60, 0x10, 2, 1),
+ PIN_FIELD_BASE(21, 23, IOCFG_RT_BASE, 0x40, 0x10, 12, 1),
+ PIN_FIELD_BASE(24, 24, IOCFG_RT_BASE, 0x40, 0x10, 18, 1),
+ PIN_FIELD_BASE(25, 25, IOCFG_RT_BASE, 0x40, 0x10, 17, 1),
+ PIN_FIELD_BASE(26, 27, IOCFG_RT_BASE, 0x40, 0x10, 15, 1),
+ PIN_FIELD_BASE(28, 29, IOCFG_RT_BASE, 0x40, 0x10, 19, 1),
+ PIN_FIELD_BASE(30, 30, IOCFG_RT_BASE, 0x40, 0x10, 23, 1),
+ PIN_FIELD_BASE(31, 31, IOCFG_RT_BASE, 0x40, 0x10, 22, 1),
+ PIN_FIELD_BASE(32, 32, IOCFG_RT_BASE, 0x40, 0x10, 21, 1),
+ PIN_FIELD_BASE(33, 33, IOCFG_LT_BASE, 0x30, 0x10, 4, 1),
+ PIN_FIELD_BASE(34, 34, IOCFG_LT_BASE, 0x30, 0x10, 8, 1),
+ PIN_FIELD_BASE(35, 35, IOCFG_LT_BASE, 0x30, 0x10, 7, 1),
+ PIN_FIELD_BASE(36, 37, IOCFG_LT_BASE, 0x30, 0x10, 5, 1),
+ PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x30, 0x10, 9, 1),
+ PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0x60, 0x10, 18, 1),
+ PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x60, 0x10, 12, 1),
+ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x60, 0x10, 23, 1),
+ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x60, 0x10, 21, 1),
+ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x60, 0x10, 27, 1),
+ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x60, 0x10, 25, 1),
+ PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x40, 0x10, 2, 1),
+ PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x40, 0x10, 1, 1),
+ PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(60, 61, IOCFG_RT_BASE, 0x40, 0x10, 10, 1),
+ PIN_FIELD_BASE(62, 62, IOCFG_RB_BASE, 0x60, 0x10, 15, 1),
+ PIN_FIELD_BASE(63, 63, IOCFG_RB_BASE, 0x60, 0x10, 14, 1),
+ PIN_FIELD_BASE(64, 64, IOCFG_RB_BASE, 0x60, 0x10, 13, 1),
+ PIN_FIELD_BASE(65, 65, IOCFG_RB_BASE, 0x60, 0x10, 16, 1),
+ PIN_FIELD_BASE(66, 68, IOCFG_LB_BASE, 0x40, 0x10, 2, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_r0_range[] = {
+ PIN_FIELD_BASE(0, 0, IOCFG_RB_BASE, 0x70, 0x10, 17, 1),
+ PIN_FIELD_BASE(1, 2, IOCFG_LT_BASE, 0x40, 0x10, 10, 1),
+ PIN_FIELD_BASE(3, 4, IOCFG_LB_BASE, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(5, 6, IOCFG_RB_BASE, 0x70, 0x10, 0, 1),
+ PIN_FIELD_BASE(7, 10, IOCFG_LT_BASE, 0x40, 0x10, 0, 1),
+ PIN_FIELD_BASE(11, 14, IOCFG_RB_BASE, 0x70, 0x10, 8, 1),
+ PIN_FIELD_BASE(15, 20, IOCFG_RB_BASE, 0x70, 0x10, 2, 1),
+ PIN_FIELD_BASE(21, 23, IOCFG_RT_BASE, 0x50, 0x10, 12, 1),
+ PIN_FIELD_BASE(24, 24, IOCFG_RT_BASE, 0x50, 0x10, 18, 1),
+ PIN_FIELD_BASE(25, 25, IOCFG_RT_BASE, 0x50, 0x10, 17, 1),
+ PIN_FIELD_BASE(26, 27, IOCFG_RT_BASE, 0x50, 0x10, 15, 1),
+ PIN_FIELD_BASE(28, 29, IOCFG_RT_BASE, 0x50, 0x10, 19, 1),
+ PIN_FIELD_BASE(30, 30, IOCFG_RT_BASE, 0x50, 0x10, 23, 1),
+ PIN_FIELD_BASE(31, 31, IOCFG_RT_BASE, 0x50, 0x10, 22, 1),
+ PIN_FIELD_BASE(32, 32, IOCFG_RT_BASE, 0x50, 0x10, 21, 1),
+ PIN_FIELD_BASE(33, 33, IOCFG_LT_BASE, 0x40, 0x10, 4, 1),
+ PIN_FIELD_BASE(34, 34, IOCFG_LT_BASE, 0x40, 0x10, 8, 1),
+ PIN_FIELD_BASE(35, 35, IOCFG_LT_BASE, 0x40, 0x10, 7, 1),
+ PIN_FIELD_BASE(36, 37, IOCFG_LT_BASE, 0x40, 0x10, 5, 1),
+ PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x40, 0x10, 9, 1),
+ PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0x70, 0x10, 18, 1),
+ PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x70, 0x10, 12, 1),
+ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x70, 0x10, 23, 1),
+ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x70, 0x10, 21, 1),
+ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x70, 0x10, 27, 1),
+ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x70, 0x10, 25, 1),
+ PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x50, 0x10, 2, 1),
+ PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x50, 0x10, 1, 1),
+ PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(60, 61, IOCFG_RT_BASE, 0x50, 0x10, 10, 1),
+ PIN_FIELD_BASE(62, 62, IOCFG_RB_BASE, 0x70, 0x10, 15, 1),
+ PIN_FIELD_BASE(63, 63, IOCFG_RB_BASE, 0x70, 0x10, 14, 1),
+ PIN_FIELD_BASE(64, 64, IOCFG_RB_BASE, 0x70, 0x10, 13, 1),
+ PIN_FIELD_BASE(65, 65, IOCFG_RB_BASE, 0x70, 0x10, 16, 1),
+ PIN_FIELD_BASE(66, 68, IOCFG_LB_BASE, 0x50, 0x10, 2, 1),
+};
+
+static const struct mtk_pin_field_calc mt7986_pin_r1_range[] = {
+ PIN_FIELD_BASE(0, 0, IOCFG_RB_BASE, 0x80, 0x10, 17, 1),
+ PIN_FIELD_BASE(1, 2, IOCFG_LT_BASE, 0x50, 0x10, 10, 1),
+ PIN_FIELD_BASE(3, 4, IOCFG_LB_BASE, 0x60, 0x10, 0, 1),
+ PIN_FIELD_BASE(5, 6, IOCFG_RB_BASE, 0x80, 0x10, 0, 1),
+ PIN_FIELD_BASE(7, 10, IOCFG_LT_BASE, 0x50, 0x10, 0, 1),
+ PIN_FIELD_BASE(11, 14, IOCFG_RB_BASE, 0x80, 0x10, 8, 1),
+ PIN_FIELD_BASE(15, 20, IOCFG_RB_BASE, 0x80, 0x10, 2, 1),
+ PIN_FIELD_BASE(21, 23, IOCFG_RT_BASE, 0x60, 0x10, 12, 1),
+ PIN_FIELD_BASE(24, 24, IOCFG_RT_BASE, 0x60, 0x10, 18, 1),
+ PIN_FIELD_BASE(25, 25, IOCFG_RT_BASE, 0x60, 0x10, 17, 1),
+ PIN_FIELD_BASE(26, 27, IOCFG_RT_BASE, 0x60, 0x10, 15, 1),
+ PIN_FIELD_BASE(28, 29, IOCFG_RT_BASE, 0x60, 0x10, 19, 1),
+ PIN_FIELD_BASE(30, 30, IOCFG_RT_BASE, 0x60, 0x10, 23, 1),
+ PIN_FIELD_BASE(31, 31, IOCFG_RT_BASE, 0x60, 0x10, 22, 1),
+ PIN_FIELD_BASE(32, 32, IOCFG_RT_BASE, 0x60, 0x10, 21, 1),
+ PIN_FIELD_BASE(33, 33, IOCFG_LT_BASE, 0x50, 0x10, 4, 1),
+ PIN_FIELD_BASE(34, 34, IOCFG_LT_BASE, 0x50, 0x10, 8, 1),
+ PIN_FIELD_BASE(35, 35, IOCFG_LT_BASE, 0x50, 0x10, 7, 1),
+ PIN_FIELD_BASE(36, 37, IOCFG_LT_BASE, 0x50, 0x10, 5, 1),
+ PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x50, 0x10, 9, 1),
+ PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0x80, 0x10, 18, 1),
+ PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x80, 0x10, 12, 1),
+ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x80, 0x10, 23, 1),
+ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x80, 0x10, 21, 1),
+ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x80, 0x10, 27, 1),
+ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x80, 0x10, 25, 1),
+ PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x60, 0x10, 2, 1),
+ PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x60, 0x10, 1, 1),
+ PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x60, 0x10, 0, 1),
+ PIN_FIELD_BASE(60, 61, IOCFG_RT_BASE, 0x60, 0x10, 10, 1),
+ PIN_FIELD_BASE(62, 62, IOCFG_RB_BASE, 0x80, 0x10, 15, 1),
+ PIN_FIELD_BASE(63, 63, IOCFG_RB_BASE, 0x80, 0x10, 14, 1),
+ PIN_FIELD_BASE(64, 64, IOCFG_RB_BASE, 0x80, 0x10, 13, 1),
+ PIN_FIELD_BASE(65, 65, IOCFG_RB_BASE, 0x80, 0x10, 16, 1),
+ PIN_FIELD_BASE(66, 68, IOCFG_LB_BASE, 0x60, 0x10, 2, 1),
+};
+
+static const struct mtk_pin_reg_calc mt7986_reg_cals[] = {
+ [PINCTRL_PIN_REG_MODE] = MTK_RANGE(mt7986_pin_mode_range),
+ [PINCTRL_PIN_REG_DIR] = MTK_RANGE(mt7986_pin_dir_range),
+ [PINCTRL_PIN_REG_DI] = MTK_RANGE(mt7986_pin_di_range),
+ [PINCTRL_PIN_REG_DO] = MTK_RANGE(mt7986_pin_do_range),
+ [PINCTRL_PIN_REG_SMT] = MTK_RANGE(mt7986_pin_smt_range),
+ [PINCTRL_PIN_REG_IES] = MTK_RANGE(mt7986_pin_ies_range),
+ [PINCTRL_PIN_REG_DRV] = MTK_RANGE(mt7986_pin_drv_range),
+ [PINCTRL_PIN_REG_PU] = MTK_RANGE(mt7986_pin_pu_range),
+ [PINCTRL_PIN_REG_PD] = MTK_RANGE(mt7986_pin_pd_range),
+ [PINCTRL_PIN_REG_PUPD] = MTK_RANGE(mt7986_pin_pupd_range),
+ [PINCTRL_PIN_REG_R0] = MTK_RANGE(mt7986_pin_r0_range),
+ [PINCTRL_PIN_REG_R1] = MTK_RANGE(mt7986_pin_r1_range),
+};
+
+static const struct mtk_pin_desc mt7986_pins[] = {
+ MT7986_TYPE0_PIN(0, "SYS_WATCHDOG"),
+ MT7986_TYPE0_PIN(1, "WF2G_LED"),
+ MT7986_TYPE0_PIN(2, "WF5G_LED"),
+ MT7986_TYPE0_PIN(3, "I2C_SCL"),
+ MT7986_TYPE0_PIN(4, "I2C_SDA"),
+ MT7986_TYPE0_PIN(5, "GPIO_0"),
+ MT7986_TYPE0_PIN(6, "GPIO_1"),
+ MT7986_TYPE0_PIN(7, "GPIO_2"),
+ MT7986_TYPE0_PIN(8, "GPIO_3"),
+ MT7986_TYPE0_PIN(9, "GPIO_4"),
+ MT7986_TYPE0_PIN(10, "GPIO_5"),
+ MT7986_TYPE0_PIN(11, "GPIO_6"),
+ MT7986_TYPE0_PIN(12, "GPIO_7"),
+ MT7986_TYPE0_PIN(13, "GPIO_8"),
+ MT7986_TYPE0_PIN(14, "GPIO_9"),
+ MT7986_TYPE0_PIN(15, "GPIO_10"),
+ MT7986_TYPE0_PIN(16, "GPIO_11"),
+ MT7986_TYPE0_PIN(17, "GPIO_12"),
+ MT7986_TYPE0_PIN(18, "GPIO_13"),
+ MT7986_TYPE0_PIN(19, "GPIO_14"),
+ MT7986_TYPE0_PIN(20, "GPIO_15"),
+ MT7986_TYPE0_PIN(21, "PWM0"),
+ MT7986_TYPE0_PIN(22, "PWM1"),
+ MT7986_TYPE0_PIN(23, "SPI0_CLK"),
+ MT7986_TYPE0_PIN(24, "SPI0_MOSI"),
+ MT7986_TYPE0_PIN(25, "SPI0_MISO"),
+ MT7986_TYPE0_PIN(26, "SPI0_CS"),
+ MT7986_TYPE0_PIN(27, "SPI0_HOLD"),
+ MT7986_TYPE0_PIN(28, "SPI0_WP"),
+ MT7986_TYPE0_PIN(29, "SPI1_CLK"),
+ MT7986_TYPE0_PIN(30, "SPI1_MOSI"),
+ MT7986_TYPE0_PIN(31, "SPI1_MISO"),
+ MT7986_TYPE0_PIN(32, "SPI1_CS"),
+ MT7986_TYPE0_PIN(33, "SPI2_CLK"),
+ MT7986_TYPE0_PIN(34, "SPI2_MOSI"),
+ MT7986_TYPE0_PIN(35, "SPI2_MISO"),
+ MT7986_TYPE0_PIN(36, "SPI2_CS"),
+ MT7986_TYPE0_PIN(37, "SPI2_HOLD"),
+ MT7986_TYPE0_PIN(38, "SPI2_WP"),
+ MT7986_TYPE0_PIN(39, "UART0_RXD"),
+ MT7986_TYPE0_PIN(40, "UART0_TXD"),
+ MT7986_TYPE0_PIN(41, "PCIE_PERESET_N"),
+ MT7986_TYPE0_PIN(42, "UART1_RXD"),
+ MT7986_TYPE0_PIN(43, "UART1_TXD"),
+ MT7986_TYPE0_PIN(44, "UART1_CTS"),
+ MT7986_TYPE0_PIN(45, "UART1_RTS"),
+ MT7986_TYPE0_PIN(46, "UART2_RXD"),
+ MT7986_TYPE0_PIN(47, "UART2_TXD"),
+ MT7986_TYPE0_PIN(48, "UART2_CTS"),
+ MT7986_TYPE0_PIN(49, "UART2_RTS"),
+ MT7986_TYPE0_PIN(50, "EMMC_DATA_0"),
+ MT7986_TYPE0_PIN(51, "EMMC_DATA_1"),
+ MT7986_TYPE0_PIN(52, "EMMC_DATA_2"),
+ MT7986_TYPE0_PIN(53, "EMMC_DATA_3"),
+ MT7986_TYPE0_PIN(54, "EMMC_DATA_4"),
+ MT7986_TYPE0_PIN(55, "EMMC_DATA_5"),
+ MT7986_TYPE0_PIN(56, "EMMC_DATA_6"),
+ MT7986_TYPE0_PIN(57, "EMMC_DATA_7"),
+ MT7986_TYPE0_PIN(58, "EMMC_CMD"),
+ MT7986_TYPE0_PIN(59, "EMMC_CK"),
+ MT7986_TYPE0_PIN(60, "EMMC_DSL"),
+ MT7986_TYPE0_PIN(61, "EMMC_RSTB"),
+ MT7986_TYPE0_PIN(62, "PCM_DTX"),
+ MT7986_TYPE0_PIN(63, "PCM_DRX"),
+ MT7986_TYPE0_PIN(64, "PCM_CLK"),
+ MT7986_TYPE0_PIN(65, "PCM_FS"),
+ MT7986_TYPE0_PIN(66, "MT7531_INT"),
+ MT7986_TYPE0_PIN(67, "SMI_MDC"),
+ MT7986_TYPE0_PIN(68, "SMI_MDIO"),
+ MT7986_TYPE1_PIN(69, "WF0_DIG_RESETB"),
+ MT7986_TYPE1_PIN(70, "WF0_CBA_RESETB"),
+ MT7986_TYPE1_PIN(71, "WF0_XO_REQ"),
+ MT7986_TYPE1_PIN(72, "WF0_TOP_CLK"),
+ MT7986_TYPE1_PIN(73, "WF0_TOP_DATA"),
+ MT7986_TYPE1_PIN(74, "WF0_HB1"),
+ MT7986_TYPE1_PIN(75, "WF0_HB2"),
+ MT7986_TYPE1_PIN(76, "WF0_HB3"),
+ MT7986_TYPE1_PIN(77, "WF0_HB4"),
+ MT7986_TYPE1_PIN(78, "WF0_HB0"),
+ MT7986_TYPE1_PIN(79, "WF0_HB0_B"),
+ MT7986_TYPE1_PIN(80, "WF0_HB5"),
+ MT7986_TYPE1_PIN(81, "WF0_HB6"),
+ MT7986_TYPE1_PIN(82, "WF0_HB7"),
+ MT7986_TYPE1_PIN(83, "WF0_HB8"),
+ MT7986_TYPE1_PIN(84, "WF0_HB9"),
+ MT7986_TYPE1_PIN(85, "WF0_HB10"),
+ MT7986_TYPE1_PIN(86, "WF1_DIG_RESETB"),
+ MT7986_TYPE1_PIN(87, "WF1_CBA_RESETB"),
+ MT7986_TYPE1_PIN(88, "WF1_XO_REQ"),
+ MT7986_TYPE1_PIN(89, "WF1_TOP_CLK"),
+ MT7986_TYPE1_PIN(90, "WF1_TOP_DATA"),
+ MT7986_TYPE1_PIN(91, "WF1_HB1"),
+ MT7986_TYPE1_PIN(92, "WF1_HB2"),
+ MT7986_TYPE1_PIN(93, "WF1_HB3"),
+ MT7986_TYPE1_PIN(94, "WF1_HB4"),
+ MT7986_TYPE1_PIN(95, "WF1_HB0"),
+ MT7986_TYPE1_PIN(96, "WF1_HB0_B"),
+ MT7986_TYPE1_PIN(97, "WF1_HB5"),
+ MT7986_TYPE1_PIN(98, "WF1_HB6"),
+ MT7986_TYPE1_PIN(99, "WF1_HB7"),
+ MT7986_TYPE1_PIN(100, "WF1_HB8"),
+};
+
+static const struct mtk_io_type_desc mt7986_io_type_desc[] = {
+ [IO_TYPE_GRP0] = {
+ .name = "18OD33",
+ .bias_set = mtk_pinconf_bias_set_pupd_r1_r0,
+ .drive_set = mtk_pinconf_drive_set_v1,
+ .input_enable = mtk_pinconf_input_enable_v1,
+ },
+ [IO_TYPE_GRP1] = {
+ .name = "18A01",
+ .bias_set = mtk_pinconf_bias_set_pu_pd,
+ .drive_set = mtk_pinconf_drive_set_v1,
+ .input_enable = mtk_pinconf_input_enable_v1,
+ },
+};
+
+/* List all groups consisting of these pins dedicated to the enablement of
+ * certain hardware block and the corresponding mode for all of the pins.
+ * The hardware probably has multiple combinations of these pinouts.
+ */
+
+static int mt7986_watchdog_pins[] = { 0, };
+static int mt7986_watchdog_funcs[] = { 1, };
+
+static int mt7986_wifi_led_pins[] = { 1, 2, };
+static int mt7986_wifi_led_funcs[] = { 1, 1, };
+
+static int mt7986_i2c_pins[] = { 3, 4, };
+static int mt7986_i2c_funcs[] = { 1, 1, };
+
+static int mt7986_uart1_0_pins[] = { 7, 8, 9, 10, };
+static int mt7986_uart1_0_funcs[] = { 3, 3, 3, 3, };
+
+static int mt7986_spi1_0_pins[] = { 11, 12, 13, 14, };
+static int mt7986_spi1_0_funcs[] = { 3, 3, 3, 3, };
+
+static int mt7986_pwm1_1_pins[] = { 20, };
+static int mt7986_pwm1_1_funcs[] = { 2, };
+
+static int mt7986_pwm0_pins[] = { 21, };
+static int mt7986_pwm0_funcs[] = { 1, };
+
+static int mt7986_pwm1_0_pins[] = { 22, };
+static int mt7986_pwm1_0_funcs[] = { 1, };
+
+static int mt7986_emmc_45_pins[] = {
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, };
+static int mt7986_emmc_45_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, }; +
+static int mt7986_snfi_pins[] = { 23, 24, 25, 26, 27, 28, }; +static int mt7986_snfi_funcs[] = { 1, 1, 1, 1, 1, 1, };
+
+static int mt7986_spi1_1_pins[] = { 23, 24, 25, 26, };
+static int mt7986_spi1_1_funcs[] = { 3, 3, 3, 3, };
+
+static int mt7986_uart1_1_pins[] = { 23, 24, 25, 26, }; +static int mt7986_uart1_1_funcs[] = { 4, 4, 4, 4, };
+
+static int mt7986_spi1_2_pins[] = { 29, 30, 31, 32, };
+static int mt7986_spi1_2_funcs[] = { 1, 1, 1, 1, };
+
+static int mt7986_uart1_2_pins[] = { 29, 30, 31, 32, }; +static int mt7986_uart1_2_funcs[] = { 3, 3, 3, 3, };
+
+static int mt7986_uart2_0_pins[] = { 29, 30, 31, 32, }; +static int mt7986_uart2_0_funcs[] = { 4, 4, 4, 4, };
+
+static int mt7986_spi0_pins[] = { 33, 34, 35, 36, };
+static int mt7986_spi0_funcs[] = { 1, 1, 1, 1, };
+
+static int mt7986_spi0_wp_hold_pins[] = { 37, 38, };
+static int mt7986_spi0_wp_hold_funcs[] = { 1, 1, };
+
+static int mt7986_uart2_1_pins[] = { 33, 34, 35, 36, }; +static int mt7986_uart2_1_funcs[] = { 3, 3, 3, 3, };
+
+static int mt7986_uart1_3_rx_tx_pins[] = { 35, 36, };
+static int mt7986_uart1_3_rx_tx_funcs[] = { 2, 2, };
+
+static int mt7986_uart1_3_cts_rts_pins[] = { 37, 38, }; +static int mt7986_uart1_3_cts_rts_funcs[] = { 2, 2, };
+
+static int mt7986_spi1_3_pins[] = { 33, 34, 35, 36, };
+static int mt7986_spi1_3_funcs[] = { 4, 4, 4, 4, };
+
+static int mt7986_uart0_pins[] = { 39, 40, };
+static int mt7986_uart0_funcs[] = { 1, 1, };
+
+static int mt7986_pcie_reset_pins[] = { 41, };
+static int mt7986_pcie_reset_funcs[] = { 1, };
+
+static int mt7986_uart1_pins[] = { 42, 43, 44, 45, };
+static int mt7986_uart1_funcs[] = { 1, 1, 1, 1, };
+
+static int mt7986_uart2_pins[] = { 46, 47, 48, 49, };
+static int mt7986_uart2_funcs[] = { 1, 1, 1, 1, };
+
+static int mt7986_emmc_51_pins[] = {
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, };
+static int mt7986_emmc_51_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
};
+
+static int mt7986_pcm_pins[] = { 62, 63, 64, 65, };
+static int mt7986_pcm_funcs[] = { 1, 1, 1, 1, };
+
+static int mt7986_i2s_pins[] = { 62, 63, 64, 65, };
+static int mt7986_i2s_funcs[] = { 1, 1, 1, 1, };
+
+static int mt7986_switch_int_pins[] = { 66, };
+static int mt7986_switch_int_funcs[] = { 1, };
+
+static int mt7986_mdc_mdio_pins[] = { 67, 68, };
+static int mt7986_mdc_mdio_funcs[] = { 1, 1, };
+
+static int mt7986_wf_2g_pins[] = {74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
};
+static int mt7986_wf_2g_funcs[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; +
+static int mt7986_wf_5g_pins[] = {91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
};
+static int mt7986_wf_5g_funcs[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; +
+static int mt7986_wf_dbdc_pins[] = {
+ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, };
+static int mt7986_wf_dbdc_funcs[] = {
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
+
+static int mt7986_pcie_clk_pins[] = { 9, };
+static int mt7986_pcie_clk_funcs[] = { 1, };
+
+static int mt7986_pcie_wake_pins[] = { 10, };
+static int mt7986_pcie_wake_funcs[] = { 1, };
+
+static const struct mtk_group_desc mt7986_groups[] = {
+ PINCTRL_PIN_GROUP("watchdog", mt7986_watchdog),
+ PINCTRL_PIN_GROUP("wifi_led", mt7986_wifi_led),
+ PINCTRL_PIN_GROUP("i2c", mt7986_i2c),
+ PINCTRL_PIN_GROUP("uart1_0", mt7986_uart1_0),
+ PINCTRL_PIN_GROUP("pcie_clk", mt7986_pcie_clk),
+ PINCTRL_PIN_GROUP("pcie_wake", mt7986_pcie_wake),
+ PINCTRL_PIN_GROUP("spi1_0", mt7986_spi1_0),
+ PINCTRL_PIN_GROUP("pwm1_1", mt7986_pwm1_1),
+ PINCTRL_PIN_GROUP("pwm0", mt7986_pwm0),
+ PINCTRL_PIN_GROUP("pwm1_0", mt7986_pwm1_0),
+ PINCTRL_PIN_GROUP("emmc_45", mt7986_emmc_45),
+ PINCTRL_PIN_GROUP("snfi", mt7986_snfi),
+ PINCTRL_PIN_GROUP("spi1_1", mt7986_spi1_1),
+ PINCTRL_PIN_GROUP("uart1_1", mt7986_uart1_1),
+ PINCTRL_PIN_GROUP("spi1_2", mt7986_spi1_2),
+ PINCTRL_PIN_GROUP("uart1_2", mt7986_uart1_2),
+ PINCTRL_PIN_GROUP("uart2_0", mt7986_uart2_0),
+ PINCTRL_PIN_GROUP("spi0", mt7986_spi0),
+ PINCTRL_PIN_GROUP("spi0_wp_hold", mt7986_spi0_wp_hold),
+ PINCTRL_PIN_GROUP("uart2_1", mt7986_uart2_1),
+ PINCTRL_PIN_GROUP("uart1_3_rx_tx", mt7986_uart1_3_rx_tx),
+ PINCTRL_PIN_GROUP("uart1_3_cts_rts", mt7986_uart1_3_cts_rts),
+ PINCTRL_PIN_GROUP("spi1_3", mt7986_spi1_3),
+ PINCTRL_PIN_GROUP("uart0", mt7986_uart0),
+ PINCTRL_PIN_GROUP("switch_int", mt7986_switch_int),
+ PINCTRL_PIN_GROUP("mdc_mdio", mt7986_mdc_mdio),
+ PINCTRL_PIN_GROUP("pcie_pereset", mt7986_pcie_reset),
+ PINCTRL_PIN_GROUP("uart1", mt7986_uart1),
+ PINCTRL_PIN_GROUP("uart2", mt7986_uart2),
+ PINCTRL_PIN_GROUP("emmc_51", mt7986_emmc_51),
+ PINCTRL_PIN_GROUP("pcm", mt7986_pcm),
+ PINCTRL_PIN_GROUP("i2s", mt7986_i2s),
+ PINCTRL_PIN_GROUP("wf_2g", mt7986_wf_2g),
+ PINCTRL_PIN_GROUP("wf_5g", mt7986_wf_5g),
+ PINCTRL_PIN_GROUP("wf_dbdc", mt7986_wf_dbdc),
+};
+
+/* Joint those groups owning the same capability in user point of view
which
+ * allows that people tend to use through the device tree.
+ */
+
+static const char *const mt7986_audio_groups[] = { "pcm", "i2s" }; +static const char *const mt7986_emmc_groups[] = { "emmc_45", "emmc_51", }; +static const char *const mt7986_ethernet_groups[] = { "switch_int",
+ "mdc_mdio", };
+static const char *const mt7986_i2c_groups[] = { "i2c", }; +static const char *const mt7986_led_groups[] = { "wifi_led", }; +static const char *const mt7986_flash_groups[] = { "snfi", }; +static const char *const mt7986_pcie_groups[] = { "pcie_clk", "pcie_wake",
+ "pcie_pereset" };
+static const char *const mt7986_pwm_groups[] = { "pwm0", "pwm1_0",
"pwm1_1", };
+static const char *const mt7986_spi_groups[] = { "spi0", "spi0_wp_hold",
+ "spi1_0", "spi1_1", "spi1_2", "spi1_3", };
+static const char *const mt7986_uart_groups[] = { "uart1_0", "uart1_1",
+ "uart1_2", "uart1_3_rx_tx", "uart1_3_cts_rts", "uart2_0", "uart2_1",
+ "uart0", "uart1", "uart2", };
+static const char *const mt7986_wdt_groups[] = { "watchdog", }; +static const char *const mt7986_wf_groups[] = { "wf_2g", "wf_5g",
"wf_dbdc", };
+
+static const struct mtk_function_desc mt7986_functions[] = {
+ {"audio", mt7986_audio_groups, ARRAY_SIZE(mt7986_audio_groups)},
+ {"emmc", mt7986_emmc_groups, ARRAY_SIZE(mt7986_emmc_groups)},
+ {"eth", mt7986_ethernet_groups, ARRAY_SIZE(mt7986_ethernet_groups)},
+ {"i2c", mt7986_i2c_groups, ARRAY_SIZE(mt7986_i2c_groups)},
+ {"led", mt7986_led_groups, ARRAY_SIZE(mt7986_led_groups)},
+ {"flash", mt7986_flash_groups, ARRAY_SIZE(mt7986_flash_groups)},
+ {"pcie", mt7986_pcie_groups, ARRAY_SIZE(mt7986_pcie_groups)},
+ {"pwm", mt7986_pwm_groups, ARRAY_SIZE(mt7986_pwm_groups)},
+ {"spi", mt7986_spi_groups, ARRAY_SIZE(mt7986_spi_groups)},
+ {"uart", mt7986_uart_groups, ARRAY_SIZE(mt7986_uart_groups)},
+ {"watchdog", mt7986_wdt_groups, ARRAY_SIZE(mt7986_wdt_groups)},
+ {"wifi", mt7986_wf_groups, ARRAY_SIZE(mt7986_wf_groups)},
+};
+
+static struct mtk_pinctrl_soc mt7986_data = {
+ .name = "mt7986_pinctrl",
+ .reg_cal = mt7986_reg_cals,
+ .pins = mt7986_pins,
+ .npins = ARRAY_SIZE(mt7986_pins),
+ .grps = mt7986_groups,
+ .ngrps = ARRAY_SIZE(mt7986_groups),
+ .funcs = mt7986_functions,
+ .nfuncs = ARRAY_SIZE(mt7986_functions),
+ .io_type = mt7986_io_type_desc,
+ .ntype = ARRAY_SIZE(mt7986_io_type_desc),
+ .gpio_mode = 0,
+ .base_names = mt7986_pinctrl_register_base_names,
+ .nbase_names = ARRAY_SIZE(mt7986_pinctrl_register_base_names),
+ .base_calc = 1,
+};
+
+static int mtk_pinctrl_mt7986_probe(struct udevice *dev)
+{
+ return mtk_pinctrl_common_probe(dev, &mt7986_data);
+}
+
+static const struct udevice_id mt7986_pctrl_match[] = {
+ {.compatible = "mediatek,mt7986-pinctrl"},
+ { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(mt7986_pinctrl) = {
+ .name = "mt7986_pinctrl",
+ .id = UCLASS_PINCTRL,
+ .of_match = mt7986_pctrl_match,
+ .ops = &mtk_pinctrl_ops,
+ .probe = mtk_pinctrl_mt7986_probe,
+ .priv_auto = sizeof(struct mtk_pinctrl_priv),
+};
Signature · 1 line
2.17.1
Re: [PATCH 21/31] pinctrl: mediatek: add pinctrl driver for MT7986 SoC
Quoted 10 lines · Weijie Gao
This patch adds pinctrl and gpio support for MT7986 SoC
Signed-off-by Weijie Gao <[email protected]>--- 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
PATCH 22/31 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.
--- drivers/clk/mediatek/clk-mtk.c | 5 ++++- drivers/clk/mediatek/clk-mtk.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/clk/mediatek/clk-mtk.c +4 -1
@@ -314,12 +314,15 @@ static ulong mtk_topckgen_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; +u32 flag =0 ; index =readl (priv->base + mux->mux_reg); index &= mux->mux_mask << mux->mux_shift; index = index >> mux->mux_shift; -if (mux->parent[index]) +if (mux->parent[index] ==CLK_XTAL && priv->tree->flags &CLK_BYPASS_XTAL ) + flag =1 ; +if (mux->parent[index] >0 || flag ==1 )return mtk_clk_find_parent_rate (clk, mux->parent[index],NULL );
drivers/clk/mediatek/clk-mtk.h +3 -0
@@ -11,6 +11,8 @@#define CLK_XTAL 0#define MHZ (1000 * 1000) +#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 +199,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
Re: [PATCH 22/31] clk: mediatek: add CLK_BYPASS_XTAL flag to allow bypassing searching clock parent of xtal clock
Hi Weijie,
Quoted 13 lines · Weijie Gao
The 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_XTALin 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_ratebe called. Current logic will make entire clock driver not working.
Quoted 8 lines
This patch adds a flag to indicate that whether a clock driver needs clocks with ID=0 to call
mtk_topckgen_get_mux_rate.Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 5 ++++- drivers/clk/mediatek/clk-mtk.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-)
Quoted 37 lines
drivers/clk/mediatek/clk-mtk.c +4
-1@@ -314,12 +314,15 @@ static ulong mtk_topckgen_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; +u32 flag =0 ; index =readl (priv->base + mux->mux_reg); index &= mux->mux_mask << mux->mux_shift; index = index >> mux->mux_shift; -if (mux->parent[index]) +if (mux->parent[index] ==CLK_XTAL && priv->tree->flags &CLK_BYPASS_XTAL ) + flag =1 ; +if (mux->parent[index] >0 || flag ==1 )return mtk_clk_find_parent_rate (clk, mux->parent[index],NULL );drivers/clk/mediatek/clk-mtk.h +2
-0@@ -11,6 +11,8 @@#define CLK_XTAL 0#define MHZ (1000 * 1000) +#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)
drivers/clk/mediatek/clk-mtk.h struct mtk_clk_tree { · line 202
Quoted 4 lines
drivers/clk/mediatek/clk-mtk.h +1
-0@@ -197,6 +199,7 @@ struct mtk_clk_tree {const struct mtk_fixed_clk *fclks;const struct mtk_fixed_factor *fdivs;const struct mtk_composite *muxes; +u32 flags;
This needs a comment as to what the flags mean
Quoted 6 lines
drivers/clk/mediatek/clk-mtk.h +0
-1};struct mtk_clk_priv { --2.17.1
Regards,
Simon
Re: [PATCH 22/31] clk: mediatek: add CLK_BYPASS_XTAL flag to allow bypassing searching clock parent of xtal clock
Quoted 69 lines · Simon Glass
Hi Weijie,
Quoted 21 lines · Weijie Gao
The 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 forCLK_XTALin 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_ratebe
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 callmtk_topckgen_get_mux_rate.Quoted 5 lines
Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 5 ++++- drivers/clk/mediatek/clk-mtk.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>Quoted 36 lines
drivers/clk/mediatek/clk-mtk.c +0
-0@@ -314,12 +314,15 @@ static ulong mtk_topckgen_get_mux_rate(structclk
*clk, u32 off)struct mtk_clk_priv *priv = dev_get_priv(clk->dev); const struct mtk_composite *mux = &priv->tree->muxes[off]; u32 index;drivers/clk/mediatek/clk-mtk.c +2
-1+u32 flag =0 ; index =readl (priv->base + mux->mux_reg); index &= mux->mux_mask << mux->mux_shift; index = index >> mux->mux_shift; -if (mux->parent[index]) + if (mux->parent[index] == CLK_XTAL && priv->tree->flags &
CLK_BYPASS_XTAL)drivers/clk/mediatek/clk-mtk.c +2
-0+ flag =1 ; +if (mux->parent[index] >0 || flag ==1 ) return mtk_clk_find_parent_rate(clk, mux-Quoted 1 line
parent[index],
NULL);drivers/clk/mediatek/clk-mtk.h +0
-0@@ -11,6 +11,8 @@#define CLK_XTAL 0#define MHZ (1000 * 1000)
Quoted 12 lines
drivers/clk/mediatek/clk-mtk.h struct mtk_clk_tree { · line 202
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.h +3
-0+#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 +199,7 @@ struct mtk_clk_tree {const struct mtk_fixed_clk *fclks;const struct mtk_fixed_factor *fdivs;const struct mtk_composite *muxes; +u32 flags;This needs a comment as to what the flags mean
OK.
Quoted 10 lines
Quoted 7 lines
drivers/clk/mediatek/clk-mtk.h +0
-1};struct mtk_clk_priv { --2.17.1
Regards,
Simon
PATCH 23/31 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.
--- 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 +5 -11
@@ -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);
@@ -322,9 +316,18 @@ static ulong mtk_topckgen_get_mux_rate(struct clk *clk,
u32 off)
if (mux->parent[index] == CLK_XTAL && priv->tree->flags & CLK_BYPASS_XTAL)
flag = 1;
- if (mux->parent[index] > 0 || flag == 1)
- return mtk_clk_find_parent_rate(clk, mux->parent[index],
- NULL);
+ if (mux->parent[index] > 0 || flag == 1) {
+ 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;
}
@@ -343,7 +346,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;
@@ -376,7 +379,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;
@@ -402,7 +405,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);
@@ -474,19 +477,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 = {
@@ -497,10 +488,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 = {
@@ -513,11 +504,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;
@@ -528,11 +530,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
@@ -203,11 +203,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
Re: [PATCH 23/31] clk: mediatek: add support to configure clock driver parent
Quoted 10 lines · Weijie Gao
This patch adds support for a clock node to configure its parent clock where possible.
Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 79 ++++++++++++++++++++-------------- drivers/clk/mediatek/clk-mtk.h | 2 + 2 files changed, 48 insertions(+), 33 deletions(-)
Re: [PATCH 23/31] clk: mediatek: add support to configure clock driver parent
In reply to Weijie GaoQuoted 27 lines · Weijie Gao
This patch adds support for a clock node to configure its parent clock where possible.
Signed-off-by Weijie Gao <[email protected]>--- 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 +1
-6@@ -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 ;
drivers/clk/mediatek/clk-mtk.c line 54
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.c +3
-4- - parent.dev = dev; - }else { +if (pdev) + parent.dev = pdev; +else parent.dev = clk->dev; - }return clk_get_rate (&parent);
You must call clk_request(parent) before calling clk_get_rate.
Quoted 123 lines
drivers/clk/mediatek/clk-mtk.c +1
-1}@@ -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);drivers/clk/mediatek/clk-mtk.c +12
-3@@ -322,9 +316,18 @@ static ulong mtk_topckgen_get_mux_rate(struct clk *clk, u32 off)if (mux->parent[index] ==CLK_XTAL && priv->tree->flags &CLK_BYPASS_XTAL ) flag =1 ; -if (mux->parent[index] >0 || flag ==1 ) -return mtk_clk_find_parent_rate (clk, mux->parent[index], -NULL ); +if (mux->parent[index] >0 || flag ==1 ) { +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;}drivers/clk/mediatek/clk-mtk.c +18
-19@@ -343,7 +346,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;@@ -376,7 +379,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;@@ -402,7 +405,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);@@ -474,19 +477,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 = {@@ -497,10 +488,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 = {@@ -513,11 +504,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;
drivers/clk/mediatek/clk-mtk.c +0
-0@@ -528,11 +530,22 @@ int mtk_common_clk_gate_init(struct udevice *dev, const struct mtk_gate *gates) {
drivers/clk/mediatek/clk-mtk.c int mtk_common_clk_gate_init(struct udevice *dev, · line 541
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.c +3
-0struct 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);
Why not just use clk_get?
Quoted 20 lines
drivers/clk/mediatek/clk-mtk.c +8
-0+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 +0
-0@@ -203,11 +203,13 @@ struct mtk_clk_tree { };struct mtk_clk_priv {
drivers/clk/mediatek/clk-mtk.h struct mtk_clk_tree { · line 215
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.h +2
-0+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;
--Sean
Re: [PATCH 23/31] clk: mediatek: add support to configure clock driver parent
Quoted 41 lines · Sean Anderson
Quoted 40 lines · Weijie Gao
This patch adds support for a clock node to configure its parent clock
where possible.Signed-off-by Weijie Gao <[email protected]>--- 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 +4
-10@@ -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; - }
Quoted 3 lines
drivers/clk/mediatek/clk-mtk.c line 54
Quoted 1 line
drivers/clk/mediatek/clk-mtk.c +0
-0return clk_get_rate (&parent);You must call
clk_request(parent)before callingclk_get_rate.
Currently the mtk clock driver doest not really register all the clock devices. The ops->request is NULL.
The clk->id is only used by the specific soc clock driver (clk- mtxxxx.c) as a reference to the soc's clock list.
Once clk_get_rate is called, the driver will use clk->id to search the actual clock internally in the driver.
If a clock has its parent clock, the driver will fill up the parent clock's id and then call clk_get_rate again. Again clk_get_rate will go into the driver and do the same thing until a clock has no parent.
As you can see we only use the clk->id, not the clk udevice, there's no need to call clk_request. Only a few top-level clk udevices are registered as the entrace to this driver (topckgen/infrasys/...).
Quoted 154 lines
Quoted 154 lines
}drivers/clk/mediatek/clk-mtk.c +0
-0@@ -296,7 +290,7 @@ static ulongmtk_topckgen_get_factor_rate(struct clk
*clk, u32 off)
switch (fdiv->flags&CLK_PARENT_MASK) { caseCLK_PARENT_APMIXED:
rate = mtk_clk_find_parent_rate(clk, fdiv-Quoted 1 line
parent,
drivers/clk/mediatek/clk-mtk.c +0
-1- DM_DRIVER_GET(mtk_clk_apmixedsys));
drivers/clk/mediatek/clk-mtk.c +1
-0+ priv->parent);break ;case CLK_PARENT_TOPCKGEN : rate = mtk_clk_find_parent_rate(clk, fdiv-Quoted 1 line
parent, NULL);
drivers/clk/mediatek/clk-mtk.c +4
-3@@ -322,9 +316,18 @@ static ulong mtk_topckgen_get_mux_rate(structclk *clk, u32 off) if (mux->parent[index] == CLK_XTAL && priv->tree->flags &CLK_BYPASS_XTAL ) flag =1 ; -if (mux->parent[index] >0 || flag ==1 ) -return mtk_clk_find_parent_rate (clk, mux- >parent[index], -NULL ); +if (mux->parent[index] >0 || flag ==1 ) { +switch (mux->flags &CLK_PARENT_MASK ) { +case CLK_PARENT_APMIXED : + return mtk_clk_find_parent_rate(clk, mux-Quoted 1 line
parent[index],
drivers/clk/mediatek/clk-mtk.c +1
-0+ priv-Quoted 1 line
parent);
drivers/clk/mediatek/clk-mtk.c +3
-0+break ; +default : + return mtk_clk_find_parent_rate(clk, mux-Quoted 1 line
parent[index],
drivers/clk/mediatek/clk-mtk.c +5
-1+ NULL); +break ; + } + }return priv->tree->xtal_rate; }@@ -343,7 +346,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;drivers/clk/mediatek/clk-mtk.c +2
-2@@ -376,7 +379,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;@@ -402,7 +405,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);drivers/clk/mediatek/clk-mtk.c +1
-13@@ -474,19 +477,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 = {drivers/clk/mediatek/clk-mtk.c +3
-3@@ -497,10 +488,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 = {drivers/clk/mediatek/clk-mtk.c +11
-0@@ -513,11 +504,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;
drivers/clk/mediatek/clk-mtk.c +2
-0@@ -528,11 +530,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 ;
Quoted 5 lines
drivers/clk/mediatek/clk-mtk.c int mtk_common_clk_gate_init(struct udevice · line 543
Quoted 3 lines
drivers/clk/mediatek/clk-mtk.c +1
-0+ ret =uclass_get_device_by_phandle (UCLASS_CLK , dev,"clock-parent" , &parent);Why not just use
clk_get?
As I mentioned before, this driver does not register clk udevices, the clk_get_* won't work, and there's no real parent clocks. We have to parse the fdt to get the actual top-level clk udevice specified as the parent clock.
Quoted 35 lines
Quoted 23 lines
drivers/clk/mediatek/clk-mtk.c +3
-0+if (ret || !parent) { + ret = uclass_get_device_by_driver(UCLASS_CLK, + DM_DRIVER_GET(mtk_clk_topckgen),&parent);
drivers/clk/mediatek/clk-mtk.c +5
-0+if (ret || !parent) +return -ENOENT ; + } + + priv->parent = parent; priv->tree = tree; priv->gates = gates;drivers/clk/mediatek/clk-mtk.h +0
-0@@ -203,11 +203,13 @@ struct mtk_clk_tree { };struct mtk_clk_priv {drivers/clk/mediatek/clk-mtk.h struct mtk_clk_tree { · line 215
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.h +2
-0+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;--Sean
PATCH 24/31 clk: mediatek: add infrasys clock mux support
In reply to Weijie GaoThis patch adds infrasys clock mux support for mediatek clock drivers.
--- drivers/clk/mediatek/clk-mtk.c | 72 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 4 +- 2 files changed, 75 insertions(+), 1 deletion(-)
drivers/clk/mediatek/clk-mtk.c +18 -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);
@@ -332,6 +350,34 @@ 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;
+ u32 flag;
+
+ index = readl(priv->base + mux->mux_reg);
+ index &= mux->mux_mask << mux->mux_shift;
+ index = index >> mux->mux_shift;
+
+ if (mux->parent[index] == CLK_XTAL && priv->tree->flags & CLK_BYPASS_XTAL)
+ flag = 1;
+ if (mux->parent[index] > 0 || flag == 1) {
+ 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);
@@ -346,6 +392,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);
@@ -494,6 +559,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
@@ -25,7 +25,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
@@ -217,6 +218,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
Re: [PATCH 24/31] clk: mediatek: add infrasys clock mux support
Quoted 9 lines · Weijie Gao
This patch adds infrasys clock mux support for mediatek clock drivers.
Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 72 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 4 +- 2 files changed, 75 insertions(+), 1 deletion(-)
Re: [PATCH 24/31] clk: mediatek: add infrasys clock mux support
In reply to Weijie GaoQuoted 47 lines · Weijie Gao
This patch adds infrasys clock mux support for mediatek clock drivers.
Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 72 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 4 +- 2 files changed, 75 insertions(+), 1 deletion(-)drivers/clk/mediatek/clk-mtk.c +18
-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);drivers/clk/mediatek/clk-mtk.c +4
-0@@ -332,6 +350,34 @@ 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];
drivers/clk/mediatek/clk-mtk.c static ulong mtk_topckgen_get_mux_rate(struct clk *clk, · line 367
Quoted 10 lines
drivers/clk/mediatek/clk-mtk.c +10
-0+u32 index; +u32 flag; + + index =readl (priv->base + mux->mux_reg); + index &= mux->mux_mask << mux->mux_shift; + index = index >> mux->mux_shift; + +if (mux->parent[index] ==CLK_XTAL && priv->tree->flags &CLK_BYPASS_XTAL ) + flag =1 ; +if (mux->parent[index] >0 || flag ==1 ) {
Please just use the condition directly
Quoted 80 lines
drivers/clk/mediatek/clk-mtk.c +14
-0+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);drivers/clk/mediatek/clk-mtk.c +26
-0@@ -346,6 +392,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);@@ -494,6 +559,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@@ -25,7 +25,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@@ -217,6 +218,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,
Re: [PATCH 24/31] clk: mediatek: add infrasys clock mux support
Quoted 61 lines · Sean Anderson
Quoted 60 lines · Weijie Gao
This patch adds infrasys clock mux support for mediatek clock drivers.
Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 72 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 4 +- 2 files changed, 75 insertions(+), 1 deletion(-)drivers/clk/mediatek/clk-mtk.c +0
-0@@ -303,6 +303,24 @@ static ulongmtk_topckgen_get_factor_rate(struct clk
*clk, u32 off)
returnmtk_factor_recalc_rate(fdiv, rate);
}+static ulong
mtk_infrasys_get_factor_rate(struct clk *clk, u32 off)drivers/clk/mediatek/clk-mtk.c +3
-0+{ +struct mtk_clk_priv *priv =dev_get_priv (clk->dev); + const struct mtk_fixed_factor *fdiv = &priv->tree-Quoted 1 line
fdivs[off];
drivers/clk/mediatek/clk-mtk.c +9
-0+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);
drivers/clk/mediatek/clk-mtk.c +14
-0+ } + +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);@@ -332,6 +350,34 @@ 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; +u32 flag; + + index =readl (priv->base + mux->mux_reg); + index &= mux->mux_mask << mux->mux_shift;
Quoted 8 lines
drivers/clk/mediatek/clk-mtk.c static ulong mtk_topckgen_get_mux_rate(struct · line 369
Quoted 6 lines
drivers/clk/mediatek/clk-mtk.c +5
-0+ index = index >> mux->mux_shift; + +if (mux->parent[index] ==CLK_XTAL && priv->tree->flags &CLK_BYPASS_XTAL ) + flag =1 ; +if (mux->parent[index] >0 || flag ==1 ) {Please just use the condition directly
OK.
Quoted 91 lines
Quoted 89 lines
drivers/clk/mediatek/clk-mtk.c +3
-0+switch (mux->flags &CLK_PARENT_MASK ) { +case CLK_PARENT_TOPCKGEN : + return mtk_clk_find_parent_rate(clk, mux-Quoted 1 line
parent[index],
drivers/clk/mediatek/clk-mtk.c +1
-0+ priv-Quoted 1 line
parent);
drivers/clk/mediatek/clk-mtk.c +3
-0+break ; +default : + return mtk_clk_find_parent_rate(clk, mux-Quoted 1 line
parent[index],
drivers/clk/mediatek/clk-mtk.c +21
-0+ NULL); +break ; + } + } +return 0 ; +} +static ulong mtk_topckgen_get_rate (struct clk *clk) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);@@ -346,6 +392,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-Quoted 1 line
muxes_offs);drivers/clk/mediatek/clk-mtk.c +12
-0+ } + +return rate; +} +static int mtk_clk_mux_enable (struct clk *clk) {struct mtk_clk_priv *priv =dev_get_priv (clk->dev);@@ -494,6 +559,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@@ -25,7 +25,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@@ -217,6 +218,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,
PATCH 25/31 clk: mediatek: add CLK_XTAL support for clock driver
In reply to Weijie GaoThis add CLK_XTAL macro and flag to mediatek clock driver common part, to make thi SoC that has clock directlly connect to XTAL working.
--- drivers/clk/mediatek/clk-mtk.c | 3 +++ drivers/clk/mediatek/clk-mtk.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/clk/mediatek/clk-mtk.c +1 -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,8 @@ 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;
default:
rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL);
}
drivers/clk/mediatek/clk-mtk.h +2 -1
@@ -26,7 +26,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
Re: [PATCH 25/31] clk: mediatek: add CLK_XTAL support for clock driver
Hi Weijie,
Quoted 24 lines · Weijie Gao
This add
CLK_XTALmacro and flag to mediatek clock driver common part, to make thi SoC that has clock directlly connect to XTAL working.Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 3 +++ drivers/clk/mediatek/clk-mtk.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)drivers/clk/mediatek/clk-mtk.c +1
-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;}
drivers/clk/mediatek/clk-mtk.c static ulong mtk_infrasys_get_factor_rate(struct clk · line 320
Quoted 6 lines
drivers/clk/mediatek/clk-mtk.c +2
-0@@ -314,6 +315,8 @@ 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;
Please document the fall-through here, if it is not a bug.
Quoted 18 lines
drivers/clk/mediatek/clk-mtk.c +0
-0default : rate =mtk_clk_find_parent_rate (clk, fdiv->parent,NULL );}drivers/clk/mediatek/clk-mtk.h +2
-2@@ -26,7 +26,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 --
Quoted 2 lines
2.17.1
REgards,
Simon
Re: [PATCH 25/31] clk: mediatek: add CLK_XTAL support for clock driver
Quoted 27 lines · Simon Glass
Hi Weijie,
Quoted 23 lines · Weijie Gao
This add
CLK_XTALmacro and flag to mediatek clock driver common part,
to make thi SoC that has clock directlly connect to XTAL working.Signed-off-by Weijie Gao <[email protected]>--- drivers/clk/mediatek/clk-mtk.c | 3 +++ drivers/clk/mediatek/clk-mtk.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)drivers/clk/mediatek/clk-mtk.c +0
-0@@ -296,6 +296,7 @@ static ulongmtk_topckgen_get_factor_rate(struct clk
*clk, u32 off)rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL); break;
Quoted 14 lines
drivers/clk/mediatek/clk-mtk.c
Quoted 12 lines
drivers/clk/mediatek/clk-mtk.c +1
-0+case CLK_PARENT_XTAL :default : rate = priv->tree->xtal_rate; }@@ -314,6 +315,8 @@ static ulongmtk_infrasys_get_factor_rate(struct clk
*clk, u32 off)rate = mtk_clk_find_parent_rate(clk, fdiv->parent, priv->parent); break;drivers/clk/mediatek/clk-mtk.c +2
-0+case CLK_PARENT_XTAL : + rate = priv->tree->xtal_rate;Please document the fall-through here, if it is not a bug.
This is indeed a bug. I'll fix it.
Quoted 26 lines
Quoted 21 lines
default: rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL); }drivers/clk/mediatek/clk-mtk.h +2
-2@@ -26,7 +26,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 --Quoted 2 lines
2.17.1
REgards,
Simon