602bf467ea0180ed0b1766c00fe64423e7cc7f25
[librecmc/librecmc.git] / target / linux / brcm63xx / files / arch / mips / bcm63xx / boards / board_livebox.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
7  */
8
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/mtd/physmap.h>
16 #include <asm/addrspace.h>
17 #include <bcm63xx_board.h>
18 #include <bcm63xx_cpu.h>
19 #include <bcm63xx_regs.h>
20 #include <bcm63xx_io.h>
21 #include <bcm63xx_board.h>
22 #include <bcm63xx_dev_pci.h>
23 #include <bcm63xx_dev_uart.h>
24 #include <bcm63xx_dev_enet.h>
25 #include <bcm63xx_dev_pcmcia.h>
26 #include <bcm63xx_dev_usb_ohci.h>
27 #include <bcm63xx_dev_usb_ehci.h>
28 #include <board_bcm963xx.h>
29
30 #define PFX     "board_livebox: "
31
32 static unsigned int mac_addr_used = 0;
33 static struct board_info board;
34
35 /*
36  * known 6348 boards
37  */
38 #ifdef CONFIG_BCM63XX_CPU_6348
39 static struct board_info __initdata board_livebox = {
40         .name                           = "Livebox",
41         .expected_cpu_id                = 0x6348,
42
43         .has_enet0                      = 1,
44         .has_enet1                      = 1,
45         .has_pci                        = 1,
46
47         .enet0 = {
48                 .has_phy                = 1,
49                 .use_internal_phy       = 1,
50         },
51
52         .enet1 = {
53                 .force_speed_100        = 1,
54                 .force_duplex_full      = 1,
55         },
56
57         .has_ohci0                      = 1,
58         .has_pccard                     = 1,
59         .has_ehci0                      = 1,
60 };
61 #endif
62
63 /*
64  * all boards
65  */
66 static const struct board_info __initdata *bcm963xx_boards[] = {
67 #ifdef CONFIG_BCM63XX_CPU_6348
68         &board_livebox
69 #endif
70 };
71
72 /*
73  * early init callback
74  */
75 void __init board_prom_init(void)
76 {
77         u32 val;
78
79         /* read base address of boot chip select (0) */
80         val = bcm_mpi_readl(MPI_CSBASE_REG(0));
81         val &= MPI_CSBASE_BASE_MASK;
82
83         /* assume board is a Livebox */
84         memcpy(&board, bcm963xx_boards[0], sizeof(board));
85
86         /* setup pin multiplexing depending on board enabled device,
87          * this has to be done this early since PCI init is done
88          * inside arch_initcall */
89         val = 0;
90
91         if (board.has_pci) {
92                 bcm63xx_pci_enabled = 1;
93                 if (BCMCPU_IS_6348())
94                         val |= GPIO_MODE_6348_G2_PCI;
95         }
96
97         if (board.has_pccard) {
98                 if (BCMCPU_IS_6348())
99                         val |= GPIO_MODE_6348_G1_MII_PCCARD;
100         }
101
102         if (board.has_enet0 && !board.enet0.use_internal_phy) {
103                 if (BCMCPU_IS_6348())
104                         val |= GPIO_MODE_6348_G3_EXT_MII |
105                                 GPIO_MODE_6348_G0_EXT_MII;
106         }
107
108         if (board.has_enet1 && !board.enet1.use_internal_phy) {
109                 if (BCMCPU_IS_6348())
110                         val |= GPIO_MODE_6348_G3_EXT_MII |
111                                 GPIO_MODE_6348_G0_EXT_MII;
112         }
113
114         bcm_gpio_writel(val, GPIO_MODE_REG);
115 }
116
117 /*
118  * second stage init callback, good time to panic if we couldn't
119  * identify on which board we're running since early printk is working
120  */
121 void __init board_setup(void)
122 {
123         if (!board.name[0])
124                 panic("unable to detect bcm963xx board");
125         printk(KERN_INFO PFX "board name: %s\n", board.name);
126
127         /* make sure we're running on expected cpu */
128         if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
129                 panic("unexpected CPU for bcm963xx board");
130 }
131
132 /*
133  * return board name for /proc/cpuinfo
134  */
135 const char *board_get_name(void)
136 {
137         return board.name;
138 }
139
140 /*
141  * register & return a new board mac address
142  */
143
144 static int board_get_mac_address(u8 *mac)
145 {
146         u8 default_mac[ETH_ALEN] = {0x00, 0x07, 0x3A, 0x00, 0x00, 0x00};
147         u8 *p;
148         int count;
149
150         memcpy(mac, default_mac, ETH_ALEN);
151
152         p = mac + ETH_ALEN - 1;
153         count = mac_addr_used;
154
155         while (count--) {
156                 do {
157                         (*p)++;
158                         if (*p != 0)
159                                 break;
160                         p--;
161                 } while (p != mac);
162         }
163
164         if (p == mac) {
165                 printk(KERN_ERR PFX "unable to fetch mac address\n");
166                 return -ENODEV;
167         }
168         mac_addr_used++;
169
170         return 0;
171 }
172
173 static struct resource mtd_resources[] = {
174         {
175                 .start          = 0,    /* filled at runtime */
176                 .end            = 0,    /* filled at runtime */
177                 .flags          = IORESOURCE_MEM,
178         }
179 };
180
181 static struct platform_device mtd_dev = {
182         .name                   = "bcm963xx-flash",
183         .resource               = mtd_resources,
184         .num_resources          = ARRAY_SIZE(mtd_resources),
185 };
186
187
188 /*
189  * third stage init callback, register all board devices.
190  */
191 int __init board_register_devices(void)
192 {
193         u32 val;
194
195         bcm63xx_uart_register();
196
197         if (board.has_pccard)
198                 bcm63xx_pcmcia_register();
199
200         if (board.has_enet0 &&
201             !board_get_mac_address(board.enet0.mac_addr))
202                 bcm63xx_enet_register(0, &board.enet0);
203
204         if (board.has_enet1 &&
205             !board_get_mac_address(board.enet1.mac_addr))
206                 bcm63xx_enet_register(1, &board.enet1);
207
208         if (board.has_ohci0)
209                 bcm63xx_ohci_register();
210
211         if (board.has_ehci0)
212                 bcm63xx_ehci_register();
213
214
215         /* read base address of boot chip select (0) */
216         val = bcm_mpi_readl(MPI_CSBASE_REG(0));
217         val &= MPI_CSBASE_BASE_MASK;
218         mtd_resources[0].start = val;
219         mtd_resources[0].end = 0x1FFFFFFF;
220         
221         platform_device_register(&mtd_dev);
222
223         return 0;
224 }
225