generic.c 10 KB

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