Merge commit 'v2.6.26' into sched/devel
[pandora-kernel.git] / arch / avr32 / boards / atstk1000 / atstk1004.c
1 /*
2  * ATSTK1003 daughterboard-specific init code
3  *
4  * Copyright (C) 2007 Atmel Corporation
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 #include <linux/clk.h>
11 #include <linux/err.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/platform_device.h>
15 #include <linux/string.h>
16 #include <linux/types.h>
17
18 #include <linux/spi/at73c213.h>
19 #include <linux/spi/spi.h>
20
21 #include <video/atmel_lcdc.h>
22
23 #include <asm/setup.h>
24
25 #include <asm/arch/at32ap700x.h>
26 #include <asm/arch/board.h>
27 #include <asm/arch/init.h>
28 #include <asm/arch/portmux.h>
29
30 #include "atstk1000.h"
31
32 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
33 static struct at73c213_board_info at73c213_data = {
34         .ssc_id         = 0,
35         .shortname      = "AVR32 STK1000 external DAC",
36 };
37 #endif
38
39 #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
40 static struct spi_board_info spi0_board_info[] __initdata = {
41 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
42         {
43                 /* AT73C213 */
44                 .modalias       = "at73c213",
45                 .max_speed_hz   = 200000,
46                 .chip_select    = 0,
47                 .mode           = SPI_MODE_1,
48                 .platform_data  = &at73c213_data,
49         },
50 #endif
51         {
52                 /* QVGA display */
53                 .modalias       = "ltv350qv",
54                 .max_speed_hz   = 16000000,
55                 .chip_select    = 1,
56                 .mode           = SPI_MODE_3,
57         },
58 };
59 #endif
60
61 #ifdef CONFIG_BOARD_ATSTK100X_SPI1
62 static struct spi_board_info spi1_board_info[] __initdata = { {
63         /* patch in custom entries here */
64 } };
65 #endif
66
67 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
68 static void __init atstk1004_setup_extdac(void)
69 {
70         struct clk *gclk;
71         struct clk *pll;
72
73         gclk = clk_get(NULL, "gclk0");
74         if (IS_ERR(gclk))
75                 goto err_gclk;
76         pll = clk_get(NULL, "pll0");
77         if (IS_ERR(pll))
78                 goto err_pll;
79
80         if (clk_set_parent(gclk, pll)) {
81                 pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
82                 goto err_set_clk;
83         }
84
85         at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
86         at73c213_data.dac_clk = gclk;
87
88 err_set_clk:
89         clk_put(pll);
90 err_pll:
91         clk_put(gclk);
92 err_gclk:
93         return;
94 }
95 #else
96 static void __init atstk1004_setup_extdac(void)
97 {
98
99 }
100 #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */
101
102 void __init setup_board(void)
103 {
104 #ifdef  CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
105         at32_map_usart(0, 1);   /* USART 0/B: /dev/ttyS1, IRDA */
106 #else
107         at32_map_usart(1, 0);   /* USART 1/A: /dev/ttyS0, DB9 */
108 #endif
109         /* USART 2/unused: expansion connector */
110         at32_map_usart(3, 2);   /* USART 3/C: /dev/ttyS2, DB9 */
111
112         at32_setup_serial_console(0);
113 }
114
115 static int __init atstk1004_init(void)
116 {
117         at32_add_system_devices();
118
119 #ifdef  CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
120         at32_add_device_usart(1);
121 #else
122         at32_add_device_usart(0);
123 #endif
124         at32_add_device_usart(2);
125
126 #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
127         at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
128 #endif
129 #ifdef CONFIG_BOARD_ATSTK100X_SPI1
130         at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
131 #endif
132 #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
133         at32_add_device_mci(0);
134 #endif
135         at32_add_device_lcdc(0, &atstk1000_lcdc_data,
136                              fbmem_start, fbmem_size);
137         at32_add_device_usba(0, NULL);
138 #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
139         at32_add_device_ssc(0, ATMEL_SSC_TX);
140 #endif
141
142         atstk1000_setup_j2_leds();
143         atstk1004_setup_extdac();
144
145         return 0;
146 }
147 postcore_initcall(atstk1004_init);