generic.c 10 KB

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