powerpc/85xx: Read board switch settings on p1_p2_rdb
[oweals/u-boot.git] / board / freescale / p1_p2_rdb / p1_p2_rdb.c
1 /*
2  * Copyright 2009-2011 Freescale Semiconductor, Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <command.h>
25 #include <asm/processor.h>
26 #include <asm/mmu.h>
27 #include <asm/cache.h>
28 #include <asm/immap_85xx.h>
29 #include <asm/fsl_serdes.h>
30 #include <asm/io.h>
31 #include <miiphy.h>
32 #include <libfdt.h>
33 #include <fdt_support.h>
34 #include <tsec.h>
35 #include <vsc7385.h>
36 #include <netdev.h>
37 #include <rtc.h>
38 #include <i2c.h>
39
40 DECLARE_GLOBAL_DATA_PTR;
41
42 #define VSC7385_RST_SET         0x00080000
43 #define SLIC_RST_SET            0x00040000
44 #define SGMII_PHY_RST_SET       0x00020000
45 #define PCIE_RST_SET            0x00010000
46 #define RGMII_PHY_RST_SET       0x02000000
47
48 #define USB_RST_CLR             0x04000000
49
50 #define GPIO_DIR                0x060f0000
51
52 #define BOARD_PERI_RST_SET      VSC7385_RST_SET | SLIC_RST_SET | \
53                                 SGMII_PHY_RST_SET | PCIE_RST_SET | \
54                                 RGMII_PHY_RST_SET
55
56 #define SYSCLK_MASK     0x00200000
57 #define BOARDREV_MASK   0x10100000
58 #define BOARDREV_B      0x10100000
59 #define BOARDREV_C      0x00100000
60 #define BOARDREV_D      0x00000000
61
62 #define SYSCLK_66       66666666
63 #define SYSCLK_50       50000000
64 #define SYSCLK_100      100000000
65
66 unsigned long get_board_sys_clk(ulong dummy)
67 {
68         volatile ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
69         u32 val_gpdat, sysclk_gpio, board_rev_gpio;
70
71         val_gpdat = in_be32(&pgpio->gpdat);
72         sysclk_gpio = val_gpdat & SYSCLK_MASK;
73         board_rev_gpio = val_gpdat & BOARDREV_MASK;
74         if (board_rev_gpio == BOARDREV_C) {
75                 if(sysclk_gpio == 0)
76                         return SYSCLK_66;
77                 else
78                         return SYSCLK_100;
79         } else if (board_rev_gpio == BOARDREV_B) {
80                 if(sysclk_gpio == 0)
81                         return SYSCLK_66;
82                 else
83                         return SYSCLK_50;
84         } else if (board_rev_gpio == BOARDREV_D) {
85                 if(sysclk_gpio == 0)
86                         return SYSCLK_66;
87                 else
88                         return SYSCLK_100;
89         }
90         return 0;
91 }
92
93 #ifdef CONFIG_MMC
94 int board_early_init_f (void)
95 {
96         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
97
98         setbits_be32(&gur->pmuxcr,
99                         (MPC85xx_PMUXCR_SDHC_CD |
100                          MPC85xx_PMUXCR_SDHC_WP));
101         return 0;
102 }
103 #endif
104
105 int checkboard (void)
106 {
107         u32 val_gpdat, board_rev_gpio;
108         volatile ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
109         char board_rev = 0;
110         struct cpu_type *cpu;
111
112         val_gpdat = in_be32(&pgpio->gpdat);
113         board_rev_gpio = val_gpdat & BOARDREV_MASK;
114         if (board_rev_gpio == BOARDREV_C)
115                 board_rev = 'C';
116         else if (board_rev_gpio == BOARDREV_B)
117                 board_rev = 'B';
118         else if (board_rev_gpio == BOARDREV_D)
119                 board_rev = 'D';
120         else
121                 panic ("Unexpected Board REV %x detected!!\n", board_rev_gpio);
122
123         cpu = gd->cpu;
124         printf ("Board: %sRDB Rev%c\n", cpu->name, board_rev);
125         setbits_be32(&pgpio->gpdir, GPIO_DIR);
126
127 /*
128  * Bringing the following peripherals out of reset via GPIOs
129  * 0 = reset and 1 = out of reset
130  * GPIO12 - Reset to Ethernet Switch
131  * GPIO13 - Reset to SLIC/SLAC devices
132  * GPIO14 - Reset to SGMII_PHY_N
133  * GPIO15 - Reset to PCIe slots
134  * GPIO6  - Reset to RGMII PHY
135  * GPIO5  - Reset to USB3300 devices 1 = reset and 0 = out of reset
136  */
137         clrsetbits_be32(&pgpio->gpdat, USB_RST_CLR, BOARD_PERI_RST_SET);
138
139         return 0;
140 }
141
142 int board_early_init_r(void)
143 {
144         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
145         const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
146         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
147         unsigned int orig_bus = i2c_get_bus_num();
148         u8 i2c_data;
149
150         i2c_set_bus_num(1);
151         if (i2c_read(CONFIG_SYS_I2C_PCA9557_ADDR, 0,
152                 1, &i2c_data, sizeof(i2c_data)) == 0) {
153                 if (i2c_data & 0x2)
154                         puts("NOR Flash Bank : Secondary\n");
155                 else
156                         puts("NOR Flash Bank : Primary\n");
157
158                 if (i2c_data & 0x1) {
159                         setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
160                         puts("SD/MMC : 8-bit Mode\n");
161                         puts("eSPI : Disabled\n");
162                 } else {
163                         puts("SD/MMC : 4-bit Mode\n");
164                         puts("eSPI : Enabled\n");
165                 }
166         } else {
167                 puts("Failed reading I2C Chip 0x18 on bus 1\n");
168         }
169         i2c_set_bus_num(orig_bus);
170
171         /*
172          * Remap Boot flash region to caching-inhibited
173          * so that flash can be erased properly.
174          */
175
176         /* Flush d-cache and invalidate i-cache of any FLASH data */
177         flush_dcache();
178         invalidate_icache();
179
180         /* invalidate existing TLB entry for flash */
181         disable_tlb(flash_esel);
182
183         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
184                         MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
185                         0, flash_esel, BOOKE_PAGESZ_16M, 1);
186         rtc_reset();
187         return 0;
188 }
189
190
191 #ifdef CONFIG_TSEC_ENET
192 int board_eth_init(bd_t *bis)
193 {
194         struct tsec_info_struct tsec_info[4];
195         int num = 0;
196         char *tmp;
197         unsigned int vscfw_addr;
198
199 #ifdef CONFIG_TSEC1
200         SET_STD_TSEC_INFO(tsec_info[num], 1);
201         num++;
202 #endif
203 #ifdef CONFIG_TSEC2
204         SET_STD_TSEC_INFO(tsec_info[num], 2);
205         num++;
206 #endif
207 #ifdef CONFIG_TSEC3
208         SET_STD_TSEC_INFO(tsec_info[num], 3);
209         if (is_serdes_configured(SGMII_TSEC3)) {
210                 puts("eTSEC3 is in sgmii mode.\n");
211                 tsec_info[num].flags |= TSEC_SGMII;
212         }
213         num++;
214 #endif
215         if (!num) {
216                 printf("No TSECs initialized\n");
217                 return 0;
218         }
219 #ifdef CONFIG_VSC7385_ENET
220 /* If a VSC7385 microcode image is present, then upload it. */
221         if ((tmp = getenv ("vscfw_addr")) != NULL) {
222                 vscfw_addr = simple_strtoul (tmp, NULL, 16);
223                 printf("uploading VSC7385 microcode from %x\n", vscfw_addr);
224                 if (vsc7385_upload_firmware((void *) vscfw_addr,
225                                         CONFIG_VSC7385_IMAGE_SIZE))
226                         puts("Failure uploading VSC7385 microcode.\n");
227         } else
228                 puts("No address specified for VSC7385 microcode.\n");
229 #endif
230
231         tsec_eth_init(bis, tsec_info, num);
232
233         return pci_eth_init(bis);
234 }
235 #endif
236
237 #if defined(CONFIG_OF_BOARD_SETUP)
238 extern void ft_pci_board_setup(void *blob);
239
240 void ft_board_setup(void *blob, bd_t *bd)
241 {
242         phys_addr_t base;
243         phys_size_t size;
244
245         ft_cpu_setup(blob, bd);
246
247         base = getenv_bootm_low();
248         size = getenv_bootm_size();
249
250 #if defined(CONFIG_PCI)
251         ft_pci_board_setup(blob);
252 #endif /* #if defined(CONFIG_PCI) */
253
254         fdt_fixup_memory(blob, (u64)base, (u64)size);
255 }
256 #endif