0eebadb849d077284c649b7edf536b73ef5f3eef
[openwrt.git] / target / linux / ramips / patches-3.18 / 0012-MIPS-ralink-add-MT7621-support.patch
1 From c8c69923236f2f3f184ddcc7eb41c113b5cc3223 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 27 Jul 2014 10:57:40 +0100
4 Subject: [PATCH 12/57] MIPS: ralink: add MT7621 support
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
8  arch/mips/include/asm/gic.h                |    4 +
9  arch/mips/include/asm/mach-ralink/irq.h    |    9 +
10  arch/mips/include/asm/mach-ralink/mt7621.h |   39 ++++
11  arch/mips/kernel/vmlinux.lds.S             |    1 +
12  arch/mips/ralink/Kconfig                   |   18 ++
13  arch/mips/ralink/Makefile                  |    7 +-
14  arch/mips/ralink/Platform                  |    5 +
15  arch/mips/ralink/irq-gic.c                 |  271 ++++++++++++++++++++++++++++
16  arch/mips/ralink/malta-amon.c              |   81 +++++++++
17  arch/mips/ralink/mt7621.c                  |  183 +++++++++++++++++++
18  10 files changed, 617 insertions(+), 1 deletion(-)
19  create mode 100644 arch/mips/include/asm/mach-ralink/irq.h
20  create mode 100644 arch/mips/include/asm/mach-ralink/mt7621.h
21  create mode 100644 arch/mips/ralink/irq-gic.c
22  create mode 100644 arch/mips/ralink/malta-amon.c
23  create mode 100644 arch/mips/ralink/mt7621.c
24
25 --- /dev/null
26 +++ b/arch/mips/include/asm/mach-ralink/irq.h
27 @@ -0,0 +1,9 @@
28 +#ifndef __ASM_MACH_RALINK_IRQ_H
29 +#define __ASM_MACH_RALINK_IRQ_H
30 +
31 +#define GIC_NUM_INTRS  64
32 +#define NR_IRQS 256
33 +
34 +#include_next <irq.h>
35 +
36 +#endif
37 --- /dev/null
38 +++ b/arch/mips/include/asm/mach-ralink/mt7621.h
39 @@ -0,0 +1,39 @@
40 +/*
41 + * This program is free software; you can redistribute it and/or modify it
42 + * under the terms of the GNU General Public License version 2 as published
43 + * by the Free Software Foundation.
44 + *
45 + * Parts of this file are based on Ralink's 2.6.21 BSP
46 + *
47 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
48 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
49 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
50 + */
51 +
52 +#ifndef _MT7621_REGS_H_
53 +#define _MT7621_REGS_H_
54 +
55 +#define MT7621_SYSC_BASE               0x1E000000
56 +
57 +#define SYSC_REG_CHIP_NAME0            0x00
58 +#define SYSC_REG_CHIP_NAME1            0x04
59 +#define SYSC_REG_CHIP_REV              0x0c
60 +#define SYSC_REG_SYSTEM_CONFIG0                0x10
61 +#define SYSC_REG_SYSTEM_CONFIG1                0x14
62 +
63 +#define CHIP_REV_PKG_MASK              0x1
64 +#define CHIP_REV_PKG_SHIFT             16
65 +#define CHIP_REV_VER_MASK              0xf
66 +#define CHIP_REV_VER_SHIFT             8
67 +#define CHIP_REV_ECO_MASK              0xf
68 +
69 +#define MT7621_DRAM_BASE                0x0
70 +#define MT7621_DDR2_SIZE_MIN           32
71 +#define MT7621_DDR2_SIZE_MAX           256
72 +
73 +#define MT7621_CHIP_NAME0              0x3637544D
74 +#define MT7621_CHIP_NAME1              0x20203132
75 +
76 +#define MIPS_GIC_IRQ_BASE           (MIPS_CPU_IRQ_BASE + 8)
77 +
78 +#endif
79 --- a/arch/mips/kernel/vmlinux.lds.S
80 +++ b/arch/mips/kernel/vmlinux.lds.S
81 @@ -51,6 +51,7 @@
82         /* read-only */
83         _text = .;      /* Text and read-only data */
84         .text : {
85 +               /*. = . + 0x8000; */
86                 TEXT_TEXT
87                 SCHED_TEXT
88                 LOCK_TEXT
89 --- a/arch/mips/ralink/Kconfig
90 +++ b/arch/mips/ralink/Kconfig
91 @@ -7,6 +7,11 @@
92         select CLKSRC_OF
93         select CLKSRC_MMIO
94  
95 +config IRQ_INTC
96 +       bool
97 +       default y
98 +       depends on !SOC_MT7621
99 +
100  choice
101         prompt "Ralink SoC selection"
102         default SOC_RT305X
103 @@ -28,6 +33,15 @@
104         config SOC_MT7620
105                 bool "MT7620"
106  
107 +       config SOC_MT7621
108 +               bool "MT7621"
109 +               select MIPS_CPU_SCACHE
110 +               select SYS_SUPPORTS_MULTITHREADING
111 +               select SYS_SUPPORTS_SMP
112 +               select SYS_SUPPORTS_MIPS_CMP
113 +               select IRQ_GIC
114 +               select HW_HAS_PCI
115 +
116  endchoice
117  
118  choice
119 @@ -59,6 +73,10 @@
120                 depends on SOC_MT7620
121                 select BUILTIN_DTB
122  
123 +       config DTB_MT7621_EVAL
124 +               bool "MT7621 eval kit"
125 +               depends on SOC_MT7621
126 +
127  endchoice
128  
129  endif
130 --- a/arch/mips/ralink/Makefile
131 +++ b/arch/mips/ralink/Makefile
132 @@ -6,16 +6,21 @@
133  # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
134  # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
135  
136 -obj-y := prom.o of.o reset.o clk.o irq.o timer.o
137 +obj-y := prom.o of.o reset.o clk.o timer.o
138  
139  obj-$(CONFIG_CLKEVT_RT3352) += cevt-rt3352.o
140  
141  obj-$(CONFIG_RALINK_ILL_ACC) += ill_acc.o
142  
143 +obj-$(CONFIG_IRQ_INTC) += irq.o
144 +obj-$(CONFIG_IRQ_GIC) += irq-gic.o
145 +obj-$(CONFIG_MIPS_MT_SMP) += malta-amon.o
146 +
147  obj-$(CONFIG_SOC_RT288X) += rt288x.o
148  obj-$(CONFIG_SOC_RT305X) += rt305x.o
149  obj-$(CONFIG_SOC_RT3883) += rt3883.o
150  obj-$(CONFIG_SOC_MT7620) += mt7620.o
151 +obj-$(CONFIG_SOC_MT7621) += mt7621.o
152  
153  obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
154  
155 --- a/arch/mips/ralink/Platform
156 +++ b/arch/mips/ralink/Platform
157 @@ -27,3 +27,8 @@
158  #
159  load-$(CONFIG_SOC_MT7620)      += 0xffffffff80000000
160  cflags-$(CONFIG_SOC_MT7620)    += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt7620
161 +
162 +# Ralink MT7621
163 +#
164 +load-$(CONFIG_SOC_MT7621)      += 0xffffffff80001000
165 +cflags-$(CONFIG_SOC_MT7621)    += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt7621
166 --- /dev/null
167 +++ b/arch/mips/ralink/irq-gic.c
168 @@ -0,0 +1,268 @@
169 +#include <linux/init.h>
170 +#include <linux/sched.h>
171 +#include <linux/slab.h>
172 +#include <linux/interrupt.h>
173 +#include <linux/kernel_stat.h>
174 +#include <linux/hardirq.h>
175 +#include <linux/preempt.h>
176 +#include <linux/irqdomain.h>
177 +#include <linux/of_platform.h>
178 +#include <linux/of_address.h>
179 +#include <linux/of_irq.h>
180 +
181 +#include <asm/irq_cpu.h>
182 +#include <asm/mipsregs.h>
183 +
184 +#include <asm/irq.h>
185 +#include <asm/setup.h>
186 +
187 +#include <asm/gic.h>
188 +
189 +#include <asm/mach-ralink/mt7621.h>
190 +#define GIC_BASE_ADDR                  0x1fbc0000
191 +
192 +unsigned long _gcmp_base;
193 +static int gic_resched_int_base = 56;
194 +static int gic_call_int_base = 60;
195 +static struct irq_chip *irq_gic;
196 +static struct gic_intr_map gic_intr_map[GIC_NUM_INTRS];
197 +
198 +#if defined(CONFIG_MIPS_MT_SMP)
199 +static int gic_resched_int_base;
200 +static int gic_call_int_base;
201 +
202 +#define GIC_RESCHED_INT(cpu) (gic_resched_int_base+(cpu))
203 +#define GIC_CALL_INT(cpu) (gic_call_int_base+(cpu))
204 +
205 +static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
206 +{
207 +       scheduler_ipi();
208 +
209 +       return IRQ_HANDLED;
210 +}
211 +
212 +static irqreturn_t
213 +ipi_call_interrupt(int irq, void *dev_id)
214 +{
215 +       smp_call_function_interrupt();
216 +
217 +       return IRQ_HANDLED;
218 +}
219 +
220 +static struct irqaction irq_resched = {
221 +        .handler        = ipi_resched_interrupt,
222 +        .flags          = IRQF_DISABLED|IRQF_PERCPU,
223 +        .name           = "ipi resched"
224 +};
225 +
226 +static struct irqaction irq_call = {
227 +        .handler        = ipi_call_interrupt,
228 +        .flags          = IRQF_DISABLED|IRQF_PERCPU,
229 +        .name           = "ipi call"
230 +};
231 +
232 +#endif
233 +
234 +static void __init
235 +gic_fill_map(void)
236 +{
237 +       int i;
238 +
239 +       for (i = 0; i < ARRAY_SIZE(gic_intr_map); i++) {
240 +               gic_intr_map[i].cpunum = 0;
241 +               gic_intr_map[i].pin = GIC_CPU_INT0;
242 +               gic_intr_map[i].polarity = GIC_POL_POS;
243 +               gic_intr_map[i].trigtype = GIC_TRIG_LEVEL;
244 +               gic_intr_map[i].flags = 0;
245 +       }
246 +
247 +#if defined(CONFIG_MIPS_MT_SMP)
248 +       {
249 +               int cpu;
250 +
251 +               gic_call_int_base = ARRAY_SIZE(gic_intr_map) - nr_cpu_ids;
252 +               gic_resched_int_base = gic_call_int_base - nr_cpu_ids;
253 +
254 +               i = gic_resched_int_base;
255 +
256 +               for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
257 +                       gic_intr_map[i + cpu].cpunum = cpu;
258 +                       gic_intr_map[i + cpu].pin = GIC_CPU_INT1;
259 +                       gic_intr_map[i + cpu].trigtype = GIC_TRIG_EDGE;
260 +
261 +                       gic_intr_map[i + cpu + nr_cpu_ids].cpunum = cpu;
262 +                       gic_intr_map[i + cpu + nr_cpu_ids].pin = GIC_CPU_INT2;
263 +                       gic_intr_map[i + cpu + nr_cpu_ids].trigtype = GIC_TRIG_EDGE;
264 +               }
265 +       }
266 +#endif
267 +}
268 +
269 +void
270 +gic_irq_ack(struct irq_data *d)
271 +{
272 +       int irq = (d->irq - gic_irq_base);
273 +
274 +       GIC_CLR_INTR_MASK(irq);
275 +
276 +       if (gic_irq_flags[irq] & GIC_TRIG_EDGE)
277 +               GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), irq);
278 +}
279 +
280 +void
281 +gic_finish_irq(struct irq_data *d)
282 +{
283 +       GIC_SET_INTR_MASK(d->irq - gic_irq_base);
284 +}
285 +
286 +void __init
287 +gic_platform_init(int irqs, struct irq_chip *irq_controller)
288 +{
289 +       irq_gic = irq_controller;
290 +}
291 +
292 +static void
293 +gic_irqdispatch(void)
294 +{
295 +       unsigned int irq = gic_get_int();
296 +
297 +       if (likely(irq < GIC_NUM_INTRS))
298 +               do_IRQ(MIPS_GIC_IRQ_BASE + irq);
299 +       else {
300 +               pr_debug("Spurious GIC Interrupt!\n");
301 +               spurious_interrupt();
302 +       }
303 +
304 +}
305 +
306 +static void
307 +vi_timer_irqdispatch(void)
308 +{
309 +       do_IRQ(cp0_compare_irq);
310 +}
311 +
312 +#if defined(CONFIG_MIPS_MT_SMP)
313 +unsigned int
314 +plat_ipi_call_int_xlate(unsigned int cpu)
315 +{
316 +       return GIC_CALL_INT(cpu);
317 +}
318 +
319 +unsigned int
320 +plat_ipi_resched_int_xlate(unsigned int cpu)
321 +{
322 +       return GIC_RESCHED_INT(cpu);
323 +}
324 +#endif
325 +
326 +asmlinkage void
327 +plat_irq_dispatch(void)
328 +{
329 +       unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
330 +
331 +       if (unlikely(!pending)) {
332 +               pr_err("Spurious CP0 Interrupt!\n");
333 +               spurious_interrupt();
334 +       } else {
335 +               if (pending & CAUSEF_IP7)
336 +                       do_IRQ(cp0_compare_irq);
337 +
338 +               if (pending & (CAUSEF_IP4 | CAUSEF_IP3 | CAUSEF_IP2))
339 +                       gic_irqdispatch();
340 +       }
341 +}
342 +
343 +unsigned int __cpuinit
344 +get_c0_compare_int(void)
345 +{
346 +       return CP0_LEGACY_COMPARE_IRQ;
347 +}
348 +
349 +static int
350 +gic_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
351 +{
352 +       irq_set_chip_and_handler(irq, irq_gic,
353 +#if defined(CONFIG_MIPS_MT_SMP)
354 +               (hw >= gic_resched_int_base) ?
355 +                       handle_percpu_irq :
356 +#endif
357 +                       handle_level_irq);
358 +
359 +       return 0;
360 +}
361 +
362 +static const struct irq_domain_ops irq_domain_ops = {
363 +       .xlate = irq_domain_xlate_onecell,
364 +       .map = gic_map,
365 +};
366 +
367 +static int __init
368 +of_gic_init(struct device_node *node,
369 +                               struct device_node *parent)
370 +{
371 +       struct irq_domain *domain;
372 +       struct resource gcmp = { 0 }, gic = { 0 };
373 +       unsigned int gic_rev;
374 +       int i;
375 +
376 +       if (of_address_to_resource(node, 0, &gic))
377 +               panic("Failed to get gic memory range");
378 +       if (request_mem_region(gic.start, resource_size(&gic),
379 +                               gic.name) < 0)
380 +               panic("Failed to request gic memory");
381 +       if (of_address_to_resource(node, 2, &gcmp))
382 +               panic("Failed to get gic memory range");
383 +       if (request_mem_region(gcmp.start, resource_size(&gcmp),
384 +                               gcmp.name) < 0)
385 +               panic("Failed to request gcmp memory");
386 +
387 +       _gcmp_base = (unsigned long) ioremap_nocache(gcmp.start, resource_size(&gcmp));
388 +       if (!_gcmp_base)
389 +               panic("Failed to remap gcmp memory\n");
390 +
391 +       /* tell the gcmp where to find the gic */
392 +       write_gcr_gic_base(GIC_BASE_ADDR | CM_GCR_GIC_BASE_GICEN_MSK);
393 +       gic_present = 1;
394 +       if (cpu_has_vint) {
395 +               set_vi_handler(2, gic_irqdispatch);
396 +               set_vi_handler(3, gic_irqdispatch);
397 +               set_vi_handler(4, gic_irqdispatch);
398 +               set_vi_handler(7, vi_timer_irqdispatch);
399 +       }
400 +
401 +       gic_fill_map();
402 +
403 +       gic_init(gic.start, resource_size(&gic), gic_intr_map,
404 +               ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE);
405 +
406 +       GICREAD(GIC_REG(SHARED, GIC_SH_REVISIONID), gic_rev);
407 +       pr_info("gic: revision %d.%d\n", (gic_rev >> 8) & 0xff, gic_rev & 0xff);
408 +
409 +       domain = irq_domain_add_legacy(node, GIC_NUM_INTRS, MIPS_GIC_IRQ_BASE,
410 +                       0, &irq_domain_ops, NULL);
411 +       if (!domain)
412 +               panic("Failed to add irqdomain");
413 +
414 +#if defined(CONFIG_MIPS_MT_SMP)
415 +       for (i = 0; i < nr_cpu_ids; i++) {
416 +               setup_irq(MIPS_GIC_IRQ_BASE + GIC_RESCHED_INT(i), &irq_resched);
417 +               setup_irq(MIPS_GIC_IRQ_BASE + GIC_CALL_INT(i), &irq_call);
418 +       }
419 +#endif
420 +
421 +       change_c0_status(ST0_IM, STATUSF_IP7 | STATUSF_IP4 | STATUSF_IP3 |
422 +                               STATUSF_IP2);
423 +       return 0;
424 +}
425 +
426 +static struct of_device_id __initdata of_irq_ids[] = {
427 +       { .compatible = "mti,cpu-interrupt-controller", .data = mips_cpu_intc_init },
428 +       { .compatible = "ralink,mt7621-gic", .data = of_gic_init },
429 +       {},
430 +};
431 +
432 +void __init
433 +arch_init_irq(void)
434 +{
435 +       of_irq_init(of_irq_ids);
436 +}
437 --- /dev/null
438 +++ b/arch/mips/ralink/malta-amon.c
439 @@ -0,0 +1,81 @@
440 +/*
441 + * Copyright (C) 2007  MIPS Technologies, Inc.
442 + *     All rights reserved.
443 +
444 + *  This program is free software; you can distribute it and/or modify it
445 + *  under the terms of the GNU General Public License (Version 2) as
446 + *  published by the Free Software Foundation.
447 + *
448 + *  This program is distributed in the hope it will be useful, but WITHOUT
449 + *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
450 + *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
451 + *  for more details.
452 + *
453 + *  You should have received a copy of the GNU General Public License along
454 + *  with this program; if not, write to the Free Software Foundation, Inc.,
455 + *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
456 + *
457 + * Arbitrary Monitor interface
458 + */
459 +
460 +#include <linux/kernel.h>
461 +#include <linux/init.h>
462 +#include <linux/smp.h>
463 +
464 +#include <asm/addrspace.h>
465 +#include <asm/mips-boards/launch.h>
466 +#include <asm/mipsmtregs.h>
467 +
468 +int amon_cpu_avail(int cpu)
469 +{
470 +       struct cpulaunch *launch = (struct cpulaunch *)CKSEG0ADDR(CPULAUNCH);
471 +
472 +       if (cpu < 0 || cpu >= NCPULAUNCH) {
473 +               pr_debug("avail: cpu%d is out of range\n", cpu);
474 +               return 0;
475 +       }
476 +
477 +       launch += cpu;
478 +       if (!(launch->flags & LAUNCH_FREADY)) {
479 +               pr_debug("avail: cpu%d is not ready\n", cpu);
480 +               return 0;
481 +       }
482 +       if (launch->flags & (LAUNCH_FGO|LAUNCH_FGONE)) {
483 +               pr_debug("avail: too late.. cpu%d is already gone\n", cpu);
484 +               return 0;
485 +       }
486 +
487 +       return 1;
488 +}
489 +
490 +void amon_cpu_start(int cpu,
491 +                   unsigned long pc, unsigned long sp,
492 +                   unsigned long gp, unsigned long a0)
493 +{
494 +       volatile struct cpulaunch *launch =
495 +               (struct cpulaunch  *)CKSEG0ADDR(CPULAUNCH);
496 +
497 +       if (!amon_cpu_avail(cpu))
498 +               return;
499 +       if (cpu == smp_processor_id()) {
500 +               pr_debug("launch: I am cpu%d!\n", cpu);
501 +               return;
502 +       }
503 +       launch += cpu;
504 +
505 +       pr_debug("launch: starting cpu%d\n", cpu);
506 +
507 +       launch->pc = pc;
508 +       launch->gp = gp;
509 +       launch->sp = sp;
510 +       launch->a0 = a0;
511 +
512 +       smp_wmb();              /* Target must see parameters before go */
513 +       launch->flags |= LAUNCH_FGO;
514 +       smp_wmb();              /* Target must see go before we poll  */
515 +
516 +       while ((launch->flags & LAUNCH_FGONE) == 0)
517 +               ;
518 +       smp_rmb();      /* Target will be updating flags soon */
519 +       pr_debug("launch: cpu%d gone!\n", cpu);
520 +}
521 --- /dev/null
522 +++ b/arch/mips/ralink/mt7621.c
523 @@ -0,0 +1,192 @@
524 +/*
525 + * This program is free software; you can redistribute it and/or modify it
526 + * under the terms of the GNU General Public License version 2 as published
527 + * by the Free Software Foundation.
528 + *
529 + * Parts of this file are based on Ralink's 2.6.21 BSP
530 + *
531 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
532 + * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
533 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
534 + */
535 +
536 +#include <linux/kernel.h>
537 +#include <linux/init.h>
538 +#include <linux/module.h>
539 +
540 +#include <asm/mipsregs.h>
541 +#include <asm/smp-ops.h>
542 +#include <asm/mips-cm.h>
543 +#include <asm/mips-cpc.h>
544 +#include <asm/mach-ralink/ralink_regs.h>
545 +#include <asm/mach-ralink/mt7621.h>
546 +
547 +#include <pinmux.h>
548 +
549 +#include "common.h"
550 +
551 +#define SYSC_REG_SYSCFG                0x10
552 +#define SYSC_REG_CPLL_CLKCFG0  0x2c
553 +#define SYSC_REG_CUR_CLK_STS   0x44
554 +#define CPU_CLK_SEL            (BIT(30) | BIT(31))
555 +
556 +#define MT7621_GPIO_MODE_UART1         1
557 +#define MT7621_GPIO_MODE_I2C           2
558 +#define MT7621_GPIO_MODE_UART2         3
559 +#define MT7621_GPIO_MODE_UART3         5
560 +#define MT7621_GPIO_MODE_JTAG          7
561 +#define MT7621_GPIO_MODE_WDT_MASK      0x3
562 +#define MT7621_GPIO_MODE_WDT_SHIFT     8
563 +#define MT7621_GPIO_MODE_WDT_GPIO      1
564 +#define MT7621_GPIO_MODE_PCIE_RST      0
565 +#define MT7621_GPIO_MODE_PCIE_REF      2
566 +#define MT7621_GPIO_MODE_PCIE_MASK     0x3
567 +#define MT7621_GPIO_MODE_PCIE_SHIFT    10
568 +#define MT7621_GPIO_MODE_PCIE_GPIO     1
569 +#define MT7621_GPIO_MODE_MDIO          12
570 +#define MT7621_GPIO_MODE_RGMII1                14
571 +#define MT7621_GPIO_MODE_RGMII2                15
572 +#define MT7621_GPIO_MODE_SPI_MASK      0x3
573 +#define MT7621_GPIO_MODE_SPI_SHIFT     16
574 +#define MT7621_GPIO_MODE_SPI_GPIO      1
575 +#define MT7621_GPIO_MODE_SDHCI_MASK    0x3
576 +#define MT7621_GPIO_MODE_SDHCI_SHIFT   18
577 +#define MT7621_GPIO_MODE_SDHCI_GPIO    1
578 +
579 +static struct rt2880_pmx_func uart1_grp[] =  { FUNC("uart", 0, 1, 2) };
580 +static struct rt2880_pmx_func i2c_grp[] =  { FUNC("i2c", 0, 3, 2) };
581 +static struct rt2880_pmx_func uart3_grp[] = { FUNC("uart", 0, 5, 4) };
582 +static struct rt2880_pmx_func uart2_grp[] = { FUNC("uart", 0, 9, 4) };
583 +static struct rt2880_pmx_func jtag_grp[] = { FUNC("jtag", 0, 13, 5) };
584 +static struct rt2880_pmx_func wdt_grp[] = {
585 +       FUNC("wdt rst", 0, 18, 1),
586 +       FUNC("wdt refclk", 2, 18, 1),
587 +};
588 +static struct rt2880_pmx_func pcie_rst_grp[] = {
589 +       FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1),
590 +       FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1)
591 +};
592 +static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 20, 2) };
593 +static struct rt2880_pmx_func rgmii2_grp[] = { FUNC("rgmii", 0, 22, 12) };
594 +static struct rt2880_pmx_func spi_grp[] = {
595 +       FUNC("spi", 0, 34, 7),
596 +       FUNC("nand", 2, 34, 8),
597 +};
598 +static struct rt2880_pmx_func sdhci_grp[] = {
599 +       FUNC("sdhci", 0, 41, 8),
600 +       FUNC("nand", 2, 41, 8),
601 +};
602 +static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii", 0, 49, 12) };
603 +
604 +static struct rt2880_pmx_group mt7621_pinmux_data[] = {
605 +       GRP("uart1", uart1_grp, 1, MT7621_GPIO_MODE_UART1),
606 +       GRP("i2c", i2c_grp, 1, MT7621_GPIO_MODE_I2C),
607 +       GRP("uart3", uart2_grp, 1, MT7621_GPIO_MODE_UART2),
608 +       GRP("uart2", uart3_grp, 1, MT7621_GPIO_MODE_UART3),
609 +       GRP("jtag", jtag_grp, 1, MT7621_GPIO_MODE_JTAG),
610 +       GRP_G("wdt", wdt_grp, MT7621_GPIO_MODE_WDT_MASK,
611 +               MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT),
612 +       GRP_G("pcie", pcie_rst_grp, MT7621_GPIO_MODE_PCIE_MASK,
613 +               MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT),
614 +       GRP("mdio", mdio_grp, 1, MT7621_GPIO_MODE_MDIO),
615 +       GRP("rgmii2", rgmii2_grp, 1, MT7621_GPIO_MODE_RGMII2),
616 +       GRP_G("spi", spi_grp, MT7621_GPIO_MODE_SPI_MASK,
617 +               MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT),
618 +       GRP_G("sdhci", sdhci_grp, MT7621_GPIO_MODE_SDHCI_MASK,
619 +               MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT),
620 +       GRP("rgmii1", rgmii1_grp, 1, MT7621_GPIO_MODE_RGMII1),
621 +       { 0 }
622 +};
623 +
624 +void __init ralink_clk_init(void)
625 +{
626 +       int cpu_fdiv = 0;
627 +       int cpu_ffrac = 0;
628 +       int fbdiv = 0;
629 +       u32 clk_sts, syscfg;
630 +       u8 clk_sel = 0, xtal_mode;
631 +       u32 cpu_clk;
632 +
633 +       if ((rt_sysc_r32(SYSC_REG_CPLL_CLKCFG0) & CPU_CLK_SEL) != 0)
634 +               clk_sel = 1;
635 +
636 +       switch (clk_sel) {
637 +       case 0:
638 +               clk_sts = rt_sysc_r32(SYSC_REG_CUR_CLK_STS);
639 +               cpu_fdiv = ((clk_sts >> 8) & 0x1F);
640 +               cpu_ffrac = (clk_sts & 0x1F);
641 +               cpu_clk = (500 * cpu_ffrac / cpu_fdiv) * 1000 * 1000;
642 +               break;
643 +
644 +       case 1:
645 +               fbdiv = ((rt_sysc_r32(0x648) >> 4) & 0x7F) + 1;
646 +               syscfg = rt_sysc_r32(SYSC_REG_SYSCFG);
647 +               xtal_mode = (syscfg >> 6) & 0x7;
648 +               if(xtal_mode >= 6) { //25Mhz Xtal
649 +                       cpu_clk = 25 * fbdiv * 1000 * 1000;
650 +               } else if(xtal_mode >=3) { //40Mhz Xtal
651 +                       cpu_clk = 40 * fbdiv * 1000 * 1000;
652 +               } else { // 20Mhz Xtal
653 +                       cpu_clk = 20 * fbdiv * 1000 * 1000;
654 +               }
655 +               break;
656 +       }
657 +       cpu_clk = 880000000;
658 +       ralink_clk_add("cpu", cpu_clk);
659 +       ralink_clk_add("1e000b00.spi", 50000000);
660 +       ralink_clk_add("1e000c00.uartlite", 50000000);
661 +       ralink_clk_add("1e000d00.uart", 50000000);
662 +}
663 +
664 +void __init ralink_of_remap(void)
665 +{
666 +       rt_sysc_membase = plat_of_remap_node("mtk,mt7621-sysc");
667 +       rt_memc_membase = plat_of_remap_node("mtk,mt7621-memc");
668 +
669 +       if (!rt_sysc_membase || !rt_memc_membase)
670 +               panic("Failed to remap core resources");
671 +}
672 +
673 +void prom_soc_init(struct ralink_soc_info *soc_info)
674 +{
675 +       void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7621_SYSC_BASE);
676 +       unsigned char *name = NULL;
677 +       u32 n0;
678 +       u32 n1;
679 +       u32 rev;
680 +
681 +       n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
682 +       n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
683 +
684 +       if (n0 == MT7621_CHIP_NAME0 && n1 == MT7621_CHIP_NAME1) {
685 +               name = "MT7621";
686 +               soc_info->compatible = "mtk,mt7621-soc";
687 +       } else {
688 +               panic("mt7621: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
689 +       }
690 +
691 +       rev = __raw_readl(sysc + SYSC_REG_CHIP_REV);
692 +
693 +       snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
694 +               "Mediatek %s ver:%u eco:%u",
695 +               name,
696 +               (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK,
697 +               (rev & CHIP_REV_ECO_MASK));
698 +
699 +       soc_info->mem_size_min = MT7621_DDR2_SIZE_MIN;
700 +       soc_info->mem_size_max = MT7621_DDR2_SIZE_MAX;
701 +       soc_info->mem_base = MT7621_DRAM_BASE;
702 +
703 +       rt2880_pinmux_data = mt7621_pinmux_data;
704 +
705 +       /* Early detection of CMP support */
706 +       mips_cm_probe();
707 +       mips_cpc_probe();
708 +
709 +       if (!register_cps_smp_ops())
710 +               return;
711 +       if (!register_cmp_smp_ops())
712 +               return;
713 +       if (!register_vsmp_smp_ops())
714 +               return;
715 +}
716 --- a/arch/mips/kernel/mips-cm.c
717 +++ b/arch/mips/kernel/mips-cm.c
718 @@ -105,7 +105,7 @@
719         write_gcr_base(base_reg);
720  
721         /* disable CM regions */
722 -       write_gcr_reg0_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
723 +/*     write_gcr_reg0_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
724         write_gcr_reg0_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
725         write_gcr_reg1_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
726         write_gcr_reg1_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
727 @@ -113,7 +113,7 @@
728         write_gcr_reg2_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
729         write_gcr_reg3_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
730         write_gcr_reg3_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
731 -
732 +*/
733         /* probe for an L2-only sync region */
734         mips_cm_probe_l2sync();
735