2 * linux/arch/arm/mach-pxa/pxa3xx.c
4 * code specific to pxa3xx aka Monahans
6 * Copyright (C) 2006 Marvell International Ltd.
8 * 2007-09-02: eric miao <eric.miao@marvell.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/irq.h>
24 #include <asm/hardware.h>
25 #include <asm/arch/pxa3xx-regs.h>
26 #include <asm/arch/ohci.h>
27 #include <asm/arch/pm.h>
28 #include <asm/arch/dma.h>
29 #include <asm/arch/ssp.h>
35 /* Crystal clock: 13MHz */
36 #define BASE_CLK 13000000
38 /* Ring Oscillator Clock: 60MHz */
39 #define RO_CLK 60000000
41 #define ACCR_D0CS (1 << 26)
43 /* crystal frequency to static memory controller multiplier (SMCFS) */
44 static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
46 /* crystal frequency to HSIO bus frequency multiplier (HSS) */
47 static unsigned char hss_mult[4] = { 8, 12, 16, 0 };
50 * Get the clock frequency as reflected by CCSR and the turbo flag.
51 * We assume these values have been applied via a fcs.
52 * If info is not 0 we also display the current settings.
54 unsigned int pxa3xx_get_clk_frequency_khz(int info)
56 unsigned long acsr, xclkcfg;
57 unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
59 /* Read XCLKCFG register turbo bit */
60 __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
66 xn = (acsr >> 8) & 0x7;
67 hss = (acsr >> 14) & 0x3;
72 ro = acsr & ACCR_D0CS;
74 CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
75 HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
78 pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
79 RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
81 pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
82 XL / 1000000, (XL % 1000000) / 10000, xl);
83 pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
84 XN / 1000000, (XN % 1000000) / 10000, xn,
86 pr_info("HSIO bus clock: %d.%02dMHz\n",
87 HSS / 1000000, (HSS % 1000000) / 10000);
94 * Return the current static memory controller clock frequency
97 unsigned int pxa3xx_get_memclk_frequency_10khz(void)
100 unsigned int smcfs, clk = 0;
104 smcfs = (acsr >> 23) & 0x7;
105 clk = (acsr & ACCR_D0CS) ? RO_CLK : smcfs_mult[smcfs] * BASE_CLK;
107 return (clk / 10000);
111 * Return the current HSIO bus clock frequency
113 static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
116 unsigned int hss, hsio_clk;
120 hss = (acsr >> 14) & 0x3;
121 hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
126 static void clk_pxa3xx_cken_enable(struct clk *clk)
128 unsigned long mask = 1ul << (clk->cken & 0x1f);
140 static void clk_pxa3xx_cken_disable(struct clk *clk)
142 unsigned long mask = 1ul << (clk->cken & 0x1f);
154 static const struct clkops clk_pxa3xx_cken_ops = {
155 .enable = clk_pxa3xx_cken_enable,
156 .disable = clk_pxa3xx_cken_disable,
159 static const struct clkops clk_pxa3xx_hsio_ops = {
160 .enable = clk_pxa3xx_cken_enable,
161 .disable = clk_pxa3xx_cken_disable,
162 .getrate = clk_pxa3xx_hsio_getrate,
165 #define PXA3xx_CKEN(_name, _cken, _rate, _delay, _dev) \
169 .ops = &clk_pxa3xx_cken_ops, \
171 .cken = CKEN_##_cken, \
175 #define PXA3xx_CK(_name, _cken, _ops, _dev) \
180 .cken = CKEN_##_cken, \
183 static struct clk pxa3xx_clks[] = {
184 PXA3xx_CK("LCDCLK", LCD, &clk_pxa3xx_hsio_ops, &pxa_device_fb.dev),
185 PXA3xx_CK("CAMCLK", CAMERA, &clk_pxa3xx_hsio_ops, NULL),
187 PXA3xx_CKEN("UARTCLK", FFUART, 14857000, 1, &pxa_device_ffuart.dev),
188 PXA3xx_CKEN("UARTCLK", BTUART, 14857000, 1, &pxa_device_btuart.dev),
189 PXA3xx_CKEN("UARTCLK", STUART, 14857000, 1, NULL),
191 PXA3xx_CKEN("I2CCLK", I2C, 32842000, 0, &pxa_device_i2c.dev),
192 PXA3xx_CKEN("UDCCLK", UDC, 48000000, 5, &pxa_device_udc.dev),
193 PXA3xx_CKEN("USBCLK", USBH, 48000000, 0, &pxa27x_device_ohci.dev),
195 PXA3xx_CKEN("SSPCLK", SSP1, 13000000, 0, &pxa27x_device_ssp1.dev),
196 PXA3xx_CKEN("SSPCLK", SSP2, 13000000, 0, &pxa27x_device_ssp2.dev),
197 PXA3xx_CKEN("SSPCLK", SSP3, 13000000, 0, &pxa27x_device_ssp3.dev),
198 PXA3xx_CKEN("SSPCLK", SSP4, 13000000, 0, &pxa3xx_device_ssp4.dev),
200 PXA3xx_CKEN("MMCCLK", MMC1, 19500000, 0, &pxa_device_mci.dev),
201 PXA3xx_CKEN("MMCCLK", MMC2, 19500000, 0, &pxa3xx_device_mci2.dev),
202 PXA3xx_CKEN("MMCCLK", MMC3, 19500000, 0, &pxa3xx_device_mci3.dev),
206 #define SLEEP_SAVE_SIZE 4
208 #define ISRAM_START 0x5c000000
209 #define ISRAM_SIZE SZ_256K
211 static void __iomem *sram;
212 static unsigned long wakeup_src;
214 static void pxa3xx_cpu_pm_save(unsigned long *sleep_save)
216 pr_debug("PM: CKENA=%08x CKENB=%08x\n", CKENA, CKENB);
218 if (CKENA & (1 << CKEN_USBH)) {
219 printk(KERN_ERR "PM: USB host clock not stopped?\n");
220 CKENA &= ~(1 << CKEN_USBH);
222 // CKENA |= 1 << (CKEN_ISC & 31);
225 * Low power modes require the HSIO2 clock to be enabled.
227 CKENB |= 1 << (CKEN_HSIO2 & 31);
230 static void pxa3xx_cpu_pm_restore(unsigned long *sleep_save)
232 CKENB &= ~(1 << (CKEN_HSIO2 & 31));
236 * Enter a standby mode (S0D1C2 or S0D2C2). Upon wakeup, the dynamic
237 * memory controller has to be reinitialised, so we place some code
238 * in the SRAM to perform this function.
240 * We disable FIQs across the standby - otherwise, we might receive a
241 * FIQ while the SDRAM is unavailable.
243 static void pxa3xx_cpu_standby(unsigned int pwrmode)
245 extern const char pm_enter_standby_start[], pm_enter_standby_end[];
246 void (*fn)(unsigned int) = (void __force *)(sram + 0x8000);
248 memcpy_toio(sram + 0x8000, pm_enter_standby_start,
249 pm_enter_standby_end - pm_enter_standby_start);
253 AD2D0ER = wakeup_src;
265 printk("PM: AD2D0SR=%08x ASCR=%08x\n", AD2D0SR, ASCR);
268 static void pxa3xx_cpu_pm_enter(suspend_state_t state)
271 * Don't sleep if no wakeup sources are defined
277 case PM_SUSPEND_STANDBY:
278 pxa3xx_cpu_standby(PXA3xx_PM_S0D2C2);
286 static int pxa3xx_cpu_pm_valid(suspend_state_t state)
288 return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
291 static struct pxa_cpu_pm_fns pxa3xx_cpu_pm_fns = {
292 .save_size = SLEEP_SAVE_SIZE,
293 .save = pxa3xx_cpu_pm_save,
294 .restore = pxa3xx_cpu_pm_restore,
295 .valid = pxa3xx_cpu_pm_valid,
296 .enter = pxa3xx_cpu_pm_enter,
299 static void __init pxa3xx_init_pm(void)
301 sram = ioremap(ISRAM_START, ISRAM_SIZE);
303 printk(KERN_ERR "Unable to map ISRAM: disabling standby/suspend\n");
308 * Since we copy wakeup code into the SRAM, we need to ensure
309 * that it is preserved over the low power modes. Note: bit 8
310 * is undocumented in the developer manual, but must be set.
312 AD1R |= ADXR_L2 | ADXR_R0;
313 AD2R |= ADXR_L2 | ADXR_R0;
314 AD3R |= ADXR_L2 | ADXR_R0;
317 * Clear the resume enable registers.
324 pxa_cpu_pm_fns = &pxa3xx_cpu_pm_fns;
327 static int pxa3xx_set_wake(unsigned int irq, unsigned int on)
329 unsigned long flags, mask = 0;
333 mask = ADXER_MFP_WSSP3;
346 mask = ADXER_MFP_WAC97;
352 mask = ADXER_MFP_WSSP2;
355 mask = ADXER_MFP_WI2C;
358 mask = ADXER_MFP_WUART3;
361 mask = ADXER_MFP_WUART2;
364 mask = ADXER_MFP_WUART1;
367 mask = ADXER_MFP_WMMC1;
370 mask = ADXER_MFP_WSSP1;
376 mask = ADXER_MFP_WSSP4;
385 mask = ADXER_MFP_WMMC2;
388 mask = ADXER_MFP_WFLASH;
394 mask = ADXER_WEXTWAKE0;
397 mask = ADXER_WEXTWAKE1;
400 mask = ADXER_MFP_GEN12;
404 local_irq_save(flags);
409 local_irq_restore(flags);
414 static void pxa3xx_init_irq_pm(void)
416 pxa_init_irq_set_wake(pxa3xx_set_wake);
420 static inline void pxa3xx_init_pm(void) {}
421 static inline void pxa3xx_init_irq_pm(void) {}
424 void __init pxa3xx_init_irq(void)
426 /* enable CP6 access */
428 __asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
430 __asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
434 pxa_init_irq_gpio(128);
435 pxa3xx_init_irq_pm();
439 * device registration specific to PXA3xx.
442 static struct platform_device *devices[] __initdata = {
455 static int __init pxa3xx_init(void)
459 if (cpu_is_pxa3xx()) {
460 clks_register(pxa3xx_clks, ARRAY_SIZE(pxa3xx_clks));
462 if ((ret = pxa_init_dma(32)))
467 return platform_add_devices(devices, ARRAY_SIZE(devices));
472 subsys_initcall(pxa3xx_init);