]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/avr32/boards/atngw100/setup.c
leds: leds-gpio for ngw100
[linux-2.6-omap-h63xx.git] / arch / avr32 / boards / atngw100 / setup.c
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/init.h>
13 #include <linux/linkage.h>
14 #include <linux/platform_device.h>
15 #include <linux/types.h>
16 #include <linux/leds.h>
17 #include <linux/spi/spi.h>
18
19 #include <asm/io.h>
20 #include <asm/setup.h>
21
22 #include <asm/arch/at32ap7000.h>
23 #include <asm/arch/board.h>
24 #include <asm/arch/init.h>
25 #include <asm/arch/portmux.h>
26
27 /* Initialized by bootloader-specific startup code. */
28 struct tag *bootloader_tags __initdata;
29
30 struct eth_addr {
31         u8 addr[6];
32 };
33 static struct eth_addr __initdata hw_addr[2];
34 static struct eth_platform_data __initdata eth_data[2];
35
36 static struct spi_board_info spi0_board_info[] __initdata = {
37         {
38                 .modalias       = "mtd_dataflash",
39                 .max_speed_hz   = 10000000,
40                 .chip_select    = 0,
41         },
42 };
43
44 /*
45  * The next two functions should go away as the boot loader is
46  * supposed to initialize the macb address registers with a valid
47  * ethernet address. But we need to keep it around for a while until
48  * we can be reasonably sure the boot loader does this.
49  *
50  * The phy_id is ignored as the driver will probe for it.
51  */
52 static int __init parse_tag_ethernet(struct tag *tag)
53 {
54         int i;
55
56         i = tag->u.ethernet.mac_index;
57         if (i < ARRAY_SIZE(hw_addr))
58                 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
59                        sizeof(hw_addr[i].addr));
60
61         return 0;
62 }
63 __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
64
65 static void __init set_hw_addr(struct platform_device *pdev)
66 {
67         struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
68         const u8 *addr;
69         void __iomem *regs;
70         struct clk *pclk;
71
72         if (!res)
73                 return;
74         if (pdev->id >= ARRAY_SIZE(hw_addr))
75                 return;
76
77         addr = hw_addr[pdev->id].addr;
78         if (!is_valid_ether_addr(addr))
79                 return;
80
81         /*
82          * Since this is board-specific code, we'll cheat and use the
83          * physical address directly as we happen to know that it's
84          * the same as the virtual address.
85          */
86         regs = (void __iomem __force *)res->start;
87         pclk = clk_get(&pdev->dev, "pclk");
88         if (!pclk)
89                 return;
90
91         clk_enable(pclk);
92         __raw_writel((addr[3] << 24) | (addr[2] << 16)
93                      | (addr[1] << 8) | addr[0], regs + 0x98);
94         __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
95         clk_disable(pclk);
96         clk_put(pclk);
97 }
98
99 void __init setup_board(void)
100 {
101         at32_map_usart(1, 0);   /* USART 1: /dev/ttyS0, DB9 */
102         at32_setup_serial_console(0);
103 }
104
105 static const struct gpio_led ngw_leds[] = {
106         { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
107                 .default_trigger = "heartbeat",
108         },
109         { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
110         { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
111 };
112
113 static const struct gpio_led_platform_data ngw_led_data = {
114         .num_leds =     ARRAY_SIZE(ngw_leds),
115         .leds =         (void *) ngw_leds,
116 };
117
118 static struct platform_device ngw_gpio_leds = {
119         .name =         "leds-gpio",
120         .id =           -1,
121         .dev = {
122                 .platform_data = (void *) &ngw_led_data,
123         }
124 };
125
126 static int __init atngw100_init(void)
127 {
128         unsigned        i;
129
130         /*
131          * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
132          * reserve any pins for it.
133          */
134
135         at32_add_system_devices();
136
137         at32_add_device_usart(0);
138
139         set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
140         set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
141
142         at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
143
144         for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
145                 at32_select_gpio(ngw_leds[i].gpio,
146                                 AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
147         }
148         platform_device_register(&ngw_gpio_leds);
149
150         return 0;
151 }
152 postcore_initcall(atngw100_init);