0012-MIPS-ralink-add-MT7621-support.patch 20 KB

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