Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 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> |
David Brownell | 9670660 | 2008-09-06 20:19:02 -0700 | [diff] [blame] | 12 | #include <linux/gpio.h> |
David Brownell | 7ef31e9 | 2008-06-12 12:18:05 -0700 | [diff] [blame] | 13 | #include <linux/irq.h> |
| 14 | #include <linux/i2c.h> |
Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 15 | #include <linux/i2c-gpio.h> |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/linkage.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/types.h> |
David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 20 | #include <linux/leds.h> |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 21 | #include <linux/spi/spi.h> |
Nicolas Ferre | c42aa77 | 2008-11-20 15:59:12 +0100 | [diff] [blame^] | 22 | #include <linux/atmel-mci.h> |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 23 | |
| 24 | #include <asm/io.h> |
| 25 | #include <asm/setup.h> |
| 26 | |
Haavard Skinnemoen | 3663b73 | 2008-08-05 13:57:38 +0200 | [diff] [blame] | 27 | #include <mach/at32ap700x.h> |
| 28 | #include <mach/board.h> |
| 29 | #include <mach/init.h> |
| 30 | #include <mach/portmux.h> |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 31 | |
Alex | 60ed795 | 2008-03-17 14:55:06 +0100 | [diff] [blame] | 32 | /* Oscillator frequencies. These are board-specific */ |
| 33 | unsigned 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 | }; |
| 38 | |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 39 | /* Initialized by bootloader-specific startup code. */ |
| 40 | struct tag *bootloader_tags __initdata; |
| 41 | |
| 42 | struct eth_addr { |
| 43 | u8 addr[6]; |
| 44 | }; |
| 45 | static struct eth_addr __initdata hw_addr[2]; |
| 46 | static struct eth_platform_data __initdata eth_data[2]; |
| 47 | |
| 48 | static struct spi_board_info spi0_board_info[] __initdata = { |
| 49 | { |
| 50 | .modalias = "mtd_dataflash", |
Haavard Skinnemoen | 0fe9497 | 2008-08-01 17:06:01 +0200 | [diff] [blame] | 51 | .max_speed_hz = 8000000, |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 52 | .chip_select = 0, |
| 53 | }, |
| 54 | }; |
| 55 | |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 56 | static struct mci_platform_data __initdata mci0_data = { |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 57 | .slot[0] = { |
| 58 | .bus_width = 4, |
Hans-Christian Egtvedt | a3bee42 | 2008-07-01 08:29:27 +0000 | [diff] [blame] | 59 | #ifndef CONFIG_BOARD_ATNGW100_EVKLCD10X |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 60 | .detect_pin = GPIO_PIN_PC(25), |
| 61 | .wp_pin = GPIO_PIN_PE(0), |
Hans-Christian Egtvedt | a3bee42 | 2008-07-01 08:29:27 +0000 | [diff] [blame] | 62 | #else |
| 63 | .detect_pin = GPIO_PIN_NONE, |
| 64 | .wp_pin = GPIO_PIN_NONE, |
| 65 | #endif |
Haavard Skinnemoen | 6b91865 | 2008-08-07 14:08:49 +0200 | [diff] [blame] | 66 | }, |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 69 | /* |
| 70 | * The next two functions should go away as the boot loader is |
| 71 | * supposed to initialize the macb address registers with a valid |
| 72 | * ethernet address. But we need to keep it around for a while until |
| 73 | * we can be reasonably sure the boot loader does this. |
| 74 | * |
| 75 | * The phy_id is ignored as the driver will probe for it. |
| 76 | */ |
| 77 | static int __init parse_tag_ethernet(struct tag *tag) |
| 78 | { |
| 79 | int i; |
| 80 | |
| 81 | i = tag->u.ethernet.mac_index; |
| 82 | if (i < ARRAY_SIZE(hw_addr)) |
| 83 | memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address, |
| 84 | sizeof(hw_addr[i].addr)); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | __tagtable(ATAG_ETHERNET, parse_tag_ethernet); |
| 89 | |
| 90 | static void __init set_hw_addr(struct platform_device *pdev) |
| 91 | { |
| 92 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 93 | const u8 *addr; |
| 94 | void __iomem *regs; |
| 95 | struct clk *pclk; |
| 96 | |
| 97 | if (!res) |
| 98 | return; |
| 99 | if (pdev->id >= ARRAY_SIZE(hw_addr)) |
| 100 | return; |
| 101 | |
| 102 | addr = hw_addr[pdev->id].addr; |
| 103 | if (!is_valid_ether_addr(addr)) |
| 104 | return; |
| 105 | |
| 106 | /* |
| 107 | * Since this is board-specific code, we'll cheat and use the |
| 108 | * physical address directly as we happen to know that it's |
| 109 | * the same as the virtual address. |
| 110 | */ |
| 111 | regs = (void __iomem __force *)res->start; |
| 112 | pclk = clk_get(&pdev->dev, "pclk"); |
| 113 | if (!pclk) |
| 114 | return; |
| 115 | |
| 116 | clk_enable(pclk); |
| 117 | __raw_writel((addr[3] << 24) | (addr[2] << 16) |
| 118 | | (addr[1] << 8) | addr[0], regs + 0x98); |
| 119 | __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c); |
| 120 | clk_disable(pclk); |
| 121 | clk_put(pclk); |
| 122 | } |
| 123 | |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 124 | void __init setup_board(void) |
| 125 | { |
| 126 | at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */ |
| 127 | at32_setup_serial_console(0); |
| 128 | } |
| 129 | |
David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 130 | static const struct gpio_led ngw_leds[] = { |
| 131 | { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1, |
| 132 | .default_trigger = "heartbeat", |
| 133 | }, |
| 134 | { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, }, |
| 135 | { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, }, |
| 136 | }; |
| 137 | |
| 138 | static const struct gpio_led_platform_data ngw_led_data = { |
| 139 | .num_leds = ARRAY_SIZE(ngw_leds), |
| 140 | .leds = (void *) ngw_leds, |
| 141 | }; |
| 142 | |
| 143 | static struct platform_device ngw_gpio_leds = { |
| 144 | .name = "leds-gpio", |
| 145 | .id = -1, |
| 146 | .dev = { |
| 147 | .platform_data = (void *) &ngw_led_data, |
| 148 | } |
| 149 | }; |
| 150 | |
Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 151 | static struct i2c_gpio_platform_data i2c_gpio_data = { |
David Brownell | 82c54f8 | 2007-09-25 07:17:48 -0700 | [diff] [blame] | 152 | .sda_pin = GPIO_PIN_PA(6), |
| 153 | .scl_pin = GPIO_PIN_PA(7), |
| 154 | .sda_is_open_drain = 1, |
| 155 | .scl_is_open_drain = 1, |
| 156 | .udelay = 2, /* close to 100 kHz */ |
Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | static struct platform_device i2c_gpio_device = { |
| 160 | .name = "i2c-gpio", |
| 161 | .id = 0, |
| 162 | .dev = { |
| 163 | .platform_data = &i2c_gpio_data, |
| 164 | }, |
| 165 | }; |
| 166 | |
David Brownell | 7ef31e9 | 2008-06-12 12:18:05 -0700 | [diff] [blame] | 167 | static struct i2c_board_info __initdata i2c_info[] = { |
| 168 | /* NOTE: original ATtiny24 firmware is at address 0x0b */ |
| 169 | }; |
| 170 | |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 171 | static int __init atngw100_init(void) |
| 172 | { |
David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 173 | unsigned i; |
| 174 | |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 175 | /* |
| 176 | * ATNGW100 uses 16-bit SDRAM interface, so we don't need to |
| 177 | * reserve any pins for it. |
| 178 | */ |
| 179 | |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 180 | at32_add_device_usart(0); |
| 181 | |
| 182 | set_hw_addr(at32_add_device_eth(0, ð_data[0])); |
| 183 | set_hw_addr(at32_add_device_eth(1, ð_data[1])); |
| 184 | |
| 185 | at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info)); |
Haavard Skinnemoen | 7d2be07 | 2008-06-30 18:35:03 +0200 | [diff] [blame] | 186 | at32_add_device_mci(0, &mci0_data); |
Haavard Skinnemoen | 6fcf061 | 2007-06-14 17:37:31 +0200 | [diff] [blame] | 187 | at32_add_device_usba(0, NULL); |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 188 | |
David Brownell | f9f451d | 2007-07-08 11:49:53 +0100 | [diff] [blame] | 189 | for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) { |
| 190 | at32_select_gpio(ngw_leds[i].gpio, |
| 191 | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH); |
| 192 | } |
| 193 | platform_device_register(&ngw_gpio_leds); |
| 194 | |
David Brownell | 7ef31e9 | 2008-06-12 12:18:05 -0700 | [diff] [blame] | 195 | /* all these i2c/smbus pins should have external pullups for |
| 196 | * open-drain sharing among all I2C devices. SDA and SCL do; |
| 197 | * PB28/EXTINT3 doesn't; it should be SMBALERT# (for PMBus), |
| 198 | * but it's not available off-board. |
| 199 | */ |
Julien May | caf18f1 | 2008-09-24 10:30:47 +0200 | [diff] [blame] | 200 | at32_select_periph(GPIO_PIOB_BASE, 1 << 28, 0, AT32_GPIOF_PULLUP); |
David Brownell | 82c54f8 | 2007-09-25 07:17:48 -0700 | [diff] [blame] | 201 | at32_select_gpio(i2c_gpio_data.sda_pin, |
| 202 | AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH); |
| 203 | at32_select_gpio(i2c_gpio_data.scl_pin, |
| 204 | AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH); |
Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 205 | platform_device_register(&i2c_gpio_device); |
David Brownell | 7ef31e9 | 2008-06-12 12:18:05 -0700 | [diff] [blame] | 206 | i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info)); |
Haavard Skinnemoen | 54bb69e | 2007-07-12 16:36:34 +0200 | [diff] [blame] | 207 | |
Haavard Skinnemoen | 9ca20a8 | 2007-04-12 17:26:57 +0200 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | postcore_initcall(atngw100_init); |
David Brownell | 7ef31e9 | 2008-06-12 12:18:05 -0700 | [diff] [blame] | 211 | |
| 212 | static int __init atngw100_arch_init(void) |
| 213 | { |
David Brownell | 9670660 | 2008-09-06 20:19:02 -0700 | [diff] [blame] | 214 | /* PB30 is the otherwise unused jumper on the mainboard, with an |
| 215 | * external pullup; the jumper grounds it. Use it however you |
| 216 | * like, including letting U-Boot or Linux tweak boot sequences. |
| 217 | */ |
| 218 | at32_select_gpio(GPIO_PIN_PB(30), 0); |
| 219 | gpio_request(GPIO_PIN_PB(30), "j15"); |
| 220 | gpio_direction_input(GPIO_PIN_PB(30)); |
| 221 | gpio_export(GPIO_PIN_PB(30), false); |
| 222 | |
David Brownell | 7ef31e9 | 2008-06-12 12:18:05 -0700 | [diff] [blame] | 223 | /* set_irq_type() after the arch_initcall for EIC has run, and |
| 224 | * before the I2C subsystem could try using this IRQ. |
| 225 | */ |
| 226 | return set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING); |
| 227 | } |
| 228 | arch_initcall(atngw100_arch_init); |