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