1 From 99342a0481d49b6e1ade90fdb02f597cb75f103f Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 2 Dec 2013 16:11:09 +0100
4 Subject: [PATCH 502/507] MIPS: ralink: add MT7621 support
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 arch/mips/include/asm/mach-ralink/mt7621.h | 39 +++++
9 arch/mips/ralink/Kconfig | 18 ++
10 arch/mips/ralink/Makefile | 7 +-
11 arch/mips/ralink/Platform | 5 +
12 arch/mips/ralink/irq-gic.c | 255 ++++++++++++++++++++++++++++
13 arch/mips/ralink/malta-amon.c | 81 +++++++++
14 arch/mips/ralink/mt7621.c | 186 ++++++++++++++++++++
15 7 files changed, 590 insertions(+), 1 deletion(-)
16 create mode 100644 arch/mips/include/asm/mach-ralink/mt7621.h
17 create mode 100644 arch/mips/ralink/irq-gic.c
18 create mode 100644 arch/mips/ralink/malta-amon.c
19 create mode 100644 arch/mips/ralink/mt7621.c
21 Index: linux-3.10.21/arch/mips/include/asm/mach-ralink/mt7621.h
22 ===================================================================
23 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
24 +++ linux-3.10.21/arch/mips/include/asm/mach-ralink/mt7621.h 2013-12-09 19:52:51.752677298 +0100
27 + * This program is free software; you can redistribute it and/or modify it
28 + * under the terms of the GNU General Public License version 2 as published
29 + * by the Free Software Foundation.
31 + * Parts of this file are based on Ralink's 2.6.21 BSP
33 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
34 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
35 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
38 +#ifndef _MT7621_REGS_H_
39 +#define _MT7621_REGS_H_
41 +#define MT7621_SYSC_BASE 0x1E000000
43 +#define SYSC_REG_CHIP_NAME0 0x00
44 +#define SYSC_REG_CHIP_NAME1 0x04
45 +#define SYSC_REG_CHIP_REV 0x0c
46 +#define SYSC_REG_SYSTEM_CONFIG0 0x10
47 +#define SYSC_REG_SYSTEM_CONFIG1 0x14
49 +#define CHIP_REV_PKG_MASK 0x1
50 +#define CHIP_REV_PKG_SHIFT 16
51 +#define CHIP_REV_VER_MASK 0xf
52 +#define CHIP_REV_VER_SHIFT 8
53 +#define CHIP_REV_ECO_MASK 0xf
55 +#define MT7621_DRAM_BASE 0x0
56 +#define MT7621_DDR2_SIZE_MIN 32
57 +#define MT7621_DDR2_SIZE_MAX 256
59 +#define MT7621_CHIP_NAME0 0x3637544D
60 +#define MT7621_CHIP_NAME1 0x20203132
62 +#define MIPS_GIC_IRQ_BASE (MIPS_CPU_IRQ_BASE + 8)
65 Index: linux-3.10.21/arch/mips/ralink/Kconfig
66 ===================================================================
67 --- linux-3.10.21.orig/arch/mips/ralink/Kconfig 2013-12-09 19:51:55.600675960 +0100
68 +++ linux-3.10.21/arch/mips/ralink/Kconfig 2013-12-09 19:52:51.756677296 +0100
75 + depends on !SOC_MT7621
78 bool "Systick Clockevent source"
79 depends on SOC_RT305X || SOC_MT7620
81 select USB_ARCH_HAS_EHCI
86 + select MIPS_CPU_SCACHE
87 + select SYS_SUPPORTS_MULTITHREADING
88 + select SYS_SUPPORTS_SMP
89 + select SYS_SUPPORTS_MIPS_CMP
97 bool "MT7620A eval kit"
100 + config DTB_MT7621_EVAL
101 + bool "MT7621 eval kit"
102 + depends on SOC_MT7621
107 Index: linux-3.10.21/arch/mips/ralink/Makefile
108 ===================================================================
109 --- linux-3.10.21.orig/arch/mips/ralink/Makefile 2013-12-09 19:51:55.600675960 +0100
110 +++ linux-3.10.21/arch/mips/ralink/Makefile 2013-12-09 19:52:51.756677296 +0100
112 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
113 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
115 -obj-y := prom.o of.o reset.o clk.o irq.o timer.o
116 +obj-y := prom.o of.o reset.o clk.o timer.o
118 +obj-$(CONFIG_IRQ_INTC) += irq.o
119 +obj-$(CONFIG_IRQ_GIC) += irq-gic.o
120 +obj-$(CONFIG_MIPS_MT_SMP) += malta-amon.o
122 obj-$(CONFIG_CLKEVT_RT3352) += cevt-rt3352.o
125 obj-$(CONFIG_SOC_RT305X) += rt305x.o
126 obj-$(CONFIG_SOC_RT3883) += rt3883.o
127 obj-$(CONFIG_SOC_MT7620) += mt7620.o
128 +obj-$(CONFIG_SOC_MT7621) += mt7621.o
130 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
132 Index: linux-3.10.21/arch/mips/ralink/Platform
133 ===================================================================
134 --- linux-3.10.21.orig/arch/mips/ralink/Platform 2013-12-09 19:51:55.000000000 +0100
135 +++ linux-3.10.21/arch/mips/ralink/Platform 2013-12-09 19:53:54.660678800 +0100
139 load-$(CONFIG_SOC_MT7620) += 0xffffffff80000000
140 +cflags-$(CONFIG_SOC_MT7620) += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt7620
145 +load-$(CONFIG_SOC_MT7621) += 0xffffffff80001000
146 +cflags-$(CONFIG_SOC_MT7620) += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt7621
147 Index: linux-3.10.21/arch/mips/ralink/irq-gic.c
148 ===================================================================
149 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
150 +++ linux-3.10.21/arch/mips/ralink/irq-gic.c 2013-12-09 19:52:51.756677296 +0100
152 +#include <linux/init.h>
153 +#include <linux/sched.h>
154 +#include <linux/slab.h>
155 +#include <linux/interrupt.h>
156 +#include <linux/kernel_stat.h>
157 +#include <linux/hardirq.h>
158 +#include <linux/preempt.h>
159 +#include <linux/irqdomain.h>
160 +#include <linux/of_platform.h>
161 +#include <linux/of_address.h>
162 +#include <linux/of_irq.h>
164 +#include <asm/irq_cpu.h>
165 +#include <asm/mipsregs.h>
167 +#include <asm/irq.h>
168 +#include <asm/setup.h>
170 +#include <asm/gic.h>
171 +#include <asm/gcmpregs.h>
173 +#include <asm/mach-ralink/mt7621.h>
175 +static unsigned long _gcmp_base;
176 +static int gic_resched_int_base = 56;
177 +static int gic_call_int_base = 60;
178 +static struct irq_chip *irq_gic;
180 +#define GIC_RESCHED_INT(cpu) (gic_resched_int_base+(cpu))
181 +#define GIC_CALL_INT(cpu) (gic_call_int_base+(cpu))
183 +static struct gic_intr_map gic_intr_map[GIC_NUM_INTRS] = {
184 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT }, //0
185 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
187 + { 0, GIC_CPU_INT3, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT }, //FE
188 + { 0, GIC_CPU_INT4, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT }, //PCIE0
190 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
191 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
192 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
193 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT }, //10
194 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
195 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
196 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
199 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
200 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
201 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
202 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
203 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT }, //20
204 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
205 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
207 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
208 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT }, //25
209 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
210 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
211 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
212 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
213 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },//30
214 + { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
217 +static struct gic_intr_map ipi_intr_map[8] = {
218 + { 0, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
219 + { 1, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
220 + { 2, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
221 + { 3, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
222 + { 0, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
223 + { 1, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
224 + { 2, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
225 + { 3, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, GIC_FLAG_IPI },
229 +ipi_resched_interrupt(int irq, void *dev_id)
233 + return IRQ_HANDLED;
237 +ipi_call_interrupt(int irq, void *dev_id)
239 + smp_call_function_interrupt();
241 + return IRQ_HANDLED;
244 +static struct irqaction irq_resched = {
245 + .handler = ipi_resched_interrupt,
246 + .flags = IRQF_DISABLED|IRQF_PERCPU,
247 + .name = "ipi resched"
250 +static struct irqaction irq_call = {
251 + .handler = ipi_call_interrupt,
252 + .flags = IRQF_DISABLED|IRQF_PERCPU,
257 +gic_irq_ack(struct irq_data *d)
259 + int irq = (d->irq - gic_irq_base);
261 + GIC_CLR_INTR_MASK(irq);
263 + if (gic_irq_flags[irq] & GIC_TRIG_EDGE)
264 + GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), irq);
268 +gic_finish_irq(struct irq_data *d)
270 + GIC_SET_INTR_MASK(d->irq - gic_irq_base);
274 +gic_platform_init(int irqs, struct irq_chip *irq_controller)
276 + irq_gic = irq_controller;
280 +vi_gic_irqdispatch(void)
282 + int irq = gic_get_int();
285 + do_IRQ(MIPS_GIC_IRQ_BASE + irq);
289 +vi_timer_irqdispatch(void)
291 + do_IRQ(cp0_compare_irq);
295 +plat_ipi_call_int_xlate(unsigned int cpu)
297 + return GIC_CALL_INT(cpu);
301 +plat_ipi_resched_int_xlate(unsigned int cpu)
303 + return GIC_RESCHED_INT(cpu);
307 +plat_irq_dispatch(void)
309 + unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
311 + if (pending & CAUSEF_IP7)
312 + do_IRQ(cp0_compare_irq);
313 + else if (pending & (CAUSEF_IP4 | CAUSEF_IP3))
314 + vi_gic_irqdispatch();
316 + spurious_interrupt();
319 +unsigned int __cpuinit
320 +get_c0_compare_int(void)
322 + return CP0_LEGACY_COMPARE_IRQ;
326 +gic_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
328 + irq_set_chip_and_handler(irq, irq_gic, handle_percpu_irq);
333 +static const struct irq_domain_ops irq_domain_ops = {
334 + .xlate = irq_domain_xlate_onecell,
339 +of_gic_init(struct device_node *node,
340 + struct device_node *parent)
342 + struct irq_domain *domain;
343 + struct resource gcmp = { 0 }, gic = { 0 };
344 + unsigned int gic_rev;
347 + if (of_address_to_resource(node, 0, &gic))
348 + panic("Failed to get gic memory range");
349 + if (request_mem_region(gic.start, resource_size(&gic),
351 + panic("Failed to request gic memory");
352 + if (of_address_to_resource(node, 2, &gcmp))
353 + panic("Failed to get gic memory range");
354 + if (request_mem_region(gcmp.start, resource_size(&gcmp),
356 + panic("Failed to request gcmp memory");
358 + _gcmp_base = (unsigned long) ioremap_nocache(gcmp.start, resource_size(&gcmp));
360 + panic("Failed to remap gcmp memory\n");
362 + if ((GCMPGCB(GCMPB) & GCMP_GCB_GCMPB_GCMPBASE_MSK) != gcmp.start)
363 + panic("Failed to find gcmp core\n");
365 + /* tell the gcmp where to find the gic */
366 + GCMPGCB(GICBA) = gic.start | GCMP_GCB_GICBA_EN_MSK;
368 + if (cpu_has_vint) {
369 + set_vi_handler(3, vi_gic_irqdispatch);
370 + set_vi_handler(4, vi_gic_irqdispatch);
371 + set_vi_handler(7, vi_timer_irqdispatch);
374 + memcpy(&gic_intr_map[gic_resched_int_base], ipi_intr_map, sizeof(ipi_intr_map));
375 + gic_init(gic.start, resource_size(&gic), gic_intr_map,
376 + ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE);
378 + GICREAD(GIC_REG(SHARED, GIC_SH_REVISIONID), gic_rev);
379 + pr_info("gic: revision %d.%d\n", (gic_rev >> 8) & 0xff, gic_rev & 0xff);
381 + domain = irq_domain_add_legacy(node, GIC_NUM_INTRS, MIPS_GIC_IRQ_BASE,
382 + 0, &irq_domain_ops, NULL);
384 + panic("Failed to add irqdomain");
386 + for (i = 0; i < NR_CPUS; i++) {
387 + setup_irq(MIPS_GIC_IRQ_BASE + GIC_RESCHED_INT(i), &irq_resched);
388 + setup_irq(MIPS_GIC_IRQ_BASE + GIC_CALL_INT(i), &irq_call);
391 + change_c0_status(ST0_IM, STATUSF_IP3 | STATUSF_IP4 | STATUSF_IP6 |
396 +static struct of_device_id __initdata of_irq_ids[] = {
397 + { .compatible = "mti,cpu-interrupt-controller", .data = mips_cpu_intc_init },
398 + { .compatible = "ralink,mt7621-gic", .data = of_gic_init },
405 + of_irq_init(of_irq_ids);
407 Index: linux-3.10.21/arch/mips/ralink/malta-amon.c
408 ===================================================================
409 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
410 +++ linux-3.10.21/arch/mips/ralink/malta-amon.c 2013-12-09 19:52:51.756677296 +0100
413 + * Copyright (C) 2007 MIPS Technologies, Inc.
414 + * All rights reserved.
416 + * This program is free software; you can distribute it and/or modify it
417 + * under the terms of the GNU General Public License (Version 2) as
418 + * published by the Free Software Foundation.
420 + * This program is distributed in the hope it will be useful, but WITHOUT
421 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
422 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
423 + * for more details.
425 + * You should have received a copy of the GNU General Public License along
426 + * with this program; if not, write to the Free Software Foundation, Inc.,
427 + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
429 + * Arbitrary Monitor interface
432 +#include <linux/kernel.h>
433 +#include <linux/init.h>
434 +#include <linux/smp.h>
436 +#include <asm/addrspace.h>
437 +#include <asm/mips-boards/launch.h>
438 +#include <asm/mipsmtregs.h>
440 +int amon_cpu_avail(int cpu)
442 + struct cpulaunch *launch = (struct cpulaunch *)CKSEG0ADDR(CPULAUNCH);
444 + if (cpu < 0 || cpu >= NCPULAUNCH) {
445 + pr_debug("avail: cpu%d is out of range\n", cpu);
450 + if (!(launch->flags & LAUNCH_FREADY)) {
451 + pr_debug("avail: cpu%d is not ready\n", cpu);
454 + if (launch->flags & (LAUNCH_FGO|LAUNCH_FGONE)) {
455 + pr_debug("avail: too late.. cpu%d is already gone\n", cpu);
462 +void amon_cpu_start(int cpu,
463 + unsigned long pc, unsigned long sp,
464 + unsigned long gp, unsigned long a0)
466 + volatile struct cpulaunch *launch =
467 + (struct cpulaunch *)CKSEG0ADDR(CPULAUNCH);
469 + if (!amon_cpu_avail(cpu))
471 + if (cpu == smp_processor_id()) {
472 + pr_debug("launch: I am cpu%d!\n", cpu);
477 + pr_debug("launch: starting cpu%d\n", cpu);
484 + smp_wmb(); /* Target must see parameters before go */
485 + launch->flags |= LAUNCH_FGO;
486 + smp_wmb(); /* Target must see go before we poll */
488 + while ((launch->flags & LAUNCH_FGONE) == 0)
490 + smp_rmb(); /* Target will be updating flags soon */
491 + pr_debug("launch: cpu%d gone!\n", cpu);
493 Index: linux-3.10.21/arch/mips/ralink/mt7621.c
494 ===================================================================
495 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
496 +++ linux-3.10.21/arch/mips/ralink/mt7621.c 2013-12-09 19:52:51.760677296 +0100
499 + * This program is free software; you can redistribute it and/or modify it
500 + * under the terms of the GNU General Public License version 2 as published
501 + * by the Free Software Foundation.
503 + * Parts of this file are based on Ralink's 2.6.21 BSP
505 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
506 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
507 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
510 +#include <linux/kernel.h>
511 +#include <linux/init.h>
512 +#include <linux/module.h>
513 +#include <asm/gcmpregs.h>
515 +#include <asm/mipsregs.h>
516 +#include <asm/mach-ralink/ralink_regs.h>
517 +#include <asm/mach-ralink/mt7621.h>
523 +#define SYSC_REG_SYSCFG 0x10
524 +#define SYSC_REG_CPLL_CLKCFG0 0x2c
525 +#define SYSC_REG_CUR_CLK_STS 0x44
526 +#define CPU_CLK_SEL (BIT(30) | BIT(31))
528 +#define MT7621_GPIO_MODE_UART1 1
529 +#define MT7621_GPIO_MODE_I2C 2
530 +#define MT7621_GPIO_MODE_UART2 3
531 +#define MT7621_GPIO_MODE_UART3 5
532 +#define MT7621_GPIO_MODE_JTAG 7
533 +#define MT7621_GPIO_MODE_WDT_MASK 0x3
534 +#define MT7621_GPIO_MODE_WDT_SHIFT 8
535 +#define MT7621_GPIO_MODE_WDT_GPIO 1
536 +#define MT7621_GPIO_MODE_PCIE_RST 0
537 +#define MT7621_GPIO_MODE_PCIE_REF 2
538 +#define MT7621_GPIO_MODE_PCIE_MASK 0x3
539 +#define MT7621_GPIO_MODE_PCIE_SHIFT 10
540 +#define MT7621_GPIO_MODE_PCIE_GPIO 1
541 +#define MT7621_GPIO_MODE_MDIO 12
542 +#define MT7621_GPIO_MODE_RGMII1 14
543 +#define MT7621_GPIO_MODE_RGMII2 15
544 +#define MT7621_GPIO_MODE_SPI_MASK 0x3
545 +#define MT7621_GPIO_MODE_SPI_SHIFT 16
546 +#define MT7621_GPIO_MODE_SPI_GPIO 1
547 +#define MT7621_GPIO_MODE_SDHCI_MASK 0x3
548 +#define MT7621_GPIO_MODE_SDHCI_SHIFT 18
549 +#define MT7621_GPIO_MODE_SDHCI_GPIO 1
551 +static struct rt2880_pmx_func uart1_grp[] = { FUNC("uart1", 0, 1, 2) };
552 +static struct rt2880_pmx_func i2c_grp[] = { FUNC("i2c", 0, 3, 2) };
553 +static struct rt2880_pmx_func uart3_grp[] = { FUNC("uart3", 0, 5, 4) };
554 +static struct rt2880_pmx_func uart2_grp[] = { FUNC("uart2", 0, 9, 4) };
555 +static struct rt2880_pmx_func jtag_grp[] = { FUNC("jtag", 0, 13, 5) };
556 +static struct rt2880_pmx_func wdt_grp[] = {
557 + FUNC("wdt rst", 0, 18, 1),
558 + FUNC("wdt refclk", 2, 18, 1),
560 +static struct rt2880_pmx_func pcie_rst_grp[] = {
561 + FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1),
562 + FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1)
564 +static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 20, 2) };
565 +static struct rt2880_pmx_func rgmii2_grp[] = { FUNC("rgmii2", 0, 22, 12) };
566 +static struct rt2880_pmx_func spi_grp[] = {
567 + FUNC("spi", 0, 34, 7),
568 + FUNC("nand", 2, 34, 8),
570 +static struct rt2880_pmx_func sdhci_grp[] = {
571 + FUNC("sdhci", 0, 41, 8),
572 + FUNC("nand", 2, 41, 8),
574 +static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 49, 12) };
576 +static struct rt2880_pmx_group mt7621_pinmux_data[] = {
577 + GRP("uart1", uart1_grp, 1, MT7621_GPIO_MODE_UART1),
578 + GRP("i2c", i2c_grp, 1, MT7621_GPIO_MODE_I2C),
579 + GRP("uart3", uart2_grp, 1, MT7621_GPIO_MODE_UART2),
580 + GRP("uart2", uart3_grp, 1, MT7621_GPIO_MODE_UART3),
581 + GRP("jtag", jtag_grp, 1, MT7621_GPIO_MODE_JTAG),
582 + GRP_G("wdt", wdt_grp, MT7621_GPIO_MODE_WDT_MASK,
583 + MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT),
584 + GRP_G("pcie", pcie_rst_grp, MT7621_GPIO_MODE_PCIE_MASK,
585 + MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT),
586 + GRP("mdio", mdio_grp, 1, MT7621_GPIO_MODE_MDIO),
587 + GRP("rgmii2", rgmii2_grp, 1, MT7621_GPIO_MODE_RGMII2),
588 + GRP_G("spi", spi_grp, MT7621_GPIO_MODE_SPI_MASK,
589 + MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT),
590 + GRP_G("sdhci", sdhci_grp, MT7621_GPIO_MODE_SDHCI_MASK,
591 + MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT),
592 + GRP("rgmii1", rgmii1_grp, 1, MT7621_GPIO_MODE_RGMII1),
596 +void __init ralink_clk_init(void)
601 + u32 clk_sts, syscfg;
602 + u8 clk_sel = 0, xtal_mode;
605 + if ((rt_sysc_r32(SYSC_REG_CPLL_CLKCFG0) & CPU_CLK_SEL) != 0)
610 + clk_sts = rt_sysc_r32(SYSC_REG_CUR_CLK_STS);
611 + cpu_fdiv = ((clk_sts >> 8) & 0x1F);
612 + cpu_ffrac = (clk_sts & 0x1F);
613 + cpu_clk = (500 * cpu_ffrac / cpu_fdiv) * 1000 * 1000;
614 + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
618 + fbdiv = ((rt_sysc_r32(0x648) >> 4) & 0x7F) + 1;
619 + syscfg = rt_sysc_r32(SYSC_REG_SYSCFG);
620 + xtal_mode = (syscfg >> 6) & 0x7;
621 + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
622 + if(xtal_mode >= 6) { //25Mhz Xtal
623 + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
624 + cpu_clk = 25 * fbdiv * 1000 * 1000;
625 + } else if(xtal_mode >=3) { //40Mhz Xtal
626 + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
627 + cpu_clk = 40 * fbdiv * 1000 * 1000;
628 + } else { // 20Mhz Xtal
629 + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
630 + cpu_clk = 20 * fbdiv * 1000 * 1000;
634 + cpu_clk = 880000000;
635 + ralink_clk_add("cpu", cpu_clk);
636 + ralink_clk_add("1e000b00.spi", 50000000);
637 + ralink_clk_add("1e000c00.uartlite", 50000000);
640 +void __init ralink_of_remap(void)
642 + rt_sysc_membase = plat_of_remap_node("mtk,mt7621-sysc");
643 + rt_memc_membase = plat_of_remap_node("mtk,mt7621-memc");
645 + if (!rt_sysc_membase || !rt_memc_membase)
646 + panic("Failed to remap core resources");
649 +void prom_soc_init(struct ralink_soc_info *soc_info)
651 + void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7621_SYSC_BASE);
652 + unsigned char *name = NULL;
657 + n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
658 + n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
660 + if (n0 == MT7621_CHIP_NAME0 && n1 == MT7621_CHIP_NAME1) {
662 + soc_info->compatible = "mtk,mt7621-soc";
664 + panic("mt7621: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
667 + rev = __raw_readl(sysc + SYSC_REG_CHIP_REV);
669 + snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
670 + "Mediatek %s ver:%u eco:%u",
672 + (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK,
673 + (rev & CHIP_REV_ECO_MASK));
675 + soc_info->mem_size_min = MT7621_DDR2_SIZE_MIN;
676 + soc_info->mem_size_max = MT7621_DDR2_SIZE_MAX;
677 + soc_info->mem_base = MT7621_DRAM_BASE;
679 + rt2880_pinmux_data = mt7621_pinmux_data;
681 + if (register_cmp_smp_ops())
682 + panic("failed to register_vsmp_smp_ops()");