blob: 1aa1ea5e92127984428e06747289f3e2f055f1d1 [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>
David Brownell3c26e172008-07-27 02:34:45 -070015#include <linux/gpio.h>
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +010016#include <linux/spi/spi.h>
Stelian Pop8d855312008-03-05 00:00:00 +010017#include <linux/usb/atmel_usba_udc.h>
Nicolas Ferre2635d1b2009-12-14 18:01:30 -080018
19#include <mach/atmel-mci.h>
Nicolas Ferrec42aa772008-11-20 15:59:12 +010020#include <linux/atmel-mci.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070021
22#include <asm/io.h>
Haavard Skinnemoene7ba1762007-10-10 14:58:29 +020023#include <asm/irq.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070024
Haavard Skinnemoen3663b732008-08-05 13:57:38 +020025#include <mach/at32ap700x.h>
26#include <mach/board.h>
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +020027#include <mach/hmatrix.h>
Haavard Skinnemoen3663b732008-08-05 13:57:38 +020028#include <mach/portmux.h>
29#include <mach/sram.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070030
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +010031#include <sound/atmel-abdac.h>
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +010032#include <sound/atmel-ac97c.h>
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +010033
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +010034#include <video/atmel_lcdc.h>
35
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070036#include "clock.h"
37#include "pio.h"
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +020038#include "pm.h"
39
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070040
41#define PBMEM(base) \
42 { \
43 .start = base, \
44 .end = base + 0x3ff, \
45 .flags = IORESOURCE_MEM, \
46 }
47#define IRQ(num) \
48 { \
49 .start = num, \
50 .end = num, \
51 .flags = IORESOURCE_IRQ, \
52 }
53#define NAMED_IRQ(num, _name) \
54 { \
55 .start = num, \
56 .end = num, \
57 .name = _name, \
58 .flags = IORESOURCE_IRQ, \
59 }
60
David Brownell6b84bbf2007-06-22 19:17:57 -070061/* REVISIT these assume *every* device supports DMA, but several
62 * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more.
63 */
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070064#define DEFINE_DEV(_name, _id) \
Yang Hongyang284901a2009-04-06 19:01:15 -070065static u64 _name##_id##_dma_mask = DMA_BIT_MASK(32); \
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070066static struct platform_device _name##_id##_device = { \
67 .name = #_name, \
68 .id = _id, \
69 .dev = { \
David Brownell6b84bbf2007-06-22 19:17:57 -070070 .dma_mask = &_name##_id##_dma_mask, \
Yang Hongyang284901a2009-04-06 19:01:15 -070071 .coherent_dma_mask = DMA_BIT_MASK(32), \
David Brownell6b84bbf2007-06-22 19:17:57 -070072 }, \
73 .resource = _name##_id##_resource, \
74 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
75}
76#define DEFINE_DEV_DATA(_name, _id) \
Yang Hongyang284901a2009-04-06 19:01:15 -070077static u64 _name##_id##_dma_mask = DMA_BIT_MASK(32); \
David Brownell6b84bbf2007-06-22 19:17:57 -070078static struct platform_device _name##_id##_device = { \
79 .name = #_name, \
80 .id = _id, \
81 .dev = { \
82 .dma_mask = &_name##_id##_dma_mask, \
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070083 .platform_data = &_name##_id##_data, \
Yang Hongyang284901a2009-04-06 19:01:15 -070084 .coherent_dma_mask = DMA_BIT_MASK(32), \
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070085 }, \
86 .resource = _name##_id##_resource, \
87 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
88}
89
Julien Maycaf18f12008-09-24 10:30:47 +020090#define select_peripheral(port, pin_mask, periph, flags) \
91 at32_select_periph(GPIO_##port##_BASE, pin_mask, \
92 GPIO_##periph, flags)
Haavard Skinnemoenc3e2a792006-12-04 13:46:52 +010093
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070094#define DEV_CLK(_name, devname, bus, _index) \
95static struct clk devname##_##_name = { \
96 .name = #_name, \
97 .dev = &devname##_device.dev, \
98 .parent = &bus##_clk, \
99 .mode = bus##_clk_mode, \
100 .get_rate = bus##_clk_get_rate, \
101 .index = _index, \
102}
103
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200104static DEFINE_SPINLOCK(pm_lock);
105
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100106static struct clk osc0;
107static struct clk osc1;
108
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700109static unsigned long osc_get_rate(struct clk *clk)
110{
Alex60ed7952008-03-17 14:55:06 +0100111 return at32_board_osc_rates[clk->index];
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700112}
113
114static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
115{
116 unsigned long div, mul, rate;
117
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200118 div = PM_BFEXT(PLLDIV, control) + 1;
119 mul = PM_BFEXT(PLLMUL, control) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700120
121 rate = clk->parent->get_rate(clk->parent);
122 rate = (rate + div / 2) / div;
123 rate *= mul;
124
125 return rate;
126}
127
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100128static long pll_set_rate(struct clk *clk, unsigned long rate,
129 u32 *pll_ctrl)
130{
131 unsigned long mul;
132 unsigned long mul_best_fit = 0;
133 unsigned long div;
134 unsigned long div_min;
135 unsigned long div_max;
136 unsigned long div_best_fit = 0;
137 unsigned long base;
138 unsigned long pll_in;
139 unsigned long actual = 0;
140 unsigned long rate_error;
141 unsigned long rate_error_prev = ~0UL;
142 u32 ctrl;
143
144 /* Rate must be between 80 MHz and 200 Mhz. */
145 if (rate < 80000000UL || rate > 200000000UL)
146 return -EINVAL;
147
148 ctrl = PM_BF(PLLOPT, 4);
149 base = clk->parent->get_rate(clk->parent);
150
151 /* PLL input frequency must be between 6 MHz and 32 MHz. */
152 div_min = DIV_ROUND_UP(base, 32000000UL);
153 div_max = base / 6000000UL;
154
155 if (div_max < div_min)
156 return -EINVAL;
157
158 for (div = div_min; div <= div_max; div++) {
159 pll_in = (base + div / 2) / div;
160 mul = (rate + pll_in / 2) / pll_in;
161
162 if (mul == 0)
163 continue;
164
165 actual = pll_in * mul;
166 rate_error = abs(actual - rate);
167
168 if (rate_error < rate_error_prev) {
169 mul_best_fit = mul;
170 div_best_fit = div;
171 rate_error_prev = rate_error;
172 }
173
174 if (rate_error == 0)
175 break;
176 }
177
178 if (div_best_fit == 0)
179 return -EINVAL;
180
181 ctrl |= PM_BF(PLLMUL, mul_best_fit - 1);
182 ctrl |= PM_BF(PLLDIV, div_best_fit - 1);
183 ctrl |= PM_BF(PLLCOUNT, 16);
184
185 if (clk->parent == &osc1)
186 ctrl |= PM_BIT(PLLOSC);
187
188 *pll_ctrl = ctrl;
189
190 return actual;
191}
192
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700193static unsigned long pll0_get_rate(struct clk *clk)
194{
195 u32 control;
196
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200197 control = pm_readl(PLL0);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700198
199 return pll_get_rate(clk, control);
200}
201
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100202static void pll1_mode(struct clk *clk, int enabled)
203{
204 unsigned long timeout;
205 u32 status;
206 u32 ctrl;
207
208 ctrl = pm_readl(PLL1);
209
210 if (enabled) {
211 if (!PM_BFEXT(PLLMUL, ctrl) && !PM_BFEXT(PLLDIV, ctrl)) {
212 pr_debug("clk %s: failed to enable, rate not set\n",
213 clk->name);
214 return;
215 }
216
217 ctrl |= PM_BIT(PLLEN);
218 pm_writel(PLL1, ctrl);
219
220 /* Wait for PLL lock. */
221 for (timeout = 10000; timeout; timeout--) {
222 status = pm_readl(ISR);
223 if (status & PM_BIT(LOCK1))
224 break;
225 udelay(10);
226 }
227
228 if (!(status & PM_BIT(LOCK1)))
229 printk(KERN_ERR "clk %s: timeout waiting for lock\n",
230 clk->name);
231 } else {
232 ctrl &= ~PM_BIT(PLLEN);
233 pm_writel(PLL1, ctrl);
234 }
235}
236
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700237static unsigned long pll1_get_rate(struct clk *clk)
238{
239 u32 control;
240
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200241 control = pm_readl(PLL1);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700242
243 return pll_get_rate(clk, control);
244}
245
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100246static long pll1_set_rate(struct clk *clk, unsigned long rate, int apply)
247{
248 u32 ctrl = 0;
249 unsigned long actual_rate;
250
251 actual_rate = pll_set_rate(clk, rate, &ctrl);
252
253 if (apply) {
254 if (actual_rate != rate)
255 return -EINVAL;
256 if (clk->users > 0)
257 return -EBUSY;
258 pr_debug(KERN_INFO "clk %s: new rate %lu (actual rate %lu)\n",
259 clk->name, rate, actual_rate);
260 pm_writel(PLL1, ctrl);
261 }
262
263 return actual_rate;
264}
265
266static int pll1_set_parent(struct clk *clk, struct clk *parent)
267{
268 u32 ctrl;
269
270 if (clk->users > 0)
271 return -EBUSY;
272
273 ctrl = pm_readl(PLL1);
274 WARN_ON(ctrl & PM_BIT(PLLEN));
275
276 if (parent == &osc0)
277 ctrl &= ~PM_BIT(PLLOSC);
278 else if (parent == &osc1)
279 ctrl |= PM_BIT(PLLOSC);
280 else
281 return -EINVAL;
282
283 pm_writel(PLL1, ctrl);
284 clk->parent = parent;
285
286 return 0;
287}
288
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700289/*
290 * The AT32AP7000 has five primary clock sources: One 32kHz
291 * oscillator, two crystal oscillators and two PLLs.
292 */
293static struct clk osc32k = {
294 .name = "osc32k",
295 .get_rate = osc_get_rate,
296 .users = 1,
297 .index = 0,
298};
299static struct clk osc0 = {
300 .name = "osc0",
301 .get_rate = osc_get_rate,
302 .users = 1,
303 .index = 1,
304};
305static struct clk osc1 = {
306 .name = "osc1",
307 .get_rate = osc_get_rate,
308 .index = 2,
309};
310static struct clk pll0 = {
311 .name = "pll0",
312 .get_rate = pll0_get_rate,
313 .parent = &osc0,
314};
315static struct clk pll1 = {
316 .name = "pll1",
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100317 .mode = pll1_mode,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700318 .get_rate = pll1_get_rate,
Hans-Christian Egtvedt35bf50c2007-12-19 09:29:19 +0100319 .set_rate = pll1_set_rate,
320 .set_parent = pll1_set_parent,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700321 .parent = &osc0,
322};
323
324/*
325 * The main clock can be either osc0 or pll0. The boot loader may
326 * have chosen one for us, so we don't really know which one until we
327 * have a look at the SM.
328 */
329static struct clk *main_clock;
330
331/*
332 * Synchronous clocks are generated from the main clock. The clocks
333 * must satisfy the constraint
334 * fCPU >= fHSB >= fPB
335 * i.e. each clock must not be faster than its parent.
336 */
337static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
338{
339 return main_clock->get_rate(main_clock) >> shift;
340};
341
342static void cpu_clk_mode(struct clk *clk, int enabled)
343{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700344 unsigned long flags;
345 u32 mask;
346
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200347 spin_lock_irqsave(&pm_lock, flags);
348 mask = pm_readl(CPU_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700349 if (enabled)
350 mask |= 1 << clk->index;
351 else
352 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200353 pm_writel(CPU_MASK, mask);
354 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700355}
356
357static unsigned long cpu_clk_get_rate(struct clk *clk)
358{
359 unsigned long cksel, shift = 0;
360
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200361 cksel = pm_readl(CKSEL);
362 if (cksel & PM_BIT(CPUDIV))
363 shift = PM_BFEXT(CPUSEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700364
365 return bus_clk_get_rate(clk, shift);
366}
367
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +0200368static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
369{
370 u32 control;
371 unsigned long parent_rate, child_div, actual_rate, div;
372
373 parent_rate = clk->parent->get_rate(clk->parent);
374 control = pm_readl(CKSEL);
375
376 if (control & PM_BIT(HSBDIV))
377 child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
378 else
379 child_div = 1;
380
381 if (rate > 3 * (parent_rate / 4) || child_div == 1) {
382 actual_rate = parent_rate;
383 control &= ~PM_BIT(CPUDIV);
384 } else {
385 unsigned int cpusel;
386 div = (parent_rate + rate / 2) / rate;
387 if (div > child_div)
388 div = child_div;
389 cpusel = (div > 1) ? (fls(div) - 2) : 0;
390 control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
391 actual_rate = parent_rate / (1 << (cpusel + 1));
392 }
393
394 pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
395 clk->name, rate, actual_rate);
396
397 if (apply)
398 pm_writel(CKSEL, control);
399
400 return actual_rate;
401}
402
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700403static void hsb_clk_mode(struct clk *clk, int enabled)
404{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700405 unsigned long flags;
406 u32 mask;
407
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200408 spin_lock_irqsave(&pm_lock, flags);
409 mask = pm_readl(HSB_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700410 if (enabled)
411 mask |= 1 << clk->index;
412 else
413 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200414 pm_writel(HSB_MASK, mask);
415 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700416}
417
418static unsigned long hsb_clk_get_rate(struct clk *clk)
419{
420 unsigned long cksel, shift = 0;
421
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200422 cksel = pm_readl(CKSEL);
423 if (cksel & PM_BIT(HSBDIV))
424 shift = PM_BFEXT(HSBSEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700425
426 return bus_clk_get_rate(clk, shift);
427}
428
Alex Raimondidd5e1332008-12-09 16:17:13 +0100429void pba_clk_mode(struct clk *clk, int enabled)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700430{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700431 unsigned long flags;
432 u32 mask;
433
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200434 spin_lock_irqsave(&pm_lock, flags);
435 mask = pm_readl(PBA_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700436 if (enabled)
437 mask |= 1 << clk->index;
438 else
439 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200440 pm_writel(PBA_MASK, mask);
441 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700442}
443
Alex Raimondidd5e1332008-12-09 16:17:13 +0100444unsigned long pba_clk_get_rate(struct clk *clk)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700445{
446 unsigned long cksel, shift = 0;
447
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200448 cksel = pm_readl(CKSEL);
449 if (cksel & PM_BIT(PBADIV))
450 shift = PM_BFEXT(PBASEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700451
452 return bus_clk_get_rate(clk, shift);
453}
454
455static void pbb_clk_mode(struct clk *clk, int enabled)
456{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700457 unsigned long flags;
458 u32 mask;
459
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200460 spin_lock_irqsave(&pm_lock, flags);
461 mask = pm_readl(PBB_MASK);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700462 if (enabled)
463 mask |= 1 << clk->index;
464 else
465 mask &= ~(1 << clk->index);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200466 pm_writel(PBB_MASK, mask);
467 spin_unlock_irqrestore(&pm_lock, flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700468}
469
470static unsigned long pbb_clk_get_rate(struct clk *clk)
471{
472 unsigned long cksel, shift = 0;
473
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200474 cksel = pm_readl(CKSEL);
475 if (cksel & PM_BIT(PBBDIV))
476 shift = PM_BFEXT(PBBSEL, cksel) + 1;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700477
478 return bus_clk_get_rate(clk, shift);
479}
480
481static struct clk cpu_clk = {
482 .name = "cpu",
483 .get_rate = cpu_clk_get_rate,
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +0200484 .set_rate = cpu_clk_set_rate,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700485 .users = 1,
486};
487static struct clk hsb_clk = {
488 .name = "hsb",
489 .parent = &cpu_clk,
490 .get_rate = hsb_clk_get_rate,
491};
492static struct clk pba_clk = {
493 .name = "pba",
494 .parent = &hsb_clk,
495 .mode = hsb_clk_mode,
496 .get_rate = pba_clk_get_rate,
497 .index = 1,
498};
499static struct clk pbb_clk = {
500 .name = "pbb",
501 .parent = &hsb_clk,
502 .mode = hsb_clk_mode,
503 .get_rate = pbb_clk_get_rate,
504 .users = 1,
505 .index = 2,
506};
507
508/* --------------------------------------------------------------------
509 * Generic Clock operations
510 * -------------------------------------------------------------------- */
511
512static void genclk_mode(struct clk *clk, int enabled)
513{
514 u32 control;
515
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200516 control = pm_readl(GCCTRL(clk->index));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700517 if (enabled)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200518 control |= PM_BIT(CEN);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700519 else
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200520 control &= ~PM_BIT(CEN);
521 pm_writel(GCCTRL(clk->index), control);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700522}
523
524static unsigned long genclk_get_rate(struct clk *clk)
525{
526 u32 control;
527 unsigned long div = 1;
528
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200529 control = pm_readl(GCCTRL(clk->index));
530 if (control & PM_BIT(DIVEN))
531 div = 2 * (PM_BFEXT(DIV, control) + 1);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700532
533 return clk->parent->get_rate(clk->parent) / div;
534}
535
536static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
537{
538 u32 control;
539 unsigned long parent_rate, actual_rate, div;
540
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700541 parent_rate = clk->parent->get_rate(clk->parent);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200542 control = pm_readl(GCCTRL(clk->index));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700543
544 if (rate > 3 * parent_rate / 4) {
545 actual_rate = parent_rate;
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200546 control &= ~PM_BIT(DIVEN);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700547 } else {
548 div = (parent_rate + rate) / (2 * rate) - 1;
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200549 control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700550 actual_rate = parent_rate / (2 * (div + 1));
551 }
552
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200553 dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
554 clk->name, rate, actual_rate);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700555
556 if (apply)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200557 pm_writel(GCCTRL(clk->index), control);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700558
559 return actual_rate;
560}
561
562int genclk_set_parent(struct clk *clk, struct clk *parent)
563{
564 u32 control;
565
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200566 dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
567 clk->name, parent->name, clk->parent->name);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700568
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200569 control = pm_readl(GCCTRL(clk->index));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700570
571 if (parent == &osc1 || parent == &pll1)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200572 control |= PM_BIT(OSCSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700573 else if (parent == &osc0 || parent == &pll0)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200574 control &= ~PM_BIT(OSCSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700575 else
576 return -EINVAL;
577
578 if (parent == &pll0 || parent == &pll1)
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200579 control |= PM_BIT(PLLSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700580 else
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200581 control &= ~PM_BIT(PLLSEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700582
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200583 pm_writel(GCCTRL(clk->index), control);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700584 clk->parent = parent;
585
586 return 0;
587}
588
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +0100589static void __init genclk_init_parent(struct clk *clk)
590{
591 u32 control;
592 struct clk *parent;
593
594 BUG_ON(clk->index > 7);
595
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200596 control = pm_readl(GCCTRL(clk->index));
597 if (control & PM_BIT(OSCSEL))
598 parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +0100599 else
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200600 parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +0100601
602 clk->parent = parent;
603}
604
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -0700605static struct dw_dma_platform_data dw_dmac0_data = {
606 .nr_channels = 3,
607};
608
609static struct resource dw_dmac0_resource[] = {
610 PBMEM(0xff200000),
611 IRQ(2),
612};
613DEFINE_DEV_DATA(dw_dmac, 0);
614DEV_CLK(hclk, dw_dmac0, hsb, 10);
615
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700616/* --------------------------------------------------------------------
617 * System peripherals
618 * -------------------------------------------------------------------- */
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200619static struct resource at32_pm0_resource[] = {
620 {
621 .start = 0xfff00000,
622 .end = 0xfff0007f,
623 .flags = IORESOURCE_MEM,
624 },
625 IRQ(20),
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700626};
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200627
628static struct resource at32ap700x_rtc0_resource[] = {
629 {
630 .start = 0xfff00080,
631 .end = 0xfff000af,
632 .flags = IORESOURCE_MEM,
633 },
634 IRQ(21),
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700635};
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200636
637static struct resource at32_wdt0_resource[] = {
638 {
639 .start = 0xfff000b0,
Hans-Christian Egtvedt9797bed2007-10-30 14:29:50 +0100640 .end = 0xfff000cf,
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200641 .flags = IORESOURCE_MEM,
642 },
643};
644
645static struct resource at32_eic0_resource[] = {
646 {
647 .start = 0xfff00100,
648 .end = 0xfff0013f,
649 .flags = IORESOURCE_MEM,
650 },
651 IRQ(19),
652};
653
654DEFINE_DEV(at32_pm, 0);
655DEFINE_DEV(at32ap700x_rtc, 0);
656DEFINE_DEV(at32_wdt, 0);
657DEFINE_DEV(at32_eic, 0);
658
659/*
660 * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
661 * is always running.
662 */
663static struct clk at32_pm_pclk = {
Haavard Skinnemoen188ff652007-03-14 13:23:44 +0100664 .name = "pclk",
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200665 .dev = &at32_pm0_device.dev,
Haavard Skinnemoen188ff652007-03-14 13:23:44 +0100666 .parent = &pbb_clk,
667 .mode = pbb_clk_mode,
668 .get_rate = pbb_clk_get_rate,
669 .users = 1,
670 .index = 0,
671};
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700672
673static struct resource intc0_resource[] = {
674 PBMEM(0xfff00400),
675};
676struct platform_device at32_intc0_device = {
677 .name = "intc",
678 .id = 0,
679 .resource = intc0_resource,
680 .num_resources = ARRAY_SIZE(intc0_resource),
681};
682DEV_CLK(pclk, at32_intc0, pbb, 1);
683
684static struct clk ebi_clk = {
685 .name = "ebi",
686 .parent = &hsb_clk,
687 .mode = hsb_clk_mode,
688 .get_rate = hsb_clk_get_rate,
689 .users = 1,
690};
691static struct clk hramc_clk = {
692 .name = "hramc",
693 .parent = &hsb_clk,
694 .mode = hsb_clk_mode,
695 .get_rate = hsb_clk_get_rate,
696 .users = 1,
Haavard Skinnemoen188ff652007-03-14 13:23:44 +0100697 .index = 3,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700698};
Haavard Skinnemoen7951f182008-03-05 15:08:27 +0100699static struct clk sdramc_clk = {
700 .name = "sdramc_clk",
701 .parent = &pbb_clk,
702 .mode = pbb_clk_mode,
703 .get_rate = pbb_clk_get_rate,
704 .users = 1,
705 .index = 14,
706};
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700707
Haavard Skinnemoenbc157b72006-09-25 23:32:16 -0700708static struct resource smc0_resource[] = {
709 PBMEM(0xfff03400),
710};
711DEFINE_DEV(smc, 0);
712DEV_CLK(pclk, smc0, pbb, 13);
713DEV_CLK(mck, smc0, hsb, 0);
714
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700715static struct platform_device pdc_device = {
716 .name = "pdc",
717 .id = 0,
718};
719DEV_CLK(hclk, pdc, hsb, 4);
720DEV_CLK(pclk, pdc, pba, 16);
721
722static struct clk pico_clk = {
723 .name = "pico",
724 .parent = &cpu_clk,
725 .mode = cpu_clk_mode,
726 .get_rate = cpu_clk_get_rate,
727 .users = 1,
728};
729
730/* --------------------------------------------------------------------
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100731 * HMATRIX
732 * -------------------------------------------------------------------- */
733
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +0200734struct clk at32_hmatrix_clk = {
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100735 .name = "hmatrix_clk",
736 .parent = &pbb_clk,
737 .mode = pbb_clk_mode,
738 .get_rate = pbb_clk_get_rate,
739 .index = 2,
740 .users = 1,
741};
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100742
743/*
744 * Set bits in the HMATRIX Special Function Register (SFR) used by the
745 * External Bus Interface (EBI). This can be used to enable special
746 * features like CompactFlash support, NAND Flash support, etc. on
747 * certain chipselects.
748 */
749static inline void set_ebi_sfr_bits(u32 mask)
750{
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +0200751 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, mask);
Haavard Skinnemoen9c8f8e72007-02-01 16:34:10 +0100752}
753
754/* --------------------------------------------------------------------
David Brownelle723ff62008-02-14 11:24:02 -0800755 * Timer/Counter (TC)
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100756 * -------------------------------------------------------------------- */
David Brownelle723ff62008-02-14 11:24:02 -0800757
758static struct resource at32_tcb0_resource[] = {
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100759 PBMEM(0xfff00c00),
760 IRQ(22),
761};
David Brownelle723ff62008-02-14 11:24:02 -0800762static struct platform_device at32_tcb0_device = {
763 .name = "atmel_tcb",
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100764 .id = 0,
David Brownelle723ff62008-02-14 11:24:02 -0800765 .resource = at32_tcb0_resource,
766 .num_resources = ARRAY_SIZE(at32_tcb0_resource),
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100767};
David Brownelle723ff62008-02-14 11:24:02 -0800768DEV_CLK(t0_clk, at32_tcb0, pbb, 3);
769
770static struct resource at32_tcb1_resource[] = {
771 PBMEM(0xfff01000),
772 IRQ(23),
773};
774static struct platform_device at32_tcb1_device = {
775 .name = "atmel_tcb",
776 .id = 1,
777 .resource = at32_tcb1_resource,
778 .num_resources = ARRAY_SIZE(at32_tcb1_resource),
779};
780DEV_CLK(t0_clk, at32_tcb1, pbb, 4);
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100781
782/* --------------------------------------------------------------------
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700783 * PIO
784 * -------------------------------------------------------------------- */
785
786static struct resource pio0_resource[] = {
787 PBMEM(0xffe02800),
788 IRQ(13),
789};
790DEFINE_DEV(pio, 0);
791DEV_CLK(mck, pio0, pba, 10);
792
793static struct resource pio1_resource[] = {
794 PBMEM(0xffe02c00),
795 IRQ(14),
796};
797DEFINE_DEV(pio, 1);
798DEV_CLK(mck, pio1, pba, 11);
799
800static struct resource pio2_resource[] = {
801 PBMEM(0xffe03000),
802 IRQ(15),
803};
804DEFINE_DEV(pio, 2);
805DEV_CLK(mck, pio2, pba, 12);
806
807static struct resource pio3_resource[] = {
808 PBMEM(0xffe03400),
809 IRQ(16),
810};
811DEFINE_DEV(pio, 3);
812DEV_CLK(mck, pio3, pba, 13);
813
Haavard Skinnemoen7f9f4672007-01-30 11:16:16 +0100814static struct resource pio4_resource[] = {
815 PBMEM(0xffe03800),
816 IRQ(17),
817};
818DEFINE_DEV(pio, 4);
819DEV_CLK(mck, pio4, pba, 14);
820
Haavard Skinnemoene82c6102008-10-23 14:42:19 +0200821static int __init system_device_init(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700822{
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200823 platform_device_register(&at32_pm0_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700824 platform_device_register(&at32_intc0_device);
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +0200825 platform_device_register(&at32ap700x_rtc0_device);
826 platform_device_register(&at32_wdt0_device);
827 platform_device_register(&at32_eic0_device);
Haavard Skinnemoenbc157b72006-09-25 23:32:16 -0700828 platform_device_register(&smc0_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700829 platform_device_register(&pdc_device);
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -0700830 platform_device_register(&dw_dmac0_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700831
David Brownelle723ff62008-02-14 11:24:02 -0800832 platform_device_register(&at32_tcb0_device);
833 platform_device_register(&at32_tcb1_device);
Hans-Christian Egtvedt77609892007-03-12 18:15:16 +0100834
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700835 platform_device_register(&pio0_device);
836 platform_device_register(&pio1_device);
837 platform_device_register(&pio2_device);
838 platform_device_register(&pio3_device);
Haavard Skinnemoen7f9f4672007-01-30 11:16:16 +0100839 platform_device_register(&pio4_device);
Haavard Skinnemoene82c6102008-10-23 14:42:19 +0200840
841 return 0;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700842}
Haavard Skinnemoene82c6102008-10-23 14:42:19 +0200843core_initcall(system_device_init);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700844
845/* --------------------------------------------------------------------
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100846 * PSIF
847 * -------------------------------------------------------------------- */
848static struct resource atmel_psif0_resource[] __initdata = {
849 {
850 .start = 0xffe03c00,
851 .end = 0xffe03cff,
852 .flags = IORESOURCE_MEM,
853 },
854 IRQ(18),
855};
856static struct clk atmel_psif0_pclk = {
857 .name = "pclk",
858 .parent = &pba_clk,
859 .mode = pba_clk_mode,
860 .get_rate = pba_clk_get_rate,
861 .index = 15,
862};
863
864static struct resource atmel_psif1_resource[] __initdata = {
865 {
866 .start = 0xffe03d00,
867 .end = 0xffe03dff,
868 .flags = IORESOURCE_MEM,
869 },
870 IRQ(18),
871};
872static struct clk atmel_psif1_pclk = {
873 .name = "pclk",
874 .parent = &pba_clk,
875 .mode = pba_clk_mode,
876 .get_rate = pba_clk_get_rate,
877 .index = 15,
878};
879
880struct platform_device *__init at32_add_device_psif(unsigned int id)
881{
882 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +0200883 u32 pin_mask;
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100884
885 if (!(id == 0 || id == 1))
886 return NULL;
887
888 pdev = platform_device_alloc("atmel_psif", id);
889 if (!pdev)
890 return NULL;
891
892 switch (id) {
893 case 0:
Julien Maycaf18f12008-09-24 10:30:47 +0200894 pin_mask = (1 << 8) | (1 << 9); /* CLOCK & DATA */
895
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100896 if (platform_device_add_resources(pdev, atmel_psif0_resource,
897 ARRAY_SIZE(atmel_psif0_resource)))
898 goto err_add_resources;
899 atmel_psif0_pclk.dev = &pdev->dev;
Julien Maycaf18f12008-09-24 10:30:47 +0200900 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100901 break;
902 case 1:
Julien Maycaf18f12008-09-24 10:30:47 +0200903 pin_mask = (1 << 11) | (1 << 12); /* CLOCK & DATA */
904
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100905 if (platform_device_add_resources(pdev, atmel_psif1_resource,
906 ARRAY_SIZE(atmel_psif1_resource)))
907 goto err_add_resources;
908 atmel_psif1_pclk.dev = &pdev->dev;
Julien Maycaf18f12008-09-24 10:30:47 +0200909 select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +0100910 break;
911 default:
912 return NULL;
913 }
914
915 platform_device_add(pdev);
916 return pdev;
917
918err_add_resources:
919 platform_device_put(pdev);
920 return NULL;
921}
922
923/* --------------------------------------------------------------------
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700924 * USART
925 * -------------------------------------------------------------------- */
926
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200927static struct atmel_uart_data atmel_usart0_data = {
928 .use_dma_tx = 1,
929 .use_dma_rx = 1,
930};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200931static struct resource atmel_usart0_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700932 PBMEM(0xffe00c00),
David Brownella3d912c82007-01-23 20:14:02 -0800933 IRQ(6),
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700934};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200935DEFINE_DEV_DATA(atmel_usart, 0);
ben.nizette@iinet.net.au80f76c52007-11-07 16:16:22 +0900936DEV_CLK(usart, atmel_usart0, pba, 3);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700937
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200938static struct atmel_uart_data atmel_usart1_data = {
939 .use_dma_tx = 1,
940 .use_dma_rx = 1,
941};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200942static struct resource atmel_usart1_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700943 PBMEM(0xffe01000),
944 IRQ(7),
945};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200946DEFINE_DEV_DATA(atmel_usart, 1);
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200947DEV_CLK(usart, atmel_usart1, pba, 4);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700948
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200949static struct atmel_uart_data atmel_usart2_data = {
950 .use_dma_tx = 1,
951 .use_dma_rx = 1,
952};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200953static struct resource atmel_usart2_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700954 PBMEM(0xffe01400),
955 IRQ(8),
956};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200957DEFINE_DEV_DATA(atmel_usart, 2);
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200958DEV_CLK(usart, atmel_usart2, pba, 5);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700959
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200960static struct atmel_uart_data atmel_usart3_data = {
961 .use_dma_tx = 1,
962 .use_dma_rx = 1,
963};
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200964static struct resource atmel_usart3_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700965 PBMEM(0xffe01800),
966 IRQ(9),
967};
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200968DEFINE_DEV_DATA(atmel_usart, 3);
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200969DEV_CLK(usart, atmel_usart3, pba, 6);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700970
Peter Mabf4861c2009-03-31 10:31:02 -0700971static inline void configure_usart0_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700972{
Julien Maycaf18f12008-09-24 10:30:47 +0200973 u32 pin_mask = (1 << 8) | (1 << 9); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -0700974 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 6);
975 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 7);
976 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 10);
Julien Maycaf18f12008-09-24 10:30:47 +0200977
Anders Blomdell10546262008-10-24 14:54:08 +0200978 select_peripheral(PIOA, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700979}
980
Peter Mabf4861c2009-03-31 10:31:02 -0700981static inline void configure_usart1_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700982{
Julien Maycaf18f12008-09-24 10:30:47 +0200983 u32 pin_mask = (1 << 17) | (1 << 18); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -0700984 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 19);
985 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 20);
986 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 16);
Julien Maycaf18f12008-09-24 10:30:47 +0200987
Anders Blomdell10546262008-10-24 14:54:08 +0200988 select_peripheral(PIOA, pin_mask, PERIPH_A, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700989}
990
Peter Mabf4861c2009-03-31 10:31:02 -0700991static inline void configure_usart2_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700992{
Julien Maycaf18f12008-09-24 10:30:47 +0200993 u32 pin_mask = (1 << 26) | (1 << 27); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -0700994 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 30);
995 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 29);
996 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 28);
Julien Maycaf18f12008-09-24 10:30:47 +0200997
Anders Blomdell10546262008-10-24 14:54:08 +0200998 select_peripheral(PIOB, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700999}
1000
Peter Mabf4861c2009-03-31 10:31:02 -07001001static inline void configure_usart3_pins(int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001002{
Julien Maycaf18f12008-09-24 10:30:47 +02001003 u32 pin_mask = (1 << 18) | (1 << 17); /* RXD & TXD */
Peter Mabf4861c2009-03-31 10:31:02 -07001004 if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 16);
1005 if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 15);
1006 if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 19);
Julien Maycaf18f12008-09-24 10:30:47 +02001007
Anders Blomdell10546262008-10-24 14:54:08 +02001008 select_peripheral(PIOB, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001009}
1010
David Brownella3d912c82007-01-23 20:14:02 -08001011static struct platform_device *__initdata at32_usarts[4];
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001012
Peter Mabf4861c2009-03-31 10:31:02 -07001013void __init at32_map_usart(unsigned int hw_id, unsigned int line, int flags)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001014{
1015 struct platform_device *pdev;
1016
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001017 switch (hw_id) {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001018 case 0:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001019 pdev = &atmel_usart0_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001020 configure_usart0_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001021 break;
1022 case 1:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001023 pdev = &atmel_usart1_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001024 configure_usart1_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001025 break;
1026 case 2:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001027 pdev = &atmel_usart2_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001028 configure_usart2_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001029 break;
1030 case 3:
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001031 pdev = &atmel_usart3_device;
Peter Mabf4861c2009-03-31 10:31:02 -07001032 configure_usart3_pins(flags);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001033 break;
1034 default:
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001035 return;
Haavard Skinnemoen75d35212006-10-04 16:02:08 +02001036 }
1037
1038 if (PXSEG(pdev->resource[0].start) == P4SEG) {
1039 /* Addresses in the P4 segment are permanently mapped 1:1 */
1040 struct atmel_uart_data *data = pdev->dev.platform_data;
1041 data->regs = (void __iomem *)pdev->resource[0].start;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001042 }
1043
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001044 pdev->id = line;
1045 at32_usarts[line] = pdev;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001046}
1047
1048struct platform_device *__init at32_add_device_usart(unsigned int id)
1049{
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001050 platform_device_register(at32_usarts[id]);
1051 return at32_usarts[id];
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001052}
1053
Haavard Skinnemoen73e27982006-10-04 16:02:04 +02001054struct platform_device *atmel_default_console_device;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001055
1056void __init at32_setup_serial_console(unsigned int usart_id)
1057{
Haavard Skinnemoenc1945882006-10-04 16:02:10 +02001058 atmel_default_console_device = at32_usarts[usart_id];
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001059}
1060
1061/* --------------------------------------------------------------------
1062 * Ethernet
1063 * -------------------------------------------------------------------- */
1064
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001065#ifdef CONFIG_CPU_AT32AP7000
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001066static struct eth_platform_data macb0_data;
1067static struct resource macb0_resource[] = {
1068 PBMEM(0xfff01800),
1069 IRQ(25),
1070};
1071DEFINE_DEV_DATA(macb, 0);
1072DEV_CLK(hclk, macb0, hsb, 8);
1073DEV_CLK(pclk, macb0, pbb, 6);
1074
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001075static struct eth_platform_data macb1_data;
1076static struct resource macb1_resource[] = {
1077 PBMEM(0xfff01c00),
1078 IRQ(26),
1079};
1080DEFINE_DEV_DATA(macb, 1);
1081DEV_CLK(hclk, macb1, hsb, 9);
1082DEV_CLK(pclk, macb1, pbb, 7);
1083
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001084struct platform_device *__init
1085at32_add_device_eth(unsigned int id, struct eth_platform_data *data)
1086{
1087 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001088 u32 pin_mask;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001089
1090 switch (id) {
1091 case 0:
1092 pdev = &macb0_device;
1093
Julien Maycaf18f12008-09-24 10:30:47 +02001094 pin_mask = (1 << 3); /* TXD0 */
1095 pin_mask |= (1 << 4); /* TXD1 */
1096 pin_mask |= (1 << 7); /* TXEN */
1097 pin_mask |= (1 << 8); /* TXCK */
1098 pin_mask |= (1 << 9); /* RXD0 */
1099 pin_mask |= (1 << 10); /* RXD1 */
1100 pin_mask |= (1 << 13); /* RXER */
1101 pin_mask |= (1 << 15); /* RXDV */
1102 pin_mask |= (1 << 16); /* MDC */
1103 pin_mask |= (1 << 17); /* MDIO */
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001104
1105 if (!data->is_rmii) {
Julien Maycaf18f12008-09-24 10:30:47 +02001106 pin_mask |= (1 << 0); /* COL */
1107 pin_mask |= (1 << 1); /* CRS */
1108 pin_mask |= (1 << 2); /* TXER */
1109 pin_mask |= (1 << 5); /* TXD2 */
1110 pin_mask |= (1 << 6); /* TXD3 */
1111 pin_mask |= (1 << 11); /* RXD2 */
1112 pin_mask |= (1 << 12); /* RXD3 */
1113 pin_mask |= (1 << 14); /* RXCK */
Mark Jackson198f2932008-10-13 10:46:27 +00001114#ifndef CONFIG_BOARD_MIMC200
Julien Maycaf18f12008-09-24 10:30:47 +02001115 pin_mask |= (1 << 18); /* SPD */
Mark Jackson198f2932008-10-13 10:46:27 +00001116#endif
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001117 }
Julien Maycaf18f12008-09-24 10:30:47 +02001118
1119 select_peripheral(PIOC, pin_mask, PERIPH_A, 0);
1120
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001121 break;
1122
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001123 case 1:
1124 pdev = &macb1_device;
1125
Julien Maycaf18f12008-09-24 10:30:47 +02001126 pin_mask = (1 << 13); /* TXD0 */
1127 pin_mask |= (1 << 14); /* TXD1 */
1128 pin_mask |= (1 << 11); /* TXEN */
1129 pin_mask |= (1 << 12); /* TXCK */
1130 pin_mask |= (1 << 10); /* RXD0 */
1131 pin_mask |= (1 << 6); /* RXD1 */
1132 pin_mask |= (1 << 5); /* RXER */
1133 pin_mask |= (1 << 4); /* RXDV */
1134 pin_mask |= (1 << 3); /* MDC */
1135 pin_mask |= (1 << 2); /* MDIO */
1136
Mark Jackson198f2932008-10-13 10:46:27 +00001137#ifndef CONFIG_BOARD_MIMC200
Julien Maycaf18f12008-09-24 10:30:47 +02001138 if (!data->is_rmii)
1139 pin_mask |= (1 << 15); /* SPD */
Mark Jackson198f2932008-10-13 10:46:27 +00001140#endif
Julien Maycaf18f12008-09-24 10:30:47 +02001141
1142 select_peripheral(PIOD, pin_mask, PERIPH_B, 0);
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001143
1144 if (!data->is_rmii) {
Julien Maycaf18f12008-09-24 10:30:47 +02001145 pin_mask = (1 << 19); /* COL */
1146 pin_mask |= (1 << 23); /* CRS */
1147 pin_mask |= (1 << 26); /* TXER */
1148 pin_mask |= (1 << 27); /* TXD2 */
1149 pin_mask |= (1 << 28); /* TXD3 */
1150 pin_mask |= (1 << 29); /* RXD2 */
1151 pin_mask |= (1 << 30); /* RXD3 */
1152 pin_mask |= (1 << 24); /* RXCK */
1153
1154 select_peripheral(PIOC, pin_mask, PERIPH_B, 0);
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01001155 }
1156 break;
1157
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001158 default:
1159 return NULL;
1160 }
1161
1162 memcpy(pdev->dev.platform_data, data, sizeof(struct eth_platform_data));
1163 platform_device_register(pdev);
1164
1165 return pdev;
1166}
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001167#endif
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001168
1169/* --------------------------------------------------------------------
1170 * SPI
1171 * -------------------------------------------------------------------- */
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001172static struct resource atmel_spi0_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001173 PBMEM(0xffe00000),
1174 IRQ(3),
1175};
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001176DEFINE_DEV(atmel_spi, 0);
1177DEV_CLK(spi_clk, atmel_spi0, pba, 0);
1178
1179static struct resource atmel_spi1_resource[] = {
1180 PBMEM(0xffe00400),
1181 IRQ(4),
1182};
1183DEFINE_DEV(atmel_spi, 1);
1184DEV_CLK(spi_clk, atmel_spi1, pba, 1);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001185
Peter Ma07084202009-08-27 00:31:47 -07001186void __init
1187at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001188{
Peter Ma07084202009-08-27 00:31:47 -07001189 /*
1190 * Manage the chipselects as GPIOs, normally using the same pins
1191 * the SPI controller expects; but boards can use other pins.
1192 */
1193 static u8 __initdata spi_pins[][4] = {
1194 { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
1195 GPIO_PIN_PA(5), GPIO_PIN_PA(20) },
1196 { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
1197 GPIO_PIN_PB(4), GPIO_PIN_PA(27) },
1198 };
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001199 unsigned int pin, mode;
1200
Peter Ma07084202009-08-27 00:31:47 -07001201 /* There are only 2 SPI controllers */
1202 if (bus_num > 1)
1203 return;
1204
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001205 for (; n; n--, b++) {
1206 b->bus_num = bus_num;
1207 if (b->chip_select >= 4)
1208 continue;
1209 pin = (unsigned)b->controller_data;
1210 if (!pin) {
Peter Ma07084202009-08-27 00:31:47 -07001211 pin = spi_pins[bus_num][b->chip_select];
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001212 b->controller_data = (void *)pin;
1213 }
1214 mode = AT32_GPIOF_OUTPUT;
1215 if (!(b->mode & SPI_CS_HIGH))
1216 mode |= AT32_GPIOF_HIGH;
1217 at32_select_gpio(pin, mode);
1218 }
1219}
1220
1221struct platform_device *__init
1222at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
1223{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001224 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001225 u32 pin_mask;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001226
1227 switch (id) {
1228 case 0:
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001229 pdev = &atmel_spi0_device;
Julien Maycaf18f12008-09-24 10:30:47 +02001230 pin_mask = (1 << 1) | (1 << 2); /* MOSI & SCK */
1231
David Brownell9c2baf72008-06-18 02:31:43 -07001232 /* pullup MISO so a level is always defined */
Julien Maycaf18f12008-09-24 10:30:47 +02001233 select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP);
1234 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
1235
Peter Ma07084202009-08-27 00:31:47 -07001236 at32_spi_setup_slaves(0, b, n);
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01001237 break;
1238
1239 case 1:
1240 pdev = &atmel_spi1_device;
Julien Maycaf18f12008-09-24 10:30:47 +02001241 pin_mask = (1 << 1) | (1 << 5); /* MOSI */
1242
David Brownell9c2baf72008-06-18 02:31:43 -07001243 /* pullup MISO so a level is always defined */
Julien Maycaf18f12008-09-24 10:30:47 +02001244 select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP);
1245 select_peripheral(PIOB, pin_mask, PERIPH_B, 0);
1246
Peter Ma07084202009-08-27 00:31:47 -07001247 at32_spi_setup_slaves(1, b, n);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001248 break;
1249
1250 default:
1251 return NULL;
1252 }
1253
Haavard Skinnemoen41d8ca42007-02-16 13:56:11 +01001254 spi_register_board_info(b, n);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001255 platform_device_register(pdev);
1256 return pdev;
1257}
1258
1259/* --------------------------------------------------------------------
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001260 * TWI
1261 * -------------------------------------------------------------------- */
1262static struct resource atmel_twi0_resource[] __initdata = {
1263 PBMEM(0xffe00800),
1264 IRQ(5),
1265};
1266static struct clk atmel_twi0_pclk = {
1267 .name = "twi_pclk",
1268 .parent = &pba_clk,
1269 .mode = pba_clk_mode,
1270 .get_rate = pba_clk_get_rate,
1271 .index = 2,
1272};
1273
Ben Nizette040b28f2008-02-07 15:28:57 +11001274struct platform_device *__init at32_add_device_twi(unsigned int id,
1275 struct i2c_board_info *b,
1276 unsigned int n)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001277{
1278 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001279 u32 pin_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001280
1281 if (id != 0)
1282 return NULL;
1283
1284 pdev = platform_device_alloc("atmel_twi", id);
1285 if (!pdev)
1286 return NULL;
1287
1288 if (platform_device_add_resources(pdev, atmel_twi0_resource,
1289 ARRAY_SIZE(atmel_twi0_resource)))
1290 goto err_add_resources;
1291
Julien Maycaf18f12008-09-24 10:30:47 +02001292 pin_mask = (1 << 6) | (1 << 7); /* SDA & SDL */
1293
1294 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001295
1296 atmel_twi0_pclk.dev = &pdev->dev;
1297
Ben Nizette040b28f2008-02-07 15:28:57 +11001298 if (b)
1299 i2c_register_board_info(id, b, n);
1300
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001301 platform_device_add(pdev);
1302 return pdev;
1303
1304err_add_resources:
1305 platform_device_put(pdev);
1306 return NULL;
1307}
1308
1309/* --------------------------------------------------------------------
1310 * MMC
1311 * -------------------------------------------------------------------- */
1312static struct resource atmel_mci0_resource[] __initdata = {
1313 PBMEM(0xfff02400),
1314 IRQ(28),
1315};
1316static struct clk atmel_mci0_pclk = {
1317 .name = "mci_clk",
1318 .parent = &pbb_clk,
1319 .mode = pbb_clk_mode,
1320 .get_rate = pbb_clk_get_rate,
1321 .index = 9,
1322};
1323
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001324struct platform_device *__init
1325at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001326{
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001327 struct platform_device *pdev;
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001328 struct mci_dma_slave *slave;
Julien Maycaf18f12008-09-24 10:30:47 +02001329 u32 pioa_mask;
1330 u32 piob_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001331
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001332 if (id != 0 || !data)
1333 return NULL;
1334
1335 /* Must have at least one usable slot */
1336 if (!data->slot[0].bus_width && !data->slot[1].bus_width)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001337 return NULL;
1338
1339 pdev = platform_device_alloc("atmel_mci", id);
1340 if (!pdev)
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001341 goto fail;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001342
1343 if (platform_device_add_resources(pdev, atmel_mci0_resource,
1344 ARRAY_SIZE(atmel_mci0_resource)))
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001345 goto fail;
1346
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001347 slave = kzalloc(sizeof(struct mci_dma_slave), GFP_KERNEL);
1348
1349 slave->sdata.dma_dev = &dw_dmac0_device.dev;
1350 slave->sdata.reg_width = DW_DMA_SLAVE_WIDTH_32BIT;
1351 slave->sdata.cfg_hi = (DWC_CFGH_SRC_PER(0)
Haavard Skinnemoen65e8b082008-07-30 20:29:03 +02001352 | DWC_CFGH_DST_PER(1));
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001353 slave->sdata.cfg_lo &= ~(DWC_CFGL_HS_DST_POL
Haavard Skinnemoen65e8b082008-07-30 20:29:03 +02001354 | DWC_CFGL_HS_SRC_POL);
1355
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001356 data->dma_slave = slave;
1357
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001358 if (platform_device_add_data(pdev, data,
1359 sizeof(struct mci_platform_data)))
1360 goto fail;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001361
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001362 /* CLK line is common to both slots */
Julien Maycaf18f12008-09-24 10:30:47 +02001363 pioa_mask = 1 << 10;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001364
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001365 switch (data->slot[0].bus_width) {
1366 case 4:
Julien Maycaf18f12008-09-24 10:30:47 +02001367 pioa_mask |= 1 << 13; /* DATA1 */
1368 pioa_mask |= 1 << 14; /* DATA2 */
1369 pioa_mask |= 1 << 15; /* DATA3 */
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001370 /* fall through */
1371 case 1:
Julien Maycaf18f12008-09-24 10:30:47 +02001372 pioa_mask |= 1 << 11; /* CMD */
1373 pioa_mask |= 1 << 12; /* DATA0 */
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001374
1375 if (gpio_is_valid(data->slot[0].detect_pin))
1376 at32_select_gpio(data->slot[0].detect_pin, 0);
1377 if (gpio_is_valid(data->slot[0].wp_pin))
1378 at32_select_gpio(data->slot[0].wp_pin, 0);
1379 break;
1380 case 0:
1381 /* Slot is unused */
1382 break;
1383 default:
1384 goto fail;
1385 }
1386
Julien Maycaf18f12008-09-24 10:30:47 +02001387 select_peripheral(PIOA, pioa_mask, PERIPH_A, 0);
1388 piob_mask = 0;
1389
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001390 switch (data->slot[1].bus_width) {
1391 case 4:
Julien Maycaf18f12008-09-24 10:30:47 +02001392 piob_mask |= 1 << 8; /* DATA1 */
1393 piob_mask |= 1 << 9; /* DATA2 */
1394 piob_mask |= 1 << 10; /* DATA3 */
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001395 /* fall through */
1396 case 1:
Julien Maycaf18f12008-09-24 10:30:47 +02001397 piob_mask |= 1 << 6; /* CMD */
1398 piob_mask |= 1 << 7; /* DATA0 */
1399 select_peripheral(PIOB, piob_mask, PERIPH_B, 0);
Haavard Skinnemoen6b918652008-08-07 14:08:49 +02001400
1401 if (gpio_is_valid(data->slot[1].detect_pin))
1402 at32_select_gpio(data->slot[1].detect_pin, 0);
1403 if (gpio_is_valid(data->slot[1].wp_pin))
1404 at32_select_gpio(data->slot[1].wp_pin, 0);
1405 break;
1406 case 0:
1407 /* Slot is unused */
1408 break;
1409 default:
1410 if (!data->slot[0].bus_width)
1411 goto fail;
1412
1413 data->slot[1].bus_width = 0;
1414 break;
1415 }
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001416
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001417 atmel_mci0_pclk.dev = &pdev->dev;
1418
1419 platform_device_add(pdev);
1420 return pdev;
1421
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001422fail:
Nicolas Ferre2635d1b2009-12-14 18:01:30 -08001423 data->dma_slave = NULL;
1424 kfree(slave);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001425 platform_device_put(pdev);
1426 return NULL;
1427}
1428
1429/* --------------------------------------------------------------------
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001430 * LCDC
1431 * -------------------------------------------------------------------- */
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001432#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001433static struct atmel_lcdfb_info atmel_lcdfb0_data;
1434static struct resource atmel_lcdfb0_resource[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001435 {
1436 .start = 0xff000000,
1437 .end = 0xff000fff,
1438 .flags = IORESOURCE_MEM,
1439 },
1440 IRQ(1),
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001441 {
1442 /* Placeholder for pre-allocated fb memory */
1443 .start = 0x00000000,
1444 .end = 0x00000000,
1445 .flags = 0,
1446 },
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001447};
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001448DEFINE_DEV_DATA(atmel_lcdfb, 0);
1449DEV_CLK(hck1, atmel_lcdfb0, hsb, 7);
1450static struct clk atmel_lcdfb0_pixclk = {
1451 .name = "lcdc_clk",
1452 .dev = &atmel_lcdfb0_device.dev,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001453 .mode = genclk_mode,
1454 .get_rate = genclk_get_rate,
1455 .set_rate = genclk_set_rate,
1456 .set_parent = genclk_set_parent,
1457 .index = 7,
1458};
1459
1460struct platform_device *__init
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001461at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
Hans-Christian Egtvedt47882cf2008-02-05 15:27:16 +01001462 unsigned long fbmem_start, unsigned long fbmem_len,
Julien May70664122008-08-04 14:27:38 +02001463 u64 pin_mask)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001464{
1465 struct platform_device *pdev;
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001466 struct atmel_lcdfb_info *info;
1467 struct fb_monspecs *monspecs;
1468 struct fb_videomode *modedb;
1469 unsigned int modedb_size;
Julien Maycaf18f12008-09-24 10:30:47 +02001470 u32 portc_mask, portd_mask, porte_mask;
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001471
1472 /*
1473 * Do a deep copy of the fb data, monspecs and modedb. Make
1474 * sure all allocations are done before setting up the
1475 * portmux.
1476 */
1477 monspecs = kmemdup(data->default_monspecs,
1478 sizeof(struct fb_monspecs), GFP_KERNEL);
1479 if (!monspecs)
1480 return NULL;
1481
1482 modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len;
1483 modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL);
1484 if (!modedb)
1485 goto err_dup_modedb;
1486 monspecs->modedb = modedb;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001487
1488 switch (id) {
1489 case 0:
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001490 pdev = &atmel_lcdfb0_device;
Hans-Christian Egtvedt47882cf2008-02-05 15:27:16 +01001491
Julien May70664122008-08-04 14:27:38 +02001492 if (pin_mask == 0ULL)
1493 /* Default to "full" lcdc control signals and 24bit */
1494 pin_mask = ATMEL_LCDC_PRI_24BIT | ATMEL_LCDC_PRI_CONTROL;
1495
1496 /* LCDC on port C */
Alex Raimondi60900652008-10-13 16:03:45 +02001497 portc_mask = pin_mask & 0xfff80000;
Julien Maycaf18f12008-09-24 10:30:47 +02001498 select_peripheral(PIOC, portc_mask, PERIPH_A, 0);
Julien May70664122008-08-04 14:27:38 +02001499
1500 /* LCDC on port D */
Julien Maycaf18f12008-09-24 10:30:47 +02001501 portd_mask = pin_mask & 0x0003ffff;
1502 select_peripheral(PIOD, portd_mask, PERIPH_A, 0);
Julien May70664122008-08-04 14:27:38 +02001503
1504 /* LCDC on port E */
Julien Maycaf18f12008-09-24 10:30:47 +02001505 porte_mask = (pin_mask >> 32) & 0x0007ffff;
1506 select_peripheral(PIOE, porte_mask, PERIPH_B, 0);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001507
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001508 clk_set_parent(&atmel_lcdfb0_pixclk, &pll0);
1509 clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001510 break;
1511
1512 default:
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001513 goto err_invalid_id;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001514 }
1515
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001516 if (fbmem_len) {
1517 pdev->resource[2].start = fbmem_start;
1518 pdev->resource[2].end = fbmem_start + fbmem_len - 1;
1519 pdev->resource[2].flags = IORESOURCE_MEM;
1520 }
1521
1522 info = pdev->dev.platform_data;
1523 memcpy(info, data, sizeof(struct atmel_lcdfb_info));
1524 info->default_monspecs = monspecs;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001525
1526 platform_device_register(pdev);
1527 return pdev;
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01001528
1529err_invalid_id:
1530 kfree(modedb);
1531err_dup_modedb:
1532 kfree(monspecs);
1533 return NULL;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001534}
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001535#endif
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001536
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01001537/* --------------------------------------------------------------------
David Brownell9a1e8eb2008-02-08 04:21:21 -08001538 * PWM
1539 * -------------------------------------------------------------------- */
1540static struct resource atmel_pwm0_resource[] __initdata = {
1541 PBMEM(0xfff01400),
1542 IRQ(24),
1543};
1544static struct clk atmel_pwm0_mck = {
Sedji Gaouaou84059962008-06-25 10:32:50 +02001545 .name = "pwm_clk",
David Brownell9a1e8eb2008-02-08 04:21:21 -08001546 .parent = &pbb_clk,
1547 .mode = pbb_clk_mode,
1548 .get_rate = pbb_clk_get_rate,
1549 .index = 5,
1550};
1551
1552struct platform_device *__init at32_add_device_pwm(u32 mask)
1553{
1554 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001555 u32 pin_mask;
David Brownell9a1e8eb2008-02-08 04:21:21 -08001556
1557 if (!mask)
1558 return NULL;
1559
1560 pdev = platform_device_alloc("atmel_pwm", 0);
1561 if (!pdev)
1562 return NULL;
1563
1564 if (platform_device_add_resources(pdev, atmel_pwm0_resource,
1565 ARRAY_SIZE(atmel_pwm0_resource)))
1566 goto out_free_pdev;
1567
1568 if (platform_device_add_data(pdev, &mask, sizeof(mask)))
1569 goto out_free_pdev;
1570
Julien Maycaf18f12008-09-24 10:30:47 +02001571 pin_mask = 0;
David Brownell9a1e8eb2008-02-08 04:21:21 -08001572 if (mask & (1 << 0))
Julien Maycaf18f12008-09-24 10:30:47 +02001573 pin_mask |= (1 << 28);
David Brownell9a1e8eb2008-02-08 04:21:21 -08001574 if (mask & (1 << 1))
Julien Maycaf18f12008-09-24 10:30:47 +02001575 pin_mask |= (1 << 29);
1576 if (pin_mask > 0)
1577 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
1578
1579 pin_mask = 0;
David Brownell9a1e8eb2008-02-08 04:21:21 -08001580 if (mask & (1 << 2))
Julien Maycaf18f12008-09-24 10:30:47 +02001581 pin_mask |= (1 << 21);
David Brownell9a1e8eb2008-02-08 04:21:21 -08001582 if (mask & (1 << 3))
Julien Maycaf18f12008-09-24 10:30:47 +02001583 pin_mask |= (1 << 22);
1584 if (pin_mask > 0)
1585 select_peripheral(PIOA, pin_mask, PERIPH_B, 0);
David Brownell9a1e8eb2008-02-08 04:21:21 -08001586
1587 atmel_pwm0_mck.dev = &pdev->dev;
1588
1589 platform_device_add(pdev);
1590
1591 return pdev;
1592
1593out_free_pdev:
1594 platform_device_put(pdev);
1595 return NULL;
1596}
1597
1598/* --------------------------------------------------------------------
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001599 * SSC
1600 * -------------------------------------------------------------------- */
1601static struct resource ssc0_resource[] = {
1602 PBMEM(0xffe01c00),
1603 IRQ(10),
1604};
1605DEFINE_DEV(ssc, 0);
1606DEV_CLK(pclk, ssc0, pba, 7);
1607
1608static struct resource ssc1_resource[] = {
1609 PBMEM(0xffe02000),
1610 IRQ(11),
1611};
1612DEFINE_DEV(ssc, 1);
1613DEV_CLK(pclk, ssc1, pba, 8);
1614
1615static struct resource ssc2_resource[] = {
1616 PBMEM(0xffe02400),
1617 IRQ(12),
1618};
1619DEFINE_DEV(ssc, 2);
1620DEV_CLK(pclk, ssc2, pba, 9);
1621
1622struct platform_device *__init
1623at32_add_device_ssc(unsigned int id, unsigned int flags)
1624{
1625 struct platform_device *pdev;
Julien Maycaf18f12008-09-24 10:30:47 +02001626 u32 pin_mask = 0;
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001627
1628 switch (id) {
1629 case 0:
1630 pdev = &ssc0_device;
1631 if (flags & ATMEL_SSC_RF)
Julien Maycaf18f12008-09-24 10:30:47 +02001632 pin_mask |= (1 << 21); /* RF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001633 if (flags & ATMEL_SSC_RK)
Julien Maycaf18f12008-09-24 10:30:47 +02001634 pin_mask |= (1 << 22); /* RK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001635 if (flags & ATMEL_SSC_TK)
Julien Maycaf18f12008-09-24 10:30:47 +02001636 pin_mask |= (1 << 23); /* TK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001637 if (flags & ATMEL_SSC_TF)
Julien Maycaf18f12008-09-24 10:30:47 +02001638 pin_mask |= (1 << 24); /* TF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001639 if (flags & ATMEL_SSC_TD)
Julien Maycaf18f12008-09-24 10:30:47 +02001640 pin_mask |= (1 << 25); /* TD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001641 if (flags & ATMEL_SSC_RD)
Julien Maycaf18f12008-09-24 10:30:47 +02001642 pin_mask |= (1 << 26); /* RD */
1643
1644 if (pin_mask > 0)
1645 select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
1646
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001647 break;
1648 case 1:
1649 pdev = &ssc1_device;
1650 if (flags & ATMEL_SSC_RF)
Julien Maycaf18f12008-09-24 10:30:47 +02001651 pin_mask |= (1 << 0); /* RF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001652 if (flags & ATMEL_SSC_RK)
Julien Maycaf18f12008-09-24 10:30:47 +02001653 pin_mask |= (1 << 1); /* RK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001654 if (flags & ATMEL_SSC_TK)
Julien Maycaf18f12008-09-24 10:30:47 +02001655 pin_mask |= (1 << 2); /* TK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001656 if (flags & ATMEL_SSC_TF)
Julien Maycaf18f12008-09-24 10:30:47 +02001657 pin_mask |= (1 << 3); /* TF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001658 if (flags & ATMEL_SSC_TD)
Julien Maycaf18f12008-09-24 10:30:47 +02001659 pin_mask |= (1 << 4); /* TD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001660 if (flags & ATMEL_SSC_RD)
Julien Maycaf18f12008-09-24 10:30:47 +02001661 pin_mask |= (1 << 5); /* RD */
1662
1663 if (pin_mask > 0)
1664 select_peripheral(PIOA, pin_mask, PERIPH_B, 0);
1665
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001666 break;
1667 case 2:
1668 pdev = &ssc2_device;
1669 if (flags & ATMEL_SSC_TD)
Julien Maycaf18f12008-09-24 10:30:47 +02001670 pin_mask |= (1 << 13); /* TD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001671 if (flags & ATMEL_SSC_RD)
Julien Maycaf18f12008-09-24 10:30:47 +02001672 pin_mask |= (1 << 14); /* RD */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001673 if (flags & ATMEL_SSC_TK)
Julien Maycaf18f12008-09-24 10:30:47 +02001674 pin_mask |= (1 << 15); /* TK */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001675 if (flags & ATMEL_SSC_TF)
Julien Maycaf18f12008-09-24 10:30:47 +02001676 pin_mask |= (1 << 16); /* TF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001677 if (flags & ATMEL_SSC_RF)
Julien Maycaf18f12008-09-24 10:30:47 +02001678 pin_mask |= (1 << 17); /* RF */
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001679 if (flags & ATMEL_SSC_RK)
Julien Maycaf18f12008-09-24 10:30:47 +02001680 pin_mask |= (1 << 18); /* RK */
1681
1682 if (pin_mask > 0)
1683 select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
1684
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02001685 break;
1686 default:
1687 return NULL;
1688 }
1689
1690 platform_device_register(pdev);
1691 return pdev;
1692}
1693
1694/* --------------------------------------------------------------------
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001695 * USB Device Controller
1696 * -------------------------------------------------------------------- */
1697static struct resource usba0_resource[] __initdata = {
1698 {
1699 .start = 0xff300000,
1700 .end = 0xff3fffff,
1701 .flags = IORESOURCE_MEM,
1702 }, {
1703 .start = 0xfff03000,
1704 .end = 0xfff033ff,
1705 .flags = IORESOURCE_MEM,
1706 },
1707 IRQ(31),
1708};
1709static struct clk usba0_pclk = {
1710 .name = "pclk",
1711 .parent = &pbb_clk,
1712 .mode = pbb_clk_mode,
1713 .get_rate = pbb_clk_get_rate,
1714 .index = 12,
1715};
1716static struct clk usba0_hclk = {
1717 .name = "hclk",
1718 .parent = &hsb_clk,
1719 .mode = hsb_clk_mode,
1720 .get_rate = hsb_clk_get_rate,
1721 .index = 6,
1722};
1723
Stelian Pop8d855312008-03-05 00:00:00 +01001724#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
1725 [idx] = { \
1726 .name = nam, \
1727 .index = idx, \
1728 .fifo_size = maxpkt, \
1729 .nr_banks = maxbk, \
1730 .can_dma = dma, \
1731 .can_isoc = isoc, \
1732 }
1733
1734static struct usba_ep_data at32_usba_ep[] __initdata = {
1735 EP("ep0", 0, 64, 1, 0, 0),
1736 EP("ep1", 1, 512, 2, 1, 1),
1737 EP("ep2", 2, 512, 2, 1, 1),
1738 EP("ep3-int", 3, 64, 3, 1, 0),
1739 EP("ep4-int", 4, 64, 3, 1, 0),
1740 EP("ep5", 5, 1024, 3, 1, 1),
1741 EP("ep6", 6, 1024, 3, 1, 1),
1742};
1743
1744#undef EP
1745
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001746struct platform_device *__init
1747at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
1748{
Stelian Pop8d855312008-03-05 00:00:00 +01001749 /*
1750 * pdata doesn't have room for any endpoints, so we need to
1751 * append room for the ones we need right after it.
1752 */
1753 struct {
1754 struct usba_platform_data pdata;
1755 struct usba_ep_data ep[7];
1756 } usba_data;
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001757 struct platform_device *pdev;
1758
1759 if (id != 0)
1760 return NULL;
1761
1762 pdev = platform_device_alloc("atmel_usba_udc", 0);
1763 if (!pdev)
1764 return NULL;
1765
1766 if (platform_device_add_resources(pdev, usba0_resource,
1767 ARRAY_SIZE(usba0_resource)))
1768 goto out_free_pdev;
1769
Stelian Pop8d855312008-03-05 00:00:00 +01001770 if (data)
1771 usba_data.pdata.vbus_pin = data->vbus_pin;
1772 else
1773 usba_data.pdata.vbus_pin = -EINVAL;
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001774
Stelian Pop8d855312008-03-05 00:00:00 +01001775 data = &usba_data.pdata;
1776 data->num_ep = ARRAY_SIZE(at32_usba_ep);
1777 memcpy(data->ep, at32_usba_ep, sizeof(at32_usba_ep));
1778
1779 if (platform_device_add_data(pdev, data, sizeof(usba_data)))
1780 goto out_free_pdev;
1781
Hans-Christian Egtvedt9477ab22009-03-24 15:45:21 +01001782 if (gpio_is_valid(data->vbus_pin))
Stelian Pop8d855312008-03-05 00:00:00 +01001783 at32_select_gpio(data->vbus_pin, 0);
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02001784
1785 usba0_pclk.dev = &pdev->dev;
1786 usba0_hclk.dev = &pdev->dev;
1787
1788 platform_device_add(pdev);
1789
1790 return pdev;
1791
1792out_free_pdev:
1793 platform_device_put(pdev);
1794 return NULL;
1795}
1796
1797/* --------------------------------------------------------------------
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001798 * IDE / CompactFlash
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001799 * -------------------------------------------------------------------- */
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001800#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7001)
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001801static struct resource at32_smc_cs4_resource[] __initdata = {
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001802 {
1803 .start = 0x04000000,
1804 .end = 0x07ffffff,
1805 .flags = IORESOURCE_MEM,
1806 },
1807 IRQ(~0UL), /* Magic IRQ will be overridden */
1808};
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001809static struct resource at32_smc_cs5_resource[] __initdata = {
1810 {
1811 .start = 0x20000000,
1812 .end = 0x23ffffff,
1813 .flags = IORESOURCE_MEM,
1814 },
1815 IRQ(~0UL), /* Magic IRQ will be overridden */
1816};
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001817
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001818static int __init at32_init_ide_or_cf(struct platform_device *pdev,
1819 unsigned int cs, unsigned int extint)
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001820{
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001821 static unsigned int extint_pin_map[4] __initdata = {
Julien Maycaf18f12008-09-24 10:30:47 +02001822 (1 << 25),
1823 (1 << 26),
1824 (1 << 27),
1825 (1 << 28),
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001826 };
1827 static bool common_pins_initialized __initdata = false;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001828 unsigned int extint_pin;
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001829 int ret;
Julien Maycaf18f12008-09-24 10:30:47 +02001830 u32 pin_mask;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001831
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001832 if (extint >= ARRAY_SIZE(extint_pin_map))
1833 return -EINVAL;
1834 extint_pin = extint_pin_map[extint];
1835
1836 switch (cs) {
1837 case 4:
1838 ret = platform_device_add_resources(pdev,
1839 at32_smc_cs4_resource,
1840 ARRAY_SIZE(at32_smc_cs4_resource));
1841 if (ret)
1842 return ret;
1843
Julien Maycaf18f12008-09-24 10:30:47 +02001844 /* NCS4 -> OE_N */
1845 select_peripheral(PIOE, (1 << 21), PERIPH_A, 0);
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02001846 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF0_ENABLE);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001847 break;
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001848 case 5:
1849 ret = platform_device_add_resources(pdev,
1850 at32_smc_cs5_resource,
1851 ARRAY_SIZE(at32_smc_cs5_resource));
1852 if (ret)
1853 return ret;
1854
Julien Maycaf18f12008-09-24 10:30:47 +02001855 /* NCS5 -> OE_N */
1856 select_peripheral(PIOE, (1 << 22), PERIPH_A, 0);
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02001857 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF1_ENABLE);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001858 break;
1859 default:
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001860 return -EINVAL;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001861 }
1862
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001863 if (!common_pins_initialized) {
Julien Maycaf18f12008-09-24 10:30:47 +02001864 pin_mask = (1 << 19); /* CFCE1 -> CS0_N */
1865 pin_mask |= (1 << 20); /* CFCE2 -> CS1_N */
1866 pin_mask |= (1 << 23); /* CFRNW -> DIR */
1867 pin_mask |= (1 << 24); /* NWAIT <- IORDY */
1868
1869 select_peripheral(PIOE, pin_mask, PERIPH_A, 0);
1870
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001871 common_pins_initialized = true;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001872 }
1873
Julien Maycaf18f12008-09-24 10:30:47 +02001874 select_peripheral(PIOB, extint_pin, PERIPH_A, AT32_GPIOF_DEGLITCH);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001875
1876 pdev->resource[1].start = EIM_IRQ_BASE + extint;
1877 pdev->resource[1].end = pdev->resource[1].start;
1878
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001879 return 0;
1880}
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001881
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001882struct platform_device *__init
1883at32_add_device_ide(unsigned int id, unsigned int extint,
1884 struct ide_platform_data *data)
1885{
1886 struct platform_device *pdev;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001887
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001888 pdev = platform_device_alloc("at32_ide", id);
1889 if (!pdev)
1890 goto fail;
1891
1892 if (platform_device_add_data(pdev, data,
1893 sizeof(struct ide_platform_data)))
1894 goto fail;
1895
1896 if (at32_init_ide_or_cf(pdev, data->cs, extint))
1897 goto fail;
1898
1899 platform_device_add(pdev);
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001900 return pdev;
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001901
1902fail:
1903 platform_device_put(pdev);
1904 return NULL;
1905}
1906
1907struct platform_device *__init
1908at32_add_device_cf(unsigned int id, unsigned int extint,
1909 struct cf_platform_data *data)
1910{
1911 struct platform_device *pdev;
1912
1913 pdev = platform_device_alloc("at32_cf", id);
1914 if (!pdev)
1915 goto fail;
1916
1917 if (platform_device_add_data(pdev, data,
1918 sizeof(struct cf_platform_data)))
1919 goto fail;
1920
1921 if (at32_init_ide_or_cf(pdev, data->cs, extint))
1922 goto fail;
1923
David Brownell3c26e172008-07-27 02:34:45 -07001924 if (gpio_is_valid(data->detect_pin))
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001925 at32_select_gpio(data->detect_pin, AT32_GPIOF_DEGLITCH);
David Brownell3c26e172008-07-27 02:34:45 -07001926 if (gpio_is_valid(data->reset_pin))
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001927 at32_select_gpio(data->reset_pin, 0);
David Brownell3c26e172008-07-27 02:34:45 -07001928 if (gpio_is_valid(data->vcc_pin))
Haavard Skinnemoeneaf5f922007-10-22 18:32:14 +02001929 at32_select_gpio(data->vcc_pin, 0);
1930 /* READY is used as extint, so we can't select it as gpio */
1931
1932 platform_device_add(pdev);
1933 return pdev;
1934
1935fail:
1936 platform_device_put(pdev);
1937 return NULL;
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001938}
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01001939#endif
Kristoffer Nyborg Gregertsen48021bd2007-08-16 13:45:00 +02001940
1941/* --------------------------------------------------------------------
HÃ¥vard Skinnemoen62090a02008-06-06 18:04:56 +02001942 * NAND Flash / SmartMedia
1943 * -------------------------------------------------------------------- */
1944static struct resource smc_cs3_resource[] __initdata = {
1945 {
1946 .start = 0x0c000000,
1947 .end = 0x0fffffff,
1948 .flags = IORESOURCE_MEM,
1949 }, {
1950 .start = 0xfff03c00,
1951 .end = 0xfff03fff,
1952 .flags = IORESOURCE_MEM,
1953 },
1954};
1955
1956struct platform_device *__init
1957at32_add_device_nand(unsigned int id, struct atmel_nand_data *data)
1958{
1959 struct platform_device *pdev;
1960
1961 if (id != 0 || !data)
1962 return NULL;
1963
1964 pdev = platform_device_alloc("atmel_nand", id);
1965 if (!pdev)
1966 goto fail;
1967
1968 if (platform_device_add_resources(pdev, smc_cs3_resource,
1969 ARRAY_SIZE(smc_cs3_resource)))
1970 goto fail;
1971
1972 if (platform_device_add_data(pdev, data,
1973 sizeof(struct atmel_nand_data)))
1974 goto fail;
1975
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02001976 hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_NAND_ENABLE);
HÃ¥vard Skinnemoen62090a02008-06-06 18:04:56 +02001977 if (data->enable_pin)
1978 at32_select_gpio(data->enable_pin,
1979 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
1980 if (data->rdy_pin)
1981 at32_select_gpio(data->rdy_pin, 0);
1982 if (data->det_pin)
1983 at32_select_gpio(data->det_pin, 0);
1984
1985 platform_device_add(pdev);
1986 return pdev;
1987
1988fail:
1989 platform_device_put(pdev);
1990 return NULL;
1991}
1992
1993/* --------------------------------------------------------------------
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02001994 * AC97C
1995 * -------------------------------------------------------------------- */
1996static struct resource atmel_ac97c0_resource[] __initdata = {
1997 PBMEM(0xfff02800),
1998 IRQ(29),
1999};
2000static struct clk atmel_ac97c0_pclk = {
2001 .name = "pclk",
2002 .parent = &pbb_clk,
2003 .mode = pbb_clk_mode,
2004 .get_rate = pbb_clk_get_rate,
2005 .index = 10,
2006};
2007
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002008struct platform_device *__init
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002009at32_add_device_ac97c(unsigned int id, struct ac97c_platform_data *data,
2010 unsigned int flags)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002011{
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002012 struct platform_device *pdev;
2013 struct dw_dma_slave *rx_dws;
2014 struct dw_dma_slave *tx_dws;
2015 struct ac97c_platform_data _data;
2016 u32 pin_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002017
2018 if (id != 0)
2019 return NULL;
2020
2021 pdev = platform_device_alloc("atmel_ac97c", id);
2022 if (!pdev)
2023 return NULL;
2024
2025 if (platform_device_add_resources(pdev, atmel_ac97c0_resource,
2026 ARRAY_SIZE(atmel_ac97c0_resource)))
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002027 goto out_free_resources;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002028
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002029 if (!data) {
2030 data = &_data;
2031 memset(data, 0, sizeof(struct ac97c_platform_data));
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002032 data->reset_pin = -ENODEV;
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002033 }
2034
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002035 rx_dws = &data->rx_dws;
2036 tx_dws = &data->tx_dws;
2037
2038 /* Check if DMA slave interface for capture should be configured. */
2039 if (flags & AC97C_CAPTURE) {
2040 rx_dws->dma_dev = &dw_dmac0_device.dev;
2041 rx_dws->reg_width = DW_DMA_SLAVE_WIDTH_16BIT;
2042 rx_dws->cfg_hi = DWC_CFGH_SRC_PER(3);
2043 rx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
2044 }
2045
2046 /* Check if DMA slave interface for playback should be configured. */
2047 if (flags & AC97C_PLAYBACK) {
2048 tx_dws->dma_dev = &dw_dmac0_device.dev;
2049 tx_dws->reg_width = DW_DMA_SLAVE_WIDTH_16BIT;
2050 tx_dws->cfg_hi = DWC_CFGH_DST_PER(4);
2051 tx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
2052 }
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002053
2054 if (platform_device_add_data(pdev, data,
2055 sizeof(struct ac97c_platform_data)))
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002056 goto out_free_resources;
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002057
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002058 /* SDO | SYNC | SCLK | SDI */
2059 pin_mask = (1 << 20) | (1 << 21) | (1 << 22) | (1 << 23);
Julien Maycaf18f12008-09-24 10:30:47 +02002060
2061 select_peripheral(PIOB, pin_mask, PERIPH_B, 0);
Hans-Christian Egtvedt218df4a2008-07-01 14:26:45 +02002062
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002063 if (gpio_is_valid(data->reset_pin))
2064 at32_select_gpio(data->reset_pin, AT32_GPIOF_OUTPUT
2065 | AT32_GPIOF_HIGH);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002066
2067 atmel_ac97c0_pclk.dev = &pdev->dev;
2068
2069 platform_device_add(pdev);
2070 return pdev;
2071
Hans-Christian Egtvedt2f47c8c2009-03-24 13:59:23 +01002072out_free_resources:
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002073 platform_device_put(pdev);
2074 return NULL;
2075}
2076
2077/* --------------------------------------------------------------------
2078 * ABDAC
2079 * -------------------------------------------------------------------- */
2080static struct resource abdac0_resource[] __initdata = {
2081 PBMEM(0xfff02000),
2082 IRQ(27),
2083};
2084static struct clk abdac0_pclk = {
2085 .name = "pclk",
2086 .parent = &pbb_clk,
2087 .mode = pbb_clk_mode,
2088 .get_rate = pbb_clk_get_rate,
2089 .index = 8,
2090};
2091static struct clk abdac0_sample_clk = {
2092 .name = "sample_clk",
2093 .mode = genclk_mode,
2094 .get_rate = genclk_get_rate,
2095 .set_rate = genclk_set_rate,
2096 .set_parent = genclk_set_parent,
2097 .index = 6,
2098};
2099
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002100struct platform_device *__init
2101at32_add_device_abdac(unsigned int id, struct atmel_abdac_pdata *data)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002102{
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002103 struct platform_device *pdev;
2104 struct dw_dma_slave *dws;
2105 u32 pin_mask;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002106
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002107 if (id != 0 || !data)
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002108 return NULL;
2109
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002110 pdev = platform_device_alloc("atmel_abdac", id);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002111 if (!pdev)
2112 return NULL;
2113
2114 if (platform_device_add_resources(pdev, abdac0_resource,
2115 ARRAY_SIZE(abdac0_resource)))
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002116 goto out_free_resources;
2117
2118 dws = &data->dws;
2119
2120 dws->dma_dev = &dw_dmac0_device.dev;
2121 dws->reg_width = DW_DMA_SLAVE_WIDTH_32BIT;
2122 dws->cfg_hi = DWC_CFGH_DST_PER(2);
2123 dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL);
2124
2125 if (platform_device_add_data(pdev, data,
2126 sizeof(struct atmel_abdac_pdata)))
2127 goto out_free_resources;
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002128
Julien Maycaf18f12008-09-24 10:30:47 +02002129 pin_mask = (1 << 20) | (1 << 22); /* DATA1 & DATAN1 */
2130 pin_mask |= (1 << 21) | (1 << 23); /* DATA0 & DATAN0 */
2131
2132 select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002133
2134 abdac0_pclk.dev = &pdev->dev;
2135 abdac0_sample_clk.dev = &pdev->dev;
2136
2137 platform_device_add(pdev);
2138 return pdev;
2139
Hans-Christian Egtvedt6b0c9352009-03-24 13:59:22 +01002140out_free_resources:
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002141 platform_device_put(pdev);
2142 return NULL;
2143}
2144
2145/* --------------------------------------------------------------------
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002146 * GCLK
2147 * -------------------------------------------------------------------- */
2148static struct clk gclk0 = {
2149 .name = "gclk0",
2150 .mode = genclk_mode,
2151 .get_rate = genclk_get_rate,
2152 .set_rate = genclk_set_rate,
2153 .set_parent = genclk_set_parent,
2154 .index = 0,
2155};
2156static struct clk gclk1 = {
2157 .name = "gclk1",
2158 .mode = genclk_mode,
2159 .get_rate = genclk_get_rate,
2160 .set_rate = genclk_set_rate,
2161 .set_parent = genclk_set_parent,
2162 .index = 1,
2163};
2164static struct clk gclk2 = {
2165 .name = "gclk2",
2166 .mode = genclk_mode,
2167 .get_rate = genclk_get_rate,
2168 .set_rate = genclk_set_rate,
2169 .set_parent = genclk_set_parent,
2170 .index = 2,
2171};
2172static struct clk gclk3 = {
2173 .name = "gclk3",
2174 .mode = genclk_mode,
2175 .get_rate = genclk_get_rate,
2176 .set_rate = genclk_set_rate,
2177 .set_parent = genclk_set_parent,
2178 .index = 3,
2179};
2180static struct clk gclk4 = {
2181 .name = "gclk4",
2182 .mode = genclk_mode,
2183 .get_rate = genclk_get_rate,
2184 .set_rate = genclk_set_rate,
2185 .set_parent = genclk_set_parent,
2186 .index = 4,
2187};
2188
Alex Raimondi300bb762008-09-22 21:40:55 +02002189static __initdata struct clk *init_clocks[] = {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002190 &osc32k,
2191 &osc0,
2192 &osc1,
2193 &pll0,
2194 &pll1,
2195 &cpu_clk,
2196 &hsb_clk,
2197 &pba_clk,
2198 &pbb_clk,
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002199 &at32_pm_pclk,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002200 &at32_intc0_pclk,
Haavard Skinnemoenb47eb402008-07-31 15:56:36 +02002201 &at32_hmatrix_clk,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002202 &ebi_clk,
2203 &hramc_clk,
Haavard Skinnemoen7951f182008-03-05 15:08:27 +01002204 &sdramc_clk,
Haavard Skinnemoenbc157b72006-09-25 23:32:16 -07002205 &smc0_pclk,
2206 &smc0_mck,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002207 &pdc_hclk,
2208 &pdc_pclk,
Haavard Skinnemoen3bfb1d22008-07-08 11:59:42 -07002209 &dw_dmac0_hclk,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002210 &pico_clk,
2211 &pio0_mck,
2212 &pio1_mck,
2213 &pio2_mck,
2214 &pio3_mck,
Haavard Skinnemoen7f9f4672007-01-30 11:16:16 +01002215 &pio4_mck,
David Brownelle723ff62008-02-14 11:24:02 -08002216 &at32_tcb0_t0_clk,
2217 &at32_tcb1_t0_clk,
Hans-Christian Egtvedtd86d3142008-02-25 11:24:30 +01002218 &atmel_psif0_pclk,
2219 &atmel_psif1_pclk,
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02002220 &atmel_usart0_usart,
2221 &atmel_usart1_usart,
2222 &atmel_usart2_usart,
2223 &atmel_usart3_usart,
David Brownell9a1e8eb2008-02-08 04:21:21 -08002224 &atmel_pwm0_mck,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002225#if defined(CONFIG_CPU_AT32AP7000)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002226 &macb0_hclk,
2227 &macb0_pclk,
Haavard Skinnemoencfcb3a82006-10-30 09:23:12 +01002228 &macb1_hclk,
2229 &macb1_pclk,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002230#endif
Haavard Skinnemoen3d60ee12007-01-10 20:20:02 +01002231 &atmel_spi0_spi_clk,
2232 &atmel_spi1_spi_clk,
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002233 &atmel_twi0_pclk,
2234 &atmel_mci0_pclk,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002235#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01002236 &atmel_lcdfb0_hck1,
2237 &atmel_lcdfb0_pixclk,
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002238#endif
Hans-Christian Egtvedt9cf6cf52007-07-06 14:31:55 +02002239 &ssc0_pclk,
2240 &ssc1_pclk,
2241 &ssc2_pclk,
Haavard Skinnemoen6fcf0612007-06-14 17:37:31 +02002242 &usba0_hclk,
2243 &usba0_pclk,
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002244 &atmel_ac97c0_pclk,
2245 &abdac0_pclk,
2246 &abdac0_sample_clk,
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002247 &gclk0,
2248 &gclk1,
2249 &gclk2,
2250 &gclk3,
2251 &gclk4,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002252};
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002253
Haavard Skinnemoen65033ed2008-03-04 15:15:00 +01002254void __init setup_platform(void)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002255{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002256 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
2257 int i;
2258
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +02002259 if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002260 main_clock = &pll0;
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +02002261 cpu_clk.parent = &pll0;
2262 } else {
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002263 main_clock = &osc0;
Hans-Christian Egtvedt9e58e182007-06-04 16:10:57 +02002264 cpu_clk.parent = &osc0;
2265 }
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002266
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002267 if (pm_readl(PLL0) & PM_BIT(PLLOSC))
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002268 pll0.parent = &osc1;
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002269 if (pm_readl(PLL1) & PM_BIT(PLLOSC))
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002270 pll1.parent = &osc1;
2271
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002272 genclk_init_parent(&gclk0);
2273 genclk_init_parent(&gclk1);
2274 genclk_init_parent(&gclk2);
2275 genclk_init_parent(&gclk3);
2276 genclk_init_parent(&gclk4);
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002277#if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
Haavard Skinnemoend0a2b7a2007-03-21 18:08:49 +01002278 genclk_init_parent(&atmel_lcdfb0_pixclk);
Haavard Skinnemoen438ff3f2007-10-29 15:28:07 +01002279#endif
Haavard Skinnemoen2042c1c2007-10-22 17:42:35 +02002280 genclk_init_parent(&abdac0_sample_clk);
Haavard Skinnemoen7a5fe232007-02-16 13:14:33 +01002281
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002282 /*
Alex Raimondi300bb762008-09-22 21:40:55 +02002283 * Build initial dynamic clock list by registering all clocks
2284 * from the array.
2285 * At the same time, turn on all clocks that have at least one
2286 * user already, and turn off everything else. We only do this
2287 * for module clocks, and even though it isn't particularly
2288 * pretty to check the address of the mode function, it should
2289 * do the trick...
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002290 */
Alex Raimondi300bb762008-09-22 21:40:55 +02002291 for (i = 0; i < ARRAY_SIZE(init_clocks); i++) {
2292 struct clk *clk = init_clocks[i];
2293
2294 /* first, register clock */
2295 at32_clk_register(clk);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002296
Haavard Skinnemoen188ff652007-03-14 13:23:44 +01002297 if (clk->users == 0)
2298 continue;
2299
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002300 if (clk->mode == &cpu_clk_mode)
2301 cpu_mask |= 1 << clk->index;
2302 else if (clk->mode == &hsb_clk_mode)
2303 hsb_mask |= 1 << clk->index;
2304 else if (clk->mode == &pba_clk_mode)
2305 pba_mask |= 1 << clk->index;
2306 else if (clk->mode == &pbb_clk_mode)
2307 pbb_mask |= 1 << clk->index;
2308 }
2309
Haavard Skinnemoen7a5b8052007-06-04 12:58:30 +02002310 pm_writel(CPU_MASK, cpu_mask);
2311 pm_writel(HSB_MASK, hsb_mask);
2312 pm_writel(PBA_MASK, pba_mask);
2313 pm_writel(PBB_MASK, pbb_mask);
Haavard Skinnemoen65033ed2008-03-04 15:15:00 +01002314
2315 /* Initialize the port muxes */
2316 at32_init_pio(&pio0_device);
2317 at32_init_pio(&pio1_device);
2318 at32_init_pio(&pio2_device);
2319 at32_init_pio(&pio3_device);
2320 at32_init_pio(&pio4_device);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07002321}
Haavard Skinnemoenb83d6ee12008-03-05 10:00:28 +01002322
2323struct gen_pool *sram_pool;
2324
2325static int __init sram_init(void)
2326{
2327 struct gen_pool *pool;
2328
2329 /* 1KiB granularity */
2330 pool = gen_pool_create(10, -1);
2331 if (!pool)
2332 goto fail;
2333
2334 if (gen_pool_add(pool, 0x24000000, 0x8000, -1))
2335 goto err_pool_add;
2336
2337 sram_pool = pool;
2338 return 0;
2339
2340err_pool_add:
2341 gen_pool_destroy(pool);
2342fail:
2343 pr_err("Failed to create SRAM pool\n");
2344 return -ENOMEM;
2345}
2346core_initcall(sram_init);