Merge branch 'devel' into next
[linux-2.6] / arch / avr32 / boards / atstk1000 / atstk1003.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 <asm/setup.h>
22
23 #include <asm/arch/at32ap700x.h>
24 #include <asm/arch/board.h>
25 #include <asm/arch/init.h>
26 #include <asm/arch/portmux.h>
27
28 #include "atstk1000.h"
29
30 /* Oscillator frequencies. These are board specific */
31 unsigned long at32_board_osc_rates[3] = {
32         [0] = 32768,    /* 32.768 kHz on RTC osc */
33         [1] = 20000000, /* 20 MHz on osc0 */
34         [2] = 12000000, /* 12 MHz on osc1 */
35 };
36
37 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
38 static struct at73c213_board_info at73c213_data = {
39         .ssc_id         = 0,
40         .shortname      = "AVR32 STK1000 external DAC",
41 };
42 #endif
43
44 #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
45 static struct spi_board_info spi0_board_info[] __initdata = {
46 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
47         {
48                 /* AT73C213 */
49                 .modalias       = "at73c213",
50                 .max_speed_hz   = 200000,
51                 .chip_select    = 0,
52                 .mode           = SPI_MODE_1,
53                 .platform_data  = &at73c213_data,
54         },
55 #endif
56         /*
57          * We can control the LTV350QV LCD panel, but it isn't much
58          * point since we don't have an LCD controller...
59          */
60 };
61 #endif
62
63 #ifdef CONFIG_BOARD_ATSTK100X_SPI1
64 static struct spi_board_info spi1_board_info[] __initdata = { {
65         /* patch in custom entries here */
66 } };
67 #endif
68
69 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
70 static void __init atstk1003_setup_extdac(void)
71 {
72         struct clk *gclk;
73         struct clk *pll;
74
75         gclk = clk_get(NULL, "gclk0");
76         if (IS_ERR(gclk))
77                 goto err_gclk;
78         pll = clk_get(NULL, "pll0");
79         if (IS_ERR(pll))
80                 goto err_pll;
81
82         if (clk_set_parent(gclk, pll)) {
83                 pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
84                 goto err_set_clk;
85         }
86
87         at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
88         at73c213_data.dac_clk = gclk;
89
90 err_set_clk:
91         clk_put(pll);
92 err_pll:
93         clk_put(gclk);
94 err_gclk:
95         return;
96 }
97 #else
98 static void __init atstk1003_setup_extdac(void)
99 {
100
101 }
102 #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */
103
104 void __init setup_board(void)
105 {
106 #ifdef  CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
107         at32_map_usart(0, 1);   /* USART 0/B: /dev/ttyS1, IRDA */
108 #else
109         at32_map_usart(1, 0);   /* USART 1/A: /dev/ttyS0, DB9 */
110 #endif
111         /* USART 2/unused: expansion connector */
112         at32_map_usart(3, 2);   /* USART 3/C: /dev/ttyS2, DB9 */
113
114         at32_setup_serial_console(0);
115 }
116
117 static int __init atstk1003_init(void)
118 {
119         /*
120          * ATSTK1000 uses 32-bit SDRAM interface. Reserve the
121          * SDRAM-specific pins so that nobody messes with them.
122          */
123         at32_reserve_pin(GPIO_PIN_PE(0));       /* DATA[16]     */
124         at32_reserve_pin(GPIO_PIN_PE(1));       /* DATA[17]     */
125         at32_reserve_pin(GPIO_PIN_PE(2));       /* DATA[18]     */
126         at32_reserve_pin(GPIO_PIN_PE(3));       /* DATA[19]     */
127         at32_reserve_pin(GPIO_PIN_PE(4));       /* DATA[20]     */
128         at32_reserve_pin(GPIO_PIN_PE(5));       /* DATA[21]     */
129         at32_reserve_pin(GPIO_PIN_PE(6));       /* DATA[22]     */
130         at32_reserve_pin(GPIO_PIN_PE(7));       /* DATA[23]     */
131         at32_reserve_pin(GPIO_PIN_PE(8));       /* DATA[24]     */
132         at32_reserve_pin(GPIO_PIN_PE(9));       /* DATA[25]     */
133         at32_reserve_pin(GPIO_PIN_PE(10));      /* DATA[26]     */
134         at32_reserve_pin(GPIO_PIN_PE(11));      /* DATA[27]     */
135         at32_reserve_pin(GPIO_PIN_PE(12));      /* DATA[28]     */
136         at32_reserve_pin(GPIO_PIN_PE(13));      /* DATA[29]     */
137         at32_reserve_pin(GPIO_PIN_PE(14));      /* DATA[30]     */
138         at32_reserve_pin(GPIO_PIN_PE(15));      /* DATA[31]     */
139         at32_reserve_pin(GPIO_PIN_PE(26));      /* SDCS         */
140
141         at32_add_system_devices();
142
143 #ifdef  CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
144         at32_add_device_usart(1);
145 #else
146         at32_add_device_usart(0);
147 #endif
148         at32_add_device_usart(2);
149
150 #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
151         at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
152 #endif
153 #ifdef CONFIG_BOARD_ATSTK100X_SPI1
154         at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
155 #endif
156 #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
157         at32_add_device_mci(0);
158 #endif
159         at32_add_device_usba(0, NULL);
160 #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
161         at32_add_device_ssc(0, ATMEL_SSC_TX);
162 #endif
163
164         atstk1000_setup_j2_leds();
165         atstk1003_setup_extdac();
166
167         return 0;
168 }
169 postcore_initcall(atstk1003_init);