linux/arch/avr32/boards/atngw100/setup.c
<<
>>
Prefs
   1/*
   2 * Board-specific setup code for the ATNGW100 Network Gateway
   3 *
   4 * Copyright (C) 2005-2006 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/etherdevice.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
  22#include <asm/atmel-mci.h>
  23#include <asm/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/* Oscillator frequencies. These are board-specific */
  32unsigned long at32_board_osc_rates[3] = {
  33        [0] = 32768,    /* 32.768 kHz on RTC osc */
  34        [1] = 20000000, /* 20 MHz on osc0 */
  35        [2] = 12000000, /* 12 MHz on osc1 */
  36};
  37
  38/* Initialized by bootloader-specific startup code. */
  39struct tag *bootloader_tags __initdata;
  40
  41struct eth_addr {
  42        u8 addr[6];
  43};
  44static struct eth_addr __initdata hw_addr[2];
  45static struct eth_platform_data __initdata eth_data[2];
  46
  47static struct spi_board_info spi0_board_info[] __initdata = {
  48        {
  49                .modalias       = "mtd_dataflash",
  50                .max_speed_hz   = 8000000,
  51                .chip_select    = 0,
  52        },
  53};
  54
  55static struct mci_platform_data __initdata mci0_data = {
  56        .detect_pin     = GPIO_PIN_PC(25),
  57        .wp_pin         = GPIO_PIN_PE(0),
  58};
  59
  60/*
  61 * The next two functions should go away as the boot loader is
  62 * supposed to initialize the macb address registers with a valid
  63 * ethernet address. But we need to keep it around for a while until
  64 * we can be reasonably sure the boot loader does this.
  65 *
  66 * The phy_id is ignored as the driver will probe for it.
  67 */
  68static int __init parse_tag_ethernet(struct tag *tag)
  69{
  70        int i;
  71
  72        i = tag->u.ethernet.mac_index;
  73        if (i < ARRAY_SIZE(hw_addr))
  74                memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  75                       sizeof(hw_addr[i].addr));
  76
  77        return 0;
  78}
  79__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  80
  81static void __init set_hw_addr(struct platform_device *pdev)
  82{
  83        struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  84        const u8 *addr;
  85        void __iomem *regs;
  86        struct clk *pclk;
  87
  88        if (!res)
  89                return;
  90        if (pdev->id >= ARRAY_SIZE(hw_addr))
  91                return;
  92
  93        addr = hw_addr[pdev->id].addr;
  94        if (!is_valid_ether_addr(addr))
  95                return;
  96
  97        /*
  98         * Since this is board-specific code, we'll cheat and use the
  99         * physical address directly as we happen to know that it's
 100         * the same as the virtual address.
 101         */
 102        regs = (void __iomem __force *)res->start;
 103        pclk = clk_get(&pdev->dev, "pclk");
 104        if (!pclk)
 105                return;
 106
 107        clk_enable(pclk);
 108        __raw_writel((addr[3] << 24) | (addr[2] << 16)
 109                     | (addr[1] << 8) | addr[0], regs + 0x98);
 110        __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
 111        clk_disable(pclk);
 112        clk_put(pclk);
 113}
 114
 115void __init setup_board(void)
 116{
 117        at32_map_usart(1, 0);   /* USART 1: /dev/ttyS0, DB9 */
 118        at32_setup_serial_console(0);
 119}
 120
 121static const struct gpio_led ngw_leds[] = {
 122        { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
 123                .default_trigger = "heartbeat",
 124        },
 125        { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
 126        { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
 127};
 128
 129static const struct gpio_led_platform_data ngw_led_data = {
 130        .num_leds =     ARRAY_SIZE(ngw_leds),
 131        .leds =         (void *) ngw_leds,
 132};
 133
 134static struct platform_device ngw_gpio_leds = {
 135        .name =         "leds-gpio",
 136        .id =           -1,
 137        .dev = {
 138                .platform_data = (void *) &ngw_led_data,
 139        }
 140};
 141
 142static struct i2c_gpio_platform_data i2c_gpio_data = {
 143        .sda_pin                = GPIO_PIN_PA(6),
 144        .scl_pin                = GPIO_PIN_PA(7),
 145        .sda_is_open_drain      = 1,
 146        .scl_is_open_drain      = 1,
 147        .udelay                 = 2,    /* close to 100 kHz */
 148};
 149
 150static struct platform_device i2c_gpio_device = {
 151        .name           = "i2c-gpio",
 152        .id             = 0,
 153        .dev            = {
 154                .platform_data  = &i2c_gpio_data,
 155        },
 156};
 157
 158static struct i2c_board_info __initdata i2c_info[] = {
 159        /* NOTE:  original ATtiny24 firmware is at address 0x0b */
 160};
 161
 162static int __init atngw100_init(void)
 163{
 164        unsigned        i;
 165
 166        /*
 167         * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
 168         * reserve any pins for it.
 169         */
 170
 171        at32_add_system_devices();
 172
 173        at32_add_device_usart(0);
 174
 175        set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
 176        set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
 177
 178        at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
 179        at32_add_device_mci(0, &mci0_data);
 180        at32_add_device_usba(0, NULL);
 181
 182        for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
 183                at32_select_gpio(ngw_leds[i].gpio,
 184                                AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
 185        }
 186        platform_device_register(&ngw_gpio_leds);
 187
 188        /* all these i2c/smbus pins should have external pullups for
 189         * open-drain sharing among all I2C devices.  SDA and SCL do;
 190         * PB28/EXTINT3 doesn't; it should be SMBALERT# (for PMBus),
 191         * but it's not available off-board.
 192         */
 193        at32_select_periph(GPIO_PIN_PB(28), 0, AT32_GPIOF_PULLUP);
 194        at32_select_gpio(i2c_gpio_data.sda_pin,
 195                AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
 196        at32_select_gpio(i2c_gpio_data.scl_pin,
 197                AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
 198        platform_device_register(&i2c_gpio_device);
 199        i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
 200
 201        return 0;
 202}
 203postcore_initcall(atngw100_init);
 204
 205static int __init atngw100_arch_init(void)
 206{
 207        /* set_irq_type() after the arch_initcall for EIC has run, and
 208         * before the I2C subsystem could try using this IRQ.
 209         */
 210        return set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
 211}
 212arch_initcall(atngw100_arch_init);
 213