generic.c 9.5 KB

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