2 * Copyright (C) 2005-2006 Atmel Corporation
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.
9 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/spi/spi.h>
15 #include <linux/usb/atmel_usba_udc.h>
20 #include <asm/arch/at32ap700x.h>
21 #include <asm/arch/board.h>
22 #include <asm/arch/portmux.h>
24 #include <video/atmel_lcdc.h>
35 .end = base + 0x3ff, \
36 .flags = IORESOURCE_MEM, \
42 .flags = IORESOURCE_IRQ, \
44 #define NAMED_IRQ(num, _name) \
49 .flags = IORESOURCE_IRQ, \
52 /* REVISIT these assume *every* device supports DMA, but several
53 * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more.
55 #define DEFINE_DEV(_name, _id) \
56 static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
57 static struct platform_device _name##_id##_device = { \
61 .dma_mask = &_name##_id##_dma_mask, \
62 .coherent_dma_mask = DMA_32BIT_MASK, \
64 .resource = _name##_id##_resource, \
65 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
67 #define DEFINE_DEV_DATA(_name, _id) \
68 static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
69 static struct platform_device _name##_id##_device = { \
73 .dma_mask = &_name##_id##_dma_mask, \
74 .platform_data = &_name##_id##_data, \
75 .coherent_dma_mask = DMA_32BIT_MASK, \
77 .resource = _name##_id##_resource, \
78 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
81 #define select_peripheral(pin, periph, flags) \
82 at32_select_periph(GPIO_PIN_##pin, GPIO_##periph, flags)
84 #define DEV_CLK(_name, devname, bus, _index) \
85 static struct clk devname##_##_name = { \
87 .dev = &devname##_device.dev, \
88 .parent = &bus##_clk, \
89 .mode = bus##_clk_mode, \
90 .get_rate = bus##_clk_get_rate, \
94 static DEFINE_SPINLOCK(pm_lock
);
96 static struct clk osc0
;
97 static struct clk osc1
;
99 static unsigned long osc_get_rate(struct clk
*clk
)
101 return at32_board_osc_rates
[clk
->index
];
104 static unsigned long pll_get_rate(struct clk
*clk
, unsigned long control
)
106 unsigned long div
, mul
, rate
;
108 div
= PM_BFEXT(PLLDIV
, control
) + 1;
109 mul
= PM_BFEXT(PLLMUL
, control
) + 1;
111 rate
= clk
->parent
->get_rate(clk
->parent
);
112 rate
= (rate
+ div
/ 2) / div
;
118 static long pll_set_rate(struct clk
*clk
, unsigned long rate
,
122 unsigned long mul_best_fit
= 0;
124 unsigned long div_min
;
125 unsigned long div_max
;
126 unsigned long div_best_fit
= 0;
128 unsigned long pll_in
;
129 unsigned long actual
= 0;
130 unsigned long rate_error
;
131 unsigned long rate_error_prev
= ~0UL;
134 /* Rate must be between 80 MHz and 200 Mhz. */
135 if (rate
< 80000000UL || rate
> 200000000UL)
138 ctrl
= PM_BF(PLLOPT
, 4);
139 base
= clk
->parent
->get_rate(clk
->parent
);
141 /* PLL input frequency must be between 6 MHz and 32 MHz. */
142 div_min
= DIV_ROUND_UP(base
, 32000000UL);
143 div_max
= base
/ 6000000UL;
145 if (div_max
< div_min
)
148 for (div
= div_min
; div
<= div_max
; div
++) {
149 pll_in
= (base
+ div
/ 2) / div
;
150 mul
= (rate
+ pll_in
/ 2) / pll_in
;
155 actual
= pll_in
* mul
;
156 rate_error
= abs(actual
- rate
);
158 if (rate_error
< rate_error_prev
) {
161 rate_error_prev
= rate_error
;
168 if (div_best_fit
== 0)
171 ctrl
|= PM_BF(PLLMUL
, mul_best_fit
- 1);
172 ctrl
|= PM_BF(PLLDIV
, div_best_fit
- 1);
173 ctrl
|= PM_BF(PLLCOUNT
, 16);
175 if (clk
->parent
== &osc1
)
176 ctrl
|= PM_BIT(PLLOSC
);
183 static unsigned long pll0_get_rate(struct clk
*clk
)
187 control
= pm_readl(PLL0
);
189 return pll_get_rate(clk
, control
);
192 static void pll1_mode(struct clk
*clk
, int enabled
)
194 unsigned long timeout
;
198 ctrl
= pm_readl(PLL1
);
201 if (!PM_BFEXT(PLLMUL
, ctrl
) && !PM_BFEXT(PLLDIV
, ctrl
)) {
202 pr_debug("clk %s: failed to enable, rate not set\n",
207 ctrl
|= PM_BIT(PLLEN
);
208 pm_writel(PLL1
, ctrl
);
210 /* Wait for PLL lock. */
211 for (timeout
= 10000; timeout
; timeout
--) {
212 status
= pm_readl(ISR
);
213 if (status
& PM_BIT(LOCK1
))
218 if (!(status
& PM_BIT(LOCK1
)))
219 printk(KERN_ERR
"clk %s: timeout waiting for lock\n",
222 ctrl
&= ~PM_BIT(PLLEN
);
223 pm_writel(PLL1
, ctrl
);
227 static unsigned long pll1_get_rate(struct clk
*clk
)
231 control
= pm_readl(PLL1
);
233 return pll_get_rate(clk
, control
);
236 static long pll1_set_rate(struct clk
*clk
, unsigned long rate
, int apply
)
239 unsigned long actual_rate
;
241 actual_rate
= pll_set_rate(clk
, rate
, &ctrl
);
244 if (actual_rate
!= rate
)
248 pr_debug(KERN_INFO
"clk %s: new rate %lu (actual rate %lu)\n",
249 clk
->name
, rate
, actual_rate
);
250 pm_writel(PLL1
, ctrl
);
256 static int pll1_set_parent(struct clk
*clk
, struct clk
*parent
)
263 ctrl
= pm_readl(PLL1
);
264 WARN_ON(ctrl
& PM_BIT(PLLEN
));
267 ctrl
&= ~PM_BIT(PLLOSC
);
268 else if (parent
== &osc1
)
269 ctrl
|= PM_BIT(PLLOSC
);
273 pm_writel(PLL1
, ctrl
);
274 clk
->parent
= parent
;
280 * The AT32AP7000 has five primary clock sources: One 32kHz
281 * oscillator, two crystal oscillators and two PLLs.
283 static struct clk osc32k
= {
285 .get_rate
= osc_get_rate
,
289 static struct clk osc0
= {
291 .get_rate
= osc_get_rate
,
295 static struct clk osc1
= {
297 .get_rate
= osc_get_rate
,
300 static struct clk pll0
= {
302 .get_rate
= pll0_get_rate
,
305 static struct clk pll1
= {
308 .get_rate
= pll1_get_rate
,
309 .set_rate
= pll1_set_rate
,
310 .set_parent
= pll1_set_parent
,
315 * The main clock can be either osc0 or pll0. The boot loader may
316 * have chosen one for us, so we don't really know which one until we
317 * have a look at the SM.
319 static struct clk
*main_clock
;
322 * Synchronous clocks are generated from the main clock. The clocks
323 * must satisfy the constraint
324 * fCPU >= fHSB >= fPB
325 * i.e. each clock must not be faster than its parent.
327 static unsigned long bus_clk_get_rate(struct clk
*clk
, unsigned int shift
)
329 return main_clock
->get_rate(main_clock
) >> shift
;
332 static void cpu_clk_mode(struct clk
*clk
, int enabled
)
337 spin_lock_irqsave(&pm_lock
, flags
);
338 mask
= pm_readl(CPU_MASK
);
340 mask
|= 1 << clk
->index
;
342 mask
&= ~(1 << clk
->index
);
343 pm_writel(CPU_MASK
, mask
);
344 spin_unlock_irqrestore(&pm_lock
, flags
);
347 static unsigned long cpu_clk_get_rate(struct clk
*clk
)
349 unsigned long cksel
, shift
= 0;
351 cksel
= pm_readl(CKSEL
);
352 if (cksel
& PM_BIT(CPUDIV
))
353 shift
= PM_BFEXT(CPUSEL
, cksel
) + 1;
355 return bus_clk_get_rate(clk
, shift
);
358 static long cpu_clk_set_rate(struct clk
*clk
, unsigned long rate
, int apply
)
361 unsigned long parent_rate
, child_div
, actual_rate
, div
;
363 parent_rate
= clk
->parent
->get_rate(clk
->parent
);
364 control
= pm_readl(CKSEL
);
366 if (control
& PM_BIT(HSBDIV
))
367 child_div
= 1 << (PM_BFEXT(HSBSEL
, control
) + 1);
371 if (rate
> 3 * (parent_rate
/ 4) || child_div
== 1) {
372 actual_rate
= parent_rate
;
373 control
&= ~PM_BIT(CPUDIV
);
376 div
= (parent_rate
+ rate
/ 2) / rate
;
379 cpusel
= (div
> 1) ? (fls(div
) - 2) : 0;
380 control
= PM_BIT(CPUDIV
) | PM_BFINS(CPUSEL
, cpusel
, control
);
381 actual_rate
= parent_rate
/ (1 << (cpusel
+ 1));
384 pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
385 clk
->name
, rate
, actual_rate
);
388 pm_writel(CKSEL
, control
);
393 static void hsb_clk_mode(struct clk
*clk
, int enabled
)
398 spin_lock_irqsave(&pm_lock
, flags
);
399 mask
= pm_readl(HSB_MASK
);
401 mask
|= 1 << clk
->index
;
403 mask
&= ~(1 << clk
->index
);
404 pm_writel(HSB_MASK
, mask
);
405 spin_unlock_irqrestore(&pm_lock
, flags
);
408 static unsigned long hsb_clk_get_rate(struct clk
*clk
)
410 unsigned long cksel
, shift
= 0;
412 cksel
= pm_readl(CKSEL
);
413 if (cksel
& PM_BIT(HSBDIV
))
414 shift
= PM_BFEXT(HSBSEL
, cksel
) + 1;
416 return bus_clk_get_rate(clk
, shift
);
419 static void pba_clk_mode(struct clk
*clk
, int enabled
)
424 spin_lock_irqsave(&pm_lock
, flags
);
425 mask
= pm_readl(PBA_MASK
);
427 mask
|= 1 << clk
->index
;
429 mask
&= ~(1 << clk
->index
);
430 pm_writel(PBA_MASK
, mask
);
431 spin_unlock_irqrestore(&pm_lock
, flags
);
434 static unsigned long pba_clk_get_rate(struct clk
*clk
)
436 unsigned long cksel
, shift
= 0;
438 cksel
= pm_readl(CKSEL
);
439 if (cksel
& PM_BIT(PBADIV
))
440 shift
= PM_BFEXT(PBASEL
, cksel
) + 1;
442 return bus_clk_get_rate(clk
, shift
);
445 static void pbb_clk_mode(struct clk
*clk
, int enabled
)
450 spin_lock_irqsave(&pm_lock
, flags
);
451 mask
= pm_readl(PBB_MASK
);
453 mask
|= 1 << clk
->index
;
455 mask
&= ~(1 << clk
->index
);
456 pm_writel(PBB_MASK
, mask
);
457 spin_unlock_irqrestore(&pm_lock
, flags
);
460 static unsigned long pbb_clk_get_rate(struct clk
*clk
)
462 unsigned long cksel
, shift
= 0;
464 cksel
= pm_readl(CKSEL
);
465 if (cksel
& PM_BIT(PBBDIV
))
466 shift
= PM_BFEXT(PBBSEL
, cksel
) + 1;
468 return bus_clk_get_rate(clk
, shift
);
471 static struct clk cpu_clk
= {
473 .get_rate
= cpu_clk_get_rate
,
474 .set_rate
= cpu_clk_set_rate
,
477 static struct clk hsb_clk
= {
480 .get_rate
= hsb_clk_get_rate
,
482 static struct clk pba_clk
= {
485 .mode
= hsb_clk_mode
,
486 .get_rate
= pba_clk_get_rate
,
489 static struct clk pbb_clk
= {
492 .mode
= hsb_clk_mode
,
493 .get_rate
= pbb_clk_get_rate
,
498 /* --------------------------------------------------------------------
499 * Generic Clock operations
500 * -------------------------------------------------------------------- */
502 static void genclk_mode(struct clk
*clk
, int enabled
)
506 control
= pm_readl(GCCTRL(clk
->index
));
508 control
|= PM_BIT(CEN
);
510 control
&= ~PM_BIT(CEN
);
511 pm_writel(GCCTRL(clk
->index
), control
);
514 static unsigned long genclk_get_rate(struct clk
*clk
)
517 unsigned long div
= 1;
519 control
= pm_readl(GCCTRL(clk
->index
));
520 if (control
& PM_BIT(DIVEN
))
521 div
= 2 * (PM_BFEXT(DIV
, control
) + 1);
523 return clk
->parent
->get_rate(clk
->parent
) / div
;
526 static long genclk_set_rate(struct clk
*clk
, unsigned long rate
, int apply
)
529 unsigned long parent_rate
, actual_rate
, div
;
531 parent_rate
= clk
->parent
->get_rate(clk
->parent
);
532 control
= pm_readl(GCCTRL(clk
->index
));
534 if (rate
> 3 * parent_rate
/ 4) {
535 actual_rate
= parent_rate
;
536 control
&= ~PM_BIT(DIVEN
);
538 div
= (parent_rate
+ rate
) / (2 * rate
) - 1;
539 control
= PM_BFINS(DIV
, div
, control
) | PM_BIT(DIVEN
);
540 actual_rate
= parent_rate
/ (2 * (div
+ 1));
543 dev_dbg(clk
->dev
, "clk %s: new rate %lu (actual rate %lu)\n",
544 clk
->name
, rate
, actual_rate
);
547 pm_writel(GCCTRL(clk
->index
), control
);
552 int genclk_set_parent(struct clk
*clk
, struct clk
*parent
)
556 dev_dbg(clk
->dev
, "clk %s: new parent %s (was %s)\n",
557 clk
->name
, parent
->name
, clk
->parent
->name
);
559 control
= pm_readl(GCCTRL(clk
->index
));
561 if (parent
== &osc1
|| parent
== &pll1
)
562 control
|= PM_BIT(OSCSEL
);
563 else if (parent
== &osc0
|| parent
== &pll0
)
564 control
&= ~PM_BIT(OSCSEL
);
568 if (parent
== &pll0
|| parent
== &pll1
)
569 control
|= PM_BIT(PLLSEL
);
571 control
&= ~PM_BIT(PLLSEL
);
573 pm_writel(GCCTRL(clk
->index
), control
);
574 clk
->parent
= parent
;
579 static void __init
genclk_init_parent(struct clk
*clk
)
584 BUG_ON(clk
->index
> 7);
586 control
= pm_readl(GCCTRL(clk
->index
));
587 if (control
& PM_BIT(OSCSEL
))
588 parent
= (control
& PM_BIT(PLLSEL
)) ? &pll1
: &osc1
;
590 parent
= (control
& PM_BIT(PLLSEL
)) ? &pll0
: &osc0
;
592 clk
->parent
= parent
;
595 /* --------------------------------------------------------------------
597 * -------------------------------------------------------------------- */
598 static struct resource at32_pm0_resource
[] = {
602 .flags
= IORESOURCE_MEM
,
607 static struct resource at32ap700x_rtc0_resource
[] = {
611 .flags
= IORESOURCE_MEM
,
616 static struct resource at32_wdt0_resource
[] = {
620 .flags
= IORESOURCE_MEM
,
624 static struct resource at32_eic0_resource
[] = {
628 .flags
= IORESOURCE_MEM
,
633 DEFINE_DEV(at32_pm
, 0);
634 DEFINE_DEV(at32ap700x_rtc
, 0);
635 DEFINE_DEV(at32_wdt
, 0);
636 DEFINE_DEV(at32_eic
, 0);
639 * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
642 static struct clk at32_pm_pclk
= {
644 .dev
= &at32_pm0_device
.dev
,
646 .mode
= pbb_clk_mode
,
647 .get_rate
= pbb_clk_get_rate
,
652 static struct resource intc0_resource
[] = {
655 struct platform_device at32_intc0_device
= {
658 .resource
= intc0_resource
,
659 .num_resources
= ARRAY_SIZE(intc0_resource
),
661 DEV_CLK(pclk
, at32_intc0
, pbb
, 1);
663 static struct clk ebi_clk
= {
666 .mode
= hsb_clk_mode
,
667 .get_rate
= hsb_clk_get_rate
,
670 static struct clk hramc_clk
= {
673 .mode
= hsb_clk_mode
,
674 .get_rate
= hsb_clk_get_rate
,
678 static struct clk sdramc_clk
= {
679 .name
= "sdramc_clk",
681 .mode
= pbb_clk_mode
,
682 .get_rate
= pbb_clk_get_rate
,
687 static struct resource smc0_resource
[] = {
691 DEV_CLK(pclk
, smc0
, pbb
, 13);
692 DEV_CLK(mck
, smc0
, hsb
, 0);
694 static struct platform_device pdc_device
= {
698 DEV_CLK(hclk
, pdc
, hsb
, 4);
699 DEV_CLK(pclk
, pdc
, pba
, 16);
701 static struct clk pico_clk
= {
704 .mode
= cpu_clk_mode
,
705 .get_rate
= cpu_clk_get_rate
,
709 static struct resource dmaca0_resource
[] = {
713 .flags
= IORESOURCE_MEM
,
717 DEFINE_DEV(dmaca
, 0);
718 DEV_CLK(hclk
, dmaca0
, hsb
, 10);
720 /* --------------------------------------------------------------------
722 * -------------------------------------------------------------------- */
724 static struct clk hmatrix_clk
= {
725 .name
= "hmatrix_clk",
727 .mode
= pbb_clk_mode
,
728 .get_rate
= pbb_clk_get_rate
,
732 #define HMATRIX_BASE ((void __iomem *)0xfff00800)
734 #define hmatrix_readl(reg) \
735 __raw_readl((HMATRIX_BASE) + HMATRIX_##reg)
736 #define hmatrix_writel(reg,value) \
737 __raw_writel((value), (HMATRIX_BASE) + HMATRIX_##reg)
740 * Set bits in the HMATRIX Special Function Register (SFR) used by the
741 * External Bus Interface (EBI). This can be used to enable special
742 * features like CompactFlash support, NAND Flash support, etc. on
743 * certain chipselects.
745 static inline void set_ebi_sfr_bits(u32 mask
)
749 clk_enable(&hmatrix_clk
);
750 sfr
= hmatrix_readl(SFR4
);
752 hmatrix_writel(SFR4
, sfr
);
753 clk_disable(&hmatrix_clk
);
756 /* --------------------------------------------------------------------
758 * -------------------------------------------------------------------- */
760 static struct resource at32_tcb0_resource
[] = {
764 static struct platform_device at32_tcb0_device
= {
767 .resource
= at32_tcb0_resource
,
768 .num_resources
= ARRAY_SIZE(at32_tcb0_resource
),
770 DEV_CLK(t0_clk
, at32_tcb0
, pbb
, 3);
772 static struct resource at32_tcb1_resource
[] = {
776 static struct platform_device at32_tcb1_device
= {
779 .resource
= at32_tcb1_resource
,
780 .num_resources
= ARRAY_SIZE(at32_tcb1_resource
),
782 DEV_CLK(t0_clk
, at32_tcb1
, pbb
, 4);
784 /* --------------------------------------------------------------------
786 * -------------------------------------------------------------------- */
788 static struct resource pio0_resource
[] = {
793 DEV_CLK(mck
, pio0
, pba
, 10);
795 static struct resource pio1_resource
[] = {
800 DEV_CLK(mck
, pio1
, pba
, 11);
802 static struct resource pio2_resource
[] = {
807 DEV_CLK(mck
, pio2
, pba
, 12);
809 static struct resource pio3_resource
[] = {
814 DEV_CLK(mck
, pio3
, pba
, 13);
816 static struct resource pio4_resource
[] = {
821 DEV_CLK(mck
, pio4
, pba
, 14);
823 void __init
at32_add_system_devices(void)
825 platform_device_register(&at32_pm0_device
);
826 platform_device_register(&at32_intc0_device
);
827 platform_device_register(&at32ap700x_rtc0_device
);
828 platform_device_register(&at32_wdt0_device
);
829 platform_device_register(&at32_eic0_device
);
830 platform_device_register(&smc0_device
);
831 platform_device_register(&pdc_device
);
832 platform_device_register(&dmaca0_device
);
834 platform_device_register(&at32_tcb0_device
);
835 platform_device_register(&at32_tcb1_device
);
837 platform_device_register(&pio0_device
);
838 platform_device_register(&pio1_device
);
839 platform_device_register(&pio2_device
);
840 platform_device_register(&pio3_device
);
841 platform_device_register(&pio4_device
);
844 /* --------------------------------------------------------------------
846 * -------------------------------------------------------------------- */
847 static struct resource atmel_psif0_resource
[] __initdata
= {
851 .flags
= IORESOURCE_MEM
,
855 static struct clk atmel_psif0_pclk
= {
858 .mode
= pba_clk_mode
,
859 .get_rate
= pba_clk_get_rate
,
863 static struct resource atmel_psif1_resource
[] __initdata
= {
867 .flags
= IORESOURCE_MEM
,
871 static struct clk atmel_psif1_pclk
= {
874 .mode
= pba_clk_mode
,
875 .get_rate
= pba_clk_get_rate
,
879 struct platform_device
*__init
at32_add_device_psif(unsigned int id
)
881 struct platform_device
*pdev
;
883 if (!(id
== 0 || id
== 1))
886 pdev
= platform_device_alloc("atmel_psif", id
);
892 if (platform_device_add_resources(pdev
, atmel_psif0_resource
,
893 ARRAY_SIZE(atmel_psif0_resource
)))
894 goto err_add_resources
;
895 atmel_psif0_pclk
.dev
= &pdev
->dev
;
896 select_peripheral(PA(8), PERIPH_A
, 0); /* CLOCK */
897 select_peripheral(PA(9), PERIPH_A
, 0); /* DATA */
900 if (platform_device_add_resources(pdev
, atmel_psif1_resource
,
901 ARRAY_SIZE(atmel_psif1_resource
)))
902 goto err_add_resources
;
903 atmel_psif1_pclk
.dev
= &pdev
->dev
;
904 select_peripheral(PB(11), PERIPH_A
, 0); /* CLOCK */
905 select_peripheral(PB(12), PERIPH_A
, 0); /* DATA */
911 platform_device_add(pdev
);
915 platform_device_put(pdev
);
919 /* --------------------------------------------------------------------
921 * -------------------------------------------------------------------- */
923 static struct atmel_uart_data atmel_usart0_data
= {
927 static struct resource atmel_usart0_resource
[] = {
931 DEFINE_DEV_DATA(atmel_usart
, 0);
932 DEV_CLK(usart
, atmel_usart0
, pba
, 3);
934 static struct atmel_uart_data atmel_usart1_data
= {
938 static struct resource atmel_usart1_resource
[] = {
942 DEFINE_DEV_DATA(atmel_usart
, 1);
943 DEV_CLK(usart
, atmel_usart1
, pba
, 4);
945 static struct atmel_uart_data atmel_usart2_data
= {
949 static struct resource atmel_usart2_resource
[] = {
953 DEFINE_DEV_DATA(atmel_usart
, 2);
954 DEV_CLK(usart
, atmel_usart2
, pba
, 5);
956 static struct atmel_uart_data atmel_usart3_data
= {
960 static struct resource atmel_usart3_resource
[] = {
964 DEFINE_DEV_DATA(atmel_usart
, 3);
965 DEV_CLK(usart
, atmel_usart3
, pba
, 6);
967 static inline void configure_usart0_pins(void)
969 select_peripheral(PA(8), PERIPH_B
, 0); /* RXD */
970 select_peripheral(PA(9), PERIPH_B
, 0); /* TXD */
973 static inline void configure_usart1_pins(void)
975 select_peripheral(PA(17), PERIPH_A
, 0); /* RXD */
976 select_peripheral(PA(18), PERIPH_A
, 0); /* TXD */
979 static inline void configure_usart2_pins(void)
981 select_peripheral(PB(26), PERIPH_B
, 0); /* RXD */
982 select_peripheral(PB(27), PERIPH_B
, 0); /* TXD */
985 static inline void configure_usart3_pins(void)
987 select_peripheral(PB(18), PERIPH_B
, 0); /* RXD */
988 select_peripheral(PB(17), PERIPH_B
, 0); /* TXD */
991 static struct platform_device
*__initdata at32_usarts
[4];
993 void __init
at32_map_usart(unsigned int hw_id
, unsigned int line
)
995 struct platform_device
*pdev
;
999 pdev
= &atmel_usart0_device
;
1000 configure_usart0_pins();
1003 pdev
= &atmel_usart1_device
;
1004 configure_usart1_pins();
1007 pdev
= &atmel_usart2_device
;
1008 configure_usart2_pins();
1011 pdev
= &atmel_usart3_device
;
1012 configure_usart3_pins();
1018 if (PXSEG(pdev
->resource
[0].start
) == P4SEG
) {
1019 /* Addresses in the P4 segment are permanently mapped 1:1 */
1020 struct atmel_uart_data
*data
= pdev
->dev
.platform_data
;
1021 data
->regs
= (void __iomem
*)pdev
->resource
[0].start
;
1025 at32_usarts
[line
] = pdev
;
1028 struct platform_device
*__init
at32_add_device_usart(unsigned int id
)
1030 platform_device_register(at32_usarts
[id
]);
1031 return at32_usarts
[id
];
1034 struct platform_device
*atmel_default_console_device
;
1036 void __init
at32_setup_serial_console(unsigned int usart_id
)
1038 atmel_default_console_device
= at32_usarts
[usart_id
];
1041 /* --------------------------------------------------------------------
1043 * -------------------------------------------------------------------- */
1045 #ifdef CONFIG_CPU_AT32AP7000
1046 static struct eth_platform_data macb0_data
;
1047 static struct resource macb0_resource
[] = {
1051 DEFINE_DEV_DATA(macb
, 0);
1052 DEV_CLK(hclk
, macb0
, hsb
, 8);
1053 DEV_CLK(pclk
, macb0
, pbb
, 6);
1055 static struct eth_platform_data macb1_data
;
1056 static struct resource macb1_resource
[] = {
1060 DEFINE_DEV_DATA(macb
, 1);
1061 DEV_CLK(hclk
, macb1
, hsb
, 9);
1062 DEV_CLK(pclk
, macb1
, pbb
, 7);
1064 struct platform_device
*__init
1065 at32_add_device_eth(unsigned int id
, struct eth_platform_data
*data
)
1067 struct platform_device
*pdev
;
1071 pdev
= &macb0_device
;
1073 select_peripheral(PC(3), PERIPH_A
, 0); /* TXD0 */
1074 select_peripheral(PC(4), PERIPH_A
, 0); /* TXD1 */
1075 select_peripheral(PC(7), PERIPH_A
, 0); /* TXEN */
1076 select_peripheral(PC(8), PERIPH_A
, 0); /* TXCK */
1077 select_peripheral(PC(9), PERIPH_A
, 0); /* RXD0 */
1078 select_peripheral(PC(10), PERIPH_A
, 0); /* RXD1 */
1079 select_peripheral(PC(13), PERIPH_A
, 0); /* RXER */
1080 select_peripheral(PC(15), PERIPH_A
, 0); /* RXDV */
1081 select_peripheral(PC(16), PERIPH_A
, 0); /* MDC */
1082 select_peripheral(PC(17), PERIPH_A
, 0); /* MDIO */
1084 if (!data
->is_rmii
) {
1085 select_peripheral(PC(0), PERIPH_A
, 0); /* COL */
1086 select_peripheral(PC(1), PERIPH_A
, 0); /* CRS */
1087 select_peripheral(PC(2), PERIPH_A
, 0); /* TXER */
1088 select_peripheral(PC(5), PERIPH_A
, 0); /* TXD2 */
1089 select_peripheral(PC(6), PERIPH_A
, 0); /* TXD3 */
1090 select_peripheral(PC(11), PERIPH_A
, 0); /* RXD2 */
1091 select_peripheral(PC(12), PERIPH_A
, 0); /* RXD3 */
1092 select_peripheral(PC(14), PERIPH_A
, 0); /* RXCK */
1093 select_peripheral(PC(18), PERIPH_A
, 0); /* SPD */
1098 pdev
= &macb1_device
;
1100 select_peripheral(PD(13), PERIPH_B
, 0); /* TXD0 */
1101 select_peripheral(PD(14), PERIPH_B
, 0); /* TXD1 */
1102 select_peripheral(PD(11), PERIPH_B
, 0); /* TXEN */
1103 select_peripheral(PD(12), PERIPH_B
, 0); /* TXCK */
1104 select_peripheral(PD(10), PERIPH_B
, 0); /* RXD0 */
1105 select_peripheral(PD(6), PERIPH_B
, 0); /* RXD1 */
1106 select_peripheral(PD(5), PERIPH_B
, 0); /* RXER */
1107 select_peripheral(PD(4), PERIPH_B
, 0); /* RXDV */
1108 select_peripheral(PD(3), PERIPH_B
, 0); /* MDC */
1109 select_peripheral(PD(2), PERIPH_B
, 0); /* MDIO */
1111 if (!data
->is_rmii
) {
1112 select_peripheral(PC(19), PERIPH_B
, 0); /* COL */
1113 select_peripheral(PC(23), PERIPH_B
, 0); /* CRS */
1114 select_peripheral(PC(26), PERIPH_B
, 0); /* TXER */
1115 select_peripheral(PC(27), PERIPH_B
, 0); /* TXD2 */
1116 select_peripheral(PC(28), PERIPH_B
, 0); /* TXD3 */
1117 select_peripheral(PC(29), PERIPH_B
, 0); /* RXD2 */
1118 select_peripheral(PC(30), PERIPH_B
, 0); /* RXD3 */
1119 select_peripheral(PC(24), PERIPH_B
, 0); /* RXCK */
1120 select_peripheral(PD(15), PERIPH_B
, 0); /* SPD */
1128 memcpy(pdev
->dev
.platform_data
, data
, sizeof(struct eth_platform_data
));
1129 platform_device_register(pdev
);
1135 /* --------------------------------------------------------------------
1137 * -------------------------------------------------------------------- */
1138 static struct resource atmel_spi0_resource
[] = {
1142 DEFINE_DEV(atmel_spi
, 0);
1143 DEV_CLK(spi_clk
, atmel_spi0
, pba
, 0);
1145 static struct resource atmel_spi1_resource
[] = {
1149 DEFINE_DEV(atmel_spi
, 1);
1150 DEV_CLK(spi_clk
, atmel_spi1
, pba
, 1);
1153 at32_spi_setup_slaves(unsigned int bus_num
, struct spi_board_info
*b
,
1154 unsigned int n
, const u8
*pins
)
1156 unsigned int pin
, mode
;
1158 for (; n
; n
--, b
++) {
1159 b
->bus_num
= bus_num
;
1160 if (b
->chip_select
>= 4)
1162 pin
= (unsigned)b
->controller_data
;
1164 pin
= pins
[b
->chip_select
];
1165 b
->controller_data
= (void *)pin
;
1167 mode
= AT32_GPIOF_OUTPUT
;
1168 if (!(b
->mode
& SPI_CS_HIGH
))
1169 mode
|= AT32_GPIOF_HIGH
;
1170 at32_select_gpio(pin
, mode
);
1174 struct platform_device
*__init
1175 at32_add_device_spi(unsigned int id
, struct spi_board_info
*b
, unsigned int n
)
1178 * Manage the chipselects as GPIOs, normally using the same pins
1179 * the SPI controller expects; but boards can use other pins.
1181 static u8 __initdata spi0_pins
[] =
1182 { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
1183 GPIO_PIN_PA(5), GPIO_PIN_PA(20), };
1184 static u8 __initdata spi1_pins
[] =
1185 { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
1186 GPIO_PIN_PB(4), GPIO_PIN_PA(27), };
1187 struct platform_device
*pdev
;
1191 pdev
= &atmel_spi0_device
;
1192 /* pullup MISO so a level is always defined */
1193 select_peripheral(PA(0), PERIPH_A
, AT32_GPIOF_PULLUP
);
1194 select_peripheral(PA(1), PERIPH_A
, 0); /* MOSI */
1195 select_peripheral(PA(2), PERIPH_A
, 0); /* SCK */
1196 at32_spi_setup_slaves(0, b
, n
, spi0_pins
);
1200 pdev
= &atmel_spi1_device
;
1201 /* pullup MISO so a level is always defined */
1202 select_peripheral(PB(0), PERIPH_B
, AT32_GPIOF_PULLUP
);
1203 select_peripheral(PB(1), PERIPH_B
, 0); /* MOSI */
1204 select_peripheral(PB(5), PERIPH_B
, 0); /* SCK */
1205 at32_spi_setup_slaves(1, b
, n
, spi1_pins
);
1212 spi_register_board_info(b
, n
);
1213 platform_device_register(pdev
);
1217 /* --------------------------------------------------------------------
1219 * -------------------------------------------------------------------- */
1220 static struct resource atmel_twi0_resource
[] __initdata
= {
1224 static struct clk atmel_twi0_pclk
= {
1227 .mode
= pba_clk_mode
,
1228 .get_rate
= pba_clk_get_rate
,
1232 struct platform_device
*__init
at32_add_device_twi(unsigned int id
,
1233 struct i2c_board_info
*b
,
1236 struct platform_device
*pdev
;
1241 pdev
= platform_device_alloc("atmel_twi", id
);
1245 if (platform_device_add_resources(pdev
, atmel_twi0_resource
,
1246 ARRAY_SIZE(atmel_twi0_resource
)))
1247 goto err_add_resources
;
1249 select_peripheral(PA(6), PERIPH_A
, 0); /* SDA */
1250 select_peripheral(PA(7), PERIPH_A
, 0); /* SDL */
1252 atmel_twi0_pclk
.dev
= &pdev
->dev
;
1255 i2c_register_board_info(id
, b
, n
);
1257 platform_device_add(pdev
);
1261 platform_device_put(pdev
);
1265 /* --------------------------------------------------------------------
1267 * -------------------------------------------------------------------- */
1268 static struct resource atmel_mci0_resource
[] __initdata
= {
1272 static struct clk atmel_mci0_pclk
= {
1275 .mode
= pbb_clk_mode
,
1276 .get_rate
= pbb_clk_get_rate
,
1280 struct platform_device
*__init
at32_add_device_mci(unsigned int id
)
1282 struct platform_device
*pdev
;
1287 pdev
= platform_device_alloc("atmel_mci", id
);
1291 if (platform_device_add_resources(pdev
, atmel_mci0_resource
,
1292 ARRAY_SIZE(atmel_mci0_resource
)))
1293 goto err_add_resources
;
1295 select_peripheral(PA(10), PERIPH_A
, 0); /* CLK */
1296 select_peripheral(PA(11), PERIPH_A
, 0); /* CMD */
1297 select_peripheral(PA(12), PERIPH_A
, 0); /* DATA0 */
1298 select_peripheral(PA(13), PERIPH_A
, 0); /* DATA1 */
1299 select_peripheral(PA(14), PERIPH_A
, 0); /* DATA2 */
1300 select_peripheral(PA(15), PERIPH_A
, 0); /* DATA3 */
1302 atmel_mci0_pclk
.dev
= &pdev
->dev
;
1304 platform_device_add(pdev
);
1308 platform_device_put(pdev
);
1312 /* --------------------------------------------------------------------
1314 * -------------------------------------------------------------------- */
1315 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
1316 static struct atmel_lcdfb_info atmel_lcdfb0_data
;
1317 static struct resource atmel_lcdfb0_resource
[] = {
1319 .start
= 0xff000000,
1321 .flags
= IORESOURCE_MEM
,
1325 /* Placeholder for pre-allocated fb memory */
1326 .start
= 0x00000000,
1331 DEFINE_DEV_DATA(atmel_lcdfb
, 0);
1332 DEV_CLK(hck1
, atmel_lcdfb0
, hsb
, 7);
1333 static struct clk atmel_lcdfb0_pixclk
= {
1335 .dev
= &atmel_lcdfb0_device
.dev
,
1336 .mode
= genclk_mode
,
1337 .get_rate
= genclk_get_rate
,
1338 .set_rate
= genclk_set_rate
,
1339 .set_parent
= genclk_set_parent
,
1343 struct platform_device
*__init
1344 at32_add_device_lcdc(unsigned int id
, struct atmel_lcdfb_info
*data
,
1345 unsigned long fbmem_start
, unsigned long fbmem_len
,
1346 unsigned int pin_config
)
1348 struct platform_device
*pdev
;
1349 struct atmel_lcdfb_info
*info
;
1350 struct fb_monspecs
*monspecs
;
1351 struct fb_videomode
*modedb
;
1352 unsigned int modedb_size
;
1355 * Do a deep copy of the fb data, monspecs and modedb. Make
1356 * sure all allocations are done before setting up the
1359 monspecs
= kmemdup(data
->default_monspecs
,
1360 sizeof(struct fb_monspecs
), GFP_KERNEL
);
1364 modedb_size
= sizeof(struct fb_videomode
) * monspecs
->modedb_len
;
1365 modedb
= kmemdup(monspecs
->modedb
, modedb_size
, GFP_KERNEL
);
1367 goto err_dup_modedb
;
1368 monspecs
->modedb
= modedb
;
1372 pdev
= &atmel_lcdfb0_device
;
1374 switch (pin_config
) {
1376 select_peripheral(PC(19), PERIPH_A
, 0); /* CC */
1377 select_peripheral(PC(20), PERIPH_A
, 0); /* HSYNC */
1378 select_peripheral(PC(21), PERIPH_A
, 0); /* PCLK */
1379 select_peripheral(PC(22), PERIPH_A
, 0); /* VSYNC */
1380 select_peripheral(PC(23), PERIPH_A
, 0); /* DVAL */
1381 select_peripheral(PC(24), PERIPH_A
, 0); /* MODE */
1382 select_peripheral(PC(25), PERIPH_A
, 0); /* PWR */
1383 select_peripheral(PC(26), PERIPH_A
, 0); /* DATA0 */
1384 select_peripheral(PC(27), PERIPH_A
, 0); /* DATA1 */
1385 select_peripheral(PC(28), PERIPH_A
, 0); /* DATA2 */
1386 select_peripheral(PC(29), PERIPH_A
, 0); /* DATA3 */
1387 select_peripheral(PC(30), PERIPH_A
, 0); /* DATA4 */
1388 select_peripheral(PC(31), PERIPH_A
, 0); /* DATA5 */
1389 select_peripheral(PD(0), PERIPH_A
, 0); /* DATA6 */
1390 select_peripheral(PD(1), PERIPH_A
, 0); /* DATA7 */
1391 select_peripheral(PD(2), PERIPH_A
, 0); /* DATA8 */
1392 select_peripheral(PD(3), PERIPH_A
, 0); /* DATA9 */
1393 select_peripheral(PD(4), PERIPH_A
, 0); /* DATA10 */
1394 select_peripheral(PD(5), PERIPH_A
, 0); /* DATA11 */
1395 select_peripheral(PD(6), PERIPH_A
, 0); /* DATA12 */
1396 select_peripheral(PD(7), PERIPH_A
, 0); /* DATA13 */
1397 select_peripheral(PD(8), PERIPH_A
, 0); /* DATA14 */
1398 select_peripheral(PD(9), PERIPH_A
, 0); /* DATA15 */
1399 select_peripheral(PD(10), PERIPH_A
, 0); /* DATA16 */
1400 select_peripheral(PD(11), PERIPH_A
, 0); /* DATA17 */
1401 select_peripheral(PD(12), PERIPH_A
, 0); /* DATA18 */
1402 select_peripheral(PD(13), PERIPH_A
, 0); /* DATA19 */
1403 select_peripheral(PD(14), PERIPH_A
, 0); /* DATA20 */
1404 select_peripheral(PD(15), PERIPH_A
, 0); /* DATA21 */
1405 select_peripheral(PD(16), PERIPH_A
, 0); /* DATA22 */
1406 select_peripheral(PD(17), PERIPH_A
, 0); /* DATA23 */
1409 select_peripheral(PE(0), PERIPH_B
, 0); /* CC */
1410 select_peripheral(PC(20), PERIPH_A
, 0); /* HSYNC */
1411 select_peripheral(PC(21), PERIPH_A
, 0); /* PCLK */
1412 select_peripheral(PC(22), PERIPH_A
, 0); /* VSYNC */
1413 select_peripheral(PE(1), PERIPH_B
, 0); /* DVAL */
1414 select_peripheral(PE(2), PERIPH_B
, 0); /* MODE */
1415 select_peripheral(PC(25), PERIPH_A
, 0); /* PWR */
1416 select_peripheral(PE(3), PERIPH_B
, 0); /* DATA0 */
1417 select_peripheral(PE(4), PERIPH_B
, 0); /* DATA1 */
1418 select_peripheral(PE(5), PERIPH_B
, 0); /* DATA2 */
1419 select_peripheral(PE(6), PERIPH_B
, 0); /* DATA3 */
1420 select_peripheral(PE(7), PERIPH_B
, 0); /* DATA4 */
1421 select_peripheral(PC(31), PERIPH_A
, 0); /* DATA5 */
1422 select_peripheral(PD(0), PERIPH_A
, 0); /* DATA6 */
1423 select_peripheral(PD(1), PERIPH_A
, 0); /* DATA7 */
1424 select_peripheral(PE(8), PERIPH_B
, 0); /* DATA8 */
1425 select_peripheral(PE(9), PERIPH_B
, 0); /* DATA9 */
1426 select_peripheral(PE(10), PERIPH_B
, 0); /* DATA10 */
1427 select_peripheral(PE(11), PERIPH_B
, 0); /* DATA11 */
1428 select_peripheral(PE(12), PERIPH_B
, 0); /* DATA12 */
1429 select_peripheral(PD(7), PERIPH_A
, 0); /* DATA13 */
1430 select_peripheral(PD(8), PERIPH_A
, 0); /* DATA14 */
1431 select_peripheral(PD(9), PERIPH_A
, 0); /* DATA15 */
1432 select_peripheral(PE(13), PERIPH_B
, 0); /* DATA16 */
1433 select_peripheral(PE(14), PERIPH_B
, 0); /* DATA17 */
1434 select_peripheral(PE(15), PERIPH_B
, 0); /* DATA18 */
1435 select_peripheral(PE(16), PERIPH_B
, 0); /* DATA19 */
1436 select_peripheral(PE(17), PERIPH_B
, 0); /* DATA20 */
1437 select_peripheral(PE(18), PERIPH_B
, 0); /* DATA21 */
1438 select_peripheral(PD(16), PERIPH_A
, 0); /* DATA22 */
1439 select_peripheral(PD(17), PERIPH_A
, 0); /* DATA23 */
1442 goto err_invalid_id
;
1445 clk_set_parent(&atmel_lcdfb0_pixclk
, &pll0
);
1446 clk_set_rate(&atmel_lcdfb0_pixclk
, clk_get_rate(&pll0
));
1450 goto err_invalid_id
;
1454 pdev
->resource
[2].start
= fbmem_start
;
1455 pdev
->resource
[2].end
= fbmem_start
+ fbmem_len
- 1;
1456 pdev
->resource
[2].flags
= IORESOURCE_MEM
;
1459 info
= pdev
->dev
.platform_data
;
1460 memcpy(info
, data
, sizeof(struct atmel_lcdfb_info
));
1461 info
->default_monspecs
= monspecs
;
1463 platform_device_register(pdev
);
1474 /* --------------------------------------------------------------------
1476 * -------------------------------------------------------------------- */
1477 static struct resource atmel_pwm0_resource
[] __initdata
= {
1481 static struct clk atmel_pwm0_mck
= {
1484 .mode
= pbb_clk_mode
,
1485 .get_rate
= pbb_clk_get_rate
,
1489 struct platform_device
*__init
at32_add_device_pwm(u32 mask
)
1491 struct platform_device
*pdev
;
1496 pdev
= platform_device_alloc("atmel_pwm", 0);
1500 if (platform_device_add_resources(pdev
, atmel_pwm0_resource
,
1501 ARRAY_SIZE(atmel_pwm0_resource
)))
1504 if (platform_device_add_data(pdev
, &mask
, sizeof(mask
)))
1507 if (mask
& (1 << 0))
1508 select_peripheral(PA(28), PERIPH_A
, 0);
1509 if (mask
& (1 << 1))
1510 select_peripheral(PA(29), PERIPH_A
, 0);
1511 if (mask
& (1 << 2))
1512 select_peripheral(PA(21), PERIPH_B
, 0);
1513 if (mask
& (1 << 3))
1514 select_peripheral(PA(22), PERIPH_B
, 0);
1516 atmel_pwm0_mck
.dev
= &pdev
->dev
;
1518 platform_device_add(pdev
);
1523 platform_device_put(pdev
);
1527 /* --------------------------------------------------------------------
1529 * -------------------------------------------------------------------- */
1530 static struct resource ssc0_resource
[] = {
1535 DEV_CLK(pclk
, ssc0
, pba
, 7);
1537 static struct resource ssc1_resource
[] = {
1542 DEV_CLK(pclk
, ssc1
, pba
, 8);
1544 static struct resource ssc2_resource
[] = {
1549 DEV_CLK(pclk
, ssc2
, pba
, 9);
1551 struct platform_device
*__init
1552 at32_add_device_ssc(unsigned int id
, unsigned int flags
)
1554 struct platform_device
*pdev
;
1558 pdev
= &ssc0_device
;
1559 if (flags
& ATMEL_SSC_RF
)
1560 select_peripheral(PA(21), PERIPH_A
, 0); /* RF */
1561 if (flags
& ATMEL_SSC_RK
)
1562 select_peripheral(PA(22), PERIPH_A
, 0); /* RK */
1563 if (flags
& ATMEL_SSC_TK
)
1564 select_peripheral(PA(23), PERIPH_A
, 0); /* TK */
1565 if (flags
& ATMEL_SSC_TF
)
1566 select_peripheral(PA(24), PERIPH_A
, 0); /* TF */
1567 if (flags
& ATMEL_SSC_TD
)
1568 select_peripheral(PA(25), PERIPH_A
, 0); /* TD */
1569 if (flags
& ATMEL_SSC_RD
)
1570 select_peripheral(PA(26), PERIPH_A
, 0); /* RD */
1573 pdev
= &ssc1_device
;
1574 if (flags
& ATMEL_SSC_RF
)
1575 select_peripheral(PA(0), PERIPH_B
, 0); /* RF */
1576 if (flags
& ATMEL_SSC_RK
)
1577 select_peripheral(PA(1), PERIPH_B
, 0); /* RK */
1578 if (flags
& ATMEL_SSC_TK
)
1579 select_peripheral(PA(2), PERIPH_B
, 0); /* TK */
1580 if (flags
& ATMEL_SSC_TF
)
1581 select_peripheral(PA(3), PERIPH_B
, 0); /* TF */
1582 if (flags
& ATMEL_SSC_TD
)
1583 select_peripheral(PA(4), PERIPH_B
, 0); /* TD */
1584 if (flags
& ATMEL_SSC_RD
)
1585 select_peripheral(PA(5), PERIPH_B
, 0); /* RD */
1588 pdev
= &ssc2_device
;
1589 if (flags
& ATMEL_SSC_TD
)
1590 select_peripheral(PB(13), PERIPH_A
, 0); /* TD */
1591 if (flags
& ATMEL_SSC_RD
)
1592 select_peripheral(PB(14), PERIPH_A
, 0); /* RD */
1593 if (flags
& ATMEL_SSC_TK
)
1594 select_peripheral(PB(15), PERIPH_A
, 0); /* TK */
1595 if (flags
& ATMEL_SSC_TF
)
1596 select_peripheral(PB(16), PERIPH_A
, 0); /* TF */
1597 if (flags
& ATMEL_SSC_RF
)
1598 select_peripheral(PB(17), PERIPH_A
, 0); /* RF */
1599 if (flags
& ATMEL_SSC_RK
)
1600 select_peripheral(PB(18), PERIPH_A
, 0); /* RK */
1606 platform_device_register(pdev
);
1610 /* --------------------------------------------------------------------
1611 * USB Device Controller
1612 * -------------------------------------------------------------------- */
1613 static struct resource usba0_resource
[] __initdata
= {
1615 .start
= 0xff300000,
1617 .flags
= IORESOURCE_MEM
,
1619 .start
= 0xfff03000,
1621 .flags
= IORESOURCE_MEM
,
1625 static struct clk usba0_pclk
= {
1628 .mode
= pbb_clk_mode
,
1629 .get_rate
= pbb_clk_get_rate
,
1632 static struct clk usba0_hclk
= {
1635 .mode
= hsb_clk_mode
,
1636 .get_rate
= hsb_clk_get_rate
,
1640 #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
1644 .fifo_size = maxpkt, \
1645 .nr_banks = maxbk, \
1650 static struct usba_ep_data at32_usba_ep
[] __initdata
= {
1651 EP("ep0", 0, 64, 1, 0, 0),
1652 EP("ep1", 1, 512, 2, 1, 1),
1653 EP("ep2", 2, 512, 2, 1, 1),
1654 EP("ep3-int", 3, 64, 3, 1, 0),
1655 EP("ep4-int", 4, 64, 3, 1, 0),
1656 EP("ep5", 5, 1024, 3, 1, 1),
1657 EP("ep6", 6, 1024, 3, 1, 1),
1662 struct platform_device
*__init
1663 at32_add_device_usba(unsigned int id
, struct usba_platform_data
*data
)
1666 * pdata doesn't have room for any endpoints, so we need to
1667 * append room for the ones we need right after it.
1670 struct usba_platform_data pdata
;
1671 struct usba_ep_data ep
[7];
1673 struct platform_device
*pdev
;
1678 pdev
= platform_device_alloc("atmel_usba_udc", 0);
1682 if (platform_device_add_resources(pdev
, usba0_resource
,
1683 ARRAY_SIZE(usba0_resource
)))
1687 usba_data
.pdata
.vbus_pin
= data
->vbus_pin
;
1689 usba_data
.pdata
.vbus_pin
= -EINVAL
;
1691 data
= &usba_data
.pdata
;
1692 data
->num_ep
= ARRAY_SIZE(at32_usba_ep
);
1693 memcpy(data
->ep
, at32_usba_ep
, sizeof(at32_usba_ep
));
1695 if (platform_device_add_data(pdev
, data
, sizeof(usba_data
)))
1698 if (data
->vbus_pin
>= 0)
1699 at32_select_gpio(data
->vbus_pin
, 0);
1701 usba0_pclk
.dev
= &pdev
->dev
;
1702 usba0_hclk
.dev
= &pdev
->dev
;
1704 platform_device_add(pdev
);
1709 platform_device_put(pdev
);
1713 /* --------------------------------------------------------------------
1714 * IDE / CompactFlash
1715 * -------------------------------------------------------------------- */
1716 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7001)
1717 static struct resource at32_smc_cs4_resource
[] __initdata
= {
1719 .start
= 0x04000000,
1721 .flags
= IORESOURCE_MEM
,
1723 IRQ(~0UL), /* Magic IRQ will be overridden */
1725 static struct resource at32_smc_cs5_resource
[] __initdata
= {
1727 .start
= 0x20000000,
1729 .flags
= IORESOURCE_MEM
,
1731 IRQ(~0UL), /* Magic IRQ will be overridden */
1734 static int __init
at32_init_ide_or_cf(struct platform_device
*pdev
,
1735 unsigned int cs
, unsigned int extint
)
1737 static unsigned int extint_pin_map
[4] __initdata
= {
1743 static bool common_pins_initialized __initdata
= false;
1744 unsigned int extint_pin
;
1747 if (extint
>= ARRAY_SIZE(extint_pin_map
))
1749 extint_pin
= extint_pin_map
[extint
];
1753 ret
= platform_device_add_resources(pdev
,
1754 at32_smc_cs4_resource
,
1755 ARRAY_SIZE(at32_smc_cs4_resource
));
1759 select_peripheral(PE(21), PERIPH_A
, 0); /* NCS4 -> OE_N */
1760 set_ebi_sfr_bits(HMATRIX_BIT(CS4A
));
1763 ret
= platform_device_add_resources(pdev
,
1764 at32_smc_cs5_resource
,
1765 ARRAY_SIZE(at32_smc_cs5_resource
));
1769 select_peripheral(PE(22), PERIPH_A
, 0); /* NCS5 -> OE_N */
1770 set_ebi_sfr_bits(HMATRIX_BIT(CS5A
));
1776 if (!common_pins_initialized
) {
1777 select_peripheral(PE(19), PERIPH_A
, 0); /* CFCE1 -> CS0_N */
1778 select_peripheral(PE(20), PERIPH_A
, 0); /* CFCE2 -> CS1_N */
1779 select_peripheral(PE(23), PERIPH_A
, 0); /* CFRNW -> DIR */
1780 select_peripheral(PE(24), PERIPH_A
, 0); /* NWAIT <- IORDY */
1781 common_pins_initialized
= true;
1784 at32_select_periph(extint_pin
, GPIO_PERIPH_A
, AT32_GPIOF_DEGLITCH
);
1786 pdev
->resource
[1].start
= EIM_IRQ_BASE
+ extint
;
1787 pdev
->resource
[1].end
= pdev
->resource
[1].start
;
1792 struct platform_device
*__init
1793 at32_add_device_ide(unsigned int id
, unsigned int extint
,
1794 struct ide_platform_data
*data
)
1796 struct platform_device
*pdev
;
1798 pdev
= platform_device_alloc("at32_ide", id
);
1802 if (platform_device_add_data(pdev
, data
,
1803 sizeof(struct ide_platform_data
)))
1806 if (at32_init_ide_or_cf(pdev
, data
->cs
, extint
))
1809 platform_device_add(pdev
);
1813 platform_device_put(pdev
);
1817 struct platform_device
*__init
1818 at32_add_device_cf(unsigned int id
, unsigned int extint
,
1819 struct cf_platform_data
*data
)
1821 struct platform_device
*pdev
;
1823 pdev
= platform_device_alloc("at32_cf", id
);
1827 if (platform_device_add_data(pdev
, data
,
1828 sizeof(struct cf_platform_data
)))
1831 if (at32_init_ide_or_cf(pdev
, data
->cs
, extint
))
1834 if (data
->detect_pin
!= GPIO_PIN_NONE
)
1835 at32_select_gpio(data
->detect_pin
, AT32_GPIOF_DEGLITCH
);
1836 if (data
->reset_pin
!= GPIO_PIN_NONE
)
1837 at32_select_gpio(data
->reset_pin
, 0);
1838 if (data
->vcc_pin
!= GPIO_PIN_NONE
)
1839 at32_select_gpio(data
->vcc_pin
, 0);
1840 /* READY is used as extint, so we can't select it as gpio */
1842 platform_device_add(pdev
);
1846 platform_device_put(pdev
);
1851 /* --------------------------------------------------------------------
1853 * -------------------------------------------------------------------- */
1854 static struct resource atmel_ac97c0_resource
[] __initdata
= {
1858 static struct clk atmel_ac97c0_pclk
= {
1861 .mode
= pbb_clk_mode
,
1862 .get_rate
= pbb_clk_get_rate
,
1866 struct platform_device
*__init
at32_add_device_ac97c(unsigned int id
)
1868 struct platform_device
*pdev
;
1873 pdev
= platform_device_alloc("atmel_ac97c", id
);
1877 if (platform_device_add_resources(pdev
, atmel_ac97c0_resource
,
1878 ARRAY_SIZE(atmel_ac97c0_resource
)))
1879 goto err_add_resources
;
1881 select_peripheral(PB(20), PERIPH_B
, 0); /* SYNC */
1882 select_peripheral(PB(21), PERIPH_B
, 0); /* SDO */
1883 select_peripheral(PB(22), PERIPH_B
, 0); /* SDI */
1884 select_peripheral(PB(23), PERIPH_B
, 0); /* SCLK */
1886 atmel_ac97c0_pclk
.dev
= &pdev
->dev
;
1888 platform_device_add(pdev
);
1892 platform_device_put(pdev
);
1896 /* --------------------------------------------------------------------
1898 * -------------------------------------------------------------------- */
1899 static struct resource abdac0_resource
[] __initdata
= {
1903 static struct clk abdac0_pclk
= {
1906 .mode
= pbb_clk_mode
,
1907 .get_rate
= pbb_clk_get_rate
,
1910 static struct clk abdac0_sample_clk
= {
1911 .name
= "sample_clk",
1912 .mode
= genclk_mode
,
1913 .get_rate
= genclk_get_rate
,
1914 .set_rate
= genclk_set_rate
,
1915 .set_parent
= genclk_set_parent
,
1919 struct platform_device
*__init
at32_add_device_abdac(unsigned int id
)
1921 struct platform_device
*pdev
;
1926 pdev
= platform_device_alloc("abdac", id
);
1930 if (platform_device_add_resources(pdev
, abdac0_resource
,
1931 ARRAY_SIZE(abdac0_resource
)))
1932 goto err_add_resources
;
1934 select_peripheral(PB(20), PERIPH_A
, 0); /* DATA1 */
1935 select_peripheral(PB(21), PERIPH_A
, 0); /* DATA0 */
1936 select_peripheral(PB(22), PERIPH_A
, 0); /* DATAN1 */
1937 select_peripheral(PB(23), PERIPH_A
, 0); /* DATAN0 */
1939 abdac0_pclk
.dev
= &pdev
->dev
;
1940 abdac0_sample_clk
.dev
= &pdev
->dev
;
1942 platform_device_add(pdev
);
1946 platform_device_put(pdev
);
1950 /* --------------------------------------------------------------------
1952 * -------------------------------------------------------------------- */
1953 static struct clk gclk0
= {
1955 .mode
= genclk_mode
,
1956 .get_rate
= genclk_get_rate
,
1957 .set_rate
= genclk_set_rate
,
1958 .set_parent
= genclk_set_parent
,
1961 static struct clk gclk1
= {
1963 .mode
= genclk_mode
,
1964 .get_rate
= genclk_get_rate
,
1965 .set_rate
= genclk_set_rate
,
1966 .set_parent
= genclk_set_parent
,
1969 static struct clk gclk2
= {
1971 .mode
= genclk_mode
,
1972 .get_rate
= genclk_get_rate
,
1973 .set_rate
= genclk_set_rate
,
1974 .set_parent
= genclk_set_parent
,
1977 static struct clk gclk3
= {
1979 .mode
= genclk_mode
,
1980 .get_rate
= genclk_get_rate
,
1981 .set_rate
= genclk_set_rate
,
1982 .set_parent
= genclk_set_parent
,
1985 static struct clk gclk4
= {
1987 .mode
= genclk_mode
,
1988 .get_rate
= genclk_get_rate
,
1989 .set_rate
= genclk_set_rate
,
1990 .set_parent
= genclk_set_parent
,
1994 struct clk
*at32_clock_list
[] = {
2025 &atmel_usart0_usart
,
2026 &atmel_usart1_usart
,
2027 &atmel_usart2_usart
,
2028 &atmel_usart3_usart
,
2030 #if defined(CONFIG_CPU_AT32AP7000)
2036 &atmel_spi0_spi_clk
,
2037 &atmel_spi1_spi_clk
,
2040 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
2042 &atmel_lcdfb0_pixclk
,
2058 unsigned int at32_nr_clocks
= ARRAY_SIZE(at32_clock_list
);
2060 void __init
setup_platform(void)
2062 u32 cpu_mask
= 0, hsb_mask
= 0, pba_mask
= 0, pbb_mask
= 0;
2065 if (pm_readl(MCCTRL
) & PM_BIT(PLLSEL
)) {
2067 cpu_clk
.parent
= &pll0
;
2070 cpu_clk
.parent
= &osc0
;
2073 if (pm_readl(PLL0
) & PM_BIT(PLLOSC
))
2074 pll0
.parent
= &osc1
;
2075 if (pm_readl(PLL1
) & PM_BIT(PLLOSC
))
2076 pll1
.parent
= &osc1
;
2078 genclk_init_parent(&gclk0
);
2079 genclk_init_parent(&gclk1
);
2080 genclk_init_parent(&gclk2
);
2081 genclk_init_parent(&gclk3
);
2082 genclk_init_parent(&gclk4
);
2083 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
2084 genclk_init_parent(&atmel_lcdfb0_pixclk
);
2086 genclk_init_parent(&abdac0_sample_clk
);
2089 * Turn on all clocks that have at least one user already, and
2090 * turn off everything else. We only do this for module
2091 * clocks, and even though it isn't particularly pretty to
2092 * check the address of the mode function, it should do the
2095 for (i
= 0; i
< ARRAY_SIZE(at32_clock_list
); i
++) {
2096 struct clk
*clk
= at32_clock_list
[i
];
2098 if (clk
->users
== 0)
2101 if (clk
->mode
== &cpu_clk_mode
)
2102 cpu_mask
|= 1 << clk
->index
;
2103 else if (clk
->mode
== &hsb_clk_mode
)
2104 hsb_mask
|= 1 << clk
->index
;
2105 else if (clk
->mode
== &pba_clk_mode
)
2106 pba_mask
|= 1 << clk
->index
;
2107 else if (clk
->mode
== &pbb_clk_mode
)
2108 pbb_mask
|= 1 << clk
->index
;
2111 pm_writel(CPU_MASK
, cpu_mask
);
2112 pm_writel(HSB_MASK
, hsb_mask
);
2113 pm_writel(PBA_MASK
, pba_mask
);
2114 pm_writel(PBB_MASK
, pbb_mask
);
2116 /* Initialize the port muxes */
2117 at32_init_pio(&pio0_device
);
2118 at32_init_pio(&pio1_device
);
2119 at32_init_pio(&pio2_device
);
2120 at32_init_pio(&pio3_device
);
2121 at32_init_pio(&pio4_device
);