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