Commit f54fe87acedbbad7d29ad18cab31d2b323717514

Authored by Kumar Gala
1 parent 54648985e2

85xx/fsl-sata: Use is_serdes_configured() to determine if SATA is enabled

On the MPC85xx platform if we have SATA its connected on SERDES.
Determing if SATA is enabled via sata_initialize should not be board
specific and thus we move it out of the MPC8536DS board code.

Additionally, now that we have is_serdes_configured() we can determine
if the given SATA port is enabled and error out if its not in the
driver.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

Showing 3 changed files with 26 additions and 13 deletions Inline Diff

arch/powerpc/cpu/mpc85xx/cpu_init.c
1 /* 1 /*
2 * Copyright 2007-2009 Freescale Semiconductor, Inc. 2 * Copyright 2007-2010 Freescale Semiconductor, Inc.
3 * 3 *
4 * (C) Copyright 2003 Motorola Inc. 4 * (C) Copyright 2003 Motorola Inc.
5 * Modified by Xianghua Xiao, X.Xiao@motorola.com 5 * Modified by Xianghua Xiao, X.Xiao@motorola.com
6 * 6 *
7 * (C) Copyright 2000 7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * 9 *
10 * See file CREDITS for list of people who contributed to this 10 * See file CREDITS for list of people who contributed to this
11 * project. 11 * project.
12 * 12 *
13 * This program is free software; you can redistribute it and/or 13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as 14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of 15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version. 16 * the License, or (at your option) any later version.
17 * 17 *
18 * This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details. 21 * GNU General Public License for more details.
22 * 22 *
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA 26 * MA 02111-1307 USA
27 */ 27 */
28 28
29 #include <common.h> 29 #include <common.h>
30 #include <watchdog.h> 30 #include <watchdog.h>
31 #include <asm/processor.h> 31 #include <asm/processor.h>
32 #include <ioports.h> 32 #include <ioports.h>
33 #include <sata.h>
33 #include <asm/io.h> 34 #include <asm/io.h>
34 #include <asm/mmu.h> 35 #include <asm/mmu.h>
35 #include <asm/fsl_law.h> 36 #include <asm/fsl_law.h>
37 #include <asm/fsl_serdes.h>
36 #include "mp.h" 38 #include "mp.h"
37 39
38 DECLARE_GLOBAL_DATA_PTR; 40 DECLARE_GLOBAL_DATA_PTR;
39 41
40 #ifdef CONFIG_MPC8536 42 #ifdef CONFIG_MPC8536
41 extern void fsl_serdes_init(void); 43 extern void fsl_serdes_init(void);
42 #endif 44 #endif
43 45
44 #ifdef CONFIG_QE 46 #ifdef CONFIG_QE
45 extern qe_iop_conf_t qe_iop_conf_tab[]; 47 extern qe_iop_conf_t qe_iop_conf_tab[];
46 extern void qe_config_iopin(u8 port, u8 pin, int dir, 48 extern void qe_config_iopin(u8 port, u8 pin, int dir,
47 int open_drain, int assign); 49 int open_drain, int assign);
48 extern void qe_init(uint qe_base); 50 extern void qe_init(uint qe_base);
49 extern void qe_reset(void); 51 extern void qe_reset(void);
50 52
51 static void config_qe_ioports(void) 53 static void config_qe_ioports(void)
52 { 54 {
53 u8 port, pin; 55 u8 port, pin;
54 int dir, open_drain, assign; 56 int dir, open_drain, assign;
55 int i; 57 int i;
56 58
57 for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) { 59 for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
58 port = qe_iop_conf_tab[i].port; 60 port = qe_iop_conf_tab[i].port;
59 pin = qe_iop_conf_tab[i].pin; 61 pin = qe_iop_conf_tab[i].pin;
60 dir = qe_iop_conf_tab[i].dir; 62 dir = qe_iop_conf_tab[i].dir;
61 open_drain = qe_iop_conf_tab[i].open_drain; 63 open_drain = qe_iop_conf_tab[i].open_drain;
62 assign = qe_iop_conf_tab[i].assign; 64 assign = qe_iop_conf_tab[i].assign;
63 qe_config_iopin(port, pin, dir, open_drain, assign); 65 qe_config_iopin(port, pin, dir, open_drain, assign);
64 } 66 }
65 } 67 }
66 #endif 68 #endif
67 69
68 #ifdef CONFIG_CPM2 70 #ifdef CONFIG_CPM2
69 void config_8560_ioports (volatile ccsr_cpm_t * cpm) 71 void config_8560_ioports (volatile ccsr_cpm_t * cpm)
70 { 72 {
71 int portnum; 73 int portnum;
72 74
73 for (portnum = 0; portnum < 4; portnum++) { 75 for (portnum = 0; portnum < 4; portnum++) {
74 uint pmsk = 0, 76 uint pmsk = 0,
75 ppar = 0, 77 ppar = 0,
76 psor = 0, 78 psor = 0,
77 pdir = 0, 79 pdir = 0,
78 podr = 0, 80 podr = 0,
79 pdat = 0; 81 pdat = 0;
80 iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0]; 82 iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
81 iop_conf_t *eiopc = iopc + 32; 83 iop_conf_t *eiopc = iopc + 32;
82 uint msk = 1; 84 uint msk = 1;
83 85
84 /* 86 /*
85 * NOTE: 87 * NOTE:
86 * index 0 refers to pin 31, 88 * index 0 refers to pin 31,
87 * index 31 refers to pin 0 89 * index 31 refers to pin 0
88 */ 90 */
89 while (iopc < eiopc) { 91 while (iopc < eiopc) {
90 if (iopc->conf) { 92 if (iopc->conf) {
91 pmsk |= msk; 93 pmsk |= msk;
92 if (iopc->ppar) 94 if (iopc->ppar)
93 ppar |= msk; 95 ppar |= msk;
94 if (iopc->psor) 96 if (iopc->psor)
95 psor |= msk; 97 psor |= msk;
96 if (iopc->pdir) 98 if (iopc->pdir)
97 pdir |= msk; 99 pdir |= msk;
98 if (iopc->podr) 100 if (iopc->podr)
99 podr |= msk; 101 podr |= msk;
100 if (iopc->pdat) 102 if (iopc->pdat)
101 pdat |= msk; 103 pdat |= msk;
102 } 104 }
103 105
104 msk <<= 1; 106 msk <<= 1;
105 iopc++; 107 iopc++;
106 } 108 }
107 109
108 if (pmsk != 0) { 110 if (pmsk != 0) {
109 volatile ioport_t *iop = ioport_addr (cpm, portnum); 111 volatile ioport_t *iop = ioport_addr (cpm, portnum);
110 uint tpmsk = ~pmsk; 112 uint tpmsk = ~pmsk;
111 113
112 /* 114 /*
113 * the (somewhat confused) paragraph at the 115 * the (somewhat confused) paragraph at the
114 * bottom of page 35-5 warns that there might 116 * bottom of page 35-5 warns that there might
115 * be "unknown behaviour" when programming 117 * be "unknown behaviour" when programming
116 * PSORx and PDIRx, if PPARx = 1, so I 118 * PSORx and PDIRx, if PPARx = 1, so I
117 * decided this meant I had to disable the 119 * decided this meant I had to disable the
118 * dedicated function first, and enable it 120 * dedicated function first, and enable it
119 * last. 121 * last.
120 */ 122 */
121 iop->ppar &= tpmsk; 123 iop->ppar &= tpmsk;
122 iop->psor = (iop->psor & tpmsk) | psor; 124 iop->psor = (iop->psor & tpmsk) | psor;
123 iop->podr = (iop->podr & tpmsk) | podr; 125 iop->podr = (iop->podr & tpmsk) | podr;
124 iop->pdat = (iop->pdat & tpmsk) | pdat; 126 iop->pdat = (iop->pdat & tpmsk) | pdat;
125 iop->pdir = (iop->pdir & tpmsk) | pdir; 127 iop->pdir = (iop->pdir & tpmsk) | pdir;
126 iop->ppar |= ppar; 128 iop->ppar |= ppar;
127 } 129 }
128 } 130 }
129 } 131 }
130 #endif 132 #endif
131 133
132 /* 134 /*
133 * Breathe some life into the CPU... 135 * Breathe some life into the CPU...
134 * 136 *
135 * Set up the memory map 137 * Set up the memory map
136 * initialize a bunch of registers 138 * initialize a bunch of registers
137 */ 139 */
138 140
139 #ifdef CONFIG_FSL_CORENET 141 #ifdef CONFIG_FSL_CORENET
140 static void corenet_tb_init(void) 142 static void corenet_tb_init(void)
141 { 143 {
142 volatile ccsr_rcpm_t *rcpm = 144 volatile ccsr_rcpm_t *rcpm =
143 (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR); 145 (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
144 volatile ccsr_pic_t *pic = 146 volatile ccsr_pic_t *pic =
145 (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR); 147 (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
146 u32 whoami = in_be32(&pic->whoami); 148 u32 whoami = in_be32(&pic->whoami);
147 149
148 /* Enable the timebase register for this core */ 150 /* Enable the timebase register for this core */
149 out_be32(&rcpm->ctbenrl, (1 << whoami)); 151 out_be32(&rcpm->ctbenrl, (1 << whoami));
150 } 152 }
151 #endif 153 #endif
152 154
153 void cpu_init_f (void) 155 void cpu_init_f (void)
154 { 156 {
155 volatile ccsr_lbc_t *memctl = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR); 157 volatile ccsr_lbc_t *memctl = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
156 extern void m8560_cpm_reset (void); 158 extern void m8560_cpm_reset (void);
157 #ifdef CONFIG_MPC8548 159 #ifdef CONFIG_MPC8548
158 ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR); 160 ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
159 uint svr = get_svr(); 161 uint svr = get_svr();
160 162
161 /* 163 /*
162 * CPU2 errata workaround: A core hang possible while executing 164 * CPU2 errata workaround: A core hang possible while executing
163 * a msync instruction and a snoopable transaction from an I/O 165 * a msync instruction and a snoopable transaction from an I/O
164 * master tagged to make quick forward progress is present. 166 * master tagged to make quick forward progress is present.
165 * Fixed in silicon rev 2.1. 167 * Fixed in silicon rev 2.1.
166 */ 168 */
167 if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0))) 169 if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
168 out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16)); 170 out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
169 #endif 171 #endif
170 172
171 disable_tlb(14); 173 disable_tlb(14);
172 disable_tlb(15); 174 disable_tlb(15);
173 175
174 #ifdef CONFIG_CPM2 176 #ifdef CONFIG_CPM2
175 config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR); 177 config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR);
176 #endif 178 #endif
177 179
178 /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary 180 /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
179 * addresses - these have to be modified later when FLASH size 181 * addresses - these have to be modified later when FLASH size
180 * has been determined 182 * has been determined
181 */ 183 */
182 #if defined(CONFIG_SYS_OR0_REMAP) 184 #if defined(CONFIG_SYS_OR0_REMAP)
183 out_be32(&memctl->or0, CONFIG_SYS_OR0_REMAP); 185 out_be32(&memctl->or0, CONFIG_SYS_OR0_REMAP);
184 #endif 186 #endif
185 #if defined(CONFIG_SYS_OR1_REMAP) 187 #if defined(CONFIG_SYS_OR1_REMAP)
186 out_be32(&memctl->or1, CONFIG_SYS_OR1_REMAP); 188 out_be32(&memctl->or1, CONFIG_SYS_OR1_REMAP);
187 #endif 189 #endif
188 190
189 /* now restrict to preliminary range */ 191 /* now restrict to preliminary range */
190 /* if cs1 is already set via debugger, leave cs0/cs1 alone */ 192 /* if cs1 is already set via debugger, leave cs0/cs1 alone */
191 if (! memctl->br1 & 1) { 193 if (! memctl->br1 & 1) {
192 #if defined(CONFIG_SYS_BR0_PRELIM) && defined(CONFIG_SYS_OR0_PRELIM) 194 #if defined(CONFIG_SYS_BR0_PRELIM) && defined(CONFIG_SYS_OR0_PRELIM)
193 out_be32(&memctl->br0, CONFIG_SYS_BR0_PRELIM); 195 out_be32(&memctl->br0, CONFIG_SYS_BR0_PRELIM);
194 out_be32(&memctl->or0, CONFIG_SYS_OR0_PRELIM); 196 out_be32(&memctl->or0, CONFIG_SYS_OR0_PRELIM);
195 #endif 197 #endif
196 198
197 #if defined(CONFIG_SYS_BR1_PRELIM) && defined(CONFIG_SYS_OR1_PRELIM) 199 #if defined(CONFIG_SYS_BR1_PRELIM) && defined(CONFIG_SYS_OR1_PRELIM)
198 out_be32(&memctl->or1, CONFIG_SYS_OR1_PRELIM); 200 out_be32(&memctl->or1, CONFIG_SYS_OR1_PRELIM);
199 out_be32(&memctl->br1, CONFIG_SYS_BR1_PRELIM); 201 out_be32(&memctl->br1, CONFIG_SYS_BR1_PRELIM);
200 #endif 202 #endif
201 } 203 }
202 204
203 #if defined(CONFIG_SYS_BR2_PRELIM) && defined(CONFIG_SYS_OR2_PRELIM) 205 #if defined(CONFIG_SYS_BR2_PRELIM) && defined(CONFIG_SYS_OR2_PRELIM)
204 out_be32(&memctl->or2, CONFIG_SYS_OR2_PRELIM); 206 out_be32(&memctl->or2, CONFIG_SYS_OR2_PRELIM);
205 out_be32(&memctl->br2, CONFIG_SYS_BR2_PRELIM); 207 out_be32(&memctl->br2, CONFIG_SYS_BR2_PRELIM);
206 #endif 208 #endif
207 209
208 #if defined(CONFIG_SYS_BR3_PRELIM) && defined(CONFIG_SYS_OR3_PRELIM) 210 #if defined(CONFIG_SYS_BR3_PRELIM) && defined(CONFIG_SYS_OR3_PRELIM)
209 out_be32(&memctl->or3, CONFIG_SYS_OR3_PRELIM); 211 out_be32(&memctl->or3, CONFIG_SYS_OR3_PRELIM);
210 out_be32(&memctl->br3, CONFIG_SYS_BR3_PRELIM); 212 out_be32(&memctl->br3, CONFIG_SYS_BR3_PRELIM);
211 #endif 213 #endif
212 214
213 #if defined(CONFIG_SYS_BR4_PRELIM) && defined(CONFIG_SYS_OR4_PRELIM) 215 #if defined(CONFIG_SYS_BR4_PRELIM) && defined(CONFIG_SYS_OR4_PRELIM)
214 out_be32(&memctl->or4, CONFIG_SYS_OR4_PRELIM); 216 out_be32(&memctl->or4, CONFIG_SYS_OR4_PRELIM);
215 out_be32(&memctl->br4, CONFIG_SYS_BR4_PRELIM); 217 out_be32(&memctl->br4, CONFIG_SYS_BR4_PRELIM);
216 #endif 218 #endif
217 219
218 #if defined(CONFIG_SYS_BR5_PRELIM) && defined(CONFIG_SYS_OR5_PRELIM) 220 #if defined(CONFIG_SYS_BR5_PRELIM) && defined(CONFIG_SYS_OR5_PRELIM)
219 out_be32(&memctl->or5, CONFIG_SYS_OR5_PRELIM); 221 out_be32(&memctl->or5, CONFIG_SYS_OR5_PRELIM);
220 out_be32(&memctl->br5, CONFIG_SYS_BR5_PRELIM); 222 out_be32(&memctl->br5, CONFIG_SYS_BR5_PRELIM);
221 #endif 223 #endif
222 224
223 #if defined(CONFIG_SYS_BR6_PRELIM) && defined(CONFIG_SYS_OR6_PRELIM) 225 #if defined(CONFIG_SYS_BR6_PRELIM) && defined(CONFIG_SYS_OR6_PRELIM)
224 out_be32(&memctl->or6, CONFIG_SYS_OR6_PRELIM); 226 out_be32(&memctl->or6, CONFIG_SYS_OR6_PRELIM);
225 out_be32(&memctl->br6, CONFIG_SYS_BR6_PRELIM); 227 out_be32(&memctl->br6, CONFIG_SYS_BR6_PRELIM);
226 #endif 228 #endif
227 229
228 #if defined(CONFIG_SYS_BR7_PRELIM) && defined(CONFIG_SYS_OR7_PRELIM) 230 #if defined(CONFIG_SYS_BR7_PRELIM) && defined(CONFIG_SYS_OR7_PRELIM)
229 out_be32(&memctl->or7, CONFIG_SYS_OR7_PRELIM); 231 out_be32(&memctl->or7, CONFIG_SYS_OR7_PRELIM);
230 out_be32(&memctl->br7, CONFIG_SYS_BR7_PRELIM); 232 out_be32(&memctl->br7, CONFIG_SYS_BR7_PRELIM);
231 #endif 233 #endif
232 234
233 #if defined(CONFIG_CPM2) 235 #if defined(CONFIG_CPM2)
234 m8560_cpm_reset(); 236 m8560_cpm_reset();
235 #endif 237 #endif
236 #ifdef CONFIG_QE 238 #ifdef CONFIG_QE
237 /* Config QE ioports */ 239 /* Config QE ioports */
238 config_qe_ioports(); 240 config_qe_ioports();
239 #endif 241 #endif
240 #if defined(CONFIG_MPC8536) 242 #if defined(CONFIG_MPC8536)
241 fsl_serdes_init(); 243 fsl_serdes_init();
242 #endif 244 #endif
243 #if defined(CONFIG_FSL_DMA) 245 #if defined(CONFIG_FSL_DMA)
244 dma_init(); 246 dma_init();
245 #endif 247 #endif
246 #ifdef CONFIG_FSL_CORENET 248 #ifdef CONFIG_FSL_CORENET
247 corenet_tb_init(); 249 corenet_tb_init();
248 #endif 250 #endif
249 init_used_tlb_cams(); 251 init_used_tlb_cams();
250 } 252 }
251 253
252 254
253 /* 255 /*
254 * Initialize L2 as cache. 256 * Initialize L2 as cache.
255 * 257 *
256 * The newer 8548, etc, parts have twice as much cache, but 258 * The newer 8548, etc, parts have twice as much cache, but
257 * use the same bit-encoding as the older 8555, etc, parts. 259 * use the same bit-encoding as the older 8555, etc, parts.
258 * 260 *
259 */ 261 */
260 262
261 int cpu_init_r(void) 263 int cpu_init_r(void)
262 { 264 {
263 #ifdef CONFIG_SYS_LBC_LCRR 265 #ifdef CONFIG_SYS_LBC_LCRR
264 volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR); 266 volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
265 #endif 267 #endif
266 268
267 puts ("L2: "); 269 puts ("L2: ");
268 270
269 #if defined(CONFIG_L2_CACHE) 271 #if defined(CONFIG_L2_CACHE)
270 volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR; 272 volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
271 volatile uint cache_ctl; 273 volatile uint cache_ctl;
272 uint svr, ver; 274 uint svr, ver;
273 uint l2srbar; 275 uint l2srbar;
274 u32 l2siz_field; 276 u32 l2siz_field;
275 277
276 svr = get_svr(); 278 svr = get_svr();
277 ver = SVR_SOC_VER(svr); 279 ver = SVR_SOC_VER(svr);
278 280
279 asm("msync;isync"); 281 asm("msync;isync");
280 cache_ctl = l2cache->l2ctl; 282 cache_ctl = l2cache->l2ctl;
281 283
282 #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR) 284 #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
283 if (cache_ctl & MPC85xx_L2CTL_L2E) { 285 if (cache_ctl & MPC85xx_L2CTL_L2E) {
284 /* Clear L2 SRAM memory-mapped base address */ 286 /* Clear L2 SRAM memory-mapped base address */
285 out_be32(&l2cache->l2srbar0, 0x0); 287 out_be32(&l2cache->l2srbar0, 0x0);
286 out_be32(&l2cache->l2srbar1, 0x0); 288 out_be32(&l2cache->l2srbar1, 0x0);
287 289
288 /* set MBECCDIS=0, SBECCDIS=0 */ 290 /* set MBECCDIS=0, SBECCDIS=0 */
289 clrbits_be32(&l2cache->l2errdis, 291 clrbits_be32(&l2cache->l2errdis,
290 (MPC85xx_L2ERRDIS_MBECC | 292 (MPC85xx_L2ERRDIS_MBECC |
291 MPC85xx_L2ERRDIS_SBECC)); 293 MPC85xx_L2ERRDIS_SBECC));
292 294
293 /* set L2E=0, L2SRAM=0 */ 295 /* set L2E=0, L2SRAM=0 */
294 clrbits_be32(&l2cache->l2ctl, 296 clrbits_be32(&l2cache->l2ctl,
295 (MPC85xx_L2CTL_L2E | 297 (MPC85xx_L2CTL_L2E |
296 MPC85xx_L2CTL_L2SRAM_ENTIRE)); 298 MPC85xx_L2CTL_L2SRAM_ENTIRE));
297 } 299 }
298 #endif 300 #endif
299 301
300 l2siz_field = (cache_ctl >> 28) & 0x3; 302 l2siz_field = (cache_ctl >> 28) & 0x3;
301 303
302 switch (l2siz_field) { 304 switch (l2siz_field) {
303 case 0x0: 305 case 0x0:
304 printf(" unknown size (0x%08x)\n", cache_ctl); 306 printf(" unknown size (0x%08x)\n", cache_ctl);
305 return -1; 307 return -1;
306 break; 308 break;
307 case 0x1: 309 case 0x1:
308 if (ver == SVR_8540 || ver == SVR_8560 || 310 if (ver == SVR_8540 || ver == SVR_8560 ||
309 ver == SVR_8541 || ver == SVR_8541_E || 311 ver == SVR_8541 || ver == SVR_8541_E ||
310 ver == SVR_8555 || ver == SVR_8555_E) { 312 ver == SVR_8555 || ver == SVR_8555_E) {
311 puts("128 KB "); 313 puts("128 KB ");
312 /* set L2E=1, L2I=1, & L2BLKSZ=1 (128 Kbyte) */ 314 /* set L2E=1, L2I=1, & L2BLKSZ=1 (128 Kbyte) */
313 cache_ctl = 0xc4000000; 315 cache_ctl = 0xc4000000;
314 } else { 316 } else {
315 puts("256 KB "); 317 puts("256 KB ");
316 cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */ 318 cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
317 } 319 }
318 break; 320 break;
319 case 0x2: 321 case 0x2:
320 if (ver == SVR_8540 || ver == SVR_8560 || 322 if (ver == SVR_8540 || ver == SVR_8560 ||
321 ver == SVR_8541 || ver == SVR_8541_E || 323 ver == SVR_8541 || ver == SVR_8541_E ||
322 ver == SVR_8555 || ver == SVR_8555_E) { 324 ver == SVR_8555 || ver == SVR_8555_E) {
323 puts("256 KB "); 325 puts("256 KB ");
324 /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 Kbyte) */ 326 /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 Kbyte) */
325 cache_ctl = 0xc8000000; 327 cache_ctl = 0xc8000000;
326 } else { 328 } else {
327 puts ("512 KB "); 329 puts ("512 KB ");
328 /* set L2E=1, L2I=1, & L2SRAM=0 */ 330 /* set L2E=1, L2I=1, & L2SRAM=0 */
329 cache_ctl = 0xc0000000; 331 cache_ctl = 0xc0000000;
330 } 332 }
331 break; 333 break;
332 case 0x3: 334 case 0x3:
333 puts("1024 KB "); 335 puts("1024 KB ");
334 /* set L2E=1, L2I=1, & L2SRAM=0 */ 336 /* set L2E=1, L2I=1, & L2SRAM=0 */
335 cache_ctl = 0xc0000000; 337 cache_ctl = 0xc0000000;
336 break; 338 break;
337 } 339 }
338 340
339 if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) { 341 if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
340 puts("already enabled"); 342 puts("already enabled");
341 l2srbar = l2cache->l2srbar0; 343 l2srbar = l2cache->l2srbar0;
342 #ifdef CONFIG_SYS_INIT_L2_ADDR 344 #ifdef CONFIG_SYS_INIT_L2_ADDR
343 if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE 345 if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
344 && l2srbar >= CONFIG_SYS_FLASH_BASE) { 346 && l2srbar >= CONFIG_SYS_FLASH_BASE) {
345 l2srbar = CONFIG_SYS_INIT_L2_ADDR; 347 l2srbar = CONFIG_SYS_INIT_L2_ADDR;
346 l2cache->l2srbar0 = l2srbar; 348 l2cache->l2srbar0 = l2srbar;
347 printf("moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR); 349 printf("moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
348 } 350 }
349 #endif /* CONFIG_SYS_INIT_L2_ADDR */ 351 #endif /* CONFIG_SYS_INIT_L2_ADDR */
350 puts("\n"); 352 puts("\n");
351 } else { 353 } else {
352 asm("msync;isync"); 354 asm("msync;isync");
353 l2cache->l2ctl = cache_ctl; /* invalidate & enable */ 355 l2cache->l2ctl = cache_ctl; /* invalidate & enable */
354 asm("msync;isync"); 356 asm("msync;isync");
355 puts("enabled\n"); 357 puts("enabled\n");
356 } 358 }
357 #elif defined(CONFIG_BACKSIDE_L2_CACHE) 359 #elif defined(CONFIG_BACKSIDE_L2_CACHE)
358 u32 l2cfg0 = mfspr(SPRN_L2CFG0); 360 u32 l2cfg0 = mfspr(SPRN_L2CFG0);
359 361
360 /* invalidate the L2 cache */ 362 /* invalidate the L2 cache */
361 mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC)); 363 mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
362 while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC)) 364 while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
363 ; 365 ;
364 366
365 #ifdef CONFIG_SYS_CACHE_STASHING 367 #ifdef CONFIG_SYS_CACHE_STASHING
366 /* set stash id to (coreID) * 2 + 32 + L2 (1) */ 368 /* set stash id to (coreID) * 2 + 32 + L2 (1) */
367 mtspr(SPRN_L2CSR1, (32 + 1)); 369 mtspr(SPRN_L2CSR1, (32 + 1));
368 #endif 370 #endif
369 371
370 /* enable the cache */ 372 /* enable the cache */
371 mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0); 373 mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
372 374
373 if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) { 375 if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
374 while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E)) 376 while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
375 ; 377 ;
376 printf("%d KB enabled\n", (l2cfg0 & 0x3fff) * 64); 378 printf("%d KB enabled\n", (l2cfg0 & 0x3fff) * 64);
377 } 379 }
378 #else 380 #else
379 puts("disabled\n"); 381 puts("disabled\n");
380 #endif 382 #endif
381 #ifdef CONFIG_QE 383 #ifdef CONFIG_QE
382 uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */ 384 uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
383 qe_init(qe_base); 385 qe_init(qe_base);
384 qe_reset(); 386 qe_reset();
385 #endif 387 #endif
386 388
387 #if defined(CONFIG_MP) 389 #if defined(CONFIG_MP)
388 setup_mp(); 390 setup_mp();
389 #endif 391 #endif
390 392
391 #ifdef CONFIG_SYS_LBC_LCRR 393 #ifdef CONFIG_SYS_LBC_LCRR
392 /* 394 /*
393 * Modify the CLKDIV field of LCRR register to improve the writing 395 * Modify the CLKDIV field of LCRR register to improve the writing
394 * speed for NOR flash. 396 * speed for NOR flash.
395 */ 397 */
396 clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR); 398 clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR);
397 __raw_readl(&lbc->lcrr); 399 __raw_readl(&lbc->lcrr);
398 isync(); 400 isync();
399 #endif 401 #endif
400 402
401 return 0; 403 return 0;
402 } 404 }
403 405
404 extern void setup_ivors(void); 406 extern void setup_ivors(void);
405 407
406 void arch_preboot_os(void) 408 void arch_preboot_os(void)
407 { 409 {
408 u32 msr; 410 u32 msr;
409 411
410 /* 412 /*
411 * We are changing interrupt offsets and are about to boot the OS so 413 * We are changing interrupt offsets and are about to boot the OS so
412 * we need to make sure we disable all async interrupts. EE is already 414 * we need to make sure we disable all async interrupts. EE is already
413 * disabled by the time we get called. 415 * disabled by the time we get called.
414 */ 416 */
415 msr = mfmsr(); 417 msr = mfmsr();
416 msr &= ~(MSR_ME|MSR_CE|MSR_DE); 418 msr &= ~(MSR_ME|MSR_CE|MSR_DE);
417 mtmsr(msr); 419 mtmsr(msr);
418 420
419 setup_ivors(); 421 setup_ivors();
420 } 422 }
423
424 #if defined(CONFIG_CMD_SATA) && defined(CONFIG_FSL_SATA)
425 int sata_initialize(void)
426 {
427 if (is_serdes_configured(SATA1) || is_serdes_configured(SATA2))
428 return __sata_initialize();
429
430 return 1;
431 }
432 #endif
421 433
board/freescale/mpc8536ds/mpc8536ds.c
1 /* 1 /*
2 * Copyright 2008-2010 Freescale Semiconductor, Inc. 2 * Copyright 2008-2010 Freescale Semiconductor, Inc.
3 * 3 *
4 * See file CREDITS for list of people who contributed to this 4 * See file CREDITS for list of people who contributed to this
5 * project. 5 * project.
6 * 6 *
7 * This program is free software; you can redistribute it and/or 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 8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of 9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version. 10 * the License, or (at your option) any later version.
11 * 11 *
12 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License 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 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA 20 * MA 02111-1307 USA
21 */ 21 */
22 22
23 #include <common.h> 23 #include <common.h>
24 #include <command.h> 24 #include <command.h>
25 #include <pci.h> 25 #include <pci.h>
26 #include <asm/processor.h> 26 #include <asm/processor.h>
27 #include <asm/mmu.h> 27 #include <asm/mmu.h>
28 #include <asm/cache.h> 28 #include <asm/cache.h>
29 #include <asm/immap_85xx.h> 29 #include <asm/immap_85xx.h>
30 #include <asm/fsl_pci.h> 30 #include <asm/fsl_pci.h>
31 #include <asm/fsl_ddr_sdram.h> 31 #include <asm/fsl_ddr_sdram.h>
32 #include <asm/io.h> 32 #include <asm/io.h>
33 #include <asm/fsl_serdes.h> 33 #include <asm/fsl_serdes.h>
34 #include <spd.h> 34 #include <spd.h>
35 #include <miiphy.h> 35 #include <miiphy.h>
36 #include <libfdt.h> 36 #include <libfdt.h>
37 #include <spd_sdram.h> 37 #include <spd_sdram.h>
38 #include <fdt_support.h> 38 #include <fdt_support.h>
39 #include <tsec.h> 39 #include <tsec.h>
40 #include <netdev.h> 40 #include <netdev.h>
41 #include <sata.h> 41 #include <sata.h>
42 42
43 #include "../common/sgmii_riser.h" 43 #include "../common/sgmii_riser.h"
44 44
45 phys_size_t fixed_sdram(void); 45 phys_size_t fixed_sdram(void);
46 46
47 int board_early_init_f (void) 47 int board_early_init_f (void)
48 { 48 {
49 #ifdef CONFIG_MMC 49 #ifdef CONFIG_MMC
50 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 50 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
51 51
52 setbits_be32(&gur->pmuxcr, 52 setbits_be32(&gur->pmuxcr,
53 (MPC85xx_PMUXCR_SD_DATA | 53 (MPC85xx_PMUXCR_SD_DATA |
54 MPC85xx_PMUXCR_SDHC_CD | 54 MPC85xx_PMUXCR_SDHC_CD |
55 MPC85xx_PMUXCR_SDHC_WP)); 55 MPC85xx_PMUXCR_SDHC_WP));
56 56
57 #endif 57 #endif
58 return 0; 58 return 0;
59 } 59 }
60 60
61 int checkboard (void) 61 int checkboard (void)
62 { 62 {
63 u8 vboot; 63 u8 vboot;
64 u8 *pixis_base = (u8 *)PIXIS_BASE; 64 u8 *pixis_base = (u8 *)PIXIS_BASE;
65 65
66 puts("Board: MPC8536DS "); 66 puts("Board: MPC8536DS ");
67 #ifdef CONFIG_PHYS_64BIT 67 #ifdef CONFIG_PHYS_64BIT
68 puts("(36-bit addrmap) "); 68 puts("(36-bit addrmap) ");
69 #endif 69 #endif
70 70
71 printf ("Sys ID: 0x%02x, " 71 printf ("Sys ID: 0x%02x, "
72 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ", 72 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
73 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER), 73 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
74 in_8(pixis_base + PIXIS_PVER)); 74 in_8(pixis_base + PIXIS_PVER));
75 75
76 vboot = in_8(pixis_base + PIXIS_VBOOT); 76 vboot = in_8(pixis_base + PIXIS_VBOOT);
77 switch ((vboot & PIXIS_VBOOT_LBMAP) >> 5) { 77 switch ((vboot & PIXIS_VBOOT_LBMAP) >> 5) {
78 case PIXIS_VBOOT_LBMAP_NOR0: 78 case PIXIS_VBOOT_LBMAP_NOR0:
79 puts ("vBank: 0\n"); 79 puts ("vBank: 0\n");
80 break; 80 break;
81 case PIXIS_VBOOT_LBMAP_NOR1: 81 case PIXIS_VBOOT_LBMAP_NOR1:
82 puts ("vBank: 1\n"); 82 puts ("vBank: 1\n");
83 break; 83 break;
84 case PIXIS_VBOOT_LBMAP_NOR2: 84 case PIXIS_VBOOT_LBMAP_NOR2:
85 puts ("vBank: 2\n"); 85 puts ("vBank: 2\n");
86 break; 86 break;
87 case PIXIS_VBOOT_LBMAP_NOR3: 87 case PIXIS_VBOOT_LBMAP_NOR3:
88 puts ("vBank: 3\n"); 88 puts ("vBank: 3\n");
89 break; 89 break;
90 case PIXIS_VBOOT_LBMAP_PJET: 90 case PIXIS_VBOOT_LBMAP_PJET:
91 puts ("Promjet\n"); 91 puts ("Promjet\n");
92 break; 92 break;
93 case PIXIS_VBOOT_LBMAP_NAND: 93 case PIXIS_VBOOT_LBMAP_NAND:
94 puts ("NAND\n"); 94 puts ("NAND\n");
95 break; 95 break;
96 } 96 }
97 97
98 return 0; 98 return 0;
99 } 99 }
100 100
101 phys_size_t 101 phys_size_t
102 initdram(int board_type) 102 initdram(int board_type)
103 { 103 {
104 phys_size_t dram_size = 0; 104 phys_size_t dram_size = 0;
105 105
106 puts("Initializing...."); 106 puts("Initializing....");
107 107
108 #ifdef CONFIG_SPD_EEPROM 108 #ifdef CONFIG_SPD_EEPROM
109 dram_size = fsl_ddr_sdram(); 109 dram_size = fsl_ddr_sdram();
110 #else 110 #else
111 dram_size = fixed_sdram(); 111 dram_size = fixed_sdram();
112 #endif 112 #endif
113 dram_size = setup_ddr_tlbs(dram_size / 0x100000); 113 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
114 dram_size *= 0x100000; 114 dram_size *= 0x100000;
115 115
116 puts(" DDR: "); 116 puts(" DDR: ");
117 return dram_size; 117 return dram_size;
118 } 118 }
119 119
120 #if !defined(CONFIG_SPD_EEPROM) 120 #if !defined(CONFIG_SPD_EEPROM)
121 /* 121 /*
122 * Fixed sdram init -- doesn't use serial presence detect. 122 * Fixed sdram init -- doesn't use serial presence detect.
123 */ 123 */
124 124
125 phys_size_t fixed_sdram (void) 125 phys_size_t fixed_sdram (void)
126 { 126 {
127 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; 127 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
128 volatile ccsr_ddr_t *ddr= &immap->im_ddr; 128 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
129 uint d_init; 129 uint d_init;
130 130
131 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS; 131 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
132 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG; 132 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
133 133
134 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; 134 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
135 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; 135 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
136 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; 136 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
137 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; 137 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
138 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1; 138 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
139 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2; 139 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
140 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL; 140 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
141 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT; 141 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
142 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL; 142 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
143 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2; 143 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
144 144
145 #if defined (CONFIG_DDR_ECC) 145 #if defined (CONFIG_DDR_ECC)
146 ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN; 146 ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN;
147 ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS; 147 ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS;
148 ddr->err_sbe = CONFIG_SYS_DDR_SBE; 148 ddr->err_sbe = CONFIG_SYS_DDR_SBE;
149 #endif 149 #endif
150 asm("sync;isync"); 150 asm("sync;isync");
151 151
152 udelay(500); 152 udelay(500);
153 153
154 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL; 154 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
155 155
156 #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) 156 #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
157 d_init = 1; 157 d_init = 1;
158 debug("DDR - 1st controller: memory initializing\n"); 158 debug("DDR - 1st controller: memory initializing\n");
159 /* 159 /*
160 * Poll until memory is initialized. 160 * Poll until memory is initialized.
161 * 512 Meg at 400 might hit this 200 times or so. 161 * 512 Meg at 400 might hit this 200 times or so.
162 */ 162 */
163 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) { 163 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
164 udelay(1000); 164 udelay(1000);
165 } 165 }
166 debug("DDR: memory initialized\n\n"); 166 debug("DDR: memory initialized\n\n");
167 asm("sync; isync"); 167 asm("sync; isync");
168 udelay(500); 168 udelay(500);
169 #endif 169 #endif
170 170
171 return 512 * 1024 * 1024; 171 return 512 * 1024 * 1024;
172 } 172 }
173 173
174 #endif 174 #endif
175 175
176 #ifdef CONFIG_PCI1 176 #ifdef CONFIG_PCI1
177 static struct pci_controller pci1_hose; 177 static struct pci_controller pci1_hose;
178 #endif 178 #endif
179 179
180 #ifdef CONFIG_PCIE1 180 #ifdef CONFIG_PCIE1
181 static struct pci_controller pcie1_hose; 181 static struct pci_controller pcie1_hose;
182 #endif 182 #endif
183 183
184 #ifdef CONFIG_PCIE2 184 #ifdef CONFIG_PCIE2
185 static struct pci_controller pcie2_hose; 185 static struct pci_controller pcie2_hose;
186 #endif 186 #endif
187 187
188 #ifdef CONFIG_PCIE3 188 #ifdef CONFIG_PCIE3
189 static struct pci_controller pcie3_hose; 189 static struct pci_controller pcie3_hose;
190 #endif 190 #endif
191 191
192 #ifdef CONFIG_PCI 192 #ifdef CONFIG_PCI
193 void pci_init_board(void) 193 void pci_init_board(void)
194 { 194 {
195 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 195 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
196 struct fsl_pci_info pci_info[4]; 196 struct fsl_pci_info pci_info[4];
197 u32 devdisr, pordevsr, io_sel, sdrs2_io_sel; 197 u32 devdisr, pordevsr, io_sel, sdrs2_io_sel;
198 u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel; 198 u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
199 int first_free_busno = 0; 199 int first_free_busno = 0;
200 int num = 0; 200 int num = 0;
201 201
202 int pcie_ep, pcie_configured; 202 int pcie_ep, pcie_configured;
203 203
204 devdisr = in_be32(&gur->devdisr); 204 devdisr = in_be32(&gur->devdisr);
205 pordevsr = in_be32(&gur->pordevsr); 205 pordevsr = in_be32(&gur->pordevsr);
206 porpllsr = in_be32(&gur->porpllsr); 206 porpllsr = in_be32(&gur->porpllsr);
207 io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19; 207 io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
208 sdrs2_io_sel = (pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; 208 sdrs2_io_sel = (pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
209 209
210 debug(" pci_init_board: devdisr=%x, sdrs2_io_sel=%x, io_sel=%x\n", 210 debug(" pci_init_board: devdisr=%x, sdrs2_io_sel=%x, io_sel=%x\n",
211 devdisr, sdrs2_io_sel, io_sel); 211 devdisr, sdrs2_io_sel, io_sel);
212 212
213 if (sdrs2_io_sel == 7) 213 if (sdrs2_io_sel == 7)
214 printf(" Serdes2 disalbed\n"); 214 printf(" Serdes2 disalbed\n");
215 else if (sdrs2_io_sel == 4) { 215 else if (sdrs2_io_sel == 4) {
216 printf(" eTSEC1 is in sgmii mode.\n"); 216 printf(" eTSEC1 is in sgmii mode.\n");
217 printf(" eTSEC3 is in sgmii mode.\n"); 217 printf(" eTSEC3 is in sgmii mode.\n");
218 } else if (sdrs2_io_sel == 6) 218 } else if (sdrs2_io_sel == 6)
219 printf(" eTSEC1 is in sgmii mode.\n"); 219 printf(" eTSEC1 is in sgmii mode.\n");
220 220
221 puts("\n"); 221 puts("\n");
222 #ifdef CONFIG_PCIE3 222 #ifdef CONFIG_PCIE3
223 pcie_configured = is_serdes_configured(PCIE3); 223 pcie_configured = is_serdes_configured(PCIE3);
224 224
225 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE3)){ 225 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE3)){
226 set_next_law(CONFIG_SYS_PCIE3_MEM_PHYS, LAW_SIZE_512M, 226 set_next_law(CONFIG_SYS_PCIE3_MEM_PHYS, LAW_SIZE_512M,
227 LAW_TRGT_IF_PCIE_3); 227 LAW_TRGT_IF_PCIE_3);
228 set_next_law(CONFIG_SYS_PCIE3_IO_PHYS, LAW_SIZE_64K, 228 set_next_law(CONFIG_SYS_PCIE3_IO_PHYS, LAW_SIZE_64K,
229 LAW_TRGT_IF_PCIE_3); 229 LAW_TRGT_IF_PCIE_3);
230 SET_STD_PCIE_INFO(pci_info[num], 3); 230 SET_STD_PCIE_INFO(pci_info[num], 3);
231 pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info[num].regs); 231 pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info[num].regs);
232 printf (" PCIE3 connected to Slot3 as %s (base address %lx)\n", 232 printf (" PCIE3 connected to Slot3 as %s (base address %lx)\n",
233 pcie_ep ? "Endpoint" : "Root Complex", 233 pcie_ep ? "Endpoint" : "Root Complex",
234 pci_info[num].regs); 234 pci_info[num].regs);
235 first_free_busno = fsl_pci_init_port(&pci_info[num++], 235 first_free_busno = fsl_pci_init_port(&pci_info[num++],
236 &pcie3_hose, first_free_busno); 236 &pcie3_hose, first_free_busno);
237 } else { 237 } else {
238 printf (" PCIE3: disabled\n"); 238 printf (" PCIE3: disabled\n");
239 } 239 }
240 240
241 puts("\n"); 241 puts("\n");
242 #else 242 #else
243 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */ 243 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */
244 #endif 244 #endif
245 245
246 #ifdef CONFIG_PCIE1 246 #ifdef CONFIG_PCIE1
247 pcie_configured = is_serdes_configured(PCIE1); 247 pcie_configured = is_serdes_configured(PCIE1);
248 248
249 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){ 249 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
250 set_next_law(CONFIG_SYS_PCIE1_MEM_PHYS, LAW_SIZE_128M, 250 set_next_law(CONFIG_SYS_PCIE1_MEM_PHYS, LAW_SIZE_128M,
251 LAW_TRGT_IF_PCIE_1); 251 LAW_TRGT_IF_PCIE_1);
252 set_next_law(CONFIG_SYS_PCIE1_IO_PHYS, LAW_SIZE_64K, 252 set_next_law(CONFIG_SYS_PCIE1_IO_PHYS, LAW_SIZE_64K,
253 LAW_TRGT_IF_PCIE_1); 253 LAW_TRGT_IF_PCIE_1);
254 SET_STD_PCIE_INFO(pci_info[num], 1); 254 SET_STD_PCIE_INFO(pci_info[num], 1);
255 pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs); 255 pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs);
256 printf (" PCIE1 connected to Slot1 as %s (base address %lx)\n", 256 printf (" PCIE1 connected to Slot1 as %s (base address %lx)\n",
257 pcie_ep ? "Endpoint" : "Root Complex", 257 pcie_ep ? "Endpoint" : "Root Complex",
258 pci_info[num].regs); 258 pci_info[num].regs);
259 first_free_busno = fsl_pci_init_port(&pci_info[num++], 259 first_free_busno = fsl_pci_init_port(&pci_info[num++],
260 &pcie1_hose, first_free_busno); 260 &pcie1_hose, first_free_busno);
261 } else { 261 } else {
262 printf (" PCIE1: disabled\n"); 262 printf (" PCIE1: disabled\n");
263 } 263 }
264 264
265 puts("\n"); 265 puts("\n");
266 #else 266 #else
267 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */ 267 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
268 #endif 268 #endif
269 269
270 #ifdef CONFIG_PCIE2 270 #ifdef CONFIG_PCIE2
271 pcie_configured = is_serdes_configured(PCIE2); 271 pcie_configured = is_serdes_configured(PCIE2);
272 272
273 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE2)){ 273 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE2)){
274 set_next_law(CONFIG_SYS_PCIE2_MEM_PHYS, LAW_SIZE_128M, 274 set_next_law(CONFIG_SYS_PCIE2_MEM_PHYS, LAW_SIZE_128M,
275 LAW_TRGT_IF_PCIE_2); 275 LAW_TRGT_IF_PCIE_2);
276 set_next_law(CONFIG_SYS_PCIE2_IO_PHYS, LAW_SIZE_64K, 276 set_next_law(CONFIG_SYS_PCIE2_IO_PHYS, LAW_SIZE_64K,
277 LAW_TRGT_IF_PCIE_2); 277 LAW_TRGT_IF_PCIE_2);
278 SET_STD_PCIE_INFO(pci_info[num], 2); 278 SET_STD_PCIE_INFO(pci_info[num], 2);
279 pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs); 279 pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs);
280 printf (" PCIE2 connected to Slot 2 as %s (base address %lx)\n", 280 printf (" PCIE2 connected to Slot 2 as %s (base address %lx)\n",
281 pcie_ep ? "Endpoint" : "Root Complex", 281 pcie_ep ? "Endpoint" : "Root Complex",
282 pci_info[num].regs); 282 pci_info[num].regs);
283 first_free_busno = fsl_pci_init_port(&pci_info[num++], 283 first_free_busno = fsl_pci_init_port(&pci_info[num++],
284 &pcie2_hose, first_free_busno); 284 &pcie2_hose, first_free_busno);
285 } else { 285 } else {
286 printf (" PCIE2: disabled\n"); 286 printf (" PCIE2: disabled\n");
287 } 287 }
288 288
289 puts("\n"); 289 puts("\n");
290 #else 290 #else
291 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE2); /* disable */ 291 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE2); /* disable */
292 #endif 292 #endif
293 293
294 #ifdef CONFIG_PCI1 294 #ifdef CONFIG_PCI1
295 pci_speed = 66666000; 295 pci_speed = 66666000;
296 pci_32 = 1; 296 pci_32 = 1;
297 pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; 297 pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
298 pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; 298 pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
299 299
300 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) { 300 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
301 set_next_law(CONFIG_SYS_PCI1_MEM_PHYS, LAW_SIZE_256M, 301 set_next_law(CONFIG_SYS_PCI1_MEM_PHYS, LAW_SIZE_256M,
302 LAW_TRGT_IF_PCI); 302 LAW_TRGT_IF_PCI);
303 set_next_law(CONFIG_SYS_PCI1_IO_PHYS, LAW_SIZE_64K, 303 set_next_law(CONFIG_SYS_PCI1_IO_PHYS, LAW_SIZE_64K,
304 LAW_TRGT_IF_PCI); 304 LAW_TRGT_IF_PCI);
305 SET_STD_PCI_INFO(pci_info[num], 1); 305 SET_STD_PCI_INFO(pci_info[num], 1);
306 pci_agent = fsl_setup_hose(&pci1_hose, pci_info[num].regs); 306 pci_agent = fsl_setup_hose(&pci1_hose, pci_info[num].regs);
307 printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %lx)\n", 307 printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %lx)\n",
308 (pci_32) ? 32 : 64, 308 (pci_32) ? 32 : 64,
309 (pci_speed == 33333000) ? "33" : 309 (pci_speed == 33333000) ? "33" :
310 (pci_speed == 66666000) ? "66" : "unknown", 310 (pci_speed == 66666000) ? "66" : "unknown",
311 pci_clk_sel ? "sync" : "async", 311 pci_clk_sel ? "sync" : "async",
312 pci_agent ? "agent" : "host", 312 pci_agent ? "agent" : "host",
313 pci_arb ? "arbiter" : "external-arbiter", 313 pci_arb ? "arbiter" : "external-arbiter",
314 pci_info[num].regs); 314 pci_info[num].regs);
315 315
316 first_free_busno = fsl_pci_init_port(&pci_info[num++], 316 first_free_busno = fsl_pci_init_port(&pci_info[num++],
317 &pci1_hose, first_free_busno); 317 &pci1_hose, first_free_busno);
318 } else { 318 } else {
319 printf (" PCI: disabled\n"); 319 printf (" PCI: disabled\n");
320 } 320 }
321 321
322 puts("\n"); 322 puts("\n");
323 #else 323 #else
324 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */ 324 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
325 #endif 325 #endif
326 } 326 }
327 #endif 327 #endif
328 328
329 int board_early_init_r(void) 329 int board_early_init_r(void)
330 { 330 {
331 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; 331 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
332 const u8 flash_esel = find_tlb_idx((void *)flashbase, 1); 332 const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
333 333
334 /* 334 /*
335 * Remap Boot flash + PROMJET region to caching-inhibited 335 * Remap Boot flash + PROMJET region to caching-inhibited
336 * so that flash can be erased properly. 336 * so that flash can be erased properly.
337 */ 337 */
338 338
339 /* Flush d-cache and invalidate i-cache of any FLASH data */ 339 /* Flush d-cache and invalidate i-cache of any FLASH data */
340 flush_dcache(); 340 flush_dcache();
341 invalidate_icache(); 341 invalidate_icache();
342 342
343 /* invalidate existing TLB entry for flash + promjet */ 343 /* invalidate existing TLB entry for flash + promjet */
344 disable_tlb(flash_esel); 344 disable_tlb(flash_esel);
345 345
346 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */ 346 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
347 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */ 347 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
348 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */ 348 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */
349 349
350 return 0; 350 return 0;
351 } 351 }
352 352
353 #ifdef CONFIG_GET_CLK_FROM_ICS307 353 #ifdef CONFIG_GET_CLK_FROM_ICS307
354 /* decode S[0-2] to Output Divider (OD) */ 354 /* decode S[0-2] to Output Divider (OD) */
355 static unsigned char 355 static unsigned char
356 ics307_S_to_OD[] = { 356 ics307_S_to_OD[] = {
357 10, 2, 8, 4, 5, 7, 3, 6 357 10, 2, 8, 4, 5, 7, 3, 6
358 }; 358 };
359 359
360 /* Calculate frequency being generated by ICS307-02 clock chip based upon 360 /* Calculate frequency being generated by ICS307-02 clock chip based upon
361 * the control bytes being programmed into it. */ 361 * the control bytes being programmed into it. */
362 /* XXX: This function should probably go into a common library */ 362 /* XXX: This function should probably go into a common library */
363 static unsigned long 363 static unsigned long
364 ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2) 364 ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2)
365 { 365 {
366 const unsigned long long InputFrequency = CONFIG_ICS307_REFCLK_HZ; 366 const unsigned long long InputFrequency = CONFIG_ICS307_REFCLK_HZ;
367 unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1); 367 unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1);
368 unsigned long RDW = cw2 & 0x7F; 368 unsigned long RDW = cw2 & 0x7F;
369 unsigned long OD = ics307_S_to_OD[cw0 & 0x7]; 369 unsigned long OD = ics307_S_to_OD[cw0 & 0x7];
370 unsigned long freq; 370 unsigned long freq;
371 371
372 /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */ 372 /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */
373 373
374 /* cw0: C1 C0 TTL F1 F0 S2 S1 S0 374 /* cw0: C1 C0 TTL F1 F0 S2 S1 S0
375 * cw1: V8 V7 V6 V5 V4 V3 V2 V1 375 * cw1: V8 V7 V6 V5 V4 V3 V2 V1
376 * cw2: V0 R6 R5 R4 R3 R2 R1 R0 376 * cw2: V0 R6 R5 R4 R3 R2 R1 R0
377 * 377 *
378 * R6:R0 = Reference Divider Word (RDW) 378 * R6:R0 = Reference Divider Word (RDW)
379 * V8:V0 = VCO Divider Word (VDW) 379 * V8:V0 = VCO Divider Word (VDW)
380 * S2:S0 = Output Divider Select (OD) 380 * S2:S0 = Output Divider Select (OD)
381 * F1:F0 = Function of CLK2 Output 381 * F1:F0 = Function of CLK2 Output
382 * TTL = duty cycle 382 * TTL = duty cycle
383 * C1:C0 = internal load capacitance for cyrstal 383 * C1:C0 = internal load capacitance for cyrstal
384 */ 384 */
385 385
386 /* Adding 1 to get a "nicely" rounded number, but this needs 386 /* Adding 1 to get a "nicely" rounded number, but this needs
387 * more tweaking to get a "properly" rounded number. */ 387 * more tweaking to get a "properly" rounded number. */
388 388
389 freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD)); 389 freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD));
390 390
391 debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2, 391 debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2,
392 freq); 392 freq);
393 return freq; 393 return freq;
394 } 394 }
395 395
396 unsigned long 396 unsigned long
397 get_board_sys_clk(ulong dummy) 397 get_board_sys_clk(ulong dummy)
398 { 398 {
399 u8 *pixis_base = (u8 *)PIXIS_BASE; 399 u8 *pixis_base = (u8 *)PIXIS_BASE;
400 400
401 return ics307_clk_freq ( 401 return ics307_clk_freq (
402 in_8(pixis_base + PIXIS_VSYSCLK0), 402 in_8(pixis_base + PIXIS_VSYSCLK0),
403 in_8(pixis_base + PIXIS_VSYSCLK1), 403 in_8(pixis_base + PIXIS_VSYSCLK1),
404 in_8(pixis_base + PIXIS_VSYSCLK2) 404 in_8(pixis_base + PIXIS_VSYSCLK2)
405 ); 405 );
406 } 406 }
407 407
408 unsigned long 408 unsigned long
409 get_board_ddr_clk(ulong dummy) 409 get_board_ddr_clk(ulong dummy)
410 { 410 {
411 u8 *pixis_base = (u8 *)PIXIS_BASE; 411 u8 *pixis_base = (u8 *)PIXIS_BASE;
412 412
413 return ics307_clk_freq ( 413 return ics307_clk_freq (
414 in_8(pixis_base + PIXIS_VDDRCLK0), 414 in_8(pixis_base + PIXIS_VDDRCLK0),
415 in_8(pixis_base + PIXIS_VDDRCLK1), 415 in_8(pixis_base + PIXIS_VDDRCLK1),
416 in_8(pixis_base + PIXIS_VDDRCLK2) 416 in_8(pixis_base + PIXIS_VDDRCLK2)
417 ); 417 );
418 } 418 }
419 #else 419 #else
420 unsigned long 420 unsigned long
421 get_board_sys_clk(ulong dummy) 421 get_board_sys_clk(ulong dummy)
422 { 422 {
423 u8 i; 423 u8 i;
424 ulong val = 0; 424 ulong val = 0;
425 u8 *pixis_base = (u8 *)PIXIS_BASE; 425 u8 *pixis_base = (u8 *)PIXIS_BASE;
426 426
427 i = in_8(pixis_base + PIXIS_SPD); 427 i = in_8(pixis_base + PIXIS_SPD);
428 i &= 0x07; 428 i &= 0x07;
429 429
430 switch (i) { 430 switch (i) {
431 case 0: 431 case 0:
432 val = 33333333; 432 val = 33333333;
433 break; 433 break;
434 case 1: 434 case 1:
435 val = 40000000; 435 val = 40000000;
436 break; 436 break;
437 case 2: 437 case 2:
438 val = 50000000; 438 val = 50000000;
439 break; 439 break;
440 case 3: 440 case 3:
441 val = 66666666; 441 val = 66666666;
442 break; 442 break;
443 case 4: 443 case 4:
444 val = 83333333; 444 val = 83333333;
445 break; 445 break;
446 case 5: 446 case 5:
447 val = 100000000; 447 val = 100000000;
448 break; 448 break;
449 case 6: 449 case 6:
450 val = 133333333; 450 val = 133333333;
451 break; 451 break;
452 case 7: 452 case 7:
453 val = 166666666; 453 val = 166666666;
454 break; 454 break;
455 } 455 }
456 456
457 return val; 457 return val;
458 } 458 }
459 459
460 unsigned long 460 unsigned long
461 get_board_ddr_clk(ulong dummy) 461 get_board_ddr_clk(ulong dummy)
462 { 462 {
463 u8 i; 463 u8 i;
464 ulong val = 0; 464 ulong val = 0;
465 u8 *pixis_base = (u8 *)PIXIS_BASE; 465 u8 *pixis_base = (u8 *)PIXIS_BASE;
466 466
467 i = in_8(pixis_base + PIXIS_SPD); 467 i = in_8(pixis_base + PIXIS_SPD);
468 i &= 0x38; 468 i &= 0x38;
469 i >>= 3; 469 i >>= 3;
470 470
471 switch (i) { 471 switch (i) {
472 case 0: 472 case 0:
473 val = 33333333; 473 val = 33333333;
474 break; 474 break;
475 case 1: 475 case 1:
476 val = 40000000; 476 val = 40000000;
477 break; 477 break;
478 case 2: 478 case 2:
479 val = 50000000; 479 val = 50000000;
480 break; 480 break;
481 case 3: 481 case 3:
482 val = 66666666; 482 val = 66666666;
483 break; 483 break;
484 case 4: 484 case 4:
485 val = 83333333; 485 val = 83333333;
486 break; 486 break;
487 case 5: 487 case 5:
488 val = 100000000; 488 val = 100000000;
489 break; 489 break;
490 case 6: 490 case 6:
491 val = 133333333; 491 val = 133333333;
492 break; 492 break;
493 case 7: 493 case 7:
494 val = 166666666; 494 val = 166666666;
495 break; 495 break;
496 } 496 }
497 return val; 497 return val;
498 } 498 }
499 #endif 499 #endif
500 500
501 int sata_initialize(void)
502 {
503 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
504 uint sdrs2_io_sel =
505 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
506 if (sdrs2_io_sel & 0x04)
507 return 1;
508
509 return __sata_initialize();
510 }
511
512 int board_eth_init(bd_t *bis) 501 int board_eth_init(bd_t *bis)
513 { 502 {
514 #ifdef CONFIG_TSEC_ENET 503 #ifdef CONFIG_TSEC_ENET
515 struct tsec_info_struct tsec_info[2]; 504 struct tsec_info_struct tsec_info[2];
516 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 505 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
517 int num = 0; 506 int num = 0;
518 uint sdrs2_io_sel = 507 uint sdrs2_io_sel =
519 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; 508 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
520 509
521 #ifdef CONFIG_TSEC1 510 #ifdef CONFIG_TSEC1
522 SET_STD_TSEC_INFO(tsec_info[num], 1); 511 SET_STD_TSEC_INFO(tsec_info[num], 1);
523 if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) { 512 if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) {
524 tsec_info[num].phyaddr = 0; 513 tsec_info[num].phyaddr = 0;
525 tsec_info[num].flags |= TSEC_SGMII; 514 tsec_info[num].flags |= TSEC_SGMII;
526 } 515 }
527 num++; 516 num++;
528 #endif 517 #endif
529 #ifdef CONFIG_TSEC3 518 #ifdef CONFIG_TSEC3
530 SET_STD_TSEC_INFO(tsec_info[num], 3); 519 SET_STD_TSEC_INFO(tsec_info[num], 3);
531 if (sdrs2_io_sel == 4) { 520 if (sdrs2_io_sel == 4) {
532 tsec_info[num].phyaddr = 1; 521 tsec_info[num].phyaddr = 1;
533 tsec_info[num].flags |= TSEC_SGMII; 522 tsec_info[num].flags |= TSEC_SGMII;
534 } 523 }
535 num++; 524 num++;
536 #endif 525 #endif
537 526
538 if (!num) { 527 if (!num) {
539 printf("No TSECs initialized\n"); 528 printf("No TSECs initialized\n");
540 return 0; 529 return 0;
541 } 530 }
542 531
543 #ifdef CONFIG_FSL_SGMII_RISER 532 #ifdef CONFIG_FSL_SGMII_RISER
544 if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) 533 if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6))
545 fsl_sgmii_riser_init(tsec_info, num); 534 fsl_sgmii_riser_init(tsec_info, num);
546 #endif 535 #endif
547 536
548 tsec_eth_init(bis, tsec_info, num); 537 tsec_eth_init(bis, tsec_info, num);
549 #endif 538 #endif
550 return pci_eth_init(bis); 539 return pci_eth_init(bis);
551 } 540 }
552 541
553 #if defined(CONFIG_OF_BOARD_SETUP) 542 #if defined(CONFIG_OF_BOARD_SETUP)
554 void ft_board_setup(void *blob, bd_t *bd) 543 void ft_board_setup(void *blob, bd_t *bd)
555 { 544 {
556 ft_cpu_setup(blob, bd); 545 ft_cpu_setup(blob, bd);
557 546
558 #ifdef CONFIG_PCI1 547 #ifdef CONFIG_PCI1
559 ft_fsl_pci_setup(blob, "pci0", &pci1_hose); 548 ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
560 #else 549 #else
561 ft_fsl_pci_setup(blob, "pci0", NULL); 550 ft_fsl_pci_setup(blob, "pci0", NULL);
562 #endif 551 #endif
563 #ifdef CONFIG_PCIE2 552 #ifdef CONFIG_PCIE2
564 ft_fsl_pci_setup(blob, "pci1", &pcie2_hose); 553 ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
565 #else 554 #else
566 ft_fsl_pci_setup(blob, "pci1", NULL); 555 ft_fsl_pci_setup(blob, "pci1", NULL);
567 #endif 556 #endif
568 #ifdef CONFIG_PCIE2 557 #ifdef CONFIG_PCIE2
569 ft_fsl_pci_setup(blob, "pci2", &pcie1_hose); 558 ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
570 #else 559 #else
571 ft_fsl_pci_setup(blob, "pci2", NULL); 560 ft_fsl_pci_setup(blob, "pci2", NULL);
572 #endif 561 #endif
573 #ifdef CONFIG_PCIE1 562 #ifdef CONFIG_PCIE1
574 ft_fsl_pci_setup(blob, "pci3", &pcie3_hose); 563 ft_fsl_pci_setup(blob, "pci3", &pcie3_hose);
575 #else 564 #else
576 ft_fsl_pci_setup(blob, "pci3", NULL); 565 ft_fsl_pci_setup(blob, "pci3", NULL);
577 #endif 566 #endif
578 #ifdef CONFIG_FSL_SGMII_RISER 567 #ifdef CONFIG_FSL_SGMII_RISER
579 fsl_sgmii_riser_fdt_fixup(blob); 568 fsl_sgmii_riser_fdt_fixup(blob);
580 #endif 569 #endif
581 } 570 }
582 #endif 571 #endif
583 572
drivers/block/fsl_sata.c
1 /* 1 /*
2 * Copyright (C) 2008 Freescale Semiconductor, Inc. 2 * Copyright (C) 2008,2010 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com> 3 * Dave Liu <daveliu@freescale.com>
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of 7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version. 8 * the License, or (at your option) any later version.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA 18 * MA 02111-1307 USA
19 */ 19 */
20 20
21 #include <common.h> 21 #include <common.h>
22 #include <command.h> 22 #include <command.h>
23 #include <asm/io.h> 23 #include <asm/io.h>
24 #include <asm/processor.h> 24 #include <asm/processor.h>
25 #include <asm/fsl_serdes.h>
25 #include <malloc.h> 26 #include <malloc.h>
26 #include <libata.h> 27 #include <libata.h>
27 #include <fis.h> 28 #include <fis.h>
28 #include "fsl_sata.h" 29 #include "fsl_sata.h"
29 30
30 extern block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE]; 31 extern block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
31 32
32 #ifndef CONFIG_SYS_SATA1_FLAGS 33 #ifndef CONFIG_SYS_SATA1_FLAGS
33 #define CONFIG_SYS_SATA1_FLAGS FLAGS_DMA 34 #define CONFIG_SYS_SATA1_FLAGS FLAGS_DMA
34 #endif 35 #endif
35 #ifndef CONFIG_SYS_SATA2_FLAGS 36 #ifndef CONFIG_SYS_SATA2_FLAGS
36 #define CONFIG_SYS_SATA2_FLAGS FLAGS_DMA 37 #define CONFIG_SYS_SATA2_FLAGS FLAGS_DMA
37 #endif 38 #endif
38 39
39 static struct fsl_sata_info fsl_sata_info[] = { 40 static struct fsl_sata_info fsl_sata_info[] = {
40 #ifdef CONFIG_SATA1 41 #ifdef CONFIG_SATA1
41 {CONFIG_SYS_SATA1, CONFIG_SYS_SATA1_FLAGS}, 42 {CONFIG_SYS_SATA1, CONFIG_SYS_SATA1_FLAGS},
42 #else 43 #else
43 {0, 0}, 44 {0, 0},
44 #endif 45 #endif
45 #ifdef CONFIG_SATA2 46 #ifdef CONFIG_SATA2
46 {CONFIG_SYS_SATA2, CONFIG_SYS_SATA2_FLAGS}, 47 {CONFIG_SYS_SATA2, CONFIG_SYS_SATA2_FLAGS},
47 #else 48 #else
48 {0, 0}, 49 {0, 0},
49 #endif 50 #endif
50 }; 51 };
51 52
52 static inline void mdelay(unsigned long msec) 53 static inline void mdelay(unsigned long msec)
53 { 54 {
54 unsigned long i; 55 unsigned long i;
55 for (i = 0; i < msec; i++) 56 for (i = 0; i < msec; i++)
56 udelay(1000); 57 udelay(1000);
57 } 58 }
58 59
59 static inline void sdelay(unsigned long sec) 60 static inline void sdelay(unsigned long sec)
60 { 61 {
61 unsigned long i; 62 unsigned long i;
62 for (i = 0; i < sec; i++) 63 for (i = 0; i < sec; i++)
63 mdelay(1000); 64 mdelay(1000);
64 } 65 }
65 66
66 void dprint_buffer(unsigned char *buf, int len) 67 void dprint_buffer(unsigned char *buf, int len)
67 { 68 {
68 int i, j; 69 int i, j;
69 70
70 i = 0; 71 i = 0;
71 j = 0; 72 j = 0;
72 printf("\n\r"); 73 printf("\n\r");
73 74
74 for (i = 0; i < len; i++) { 75 for (i = 0; i < len; i++) {
75 printf("%02x ", *buf++); 76 printf("%02x ", *buf++);
76 j++; 77 j++;
77 if (j == 16) { 78 if (j == 16) {
78 printf("\n\r"); 79 printf("\n\r");
79 j = 0; 80 j = 0;
80 } 81 }
81 } 82 }
82 printf("\n\r"); 83 printf("\n\r");
83 } 84 }
84 85
85 static void fsl_sata_dump_sfis(struct sata_fis_d2h *s) 86 static void fsl_sata_dump_sfis(struct sata_fis_d2h *s)
86 { 87 {
87 printf("Status FIS dump:\n\r"); 88 printf("Status FIS dump:\n\r");
88 printf("fis_type: %02x\n\r", s->fis_type); 89 printf("fis_type: %02x\n\r", s->fis_type);
89 printf("pm_port_i: %02x\n\r", s->pm_port_i); 90 printf("pm_port_i: %02x\n\r", s->pm_port_i);
90 printf("status: %02x\n\r", s->status); 91 printf("status: %02x\n\r", s->status);
91 printf("error: %02x\n\r", s->error); 92 printf("error: %02x\n\r", s->error);
92 printf("lba_low: %02x\n\r", s->lba_low); 93 printf("lba_low: %02x\n\r", s->lba_low);
93 printf("lba_mid: %02x\n\r", s->lba_mid); 94 printf("lba_mid: %02x\n\r", s->lba_mid);
94 printf("lba_high: %02x\n\r", s->lba_high); 95 printf("lba_high: %02x\n\r", s->lba_high);
95 printf("device: %02x\n\r", s->device); 96 printf("device: %02x\n\r", s->device);
96 printf("lba_low_exp: %02x\n\r", s->lba_low_exp); 97 printf("lba_low_exp: %02x\n\r", s->lba_low_exp);
97 printf("lba_mid_exp: %02x\n\r", s->lba_mid_exp); 98 printf("lba_mid_exp: %02x\n\r", s->lba_mid_exp);
98 printf("lba_high_exp: %02x\n\r", s->lba_high_exp); 99 printf("lba_high_exp: %02x\n\r", s->lba_high_exp);
99 printf("res1: %02x\n\r", s->res1); 100 printf("res1: %02x\n\r", s->res1);
100 printf("sector_count: %02x\n\r", s->sector_count); 101 printf("sector_count: %02x\n\r", s->sector_count);
101 printf("sector_count_exp: %02x\n\r", s->sector_count_exp); 102 printf("sector_count_exp: %02x\n\r", s->sector_count_exp);
102 } 103 }
103 104
104 static int ata_wait_register(volatile unsigned *addr, u32 mask, 105 static int ata_wait_register(volatile unsigned *addr, u32 mask,
105 u32 val, u32 timeout_msec) 106 u32 val, u32 timeout_msec)
106 { 107 {
107 int i; 108 int i;
108 u32 temp; 109 u32 temp;
109 110
110 for (i = 0; (((temp = in_le32(addr)) & mask) != val) 111 for (i = 0; (((temp = in_le32(addr)) & mask) != val)
111 && i < timeout_msec; i++) 112 && i < timeout_msec; i++)
112 mdelay(1); 113 mdelay(1);
113 return (i < timeout_msec) ? 0 : -1; 114 return (i < timeout_msec) ? 0 : -1;
114 } 115 }
115 116
116 int init_sata(int dev) 117 int init_sata(int dev)
117 { 118 {
118 u32 length, align; 119 u32 length, align;
119 cmd_hdr_tbl_t *cmd_hdr; 120 cmd_hdr_tbl_t *cmd_hdr;
120 u32 cda; 121 u32 cda;
121 u32 val32; 122 u32 val32;
122 fsl_sata_reg_t *reg; 123 fsl_sata_reg_t *reg;
123 u32 sig; 124 u32 sig;
124 int i; 125 int i;
125 fsl_sata_t *sata; 126 fsl_sata_t *sata;
126 127
127 if (dev < 0 || dev > (CONFIG_SYS_SATA_MAX_DEVICE - 1)) { 128 if (dev < 0 || dev > (CONFIG_SYS_SATA_MAX_DEVICE - 1)) {
128 printf("the sata index %d is out of ranges\n\r", dev); 129 printf("the sata index %d is out of ranges\n\r", dev);
129 return -1; 130 return -1;
130 } 131 }
132
133 #ifdef CONFIG_MPC85xx
134 if ((dev == 0) && (!is_serdes_configured(SATA1))) {
135 printf("SATA%d [dev = %d] is not enabled\n", dev+1, dev);
136 return -1;
137 }
138 if ((dev == 1) && (!is_serdes_configured(SATA2))) {
139 printf("SATA%d [dev = %d] is not enabled\n", dev+1, dev);
140 return -1;
141 }
142 #endif
131 143
132 /* Allocate SATA device driver struct */ 144 /* Allocate SATA device driver struct */
133 sata = (fsl_sata_t *)malloc(sizeof(fsl_sata_t)); 145 sata = (fsl_sata_t *)malloc(sizeof(fsl_sata_t));
134 if (!sata) { 146 if (!sata) {
135 printf("alloc the sata device struct failed\n\r"); 147 printf("alloc the sata device struct failed\n\r");
136 return -1; 148 return -1;
137 } 149 }
138 /* Zero all of the device driver struct */ 150 /* Zero all of the device driver struct */
139 memset((void *)sata, 0, sizeof(fsl_sata_t)); 151 memset((void *)sata, 0, sizeof(fsl_sata_t));
140 152
141 /* Save the private struct to block device struct */ 153 /* Save the private struct to block device struct */
142 sata_dev_desc[dev].priv = (void *)sata; 154 sata_dev_desc[dev].priv = (void *)sata;
143 155
144 sprintf(sata->name, "SATA%d", dev); 156 sprintf(sata->name, "SATA%d", dev);
145 157
146 /* Set the controller register base address to device struct */ 158 /* Set the controller register base address to device struct */
147 reg = (fsl_sata_reg_t *)(fsl_sata_info[dev].sata_reg_base); 159 reg = (fsl_sata_reg_t *)(fsl_sata_info[dev].sata_reg_base);
148 sata->reg_base = reg; 160 sata->reg_base = reg;
149 161
150 /* Allocate the command header table, 4 bytes aligned */ 162 /* Allocate the command header table, 4 bytes aligned */
151 length = sizeof(struct cmd_hdr_tbl); 163 length = sizeof(struct cmd_hdr_tbl);
152 align = SATA_HC_CMD_HDR_TBL_ALIGN; 164 align = SATA_HC_CMD_HDR_TBL_ALIGN;
153 sata->cmd_hdr_tbl_offset = (void *)malloc(length + align); 165 sata->cmd_hdr_tbl_offset = (void *)malloc(length + align);
154 if (!sata) { 166 if (!sata) {
155 printf("alloc the command header failed\n\r"); 167 printf("alloc the command header failed\n\r");
156 return -1; 168 return -1;
157 } 169 }
158 170
159 cmd_hdr = (cmd_hdr_tbl_t *)(((u32)sata->cmd_hdr_tbl_offset + align) 171 cmd_hdr = (cmd_hdr_tbl_t *)(((u32)sata->cmd_hdr_tbl_offset + align)
160 & ~(align - 1)); 172 & ~(align - 1));
161 sata->cmd_hdr = cmd_hdr; 173 sata->cmd_hdr = cmd_hdr;
162 174
163 /* Zero all of the command header table */ 175 /* Zero all of the command header table */
164 memset((void *)sata->cmd_hdr_tbl_offset, 0, length + align); 176 memset((void *)sata->cmd_hdr_tbl_offset, 0, length + align);
165 177
166 /* Allocate command descriptor for all command */ 178 /* Allocate command descriptor for all command */
167 length = sizeof(struct cmd_desc) * SATA_HC_MAX_CMD; 179 length = sizeof(struct cmd_desc) * SATA_HC_MAX_CMD;
168 align = SATA_HC_CMD_DESC_ALIGN; 180 align = SATA_HC_CMD_DESC_ALIGN;
169 sata->cmd_desc_offset = (void *)malloc(length + align); 181 sata->cmd_desc_offset = (void *)malloc(length + align);
170 if (!sata->cmd_desc_offset) { 182 if (!sata->cmd_desc_offset) {
171 printf("alloc the command descriptor failed\n\r"); 183 printf("alloc the command descriptor failed\n\r");
172 return -1; 184 return -1;
173 } 185 }
174 sata->cmd_desc = (cmd_desc_t *)(((u32)sata->cmd_desc_offset + align) 186 sata->cmd_desc = (cmd_desc_t *)(((u32)sata->cmd_desc_offset + align)
175 & ~(align - 1)); 187 & ~(align - 1));
176 /* Zero all of command descriptor */ 188 /* Zero all of command descriptor */
177 memset((void *)sata->cmd_desc_offset, 0, length + align); 189 memset((void *)sata->cmd_desc_offset, 0, length + align);
178 190
179 /* Link the command descriptor to command header */ 191 /* Link the command descriptor to command header */
180 for (i = 0; i < SATA_HC_MAX_CMD; i++) { 192 for (i = 0; i < SATA_HC_MAX_CMD; i++) {
181 cda = ((u32)sata->cmd_desc + SATA_HC_CMD_DESC_SIZE * i) 193 cda = ((u32)sata->cmd_desc + SATA_HC_CMD_DESC_SIZE * i)
182 & ~(CMD_HDR_CDA_ALIGN - 1); 194 & ~(CMD_HDR_CDA_ALIGN - 1);
183 cmd_hdr->cmd_slot[i].cda = cpu_to_le32(cda); 195 cmd_hdr->cmd_slot[i].cda = cpu_to_le32(cda);
184 } 196 }
185 197
186 /* To have safe state, force the controller offline */ 198 /* To have safe state, force the controller offline */
187 val32 = in_le32(&reg->hcontrol); 199 val32 = in_le32(&reg->hcontrol);
188 val32 &= ~HCONTROL_ONOFF; 200 val32 &= ~HCONTROL_ONOFF;
189 val32 |= HCONTROL_FORCE_OFFLINE; 201 val32 |= HCONTROL_FORCE_OFFLINE;
190 out_le32(&reg->hcontrol, val32); 202 out_le32(&reg->hcontrol, val32);
191 203
192 /* Wait the controller offline */ 204 /* Wait the controller offline */
193 ata_wait_register(&reg->hstatus, HSTATUS_ONOFF, 0, 1000); 205 ata_wait_register(&reg->hstatus, HSTATUS_ONOFF, 0, 1000);
194 206
195 #if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_FSL_SATA_ERRATUM_A001) 207 #if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_FSL_SATA_ERRATUM_A001)
196 /* 208 /*
197 * For P1022/1013 Rev1.0 silicon, after power on SATA host 209 * For P1022/1013 Rev1.0 silicon, after power on SATA host
198 * controller is configured in legacy mode instead of the 210 * controller is configured in legacy mode instead of the
199 * expected enterprise mode. software needs to clear bit[28] 211 * expected enterprise mode. software needs to clear bit[28]
200 * of HControl register to change to enterprise mode from 212 * of HControl register to change to enterprise mode from
201 * legacy mode. 213 * legacy mode.
202 */ 214 */
203 { 215 {
204 u32 svr = get_svr(); 216 u32 svr = get_svr();
205 if (IS_SVR_REV(svr, 1, 0) && 217 if (IS_SVR_REV(svr, 1, 0) &&
206 ((SVR_SOC_VER(svr) == SVR_P1022) || 218 ((SVR_SOC_VER(svr) == SVR_P1022) ||
207 (SVR_SOC_VER(svr) == SVR_P1022_E) || 219 (SVR_SOC_VER(svr) == SVR_P1022_E) ||
208 (SVR_SOC_VER(svr) == SVR_P1013) || 220 (SVR_SOC_VER(svr) == SVR_P1013) ||
209 (SVR_SOC_VER(svr) == SVR_P1013_E))) { 221 (SVR_SOC_VER(svr) == SVR_P1013_E))) {
210 out_le32(&reg->hstatus, 0x20000000); 222 out_le32(&reg->hstatus, 0x20000000);
211 out_le32(&reg->hcontrol, 0x00000100); 223 out_le32(&reg->hcontrol, 0x00000100);
212 } 224 }
213 } 225 }
214 #endif 226 #endif
215 227
216 /* Set the command header base address to CHBA register to tell DMA */ 228 /* Set the command header base address to CHBA register to tell DMA */
217 out_le32(&reg->chba, (u32)cmd_hdr & ~0x3); 229 out_le32(&reg->chba, (u32)cmd_hdr & ~0x3);
218 230
219 /* Snoop for the command header */ 231 /* Snoop for the command header */
220 val32 = in_le32(&reg->hcontrol); 232 val32 = in_le32(&reg->hcontrol);
221 val32 |= HCONTROL_HDR_SNOOP; 233 val32 |= HCONTROL_HDR_SNOOP;
222 out_le32(&reg->hcontrol, val32); 234 out_le32(&reg->hcontrol, val32);
223 235
224 /* Disable all of interrupts */ 236 /* Disable all of interrupts */
225 val32 = in_le32(&reg->hcontrol); 237 val32 = in_le32(&reg->hcontrol);
226 val32 &= ~HCONTROL_INT_EN_ALL; 238 val32 &= ~HCONTROL_INT_EN_ALL;
227 out_le32(&reg->hcontrol, val32); 239 out_le32(&reg->hcontrol, val32);
228 240
229 /* Clear all of interrupts */ 241 /* Clear all of interrupts */
230 val32 = in_le32(&reg->hstatus); 242 val32 = in_le32(&reg->hstatus);
231 out_le32(&reg->hstatus, val32); 243 out_le32(&reg->hstatus, val32);
232 244
233 /* Set the ICC, no interrupt coalescing */ 245 /* Set the ICC, no interrupt coalescing */
234 out_le32(&reg->icc, 0x01000000); 246 out_le32(&reg->icc, 0x01000000);
235 247
236 /* No PM attatched, the SATA device direct connect */ 248 /* No PM attatched, the SATA device direct connect */
237 out_le32(&reg->cqpmp, 0); 249 out_le32(&reg->cqpmp, 0);
238 250
239 /* Clear SError register */ 251 /* Clear SError register */
240 val32 = in_le32(&reg->serror); 252 val32 = in_le32(&reg->serror);
241 out_le32(&reg->serror, val32); 253 out_le32(&reg->serror, val32);
242 254
243 /* Clear CER register */ 255 /* Clear CER register */
244 val32 = in_le32(&reg->cer); 256 val32 = in_le32(&reg->cer);
245 out_le32(&reg->cer, val32); 257 out_le32(&reg->cer, val32);
246 258
247 /* Clear DER register */ 259 /* Clear DER register */
248 val32 = in_le32(&reg->der); 260 val32 = in_le32(&reg->der);
249 out_le32(&reg->der, val32); 261 out_le32(&reg->der, val32);
250 262
251 /* No device detection or initialization action requested */ 263 /* No device detection or initialization action requested */
252 out_le32(&reg->scontrol, 0x00000300); 264 out_le32(&reg->scontrol, 0x00000300);
253 265
254 /* Configure the transport layer, default value */ 266 /* Configure the transport layer, default value */
255 out_le32(&reg->transcfg, 0x08000016); 267 out_le32(&reg->transcfg, 0x08000016);
256 268
257 /* Configure the link layer, default value */ 269 /* Configure the link layer, default value */
258 out_le32(&reg->linkcfg, 0x0000ff34); 270 out_le32(&reg->linkcfg, 0x0000ff34);
259 271
260 /* Bring the controller online */ 272 /* Bring the controller online */
261 val32 = in_le32(&reg->hcontrol); 273 val32 = in_le32(&reg->hcontrol);
262 val32 |= HCONTROL_ONOFF; 274 val32 |= HCONTROL_ONOFF;
263 out_le32(&reg->hcontrol, val32); 275 out_le32(&reg->hcontrol, val32);
264 276
265 mdelay(100); 277 mdelay(100);
266 278
267 /* print sata device name */ 279 /* print sata device name */
268 if (!dev) 280 if (!dev)
269 printf("%s ", sata->name); 281 printf("%s ", sata->name);
270 else 282 else
271 printf(" %s ", sata->name); 283 printf(" %s ", sata->name);
272 284
273 /* Wait PHY RDY signal changed for 500ms */ 285 /* Wait PHY RDY signal changed for 500ms */
274 ata_wait_register(&reg->hstatus, HSTATUS_PHY_RDY, 286 ata_wait_register(&reg->hstatus, HSTATUS_PHY_RDY,
275 HSTATUS_PHY_RDY, 500); 287 HSTATUS_PHY_RDY, 500);
276 288
277 /* Check PHYRDY */ 289 /* Check PHYRDY */
278 val32 = in_le32(&reg->hstatus); 290 val32 = in_le32(&reg->hstatus);
279 if (val32 & HSTATUS_PHY_RDY) { 291 if (val32 & HSTATUS_PHY_RDY) {
280 sata->link = 1; 292 sata->link = 1;
281 } else { 293 } else {
282 sata->link = 0; 294 sata->link = 0;
283 printf("(No RDY)\n\r"); 295 printf("(No RDY)\n\r");
284 return -1; 296 return -1;
285 } 297 }
286 298
287 /* Wait for signature updated, which is 1st D2H */ 299 /* Wait for signature updated, which is 1st D2H */
288 ata_wait_register(&reg->hstatus, HSTATUS_SIGNATURE, 300 ata_wait_register(&reg->hstatus, HSTATUS_SIGNATURE,
289 HSTATUS_SIGNATURE, 10000); 301 HSTATUS_SIGNATURE, 10000);
290 302
291 if (val32 & HSTATUS_SIGNATURE) { 303 if (val32 & HSTATUS_SIGNATURE) {
292 sig = in_le32(&reg->sig); 304 sig = in_le32(&reg->sig);
293 debug("Signature updated, the sig =%08x\n\r", sig); 305 debug("Signature updated, the sig =%08x\n\r", sig);
294 sata->ata_device_type = ata_dev_classify(sig); 306 sata->ata_device_type = ata_dev_classify(sig);
295 } 307 }
296 308
297 /* Check the speed */ 309 /* Check the speed */
298 val32 = in_le32(&reg->sstatus); 310 val32 = in_le32(&reg->sstatus);
299 if ((val32 & SSTATUS_SPD_MASK) == SSTATUS_SPD_GEN1) 311 if ((val32 & SSTATUS_SPD_MASK) == SSTATUS_SPD_GEN1)
300 printf("(1.5 Gbps)\n\r"); 312 printf("(1.5 Gbps)\n\r");
301 else if ((val32 & SSTATUS_SPD_MASK) == SSTATUS_SPD_GEN2) 313 else if ((val32 & SSTATUS_SPD_MASK) == SSTATUS_SPD_GEN2)
302 printf("(3 Gbps)\n\r"); 314 printf("(3 Gbps)\n\r");
303 315
304 return 0; 316 return 0;
305 } 317 }
306 318
307 /* Hardware reset, like Power-on and COMRESET */ 319 /* Hardware reset, like Power-on and COMRESET */
308 void fsl_sata_hardware_reset(u32 reg_base) 320 void fsl_sata_hardware_reset(u32 reg_base)
309 { 321 {
310 fsl_sata_reg_t *reg = (fsl_sata_reg_t *)reg_base; 322 fsl_sata_reg_t *reg = (fsl_sata_reg_t *)reg_base;
311 u32 scontrol; 323 u32 scontrol;
312 324
313 /* Disable the SATA interface and put PHY offline */ 325 /* Disable the SATA interface and put PHY offline */
314 scontrol = in_le32(&reg->scontrol); 326 scontrol = in_le32(&reg->scontrol);
315 scontrol = (scontrol & 0x0f0) | 0x304; 327 scontrol = (scontrol & 0x0f0) | 0x304;
316 out_le32(&reg->scontrol, scontrol); 328 out_le32(&reg->scontrol, scontrol);
317 329
318 /* No speed strict */ 330 /* No speed strict */
319 scontrol = in_le32(&reg->scontrol); 331 scontrol = in_le32(&reg->scontrol);
320 scontrol = scontrol & ~0x0f0; 332 scontrol = scontrol & ~0x0f0;
321 out_le32(&reg->scontrol, scontrol); 333 out_le32(&reg->scontrol, scontrol);
322 334
323 /* Issue PHY wake/reset, Hardware_reset_asserted */ 335 /* Issue PHY wake/reset, Hardware_reset_asserted */
324 scontrol = in_le32(&reg->scontrol); 336 scontrol = in_le32(&reg->scontrol);
325 scontrol = (scontrol & 0x0f0) | 0x301; 337 scontrol = (scontrol & 0x0f0) | 0x301;
326 out_le32(&reg->scontrol, scontrol); 338 out_le32(&reg->scontrol, scontrol);
327 339
328 mdelay(100); 340 mdelay(100);
329 341
330 /* Resume PHY, COMRESET negated, the device initialize hardware 342 /* Resume PHY, COMRESET negated, the device initialize hardware
331 * and execute diagnostics, send good status-signature to host, 343 * and execute diagnostics, send good status-signature to host,
332 * which is D2H register FIS, and then the device enter idle state. 344 * which is D2H register FIS, and then the device enter idle state.
333 */ 345 */
334 scontrol = in_le32(&reg->scontrol); 346 scontrol = in_le32(&reg->scontrol);
335 scontrol = (scontrol & 0x0f0) | 0x300; 347 scontrol = (scontrol & 0x0f0) | 0x300;
336 out_le32(&reg->scontrol, scontrol); 348 out_le32(&reg->scontrol, scontrol);
337 349
338 mdelay(100); 350 mdelay(100);
339 return; 351 return;
340 } 352 }
341 353
342 static void fsl_sata_dump_regs(fsl_sata_reg_t *reg) 354 static void fsl_sata_dump_regs(fsl_sata_reg_t *reg)
343 { 355 {
344 printf("\n\rSATA: %08x\n\r", (u32)reg); 356 printf("\n\rSATA: %08x\n\r", (u32)reg);
345 printf("CQR: %08x\n\r", in_le32(&reg->cqr)); 357 printf("CQR: %08x\n\r", in_le32(&reg->cqr));
346 printf("CAR: %08x\n\r", in_le32(&reg->car)); 358 printf("CAR: %08x\n\r", in_le32(&reg->car));
347 printf("CCR: %08x\n\r", in_le32(&reg->ccr)); 359 printf("CCR: %08x\n\r", in_le32(&reg->ccr));
348 printf("CER: %08x\n\r", in_le32(&reg->cer)); 360 printf("CER: %08x\n\r", in_le32(&reg->cer));
349 printf("CQR: %08x\n\r", in_le32(&reg->cqr)); 361 printf("CQR: %08x\n\r", in_le32(&reg->cqr));
350 printf("DER: %08x\n\r", in_le32(&reg->der)); 362 printf("DER: %08x\n\r", in_le32(&reg->der));
351 printf("CHBA: %08x\n\r", in_le32(&reg->chba)); 363 printf("CHBA: %08x\n\r", in_le32(&reg->chba));
352 printf("HStatus: %08x\n\r", in_le32(&reg->hstatus)); 364 printf("HStatus: %08x\n\r", in_le32(&reg->hstatus));
353 printf("HControl: %08x\n\r", in_le32(&reg->hcontrol)); 365 printf("HControl: %08x\n\r", in_le32(&reg->hcontrol));
354 printf("CQPMP: %08x\n\r", in_le32(&reg->cqpmp)); 366 printf("CQPMP: %08x\n\r", in_le32(&reg->cqpmp));
355 printf("SIG: %08x\n\r", in_le32(&reg->sig)); 367 printf("SIG: %08x\n\r", in_le32(&reg->sig));
356 printf("ICC: %08x\n\r", in_le32(&reg->icc)); 368 printf("ICC: %08x\n\r", in_le32(&reg->icc));
357 printf("SStatus: %08x\n\r", in_le32(&reg->sstatus)); 369 printf("SStatus: %08x\n\r", in_le32(&reg->sstatus));
358 printf("SError: %08x\n\r", in_le32(&reg->serror)); 370 printf("SError: %08x\n\r", in_le32(&reg->serror));
359 printf("SControl: %08x\n\r", in_le32(&reg->scontrol)); 371 printf("SControl: %08x\n\r", in_le32(&reg->scontrol));
360 printf("SNotification: %08x\n\r", in_le32(&reg->snotification)); 372 printf("SNotification: %08x\n\r", in_le32(&reg->snotification));
361 printf("TransCfg: %08x\n\r", in_le32(&reg->transcfg)); 373 printf("TransCfg: %08x\n\r", in_le32(&reg->transcfg));
362 printf("TransStatus: %08x\n\r", in_le32(&reg->transstatus)); 374 printf("TransStatus: %08x\n\r", in_le32(&reg->transstatus));
363 printf("LinkCfg: %08x\n\r", in_le32(&reg->linkcfg)); 375 printf("LinkCfg: %08x\n\r", in_le32(&reg->linkcfg));
364 printf("LinkCfg1: %08x\n\r", in_le32(&reg->linkcfg1)); 376 printf("LinkCfg1: %08x\n\r", in_le32(&reg->linkcfg1));
365 printf("LinkCfg2: %08x\n\r", in_le32(&reg->linkcfg2)); 377 printf("LinkCfg2: %08x\n\r", in_le32(&reg->linkcfg2));
366 printf("LinkStatus: %08x\n\r", in_le32(&reg->linkstatus)); 378 printf("LinkStatus: %08x\n\r", in_le32(&reg->linkstatus));
367 printf("LinkStatus1: %08x\n\r", in_le32(&reg->linkstatus1)); 379 printf("LinkStatus1: %08x\n\r", in_le32(&reg->linkstatus1));
368 printf("PhyCtrlCfg: %08x\n\r", in_le32(&reg->phyctrlcfg)); 380 printf("PhyCtrlCfg: %08x\n\r", in_le32(&reg->phyctrlcfg));
369 printf("SYSPR: %08x\n\r", in_be32(&reg->syspr)); 381 printf("SYSPR: %08x\n\r", in_be32(&reg->syspr));
370 } 382 }
371 383
372 static int fsl_ata_exec_ata_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis, 384 static int fsl_ata_exec_ata_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis,
373 int is_ncq, int tag, u8 *buffer, u32 len) 385 int is_ncq, int tag, u8 *buffer, u32 len)
374 { 386 {
375 cmd_hdr_entry_t *cmd_hdr; 387 cmd_hdr_entry_t *cmd_hdr;
376 cmd_desc_t *cmd_desc; 388 cmd_desc_t *cmd_desc;
377 sata_fis_h2d_t *h2d; 389 sata_fis_h2d_t *h2d;
378 prd_entry_t *prde; 390 prd_entry_t *prde;
379 u32 ext_c_ddc; 391 u32 ext_c_ddc;
380 u32 prde_count; 392 u32 prde_count;
381 u32 val32; 393 u32 val32;
382 u32 ttl; 394 u32 ttl;
383 fsl_sata_reg_t *reg = sata->reg_base; 395 fsl_sata_reg_t *reg = sata->reg_base;
384 int i; 396 int i;
385 397
386 /* Check xfer length */ 398 /* Check xfer length */
387 if (len > SATA_HC_MAX_XFER_LEN) { 399 if (len > SATA_HC_MAX_XFER_LEN) {
388 printf("max transfer length is 64MB\n\r"); 400 printf("max transfer length is 64MB\n\r");
389 return 0; 401 return 0;
390 } 402 }
391 403
392 /* Setup the command descriptor */ 404 /* Setup the command descriptor */
393 cmd_desc = sata->cmd_desc + tag; 405 cmd_desc = sata->cmd_desc + tag;
394 406
395 /* Get the pointer cfis of command descriptor */ 407 /* Get the pointer cfis of command descriptor */
396 h2d = (sata_fis_h2d_t *)cmd_desc->cfis; 408 h2d = (sata_fis_h2d_t *)cmd_desc->cfis;
397 409
398 /* Zero the cfis of command descriptor */ 410 /* Zero the cfis of command descriptor */
399 memset((void *)h2d, 0, SATA_HC_CMD_DESC_CFIS_SIZE); 411 memset((void *)h2d, 0, SATA_HC_CMD_DESC_CFIS_SIZE);
400 412
401 /* Copy the cfis from user to command descriptor */ 413 /* Copy the cfis from user to command descriptor */
402 h2d->fis_type = cfis->fis_type; 414 h2d->fis_type = cfis->fis_type;
403 h2d->pm_port_c = cfis->pm_port_c; 415 h2d->pm_port_c = cfis->pm_port_c;
404 h2d->command = cfis->command; 416 h2d->command = cfis->command;
405 417
406 h2d->features = cfis->features; 418 h2d->features = cfis->features;
407 h2d->features_exp = cfis->features_exp; 419 h2d->features_exp = cfis->features_exp;
408 420
409 h2d->lba_low = cfis->lba_low; 421 h2d->lba_low = cfis->lba_low;
410 h2d->lba_mid = cfis->lba_mid; 422 h2d->lba_mid = cfis->lba_mid;
411 h2d->lba_high = cfis->lba_high; 423 h2d->lba_high = cfis->lba_high;
412 h2d->lba_low_exp = cfis->lba_low_exp; 424 h2d->lba_low_exp = cfis->lba_low_exp;
413 h2d->lba_mid_exp = cfis->lba_mid_exp; 425 h2d->lba_mid_exp = cfis->lba_mid_exp;
414 h2d->lba_high_exp = cfis->lba_high_exp; 426 h2d->lba_high_exp = cfis->lba_high_exp;
415 427
416 if (!is_ncq) { 428 if (!is_ncq) {
417 h2d->sector_count = cfis->sector_count; 429 h2d->sector_count = cfis->sector_count;
418 h2d->sector_count_exp = cfis->sector_count_exp; 430 h2d->sector_count_exp = cfis->sector_count_exp;
419 } else { /* NCQ */ 431 } else { /* NCQ */
420 h2d->sector_count = (u8)(tag << 3); 432 h2d->sector_count = (u8)(tag << 3);
421 } 433 }
422 434
423 h2d->device = cfis->device; 435 h2d->device = cfis->device;
424 h2d->control = cfis->control; 436 h2d->control = cfis->control;
425 437
426 /* Setup the PRD table */ 438 /* Setup the PRD table */
427 prde = (prd_entry_t *)cmd_desc->prdt; 439 prde = (prd_entry_t *)cmd_desc->prdt;
428 memset((void *)prde, 0, sizeof(struct prdt)); 440 memset((void *)prde, 0, sizeof(struct prdt));
429 441
430 prde_count = 0; 442 prde_count = 0;
431 ttl = len; 443 ttl = len;
432 for (i = 0; i < SATA_HC_MAX_PRD_DIRECT; i++) { 444 for (i = 0; i < SATA_HC_MAX_PRD_DIRECT; i++) {
433 if (!len) 445 if (!len)
434 break; 446 break;
435 prde->dba = cpu_to_le32((u32)buffer & ~0x3); 447 prde->dba = cpu_to_le32((u32)buffer & ~0x3);
436 debug("dba = %08x\n\r", (u32)buffer); 448 debug("dba = %08x\n\r", (u32)buffer);
437 449
438 if (len < PRD_ENTRY_MAX_XFER_SZ) { 450 if (len < PRD_ENTRY_MAX_XFER_SZ) {
439 ext_c_ddc = PRD_ENTRY_DATA_SNOOP | len; 451 ext_c_ddc = PRD_ENTRY_DATA_SNOOP | len;
440 debug("ext_c_ddc1 = %08x, len = %08x\n\r", ext_c_ddc, len); 452 debug("ext_c_ddc1 = %08x, len = %08x\n\r", ext_c_ddc, len);
441 prde->ext_c_ddc = cpu_to_le32(ext_c_ddc); 453 prde->ext_c_ddc = cpu_to_le32(ext_c_ddc);
442 prde_count++; 454 prde_count++;
443 prde++; 455 prde++;
444 break; 456 break;
445 } else { 457 } else {
446 ext_c_ddc = PRD_ENTRY_DATA_SNOOP; /* 4M bytes */ 458 ext_c_ddc = PRD_ENTRY_DATA_SNOOP; /* 4M bytes */
447 debug("ext_c_ddc2 = %08x, len = %08x\n\r", ext_c_ddc, len); 459 debug("ext_c_ddc2 = %08x, len = %08x\n\r", ext_c_ddc, len);
448 prde->ext_c_ddc = cpu_to_le32(ext_c_ddc); 460 prde->ext_c_ddc = cpu_to_le32(ext_c_ddc);
449 buffer += PRD_ENTRY_MAX_XFER_SZ; 461 buffer += PRD_ENTRY_MAX_XFER_SZ;
450 len -= PRD_ENTRY_MAX_XFER_SZ; 462 len -= PRD_ENTRY_MAX_XFER_SZ;
451 prde_count++; 463 prde_count++;
452 prde++; 464 prde++;
453 } 465 }
454 } 466 }
455 467
456 /* Setup the command slot of cmd hdr */ 468 /* Setup the command slot of cmd hdr */
457 cmd_hdr = (cmd_hdr_entry_t *)&sata->cmd_hdr->cmd_slot[tag]; 469 cmd_hdr = (cmd_hdr_entry_t *)&sata->cmd_hdr->cmd_slot[tag];
458 470
459 cmd_hdr->cda = cpu_to_le32((u32)cmd_desc & ~0x3); 471 cmd_hdr->cda = cpu_to_le32((u32)cmd_desc & ~0x3);
460 472
461 val32 = prde_count << CMD_HDR_PRD_ENTRY_SHIFT; 473 val32 = prde_count << CMD_HDR_PRD_ENTRY_SHIFT;
462 val32 |= sizeof(sata_fis_h2d_t); 474 val32 |= sizeof(sata_fis_h2d_t);
463 cmd_hdr->prde_fis_len = cpu_to_le32(val32); 475 cmd_hdr->prde_fis_len = cpu_to_le32(val32);
464 476
465 cmd_hdr->ttl = cpu_to_le32(ttl); 477 cmd_hdr->ttl = cpu_to_le32(ttl);
466 478
467 if (!is_ncq) { 479 if (!is_ncq) {
468 val32 = CMD_HDR_ATTR_RES | CMD_HDR_ATTR_SNOOP; 480 val32 = CMD_HDR_ATTR_RES | CMD_HDR_ATTR_SNOOP;
469 } else { 481 } else {
470 val32 = CMD_HDR_ATTR_RES | CMD_HDR_ATTR_SNOOP | CMD_HDR_ATTR_FPDMA; 482 val32 = CMD_HDR_ATTR_RES | CMD_HDR_ATTR_SNOOP | CMD_HDR_ATTR_FPDMA;
471 } 483 }
472 484
473 tag &= CMD_HDR_ATTR_TAG; 485 tag &= CMD_HDR_ATTR_TAG;
474 val32 |= tag; 486 val32 |= tag;
475 487
476 debug("attribute = %08x\n\r", val32); 488 debug("attribute = %08x\n\r", val32);
477 cmd_hdr->attribute = cpu_to_le32(val32); 489 cmd_hdr->attribute = cpu_to_le32(val32);
478 490
479 /* Make sure cmd desc and cmd slot valid before commmand issue */ 491 /* Make sure cmd desc and cmd slot valid before commmand issue */
480 sync(); 492 sync();
481 493
482 /* PMP*/ 494 /* PMP*/
483 val32 = (u32)(h2d->pm_port_c & 0x0f); 495 val32 = (u32)(h2d->pm_port_c & 0x0f);
484 out_le32(&reg->cqpmp, val32); 496 out_le32(&reg->cqpmp, val32);
485 497
486 /* Wait no active */ 498 /* Wait no active */
487 if (ata_wait_register(&reg->car, (1 << tag), 0, 10000)) 499 if (ata_wait_register(&reg->car, (1 << tag), 0, 10000))
488 printf("Wait no active time out\n\r"); 500 printf("Wait no active time out\n\r");
489 501
490 /* Issue command */ 502 /* Issue command */
491 if (!(in_le32(&reg->cqr) & (1 << tag))) { 503 if (!(in_le32(&reg->cqr) & (1 << tag))) {
492 val32 = 1 << tag; 504 val32 = 1 << tag;
493 out_le32(&reg->cqr, val32); 505 out_le32(&reg->cqr, val32);
494 } 506 }
495 507
496 /* Wait command completed for 10s */ 508 /* Wait command completed for 10s */
497 if (ata_wait_register(&reg->ccr, (1 << tag), (1 << tag), 10000)) { 509 if (ata_wait_register(&reg->ccr, (1 << tag), (1 << tag), 10000)) {
498 if (!is_ncq) 510 if (!is_ncq)
499 printf("Non-NCQ command time out\n\r"); 511 printf("Non-NCQ command time out\n\r");
500 else 512 else
501 printf("NCQ command time out\n\r"); 513 printf("NCQ command time out\n\r");
502 } 514 }
503 515
504 val32 = in_le32(&reg->cer); 516 val32 = in_le32(&reg->cer);
505 517
506 if (val32) { 518 if (val32) {
507 u32 der; 519 u32 der;
508 fsl_sata_dump_sfis((struct sata_fis_d2h *)cmd_desc->sfis); 520 fsl_sata_dump_sfis((struct sata_fis_d2h *)cmd_desc->sfis);
509 printf("CE at device\n\r"); 521 printf("CE at device\n\r");
510 fsl_sata_dump_regs(reg); 522 fsl_sata_dump_regs(reg);
511 der = in_le32(&reg->der); 523 der = in_le32(&reg->der);
512 out_le32(&reg->cer, val32); 524 out_le32(&reg->cer, val32);
513 out_le32(&reg->der, der); 525 out_le32(&reg->der, der);
514 } 526 }
515 527
516 /* Clear complete flags */ 528 /* Clear complete flags */
517 val32 = in_le32(&reg->ccr); 529 val32 = in_le32(&reg->ccr);
518 out_le32(&reg->ccr, val32); 530 out_le32(&reg->ccr, val32);
519 531
520 return len; 532 return len;
521 } 533 }
522 534
523 static int fsl_ata_exec_reset_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis, 535 static int fsl_ata_exec_reset_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis,
524 int tag, u8 *buffer, u32 len) 536 int tag, u8 *buffer, u32 len)
525 { 537 {
526 return 0; 538 return 0;
527 } 539 }
528 540
529 static int fsl_sata_exec_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis, 541 static int fsl_sata_exec_cmd(struct fsl_sata *sata, struct sata_fis_h2d *cfis,
530 enum cmd_type command_type, int tag, u8 *buffer, u32 len) 542 enum cmd_type command_type, int tag, u8 *buffer, u32 len)
531 { 543 {
532 int rc; 544 int rc;
533 545
534 if (tag > SATA_HC_MAX_CMD || tag < 0) { 546 if (tag > SATA_HC_MAX_CMD || tag < 0) {
535 printf("tag is out of range, tag=%d\n\r", tag); 547 printf("tag is out of range, tag=%d\n\r", tag);
536 return -1; 548 return -1;
537 } 549 }
538 550
539 switch (command_type) { 551 switch (command_type) {
540 case CMD_ATA: 552 case CMD_ATA:
541 rc = fsl_ata_exec_ata_cmd(sata, cfis, 0, tag, buffer, len); 553 rc = fsl_ata_exec_ata_cmd(sata, cfis, 0, tag, buffer, len);
542 return rc; 554 return rc;
543 case CMD_RESET: 555 case CMD_RESET:
544 rc = fsl_ata_exec_reset_cmd(sata, cfis, tag, buffer, len); 556 rc = fsl_ata_exec_reset_cmd(sata, cfis, tag, buffer, len);
545 return rc; 557 return rc;
546 case CMD_NCQ: 558 case CMD_NCQ:
547 rc = fsl_ata_exec_ata_cmd(sata, cfis, 1, tag, buffer, len); 559 rc = fsl_ata_exec_ata_cmd(sata, cfis, 1, tag, buffer, len);
548 return rc; 560 return rc;
549 case CMD_ATAPI: 561 case CMD_ATAPI:
550 case CMD_VENDOR_BIST: 562 case CMD_VENDOR_BIST:
551 case CMD_BIST: 563 case CMD_BIST:
552 printf("not support now\n\r"); 564 printf("not support now\n\r");
553 return -1; 565 return -1;
554 default: 566 default:
555 break; 567 break;
556 } 568 }
557 569
558 return -1; 570 return -1;
559 } 571 }
560 572
561 static void fsl_sata_identify(int dev, u16 *id) 573 static void fsl_sata_identify(int dev, u16 *id)
562 { 574 {
563 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 575 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
564 struct sata_fis_h2d h2d, *cfis = &h2d; 576 struct sata_fis_h2d h2d, *cfis = &h2d;
565 577
566 memset(cfis, 0, sizeof(struct sata_fis_h2d)); 578 memset(cfis, 0, sizeof(struct sata_fis_h2d));
567 579
568 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; 580 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D;
569 cfis->pm_port_c = 0x80; /* is command */ 581 cfis->pm_port_c = 0x80; /* is command */
570 cfis->command = ATA_CMD_ID_ATA; 582 cfis->command = ATA_CMD_ID_ATA;
571 583
572 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, (u8 *)id, ATA_ID_WORDS * 2); 584 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, (u8 *)id, ATA_ID_WORDS * 2);
573 ata_swap_buf_le16(id, ATA_ID_WORDS); 585 ata_swap_buf_le16(id, ATA_ID_WORDS);
574 } 586 }
575 587
576 static void fsl_sata_xfer_mode(int dev, u16 *id) 588 static void fsl_sata_xfer_mode(int dev, u16 *id)
577 { 589 {
578 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 590 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
579 591
580 sata->pio = id[ATA_ID_PIO_MODES]; 592 sata->pio = id[ATA_ID_PIO_MODES];
581 sata->mwdma = id[ATA_ID_MWDMA_MODES]; 593 sata->mwdma = id[ATA_ID_MWDMA_MODES];
582 sata->udma = id[ATA_ID_UDMA_MODES]; 594 sata->udma = id[ATA_ID_UDMA_MODES];
583 debug("pio %04x, mwdma %04x, udma %04x\n\r", sata->pio, sata->mwdma, sata->udma); 595 debug("pio %04x, mwdma %04x, udma %04x\n\r", sata->pio, sata->mwdma, sata->udma);
584 } 596 }
585 597
586 static void fsl_sata_set_features(int dev) 598 static void fsl_sata_set_features(int dev)
587 { 599 {
588 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 600 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
589 struct sata_fis_h2d h2d, *cfis = &h2d; 601 struct sata_fis_h2d h2d, *cfis = &h2d;
590 u8 udma_cap; 602 u8 udma_cap;
591 603
592 memset(cfis, 0, sizeof(struct sata_fis_h2d)); 604 memset(cfis, 0, sizeof(struct sata_fis_h2d));
593 605
594 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; 606 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D;
595 cfis->pm_port_c = 0x80; /* is command */ 607 cfis->pm_port_c = 0x80; /* is command */
596 cfis->command = ATA_CMD_SET_FEATURES; 608 cfis->command = ATA_CMD_SET_FEATURES;
597 cfis->features = SETFEATURES_XFER; 609 cfis->features = SETFEATURES_XFER;
598 610
599 /* First check the device capablity */ 611 /* First check the device capablity */
600 udma_cap = (u8)(sata->udma & 0xff); 612 udma_cap = (u8)(sata->udma & 0xff);
601 debug("udma_cap %02x\n\r", udma_cap); 613 debug("udma_cap %02x\n\r", udma_cap);
602 614
603 if (udma_cap == ATA_UDMA6) 615 if (udma_cap == ATA_UDMA6)
604 cfis->sector_count = XFER_UDMA_6; 616 cfis->sector_count = XFER_UDMA_6;
605 if (udma_cap == ATA_UDMA5) 617 if (udma_cap == ATA_UDMA5)
606 cfis->sector_count = XFER_UDMA_5; 618 cfis->sector_count = XFER_UDMA_5;
607 if (udma_cap == ATA_UDMA4) 619 if (udma_cap == ATA_UDMA4)
608 cfis->sector_count = XFER_UDMA_4; 620 cfis->sector_count = XFER_UDMA_4;
609 if (udma_cap == ATA_UDMA3) 621 if (udma_cap == ATA_UDMA3)
610 cfis->sector_count = XFER_UDMA_3; 622 cfis->sector_count = XFER_UDMA_3;
611 623
612 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0); 624 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0);
613 } 625 }
614 626
615 static u32 fsl_sata_rw_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write) 627 static u32 fsl_sata_rw_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write)
616 { 628 {
617 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 629 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
618 struct sata_fis_h2d h2d, *cfis = &h2d; 630 struct sata_fis_h2d h2d, *cfis = &h2d;
619 u32 block; 631 u32 block;
620 632
621 block = start; 633 block = start;
622 634
623 memset(cfis, 0, sizeof(struct sata_fis_h2d)); 635 memset(cfis, 0, sizeof(struct sata_fis_h2d));
624 636
625 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; 637 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D;
626 cfis->pm_port_c = 0x80; /* is command */ 638 cfis->pm_port_c = 0x80; /* is command */
627 cfis->command = (is_write) ? ATA_CMD_WRITE : ATA_CMD_READ; 639 cfis->command = (is_write) ? ATA_CMD_WRITE : ATA_CMD_READ;
628 cfis->device = ATA_LBA; 640 cfis->device = ATA_LBA;
629 641
630 cfis->device |= (block >> 24) & 0xf; 642 cfis->device |= (block >> 24) & 0xf;
631 cfis->lba_high = (block >> 16) & 0xff; 643 cfis->lba_high = (block >> 16) & 0xff;
632 cfis->lba_mid = (block >> 8) & 0xff; 644 cfis->lba_mid = (block >> 8) & 0xff;
633 cfis->lba_low = block & 0xff; 645 cfis->lba_low = block & 0xff;
634 cfis->sector_count = (u8)(blkcnt & 0xff); 646 cfis->sector_count = (u8)(blkcnt & 0xff);
635 647
636 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, buffer, ATA_SECT_SIZE * blkcnt); 648 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, buffer, ATA_SECT_SIZE * blkcnt);
637 return blkcnt; 649 return blkcnt;
638 } 650 }
639 651
640 void fsl_sata_flush_cache(int dev) 652 void fsl_sata_flush_cache(int dev)
641 { 653 {
642 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 654 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
643 struct sata_fis_h2d h2d, *cfis = &h2d; 655 struct sata_fis_h2d h2d, *cfis = &h2d;
644 656
645 memset(cfis, 0, sizeof(struct sata_fis_h2d)); 657 memset(cfis, 0, sizeof(struct sata_fis_h2d));
646 658
647 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; 659 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D;
648 cfis->pm_port_c = 0x80; /* is command */ 660 cfis->pm_port_c = 0x80; /* is command */
649 cfis->command = ATA_CMD_FLUSH; 661 cfis->command = ATA_CMD_FLUSH;
650 662
651 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0); 663 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0);
652 } 664 }
653 665
654 static u32 fsl_sata_rw_cmd_ext(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write) 666 static u32 fsl_sata_rw_cmd_ext(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write)
655 { 667 {
656 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 668 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
657 struct sata_fis_h2d h2d, *cfis = &h2d; 669 struct sata_fis_h2d h2d, *cfis = &h2d;
658 u64 block; 670 u64 block;
659 671
660 block = (u64)start; 672 block = (u64)start;
661 673
662 memset(cfis, 0, sizeof(struct sata_fis_h2d)); 674 memset(cfis, 0, sizeof(struct sata_fis_h2d));
663 675
664 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; 676 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D;
665 cfis->pm_port_c = 0x80; /* is command */ 677 cfis->pm_port_c = 0x80; /* is command */
666 678
667 cfis->command = (is_write) ? ATA_CMD_WRITE_EXT 679 cfis->command = (is_write) ? ATA_CMD_WRITE_EXT
668 : ATA_CMD_READ_EXT; 680 : ATA_CMD_READ_EXT;
669 681
670 cfis->lba_high_exp = (block >> 40) & 0xff; 682 cfis->lba_high_exp = (block >> 40) & 0xff;
671 cfis->lba_mid_exp = (block >> 32) & 0xff; 683 cfis->lba_mid_exp = (block >> 32) & 0xff;
672 cfis->lba_low_exp = (block >> 24) & 0xff; 684 cfis->lba_low_exp = (block >> 24) & 0xff;
673 cfis->lba_high = (block >> 16) & 0xff; 685 cfis->lba_high = (block >> 16) & 0xff;
674 cfis->lba_mid = (block >> 8) & 0xff; 686 cfis->lba_mid = (block >> 8) & 0xff;
675 cfis->lba_low = block & 0xff; 687 cfis->lba_low = block & 0xff;
676 cfis->device = ATA_LBA; 688 cfis->device = ATA_LBA;
677 cfis->sector_count_exp = (blkcnt >> 8) & 0xff; 689 cfis->sector_count_exp = (blkcnt >> 8) & 0xff;
678 cfis->sector_count = blkcnt & 0xff; 690 cfis->sector_count = blkcnt & 0xff;
679 691
680 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, buffer, ATA_SECT_SIZE * blkcnt); 692 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, buffer, ATA_SECT_SIZE * blkcnt);
681 return blkcnt; 693 return blkcnt;
682 } 694 }
683 695
684 u32 fsl_sata_rw_ncq_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write) 696 u32 fsl_sata_rw_ncq_cmd(int dev, u32 start, u32 blkcnt, u8 *buffer, int is_write)
685 { 697 {
686 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 698 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
687 struct sata_fis_h2d h2d, *cfis = &h2d; 699 struct sata_fis_h2d h2d, *cfis = &h2d;
688 int ncq_channel; 700 int ncq_channel;
689 u64 block; 701 u64 block;
690 702
691 if (sata_dev_desc[dev].lba48 != 1) { 703 if (sata_dev_desc[dev].lba48 != 1) {
692 printf("execute FPDMA command on non-LBA48 hard disk\n\r"); 704 printf("execute FPDMA command on non-LBA48 hard disk\n\r");
693 return -1; 705 return -1;
694 } 706 }
695 707
696 block = (u64)start; 708 block = (u64)start;
697 709
698 memset(cfis, 0, sizeof(struct sata_fis_h2d)); 710 memset(cfis, 0, sizeof(struct sata_fis_h2d));
699 711
700 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; 712 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D;
701 cfis->pm_port_c = 0x80; /* is command */ 713 cfis->pm_port_c = 0x80; /* is command */
702 714
703 cfis->command = (is_write) ? ATA_CMD_FPDMA_WRITE 715 cfis->command = (is_write) ? ATA_CMD_FPDMA_WRITE
704 : ATA_CMD_FPDMA_READ; 716 : ATA_CMD_FPDMA_READ;
705 717
706 cfis->lba_high_exp = (block >> 40) & 0xff; 718 cfis->lba_high_exp = (block >> 40) & 0xff;
707 cfis->lba_mid_exp = (block >> 32) & 0xff; 719 cfis->lba_mid_exp = (block >> 32) & 0xff;
708 cfis->lba_low_exp = (block >> 24) & 0xff; 720 cfis->lba_low_exp = (block >> 24) & 0xff;
709 cfis->lba_high = (block >> 16) & 0xff; 721 cfis->lba_high = (block >> 16) & 0xff;
710 cfis->lba_mid = (block >> 8) & 0xff; 722 cfis->lba_mid = (block >> 8) & 0xff;
711 cfis->lba_low = block & 0xff; 723 cfis->lba_low = block & 0xff;
712 724
713 cfis->device = ATA_LBA; 725 cfis->device = ATA_LBA;
714 cfis->features_exp = (blkcnt >> 8) & 0xff; 726 cfis->features_exp = (blkcnt >> 8) & 0xff;
715 cfis->features = blkcnt & 0xff; 727 cfis->features = blkcnt & 0xff;
716 728
717 if (sata->queue_depth >= SATA_HC_MAX_CMD) 729 if (sata->queue_depth >= SATA_HC_MAX_CMD)
718 ncq_channel = SATA_HC_MAX_CMD - 1; 730 ncq_channel = SATA_HC_MAX_CMD - 1;
719 else 731 else
720 ncq_channel = sata->queue_depth - 1; 732 ncq_channel = sata->queue_depth - 1;
721 733
722 /* Use the latest queue */ 734 /* Use the latest queue */
723 fsl_sata_exec_cmd(sata, cfis, CMD_NCQ, ncq_channel, buffer, ATA_SECT_SIZE * blkcnt); 735 fsl_sata_exec_cmd(sata, cfis, CMD_NCQ, ncq_channel, buffer, ATA_SECT_SIZE * blkcnt);
724 return blkcnt; 736 return blkcnt;
725 } 737 }
726 738
727 void fsl_sata_flush_cache_ext(int dev) 739 void fsl_sata_flush_cache_ext(int dev)
728 { 740 {
729 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 741 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
730 struct sata_fis_h2d h2d, *cfis = &h2d; 742 struct sata_fis_h2d h2d, *cfis = &h2d;
731 743
732 memset(cfis, 0, sizeof(struct sata_fis_h2d)); 744 memset(cfis, 0, sizeof(struct sata_fis_h2d));
733 745
734 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D; 746 cfis->fis_type = SATA_FIS_TYPE_REGISTER_H2D;
735 cfis->pm_port_c = 0x80; /* is command */ 747 cfis->pm_port_c = 0x80; /* is command */
736 cfis->command = ATA_CMD_FLUSH_EXT; 748 cfis->command = ATA_CMD_FLUSH_EXT;
737 749
738 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0); 750 fsl_sata_exec_cmd(sata, cfis, CMD_ATA, 0, NULL, 0);
739 } 751 }
740 752
741 /* Software reset, set SRST of the Device Control register */ 753 /* Software reset, set SRST of the Device Control register */
742 void fsl_sata_software_reset(int dev) 754 void fsl_sata_software_reset(int dev)
743 { 755 {
744 return; 756 return;
745 } 757 }
746 758
747 static void fsl_sata_init_wcache(int dev, u16 *id) 759 static void fsl_sata_init_wcache(int dev, u16 *id)
748 { 760 {
749 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 761 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
750 762
751 if (ata_id_has_wcache(id) && ata_id_wcache_enabled(id)) 763 if (ata_id_has_wcache(id) && ata_id_wcache_enabled(id))
752 sata->wcache = 1; 764 sata->wcache = 1;
753 if (ata_id_has_flush(id)) 765 if (ata_id_has_flush(id))
754 sata->flush = 1; 766 sata->flush = 1;
755 if (ata_id_has_flush_ext(id)) 767 if (ata_id_has_flush_ext(id))
756 sata->flush_ext = 1; 768 sata->flush_ext = 1;
757 } 769 }
758 770
759 static int fsl_sata_get_wcache(int dev) 771 static int fsl_sata_get_wcache(int dev)
760 { 772 {
761 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 773 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
762 return sata->wcache; 774 return sata->wcache;
763 } 775 }
764 776
765 static int fsl_sata_get_flush(int dev) 777 static int fsl_sata_get_flush(int dev)
766 { 778 {
767 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 779 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
768 return sata->flush; 780 return sata->flush;
769 } 781 }
770 782
771 static int fsl_sata_get_flush_ext(int dev) 783 static int fsl_sata_get_flush_ext(int dev)
772 { 784 {
773 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 785 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
774 return sata->flush_ext; 786 return sata->flush_ext;
775 } 787 }
776 788
777 u32 ata_low_level_rw_lba48(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_write) 789 u32 ata_low_level_rw_lba48(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_write)
778 { 790 {
779 u32 start, blks; 791 u32 start, blks;
780 u8 *addr; 792 u8 *addr;
781 int max_blks; 793 int max_blks;
782 794
783 start = blknr; 795 start = blknr;
784 blks = blkcnt; 796 blks = blkcnt;
785 addr = (u8 *)buffer; 797 addr = (u8 *)buffer;
786 798
787 max_blks = ATA_MAX_SECTORS_LBA48; 799 max_blks = ATA_MAX_SECTORS_LBA48;
788 do { 800 do {
789 if (blks > max_blks) { 801 if (blks > max_blks) {
790 if (fsl_sata_info[dev].flags != FLAGS_FPDMA) 802 if (fsl_sata_info[dev].flags != FLAGS_FPDMA)
791 fsl_sata_rw_cmd_ext(dev, start, max_blks, addr, is_write); 803 fsl_sata_rw_cmd_ext(dev, start, max_blks, addr, is_write);
792 else 804 else
793 fsl_sata_rw_ncq_cmd(dev, start, max_blks, addr, is_write); 805 fsl_sata_rw_ncq_cmd(dev, start, max_blks, addr, is_write);
794 start += max_blks; 806 start += max_blks;
795 blks -= max_blks; 807 blks -= max_blks;
796 addr += ATA_SECT_SIZE * max_blks; 808 addr += ATA_SECT_SIZE * max_blks;
797 } else { 809 } else {
798 if (fsl_sata_info[dev].flags != FLAGS_FPDMA) 810 if (fsl_sata_info[dev].flags != FLAGS_FPDMA)
799 fsl_sata_rw_cmd_ext(dev, start, blks, addr, is_write); 811 fsl_sata_rw_cmd_ext(dev, start, blks, addr, is_write);
800 else 812 else
801 fsl_sata_rw_ncq_cmd(dev, start, blks, addr, is_write); 813 fsl_sata_rw_ncq_cmd(dev, start, blks, addr, is_write);
802 start += blks; 814 start += blks;
803 blks = 0; 815 blks = 0;
804 addr += ATA_SECT_SIZE * blks; 816 addr += ATA_SECT_SIZE * blks;
805 } 817 }
806 } while (blks != 0); 818 } while (blks != 0);
807 819
808 return blkcnt; 820 return blkcnt;
809 } 821 }
810 822
811 u32 ata_low_level_rw_lba28(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_write) 823 u32 ata_low_level_rw_lba28(int dev, u32 blknr, u32 blkcnt, void *buffer, int is_write)
812 { 824 {
813 u32 start, blks; 825 u32 start, blks;
814 u8 *addr; 826 u8 *addr;
815 int max_blks; 827 int max_blks;
816 828
817 start = blknr; 829 start = blknr;
818 blks = blkcnt; 830 blks = blkcnt;
819 addr = (u8 *)buffer; 831 addr = (u8 *)buffer;
820 832
821 max_blks = ATA_MAX_SECTORS; 833 max_blks = ATA_MAX_SECTORS;
822 do { 834 do {
823 if (blks > max_blks) { 835 if (blks > max_blks) {
824 fsl_sata_rw_cmd(dev, start, max_blks, addr, is_write); 836 fsl_sata_rw_cmd(dev, start, max_blks, addr, is_write);
825 start += max_blks; 837 start += max_blks;
826 blks -= max_blks; 838 blks -= max_blks;
827 addr += ATA_SECT_SIZE * max_blks; 839 addr += ATA_SECT_SIZE * max_blks;
828 } else { 840 } else {
829 fsl_sata_rw_cmd(dev, start, blks, addr, is_write); 841 fsl_sata_rw_cmd(dev, start, blks, addr, is_write);
830 start += blks; 842 start += blks;
831 blks = 0; 843 blks = 0;
832 addr += ATA_SECT_SIZE * blks; 844 addr += ATA_SECT_SIZE * blks;
833 } 845 }
834 } while (blks != 0); 846 } while (blks != 0);
835 847
836 return blkcnt; 848 return blkcnt;
837 } 849 }
838 850
839 /* 851 /*
840 * SATA interface between low level driver and command layer 852 * SATA interface between low level driver and command layer
841 */ 853 */
842 ulong sata_read(int dev, u32 blknr, u32 blkcnt, void *buffer) 854 ulong sata_read(int dev, u32 blknr, u32 blkcnt, void *buffer)
843 { 855 {
844 u32 rc; 856 u32 rc;
845 857
846 if (sata_dev_desc[dev].lba48) 858 if (sata_dev_desc[dev].lba48)
847 rc = ata_low_level_rw_lba48(dev, blknr, blkcnt, buffer, READ_CMD); 859 rc = ata_low_level_rw_lba48(dev, blknr, blkcnt, buffer, READ_CMD);
848 else 860 else
849 rc = ata_low_level_rw_lba28(dev, blknr, blkcnt, buffer, READ_CMD); 861 rc = ata_low_level_rw_lba28(dev, blknr, blkcnt, buffer, READ_CMD);
850 return rc; 862 return rc;
851 } 863 }
852 864
853 ulong sata_write(int dev, u32 blknr, u32 blkcnt, void *buffer) 865 ulong sata_write(int dev, u32 blknr, u32 blkcnt, void *buffer)
854 { 866 {
855 u32 rc; 867 u32 rc;
856 868
857 if (sata_dev_desc[dev].lba48) { 869 if (sata_dev_desc[dev].lba48) {
858 rc = ata_low_level_rw_lba48(dev, blknr, blkcnt, buffer, WRITE_CMD); 870 rc = ata_low_level_rw_lba48(dev, blknr, blkcnt, buffer, WRITE_CMD);
859 if (fsl_sata_get_wcache(dev) && fsl_sata_get_flush_ext(dev)) 871 if (fsl_sata_get_wcache(dev) && fsl_sata_get_flush_ext(dev))
860 fsl_sata_flush_cache_ext(dev); 872 fsl_sata_flush_cache_ext(dev);
861 } else { 873 } else {
862 rc = ata_low_level_rw_lba28(dev, blknr, blkcnt, buffer, WRITE_CMD); 874 rc = ata_low_level_rw_lba28(dev, blknr, blkcnt, buffer, WRITE_CMD);
863 if (fsl_sata_get_wcache(dev) && fsl_sata_get_flush(dev)) 875 if (fsl_sata_get_wcache(dev) && fsl_sata_get_flush(dev))
864 fsl_sata_flush_cache(dev); 876 fsl_sata_flush_cache(dev);
865 } 877 }
866 return rc; 878 return rc;
867 } 879 }
868 880
869 int scan_sata(int dev) 881 int scan_sata(int dev)
870 { 882 {
871 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv; 883 fsl_sata_t *sata = (fsl_sata_t *)sata_dev_desc[dev].priv;
872 unsigned char serial[ATA_ID_SERNO_LEN + 1]; 884 unsigned char serial[ATA_ID_SERNO_LEN + 1];
873 unsigned char firmware[ATA_ID_FW_REV_LEN + 1]; 885 unsigned char firmware[ATA_ID_FW_REV_LEN + 1];
874 unsigned char product[ATA_ID_PROD_LEN + 1]; 886 unsigned char product[ATA_ID_PROD_LEN + 1];
875 u16 *id; 887 u16 *id;
876 u64 n_sectors; 888 u64 n_sectors;
877 889
878 /* if no detected link */ 890 /* if no detected link */
879 if (!sata->link) 891 if (!sata->link)
880 return -1; 892 return -1;
881 893
882 id = (u16 *)malloc(ATA_ID_WORDS * 2); 894 id = (u16 *)malloc(ATA_ID_WORDS * 2);
883 if (!id) { 895 if (!id) {
884 printf("id malloc failed\n\r"); 896 printf("id malloc failed\n\r");
885 return -1; 897 return -1;
886 } 898 }
887 899
888 /* Identify device to get information */ 900 /* Identify device to get information */
889 fsl_sata_identify(dev, id); 901 fsl_sata_identify(dev, id);
890 902
891 /* Serial number */ 903 /* Serial number */
892 ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial)); 904 ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
893 memcpy(sata_dev_desc[dev].product, serial, sizeof(serial)); 905 memcpy(sata_dev_desc[dev].product, serial, sizeof(serial));
894 906
895 /* Firmware version */ 907 /* Firmware version */
896 ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware)); 908 ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware));
897 memcpy(sata_dev_desc[dev].revision, firmware, sizeof(firmware)); 909 memcpy(sata_dev_desc[dev].revision, firmware, sizeof(firmware));
898 910
899 /* Product model */ 911 /* Product model */
900 ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product)); 912 ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product));
901 memcpy(sata_dev_desc[dev].vendor, product, sizeof(product)); 913 memcpy(sata_dev_desc[dev].vendor, product, sizeof(product));
902 914
903 /* Totoal sectors */ 915 /* Totoal sectors */
904 n_sectors = ata_id_n_sectors(id); 916 n_sectors = ata_id_n_sectors(id);
905 sata_dev_desc[dev].lba = (u32)n_sectors; 917 sata_dev_desc[dev].lba = (u32)n_sectors;
906 918
907 /* Check if support LBA48 */ 919 /* Check if support LBA48 */
908 if (ata_id_has_lba48(id)) { 920 if (ata_id_has_lba48(id)) {
909 sata_dev_desc[dev].lba48 = 1; 921 sata_dev_desc[dev].lba48 = 1;
910 debug("Device support LBA48\n\r"); 922 debug("Device support LBA48\n\r");
911 } 923 }
912 924
913 /* Get the NCQ queue depth from device */ 925 /* Get the NCQ queue depth from device */
914 sata->queue_depth = ata_id_queue_depth(id); 926 sata->queue_depth = ata_id_queue_depth(id);
915 927
916 /* Get the xfer mode from device */ 928 /* Get the xfer mode from device */
917 fsl_sata_xfer_mode(dev, id); 929 fsl_sata_xfer_mode(dev, id);
918 930
919 /* Get the write cache status from device */ 931 /* Get the write cache status from device */
920 fsl_sata_init_wcache(dev, id); 932 fsl_sata_init_wcache(dev, id);
921 933
922 /* Set the xfer mode to highest speed */ 934 /* Set the xfer mode to highest speed */
923 fsl_sata_set_features(dev); 935 fsl_sata_set_features(dev);
924 #ifdef DEBUG 936 #ifdef DEBUG
925 fsl_sata_identify(dev, id); 937 fsl_sata_identify(dev, id);
926 ata_dump_id(id); 938 ata_dump_id(id);
927 #endif 939 #endif
928 free((void *)id); 940 free((void *)id);
929 return 0; 941 return 0;
930 } 942 }
931 943