generic.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * linux/arch/arm/mach-sa1100/generic.c
  3. *
  4. * Author: Nicolas Pitre
  5. *
  6. * Code common to all SA11x0 machines.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/cpufreq.h>
  19. #include <linux/ioport.h>
  20. #include <asm/div64.h>
  21. #include <asm/hardware.h>
  22. #include <asm/system.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/irq.h>
  26. #include "generic.h"
  27. #define NR_FREQS 16
  28. /*
  29. * This table is setup for a 3.6864MHz Crystal.
  30. */
  31. static const unsigned short cclk_frequency_100khz[NR_FREQS] = {
  32. 590, /* 59.0 MHz */
  33. 737, /* 73.7 MHz */
  34. 885, /* 88.5 MHz */
  35. 1032, /* 103.2 MHz */
  36. 1180, /* 118.0 MHz */
  37. 1327, /* 132.7 MHz */
  38. 1475, /* 147.5 MHz */
  39. 1622, /* 162.2 MHz */
  40. 1769, /* 176.9 MHz */
  41. 1917, /* 191.7 MHz */
  42. 2064, /* 206.4 MHz */
  43. 2212, /* 221.2 MHz */
  44. 2359, /* 235.9 MHz */
  45. 2507, /* 250.7 MHz */
  46. 2654, /* 265.4 MHz */
  47. 2802 /* 280.2 MHz */
  48. };
  49. #if defined(CONFIG_CPU_FREQ_SA1100) || defined(CONFIG_CPU_FREQ_SA1110)
  50. /* rounds up(!) */
  51. unsigned int sa11x0_freq_to_ppcr(unsigned int khz)
  52. {
  53. int i;
  54. khz /= 100;
  55. for (i = 0; i < NR_FREQS; i++)
  56. if (cclk_frequency_100khz[i] >= khz)
  57. break;
  58. return i;
  59. }
  60. unsigned int sa11x0_ppcr_to_freq(unsigned int idx)
  61. {
  62. unsigned int freq = 0;
  63. if (idx < NR_FREQS)
  64. freq = cclk_frequency_100khz[idx] * 100;
  65. return freq;
  66. }
  67. /* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
  68. * this platform, anyway.
  69. */
  70. int sa11x0_verify_speed(struct cpufreq_policy *policy)
  71. {
  72. unsigned int tmp;
  73. if (policy->cpu)
  74. return -EINVAL;
  75. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
  76. /* make sure that at least one frequency is within the policy */
  77. tmp = cclk_frequency_100khz[sa11x0_freq_to_ppcr(policy->min)] * 100;
  78. if (tmp > policy->max)
  79. policy->max = tmp;
  80. cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
  81. return 0;
  82. }
  83. unsigned int sa11x0_getspeed(unsigned int cpu)
  84. {
  85. if (cpu)
  86. return 0;
  87. return cclk_frequency_100khz[PPCR & 0xf] * 100;
  88. }
  89. #else
  90. /*
  91. * We still need to provide this so building without cpufreq works.
  92. */
  93. unsigned int cpufreq_get(unsigned int cpu)
  94. {
  95. return cclk_frequency_100khz[PPCR & 0xf] * 100;
  96. }
  97. EXPORT_SYMBOL(cpufreq_get);
  98. #endif
  99. /*
  100. * This is the SA11x0 sched_clock implementation. This has
  101. * a resolution of 271ns, and a maximum value of 1165s.
  102. * ( * 1E9 / 3686400 => * 78125 / 288)
  103. */
  104. unsigned long long sched_clock(void)
  105. {
  106. unsigned long long v;
  107. v = (unsigned long long)OSCR * 78125;
  108. do_div(v, 288);
  109. return v;
  110. }
  111. /*
  112. * Default power-off for SA1100
  113. */
  114. static void sa1100_power_off(void)
  115. {
  116. mdelay(100);
  117. local_irq_disable();
  118. /* disable internal oscillator, float CS lines */
  119. PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
  120. /* enable wake-up on GPIO0 (Assabet...) */
  121. PWER = GFER = GRER = 1;
  122. /*
  123. * set scratchpad to zero, just in case it is used as a
  124. * restart address by the bootloader.
  125. */
  126. PSPR = 0;
  127. /* enter sleep mode */
  128. PMCR = PMCR_SF;
  129. }
  130. static struct resource sa11x0udc_resources[] = {
  131. [0] = {
  132. .start = 0x80000000,
  133. .end = 0x8000ffff,
  134. .flags = IORESOURCE_MEM,
  135. },
  136. };
  137. static u64 sa11x0udc_dma_mask = 0xffffffffUL;
  138. static struct platform_device sa11x0udc_device = {
  139. .name = "sa11x0-udc",
  140. .id = -1,
  141. .dev = {
  142. .dma_mask = &sa11x0udc_dma_mask,
  143. .coherent_dma_mask = 0xffffffff,
  144. },
  145. .num_resources = ARRAY_SIZE(sa11x0udc_resources),
  146. .resource = sa11x0udc_resources,
  147. };
  148. static struct resource sa11x0uart1_resources[] = {
  149. [0] = {
  150. .start = 0x80010000,
  151. .end = 0x8001ffff,
  152. .flags = IORESOURCE_MEM,
  153. },
  154. };
  155. static struct platform_device sa11x0uart1_device = {
  156. .name = "sa11x0-uart",
  157. .id = 1,
  158. .num_resources = ARRAY_SIZE(sa11x0uart1_resources),
  159. .resource = sa11x0uart1_resources,
  160. };
  161. static struct resource sa11x0uart3_resources[] = {
  162. [0] = {
  163. .start = 0x80050000,
  164. .end = 0x8005ffff,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. };
  168. static struct platform_device sa11x0uart3_device = {
  169. .name = "sa11x0-uart",
  170. .id = 3,
  171. .num_resources = ARRAY_SIZE(sa11x0uart3_resources),
  172. .resource = sa11x0uart3_resources,
  173. };
  174. static struct resource sa11x0mcp_resources[] = {
  175. [0] = {
  176. .start = 0x80060000,
  177. .end = 0x8006ffff,
  178. .flags = IORESOURCE_MEM,
  179. },
  180. };
  181. static u64 sa11x0mcp_dma_mask = 0xffffffffUL;
  182. static struct platform_device sa11x0mcp_device = {
  183. .name = "sa11x0-mcp",
  184. .id = -1,
  185. .dev = {
  186. .dma_mask = &sa11x0mcp_dma_mask,
  187. .coherent_dma_mask = 0xffffffff,
  188. },
  189. .num_resources = ARRAY_SIZE(sa11x0mcp_resources),
  190. .resource = sa11x0mcp_resources,
  191. };
  192. void sa11x0_set_mcp_data(struct mcp_plat_data *data)
  193. {
  194. sa11x0mcp_device.dev.platform_data = data;
  195. }
  196. static struct resource sa11x0ssp_resources[] = {
  197. [0] = {
  198. .start = 0x80070000,
  199. .end = 0x8007ffff,
  200. .flags = IORESOURCE_MEM,
  201. },
  202. };
  203. static u64 sa11x0ssp_dma_mask = 0xffffffffUL;
  204. static struct platform_device sa11x0ssp_device = {
  205. .name = "sa11x0-ssp",
  206. .id = -1,
  207. .dev = {
  208. .dma_mask = &sa11x0ssp_dma_mask,
  209. .coherent_dma_mask = 0xffffffff,
  210. },
  211. .num_resources = ARRAY_SIZE(sa11x0ssp_resources),
  212. .resource = sa11x0ssp_resources,
  213. };
  214. static struct resource sa11x0fb_resources[] = {
  215. [0] = {
  216. .start = 0xb0100000,
  217. .end = 0xb010ffff,
  218. .flags = IORESOURCE_MEM,
  219. },
  220. [1] = {
  221. .start = IRQ_LCD,
  222. .end = IRQ_LCD,
  223. .flags = IORESOURCE_IRQ,
  224. },
  225. };
  226. static struct platform_device sa11x0fb_device = {
  227. .name = "sa11x0-fb",
  228. .id = -1,
  229. .dev = {
  230. .coherent_dma_mask = 0xffffffff,
  231. },
  232. .num_resources = ARRAY_SIZE(sa11x0fb_resources),
  233. .resource = sa11x0fb_resources,
  234. };
  235. static struct platform_device sa11x0pcmcia_device = {
  236. .name = "sa11x0-pcmcia",
  237. .id = -1,
  238. };
  239. static struct platform_device sa11x0mtd_device = {
  240. .name = "flash",
  241. .id = -1,
  242. };
  243. void sa11x0_set_flash_data(struct flash_platform_data *flash,
  244. struct resource *res, int nr)
  245. {
  246. sa11x0mtd_device.dev.platform_data = flash;
  247. sa11x0mtd_device.resource = res;
  248. sa11x0mtd_device.num_resources = nr;
  249. }
  250. static struct resource sa11x0ir_resources[] = {
  251. {
  252. .start = __PREG(Ser2UTCR0),
  253. .end = __PREG(Ser2UTCR0) + 0x24 - 1,
  254. .flags = IORESOURCE_MEM,
  255. }, {
  256. .start = __PREG(Ser2HSCR0),
  257. .end = __PREG(Ser2HSCR0) + 0x1c - 1,
  258. .flags = IORESOURCE_MEM,
  259. }, {
  260. .start = __PREG(Ser2HSCR2),
  261. .end = __PREG(Ser2HSCR2) + 0x04 - 1,
  262. .flags = IORESOURCE_MEM,
  263. }, {
  264. .start = IRQ_Ser2ICP,
  265. .end = IRQ_Ser2ICP,
  266. .flags = IORESOURCE_IRQ,
  267. }
  268. };
  269. static struct platform_device sa11x0ir_device = {
  270. .name = "sa11x0-ir",
  271. .id = -1,
  272. .num_resources = ARRAY_SIZE(sa11x0ir_resources),
  273. .resource = sa11x0ir_resources,
  274. };
  275. void sa11x0_set_irda_data(struct irda_platform_data *irda)
  276. {
  277. sa11x0ir_device.dev.platform_data = irda;
  278. }
  279. static struct platform_device *sa11x0_devices[] __initdata = {
  280. &sa11x0udc_device,
  281. &sa11x0uart1_device,
  282. &sa11x0uart3_device,
  283. &sa11x0mcp_device,
  284. &sa11x0ssp_device,
  285. &sa11x0pcmcia_device,
  286. &sa11x0fb_device,
  287. &sa11x0mtd_device,
  288. };
  289. static int __init sa1100_init(void)
  290. {
  291. pm_power_off = sa1100_power_off;
  292. if (sa11x0ir_device.dev.platform_data)
  293. platform_device_register(&sa11x0ir_device);
  294. return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
  295. }
  296. arch_initcall(sa1100_init);
  297. void (*sa1100fb_backlight_power)(int on);
  298. void (*sa1100fb_lcd_power)(int on);
  299. EXPORT_SYMBOL(sa1100fb_backlight_power);
  300. EXPORT_SYMBOL(sa1100fb_lcd_power);
  301. /*
  302. * Common I/O mapping:
  303. *
  304. * Typically, static virtual address mappings are as follow:
  305. *
  306. * 0xf0000000-0xf3ffffff: miscellaneous stuff (CPLDs, etc.)
  307. * 0xf4000000-0xf4ffffff: SA-1111
  308. * 0xf5000000-0xf5ffffff: reserved (used by cache flushing area)
  309. * 0xf6000000-0xfffeffff: reserved (internal SA1100 IO defined above)
  310. * 0xffff0000-0xffff0fff: SA1100 exception vectors
  311. * 0xffff2000-0xffff2fff: Minicache copy_user_page area
  312. *
  313. * Below 0xe8000000 is reserved for vm allocation.
  314. *
  315. * The machine specific code must provide the extra mapping beside the
  316. * default mapping provided here.
  317. */
  318. static struct map_desc standard_io_desc[] __initdata = {
  319. /* virtual physical length type */
  320. { 0xf8000000, 0x80000000, 0x00100000, MT_DEVICE }, /* PCM */
  321. { 0xfa000000, 0x90000000, 0x00100000, MT_DEVICE }, /* SCM */
  322. { 0xfc000000, 0xa0000000, 0x00100000, MT_DEVICE }, /* MER */
  323. { 0xfe000000, 0xb0000000, 0x00200000, MT_DEVICE } /* LCD + DMA */
  324. };
  325. void __init sa1100_map_io(void)
  326. {
  327. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  328. }
  329. /*
  330. * Disable the memory bus request/grant signals on the SA1110 to
  331. * ensure that we don't receive spurious memory requests. We set
  332. * the MBGNT signal false to ensure the SA1111 doesn't own the
  333. * SDRAM bus.
  334. */
  335. void __init sa1110_mb_disable(void)
  336. {
  337. unsigned long flags;
  338. local_irq_save(flags);
  339. PGSR &= ~GPIO_MBGNT;
  340. GPCR = GPIO_MBGNT;
  341. GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
  342. GAFR &= ~(GPIO_MBGNT | GPIO_MBREQ);
  343. local_irq_restore(flags);
  344. }
  345. /*
  346. * If the system is going to use the SA-1111 DMA engines, set up
  347. * the memory bus request/grant pins.
  348. */
  349. void __init sa1110_mb_enable(void)
  350. {
  351. unsigned long flags;
  352. local_irq_save(flags);
  353. PGSR &= ~GPIO_MBGNT;
  354. GPCR = GPIO_MBGNT;
  355. GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
  356. GAFR |= (GPIO_MBGNT | GPIO_MBREQ);
  357. TUCR |= TUCR_MR;
  358. local_irq_restore(flags);
  359. }