common.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  2. * linux/arch/arm/plat-omap/common.c
  3. *
  4. * Code common to all OMAP machines.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/delay.h>
  14. #include <linux/pm.h>
  15. #include <linux/console.h>
  16. #include <linux/serial.h>
  17. #include <linux/tty.h>
  18. #include <linux/serial_8250.h>
  19. #include <linux/serial_reg.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include <mach/hardware.h>
  23. #include <asm/system.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/setup.h>
  27. #include <mach/common.h>
  28. #include <mach/board.h>
  29. #include <mach/control.h>
  30. #include <mach/mux.h>
  31. #include <mach/fpga.h>
  32. #include <mach/clock.h>
  33. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  34. # include "../mach-omap2/sdrc.h"
  35. #endif
  36. #define NO_LENGTH_CHECK 0xffffffff
  37. unsigned char omap_bootloader_tag[512];
  38. int omap_bootloader_tag_len;
  39. struct omap_board_config_kernel *omap_board_config;
  40. int omap_board_config_size;
  41. static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
  42. {
  43. struct omap_board_config_kernel *kinfo = NULL;
  44. int i;
  45. #ifdef CONFIG_OMAP_BOOT_TAG
  46. struct omap_board_config_entry *info = NULL;
  47. if (omap_bootloader_tag_len > 4)
  48. info = (struct omap_board_config_entry *) omap_bootloader_tag;
  49. while (info != NULL) {
  50. u8 *next;
  51. if (info->tag == tag) {
  52. if (skip == 0)
  53. break;
  54. skip--;
  55. }
  56. if ((info->len & 0x03) != 0) {
  57. /* We bail out to avoid an alignment fault */
  58. printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
  59. info->len, info->tag);
  60. return NULL;
  61. }
  62. next = (u8 *) info + sizeof(*info) + info->len;
  63. if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
  64. info = NULL;
  65. else
  66. info = (struct omap_board_config_entry *) next;
  67. }
  68. if (info != NULL) {
  69. /* Check the length as a lame attempt to check for
  70. * binary inconsistency. */
  71. if (len != NO_LENGTH_CHECK) {
  72. /* Word-align len */
  73. if (len & 0x03)
  74. len = (len + 3) & ~0x03;
  75. if (info->len != len) {
  76. printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
  77. tag, len, info->len);
  78. return NULL;
  79. }
  80. }
  81. if (len_out != NULL)
  82. *len_out = info->len;
  83. return info->data;
  84. }
  85. #endif
  86. /* Try to find the config from the board-specific structures
  87. * in the kernel. */
  88. for (i = 0; i < omap_board_config_size; i++) {
  89. if (omap_board_config[i].tag == tag) {
  90. if (skip == 0) {
  91. kinfo = &omap_board_config[i];
  92. break;
  93. } else {
  94. skip--;
  95. }
  96. }
  97. }
  98. if (kinfo == NULL)
  99. return NULL;
  100. return kinfo->data;
  101. }
  102. const void *__omap_get_config(u16 tag, size_t len, int nr)
  103. {
  104. return get_config(tag, len, nr, NULL);
  105. }
  106. EXPORT_SYMBOL(__omap_get_config);
  107. const void *omap_get_var_config(u16 tag, size_t *len)
  108. {
  109. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  110. }
  111. EXPORT_SYMBOL(omap_get_var_config);
  112. static int __init omap_add_serial_console(void)
  113. {
  114. const struct omap_serial_console_config *con_info;
  115. const struct omap_uart_config *uart_info;
  116. static char speed[11], *opt = NULL;
  117. int line, i, uart_idx;
  118. uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
  119. con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
  120. struct omap_serial_console_config);
  121. if (uart_info == NULL || con_info == NULL)
  122. return 0;
  123. if (con_info->console_uart == 0)
  124. return 0;
  125. if (con_info->console_speed) {
  126. snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
  127. opt = speed;
  128. }
  129. uart_idx = con_info->console_uart - 1;
  130. if (uart_idx >= OMAP_MAX_NR_PORTS) {
  131. printk(KERN_INFO "Console: external UART#%d. "
  132. "Not adding it as console this time.\n",
  133. uart_idx + 1);
  134. return 0;
  135. }
  136. if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
  137. printk(KERN_ERR "Console: Selected UART#%d is "
  138. "not enabled for this platform\n",
  139. uart_idx + 1);
  140. return -1;
  141. }
  142. line = 0;
  143. for (i = 0; i < uart_idx; i++) {
  144. if (uart_info->enabled_uarts & (1 << i))
  145. line++;
  146. }
  147. return add_preferred_console("ttyS", line, opt);
  148. }
  149. console_initcall(omap_add_serial_console);
  150. /*
  151. * 32KHz clocksource ... always available, on pretty most chips except
  152. * OMAP 730 and 1510. Other timers could be used as clocksources, with
  153. * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
  154. * but systems won't necessarily want to spend resources that way.
  155. */
  156. #define OMAP16XX_TIMER_32K_SYNCHRONIZED 0xfffbc410
  157. #if !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX))
  158. #include <linux/clocksource.h>
  159. #ifdef CONFIG_ARCH_OMAP16XX
  160. static cycle_t omap16xx_32k_read(struct clocksource *cs)
  161. {
  162. return omap_readl(OMAP16XX_TIMER_32K_SYNCHRONIZED);
  163. }
  164. #else
  165. #define omap16xx_32k_read NULL
  166. #endif
  167. #ifdef CONFIG_ARCH_OMAP2420
  168. static cycle_t omap2420_32k_read(struct clocksource *cs)
  169. {
  170. return omap_readl(OMAP2420_32KSYNCT_BASE + 0x10);
  171. }
  172. #else
  173. #define omap2420_32k_read NULL
  174. #endif
  175. #ifdef CONFIG_ARCH_OMAP2430
  176. static cycle_t omap2430_32k_read(struct clocksource *cs)
  177. {
  178. return omap_readl(OMAP2430_32KSYNCT_BASE + 0x10);
  179. }
  180. #else
  181. #define omap2430_32k_read NULL
  182. #endif
  183. #ifdef CONFIG_ARCH_OMAP34XX
  184. static cycle_t omap34xx_32k_read(struct clocksource *cs)
  185. {
  186. return omap_readl(OMAP3430_32KSYNCT_BASE + 0x10);
  187. }
  188. #else
  189. #define omap34xx_32k_read NULL
  190. #endif
  191. /*
  192. * Kernel assumes that sched_clock can be called early but may not have
  193. * things ready yet.
  194. */
  195. static cycle_t omap_32k_read_dummy(struct clocksource *cs)
  196. {
  197. return 0;
  198. }
  199. static struct clocksource clocksource_32k = {
  200. .name = "32k_counter",
  201. .rating = 250,
  202. .read = omap_32k_read_dummy,
  203. .mask = CLOCKSOURCE_MASK(32),
  204. .shift = 10,
  205. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  206. };
  207. /*
  208. * Returns current time from boot in nsecs. It's OK for this to wrap
  209. * around for now, as it's just a relative time stamp.
  210. */
  211. unsigned long long sched_clock(void)
  212. {
  213. unsigned long long ret;
  214. ret = (unsigned long long)clocksource_32k.read(&clocksource_32k);
  215. ret = (ret * clocksource_32k.mult_orig) >> clocksource_32k.shift;
  216. return ret;
  217. }
  218. static int __init omap_init_clocksource_32k(void)
  219. {
  220. static char err[] __initdata = KERN_ERR
  221. "%s: can't register clocksource!\n";
  222. if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
  223. struct clk *sync_32k_ick;
  224. if (cpu_is_omap16xx())
  225. clocksource_32k.read = omap16xx_32k_read;
  226. else if (cpu_is_omap2420())
  227. clocksource_32k.read = omap2420_32k_read;
  228. else if (cpu_is_omap2430())
  229. clocksource_32k.read = omap2430_32k_read;
  230. else if (cpu_is_omap34xx())
  231. clocksource_32k.read = omap34xx_32k_read;
  232. else
  233. return -ENODEV;
  234. sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
  235. if (sync_32k_ick)
  236. clk_enable(sync_32k_ick);
  237. clocksource_32k.mult = clocksource_hz2mult(32768,
  238. clocksource_32k.shift);
  239. if (clocksource_register(&clocksource_32k))
  240. printk(err, clocksource_32k.name);
  241. }
  242. return 0;
  243. }
  244. arch_initcall(omap_init_clocksource_32k);
  245. #endif /* !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX)) */
  246. /* Global address base setup code */
  247. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  248. static void __init __omap2_set_globals(struct omap_globals *omap2_globals)
  249. {
  250. omap2_set_globals_tap(omap2_globals);
  251. omap2_set_globals_sdrc(omap2_globals);
  252. omap2_set_globals_control(omap2_globals);
  253. omap2_set_globals_prcm(omap2_globals);
  254. }
  255. #endif
  256. #if defined(CONFIG_ARCH_OMAP2420)
  257. static struct omap_globals omap242x_globals = {
  258. .class = OMAP242X_CLASS,
  259. .tap = OMAP2_IO_ADDRESS(0x48014000),
  260. .sdrc = OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
  261. .sms = OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
  262. .ctrl = OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
  263. .prm = OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
  264. .cm = OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
  265. };
  266. void __init omap2_set_globals_242x(void)
  267. {
  268. __omap2_set_globals(&omap242x_globals);
  269. }
  270. #endif
  271. #if defined(CONFIG_ARCH_OMAP2430)
  272. static struct omap_globals omap243x_globals = {
  273. .class = OMAP243X_CLASS,
  274. .tap = OMAP2_IO_ADDRESS(0x4900a000),
  275. .sdrc = OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
  276. .sms = OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
  277. .ctrl = OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
  278. .prm = OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
  279. .cm = OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
  280. };
  281. void __init omap2_set_globals_243x(void)
  282. {
  283. __omap2_set_globals(&omap243x_globals);
  284. }
  285. #endif
  286. #if defined(CONFIG_ARCH_OMAP3430)
  287. static struct omap_globals omap343x_globals = {
  288. .class = OMAP343X_CLASS,
  289. .tap = OMAP2_IO_ADDRESS(0x4830A000),
  290. .sdrc = OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
  291. .sms = OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
  292. .ctrl = OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
  293. .prm = OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
  294. .cm = OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
  295. };
  296. void __init omap2_set_globals_343x(void)
  297. {
  298. __omap2_set_globals(&omap343x_globals);
  299. }
  300. #endif