Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: ralink: add MT7621 support

MT7621 is based on a 1004k core. This patch adds support for the SoC. The
timer and IRQ is just boiler plate as GIC has recently been moved to
generic places in the kernel and just works.

Signed-off-by: John Crispin <blogic@openwrt.org>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/11990/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

John Crispin and committed by
Ralf Baechle
1df7addb 2761f83c

+410 -1
+9
arch/mips/include/asm/mach-ralink/irq.h
··· 1 + #ifndef __ASM_MACH_RALINK_IRQ_H 2 + #define __ASM_MACH_RALINK_IRQ_H 3 + 4 + #define GIC_NUM_INTRS 64 5 + #define NR_IRQS 256 6 + 7 + #include_next <irq.h> 8 + 9 + #endif
+38
arch/mips/include/asm/mach-ralink/mt7621.h
··· 1 + /* 2 + * This program is free software; you can redistribute it and/or modify it 3 + * under the terms of the GNU General Public License version 2 as published 4 + * by the Free Software Foundation. 5 + * 6 + * Copyright (C) 2015 John Crispin <blogic@openwrt.org> 7 + */ 8 + 9 + #ifndef _MT7621_REGS_H_ 10 + #define _MT7621_REGS_H_ 11 + 12 + #define MT7621_PALMBUS_BASE 0x1C000000 13 + #define MT7621_PALMBUS_SIZE 0x03FFFFFF 14 + 15 + #define MT7621_SYSC_BASE 0x1E000000 16 + 17 + #define SYSC_REG_CHIP_NAME0 0x00 18 + #define SYSC_REG_CHIP_NAME1 0x04 19 + #define SYSC_REG_CHIP_REV 0x0c 20 + #define SYSC_REG_SYSTEM_CONFIG0 0x10 21 + #define SYSC_REG_SYSTEM_CONFIG1 0x14 22 + 23 + #define CHIP_REV_PKG_MASK 0x1 24 + #define CHIP_REV_PKG_SHIFT 16 25 + #define CHIP_REV_VER_MASK 0xf 26 + #define CHIP_REV_VER_SHIFT 8 27 + #define CHIP_REV_ECO_MASK 0xf 28 + 29 + #define MT7621_DRAM_BASE 0x0 30 + #define MT7621_DDR2_SIZE_MIN 32 31 + #define MT7621_DDR2_SIZE_MAX 256 32 + 33 + #define MT7621_CHIP_NAME0 0x3637544D 34 + #define MT7621_CHIP_NAME1 0x20203132 35 + 36 + #define MIPS_GIC_IRQ_BASE (MIPS_CPU_IRQ_BASE + 8) 37 + 38 + #endif
+65
arch/mips/include/asm/mach-ralink/mt7621/cpu-feature-overrides.h
··· 1 + /* 2 + * Ralink MT7621 specific CPU feature overrides 3 + * 4 + * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org> 5 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> 6 + * Copyright (C) 2015 Felix Fietkau <nbd@openwrt.org> 7 + * 8 + * This file was derived from: include/asm-mips/cpu-features.h 9 + * Copyright (C) 2003, 2004 Ralf Baechle 10 + * Copyright (C) 2004 Maciej W. Rozycki 11 + * 12 + * This program is free software; you can redistribute it and/or modify it 13 + * under the terms of the GNU General Public License version 2 as published 14 + * by the Free Software Foundation. 15 + * 16 + */ 17 + #ifndef _MT7621_CPU_FEATURE_OVERRIDES_H 18 + #define _MT7621_CPU_FEATURE_OVERRIDES_H 19 + 20 + #define cpu_has_tlb 1 21 + #define cpu_has_4kex 1 22 + #define cpu_has_3k_cache 0 23 + #define cpu_has_4k_cache 1 24 + #define cpu_has_tx39_cache 0 25 + #define cpu_has_sb1_cache 0 26 + #define cpu_has_fpu 0 27 + #define cpu_has_32fpr 0 28 + #define cpu_has_counter 1 29 + #define cpu_has_watch 1 30 + #define cpu_has_divec 1 31 + 32 + #define cpu_has_prefetch 1 33 + #define cpu_has_ejtag 1 34 + #define cpu_has_llsc 1 35 + 36 + #define cpu_has_mips16 1 37 + #define cpu_has_mdmx 0 38 + #define cpu_has_mips3d 0 39 + #define cpu_has_smartmips 0 40 + 41 + #define cpu_has_mips32r1 1 42 + #define cpu_has_mips32r2 1 43 + #define cpu_has_mips64r1 0 44 + #define cpu_has_mips64r2 0 45 + 46 + #define cpu_has_dsp 1 47 + #define cpu_has_dsp2 0 48 + #define cpu_has_mipsmt 1 49 + 50 + #define cpu_has_64bits 0 51 + #define cpu_has_64bit_zero_reg 0 52 + #define cpu_has_64bit_gp_regs 0 53 + #define cpu_has_64bit_addresses 0 54 + 55 + #define cpu_dcache_line_size() 32 56 + #define cpu_icache_line_size() 32 57 + 58 + #define cpu_has_dc_aliases 0 59 + #define cpu_has_vtag_icache 0 60 + 61 + #define cpu_has_rixi 0 62 + #define cpu_has_tlbinv 0 63 + #define cpu_has_userlocal 1 64 + 65 + #endif /* _MT7621_CPU_FEATURE_OVERRIDES_H */
+11
arch/mips/ralink/Kconfig
··· 15 15 config IRQ_INTC 16 16 bool 17 17 default y 18 + depends on !SOC_MT7621 18 19 19 20 choice 20 21 prompt "Ralink SoC selection" ··· 39 38 config SOC_MT7620 40 39 bool "MT7620/8" 41 40 41 + config SOC_MT7621 42 + bool "MT7621" 43 + select MIPS_CPU_SCACHE 44 + select SYS_SUPPORTS_MULTITHREADING 45 + select SYS_SUPPORTS_SMP 46 + select SYS_SUPPORTS_MIPS_CPS 47 + select MIPS_GIC 48 + select COMMON_CLK 49 + select CLKSRC_MIPS_GIC 50 + select HW_HAS_PCI 42 51 endchoice 43 52 44 53 choice
+7 -1
arch/mips/ralink/Makefile
··· 6 6 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org> 7 7 # Copyright (C) 2013 John Crispin <blogic@openwrt.org> 8 8 9 - obj-y := prom.o of.o reset.o clk.o irq.o timer.o 9 + obj-y := prom.o of.o reset.o 10 + 11 + ifndef CONFIG_MIPS_GIC 12 + obj-y += clk.o timer.o 13 + endif 10 14 11 15 obj-$(CONFIG_CLKEVT_RT3352) += cevt-rt3352.o 12 16 13 17 obj-$(CONFIG_RALINK_ILL_ACC) += ill_acc.o 14 18 15 19 obj-$(CONFIG_IRQ_INTC) += irq.o 20 + obj-$(CONFIG_MIPS_GIC) += irq-gic.o timer-gic.o 16 21 17 22 obj-$(CONFIG_SOC_RT288X) += rt288x.o 18 23 obj-$(CONFIG_SOC_RT305X) += rt305x.o 19 24 obj-$(CONFIG_SOC_RT3883) += rt3883.o 20 25 obj-$(CONFIG_SOC_MT7620) += mt7620.o 26 + obj-$(CONFIG_SOC_MT7621) += mt7621.o 21 27 22 28 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 23 29
+5
arch/mips/ralink/Platform
··· 27 27 # 28 28 load-$(CONFIG_SOC_MT7620) += 0xffffffff80000000 29 29 cflags-$(CONFIG_SOC_MT7620) += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt7620 30 + 31 + # Ralink MT7621 32 + # 33 + load-$(CONFIG_SOC_MT7621) += 0xffffffff80001000 34 + cflags-$(CONFIG_SOC_MT7621) += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt7621
+25
arch/mips/ralink/irq-gic.c
··· 1 + /* 2 + * This program is free software; you can redistribute it and/or modify it 3 + * under the terms of the GNU General Public License version 2 as published 4 + * by the Free Software Foundation. 5 + * 6 + * Copyright (C) 2015 Nikolay Martynov <mar.kolya@gmail.com> 7 + * Copyright (C) 2015 John Crispin <blogic@openwrt.org> 8 + */ 9 + 10 + #include <linux/init.h> 11 + 12 + #include <linux/of.h> 13 + #include <linux/irqchip.h> 14 + #include <linux/irqchip/mips-gic.h> 15 + 16 + int get_c0_perfcount_int(void) 17 + { 18 + return gic_get_c0_perfcount_int(); 19 + } 20 + EXPORT_SYMBOL_GPL(get_c0_perfcount_int); 21 + 22 + void __init arch_init_irq(void) 23 + { 24 + irqchip_init(); 25 + }
+226
arch/mips/ralink/mt7621.c
··· 1 + /* 2 + * This program is free software; you can redistribute it and/or modify it 3 + * under the terms of the GNU General Public License version 2 as published 4 + * by the Free Software Foundation. 5 + * 6 + * Copyright (C) 2015 Nikolay Martynov <mar.kolya@gmail.com> 7 + * Copyright (C) 2015 John Crispin <blogic@openwrt.org> 8 + */ 9 + 10 + #include <linux/kernel.h> 11 + #include <linux/init.h> 12 + #include <linux/module.h> 13 + 14 + #include <asm/mipsregs.h> 15 + #include <asm/smp-ops.h> 16 + #include <asm/mips-cm.h> 17 + #include <asm/mips-cpc.h> 18 + #include <asm/mach-ralink/ralink_regs.h> 19 + #include <asm/mach-ralink/mt7621.h> 20 + 21 + #include <pinmux.h> 22 + 23 + #include "common.h" 24 + 25 + #define SYSC_REG_SYSCFG 0x10 26 + #define SYSC_REG_CPLL_CLKCFG0 0x2c 27 + #define SYSC_REG_CUR_CLK_STS 0x44 28 + #define CPU_CLK_SEL (BIT(30) | BIT(31)) 29 + 30 + #define MT7621_GPIO_MODE_UART1 1 31 + #define MT7621_GPIO_MODE_I2C 2 32 + #define MT7621_GPIO_MODE_UART3_MASK 0x3 33 + #define MT7621_GPIO_MODE_UART3_SHIFT 3 34 + #define MT7621_GPIO_MODE_UART3_GPIO 1 35 + #define MT7621_GPIO_MODE_UART2_MASK 0x3 36 + #define MT7621_GPIO_MODE_UART2_SHIFT 5 37 + #define MT7621_GPIO_MODE_UART2_GPIO 1 38 + #define MT7621_GPIO_MODE_JTAG 7 39 + #define MT7621_GPIO_MODE_WDT_MASK 0x3 40 + #define MT7621_GPIO_MODE_WDT_SHIFT 8 41 + #define MT7621_GPIO_MODE_WDT_GPIO 1 42 + #define MT7621_GPIO_MODE_PCIE_RST 0 43 + #define MT7621_GPIO_MODE_PCIE_REF 2 44 + #define MT7621_GPIO_MODE_PCIE_MASK 0x3 45 + #define MT7621_GPIO_MODE_PCIE_SHIFT 10 46 + #define MT7621_GPIO_MODE_PCIE_GPIO 1 47 + #define MT7621_GPIO_MODE_MDIO_MASK 0x3 48 + #define MT7621_GPIO_MODE_MDIO_SHIFT 12 49 + #define MT7621_GPIO_MODE_MDIO_GPIO 1 50 + #define MT7621_GPIO_MODE_RGMII1 14 51 + #define MT7621_GPIO_MODE_RGMII2 15 52 + #define MT7621_GPIO_MODE_SPI_MASK 0x3 53 + #define MT7621_GPIO_MODE_SPI_SHIFT 16 54 + #define MT7621_GPIO_MODE_SPI_GPIO 1 55 + #define MT7621_GPIO_MODE_SDHCI_MASK 0x3 56 + #define MT7621_GPIO_MODE_SDHCI_SHIFT 18 57 + #define MT7621_GPIO_MODE_SDHCI_GPIO 1 58 + 59 + static struct rt2880_pmx_func uart1_grp[] = { FUNC("uart1", 0, 1, 2) }; 60 + static struct rt2880_pmx_func i2c_grp[] = { FUNC("i2c", 0, 3, 2) }; 61 + static struct rt2880_pmx_func uart3_grp[] = { 62 + FUNC("uart3", 0, 5, 4), 63 + FUNC("i2s", 2, 5, 4), 64 + FUNC("spdif3", 3, 5, 4), 65 + }; 66 + static struct rt2880_pmx_func uart2_grp[] = { 67 + FUNC("uart2", 0, 9, 4), 68 + FUNC("pcm", 2, 9, 4), 69 + FUNC("spdif2", 3, 9, 4), 70 + }; 71 + static struct rt2880_pmx_func jtag_grp[] = { FUNC("jtag", 0, 13, 5) }; 72 + static struct rt2880_pmx_func wdt_grp[] = { 73 + FUNC("wdt rst", 0, 18, 1), 74 + FUNC("wdt refclk", 2, 18, 1), 75 + }; 76 + static struct rt2880_pmx_func pcie_rst_grp[] = { 77 + FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1), 78 + FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1) 79 + }; 80 + static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 20, 2) }; 81 + static struct rt2880_pmx_func rgmii2_grp[] = { FUNC("rgmii2", 0, 22, 12) }; 82 + static struct rt2880_pmx_func spi_grp[] = { 83 + FUNC("spi", 0, 34, 7), 84 + FUNC("nand1", 2, 34, 7), 85 + }; 86 + static struct rt2880_pmx_func sdhci_grp[] = { 87 + FUNC("sdhci", 0, 41, 8), 88 + FUNC("nand2", 2, 41, 8), 89 + }; 90 + static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 49, 12) }; 91 + 92 + static struct rt2880_pmx_group mt7621_pinmux_data[] = { 93 + GRP("uart1", uart1_grp, 1, MT7621_GPIO_MODE_UART1), 94 + GRP("i2c", i2c_grp, 1, MT7621_GPIO_MODE_I2C), 95 + GRP_G("uart3", uart3_grp, MT7621_GPIO_MODE_UART3_MASK, 96 + MT7621_GPIO_MODE_UART3_GPIO, MT7621_GPIO_MODE_UART3_SHIFT), 97 + GRP_G("uart2", uart2_grp, MT7621_GPIO_MODE_UART2_MASK, 98 + MT7621_GPIO_MODE_UART2_GPIO, MT7621_GPIO_MODE_UART2_SHIFT), 99 + GRP("jtag", jtag_grp, 1, MT7621_GPIO_MODE_JTAG), 100 + GRP_G("wdt", wdt_grp, MT7621_GPIO_MODE_WDT_MASK, 101 + MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT), 102 + GRP_G("pcie", pcie_rst_grp, MT7621_GPIO_MODE_PCIE_MASK, 103 + MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT), 104 + GRP_G("mdio", mdio_grp, MT7621_GPIO_MODE_MDIO_MASK, 105 + MT7621_GPIO_MODE_MDIO_GPIO, MT7621_GPIO_MODE_MDIO_SHIFT), 106 + GRP("rgmii2", rgmii2_grp, 1, MT7621_GPIO_MODE_RGMII2), 107 + GRP_G("spi", spi_grp, MT7621_GPIO_MODE_SPI_MASK, 108 + MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT), 109 + GRP_G("sdhci", sdhci_grp, MT7621_GPIO_MODE_SDHCI_MASK, 110 + MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT), 111 + GRP("rgmii1", rgmii1_grp, 1, MT7621_GPIO_MODE_RGMII1), 112 + { 0 } 113 + }; 114 + 115 + phys_addr_t mips_cpc_default_phys_base(void) 116 + { 117 + panic("Cannot detect cpc address"); 118 + } 119 + 120 + void __init ralink_clk_init(void) 121 + { 122 + int cpu_fdiv = 0; 123 + int cpu_ffrac = 0; 124 + int fbdiv = 0; 125 + u32 clk_sts, syscfg; 126 + u8 clk_sel = 0, xtal_mode; 127 + u32 cpu_clk; 128 + 129 + if ((rt_sysc_r32(SYSC_REG_CPLL_CLKCFG0) & CPU_CLK_SEL) != 0) 130 + clk_sel = 1; 131 + 132 + switch (clk_sel) { 133 + case 0: 134 + clk_sts = rt_sysc_r32(SYSC_REG_CUR_CLK_STS); 135 + cpu_fdiv = ((clk_sts >> 8) & 0x1F); 136 + cpu_ffrac = (clk_sts & 0x1F); 137 + cpu_clk = (500 * cpu_ffrac / cpu_fdiv) * 1000 * 1000; 138 + break; 139 + 140 + case 1: 141 + fbdiv = ((rt_sysc_r32(0x648) >> 4) & 0x7F) + 1; 142 + syscfg = rt_sysc_r32(SYSC_REG_SYSCFG); 143 + xtal_mode = (syscfg >> 6) & 0x7; 144 + if (xtal_mode >= 6) { 145 + /* 25Mhz Xtal */ 146 + cpu_clk = 25 * fbdiv * 1000 * 1000; 147 + } else if (xtal_mode >= 3) { 148 + /* 40Mhz Xtal */ 149 + cpu_clk = 40 * fbdiv * 1000 * 1000; 150 + } else { 151 + /* 20Mhz Xtal */ 152 + cpu_clk = 20 * fbdiv * 1000 * 1000; 153 + } 154 + break; 155 + } 156 + } 157 + 158 + void __init ralink_of_remap(void) 159 + { 160 + rt_sysc_membase = plat_of_remap_node("mtk,mt7621-sysc"); 161 + rt_memc_membase = plat_of_remap_node("mtk,mt7621-memc"); 162 + 163 + if (!rt_sysc_membase || !rt_memc_membase) 164 + panic("Failed to remap core resources"); 165 + } 166 + 167 + void prom_soc_init(struct ralink_soc_info *soc_info) 168 + { 169 + void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7621_SYSC_BASE); 170 + unsigned char *name = NULL; 171 + u32 n0; 172 + u32 n1; 173 + u32 rev; 174 + 175 + n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0); 176 + n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1); 177 + 178 + if (n0 == MT7621_CHIP_NAME0 && n1 == MT7621_CHIP_NAME1) { 179 + name = "MT7621"; 180 + soc_info->compatible = "mtk,mt7621-soc"; 181 + } else { 182 + panic("mt7621: unknown SoC, n0:%08x n1:%08x\n", n0, n1); 183 + } 184 + 185 + rev = __raw_readl(sysc + SYSC_REG_CHIP_REV); 186 + 187 + snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN, 188 + "MediaTek %s ver:%u eco:%u", 189 + name, 190 + (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK, 191 + (rev & CHIP_REV_ECO_MASK)); 192 + 193 + soc_info->mem_size_min = MT7621_DDR2_SIZE_MIN; 194 + soc_info->mem_size_max = MT7621_DDR2_SIZE_MAX; 195 + soc_info->mem_base = MT7621_DRAM_BASE; 196 + 197 + rt2880_pinmux_data = mt7621_pinmux_data; 198 + 199 + /* Early detection of CMP support */ 200 + mips_cm_probe(); 201 + mips_cpc_probe(); 202 + 203 + if (mips_cm_numiocu()) { 204 + /* 205 + * mips_cm_probe() wipes out bootloader 206 + * config for CM regions and we have to configure them 207 + * again. This SoC cannot talk to pamlbus devices 208 + * witout proper iocu region set up. 209 + * 210 + * FIXME: it would be better to do this with values 211 + * from DT, but we need this very early because 212 + * without this we cannot talk to pretty much anything 213 + * including serial. 214 + */ 215 + write_gcr_reg0_base(MT7621_PALMBUS_BASE); 216 + write_gcr_reg0_mask(~MT7621_PALMBUS_SIZE | 217 + CM_GCR_REGn_MASK_CMTGT_IOCU0); 218 + } 219 + 220 + if (!register_cps_smp_ops()) 221 + return; 222 + if (!register_cmp_smp_ops()) 223 + return; 224 + if (!register_vsmp_smp_ops()) 225 + return; 226 + }
+24
arch/mips/ralink/timer-gic.c
··· 1 + /* 2 + * This program is free software; you can redistribute it and/or modify it 3 + * under the terms of the GNU General Public License version 2 as published 4 + * by the Free Software Foundation. 5 + * 6 + * Copyright (C) 2015 Nikolay Martynov <mar.kolya@gmail.com> 7 + * Copyright (C) 2015 John Crispin <blogic@openwrt.org> 8 + */ 9 + 10 + #include <linux/init.h> 11 + 12 + #include <linux/of.h> 13 + #include <linux/clk-provider.h> 14 + #include <linux/clocksource.h> 15 + 16 + #include "common.h" 17 + 18 + void __init plat_time_init(void) 19 + { 20 + ralink_of_remap(); 21 + 22 + of_clk_init(NULL); 23 + clocksource_probe(); 24 + }