generic.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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/gpio.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/pm.h>
  19. #include <linux/cpufreq.h>
  20. #include <linux/ioport.h>
  21. #include <linux/platform_device.h>
  22. #include <video/sa1100fb.h>
  23. #include <asm/div64.h>
  24. #include <mach/hardware.h>
  25. #include <asm/system.h>
  26. #include <asm/mach/map.h>
  27. #include <asm/mach/flash.h>
  28. #include <asm/irq.h>
  29. #include "generic.h"
  30. unsigned int reset_status;
  31. EXPORT_SYMBOL(reset_status);
  32. #define NR_FREQS 16
  33. /*
  34. * This table is setup for a 3.6864MHz Crystal.
  35. */
  36. static const unsigned short cclk_frequency_100khz[NR_FREQS] = {
  37. 590, /* 59.0 MHz */
  38. 737, /* 73.7 MHz */
  39. 885, /* 88.5 MHz */
  40. 1032, /* 103.2 MHz */
  41. 1180, /* 118.0 MHz */
  42. 1327, /* 132.7 MHz */
  43. 1475, /* 147.5 MHz */
  44. 1622, /* 162.2 MHz */
  45. 1769, /* 176.9 MHz */
  46. 1917, /* 191.7 MHz */
  47. 2064, /* 206.4 MHz */
  48. 2212, /* 221.2 MHz */
  49. 2359, /* 235.9 MHz */
  50. 2507, /* 250.7 MHz */
  51. 2654, /* 265.4 MHz */
  52. 2802 /* 280.2 MHz */
  53. };
  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. /*
  94. * Default power-off for SA1100
  95. */
  96. static void sa1100_power_off(void)
  97. {
  98. mdelay(100);
  99. local_irq_disable();
  100. /* disable internal oscillator, float CS lines */
  101. PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
  102. /* enable wake-up on GPIO0 (Assabet...) */
  103. PWER = GFER = GRER = 1;
  104. /*
  105. * set scratchpad to zero, just in case it is used as a
  106. * restart address by the bootloader.
  107. */
  108. PSPR = 0;
  109. /* enter sleep mode */
  110. PMCR = PMCR_SF;
  111. }
  112. void sa11x0_restart(char mode, const char *cmd)
  113. {
  114. if (mode == 's') {
  115. /* Jump into ROM at address 0 */
  116. soft_restart(0);
  117. } else {
  118. /* Use on-chip reset capability */
  119. RSRR = RSRR_SWR;
  120. }
  121. }
  122. static void sa11x0_register_device(struct platform_device *dev, void *data)
  123. {
  124. int err;
  125. dev->dev.platform_data = data;
  126. err = platform_device_register(dev);
  127. if (err)
  128. printk(KERN_ERR "Unable to register device %s: %d\n",
  129. dev->name, err);
  130. }
  131. static struct resource sa11x0udc_resources[] = {
  132. [0] = DEFINE_RES_MEM(__PREG(Ser0UDCCR), SZ_64K),
  133. [1] = DEFINE_RES_IRQ(IRQ_Ser0UDC),
  134. };
  135. static u64 sa11x0udc_dma_mask = 0xffffffffUL;
  136. static struct platform_device sa11x0udc_device = {
  137. .name = "sa11x0-udc",
  138. .id = -1,
  139. .dev = {
  140. .dma_mask = &sa11x0udc_dma_mask,
  141. .coherent_dma_mask = 0xffffffff,
  142. },
  143. .num_resources = ARRAY_SIZE(sa11x0udc_resources),
  144. .resource = sa11x0udc_resources,
  145. };
  146. static struct resource sa11x0uart1_resources[] = {
  147. [0] = DEFINE_RES_MEM(__PREG(Ser1UTCR0), SZ_64K),
  148. [1] = DEFINE_RES_IRQ(IRQ_Ser1UART),
  149. };
  150. static struct platform_device sa11x0uart1_device = {
  151. .name = "sa11x0-uart",
  152. .id = 1,
  153. .num_resources = ARRAY_SIZE(sa11x0uart1_resources),
  154. .resource = sa11x0uart1_resources,
  155. };
  156. static struct resource sa11x0uart3_resources[] = {
  157. [0] = DEFINE_RES_MEM(__PREG(Ser3UTCR0), SZ_64K),
  158. [1] = DEFINE_RES_IRQ(IRQ_Ser3UART),
  159. };
  160. static struct platform_device sa11x0uart3_device = {
  161. .name = "sa11x0-uart",
  162. .id = 3,
  163. .num_resources = ARRAY_SIZE(sa11x0uart3_resources),
  164. .resource = sa11x0uart3_resources,
  165. };
  166. static struct resource sa11x0mcp_resources[] = {
  167. [0] = DEFINE_RES_MEM(__PREG(Ser4MCCR0), SZ_64K),
  168. [1] = DEFINE_RES_IRQ(IRQ_Ser4MCP),
  169. };
  170. static u64 sa11x0mcp_dma_mask = 0xffffffffUL;
  171. static struct platform_device sa11x0mcp_device = {
  172. .name = "sa11x0-mcp",
  173. .id = -1,
  174. .dev = {
  175. .dma_mask = &sa11x0mcp_dma_mask,
  176. .coherent_dma_mask = 0xffffffff,
  177. },
  178. .num_resources = ARRAY_SIZE(sa11x0mcp_resources),
  179. .resource = sa11x0mcp_resources,
  180. };
  181. void sa11x0_register_mcp(struct mcp_plat_data *data)
  182. {
  183. sa11x0_register_device(&sa11x0mcp_device, data);
  184. }
  185. static struct resource sa11x0ssp_resources[] = {
  186. [0] = DEFINE_RES_MEM(0x80070000, SZ_64K),
  187. [1] = DEFINE_RES_IRQ(IRQ_Ser4SSP),
  188. };
  189. static u64 sa11x0ssp_dma_mask = 0xffffffffUL;
  190. static struct platform_device sa11x0ssp_device = {
  191. .name = "sa11x0-ssp",
  192. .id = -1,
  193. .dev = {
  194. .dma_mask = &sa11x0ssp_dma_mask,
  195. .coherent_dma_mask = 0xffffffff,
  196. },
  197. .num_resources = ARRAY_SIZE(sa11x0ssp_resources),
  198. .resource = sa11x0ssp_resources,
  199. };
  200. static struct resource sa11x0fb_resources[] = {
  201. [0] = DEFINE_RES_MEM(0xb0100000, SZ_64K),
  202. [1] = DEFINE_RES_IRQ(IRQ_LCD),
  203. };
  204. static struct platform_device sa11x0fb_device = {
  205. .name = "sa11x0-fb",
  206. .id = -1,
  207. .dev = {
  208. .coherent_dma_mask = 0xffffffff,
  209. },
  210. .num_resources = ARRAY_SIZE(sa11x0fb_resources),
  211. .resource = sa11x0fb_resources,
  212. };
  213. void sa11x0_register_lcd(struct sa1100fb_mach_info *inf)
  214. {
  215. sa11x0_register_device(&sa11x0fb_device, inf);
  216. }
  217. static struct platform_device sa11x0pcmcia_device = {
  218. .name = "sa11x0-pcmcia",
  219. .id = -1,
  220. };
  221. static struct platform_device sa11x0mtd_device = {
  222. .name = "sa1100-mtd",
  223. .id = -1,
  224. };
  225. void sa11x0_register_mtd(struct flash_platform_data *flash,
  226. struct resource *res, int nr)
  227. {
  228. flash->name = "sa1100";
  229. sa11x0mtd_device.resource = res;
  230. sa11x0mtd_device.num_resources = nr;
  231. sa11x0_register_device(&sa11x0mtd_device, flash);
  232. }
  233. static struct resource sa11x0ir_resources[] = {
  234. DEFINE_RES_MEM(__PREG(Ser2UTCR0), 0x24),
  235. DEFINE_RES_MEM(__PREG(Ser2HSCR0), 0x1c),
  236. DEFINE_RES_MEM(__PREG(Ser2HSCR2), 0x04),
  237. DEFINE_RES_IRQ(IRQ_Ser2ICP),
  238. };
  239. static struct platform_device sa11x0ir_device = {
  240. .name = "sa11x0-ir",
  241. .id = -1,
  242. .num_resources = ARRAY_SIZE(sa11x0ir_resources),
  243. .resource = sa11x0ir_resources,
  244. };
  245. void sa11x0_register_irda(struct irda_platform_data *irda)
  246. {
  247. sa11x0_register_device(&sa11x0ir_device, irda);
  248. }
  249. static struct platform_device sa11x0rtc_device = {
  250. .name = "sa1100-rtc",
  251. .id = -1,
  252. };
  253. static struct resource sa11x0dma_resources[] = {
  254. DEFINE_RES_MEM(DMA_PHYS, DMA_SIZE),
  255. DEFINE_RES_IRQ(IRQ_DMA0),
  256. DEFINE_RES_IRQ(IRQ_DMA1),
  257. DEFINE_RES_IRQ(IRQ_DMA2),
  258. DEFINE_RES_IRQ(IRQ_DMA3),
  259. DEFINE_RES_IRQ(IRQ_DMA4),
  260. DEFINE_RES_IRQ(IRQ_DMA5),
  261. };
  262. static u64 sa11x0dma_dma_mask = DMA_BIT_MASK(32);
  263. static struct platform_device sa11x0dma_device = {
  264. .name = "sa11x0-dma",
  265. .id = -1,
  266. .dev = {
  267. .dma_mask = &sa11x0dma_dma_mask,
  268. .coherent_dma_mask = 0xffffffff,
  269. },
  270. .num_resources = ARRAY_SIZE(sa11x0dma_resources),
  271. .resource = sa11x0dma_resources,
  272. };
  273. static struct platform_device *sa11x0_devices[] __initdata = {
  274. &sa11x0udc_device,
  275. &sa11x0uart1_device,
  276. &sa11x0uart3_device,
  277. &sa11x0ssp_device,
  278. &sa11x0pcmcia_device,
  279. &sa11x0rtc_device,
  280. &sa11x0dma_device,
  281. };
  282. static int __init sa1100_init(void)
  283. {
  284. pm_power_off = sa1100_power_off;
  285. return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
  286. }
  287. arch_initcall(sa1100_init);
  288. /*
  289. * Common I/O mapping:
  290. *
  291. * Typically, static virtual address mappings are as follow:
  292. *
  293. * 0xf0000000-0xf3ffffff: miscellaneous stuff (CPLDs, etc.)
  294. * 0xf4000000-0xf4ffffff: SA-1111
  295. * 0xf5000000-0xf5ffffff: reserved (used by cache flushing area)
  296. * 0xf6000000-0xfffeffff: reserved (internal SA1100 IO defined above)
  297. * 0xffff0000-0xffff0fff: SA1100 exception vectors
  298. * 0xffff2000-0xffff2fff: Minicache copy_user_page area
  299. *
  300. * Below 0xe8000000 is reserved for vm allocation.
  301. *
  302. * The machine specific code must provide the extra mapping beside the
  303. * default mapping provided here.
  304. */
  305. static struct map_desc standard_io_desc[] __initdata = {
  306. { /* PCM */
  307. .virtual = 0xf8000000,
  308. .pfn = __phys_to_pfn(0x80000000),
  309. .length = 0x00100000,
  310. .type = MT_DEVICE
  311. }, { /* SCM */
  312. .virtual = 0xfa000000,
  313. .pfn = __phys_to_pfn(0x90000000),
  314. .length = 0x00100000,
  315. .type = MT_DEVICE
  316. }, { /* MER */
  317. .virtual = 0xfc000000,
  318. .pfn = __phys_to_pfn(0xa0000000),
  319. .length = 0x00100000,
  320. .type = MT_DEVICE
  321. }, { /* LCD + DMA */
  322. .virtual = 0xfe000000,
  323. .pfn = __phys_to_pfn(0xb0000000),
  324. .length = 0x00200000,
  325. .type = MT_DEVICE
  326. },
  327. };
  328. void __init sa1100_map_io(void)
  329. {
  330. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  331. }
  332. /*
  333. * Disable the memory bus request/grant signals on the SA1110 to
  334. * ensure that we don't receive spurious memory requests. We set
  335. * the MBGNT signal false to ensure the SA1111 doesn't own the
  336. * SDRAM bus.
  337. */
  338. void sa1110_mb_disable(void)
  339. {
  340. unsigned long flags;
  341. local_irq_save(flags);
  342. PGSR &= ~GPIO_MBGNT;
  343. GPCR = GPIO_MBGNT;
  344. GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
  345. GAFR &= ~(GPIO_MBGNT | GPIO_MBREQ);
  346. local_irq_restore(flags);
  347. }
  348. /*
  349. * If the system is going to use the SA-1111 DMA engines, set up
  350. * the memory bus request/grant pins.
  351. */
  352. void sa1110_mb_enable(void)
  353. {
  354. unsigned long flags;
  355. local_irq_save(flags);
  356. PGSR &= ~GPIO_MBGNT;
  357. GPCR = GPIO_MBGNT;
  358. GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
  359. GAFR |= (GPIO_MBGNT | GPIO_MBREQ);
  360. TUCR |= TUCR_MR;
  361. local_irq_restore(flags);
  362. }