Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/hskinnemoen...
[linux-2.6] / 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 <mach/at32ap700x.h>
26 #include <mach/board.h>
27 #include <mach/init.h>
28 #include <mach/portmux.h>
29
30 #include "atstk1000.h"
31
32 /* Oscillator frequencies. These are board specific */
33 unsigned long at32_board_osc_rates[3] = {
34         [0] = 32768,    /* 32.768 kHz on RTC osc */
35         [1] = 20000000, /* 20 MHz on osc0 */
36         [2] = 12000000, /* 12 MHz on osc1 */
37 };
38
39 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
40 static struct at73c213_board_info at73c213_data = {
41         .ssc_id         = 0,
42         .shortname      = "AVR32 STK1000 external DAC",
43 };
44 #endif
45
46 #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
47 static struct spi_board_info spi0_board_info[] __initdata = {
48 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
49         {
50                 /* AT73C213 */
51                 .modalias       = "at73c213",
52                 .max_speed_hz   = 200000,
53                 .chip_select    = 0,
54                 .mode           = SPI_MODE_1,
55                 .platform_data  = &at73c213_data,
56         },
57 #endif
58         {
59                 /* QVGA display */
60                 .modalias       = "ltv350qv",
61                 .max_speed_hz   = 16000000,
62                 .chip_select    = 1,
63                 .mode           = SPI_MODE_3,
64         },
65 };
66 #endif
67
68 #ifdef CONFIG_BOARD_ATSTK100X_SPI1
69 static struct spi_board_info spi1_board_info[] __initdata = { {
70         /* patch in custom entries here */
71 } };
72 #endif
73
74 #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
75 static struct mci_platform_data __initdata mci0_data = {
76         .slot[0] = {
77                 .bus_width      = 4,
78                 .detect_pin     = -ENODEV,
79                 .wp_pin         = -ENODEV,
80         },
81 };
82 #endif
83
84 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
85 static void __init atstk1004_setup_extdac(void)
86 {
87         struct clk *gclk;
88         struct clk *pll;
89
90         gclk = clk_get(NULL, "gclk0");
91         if (IS_ERR(gclk))
92                 goto err_gclk;
93         pll = clk_get(NULL, "pll0");
94         if (IS_ERR(pll))
95                 goto err_pll;
96
97         if (clk_set_parent(gclk, pll)) {
98                 pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
99                 goto err_set_clk;
100         }
101
102         at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
103         at73c213_data.dac_clk = gclk;
104
105 err_set_clk:
106         clk_put(pll);
107 err_pll:
108         clk_put(gclk);
109 err_gclk:
110         return;
111 }
112 #else
113 static void __init atstk1004_setup_extdac(void)
114 {
115
116 }
117 #endif /* CONFIG_BOARD_ATSTK1000_EXTDAC */
118
119 void __init setup_board(void)
120 {
121 #ifdef  CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
122         at32_map_usart(0, 1);   /* USART 0/B: /dev/ttyS1, IRDA */
123 #else
124         at32_map_usart(1, 0);   /* USART 1/A: /dev/ttyS0, DB9 */
125 #endif
126         /* USART 2/unused: expansion connector */
127         at32_map_usart(3, 2);   /* USART 3/C: /dev/ttyS2, DB9 */
128
129         at32_setup_serial_console(0);
130 }
131
132 static int __init atstk1004_init(void)
133 {
134         at32_add_system_devices();
135
136 #ifdef  CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
137         at32_add_device_usart(1);
138 #else
139         at32_add_device_usart(0);
140 #endif
141         at32_add_device_usart(2);
142
143 #ifndef CONFIG_BOARD_ATSTK100X_SW1_CUSTOM
144         at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
145 #endif
146 #ifdef CONFIG_BOARD_ATSTK100X_SPI1
147         at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
148 #endif
149 #ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
150         at32_add_device_mci(0, &mci0_data);
151 #endif
152         at32_add_device_lcdc(0, &atstk1000_lcdc_data,
153                              fbmem_start, fbmem_size,
154                              ATMEL_LCDC_PRI_24BIT | ATMEL_LCDC_PRI_CONTROL);
155         at32_add_device_usba(0, NULL);
156 #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
157         at32_add_device_ssc(0, ATMEL_SSC_TX);
158 #endif
159
160         atstk1000_setup_j2_leds();
161         atstk1004_setup_extdac();
162
163         return 0;
164 }
165 postcore_initcall(atstk1004_init);