cpu-8815.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * Copyright STMicroelectronics, 2007.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/types.h>
  19. #include <linux/init.h>
  20. #include <linux/device.h>
  21. #include <linux/amba/bus.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/io.h>
  24. #include <linux/slab.h>
  25. #include <linux/irq.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/irqchip.h>
  28. #include <linux/platform_data/clk-nomadik.h>
  29. #include <linux/platform_data/pinctrl-nomadik.h>
  30. #include <linux/pinctrl/machine.h>
  31. #include <linux/platform_data/clocksource-nomadik-mtu.h>
  32. #include <linux/of_irq.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_platform.h>
  35. #include <linux/mtd/fsmc.h>
  36. #include <mach/hardware.h>
  37. #include <mach/irqs.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/map.h>
  40. #include <asm/mach/time.h>
  41. #include <asm/mach-types.h>
  42. #include <asm/cacheflush.h>
  43. #include <asm/hardware/cache-l2x0.h>
  44. #include "cpu-8815.h"
  45. /* The 8815 has 4 GPIO blocks, let's register them immediately */
  46. static resource_size_t __initdata cpu8815_gpio_base[] = {
  47. NOMADIK_GPIO0_BASE,
  48. NOMADIK_GPIO1_BASE,
  49. NOMADIK_GPIO2_BASE,
  50. NOMADIK_GPIO3_BASE,
  51. };
  52. static struct platform_device *
  53. cpu8815_add_gpio(int id, resource_size_t addr, int irq,
  54. struct nmk_gpio_platform_data *pdata)
  55. {
  56. struct resource resources[] = {
  57. {
  58. .start = addr,
  59. .end = addr + 127,
  60. .flags = IORESOURCE_MEM,
  61. },
  62. {
  63. .start = irq,
  64. .end = irq,
  65. .flags = IORESOURCE_IRQ,
  66. }
  67. };
  68. return platform_device_register_resndata(NULL, "gpio", id,
  69. resources, ARRAY_SIZE(resources),
  70. pdata, sizeof(*pdata));
  71. }
  72. void cpu8815_add_gpios(resource_size_t *base, int num, int irq,
  73. struct nmk_gpio_platform_data *pdata)
  74. {
  75. int first = 0;
  76. int i;
  77. for (i = 0; i < num; i++, first += 32, irq++) {
  78. pdata->first_gpio = first;
  79. pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
  80. pdata->num_gpio = 32;
  81. cpu8815_add_gpio(i, base[i], irq, pdata);
  82. }
  83. }
  84. static unsigned long out_low[] = { PIN_OUTPUT_LOW };
  85. static unsigned long out_high[] = { PIN_OUTPUT_HIGH };
  86. static unsigned long in_nopull[] = { PIN_INPUT_NOPULL };
  87. static unsigned long in_pullup[] = { PIN_INPUT_PULLUP };
  88. static struct pinctrl_map __initdata nhk8815_pinmap[] = {
  89. PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"),
  90. PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"),
  91. /* Hog in MMC/SD card mux */
  92. PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"),
  93. /* MCCLK */
  94. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low),
  95. /* MCCMD */
  96. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup),
  97. /* MCCMDDIR */
  98. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high),
  99. /* MCDAT3-0 */
  100. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup),
  101. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup),
  102. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup),
  103. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup),
  104. /* MCDAT0DIR */
  105. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high),
  106. /* MCDAT31DIR */
  107. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high),
  108. /* MCMSFBCLK */
  109. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup),
  110. /* CD input GPIO */
  111. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull),
  112. /* CD bias drive */
  113. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low),
  114. /* I2C0 */
  115. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup),
  116. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup),
  117. /* I2C1 */
  118. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup),
  119. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup),
  120. /* I2C2 */
  121. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup),
  122. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup),
  123. };
  124. static inline void
  125. cpu8815_add_pinctrl(struct device *parent, const char *name)
  126. {
  127. struct platform_device_info pdevinfo = {
  128. .parent = parent,
  129. .name = name,
  130. .id = -1,
  131. };
  132. pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap));
  133. platform_device_register_full(&pdevinfo);
  134. }
  135. static int __init cpu8815_init(void)
  136. {
  137. struct nmk_gpio_platform_data pdata = {
  138. /* No custom data yet */
  139. };
  140. cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base),
  141. IRQ_GPIO0, &pdata);
  142. cpu8815_add_pinctrl(NULL, "pinctrl-stn8815");
  143. if (machine_is_nomadik()) {
  144. amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0);
  145. amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0);
  146. }
  147. return 0;
  148. }
  149. arch_initcall(cpu8815_init);
  150. /* All SoC devices live in the same area (see hardware.h) */
  151. static struct map_desc nomadik_io_desc[] __initdata = {
  152. {
  153. .virtual = NOMADIK_IO_VIRTUAL,
  154. .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL),
  155. .length = NOMADIK_IO_SIZE,
  156. .type = MT_DEVICE,
  157. }
  158. /* static ram and secured ram may be added later */
  159. };
  160. void __init cpu8815_map_io(void)
  161. {
  162. iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
  163. }
  164. void __init cpu8815_init_irq(void)
  165. {
  166. /* This modified VIC cell has two register blocks, at 0 and 0x20 */
  167. vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0);
  168. vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0);
  169. /*
  170. * Init clocks here so that they are available for system timer
  171. * initialization.
  172. */
  173. nomadik_clk_init();
  174. }
  175. /*
  176. * This function is called from the board init ("init_machine").
  177. */
  178. void __init cpu8815_platform_init(void)
  179. {
  180. #ifdef CONFIG_CACHE_L2X0
  181. /* At full speed latency must be >=2, so 0x249 in low bits */
  182. l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff);
  183. #endif
  184. return;
  185. }
  186. void cpu8815_restart(char mode, const char *cmd)
  187. {
  188. void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
  189. /* FIXME: use egpio when implemented */
  190. /* Write anything to Reset status register */
  191. writel(1, src_rstsr);
  192. }
  193. #ifdef CONFIG_OF
  194. /* Initial value for SRC control register: all timers use MXTAL/8 source */
  195. #define SRC_CR_INIT_MASK 0x00007fff
  196. #define SRC_CR_INIT_VAL 0x2aaa8000
  197. static void __init cpu8815_timer_init_of(void)
  198. {
  199. struct device_node *mtu;
  200. void __iomem *base;
  201. int irq;
  202. u32 src_cr;
  203. /* We need this to be up now */
  204. nomadik_clk_init();
  205. mtu = of_find_node_by_path("/mtu0");
  206. if (!mtu)
  207. return;
  208. base = of_iomap(mtu, 0);
  209. if (WARN_ON(!base))
  210. return;
  211. irq = irq_of_parse_and_map(mtu, 0);
  212. pr_info("Remapped MTU @ %p, irq: %d\n", base, irq);
  213. /* Configure timer sources in "system reset controller" ctrl reg */
  214. src_cr = readl(base);
  215. src_cr &= SRC_CR_INIT_MASK;
  216. src_cr |= SRC_CR_INIT_VAL;
  217. writel(src_cr, base);
  218. nmdk_timer_init(base, irq);
  219. }
  220. static struct fsmc_nand_timings cpu8815_nand_timings = {
  221. .thiz = 0,
  222. .thold = 0x10,
  223. .twait = 0x0A,
  224. .tset = 0,
  225. };
  226. static struct fsmc_nand_platform_data cpu8815_nand_data = {
  227. .nand_timings = &cpu8815_nand_timings,
  228. };
  229. /* These are mostly to get the right device names for the clock lookups */
  230. static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = {
  231. OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE,
  232. "uart0", NULL),
  233. OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE,
  234. "uart1", NULL),
  235. OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE,
  236. "rng", NULL),
  237. OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE,
  238. "rtc-pl031", NULL),
  239. OF_DEV_AUXDATA("stericsson,fsmc-nand", NOMADIK_FSMC_BASE,
  240. "fsmc-nand", &cpu8815_nand_data),
  241. { /* sentinel */ },
  242. };
  243. static void __init cpu8815_init_of(void)
  244. {
  245. #ifdef CONFIG_CACHE_L2X0
  246. /* At full speed latency must be >=2, so 0x249 in low bits */
  247. l2x0_of_init(0x00730249, 0xfe000fff);
  248. #endif
  249. of_platform_populate(NULL, of_default_bus_match_table,
  250. cpu8815_auxdata_lookup, NULL);
  251. }
  252. static const char * cpu8815_board_compat[] = {
  253. "calaosystems,usb-s8815",
  254. NULL,
  255. };
  256. DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815")
  257. .map_io = cpu8815_map_io,
  258. .init_irq = irqchip_init,
  259. .init_time = cpu8815_timer_init_of,
  260. .init_machine = cpu8815_init_of,
  261. .restart = cpu8815_restart,
  262. .dt_compat = cpu8815_board_compat,
  263. MACHINE_END
  264. #endif