0027-MIPS-ralink-adds-support-for-RT2880-SoC-family.patch 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. From 2a0d9878985bb3274bb61535f76ea293991635a9 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Sun, 27 Jan 2013 09:17:20 +0100
  4. Subject: [PATCH 27/79] MIPS: ralink: adds support for RT2880 SoC family
  5. Add support code for rt2880 SOC.
  6. The code detects the SoC and registers the clk / pinmux settings.
  7. Signed-off-by: John Crispin <[email protected]>
  8. Signed-off-by: Gabor Juhos <[email protected]>
  9. Patchwork: http://patchwork.linux-mips.org/patch/5176/
  10. ---
  11. arch/mips/Kconfig | 2 +-
  12. arch/mips/include/asm/mach-ralink/rt288x.h | 49 ++++++++++
  13. arch/mips/ralink/Kconfig | 3 +
  14. arch/mips/ralink/Makefile | 1 +
  15. arch/mips/ralink/Platform | 5 +
  16. arch/mips/ralink/rt288x.c | 139 ++++++++++++++++++++++++++++
  17. 6 files changed, 198 insertions(+), 1 deletion(-)
  18. create mode 100644 arch/mips/include/asm/mach-ralink/rt288x.h
  19. create mode 100644 arch/mips/ralink/rt288x.c
  20. diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
  21. index b5081b5..b5fd476 100644
  22. --- a/arch/mips/Kconfig
  23. +++ b/arch/mips/Kconfig
  24. @@ -1177,7 +1177,7 @@ config BOOT_ELF32
  25. config MIPS_L1_CACHE_SHIFT
  26. int
  27. - default "4" if MACH_DECSTATION || MIKROTIK_RB532 || PMC_MSP4200_EVAL
  28. + default "4" if MACH_DECSTATION || MIKROTIK_RB532 || PMC_MSP4200_EVAL || SOC_RT288X
  29. default "6" if MIPS_CPU_SCACHE
  30. default "7" if SGI_IP22 || SGI_IP27 || SGI_IP28 || SNI_RM || CPU_CAVIUM_OCTEON
  31. default "5"
  32. diff --git a/arch/mips/include/asm/mach-ralink/rt288x.h b/arch/mips/include/asm/mach-ralink/rt288x.h
  33. new file mode 100644
  34. index 0000000..ad8b42d
  35. --- /dev/null
  36. +++ b/arch/mips/include/asm/mach-ralink/rt288x.h
  37. @@ -0,0 +1,49 @@
  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 <[email protected]>
  46. + * Copyright (C) 2008 Imre Kaloz <[email protected]>
  47. + * Copyright (C) 2013 John Crispin <[email protected]>
  48. + */
  49. +
  50. +#ifndef _RT288X_REGS_H_
  51. +#define _RT288X_REGS_H_
  52. +
  53. +#define RT2880_SYSC_BASE 0x00300000
  54. +
  55. +#define SYSC_REG_CHIP_NAME0 0x00
  56. +#define SYSC_REG_CHIP_NAME1 0x04
  57. +#define SYSC_REG_CHIP_ID 0x0c
  58. +#define SYSC_REG_SYSTEM_CONFIG 0x10
  59. +#define SYSC_REG_CLKCFG 0x30
  60. +
  61. +#define RT2880_CHIP_NAME0 0x38325452
  62. +#define RT2880_CHIP_NAME1 0x20203038
  63. +
  64. +#define CHIP_ID_ID_MASK 0xff
  65. +#define CHIP_ID_ID_SHIFT 8
  66. +#define CHIP_ID_REV_MASK 0xff
  67. +
  68. +#define SYSTEM_CONFIG_CPUCLK_SHIFT 20
  69. +#define SYSTEM_CONFIG_CPUCLK_MASK 0x3
  70. +#define SYSTEM_CONFIG_CPUCLK_250 0x0
  71. +#define SYSTEM_CONFIG_CPUCLK_266 0x1
  72. +#define SYSTEM_CONFIG_CPUCLK_280 0x2
  73. +#define SYSTEM_CONFIG_CPUCLK_300 0x3
  74. +
  75. +#define RT2880_GPIO_MODE_I2C BIT(0)
  76. +#define RT2880_GPIO_MODE_UART0 BIT(1)
  77. +#define RT2880_GPIO_MODE_SPI BIT(2)
  78. +#define RT2880_GPIO_MODE_UART1 BIT(3)
  79. +#define RT2880_GPIO_MODE_JTAG BIT(4)
  80. +#define RT2880_GPIO_MODE_MDIO BIT(5)
  81. +#define RT2880_GPIO_MODE_SDRAM BIT(6)
  82. +#define RT2880_GPIO_MODE_PCI BIT(7)
  83. +
  84. +#define CLKCFG_SRAM_CS_N_WDT BIT(9)
  85. +
  86. +#endif
  87. diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
  88. index a0b0197..6723b94 100644
  89. --- a/arch/mips/ralink/Kconfig
  90. +++ b/arch/mips/ralink/Kconfig
  91. @@ -6,6 +6,9 @@ choice
  92. help
  93. Select Ralink MIPS SoC type.
  94. + config SOC_RT288X
  95. + bool "RT288x"
  96. +
  97. config SOC_RT305X
  98. bool "RT305x"
  99. select USB_ARCH_HAS_HCD
  100. diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
  101. index 939757f..6d826f2 100644
  102. --- a/arch/mips/ralink/Makefile
  103. +++ b/arch/mips/ralink/Makefile
  104. @@ -8,6 +8,7 @@
  105. obj-y := prom.o of.o reset.o clk.o irq.o
  106. +obj-$(CONFIG_SOC_RT288X) += rt288x.o
  107. obj-$(CONFIG_SOC_RT305X) += rt305x.o
  108. obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  109. diff --git a/arch/mips/ralink/Platform b/arch/mips/ralink/Platform
  110. index 6babd65..3f49e51 100644
  111. --- a/arch/mips/ralink/Platform
  112. +++ b/arch/mips/ralink/Platform
  113. @@ -5,6 +5,11 @@ core-$(CONFIG_RALINK) += arch/mips/ralink/
  114. cflags-$(CONFIG_RALINK) += -I$(srctree)/arch/mips/include/asm/mach-ralink
  115. #
  116. +# Ralink RT288x
  117. +#
  118. +load-$(CONFIG_SOC_RT288X) += 0xffffffff88000000
  119. +
  120. +#
  121. # Ralink RT305x
  122. #
  123. load-$(CONFIG_SOC_RT305X) += 0xffffffff80000000
  124. diff --git a/arch/mips/ralink/rt288x.c b/arch/mips/ralink/rt288x.c
  125. new file mode 100644
  126. index 0000000..1e0788e
  127. --- /dev/null
  128. +++ b/arch/mips/ralink/rt288x.c
  129. @@ -0,0 +1,139 @@
  130. +/*
  131. + * This program is free software; you can redistribute it and/or modify it
  132. + * under the terms of the GNU General Public License version 2 as published
  133. + * by the Free Software Foundation.
  134. + *
  135. + * Parts of this file are based on Ralink's 2.6.21 BSP
  136. + *
  137. + * Copyright (C) 2008-2011 Gabor Juhos <[email protected]>
  138. + * Copyright (C) 2008 Imre Kaloz <[email protected]>
  139. + * Copyright (C) 2013 John Crispin <[email protected]>
  140. + */
  141. +
  142. +#include <linux/kernel.h>
  143. +#include <linux/init.h>
  144. +#include <linux/module.h>
  145. +
  146. +#include <asm/mipsregs.h>
  147. +#include <asm/mach-ralink/ralink_regs.h>
  148. +#include <asm/mach-ralink/rt288x.h>
  149. +
  150. +#include "common.h"
  151. +
  152. +static struct ralink_pinmux_grp mode_mux[] = {
  153. + {
  154. + .name = "i2c",
  155. + .mask = RT2880_GPIO_MODE_I2C,
  156. + .gpio_first = 1,
  157. + .gpio_last = 2,
  158. + }, {
  159. + .name = "spi",
  160. + .mask = RT2880_GPIO_MODE_SPI,
  161. + .gpio_first = 3,
  162. + .gpio_last = 6,
  163. + }, {
  164. + .name = "uartlite",
  165. + .mask = RT2880_GPIO_MODE_UART0,
  166. + .gpio_first = 7,
  167. + .gpio_last = 14,
  168. + }, {
  169. + .name = "jtag",
  170. + .mask = RT2880_GPIO_MODE_JTAG,
  171. + .gpio_first = 17,
  172. + .gpio_last = 21,
  173. + }, {
  174. + .name = "mdio",
  175. + .mask = RT2880_GPIO_MODE_MDIO,
  176. + .gpio_first = 22,
  177. + .gpio_last = 23,
  178. + }, {
  179. + .name = "sdram",
  180. + .mask = RT2880_GPIO_MODE_SDRAM,
  181. + .gpio_first = 24,
  182. + .gpio_last = 39,
  183. + }, {
  184. + .name = "pci",
  185. + .mask = RT2880_GPIO_MODE_PCI,
  186. + .gpio_first = 40,
  187. + .gpio_last = 71,
  188. + }, {0}
  189. +};
  190. +
  191. +static void rt288x_wdt_reset(void)
  192. +{
  193. + u32 t;
  194. +
  195. + /* enable WDT reset output on pin SRAM_CS_N */
  196. + t = rt_sysc_r32(SYSC_REG_CLKCFG);
  197. + t |= CLKCFG_SRAM_CS_N_WDT;
  198. + rt_sysc_w32(t, SYSC_REG_CLKCFG);
  199. +}
  200. +
  201. +struct ralink_pinmux rt_gpio_pinmux = {
  202. + .mode = mode_mux,
  203. + .wdt_reset = rt288x_wdt_reset,
  204. +};
  205. +
  206. +void __init ralink_clk_init(void)
  207. +{
  208. + unsigned long cpu_rate;
  209. + u32 t = rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG);
  210. + t = ((t >> SYSTEM_CONFIG_CPUCLK_SHIFT) & SYSTEM_CONFIG_CPUCLK_MASK);
  211. +
  212. + switch (t) {
  213. + case SYSTEM_CONFIG_CPUCLK_250:
  214. + cpu_rate = 250000000;
  215. + break;
  216. + case SYSTEM_CONFIG_CPUCLK_266:
  217. + cpu_rate = 266666667;
  218. + break;
  219. + case SYSTEM_CONFIG_CPUCLK_280:
  220. + cpu_rate = 280000000;
  221. + break;
  222. + case SYSTEM_CONFIG_CPUCLK_300:
  223. + cpu_rate = 300000000;
  224. + break;
  225. + }
  226. +
  227. + ralink_clk_add("cpu", cpu_rate);
  228. + ralink_clk_add("300100.timer", cpu_rate / 2);
  229. + ralink_clk_add("300120.watchdog", cpu_rate / 2);
  230. + ralink_clk_add("300500.uart", cpu_rate / 2);
  231. + ralink_clk_add("300c00.uartlite", cpu_rate / 2);
  232. + ralink_clk_add("400000.ethernet", cpu_rate / 2);
  233. +}
  234. +
  235. +void __init ralink_of_remap(void)
  236. +{
  237. + rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc");
  238. + rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc");
  239. +
  240. + if (!rt_sysc_membase || !rt_memc_membase)
  241. + panic("Failed to remap core resources");
  242. +}
  243. +
  244. +void prom_soc_init(struct ralink_soc_info *soc_info)
  245. +{
  246. + void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT2880_SYSC_BASE);
  247. + const char *name;
  248. + u32 n0;
  249. + u32 n1;
  250. + u32 id;
  251. +
  252. + n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
  253. + n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
  254. + id = __raw_readl(sysc + SYSC_REG_CHIP_ID);
  255. +
  256. + if (n0 == RT2880_CHIP_NAME0 && n1 == RT2880_CHIP_NAME1) {
  257. + soc_info->compatible = "ralink,r2880-soc";
  258. + name = "RT2880";
  259. + } else {
  260. + panic("rt288x: unknown SoC, n0:%08x n1:%08x", n0, n1);
  261. + }
  262. +
  263. + snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
  264. + "Ralink %s id:%u rev:%u",
  265. + name,
  266. + (id >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK,
  267. + (id & CHIP_ID_REV_MASK));
  268. +}
  269. --
  270. 1.7.10.4