Path: blob/master/arch/avr32/boards/mimc200/setup.c
10819 views
/*1* Board-specific setup code for the MIMC2002*3* Copyright (C) 2008 Mercury IMC Ltd4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*/910extern struct atmel_lcdfb_info mimc200_lcdc_data;1112#include <linux/clk.h>13#include <linux/etherdevice.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/leds.h>20#include <linux/spi/spi.h>21#include <linux/spi/eeprom.h>2223#include <video/atmel_lcdc.h>24#include <linux/fb.h>2526#include <linux/atmel-mci.h>27#include <linux/io.h>28#include <asm/setup.h>2930#include <mach/at32ap700x.h>31#include <mach/board.h>32#include <mach/init.h>33#include <mach/portmux.h>3435/* Oscillator frequencies. These are board-specific */36unsigned long at32_board_osc_rates[3] = {37[0] = 32768, /* 32.768 kHz on RTC osc */38[1] = 10000000, /* 10 MHz on osc0 */39[2] = 12000000, /* 12 MHz on osc1 */40};4142/* Initialized by bootloader-specific startup code. */43struct tag *bootloader_tags __initdata;4445static struct fb_videomode __initdata pt0434827_modes[] = {46{47.name = "480x272 @ 72",48.refresh = 72,49.xres = 480, .yres = 272,50.pixclock = KHZ2PICOS(10000),5152.left_margin = 1, .right_margin = 1,53.upper_margin = 12, .lower_margin = 1,54.hsync_len = 42, .vsync_len = 1,5556.sync = 0,57.vmode = FB_VMODE_NONINTERLACED,58},59};6061static struct fb_monspecs __initdata mimc200_default_monspecs = {62.manufacturer = "PT",63.monitor = "PT0434827-A401",64.modedb = pt0434827_modes,65.modedb_len = ARRAY_SIZE(pt0434827_modes),66.hfmin = 14820,67.hfmax = 22230,68.vfmin = 60,69.vfmax = 85,70.dclkmax = 25200000,71};7273struct atmel_lcdfb_info __initdata mimc200_lcdc_data = {74.default_bpp = 16,75.default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,76.default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT77| ATMEL_LCDC_INVCLK78| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE79| ATMEL_LCDC_MEMOR_BIG),80.default_monspecs = &mimc200_default_monspecs,81.guard_time = 2,82};8384struct eth_addr {85u8 addr[6];86};87static struct eth_addr __initdata hw_addr[2];88static struct eth_platform_data __initdata eth_data[2];8990static struct spi_eeprom eeprom_25lc010 = {91.name = "25lc010",92.byte_len = 128,93.page_size = 16,94.flags = EE_ADDR1,95};9697static struct spi_board_info spi0_board_info[] __initdata = {98{99.modalias = "rtc-ds1390",100.max_speed_hz = 4000000,101.chip_select = 2,102},103{104.modalias = "at25",105.max_speed_hz = 1000000,106.chip_select = 1,107.mode = SPI_MODE_3,108.platform_data = &eeprom_25lc010,109},110};111112static struct mci_platform_data __initdata mci0_data = {113.slot[0] = {114.bus_width = 4,115.detect_pin = GPIO_PIN_PA(26),116.wp_pin = GPIO_PIN_PA(27),117},118};119120/*121* The next two functions should go away as the boot loader is122* supposed to initialize the macb address registers with a valid123* ethernet address. But we need to keep it around for a while until124* we can be reasonably sure the boot loader does this.125*126* The phy_id is ignored as the driver will probe for it.127*/128static int __init parse_tag_ethernet(struct tag *tag)129{130int i;131132i = tag->u.ethernet.mac_index;133if (i < ARRAY_SIZE(hw_addr))134memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,135sizeof(hw_addr[i].addr));136137return 0;138}139__tagtable(ATAG_ETHERNET, parse_tag_ethernet);140141static void __init set_hw_addr(struct platform_device *pdev)142{143struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);144const u8 *addr;145void __iomem *regs;146struct clk *pclk;147148if (!res)149return;150if (pdev->id >= ARRAY_SIZE(hw_addr))151return;152153addr = hw_addr[pdev->id].addr;154if (!is_valid_ether_addr(addr))155return;156157/*158* Since this is board-specific code, we'll cheat and use the159* physical address directly as we happen to know that it's160* the same as the virtual address.161*/162regs = (void __iomem __force *)res->start;163pclk = clk_get(&pdev->dev, "pclk");164if (IS_ERR(pclk))165return;166167clk_enable(pclk);168__raw_writel((addr[3] << 24) | (addr[2] << 16)169| (addr[1] << 8) | addr[0], regs + 0x98);170__raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);171clk_disable(pclk);172clk_put(pclk);173}174175void __init setup_board(void)176{177at32_map_usart(0, 0, 0); /* USART 0: /dev/ttyS0 (TTL --> Altera) */178at32_map_usart(1, 1, 0); /* USART 1: /dev/ttyS1 (RS232) */179at32_map_usart(2, 2, 0); /* USART 2: /dev/ttyS2 (RS485) */180at32_map_usart(3, 3, 0); /* USART 3: /dev/ttyS3 (RS422 Multidrop) */181}182183static struct i2c_gpio_platform_data i2c_gpio_data = {184.sda_pin = GPIO_PIN_PA(6),185.scl_pin = GPIO_PIN_PA(7),186.sda_is_open_drain = 1,187.scl_is_open_drain = 1,188.udelay = 2, /* close to 100 kHz */189};190191static struct platform_device i2c_gpio_device = {192.name = "i2c-gpio",193.id = 0,194.dev = {195.platform_data = &i2c_gpio_data,196},197};198199static struct i2c_board_info __initdata i2c_info[] = {200};201202static int __init mimc200_init(void)203{204/*205* MIMC200 uses 16-bit SDRAM interface, so we don't need to206* reserve any pins for it.207*/208209at32_add_device_usart(0);210at32_add_device_usart(1);211at32_add_device_usart(2);212at32_add_device_usart(3);213214set_hw_addr(at32_add_device_eth(0, ð_data[0]));215set_hw_addr(at32_add_device_eth(1, ð_data[1]));216217at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));218at32_add_device_mci(0, &mci0_data);219at32_add_device_usba(0, NULL);220221at32_select_periph(GPIO_PIOB_BASE, 1 << 28, 0, AT32_GPIOF_PULLUP);222at32_select_gpio(i2c_gpio_data.sda_pin,223AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);224at32_select_gpio(i2c_gpio_data.scl_pin,225AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);226platform_device_register(&i2c_gpio_device);227i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));228229at32_add_device_lcdc(0, &mimc200_lcdc_data,230fbmem_start, fbmem_size,231ATMEL_LCDC_CONTROL | ATMEL_LCDC_ALT_CONTROL | ATMEL_LCDC_ALT_24B_DATA);232233return 0;234}235postcore_initcall(mimc200_init);236237238