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 unsigned long at32ap7000_osc_rates[3] = {
98 /* FIXME: these are ATSTK1002-specific */
103 static struct clk osc0;
104 static struct clk osc1;
106 static unsigned long osc_get_rate(struct clk *clk)
108 return at32ap7000_osc_rates[clk->index];
111 static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
113 unsigned long div, mul, rate;
115 div = PM_BFEXT(PLLDIV, control) + 1;
116 mul = PM_BFEXT(PLLMUL, control) + 1;
118 rate = clk->parent->get_rate(clk->parent);
119 rate = (rate + div / 2) / div;
125 static long pll_set_rate(struct clk *clk, unsigned long rate,
129 unsigned long mul_best_fit = 0;
131 unsigned long div_min;
132 unsigned long div_max;
133 unsigned long div_best_fit = 0;
135 unsigned long pll_in;
136 unsigned long actual = 0;
137 unsigned long rate_error;
138 unsigned long rate_error_prev = ~0UL;
141 /* Rate must be between 80 MHz and 200 Mhz. */
142 if (rate < 80000000UL || rate > 200000000UL)
145 ctrl = PM_BF(PLLOPT, 4);
146 base = clk->parent->get_rate(clk->parent);
148 /* PLL input frequency must be between 6 MHz and 32 MHz. */
149 div_min = DIV_ROUND_UP(base, 32000000UL);
150 div_max = base / 6000000UL;
152 if (div_max < div_min)
155 for (div = div_min; div <= div_max; div++) {
156 pll_in = (base + div / 2) / div;
157 mul = (rate + pll_in / 2) / pll_in;
162 actual = pll_in * mul;
163 rate_error = abs(actual - rate);
165 if (rate_error < rate_error_prev) {
168 rate_error_prev = rate_error;
175 if (div_best_fit == 0)
178 ctrl |= PM_BF(PLLMUL, mul_best_fit - 1);
179 ctrl |= PM_BF(PLLDIV, div_best_fit - 1);
180 ctrl |= PM_BF(PLLCOUNT, 16);
182 if (clk->parent == &osc1)
183 ctrl |= PM_BIT(PLLOSC);
190 static unsigned long pll0_get_rate(struct clk *clk)
194 control = pm_readl(PLL0);
196 return pll_get_rate(clk, control);
199 static void pll1_mode(struct clk *clk, int enabled)
201 unsigned long timeout;
205 ctrl = pm_readl(PLL1);
208 if (!PM_BFEXT(PLLMUL, ctrl) && !PM_BFEXT(PLLDIV, ctrl)) {
209 pr_debug("clk %s: failed to enable, rate not set\n",
214 ctrl |= PM_BIT(PLLEN);
215 pm_writel(PLL1, ctrl);
217 /* Wait for PLL lock. */
218 for (timeout = 10000; timeout; timeout--) {
219 status = pm_readl(ISR);
220 if (status & PM_BIT(LOCK1))
225 if (!(status & PM_BIT(LOCK1)))
226 printk(KERN_ERR "clk %s: timeout waiting for lock\n",
229 ctrl &= ~PM_BIT(PLLEN);
230 pm_writel(PLL1, ctrl);
234 static unsigned long pll1_get_rate(struct clk *clk)
238 control = pm_readl(PLL1);
240 return pll_get_rate(clk, control);
243 static long pll1_set_rate(struct clk *clk, unsigned long rate, int apply)
246 unsigned long actual_rate;
248 actual_rate = pll_set_rate(clk, rate, &ctrl);
251 if (actual_rate != rate)
255 pr_debug(KERN_INFO "clk %s: new rate %lu (actual rate %lu)\n",
256 clk->name, rate, actual_rate);
257 pm_writel(PLL1, ctrl);
263 static int pll1_set_parent(struct clk *clk, struct clk *parent)
270 ctrl = pm_readl(PLL1);
271 WARN_ON(ctrl & PM_BIT(PLLEN));
274 ctrl &= ~PM_BIT(PLLOSC);
275 else if (parent == &osc1)
276 ctrl |= PM_BIT(PLLOSC);
280 pm_writel(PLL1, ctrl);
281 clk->parent = parent;
287 * The AT32AP7000 has five primary clock sources: One 32kHz
288 * oscillator, two crystal oscillators and two PLLs.
290 static struct clk osc32k = {
292 .get_rate = osc_get_rate,
296 static struct clk osc0 = {
298 .get_rate = osc_get_rate,
302 static struct clk osc1 = {
304 .get_rate = osc_get_rate,
307 static struct clk pll0 = {
309 .get_rate = pll0_get_rate,
312 static struct clk pll1 = {
315 .get_rate = pll1_get_rate,
316 .set_rate = pll1_set_rate,
317 .set_parent = pll1_set_parent,
322 * The main clock can be either osc0 or pll0. The boot loader may
323 * have chosen one for us, so we don't really know which one until we
324 * have a look at the SM.
326 static struct clk *main_clock;
329 * Synchronous clocks are generated from the main clock. The clocks
330 * must satisfy the constraint
331 * fCPU >= fHSB >= fPB
332 * i.e. each clock must not be faster than its parent.
334 static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
336 return main_clock->get_rate(main_clock) >> shift;
339 static void cpu_clk_mode(struct clk *clk, int enabled)
344 spin_lock_irqsave(&pm_lock, flags);
345 mask = pm_readl(CPU_MASK);
347 mask |= 1 << clk->index;
349 mask &= ~(1 << clk->index);
350 pm_writel(CPU_MASK, mask);
351 spin_unlock_irqrestore(&pm_lock, flags);
354 static unsigned long cpu_clk_get_rate(struct clk *clk)
356 unsigned long cksel, shift = 0;
358 cksel = pm_readl(CKSEL);
359 if (cksel & PM_BIT(CPUDIV))
360 shift = PM_BFEXT(CPUSEL, cksel) + 1;
362 return bus_clk_get_rate(clk, shift);
365 static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
368 unsigned long parent_rate, child_div, actual_rate, div;
370 parent_rate = clk->parent->get_rate(clk->parent);
371 control = pm_readl(CKSEL);
373 if (control & PM_BIT(HSBDIV))
374 child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
378 if (rate > 3 * (parent_rate / 4) || child_div == 1) {
379 actual_rate = parent_rate;
380 control &= ~PM_BIT(CPUDIV);
383 div = (parent_rate + rate / 2) / rate;
386 cpusel = (div > 1) ? (fls(div) - 2) : 0;
387 control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
388 actual_rate = parent_rate / (1 << (cpusel + 1));
391 pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
392 clk->name, rate, actual_rate);
395 pm_writel(CKSEL, control);
400 static void hsb_clk_mode(struct clk *clk, int enabled)
405 spin_lock_irqsave(&pm_lock, flags);
406 mask = pm_readl(HSB_MASK);
408 mask |= 1 << clk->index;
410 mask &= ~(1 << clk->index);
411 pm_writel(HSB_MASK, mask);
412 spin_unlock_irqrestore(&pm_lock, flags);
415 static unsigned long hsb_clk_get_rate(struct clk *clk)
417 unsigned long cksel, shift = 0;
419 cksel = pm_readl(CKSEL);
420 if (cksel & PM_BIT(HSBDIV))
421 shift = PM_BFEXT(HSBSEL, cksel) + 1;
423 return bus_clk_get_rate(clk, shift);
426 static void pba_clk_mode(struct clk *clk, int enabled)
431 spin_lock_irqsave(&pm_lock, flags);
432 mask = pm_readl(PBA_MASK);
434 mask |= 1 << clk->index;
436 mask &= ~(1 << clk->index);
437 pm_writel(PBA_MASK, mask);
438 spin_unlock_irqrestore(&pm_lock, flags);
441 static unsigned long pba_clk_get_rate(struct clk *clk)
443 unsigned long cksel, shift = 0;
445 cksel = pm_readl(CKSEL);
446 if (cksel & PM_BIT(PBADIV))
447 shift = PM_BFEXT(PBASEL, cksel) + 1;
449 return bus_clk_get_rate(clk, shift);
452 static void pbb_clk_mode(struct clk *clk, int enabled)
457 spin_lock_irqsave(&pm_lock, flags);
458 mask = pm_readl(PBB_MASK);
460 mask |= 1 << clk->index;
462 mask &= ~(1 << clk->index);
463 pm_writel(PBB_MASK, mask);
464 spin_unlock_irqrestore(&pm_lock, flags);
467 static unsigned long pbb_clk_get_rate(struct clk *clk)
469 unsigned long cksel, shift = 0;
471 cksel = pm_readl(CKSEL);
472 if (cksel & PM_BIT(PBBDIV))
473 shift = PM_BFEXT(PBBSEL, cksel) + 1;
475 return bus_clk_get_rate(clk, shift);
478 static struct clk cpu_clk = {
480 .get_rate = cpu_clk_get_rate,
481 .set_rate = cpu_clk_set_rate,
484 static struct clk hsb_clk = {
487 .get_rate = hsb_clk_get_rate,
489 static struct clk pba_clk = {
492 .mode = hsb_clk_mode,
493 .get_rate = pba_clk_get_rate,
496 static struct clk pbb_clk = {
499 .mode = hsb_clk_mode,
500 .get_rate = pbb_clk_get_rate,
505 /* --------------------------------------------------------------------
506 * Generic Clock operations
507 * -------------------------------------------------------------------- */
509 static void genclk_mode(struct clk *clk, int enabled)
513 control = pm_readl(GCCTRL(clk->index));
515 control |= PM_BIT(CEN);
517 control &= ~PM_BIT(CEN);
518 pm_writel(GCCTRL(clk->index), control);
521 static unsigned long genclk_get_rate(struct clk *clk)
524 unsigned long div = 1;
526 control = pm_readl(GCCTRL(clk->index));
527 if (control & PM_BIT(DIVEN))
528 div = 2 * (PM_BFEXT(DIV, control) + 1);
530 return clk->parent->get_rate(clk->parent) / div;
533 static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
536 unsigned long parent_rate, actual_rate, div;
538 parent_rate = clk->parent->get_rate(clk->parent);
539 control = pm_readl(GCCTRL(clk->index));
541 if (rate > 3 * parent_rate / 4) {
542 actual_rate = parent_rate;
543 control &= ~PM_BIT(DIVEN);
545 div = (parent_rate + rate) / (2 * rate) - 1;
546 control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
547 actual_rate = parent_rate / (2 * (div + 1));
550 dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
551 clk->name, rate, actual_rate);
554 pm_writel(GCCTRL(clk->index), control);
559 int genclk_set_parent(struct clk *clk, struct clk *parent)
563 dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
564 clk->name, parent->name, clk->parent->name);
566 control = pm_readl(GCCTRL(clk->index));
568 if (parent == &osc1 || parent == &pll1)
569 control |= PM_BIT(OSCSEL);
570 else if (parent == &osc0 || parent == &pll0)
571 control &= ~PM_BIT(OSCSEL);
575 if (parent == &pll0 || parent == &pll1)
576 control |= PM_BIT(PLLSEL);
578 control &= ~PM_BIT(PLLSEL);
580 pm_writel(GCCTRL(clk->index), control);
581 clk->parent = parent;
586 static void __init genclk_init_parent(struct clk *clk)
591 BUG_ON(clk->index > 7);
593 control = pm_readl(GCCTRL(clk->index));
594 if (control & PM_BIT(OSCSEL))
595 parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
597 parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
599 clk->parent = parent;
602 /* --------------------------------------------------------------------
604 * -------------------------------------------------------------------- */
605 static struct resource at32_pm0_resource[] = {
609 .flags = IORESOURCE_MEM,
614 static struct resource at32ap700x_rtc0_resource[] = {
618 .flags = IORESOURCE_MEM,
623 static struct resource at32_wdt0_resource[] = {
627 .flags = IORESOURCE_MEM,
631 static struct resource at32_eic0_resource[] = {
635 .flags = IORESOURCE_MEM,
640 DEFINE_DEV(at32_pm, 0);
641 DEFINE_DEV(at32ap700x_rtc, 0);
642 DEFINE_DEV(at32_wdt, 0);
643 DEFINE_DEV(at32_eic, 0);
646 * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
649 static struct clk at32_pm_pclk = {
651 .dev = &at32_pm0_device.dev,
653 .mode = pbb_clk_mode,
654 .get_rate = pbb_clk_get_rate,
659 static struct resource intc0_resource[] = {
662 struct platform_device at32_intc0_device = {
665 .resource = intc0_resource,
666 .num_resources = ARRAY_SIZE(intc0_resource),
668 DEV_CLK(pclk, at32_intc0, pbb, 1);
670 static struct clk ebi_clk = {
673 .mode = hsb_clk_mode,
674 .get_rate = hsb_clk_get_rate,
677 static struct clk hramc_clk = {
680 .mode = hsb_clk_mode,
681 .get_rate = hsb_clk_get_rate,
686 static struct resource smc0_resource[] = {
690 DEV_CLK(pclk, smc0, pbb, 13);
691 DEV_CLK(mck, smc0, hsb, 0);
693 static struct platform_device pdc_device = {
697 DEV_CLK(hclk, pdc, hsb, 4);
698 DEV_CLK(pclk, pdc, pba, 16);
700 static struct clk pico_clk = {
703 .mode = cpu_clk_mode,
704 .get_rate = cpu_clk_get_rate,
708 static struct resource dmaca0_resource[] = {
712 .flags = IORESOURCE_MEM,
716 DEFINE_DEV(dmaca, 0);
717 DEV_CLK(hclk, dmaca0, hsb, 10);
719 /* --------------------------------------------------------------------
721 * -------------------------------------------------------------------- */
723 static struct clk hmatrix_clk = {
724 .name = "hmatrix_clk",
726 .mode = pbb_clk_mode,
727 .get_rate = pbb_clk_get_rate,
731 #define HMATRIX_BASE ((void __iomem *)0xfff00800)
733 #define hmatrix_readl(reg) \
734 __raw_readl((HMATRIX_BASE) + HMATRIX_##reg)
735 #define hmatrix_writel(reg,value) \
736 __raw_writel((value), (HMATRIX_BASE) + HMATRIX_##reg)
739 * Set bits in the HMATRIX Special Function Register (SFR) used by the
740 * External Bus Interface (EBI). This can be used to enable special
741 * features like CompactFlash support, NAND Flash support, etc. on
742 * certain chipselects.
744 static inline void set_ebi_sfr_bits(u32 mask)
748 clk_enable(&hmatrix_clk);
749 sfr = hmatrix_readl(SFR4);
751 hmatrix_writel(SFR4, sfr);
752 clk_disable(&hmatrix_clk);
755 /* --------------------------------------------------------------------
757 * -------------------------------------------------------------------- */
759 static struct resource at32_tcb0_resource[] = {
763 static struct platform_device at32_tcb0_device = {
766 .resource = at32_tcb0_resource,
767 .num_resources = ARRAY_SIZE(at32_tcb0_resource),
769 DEV_CLK(t0_clk, at32_tcb0, pbb, 3);
771 static struct resource at32_tcb1_resource[] = {
775 static struct platform_device at32_tcb1_device = {
778 .resource = at32_tcb1_resource,
779 .num_resources = ARRAY_SIZE(at32_tcb1_resource),
781 DEV_CLK(t0_clk, at32_tcb1, pbb, 4);
783 /* --------------------------------------------------------------------
785 * -------------------------------------------------------------------- */
787 static struct resource pio0_resource[] = {
792 DEV_CLK(mck, pio0, pba, 10);
794 static struct resource pio1_resource[] = {
799 DEV_CLK(mck, pio1, pba, 11);
801 static struct resource pio2_resource[] = {
806 DEV_CLK(mck, pio2, pba, 12);
808 static struct resource pio3_resource[] = {
813 DEV_CLK(mck, pio3, pba, 13);
815 static struct resource pio4_resource[] = {
820 DEV_CLK(mck, pio4, pba, 14);
822 void __init at32_add_system_devices(void)
824 platform_device_register(&at32_pm0_device);
825 platform_device_register(&at32_intc0_device);
826 platform_device_register(&at32ap700x_rtc0_device);
827 platform_device_register(&at32_wdt0_device);
828 platform_device_register(&at32_eic0_device);
829 platform_device_register(&smc0_device);
830 platform_device_register(&pdc_device);
831 platform_device_register(&dmaca0_device);
833 platform_device_register(&at32_tcb0_device);
834 platform_device_register(&at32_tcb1_device);
836 platform_device_register(&pio0_device);
837 platform_device_register(&pio1_device);
838 platform_device_register(&pio2_device);
839 platform_device_register(&pio3_device);
840 platform_device_register(&pio4_device);
843 /* --------------------------------------------------------------------
845 * -------------------------------------------------------------------- */
847 static struct atmel_uart_data atmel_usart0_data = {
851 static struct resource atmel_usart0_resource[] = {
855 DEFINE_DEV_DATA(atmel_usart, 0);
856 DEV_CLK(usart, atmel_usart0, pba, 3);
858 static struct atmel_uart_data atmel_usart1_data = {
862 static struct resource atmel_usart1_resource[] = {
866 DEFINE_DEV_DATA(atmel_usart, 1);
867 DEV_CLK(usart, atmel_usart1, pba, 4);
869 static struct atmel_uart_data atmel_usart2_data = {
873 static struct resource atmel_usart2_resource[] = {
877 DEFINE_DEV_DATA(atmel_usart, 2);
878 DEV_CLK(usart, atmel_usart2, pba, 5);
880 static struct atmel_uart_data atmel_usart3_data = {
884 static struct resource atmel_usart3_resource[] = {
888 DEFINE_DEV_DATA(atmel_usart, 3);
889 DEV_CLK(usart, atmel_usart3, pba, 6);
891 static inline void configure_usart0_pins(void)
893 select_peripheral(PA(8), PERIPH_B, 0); /* RXD */
894 select_peripheral(PA(9), PERIPH_B, 0); /* TXD */
897 static inline void configure_usart1_pins(void)
899 select_peripheral(PA(17), PERIPH_A, 0); /* RXD */
900 select_peripheral(PA(18), PERIPH_A, 0); /* TXD */
903 static inline void configure_usart2_pins(void)
905 select_peripheral(PB(26), PERIPH_B, 0); /* RXD */
906 select_peripheral(PB(27), PERIPH_B, 0); /* TXD */
909 static inline void configure_usart3_pins(void)
911 select_peripheral(PB(18), PERIPH_B, 0); /* RXD */
912 select_peripheral(PB(17), PERIPH_B, 0); /* TXD */
915 static struct platform_device *__initdata at32_usarts[4];
917 void __init at32_map_usart(unsigned int hw_id, unsigned int line)
919 struct platform_device *pdev;
923 pdev = &atmel_usart0_device;
924 configure_usart0_pins();
927 pdev = &atmel_usart1_device;
928 configure_usart1_pins();
931 pdev = &atmel_usart2_device;
932 configure_usart2_pins();
935 pdev = &atmel_usart3_device;
936 configure_usart3_pins();
942 if (PXSEG(pdev->resource[0].start) == P4SEG) {
943 /* Addresses in the P4 segment are permanently mapped 1:1 */
944 struct atmel_uart_data *data = pdev->dev.platform_data;
945 data->regs = (void __iomem *)pdev->resource[0].start;
949 at32_usarts[line] = pdev;
952 struct platform_device *__init at32_add_device_usart(unsigned int id)
954 platform_device_register(at32_usarts[id]);
955 return at32_usarts[id];
958 struct platform_device *atmel_default_console_device;
960 void __init at32_setup_serial_console(unsigned int usart_id)
962 atmel_default_console_device = at32_usarts[usart_id];
965 /* --------------------------------------------------------------------
967 * -------------------------------------------------------------------- */
969 #ifdef CONFIG_CPU_AT32AP7000
970 static struct eth_platform_data macb0_data;
971 static struct resource macb0_resource[] = {
975 DEFINE_DEV_DATA(macb, 0);
976 DEV_CLK(hclk, macb0, hsb, 8);
977 DEV_CLK(pclk, macb0, pbb, 6);
979 static struct eth_platform_data macb1_data;
980 static struct resource macb1_resource[] = {
984 DEFINE_DEV_DATA(macb, 1);
985 DEV_CLK(hclk, macb1, hsb, 9);
986 DEV_CLK(pclk, macb1, pbb, 7);
988 struct platform_device *__init
989 at32_add_device_eth(unsigned int id, struct eth_platform_data *data)
991 struct platform_device *pdev;
995 pdev = &macb0_device;
997 select_peripheral(PC(3), PERIPH_A, 0); /* TXD0 */
998 select_peripheral(PC(4), PERIPH_A, 0); /* TXD1 */
999 select_peripheral(PC(7), PERIPH_A, 0); /* TXEN */
1000 select_peripheral(PC(8), PERIPH_A, 0); /* TXCK */
1001 select_peripheral(PC(9), PERIPH_A, 0); /* RXD0 */
1002 select_peripheral(PC(10), PERIPH_A, 0); /* RXD1 */
1003 select_peripheral(PC(13), PERIPH_A, 0); /* RXER */
1004 select_peripheral(PC(15), PERIPH_A, 0); /* RXDV */
1005 select_peripheral(PC(16), PERIPH_A, 0); /* MDC */
1006 select_peripheral(PC(17), PERIPH_A, 0); /* MDIO */
1008 if (!data->is_rmii) {
1009 select_peripheral(PC(0), PERIPH_A, 0); /* COL */
1010 select_peripheral(PC(1), PERIPH_A, 0); /* CRS */
1011 select_peripheral(PC(2), PERIPH_A, 0); /* TXER */
1012 select_peripheral(PC(5), PERIPH_A, 0); /* TXD2 */
1013 select_peripheral(PC(6), PERIPH_A, 0); /* TXD3 */
1014 select_peripheral(PC(11), PERIPH_A, 0); /* RXD2 */
1015 select_peripheral(PC(12), PERIPH_A, 0); /* RXD3 */
1016 select_peripheral(PC(14), PERIPH_A, 0); /* RXCK */
1017 select_peripheral(PC(18), PERIPH_A, 0); /* SPD */
1022 pdev = &macb1_device;
1024 select_peripheral(PD(13), PERIPH_B, 0); /* TXD0 */
1025 select_peripheral(PD(14), PERIPH_B, 0); /* TXD1 */
1026 select_peripheral(PD(11), PERIPH_B, 0); /* TXEN */
1027 select_peripheral(PD(12), PERIPH_B, 0); /* TXCK */
1028 select_peripheral(PD(10), PERIPH_B, 0); /* RXD0 */
1029 select_peripheral(PD(6), PERIPH_B, 0); /* RXD1 */
1030 select_peripheral(PD(5), PERIPH_B, 0); /* RXER */
1031 select_peripheral(PD(4), PERIPH_B, 0); /* RXDV */
1032 select_peripheral(PD(3), PERIPH_B, 0); /* MDC */
1033 select_peripheral(PD(2), PERIPH_B, 0); /* MDIO */
1035 if (!data->is_rmii) {
1036 select_peripheral(PC(19), PERIPH_B, 0); /* COL */
1037 select_peripheral(PC(23), PERIPH_B, 0); /* CRS */
1038 select_peripheral(PC(26), PERIPH_B, 0); /* TXER */
1039 select_peripheral(PC(27), PERIPH_B, 0); /* TXD2 */
1040 select_peripheral(PC(28), PERIPH_B, 0); /* TXD3 */
1041 select_peripheral(PC(29), PERIPH_B, 0); /* RXD2 */
1042 select_peripheral(PC(30), PERIPH_B, 0); /* RXD3 */
1043 select_peripheral(PC(24), PERIPH_B, 0); /* RXCK */
1044 select_peripheral(PD(15), PERIPH_B, 0); /* SPD */
1052 memcpy(pdev->dev.platform_data, data, sizeof(struct eth_platform_data));
1053 platform_device_register(pdev);
1059 /* --------------------------------------------------------------------
1061 * -------------------------------------------------------------------- */
1062 static struct resource atmel_spi0_resource[] = {
1066 DEFINE_DEV(atmel_spi, 0);
1067 DEV_CLK(spi_clk, atmel_spi0, pba, 0);
1069 static struct resource atmel_spi1_resource[] = {
1073 DEFINE_DEV(atmel_spi, 1);
1074 DEV_CLK(spi_clk, atmel_spi1, pba, 1);
1077 at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b,
1078 unsigned int n, const u8 *pins)
1080 unsigned int pin, mode;
1082 for (; n; n--, b++) {
1083 b->bus_num = bus_num;
1084 if (b->chip_select >= 4)
1086 pin = (unsigned)b->controller_data;
1088 pin = pins[b->chip_select];
1089 b->controller_data = (void *)pin;
1091 mode = AT32_GPIOF_OUTPUT;
1092 if (!(b->mode & SPI_CS_HIGH))
1093 mode |= AT32_GPIOF_HIGH;
1094 at32_select_gpio(pin, mode);
1098 struct platform_device *__init
1099 at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
1102 * Manage the chipselects as GPIOs, normally using the same pins
1103 * the SPI controller expects; but boards can use other pins.
1105 static u8 __initdata spi0_pins[] =
1106 { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
1107 GPIO_PIN_PA(5), GPIO_PIN_PA(20), };
1108 static u8 __initdata spi1_pins[] =
1109 { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
1110 GPIO_PIN_PB(4), GPIO_PIN_PA(27), };
1111 struct platform_device *pdev;
1115 pdev = &atmel_spi0_device;
1116 select_peripheral(PA(0), PERIPH_A, 0); /* MISO */
1117 select_peripheral(PA(1), PERIPH_A, 0); /* MOSI */
1118 select_peripheral(PA(2), PERIPH_A, 0); /* SCK */
1119 at32_spi_setup_slaves(0, b, n, spi0_pins);
1123 pdev = &atmel_spi1_device;
1124 select_peripheral(PB(0), PERIPH_B, 0); /* MISO */
1125 select_peripheral(PB(1), PERIPH_B, 0); /* MOSI */
1126 select_peripheral(PB(5), PERIPH_B, 0); /* SCK */
1127 at32_spi_setup_slaves(1, b, n, spi1_pins);
1134 spi_register_board_info(b, n);
1135 platform_device_register(pdev);
1139 /* --------------------------------------------------------------------
1141 * -------------------------------------------------------------------- */
1142 static struct resource atmel_twi0_resource[] __initdata = {
1146 static struct clk atmel_twi0_pclk = {
1149 .mode = pba_clk_mode,
1150 .get_rate = pba_clk_get_rate,
1154 struct platform_device *__init at32_add_device_twi(unsigned int id,
1155 struct i2c_board_info *b,
1158 struct platform_device *pdev;
1163 pdev = platform_device_alloc("atmel_twi", id);
1167 if (platform_device_add_resources(pdev, atmel_twi0_resource,
1168 ARRAY_SIZE(atmel_twi0_resource)))
1169 goto err_add_resources;
1171 select_peripheral(PA(6), PERIPH_A, 0); /* SDA */
1172 select_peripheral(PA(7), PERIPH_A, 0); /* SDL */
1174 atmel_twi0_pclk.dev = &pdev->dev;
1177 i2c_register_board_info(id, b, n);
1179 platform_device_add(pdev);
1183 platform_device_put(pdev);
1187 /* --------------------------------------------------------------------
1189 * -------------------------------------------------------------------- */
1190 static struct resource atmel_mci0_resource[] __initdata = {
1194 static struct clk atmel_mci0_pclk = {
1197 .mode = pbb_clk_mode,
1198 .get_rate = pbb_clk_get_rate,
1202 struct platform_device *__init at32_add_device_mci(unsigned int id)
1204 struct platform_device *pdev;
1209 pdev = platform_device_alloc("atmel_mci", id);
1213 if (platform_device_add_resources(pdev, atmel_mci0_resource,
1214 ARRAY_SIZE(atmel_mci0_resource)))
1215 goto err_add_resources;
1217 select_peripheral(PA(10), PERIPH_A, 0); /* CLK */
1218 select_peripheral(PA(11), PERIPH_A, 0); /* CMD */
1219 select_peripheral(PA(12), PERIPH_A, 0); /* DATA0 */
1220 select_peripheral(PA(13), PERIPH_A, 0); /* DATA1 */
1221 select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */
1222 select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */
1224 atmel_mci0_pclk.dev = &pdev->dev;
1226 platform_device_add(pdev);
1230 platform_device_put(pdev);
1234 /* --------------------------------------------------------------------
1236 * -------------------------------------------------------------------- */
1237 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
1238 static struct atmel_lcdfb_info atmel_lcdfb0_data;
1239 static struct resource atmel_lcdfb0_resource[] = {
1241 .start = 0xff000000,
1243 .flags = IORESOURCE_MEM,
1247 /* Placeholder for pre-allocated fb memory */
1248 .start = 0x00000000,
1253 DEFINE_DEV_DATA(atmel_lcdfb, 0);
1254 DEV_CLK(hck1, atmel_lcdfb0, hsb, 7);
1255 static struct clk atmel_lcdfb0_pixclk = {
1257 .dev = &atmel_lcdfb0_device.dev,
1258 .mode = genclk_mode,
1259 .get_rate = genclk_get_rate,
1260 .set_rate = genclk_set_rate,
1261 .set_parent = genclk_set_parent,
1265 struct platform_device *__init
1266 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
1267 unsigned long fbmem_start, unsigned long fbmem_len)
1269 struct platform_device *pdev;
1270 struct atmel_lcdfb_info *info;
1271 struct fb_monspecs *monspecs;
1272 struct fb_videomode *modedb;
1273 unsigned int modedb_size;
1276 * Do a deep copy of the fb data, monspecs and modedb. Make
1277 * sure all allocations are done before setting up the
1280 monspecs = kmemdup(data->default_monspecs,
1281 sizeof(struct fb_monspecs), GFP_KERNEL);
1285 modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len;
1286 modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL);
1288 goto err_dup_modedb;
1289 monspecs->modedb = modedb;
1293 pdev = &atmel_lcdfb0_device;
1294 select_peripheral(PC(19), PERIPH_A, 0); /* CC */
1295 select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC */
1296 select_peripheral(PC(21), PERIPH_A, 0); /* PCLK */
1297 select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC */
1298 select_peripheral(PC(23), PERIPH_A, 0); /* DVAL */
1299 select_peripheral(PC(24), PERIPH_A, 0); /* MODE */
1300 select_peripheral(PC(25), PERIPH_A, 0); /* PWR */
1301 select_peripheral(PC(26), PERIPH_A, 0); /* DATA0 */
1302 select_peripheral(PC(27), PERIPH_A, 0); /* DATA1 */
1303 select_peripheral(PC(28), PERIPH_A, 0); /* DATA2 */
1304 select_peripheral(PC(29), PERIPH_A, 0); /* DATA3 */
1305 select_peripheral(PC(30), PERIPH_A, 0); /* DATA4 */
1306 select_peripheral(PC(31), PERIPH_A, 0); /* DATA5 */
1307 select_peripheral(PD(0), PERIPH_A, 0); /* DATA6 */
1308 select_peripheral(PD(1), PERIPH_A, 0); /* DATA7 */
1309 select_peripheral(PD(2), PERIPH_A, 0); /* DATA8 */
1310 select_peripheral(PD(3), PERIPH_A, 0); /* DATA9 */
1311 select_peripheral(PD(4), PERIPH_A, 0); /* DATA10 */
1312 select_peripheral(PD(5), PERIPH_A, 0); /* DATA11 */
1313 select_peripheral(PD(6), PERIPH_A, 0); /* DATA12 */
1314 select_peripheral(PD(7), PERIPH_A, 0); /* DATA13 */
1315 select_peripheral(PD(8), PERIPH_A, 0); /* DATA14 */
1316 select_peripheral(PD(9), PERIPH_A, 0); /* DATA15 */
1317 select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */
1318 select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */
1319 select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */
1320 select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */
1321 select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */
1322 select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */
1323 select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
1324 select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
1326 clk_set_parent(&atmel_lcdfb0_pixclk, &pll0);
1327 clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0));
1331 goto err_invalid_id;
1335 pdev->resource[2].start = fbmem_start;
1336 pdev->resource[2].end = fbmem_start + fbmem_len - 1;
1337 pdev->resource[2].flags = IORESOURCE_MEM;
1340 info = pdev->dev.platform_data;
1341 memcpy(info, data, sizeof(struct atmel_lcdfb_info));
1342 info->default_monspecs = monspecs;
1344 platform_device_register(pdev);
1355 /* --------------------------------------------------------------------
1357 * -------------------------------------------------------------------- */
1358 static struct resource atmel_pwm0_resource[] __initdata = {
1362 static struct clk atmel_pwm0_mck = {
1365 .mode = pbb_clk_mode,
1366 .get_rate = pbb_clk_get_rate,
1370 struct platform_device *__init at32_add_device_pwm(u32 mask)
1372 struct platform_device *pdev;
1377 pdev = platform_device_alloc("atmel_pwm", 0);
1381 if (platform_device_add_resources(pdev, atmel_pwm0_resource,
1382 ARRAY_SIZE(atmel_pwm0_resource)))
1385 if (platform_device_add_data(pdev, &mask, sizeof(mask)))
1388 if (mask & (1 << 0))
1389 select_peripheral(PA(28), PERIPH_A, 0);
1390 if (mask & (1 << 1))
1391 select_peripheral(PA(29), PERIPH_A, 0);
1392 if (mask & (1 << 2))
1393 select_peripheral(PA(21), PERIPH_B, 0);
1394 if (mask & (1 << 3))
1395 select_peripheral(PA(22), PERIPH_B, 0);
1397 atmel_pwm0_mck.dev = &pdev->dev;
1399 platform_device_add(pdev);
1404 platform_device_put(pdev);
1408 /* --------------------------------------------------------------------
1410 * -------------------------------------------------------------------- */
1411 static struct resource ssc0_resource[] = {
1416 DEV_CLK(pclk, ssc0, pba, 7);
1418 static struct resource ssc1_resource[] = {
1423 DEV_CLK(pclk, ssc1, pba, 8);
1425 static struct resource ssc2_resource[] = {
1430 DEV_CLK(pclk, ssc2, pba, 9);
1432 struct platform_device *__init
1433 at32_add_device_ssc(unsigned int id, unsigned int flags)
1435 struct platform_device *pdev;
1439 pdev = &ssc0_device;
1440 if (flags & ATMEL_SSC_RF)
1441 select_peripheral(PA(21), PERIPH_A, 0); /* RF */
1442 if (flags & ATMEL_SSC_RK)
1443 select_peripheral(PA(22), PERIPH_A, 0); /* RK */
1444 if (flags & ATMEL_SSC_TK)
1445 select_peripheral(PA(23), PERIPH_A, 0); /* TK */
1446 if (flags & ATMEL_SSC_TF)
1447 select_peripheral(PA(24), PERIPH_A, 0); /* TF */
1448 if (flags & ATMEL_SSC_TD)
1449 select_peripheral(PA(25), PERIPH_A, 0); /* TD */
1450 if (flags & ATMEL_SSC_RD)
1451 select_peripheral(PA(26), PERIPH_A, 0); /* RD */
1454 pdev = &ssc1_device;
1455 if (flags & ATMEL_SSC_RF)
1456 select_peripheral(PA(0), PERIPH_B, 0); /* RF */
1457 if (flags & ATMEL_SSC_RK)
1458 select_peripheral(PA(1), PERIPH_B, 0); /* RK */
1459 if (flags & ATMEL_SSC_TK)
1460 select_peripheral(PA(2), PERIPH_B, 0); /* TK */
1461 if (flags & ATMEL_SSC_TF)
1462 select_peripheral(PA(3), PERIPH_B, 0); /* TF */
1463 if (flags & ATMEL_SSC_TD)
1464 select_peripheral(PA(4), PERIPH_B, 0); /* TD */
1465 if (flags & ATMEL_SSC_RD)
1466 select_peripheral(PA(5), PERIPH_B, 0); /* RD */
1469 pdev = &ssc2_device;
1470 if (flags & ATMEL_SSC_TD)
1471 select_peripheral(PB(13), PERIPH_A, 0); /* TD */
1472 if (flags & ATMEL_SSC_RD)
1473 select_peripheral(PB(14), PERIPH_A, 0); /* RD */
1474 if (flags & ATMEL_SSC_TK)
1475 select_peripheral(PB(15), PERIPH_A, 0); /* TK */
1476 if (flags & ATMEL_SSC_TF)
1477 select_peripheral(PB(16), PERIPH_A, 0); /* TF */
1478 if (flags & ATMEL_SSC_RF)
1479 select_peripheral(PB(17), PERIPH_A, 0); /* RF */
1480 if (flags & ATMEL_SSC_RK)
1481 select_peripheral(PB(18), PERIPH_A, 0); /* RK */
1487 platform_device_register(pdev);
1491 /* --------------------------------------------------------------------
1492 * USB Device Controller
1493 * -------------------------------------------------------------------- */
1494 static struct resource usba0_resource[] __initdata = {
1496 .start = 0xff300000,
1498 .flags = IORESOURCE_MEM,
1500 .start = 0xfff03000,
1502 .flags = IORESOURCE_MEM,
1506 static struct clk usba0_pclk = {
1509 .mode = pbb_clk_mode,
1510 .get_rate = pbb_clk_get_rate,
1513 static struct clk usba0_hclk = {
1516 .mode = hsb_clk_mode,
1517 .get_rate = hsb_clk_get_rate,
1521 #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
1525 .fifo_size = maxpkt, \
1526 .nr_banks = maxbk, \
1531 static struct usba_ep_data at32_usba_ep[] __initdata = {
1532 EP("ep0", 0, 64, 1, 0, 0),
1533 EP("ep1", 1, 512, 2, 1, 1),
1534 EP("ep2", 2, 512, 2, 1, 1),
1535 EP("ep3-int", 3, 64, 3, 1, 0),
1536 EP("ep4-int", 4, 64, 3, 1, 0),
1537 EP("ep5", 5, 1024, 3, 1, 1),
1538 EP("ep6", 6, 1024, 3, 1, 1),
1543 struct platform_device *__init
1544 at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
1547 * pdata doesn't have room for any endpoints, so we need to
1548 * append room for the ones we need right after it.
1551 struct usba_platform_data pdata;
1552 struct usba_ep_data ep[7];
1554 struct platform_device *pdev;
1559 pdev = platform_device_alloc("atmel_usba_udc", 0);
1563 if (platform_device_add_resources(pdev, usba0_resource,
1564 ARRAY_SIZE(usba0_resource)))
1568 usba_data.pdata.vbus_pin = data->vbus_pin;
1570 usba_data.pdata.vbus_pin = -EINVAL;
1572 data = &usba_data.pdata;
1573 data->num_ep = ARRAY_SIZE(at32_usba_ep);
1574 memcpy(data->ep, at32_usba_ep, sizeof(at32_usba_ep));
1576 if (platform_device_add_data(pdev, data, sizeof(usba_data)))
1579 if (data->vbus_pin >= 0)
1580 at32_select_gpio(data->vbus_pin, 0);
1582 usba0_pclk.dev = &pdev->dev;
1583 usba0_hclk.dev = &pdev->dev;
1585 platform_device_add(pdev);
1590 platform_device_put(pdev);
1594 /* --------------------------------------------------------------------
1595 * IDE / CompactFlash
1596 * -------------------------------------------------------------------- */
1597 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7001)
1598 static struct resource at32_smc_cs4_resource[] __initdata = {
1600 .start = 0x04000000,
1602 .flags = IORESOURCE_MEM,
1604 IRQ(~0UL), /* Magic IRQ will be overridden */
1606 static struct resource at32_smc_cs5_resource[] __initdata = {
1608 .start = 0x20000000,
1610 .flags = IORESOURCE_MEM,
1612 IRQ(~0UL), /* Magic IRQ will be overridden */
1615 static int __init at32_init_ide_or_cf(struct platform_device *pdev,
1616 unsigned int cs, unsigned int extint)
1618 static unsigned int extint_pin_map[4] __initdata = {
1624 static bool common_pins_initialized __initdata = false;
1625 unsigned int extint_pin;
1628 if (extint >= ARRAY_SIZE(extint_pin_map))
1630 extint_pin = extint_pin_map[extint];
1634 ret = platform_device_add_resources(pdev,
1635 at32_smc_cs4_resource,
1636 ARRAY_SIZE(at32_smc_cs4_resource));
1640 select_peripheral(PE(21), PERIPH_A, 0); /* NCS4 -> OE_N */
1641 set_ebi_sfr_bits(HMATRIX_BIT(CS4A));
1644 ret = platform_device_add_resources(pdev,
1645 at32_smc_cs5_resource,
1646 ARRAY_SIZE(at32_smc_cs5_resource));
1650 select_peripheral(PE(22), PERIPH_A, 0); /* NCS5 -> OE_N */
1651 set_ebi_sfr_bits(HMATRIX_BIT(CS5A));
1657 if (!common_pins_initialized) {
1658 select_peripheral(PE(19), PERIPH_A, 0); /* CFCE1 -> CS0_N */
1659 select_peripheral(PE(20), PERIPH_A, 0); /* CFCE2 -> CS1_N */
1660 select_peripheral(PE(23), PERIPH_A, 0); /* CFRNW -> DIR */
1661 select_peripheral(PE(24), PERIPH_A, 0); /* NWAIT <- IORDY */
1662 common_pins_initialized = true;
1665 at32_select_periph(extint_pin, GPIO_PERIPH_A, AT32_GPIOF_DEGLITCH);
1667 pdev->resource[1].start = EIM_IRQ_BASE + extint;
1668 pdev->resource[1].end = pdev->resource[1].start;
1673 struct platform_device *__init
1674 at32_add_device_ide(unsigned int id, unsigned int extint,
1675 struct ide_platform_data *data)
1677 struct platform_device *pdev;
1679 pdev = platform_device_alloc("at32_ide", id);
1683 if (platform_device_add_data(pdev, data,
1684 sizeof(struct ide_platform_data)))
1687 if (at32_init_ide_or_cf(pdev, data->cs, extint))
1690 platform_device_add(pdev);
1694 platform_device_put(pdev);
1698 struct platform_device *__init
1699 at32_add_device_cf(unsigned int id, unsigned int extint,
1700 struct cf_platform_data *data)
1702 struct platform_device *pdev;
1704 pdev = platform_device_alloc("at32_cf", id);
1708 if (platform_device_add_data(pdev, data,
1709 sizeof(struct cf_platform_data)))
1712 if (at32_init_ide_or_cf(pdev, data->cs, extint))
1715 if (data->detect_pin != GPIO_PIN_NONE)
1716 at32_select_gpio(data->detect_pin, AT32_GPIOF_DEGLITCH);
1717 if (data->reset_pin != GPIO_PIN_NONE)
1718 at32_select_gpio(data->reset_pin, 0);
1719 if (data->vcc_pin != GPIO_PIN_NONE)
1720 at32_select_gpio(data->vcc_pin, 0);
1721 /* READY is used as extint, so we can't select it as gpio */
1723 platform_device_add(pdev);
1727 platform_device_put(pdev);
1732 /* --------------------------------------------------------------------
1734 * -------------------------------------------------------------------- */
1735 static struct resource atmel_ac97c0_resource[] __initdata = {
1739 static struct clk atmel_ac97c0_pclk = {
1742 .mode = pbb_clk_mode,
1743 .get_rate = pbb_clk_get_rate,
1747 struct platform_device *__init at32_add_device_ac97c(unsigned int id)
1749 struct platform_device *pdev;
1754 pdev = platform_device_alloc("atmel_ac97c", id);
1758 if (platform_device_add_resources(pdev, atmel_ac97c0_resource,
1759 ARRAY_SIZE(atmel_ac97c0_resource)))
1760 goto err_add_resources;
1762 select_peripheral(PB(20), PERIPH_B, 0); /* SYNC */
1763 select_peripheral(PB(21), PERIPH_B, 0); /* SDO */
1764 select_peripheral(PB(22), PERIPH_B, 0); /* SDI */
1765 select_peripheral(PB(23), PERIPH_B, 0); /* SCLK */
1767 atmel_ac97c0_pclk.dev = &pdev->dev;
1769 platform_device_add(pdev);
1773 platform_device_put(pdev);
1777 /* --------------------------------------------------------------------
1779 * -------------------------------------------------------------------- */
1780 static struct resource abdac0_resource[] __initdata = {
1784 static struct clk abdac0_pclk = {
1787 .mode = pbb_clk_mode,
1788 .get_rate = pbb_clk_get_rate,
1791 static struct clk abdac0_sample_clk = {
1792 .name = "sample_clk",
1793 .mode = genclk_mode,
1794 .get_rate = genclk_get_rate,
1795 .set_rate = genclk_set_rate,
1796 .set_parent = genclk_set_parent,
1800 struct platform_device *__init at32_add_device_abdac(unsigned int id)
1802 struct platform_device *pdev;
1807 pdev = platform_device_alloc("abdac", id);
1811 if (platform_device_add_resources(pdev, abdac0_resource,
1812 ARRAY_SIZE(abdac0_resource)))
1813 goto err_add_resources;
1815 select_peripheral(PB(20), PERIPH_A, 0); /* DATA1 */
1816 select_peripheral(PB(21), PERIPH_A, 0); /* DATA0 */
1817 select_peripheral(PB(22), PERIPH_A, 0); /* DATAN1 */
1818 select_peripheral(PB(23), PERIPH_A, 0); /* DATAN0 */
1820 abdac0_pclk.dev = &pdev->dev;
1821 abdac0_sample_clk.dev = &pdev->dev;
1823 platform_device_add(pdev);
1827 platform_device_put(pdev);
1831 /* --------------------------------------------------------------------
1833 * -------------------------------------------------------------------- */
1834 static struct clk gclk0 = {
1836 .mode = genclk_mode,
1837 .get_rate = genclk_get_rate,
1838 .set_rate = genclk_set_rate,
1839 .set_parent = genclk_set_parent,
1842 static struct clk gclk1 = {
1844 .mode = genclk_mode,
1845 .get_rate = genclk_get_rate,
1846 .set_rate = genclk_set_rate,
1847 .set_parent = genclk_set_parent,
1850 static struct clk gclk2 = {
1852 .mode = genclk_mode,
1853 .get_rate = genclk_get_rate,
1854 .set_rate = genclk_set_rate,
1855 .set_parent = genclk_set_parent,
1858 static struct clk gclk3 = {
1860 .mode = genclk_mode,
1861 .get_rate = genclk_get_rate,
1862 .set_rate = genclk_set_rate,
1863 .set_parent = genclk_set_parent,
1866 static struct clk gclk4 = {
1868 .mode = genclk_mode,
1869 .get_rate = genclk_get_rate,
1870 .set_rate = genclk_set_rate,
1871 .set_parent = genclk_set_parent,
1875 struct clk *at32_clock_list[] = {
1903 &atmel_usart0_usart,
1904 &atmel_usart1_usart,
1905 &atmel_usart2_usart,
1906 &atmel_usart3_usart,
1908 #if defined(CONFIG_CPU_AT32AP7000)
1914 &atmel_spi0_spi_clk,
1915 &atmel_spi1_spi_clk,
1918 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
1920 &atmel_lcdfb0_pixclk,
1936 unsigned int at32_nr_clocks = ARRAY_SIZE(at32_clock_list);
1938 void __init at32_portmux_init(void)
1940 at32_init_pio(&pio0_device);
1941 at32_init_pio(&pio1_device);
1942 at32_init_pio(&pio2_device);
1943 at32_init_pio(&pio3_device);
1944 at32_init_pio(&pio4_device);
1947 void __init at32_clock_init(void)
1949 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
1952 if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
1954 cpu_clk.parent = &pll0;
1957 cpu_clk.parent = &osc0;
1960 if (pm_readl(PLL0) & PM_BIT(PLLOSC))
1961 pll0.parent = &osc1;
1962 if (pm_readl(PLL1) & PM_BIT(PLLOSC))
1963 pll1.parent = &osc1;
1965 genclk_init_parent(&gclk0);
1966 genclk_init_parent(&gclk1);
1967 genclk_init_parent(&gclk2);
1968 genclk_init_parent(&gclk3);
1969 genclk_init_parent(&gclk4);
1970 #if defined(CONFIG_CPU_AT32AP7000) || defined(CONFIG_CPU_AT32AP7002)
1971 genclk_init_parent(&atmel_lcdfb0_pixclk);
1973 genclk_init_parent(&abdac0_sample_clk);
1976 * Turn on all clocks that have at least one user already, and
1977 * turn off everything else. We only do this for module
1978 * clocks, and even though it isn't particularly pretty to
1979 * check the address of the mode function, it should do the
1982 for (i = 0; i < ARRAY_SIZE(at32_clock_list); i++) {
1983 struct clk *clk = at32_clock_list[i];
1985 if (clk->users == 0)
1988 if (clk->mode == &cpu_clk_mode)
1989 cpu_mask |= 1 << clk->index;
1990 else if (clk->mode == &hsb_clk_mode)
1991 hsb_mask |= 1 << clk->index;
1992 else if (clk->mode == &pba_clk_mode)
1993 pba_mask |= 1 << clk->index;
1994 else if (clk->mode == &pbb_clk_mode)
1995 pbb_mask |= 1 << clk->index;
1998 pm_writel(CPU_MASK, cpu_mask);
1999 pm_writel(HSB_MASK, hsb_mask);
2000 pm_writel(PBA_MASK, pba_mask);
2001 pm_writel(PBB_MASK, pbb_mask);