generic.c 10 KB

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