Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2006 Atmel Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | #include <linux/clk.h> |
Hans-Christian Egtvedt | 35bf50c | 2007-12-19 09:29:19 +0100 | [diff] [blame] | 9 | #include <linux/delay.h> |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 10 | #include <linux/dw_dmac.h> |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 11 | #include <linux/fb.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/platform_device.h> |
David Brownell | 6b84bbf | 2007-06-22 19:17:57 -0700 | [diff] [blame] | 14 | #include <linux/dma-mapping.h> |
David Brownell | 3c26e17 | 2008-07-27 02:34:45 -0700 | [diff] [blame] | 15 | #include <linux/gpio.h> |
Haavard Skinnemoen | 41d8ca4 | 2007-02-16 13:56:11 +0100 | [diff] [blame] | 16 | #include <linux/spi/spi.h> |
Stelian Pop | 8d85531 | 2008-03-05 00:00:00 +0100 | [diff] [blame] | 17 | #include <linux/usb/atmel_usba_udc.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 18 | |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 19 | #include <asm/atmel-mci.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 20 | #include <asm/io.h> |
Haavard Skinnemoen | e7ba176 | 2007-10-10 14:58:29 +0200 | [diff] [blame] | 21 | #include <asm/irq.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 22 | |
Haavard Skinnemoen | 3663b73 | 2008-08-05 13:57:38 +0200 | [diff] [blame] | 23 | #include <mach/at32ap700x.h> |
| 24 | #include <mach/board.h> |
Haavard Skinnemoen | b47eb40 | 2008-07-31 15:56:36 +0200 | [diff] [blame] | 25 | #include <mach/hmatrix.h> |
Haavard Skinnemoen | 3663b73 | 2008-08-05 13:57:38 +0200 | [diff] [blame] | 26 | #include <mach/portmux.h> |
| 27 | #include <mach/sram.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 28 | |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 29 | #include <video/atmel_lcdc.h> |
| 30 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 31 | #include "clock.h" |
| 32 | #include "pio.h" |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 33 | #include "pm.h" |
| 34 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 35 | |
| 36 | #define PBMEM(base) \ |
| 37 | { \ |
| 38 | .start = base, \ |
| 39 | .end = base + 0x3ff, \ |
| 40 | .flags = IORESOURCE_MEM, \ |
| 41 | } |
| 42 | #define IRQ(num) \ |
| 43 | { \ |
| 44 | .start = num, \ |
| 45 | .end = num, \ |
| 46 | .flags = IORESOURCE_IRQ, \ |
| 47 | } |
| 48 | #define NAMED_IRQ(num, _name) \ |
| 49 | { \ |
| 50 | .start = num, \ |
| 51 | .end = num, \ |
| 52 | .name = _name, \ |
| 53 | .flags = IORESOURCE_IRQ, \ |
| 54 | } |
| 55 | |
David Brownell | 6b84bbf | 2007-06-22 19:17:57 -0700 | [diff] [blame] | 56 | /* REVISIT these assume *every* device supports DMA, but several |
| 57 | * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more. |
| 58 | */ |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 59 | #define DEFINE_DEV(_name, _id) \ |
David Brownell | 6b84bbf | 2007-06-22 19:17:57 -0700 | [diff] [blame] | 60 | static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \ |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 61 | static struct platform_device _name##_id##_device = { \ |
| 62 | .name = #_name, \ |
| 63 | .id = _id, \ |
| 64 | .dev = { \ |
David Brownell | 6b84bbf | 2007-06-22 19:17:57 -0700 | [diff] [blame] | 65 | .dma_mask = &_name##_id##_dma_mask, \ |
| 66 | .coherent_dma_mask = DMA_32BIT_MASK, \ |
| 67 | }, \ |
| 68 | .resource = _name##_id##_resource, \ |
| 69 | .num_resources = ARRAY_SIZE(_name##_id##_resource), \ |
| 70 | } |
| 71 | #define DEFINE_DEV_DATA(_name, _id) \ |
| 72 | static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \ |
| 73 | static struct platform_device _name##_id##_device = { \ |
| 74 | .name = #_name, \ |
| 75 | .id = _id, \ |
| 76 | .dev = { \ |
| 77 | .dma_mask = &_name##_id##_dma_mask, \ |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 78 | .platform_data = &_name##_id##_data, \ |
David Brownell | 6b84bbf | 2007-06-22 19:17:57 -0700 | [diff] [blame] | 79 | .coherent_dma_mask = DMA_32BIT_MASK, \ |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 80 | }, \ |
| 81 | .resource = _name##_id##_resource, \ |
| 82 | .num_resources = ARRAY_SIZE(_name##_id##_resource), \ |
| 83 | } |
| 84 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 85 | #define select_peripheral(port, pin_mask, periph, flags) \ |
| 86 | at32_select_periph(GPIO_##port##_BASE, pin_mask, \ |
| 87 | GPIO_##periph, flags) |
Haavard Skinnemoen | c3e2a79 | 2006-12-04 13:46:52 +0100 | [diff] [blame] | 88 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 89 | #define DEV_CLK(_name, devname, bus, _index) \ |
| 90 | static struct clk devname##_##_name = { \ |
| 91 | .name = #_name, \ |
| 92 | .dev = &devname##_device.dev, \ |
| 93 | .parent = &bus##_clk, \ |
| 94 | .mode = bus##_clk_mode, \ |
| 95 | .get_rate = bus##_clk_get_rate, \ |
| 96 | .index = _index, \ |
| 97 | } |
| 98 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 99 | static DEFINE_SPINLOCK(pm_lock); |
| 100 | |
Hans-Christian Egtvedt | 35bf50c | 2007-12-19 09:29:19 +0100 | [diff] [blame] | 101 | static struct clk osc0; |
| 102 | static struct clk osc1; |
| 103 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 104 | static unsigned long osc_get_rate(struct clk *clk) |
| 105 | { |
Alex | 60ed795 | 2008-03-17 14:55:06 +0100 | [diff] [blame] | 106 | return at32_board_osc_rates[clk->index]; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static unsigned long pll_get_rate(struct clk *clk, unsigned long control) |
| 110 | { |
| 111 | unsigned long div, mul, rate; |
| 112 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 113 | div = PM_BFEXT(PLLDIV, control) + 1; |
| 114 | mul = PM_BFEXT(PLLMUL, control) + 1; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 115 | |
| 116 | rate = clk->parent->get_rate(clk->parent); |
| 117 | rate = (rate + div / 2) / div; |
| 118 | rate *= mul; |
| 119 | |
| 120 | return rate; |
| 121 | } |
| 122 | |
Hans-Christian Egtvedt | 35bf50c | 2007-12-19 09:29:19 +0100 | [diff] [blame] | 123 | static long pll_set_rate(struct clk *clk, unsigned long rate, |
| 124 | u32 *pll_ctrl) |
| 125 | { |
| 126 | unsigned long mul; |
| 127 | unsigned long mul_best_fit = 0; |
| 128 | unsigned long div; |
| 129 | unsigned long div_min; |
| 130 | unsigned long div_max; |
| 131 | unsigned long div_best_fit = 0; |
| 132 | unsigned long base; |
| 133 | unsigned long pll_in; |
| 134 | unsigned long actual = 0; |
| 135 | unsigned long rate_error; |
| 136 | unsigned long rate_error_prev = ~0UL; |
| 137 | u32 ctrl; |
| 138 | |
| 139 | /* Rate must be between 80 MHz and 200 Mhz. */ |
| 140 | if (rate < 80000000UL || rate > 200000000UL) |
| 141 | return -EINVAL; |
| 142 | |
| 143 | ctrl = PM_BF(PLLOPT, 4); |
| 144 | base = clk->parent->get_rate(clk->parent); |
| 145 | |
| 146 | /* PLL input frequency must be between 6 MHz and 32 MHz. */ |
| 147 | div_min = DIV_ROUND_UP(base, 32000000UL); |
| 148 | div_max = base / 6000000UL; |
| 149 | |
| 150 | if (div_max < div_min) |
| 151 | return -EINVAL; |
| 152 | |
| 153 | for (div = div_min; div <= div_max; div++) { |
| 154 | pll_in = (base + div / 2) / div; |
| 155 | mul = (rate + pll_in / 2) / pll_in; |
| 156 | |
| 157 | if (mul == 0) |
| 158 | continue; |
| 159 | |
| 160 | actual = pll_in * mul; |
| 161 | rate_error = abs(actual - rate); |
| 162 | |
| 163 | if (rate_error < rate_error_prev) { |
| 164 | mul_best_fit = mul; |
| 165 | div_best_fit = div; |
| 166 | rate_error_prev = rate_error; |
| 167 | } |
| 168 | |
| 169 | if (rate_error == 0) |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | if (div_best_fit == 0) |
| 174 | return -EINVAL; |
| 175 | |
| 176 | ctrl |= PM_BF(PLLMUL, mul_best_fit - 1); |
| 177 | ctrl |= PM_BF(PLLDIV, div_best_fit - 1); |
| 178 | ctrl |= PM_BF(PLLCOUNT, 16); |
| 179 | |
| 180 | if (clk->parent == &osc1) |
| 181 | ctrl |= PM_BIT(PLLOSC); |
| 182 | |
| 183 | *pll_ctrl = ctrl; |
| 184 | |
| 185 | return actual; |
| 186 | } |
| 187 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 188 | static unsigned long pll0_get_rate(struct clk *clk) |
| 189 | { |
| 190 | u32 control; |
| 191 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 192 | control = pm_readl(PLL0); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 193 | |
| 194 | return pll_get_rate(clk, control); |
| 195 | } |
| 196 | |
Hans-Christian Egtvedt | 35bf50c | 2007-12-19 09:29:19 +0100 | [diff] [blame] | 197 | static void pll1_mode(struct clk *clk, int enabled) |
| 198 | { |
| 199 | unsigned long timeout; |
| 200 | u32 status; |
| 201 | u32 ctrl; |
| 202 | |
| 203 | ctrl = pm_readl(PLL1); |
| 204 | |
| 205 | if (enabled) { |
| 206 | if (!PM_BFEXT(PLLMUL, ctrl) && !PM_BFEXT(PLLDIV, ctrl)) { |
| 207 | pr_debug("clk %s: failed to enable, rate not set\n", |
| 208 | clk->name); |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | ctrl |= PM_BIT(PLLEN); |
| 213 | pm_writel(PLL1, ctrl); |
| 214 | |
| 215 | /* Wait for PLL lock. */ |
| 216 | for (timeout = 10000; timeout; timeout--) { |
| 217 | status = pm_readl(ISR); |
| 218 | if (status & PM_BIT(LOCK1)) |
| 219 | break; |
| 220 | udelay(10); |
| 221 | } |
| 222 | |
| 223 | if (!(status & PM_BIT(LOCK1))) |
| 224 | printk(KERN_ERR "clk %s: timeout waiting for lock\n", |
| 225 | clk->name); |
| 226 | } else { |
| 227 | ctrl &= ~PM_BIT(PLLEN); |
| 228 | pm_writel(PLL1, ctrl); |
| 229 | } |
| 230 | } |
| 231 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 232 | static unsigned long pll1_get_rate(struct clk *clk) |
| 233 | { |
| 234 | u32 control; |
| 235 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 236 | control = pm_readl(PLL1); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 237 | |
| 238 | return pll_get_rate(clk, control); |
| 239 | } |
| 240 | |
Hans-Christian Egtvedt | 35bf50c | 2007-12-19 09:29:19 +0100 | [diff] [blame] | 241 | static long pll1_set_rate(struct clk *clk, unsigned long rate, int apply) |
| 242 | { |
| 243 | u32 ctrl = 0; |
| 244 | unsigned long actual_rate; |
| 245 | |
| 246 | actual_rate = pll_set_rate(clk, rate, &ctrl); |
| 247 | |
| 248 | if (apply) { |
| 249 | if (actual_rate != rate) |
| 250 | return -EINVAL; |
| 251 | if (clk->users > 0) |
| 252 | return -EBUSY; |
| 253 | pr_debug(KERN_INFO "clk %s: new rate %lu (actual rate %lu)\n", |
| 254 | clk->name, rate, actual_rate); |
| 255 | pm_writel(PLL1, ctrl); |
| 256 | } |
| 257 | |
| 258 | return actual_rate; |
| 259 | } |
| 260 | |
| 261 | static int pll1_set_parent(struct clk *clk, struct clk *parent) |
| 262 | { |
| 263 | u32 ctrl; |
| 264 | |
| 265 | if (clk->users > 0) |
| 266 | return -EBUSY; |
| 267 | |
| 268 | ctrl = pm_readl(PLL1); |
| 269 | WARN_ON(ctrl & PM_BIT(PLLEN)); |
| 270 | |
| 271 | if (parent == &osc0) |
| 272 | ctrl &= ~PM_BIT(PLLOSC); |
| 273 | else if (parent == &osc1) |
| 274 | ctrl |= PM_BIT(PLLOSC); |
| 275 | else |
| 276 | return -EINVAL; |
| 277 | |
| 278 | pm_writel(PLL1, ctrl); |
| 279 | clk->parent = parent; |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 284 | /* |
| 285 | * The AT32AP7000 has five primary clock sources: One 32kHz |
| 286 | * oscillator, two crystal oscillators and two PLLs. |
| 287 | */ |
| 288 | static struct clk osc32k = { |
| 289 | .name = "osc32k", |
| 290 | .get_rate = osc_get_rate, |
| 291 | .users = 1, |
| 292 | .index = 0, |
| 293 | }; |
| 294 | static struct clk osc0 = { |
| 295 | .name = "osc0", |
| 296 | .get_rate = osc_get_rate, |
| 297 | .users = 1, |
| 298 | .index = 1, |
| 299 | }; |
| 300 | static struct clk osc1 = { |
| 301 | .name = "osc1", |
| 302 | .get_rate = osc_get_rate, |
| 303 | .index = 2, |
| 304 | }; |
| 305 | static struct clk pll0 = { |
| 306 | .name = "pll0", |
| 307 | .get_rate = pll0_get_rate, |
| 308 | .parent = &osc0, |
| 309 | }; |
| 310 | static struct clk pll1 = { |
| 311 | .name = "pll1", |
Hans-Christian Egtvedt | 35bf50c | 2007-12-19 09:29:19 +0100 | [diff] [blame] | 312 | .mode = pll1_mode, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 313 | .get_rate = pll1_get_rate, |
Hans-Christian Egtvedt | 35bf50c | 2007-12-19 09:29:19 +0100 | [diff] [blame] | 314 | .set_rate = pll1_set_rate, |
| 315 | .set_parent = pll1_set_parent, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 316 | .parent = &osc0, |
| 317 | }; |
| 318 | |
| 319 | /* |
| 320 | * The main clock can be either osc0 or pll0. The boot loader may |
| 321 | * have chosen one for us, so we don't really know which one until we |
| 322 | * have a look at the SM. |
| 323 | */ |
| 324 | static struct clk *main_clock; |
| 325 | |
| 326 | /* |
| 327 | * Synchronous clocks are generated from the main clock. The clocks |
| 328 | * must satisfy the constraint |
| 329 | * fCPU >= fHSB >= fPB |
| 330 | * i.e. each clock must not be faster than its parent. |
| 331 | */ |
| 332 | static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift) |
| 333 | { |
| 334 | return main_clock->get_rate(main_clock) >> shift; |
| 335 | }; |
| 336 | |
| 337 | static void cpu_clk_mode(struct clk *clk, int enabled) |
| 338 | { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 339 | unsigned long flags; |
| 340 | u32 mask; |
| 341 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 342 | spin_lock_irqsave(&pm_lock, flags); |
| 343 | mask = pm_readl(CPU_MASK); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 344 | if (enabled) |
| 345 | mask |= 1 << clk->index; |
| 346 | else |
| 347 | mask &= ~(1 << clk->index); |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 348 | pm_writel(CPU_MASK, mask); |
| 349 | spin_unlock_irqrestore(&pm_lock, flags); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static unsigned long cpu_clk_get_rate(struct clk *clk) |
| 353 | { |
| 354 | unsigned long cksel, shift = 0; |
| 355 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 356 | cksel = pm_readl(CKSEL); |
| 357 | if (cksel & PM_BIT(CPUDIV)) |
| 358 | shift = PM_BFEXT(CPUSEL, cksel) + 1; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 359 | |
| 360 | return bus_clk_get_rate(clk, shift); |
| 361 | } |
| 362 | |
Hans-Christian Egtvedt | 9e58e18 | 2007-06-04 16:10:57 +0200 | [diff] [blame] | 363 | static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply) |
| 364 | { |
| 365 | u32 control; |
| 366 | unsigned long parent_rate, child_div, actual_rate, div; |
| 367 | |
| 368 | parent_rate = clk->parent->get_rate(clk->parent); |
| 369 | control = pm_readl(CKSEL); |
| 370 | |
| 371 | if (control & PM_BIT(HSBDIV)) |
| 372 | child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1); |
| 373 | else |
| 374 | child_div = 1; |
| 375 | |
| 376 | if (rate > 3 * (parent_rate / 4) || child_div == 1) { |
| 377 | actual_rate = parent_rate; |
| 378 | control &= ~PM_BIT(CPUDIV); |
| 379 | } else { |
| 380 | unsigned int cpusel; |
| 381 | div = (parent_rate + rate / 2) / rate; |
| 382 | if (div > child_div) |
| 383 | div = child_div; |
| 384 | cpusel = (div > 1) ? (fls(div) - 2) : 0; |
| 385 | control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control); |
| 386 | actual_rate = parent_rate / (1 << (cpusel + 1)); |
| 387 | } |
| 388 | |
| 389 | pr_debug("clk %s: new rate %lu (actual rate %lu)\n", |
| 390 | clk->name, rate, actual_rate); |
| 391 | |
| 392 | if (apply) |
| 393 | pm_writel(CKSEL, control); |
| 394 | |
| 395 | return actual_rate; |
| 396 | } |
| 397 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 398 | static void hsb_clk_mode(struct clk *clk, int enabled) |
| 399 | { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 400 | unsigned long flags; |
| 401 | u32 mask; |
| 402 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 403 | spin_lock_irqsave(&pm_lock, flags); |
| 404 | mask = pm_readl(HSB_MASK); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 405 | if (enabled) |
| 406 | mask |= 1 << clk->index; |
| 407 | else |
| 408 | mask &= ~(1 << clk->index); |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 409 | pm_writel(HSB_MASK, mask); |
| 410 | spin_unlock_irqrestore(&pm_lock, flags); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static unsigned long hsb_clk_get_rate(struct clk *clk) |
| 414 | { |
| 415 | unsigned long cksel, shift = 0; |
| 416 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 417 | cksel = pm_readl(CKSEL); |
| 418 | if (cksel & PM_BIT(HSBDIV)) |
| 419 | shift = PM_BFEXT(HSBSEL, cksel) + 1; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 420 | |
| 421 | return bus_clk_get_rate(clk, shift); |
| 422 | } |
| 423 | |
| 424 | static void pba_clk_mode(struct clk *clk, int enabled) |
| 425 | { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 426 | unsigned long flags; |
| 427 | u32 mask; |
| 428 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 429 | spin_lock_irqsave(&pm_lock, flags); |
| 430 | mask = pm_readl(PBA_MASK); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 431 | if (enabled) |
| 432 | mask |= 1 << clk->index; |
| 433 | else |
| 434 | mask &= ~(1 << clk->index); |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 435 | pm_writel(PBA_MASK, mask); |
| 436 | spin_unlock_irqrestore(&pm_lock, flags); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static unsigned long pba_clk_get_rate(struct clk *clk) |
| 440 | { |
| 441 | unsigned long cksel, shift = 0; |
| 442 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 443 | cksel = pm_readl(CKSEL); |
| 444 | if (cksel & PM_BIT(PBADIV)) |
| 445 | shift = PM_BFEXT(PBASEL, cksel) + 1; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 446 | |
| 447 | return bus_clk_get_rate(clk, shift); |
| 448 | } |
| 449 | |
| 450 | static void pbb_clk_mode(struct clk *clk, int enabled) |
| 451 | { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 452 | unsigned long flags; |
| 453 | u32 mask; |
| 454 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 455 | spin_lock_irqsave(&pm_lock, flags); |
| 456 | mask = pm_readl(PBB_MASK); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 457 | if (enabled) |
| 458 | mask |= 1 << clk->index; |
| 459 | else |
| 460 | mask &= ~(1 << clk->index); |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 461 | pm_writel(PBB_MASK, mask); |
| 462 | spin_unlock_irqrestore(&pm_lock, flags); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | static unsigned long pbb_clk_get_rate(struct clk *clk) |
| 466 | { |
| 467 | unsigned long cksel, shift = 0; |
| 468 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 469 | cksel = pm_readl(CKSEL); |
| 470 | if (cksel & PM_BIT(PBBDIV)) |
| 471 | shift = PM_BFEXT(PBBSEL, cksel) + 1; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 472 | |
| 473 | return bus_clk_get_rate(clk, shift); |
| 474 | } |
| 475 | |
| 476 | static struct clk cpu_clk = { |
| 477 | .name = "cpu", |
| 478 | .get_rate = cpu_clk_get_rate, |
Hans-Christian Egtvedt | 9e58e18 | 2007-06-04 16:10:57 +0200 | [diff] [blame] | 479 | .set_rate = cpu_clk_set_rate, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 480 | .users = 1, |
| 481 | }; |
| 482 | static struct clk hsb_clk = { |
| 483 | .name = "hsb", |
| 484 | .parent = &cpu_clk, |
| 485 | .get_rate = hsb_clk_get_rate, |
| 486 | }; |
| 487 | static struct clk pba_clk = { |
| 488 | .name = "pba", |
| 489 | .parent = &hsb_clk, |
| 490 | .mode = hsb_clk_mode, |
| 491 | .get_rate = pba_clk_get_rate, |
| 492 | .index = 1, |
| 493 | }; |
| 494 | static struct clk pbb_clk = { |
| 495 | .name = "pbb", |
| 496 | .parent = &hsb_clk, |
| 497 | .mode = hsb_clk_mode, |
| 498 | .get_rate = pbb_clk_get_rate, |
| 499 | .users = 1, |
| 500 | .index = 2, |
| 501 | }; |
| 502 | |
| 503 | /* -------------------------------------------------------------------- |
| 504 | * Generic Clock operations |
| 505 | * -------------------------------------------------------------------- */ |
| 506 | |
| 507 | static void genclk_mode(struct clk *clk, int enabled) |
| 508 | { |
| 509 | u32 control; |
| 510 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 511 | control = pm_readl(GCCTRL(clk->index)); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 512 | if (enabled) |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 513 | control |= PM_BIT(CEN); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 514 | else |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 515 | control &= ~PM_BIT(CEN); |
| 516 | pm_writel(GCCTRL(clk->index), control); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static unsigned long genclk_get_rate(struct clk *clk) |
| 520 | { |
| 521 | u32 control; |
| 522 | unsigned long div = 1; |
| 523 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 524 | control = pm_readl(GCCTRL(clk->index)); |
| 525 | if (control & PM_BIT(DIVEN)) |
| 526 | div = 2 * (PM_BFEXT(DIV, control) + 1); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 527 | |
| 528 | return clk->parent->get_rate(clk->parent) / div; |
| 529 | } |
| 530 | |
| 531 | static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply) |
| 532 | { |
| 533 | u32 control; |
| 534 | unsigned long parent_rate, actual_rate, div; |
| 535 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 536 | parent_rate = clk->parent->get_rate(clk->parent); |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 537 | control = pm_readl(GCCTRL(clk->index)); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 538 | |
| 539 | if (rate > 3 * parent_rate / 4) { |
| 540 | actual_rate = parent_rate; |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 541 | control &= ~PM_BIT(DIVEN); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 542 | } else { |
| 543 | div = (parent_rate + rate) / (2 * rate) - 1; |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 544 | control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 545 | actual_rate = parent_rate / (2 * (div + 1)); |
| 546 | } |
| 547 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 548 | dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n", |
| 549 | clk->name, rate, actual_rate); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 550 | |
| 551 | if (apply) |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 552 | pm_writel(GCCTRL(clk->index), control); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 553 | |
| 554 | return actual_rate; |
| 555 | } |
| 556 | |
| 557 | int genclk_set_parent(struct clk *clk, struct clk *parent) |
| 558 | { |
| 559 | u32 control; |
| 560 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 561 | dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n", |
| 562 | clk->name, parent->name, clk->parent->name); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 563 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 564 | control = pm_readl(GCCTRL(clk->index)); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 565 | |
| 566 | if (parent == &osc1 || parent == &pll1) |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 567 | control |= PM_BIT(OSCSEL); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 568 | else if (parent == &osc0 || parent == &pll0) |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 569 | control &= ~PM_BIT(OSCSEL); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 570 | else |
| 571 | return -EINVAL; |
| 572 | |
| 573 | if (parent == &pll0 || parent == &pll1) |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 574 | control |= PM_BIT(PLLSEL); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 575 | else |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 576 | control &= ~PM_BIT(PLLSEL); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 577 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 578 | pm_writel(GCCTRL(clk->index), control); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 579 | clk->parent = parent; |
| 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 584 | static void __init genclk_init_parent(struct clk *clk) |
| 585 | { |
| 586 | u32 control; |
| 587 | struct clk *parent; |
| 588 | |
| 589 | BUG_ON(clk->index > 7); |
| 590 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 591 | control = pm_readl(GCCTRL(clk->index)); |
| 592 | if (control & PM_BIT(OSCSEL)) |
| 593 | parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1; |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 594 | else |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 595 | parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0; |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 596 | |
| 597 | clk->parent = parent; |
| 598 | } |
| 599 | |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 600 | static struct dw_dma_platform_data dw_dmac0_data = { |
| 601 | .nr_channels = 3, |
| 602 | }; |
| 603 | |
| 604 | static struct resource dw_dmac0_resource[] = { |
| 605 | PBMEM(0xff200000), |
| 606 | IRQ(2), |
| 607 | }; |
| 608 | DEFINE_DEV_DATA(dw_dmac, 0); |
| 609 | DEV_CLK(hclk, dw_dmac0, hsb, 10); |
| 610 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 611 | /* -------------------------------------------------------------------- |
| 612 | * System peripherals |
| 613 | * -------------------------------------------------------------------- */ |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 614 | static struct resource at32_pm0_resource[] = { |
| 615 | { |
| 616 | .start = 0xfff00000, |
| 617 | .end = 0xfff0007f, |
| 618 | .flags = IORESOURCE_MEM, |
| 619 | }, |
| 620 | IRQ(20), |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 621 | }; |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 622 | |
| 623 | static struct resource at32ap700x_rtc0_resource[] = { |
| 624 | { |
| 625 | .start = 0xfff00080, |
| 626 | .end = 0xfff000af, |
| 627 | .flags = IORESOURCE_MEM, |
| 628 | }, |
| 629 | IRQ(21), |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 630 | }; |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 631 | |
| 632 | static struct resource at32_wdt0_resource[] = { |
| 633 | { |
| 634 | .start = 0xfff000b0, |
Hans-Christian Egtvedt | 9797bed | 2007-10-30 14:29:50 +0100 | [diff] [blame] | 635 | .end = 0xfff000cf, |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 636 | .flags = IORESOURCE_MEM, |
| 637 | }, |
| 638 | }; |
| 639 | |
| 640 | static struct resource at32_eic0_resource[] = { |
| 641 | { |
| 642 | .start = 0xfff00100, |
| 643 | .end = 0xfff0013f, |
| 644 | .flags = IORESOURCE_MEM, |
| 645 | }, |
| 646 | IRQ(19), |
| 647 | }; |
| 648 | |
| 649 | DEFINE_DEV(at32_pm, 0); |
| 650 | DEFINE_DEV(at32ap700x_rtc, 0); |
| 651 | DEFINE_DEV(at32_wdt, 0); |
| 652 | DEFINE_DEV(at32_eic, 0); |
| 653 | |
| 654 | /* |
| 655 | * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this |
| 656 | * is always running. |
| 657 | */ |
| 658 | static struct clk at32_pm_pclk = { |
Haavard Skinnemoen | 188ff65 | 2007-03-14 13:23:44 +0100 | [diff] [blame] | 659 | .name = "pclk", |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 660 | .dev = &at32_pm0_device.dev, |
Haavard Skinnemoen | 188ff65 | 2007-03-14 13:23:44 +0100 | [diff] [blame] | 661 | .parent = &pbb_clk, |
| 662 | .mode = pbb_clk_mode, |
| 663 | .get_rate = pbb_clk_get_rate, |
| 664 | .users = 1, |
| 665 | .index = 0, |
| 666 | }; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 667 | |
| 668 | static struct resource intc0_resource[] = { |
| 669 | PBMEM(0xfff00400), |
| 670 | }; |
| 671 | struct platform_device at32_intc0_device = { |
| 672 | .name = "intc", |
| 673 | .id = 0, |
| 674 | .resource = intc0_resource, |
| 675 | .num_resources = ARRAY_SIZE(intc0_resource), |
| 676 | }; |
| 677 | DEV_CLK(pclk, at32_intc0, pbb, 1); |
| 678 | |
| 679 | static struct clk ebi_clk = { |
| 680 | .name = "ebi", |
| 681 | .parent = &hsb_clk, |
| 682 | .mode = hsb_clk_mode, |
| 683 | .get_rate = hsb_clk_get_rate, |
| 684 | .users = 1, |
| 685 | }; |
| 686 | static struct clk hramc_clk = { |
| 687 | .name = "hramc", |
| 688 | .parent = &hsb_clk, |
| 689 | .mode = hsb_clk_mode, |
| 690 | .get_rate = hsb_clk_get_rate, |
| 691 | .users = 1, |
Haavard Skinnemoen | 188ff65 | 2007-03-14 13:23:44 +0100 | [diff] [blame] | 692 | .index = 3, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 693 | }; |
Haavard Skinnemoen | 7951f18 | 2008-03-05 15:08:27 +0100 | [diff] [blame] | 694 | static struct clk sdramc_clk = { |
| 695 | .name = "sdramc_clk", |
| 696 | .parent = &pbb_clk, |
| 697 | .mode = pbb_clk_mode, |
| 698 | .get_rate = pbb_clk_get_rate, |
| 699 | .users = 1, |
| 700 | .index = 14, |
| 701 | }; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 702 | |
Haavard Skinnemoen | bc157b7 | 2006-09-25 23:32:16 -0700 | [diff] [blame] | 703 | static struct resource smc0_resource[] = { |
| 704 | PBMEM(0xfff03400), |
| 705 | }; |
| 706 | DEFINE_DEV(smc, 0); |
| 707 | DEV_CLK(pclk, smc0, pbb, 13); |
| 708 | DEV_CLK(mck, smc0, hsb, 0); |
| 709 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 710 | static struct platform_device pdc_device = { |
| 711 | .name = "pdc", |
| 712 | .id = 0, |
| 713 | }; |
| 714 | DEV_CLK(hclk, pdc, hsb, 4); |
| 715 | DEV_CLK(pclk, pdc, pba, 16); |
| 716 | |
| 717 | static struct clk pico_clk = { |
| 718 | .name = "pico", |
| 719 | .parent = &cpu_clk, |
| 720 | .mode = cpu_clk_mode, |
| 721 | .get_rate = cpu_clk_get_rate, |
| 722 | .users = 1, |
| 723 | }; |
| 724 | |
| 725 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 9c8f8e7 | 2007-02-01 16:34:10 +0100 | [diff] [blame] | 726 | * HMATRIX |
| 727 | * -------------------------------------------------------------------- */ |
| 728 | |
Haavard Skinnemoen | b47eb40 | 2008-07-31 15:56:36 +0200 | [diff] [blame] | 729 | struct clk at32_hmatrix_clk = { |
Haavard Skinnemoen | 9c8f8e7 | 2007-02-01 16:34:10 +0100 | [diff] [blame] | 730 | .name = "hmatrix_clk", |
| 731 | .parent = &pbb_clk, |
| 732 | .mode = pbb_clk_mode, |
| 733 | .get_rate = pbb_clk_get_rate, |
| 734 | .index = 2, |
| 735 | .users = 1, |
| 736 | }; |
Haavard Skinnemoen | 9c8f8e7 | 2007-02-01 16:34:10 +0100 | [diff] [blame] | 737 | |
| 738 | /* |
| 739 | * Set bits in the HMATRIX Special Function Register (SFR) used by the |
| 740 | * External Bus Interface (EBI). This can be used to enable special |
| 741 | * features like CompactFlash support, NAND Flash support, etc. on |
| 742 | * certain chipselects. |
| 743 | */ |
| 744 | static inline void set_ebi_sfr_bits(u32 mask) |
| 745 | { |
Haavard Skinnemoen | b47eb40 | 2008-07-31 15:56:36 +0200 | [diff] [blame] | 746 | hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, mask); |
Haavard Skinnemoen | 9c8f8e7 | 2007-02-01 16:34:10 +0100 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /* -------------------------------------------------------------------- |
David Brownell | e723ff6 | 2008-02-14 11:24:02 -0800 | [diff] [blame] | 750 | * Timer/Counter (TC) |
Hans-Christian Egtvedt | 7760989 | 2007-03-12 18:15:16 +0100 | [diff] [blame] | 751 | * -------------------------------------------------------------------- */ |
David Brownell | e723ff6 | 2008-02-14 11:24:02 -0800 | [diff] [blame] | 752 | |
| 753 | static struct resource at32_tcb0_resource[] = { |
Hans-Christian Egtvedt | 7760989 | 2007-03-12 18:15:16 +0100 | [diff] [blame] | 754 | PBMEM(0xfff00c00), |
| 755 | IRQ(22), |
| 756 | }; |
David Brownell | e723ff6 | 2008-02-14 11:24:02 -0800 | [diff] [blame] | 757 | static struct platform_device at32_tcb0_device = { |
| 758 | .name = "atmel_tcb", |
Hans-Christian Egtvedt | 7760989 | 2007-03-12 18:15:16 +0100 | [diff] [blame] | 759 | .id = 0, |
David Brownell | e723ff6 | 2008-02-14 11:24:02 -0800 | [diff] [blame] | 760 | .resource = at32_tcb0_resource, |
| 761 | .num_resources = ARRAY_SIZE(at32_tcb0_resource), |
Hans-Christian Egtvedt | 7760989 | 2007-03-12 18:15:16 +0100 | [diff] [blame] | 762 | }; |
David Brownell | e723ff6 | 2008-02-14 11:24:02 -0800 | [diff] [blame] | 763 | DEV_CLK(t0_clk, at32_tcb0, pbb, 3); |
| 764 | |
| 765 | static struct resource at32_tcb1_resource[] = { |
| 766 | PBMEM(0xfff01000), |
| 767 | IRQ(23), |
| 768 | }; |
| 769 | static struct platform_device at32_tcb1_device = { |
| 770 | .name = "atmel_tcb", |
| 771 | .id = 1, |
| 772 | .resource = at32_tcb1_resource, |
| 773 | .num_resources = ARRAY_SIZE(at32_tcb1_resource), |
| 774 | }; |
| 775 | DEV_CLK(t0_clk, at32_tcb1, pbb, 4); |
Hans-Christian Egtvedt | 7760989 | 2007-03-12 18:15:16 +0100 | [diff] [blame] | 776 | |
| 777 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 778 | * PIO |
| 779 | * -------------------------------------------------------------------- */ |
| 780 | |
| 781 | static struct resource pio0_resource[] = { |
| 782 | PBMEM(0xffe02800), |
| 783 | IRQ(13), |
| 784 | }; |
| 785 | DEFINE_DEV(pio, 0); |
| 786 | DEV_CLK(mck, pio0, pba, 10); |
| 787 | |
| 788 | static struct resource pio1_resource[] = { |
| 789 | PBMEM(0xffe02c00), |
| 790 | IRQ(14), |
| 791 | }; |
| 792 | DEFINE_DEV(pio, 1); |
| 793 | DEV_CLK(mck, pio1, pba, 11); |
| 794 | |
| 795 | static struct resource pio2_resource[] = { |
| 796 | PBMEM(0xffe03000), |
| 797 | IRQ(15), |
| 798 | }; |
| 799 | DEFINE_DEV(pio, 2); |
| 800 | DEV_CLK(mck, pio2, pba, 12); |
| 801 | |
| 802 | static struct resource pio3_resource[] = { |
| 803 | PBMEM(0xffe03400), |
| 804 | IRQ(16), |
| 805 | }; |
| 806 | DEFINE_DEV(pio, 3); |
| 807 | DEV_CLK(mck, pio3, pba, 13); |
| 808 | |
Haavard Skinnemoen | 7f9f467 | 2007-01-30 11:16:16 +0100 | [diff] [blame] | 809 | static struct resource pio4_resource[] = { |
| 810 | PBMEM(0xffe03800), |
| 811 | IRQ(17), |
| 812 | }; |
| 813 | DEFINE_DEV(pio, 4); |
| 814 | DEV_CLK(mck, pio4, pba, 14); |
| 815 | |
Haavard Skinnemoen | e82c610 | 2008-10-23 14:42:19 +0200 | [diff] [blame^] | 816 | static int __init system_device_init(void) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 817 | { |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 818 | platform_device_register(&at32_pm0_device); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 819 | platform_device_register(&at32_intc0_device); |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 820 | platform_device_register(&at32ap700x_rtc0_device); |
| 821 | platform_device_register(&at32_wdt0_device); |
| 822 | platform_device_register(&at32_eic0_device); |
Haavard Skinnemoen | bc157b7 | 2006-09-25 23:32:16 -0700 | [diff] [blame] | 823 | platform_device_register(&smc0_device); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 824 | platform_device_register(&pdc_device); |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 825 | platform_device_register(&dw_dmac0_device); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 826 | |
David Brownell | e723ff6 | 2008-02-14 11:24:02 -0800 | [diff] [blame] | 827 | platform_device_register(&at32_tcb0_device); |
| 828 | platform_device_register(&at32_tcb1_device); |
Hans-Christian Egtvedt | 7760989 | 2007-03-12 18:15:16 +0100 | [diff] [blame] | 829 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 830 | platform_device_register(&pio0_device); |
| 831 | platform_device_register(&pio1_device); |
| 832 | platform_device_register(&pio2_device); |
| 833 | platform_device_register(&pio3_device); |
Haavard Skinnemoen | 7f9f467 | 2007-01-30 11:16:16 +0100 | [diff] [blame] | 834 | platform_device_register(&pio4_device); |
Haavard Skinnemoen | e82c610 | 2008-10-23 14:42:19 +0200 | [diff] [blame^] | 835 | |
| 836 | return 0; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 837 | } |
Haavard Skinnemoen | e82c610 | 2008-10-23 14:42:19 +0200 | [diff] [blame^] | 838 | core_initcall(system_device_init); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 839 | |
| 840 | /* -------------------------------------------------------------------- |
Hans-Christian Egtvedt | d86d314 | 2008-02-25 11:24:30 +0100 | [diff] [blame] | 841 | * PSIF |
| 842 | * -------------------------------------------------------------------- */ |
| 843 | static struct resource atmel_psif0_resource[] __initdata = { |
| 844 | { |
| 845 | .start = 0xffe03c00, |
| 846 | .end = 0xffe03cff, |
| 847 | .flags = IORESOURCE_MEM, |
| 848 | }, |
| 849 | IRQ(18), |
| 850 | }; |
| 851 | static struct clk atmel_psif0_pclk = { |
| 852 | .name = "pclk", |
| 853 | .parent = &pba_clk, |
| 854 | .mode = pba_clk_mode, |
| 855 | .get_rate = pba_clk_get_rate, |
| 856 | .index = 15, |
| 857 | }; |
| 858 | |
| 859 | static struct resource atmel_psif1_resource[] __initdata = { |
| 860 | { |
| 861 | .start = 0xffe03d00, |
| 862 | .end = 0xffe03dff, |
| 863 | .flags = IORESOURCE_MEM, |
| 864 | }, |
| 865 | IRQ(18), |
| 866 | }; |
| 867 | static struct clk atmel_psif1_pclk = { |
| 868 | .name = "pclk", |
| 869 | .parent = &pba_clk, |
| 870 | .mode = pba_clk_mode, |
| 871 | .get_rate = pba_clk_get_rate, |
| 872 | .index = 15, |
| 873 | }; |
| 874 | |
| 875 | struct platform_device *__init at32_add_device_psif(unsigned int id) |
| 876 | { |
| 877 | struct platform_device *pdev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 878 | u32 pin_mask; |
Hans-Christian Egtvedt | d86d314 | 2008-02-25 11:24:30 +0100 | [diff] [blame] | 879 | |
| 880 | if (!(id == 0 || id == 1)) |
| 881 | return NULL; |
| 882 | |
| 883 | pdev = platform_device_alloc("atmel_psif", id); |
| 884 | if (!pdev) |
| 885 | return NULL; |
| 886 | |
| 887 | switch (id) { |
| 888 | case 0: |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 889 | pin_mask = (1 << 8) | (1 << 9); /* CLOCK & DATA */ |
| 890 | |
Hans-Christian Egtvedt | d86d314 | 2008-02-25 11:24:30 +0100 | [diff] [blame] | 891 | if (platform_device_add_resources(pdev, atmel_psif0_resource, |
| 892 | ARRAY_SIZE(atmel_psif0_resource))) |
| 893 | goto err_add_resources; |
| 894 | atmel_psif0_pclk.dev = &pdev->dev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 895 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); |
Hans-Christian Egtvedt | d86d314 | 2008-02-25 11:24:30 +0100 | [diff] [blame] | 896 | break; |
| 897 | case 1: |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 898 | pin_mask = (1 << 11) | (1 << 12); /* CLOCK & DATA */ |
| 899 | |
Hans-Christian Egtvedt | d86d314 | 2008-02-25 11:24:30 +0100 | [diff] [blame] | 900 | if (platform_device_add_resources(pdev, atmel_psif1_resource, |
| 901 | ARRAY_SIZE(atmel_psif1_resource))) |
| 902 | goto err_add_resources; |
| 903 | atmel_psif1_pclk.dev = &pdev->dev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 904 | select_peripheral(PIOB, pin_mask, PERIPH_A, 0); |
Hans-Christian Egtvedt | d86d314 | 2008-02-25 11:24:30 +0100 | [diff] [blame] | 905 | break; |
| 906 | default: |
| 907 | return NULL; |
| 908 | } |
| 909 | |
| 910 | platform_device_add(pdev); |
| 911 | return pdev; |
| 912 | |
| 913 | err_add_resources: |
| 914 | platform_device_put(pdev); |
| 915 | return NULL; |
| 916 | } |
| 917 | |
| 918 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 919 | * USART |
| 920 | * -------------------------------------------------------------------- */ |
| 921 | |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 922 | static struct atmel_uart_data atmel_usart0_data = { |
| 923 | .use_dma_tx = 1, |
| 924 | .use_dma_rx = 1, |
| 925 | }; |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 926 | static struct resource atmel_usart0_resource[] = { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 927 | PBMEM(0xffe00c00), |
David Brownell | a3d912c8 | 2007-01-23 20:14:02 -0800 | [diff] [blame] | 928 | IRQ(6), |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 929 | }; |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 930 | DEFINE_DEV_DATA(atmel_usart, 0); |
ben.nizette@iinet.net.au | 80f76c5 | 2007-11-07 16:16:22 +0900 | [diff] [blame] | 931 | DEV_CLK(usart, atmel_usart0, pba, 3); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 932 | |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 933 | static struct atmel_uart_data atmel_usart1_data = { |
| 934 | .use_dma_tx = 1, |
| 935 | .use_dma_rx = 1, |
| 936 | }; |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 937 | static struct resource atmel_usart1_resource[] = { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 938 | PBMEM(0xffe01000), |
| 939 | IRQ(7), |
| 940 | }; |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 941 | DEFINE_DEV_DATA(atmel_usart, 1); |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 942 | DEV_CLK(usart, atmel_usart1, pba, 4); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 943 | |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 944 | static struct atmel_uart_data atmel_usart2_data = { |
| 945 | .use_dma_tx = 1, |
| 946 | .use_dma_rx = 1, |
| 947 | }; |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 948 | static struct resource atmel_usart2_resource[] = { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 949 | PBMEM(0xffe01400), |
| 950 | IRQ(8), |
| 951 | }; |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 952 | DEFINE_DEV_DATA(atmel_usart, 2); |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 953 | DEV_CLK(usart, atmel_usart2, pba, 5); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 954 | |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 955 | static struct atmel_uart_data atmel_usart3_data = { |
| 956 | .use_dma_tx = 1, |
| 957 | .use_dma_rx = 1, |
| 958 | }; |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 959 | static struct resource atmel_usart3_resource[] = { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 960 | PBMEM(0xffe01800), |
| 961 | IRQ(9), |
| 962 | }; |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 963 | DEFINE_DEV_DATA(atmel_usart, 3); |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 964 | DEV_CLK(usart, atmel_usart3, pba, 6); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 965 | |
| 966 | static inline void configure_usart0_pins(void) |
| 967 | { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 968 | u32 pin_mask = (1 << 8) | (1 << 9); /* RXD & TXD */ |
| 969 | |
| 970 | select_peripheral(PIOA, pin_mask, PERIPH_B, 0); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | static inline void configure_usart1_pins(void) |
| 974 | { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 975 | u32 pin_mask = (1 << 17) | (1 << 18); /* RXD & TXD */ |
| 976 | |
| 977 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | static inline void configure_usart2_pins(void) |
| 981 | { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 982 | u32 pin_mask = (1 << 26) | (1 << 27); /* RXD & TXD */ |
| 983 | |
| 984 | select_peripheral(PIOB, pin_mask, PERIPH_B, 0); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static inline void configure_usart3_pins(void) |
| 988 | { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 989 | u32 pin_mask = (1 << 18) | (1 << 17); /* RXD & TXD */ |
| 990 | |
| 991 | select_peripheral(PIOB, pin_mask, PERIPH_B, 0); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 992 | } |
| 993 | |
David Brownell | a3d912c8 | 2007-01-23 20:14:02 -0800 | [diff] [blame] | 994 | static struct platform_device *__initdata at32_usarts[4]; |
Haavard Skinnemoen | c194588 | 2006-10-04 16:02:10 +0200 | [diff] [blame] | 995 | |
| 996 | void __init at32_map_usart(unsigned int hw_id, unsigned int line) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 997 | { |
| 998 | struct platform_device *pdev; |
| 999 | |
Haavard Skinnemoen | c194588 | 2006-10-04 16:02:10 +0200 | [diff] [blame] | 1000 | switch (hw_id) { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1001 | case 0: |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 1002 | pdev = &atmel_usart0_device; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1003 | configure_usart0_pins(); |
| 1004 | break; |
| 1005 | case 1: |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 1006 | pdev = &atmel_usart1_device; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1007 | configure_usart1_pins(); |
| 1008 | break; |
| 1009 | case 2: |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 1010 | pdev = &atmel_usart2_device; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1011 | configure_usart2_pins(); |
| 1012 | break; |
| 1013 | case 3: |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 1014 | pdev = &atmel_usart3_device; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1015 | configure_usart3_pins(); |
| 1016 | break; |
| 1017 | default: |
Haavard Skinnemoen | c194588 | 2006-10-04 16:02:10 +0200 | [diff] [blame] | 1018 | return; |
Haavard Skinnemoen | 75d3521 | 2006-10-04 16:02:08 +0200 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | if (PXSEG(pdev->resource[0].start) == P4SEG) { |
| 1022 | /* Addresses in the P4 segment are permanently mapped 1:1 */ |
| 1023 | struct atmel_uart_data *data = pdev->dev.platform_data; |
| 1024 | data->regs = (void __iomem *)pdev->resource[0].start; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Haavard Skinnemoen | c194588 | 2006-10-04 16:02:10 +0200 | [diff] [blame] | 1027 | pdev->id = line; |
| 1028 | at32_usarts[line] = pdev; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | struct platform_device *__init at32_add_device_usart(unsigned int id) |
| 1032 | { |
Haavard Skinnemoen | c194588 | 2006-10-04 16:02:10 +0200 | [diff] [blame] | 1033 | platform_device_register(at32_usarts[id]); |
| 1034 | return at32_usarts[id]; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Haavard Skinnemoen | 73e2798 | 2006-10-04 16:02:04 +0200 | [diff] [blame] | 1037 | struct platform_device *atmel_default_console_device; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1038 | |
| 1039 | void __init at32_setup_serial_console(unsigned int usart_id) |
| 1040 | { |
Haavard Skinnemoen | c194588 | 2006-10-04 16:02:10 +0200 | [diff] [blame] | 1041 | atmel_default_console_device = at32_usarts[usart_id]; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | /* -------------------------------------------------------------------- |
| 1045 | * Ethernet |
| 1046 | * -------------------------------------------------------------------- */ |
| 1047 | |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 1048 | #ifdef CONFIG_CPU_AT32AP7000 |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1049 | static struct eth_platform_data macb0_data; |
| 1050 | static struct resource macb0_resource[] = { |
| 1051 | PBMEM(0xfff01800), |
| 1052 | IRQ(25), |
| 1053 | }; |
| 1054 | DEFINE_DEV_DATA(macb, 0); |
| 1055 | DEV_CLK(hclk, macb0, hsb, 8); |
| 1056 | DEV_CLK(pclk, macb0, pbb, 6); |
| 1057 | |
Haavard Skinnemoen | cfcb3a8 | 2006-10-30 09:23:12 +0100 | [diff] [blame] | 1058 | static struct eth_platform_data macb1_data; |
| 1059 | static struct resource macb1_resource[] = { |
| 1060 | PBMEM(0xfff01c00), |
| 1061 | IRQ(26), |
| 1062 | }; |
| 1063 | DEFINE_DEV_DATA(macb, 1); |
| 1064 | DEV_CLK(hclk, macb1, hsb, 9); |
| 1065 | DEV_CLK(pclk, macb1, pbb, 7); |
| 1066 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1067 | struct platform_device *__init |
| 1068 | at32_add_device_eth(unsigned int id, struct eth_platform_data *data) |
| 1069 | { |
| 1070 | struct platform_device *pdev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1071 | u32 pin_mask; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1072 | |
| 1073 | switch (id) { |
| 1074 | case 0: |
| 1075 | pdev = &macb0_device; |
| 1076 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1077 | pin_mask = (1 << 3); /* TXD0 */ |
| 1078 | pin_mask |= (1 << 4); /* TXD1 */ |
| 1079 | pin_mask |= (1 << 7); /* TXEN */ |
| 1080 | pin_mask |= (1 << 8); /* TXCK */ |
| 1081 | pin_mask |= (1 << 9); /* RXD0 */ |
| 1082 | pin_mask |= (1 << 10); /* RXD1 */ |
| 1083 | pin_mask |= (1 << 13); /* RXER */ |
| 1084 | pin_mask |= (1 << 15); /* RXDV */ |
| 1085 | pin_mask |= (1 << 16); /* MDC */ |
| 1086 | pin_mask |= (1 << 17); /* MDIO */ |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1087 | |
| 1088 | if (!data->is_rmii) { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1089 | pin_mask |= (1 << 0); /* COL */ |
| 1090 | pin_mask |= (1 << 1); /* CRS */ |
| 1091 | pin_mask |= (1 << 2); /* TXER */ |
| 1092 | pin_mask |= (1 << 5); /* TXD2 */ |
| 1093 | pin_mask |= (1 << 6); /* TXD3 */ |
| 1094 | pin_mask |= (1 << 11); /* RXD2 */ |
| 1095 | pin_mask |= (1 << 12); /* RXD3 */ |
| 1096 | pin_mask |= (1 << 14); /* RXCK */ |
| 1097 | pin_mask |= (1 << 18); /* SPD */ |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1098 | } |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1099 | |
| 1100 | select_peripheral(PIOC, pin_mask, PERIPH_A, 0); |
| 1101 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1102 | break; |
| 1103 | |
Haavard Skinnemoen | cfcb3a8 | 2006-10-30 09:23:12 +0100 | [diff] [blame] | 1104 | case 1: |
| 1105 | pdev = &macb1_device; |
| 1106 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1107 | pin_mask = (1 << 13); /* TXD0 */ |
| 1108 | pin_mask |= (1 << 14); /* TXD1 */ |
| 1109 | pin_mask |= (1 << 11); /* TXEN */ |
| 1110 | pin_mask |= (1 << 12); /* TXCK */ |
| 1111 | pin_mask |= (1 << 10); /* RXD0 */ |
| 1112 | pin_mask |= (1 << 6); /* RXD1 */ |
| 1113 | pin_mask |= (1 << 5); /* RXER */ |
| 1114 | pin_mask |= (1 << 4); /* RXDV */ |
| 1115 | pin_mask |= (1 << 3); /* MDC */ |
| 1116 | pin_mask |= (1 << 2); /* MDIO */ |
| 1117 | |
| 1118 | if (!data->is_rmii) |
| 1119 | pin_mask |= (1 << 15); /* SPD */ |
| 1120 | |
| 1121 | select_peripheral(PIOD, pin_mask, PERIPH_B, 0); |
Haavard Skinnemoen | cfcb3a8 | 2006-10-30 09:23:12 +0100 | [diff] [blame] | 1122 | |
| 1123 | if (!data->is_rmii) { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1124 | pin_mask = (1 << 19); /* COL */ |
| 1125 | pin_mask |= (1 << 23); /* CRS */ |
| 1126 | pin_mask |= (1 << 26); /* TXER */ |
| 1127 | pin_mask |= (1 << 27); /* TXD2 */ |
| 1128 | pin_mask |= (1 << 28); /* TXD3 */ |
| 1129 | pin_mask |= (1 << 29); /* RXD2 */ |
| 1130 | pin_mask |= (1 << 30); /* RXD3 */ |
| 1131 | pin_mask |= (1 << 24); /* RXCK */ |
| 1132 | |
| 1133 | select_peripheral(PIOC, pin_mask, PERIPH_B, 0); |
Haavard Skinnemoen | cfcb3a8 | 2006-10-30 09:23:12 +0100 | [diff] [blame] | 1134 | } |
| 1135 | break; |
| 1136 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1137 | default: |
| 1138 | return NULL; |
| 1139 | } |
| 1140 | |
| 1141 | memcpy(pdev->dev.platform_data, data, sizeof(struct eth_platform_data)); |
| 1142 | platform_device_register(pdev); |
| 1143 | |
| 1144 | return pdev; |
| 1145 | } |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 1146 | #endif |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1147 | |
| 1148 | /* -------------------------------------------------------------------- |
| 1149 | * SPI |
| 1150 | * -------------------------------------------------------------------- */ |
Haavard Skinnemoen | 3d60ee1 | 2007-01-10 20:20:02 +0100 | [diff] [blame] | 1151 | static struct resource atmel_spi0_resource[] = { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1152 | PBMEM(0xffe00000), |
| 1153 | IRQ(3), |
| 1154 | }; |
Haavard Skinnemoen | 3d60ee1 | 2007-01-10 20:20:02 +0100 | [diff] [blame] | 1155 | DEFINE_DEV(atmel_spi, 0); |
| 1156 | DEV_CLK(spi_clk, atmel_spi0, pba, 0); |
| 1157 | |
| 1158 | static struct resource atmel_spi1_resource[] = { |
| 1159 | PBMEM(0xffe00400), |
| 1160 | IRQ(4), |
| 1161 | }; |
| 1162 | DEFINE_DEV(atmel_spi, 1); |
| 1163 | DEV_CLK(spi_clk, atmel_spi1, pba, 1); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1164 | |
Haavard Skinnemoen | 9a596a6 | 2007-02-19 10:38:04 +0100 | [diff] [blame] | 1165 | static void __init |
Haavard Skinnemoen | 41d8ca4 | 2007-02-16 13:56:11 +0100 | [diff] [blame] | 1166 | at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, |
| 1167 | unsigned int n, const u8 *pins) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1168 | { |
Haavard Skinnemoen | 41d8ca4 | 2007-02-16 13:56:11 +0100 | [diff] [blame] | 1169 | unsigned int pin, mode; |
| 1170 | |
| 1171 | for (; n; n--, b++) { |
| 1172 | b->bus_num = bus_num; |
| 1173 | if (b->chip_select >= 4) |
| 1174 | continue; |
| 1175 | pin = (unsigned)b->controller_data; |
| 1176 | if (!pin) { |
| 1177 | pin = pins[b->chip_select]; |
| 1178 | b->controller_data = (void *)pin; |
| 1179 | } |
| 1180 | mode = AT32_GPIOF_OUTPUT; |
| 1181 | if (!(b->mode & SPI_CS_HIGH)) |
| 1182 | mode |= AT32_GPIOF_HIGH; |
| 1183 | at32_select_gpio(pin, mode); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | struct platform_device *__init |
| 1188 | at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) |
| 1189 | { |
| 1190 | /* |
| 1191 | * Manage the chipselects as GPIOs, normally using the same pins |
| 1192 | * the SPI controller expects; but boards can use other pins. |
| 1193 | */ |
| 1194 | static u8 __initdata spi0_pins[] = |
| 1195 | { GPIO_PIN_PA(3), GPIO_PIN_PA(4), |
| 1196 | GPIO_PIN_PA(5), GPIO_PIN_PA(20), }; |
| 1197 | static u8 __initdata spi1_pins[] = |
| 1198 | { GPIO_PIN_PB(2), GPIO_PIN_PB(3), |
| 1199 | GPIO_PIN_PB(4), GPIO_PIN_PA(27), }; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1200 | struct platform_device *pdev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1201 | u32 pin_mask; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1202 | |
| 1203 | switch (id) { |
| 1204 | case 0: |
Haavard Skinnemoen | 3d60ee1 | 2007-01-10 20:20:02 +0100 | [diff] [blame] | 1205 | pdev = &atmel_spi0_device; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1206 | pin_mask = (1 << 1) | (1 << 2); /* MOSI & SCK */ |
| 1207 | |
David Brownell | 9c2baf7 | 2008-06-18 02:31:43 -0700 | [diff] [blame] | 1208 | /* pullup MISO so a level is always defined */ |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1209 | select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP); |
| 1210 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); |
| 1211 | |
Haavard Skinnemoen | 41d8ca4 | 2007-02-16 13:56:11 +0100 | [diff] [blame] | 1212 | at32_spi_setup_slaves(0, b, n, spi0_pins); |
Haavard Skinnemoen | 3d60ee1 | 2007-01-10 20:20:02 +0100 | [diff] [blame] | 1213 | break; |
| 1214 | |
| 1215 | case 1: |
| 1216 | pdev = &atmel_spi1_device; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1217 | pin_mask = (1 << 1) | (1 << 5); /* MOSI */ |
| 1218 | |
David Brownell | 9c2baf7 | 2008-06-18 02:31:43 -0700 | [diff] [blame] | 1219 | /* pullup MISO so a level is always defined */ |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1220 | select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP); |
| 1221 | select_peripheral(PIOB, pin_mask, PERIPH_B, 0); |
| 1222 | |
Haavard Skinnemoen | 41d8ca4 | 2007-02-16 13:56:11 +0100 | [diff] [blame] | 1223 | at32_spi_setup_slaves(1, b, n, spi1_pins); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1224 | break; |
| 1225 | |
| 1226 | default: |
| 1227 | return NULL; |
| 1228 | } |
| 1229 | |
Haavard Skinnemoen | 41d8ca4 | 2007-02-16 13:56:11 +0100 | [diff] [blame] | 1230 | spi_register_board_info(b, n); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1231 | platform_device_register(pdev); |
| 1232 | return pdev; |
| 1233 | } |
| 1234 | |
| 1235 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1236 | * TWI |
| 1237 | * -------------------------------------------------------------------- */ |
| 1238 | static struct resource atmel_twi0_resource[] __initdata = { |
| 1239 | PBMEM(0xffe00800), |
| 1240 | IRQ(5), |
| 1241 | }; |
| 1242 | static struct clk atmel_twi0_pclk = { |
| 1243 | .name = "twi_pclk", |
| 1244 | .parent = &pba_clk, |
| 1245 | .mode = pba_clk_mode, |
| 1246 | .get_rate = pba_clk_get_rate, |
| 1247 | .index = 2, |
| 1248 | }; |
| 1249 | |
Ben Nizette | 040b28f | 2008-02-07 15:28:57 +1100 | [diff] [blame] | 1250 | struct platform_device *__init at32_add_device_twi(unsigned int id, |
| 1251 | struct i2c_board_info *b, |
| 1252 | unsigned int n) |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1253 | { |
| 1254 | struct platform_device *pdev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1255 | u32 pin_mask; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1256 | |
| 1257 | if (id != 0) |
| 1258 | return NULL; |
| 1259 | |
| 1260 | pdev = platform_device_alloc("atmel_twi", id); |
| 1261 | if (!pdev) |
| 1262 | return NULL; |
| 1263 | |
| 1264 | if (platform_device_add_resources(pdev, atmel_twi0_resource, |
| 1265 | ARRAY_SIZE(atmel_twi0_resource))) |
| 1266 | goto err_add_resources; |
| 1267 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1268 | pin_mask = (1 << 6) | (1 << 7); /* SDA & SDL */ |
| 1269 | |
| 1270 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1271 | |
| 1272 | atmel_twi0_pclk.dev = &pdev->dev; |
| 1273 | |
Ben Nizette | 040b28f | 2008-02-07 15:28:57 +1100 | [diff] [blame] | 1274 | if (b) |
| 1275 | i2c_register_board_info(id, b, n); |
| 1276 | |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1277 | platform_device_add(pdev); |
| 1278 | return pdev; |
| 1279 | |
| 1280 | err_add_resources: |
| 1281 | platform_device_put(pdev); |
| 1282 | return NULL; |
| 1283 | } |
| 1284 | |
| 1285 | /* -------------------------------------------------------------------- |
| 1286 | * MMC |
| 1287 | * -------------------------------------------------------------------- */ |
| 1288 | static struct resource atmel_mci0_resource[] __initdata = { |
| 1289 | PBMEM(0xfff02400), |
| 1290 | IRQ(28), |
| 1291 | }; |
| 1292 | static struct clk atmel_mci0_pclk = { |
| 1293 | .name = "mci_clk", |
| 1294 | .parent = &pbb_clk, |
| 1295 | .mode = pbb_clk_mode, |
| 1296 | .get_rate = pbb_clk_get_rate, |
| 1297 | .index = 9, |
| 1298 | }; |
| 1299 | |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 1300 | struct platform_device *__init |
| 1301 | at32_add_device_mci(unsigned int id, struct mci_platform_data *data) |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1302 | { |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 1303 | struct platform_device *pdev; |
Haavard Skinnemoen | 65e8b08 | 2008-07-30 20:29:03 +0200 | [diff] [blame] | 1304 | struct dw_dma_slave *dws; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1305 | u32 pioa_mask; |
| 1306 | u32 piob_mask; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1307 | |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1308 | if (id != 0 || !data) |
| 1309 | return NULL; |
| 1310 | |
| 1311 | /* Must have at least one usable slot */ |
| 1312 | if (!data->slot[0].bus_width && !data->slot[1].bus_width) |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1313 | return NULL; |
| 1314 | |
| 1315 | pdev = platform_device_alloc("atmel_mci", id); |
| 1316 | if (!pdev) |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 1317 | goto fail; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1318 | |
| 1319 | if (platform_device_add_resources(pdev, atmel_mci0_resource, |
| 1320 | ARRAY_SIZE(atmel_mci0_resource))) |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 1321 | goto fail; |
| 1322 | |
Haavard Skinnemoen | 65e8b08 | 2008-07-30 20:29:03 +0200 | [diff] [blame] | 1323 | if (data->dma_slave) |
| 1324 | dws = kmemdup(to_dw_dma_slave(data->dma_slave), |
| 1325 | sizeof(struct dw_dma_slave), GFP_KERNEL); |
| 1326 | else |
| 1327 | dws = kzalloc(sizeof(struct dw_dma_slave), GFP_KERNEL); |
| 1328 | |
| 1329 | dws->slave.dev = &pdev->dev; |
| 1330 | dws->slave.dma_dev = &dw_dmac0_device.dev; |
| 1331 | dws->slave.reg_width = DMA_SLAVE_WIDTH_32BIT; |
| 1332 | dws->cfg_hi = (DWC_CFGH_SRC_PER(0) |
| 1333 | | DWC_CFGH_DST_PER(1)); |
| 1334 | dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL |
| 1335 | | DWC_CFGL_HS_SRC_POL); |
| 1336 | |
| 1337 | data->dma_slave = &dws->slave; |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 1338 | |
| 1339 | if (platform_device_add_data(pdev, data, |
| 1340 | sizeof(struct mci_platform_data))) |
| 1341 | goto fail; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1342 | |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1343 | /* CLK line is common to both slots */ |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1344 | pioa_mask = 1 << 10; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1345 | |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1346 | switch (data->slot[0].bus_width) { |
| 1347 | case 4: |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1348 | pioa_mask |= 1 << 13; /* DATA1 */ |
| 1349 | pioa_mask |= 1 << 14; /* DATA2 */ |
| 1350 | pioa_mask |= 1 << 15; /* DATA3 */ |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1351 | /* fall through */ |
| 1352 | case 1: |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1353 | pioa_mask |= 1 << 11; /* CMD */ |
| 1354 | pioa_mask |= 1 << 12; /* DATA0 */ |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1355 | |
| 1356 | if (gpio_is_valid(data->slot[0].detect_pin)) |
| 1357 | at32_select_gpio(data->slot[0].detect_pin, 0); |
| 1358 | if (gpio_is_valid(data->slot[0].wp_pin)) |
| 1359 | at32_select_gpio(data->slot[0].wp_pin, 0); |
| 1360 | break; |
| 1361 | case 0: |
| 1362 | /* Slot is unused */ |
| 1363 | break; |
| 1364 | default: |
| 1365 | goto fail; |
| 1366 | } |
| 1367 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1368 | select_peripheral(PIOA, pioa_mask, PERIPH_A, 0); |
| 1369 | piob_mask = 0; |
| 1370 | |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1371 | switch (data->slot[1].bus_width) { |
| 1372 | case 4: |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1373 | piob_mask |= 1 << 8; /* DATA1 */ |
| 1374 | piob_mask |= 1 << 9; /* DATA2 */ |
| 1375 | piob_mask |= 1 << 10; /* DATA3 */ |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1376 | /* fall through */ |
| 1377 | case 1: |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1378 | piob_mask |= 1 << 6; /* CMD */ |
| 1379 | piob_mask |= 1 << 7; /* DATA0 */ |
| 1380 | select_peripheral(PIOB, piob_mask, PERIPH_B, 0); |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 1381 | |
| 1382 | if (gpio_is_valid(data->slot[1].detect_pin)) |
| 1383 | at32_select_gpio(data->slot[1].detect_pin, 0); |
| 1384 | if (gpio_is_valid(data->slot[1].wp_pin)) |
| 1385 | at32_select_gpio(data->slot[1].wp_pin, 0); |
| 1386 | break; |
| 1387 | case 0: |
| 1388 | /* Slot is unused */ |
| 1389 | break; |
| 1390 | default: |
| 1391 | if (!data->slot[0].bus_width) |
| 1392 | goto fail; |
| 1393 | |
| 1394 | data->slot[1].bus_width = 0; |
| 1395 | break; |
| 1396 | } |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 1397 | |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1398 | atmel_mci0_pclk.dev = &pdev->dev; |
| 1399 | |
| 1400 | platform_device_add(pdev); |
| 1401 | return pdev; |
| 1402 | |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 1403 | fail: |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1404 | platform_device_put(pdev); |
| 1405 | return NULL; |
| 1406 | } |
| 1407 | |
| 1408 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1409 | * LCDC |
| 1410 | * -------------------------------------------------------------------- */ |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 1411 | #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002) |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1412 | static struct atmel_lcdfb_info atmel_lcdfb0_data; |
| 1413 | static struct resource atmel_lcdfb0_resource[] = { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1414 | { |
| 1415 | .start = 0xff000000, |
| 1416 | .end = 0xff000fff, |
| 1417 | .flags = IORESOURCE_MEM, |
| 1418 | }, |
| 1419 | IRQ(1), |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1420 | { |
| 1421 | /* Placeholder for pre-allocated fb memory */ |
| 1422 | .start = 0x00000000, |
| 1423 | .end = 0x00000000, |
| 1424 | .flags = 0, |
| 1425 | }, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1426 | }; |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1427 | DEFINE_DEV_DATA(atmel_lcdfb, 0); |
| 1428 | DEV_CLK(hck1, atmel_lcdfb0, hsb, 7); |
| 1429 | static struct clk atmel_lcdfb0_pixclk = { |
| 1430 | .name = "lcdc_clk", |
| 1431 | .dev = &atmel_lcdfb0_device.dev, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1432 | .mode = genclk_mode, |
| 1433 | .get_rate = genclk_get_rate, |
| 1434 | .set_rate = genclk_set_rate, |
| 1435 | .set_parent = genclk_set_parent, |
| 1436 | .index = 7, |
| 1437 | }; |
| 1438 | |
| 1439 | struct platform_device *__init |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1440 | at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data, |
Hans-Christian Egtvedt | 47882cf | 2008-02-05 15:27:16 +0100 | [diff] [blame] | 1441 | unsigned long fbmem_start, unsigned long fbmem_len, |
Julien May | 7066412 | 2008-08-04 14:27:38 +0200 | [diff] [blame] | 1442 | u64 pin_mask) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1443 | { |
| 1444 | struct platform_device *pdev; |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1445 | struct atmel_lcdfb_info *info; |
| 1446 | struct fb_monspecs *monspecs; |
| 1447 | struct fb_videomode *modedb; |
| 1448 | unsigned int modedb_size; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1449 | u32 portc_mask, portd_mask, porte_mask; |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1450 | |
| 1451 | /* |
| 1452 | * Do a deep copy of the fb data, monspecs and modedb. Make |
| 1453 | * sure all allocations are done before setting up the |
| 1454 | * portmux. |
| 1455 | */ |
| 1456 | monspecs = kmemdup(data->default_monspecs, |
| 1457 | sizeof(struct fb_monspecs), GFP_KERNEL); |
| 1458 | if (!monspecs) |
| 1459 | return NULL; |
| 1460 | |
| 1461 | modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len; |
| 1462 | modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL); |
| 1463 | if (!modedb) |
| 1464 | goto err_dup_modedb; |
| 1465 | monspecs->modedb = modedb; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1466 | |
| 1467 | switch (id) { |
| 1468 | case 0: |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1469 | pdev = &atmel_lcdfb0_device; |
Hans-Christian Egtvedt | 47882cf | 2008-02-05 15:27:16 +0100 | [diff] [blame] | 1470 | |
Julien May | 7066412 | 2008-08-04 14:27:38 +0200 | [diff] [blame] | 1471 | if (pin_mask == 0ULL) |
| 1472 | /* Default to "full" lcdc control signals and 24bit */ |
| 1473 | pin_mask = ATMEL_LCDC_PRI_24BIT | ATMEL_LCDC_PRI_CONTROL; |
| 1474 | |
| 1475 | /* LCDC on port C */ |
Alex Raimondi | 6090065 | 2008-10-13 16:03:45 +0200 | [diff] [blame] | 1476 | portc_mask = pin_mask & 0xfff80000; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1477 | select_peripheral(PIOC, portc_mask, PERIPH_A, 0); |
Julien May | 7066412 | 2008-08-04 14:27:38 +0200 | [diff] [blame] | 1478 | |
| 1479 | /* LCDC on port D */ |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1480 | portd_mask = pin_mask & 0x0003ffff; |
| 1481 | select_peripheral(PIOD, portd_mask, PERIPH_A, 0); |
Julien May | 7066412 | 2008-08-04 14:27:38 +0200 | [diff] [blame] | 1482 | |
| 1483 | /* LCDC on port E */ |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1484 | porte_mask = (pin_mask >> 32) & 0x0007ffff; |
| 1485 | select_peripheral(PIOE, porte_mask, PERIPH_B, 0); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1486 | |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1487 | clk_set_parent(&atmel_lcdfb0_pixclk, &pll0); |
| 1488 | clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0)); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1489 | break; |
| 1490 | |
| 1491 | default: |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1492 | goto err_invalid_id; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1495 | if (fbmem_len) { |
| 1496 | pdev->resource[2].start = fbmem_start; |
| 1497 | pdev->resource[2].end = fbmem_start + fbmem_len - 1; |
| 1498 | pdev->resource[2].flags = IORESOURCE_MEM; |
| 1499 | } |
| 1500 | |
| 1501 | info = pdev->dev.platform_data; |
| 1502 | memcpy(info, data, sizeof(struct atmel_lcdfb_info)); |
| 1503 | info->default_monspecs = monspecs; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1504 | |
| 1505 | platform_device_register(pdev); |
| 1506 | return pdev; |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 1507 | |
| 1508 | err_invalid_id: |
| 1509 | kfree(modedb); |
| 1510 | err_dup_modedb: |
| 1511 | kfree(monspecs); |
| 1512 | return NULL; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1513 | } |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 1514 | #endif |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1515 | |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 1516 | /* -------------------------------------------------------------------- |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1517 | * PWM |
| 1518 | * -------------------------------------------------------------------- */ |
| 1519 | static struct resource atmel_pwm0_resource[] __initdata = { |
| 1520 | PBMEM(0xfff01400), |
| 1521 | IRQ(24), |
| 1522 | }; |
| 1523 | static struct clk atmel_pwm0_mck = { |
Sedji Gaouaou | 8405996 | 2008-06-25 10:32:50 +0200 | [diff] [blame] | 1524 | .name = "pwm_clk", |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1525 | .parent = &pbb_clk, |
| 1526 | .mode = pbb_clk_mode, |
| 1527 | .get_rate = pbb_clk_get_rate, |
| 1528 | .index = 5, |
| 1529 | }; |
| 1530 | |
| 1531 | struct platform_device *__init at32_add_device_pwm(u32 mask) |
| 1532 | { |
| 1533 | struct platform_device *pdev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1534 | u32 pin_mask; |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1535 | |
| 1536 | if (!mask) |
| 1537 | return NULL; |
| 1538 | |
| 1539 | pdev = platform_device_alloc("atmel_pwm", 0); |
| 1540 | if (!pdev) |
| 1541 | return NULL; |
| 1542 | |
| 1543 | if (platform_device_add_resources(pdev, atmel_pwm0_resource, |
| 1544 | ARRAY_SIZE(atmel_pwm0_resource))) |
| 1545 | goto out_free_pdev; |
| 1546 | |
| 1547 | if (platform_device_add_data(pdev, &mask, sizeof(mask))) |
| 1548 | goto out_free_pdev; |
| 1549 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1550 | pin_mask = 0; |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1551 | if (mask & (1 << 0)) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1552 | pin_mask |= (1 << 28); |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1553 | if (mask & (1 << 1)) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1554 | pin_mask |= (1 << 29); |
| 1555 | if (pin_mask > 0) |
| 1556 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); |
| 1557 | |
| 1558 | pin_mask = 0; |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1559 | if (mask & (1 << 2)) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1560 | pin_mask |= (1 << 21); |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1561 | if (mask & (1 << 3)) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1562 | pin_mask |= (1 << 22); |
| 1563 | if (pin_mask > 0) |
| 1564 | select_peripheral(PIOA, pin_mask, PERIPH_B, 0); |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 1565 | |
| 1566 | atmel_pwm0_mck.dev = &pdev->dev; |
| 1567 | |
| 1568 | platform_device_add(pdev); |
| 1569 | |
| 1570 | return pdev; |
| 1571 | |
| 1572 | out_free_pdev: |
| 1573 | platform_device_put(pdev); |
| 1574 | return NULL; |
| 1575 | } |
| 1576 | |
| 1577 | /* -------------------------------------------------------------------- |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1578 | * SSC |
| 1579 | * -------------------------------------------------------------------- */ |
| 1580 | static struct resource ssc0_resource[] = { |
| 1581 | PBMEM(0xffe01c00), |
| 1582 | IRQ(10), |
| 1583 | }; |
| 1584 | DEFINE_DEV(ssc, 0); |
| 1585 | DEV_CLK(pclk, ssc0, pba, 7); |
| 1586 | |
| 1587 | static struct resource ssc1_resource[] = { |
| 1588 | PBMEM(0xffe02000), |
| 1589 | IRQ(11), |
| 1590 | }; |
| 1591 | DEFINE_DEV(ssc, 1); |
| 1592 | DEV_CLK(pclk, ssc1, pba, 8); |
| 1593 | |
| 1594 | static struct resource ssc2_resource[] = { |
| 1595 | PBMEM(0xffe02400), |
| 1596 | IRQ(12), |
| 1597 | }; |
| 1598 | DEFINE_DEV(ssc, 2); |
| 1599 | DEV_CLK(pclk, ssc2, pba, 9); |
| 1600 | |
| 1601 | struct platform_device *__init |
| 1602 | at32_add_device_ssc(unsigned int id, unsigned int flags) |
| 1603 | { |
| 1604 | struct platform_device *pdev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1605 | u32 pin_mask = 0; |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1606 | |
| 1607 | switch (id) { |
| 1608 | case 0: |
| 1609 | pdev = &ssc0_device; |
| 1610 | if (flags & ATMEL_SSC_RF) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1611 | pin_mask |= (1 << 21); /* RF */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1612 | if (flags & ATMEL_SSC_RK) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1613 | pin_mask |= (1 << 22); /* RK */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1614 | if (flags & ATMEL_SSC_TK) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1615 | pin_mask |= (1 << 23); /* TK */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1616 | if (flags & ATMEL_SSC_TF) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1617 | pin_mask |= (1 << 24); /* TF */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1618 | if (flags & ATMEL_SSC_TD) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1619 | pin_mask |= (1 << 25); /* TD */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1620 | if (flags & ATMEL_SSC_RD) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1621 | pin_mask |= (1 << 26); /* RD */ |
| 1622 | |
| 1623 | if (pin_mask > 0) |
| 1624 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); |
| 1625 | |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1626 | break; |
| 1627 | case 1: |
| 1628 | pdev = &ssc1_device; |
| 1629 | if (flags & ATMEL_SSC_RF) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1630 | pin_mask |= (1 << 0); /* RF */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1631 | if (flags & ATMEL_SSC_RK) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1632 | pin_mask |= (1 << 1); /* RK */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1633 | if (flags & ATMEL_SSC_TK) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1634 | pin_mask |= (1 << 2); /* TK */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1635 | if (flags & ATMEL_SSC_TF) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1636 | pin_mask |= (1 << 3); /* TF */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1637 | if (flags & ATMEL_SSC_TD) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1638 | pin_mask |= (1 << 4); /* TD */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1639 | if (flags & ATMEL_SSC_RD) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1640 | pin_mask |= (1 << 5); /* RD */ |
| 1641 | |
| 1642 | if (pin_mask > 0) |
| 1643 | select_peripheral(PIOA, pin_mask, PERIPH_B, 0); |
| 1644 | |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1645 | break; |
| 1646 | case 2: |
| 1647 | pdev = &ssc2_device; |
| 1648 | if (flags & ATMEL_SSC_TD) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1649 | pin_mask |= (1 << 13); /* TD */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1650 | if (flags & ATMEL_SSC_RD) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1651 | pin_mask |= (1 << 14); /* RD */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1652 | if (flags & ATMEL_SSC_TK) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1653 | pin_mask |= (1 << 15); /* TK */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1654 | if (flags & ATMEL_SSC_TF) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1655 | pin_mask |= (1 << 16); /* TF */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1656 | if (flags & ATMEL_SSC_RF) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1657 | pin_mask |= (1 << 17); /* RF */ |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1658 | if (flags & ATMEL_SSC_RK) |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1659 | pin_mask |= (1 << 18); /* RK */ |
| 1660 | |
| 1661 | if (pin_mask > 0) |
| 1662 | select_peripheral(PIOB, pin_mask, PERIPH_A, 0); |
| 1663 | |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 1664 | break; |
| 1665 | default: |
| 1666 | return NULL; |
| 1667 | } |
| 1668 | |
| 1669 | platform_device_register(pdev); |
| 1670 | return pdev; |
| 1671 | } |
| 1672 | |
| 1673 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 1674 | * USB Device Controller |
| 1675 | * -------------------------------------------------------------------- */ |
| 1676 | static struct resource usba0_resource[] __initdata = { |
| 1677 | { |
| 1678 | .start = 0xff300000, |
| 1679 | .end = 0xff3fffff, |
| 1680 | .flags = IORESOURCE_MEM, |
| 1681 | }, { |
| 1682 | .start = 0xfff03000, |
| 1683 | .end = 0xfff033ff, |
| 1684 | .flags = IORESOURCE_MEM, |
| 1685 | }, |
| 1686 | IRQ(31), |
| 1687 | }; |
| 1688 | static struct clk usba0_pclk = { |
| 1689 | .name = "pclk", |
| 1690 | .parent = &pbb_clk, |
| 1691 | .mode = pbb_clk_mode, |
| 1692 | .get_rate = pbb_clk_get_rate, |
| 1693 | .index = 12, |
| 1694 | }; |
| 1695 | static struct clk usba0_hclk = { |
| 1696 | .name = "hclk", |
| 1697 | .parent = &hsb_clk, |
| 1698 | .mode = hsb_clk_mode, |
| 1699 | .get_rate = hsb_clk_get_rate, |
| 1700 | .index = 6, |
| 1701 | }; |
| 1702 | |
Stelian Pop | 8d85531 | 2008-03-05 00:00:00 +0100 | [diff] [blame] | 1703 | #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \ |
| 1704 | [idx] = { \ |
| 1705 | .name = nam, \ |
| 1706 | .index = idx, \ |
| 1707 | .fifo_size = maxpkt, \ |
| 1708 | .nr_banks = maxbk, \ |
| 1709 | .can_dma = dma, \ |
| 1710 | .can_isoc = isoc, \ |
| 1711 | } |
| 1712 | |
| 1713 | static struct usba_ep_data at32_usba_ep[] __initdata = { |
| 1714 | EP("ep0", 0, 64, 1, 0, 0), |
| 1715 | EP("ep1", 1, 512, 2, 1, 1), |
| 1716 | EP("ep2", 2, 512, 2, 1, 1), |
| 1717 | EP("ep3-int", 3, 64, 3, 1, 0), |
| 1718 | EP("ep4-int", 4, 64, 3, 1, 0), |
| 1719 | EP("ep5", 5, 1024, 3, 1, 1), |
| 1720 | EP("ep6", 6, 1024, 3, 1, 1), |
| 1721 | }; |
| 1722 | |
| 1723 | #undef EP |
| 1724 | |
Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 1725 | struct platform_device *__init |
| 1726 | at32_add_device_usba(unsigned int id, struct usba_platform_data *data) |
| 1727 | { |
Stelian Pop | 8d85531 | 2008-03-05 00:00:00 +0100 | [diff] [blame] | 1728 | /* |
| 1729 | * pdata doesn't have room for any endpoints, so we need to |
| 1730 | * append room for the ones we need right after it. |
| 1731 | */ |
| 1732 | struct { |
| 1733 | struct usba_platform_data pdata; |
| 1734 | struct usba_ep_data ep[7]; |
| 1735 | } usba_data; |
Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 1736 | struct platform_device *pdev; |
| 1737 | |
| 1738 | if (id != 0) |
| 1739 | return NULL; |
| 1740 | |
| 1741 | pdev = platform_device_alloc("atmel_usba_udc", 0); |
| 1742 | if (!pdev) |
| 1743 | return NULL; |
| 1744 | |
| 1745 | if (platform_device_add_resources(pdev, usba0_resource, |
| 1746 | ARRAY_SIZE(usba0_resource))) |
| 1747 | goto out_free_pdev; |
| 1748 | |
Stelian Pop | 8d85531 | 2008-03-05 00:00:00 +0100 | [diff] [blame] | 1749 | if (data) |
| 1750 | usba_data.pdata.vbus_pin = data->vbus_pin; |
| 1751 | else |
| 1752 | usba_data.pdata.vbus_pin = -EINVAL; |
Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 1753 | |
Stelian Pop | 8d85531 | 2008-03-05 00:00:00 +0100 | [diff] [blame] | 1754 | data = &usba_data.pdata; |
| 1755 | data->num_ep = ARRAY_SIZE(at32_usba_ep); |
| 1756 | memcpy(data->ep, at32_usba_ep, sizeof(at32_usba_ep)); |
| 1757 | |
| 1758 | if (platform_device_add_data(pdev, data, sizeof(usba_data))) |
| 1759 | goto out_free_pdev; |
| 1760 | |
| 1761 | if (data->vbus_pin >= 0) |
| 1762 | at32_select_gpio(data->vbus_pin, 0); |
Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 1763 | |
| 1764 | usba0_pclk.dev = &pdev->dev; |
| 1765 | usba0_hclk.dev = &pdev->dev; |
| 1766 | |
| 1767 | platform_device_add(pdev); |
| 1768 | |
| 1769 | return pdev; |
| 1770 | |
| 1771 | out_free_pdev: |
| 1772 | platform_device_put(pdev); |
| 1773 | return NULL; |
| 1774 | } |
| 1775 | |
| 1776 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1777 | * IDE / CompactFlash |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1778 | * -------------------------------------------------------------------- */ |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 1779 | #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7001) |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1780 | static struct resource at32_smc_cs4_resource[] __initdata = { |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1781 | { |
| 1782 | .start = 0x04000000, |
| 1783 | .end = 0x07ffffff, |
| 1784 | .flags = IORESOURCE_MEM, |
| 1785 | }, |
| 1786 | IRQ(~0UL), /* Magic IRQ will be overridden */ |
| 1787 | }; |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1788 | static struct resource at32_smc_cs5_resource[] __initdata = { |
| 1789 | { |
| 1790 | .start = 0x20000000, |
| 1791 | .end = 0x23ffffff, |
| 1792 | .flags = IORESOURCE_MEM, |
| 1793 | }, |
| 1794 | IRQ(~0UL), /* Magic IRQ will be overridden */ |
| 1795 | }; |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1796 | |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1797 | static int __init at32_init_ide_or_cf(struct platform_device *pdev, |
| 1798 | unsigned int cs, unsigned int extint) |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1799 | { |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1800 | static unsigned int extint_pin_map[4] __initdata = { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1801 | (1 << 25), |
| 1802 | (1 << 26), |
| 1803 | (1 << 27), |
| 1804 | (1 << 28), |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1805 | }; |
| 1806 | static bool common_pins_initialized __initdata = false; |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1807 | unsigned int extint_pin; |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1808 | int ret; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1809 | u32 pin_mask; |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1810 | |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1811 | if (extint >= ARRAY_SIZE(extint_pin_map)) |
| 1812 | return -EINVAL; |
| 1813 | extint_pin = extint_pin_map[extint]; |
| 1814 | |
| 1815 | switch (cs) { |
| 1816 | case 4: |
| 1817 | ret = platform_device_add_resources(pdev, |
| 1818 | at32_smc_cs4_resource, |
| 1819 | ARRAY_SIZE(at32_smc_cs4_resource)); |
| 1820 | if (ret) |
| 1821 | return ret; |
| 1822 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1823 | /* NCS4 -> OE_N */ |
| 1824 | select_peripheral(PIOE, (1 << 21), PERIPH_A, 0); |
Haavard Skinnemoen | b47eb40 | 2008-07-31 15:56:36 +0200 | [diff] [blame] | 1825 | hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF0_ENABLE); |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1826 | break; |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1827 | case 5: |
| 1828 | ret = platform_device_add_resources(pdev, |
| 1829 | at32_smc_cs5_resource, |
| 1830 | ARRAY_SIZE(at32_smc_cs5_resource)); |
| 1831 | if (ret) |
| 1832 | return ret; |
| 1833 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1834 | /* NCS5 -> OE_N */ |
| 1835 | select_peripheral(PIOE, (1 << 22), PERIPH_A, 0); |
Haavard Skinnemoen | b47eb40 | 2008-07-31 15:56:36 +0200 | [diff] [blame] | 1836 | hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF1_ENABLE); |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1837 | break; |
| 1838 | default: |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1839 | return -EINVAL; |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1842 | if (!common_pins_initialized) { |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1843 | pin_mask = (1 << 19); /* CFCE1 -> CS0_N */ |
| 1844 | pin_mask |= (1 << 20); /* CFCE2 -> CS1_N */ |
| 1845 | pin_mask |= (1 << 23); /* CFRNW -> DIR */ |
| 1846 | pin_mask |= (1 << 24); /* NWAIT <- IORDY */ |
| 1847 | |
| 1848 | select_peripheral(PIOE, pin_mask, PERIPH_A, 0); |
| 1849 | |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1850 | common_pins_initialized = true; |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1851 | } |
| 1852 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1853 | select_peripheral(PIOB, extint_pin, PERIPH_A, AT32_GPIOF_DEGLITCH); |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1854 | |
| 1855 | pdev->resource[1].start = EIM_IRQ_BASE + extint; |
| 1856 | pdev->resource[1].end = pdev->resource[1].start; |
| 1857 | |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1858 | return 0; |
| 1859 | } |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1860 | |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1861 | struct platform_device *__init |
| 1862 | at32_add_device_ide(unsigned int id, unsigned int extint, |
| 1863 | struct ide_platform_data *data) |
| 1864 | { |
| 1865 | struct platform_device *pdev; |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1866 | |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1867 | pdev = platform_device_alloc("at32_ide", id); |
| 1868 | if (!pdev) |
| 1869 | goto fail; |
| 1870 | |
| 1871 | if (platform_device_add_data(pdev, data, |
| 1872 | sizeof(struct ide_platform_data))) |
| 1873 | goto fail; |
| 1874 | |
| 1875 | if (at32_init_ide_or_cf(pdev, data->cs, extint)) |
| 1876 | goto fail; |
| 1877 | |
| 1878 | platform_device_add(pdev); |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1879 | return pdev; |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1880 | |
| 1881 | fail: |
| 1882 | platform_device_put(pdev); |
| 1883 | return NULL; |
| 1884 | } |
| 1885 | |
| 1886 | struct platform_device *__init |
| 1887 | at32_add_device_cf(unsigned int id, unsigned int extint, |
| 1888 | struct cf_platform_data *data) |
| 1889 | { |
| 1890 | struct platform_device *pdev; |
| 1891 | |
| 1892 | pdev = platform_device_alloc("at32_cf", id); |
| 1893 | if (!pdev) |
| 1894 | goto fail; |
| 1895 | |
| 1896 | if (platform_device_add_data(pdev, data, |
| 1897 | sizeof(struct cf_platform_data))) |
| 1898 | goto fail; |
| 1899 | |
| 1900 | if (at32_init_ide_or_cf(pdev, data->cs, extint)) |
| 1901 | goto fail; |
| 1902 | |
David Brownell | 3c26e17 | 2008-07-27 02:34:45 -0700 | [diff] [blame] | 1903 | if (gpio_is_valid(data->detect_pin)) |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1904 | at32_select_gpio(data->detect_pin, AT32_GPIOF_DEGLITCH); |
David Brownell | 3c26e17 | 2008-07-27 02:34:45 -0700 | [diff] [blame] | 1905 | if (gpio_is_valid(data->reset_pin)) |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1906 | at32_select_gpio(data->reset_pin, 0); |
David Brownell | 3c26e17 | 2008-07-27 02:34:45 -0700 | [diff] [blame] | 1907 | if (gpio_is_valid(data->vcc_pin)) |
Haavard Skinnemoen | eaf5f92 | 2007-10-22 18:32:14 +0200 | [diff] [blame] | 1908 | at32_select_gpio(data->vcc_pin, 0); |
| 1909 | /* READY is used as extint, so we can't select it as gpio */ |
| 1910 | |
| 1911 | platform_device_add(pdev); |
| 1912 | return pdev; |
| 1913 | |
| 1914 | fail: |
| 1915 | platform_device_put(pdev); |
| 1916 | return NULL; |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1917 | } |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 1918 | #endif |
Kristoffer Nyborg Gregertsen | 48021bd | 2007-08-16 13:45:00 +0200 | [diff] [blame] | 1919 | |
| 1920 | /* -------------------------------------------------------------------- |
HÃ¥vard Skinnemoen | 62090a0 | 2008-06-06 18:04:56 +0200 | [diff] [blame] | 1921 | * NAND Flash / SmartMedia |
| 1922 | * -------------------------------------------------------------------- */ |
| 1923 | static struct resource smc_cs3_resource[] __initdata = { |
| 1924 | { |
| 1925 | .start = 0x0c000000, |
| 1926 | .end = 0x0fffffff, |
| 1927 | .flags = IORESOURCE_MEM, |
| 1928 | }, { |
| 1929 | .start = 0xfff03c00, |
| 1930 | .end = 0xfff03fff, |
| 1931 | .flags = IORESOURCE_MEM, |
| 1932 | }, |
| 1933 | }; |
| 1934 | |
| 1935 | struct platform_device *__init |
| 1936 | at32_add_device_nand(unsigned int id, struct atmel_nand_data *data) |
| 1937 | { |
| 1938 | struct platform_device *pdev; |
| 1939 | |
| 1940 | if (id != 0 || !data) |
| 1941 | return NULL; |
| 1942 | |
| 1943 | pdev = platform_device_alloc("atmel_nand", id); |
| 1944 | if (!pdev) |
| 1945 | goto fail; |
| 1946 | |
| 1947 | if (platform_device_add_resources(pdev, smc_cs3_resource, |
| 1948 | ARRAY_SIZE(smc_cs3_resource))) |
| 1949 | goto fail; |
| 1950 | |
| 1951 | if (platform_device_add_data(pdev, data, |
| 1952 | sizeof(struct atmel_nand_data))) |
| 1953 | goto fail; |
| 1954 | |
Haavard Skinnemoen | b47eb40 | 2008-07-31 15:56:36 +0200 | [diff] [blame] | 1955 | hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_NAND_ENABLE); |
HÃ¥vard Skinnemoen | 62090a0 | 2008-06-06 18:04:56 +0200 | [diff] [blame] | 1956 | if (data->enable_pin) |
| 1957 | at32_select_gpio(data->enable_pin, |
| 1958 | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH); |
| 1959 | if (data->rdy_pin) |
| 1960 | at32_select_gpio(data->rdy_pin, 0); |
| 1961 | if (data->det_pin) |
| 1962 | at32_select_gpio(data->det_pin, 0); |
| 1963 | |
| 1964 | platform_device_add(pdev); |
| 1965 | return pdev; |
| 1966 | |
| 1967 | fail: |
| 1968 | platform_device_put(pdev); |
| 1969 | return NULL; |
| 1970 | } |
| 1971 | |
| 1972 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1973 | * AC97C |
| 1974 | * -------------------------------------------------------------------- */ |
| 1975 | static struct resource atmel_ac97c0_resource[] __initdata = { |
| 1976 | PBMEM(0xfff02800), |
| 1977 | IRQ(29), |
| 1978 | }; |
| 1979 | static struct clk atmel_ac97c0_pclk = { |
| 1980 | .name = "pclk", |
| 1981 | .parent = &pbb_clk, |
| 1982 | .mode = pbb_clk_mode, |
| 1983 | .get_rate = pbb_clk_get_rate, |
| 1984 | .index = 10, |
| 1985 | }; |
| 1986 | |
Hans-Christian Egtvedt | 218df4a | 2008-07-01 14:26:45 +0200 | [diff] [blame] | 1987 | struct platform_device *__init |
| 1988 | at32_add_device_ac97c(unsigned int id, struct ac97c_platform_data *data) |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1989 | { |
| 1990 | struct platform_device *pdev; |
Hans-Christian Egtvedt | 218df4a | 2008-07-01 14:26:45 +0200 | [diff] [blame] | 1991 | struct ac97c_platform_data _data; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 1992 | u32 pin_mask; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 1993 | |
| 1994 | if (id != 0) |
| 1995 | return NULL; |
| 1996 | |
| 1997 | pdev = platform_device_alloc("atmel_ac97c", id); |
| 1998 | if (!pdev) |
| 1999 | return NULL; |
| 2000 | |
| 2001 | if (platform_device_add_resources(pdev, atmel_ac97c0_resource, |
| 2002 | ARRAY_SIZE(atmel_ac97c0_resource))) |
Hans-Christian Egtvedt | 218df4a | 2008-07-01 14:26:45 +0200 | [diff] [blame] | 2003 | goto fail; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2004 | |
Hans-Christian Egtvedt | 218df4a | 2008-07-01 14:26:45 +0200 | [diff] [blame] | 2005 | if (!data) { |
| 2006 | data = &_data; |
| 2007 | memset(data, 0, sizeof(struct ac97c_platform_data)); |
| 2008 | data->reset_pin = GPIO_PIN_NONE; |
| 2009 | } |
| 2010 | |
| 2011 | data->dma_rx_periph_id = 3; |
| 2012 | data->dma_tx_periph_id = 4; |
| 2013 | data->dma_controller_id = 0; |
| 2014 | |
| 2015 | if (platform_device_add_data(pdev, data, |
| 2016 | sizeof(struct ac97c_platform_data))) |
| 2017 | goto fail; |
| 2018 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 2019 | pin_mask = (1 << 20) | (1 << 21); /* SDO & SYNC */ |
| 2020 | pin_mask |= (1 << 22) | (1 << 23); /* SCLK & SDI */ |
| 2021 | |
| 2022 | select_peripheral(PIOB, pin_mask, PERIPH_B, 0); |
Hans-Christian Egtvedt | 218df4a | 2008-07-01 14:26:45 +0200 | [diff] [blame] | 2023 | |
| 2024 | /* TODO: gpio_is_valid(data->reset_pin) with kernel 2.6.26. */ |
| 2025 | if (data->reset_pin != GPIO_PIN_NONE) |
| 2026 | at32_select_gpio(data->reset_pin, 0); |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2027 | |
| 2028 | atmel_ac97c0_pclk.dev = &pdev->dev; |
| 2029 | |
| 2030 | platform_device_add(pdev); |
| 2031 | return pdev; |
| 2032 | |
Hans-Christian Egtvedt | 218df4a | 2008-07-01 14:26:45 +0200 | [diff] [blame] | 2033 | fail: |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2034 | platform_device_put(pdev); |
| 2035 | return NULL; |
| 2036 | } |
| 2037 | |
| 2038 | /* -------------------------------------------------------------------- |
| 2039 | * ABDAC |
| 2040 | * -------------------------------------------------------------------- */ |
| 2041 | static struct resource abdac0_resource[] __initdata = { |
| 2042 | PBMEM(0xfff02000), |
| 2043 | IRQ(27), |
| 2044 | }; |
| 2045 | static struct clk abdac0_pclk = { |
| 2046 | .name = "pclk", |
| 2047 | .parent = &pbb_clk, |
| 2048 | .mode = pbb_clk_mode, |
| 2049 | .get_rate = pbb_clk_get_rate, |
| 2050 | .index = 8, |
| 2051 | }; |
| 2052 | static struct clk abdac0_sample_clk = { |
| 2053 | .name = "sample_clk", |
| 2054 | .mode = genclk_mode, |
| 2055 | .get_rate = genclk_get_rate, |
| 2056 | .set_rate = genclk_set_rate, |
| 2057 | .set_parent = genclk_set_parent, |
| 2058 | .index = 6, |
| 2059 | }; |
| 2060 | |
| 2061 | struct platform_device *__init at32_add_device_abdac(unsigned int id) |
| 2062 | { |
| 2063 | struct platform_device *pdev; |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 2064 | u32 pin_mask; |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2065 | |
| 2066 | if (id != 0) |
| 2067 | return NULL; |
| 2068 | |
| 2069 | pdev = platform_device_alloc("abdac", id); |
| 2070 | if (!pdev) |
| 2071 | return NULL; |
| 2072 | |
| 2073 | if (platform_device_add_resources(pdev, abdac0_resource, |
| 2074 | ARRAY_SIZE(abdac0_resource))) |
| 2075 | goto err_add_resources; |
| 2076 | |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 2077 | pin_mask = (1 << 20) | (1 << 22); /* DATA1 & DATAN1 */ |
| 2078 | pin_mask |= (1 << 21) | (1 << 23); /* DATA0 & DATAN0 */ |
| 2079 | |
| 2080 | select_peripheral(PIOB, pin_mask, PERIPH_A, 0); |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2081 | |
| 2082 | abdac0_pclk.dev = &pdev->dev; |
| 2083 | abdac0_sample_clk.dev = &pdev->dev; |
| 2084 | |
| 2085 | platform_device_add(pdev); |
| 2086 | return pdev; |
| 2087 | |
| 2088 | err_add_resources: |
| 2089 | platform_device_put(pdev); |
| 2090 | return NULL; |
| 2091 | } |
| 2092 | |
| 2093 | /* -------------------------------------------------------------------- |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 2094 | * GCLK |
| 2095 | * -------------------------------------------------------------------- */ |
| 2096 | static struct clk gclk0 = { |
| 2097 | .name = "gclk0", |
| 2098 | .mode = genclk_mode, |
| 2099 | .get_rate = genclk_get_rate, |
| 2100 | .set_rate = genclk_set_rate, |
| 2101 | .set_parent = genclk_set_parent, |
| 2102 | .index = 0, |
| 2103 | }; |
| 2104 | static struct clk gclk1 = { |
| 2105 | .name = "gclk1", |
| 2106 | .mode = genclk_mode, |
| 2107 | .get_rate = genclk_get_rate, |
| 2108 | .set_rate = genclk_set_rate, |
| 2109 | .set_parent = genclk_set_parent, |
| 2110 | .index = 1, |
| 2111 | }; |
| 2112 | static struct clk gclk2 = { |
| 2113 | .name = "gclk2", |
| 2114 | .mode = genclk_mode, |
| 2115 | .get_rate = genclk_get_rate, |
| 2116 | .set_rate = genclk_set_rate, |
| 2117 | .set_parent = genclk_set_parent, |
| 2118 | .index = 2, |
| 2119 | }; |
| 2120 | static struct clk gclk3 = { |
| 2121 | .name = "gclk3", |
| 2122 | .mode = genclk_mode, |
| 2123 | .get_rate = genclk_get_rate, |
| 2124 | .set_rate = genclk_set_rate, |
| 2125 | .set_parent = genclk_set_parent, |
| 2126 | .index = 3, |
| 2127 | }; |
| 2128 | static struct clk gclk4 = { |
| 2129 | .name = "gclk4", |
| 2130 | .mode = genclk_mode, |
| 2131 | .get_rate = genclk_get_rate, |
| 2132 | .set_rate = genclk_set_rate, |
| 2133 | .set_parent = genclk_set_parent, |
| 2134 | .index = 4, |
| 2135 | }; |
| 2136 | |
Alex Raimondi | 300bb76 | 2008-09-22 21:40:55 +0200 | [diff] [blame] | 2137 | static __initdata struct clk *init_clocks[] = { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2138 | &osc32k, |
| 2139 | &osc0, |
| 2140 | &osc1, |
| 2141 | &pll0, |
| 2142 | &pll1, |
| 2143 | &cpu_clk, |
| 2144 | &hsb_clk, |
| 2145 | &pba_clk, |
| 2146 | &pbb_clk, |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 2147 | &at32_pm_pclk, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2148 | &at32_intc0_pclk, |
Haavard Skinnemoen | b47eb40 | 2008-07-31 15:56:36 +0200 | [diff] [blame] | 2149 | &at32_hmatrix_clk, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2150 | &ebi_clk, |
| 2151 | &hramc_clk, |
Haavard Skinnemoen | 7951f18 | 2008-03-05 15:08:27 +0100 | [diff] [blame] | 2152 | &sdramc_clk, |
Haavard Skinnemoen | bc157b7 | 2006-09-25 23:32:16 -0700 | [diff] [blame] | 2153 | &smc0_pclk, |
| 2154 | &smc0_mck, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2155 | &pdc_hclk, |
| 2156 | &pdc_pclk, |
Haavard Skinnemoen | 3bfb1d2 | 2008-07-08 11:59:42 -0700 | [diff] [blame] | 2157 | &dw_dmac0_hclk, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2158 | &pico_clk, |
| 2159 | &pio0_mck, |
| 2160 | &pio1_mck, |
| 2161 | &pio2_mck, |
| 2162 | &pio3_mck, |
Haavard Skinnemoen | 7f9f467 | 2007-01-30 11:16:16 +0100 | [diff] [blame] | 2163 | &pio4_mck, |
David Brownell | e723ff6 | 2008-02-14 11:24:02 -0800 | [diff] [blame] | 2164 | &at32_tcb0_t0_clk, |
| 2165 | &at32_tcb1_t0_clk, |
Hans-Christian Egtvedt | d86d314 | 2008-02-25 11:24:30 +0100 | [diff] [blame] | 2166 | &atmel_psif0_pclk, |
| 2167 | &atmel_psif1_pclk, |
Haavard Skinnemoen | 1e8ea80 | 2006-10-04 16:02:03 +0200 | [diff] [blame] | 2168 | &atmel_usart0_usart, |
| 2169 | &atmel_usart1_usart, |
| 2170 | &atmel_usart2_usart, |
| 2171 | &atmel_usart3_usart, |
David Brownell | 9a1e8eb | 2008-02-08 04:21:21 -0800 | [diff] [blame] | 2172 | &atmel_pwm0_mck, |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 2173 | #if defined(CONFIG_CPU_AT32AP7000) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2174 | &macb0_hclk, |
| 2175 | &macb0_pclk, |
Haavard Skinnemoen | cfcb3a8 | 2006-10-30 09:23:12 +0100 | [diff] [blame] | 2176 | &macb1_hclk, |
| 2177 | &macb1_pclk, |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 2178 | #endif |
Haavard Skinnemoen | 3d60ee1 | 2007-01-10 20:20:02 +0100 | [diff] [blame] | 2179 | &atmel_spi0_spi_clk, |
| 2180 | &atmel_spi1_spi_clk, |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2181 | &atmel_twi0_pclk, |
| 2182 | &atmel_mci0_pclk, |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 2183 | #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002) |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 2184 | &atmel_lcdfb0_hck1, |
| 2185 | &atmel_lcdfb0_pixclk, |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 2186 | #endif |
Hans-Christian Egtvedt | 9cf6cf5 | 2007-07-06 14:31:55 +0200 | [diff] [blame] | 2187 | &ssc0_pclk, |
| 2188 | &ssc1_pclk, |
| 2189 | &ssc2_pclk, |
Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 2190 | &usba0_hclk, |
| 2191 | &usba0_pclk, |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2192 | &atmel_ac97c0_pclk, |
| 2193 | &abdac0_pclk, |
| 2194 | &abdac0_sample_clk, |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 2195 | &gclk0, |
| 2196 | &gclk1, |
| 2197 | &gclk2, |
| 2198 | &gclk3, |
| 2199 | &gclk4, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2200 | }; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2201 | |
Haavard Skinnemoen | 65033ed | 2008-03-04 15:15:00 +0100 | [diff] [blame] | 2202 | void __init setup_platform(void) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2203 | { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2204 | u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0; |
| 2205 | int i; |
| 2206 | |
Hans-Christian Egtvedt | 9e58e18 | 2007-06-04 16:10:57 +0200 | [diff] [blame] | 2207 | if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2208 | main_clock = &pll0; |
Hans-Christian Egtvedt | 9e58e18 | 2007-06-04 16:10:57 +0200 | [diff] [blame] | 2209 | cpu_clk.parent = &pll0; |
| 2210 | } else { |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2211 | main_clock = &osc0; |
Hans-Christian Egtvedt | 9e58e18 | 2007-06-04 16:10:57 +0200 | [diff] [blame] | 2212 | cpu_clk.parent = &osc0; |
| 2213 | } |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2214 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 2215 | if (pm_readl(PLL0) & PM_BIT(PLLOSC)) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2216 | pll0.parent = &osc1; |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 2217 | if (pm_readl(PLL1) & PM_BIT(PLLOSC)) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2218 | pll1.parent = &osc1; |
| 2219 | |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 2220 | genclk_init_parent(&gclk0); |
| 2221 | genclk_init_parent(&gclk1); |
| 2222 | genclk_init_parent(&gclk2); |
| 2223 | genclk_init_parent(&gclk3); |
| 2224 | genclk_init_parent(&gclk4); |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 2225 | #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002) |
Haavard Skinnemoen | d0a2b7a | 2007-03-21 18:08:49 +0100 | [diff] [blame] | 2226 | genclk_init_parent(&atmel_lcdfb0_pixclk); |
Haavard Skinnemoen | 438ff3f | 2007-10-29 15:28:07 +0100 | [diff] [blame] | 2227 | #endif |
Haavard Skinnemoen | 2042c1c | 2007-10-22 17:42:35 +0200 | [diff] [blame] | 2228 | genclk_init_parent(&abdac0_sample_clk); |
Haavard Skinnemoen | 7a5fe23 | 2007-02-16 13:14:33 +0100 | [diff] [blame] | 2229 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2230 | /* |
Alex Raimondi | 300bb76 | 2008-09-22 21:40:55 +0200 | [diff] [blame] | 2231 | * Build initial dynamic clock list by registering all clocks |
| 2232 | * from the array. |
| 2233 | * At the same time, turn on all clocks that have at least one |
| 2234 | * user already, and turn off everything else. We only do this |
| 2235 | * for module clocks, and even though it isn't particularly |
| 2236 | * pretty to check the address of the mode function, it should |
| 2237 | * do the trick... |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2238 | */ |
Alex Raimondi | 300bb76 | 2008-09-22 21:40:55 +0200 | [diff] [blame] | 2239 | for (i = 0; i < ARRAY_SIZE(init_clocks); i++) { |
| 2240 | struct clk *clk = init_clocks[i]; |
| 2241 | |
| 2242 | /* first, register clock */ |
| 2243 | at32_clk_register(clk); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2244 | |
Haavard Skinnemoen | 188ff65 | 2007-03-14 13:23:44 +0100 | [diff] [blame] | 2245 | if (clk->users == 0) |
| 2246 | continue; |
| 2247 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2248 | if (clk->mode == &cpu_clk_mode) |
| 2249 | cpu_mask |= 1 << clk->index; |
| 2250 | else if (clk->mode == &hsb_clk_mode) |
| 2251 | hsb_mask |= 1 << clk->index; |
| 2252 | else if (clk->mode == &pba_clk_mode) |
| 2253 | pba_mask |= 1 << clk->index; |
| 2254 | else if (clk->mode == &pbb_clk_mode) |
| 2255 | pbb_mask |= 1 << clk->index; |
| 2256 | } |
| 2257 | |
Haavard Skinnemoen | 7a5b805 | 2007-06-04 12:58:30 +0200 | [diff] [blame] | 2258 | pm_writel(CPU_MASK, cpu_mask); |
| 2259 | pm_writel(HSB_MASK, hsb_mask); |
| 2260 | pm_writel(PBA_MASK, pba_mask); |
| 2261 | pm_writel(PBB_MASK, pbb_mask); |
Haavard Skinnemoen | 65033ed | 2008-03-04 15:15:00 +0100 | [diff] [blame] | 2262 | |
| 2263 | /* Initialize the port muxes */ |
| 2264 | at32_init_pio(&pio0_device); |
| 2265 | at32_init_pio(&pio1_device); |
| 2266 | at32_init_pio(&pio2_device); |
| 2267 | at32_init_pio(&pio3_device); |
| 2268 | at32_init_pio(&pio4_device); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 2269 | } |
Haavard Skinnemoen | b83d6ee1 | 2008-03-05 10:00:28 +0100 | [diff] [blame] | 2270 | |
| 2271 | struct gen_pool *sram_pool; |
| 2272 | |
| 2273 | static int __init sram_init(void) |
| 2274 | { |
| 2275 | struct gen_pool *pool; |
| 2276 | |
| 2277 | /* 1KiB granularity */ |
| 2278 | pool = gen_pool_create(10, -1); |
| 2279 | if (!pool) |
| 2280 | goto fail; |
| 2281 | |
| 2282 | if (gen_pool_add(pool, 0x24000000, 0x8000, -1)) |
| 2283 | goto err_pool_add; |
| 2284 | |
| 2285 | sram_pool = pool; |
| 2286 | return 0; |
| 2287 | |
| 2288 | err_pool_add: |
| 2289 | gen_pool_destroy(pool); |
| 2290 | fail: |
| 2291 | pr_err("Failed to create SRAM pool\n"); |
| 2292 | return -ENOMEM; |
| 2293 | } |
| 2294 | core_initcall(sram_init); |