cpu.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * linux/arch/arm/mach-w90x900/cpu.c
  3. *
  4. * Copyright (c) 2009 Nuvoton corporation.
  5. *
  6. * Wan ZongShun <mcuos.com@gmail.com>
  7. *
  8. * NUC900 series cpu common support
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation;version 2 of the License.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/list.h>
  19. #include <linux/timer.h>
  20. #include <linux/init.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/io.h>
  23. #include <linux/serial_8250.h>
  24. #include <linux/delay.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include <asm/mach/irq.h>
  28. #include <asm/irq.h>
  29. #include <asm/system_misc.h>
  30. #include <mach/hardware.h>
  31. #include <mach/regs-serial.h>
  32. #include <mach/regs-clock.h>
  33. #include "regs-ebi.h"
  34. #include "regs-timer.h"
  35. #include "cpu.h"
  36. #include "clock.h"
  37. #include "nuc9xx.h"
  38. /* Initial IO mappings */
  39. static struct map_desc nuc900_iodesc[] __initdata = {
  40. IODESC_ENT(IRQ),
  41. IODESC_ENT(GCR),
  42. IODESC_ENT(UART),
  43. IODESC_ENT(TIMER),
  44. IODESC_ENT(EBI),
  45. IODESC_ENT(GPIO),
  46. };
  47. /* Initial clock declarations. */
  48. static DEFINE_CLK(lcd, 0);
  49. static DEFINE_CLK(audio, 1);
  50. static DEFINE_CLK(fmi, 4);
  51. static DEFINE_SUBCLK(ms, 0);
  52. static DEFINE_SUBCLK(sd, 1);
  53. static DEFINE_CLK(dmac, 5);
  54. static DEFINE_CLK(atapi, 6);
  55. static DEFINE_CLK(emc, 7);
  56. static DEFINE_SUBCLK(rmii, 2);
  57. static DEFINE_CLK(usbd, 8);
  58. static DEFINE_CLK(usbh, 9);
  59. static DEFINE_CLK(g2d, 10);
  60. static DEFINE_CLK(pwm, 18);
  61. static DEFINE_CLK(ps2, 24);
  62. static DEFINE_CLK(kpi, 25);
  63. static DEFINE_CLK(wdt, 26);
  64. static DEFINE_CLK(gdma, 27);
  65. static DEFINE_CLK(adc, 28);
  66. static DEFINE_CLK(usi, 29);
  67. static DEFINE_CLK(ext, 0);
  68. static DEFINE_CLK(timer0, 19);
  69. static DEFINE_CLK(timer1, 20);
  70. static DEFINE_CLK(timer2, 21);
  71. static DEFINE_CLK(timer3, 22);
  72. static DEFINE_CLK(timer4, 23);
  73. static struct clk_lookup nuc900_clkregs[] = {
  74. DEF_CLKLOOK(&clk_lcd, "nuc900-lcd", NULL),
  75. DEF_CLKLOOK(&clk_audio, "nuc900-ac97", NULL),
  76. DEF_CLKLOOK(&clk_fmi, "nuc900-fmi", NULL),
  77. DEF_CLKLOOK(&clk_ms, "nuc900-fmi", "MS"),
  78. DEF_CLKLOOK(&clk_sd, "nuc900-fmi", "SD"),
  79. DEF_CLKLOOK(&clk_dmac, "nuc900-dmac", NULL),
  80. DEF_CLKLOOK(&clk_atapi, "nuc900-atapi", NULL),
  81. DEF_CLKLOOK(&clk_emc, "nuc900-emc", NULL),
  82. DEF_CLKLOOK(&clk_rmii, "nuc900-emc", "RMII"),
  83. DEF_CLKLOOK(&clk_usbd, "nuc900-usbd", NULL),
  84. DEF_CLKLOOK(&clk_usbh, "nuc900-usbh", NULL),
  85. DEF_CLKLOOK(&clk_g2d, "nuc900-g2d", NULL),
  86. DEF_CLKLOOK(&clk_pwm, "nuc900-pwm", NULL),
  87. DEF_CLKLOOK(&clk_ps2, "nuc900-ps2", NULL),
  88. DEF_CLKLOOK(&clk_kpi, "nuc900-kpi", NULL),
  89. DEF_CLKLOOK(&clk_wdt, "nuc900-wdt", NULL),
  90. DEF_CLKLOOK(&clk_gdma, "nuc900-gdma", NULL),
  91. DEF_CLKLOOK(&clk_adc, "nuc900-ts", NULL),
  92. DEF_CLKLOOK(&clk_usi, "nuc900-spi", NULL),
  93. DEF_CLKLOOK(&clk_ext, NULL, "ext"),
  94. DEF_CLKLOOK(&clk_timer0, NULL, "timer0"),
  95. DEF_CLKLOOK(&clk_timer1, NULL, "timer1"),
  96. DEF_CLKLOOK(&clk_timer2, NULL, "timer2"),
  97. DEF_CLKLOOK(&clk_timer3, NULL, "timer3"),
  98. DEF_CLKLOOK(&clk_timer4, NULL, "timer4"),
  99. };
  100. /* Initial serial platform data */
  101. struct plat_serial8250_port nuc900_uart_data[] = {
  102. NUC900_8250PORT(UART0),
  103. {},
  104. };
  105. struct platform_device nuc900_serial_device = {
  106. .name = "serial8250",
  107. .id = PLAT8250_DEV_PLATFORM,
  108. .dev = {
  109. .platform_data = nuc900_uart_data,
  110. },
  111. };
  112. /*Set NUC900 series cpu frequence*/
  113. static int __init nuc900_set_clkval(unsigned int cpufreq)
  114. {
  115. unsigned int pllclk, ahbclk, apbclk, val;
  116. pllclk = 0;
  117. ahbclk = 0;
  118. apbclk = 0;
  119. switch (cpufreq) {
  120. case 66:
  121. pllclk = PLL_66MHZ;
  122. ahbclk = AHB_CPUCLK_1_1;
  123. apbclk = APB_AHB_1_2;
  124. break;
  125. case 100:
  126. pllclk = PLL_100MHZ;
  127. ahbclk = AHB_CPUCLK_1_1;
  128. apbclk = APB_AHB_1_2;
  129. break;
  130. case 120:
  131. pllclk = PLL_120MHZ;
  132. ahbclk = AHB_CPUCLK_1_2;
  133. apbclk = APB_AHB_1_2;
  134. break;
  135. case 166:
  136. pllclk = PLL_166MHZ;
  137. ahbclk = AHB_CPUCLK_1_2;
  138. apbclk = APB_AHB_1_2;
  139. break;
  140. case 200:
  141. pllclk = PLL_200MHZ;
  142. ahbclk = AHB_CPUCLK_1_2;
  143. apbclk = APB_AHB_1_2;
  144. break;
  145. }
  146. __raw_writel(pllclk, REG_PLLCON0);
  147. val = __raw_readl(REG_CLKDIV);
  148. val &= ~(0x03 << 24 | 0x03 << 26);
  149. val |= (ahbclk << 24 | apbclk << 26);
  150. __raw_writel(val, REG_CLKDIV);
  151. return 0;
  152. }
  153. static int __init nuc900_set_cpufreq(char *str)
  154. {
  155. unsigned long cpufreq, val;
  156. if (!*str)
  157. return 0;
  158. if (kstrtoul(str, 0, &cpufreq))
  159. return 0;
  160. nuc900_clock_source(NULL, "ext");
  161. nuc900_set_clkval(cpufreq);
  162. mdelay(1);
  163. val = __raw_readl(REG_CKSKEW);
  164. val &= ~0xff;
  165. val |= DEFAULTSKEW;
  166. __raw_writel(val, REG_CKSKEW);
  167. nuc900_clock_source(NULL, "pll0");
  168. return 1;
  169. }
  170. __setup("cpufreq=", nuc900_set_cpufreq);
  171. /*Init NUC900 evb io*/
  172. void __init nuc900_map_io(struct map_desc *mach_desc, int mach_size)
  173. {
  174. unsigned long idcode = 0x0;
  175. iotable_init(mach_desc, mach_size);
  176. iotable_init(nuc900_iodesc, ARRAY_SIZE(nuc900_iodesc));
  177. idcode = __raw_readl(NUC900PDID);
  178. if (idcode == NUC910_CPUID)
  179. printk(KERN_INFO "CPU type 0x%08lx is NUC910\n", idcode);
  180. else if (idcode == NUC920_CPUID)
  181. printk(KERN_INFO "CPU type 0x%08lx is NUC920\n", idcode);
  182. else if (idcode == NUC950_CPUID)
  183. printk(KERN_INFO "CPU type 0x%08lx is NUC950\n", idcode);
  184. else if (idcode == NUC960_CPUID)
  185. printk(KERN_INFO "CPU type 0x%08lx is NUC960\n", idcode);
  186. }
  187. /*Init NUC900 clock*/
  188. void __init nuc900_init_clocks(void)
  189. {
  190. clkdev_add_table(nuc900_clkregs, ARRAY_SIZE(nuc900_clkregs));
  191. }
  192. #define WTCR (TMR_BA + 0x1C)
  193. #define WTCLK (1 << 10)
  194. #define WTE (1 << 7)
  195. #define WTRE (1 << 1)
  196. void nuc9xx_restart(enum reboot_mode mode, const char *cmd)
  197. {
  198. if (mode == REBOOT_SOFT) {
  199. /* Jump into ROM at address 0 */
  200. soft_restart(0);
  201. } else {
  202. __raw_writel(WTE | WTRE | WTCLK, WTCR);
  203. }
  204. }