Path: blob/master/arch/avr32/boards/atngw100/setup.c
10819 views
/*1* Board-specific setup code for the ATNGW100 Network Gateway2*3* Copyright (C) 2005-2006 Atmel Corporation4*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*/9#include <linux/clk.h>10#include <linux/etherdevice.h>11#include <linux/gpio.h>12#include <linux/irq.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/leds.h>20#include <linux/spi/spi.h>21#include <linux/atmel-mci.h>22#include <linux/usb/atmel_usba_udc.h>2324#include <asm/io.h>25#include <asm/setup.h>2627#include <mach/at32ap700x.h>28#include <mach/board.h>29#include <mach/init.h>30#include <mach/portmux.h>3132/* Oscillator frequencies. These are board-specific */33unsigned 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};3839/*40* The ATNGW100 mkII is very similar to the ATNGW100. Both have the AT32AP700041* chip on board; the difference is that the ATNGW100 mkII has 128 MB 32-bit42* SDRAM (the ATNGW100 has 32 MB 16-bit SDRAM) and 256 MB 16-bit NAND flash43* (the ATNGW100 has none.)44*45* The RAM difference is handled by the boot loader, so the only difference we46* end up handling here is the NAND flash, EBI pin reservation and if LCDC or47* MACB1 should be enabled.48*/49#ifdef CONFIG_BOARD_ATNGW100_MKII50#include <linux/mtd/partitions.h>51#include <mach/smc.h>5253static struct smc_timing nand_timing __initdata = {54.ncs_read_setup = 0,55.nrd_setup = 10,56.ncs_write_setup = 0,57.nwe_setup = 10,5859.ncs_read_pulse = 30,60.nrd_pulse = 15,61.ncs_write_pulse = 30,62.nwe_pulse = 15,6364.read_cycle = 30,65.write_cycle = 30,6667.ncs_read_recover = 0,68.nrd_recover = 15,69.ncs_write_recover = 0,70/* WE# high -> RE# low min 60 ns */71.nwe_recover = 50,72};7374static struct smc_config nand_config __initdata = {75.bus_width = 2,76.nrd_controlled = 1,77.nwe_controlled = 1,78.nwait_mode = 0,79.byte_write = 0,80.tdf_cycles = 2,81.tdf_mode = 0,82};8384static struct mtd_partition nand_partitions[] = {85{86.name = "main",87.offset = 0x00000000,88.size = MTDPART_SIZ_FULL,89},90};9192static struct mtd_partition *nand_part_info(int size, int *num_partitions)93{94*num_partitions = ARRAY_SIZE(nand_partitions);95return nand_partitions;96}9798static struct atmel_nand_data atngw100mkii_nand_data __initdata = {99.cle = 21,100.ale = 22,101.rdy_pin = GPIO_PIN_PB(28),102.enable_pin = GPIO_PIN_PE(23),103.bus_width_16 = true,104.partition_info = nand_part_info,105};106#endif107108/* Initialized by bootloader-specific startup code. */109struct tag *bootloader_tags __initdata;110111struct eth_addr {112u8 addr[6];113};114static struct eth_addr __initdata hw_addr[2];115static struct eth_platform_data __initdata eth_data[2];116117static struct spi_board_info spi0_board_info[] __initdata = {118{119.modalias = "mtd_dataflash",120.max_speed_hz = 8000000,121.chip_select = 0,122},123};124125static struct mci_platform_data __initdata mci0_data = {126.slot[0] = {127.bus_width = 4,128#if defined(CONFIG_BOARD_ATNGW100_MKII)129.detect_pin = GPIO_PIN_PC(25),130.wp_pin = GPIO_PIN_PE(22),131#else132.detect_pin = GPIO_PIN_PC(25),133.wp_pin = GPIO_PIN_PE(0),134#endif135},136};137138static struct usba_platform_data atngw100_usba_data __initdata = {139#if defined(CONFIG_BOARD_ATNGW100_MKII)140.vbus_pin = GPIO_PIN_PE(26),141#else142.vbus_pin = -ENODEV,143#endif144};145146/*147* The next two functions should go away as the boot loader is148* supposed to initialize the macb address registers with a valid149* ethernet address. But we need to keep it around for a while until150* we can be reasonably sure the boot loader does this.151*152* The phy_id is ignored as the driver will probe for it.153*/154static int __init parse_tag_ethernet(struct tag *tag)155{156int i;157158i = tag->u.ethernet.mac_index;159if (i < ARRAY_SIZE(hw_addr))160memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,161sizeof(hw_addr[i].addr));162163return 0;164}165__tagtable(ATAG_ETHERNET, parse_tag_ethernet);166167static void __init set_hw_addr(struct platform_device *pdev)168{169struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);170const u8 *addr;171void __iomem *regs;172struct clk *pclk;173174if (!res)175return;176if (pdev->id >= ARRAY_SIZE(hw_addr))177return;178179addr = hw_addr[pdev->id].addr;180if (!is_valid_ether_addr(addr))181return;182183/*184* Since this is board-specific code, we'll cheat and use the185* physical address directly as we happen to know that it's186* the same as the virtual address.187*/188regs = (void __iomem __force *)res->start;189pclk = clk_get(&pdev->dev, "pclk");190if (IS_ERR(pclk))191return;192193clk_enable(pclk);194__raw_writel((addr[3] << 24) | (addr[2] << 16)195| (addr[1] << 8) | addr[0], regs + 0x98);196__raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);197clk_disable(pclk);198clk_put(pclk);199}200201void __init setup_board(void)202{203at32_map_usart(1, 0, 0); /* USART 1: /dev/ttyS0, DB9 */204at32_setup_serial_console(0);205}206207static const struct gpio_led ngw_leds[] = {208{ .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,209.default_trigger = "heartbeat",210},211{ .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },212{ .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },213};214215static const struct gpio_led_platform_data ngw_led_data = {216.num_leds = ARRAY_SIZE(ngw_leds),217.leds = (void *) ngw_leds,218};219220static struct platform_device ngw_gpio_leds = {221.name = "leds-gpio",222.id = -1,223.dev = {224.platform_data = (void *) &ngw_led_data,225}226};227228static struct i2c_gpio_platform_data i2c_gpio_data = {229.sda_pin = GPIO_PIN_PA(6),230.scl_pin = GPIO_PIN_PA(7),231.sda_is_open_drain = 1,232.scl_is_open_drain = 1,233.udelay = 2, /* close to 100 kHz */234};235236static struct platform_device i2c_gpio_device = {237.name = "i2c-gpio",238.id = 0,239.dev = {240.platform_data = &i2c_gpio_data,241},242};243244static struct i2c_board_info __initdata i2c_info[] = {245/* NOTE: original ATtiny24 firmware is at address 0x0b */246};247248static int __init atngw100_init(void)249{250unsigned i;251252/*253* ATNGW100 mkII uses 32-bit SDRAM interface. Reserve the254* SDRAM-specific pins so that nobody messes with them.255*/256#ifdef CONFIG_BOARD_ATNGW100_MKII257at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);258259smc_set_timing(&nand_config, &nand_timing);260smc_set_configuration(3, &nand_config);261at32_add_device_nand(0, &atngw100mkii_nand_data);262#endif263264at32_add_device_usart(0);265266set_hw_addr(at32_add_device_eth(0, ð_data[0]));267#ifndef CONFIG_BOARD_ATNGW100_MKII_LCD268set_hw_addr(at32_add_device_eth(1, ð_data[1]));269#endif270271at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));272at32_add_device_mci(0, &mci0_data);273at32_add_device_usba(0, &atngw100_usba_data);274275for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {276at32_select_gpio(ngw_leds[i].gpio,277AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);278}279platform_device_register(&ngw_gpio_leds);280281/* all these i2c/smbus pins should have external pullups for282* open-drain sharing among all I2C devices. SDA and SCL do;283* PB28/EXTINT3 (ATNGW100) and PE21 (ATNGW100 mkII) doesn't; it should284* be SMBALERT# (for PMBus), but it's not available off-board.285*/286#ifdef CONFIG_BOARD_ATNGW100_MKII287at32_select_periph(GPIO_PIOE_BASE, 1 << 21, 0, AT32_GPIOF_PULLUP);288#else289at32_select_periph(GPIO_PIOB_BASE, 1 << 28, 0, AT32_GPIOF_PULLUP);290#endif291at32_select_gpio(i2c_gpio_data.sda_pin,292AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);293at32_select_gpio(i2c_gpio_data.scl_pin,294AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);295platform_device_register(&i2c_gpio_device);296i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));297298return 0;299}300postcore_initcall(atngw100_init);301302static int __init atngw100_arch_init(void)303{304/* PB30 (ATNGW100) and PE30 (ATNGW100 mkII) is the otherwise unused305* jumper on the mainboard, with an external pullup; the jumper grounds306* it. Use it however you like, including letting U-Boot or Linux tweak307* boot sequences.308*/309#ifdef CONFIG_BOARD_ATNGW100_MKII310at32_select_gpio(GPIO_PIN_PE(30), 0);311gpio_request(GPIO_PIN_PE(30), "j15");312gpio_direction_input(GPIO_PIN_PE(30));313gpio_export(GPIO_PIN_PE(30), false);314#else315at32_select_gpio(GPIO_PIN_PB(30), 0);316gpio_request(GPIO_PIN_PB(30), "j15");317gpio_direction_input(GPIO_PIN_PB(30));318gpio_export(GPIO_PIN_PB(30), false);319#endif320321/* set_irq_type() after the arch_initcall for EIC has run, and322* before the I2C subsystem could try using this IRQ.323*/324return irq_set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);325}326arch_initcall(atngw100_arch_init);327328329