generic.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-sa1100/generic.c
  4. *
  5. * Author: Nicolas Pitre
  6. *
  7. * Code common to all SA11x0 machines.
  8. */
  9. #include <linux/gpio.h>
  10. #include <linux/gpio/machine.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/pm.h>
  17. #include <linux/cpufreq.h>
  18. #include <linux/ioport.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/reboot.h>
  21. #include <linux/regulator/fixed.h>
  22. #include <linux/regulator/machine.h>
  23. #include <linux/irqchip/irq-sa11x0.h>
  24. #include <video/sa1100fb.h>
  25. #include <soc/sa1100/pwer.h>
  26. #include <asm/div64.h>
  27. #include <asm/mach/map.h>
  28. #include <asm/mach/flash.h>
  29. #include <asm/irq.h>
  30. #include <asm/system_misc.h>
  31. #include <mach/hardware.h>
  32. #include <mach/irqs.h>
  33. #include <mach/reset.h>
  34. #include "generic.h"
  35. #include <clocksource/pxa.h>
  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. clear_reset_status(RESET_STATUS_ALL);
  87. if (mode == REBOOT_SOFT) {
  88. /* Jump into ROM at address 0 */
  89. soft_restart(0);
  90. } else {
  91. /* Use on-chip reset capability */
  92. RSRR = RSRR_SWR;
  93. }
  94. }
  95. static void sa11x0_register_device(struct platform_device *dev, void *data)
  96. {
  97. int err;
  98. dev->dev.platform_data = data;
  99. err = platform_device_register(dev);
  100. if (err)
  101. printk(KERN_ERR "Unable to register device %s: %d\n",
  102. dev->name, err);
  103. }
  104. static struct resource sa11x0udc_resources[] = {
  105. [0] = DEFINE_RES_MEM(__PREG(Ser0UDCCR), SZ_64K),
  106. [1] = DEFINE_RES_IRQ(IRQ_Ser0UDC),
  107. };
  108. static u64 sa11x0udc_dma_mask = 0xffffffffUL;
  109. static struct platform_device sa11x0udc_device = {
  110. .name = "sa11x0-udc",
  111. .id = -1,
  112. .dev = {
  113. .dma_mask = &sa11x0udc_dma_mask,
  114. .coherent_dma_mask = 0xffffffff,
  115. },
  116. .num_resources = ARRAY_SIZE(sa11x0udc_resources),
  117. .resource = sa11x0udc_resources,
  118. };
  119. static struct resource sa11x0uart1_resources[] = {
  120. [0] = DEFINE_RES_MEM(__PREG(Ser1UTCR0), SZ_64K),
  121. [1] = DEFINE_RES_IRQ(IRQ_Ser1UART),
  122. };
  123. static struct platform_device sa11x0uart1_device = {
  124. .name = "sa11x0-uart",
  125. .id = 1,
  126. .num_resources = ARRAY_SIZE(sa11x0uart1_resources),
  127. .resource = sa11x0uart1_resources,
  128. };
  129. static struct resource sa11x0uart3_resources[] = {
  130. [0] = DEFINE_RES_MEM(__PREG(Ser3UTCR0), SZ_64K),
  131. [1] = DEFINE_RES_IRQ(IRQ_Ser3UART),
  132. };
  133. static struct platform_device sa11x0uart3_device = {
  134. .name = "sa11x0-uart",
  135. .id = 3,
  136. .num_resources = ARRAY_SIZE(sa11x0uart3_resources),
  137. .resource = sa11x0uart3_resources,
  138. };
  139. static struct resource sa11x0mcp_resources[] = {
  140. [0] = DEFINE_RES_MEM(__PREG(Ser4MCCR0), SZ_64K),
  141. [1] = DEFINE_RES_MEM(__PREG(Ser4MCCR1), 4),
  142. [2] = DEFINE_RES_IRQ(IRQ_Ser4MCP),
  143. };
  144. static u64 sa11x0mcp_dma_mask = 0xffffffffUL;
  145. static struct platform_device sa11x0mcp_device = {
  146. .name = "sa11x0-mcp",
  147. .id = -1,
  148. .dev = {
  149. .dma_mask = &sa11x0mcp_dma_mask,
  150. .coherent_dma_mask = 0xffffffff,
  151. },
  152. .num_resources = ARRAY_SIZE(sa11x0mcp_resources),
  153. .resource = sa11x0mcp_resources,
  154. };
  155. void __init sa11x0_ppc_configure_mcp(void)
  156. {
  157. /* Setup the PPC unit for the MCP */
  158. PPDR &= ~PPC_RXD4;
  159. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  160. PSDR |= PPC_RXD4;
  161. PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  162. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  163. }
  164. void sa11x0_register_mcp(struct mcp_plat_data *data)
  165. {
  166. sa11x0_register_device(&sa11x0mcp_device, data);
  167. }
  168. static struct resource sa11x0ssp_resources[] = {
  169. [0] = DEFINE_RES_MEM(0x80070000, SZ_64K),
  170. [1] = DEFINE_RES_IRQ(IRQ_Ser4SSP),
  171. };
  172. static u64 sa11x0ssp_dma_mask = 0xffffffffUL;
  173. static struct platform_device sa11x0ssp_device = {
  174. .name = "sa11x0-ssp",
  175. .id = -1,
  176. .dev = {
  177. .dma_mask = &sa11x0ssp_dma_mask,
  178. .coherent_dma_mask = 0xffffffff,
  179. },
  180. .num_resources = ARRAY_SIZE(sa11x0ssp_resources),
  181. .resource = sa11x0ssp_resources,
  182. };
  183. static struct resource sa11x0fb_resources[] = {
  184. [0] = DEFINE_RES_MEM(0xb0100000, SZ_64K),
  185. [1] = DEFINE_RES_IRQ(IRQ_LCD),
  186. };
  187. static struct platform_device sa11x0fb_device = {
  188. .name = "sa11x0-fb",
  189. .id = -1,
  190. .dev = {
  191. .coherent_dma_mask = 0xffffffff,
  192. },
  193. .num_resources = ARRAY_SIZE(sa11x0fb_resources),
  194. .resource = sa11x0fb_resources,
  195. };
  196. void sa11x0_register_lcd(struct sa1100fb_mach_info *inf)
  197. {
  198. sa11x0_register_device(&sa11x0fb_device, inf);
  199. }
  200. void sa11x0_register_pcmcia(int socket, struct gpiod_lookup_table *table)
  201. {
  202. if (table)
  203. gpiod_add_lookup_table(table);
  204. platform_device_register_simple("sa11x0-pcmcia", socket, NULL, 0);
  205. }
  206. static struct platform_device sa11x0mtd_device = {
  207. .name = "sa1100-mtd",
  208. .id = -1,
  209. };
  210. void sa11x0_register_mtd(struct flash_platform_data *flash,
  211. struct resource *res, int nr)
  212. {
  213. flash->name = "sa1100";
  214. sa11x0mtd_device.resource = res;
  215. sa11x0mtd_device.num_resources = nr;
  216. sa11x0_register_device(&sa11x0mtd_device, flash);
  217. }
  218. static struct resource sa11x0ir_resources[] = {
  219. DEFINE_RES_MEM(__PREG(Ser2UTCR0), 0x24),
  220. DEFINE_RES_MEM(__PREG(Ser2HSCR0), 0x1c),
  221. DEFINE_RES_MEM(__PREG(Ser2HSCR2), 0x04),
  222. DEFINE_RES_IRQ(IRQ_Ser2ICP),
  223. };
  224. static struct platform_device sa11x0ir_device = {
  225. .name = "sa11x0-ir",
  226. .id = -1,
  227. .num_resources = ARRAY_SIZE(sa11x0ir_resources),
  228. .resource = sa11x0ir_resources,
  229. };
  230. void sa11x0_register_irda(struct irda_platform_data *irda)
  231. {
  232. sa11x0_register_device(&sa11x0ir_device, irda);
  233. }
  234. static struct resource sa1100_rtc_resources[] = {
  235. DEFINE_RES_MEM(0x90010000, 0x40),
  236. DEFINE_RES_IRQ_NAMED(IRQ_RTC1Hz, "rtc 1Hz"),
  237. DEFINE_RES_IRQ_NAMED(IRQ_RTCAlrm, "rtc alarm"),
  238. };
  239. static struct platform_device sa11x0rtc_device = {
  240. .name = "sa1100-rtc",
  241. .id = -1,
  242. .num_resources = ARRAY_SIZE(sa1100_rtc_resources),
  243. .resource = sa1100_rtc_resources,
  244. };
  245. static struct resource sa11x0dma_resources[] = {
  246. DEFINE_RES_MEM(DMA_PHYS, DMA_SIZE),
  247. DEFINE_RES_IRQ(IRQ_DMA0),
  248. DEFINE_RES_IRQ(IRQ_DMA1),
  249. DEFINE_RES_IRQ(IRQ_DMA2),
  250. DEFINE_RES_IRQ(IRQ_DMA3),
  251. DEFINE_RES_IRQ(IRQ_DMA4),
  252. DEFINE_RES_IRQ(IRQ_DMA5),
  253. };
  254. static u64 sa11x0dma_dma_mask = DMA_BIT_MASK(32);
  255. static struct platform_device sa11x0dma_device = {
  256. .name = "sa11x0-dma",
  257. .id = -1,
  258. .dev = {
  259. .dma_mask = &sa11x0dma_dma_mask,
  260. .coherent_dma_mask = 0xffffffff,
  261. },
  262. .num_resources = ARRAY_SIZE(sa11x0dma_resources),
  263. .resource = sa11x0dma_resources,
  264. };
  265. static struct platform_device *sa11x0_devices[] __initdata = {
  266. &sa11x0udc_device,
  267. &sa11x0uart1_device,
  268. &sa11x0uart3_device,
  269. &sa11x0ssp_device,
  270. &sa11x0rtc_device,
  271. &sa11x0dma_device,
  272. };
  273. static int __init sa1100_init(void)
  274. {
  275. struct resource wdt_res = DEFINE_RES_MEM(0x90000000, 0x20);
  276. pm_power_off = sa1100_power_off;
  277. regulator_has_full_constraints();
  278. platform_device_register_simple("sa1100_wdt", -1, &wdt_res, 1);
  279. return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
  280. }
  281. arch_initcall(sa1100_init);
  282. void __init sa11x0_init_late(void)
  283. {
  284. sa11x0_pm_init();
  285. }
  286. int __init sa11x0_register_fixed_regulator(int n,
  287. struct fixed_voltage_config *cfg,
  288. struct regulator_consumer_supply *supplies, unsigned num_supplies,
  289. bool uses_gpio)
  290. {
  291. struct regulator_init_data *id;
  292. cfg->init_data = id = kzalloc(sizeof(*cfg->init_data), GFP_KERNEL);
  293. if (!cfg->init_data)
  294. return -ENOMEM;
  295. if (!uses_gpio)
  296. id->constraints.always_on = 1;
  297. id->constraints.name = cfg->supply_name;
  298. id->constraints.min_uV = cfg->microvolts;
  299. id->constraints.max_uV = cfg->microvolts;
  300. id->constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
  301. id->constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
  302. id->consumer_supplies = supplies;
  303. id->num_consumer_supplies = num_supplies;
  304. platform_device_register_resndata(NULL, "reg-fixed-voltage", n,
  305. NULL, 0, cfg, sizeof(*cfg));
  306. return 0;
  307. }
  308. /*
  309. * Common I/O mapping:
  310. *
  311. * Typically, static virtual address mappings are as follow:
  312. *
  313. * 0xf0000000-0xf3ffffff: miscellaneous stuff (CPLDs, etc.)
  314. * 0xf4000000-0xf4ffffff: SA-1111
  315. * 0xf5000000-0xf5ffffff: reserved (used by cache flushing area)
  316. * 0xf6000000-0xfffeffff: reserved (internal SA1100 IO defined above)
  317. * 0xffff0000-0xffff0fff: SA1100 exception vectors
  318. * 0xffff2000-0xffff2fff: Minicache copy_user_page area
  319. *
  320. * Below 0xe8000000 is reserved for vm allocation.
  321. *
  322. * The machine specific code must provide the extra mapping beside the
  323. * default mapping provided here.
  324. */
  325. static struct map_desc standard_io_desc[] __initdata = {
  326. { /* PCM */
  327. .virtual = 0xf8000000,
  328. .pfn = __phys_to_pfn(0x80000000),
  329. .length = 0x00100000,
  330. .type = MT_DEVICE
  331. }, { /* SCM */
  332. .virtual = 0xfa000000,
  333. .pfn = __phys_to_pfn(0x90000000),
  334. .length = 0x00100000,
  335. .type = MT_DEVICE
  336. }, { /* MER */
  337. .virtual = 0xfc000000,
  338. .pfn = __phys_to_pfn(0xa0000000),
  339. .length = 0x00100000,
  340. .type = MT_DEVICE
  341. }, { /* LCD + DMA */
  342. .virtual = 0xfe000000,
  343. .pfn = __phys_to_pfn(0xb0000000),
  344. .length = 0x00200000,
  345. .type = MT_DEVICE
  346. },
  347. };
  348. void __init sa1100_map_io(void)
  349. {
  350. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  351. }
  352. void __init sa1100_timer_init(void)
  353. {
  354. pxa_timer_nodt_init(IRQ_OST0, io_p2v(0x90000000));
  355. }
  356. static struct resource irq_resource =
  357. DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
  358. void __init sa1100_init_irq(void)
  359. {
  360. request_resource(&iomem_resource, &irq_resource);
  361. sa11x0_init_irq_nodt(IRQ_GPIO0_SC, irq_resource.start);
  362. sa1100_init_gpio();
  363. sa11xx_clk_init();
  364. }
  365. /*
  366. * Disable the memory bus request/grant signals on the SA1110 to
  367. * ensure that we don't receive spurious memory requests. We set
  368. * the MBGNT signal false to ensure the SA1111 doesn't own the
  369. * SDRAM bus.
  370. */
  371. void sa1110_mb_disable(void)
  372. {
  373. unsigned long flags;
  374. local_irq_save(flags);
  375. PGSR &= ~GPIO_MBGNT;
  376. GPCR = GPIO_MBGNT;
  377. GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
  378. GAFR &= ~(GPIO_MBGNT | GPIO_MBREQ);
  379. local_irq_restore(flags);
  380. }
  381. /*
  382. * If the system is going to use the SA-1111 DMA engines, set up
  383. * the memory bus request/grant pins.
  384. */
  385. void sa1110_mb_enable(void)
  386. {
  387. unsigned long flags;
  388. local_irq_save(flags);
  389. PGSR &= ~GPIO_MBGNT;
  390. GPCR = GPIO_MBGNT;
  391. GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
  392. GAFR |= (GPIO_MBGNT | GPIO_MBREQ);
  393. TUCR |= TUCR_MR;
  394. local_irq_restore(flags);
  395. }
  396. int sa11x0_gpio_set_wake(unsigned int gpio, unsigned int on)
  397. {
  398. if (on)
  399. PWER |= BIT(gpio);
  400. else
  401. PWER &= ~BIT(gpio);
  402. return 0;
  403. }
  404. int sa11x0_sc_set_wake(unsigned int irq, unsigned int on)
  405. {
  406. if (BIT(irq) != IC_RTCAlrm)
  407. return -EINVAL;
  408. if (on)
  409. PWER |= PWER_RTC;
  410. else
  411. PWER &= ~PWER_RTC;
  412. return 0;
  413. }