generic.c 10 KB

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