generic.c 9.7 KB

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