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.
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/spi/spi.h>
17 #include <asm/arch/at32ap7000.h>
18 #include <asm/arch/board.h>
19 #include <asm/arch/portmux.h>
20 #include <asm/arch/sm.h>
22 #include <video/atmel_lcdc.h>
32 .end = base + 0x3ff, \
33 .flags = IORESOURCE_MEM, \
39 .flags = IORESOURCE_IRQ, \
41 #define NAMED_IRQ(num, _name) \
46 .flags = IORESOURCE_IRQ, \
49 /* REVISIT these assume *every* device supports DMA, but several
50 * don't ... tc, smc, pio, rtc, watchdog, pwm, ps2, and more.
52 #define DEFINE_DEV(_name, _id) \
53 static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
54 static struct platform_device _name##_id##_device = { \
58 .dma_mask = &_name##_id##_dma_mask, \
59 .coherent_dma_mask = DMA_32BIT_MASK, \
61 .resource = _name##_id##_resource, \
62 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
64 #define DEFINE_DEV_DATA(_name, _id) \
65 static u64 _name##_id##_dma_mask = DMA_32BIT_MASK; \
66 static struct platform_device _name##_id##_device = { \
70 .dma_mask = &_name##_id##_dma_mask, \
71 .platform_data = &_name##_id##_data, \
72 .coherent_dma_mask = DMA_32BIT_MASK, \
74 .resource = _name##_id##_resource, \
75 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
78 #define select_peripheral(pin, periph, flags) \
79 at32_select_periph(GPIO_PIN_##pin, GPIO_##periph, flags)
81 #define DEV_CLK(_name, devname, bus, _index) \
82 static struct clk devname##_##_name = { \
84 .dev = &devname##_device.dev, \
85 .parent = &bus##_clk, \
86 .mode = bus##_clk_mode, \
87 .get_rate = bus##_clk_get_rate, \
91 unsigned long at32ap7000_osc_rates[3] = {
93 /* FIXME: these are ATSTK1002-specific */
98 static unsigned long osc_get_rate(struct clk *clk)
100 return at32ap7000_osc_rates[clk->index];
103 static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
105 unsigned long div, mul, rate;
107 if (!(control & SM_BIT(PLLEN)))
110 div = SM_BFEXT(PLLDIV, control) + 1;
111 mul = SM_BFEXT(PLLMUL, control) + 1;
113 rate = clk->parent->get_rate(clk->parent);
114 rate = (rate + div / 2) / div;
120 static unsigned long pll0_get_rate(struct clk *clk)
124 control = sm_readl(&system_manager, PM_PLL0);
126 return pll_get_rate(clk, control);
129 static unsigned long pll1_get_rate(struct clk *clk)
133 control = sm_readl(&system_manager, PM_PLL1);
135 return pll_get_rate(clk, control);
139 * The AT32AP7000 has five primary clock sources: One 32kHz
140 * oscillator, two crystal oscillators and two PLLs.
142 static struct clk osc32k = {
144 .get_rate = osc_get_rate,
148 static struct clk osc0 = {
150 .get_rate = osc_get_rate,
154 static struct clk osc1 = {
156 .get_rate = osc_get_rate,
159 static struct clk pll0 = {
161 .get_rate = pll0_get_rate,
164 static struct clk pll1 = {
166 .get_rate = pll1_get_rate,
171 * The main clock can be either osc0 or pll0. The boot loader may
172 * have chosen one for us, so we don't really know which one until we
173 * have a look at the SM.
175 static struct clk *main_clock;
178 * Synchronous clocks are generated from the main clock. The clocks
179 * must satisfy the constraint
180 * fCPU >= fHSB >= fPB
181 * i.e. each clock must not be faster than its parent.
183 static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
185 return main_clock->get_rate(main_clock) >> shift;
188 static void cpu_clk_mode(struct clk *clk, int enabled)
190 struct at32_sm *sm = &system_manager;
194 spin_lock_irqsave(&sm->lock, flags);
195 mask = sm_readl(sm, PM_CPU_MASK);
197 mask |= 1 << clk->index;
199 mask &= ~(1 << clk->index);
200 sm_writel(sm, PM_CPU_MASK, mask);
201 spin_unlock_irqrestore(&sm->lock, flags);
204 static unsigned long cpu_clk_get_rate(struct clk *clk)
206 unsigned long cksel, shift = 0;
208 cksel = sm_readl(&system_manager, PM_CKSEL);
209 if (cksel & SM_BIT(CPUDIV))
210 shift = SM_BFEXT(CPUSEL, cksel) + 1;
212 return bus_clk_get_rate(clk, shift);
215 static void hsb_clk_mode(struct clk *clk, int enabled)
217 struct at32_sm *sm = &system_manager;
221 spin_lock_irqsave(&sm->lock, flags);
222 mask = sm_readl(sm, PM_HSB_MASK);
224 mask |= 1 << clk->index;
226 mask &= ~(1 << clk->index);
227 sm_writel(sm, PM_HSB_MASK, mask);
228 spin_unlock_irqrestore(&sm->lock, flags);
231 static unsigned long hsb_clk_get_rate(struct clk *clk)
233 unsigned long cksel, shift = 0;
235 cksel = sm_readl(&system_manager, PM_CKSEL);
236 if (cksel & SM_BIT(HSBDIV))
237 shift = SM_BFEXT(HSBSEL, cksel) + 1;
239 return bus_clk_get_rate(clk, shift);
242 static void pba_clk_mode(struct clk *clk, int enabled)
244 struct at32_sm *sm = &system_manager;
248 spin_lock_irqsave(&sm->lock, flags);
249 mask = sm_readl(sm, PM_PBA_MASK);
251 mask |= 1 << clk->index;
253 mask &= ~(1 << clk->index);
254 sm_writel(sm, PM_PBA_MASK, mask);
255 spin_unlock_irqrestore(&sm->lock, flags);
258 static unsigned long pba_clk_get_rate(struct clk *clk)
260 unsigned long cksel, shift = 0;
262 cksel = sm_readl(&system_manager, PM_CKSEL);
263 if (cksel & SM_BIT(PBADIV))
264 shift = SM_BFEXT(PBASEL, cksel) + 1;
266 return bus_clk_get_rate(clk, shift);
269 static void pbb_clk_mode(struct clk *clk, int enabled)
271 struct at32_sm *sm = &system_manager;
275 spin_lock_irqsave(&sm->lock, flags);
276 mask = sm_readl(sm, PM_PBB_MASK);
278 mask |= 1 << clk->index;
280 mask &= ~(1 << clk->index);
281 sm_writel(sm, PM_PBB_MASK, mask);
282 spin_unlock_irqrestore(&sm->lock, flags);
285 static unsigned long pbb_clk_get_rate(struct clk *clk)
287 unsigned long cksel, shift = 0;
289 cksel = sm_readl(&system_manager, PM_CKSEL);
290 if (cksel & SM_BIT(PBBDIV))
291 shift = SM_BFEXT(PBBSEL, cksel) + 1;
293 return bus_clk_get_rate(clk, shift);
296 static struct clk cpu_clk = {
298 .get_rate = cpu_clk_get_rate,
301 static struct clk hsb_clk = {
304 .get_rate = hsb_clk_get_rate,
306 static struct clk pba_clk = {
309 .mode = hsb_clk_mode,
310 .get_rate = pba_clk_get_rate,
313 static struct clk pbb_clk = {
316 .mode = hsb_clk_mode,
317 .get_rate = pbb_clk_get_rate,
322 /* --------------------------------------------------------------------
323 * Generic Clock operations
324 * -------------------------------------------------------------------- */
326 static void genclk_mode(struct clk *clk, int enabled)
330 control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
332 control |= SM_BIT(CEN);
334 control &= ~SM_BIT(CEN);
335 sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
338 static unsigned long genclk_get_rate(struct clk *clk)
341 unsigned long div = 1;
343 control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
344 if (control & SM_BIT(DIVEN))
345 div = 2 * (SM_BFEXT(DIV, control) + 1);
347 return clk->parent->get_rate(clk->parent) / div;
350 static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
353 unsigned long parent_rate, actual_rate, div;
355 parent_rate = clk->parent->get_rate(clk->parent);
356 control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
358 if (rate > 3 * parent_rate / 4) {
359 actual_rate = parent_rate;
360 control &= ~SM_BIT(DIVEN);
362 div = (parent_rate + rate) / (2 * rate) - 1;
363 control = SM_BFINS(DIV, div, control) | SM_BIT(DIVEN);
364 actual_rate = parent_rate / (2 * (div + 1));
367 printk("clk %s: new rate %lu (actual rate %lu)\n",
368 clk->name, rate, actual_rate);
371 sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index,
377 int genclk_set_parent(struct clk *clk, struct clk *parent)
381 printk("clk %s: new parent %s (was %s)\n",
382 clk->name, parent->name, clk->parent->name);
384 control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
386 if (parent == &osc1 || parent == &pll1)
387 control |= SM_BIT(OSCSEL);
388 else if (parent == &osc0 || parent == &pll0)
389 control &= ~SM_BIT(OSCSEL);
393 if (parent == &pll0 || parent == &pll1)
394 control |= SM_BIT(PLLSEL);
396 control &= ~SM_BIT(PLLSEL);
398 sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
399 clk->parent = parent;
404 static void __init genclk_init_parent(struct clk *clk)
409 BUG_ON(clk->index > 7);
411 control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
412 if (control & SM_BIT(OSCSEL))
413 parent = (control & SM_BIT(PLLSEL)) ? &pll1 : &osc1;
415 parent = (control & SM_BIT(PLLSEL)) ? &pll0 : &osc0;
417 clk->parent = parent;
420 /* --------------------------------------------------------------------
422 * -------------------------------------------------------------------- */
423 static struct resource sm_resource[] = {
425 NAMED_IRQ(19, "eim"),
427 NAMED_IRQ(21, "rtc"),
429 struct platform_device at32_sm_device = {
432 .resource = sm_resource,
433 .num_resources = ARRAY_SIZE(sm_resource),
435 static struct clk at32_sm_pclk = {
437 .dev = &at32_sm_device.dev,
439 .mode = pbb_clk_mode,
440 .get_rate = pbb_clk_get_rate,
445 static struct resource intc0_resource[] = {
448 struct platform_device at32_intc0_device = {
451 .resource = intc0_resource,
452 .num_resources = ARRAY_SIZE(intc0_resource),
454 DEV_CLK(pclk, at32_intc0, pbb, 1);
456 static struct clk ebi_clk = {
459 .mode = hsb_clk_mode,
460 .get_rate = hsb_clk_get_rate,
463 static struct clk hramc_clk = {
466 .mode = hsb_clk_mode,
467 .get_rate = hsb_clk_get_rate,
472 static struct resource smc0_resource[] = {
476 DEV_CLK(pclk, smc0, pbb, 13);
477 DEV_CLK(mck, smc0, hsb, 0);
479 static struct platform_device pdc_device = {
483 DEV_CLK(hclk, pdc, hsb, 4);
484 DEV_CLK(pclk, pdc, pba, 16);
486 static struct clk pico_clk = {
489 .mode = cpu_clk_mode,
490 .get_rate = cpu_clk_get_rate,
494 /* --------------------------------------------------------------------
496 * -------------------------------------------------------------------- */
498 static struct clk hmatrix_clk = {
499 .name = "hmatrix_clk",
501 .mode = pbb_clk_mode,
502 .get_rate = pbb_clk_get_rate,
506 #define HMATRIX_BASE ((void __iomem *)0xfff00800)
508 #define hmatrix_readl(reg) \
509 __raw_readl((HMATRIX_BASE) + HMATRIX_##reg)
510 #define hmatrix_writel(reg,value) \
511 __raw_writel((value), (HMATRIX_BASE) + HMATRIX_##reg)
514 * Set bits in the HMATRIX Special Function Register (SFR) used by the
515 * External Bus Interface (EBI). This can be used to enable special
516 * features like CompactFlash support, NAND Flash support, etc. on
517 * certain chipselects.
519 static inline void set_ebi_sfr_bits(u32 mask)
523 clk_enable(&hmatrix_clk);
524 sfr = hmatrix_readl(SFR4);
526 hmatrix_writel(SFR4, sfr);
527 clk_disable(&hmatrix_clk);
530 /* --------------------------------------------------------------------
531 * System Timer/Counter (TC)
532 * -------------------------------------------------------------------- */
533 static struct resource at32_systc0_resource[] = {
537 struct platform_device at32_systc0_device = {
540 .resource = at32_systc0_resource,
541 .num_resources = ARRAY_SIZE(at32_systc0_resource),
543 DEV_CLK(pclk, at32_systc0, pbb, 3);
545 /* --------------------------------------------------------------------
547 * -------------------------------------------------------------------- */
549 static struct resource pio0_resource[] = {
554 DEV_CLK(mck, pio0, pba, 10);
556 static struct resource pio1_resource[] = {
561 DEV_CLK(mck, pio1, pba, 11);
563 static struct resource pio2_resource[] = {
568 DEV_CLK(mck, pio2, pba, 12);
570 static struct resource pio3_resource[] = {
575 DEV_CLK(mck, pio3, pba, 13);
577 static struct resource pio4_resource[] = {
582 DEV_CLK(mck, pio4, pba, 14);
584 void __init at32_add_system_devices(void)
586 system_manager.eim_first_irq = EIM_IRQ_BASE;
588 platform_device_register(&at32_sm_device);
589 platform_device_register(&at32_intc0_device);
590 platform_device_register(&smc0_device);
591 platform_device_register(&pdc_device);
593 platform_device_register(&at32_systc0_device);
595 platform_device_register(&pio0_device);
596 platform_device_register(&pio1_device);
597 platform_device_register(&pio2_device);
598 platform_device_register(&pio3_device);
599 platform_device_register(&pio4_device);
602 /* --------------------------------------------------------------------
604 * -------------------------------------------------------------------- */
606 static struct atmel_uart_data atmel_usart0_data = {
610 static struct resource atmel_usart0_resource[] = {
614 DEFINE_DEV_DATA(atmel_usart, 0);
615 DEV_CLK(usart, atmel_usart0, pba, 4);
617 static struct atmel_uart_data atmel_usart1_data = {
621 static struct resource atmel_usart1_resource[] = {
625 DEFINE_DEV_DATA(atmel_usart, 1);
626 DEV_CLK(usart, atmel_usart1, pba, 4);
628 static struct atmel_uart_data atmel_usart2_data = {
632 static struct resource atmel_usart2_resource[] = {
636 DEFINE_DEV_DATA(atmel_usart, 2);
637 DEV_CLK(usart, atmel_usart2, pba, 5);
639 static struct atmel_uart_data atmel_usart3_data = {
643 static struct resource atmel_usart3_resource[] = {
647 DEFINE_DEV_DATA(atmel_usart, 3);
648 DEV_CLK(usart, atmel_usart3, pba, 6);
650 static inline void configure_usart0_pins(void)
652 select_peripheral(PA(8), PERIPH_B, 0); /* RXD */
653 select_peripheral(PA(9), PERIPH_B, 0); /* TXD */
656 static inline void configure_usart1_pins(void)
658 select_peripheral(PA(17), PERIPH_A, 0); /* RXD */
659 select_peripheral(PA(18), PERIPH_A, 0); /* TXD */
662 static inline void configure_usart2_pins(void)
664 select_peripheral(PB(26), PERIPH_B, 0); /* RXD */
665 select_peripheral(PB(27), PERIPH_B, 0); /* TXD */
668 static inline void configure_usart3_pins(void)
670 select_peripheral(PB(18), PERIPH_B, 0); /* RXD */
671 select_peripheral(PB(17), PERIPH_B, 0); /* TXD */
674 static struct platform_device *__initdata at32_usarts[4];
676 void __init at32_map_usart(unsigned int hw_id, unsigned int line)
678 struct platform_device *pdev;
682 pdev = &atmel_usart0_device;
683 configure_usart0_pins();
686 pdev = &atmel_usart1_device;
687 configure_usart1_pins();
690 pdev = &atmel_usart2_device;
691 configure_usart2_pins();
694 pdev = &atmel_usart3_device;
695 configure_usart3_pins();
701 if (PXSEG(pdev->resource[0].start) == P4SEG) {
702 /* Addresses in the P4 segment are permanently mapped 1:1 */
703 struct atmel_uart_data *data = pdev->dev.platform_data;
704 data->regs = (void __iomem *)pdev->resource[0].start;
708 at32_usarts[line] = pdev;
711 struct platform_device *__init at32_add_device_usart(unsigned int id)
713 platform_device_register(at32_usarts[id]);
714 return at32_usarts[id];
717 struct platform_device *atmel_default_console_device;
719 void __init at32_setup_serial_console(unsigned int usart_id)
721 atmel_default_console_device = at32_usarts[usart_id];
724 /* --------------------------------------------------------------------
726 * -------------------------------------------------------------------- */
728 static struct eth_platform_data macb0_data;
729 static struct resource macb0_resource[] = {
733 DEFINE_DEV_DATA(macb, 0);
734 DEV_CLK(hclk, macb0, hsb, 8);
735 DEV_CLK(pclk, macb0, pbb, 6);
737 static struct eth_platform_data macb1_data;
738 static struct resource macb1_resource[] = {
742 DEFINE_DEV_DATA(macb, 1);
743 DEV_CLK(hclk, macb1, hsb, 9);
744 DEV_CLK(pclk, macb1, pbb, 7);
746 struct platform_device *__init
747 at32_add_device_eth(unsigned int id, struct eth_platform_data *data)
749 struct platform_device *pdev;
753 pdev = &macb0_device;
755 select_peripheral(PC(3), PERIPH_A, 0); /* TXD0 */
756 select_peripheral(PC(4), PERIPH_A, 0); /* TXD1 */
757 select_peripheral(PC(7), PERIPH_A, 0); /* TXEN */
758 select_peripheral(PC(8), PERIPH_A, 0); /* TXCK */
759 select_peripheral(PC(9), PERIPH_A, 0); /* RXD0 */
760 select_peripheral(PC(10), PERIPH_A, 0); /* RXD1 */
761 select_peripheral(PC(13), PERIPH_A, 0); /* RXER */
762 select_peripheral(PC(15), PERIPH_A, 0); /* RXDV */
763 select_peripheral(PC(16), PERIPH_A, 0); /* MDC */
764 select_peripheral(PC(17), PERIPH_A, 0); /* MDIO */
766 if (!data->is_rmii) {
767 select_peripheral(PC(0), PERIPH_A, 0); /* COL */
768 select_peripheral(PC(1), PERIPH_A, 0); /* CRS */
769 select_peripheral(PC(2), PERIPH_A, 0); /* TXER */
770 select_peripheral(PC(5), PERIPH_A, 0); /* TXD2 */
771 select_peripheral(PC(6), PERIPH_A, 0); /* TXD3 */
772 select_peripheral(PC(11), PERIPH_A, 0); /* RXD2 */
773 select_peripheral(PC(12), PERIPH_A, 0); /* RXD3 */
774 select_peripheral(PC(14), PERIPH_A, 0); /* RXCK */
775 select_peripheral(PC(18), PERIPH_A, 0); /* SPD */
780 pdev = &macb1_device;
782 select_peripheral(PD(13), PERIPH_B, 0); /* TXD0 */
783 select_peripheral(PD(14), PERIPH_B, 0); /* TXD1 */
784 select_peripheral(PD(11), PERIPH_B, 0); /* TXEN */
785 select_peripheral(PD(12), PERIPH_B, 0); /* TXCK */
786 select_peripheral(PD(10), PERIPH_B, 0); /* RXD0 */
787 select_peripheral(PD(6), PERIPH_B, 0); /* RXD1 */
788 select_peripheral(PD(5), PERIPH_B, 0); /* RXER */
789 select_peripheral(PD(4), PERIPH_B, 0); /* RXDV */
790 select_peripheral(PD(3), PERIPH_B, 0); /* MDC */
791 select_peripheral(PD(2), PERIPH_B, 0); /* MDIO */
793 if (!data->is_rmii) {
794 select_peripheral(PC(19), PERIPH_B, 0); /* COL */
795 select_peripheral(PC(23), PERIPH_B, 0); /* CRS */
796 select_peripheral(PC(26), PERIPH_B, 0); /* TXER */
797 select_peripheral(PC(27), PERIPH_B, 0); /* TXD2 */
798 select_peripheral(PC(28), PERIPH_B, 0); /* TXD3 */
799 select_peripheral(PC(29), PERIPH_B, 0); /* RXD2 */
800 select_peripheral(PC(30), PERIPH_B, 0); /* RXD3 */
801 select_peripheral(PC(24), PERIPH_B, 0); /* RXCK */
802 select_peripheral(PD(15), PERIPH_B, 0); /* SPD */
810 memcpy(pdev->dev.platform_data, data, sizeof(struct eth_platform_data));
811 platform_device_register(pdev);
816 /* --------------------------------------------------------------------
818 * -------------------------------------------------------------------- */
819 static struct resource atmel_spi0_resource[] = {
823 DEFINE_DEV(atmel_spi, 0);
824 DEV_CLK(spi_clk, atmel_spi0, pba, 0);
826 static struct resource atmel_spi1_resource[] = {
830 DEFINE_DEV(atmel_spi, 1);
831 DEV_CLK(spi_clk, atmel_spi1, pba, 1);
834 at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b,
835 unsigned int n, const u8 *pins)
837 unsigned int pin, mode;
839 for (; n; n--, b++) {
840 b->bus_num = bus_num;
841 if (b->chip_select >= 4)
843 pin = (unsigned)b->controller_data;
845 pin = pins[b->chip_select];
846 b->controller_data = (void *)pin;
848 mode = AT32_GPIOF_OUTPUT;
849 if (!(b->mode & SPI_CS_HIGH))
850 mode |= AT32_GPIOF_HIGH;
851 at32_select_gpio(pin, mode);
855 struct platform_device *__init
856 at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
859 * Manage the chipselects as GPIOs, normally using the same pins
860 * the SPI controller expects; but boards can use other pins.
862 static u8 __initdata spi0_pins[] =
863 { GPIO_PIN_PA(3), GPIO_PIN_PA(4),
864 GPIO_PIN_PA(5), GPIO_PIN_PA(20), };
865 static u8 __initdata spi1_pins[] =
866 { GPIO_PIN_PB(2), GPIO_PIN_PB(3),
867 GPIO_PIN_PB(4), GPIO_PIN_PA(27), };
868 struct platform_device *pdev;
872 pdev = &atmel_spi0_device;
873 select_peripheral(PA(0), PERIPH_A, 0); /* MISO */
874 select_peripheral(PA(1), PERIPH_A, 0); /* MOSI */
875 select_peripheral(PA(2), PERIPH_A, 0); /* SCK */
876 at32_spi_setup_slaves(0, b, n, spi0_pins);
880 pdev = &atmel_spi1_device;
881 select_peripheral(PB(0), PERIPH_B, 0); /* MISO */
882 select_peripheral(PB(1), PERIPH_B, 0); /* MOSI */
883 select_peripheral(PB(5), PERIPH_B, 0); /* SCK */
884 at32_spi_setup_slaves(1, b, n, spi1_pins);
891 spi_register_board_info(b, n);
892 platform_device_register(pdev);
896 /* --------------------------------------------------------------------
898 * -------------------------------------------------------------------- */
899 static struct atmel_lcdfb_info atmel_lcdfb0_data;
900 static struct resource atmel_lcdfb0_resource[] = {
904 .flags = IORESOURCE_MEM,
908 /* Placeholder for pre-allocated fb memory */
914 DEFINE_DEV_DATA(atmel_lcdfb, 0);
915 DEV_CLK(hck1, atmel_lcdfb0, hsb, 7);
916 static struct clk atmel_lcdfb0_pixclk = {
918 .dev = &atmel_lcdfb0_device.dev,
920 .get_rate = genclk_get_rate,
921 .set_rate = genclk_set_rate,
922 .set_parent = genclk_set_parent,
926 struct platform_device *__init
927 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
928 unsigned long fbmem_start, unsigned long fbmem_len)
930 struct platform_device *pdev;
931 struct atmel_lcdfb_info *info;
932 struct fb_monspecs *monspecs;
933 struct fb_videomode *modedb;
934 unsigned int modedb_size;
937 * Do a deep copy of the fb data, monspecs and modedb. Make
938 * sure all allocations are done before setting up the
941 monspecs = kmemdup(data->default_monspecs,
942 sizeof(struct fb_monspecs), GFP_KERNEL);
946 modedb_size = sizeof(struct fb_videomode) * monspecs->modedb_len;
947 modedb = kmemdup(monspecs->modedb, modedb_size, GFP_KERNEL);
950 monspecs->modedb = modedb;
954 pdev = &atmel_lcdfb0_device;
955 select_peripheral(PC(19), PERIPH_A, 0); /* CC */
956 select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC */
957 select_peripheral(PC(21), PERIPH_A, 0); /* PCLK */
958 select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC */
959 select_peripheral(PC(23), PERIPH_A, 0); /* DVAL */
960 select_peripheral(PC(24), PERIPH_A, 0); /* MODE */
961 select_peripheral(PC(25), PERIPH_A, 0); /* PWR */
962 select_peripheral(PC(26), PERIPH_A, 0); /* DATA0 */
963 select_peripheral(PC(27), PERIPH_A, 0); /* DATA1 */
964 select_peripheral(PC(28), PERIPH_A, 0); /* DATA2 */
965 select_peripheral(PC(29), PERIPH_A, 0); /* DATA3 */
966 select_peripheral(PC(30), PERIPH_A, 0); /* DATA4 */
967 select_peripheral(PC(31), PERIPH_A, 0); /* DATA5 */
968 select_peripheral(PD(0), PERIPH_A, 0); /* DATA6 */
969 select_peripheral(PD(1), PERIPH_A, 0); /* DATA7 */
970 select_peripheral(PD(2), PERIPH_A, 0); /* DATA8 */
971 select_peripheral(PD(3), PERIPH_A, 0); /* DATA9 */
972 select_peripheral(PD(4), PERIPH_A, 0); /* DATA10 */
973 select_peripheral(PD(5), PERIPH_A, 0); /* DATA11 */
974 select_peripheral(PD(6), PERIPH_A, 0); /* DATA12 */
975 select_peripheral(PD(7), PERIPH_A, 0); /* DATA13 */
976 select_peripheral(PD(8), PERIPH_A, 0); /* DATA14 */
977 select_peripheral(PD(9), PERIPH_A, 0); /* DATA15 */
978 select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */
979 select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */
980 select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */
981 select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */
982 select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */
983 select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */
984 select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
985 select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
987 clk_set_parent(&atmel_lcdfb0_pixclk, &pll0);
988 clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0));
996 pdev->resource[2].start = fbmem_start;
997 pdev->resource[2].end = fbmem_start + fbmem_len - 1;
998 pdev->resource[2].flags = IORESOURCE_MEM;
1001 info = pdev->dev.platform_data;
1002 memcpy(info, data, sizeof(struct atmel_lcdfb_info));
1003 info->default_monspecs = monspecs;
1005 platform_device_register(pdev);
1015 /* --------------------------------------------------------------------
1017 * -------------------------------------------------------------------- */
1018 static struct clk gclk0 = {
1020 .mode = genclk_mode,
1021 .get_rate = genclk_get_rate,
1022 .set_rate = genclk_set_rate,
1023 .set_parent = genclk_set_parent,
1026 static struct clk gclk1 = {
1028 .mode = genclk_mode,
1029 .get_rate = genclk_get_rate,
1030 .set_rate = genclk_set_rate,
1031 .set_parent = genclk_set_parent,
1034 static struct clk gclk2 = {
1036 .mode = genclk_mode,
1037 .get_rate = genclk_get_rate,
1038 .set_rate = genclk_set_rate,
1039 .set_parent = genclk_set_parent,
1042 static struct clk gclk3 = {
1044 .mode = genclk_mode,
1045 .get_rate = genclk_get_rate,
1046 .set_rate = genclk_set_rate,
1047 .set_parent = genclk_set_parent,
1050 static struct clk gclk4 = {
1052 .mode = genclk_mode,
1053 .get_rate = genclk_get_rate,
1054 .set_rate = genclk_set_rate,
1055 .set_parent = genclk_set_parent,
1059 struct clk *at32_clock_list[] = {
1085 &atmel_usart0_usart,
1086 &atmel_usart1_usart,
1087 &atmel_usart2_usart,
1088 &atmel_usart3_usart,
1093 &atmel_spi0_spi_clk,
1094 &atmel_spi1_spi_clk,
1096 &atmel_lcdfb0_pixclk,
1103 unsigned int at32_nr_clocks = ARRAY_SIZE(at32_clock_list);
1105 void __init at32_portmux_init(void)
1107 at32_init_pio(&pio0_device);
1108 at32_init_pio(&pio1_device);
1109 at32_init_pio(&pio2_device);
1110 at32_init_pio(&pio3_device);
1111 at32_init_pio(&pio4_device);
1114 void __init at32_clock_init(void)
1116 struct at32_sm *sm = &system_manager;
1117 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
1120 if (sm_readl(sm, PM_MCCTRL) & SM_BIT(PLLSEL))
1125 if (sm_readl(sm, PM_PLL0) & SM_BIT(PLLOSC))
1126 pll0.parent = &osc1;
1127 if (sm_readl(sm, PM_PLL1) & SM_BIT(PLLOSC))
1128 pll1.parent = &osc1;
1130 genclk_init_parent(&gclk0);
1131 genclk_init_parent(&gclk1);
1132 genclk_init_parent(&gclk2);
1133 genclk_init_parent(&gclk3);
1134 genclk_init_parent(&gclk4);
1135 genclk_init_parent(&atmel_lcdfb0_pixclk);
1138 * Turn on all clocks that have at least one user already, and
1139 * turn off everything else. We only do this for module
1140 * clocks, and even though it isn't particularly pretty to
1141 * check the address of the mode function, it should do the
1144 for (i = 0; i < ARRAY_SIZE(at32_clock_list); i++) {
1145 struct clk *clk = at32_clock_list[i];
1147 if (clk->users == 0)
1150 if (clk->mode == &cpu_clk_mode)
1151 cpu_mask |= 1 << clk->index;
1152 else if (clk->mode == &hsb_clk_mode)
1153 hsb_mask |= 1 << clk->index;
1154 else if (clk->mode == &pba_clk_mode)
1155 pba_mask |= 1 << clk->index;
1156 else if (clk->mode == &pbb_clk_mode)
1157 pbb_mask |= 1 << clk->index;
1160 sm_writel(sm, PM_CPU_MASK, cpu_mask);
1161 sm_writel(sm, PM_HSB_MASK, hsb_mask);
1162 sm_writel(sm, PM_PBA_MASK, pba_mask);
1163 sm_writel(sm, PM_PBB_MASK, pbb_mask);