generic.c 9.7 KB

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