generic.c 12 KB

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