Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-pxa/pxa27x.c |
| 3 | * |
| 4 | * Author: Nicolas Pitre |
| 5 | * Created: Nov 05, 2002 |
| 6 | * Copyright: MontaVista Software Inc. |
| 7 | * |
| 8 | * Code specific to PXA27x aka Bulverde. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/pm.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <asm/hardware.h> |
| 21 | #include <asm/irq.h> |
Eric Miao | cd49104 | 2007-06-22 04:14:09 +0100 | [diff] [blame] | 22 | #include <asm/arch/irqs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/arch/pxa-regs.h> |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 24 | #include <asm/arch/ohci.h> |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 25 | #include <asm/arch/pm.h> |
Eric Miao | f53f066 | 2007-06-22 05:40:17 +0100 | [diff] [blame] | 26 | #include <asm/arch/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include "generic.h" |
| 29 | |
| 30 | /* Crystal clock: 13MHz */ |
| 31 | #define BASE_CLK 13000000 |
| 32 | |
| 33 | /* |
| 34 | * Get the clock frequency as reflected by CCSR and the turbo flag. |
| 35 | * We assume these values have been applied via a fcs. |
| 36 | * If info is not 0 we also display the current settings. |
| 37 | */ |
| 38 | unsigned int get_clk_frequency_khz( int info) |
| 39 | { |
| 40 | unsigned long ccsr, clkcfg; |
| 41 | unsigned int l, L, m, M, n2, N, S; |
| 42 | int cccr_a, t, ht, b; |
| 43 | |
| 44 | ccsr = CCSR; |
| 45 | cccr_a = CCCR & (1 << 25); |
| 46 | |
| 47 | /* Read clkcfg register: it has turbo, b, half-turbo (and f) */ |
| 48 | asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) ); |
Richard Purdie | afe5df2 | 2006-02-01 19:25:59 +0000 | [diff] [blame] | 49 | t = clkcfg & (1 << 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | ht = clkcfg & (1 << 2); |
| 51 | b = clkcfg & (1 << 3); |
| 52 | |
| 53 | l = ccsr & 0x1f; |
| 54 | n2 = (ccsr>>7) & 0xf; |
| 55 | m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4; |
| 56 | |
| 57 | L = l * BASE_CLK; |
| 58 | N = (L * n2) / 2; |
| 59 | M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2)); |
| 60 | S = (b) ? L : (L/2); |
| 61 | |
| 62 | if (info) { |
| 63 | printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n", |
| 64 | L / 1000000, (L % 1000000) / 10000, l ); |
| 65 | printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n", |
| 66 | N / 1000000, (N % 1000000)/10000, n2 / 2, (n2 % 2)*5, |
| 67 | (t) ? "" : "in" ); |
| 68 | printk( KERN_INFO "Memory clock: %d.%02dMHz (/%d)\n", |
| 69 | M / 1000000, (M % 1000000) / 10000, m ); |
| 70 | printk( KERN_INFO "System bus clock: %d.%02dMHz \n", |
| 71 | S / 1000000, (S % 1000000) / 10000 ); |
| 72 | } |
| 73 | |
| 74 | return (t) ? (N/1000) : (L/1000); |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Return the current mem clock frequency in units of 10kHz as |
| 79 | * reflected by CCCR[A], B, and L |
| 80 | */ |
| 81 | unsigned int get_memclk_frequency_10khz(void) |
| 82 | { |
| 83 | unsigned long ccsr, clkcfg; |
| 84 | unsigned int l, L, m, M; |
| 85 | int cccr_a, b; |
| 86 | |
| 87 | ccsr = CCSR; |
| 88 | cccr_a = CCCR & (1 << 25); |
| 89 | |
| 90 | /* Read clkcfg register: it has turbo, b, half-turbo (and f) */ |
| 91 | asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) ); |
| 92 | b = clkcfg & (1 << 3); |
| 93 | |
| 94 | l = ccsr & 0x1f; |
| 95 | m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4; |
| 96 | |
| 97 | L = l * BASE_CLK; |
| 98 | M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2)); |
| 99 | |
| 100 | return (M / 10000); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Return the current LCD clock frequency in units of 10kHz as |
| 105 | */ |
| 106 | unsigned int get_lcdclk_frequency_10khz(void) |
| 107 | { |
| 108 | unsigned long ccsr; |
| 109 | unsigned int l, L, k, K; |
| 110 | |
| 111 | ccsr = CCSR; |
| 112 | |
| 113 | l = ccsr & 0x1f; |
| 114 | k = (l <= 7) ? 1 : (l <= 16) ? 2 : 4; |
| 115 | |
| 116 | L = l * BASE_CLK; |
| 117 | K = L / k; |
| 118 | |
| 119 | return (K / 10000); |
| 120 | } |
| 121 | |
| 122 | EXPORT_SYMBOL(get_clk_frequency_khz); |
| 123 | EXPORT_SYMBOL(get_memclk_frequency_10khz); |
| 124 | EXPORT_SYMBOL(get_lcdclk_frequency_10khz); |
| 125 | |
Nicolas Pitre | a8fa3f0 | 2005-06-13 22:35:41 +0100 | [diff] [blame] | 126 | #ifdef CONFIG_PM |
| 127 | |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 128 | void pxa_cpu_pm_enter(suspend_state_t state) |
| 129 | { |
| 130 | extern void pxa_cpu_standby(void); |
| 131 | extern void pxa_cpu_suspend(unsigned int); |
| 132 | extern void pxa_cpu_resume(void); |
| 133 | |
Todd Poynor | 26705ca | 2005-07-01 11:27:05 +0100 | [diff] [blame] | 134 | if (state == PM_SUSPEND_STANDBY) |
Richard Purdie | 1f750a7 | 2007-07-02 10:19:07 +0100 | [diff] [blame] | 135 | CKEN = (1 << CKEN_MEMC) | (1 << CKEN_OSTIMER) | (1 << CKEN_LCD) | (1 << CKEN_PWM0); |
Todd Poynor | 26705ca | 2005-07-01 11:27:05 +0100 | [diff] [blame] | 136 | else |
Richard Purdie | 1f750a7 | 2007-07-02 10:19:07 +0100 | [diff] [blame] | 137 | CKEN = (1 << CKEN_MEMC) | (1 << CKEN_OSTIMER); |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 138 | |
| 139 | /* ensure voltage-change sequencer not initiated, which hangs */ |
| 140 | PCFR &= ~PCFR_FVC; |
| 141 | |
| 142 | /* Clear edge-detect status register. */ |
| 143 | PEDR = 0xDF12FE1B; |
| 144 | |
| 145 | switch (state) { |
Todd Poynor | 26705ca | 2005-07-01 11:27:05 +0100 | [diff] [blame] | 146 | case PM_SUSPEND_STANDBY: |
| 147 | pxa_cpu_standby(); |
| 148 | break; |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 149 | case PM_SUSPEND_MEM: |
| 150 | /* set resume return address */ |
| 151 | PSPR = virt_to_phys(pxa_cpu_resume); |
Todd Poynor | 80a1857 | 2005-10-28 16:25:01 +0100 | [diff] [blame] | 152 | pxa_cpu_suspend(PWRMODE_SLEEP); |
Todd Poynor | 8775420 | 2005-06-03 20:52:27 +0100 | [diff] [blame] | 153 | break; |
| 154 | } |
| 155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Russell King | 88dfe98 | 2007-05-15 11:22:48 +0100 | [diff] [blame] | 157 | static int pxa27x_pm_valid(suspend_state_t state) |
| 158 | { |
| 159 | return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY; |
| 160 | } |
| 161 | |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 162 | static struct pm_ops pxa27x_pm_ops = { |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 163 | .enter = pxa_pm_enter, |
Russell King | 88dfe98 | 2007-05-15 11:22:48 +0100 | [diff] [blame] | 164 | .valid = pxa27x_pm_valid, |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 165 | }; |
Nicolas Pitre | a8fa3f0 | 2005-06-13 22:35:41 +0100 | [diff] [blame] | 166 | #endif |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* |
| 169 | * device registration specific to PXA27x. |
| 170 | */ |
| 171 | |
| 172 | static u64 pxa27x_dmamask = 0xffffffffUL; |
| 173 | |
| 174 | static struct resource pxa27x_ohci_resources[] = { |
| 175 | [0] = { |
| 176 | .start = 0x4C000000, |
| 177 | .end = 0x4C00ff6f, |
| 178 | .flags = IORESOURCE_MEM, |
| 179 | }, |
| 180 | [1] = { |
| 181 | .start = IRQ_USBH1, |
| 182 | .end = IRQ_USBH1, |
| 183 | .flags = IORESOURCE_IRQ, |
| 184 | }, |
| 185 | }; |
| 186 | |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame^] | 187 | static struct platform_device pxaohci_device = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | .name = "pxa27x-ohci", |
| 189 | .id = -1, |
| 190 | .dev = { |
| 191 | .dma_mask = &pxa27x_dmamask, |
| 192 | .coherent_dma_mask = 0xffffffff, |
| 193 | }, |
| 194 | .num_resources = ARRAY_SIZE(pxa27x_ohci_resources), |
| 195 | .resource = pxa27x_ohci_resources, |
| 196 | }; |
| 197 | |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 198 | void __init pxa_set_ohci_info(struct pxaohci_platform_data *info) |
| 199 | { |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame^] | 200 | pxaohci_device.dev.platform_data = info; |
Richard Purdie | 81f280e | 2005-11-12 14:22:11 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame^] | 203 | static struct resource i2c_power_resources[] = { |
| 204 | { |
| 205 | .start = 0x40f00180, |
| 206 | .end = 0x40f001a3, |
| 207 | .flags = IORESOURCE_MEM, |
| 208 | }, { |
| 209 | .start = IRQ_PWRI2C, |
| 210 | .end = IRQ_PWRI2C, |
| 211 | .flags = IORESOURCE_IRQ, |
| 212 | }, |
| 213 | }; |
| 214 | |
| 215 | static struct platform_device pxai2c_power_device = { |
| 216 | .name = "pxa2xx-i2c", |
| 217 | .id = 1, |
| 218 | .resource = i2c_power_resources, |
| 219 | .num_resources = ARRAY_SIZE(i2c_power_resources), |
| 220 | }; |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | static struct platform_device *devices[] __initdata = { |
Russell King | 34f3231 | 2007-05-15 10:39:49 +0100 | [diff] [blame^] | 223 | &pxamci_device, |
| 224 | &pxaudc_device, |
| 225 | &pxafb_device, |
| 226 | &ffuart_device, |
| 227 | &btuart_device, |
| 228 | &stuart_device, |
| 229 | &pxai2c_device, |
| 230 | &pxai2c_power_device, |
| 231 | &pxai2s_device, |
| 232 | &pxaficp_device, |
| 233 | &pxartc_device, |
| 234 | &pxaohci_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
Eric Miao | cd49104 | 2007-06-22 04:14:09 +0100 | [diff] [blame] | 237 | void __init pxa27x_init_irq(void) |
| 238 | { |
| 239 | pxa_init_irq_low(); |
| 240 | pxa_init_irq_high(); |
| 241 | pxa_init_irq_gpio(128); |
| 242 | } |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | static int __init pxa27x_init(void) |
| 245 | { |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 246 | int ret = 0; |
| 247 | if (cpu_is_pxa27x()) { |
Eric Miao | f53f066 | 2007-06-22 05:40:17 +0100 | [diff] [blame] | 248 | if ((ret = pxa_init_dma(32))) |
| 249 | return ret; |
Russell King | e176bb0 | 2007-05-15 11:16:10 +0100 | [diff] [blame] | 250 | #ifdef CONFIG_PM |
| 251 | pm_set_ops(&pxa27x_pm_ops); |
| 252 | #endif |
| 253 | ret = platform_add_devices(devices, ARRAY_SIZE(devices)); |
| 254 | } |
| 255 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | subsys_initcall(pxa27x_init); |