Merge branch 'bkl-removal' of git://git.lwn.net/linux-2.6
[linux-2.6] / arch / avr32 / boards / hammerhead / setup.c
1 /*
2  * Board-specific setup code for the Miromico Hammerhead board
3  *
4  * Copyright (C) 2008 Miromico AG
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/atmel-mci.h>
11 #include <linux/clk.h>
12 #include <linux/fb.h>
13 #include <linux/etherdevice.h>
14 #include <linux/i2c.h>
15 #include <linux/i2c-gpio.h>
16 #include <linux/init.h>
17 #include <linux/linkage.h>
18 #include <linux/platform_device.h>
19 #include <linux/types.h>
20 #include <linux/spi/spi.h>
21
22 #include <video/atmel_lcdc.h>
23
24 #include <linux/io.h>
25 #include <asm/setup.h>
26
27 #include <mach/at32ap700x.h>
28 #include <mach/board.h>
29 #include <mach/init.h>
30 #include <mach/portmux.h>
31
32 #include "../../mach-at32ap/clock.h"
33 #include "flash.h"
34
35 /* Oscillator frequencies. These are board-specific */
36 unsigned long at32_board_osc_rates[3] = {
37         [0] = 32768,    /* 32.768 kHz on RTC osc */
38         [1] = 25000000, /* 25MHz on osc0 */
39         [2] = 12000000, /* 12 MHz on osc1 */
40 };
41
42 /* Initialized by bootloader-specific startup code. */
43 struct tag *bootloader_tags __initdata;
44
45 #ifdef CONFIG_BOARD_HAMMERHEAD_LCD
46 static struct fb_videomode __initdata hda350tlv_modes[] = {
47         {
48                 .name           = "320x240 @ 75",
49                 .refresh        = 75,
50                 .xres           = 320,
51                 .yres           = 240,
52                 .pixclock       = KHZ2PICOS(6891),
53
54                 .left_margin    = 48,
55                 .right_margin   = 18,
56                 .upper_margin   = 18,
57                 .lower_margin   = 4,
58                 .hsync_len      = 20,
59                 .vsync_len      = 2,
60
61                 .sync           = 0,
62                 .vmode          = FB_VMODE_NONINTERLACED,
63         },
64 };
65
66 static struct fb_monspecs __initdata hammerhead_hda350t_monspecs = {
67         .manufacturer           = "HAN",
68         .monitor                = "HDA350T-LV",
69         .modedb                 = hda350tlv_modes,
70         .modedb_len             = ARRAY_SIZE(hda350tlv_modes),
71         .hfmin                  = 14900,
72         .hfmax                  = 22350,
73         .vfmin                  = 60,
74         .vfmax                  = 90,
75         .dclkmax                = 10000000,
76 };
77
78 struct atmel_lcdfb_info __initdata hammerhead_lcdc_data = {
79         .default_bpp            = 24,
80         .default_dmacon         = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
81         .default_lcdcon2        = (ATMEL_LCDC_DISTYPE_TFT
82                                    | ATMEL_LCDC_INVCLK
83                                    | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
84                                    | ATMEL_LCDC_MEMOR_BIG),
85         .default_monspecs       = &hammerhead_hda350t_monspecs,
86         .guard_time             = 2,
87 };
88 #endif
89
90 static struct mci_platform_data __initdata mci0_data = {
91         .slot[0] = {
92                 .bus_width      = 4,
93                 .detect_pin     = -ENODEV,
94                 .wp_pin         = -ENODEV,
95         },
96 };
97
98 struct eth_addr {
99         u8 addr[6];
100 };
101
102 static struct eth_addr __initdata hw_addr[1];
103 static struct eth_platform_data __initdata eth_data[1];
104
105 /*
106  * The next two functions should go away as the boot loader is
107  * supposed to initialize the macb address registers with a valid
108  * ethernet address. But we need to keep it around for a while until
109  * we can be reasonably sure the boot loader does this.
110  *
111  * The phy_id is ignored as the driver will probe for it.
112  */
113 static int __init parse_tag_ethernet(struct tag *tag)
114 {
115         int i = tag->u.ethernet.mac_index;
116
117         if (i < ARRAY_SIZE(hw_addr))
118                 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
119                        sizeof(hw_addr[i].addr));
120
121         return 0;
122 }
123 __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
124
125 static void __init set_hw_addr(struct platform_device *pdev)
126 {
127         struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
128         const u8 *addr;
129         void __iomem *regs;
130         struct clk *pclk;
131
132         if (!res)
133                 return;
134
135         if (pdev->id >= ARRAY_SIZE(hw_addr))
136                 return;
137
138         addr = hw_addr[pdev->id].addr;
139
140         if (!is_valid_ether_addr(addr))
141                 return;
142
143         /*
144          * Since this is board-specific code, we'll cheat and use the
145          * physical address directly as we happen to know that it's
146          * the same as the virtual address.
147          */
148         regs = (void __iomem __force *)res->start;
149         pclk = clk_get(&pdev->dev, "pclk");
150
151         if (!pclk)
152                 return;
153
154         clk_enable(pclk);
155
156         __raw_writel((addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) |
157                      addr[0], regs + 0x98);
158         __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
159
160         clk_disable(pclk);
161         clk_put(pclk);
162 }
163
164 void __init setup_board(void)
165 {
166         at32_map_usart(1, 0);   /* USART 1: /dev/ttyS0, DB9 */
167         at32_setup_serial_console(0);
168 }
169
170 static struct i2c_gpio_platform_data i2c_gpio_data = {
171         .sda_pin                = GPIO_PIN_PA(6),
172         .scl_pin                = GPIO_PIN_PA(7),
173         .sda_is_open_drain      = 1,
174         .scl_is_open_drain      = 1,
175         .udelay                 = 2,    /* close to 100 kHz */
176 };
177
178 static struct platform_device i2c_gpio_device = {
179         .name           = "i2c-gpio",
180         .id             = 0,
181         .dev            = { .platform_data = &i2c_gpio_data, },
182 };
183
184 static struct i2c_board_info __initdata i2c_info[] = {};
185
186 #ifdef CONFIG_BOARD_HAMMERHEAD_SND
187 static struct ac97c_platform_data ac97c_data = {
188         .reset_pin = GPIO_PIN_PA(16),
189 };
190 #endif
191
192 static int __init hammerhead_init(void)
193 {
194         /*
195          * Hammerhead uses 32-bit SDRAM interface. Reserve the
196          * SDRAM-specific pins so that nobody messes with them.
197          */
198         at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
199
200         at32_add_device_usart(0);
201
202         /* Reserve PB29 (GCLK3). This pin is used as clock source
203          * for ETH PHY (25MHz). GCLK3 setup is done by U-Boot.
204          */
205         at32_reserve_pin(GPIO_PIOB_BASE, (1<<29));
206
207         /*
208          * Hammerhead uses only one ethernet port, so we don't set
209          * address of second port
210          */
211         set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
212
213 #ifdef CONFIG_BOARD_HAMMERHEAD_FPGA
214         at32_add_device_hh_fpga();
215 #endif
216         at32_add_device_mci(0, &mci0_data);
217
218 #ifdef CONFIG_BOARD_HAMMERHEAD_USB
219         at32_add_device_usba(0, NULL);
220 #endif
221 #ifdef CONFIG_BOARD_HAMMERHEAD_LCD
222         at32_add_device_lcdc(0, &hammerhead_lcdc_data, fbmem_start,
223                              fbmem_size, ATMEL_LCDC_PRI_24BIT);
224 #endif
225
226         at32_select_gpio(i2c_gpio_data.sda_pin,
227                          AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT |
228                          AT32_GPIOF_HIGH);
229         at32_select_gpio(i2c_gpio_data.scl_pin,
230                          AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT |
231                          AT32_GPIOF_HIGH);
232         platform_device_register(&i2c_gpio_device);
233         i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
234
235 #ifdef CONFIG_BOARD_HAMMERHEAD_SND
236         at32_add_device_ac97c(0, &ac97c_data);
237 #endif
238
239         /* Select the Touchscreen interrupt pin mode */
240         at32_select_periph(GPIO_PIOB_BASE, 0x08000000, GPIO_PERIPH_A, 0);
241
242         return 0;
243 }
244
245 postcore_initcall(hammerhead_init);