blob: 6f20dc3b9b65e14810cf33408fb7d79f7a7acbb2 [file] [log] [blame]
Timur Tabi9b45b5a2010-06-14 15:28:24 -05001/*
Kumar Gala365024c2011-01-31 15:51:20 -06002 * Copyright 2010-2011 Freescale Semiconductor, Inc.
Timur Tabi9b45b5a2010-06-14 15:28:24 -05003 * Authors: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
4 * Timur Tabi <timur@freescale.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 */
11
12#include <common.h>
13#include <command.h>
14#include <pci.h>
15#include <asm/processor.h>
16#include <asm/mmu.h>
17#include <asm/cache.h>
18#include <asm/immap_85xx.h>
19#include <asm/fsl_pci.h>
20#include <asm/fsl_ddr_sdram.h>
21#include <asm/fsl_serdes.h>
22#include <asm/io.h>
23#include <libfdt.h>
24#include <fdt_support.h>
25#include <tsec.h>
26#include <asm/fsl_law.h>
Timur Tabi9b45b5a2010-06-14 15:28:24 -050027#include <netdev.h>
28#include <i2c.h>
Timur Tabi8848d472010-07-21 16:56:19 -050029#include <hwconfig.h>
Timur Tabi9b45b5a2010-06-14 15:28:24 -050030
31#include "../common/ngpixis.h"
32
33DECLARE_GLOBAL_DATA_PTR;
34
35int board_early_init_f(void)
36{
37 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
38
39 /* Set pmuxcr to allow both i2c1 and i2c2 */
40 setbits_be32(&gur->pmuxcr, 0x1000);
41
42 /* Read back the register to synchronize the write. */
43 in_be32(&gur->pmuxcr);
44
45 /* Set the pin muxing to enable ETSEC2. */
46 clrbits_be32(&gur->pmuxcr2, 0x001F8000);
47
48 return 0;
49}
50
51int checkboard(void)
52{
53 u8 sw;
54
55 puts("Board: P1022DS ");
Jiang Yutangb7738b52011-01-24 18:21:15 +080056#ifdef CONFIG_PHYS_64BIT
57 puts("(36-bit addrmap) ");
58#endif
Timur Tabi9b45b5a2010-06-14 15:28:24 -050059
60 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
61 in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
62
63 sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
64
65 switch ((sw & PIXIS_LBMAP_MASK) >> 6) {
66 case 0:
67 printf ("vBank: %u\n", ((sw & 0x30) >> 4));
68 break;
69 case 1:
70 printf ("NAND\n");
71 break;
72 case 2:
73 case 3:
74 puts ("Promjet\n");
75 break;
76 }
77
78 return 0;
79}
80
Timur Tabi9b45b5a2010-06-14 15:28:24 -050081#define CONFIG_TFP410_I2C_ADDR 0x38
82
Timur Tabi8848d472010-07-21 16:56:19 -050083/* Masks for the SSI_TDM and AUDCLK bits of the ngPIXIS BRDCFG1 register. */
84#define CONFIG_PIXIS_BRDCFG1_SSI_TDM_MASK 0x0c
85#define CONFIG_PIXIS_BRDCFG1_AUDCLK_MASK 0x03
86
87/* Route the I2C1 pins to the SSI port instead. */
88#define CONFIG_PIXIS_BRDCFG1_SSI_TDM_SSI 0x08
89
90/* Choose the 12.288Mhz codec reference clock */
91#define CONFIG_PIXIS_BRDCFG1_AUDCLK_12 0x02
92
93/* Choose the 11.2896Mhz codec reference clock */
94#define CONFIG_PIXIS_BRDCFG1_AUDCLK_11 0x01
95
Timur Tabi9b45b5a2010-06-14 15:28:24 -050096int misc_init_r(void)
97{
98 u8 temp;
Timur Tabi8848d472010-07-21 16:56:19 -050099 const char *audclk;
100 size_t arglen;
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500101
Timur Tabi8848d472010-07-21 16:56:19 -0500102 /* For DVI, enable the TFP410 Encoder. */
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500103
104 temp = 0xBF;
105 if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
106 return -1;
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500107 if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
108 return -1;
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500109 debug("DVI Encoder Read: 0x%02x\n", temp);
110
111 temp = 0x10;
112 if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
113 return -1;
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500114 if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
115 return -1;
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500116 debug("DVI Encoder Read: 0x%02x\n",temp);
117
Timur Tabi8848d472010-07-21 16:56:19 -0500118 /*
119 * Enable the reference clock for the WM8776 codec, and route the MUX
120 * pins for SSI. The default is the 12.288 MHz clock
121 */
122
123 temp = in_8(&pixis->brdcfg1) & ~(CONFIG_PIXIS_BRDCFG1_SSI_TDM_MASK |
124 CONFIG_PIXIS_BRDCFG1_AUDCLK_MASK);
125 temp |= CONFIG_PIXIS_BRDCFG1_SSI_TDM_SSI;
126
127 audclk = hwconfig_arg("audclk", &arglen);
128 /* Check the first two chars only */
129 if (audclk && (strncmp(audclk, "11", 2) == 0))
130 temp |= CONFIG_PIXIS_BRDCFG1_AUDCLK_11;
131 else
132 temp |= CONFIG_PIXIS_BRDCFG1_AUDCLK_12;
133 out_8(&pixis->brdcfg1, temp);
134
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500135 return 0;
136}
137
Kumar Galab07fbe62010-07-08 22:27:30 -0500138/*
139 * A list of PCI and SATA slots
140 */
141enum slot_id {
142 SLOT_PCIE1 = 1,
143 SLOT_PCIE2,
144 SLOT_PCIE3,
145 SLOT_PCIE4,
146 SLOT_PCIE5,
147 SLOT_SATA1,
148 SLOT_SATA2
149};
150
151/*
152 * This array maps the slot identifiers to their names on the P1022DS board.
153 */
154static const char *slot_names[] = {
155 [SLOT_PCIE1] = "Slot 1",
156 [SLOT_PCIE2] = "Slot 2",
157 [SLOT_PCIE3] = "Slot 3",
158 [SLOT_PCIE4] = "Slot 4",
159 [SLOT_PCIE5] = "Mini-PCIe",
160 [SLOT_SATA1] = "SATA 1",
161 [SLOT_SATA2] = "SATA 2",
162};
163
164/*
165 * This array maps a given SERDES configuration and SERDES device to the PCI or
166 * SATA slot that it connects to. This mapping is hard-coded in the FPGA.
167 */
168static u8 serdes_dev_slot[][SATA2 + 1] = {
169 [0x01] = { [PCIE3] = SLOT_PCIE4, [PCIE2] = SLOT_PCIE5 },
170 [0x02] = { [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
171 [0x09] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE4,
172 [PCIE2] = SLOT_PCIE5 },
173 [0x16] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
174 [PCIE2] = SLOT_PCIE3,
175 [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
176 [0x17] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
177 [PCIE2] = SLOT_PCIE3 },
178 [0x1a] = { [PCIE1] = SLOT_PCIE1, [PCIE2] = SLOT_PCIE3,
179 [PCIE2] = SLOT_PCIE3,
180 [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
181 [0x1c] = { [PCIE1] = SLOT_PCIE1,
182 [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
183 [0x1e] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE3 },
184 [0x1f] = { [PCIE1] = SLOT_PCIE1 },
185};
186
187
188/*
189 * Returns the name of the slot to which the PCIe or SATA controller is
190 * connected
191 */
Kumar Gala4d4384e2010-12-15 14:21:41 -0600192const char *board_serdes_name(enum srds_prtcl device)
Kumar Galab07fbe62010-07-08 22:27:30 -0500193{
194 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
195 u32 pordevsr = in_be32(&gur->pordevsr);
196 unsigned int srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
197 MPC85xx_PORDEVSR_IO_SEL_SHIFT;
198 enum slot_id slot = serdes_dev_slot[srds_cfg][device];
199 const char *name = slot_names[slot];
200
201 if (name)
202 return name;
203 else
204 return "Nothing";
205}
206
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500207#ifdef CONFIG_PCI
208void pci_init_board(void)
209{
Kumar Gala4d4384e2010-12-15 14:21:41 -0600210 fsl_pcie_init_board(0);
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500211}
212#endif
213
214int board_early_init_r(void)
215{
216 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
217 const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
218
219 /*
220 * Remap Boot flash + PROMJET region to caching-inhibited
221 * so that flash can be erased properly.
222 */
223
224 /* Flush d-cache and invalidate i-cache of any FLASH data */
225 flush_dcache();
226 invalidate_icache();
227
228 /* invalidate existing TLB entry for flash + promjet */
229 disable_tlb(flash_esel);
230
231 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
232 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
233 0, flash_esel, BOOKE_PAGESZ_256M, 1);
234
235 return 0;
236}
237
238/*
239 * Initialize on-board and/or PCI Ethernet devices
240 *
241 * Returns:
242 * <0, error
243 * 0, no ethernet devices found
244 * >0, number of ethernet devices initialized
245 */
246int board_eth_init(bd_t *bis)
247{
248 struct tsec_info_struct tsec_info[2];
249 unsigned int num = 0;
250
251#ifdef CONFIG_TSEC1
252 SET_STD_TSEC_INFO(tsec_info[num], 1);
253 num++;
254#endif
255#ifdef CONFIG_TSEC2
256 SET_STD_TSEC_INFO(tsec_info[num], 2);
257 num++;
258#endif
259
260 return tsec_eth_init(bis, tsec_info, num) + pci_eth_init(bis);
261}
262
263#ifdef CONFIG_OF_BOARD_SETUP
Timur Tabi8848d472010-07-21 16:56:19 -0500264/**
265 * ft_codec_setup - fix up the clock-frequency property of the codec node
266 *
267 * Update the clock-frequency property based on the value of the 'audclk'
268 * hwconfig option. If audclk is not specified, then default to 12.288MHz.
269 */
270static void ft_codec_setup(void *blob, const char *compatible)
271{
272 const char *audclk;
273 size_t arglen;
274 u32 freq;
275
276 audclk = hwconfig_arg("audclk", &arglen);
277 if (audclk && (strncmp(audclk, "11", 2) == 0))
278 freq = 11289600;
279 else
280 freq = 12288000;
281
282 do_fixup_by_compat_u32(blob, compatible, "clock-frequency", freq, 1);
283}
284
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500285void ft_board_setup(void *blob, bd_t *bd)
286{
287 phys_addr_t base;
288 phys_size_t size;
289
290 ft_cpu_setup(blob, bd);
291
292 base = getenv_bootm_low();
293 size = getenv_bootm_size();
294
295 fdt_fixup_memory(blob, (u64)base, (u64)size);
296
Kumar Galad0f27d32010-07-08 22:37:44 -0500297 FT_FSL_PCI_SETUP;
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500298
299#ifdef CONFIG_FSL_SGMII_RISER
300 fsl_sgmii_riser_fdt_fixup(blob);
301#endif
Timur Tabi8848d472010-07-21 16:56:19 -0500302
303 /* Update the WM8776 node's clock frequency property */
304 ft_codec_setup(blob, "wlf,wm8776");
Timur Tabi9b45b5a2010-06-14 15:28:24 -0500305}
306#endif