Merge ../linus
[linux-drm-fsl-dcu.git] / arch / avr32 / boards / atstk1000 / atstk1002.c
1 /*
2  * ATSTK1002 daughterboard-specific init code
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/kernel.h>
14 #include <linux/platform_device.h>
15 #include <linux/string.h>
16 #include <linux/types.h>
17
18 #include <asm/io.h>
19 #include <asm/setup.h>
20 #include <asm/arch/board.h>
21 #include <asm/arch/init.h>
22
23 struct eth_addr {
24         u8 addr[6];
25 };
26
27 static struct eth_addr __initdata hw_addr[2];
28
29 static struct eth_platform_data __initdata eth_data[2];
30 extern struct lcdc_platform_data atstk1000_fb0_data;
31
32 /*
33  * The next two functions should go away as the boot loader is
34  * supposed to initialize the macb address registers with a valid
35  * ethernet address. But we need to keep it around for a while until
36  * we can be reasonably sure the boot loader does this.
37  *
38  * The phy_id is ignored as the driver will probe for it.
39  */
40 static int __init parse_tag_ethernet(struct tag *tag)
41 {
42         int i;
43
44         i = tag->u.ethernet.mac_index;
45         if (i < ARRAY_SIZE(hw_addr))
46                 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
47                        sizeof(hw_addr[i].addr));
48
49         return 0;
50 }
51 __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
52
53 static void __init set_hw_addr(struct platform_device *pdev)
54 {
55         struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
56         const u8 *addr;
57         void __iomem *regs;
58         struct clk *pclk;
59
60         if (!res)
61                 return;
62         if (pdev->id >= ARRAY_SIZE(hw_addr))
63                 return;
64
65         addr = hw_addr[pdev->id].addr;
66         if (!is_valid_ether_addr(addr))
67                 return;
68
69         /*
70          * Since this is board-specific code, we'll cheat and use the
71          * physical address directly as we happen to know that it's
72          * the same as the virtual address.
73          */
74         regs = (void __iomem __force *)res->start;
75         pclk = clk_get(&pdev->dev, "pclk");
76         if (!pclk)
77                 return;
78
79         clk_enable(pclk);
80         __raw_writel((addr[3] << 24) | (addr[2] << 16)
81                      | (addr[1] << 8) | addr[0], regs + 0x98);
82         __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
83         clk_disable(pclk);
84         clk_put(pclk);
85 }
86
87 void __init setup_board(void)
88 {
89         at32_map_usart(1, 0);   /* /dev/ttyS0 */
90         at32_map_usart(2, 1);   /* /dev/ttyS1 */
91         at32_map_usart(3, 2);   /* /dev/ttyS2 */
92
93         at32_setup_serial_console(0);
94 }
95
96 static int __init atstk1002_init(void)
97 {
98         at32_add_system_devices();
99
100         at32_add_device_usart(0);
101         at32_add_device_usart(1);
102         at32_add_device_usart(2);
103
104         set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
105
106         at32_add_device_spi(0);
107         at32_add_device_lcdc(0, &atstk1000_fb0_data);
108
109         return 0;
110 }
111 postcore_initcall(atstk1002_init);