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