generic.c 9.7 KB

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