0029-MIPS-ralink-adds-support-for-MT7620-SoC-family.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. From 41b7b06b494eef5a081363566314960306437d73 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Thu, 21 Mar 2013 17:49:02 +0100
  4. Subject: [PATCH 29/79] MIPS: ralink: adds support for MT7620 SoC family
  5. Add support code for mt7620 SOC.
  6. The code detects the SoC and registers the clk / pinmux settings.
  7. Signed-off-by: John Crispin <[email protected]>
  8. Acked-by: Gabor Juhos <[email protected]>
  9. Patchwork: http://patchwork.linux-mips.org/patch/5177/
  10. ---
  11. arch/mips/include/asm/mach-ralink/mt7620.h | 76 ++++++++++
  12. arch/mips/ralink/Kconfig | 3 +
  13. arch/mips/ralink/Makefile | 1 +
  14. arch/mips/ralink/Platform | 5 +
  15. arch/mips/ralink/mt7620.c | 214 ++++++++++++++++++++++++++++
  16. 5 files changed, 299 insertions(+)
  17. create mode 100644 arch/mips/include/asm/mach-ralink/mt7620.h
  18. create mode 100644 arch/mips/ralink/mt7620.c
  19. diff --git a/arch/mips/include/asm/mach-ralink/mt7620.h b/arch/mips/include/asm/mach-ralink/mt7620.h
  20. new file mode 100644
  21. index 0000000..b272649
  22. --- /dev/null
  23. +++ b/arch/mips/include/asm/mach-ralink/mt7620.h
  24. @@ -0,0 +1,76 @@
  25. +/*
  26. + * This program is free software; you can redistribute it and/or modify it
  27. + * under the terms of the GNU General Public License version 2 as published
  28. + * by the Free Software Foundation.
  29. + *
  30. + * Parts of this file are based on Ralink's 2.6.21 BSP
  31. + *
  32. + * Copyright (C) 2008-2011 Gabor Juhos <[email protected]>
  33. + * Copyright (C) 2008 Imre Kaloz <[email protected]>
  34. + * Copyright (C) 2013 John Crispin <[email protected]>
  35. + */
  36. +
  37. +#ifndef _MT7620_REGS_H_
  38. +#define _MT7620_REGS_H_
  39. +
  40. +#define MT7620_SYSC_BASE 0x10000000
  41. +
  42. +#define SYSC_REG_CHIP_NAME0 0x00
  43. +#define SYSC_REG_CHIP_NAME1 0x04
  44. +#define SYSC_REG_CHIP_REV 0x0c
  45. +#define SYSC_REG_SYSTEM_CONFIG0 0x10
  46. +#define SYSC_REG_SYSTEM_CONFIG1 0x14
  47. +#define SYSC_REG_CPLL_CONFIG0 0x54
  48. +#define SYSC_REG_CPLL_CONFIG1 0x58
  49. +
  50. +#define MT7620N_CHIP_NAME0 0x33365452
  51. +#define MT7620N_CHIP_NAME1 0x20203235
  52. +
  53. +#define MT7620A_CHIP_NAME0 0x3637544d
  54. +#define MT7620A_CHIP_NAME1 0x20203032
  55. +
  56. +#define CHIP_REV_PKG_MASK 0x1
  57. +#define CHIP_REV_PKG_SHIFT 16
  58. +#define CHIP_REV_VER_MASK 0xf
  59. +#define CHIP_REV_VER_SHIFT 8
  60. +#define CHIP_REV_ECO_MASK 0xf
  61. +
  62. +#define CPLL_SW_CONFIG_SHIFT 31
  63. +#define CPLL_SW_CONFIG_MASK 0x1
  64. +#define CPLL_CPU_CLK_SHIFT 24
  65. +#define CPLL_CPU_CLK_MASK 0x1
  66. +#define CPLL_MULT_RATIO_SHIFT 16
  67. +#define CPLL_MULT_RATIO 0x7
  68. +#define CPLL_DIV_RATIO_SHIFT 10
  69. +#define CPLL_DIV_RATIO 0x3
  70. +
  71. +#define SYSCFG0_DRAM_TYPE_MASK 0x3
  72. +#define SYSCFG0_DRAM_TYPE_SHIFT 4
  73. +#define SYSCFG0_DRAM_TYPE_SDRAM 0
  74. +#define SYSCFG0_DRAM_TYPE_DDR1 1
  75. +#define SYSCFG0_DRAM_TYPE_DDR2 2
  76. +
  77. +#define MT7620_GPIO_MODE_I2C BIT(0)
  78. +#define MT7620_GPIO_MODE_UART0_SHIFT 2
  79. +#define MT7620_GPIO_MODE_UART0_MASK 0x7
  80. +#define MT7620_GPIO_MODE_UART0(x) ((x) << MT7620_GPIO_MODE_UART0_SHIFT)
  81. +#define MT7620_GPIO_MODE_UARTF 0x0
  82. +#define MT7620_GPIO_MODE_PCM_UARTF 0x1
  83. +#define MT7620_GPIO_MODE_PCM_I2S 0x2
  84. +#define MT7620_GPIO_MODE_I2S_UARTF 0x3
  85. +#define MT7620_GPIO_MODE_PCM_GPIO 0x4
  86. +#define MT7620_GPIO_MODE_GPIO_UARTF 0x5
  87. +#define MT7620_GPIO_MODE_GPIO_I2S 0x6
  88. +#define MT7620_GPIO_MODE_GPIO 0x7
  89. +#define MT7620_GPIO_MODE_UART1 BIT(5)
  90. +#define MT7620_GPIO_MODE_MDIO BIT(8)
  91. +#define MT7620_GPIO_MODE_RGMII1 BIT(9)
  92. +#define MT7620_GPIO_MODE_RGMII2 BIT(10)
  93. +#define MT7620_GPIO_MODE_SPI BIT(11)
  94. +#define MT7620_GPIO_MODE_SPI_REF_CLK BIT(12)
  95. +#define MT7620_GPIO_MODE_WLED BIT(13)
  96. +#define MT7620_GPIO_MODE_JTAG BIT(15)
  97. +#define MT7620_GPIO_MODE_EPHY BIT(15)
  98. +#define MT7620_GPIO_MODE_WDT BIT(22)
  99. +
  100. +#endif
  101. diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
  102. index ce57d3e..86f6c77 100644
  103. --- a/arch/mips/ralink/Kconfig
  104. +++ b/arch/mips/ralink/Kconfig
  105. @@ -20,6 +20,9 @@ choice
  106. select USB_ARCH_HAS_OHCI
  107. select USB_ARCH_HAS_EHCI
  108. + config SOC_MT7620
  109. + bool "MT7620"
  110. +
  111. endchoice
  112. choice
  113. diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
  114. index ba9669c..38cf1a8 100644
  115. --- a/arch/mips/ralink/Makefile
  116. +++ b/arch/mips/ralink/Makefile
  117. @@ -11,6 +11,7 @@ obj-y := prom.o of.o reset.o clk.o irq.o
  118. obj-$(CONFIG_SOC_RT288X) += rt288x.o
  119. obj-$(CONFIG_SOC_RT305X) += rt305x.o
  120. obj-$(CONFIG_SOC_RT3883) += rt3883.o
  121. +obj-$(CONFIG_SOC_MT7620) += mt7620.o
  122. obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  123. diff --git a/arch/mips/ralink/Platform b/arch/mips/ralink/Platform
  124. index f67c08d..b2cbf16 100644
  125. --- a/arch/mips/ralink/Platform
  126. +++ b/arch/mips/ralink/Platform
  127. @@ -18,3 +18,8 @@ load-$(CONFIG_SOC_RT305X) += 0xffffffff80000000
  128. # Ralink RT3883
  129. #
  130. load-$(CONFIG_SOC_RT3883) += 0xffffffff80000000
  131. +
  132. +#
  133. +# Ralink MT7620
  134. +#
  135. +load-$(CONFIG_SOC_MT7620) += 0xffffffff80000000
  136. diff --git a/arch/mips/ralink/mt7620.c b/arch/mips/ralink/mt7620.c
  137. new file mode 100644
  138. index 0000000..eb00ab8
  139. --- /dev/null
  140. +++ b/arch/mips/ralink/mt7620.c
  141. @@ -0,0 +1,214 @@
  142. +/*
  143. + * This program is free software; you can redistribute it and/or modify it
  144. + * under the terms of the GNU General Public License version 2 as published
  145. + * by the Free Software Foundation.
  146. + *
  147. + * Parts of this file are based on Ralink's 2.6.21 BSP
  148. + *
  149. + * Copyright (C) 2008-2011 Gabor Juhos <[email protected]>
  150. + * Copyright (C) 2008 Imre Kaloz <[email protected]>
  151. + * Copyright (C) 2013 John Crispin <[email protected]>
  152. + */
  153. +
  154. +#include <linux/kernel.h>
  155. +#include <linux/init.h>
  156. +#include <linux/module.h>
  157. +
  158. +#include <asm/mipsregs.h>
  159. +#include <asm/mach-ralink/ralink_regs.h>
  160. +#include <asm/mach-ralink/mt7620.h>
  161. +
  162. +#include "common.h"
  163. +
  164. +/* does the board have sdram or ddram */
  165. +static int dram_type;
  166. +
  167. +/* the pll dividers */
  168. +static u32 mt7620_clk_divider[] = { 2, 3, 4, 8 };
  169. +
  170. +static struct ralink_pinmux_grp mode_mux[] = {
  171. + {
  172. + .name = "i2c",
  173. + .mask = MT7620_GPIO_MODE_I2C,
  174. + .gpio_first = 1,
  175. + .gpio_last = 2,
  176. + }, {
  177. + .name = "spi",
  178. + .mask = MT7620_GPIO_MODE_SPI,
  179. + .gpio_first = 3,
  180. + .gpio_last = 6,
  181. + }, {
  182. + .name = "uartlite",
  183. + .mask = MT7620_GPIO_MODE_UART1,
  184. + .gpio_first = 15,
  185. + .gpio_last = 16,
  186. + }, {
  187. + .name = "wdt",
  188. + .mask = MT7620_GPIO_MODE_WDT,
  189. + .gpio_first = 17,
  190. + .gpio_last = 17,
  191. + }, {
  192. + .name = "mdio",
  193. + .mask = MT7620_GPIO_MODE_MDIO,
  194. + .gpio_first = 22,
  195. + .gpio_last = 23,
  196. + }, {
  197. + .name = "rgmii1",
  198. + .mask = MT7620_GPIO_MODE_RGMII1,
  199. + .gpio_first = 24,
  200. + .gpio_last = 35,
  201. + }, {
  202. + .name = "spi refclk",
  203. + .mask = MT7620_GPIO_MODE_SPI_REF_CLK,
  204. + .gpio_first = 37,
  205. + .gpio_last = 39,
  206. + }, {
  207. + .name = "jtag",
  208. + .mask = MT7620_GPIO_MODE_JTAG,
  209. + .gpio_first = 40,
  210. + .gpio_last = 44,
  211. + }, {
  212. + /* shared lines with jtag */
  213. + .name = "ephy",
  214. + .mask = MT7620_GPIO_MODE_EPHY,
  215. + .gpio_first = 40,
  216. + .gpio_last = 44,
  217. + }, {
  218. + .name = "nand",
  219. + .mask = MT7620_GPIO_MODE_JTAG,
  220. + .gpio_first = 45,
  221. + .gpio_last = 59,
  222. + }, {
  223. + .name = "rgmii2",
  224. + .mask = MT7620_GPIO_MODE_RGMII2,
  225. + .gpio_first = 60,
  226. + .gpio_last = 71,
  227. + }, {
  228. + .name = "wled",
  229. + .mask = MT7620_GPIO_MODE_WLED,
  230. + .gpio_first = 72,
  231. + .gpio_last = 72,
  232. + }, {0}
  233. +};
  234. +
  235. +static struct ralink_pinmux_grp uart_mux[] = {
  236. + {
  237. + .name = "uartf",
  238. + .mask = MT7620_GPIO_MODE_UARTF,
  239. + .gpio_first = 7,
  240. + .gpio_last = 14,
  241. + }, {
  242. + .name = "pcm uartf",
  243. + .mask = MT7620_GPIO_MODE_PCM_UARTF,
  244. + .gpio_first = 7,
  245. + .gpio_last = 14,
  246. + }, {
  247. + .name = "pcm i2s",
  248. + .mask = MT7620_GPIO_MODE_PCM_I2S,
  249. + .gpio_first = 7,
  250. + .gpio_last = 14,
  251. + }, {
  252. + .name = "i2s uartf",
  253. + .mask = MT7620_GPIO_MODE_I2S_UARTF,
  254. + .gpio_first = 7,
  255. + .gpio_last = 14,
  256. + }, {
  257. + .name = "pcm gpio",
  258. + .mask = MT7620_GPIO_MODE_PCM_GPIO,
  259. + .gpio_first = 11,
  260. + .gpio_last = 14,
  261. + }, {
  262. + .name = "gpio uartf",
  263. + .mask = MT7620_GPIO_MODE_GPIO_UARTF,
  264. + .gpio_first = 7,
  265. + .gpio_last = 10,
  266. + }, {
  267. + .name = "gpio i2s",
  268. + .mask = MT7620_GPIO_MODE_GPIO_I2S,
  269. + .gpio_first = 7,
  270. + .gpio_last = 10,
  271. + }, {
  272. + .name = "gpio",
  273. + .mask = MT7620_GPIO_MODE_GPIO,
  274. + }, {0}
  275. +};
  276. +
  277. +struct ralink_pinmux rt_gpio_pinmux = {
  278. + .mode = mode_mux,
  279. + .uart = uart_mux,
  280. + .uart_shift = MT7620_GPIO_MODE_UART0_SHIFT,
  281. + .uart_mask = MT7620_GPIO_MODE_GPIO,
  282. +};
  283. +
  284. +void __init ralink_clk_init(void)
  285. +{
  286. + unsigned long cpu_rate, sys_rate;
  287. + u32 c0 = rt_sysc_r32(SYSC_REG_CPLL_CONFIG0);
  288. + u32 c1 = rt_sysc_r32(SYSC_REG_CPLL_CONFIG1);
  289. + u32 swconfig = (c0 >> CPLL_SW_CONFIG_SHIFT) & CPLL_SW_CONFIG_MASK;
  290. + u32 cpu_clk = (c1 >> CPLL_CPU_CLK_SHIFT) & CPLL_CPU_CLK_MASK;
  291. +
  292. + if (cpu_clk) {
  293. + cpu_rate = 480000000;
  294. + } else if (!swconfig) {
  295. + cpu_rate = 600000000;
  296. + } else {
  297. + u32 m = (c0 >> CPLL_MULT_RATIO_SHIFT) & CPLL_MULT_RATIO;
  298. + u32 d = (c0 >> CPLL_DIV_RATIO_SHIFT) & CPLL_DIV_RATIO;
  299. +
  300. + cpu_rate = ((40 * (m + 24)) / mt7620_clk_divider[d]) * 1000000;
  301. + }
  302. +
  303. + if (dram_type == SYSCFG0_DRAM_TYPE_SDRAM)
  304. + sys_rate = cpu_rate / 4;
  305. + else
  306. + sys_rate = cpu_rate / 3;
  307. +
  308. + ralink_clk_add("cpu", cpu_rate);
  309. + ralink_clk_add("10000100.timer", 40000000);
  310. + ralink_clk_add("10000500.uart", 40000000);
  311. + ralink_clk_add("10000c00.uartlite", 40000000);
  312. +}
  313. +
  314. +void __init ralink_of_remap(void)
  315. +{
  316. + rt_sysc_membase = plat_of_remap_node("ralink,mt7620a-sysc");
  317. + rt_memc_membase = plat_of_remap_node("ralink,mt7620a-memc");
  318. +
  319. + if (!rt_sysc_membase || !rt_memc_membase)
  320. + panic("Failed to remap core resources");
  321. +}
  322. +
  323. +void prom_soc_init(struct ralink_soc_info *soc_info)
  324. +{
  325. + void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7620_SYSC_BASE);
  326. + unsigned char *name = NULL;
  327. + u32 n0;
  328. + u32 n1;
  329. + u32 rev;
  330. + u32 cfg0;
  331. +
  332. + n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
  333. + n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
  334. +
  335. + if (n0 == MT7620N_CHIP_NAME0 && n1 == MT7620N_CHIP_NAME1) {
  336. + name = "MT7620N";
  337. + soc_info->compatible = "ralink,mt7620n-soc";
  338. + } else if (n0 == MT7620A_CHIP_NAME0 && n1 == MT7620A_CHIP_NAME1) {
  339. + name = "MT7620A";
  340. + soc_info->compatible = "ralink,mt7620a-soc";
  341. + } else {
  342. + panic("mt7620: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
  343. + }
  344. +
  345. + rev = __raw_readl(sysc + SYSC_REG_CHIP_REV);
  346. +
  347. + snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
  348. + "Ralink %s ver:%u eco:%u",
  349. + name,
  350. + (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK,
  351. + (rev & CHIP_REV_ECO_MASK));
  352. +
  353. + cfg0 = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG0);
  354. + dram_type = (cfg0 >> SYSCFG0_DRAM_TYPE_SHIFT) & SYSCFG0_DRAM_TYPE_MASK;
  355. +}
  356. --
  357. 1.7.10.4