blob: 2c4aefeb86b57de8da6b7b0875f1bbbc339f33ca [file] [log] [blame]
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001/*
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 Egtvedt35bf50c2007-12-19 09:29:19 +01009#include <linux/delay.h>
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -070010#include <linux/dw_dmac.h>
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +010011#include <linux/fb.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070012#include <linux/init.h>
13#include <linux/platform_device.h>
David Brownell6b84bbf2007-06-22 19:17:57 -070014#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
David Brownell3c26e172008-07-27 02:34:45 -070016#include <linux/gpio.h>
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +010017#include <linux/spi/spi.h>
Stelian Pop8d855312008-03-05 00:00:00 +010018#include <linux/usb/atmel_usba_udc.h>
Nicolas Ferre2635d1b2009-12-14 18:01:30 -080019
20#include <mach/atmel-mci.h>
Nicolas Ferrec42aa772008-11-20 15:59:12 +010021#include <linux/atmel-mci.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070022
23#include <asm/io.h>
Haavard Skinnemoene7ba1762007-10-10 14:58:29 +020024#include <asm/irq.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070025
Haavard Skinnemoen3663b732008-08-05 13:57:38 +020026#include <mach/at32ap700x.h>
27#include <mach/board.h>
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +020028#include <mach/hmatrix.h>
Haavard Skinnemoen3663b732008-08-05 13:57:38 +020029#include <mach/portmux.h>
30#include <mach/sram.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070031
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +010032#include <sound/atmel-abdac.h>
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +010033#include <sound/atmel-ac97c.h>
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +010034
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +010035#include <video/atmel_lcdc.h>
36
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070037#include "clock.h"
38#include "pio.h"
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +020039#include "pm.h"
40
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070041
42#define PBMEM(base) \
43 { \
44 .start = base, \
45 .end = base + 0x3ff, \
46 .flags = IORESOURCE_MEM, \
47 }
48#define IRQ(num) \
49 { \
50 .start = num, \
51 .end = num, \
52 .flags = IORESOURCE_IRQ, \
53 }
54#define NAMED_IRQ(num, _name) \
55 { \
56 .start = num, \
57 .end = num, \
58 .name = _name, \
59 .flags = IORESOURCE_IRQ, \
60 }
61
David Brownell6b84bbf2007-06-22 19:17:57 -070062/* REVISIT these assume *every* device supports DMA, but several
63 * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more.
64 */
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070065#define DEFINE_DEV(_name, _id) \
Yang Hongyang284901a2009-04-06 19:01:15 -070066static u64 _name##_id##_dma_mask = DMA_BIT_MASK(32); \
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070067static struct platform_device _name##_id##_device = { \
68 .name = #_name, \
69 .id = _id, \
70 .dev = { \
David Brownell6b84bbf2007-06-22 19:17:57 -070071 .dma_mask = &_name##_id##_dma_mask, \
Yang Hongyang284901a2009-04-06 19:01:15 -070072 .coherent_dma_mask = DMA_BIT_MASK(32), \
David Brownell6b84bbf2007-06-22 19:17:57 -070073 }, \
74 .resource = _name##_id##_resource, \
75 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
76}
77#define DEFINE_DEV_DATA(_name, _id) \
Yang Hongyang284901a2009-04-06 19:01:15 -070078static u64 _name##_id##_dma_mask = DMA_BIT_MASK(32); \
David Brownell6b84bbf2007-06-22 19:17:57 -070079static struct platform_device _name##_id##_device = { \
80 .name = #_name, \
81 .id = _id, \
82 .dev = { \
83 .dma_mask = &_name##_id##_dma_mask, \
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070084 .platform_data = &_name##_id##_data, \
Yang Hongyang284901a2009-04-06 19:01:15 -070085 .coherent_dma_mask = DMA_BIT_MASK(32), \
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070086 }, \
87 .resource = _name##_id##_resource, \
88 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
89}
90
Julien Maycaf18f12008-09-24 10:30:47 +020091#define select_peripheral(port, pin_mask, periph, flags) \
92 at32_select_periph(GPIO_##port##_BASE, pin_mask, \
93 GPIO_##periph, flags)
Haavard Skinnemoenc3e2a792006-12-04 13:46:52 +010094
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070095#define DEV_CLK(_name, devname, bus, _index) \
96static struct clk devname##_##_name = { \
97 .name = #_name, \
98 .dev = &devname##_device.dev, \
99 .parent = &bus##_clk, \
100 .mode = bus##_clk_mode, \
101 .get_rate = bus##_clk_get_rate, \
102 .index = _index, \
103}
104
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200105static DEFINE_SPINLOCK(pm_lock);
106
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100107static struct clk osc0;
108static struct clk osc1;
109
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700110static unsigned long osc_get_rate(struct clk *clk)
111{
Alex60ed7952008-03-17 14:55:06 +0100112 return at32_board_osc_rates[clk->index];
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700113}
114
115static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
116{
117 unsigned long div, mul, rate;
118
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200119 div = PM_BFEXT(PLLDIV, control) + 1;
120 mul = PM_BFEXT(PLLMUL, control) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700121
122 rate = clk->parent->get_rate(clk->parent);
123 rate = (rate + div / 2) / div;
124 rate *= mul;
125
126 return rate;
127}
128
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100129static long pll_set_rate(struct clk *clk, unsigned long rate,
130 u32 *pll_ctrl)
131{
132 unsigned long mul;
133 unsigned long mul_best_fit = 0;
134 unsigned long div;
135 unsigned long div_min;
136 unsigned long div_max;
137 unsigned long div_best_fit = 0;
138 unsigned long base;
139 unsigned long pll_in;
140 unsigned long actual = 0;
141 unsigned long rate_error;
142 unsigned long rate_error_prev = ~0UL;
143 u32 ctrl;
144
145 /* Rate must be between 80 MHz and 200 Mhz. */
146 if (rate < 80000000UL || rate > 200000000UL)
147 return -EINVAL;
148
149 ctrl = PM_BF(PLLOPT, 4);
150 base = clk->parent->get_rate(clk->parent);
151
152 /* PLL input frequency must be between 6 MHz and 32 MHz. */
153 div_min = DIV_ROUND_UP(base, 32000000UL);
154 div_max = base / 6000000UL;
155
156 if (div_max < div_min)
157 return -EINVAL;
158
159 for (div = div_min; div <= div_max; div++) {
160 pll_in = (base + div / 2) / div;
161 mul = (rate + pll_in / 2) / pll_in;
162
163 if (mul == 0)
164 continue;
165
166 actual = pll_in * mul;
167 rate_error = abs(actual - rate);
168
169 if (rate_error < rate_error_prev) {
170 mul_best_fit = mul;
171 div_best_fit = div;
172 rate_error_prev = rate_error;
173 }
174
175 if (rate_error == 0)
176 break;
177 }
178
179 if (div_best_fit == 0)
180 return -EINVAL;
181
182 ctrl |= PM_BF(PLLMUL, mul_best_fit - 1);
183 ctrl |= PM_BF(PLLDIV, div_best_fit - 1);
184 ctrl |= PM_BF(PLLCOUNT, 16);
185
186 if (clk->parent == &osc1)
187 ctrl |= PM_BIT(PLLOSC);
188
189 *pll_ctrl = ctrl;
190
191 return actual;
192}
193
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700194static unsigned long pll0_get_rate(struct clk *clk)
195{
196 u32 control;
197
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200198 control = pm_readl(PLL0);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700199
200 return pll_get_rate(clk, control);
201}
202
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100203static void pll1_mode(struct clk *clk, int enabled)
204{
205 unsigned long timeout;
206 u32 status;
207 u32 ctrl;
208
209 ctrl = pm_readl(PLL1);
210
211 if (enabled) {
212 if (!PM_BFEXT(PLLMUL, ctrl) && !PM_BFEXT(PLLDIV, ctrl)) {
213 pr_debug("clk %s: failed to enable, rate not set\n",
214 clk->name);
215 return;
216 }
217
218 ctrl |= PM_BIT(PLLEN);
219 pm_writel(PLL1, ctrl);
220
221 /* Wait for PLL lock. */
222 for (timeout = 10000; timeout; timeout--) {
223 status = pm_readl(ISR);
224 if (status & PM_BIT(LOCK1))
225 break;
226 udelay(10);
227 }
228
229 if (!(status & PM_BIT(LOCK1)))
230 printk(KERN_ERR "clk %s: timeout waiting for lock\n",
231 clk->name);
232 } else {
233 ctrl &= ~PM_BIT(PLLEN);
234 pm_writel(PLL1, ctrl);
235 }
236}
237
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700238static unsigned long pll1_get_rate(struct clk *clk)
239{
240 u32 control;
241
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200242 control = pm_readl(PLL1);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700243
244 return pll_get_rate(clk, control);
245}
246
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100247static long pll1_set_rate(struct clk *clk, unsigned long rate, int apply)
248{
249 u32 ctrl = 0;
250 unsigned long actual_rate;
251
252 actual_rate = pll_set_rate(clk, rate, &ctrl);
253
254 if (apply) {
255 if (actual_rate != rate)
256 return -EINVAL;
257 if (clk->users > 0)
258 return -EBUSY;
259 pr_debug(KERN_INFO "clk %s: new rate %lu (actual rate %lu)\n",
260 clk->name, rate, actual_rate);
261 pm_writel(PLL1, ctrl);
262 }
263
264 return actual_rate;
265}
266
267static int pll1_set_parent(struct clk *clk, struct clk *parent)
268{
269 u32 ctrl;
270
271 if (clk->users > 0)
272 return -EBUSY;
273
274 ctrl = pm_readl(PLL1);
275 WARN_ON(ctrl & PM_BIT(PLLEN));
276
277 if (parent == &osc0)
278 ctrl &= ~PM_BIT(PLLOSC);
279 else if (parent == &osc1)
280 ctrl |= PM_BIT(PLLOSC);
281 else
282 return -EINVAL;
283
284 pm_writel(PLL1, ctrl);
285 clk->parent = parent;
286
287 return 0;
288}
289
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700290/*
291 * The AT32AP7000 has five primary clock sources: One 32kHz
292 * oscillator, two crystal oscillators and two PLLs.
293 */
294static struct clk osc32k = {
295 .name = "osc32k",
296 .get_rate = osc_get_rate,
297 .users = 1,
298 .index = 0,
299};
300static struct clk osc0 = {
301 .name = "osc0",
302 .get_rate = osc_get_rate,
303 .users = 1,
304 .index = 1,
305};
306static struct clk osc1 = {
307 .name = "osc1",
308 .get_rate = osc_get_rate,
309 .index = 2,
310};
311static struct clk pll0 = {
312 .name = "pll0",
313 .get_rate = pll0_get_rate,
314 .parent = &osc0,
315};
316static struct clk pll1 = {
317 .name = "pll1",
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100318 .mode = pll1_mode,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700319 .get_rate = pll1_get_rate,
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100320 .set_rate = pll1_set_rate,
321 .set_parent = pll1_set_parent,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700322 .parent = &osc0,
323};
324
325/*
326 * The main clock can be either osc0 or pll0. The boot loader may
327 * have chosen one for us, so we don't really know which one until we
328 * have a look at the SM.
329 */
330static struct clk *main_clock;
331
332/*
333 * Synchronous clocks are generated from the main clock. The clocks
334 * must satisfy the constraint
335 * fCPU >= fHSB >= fPB
336 * i.e. each clock must not be faster than its parent.
337 */
338static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
339{
340 return main_clock->get_rate(main_clock) >> shift;
341};
342
343static void cpu_clk_mode(struct clk *clk, int enabled)
344{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700345 unsigned long flags;
346 u32 mask;
347
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200348 spin_lock_irqsave(&pm_lock, flags);
349 mask = pm_readl(CPU_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700350 if (enabled)
351 mask |= 1 << clk->index;
352 else
353 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200354 pm_writel(CPU_MASK, mask);
355 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700356}
357
358static unsigned long cpu_clk_get_rate(struct clk *clk)
359{
360 unsigned long cksel, shift = 0;
361
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200362 cksel = pm_readl(CKSEL);
363 if (cksel & PM_BIT(CPUDIV))
364 shift = PM_BFEXT(CPUSEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700365
366 return bus_clk_get_rate(clk, shift);
367}
368
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +0200369static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
370{
371 u32 control;
372 unsigned long parent_rate, child_div, actual_rate, div;
373
374 parent_rate = clk->parent->get_rate(clk->parent);
375 control = pm_readl(CKSEL);
376
377 if (control & PM_BIT(HSBDIV))
378 child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
379 else
380 child_div = 1;
381
382 if (rate > 3 * (parent_rate / 4) || child_div == 1) {
383 actual_rate = parent_rate;
384 control &= ~PM_BIT(CPUDIV);
385 } else {
386 unsigned int cpusel;
387 div = (parent_rate + rate / 2) / rate;
388 if (div > child_div)
389 div = child_div;
390 cpusel = (div > 1) ? (fls(div) - 2) : 0;
391 control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
392 actual_rate = parent_rate / (1 << (cpusel + 1));
393 }
394
395 pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
396 clk->name, rate, actual_rate);
397
398 if (apply)
399 pm_writel(CKSEL, control);
400
401 return actual_rate;
402}
403
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700404static void hsb_clk_mode(struct clk *clk, int enabled)
405{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700406 unsigned long flags;
407 u32 mask;
408
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200409 spin_lock_irqsave(&pm_lock, flags);
410 mask = pm_readl(HSB_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700411 if (enabled)
412 mask |= 1 << clk->index;
413 else
414 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200415 pm_writel(HSB_MASK, mask);
416 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700417}
418
419static unsigned long hsb_clk_get_rate(struct clk *clk)
420{
421 unsigned long cksel, shift = 0;
422
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200423 cksel = pm_readl(CKSEL);
424 if (cksel & PM_BIT(HSBDIV))
425 shift = PM_BFEXT(HSBSEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700426
427 return bus_clk_get_rate(clk, shift);
428}
429
Alex Raimondidd5e1332008-12-09 16:17:13 +0100430void pba_clk_mode(struct clk *clk, int enabled)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700431{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700432 unsigned long flags;
433 u32 mask;
434
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200435 spin_lock_irqsave(&pm_lock, flags);
436 mask = pm_readl(PBA_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700437 if (enabled)
438 mask |= 1 << clk->index;
439 else
440 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200441 pm_writel(PBA_MASK, mask);
442 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700443}
444
Alex Raimondidd5e1332008-12-09 16:17:13 +0100445unsigned long pba_clk_get_rate(struct clk *clk)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700446{
447 unsigned long cksel, shift = 0;
448
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200449 cksel = pm_readl(CKSEL);
450 if (cksel & PM_BIT(PBADIV))
451 shift = PM_BFEXT(PBASEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700452
453 return bus_clk_get_rate(clk, shift);
454}
455
456static void pbb_clk_mode(struct clk *clk, int enabled)
457{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700458 unsigned long flags;
459 u32 mask;
460
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200461 spin_lock_irqsave(&pm_lock, flags);
462 mask = pm_readl(PBB_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700463 if (enabled)
464 mask |= 1 << clk->index;
465 else
466 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200467 pm_writel(PBB_MASK, mask);
468 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700469}
470
471static unsigned long pbb_clk_get_rate(struct clk *clk)
472{
473 unsigned long cksel, shift = 0;
474
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200475 cksel = pm_readl(CKSEL);
476 if (cksel & PM_BIT(PBBDIV))
477 shift = PM_BFEXT(PBBSEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700478
479 return bus_clk_get_rate(clk, shift);
480}
481
482static struct clk cpu_clk = {
483 .name = "cpu",
484 .get_rate = cpu_clk_get_rate,
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +0200485 .set_rate = cpu_clk_set_rate,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700486 .users = 1,
487};
488static struct clk hsb_clk = {
489 .name = "hsb",
490 .parent = &cpu_clk,
491 .get_rate = hsb_clk_get_rate,
492};
493static struct clk pba_clk = {
494 .name = "pba",
495 .parent = &hsb_clk,
496 .mode = hsb_clk_mode,
497 .get_rate = pba_clk_get_rate,
498 .index = 1,
499};
500static struct clk pbb_clk = {
501 .name = "pbb",
502 .parent = &hsb_clk,
503 .mode = hsb_clk_mode,
504 .get_rate = pbb_clk_get_rate,
505 .users = 1,
506 .index = 2,
507};
508
509/* --------------------------------------------------------------------
510 * Generic Clock operations
511 * -------------------------------------------------------------------- */
512
513static void genclk_mode(struct clk *clk, int enabled)
514{
515 u32 control;
516
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200517 control = pm_readl(GCCTRL(clk->index));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700518 if (enabled)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200519 control |= PM_BIT(CEN);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700520 else
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200521 control &= ~PM_BIT(CEN);
522 pm_writel(GCCTRL(clk->index), control);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700523}
524
525static unsigned long genclk_get_rate(struct clk *clk)
526{
527 u32 control;
528 unsigned long div = 1;
529
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200530 control = pm_readl(GCCTRL(clk->index));
531 if (control & PM_BIT(DIVEN))
532 div = 2 * (PM_BFEXT(DIV, control) + 1);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700533
534 return clk->parent->get_rate(clk->parent) / div;
535}
536
537static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
538{
539 u32 control;
540 unsigned long parent_rate, actual_rate, div;
541
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700542 parent_rate = clk->parent->get_rate(clk->parent);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200543 control = pm_readl(GCCTRL(clk->index));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700544
545 if (rate > 3 * parent_rate / 4) {
546 actual_rate = parent_rate;
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200547 control &= ~PM_BIT(DIVEN);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700548 } else {
549 div = (parent_rate + rate) / (2 * rate) - 1;
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200550 control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700551 actual_rate = parent_rate / (2 * (div + 1));
552 }
553
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200554 dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
555 clk->name, rate, actual_rate);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700556
557 if (apply)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200558 pm_writel(GCCTRL(clk->index), control);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700559
560 return actual_rate;
561}
562
563int genclk_set_parent(struct clk *clk, struct clk *parent)
564{
565 u32 control;
566
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200567 dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
568 clk->name, parent->name, clk->parent->name);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700569
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200570 control = pm_readl(GCCTRL(clk->index));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700571
572 if (parent == &osc1 || parent == &pll1)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200573 control |= PM_BIT(OSCSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700574 else if (parent == &osc0 || parent == &pll0)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200575 control &= ~PM_BIT(OSCSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700576 else
577 return -EINVAL;
578
579 if (parent == &pll0 || parent == &pll1)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200580 control |= PM_BIT(PLLSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700581 else
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200582 control &= ~PM_BIT(PLLSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700583
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200584 pm_writel(GCCTRL(clk->index), control);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700585 clk->parent = parent;
586
587 return 0;
588}
589
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +0100590static void __init genclk_init_parent(struct clk *clk)
591{
592 u32 control;
593 struct clk *parent;
594
595 BUG_ON(clk->index > 7);
596
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200597 control = pm_readl(GCCTRL(clk->index));
598 if (control & PM_BIT(OSCSEL))
599 parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +0100600 else
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200601 parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +0100602
603 clk->parent = parent;
604}
605
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -0700606static struct dw_dma_platform_data dw_dmac0_data = {
607 .nr_channels = 3,
Andy Shevchenko4a63a8b2012-09-21 15:05:47 +0300608 .block_size = 4095U,
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -0700609};
610
611static struct resource dw_dmac0_resource[] = {
612 PBMEM(0xff200000),
613 IRQ(2),
614};
615DEFINE_DEV_DATA(dw_dmac, 0);
616DEV_CLK(hclk, dw_dmac0, hsb, 10);
617
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700618/* --------------------------------------------------------------------
619 * System peripherals
620 * -------------------------------------------------------------------- */
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200621static struct resource at32_pm0_resource[] = {
622 {
623 .start = 0xfff00000,
624 .end = 0xfff0007f,
625 .flags = IORESOURCE_MEM,
626 },
627 IRQ(20),
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700628};
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200629
630static struct resource at32ap700x_rtc0_resource[] = {
631 {
632 .start = 0xfff00080,
633 .end = 0xfff000af,
634 .flags = IORESOURCE_MEM,
635 },
636 IRQ(21),
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700637};
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200638
639static struct resource at32_wdt0_resource[] = {
640 {
641 .start = 0xfff000b0,
Hans-Christian Egtvedt9797bed2007-10-30 14:29:50 +0100642 .end = 0xfff000cf,
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200643 .flags = IORESOURCE_MEM,
644 },
645};
646
647static struct resource at32_eic0_resource[] = {
648 {
649 .start = 0xfff00100,
650 .end = 0xfff0013f,
651 .flags = IORESOURCE_MEM,
652 },
653 IRQ(19),
654};
655
656DEFINE_DEV(at32_pm, 0);
657DEFINE_DEV(at32ap700x_rtc, 0);
658DEFINE_DEV(at32_wdt, 0);
659DEFINE_DEV(at32_eic, 0);
660
661/*
662 * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
663 * is always running.
664 */
665static struct clk at32_pm_pclk = {
Haavard Skinnemoen188ff652007-03-14 13:23:44 +0100666 .name = "pclk",
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200667 .dev = &at32_pm0_device.dev,
Haavard Skinnemoen188ff652007-03-14 13:23:44 +0100668 .parent = &pbb_clk,
669 .mode = pbb_clk_mode,
670 .get_rate = pbb_clk_get_rate,
671 .users = 1,
672 .index = 0,
673};
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700674
675static struct resource intc0_resource[] = {
676 PBMEM(0xfff00400),
677};
678struct platform_device at32_intc0_device = {
679 .name = "intc",
680 .id = 0,
681 .resource = intc0_resource,
682 .num_resources = ARRAY_SIZE(intc0_resource),
683};
684DEV_CLK(pclk, at32_intc0, pbb, 1);
685
686static struct clk ebi_clk = {
687 .name = "ebi",
688 .parent = &hsb_clk,
689 .mode = hsb_clk_mode,
690 .get_rate = hsb_clk_get_rate,
691 .users = 1,
692};
693static struct clk hramc_clk = {
694 .name = "hramc",
695 .parent = &hsb_clk,
696 .mode = hsb_clk_mode,
697 .get_rate = hsb_clk_get_rate,
698 .users = 1,
Haavard Skinnemoen188ff652007-03-14 13:23:44 +0100699 .index = 3,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700700};
Haavard Skinnemoen7951f182008-03-05 15:08:27 +0100701static struct clk sdramc_clk = {
702 .name = "sdramc_clk",
703 .parent = &pbb_clk,
704 .mode = pbb_clk_mode,
705 .get_rate = pbb_clk_get_rate,
706 .users = 1,
707 .index = 14,
708};
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700709
Haavard Skinnemoenbc157b72006-09-25 23:32:16 -0700710static struct resource smc0_resource[] = {
711 PBMEM(0xfff03400),
712};
713DEFINE_DEV(smc, 0);
714DEV_CLK(pclk, smc0, pbb, 13);
715DEV_CLK(mck, smc0, hsb, 0);
716
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700717static struct platform_device pdc_device = {
718 .name = "pdc",
719 .id = 0,
720};
721DEV_CLK(hclk, pdc, hsb, 4);
722DEV_CLK(pclk, pdc, pba, 16);
723
724static struct clk pico_clk = {
725 .name = "pico",
726 .parent = &cpu_clk,
727 .mode = cpu_clk_mode,
728 .get_rate = cpu_clk_get_rate,
729 .users = 1,
730};
731
732/* --------------------------------------------------------------------
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100733 * HMATRIX
734 * -------------------------------------------------------------------- */
735
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +0200736struct clk at32_hmatrix_clk = {
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100737 .name = "hmatrix_clk",
738 .parent = &pbb_clk,
739 .mode = pbb_clk_mode,
740 .get_rate = pbb_clk_get_rate,
741 .index = 2,
742 .users = 1,
743};
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100744
745/*
746 * Set bits in the HMATRIX Special Function Register (SFR) used by the
747 * External Bus Interface (EBI). This can be used to enable special
748 * features like CompactFlash support, NAND Flash support, etc. on
749 * certain chipselects.
750 */
751static inline void set_ebi_sfr_bits(u32 mask)
752{
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +0200753 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, mask);
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100754}
755
756/* --------------------------------------------------------------------
David Brownelle723ff62008-02-14 11:24:02 -0800757 * Timer/Counter (TC)
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100758 * -------------------------------------------------------------------- */
David Brownelle723ff62008-02-14 11:24:02 -0800759
760static struct resource at32_tcb0_resource[] = {
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100761 PBMEM(0xfff00c00),
762 IRQ(22),
763};
David Brownelle723ff62008-02-14 11:24:02 -0800764static struct platform_device at32_tcb0_device = {
765 .name = "atmel_tcb",
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100766 .id = 0,
David Brownelle723ff62008-02-14 11:24:02 -0800767 .resource = at32_tcb0_resource,
768 .num_resources = ARRAY_SIZE(at32_tcb0_resource),
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100769};
David Brownelle723ff62008-02-14 11:24:02 -0800770DEV_CLK(t0_clk, at32_tcb0, pbb, 3);
771
772static struct resource at32_tcb1_resource[] = {
773 PBMEM(0xfff01000),
774 IRQ(23),
775};
776static struct platform_device at32_tcb1_device = {
777 .name = "atmel_tcb",
778 .id = 1,
779 .resource = at32_tcb1_resource,
780 .num_resources = ARRAY_SIZE(at32_tcb1_resource),
781};
782DEV_CLK(t0_clk, at32_tcb1, pbb, 4);
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100783
784/* --------------------------------------------------------------------
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700785 * PIO
786 * -------------------------------------------------------------------- */
787
788static struct resource pio0_resource[] = {
789 PBMEM(0xffe02800),
790 IRQ(13),
791};
792DEFINE_DEV(pio, 0);
793DEV_CLK(mck, pio0, pba, 10);
794
795static struct resource pio1_resource[] = {
796 PBMEM(0xffe02c00),
797 IRQ(14),
798};
799DEFINE_DEV(pio, 1);
800DEV_CLK(mck, pio1, pba, 11);
801
802static struct resource pio2_resource[] = {
803 PBMEM(0xffe03000),
804 IRQ(15),
805};
806DEFINE_DEV(pio, 2);
807DEV_CLK(mck, pio2, pba, 12);
808
809static struct resource pio3_resource[] = {
810 PBMEM(0xffe03400),
811 IRQ(16),
812};
813DEFINE_DEV(pio, 3);
814DEV_CLK(mck, pio3, pba, 13);
815
Haavard Skinnemoen7f9f4672007-01-30 11:16:16 +0100816static struct resource pio4_resource[] = {
817 PBMEM(0xffe03800),
818 IRQ(17),
819};
820DEFINE_DEV(pio, 4);
821DEV_CLK(mck, pio4, pba, 14);
822
Haavard Skinnemoene82c6102008-10-23 14:42:19 +0200823static int __init system_device_init(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700824{
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200825 platform_device_register(&at32_pm0_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700826 platform_device_register(&at32_intc0_device);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200827 platform_device_register(&at32ap700x_rtc0_device);
828 platform_device_register(&at32_wdt0_device);
829 platform_device_register(&at32_eic0_device);
Haavard Skinnemoenbc157b72006-09-25 23:32:16 -0700830 platform_device_register(&smc0_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700831 platform_device_register(&pdc_device);
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -0700832 platform_device_register(&dw_dmac0_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700833
David Brownelle723ff62008-02-14 11:24:02 -0800834 platform_device_register(&at32_tcb0_device);
835 platform_device_register(&at32_tcb1_device);
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100836
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700837 platform_device_register(&pio0_device);
838 platform_device_register(&pio1_device);
839 platform_device_register(&pio2_device);
840 platform_device_register(&pio3_device);
Haavard Skinnemoen7f9f4672007-01-30 11:16:16 +0100841 platform_device_register(&pio4_device);
Haavard Skinnemoene82c6102008-10-23 14:42:19 +0200842
843 return 0;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700844}
Haavard Skinnemoene82c6102008-10-23 14:42:19 +0200845core_initcall(system_device_init);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700846
847/* --------------------------------------------------------------------
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100848 * PSIF
849 * -------------------------------------------------------------------- */
850static struct resource atmel_psif0_resource[] __initdata = {
851 {
852 .start = 0xffe03c00,
853 .end = 0xffe03cff,
854 .flags = IORESOURCE_MEM,
855 },
856 IRQ(18),
857};
858static struct clk atmel_psif0_pclk = {
859 .name = "pclk",
860 .parent = &pba_clk,
861 .mode = pba_clk_mode,
862 .get_rate = pba_clk_get_rate,
863 .index = 15,
864};
865
866static struct resource atmel_psif1_resource[] __initdata = {
867 {
868 .start = 0xffe03d00,
869 .end = 0xffe03dff,
870 .flags = IORESOURCE_MEM,
871 },
872 IRQ(18),
873};
874static struct clk atmel_psif1_pclk = {
875 .name = "pclk",
876 .parent = &pba_clk,
877 .mode = pba_clk_mode,
878 .get_rate = pba_clk_get_rate,
879 .index = 15,
880};
881
882struct platform_device *__init at32_add_device_psif(unsigned int id)
883{
884 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +0200885 u32 pin_mask;
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100886
887 if (!(id == 0 || id == 1))
888 return NULL;
889
890 pdev = platform_device_alloc("atmel_psif", id);
891 if (!pdev)
892 return NULL;
893
894 switch (id) {
895 case 0:
Julien Maycaf18f12008-09-24 10:30:47 +0200896 pin_mask = (1 << 8) | (1 << 9); /* CLOCK & DATA */
897
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100898 if (platform_device_add_resources(pdev, atmel_psif0_resource,
899 ARRAY_SIZE(atmel_psif0_resource)))
900 goto err_add_resources;
901 atmel_psif0_pclk.dev = &pdev->dev;
Julien Maycaf18f12008-09-24 10:30:47 +0200902 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100903 break;
904 case 1:
Julien Maycaf18f12008-09-24 10:30:47 +0200905 pin_mask = (1 << 11) | (1 << 12); /* CLOCK & DATA */
906
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100907 if (platform_device_add_resources(pdev, atmel_psif1_resource,
908 ARRAY_SIZE(atmel_psif1_resource)))
909 goto err_add_resources;
910 atmel_psif1_pclk.dev = &pdev->dev;
Julien Maycaf18f12008-09-24 10:30:47 +0200911 select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100912 break;
913 default:
914 return NULL;
915 }
916
917 platform_device_add(pdev);
918 return pdev;
919
920err_add_resources:
921 platform_device_put(pdev);
922 return NULL;
923}
924
925/* --------------------------------------------------------------------
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700926 * USART
927 * -------------------------------------------------------------------- */
928
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200929static struct atmel_uart_data atmel_usart0_data = {
930 .use_dma_tx = 1,
931 .use_dma_rx = 1,
932};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200933static struct resource atmel_usart0_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700934 PBMEM(0xffe00c00),
David Brownella3d912c82007-01-23 20:14:02 -0800935 IRQ(6),
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700936};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200937DEFINE_DEV_DATA(atmel_usart, 0);
ben.nizette@iinet.net.au80f76c52007-11-07 16:16:22 +0900938DEV_CLK(usart, atmel_usart0, pba, 3);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700939
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200940static struct atmel_uart_data atmel_usart1_data = {
941 .use_dma_tx = 1,
942 .use_dma_rx = 1,
943};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200944static struct resource atmel_usart1_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700945 PBMEM(0xffe01000),
946 IRQ(7),
947};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200948DEFINE_DEV_DATA(atmel_usart, 1);
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200949DEV_CLK(usart, atmel_usart1, pba, 4);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700950
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200951static struct atmel_uart_data atmel_usart2_data = {
952 .use_dma_tx = 1,
953 .use_dma_rx = 1,
954};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200955static struct resource atmel_usart2_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700956 PBMEM(0xffe01400),
957 IRQ(8),
958};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200959DEFINE_DEV_DATA(atmel_usart, 2);
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200960DEV_CLK(usart, atmel_usart2, pba, 5);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700961
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200962static struct atmel_uart_data atmel_usart3_data = {
963 .use_dma_tx = 1,
964 .use_dma_rx = 1,
965};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200966static struct resource atmel_usart3_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700967 PBMEM(0xffe01800),
968 IRQ(9),
969};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200970DEFINE_DEV_DATA(atmel_usart, 3);
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200971DEV_CLK(usart, atmel_usart3, pba, 6);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700972
Peter Mabf4861c2009-03-31 10:31:02 -0700973static inline void configure_usart0_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700974{
Julien Maycaf18f12008-09-24 10:30:47 +0200975 u32 pin_mask = (1 << 8) | (1 << 9); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -0700976 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 6);
977 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 7);
978 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 10);
Julien Maycaf18f12008-09-24 10:30:47 +0200979
Anders Blomdell10546262008-10-24 14:54:08 +0200980 select_peripheral(PIOA, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700981}
982
Peter Mabf4861c2009-03-31 10:31:02 -0700983static inline void configure_usart1_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700984{
Julien Maycaf18f12008-09-24 10:30:47 +0200985 u32 pin_mask = (1 << 17) | (1 << 18); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -0700986 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 19);
987 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 20);
988 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 16);
Julien Maycaf18f12008-09-24 10:30:47 +0200989
Anders Blomdell10546262008-10-24 14:54:08 +0200990 select_peripheral(PIOA, pin_mask, PERIPH_A, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700991}
992
Peter Mabf4861c2009-03-31 10:31:02 -0700993static inline void configure_usart2_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700994{
Julien Maycaf18f12008-09-24 10:30:47 +0200995 u32 pin_mask = (1 << 26) | (1 << 27); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -0700996 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 30);
997 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 29);
998 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 28);
Julien Maycaf18f12008-09-24 10:30:47 +0200999
Anders Blomdell10546262008-10-24 14:54:08 +02001000 select_peripheral(PIOB, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001001}
1002
Peter Mabf4861c2009-03-31 10:31:02 -07001003static inline void configure_usart3_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001004{
Julien Maycaf18f12008-09-24 10:30:47 +02001005 u32 pin_mask = (1 << 18) | (1 << 17); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -07001006 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 16);
1007 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 15);
1008 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 19);
Julien Maycaf18f12008-09-24 10:30:47 +02001009
Anders Blomdell10546262008-10-24 14:54:08 +02001010 select_peripheral(PIOB, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001011}
1012
David Brownella3d912c82007-01-23 20:14:02 -08001013static struct platform_device *__initdata at32_usarts[4];
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001014
Peter Mabf4861c2009-03-31 10:31:02 -07001015void __init at32_map_usart(unsigned int hw_id, unsigned int line, int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001016{
1017 struct platform_device *pdev;
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001018 struct atmel_uart_data *pdata;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001019
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001020 switch (hw_id) {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001021 case 0:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001022 pdev = &atmel_usart0_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001023 configure_usart0_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001024 break;
1025 case 1:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001026 pdev = &atmel_usart1_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001027 configure_usart1_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001028 break;
1029 case 2:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001030 pdev = &atmel_usart2_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001031 configure_usart2_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001032 break;
1033 case 3:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001034 pdev = &atmel_usart3_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001035 configure_usart3_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001036 break;
1037 default:
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001038 return;
Haavard Skinnemoen75d35212006-10-04 16:02:08 +02001039 }
1040
1041 if (PXSEG(pdev->resource[0].start) == P4SEG) {
1042 /* Addresses in the P4 segment are permanently mapped 1:1 */
1043 struct atmel_uart_data *data = pdev->dev.platform_data;
1044 data->regs = (void __iomem *)pdev->resource[0].start;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001045 }
1046
Hans-Christian Egtvedt4137b312011-06-08 10:47:25 +02001047 pdev->id = line;
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001048 pdata = pdev->dev.platform_data;
Hans-Christian Egtvedt7bbf1d42011-06-01 11:08:01 +02001049 pdata->num = line;
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001050 at32_usarts[line] = pdev;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001051}
1052
1053struct platform_device *__init at32_add_device_usart(unsigned int id)
1054{
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001055 platform_device_register(at32_usarts[id]);
1056 return at32_usarts[id];
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001057}
1058
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001059void __init at32_setup_serial_console(unsigned int usart_id)
1060{
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001061 atmel_default_console_device = at32_usarts[usart_id];
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001062}
1063
1064/* --------------------------------------------------------------------
1065 * Ethernet
1066 * -------------------------------------------------------------------- */
1067
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001068#ifdef CONFIG_CPU_AT32AP7000
Jamie Iles84e0cdb2011-03-08 20:17:06 +00001069static struct macb_platform_data macb0_data;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001070static struct resource macb0_resource[] = {
1071 PBMEM(0xfff01800),
1072 IRQ(25),
1073};
1074DEFINE_DEV_DATA(macb, 0);
1075DEV_CLK(hclk, macb0, hsb, 8);
1076DEV_CLK(pclk, macb0, pbb, 6);
1077
Jamie Iles84e0cdb2011-03-08 20:17:06 +00001078static struct macb_platform_data macb1_data;
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001079static struct resource macb1_resource[] = {
1080 PBMEM(0xfff01c00),
1081 IRQ(26),
1082};
1083DEFINE_DEV_DATA(macb, 1);
1084DEV_CLK(hclk, macb1, hsb, 9);
1085DEV_CLK(pclk, macb1, pbb, 7);
1086
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001087struct platform_device *__init
Jamie Iles84e0cdb2011-03-08 20:17:06 +00001088at32_add_device_eth(unsigned int id, struct macb_platform_data *data)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001089{
1090 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001091 u32 pin_mask;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001092
1093 switch (id) {
1094 case 0:
1095 pdev = &macb0_device;
1096
Julien Maycaf18f12008-09-24 10:30:47 +02001097 pin_mask = (1 << 3); /* TXD0 */
1098 pin_mask |= (1 << 4); /* TXD1 */
1099 pin_mask |= (1 << 7); /* TXEN */
1100 pin_mask |= (1 << 8); /* TXCK */
1101 pin_mask |= (1 << 9); /* RXD0 */
1102 pin_mask |= (1 << 10); /* RXD1 */
1103 pin_mask |= (1 << 13); /* RXER */
1104 pin_mask |= (1 << 15); /* RXDV */
1105 pin_mask |= (1 << 16); /* MDC */
1106 pin_mask |= (1 << 17); /* MDIO */
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001107
1108 if (!data->is_rmii) {
Julien Maycaf18f12008-09-24 10:30:47 +02001109 pin_mask |= (1 << 0); /* COL */
1110 pin_mask |= (1 << 1); /* CRS */
1111 pin_mask |= (1 << 2); /* TXER */
1112 pin_mask |= (1 << 5); /* TXD2 */
1113 pin_mask |= (1 << 6); /* TXD3 */
1114 pin_mask |= (1 << 11); /* RXD2 */
1115 pin_mask |= (1 << 12); /* RXD3 */
1116 pin_mask |= (1 << 14); /* RXCK */
Mark Jackson198f2932008-10-13 10:46:27 +00001117#ifndef CONFIG_BOARD_MIMC200
Julien Maycaf18f12008-09-24 10:30:47 +02001118 pin_mask |= (1 << 18); /* SPD */
Mark Jackson198f2932008-10-13 10:46:27 +00001119#endif
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001120 }
Julien Maycaf18f12008-09-24 10:30:47 +02001121
1122 select_peripheral(PIOC, pin_mask, PERIPH_A, 0);
1123
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001124 break;
1125
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001126 case 1:
1127 pdev = &macb1_device;
1128
Julien Maycaf18f12008-09-24 10:30:47 +02001129 pin_mask = (1 << 13); /* TXD0 */
1130 pin_mask |= (1 << 14); /* TXD1 */
1131 pin_mask |= (1 << 11); /* TXEN */
1132 pin_mask |= (1 << 12); /* TXCK */
1133 pin_mask |= (1 << 10); /* RXD0 */
1134 pin_mask |= (1 << 6); /* RXD1 */
1135 pin_mask |= (1 << 5); /* RXER */
1136 pin_mask |= (1 << 4); /* RXDV */
1137 pin_mask |= (1 << 3); /* MDC */
1138 pin_mask |= (1 << 2); /* MDIO */
1139
Mark Jackson198f2932008-10-13 10:46:27 +00001140#ifndef CONFIG_BOARD_MIMC200
Julien Maycaf18f12008-09-24 10:30:47 +02001141 if (!data->is_rmii)
1142 pin_mask |= (1 << 15); /* SPD */
Mark Jackson198f2932008-10-13 10:46:27 +00001143#endif
Julien Maycaf18f12008-09-24 10:30:47 +02001144
1145 select_peripheral(PIOD, pin_mask, PERIPH_B, 0);
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001146
1147 if (!data->is_rmii) {
Julien Maycaf18f12008-09-24 10:30:47 +02001148 pin_mask = (1 << 19); /* COL */
1149 pin_mask |= (1 << 23); /* CRS */
1150 pin_mask |= (1 << 26); /* TXER */
1151 pin_mask |= (1 << 27); /* TXD2 */
1152 pin_mask |= (1 << 28); /* TXD3 */
1153 pin_mask |= (1 << 29); /* RXD2 */
1154 pin_mask |= (1 << 30); /* RXD3 */
1155 pin_mask |= (1 << 24); /* RXCK */
1156
1157 select_peripheral(PIOC, pin_mask, PERIPH_B, 0);
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001158 }
1159 break;
1160
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001161 default:
1162 return NULL;
1163 }
1164
Jamie Iles84e0cdb2011-03-08 20:17:06 +00001165 memcpy(pdev->dev.platform_data, data, sizeof(struct macb_platform_data));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001166 platform_device_register(pdev);
1167
1168 return pdev;
1169}
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001170#endif
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001171
1172/* --------------------------------------------------------------------
1173 * SPI
1174 * -------------------------------------------------------------------- */
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001175static struct resource atmel_spi0_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001176 PBMEM(0xffe00000),
1177 IRQ(3),
1178};
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001179DEFINE_DEV(atmel_spi, 0);
1180DEV_CLK(spi_clk, atmel_spi0, pba, 0);
1181
1182static struct resource atmel_spi1_resource[] = {
1183 PBMEM(0xffe00400),
1184 IRQ(4),
1185};
1186DEFINE_DEV(atmel_spi, 1);
1187DEV_CLK(spi_clk, atmel_spi1, pba, 1);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001188
Peter Ma07084202009-08-27 00:31:47 -07001189void __init
1190at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001191{
Peter Ma07084202009-08-27 00:31:47 -07001192 /*
1193 * Manage the chipselects as GPIOs, normally using the same pins
1194 * the SPI controller expects; but boards can use other pins.
1195 */
1196 static u8 __initdata spi_pins[][4] = {
1197 { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
1198 GPIO_PIN_PA(5), GPIO_PIN_PA(20) },
1199 { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
1200 GPIO_PIN_PB(4), GPIO_PIN_PA(27) },
1201 };
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001202 unsigned int pin, mode;
1203
Peter Ma07084202009-08-27 00:31:47 -07001204 /* There are only 2 SPI controllers */
1205 if (bus_num > 1)
1206 return;
1207
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001208 for (; n; n--, b++) {
1209 b->bus_num = bus_num;
1210 if (b->chip_select >= 4)
1211 continue;
1212 pin = (unsigned)b->controller_data;
1213 if (!pin) {
Peter Ma07084202009-08-27 00:31:47 -07001214 pin = spi_pins[bus_num][b->chip_select];
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001215 b->controller_data = (void *)pin;
1216 }
1217 mode = AT32_GPIOF_OUTPUT;
1218 if (!(b->mode & SPI_CS_HIGH))
1219 mode |= AT32_GPIOF_HIGH;
1220 at32_select_gpio(pin, mode);
1221 }
1222}
1223
1224struct platform_device *__init
1225at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
1226{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001227 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001228 u32 pin_mask;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001229
1230 switch (id) {
1231 case 0:
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001232 pdev = &atmel_spi0_device;
Julien Maycaf18f12008-09-24 10:30:47 +02001233 pin_mask = (1 << 1) | (1 << 2); /* MOSI & SCK */
1234
David Brownell9c2baf72008-06-18 02:31:43 -07001235 /* pullup MISO so a level is always defined */
Julien Maycaf18f12008-09-24 10:30:47 +02001236 select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP);
1237 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
1238
Peter Ma07084202009-08-27 00:31:47 -07001239 at32_spi_setup_slaves(0, b, n);
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001240 break;
1241
1242 case 1:
1243 pdev = &atmel_spi1_device;
Julien Maycaf18f12008-09-24 10:30:47 +02001244 pin_mask = (1 << 1) | (1 << 5); /* MOSI */
1245
David Brownell9c2baf72008-06-18 02:31:43 -07001246 /* pullup MISO so a level is always defined */
Julien Maycaf18f12008-09-24 10:30:47 +02001247 select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP);
1248 select_peripheral(PIOB, pin_mask, PERIPH_B, 0);
1249
Peter Ma07084202009-08-27 00:31:47 -07001250 at32_spi_setup_slaves(1, b, n);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001251 break;
1252
1253 default:
1254 return NULL;
1255 }
1256
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001257 spi_register_board_info(b, n);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001258 platform_device_register(pdev);
1259 return pdev;
1260}
1261
1262/* --------------------------------------------------------------------
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001263 * TWI
1264 * -------------------------------------------------------------------- */
1265static struct resource atmel_twi0_resource[] __initdata = {
1266 PBMEM(0xffe00800),
1267 IRQ(5),
1268};
1269static struct clk atmel_twi0_pclk = {
1270 .name = "twi_pclk",
1271 .parent = &pba_clk,
1272 .mode = pba_clk_mode,
1273 .get_rate = pba_clk_get_rate,
1274 .index = 2,
1275};
1276
Ben Nizette040b28f2008-02-07 15:28:57 +11001277struct platform_device *__init at32_add_device_twi(unsigned int id,
1278 struct i2c_board_info *b,
1279 unsigned int n)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001280{
1281 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001282 u32 pin_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001283
1284 if (id != 0)
1285 return NULL;
1286
1287 pdev = platform_device_alloc("atmel_twi", id);
1288 if (!pdev)
1289 return NULL;
1290
1291 if (platform_device_add_resources(pdev, atmel_twi0_resource,
1292 ARRAY_SIZE(atmel_twi0_resource)))
1293 goto err_add_resources;
1294
Julien Maycaf18f12008-09-24 10:30:47 +02001295 pin_mask = (1 << 6) | (1 << 7); /* SDA & SDL */
1296
1297 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001298
1299 atmel_twi0_pclk.dev = &pdev->dev;
1300
Ben Nizette040b28f2008-02-07 15:28:57 +11001301 if (b)
1302 i2c_register_board_info(id, b, n);
1303
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001304 platform_device_add(pdev);
1305 return pdev;
1306
1307err_add_resources:
1308 platform_device_put(pdev);
1309 return NULL;
1310}
1311
1312/* --------------------------------------------------------------------
1313 * MMC
1314 * -------------------------------------------------------------------- */
1315static struct resource atmel_mci0_resource[] __initdata = {
1316 PBMEM(0xfff02400),
1317 IRQ(28),
1318};
1319static struct clk atmel_mci0_pclk = {
1320 .name = "mci_clk",
1321 .parent = &pbb_clk,
1322 .mode = pbb_clk_mode,
1323 .get_rate = pbb_clk_get_rate,
1324 .index = 9,
1325};
1326
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001327struct platform_device *__init
1328at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001329{
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001330 struct platform_device *pdev;
Peter Huewe754a00a2009-12-25 20:08:45 +01001331 struct mci_dma_data *slave;
Julien Maycaf18f12008-09-24 10:30:47 +02001332 u32 pioa_mask;
1333 u32 piob_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001334
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001335 if (id != 0 || !data)
1336 return NULL;
1337
1338 /* Must have at least one usable slot */
1339 if (!data->slot[0].bus_width && !data->slot[1].bus_width)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001340 return NULL;
1341
1342 pdev = platform_device_alloc("atmel_mci", id);
1343 if (!pdev)
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001344 goto fail;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001345
1346 if (platform_device_add_resources(pdev, atmel_mci0_resource,
1347 ARRAY_SIZE(atmel_mci0_resource)))
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001348 goto fail;
1349
Peter Huewe754a00a2009-12-25 20:08:45 +01001350 slave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL);
Hans-Christian Egtvedtcbf8de12009-12-28 12:22:06 +01001351 if (!slave)
1352 goto fail;
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001353
1354 slave->sdata.dma_dev = &dw_dmac0_device.dev;
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001355 slave->sdata.cfg_hi = (DWC_CFGH_SRC_PER(0)
Haavard Skinnemoen65e8b082008-07-30 20:29:03 +02001356 | DWC_CFGH_DST_PER(1));
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001357 slave->sdata.cfg_lo &= ~(DWC_CFGL_HS_DST_POL
Haavard Skinnemoen65e8b082008-07-30 20:29:03 +02001358 | DWC_CFGL_HS_SRC_POL);
1359
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001360 data->dma_slave = slave;
1361
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001362 if (platform_device_add_data(pdev, data,
1363 sizeof(struct mci_platform_data)))
Hans-Christian Egtvedtcbf8de12009-12-28 12:22:06 +01001364 goto fail_free;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001365
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001366 /* CLK line is common to both slots */
Julien Maycaf18f12008-09-24 10:30:47 +02001367 pioa_mask = 1 << 10;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001368
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001369 switch (data->slot[0].bus_width) {
1370 case 4:
Julien Maycaf18f12008-09-24 10:30:47 +02001371 pioa_mask |= 1 << 13; /* DATA1 */
1372 pioa_mask |= 1 << 14; /* DATA2 */
1373 pioa_mask |= 1 << 15; /* DATA3 */
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001374 /* fall through */
1375 case 1:
Julien Maycaf18f12008-09-24 10:30:47 +02001376 pioa_mask |= 1 << 11; /* CMD */
1377 pioa_mask |= 1 << 12; /* DATA0 */
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001378
1379 if (gpio_is_valid(data->slot[0].detect_pin))
1380 at32_select_gpio(data->slot[0].detect_pin, 0);
1381 if (gpio_is_valid(data->slot[0].wp_pin))
1382 at32_select_gpio(data->slot[0].wp_pin, 0);
1383 break;
1384 case 0:
1385 /* Slot is unused */
1386 break;
1387 default:
Hans-Christian Egtvedtcbf8de12009-12-28 12:22:06 +01001388 goto fail_free;
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001389 }
1390
Julien Maycaf18f12008-09-24 10:30:47 +02001391 select_peripheral(PIOA, pioa_mask, PERIPH_A, 0);
1392 piob_mask = 0;
1393
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001394 switch (data->slot[1].bus_width) {
1395 case 4:
Julien Maycaf18f12008-09-24 10:30:47 +02001396 piob_mask |= 1 << 8; /* DATA1 */
1397 piob_mask |= 1 << 9; /* DATA2 */
1398 piob_mask |= 1 << 10; /* DATA3 */
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001399 /* fall through */
1400 case 1:
Julien Maycaf18f12008-09-24 10:30:47 +02001401 piob_mask |= 1 << 6; /* CMD */
1402 piob_mask |= 1 << 7; /* DATA0 */
1403 select_peripheral(PIOB, piob_mask, PERIPH_B, 0);
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001404
1405 if (gpio_is_valid(data->slot[1].detect_pin))
1406 at32_select_gpio(data->slot[1].detect_pin, 0);
1407 if (gpio_is_valid(data->slot[1].wp_pin))
1408 at32_select_gpio(data->slot[1].wp_pin, 0);
1409 break;
1410 case 0:
1411 /* Slot is unused */
1412 break;
1413 default:
1414 if (!data->slot[0].bus_width)
Hans-Christian Egtvedtcbf8de12009-12-28 12:22:06 +01001415 goto fail_free;
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001416
1417 data->slot[1].bus_width = 0;
1418 break;
1419 }
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001420
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001421 atmel_mci0_pclk.dev = &pdev->dev;
1422
1423 platform_device_add(pdev);
1424 return pdev;
1425
Hans-Christian Egtvedtcbf8de12009-12-28 12:22:06 +01001426fail_free:
1427 kfree(slave);
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001428fail:
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001429 data->dma_slave = NULL;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001430 platform_device_put(pdev);
1431 return NULL;
1432}
1433
1434/* --------------------------------------------------------------------
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001435 * LCDC
1436 * -------------------------------------------------------------------- */
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001437#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001438static struct atmel_lcdfb_info atmel_lcdfb0_data;
1439static struct resource atmel_lcdfb0_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001440 {
1441 .start = 0xff000000,
1442 .end = 0xff000fff,
1443 .flags = IORESOURCE_MEM,
1444 },
1445 IRQ(1),
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001446 {
1447 /* Placeholder for pre-allocated fb memory */
1448 .start = 0x00000000,
1449 .end = 0x00000000,
1450 .flags = 0,
1451 },
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001452};
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001453DEFINE_DEV_DATA(atmel_lcdfb, 0);
1454DEV_CLK(hck1, atmel_lcdfb0, hsb, 7);
1455static struct clk atmel_lcdfb0_pixclk = {
1456 .name = "lcdc_clk",
1457 .dev = &atmel_lcdfb0_device.dev,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001458 .mode = genclk_mode,
1459 .get_rate = genclk_get_rate,
1460 .set_rate = genclk_set_rate,
1461 .set_parent = genclk_set_parent,
1462 .index = 7,
1463};
1464
1465struct platform_device *__init
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001466at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
Hans-Christian Egtvedt47882cf2008-02-05 15:27:16 +01001467 unsigned long fbmem_start, unsigned long fbmem_len,
Julien May70664122008-08-04 14:27:38 +02001468 u64 pin_mask)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001469{
1470 struct platform_device *pdev;
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001471 struct atmel_lcdfb_info *info;
1472 struct fb_monspecs *monspecs;
1473 struct fb_videomode *modedb;
1474 unsigned int modedb_size;
Julien Maycaf18f12008-09-24 10:30:47 +02001475 u32 portc_mask, portd_mask, porte_mask;
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001476
1477 /*
1478 * Do a deep copy of the fb data, monspecs and modedb. Make
1479 * sure all allocations are done before setting up the
1480 * portmux.
1481 */
1482 monspecs = kmemdup(data->default_monspecs,
1483 sizeof(struct fb_monspecs), GFP_KERNEL);
1484 if (!monspecs)
1485 return NULL;
1486
1487 modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len;
1488 modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL);
1489 if (!modedb)
1490 goto err_dup_modedb;
1491 monspecs->modedb = modedb;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001492
1493 switch (id) {
1494 case 0:
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001495 pdev = &atmel_lcdfb0_device;
Hans-Christian Egtvedt47882cf2008-02-05 15:27:16 +01001496
Julien May70664122008-08-04 14:27:38 +02001497 if (pin_mask == 0ULL)
1498 /* Default to "full" lcdc control signals and 24bit */
1499 pin_mask = ATMEL_LCDC_PRI_24BIT | ATMEL_LCDC_PRI_CONTROL;
1500
1501 /* LCDC on port C */
Alex Raimondi60900652008-10-13 16:03:45 +02001502 portc_mask = pin_mask & 0xfff80000;
Julien Maycaf18f12008-09-24 10:30:47 +02001503 select_peripheral(PIOC, portc_mask, PERIPH_A, 0);
Julien May70664122008-08-04 14:27:38 +02001504
1505 /* LCDC on port D */
Julien Maycaf18f12008-09-24 10:30:47 +02001506 portd_mask = pin_mask & 0x0003ffff;
1507 select_peripheral(PIOD, portd_mask, PERIPH_A, 0);
Julien May70664122008-08-04 14:27:38 +02001508
1509 /* LCDC on port E */
Julien Maycaf18f12008-09-24 10:30:47 +02001510 porte_mask = (pin_mask >> 32) & 0x0007ffff;
1511 select_peripheral(PIOE, porte_mask, PERIPH_B, 0);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001512
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001513 clk_set_parent(&atmel_lcdfb0_pixclk, &pll0);
1514 clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001515 break;
1516
1517 default:
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001518 goto err_invalid_id;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001519 }
1520
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001521 if (fbmem_len) {
1522 pdev->resource[2].start = fbmem_start;
1523 pdev->resource[2].end = fbmem_start + fbmem_len - 1;
1524 pdev->resource[2].flags = IORESOURCE_MEM;
1525 }
1526
1527 info = pdev->dev.platform_data;
1528 memcpy(info, data, sizeof(struct atmel_lcdfb_info));
1529 info->default_monspecs = monspecs;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001530
1531 platform_device_register(pdev);
1532 return pdev;
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001533
1534err_invalid_id:
1535 kfree(modedb);
1536err_dup_modedb:
1537 kfree(monspecs);
1538 return NULL;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001539}
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001540#endif
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001541
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01001542/* --------------------------------------------------------------------
David Brownell9a1e8eb2008-02-08 04:21:21 -08001543 * PWM
1544 * -------------------------------------------------------------------- */
1545static struct resource atmel_pwm0_resource[] __initdata = {
1546 PBMEM(0xfff01400),
1547 IRQ(24),
1548};
1549static struct clk atmel_pwm0_mck = {
Sedji Gaouaou84059962008-06-25 10:32:50 +02001550 .name = "pwm_clk",
David Brownell9a1e8eb2008-02-08 04:21:21 -08001551 .parent = &pbb_clk,
1552 .mode = pbb_clk_mode,
1553 .get_rate = pbb_clk_get_rate,
1554 .index = 5,
1555};
1556
1557struct platform_device *__init at32_add_device_pwm(u32 mask)
1558{
1559 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001560 u32 pin_mask;
David Brownell9a1e8eb2008-02-08 04:21:21 -08001561
1562 if (!mask)
1563 return NULL;
1564
1565 pdev = platform_device_alloc("atmel_pwm", 0);
1566 if (!pdev)
1567 return NULL;
1568
1569 if (platform_device_add_resources(pdev, atmel_pwm0_resource,
1570 ARRAY_SIZE(atmel_pwm0_resource)))
1571 goto out_free_pdev;
1572
1573 if (platform_device_add_data(pdev, &mask, sizeof(mask)))
1574 goto out_free_pdev;
1575
Julien Maycaf18f12008-09-24 10:30:47 +02001576 pin_mask = 0;
David Brownell9a1e8eb2008-02-08 04:21:21 -08001577 if (mask & (1 << 0))
Julien Maycaf18f12008-09-24 10:30:47 +02001578 pin_mask |= (1 << 28);
David Brownell9a1e8eb2008-02-08 04:21:21 -08001579 if (mask & (1 << 1))
Julien Maycaf18f12008-09-24 10:30:47 +02001580 pin_mask |= (1 << 29);
1581 if (pin_mask > 0)
1582 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
1583
1584 pin_mask = 0;
David Brownell9a1e8eb2008-02-08 04:21:21 -08001585 if (mask & (1 << 2))
Julien Maycaf18f12008-09-24 10:30:47 +02001586 pin_mask |= (1 << 21);
David Brownell9a1e8eb2008-02-08 04:21:21 -08001587 if (mask & (1 << 3))
Julien Maycaf18f12008-09-24 10:30:47 +02001588 pin_mask |= (1 << 22);
1589 if (pin_mask > 0)
1590 select_peripheral(PIOA, pin_mask, PERIPH_B, 0);
David Brownell9a1e8eb2008-02-08 04:21:21 -08001591
1592 atmel_pwm0_mck.dev = &pdev->dev;
1593
1594 platform_device_add(pdev);
1595
1596 return pdev;
1597
1598out_free_pdev:
1599 platform_device_put(pdev);
1600 return NULL;
1601}
1602
1603/* --------------------------------------------------------------------
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001604 * SSC
1605 * -------------------------------------------------------------------- */
1606static struct resource ssc0_resource[] = {
1607 PBMEM(0xffe01c00),
1608 IRQ(10),
1609};
1610DEFINE_DEV(ssc, 0);
1611DEV_CLK(pclk, ssc0, pba, 7);
1612
1613static struct resource ssc1_resource[] = {
1614 PBMEM(0xffe02000),
1615 IRQ(11),
1616};
1617DEFINE_DEV(ssc, 1);
1618DEV_CLK(pclk, ssc1, pba, 8);
1619
1620static struct resource ssc2_resource[] = {
1621 PBMEM(0xffe02400),
1622 IRQ(12),
1623};
1624DEFINE_DEV(ssc, 2);
1625DEV_CLK(pclk, ssc2, pba, 9);
1626
1627struct platform_device *__init
1628at32_add_device_ssc(unsigned int id, unsigned int flags)
1629{
1630 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001631 u32 pin_mask = 0;
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001632
1633 switch (id) {
1634 case 0:
1635 pdev = &ssc0_device;
1636 if (flags & ATMEL_SSC_RF)
Julien Maycaf18f12008-09-24 10:30:47 +02001637 pin_mask |= (1 << 21); /* RF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001638 if (flags & ATMEL_SSC_RK)
Julien Maycaf18f12008-09-24 10:30:47 +02001639 pin_mask |= (1 << 22); /* RK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001640 if (flags & ATMEL_SSC_TK)
Julien Maycaf18f12008-09-24 10:30:47 +02001641 pin_mask |= (1 << 23); /* TK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001642 if (flags & ATMEL_SSC_TF)
Julien Maycaf18f12008-09-24 10:30:47 +02001643 pin_mask |= (1 << 24); /* TF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001644 if (flags & ATMEL_SSC_TD)
Julien Maycaf18f12008-09-24 10:30:47 +02001645 pin_mask |= (1 << 25); /* TD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001646 if (flags & ATMEL_SSC_RD)
Julien Maycaf18f12008-09-24 10:30:47 +02001647 pin_mask |= (1 << 26); /* RD */
1648
1649 if (pin_mask > 0)
1650 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
1651
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001652 break;
1653 case 1:
1654 pdev = &ssc1_device;
1655 if (flags & ATMEL_SSC_RF)
Julien Maycaf18f12008-09-24 10:30:47 +02001656 pin_mask |= (1 << 0); /* RF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001657 if (flags & ATMEL_SSC_RK)
Julien Maycaf18f12008-09-24 10:30:47 +02001658 pin_mask |= (1 << 1); /* RK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001659 if (flags & ATMEL_SSC_TK)
Julien Maycaf18f12008-09-24 10:30:47 +02001660 pin_mask |= (1 << 2); /* TK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001661 if (flags & ATMEL_SSC_TF)
Julien Maycaf18f12008-09-24 10:30:47 +02001662 pin_mask |= (1 << 3); /* TF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001663 if (flags & ATMEL_SSC_TD)
Julien Maycaf18f12008-09-24 10:30:47 +02001664 pin_mask |= (1 << 4); /* TD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001665 if (flags & ATMEL_SSC_RD)
Julien Maycaf18f12008-09-24 10:30:47 +02001666 pin_mask |= (1 << 5); /* RD */
1667
1668 if (pin_mask > 0)
1669 select_peripheral(PIOA, pin_mask, PERIPH_B, 0);
1670
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001671 break;
1672 case 2:
1673 pdev = &ssc2_device;
1674 if (flags & ATMEL_SSC_TD)
Julien Maycaf18f12008-09-24 10:30:47 +02001675 pin_mask |= (1 << 13); /* TD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001676 if (flags & ATMEL_SSC_RD)
Julien Maycaf18f12008-09-24 10:30:47 +02001677 pin_mask |= (1 << 14); /* RD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001678 if (flags & ATMEL_SSC_TK)
Julien Maycaf18f12008-09-24 10:30:47 +02001679 pin_mask |= (1 << 15); /* TK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001680 if (flags & ATMEL_SSC_TF)
Julien Maycaf18f12008-09-24 10:30:47 +02001681 pin_mask |= (1 << 16); /* TF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001682 if (flags & ATMEL_SSC_RF)
Julien Maycaf18f12008-09-24 10:30:47 +02001683 pin_mask |= (1 << 17); /* RF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001684 if (flags & ATMEL_SSC_RK)
Julien Maycaf18f12008-09-24 10:30:47 +02001685 pin_mask |= (1 << 18); /* RK */
1686
1687 if (pin_mask > 0)
1688 select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
1689
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001690 break;
1691 default:
1692 return NULL;
1693 }
1694
1695 platform_device_register(pdev);
1696 return pdev;
1697}
1698
1699/* --------------------------------------------------------------------
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001700 * USB Device Controller
1701 * -------------------------------------------------------------------- */
1702static struct resource usba0_resource[] __initdata = {
1703 {
1704 .start = 0xff300000,
1705 .end = 0xff3fffff,
1706 .flags = IORESOURCE_MEM,
1707 }, {
1708 .start = 0xfff03000,
1709 .end = 0xfff033ff,
1710 .flags = IORESOURCE_MEM,
1711 },
1712 IRQ(31),
1713};
1714static struct clk usba0_pclk = {
1715 .name = "pclk",
1716 .parent = &pbb_clk,
1717 .mode = pbb_clk_mode,
1718 .get_rate = pbb_clk_get_rate,
1719 .index = 12,
1720};
1721static struct clk usba0_hclk = {
1722 .name = "hclk",
1723 .parent = &hsb_clk,
1724 .mode = hsb_clk_mode,
1725 .get_rate = hsb_clk_get_rate,
1726 .index = 6,
1727};
1728
Stelian Pop8d855312008-03-05 00:00:00 +01001729#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
1730 [idx] = { \
1731 .name = nam, \
1732 .index = idx, \
1733 .fifo_size = maxpkt, \
1734 .nr_banks = maxbk, \
1735 .can_dma = dma, \
1736 .can_isoc = isoc, \
1737 }
1738
1739static struct usba_ep_data at32_usba_ep[] __initdata = {
1740 EP("ep0", 0, 64, 1, 0, 0),
1741 EP("ep1", 1, 512, 2, 1, 1),
1742 EP("ep2", 2, 512, 2, 1, 1),
1743 EP("ep3-int", 3, 64, 3, 1, 0),
1744 EP("ep4-int", 4, 64, 3, 1, 0),
1745 EP("ep5", 5, 1024, 3, 1, 1),
1746 EP("ep6", 6, 1024, 3, 1, 1),
1747};
1748
1749#undef EP
1750
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001751struct platform_device *__init
1752at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
1753{
Stelian Pop8d855312008-03-05 00:00:00 +01001754 /*
1755 * pdata doesn't have room for any endpoints, so we need to
1756 * append room for the ones we need right after it.
1757 */
1758 struct {
1759 struct usba_platform_data pdata;
1760 struct usba_ep_data ep[7];
1761 } usba_data;
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001762 struct platform_device *pdev;
1763
1764 if (id != 0)
1765 return NULL;
1766
1767 pdev = platform_device_alloc("atmel_usba_udc", 0);
1768 if (!pdev)
1769 return NULL;
1770
1771 if (platform_device_add_resources(pdev, usba0_resource,
1772 ARRAY_SIZE(usba0_resource)))
1773 goto out_free_pdev;
1774
Eirik Aanonsen640e95a2010-02-05 09:49:25 +01001775 if (data) {
Stelian Pop8d855312008-03-05 00:00:00 +01001776 usba_data.pdata.vbus_pin = data->vbus_pin;
Eirik Aanonsen640e95a2010-02-05 09:49:25 +01001777 usba_data.pdata.vbus_pin_inverted = data->vbus_pin_inverted;
1778 } else {
Stelian Pop8d855312008-03-05 00:00:00 +01001779 usba_data.pdata.vbus_pin = -EINVAL;
Eirik Aanonsen640e95a2010-02-05 09:49:25 +01001780 usba_data.pdata.vbus_pin_inverted = -EINVAL;
1781 }
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001782
Stelian Pop8d855312008-03-05 00:00:00 +01001783 data = &usba_data.pdata;
1784 data->num_ep = ARRAY_SIZE(at32_usba_ep);
1785 memcpy(data->ep, at32_usba_ep, sizeof(at32_usba_ep));
1786
1787 if (platform_device_add_data(pdev, data, sizeof(usba_data)))
1788 goto out_free_pdev;
1789
Hans-Christian Egtvedt9477ab22009-03-24 15:45:21 +01001790 if (gpio_is_valid(data->vbus_pin))
Stelian Pop8d855312008-03-05 00:00:00 +01001791 at32_select_gpio(data->vbus_pin, 0);
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001792
1793 usba0_pclk.dev = &pdev->dev;
1794 usba0_hclk.dev = &pdev->dev;
1795
1796 platform_device_add(pdev);
1797
1798 return pdev;
1799
1800out_free_pdev:
1801 platform_device_put(pdev);
1802 return NULL;
1803}
1804
1805/* --------------------------------------------------------------------
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001806 * IDE / CompactFlash
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001807 * -------------------------------------------------------------------- */
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001808#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7001)
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001809static struct resource at32_smc_cs4_resource[] __initdata = {
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001810 {
1811 .start = 0x04000000,
1812 .end = 0x07ffffff,
1813 .flags = IORESOURCE_MEM,
1814 },
1815 IRQ(~0UL), /* Magic IRQ will be overridden */
1816};
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001817static struct resource at32_smc_cs5_resource[] __initdata = {
1818 {
1819 .start = 0x20000000,
1820 .end = 0x23ffffff,
1821 .flags = IORESOURCE_MEM,
1822 },
1823 IRQ(~0UL), /* Magic IRQ will be overridden */
1824};
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001825
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001826static int __init at32_init_ide_or_cf(struct platform_device *pdev,
1827 unsigned int cs, unsigned int extint)
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001828{
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001829 static unsigned int extint_pin_map[4] __initdata = {
Julien Maycaf18f12008-09-24 10:30:47 +02001830 (1 << 25),
1831 (1 << 26),
1832 (1 << 27),
1833 (1 << 28),
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001834 };
1835 static bool common_pins_initialized __initdata = false;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001836 unsigned int extint_pin;
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001837 int ret;
Julien Maycaf18f12008-09-24 10:30:47 +02001838 u32 pin_mask;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001839
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001840 if (extint >= ARRAY_SIZE(extint_pin_map))
1841 return -EINVAL;
1842 extint_pin = extint_pin_map[extint];
1843
1844 switch (cs) {
1845 case 4:
1846 ret = platform_device_add_resources(pdev,
1847 at32_smc_cs4_resource,
1848 ARRAY_SIZE(at32_smc_cs4_resource));
1849 if (ret)
1850 return ret;
1851
Julien Maycaf18f12008-09-24 10:30:47 +02001852 /* NCS4 -> OE_N */
1853 select_peripheral(PIOE, (1 << 21), PERIPH_A, 0);
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02001854 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF0_ENABLE);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001855 break;
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001856 case 5:
1857 ret = platform_device_add_resources(pdev,
1858 at32_smc_cs5_resource,
1859 ARRAY_SIZE(at32_smc_cs5_resource));
1860 if (ret)
1861 return ret;
1862
Julien Maycaf18f12008-09-24 10:30:47 +02001863 /* NCS5 -> OE_N */
1864 select_peripheral(PIOE, (1 << 22), PERIPH_A, 0);
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02001865 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF1_ENABLE);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001866 break;
1867 default:
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001868 return -EINVAL;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001869 }
1870
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001871 if (!common_pins_initialized) {
Julien Maycaf18f12008-09-24 10:30:47 +02001872 pin_mask = (1 << 19); /* CFCE1 -> CS0_N */
1873 pin_mask |= (1 << 20); /* CFCE2 -> CS1_N */
1874 pin_mask |= (1 << 23); /* CFRNW -> DIR */
1875 pin_mask |= (1 << 24); /* NWAIT <- IORDY */
1876
1877 select_peripheral(PIOE, pin_mask, PERIPH_A, 0);
1878
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001879 common_pins_initialized = true;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001880 }
1881
Julien Maycaf18f12008-09-24 10:30:47 +02001882 select_peripheral(PIOB, extint_pin, PERIPH_A, AT32_GPIOF_DEGLITCH);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001883
1884 pdev->resource[1].start = EIM_IRQ_BASE + extint;
1885 pdev->resource[1].end = pdev->resource[1].start;
1886
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001887 return 0;
1888}
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001889
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001890struct platform_device *__init
1891at32_add_device_ide(unsigned int id, unsigned int extint,
1892 struct ide_platform_data *data)
1893{
1894 struct platform_device *pdev;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001895
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001896 pdev = platform_device_alloc("at32_ide", id);
1897 if (!pdev)
1898 goto fail;
1899
1900 if (platform_device_add_data(pdev, data,
1901 sizeof(struct ide_platform_data)))
1902 goto fail;
1903
1904 if (at32_init_ide_or_cf(pdev, data->cs, extint))
1905 goto fail;
1906
1907 platform_device_add(pdev);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001908 return pdev;
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001909
1910fail:
1911 platform_device_put(pdev);
1912 return NULL;
1913}
1914
1915struct platform_device *__init
1916at32_add_device_cf(unsigned int id, unsigned int extint,
1917 struct cf_platform_data *data)
1918{
1919 struct platform_device *pdev;
1920
1921 pdev = platform_device_alloc("at32_cf", id);
1922 if (!pdev)
1923 goto fail;
1924
1925 if (platform_device_add_data(pdev, data,
1926 sizeof(struct cf_platform_data)))
1927 goto fail;
1928
1929 if (at32_init_ide_or_cf(pdev, data->cs, extint))
1930 goto fail;
1931
David Brownell3c26e172008-07-27 02:34:45 -07001932 if (gpio_is_valid(data->detect_pin))
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001933 at32_select_gpio(data->detect_pin, AT32_GPIOF_DEGLITCH);
David Brownell3c26e172008-07-27 02:34:45 -07001934 if (gpio_is_valid(data->reset_pin))
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001935 at32_select_gpio(data->reset_pin, 0);
David Brownell3c26e172008-07-27 02:34:45 -07001936 if (gpio_is_valid(data->vcc_pin))
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001937 at32_select_gpio(data->vcc_pin, 0);
1938 /* READY is used as extint, so we can't select it as gpio */
1939
1940 platform_device_add(pdev);
1941 return pdev;
1942
1943fail:
1944 platform_device_put(pdev);
1945 return NULL;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001946}
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001947#endif
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001948
1949/* --------------------------------------------------------------------
HÃ¥vard Skinnemoen62090a02008-06-06 18:04:56 +02001950 * NAND Flash / SmartMedia
1951 * -------------------------------------------------------------------- */
1952static struct resource smc_cs3_resource[] __initdata = {
1953 {
1954 .start = 0x0c000000,
1955 .end = 0x0fffffff,
1956 .flags = IORESOURCE_MEM,
1957 }, {
1958 .start = 0xfff03c00,
1959 .end = 0xfff03fff,
1960 .flags = IORESOURCE_MEM,
1961 },
1962};
1963
1964struct platform_device *__init
1965at32_add_device_nand(unsigned int id, struct atmel_nand_data *data)
1966{
1967 struct platform_device *pdev;
1968
1969 if (id != 0 || !data)
1970 return NULL;
1971
1972 pdev = platform_device_alloc("atmel_nand", id);
1973 if (!pdev)
1974 goto fail;
1975
1976 if (platform_device_add_resources(pdev, smc_cs3_resource,
1977 ARRAY_SIZE(smc_cs3_resource)))
1978 goto fail;
1979
1980 if (platform_device_add_data(pdev, data,
1981 sizeof(struct atmel_nand_data)))
1982 goto fail;
1983
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02001984 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_NAND_ENABLE);
HÃ¥vard Skinnemoen62090a02008-06-06 18:04:56 +02001985 if (data->enable_pin)
1986 at32_select_gpio(data->enable_pin,
1987 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
1988 if (data->rdy_pin)
1989 at32_select_gpio(data->rdy_pin, 0);
1990 if (data->det_pin)
1991 at32_select_gpio(data->det_pin, 0);
1992
1993 platform_device_add(pdev);
1994 return pdev;
1995
1996fail:
1997 platform_device_put(pdev);
1998 return NULL;
1999}
2000
2001/* --------------------------------------------------------------------
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002002 * AC97C
2003 * -------------------------------------------------------------------- */
2004static struct resource atmel_ac97c0_resource[] __initdata = {
2005 PBMEM(0xfff02800),
2006 IRQ(29),
2007};
2008static struct clk atmel_ac97c0_pclk = {
2009 .name = "pclk",
2010 .parent = &pbb_clk,
2011 .mode = pbb_clk_mode,
2012 .get_rate = pbb_clk_get_rate,
2013 .index = 10,
2014};
2015
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002016struct platform_device *__init
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002017at32_add_device_ac97c(unsigned int id, struct ac97c_platform_data *data,
2018 unsigned int flags)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002019{
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002020 struct platform_device *pdev;
2021 struct dw_dma_slave *rx_dws;
2022 struct dw_dma_slave *tx_dws;
2023 struct ac97c_platform_data _data;
2024 u32 pin_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002025
2026 if (id != 0)
2027 return NULL;
2028
2029 pdev = platform_device_alloc("atmel_ac97c", id);
2030 if (!pdev)
2031 return NULL;
2032
2033 if (platform_device_add_resources(pdev, atmel_ac97c0_resource,
2034 ARRAY_SIZE(atmel_ac97c0_resource)))
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002035 goto out_free_resources;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002036
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002037 if (!data) {
2038 data = &_data;
2039 memset(data, 0, sizeof(struct ac97c_platform_data));
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002040 data->reset_pin = -ENODEV;
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002041 }
2042
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002043 rx_dws = &data->rx_dws;
2044 tx_dws = &data->tx_dws;
2045
2046 /* Check if DMA slave interface for capture should be configured. */
2047 if (flags & AC97C_CAPTURE) {
2048 rx_dws->dma_dev = &dw_dmac0_device.dev;
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002049 rx_dws->cfg_hi = DWC_CFGH_SRC_PER(3);
2050 rx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
Jamie Iles4aa5f362011-01-21 14:11:55 +00002051 rx_dws->src_master = 0;
2052 rx_dws->dst_master = 1;
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002053 }
2054
2055 /* Check if DMA slave interface for playback should be configured. */
2056 if (flags & AC97C_PLAYBACK) {
2057 tx_dws->dma_dev = &dw_dmac0_device.dev;
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002058 tx_dws->cfg_hi = DWC_CFGH_DST_PER(4);
2059 tx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
Jamie Iles3ea205c2011-03-22 15:34:56 -07002060 tx_dws->src_master = 0;
2061 tx_dws->dst_master = 1;
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002062 }
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002063
2064 if (platform_device_add_data(pdev, data,
2065 sizeof(struct ac97c_platform_data)))
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002066 goto out_free_resources;
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002067
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002068 /* SDO | SYNC | SCLK | SDI */
2069 pin_mask = (1 << 20) | (1 << 21) | (1 << 22) | (1 << 23);
Julien Maycaf18f12008-09-24 10:30:47 +02002070
2071 select_peripheral(PIOB, pin_mask, PERIPH_B, 0);
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002072
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002073 if (gpio_is_valid(data->reset_pin))
2074 at32_select_gpio(data->reset_pin, AT32_GPIOF_OUTPUT
2075 | AT32_GPIOF_HIGH);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002076
2077 atmel_ac97c0_pclk.dev = &pdev->dev;
2078
2079 platform_device_add(pdev);
2080 return pdev;
2081
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002082out_free_resources:
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002083 platform_device_put(pdev);
2084 return NULL;
2085}
2086
2087/* --------------------------------------------------------------------
2088 * ABDAC
2089 * -------------------------------------------------------------------- */
2090static struct resource abdac0_resource[] __initdata = {
2091 PBMEM(0xfff02000),
2092 IRQ(27),
2093};
2094static struct clk abdac0_pclk = {
2095 .name = "pclk",
2096 .parent = &pbb_clk,
2097 .mode = pbb_clk_mode,
2098 .get_rate = pbb_clk_get_rate,
2099 .index = 8,
2100};
2101static struct clk abdac0_sample_clk = {
2102 .name = "sample_clk",
2103 .mode = genclk_mode,
2104 .get_rate = genclk_get_rate,
2105 .set_rate = genclk_set_rate,
2106 .set_parent = genclk_set_parent,
2107 .index = 6,
2108};
2109
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002110struct platform_device *__init
2111at32_add_device_abdac(unsigned int id, struct atmel_abdac_pdata *data)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002112{
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002113 struct platform_device *pdev;
2114 struct dw_dma_slave *dws;
2115 u32 pin_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002116
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002117 if (id != 0 || !data)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002118 return NULL;
2119
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002120 pdev = platform_device_alloc("atmel_abdac", id);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002121 if (!pdev)
2122 return NULL;
2123
2124 if (platform_device_add_resources(pdev, abdac0_resource,
2125 ARRAY_SIZE(abdac0_resource)))
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002126 goto out_free_resources;
2127
2128 dws = &data->dws;
2129
2130 dws->dma_dev = &dw_dmac0_device.dev;
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002131 dws->cfg_hi = DWC_CFGH_DST_PER(2);
2132 dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
Jamie Iles4aa5f362011-01-21 14:11:55 +00002133 dws->src_master = 0;
2134 dws->dst_master = 1;
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002135
2136 if (platform_device_add_data(pdev, data,
2137 sizeof(struct atmel_abdac_pdata)))
2138 goto out_free_resources;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002139
Julien Maycaf18f12008-09-24 10:30:47 +02002140 pin_mask = (1 << 20) | (1 << 22); /* DATA1 & DATAN1 */
2141 pin_mask |= (1 << 21) | (1 << 23); /* DATA0 & DATAN0 */
2142
2143 select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002144
2145 abdac0_pclk.dev = &pdev->dev;
2146 abdac0_sample_clk.dev = &pdev->dev;
2147
2148 platform_device_add(pdev);
2149 return pdev;
2150
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002151out_free_resources:
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002152 platform_device_put(pdev);
2153 return NULL;
2154}
2155
2156/* --------------------------------------------------------------------
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002157 * GCLK
2158 * -------------------------------------------------------------------- */
2159static struct clk gclk0 = {
2160 .name = "gclk0",
2161 .mode = genclk_mode,
2162 .get_rate = genclk_get_rate,
2163 .set_rate = genclk_set_rate,
2164 .set_parent = genclk_set_parent,
2165 .index = 0,
2166};
2167static struct clk gclk1 = {
2168 .name = "gclk1",
2169 .mode = genclk_mode,
2170 .get_rate = genclk_get_rate,
2171 .set_rate = genclk_set_rate,
2172 .set_parent = genclk_set_parent,
2173 .index = 1,
2174};
2175static struct clk gclk2 = {
2176 .name = "gclk2",
2177 .mode = genclk_mode,
2178 .get_rate = genclk_get_rate,
2179 .set_rate = genclk_set_rate,
2180 .set_parent = genclk_set_parent,
2181 .index = 2,
2182};
2183static struct clk gclk3 = {
2184 .name = "gclk3",
2185 .mode = genclk_mode,
2186 .get_rate = genclk_get_rate,
2187 .set_rate = genclk_set_rate,
2188 .set_parent = genclk_set_parent,
2189 .index = 3,
2190};
2191static struct clk gclk4 = {
2192 .name = "gclk4",
2193 .mode = genclk_mode,
2194 .get_rate = genclk_get_rate,
2195 .set_rate = genclk_set_rate,
2196 .set_parent = genclk_set_parent,
2197 .index = 4,
2198};
2199
Alex Raimondi300bb762008-09-22 21:40:55 +02002200static __initdata struct clk *init_clocks[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002201 &osc32k,
2202 &osc0,
2203 &osc1,
2204 &pll0,
2205 &pll1,
2206 &cpu_clk,
2207 &hsb_clk,
2208 &pba_clk,
2209 &pbb_clk,
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002210 &at32_pm_pclk,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002211 &at32_intc0_pclk,
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02002212 &at32_hmatrix_clk,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002213 &ebi_clk,
2214 &hramc_clk,
Haavard Skinnemoen7951f182008-03-05 15:08:27 +01002215 &sdramc_clk,
Haavard Skinnemoenbc157b72006-09-25 23:32:16 -07002216 &smc0_pclk,
2217 &smc0_mck,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002218 &pdc_hclk,
2219 &pdc_pclk,
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -07002220 &dw_dmac0_hclk,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002221 &pico_clk,
2222 &pio0_mck,
2223 &pio1_mck,
2224 &pio2_mck,
2225 &pio3_mck,
Haavard Skinnemoen7f9f4672007-01-30 11:16:16 +01002226 &pio4_mck,
David Brownelle723ff62008-02-14 11:24:02 -08002227 &at32_tcb0_t0_clk,
2228 &at32_tcb1_t0_clk,
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +01002229 &atmel_psif0_pclk,
2230 &atmel_psif1_pclk,
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02002231 &atmel_usart0_usart,
2232 &atmel_usart1_usart,
2233 &atmel_usart2_usart,
2234 &atmel_usart3_usart,
David Brownell9a1e8eb2008-02-08 04:21:21 -08002235 &atmel_pwm0_mck,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002236#if defined(CONFIG_CPU_AT32AP7000)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002237 &macb0_hclk,
2238 &macb0_pclk,
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01002239 &macb1_hclk,
2240 &macb1_pclk,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002241#endif
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01002242 &atmel_spi0_spi_clk,
2243 &atmel_spi1_spi_clk,
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002244 &atmel_twi0_pclk,
2245 &atmel_mci0_pclk,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002246#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01002247 &atmel_lcdfb0_hck1,
2248 &atmel_lcdfb0_pixclk,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002249#endif
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02002250 &ssc0_pclk,
2251 &ssc1_pclk,
2252 &ssc2_pclk,
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02002253 &usba0_hclk,
2254 &usba0_pclk,
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002255 &atmel_ac97c0_pclk,
2256 &abdac0_pclk,
2257 &abdac0_sample_clk,
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002258 &gclk0,
2259 &gclk1,
2260 &gclk2,
2261 &gclk3,
2262 &gclk4,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002263};
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002264
Haavard Skinnemoen65033ed2008-03-04 15:15:00 +01002265void __init setup_platform(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002266{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002267 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
2268 int i;
2269
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +02002270 if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002271 main_clock = &pll0;
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +02002272 cpu_clk.parent = &pll0;
2273 } else {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002274 main_clock = &osc0;
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +02002275 cpu_clk.parent = &osc0;
2276 }
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002277
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002278 if (pm_readl(PLL0) & PM_BIT(PLLOSC))
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002279 pll0.parent = &osc1;
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002280 if (pm_readl(PLL1) & PM_BIT(PLLOSC))
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002281 pll1.parent = &osc1;
2282
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002283 genclk_init_parent(&gclk0);
2284 genclk_init_parent(&gclk1);
2285 genclk_init_parent(&gclk2);
2286 genclk_init_parent(&gclk3);
2287 genclk_init_parent(&gclk4);
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002288#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01002289 genclk_init_parent(&atmel_lcdfb0_pixclk);
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002290#endif
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002291 genclk_init_parent(&abdac0_sample_clk);
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002292
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002293 /*
Alex Raimondi300bb762008-09-22 21:40:55 +02002294 * Build initial dynamic clock list by registering all clocks
2295 * from the array.
2296 * At the same time, turn on all clocks that have at least one
2297 * user already, and turn off everything else. We only do this
2298 * for module clocks, and even though it isn't particularly
2299 * pretty to check the address of the mode function, it should
2300 * do the trick...
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002301 */
Alex Raimondi300bb762008-09-22 21:40:55 +02002302 for (i = 0; i < ARRAY_SIZE(init_clocks); i++) {
2303 struct clk *clk = init_clocks[i];
2304
2305 /* first, register clock */
2306 at32_clk_register(clk);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002307
Haavard Skinnemoen188ff652007-03-14 13:23:44 +01002308 if (clk->users == 0)
2309 continue;
2310
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002311 if (clk->mode == &cpu_clk_mode)
2312 cpu_mask |= 1 << clk->index;
2313 else if (clk->mode == &hsb_clk_mode)
2314 hsb_mask |= 1 << clk->index;
2315 else if (clk->mode == &pba_clk_mode)
2316 pba_mask |= 1 << clk->index;
2317 else if (clk->mode == &pbb_clk_mode)
2318 pbb_mask |= 1 << clk->index;
2319 }
2320
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002321 pm_writel(CPU_MASK, cpu_mask);
2322 pm_writel(HSB_MASK, hsb_mask);
2323 pm_writel(PBA_MASK, pba_mask);
2324 pm_writel(PBB_MASK, pbb_mask);
Haavard Skinnemoen65033ed2008-03-04 15:15:00 +01002325
2326 /* Initialize the port muxes */
2327 at32_init_pio(&pio0_device);
2328 at32_init_pio(&pio1_device);
2329 at32_init_pio(&pio2_device);
2330 at32_init_pio(&pio3_device);
2331 at32_init_pio(&pio4_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002332}
Haavard Skinnemoenb83d6ee12008-03-05 10:00:28 +01002333
2334struct gen_pool *sram_pool;
2335
2336static int __init sram_init(void)
2337{
2338 struct gen_pool *pool;
2339
2340 /* 1KiB granularity */
2341 pool = gen_pool_create(10, -1);
2342 if (!pool)
2343 goto fail;
2344
2345 if (gen_pool_add(pool, 0x24000000, 0x8000, -1))
2346 goto err_pool_add;
2347
2348 sram_pool = pool;
2349 return 0;
2350
2351err_pool_add:
2352 gen_pool_destroy(pool);
2353fail:
2354 pr_err("Failed to create SRAM pool\n");
2355 return -ENOMEM;
2356}
2357core_initcall(sram_init);