Commit 04de09f89bbc647d5b72db3512d1af1475a13bbd

Authored by Tom Rini

Merge branch 'topic/arm/socfpga-20141006' of git://git.denx.de/u-boot-socfpga

Fix a trivial conflict in dw_mmc.c after talking with Marek.

Conflicts:
	drivers/mmc/dw_mmc.c

Signed-off-by: Tom Rini <trini@ti.com>

Showing 37 changed files Side-by-side Diff

arch/arm/cpu/armv7/socfpga/Makefile
... ... @@ -8,6 +8,7 @@
8 8 #
9 9  
10 10 obj-y := lowlevel_init.o
11   -obj-y += misc.o timer.o reset_manager.o system_manager.o clock_manager.o
  11 +obj-y += misc.o timer.o reset_manager.o system_manager.o clock_manager.o \
  12 + fpga_manager.o
12 13 obj-$(CONFIG_SPL_BUILD) += spl.o freeze_controller.o scan_manager.o
arch/arm/cpu/armv7/socfpga/clock_manager.c
... ... @@ -8,38 +8,28 @@
8 8 #include <asm/io.h>
9 9 #include <asm/arch/clock_manager.h>
10 10  
  11 +DECLARE_GLOBAL_DATA_PTR;
  12 +
11 13 static const struct socfpga_clock_manager *clock_manager_base =
12   - (void *)SOCFPGA_CLKMGR_ADDRESS;
  14 + (struct socfpga_clock_manager *)SOCFPGA_CLKMGR_ADDRESS;
13 15  
14   -#define CLKMGR_BYPASS_ENABLE 1
15   -#define CLKMGR_BYPASS_DISABLE 0
16   -#define CLKMGR_STAT_IDLE 0
17   -#define CLKMGR_STAT_BUSY 1
18   -#define CLKMGR_BYPASS_PERPLLSRC_SELECT_EOSC1 0
19   -#define CLKMGR_BYPASS_PERPLLSRC_SELECT_INPUT_MUX 1
20   -#define CLKMGR_BYPASS_SDRPLLSRC_SELECT_EOSC1 0
21   -#define CLKMGR_BYPASS_SDRPLLSRC_SELECT_INPUT_MUX 1
22   -
23   -#define CLEAR_BGP_EN_PWRDN \
24   - (CLKMGR_MAINPLLGRP_VCO_PWRDN_SET(0)| \
25   - CLKMGR_MAINPLLGRP_VCO_EN_SET(0)| \
26   - CLKMGR_MAINPLLGRP_VCO_BGPWRDN_SET(0))
27   -
28   -#define VCO_EN_BASE \
29   - (CLKMGR_MAINPLLGRP_VCO_PWRDN_SET(0)| \
30   - CLKMGR_MAINPLLGRP_VCO_EN_SET(1)| \
31   - CLKMGR_MAINPLLGRP_VCO_BGPWRDN_SET(0))
32   -
33   -static inline void cm_wait_for_lock(uint32_t mask)
  16 +static void cm_wait_for_lock(uint32_t mask)
34 17 {
35 18 register uint32_t inter_val;
  19 + uint32_t retry = 0;
36 20 do {
37 21 inter_val = readl(&clock_manager_base->inter) & mask;
38   - } while (inter_val != mask);
  22 + if (inter_val == mask)
  23 + retry++;
  24 + else
  25 + retry = 0;
  26 + if (retry >= 10)
  27 + break;
  28 + } while (1);
39 29 }
40 30  
41 31 /* function to poll in the fsm busy bit */
42   -static inline void cm_wait_for_fsm(void)
  32 +static void cm_wait_for_fsm(void)
43 33 {
44 34 while (readl(&clock_manager_base->stat) & CLKMGR_STAT_BUSY)
45 35 ;
46 36  
47 37  
... ... @@ -49,22 +39,22 @@
49 39 * function to write the bypass register which requires a poll of the
50 40 * busy bit
51 41 */
52   -static inline void cm_write_bypass(uint32_t val)
  42 +static void cm_write_bypass(uint32_t val)
53 43 {
54 44 writel(val, &clock_manager_base->bypass);
55 45 cm_wait_for_fsm();
56 46 }
57 47  
58 48 /* function to write the ctrl register which requires a poll of the busy bit */
59   -static inline void cm_write_ctrl(uint32_t val)
  49 +static void cm_write_ctrl(uint32_t val)
60 50 {
61 51 writel(val, &clock_manager_base->ctrl);
62 52 cm_wait_for_fsm();
63 53 }
64 54  
65 55 /* function to write a clock register that has phase information */
66   -static inline void cm_write_with_phase(uint32_t value,
67   - uint32_t reg_address, uint32_t mask)
  56 +static void cm_write_with_phase(uint32_t value,
  57 + uint32_t reg_address, uint32_t mask)
68 58 {
69 59 /* poll until phase is zero */
70 60 while (readl(reg_address) & mask)
71 61  
72 62  
73 63  
... ... @@ -128,24 +118,18 @@
128 118 writel(0, &clock_manager_base->per_pll.en);
129 119  
130 120 /* Put all plls in bypass */
131   - cm_write_bypass(
132   - CLKMGR_BYPASS_PERPLLSRC_SET(
133   - CLKMGR_BYPASS_PERPLLSRC_SELECT_EOSC1) |
134   - CLKMGR_BYPASS_SDRPLLSRC_SET(
135   - CLKMGR_BYPASS_SDRPLLSRC_SELECT_EOSC1) |
136   - CLKMGR_BYPASS_PERPLL_SET(CLKMGR_BYPASS_ENABLE) |
137   - CLKMGR_BYPASS_SDRPLL_SET(CLKMGR_BYPASS_ENABLE) |
138   - CLKMGR_BYPASS_MAINPLL_SET(CLKMGR_BYPASS_ENABLE));
  121 + cm_write_bypass(CLKMGR_BYPASS_PERPLL | CLKMGR_BYPASS_SDRPLL |
  122 + CLKMGR_BYPASS_MAINPLL);
139 123  
140   - /*
141   - * Put all plls VCO registers back to reset value.
142   - * Some code might have messed with them.
143   - */
144   - writel(CLKMGR_MAINPLLGRP_VCO_RESET_VALUE,
  124 + /* Put all plls VCO registers back to reset value. */
  125 + writel(CLKMGR_MAINPLLGRP_VCO_RESET_VALUE &
  126 + ~CLKMGR_MAINPLLGRP_VCO_REGEXTSEL_MASK,
145 127 &clock_manager_base->main_pll.vco);
146   - writel(CLKMGR_PERPLLGRP_VCO_RESET_VALUE,
  128 + writel(CLKMGR_PERPLLGRP_VCO_RESET_VALUE &
  129 + ~CLKMGR_PERPLLGRP_VCO_REGEXTSEL_MASK,
147 130 &clock_manager_base->per_pll.vco);
148   - writel(CLKMGR_SDRPLLGRP_VCO_RESET_VALUE,
  131 + writel(CLKMGR_SDRPLLGRP_VCO_RESET_VALUE &
  132 + ~CLKMGR_SDRPLLGRP_VCO_REGEXTSEL_MASK,
149 133 &clock_manager_base->sdr_pll.vco);
150 134  
151 135 /*
152 136  
... ... @@ -170,20 +154,10 @@
170 154 * We made sure bgpwr down was assert for 5 us. Now deassert BG PWR DN
171 155 * with numerator and denominator.
172 156 */
173   - writel(cfg->main_vco_base | CLEAR_BGP_EN_PWRDN |
174   - CLKMGR_MAINPLLGRP_VCO_REGEXTSEL_MASK,
175   - &clock_manager_base->main_pll.vco);
  157 + writel(cfg->main_vco_base, &clock_manager_base->main_pll.vco);
  158 + writel(cfg->peri_vco_base, &clock_manager_base->per_pll.vco);
  159 + writel(cfg->sdram_vco_base, &clock_manager_base->sdr_pll.vco);
176 160  
177   - writel(cfg->peri_vco_base | CLEAR_BGP_EN_PWRDN |
178   - CLKMGR_PERPLLGRP_VCO_REGEXTSEL_MASK,
179   - &clock_manager_base->per_pll.vco);
180   -
181   - writel(CLKMGR_SDRPLLGRP_VCO_OUTRESET_SET(0) |
182   - CLKMGR_SDRPLLGRP_VCO_OUTRESETALL_SET(0) |
183   - cfg->sdram_vco_base | CLEAR_BGP_EN_PWRDN |
184   - CLKMGR_SDRPLLGRP_VCO_REGEXTSEL_MASK,
185   - &clock_manager_base->sdr_pll.vco);
186   -
187 161 /*
188 162 * Time starts here
189 163 * must wait 7 us from BGPWRDN_SET(0) to VCO_ENABLE_SET(1)
... ... @@ -217,6 +191,9 @@
217 191 writel(cfg->perqspiclk, &clock_manager_base->per_pll.perqspiclk);
218 192  
219 193 /* Peri pernandsdmmcclk */
  194 + writel(cfg->mainnandsdmmcclk,
  195 + &clock_manager_base->main_pll.mainnandsdmmcclk);
  196 +
220 197 writel(cfg->pernandsdmmcclk,
221 198 &clock_manager_base->per_pll.pernandsdmmcclk);
222 199  
223 200  
224 201  
... ... @@ -232,18 +209,16 @@
232 209  
233 210 /* Enable vco */
234 211 /* main pll vco */
235   - writel(cfg->main_vco_base | VCO_EN_BASE,
  212 + writel(cfg->main_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
236 213 &clock_manager_base->main_pll.vco);
237 214  
238 215 /* periferal pll */
239   - writel(cfg->peri_vco_base | VCO_EN_BASE,
  216 + writel(cfg->peri_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
240 217 &clock_manager_base->per_pll.vco);
241 218  
242 219 /* sdram pll vco */
243   - writel(CLKMGR_SDRPLLGRP_VCO_OUTRESET_SET(0) |
244   - CLKMGR_SDRPLLGRP_VCO_OUTRESETALL_SET(0) |
245   - cfg->sdram_vco_base | VCO_EN_BASE,
246   - &clock_manager_base->sdr_pll.vco);
  220 + writel(cfg->sdram_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
  221 + &clock_manager_base->sdr_pll.vco);
247 222  
248 223 /* L3 MP and L3 SP */
249 224 writel(cfg->maindiv, &clock_manager_base->main_pll.maindiv);
... ... @@ -294,8 +269,8 @@
294 269 &clock_manager_base->per_pll.vco);
295 270  
296 271 /* assert sdram outresetall */
297   - writel(cfg->sdram_vco_base | VCO_EN_BASE|
298   - CLKMGR_SDRPLLGRP_VCO_OUTRESETALL_SET(1),
  272 + writel(cfg->sdram_vco_base | CLKMGR_MAINPLLGRP_VCO_EN|
  273 + CLKMGR_SDRPLLGRP_VCO_OUTRESETALL,
299 274 &clock_manager_base->sdr_pll.vco);
300 275  
301 276 /* deassert main outresetall */
... ... @@ -307,9 +282,8 @@
307 282 &clock_manager_base->per_pll.vco);
308 283  
309 284 /* deassert sdram outresetall */
310   - writel(CLKMGR_SDRPLLGRP_VCO_OUTRESETALL_SET(0) |
311   - cfg->sdram_vco_base | VCO_EN_BASE,
312   - &clock_manager_base->sdr_pll.vco);
  285 + writel(cfg->sdram_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
  286 + &clock_manager_base->sdr_pll.vco);
313 287  
314 288 /*
315 289 * now that we've toggled outreset all, all the clocks
316 290  
... ... @@ -333,18 +307,10 @@
333 307 CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_MASK);
334 308  
335 309 /* Take all three PLLs out of bypass when safe mode is cleared. */
336   - cm_write_bypass(
337   - CLKMGR_BYPASS_PERPLLSRC_SET(
338   - CLKMGR_BYPASS_PERPLLSRC_SELECT_EOSC1) |
339   - CLKMGR_BYPASS_SDRPLLSRC_SET(
340   - CLKMGR_BYPASS_SDRPLLSRC_SELECT_EOSC1) |
341   - CLKMGR_BYPASS_PERPLL_SET(CLKMGR_BYPASS_DISABLE) |
342   - CLKMGR_BYPASS_SDRPLL_SET(CLKMGR_BYPASS_DISABLE) |
343   - CLKMGR_BYPASS_MAINPLL_SET(CLKMGR_BYPASS_DISABLE));
  310 + cm_write_bypass(0);
344 311  
345 312 /* clear safe mode */
346   - cm_write_ctrl(readl(&clock_manager_base->ctrl) |
347   - CLKMGR_CTRL_SAFEMODE_SET(CLKMGR_CTRL_SAFEMODE_MASK));
  313 + cm_write_ctrl(readl(&clock_manager_base->ctrl) | CLKMGR_CTRL_SAFEMODE);
348 314  
349 315 /*
350 316 * now that safe mode is clear with clocks gated
351 317  
... ... @@ -357,5 +323,225 @@
357 323 writel(~0, &clock_manager_base->main_pll.en);
358 324 writel(~0, &clock_manager_base->per_pll.en);
359 325 writel(~0, &clock_manager_base->sdr_pll.en);
  326 +
  327 + /* Clear the loss of lock bits (write 1 to clear) */
  328 + writel(CLKMGR_INTER_SDRPLLLOST_MASK | CLKMGR_INTER_PERPLLLOST_MASK |
  329 + CLKMGR_INTER_MAINPLLLOST_MASK,
  330 + &clock_manager_base->inter);
360 331 }
  332 +
  333 +static unsigned int cm_get_main_vco_clk_hz(void)
  334 +{
  335 + uint32_t reg, clock;
  336 +
  337 + /* get the main VCO clock */
  338 + reg = readl(&clock_manager_base->main_pll.vco);
  339 + clock = CONFIG_HPS_CLK_OSC1_HZ;
  340 + clock /= ((reg & CLKMGR_MAINPLLGRP_VCO_DENOM_MASK) >>
  341 + CLKMGR_MAINPLLGRP_VCO_DENOM_OFFSET) + 1;
  342 + clock *= ((reg & CLKMGR_MAINPLLGRP_VCO_NUMER_MASK) >>
  343 + CLKMGR_MAINPLLGRP_VCO_NUMER_OFFSET) + 1;
  344 +
  345 + return clock;
  346 +}
  347 +
  348 +static unsigned int cm_get_per_vco_clk_hz(void)
  349 +{
  350 + uint32_t reg, clock = 0;
  351 +
  352 + /* identify PER PLL clock source */
  353 + reg = readl(&clock_manager_base->per_pll.vco);
  354 + reg = (reg & CLKMGR_PERPLLGRP_VCO_SSRC_MASK) >>
  355 + CLKMGR_PERPLLGRP_VCO_SSRC_OFFSET;
  356 + if (reg == CLKMGR_VCO_SSRC_EOSC1)
  357 + clock = CONFIG_HPS_CLK_OSC1_HZ;
  358 + else if (reg == CLKMGR_VCO_SSRC_EOSC2)
  359 + clock = CONFIG_HPS_CLK_OSC2_HZ;
  360 + else if (reg == CLKMGR_VCO_SSRC_F2S)
  361 + clock = CONFIG_HPS_CLK_F2S_PER_REF_HZ;
  362 +
  363 + /* get the PER VCO clock */
  364 + reg = readl(&clock_manager_base->per_pll.vco);
  365 + clock /= ((reg & CLKMGR_PERPLLGRP_VCO_DENOM_MASK) >>
  366 + CLKMGR_PERPLLGRP_VCO_DENOM_OFFSET) + 1;
  367 + clock *= ((reg & CLKMGR_PERPLLGRP_VCO_NUMER_MASK) >>
  368 + CLKMGR_PERPLLGRP_VCO_NUMER_OFFSET) + 1;
  369 +
  370 + return clock;
  371 +}
  372 +
  373 +unsigned long cm_get_mpu_clk_hz(void)
  374 +{
  375 + uint32_t reg, clock;
  376 +
  377 + clock = cm_get_main_vco_clk_hz();
  378 +
  379 + /* get the MPU clock */
  380 + reg = readl(&clock_manager_base->altera.mpuclk);
  381 + clock /= (reg + 1);
  382 + reg = readl(&clock_manager_base->main_pll.mpuclk);
  383 + clock /= (reg + 1);
  384 + return clock;
  385 +}
  386 +
  387 +unsigned long cm_get_sdram_clk_hz(void)
  388 +{
  389 + uint32_t reg, clock = 0;
  390 +
  391 + /* identify SDRAM PLL clock source */
  392 + reg = readl(&clock_manager_base->sdr_pll.vco);
  393 + reg = (reg & CLKMGR_SDRPLLGRP_VCO_SSRC_MASK) >>
  394 + CLKMGR_SDRPLLGRP_VCO_SSRC_OFFSET;
  395 + if (reg == CLKMGR_VCO_SSRC_EOSC1)
  396 + clock = CONFIG_HPS_CLK_OSC1_HZ;
  397 + else if (reg == CLKMGR_VCO_SSRC_EOSC2)
  398 + clock = CONFIG_HPS_CLK_OSC2_HZ;
  399 + else if (reg == CLKMGR_VCO_SSRC_F2S)
  400 + clock = CONFIG_HPS_CLK_F2S_SDR_REF_HZ;
  401 +
  402 + /* get the SDRAM VCO clock */
  403 + reg = readl(&clock_manager_base->sdr_pll.vco);
  404 + clock /= ((reg & CLKMGR_SDRPLLGRP_VCO_DENOM_MASK) >>
  405 + CLKMGR_SDRPLLGRP_VCO_DENOM_OFFSET) + 1;
  406 + clock *= ((reg & CLKMGR_SDRPLLGRP_VCO_NUMER_MASK) >>
  407 + CLKMGR_SDRPLLGRP_VCO_NUMER_OFFSET) + 1;
  408 +
  409 + /* get the SDRAM (DDR_DQS) clock */
  410 + reg = readl(&clock_manager_base->sdr_pll.ddrdqsclk);
  411 + reg = (reg & CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_MASK) >>
  412 + CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_OFFSET;
  413 + clock /= (reg + 1);
  414 +
  415 + return clock;
  416 +}
  417 +
  418 +unsigned int cm_get_l4_sp_clk_hz(void)
  419 +{
  420 + uint32_t reg, clock = 0;
  421 +
  422 + /* identify the source of L4 SP clock */
  423 + reg = readl(&clock_manager_base->main_pll.l4src);
  424 + reg = (reg & CLKMGR_MAINPLLGRP_L4SRC_L4SP) >>
  425 + CLKMGR_MAINPLLGRP_L4SRC_L4SP_OFFSET;
  426 +
  427 + if (reg == CLKMGR_L4_SP_CLK_SRC_MAINPLL) {
  428 + clock = cm_get_main_vco_clk_hz();
  429 +
  430 + /* get the clock prior L4 SP divider (main clk) */
  431 + reg = readl(&clock_manager_base->altera.mainclk);
  432 + clock /= (reg + 1);
  433 + reg = readl(&clock_manager_base->main_pll.mainclk);
  434 + clock /= (reg + 1);
  435 + } else if (reg == CLKMGR_L4_SP_CLK_SRC_PERPLL) {
  436 + clock = cm_get_per_vco_clk_hz();
  437 +
  438 + /* get the clock prior L4 SP divider (periph_base_clk) */
  439 + reg = readl(&clock_manager_base->per_pll.perbaseclk);
  440 + clock /= (reg + 1);
  441 + }
  442 +
  443 + /* get the L4 SP clock which supplied to UART */
  444 + reg = readl(&clock_manager_base->main_pll.maindiv);
  445 + reg = (reg & CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_MASK) >>
  446 + CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_OFFSET;
  447 + clock = clock / (1 << reg);
  448 +
  449 + return clock;
  450 +}
  451 +
  452 +unsigned int cm_get_mmc_controller_clk_hz(void)
  453 +{
  454 + uint32_t reg, clock = 0;
  455 +
  456 + /* identify the source of MMC clock */
  457 + reg = readl(&clock_manager_base->per_pll.src);
  458 + reg = (reg & CLKMGR_PERPLLGRP_SRC_SDMMC_MASK) >>
  459 + CLKMGR_PERPLLGRP_SRC_SDMMC_OFFSET;
  460 +
  461 + if (reg == CLKMGR_SDMMC_CLK_SRC_F2S) {
  462 + clock = CONFIG_HPS_CLK_F2S_PER_REF_HZ;
  463 + } else if (reg == CLKMGR_SDMMC_CLK_SRC_MAIN) {
  464 + clock = cm_get_main_vco_clk_hz();
  465 +
  466 + /* get the SDMMC clock */
  467 + reg = readl(&clock_manager_base->main_pll.mainnandsdmmcclk);
  468 + clock /= (reg + 1);
  469 + } else if (reg == CLKMGR_SDMMC_CLK_SRC_PER) {
  470 + clock = cm_get_per_vco_clk_hz();
  471 +
  472 + /* get the SDMMC clock */
  473 + reg = readl(&clock_manager_base->per_pll.pernandsdmmcclk);
  474 + clock /= (reg + 1);
  475 + }
  476 +
  477 + /* further divide by 4 as we have fixed divider at wrapper */
  478 + clock /= 4;
  479 + return clock;
  480 +}
  481 +
  482 +unsigned int cm_get_qspi_controller_clk_hz(void)
  483 +{
  484 + uint32_t reg, clock = 0;
  485 +
  486 + /* identify the source of QSPI clock */
  487 + reg = readl(&clock_manager_base->per_pll.src);
  488 + reg = (reg & CLKMGR_PERPLLGRP_SRC_QSPI_MASK) >>
  489 + CLKMGR_PERPLLGRP_SRC_QSPI_OFFSET;
  490 +
  491 + if (reg == CLKMGR_QSPI_CLK_SRC_F2S) {
  492 + clock = CONFIG_HPS_CLK_F2S_PER_REF_HZ;
  493 + } else if (reg == CLKMGR_QSPI_CLK_SRC_MAIN) {
  494 + clock = cm_get_main_vco_clk_hz();
  495 +
  496 + /* get the qspi clock */
  497 + reg = readl(&clock_manager_base->main_pll.mainqspiclk);
  498 + clock /= (reg + 1);
  499 + } else if (reg == CLKMGR_QSPI_CLK_SRC_PER) {
  500 + clock = cm_get_per_vco_clk_hz();
  501 +
  502 + /* get the qspi clock */
  503 + reg = readl(&clock_manager_base->per_pll.perqspiclk);
  504 + clock /= (reg + 1);
  505 + }
  506 +
  507 + return clock;
  508 +}
  509 +
  510 +static void cm_print_clock_quick_summary(void)
  511 +{
  512 + printf("MPU %10ld kHz\n", cm_get_mpu_clk_hz() / 1000);
  513 + printf("DDR %10ld kHz\n", cm_get_sdram_clk_hz() / 1000);
  514 + printf("EOSC1 %8d kHz\n", CONFIG_HPS_CLK_OSC1_HZ / 1000);
  515 + printf("EOSC2 %8d kHz\n", CONFIG_HPS_CLK_OSC2_HZ / 1000);
  516 + printf("F2S_SDR_REF %8d kHz\n", CONFIG_HPS_CLK_F2S_SDR_REF_HZ / 1000);
  517 + printf("F2S_PER_REF %8d kHz\n", CONFIG_HPS_CLK_F2S_PER_REF_HZ / 1000);
  518 + printf("MMC %8d kHz\n", cm_get_mmc_controller_clk_hz() / 1000);
  519 + printf("QSPI %8d kHz\n", cm_get_qspi_controller_clk_hz() / 1000);
  520 + printf("UART %8d kHz\n", cm_get_l4_sp_clk_hz() / 1000);
  521 +}
  522 +
  523 +int set_cpu_clk_info(void)
  524 +{
  525 + /* Calculate the clock frequencies required for drivers */
  526 + cm_get_l4_sp_clk_hz();
  527 + cm_get_mmc_controller_clk_hz();
  528 +
  529 + gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
  530 + gd->bd->bi_dsp_freq = 0;
  531 + gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
  532 +
  533 + return 0;
  534 +}
  535 +
  536 +int do_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  537 +{
  538 + cm_print_clock_quick_summary();
  539 + return 0;
  540 +}
  541 +
  542 +U_BOOT_CMD(
  543 + clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
  544 + "display clocks",
  545 + ""
  546 +);
arch/arm/cpu/armv7/socfpga/fpga_manager.c
  1 +/*
  2 + * Copyright (C) 2012 Altera Corporation <www.altera.com>
  3 + * All rights reserved.
  4 + *
  5 + * This file contains only support functions used also by the SoCFPGA
  6 + * platform code, the real meat is located in drivers/fpga/socfpga.c .
  7 + *
  8 + * SPDX-License-Identifier: BSD-3-Clause
  9 + */
  10 +
  11 +#include <common.h>
  12 +#include <asm/io.h>
  13 +#include <asm/errno.h>
  14 +#include <asm/arch/fpga_manager.h>
  15 +#include <asm/arch/reset_manager.h>
  16 +#include <asm/arch/system_manager.h>
  17 +
  18 +DECLARE_GLOBAL_DATA_PTR;
  19 +
  20 +/* Timeout count */
  21 +#define FPGA_TIMEOUT_CNT 0x1000000
  22 +
  23 +static struct socfpga_fpga_manager *fpgamgr_regs =
  24 + (struct socfpga_fpga_manager *)SOCFPGA_FPGAMGRREGS_ADDRESS;
  25 +
  26 +/* Check whether FPGA Init_Done signal is high */
  27 +static int is_fpgamgr_initdone_high(void)
  28 +{
  29 + unsigned long val;
  30 +
  31 + val = readl(&fpgamgr_regs->gpio_ext_porta);
  32 + return val & FPGAMGRREGS_MON_GPIO_EXT_PORTA_ID_MASK;
  33 +}
  34 +
  35 +/* Get the FPGA mode */
  36 +int fpgamgr_get_mode(void)
  37 +{
  38 + unsigned long val;
  39 +
  40 + val = readl(&fpgamgr_regs->stat);
  41 + return val & FPGAMGRREGS_STAT_MODE_MASK;
  42 +}
  43 +
  44 +/* Check whether FPGA is ready to be accessed */
  45 +int fpgamgr_test_fpga_ready(void)
  46 +{
  47 + /* Check for init done signal */
  48 + if (!is_fpgamgr_initdone_high())
  49 + return 0;
  50 +
  51 + /* Check again to avoid false glitches */
  52 + if (!is_fpgamgr_initdone_high())
  53 + return 0;
  54 +
  55 + if (fpgamgr_get_mode() != FPGAMGRREGS_MODE_USERMODE)
  56 + return 0;
  57 +
  58 + return 1;
  59 +}
  60 +
  61 +/* Poll until FPGA is ready to be accessed or timeout occurred */
  62 +int fpgamgr_poll_fpga_ready(void)
  63 +{
  64 + unsigned long i;
  65 +
  66 + /* If FPGA is blank, wait till WD invoke warm reset */
  67 + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  68 + /* check for init done signal */
  69 + if (!is_fpgamgr_initdone_high())
  70 + continue;
  71 + /* check again to avoid false glitches */
  72 + if (!is_fpgamgr_initdone_high())
  73 + continue;
  74 + return 1;
  75 + }
  76 +
  77 + return 0;
  78 +}
arch/arm/cpu/armv7/socfpga/misc.c
... ... @@ -6,24 +6,103 @@
6 6  
7 7 #include <common.h>
8 8 #include <asm/io.h>
  9 +#include <altera.h>
9 10 #include <miiphy.h>
10 11 #include <netdev.h>
  12 +#include <asm/arch/reset_manager.h>
  13 +#include <asm/arch/system_manager.h>
  14 +#include <asm/arch/dwmmc.h>
  15 +#include <asm/arch/nic301.h>
  16 +#include <asm/arch/scu.h>
  17 +#include <asm/pl310.h>
11 18  
12 19 DECLARE_GLOBAL_DATA_PTR;
13 20  
  21 +static struct pl310_regs *const pl310 =
  22 + (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  23 +static struct socfpga_system_manager *sysmgr_regs =
  24 + (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  25 +static struct socfpga_reset_manager *reset_manager_base =
  26 + (struct socfpga_reset_manager *)SOCFPGA_RSTMGR_ADDRESS;
  27 +static struct nic301_registers *nic301_regs =
  28 + (struct nic301_registers *)SOCFPGA_L3REGS_ADDRESS;
  29 +static struct scu_registers *scu_regs =
  30 + (struct scu_registers *)SOCFPGA_MPUSCU_ADDRESS;
  31 +
14 32 int dram_init(void)
15 33 {
16 34 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
17 35 return 0;
18 36 }
19 37  
  38 +void enable_caches(void)
  39 +{
  40 +#ifndef CONFIG_SYS_ICACHE_OFF
  41 + icache_enable();
  42 +#endif
  43 +#ifndef CONFIG_SYS_DCACHE_OFF
  44 + dcache_enable();
  45 +#endif
  46 +}
  47 +
  48 +/*
  49 + * DesignWare Ethernet initialization
  50 + */
  51 +#ifdef CONFIG_DESIGNWARE_ETH
  52 +int cpu_eth_init(bd_t *bis)
  53 +{
  54 +#if CONFIG_EMAC_BASE == SOCFPGA_EMAC0_ADDRESS
  55 + const int physhift = SYSMGR_EMACGRP_CTRL_PHYSEL0_LSB;
  56 +#elif CONFIG_EMAC_BASE == SOCFPGA_EMAC1_ADDRESS
  57 + const int physhift = SYSMGR_EMACGRP_CTRL_PHYSEL1_LSB;
  58 +#else
  59 +#error "Incorrect CONFIG_EMAC_BASE value!"
  60 +#endif
  61 +
  62 + /* Initialize EMAC. This needs to be done at least once per boot. */
  63 +
  64 + /*
  65 + * Putting the EMAC controller to reset when configuring the PHY
  66 + * interface select at System Manager
  67 + */
  68 + socfpga_emac_reset(1);
  69 +
  70 + /* Clearing emac0 PHY interface select to 0 */
  71 + clrbits_le32(&sysmgr_regs->emacgrp_ctrl,
  72 + SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << physhift);
  73 +
  74 + /* configure to PHY interface select choosed */
  75 + setbits_le32(&sysmgr_regs->emacgrp_ctrl,
  76 + SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII << physhift);
  77 +
  78 + /* Release the EMAC controller from reset */
  79 + socfpga_emac_reset(0);
  80 +
  81 + /* initialize and register the emac */
  82 + return designware_initialize(CONFIG_EMAC_BASE,
  83 + CONFIG_PHY_INTERFACE_MODE);
  84 +}
  85 +#endif
  86 +
  87 +#ifdef CONFIG_DWMMC
  88 +/*
  89 + * Initializes MMC controllers.
  90 + * to override, implement board_mmc_init()
  91 + */
  92 +int cpu_mmc_init(bd_t *bis)
  93 +{
  94 + return socfpga_dwmmc_init(SOCFPGA_SDMMC_ADDRESS,
  95 + CONFIG_HPS_SDMMC_BUSWIDTH, 0);
  96 +}
  97 +#endif
  98 +
20 99 #if defined(CONFIG_DISPLAY_CPUINFO)
21 100 /*
22 101 * Print CPU information
23 102 */
24 103 int print_cpuinfo(void)
25 104 {
26   - puts("CPU : Altera SOCFPGA Platform\n");
  105 + puts("CPU: Altera SoCFPGA Platform\n");
27 106 return 0;
28 107 }
29 108 #endif
30 109  
31 110  
32 111  
33 112  
34 113  
35 114  
36 115  
37 116  
... ... @@ -36,23 +115,160 @@
36 115 }
37 116 #endif
38 117  
39   -int misc_init_r(void)
  118 +#ifdef CONFIG_FPGA
  119 +/*
  120 + * FPGA programming support for SoC FPGA Cyclone V
  121 + */
  122 +static Altera_desc altera_fpga[] = {
  123 + {
  124 + /* Family */
  125 + Altera_SoCFPGA,
  126 + /* Interface type */
  127 + fast_passive_parallel,
  128 + /* No limitation as additional data will be ignored */
  129 + -1,
  130 + /* No device function table */
  131 + NULL,
  132 + /* Base interface address specified in driver */
  133 + NULL,
  134 + /* No cookie implementation */
  135 + 0
  136 + },
  137 +};
  138 +
  139 +/* add device descriptor to FPGA device table */
  140 +static void socfpga_fpga_add(void)
40 141 {
  142 + int i;
  143 + fpga_init();
  144 + for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  145 + fpga_add(fpga_altera, &altera_fpga[i]);
  146 +}
  147 +#else
  148 +static inline void socfpga_fpga_add(void) {}
  149 +#endif
  150 +
  151 +int arch_cpu_init(void)
  152 +{
  153 + /*
  154 + * If the HW watchdog is NOT enabled, make sure it is not running,
  155 + * for example because it was enabled in the preloader. This might
  156 + * trigger a watchdog-triggered reboot of Linux kernel later.
  157 + */
  158 +#ifndef CONFIG_HW_WATCHDOG
  159 + socfpga_watchdog_reset();
  160 +#endif
41 161 return 0;
42 162 }
43 163  
44   -
45 164 /*
46   - * DesignWare Ethernet initialization
  165 + * Convert all NIC-301 AMBA slaves from secure to non-secure
47 166 */
48   -int cpu_eth_init(bd_t *bis)
  167 +static void socfpga_nic301_slave_ns(void)
49 168 {
50   -#if !defined(CONFIG_SOCFPGA_VIRTUAL_TARGET) && !defined(CONFIG_SPL_BUILD)
51   - /* initialize and register the emac */
52   - return designware_initialize(CONFIG_EMAC_BASE,
53   - CONFIG_PHY_INTERFACE_MODE);
  169 + writel(0x1, &nic301_regs->lwhps2fpgaregs);
  170 + writel(0x1, &nic301_regs->hps2fpgaregs);
  171 + writel(0x1, &nic301_regs->acp);
  172 + writel(0x1, &nic301_regs->rom);
  173 + writel(0x1, &nic301_regs->ocram);
  174 + writel(0x1, &nic301_regs->sdrdata);
  175 +}
  176 +
  177 +static uint32_t iswgrp_handoff[8];
  178 +
  179 +int misc_init_r(void)
  180 +{
  181 + int i;
  182 + for (i = 0; i < 8; i++) /* Cache initial SW setting regs */
  183 + iswgrp_handoff[i] = readl(&sysmgr_regs->iswgrp_handoff[i]);
  184 +
  185 + socfpga_bridges_reset(1);
  186 + socfpga_nic301_slave_ns();
  187 +
  188 + /*
  189 + * Private components security:
  190 + * U-Boot : configure private timer, global timer and cpu component
  191 + * access as non secure for kernel stage (as required by Linux)
  192 + */
  193 + setbits_le32(&scu_regs->sacr, 0xfff);
  194 +
  195 + /* Configure the L2 controller to make SDRAM start at 0 */
  196 +#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
  197 + writel(0x2, &nic301_regs->remap);
54 198 #else
55   - return 0;
  199 + writel(0x1, &nic301_regs->remap); /* remap.mpuzero */
  200 + writel(0x1, &pl310->pl310_addr_filter_start);
56 201 #endif
  202 +
  203 + /* Add device descriptor to FPGA device table */
  204 + socfpga_fpga_add();
  205 + return 0;
57 206 }
  207 +
  208 +static void socfpga_sdram_apply_static_cfg(void)
  209 +{
  210 + const uint32_t staticcfg = SOCFPGA_SDR_ADDRESS + 0x505c;
  211 + const uint32_t applymask = 0x8;
  212 + uint32_t val = readl(staticcfg) | applymask;
  213 +
  214 + /*
  215 + * SDRAM staticcfg register specific:
  216 + * When applying the register setting, the CPU must not access
  217 + * SDRAM. Luckily for us, we can abuse i-cache here to help us
  218 + * circumvent the SDRAM access issue. The idea is to make sure
  219 + * that the code is in one full i-cache line by branching past
  220 + * it and back. Once it is in the i-cache, we execute the core
  221 + * of the code and apply the register settings.
  222 + *
  223 + * The code below uses 7 instructions, while the Cortex-A9 has
  224 + * 32-byte cachelines, thus the limit is 8 instructions total.
  225 + */
  226 + asm volatile(
  227 + ".align 5 \n"
  228 + " b 2f \n"
  229 + "1: str %0, [%1] \n"
  230 + " dsb \n"
  231 + " isb \n"
  232 + " b 3f \n"
  233 + "2: b 1b \n"
  234 + "3: nop \n"
  235 + : : "r"(val), "r"(staticcfg) : "memory", "cc");
  236 +}
  237 +
  238 +int do_bridge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  239 +{
  240 + if (argc != 2)
  241 + return CMD_RET_USAGE;
  242 +
  243 + argv++;
  244 +
  245 + switch (*argv[0]) {
  246 + case 'e': /* Enable */
  247 + writel(iswgrp_handoff[2], &sysmgr_regs->fpgaintfgrp_module);
  248 + socfpga_sdram_apply_static_cfg();
  249 + writel(iswgrp_handoff[3], SOCFPGA_SDR_ADDRESS + 0x5080);
  250 + writel(iswgrp_handoff[0], &reset_manager_base->brg_mod_reset);
  251 + writel(iswgrp_handoff[1], &nic301_regs->remap);
  252 + break;
  253 + case 'd': /* Disable */
  254 + writel(0, &sysmgr_regs->fpgaintfgrp_module);
  255 + writel(0, SOCFPGA_SDR_ADDRESS + 0x5080);
  256 + socfpga_sdram_apply_static_cfg();
  257 + writel(0, &reset_manager_base->brg_mod_reset);
  258 + writel(1, &nic301_regs->remap);
  259 + break;
  260 + default:
  261 + return CMD_RET_USAGE;
  262 + }
  263 +
  264 + return 0;
  265 +}
  266 +
  267 +U_BOOT_CMD(
  268 + bridge, 2, 1, do_bridge,
  269 + "SoCFPGA HPS FPGA bridge control",
  270 + "enable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
  271 + "bridge disable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
  272 + ""
  273 +);
arch/arm/cpu/armv7/socfpga/reset_manager.c
... ... @@ -8,12 +8,25 @@
8 8 #include <common.h>
9 9 #include <asm/io.h>
10 10 #include <asm/arch/reset_manager.h>
  11 +#include <asm/arch/fpga_manager.h>
11 12  
12 13 DECLARE_GLOBAL_DATA_PTR;
13 14  
14 15 static const struct socfpga_reset_manager *reset_manager_base =
15 16 (void *)SOCFPGA_RSTMGR_ADDRESS;
16 17  
  18 +/* Toggle reset signal to watchdog (WDT is disabled after this operation!) */
  19 +void socfpga_watchdog_reset(void)
  20 +{
  21 + /* assert reset for watchdog */
  22 + setbits_le32(&reset_manager_base->per_mod_reset,
  23 + 1 << RSTMGR_PERMODRST_L4WD0_LSB);
  24 +
  25 + /* deassert watchdog from reset (watchdog in not running state) */
  26 + clrbits_le32(&reset_manager_base->per_mod_reset,
  27 + 1 << RSTMGR_PERMODRST_L4WD0_LSB);
  28 +}
  29 +
17 30 /*
18 31 * Write the reset manager register to cause reset
19 32 */
... ... @@ -36,5 +49,59 @@
36 49 void reset_deassert_peripherals_handoff(void)
37 50 {
38 51 writel(0, &reset_manager_base->per_mod_reset);
  52 +}
  53 +
  54 +#if defined(CONFIG_SOCFPGA_VIRTUAL_TARGET)
  55 +void socfpga_bridges_reset(int enable)
  56 +{
  57 + /* For SoCFPGA-VT, this is NOP. */
  58 +}
  59 +#else
  60 +
  61 +#define L3REGS_REMAP_LWHPS2FPGA_MASK 0x10
  62 +#define L3REGS_REMAP_HPS2FPGA_MASK 0x08
  63 +#define L3REGS_REMAP_OCRAM_MASK 0x01
  64 +
  65 +void socfpga_bridges_reset(int enable)
  66 +{
  67 + const uint32_t l3mask = L3REGS_REMAP_LWHPS2FPGA_MASK |
  68 + L3REGS_REMAP_HPS2FPGA_MASK |
  69 + L3REGS_REMAP_OCRAM_MASK;
  70 +
  71 + if (enable) {
  72 + /* brdmodrst */
  73 + writel(0xffffffff, &reset_manager_base->brg_mod_reset);
  74 + } else {
  75 + /* Check signal from FPGA. */
  76 + if (fpgamgr_poll_fpga_ready()) {
  77 + /* FPGA not ready. Wait for watchdog timeout. */
  78 + printf("%s: fpga not ready, hanging.\n", __func__);
  79 + hang();
  80 + }
  81 +
  82 + /* brdmodrst */
  83 + writel(0, &reset_manager_base->brg_mod_reset);
  84 +
  85 + /* Remap the bridges into memory map */
  86 + writel(l3mask, SOCFPGA_L3REGS_ADDRESS);
  87 + }
  88 +}
  89 +#endif
  90 +
  91 +/* Change the reset state for EMAC 0 and EMAC 1 */
  92 +void socfpga_emac_reset(int enable)
  93 +{
  94 + const void *reset = &reset_manager_base->per_mod_reset;
  95 +
  96 + if (enable) {
  97 + setbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC0_LSB);
  98 + setbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC1_LSB);
  99 + } else {
  100 +#if (CONFIG_EMAC_BASE == SOCFPGA_EMAC0_ADDRESS)
  101 + clrbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC0_LSB);
  102 +#elif (CONFIG_EMAC_BASE == SOCFPGA_EMAC1_ADDRESS)
  103 + clrbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC1_LSB);
  104 +#endif
  105 + }
39 106 }
arch/arm/cpu/armv7/socfpga/spl.c
... ... @@ -19,6 +19,31 @@
19 19  
20 20 DECLARE_GLOBAL_DATA_PTR;
21 21  
  22 +#define MAIN_VCO_BASE ( \
  23 + (CONFIG_HPS_MAINPLLGRP_VCO_DENOM << \
  24 + CLKMGR_MAINPLLGRP_VCO_DENOM_OFFSET) | \
  25 + (CONFIG_HPS_MAINPLLGRP_VCO_NUMER << \
  26 + CLKMGR_MAINPLLGRP_VCO_NUMER_OFFSET) \
  27 + )
  28 +
  29 +#define PERI_VCO_BASE ( \
  30 + (CONFIG_HPS_PERPLLGRP_VCO_PSRC << \
  31 + CLKMGR_PERPLLGRP_VCO_PSRC_OFFSET) | \
  32 + (CONFIG_HPS_PERPLLGRP_VCO_DENOM << \
  33 + CLKMGR_PERPLLGRP_VCO_DENOM_OFFSET) | \
  34 + (CONFIG_HPS_PERPLLGRP_VCO_NUMER << \
  35 + CLKMGR_PERPLLGRP_VCO_NUMER_OFFSET) \
  36 + )
  37 +
  38 +#define SDR_VCO_BASE ( \
  39 + (CONFIG_HPS_SDRPLLGRP_VCO_SSRC << \
  40 + CLKMGR_SDRPLLGRP_VCO_SSRC_OFFSET) | \
  41 + (CONFIG_HPS_SDRPLLGRP_VCO_DENOM << \
  42 + CLKMGR_SDRPLLGRP_VCO_DENOM_OFFSET) | \
  43 + (CONFIG_HPS_SDRPLLGRP_VCO_NUMER << \
  44 + CLKMGR_SDRPLLGRP_VCO_NUMER_OFFSET) \
  45 + )
  46 +
22 47 u32 spl_boot_device(void)
23 48 {
24 49 return BOOT_DEVICE_RAM;
25 50  
26 51  
... ... @@ -33,86 +58,87 @@
33 58 cm_config_t cm_default_cfg = {
34 59 /* main group */
35 60 MAIN_VCO_BASE,
36   - CLKMGR_MAINPLLGRP_MPUCLK_CNT_SET(
37   - CONFIG_HPS_MAINPLLGRP_MPUCLK_CNT),
38   - CLKMGR_MAINPLLGRP_MAINCLK_CNT_SET(
39   - CONFIG_HPS_MAINPLLGRP_MAINCLK_CNT),
40   - CLKMGR_MAINPLLGRP_DBGATCLK_CNT_SET(
41   - CONFIG_HPS_MAINPLLGRP_DBGATCLK_CNT),
42   - CLKMGR_MAINPLLGRP_MAINQSPICLK_CNT_SET(
43   - CONFIG_HPS_MAINPLLGRP_MAINQSPICLK_CNT),
44   - CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_SET(
45   - CONFIG_HPS_MAINPLLGRP_MAINNANDSDMMCCLK_CNT),
46   - CLKMGR_MAINPLLGRP_CFGS2FUSER0CLK_CNT_SET(
47   - CONFIG_HPS_MAINPLLGRP_CFGS2FUSER0CLK_CNT),
48   - CLKMGR_MAINPLLGRP_MAINDIV_L3MPCLK_SET(
49   - CONFIG_HPS_MAINPLLGRP_MAINDIV_L3MPCLK) |
50   - CLKMGR_MAINPLLGRP_MAINDIV_L3SPCLK_SET(
51   - CONFIG_HPS_MAINPLLGRP_MAINDIV_L3SPCLK) |
52   - CLKMGR_MAINPLLGRP_MAINDIV_L4MPCLK_SET(
53   - CONFIG_HPS_MAINPLLGRP_MAINDIV_L4MPCLK) |
54   - CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_SET(
55   - CONFIG_HPS_MAINPLLGRP_MAINDIV_L4SPCLK),
56   - CLKMGR_MAINPLLGRP_DBGDIV_DBGATCLK_SET(
57   - CONFIG_HPS_MAINPLLGRP_DBGDIV_DBGATCLK) |
58   - CLKMGR_MAINPLLGRP_DBGDIV_DBGCLK_SET(
59   - CONFIG_HPS_MAINPLLGRP_DBGDIV_DBGCLK),
60   - CLKMGR_MAINPLLGRP_TRACEDIV_TRACECLK_SET(
61   - CONFIG_HPS_MAINPLLGRP_TRACEDIV_TRACECLK),
62   - CLKMGR_MAINPLLGRP_L4SRC_L4MP_SET(
63   - CONFIG_HPS_MAINPLLGRP_L4SRC_L4MP) |
64   - CLKMGR_MAINPLLGRP_L4SRC_L4SP_SET(
65   - CONFIG_HPS_MAINPLLGRP_L4SRC_L4SP),
  61 + (CONFIG_HPS_MAINPLLGRP_MPUCLK_CNT <<
  62 + CLKMGR_MAINPLLGRP_MPUCLK_CNT_OFFSET),
  63 + (CONFIG_HPS_MAINPLLGRP_MAINCLK_CNT <<
  64 + CLKMGR_MAINPLLGRP_MAINCLK_CNT_OFFSET),
  65 + (CONFIG_HPS_MAINPLLGRP_DBGATCLK_CNT <<
  66 + CLKMGR_MAINPLLGRP_DBGATCLK_CNT_OFFSET),
  67 + (CONFIG_HPS_MAINPLLGRP_MAINQSPICLK_CNT <<
  68 + CLKMGR_MAINPLLGRP_MAINQSPICLK_CNT_OFFSET),
  69 + (CONFIG_HPS_MAINPLLGRP_MAINNANDSDMMCCLK_CNT <<
  70 + CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_OFFSET),
  71 + (CONFIG_HPS_MAINPLLGRP_CFGS2FUSER0CLK_CNT <<
  72 + CLKMGR_MAINPLLGRP_CFGS2FUSER0CLK_CNT_OFFSET),
  73 + (CONFIG_HPS_MAINPLLGRP_MAINDIV_L3MPCLK <<
  74 + CLKMGR_MAINPLLGRP_MAINDIV_L3MPCLK_OFFSET) |
  75 + (CONFIG_HPS_MAINPLLGRP_MAINDIV_L3SPCLK <<
  76 + CLKMGR_MAINPLLGRP_MAINDIV_L3SPCLK_OFFSET) |
  77 + (CONFIG_HPS_MAINPLLGRP_MAINDIV_L4MPCLK <<
  78 + CLKMGR_MAINPLLGRP_MAINDIV_L4MPCLK_OFFSET) |
  79 + (CONFIG_HPS_MAINPLLGRP_MAINDIV_L4SPCLK <<
  80 + CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_OFFSET),
  81 + (CONFIG_HPS_MAINPLLGRP_DBGDIV_DBGATCLK <<
  82 + CLKMGR_MAINPLLGRP_DBGDIV_DBGATCLK_OFFSET) |
  83 + (CONFIG_HPS_MAINPLLGRP_DBGDIV_DBGCLK <<
  84 + CLKMGR_MAINPLLGRP_DBGDIV_DBGCLK_OFFSET),
  85 + (CONFIG_HPS_MAINPLLGRP_TRACEDIV_TRACECLK <<
  86 + CLKMGR_MAINPLLGRP_TRACEDIV_TRACECLK_OFFSET),
  87 + (CONFIG_HPS_MAINPLLGRP_L4SRC_L4MP <<
  88 + CLKMGR_MAINPLLGRP_L4SRC_L4MP_OFFSET) |
  89 + (CONFIG_HPS_MAINPLLGRP_L4SRC_L4SP <<
  90 + CLKMGR_MAINPLLGRP_L4SRC_L4SP_OFFSET),
66 91  
67 92 /* peripheral group */
68 93 PERI_VCO_BASE,
69   - CLKMGR_PERPLLGRP_EMAC0CLK_CNT_SET(
70   - CONFIG_HPS_PERPLLGRP_EMAC0CLK_CNT),
71   - CLKMGR_PERPLLGRP_EMAC1CLK_CNT_SET(
72   - CONFIG_HPS_PERPLLGRP_EMAC1CLK_CNT),
73   - CLKMGR_PERPLLGRP_PERQSPICLK_CNT_SET(
74   - CONFIG_HPS_PERPLLGRP_PERQSPICLK_CNT),
75   - CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_SET(
76   - CONFIG_HPS_PERPLLGRP_PERNANDSDMMCCLK_CNT),
77   - CLKMGR_PERPLLGRP_PERBASECLK_CNT_SET(
78   - CONFIG_HPS_PERPLLGRP_PERBASECLK_CNT),
79   - CLKMGR_PERPLLGRP_S2FUSER1CLK_CNT_SET(
80   - CONFIG_HPS_PERPLLGRP_S2FUSER1CLK_CNT),
81   - CLKMGR_PERPLLGRP_DIV_USBCLK_SET(
82   - CONFIG_HPS_PERPLLGRP_DIV_USBCLK) |
83   - CLKMGR_PERPLLGRP_DIV_SPIMCLK_SET(
84   - CONFIG_HPS_PERPLLGRP_DIV_SPIMCLK) |
85   - CLKMGR_PERPLLGRP_DIV_CAN0CLK_SET(
86   - CONFIG_HPS_PERPLLGRP_DIV_CAN0CLK) |
87   - CLKMGR_PERPLLGRP_DIV_CAN1CLK_SET(
88   - CONFIG_HPS_PERPLLGRP_DIV_CAN1CLK),
89   - CLKMGR_PERPLLGRP_GPIODIV_GPIODBCLK_SET(
90   - CONFIG_HPS_PERPLLGRP_GPIODIV_GPIODBCLK),
91   - CLKMGR_PERPLLGRP_SRC_QSPI_SET(
92   - CONFIG_HPS_PERPLLGRP_SRC_QSPI) |
93   - CLKMGR_PERPLLGRP_SRC_NAND_SET(
94   - CONFIG_HPS_PERPLLGRP_SRC_NAND) |
95   - CLKMGR_PERPLLGRP_SRC_SDMMC_SET(
96   - CONFIG_HPS_PERPLLGRP_SRC_SDMMC),
  94 + (CONFIG_HPS_PERPLLGRP_EMAC0CLK_CNT <<
  95 + CLKMGR_PERPLLGRP_EMAC0CLK_CNT_OFFSET),
  96 + (CONFIG_HPS_PERPLLGRP_EMAC1CLK_CNT <<
  97 + CLKMGR_PERPLLGRP_EMAC1CLK_CNT_OFFSET),
  98 + (CONFIG_HPS_PERPLLGRP_PERQSPICLK_CNT <<
  99 + CLKMGR_PERPLLGRP_PERQSPICLK_CNT_OFFSET),
  100 + (CONFIG_HPS_PERPLLGRP_PERNANDSDMMCCLK_CNT <<
  101 + CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_OFFSET),
  102 + (CONFIG_HPS_PERPLLGRP_PERBASECLK_CNT <<
  103 + CLKMGR_PERPLLGRP_PERBASECLK_CNT_OFFSET),
  104 + (CONFIG_HPS_PERPLLGRP_S2FUSER1CLK_CNT <<
  105 + CLKMGR_PERPLLGRP_S2FUSER1CLK_CNT_OFFSET),
  106 + (CONFIG_HPS_PERPLLGRP_DIV_USBCLK <<
  107 + CLKMGR_PERPLLGRP_DIV_USBCLK_OFFSET) |
  108 + (CONFIG_HPS_PERPLLGRP_DIV_SPIMCLK <<
  109 + CLKMGR_PERPLLGRP_DIV_SPIMCLK_OFFSET) |
  110 + (CONFIG_HPS_PERPLLGRP_DIV_CAN0CLK <<
  111 + CLKMGR_PERPLLGRP_DIV_CAN0CLK_OFFSET) |
  112 + (CONFIG_HPS_PERPLLGRP_DIV_CAN1CLK <<
  113 + CLKMGR_PERPLLGRP_DIV_CAN1CLK_OFFSET),
  114 + (CONFIG_HPS_PERPLLGRP_GPIODIV_GPIODBCLK <<
  115 + CLKMGR_PERPLLGRP_GPIODIV_GPIODBCLK_OFFSET),
  116 + (CONFIG_HPS_PERPLLGRP_SRC_QSPI <<
  117 + CLKMGR_PERPLLGRP_SRC_QSPI_OFFSET) |
  118 + (CONFIG_HPS_PERPLLGRP_SRC_NAND <<
  119 + CLKMGR_PERPLLGRP_SRC_NAND_OFFSET) |
  120 + (CONFIG_HPS_PERPLLGRP_SRC_SDMMC <<
  121 + CLKMGR_PERPLLGRP_SRC_SDMMC_OFFSET),
97 122  
98 123 /* sdram pll group */
99 124 SDR_VCO_BASE,
100   - CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_SET(
101   - CONFIG_HPS_SDRPLLGRP_DDRDQSCLK_PHASE) |
102   - CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_SET(
103   - CONFIG_HPS_SDRPLLGRP_DDRDQSCLK_CNT),
104   - CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_SET(
105   - CONFIG_HPS_SDRPLLGRP_DDR2XDQSCLK_PHASE) |
106   - CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_SET(
107   - CONFIG_HPS_SDRPLLGRP_DDR2XDQSCLK_CNT),
108   - CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_SET(
109   - CONFIG_HPS_SDRPLLGRP_DDRDQCLK_PHASE) |
110   - CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_SET(
111   - CONFIG_HPS_SDRPLLGRP_DDRDQCLK_CNT),
112   - CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_SET(
113   - CONFIG_HPS_SDRPLLGRP_S2FUSER2CLK_PHASE) |
114   - CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_SET(
115   - CONFIG_HPS_SDRPLLGRP_S2FUSER2CLK_CNT),
  125 + (CONFIG_HPS_SDRPLLGRP_DDRDQSCLK_PHASE <<
  126 + CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_OFFSET) |
  127 + (CONFIG_HPS_SDRPLLGRP_DDRDQSCLK_CNT <<
  128 + CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_OFFSET),
  129 + (CONFIG_HPS_SDRPLLGRP_DDR2XDQSCLK_PHASE <<
  130 + CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_OFFSET) |
  131 + (CONFIG_HPS_SDRPLLGRP_DDR2XDQSCLK_CNT <<
  132 + CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_OFFSET),
  133 + (CONFIG_HPS_SDRPLLGRP_DDRDQCLK_PHASE <<
  134 + CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_OFFSET) |
  135 + (CONFIG_HPS_SDRPLLGRP_DDRDQCLK_CNT <<
  136 + CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_OFFSET),
  137 + (CONFIG_HPS_SDRPLLGRP_S2FUSER2CLK_PHASE <<
  138 + CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_OFFSET) |
  139 + (CONFIG_HPS_SDRPLLGRP_S2FUSER2CLK_CNT <<
  140 + CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_OFFSET),
  141 +
116 142 };
117 143  
118 144 debug("Freezing all I/O banks\n");
arch/arm/cpu/armv7/socfpga/system_manager.c
1 1 /*
2   - * Copyright (C) 2013 Altera Corporation <www.altera.com>
  2 + * Copyright (C) 2013 Altera Corporation <www.altera.com>
3 3 *
4 4 * SPDX-License-Identifier: GPL-2.0+
5 5 */
6 6  
7 7  
8 8  
9 9  
10 10  
... ... @@ -7,22 +7,63 @@
7 7 #include <common.h>
8 8 #include <asm/io.h>
9 9 #include <asm/arch/system_manager.h>
  10 +#include <asm/arch/fpga_manager.h>
10 11  
11 12 DECLARE_GLOBAL_DATA_PTR;
12 13  
  14 +static struct socfpga_system_manager *sysmgr_regs =
  15 + (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  16 +
13 17 /*
  18 + * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
  19 + * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
  20 + * CONFIG_SYSMGR_ISWGRP_HANDOFF.
  21 + */
  22 +static void populate_sysmgr_fpgaintf_module(void)
  23 +{
  24 + uint32_t handoff_val = 0;
  25 +
  26 + /* ISWGRP_HANDOFF_FPGAINTF */
  27 + writel(0, &sysmgr_regs->iswgrp_handoff[2]);
  28 +
  29 + /* Enable the signal for those HPS peripherals that use FPGA. */
  30 + if (readl(&sysmgr_regs->nandusefpga) == SYSMGR_FPGAINTF_USEFPGA)
  31 + handoff_val |= SYSMGR_FPGAINTF_NAND;
  32 + if (readl(&sysmgr_regs->rgmii1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  33 + handoff_val |= SYSMGR_FPGAINTF_EMAC1;
  34 + if (readl(&sysmgr_regs->sdmmcusefpga) == SYSMGR_FPGAINTF_USEFPGA)
  35 + handoff_val |= SYSMGR_FPGAINTF_SDMMC;
  36 + if (readl(&sysmgr_regs->rgmii0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  37 + handoff_val |= SYSMGR_FPGAINTF_EMAC0;
  38 + if (readl(&sysmgr_regs->spim0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  39 + handoff_val |= SYSMGR_FPGAINTF_SPIM0;
  40 + if (readl(&sysmgr_regs->spim1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
  41 + handoff_val |= SYSMGR_FPGAINTF_SPIM1;
  42 +
  43 + /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE
  44 + based on pinmux setting */
  45 + setbits_le32(&sysmgr_regs->iswgrp_handoff[2], handoff_val);
  46 +
  47 + handoff_val = readl(&sysmgr_regs->iswgrp_handoff[2]);
  48 + if (fpgamgr_test_fpga_ready()) {
  49 + /* Enable the required signals only */
  50 + writel(handoff_val, &sysmgr_regs->fpgaintfgrp_module);
  51 + }
  52 +}
  53 +
  54 +/*
14 55 * Configure all the pin muxes
15 56 */
16 57 void sysmgr_pinmux_init(void)
17 58 {
18   - unsigned long offset = CONFIG_SYSMGR_PINMUXGRP_OFFSET;
  59 + uint32_t regs = (uint32_t)&sysmgr_regs->emacio[0];
  60 + int i;
19 61  
20   - const unsigned long *pval = sys_mgr_init_table;
21   - unsigned long i;
22   -
23   - for (i = 0; i < ARRAY_SIZE(sys_mgr_init_table);
24   - i++, offset += sizeof(unsigned long)) {
25   - writel(*pval++, (SOCFPGA_SYSMGR_ADDRESS + offset));
  62 + for (i = 0; i < ARRAY_SIZE(sys_mgr_init_table); i++) {
  63 + writel(sys_mgr_init_table[i], regs);
  64 + regs += sizeof(regs);
26 65 }
  66 +
  67 + populate_sysmgr_fpgaintf_module();
27 68 }
arch/arm/cpu/armv7/socfpga/timer.c
... ... @@ -8,6 +8,8 @@
8 8 #include <asm/io.h>
9 9 #include <asm/arch/timer.h>
10 10  
  11 +#define TIMER_LOAD_VAL 0xFFFFFFFF
  12 +
11 13 static const struct socfpga_timer *timer_base = (void *)CONFIG_SYS_TIMERBASE;
12 14  
13 15 /*
arch/arm/include/asm/arch-socfpga/clock_manager.h
... ... @@ -7,6 +7,15 @@
7 7 #ifndef _CLOCK_MANAGER_H_
8 8 #define _CLOCK_MANAGER_H_
9 9  
  10 +#ifndef __ASSEMBLER__
  11 +/* Clock speed accessors */
  12 +unsigned long cm_get_mpu_clk_hz(void);
  13 +unsigned long cm_get_sdram_clk_hz(void);
  14 +unsigned int cm_get_l4_sp_clk_hz(void);
  15 +unsigned int cm_get_mmc_controller_clk_hz(void);
  16 +unsigned int cm_get_qspi_controller_clk_hz(void);
  17 +#endif
  18 +
10 19 typedef struct {
11 20 /* main group */
12 21 uint32_t main_vco_base;
... ... @@ -89,6 +98,11 @@
89 98 u32 stat;
90 99 };
91 100  
  101 +struct socfpga_clock_manager_altera {
  102 + u32 mpuclk;
  103 + u32 mainclk;
  104 +};
  105 +
92 106 struct socfpga_clock_manager {
93 107 u32 ctrl;
94 108 u32 bypass;
95 109  
96 110  
97 111  
98 112  
... ... @@ -100,113 +114,195 @@
100 114 struct socfpga_clock_manager_main_pll main_pll;
101 115 struct socfpga_clock_manager_per_pll per_pll;
102 116 struct socfpga_clock_manager_sdr_pll sdr_pll;
103   - u32 _pad_0xe0_0x200[72];
  117 + struct socfpga_clock_manager_altera altera;
  118 + u32 _pad_0xe8_0x200[70];
104 119 };
105 120  
106   -#define CLKMGR_MAINPLLGRP_EN_S2FUSER0CLK_MASK 0x00000200
107   -#define CLKMGR_MAINPLLGRP_EN_DBGTIMERCLK_MASK 0x00000080
108   -#define CLKMGR_MAINPLLGRP_EN_DBGTRACECLK_MASK 0x00000040
109   -#define CLKMGR_MAINPLLGRP_EN_DBGCLK_MASK 0x00000020
110   -#define CLKMGR_MAINPLLGRP_EN_DBGATCLK_MASK 0x00000010
111   -#define CLKMGR_MAINPLLGRP_EN_L4MPCLK_MASK 0x00000004
112   -#define CLKMGR_MAINPLLGRP_VCO_RESET_VALUE 0x8001000d
113   -#define CLKMGR_PERPLLGRP_VCO_RESET_VALUE 0x8001000d
114   -#define CLKMGR_SDRPLLGRP_VCO_RESET_VALUE 0x8001000d
115   -#define CLKMGR_MAINPLLGRP_MAINDIV_L4MPCLK_SET(x) (((x) << 4) & 0x00000070)
116   -#define CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_SET(x) (((x) << 7) & 0x00000380)
117   -#define CLKMGR_MAINPLLGRP_L4SRC_L4MP_SET(x) (((x) << 0) & 0x00000001)
118   -#define CLKMGR_MAINPLLGRP_L4SRC_L4SP_SET(x) (((x) << 1) & 0x00000002)
119   -#define CLKMGR_PERPLLGRP_SRC_QSPI_SET(x) (((x) << 4) & 0x00000030)
120   -#define CLKMGR_PERPLLGRP_SRC_NAND_SET(x) (((x) << 2) & 0x0000000c)
121   -#define CLKMGR_PERPLLGRP_SRC_SDMMC_SET(x) (((x) << 0) & 0x00000003)
122   -#define CLKMGR_MAINPLLGRP_VCO_DENOM_SET(x) (((x) << 16) & 0x003f0000)
123   -#define CLKMGR_MAINPLLGRP_VCO_NUMER_SET(x) (((x) << 3) & 0x0000fff8)
124   -#define CLKMGR_MAINPLLGRP_VCO_PWRDN_SET(x) (((x) << 2) & 0x00000004)
125   -#define CLKMGR_MAINPLLGRP_VCO_EN_SET(x) (((x) << 1) & 0x00000002)
126   -#define CLKMGR_MAINPLLGRP_VCO_BGPWRDN_SET(x) (((x) << 0) & 0x00000001)
127   -#define CLKMGR_PERPLLGRP_VCO_PSRC_SET(x) (((x) << 22) & 0x00c00000)
128   -#define CLKMGR_PERPLLGRP_VCO_DENOM_SET(x) (((x) << 16) & 0x003f0000)
129   -#define CLKMGR_PERPLLGRP_VCO_NUMER_SET(x) (((x) << 3) & 0x0000fff8)
130   -#define CLKMGR_SDRPLLGRP_VCO_OUTRESET_SET(x) (((x) << 25) & 0x7e000000)
131   -#define CLKMGR_SDRPLLGRP_VCO_OUTRESETALL_SET(x) (((x) << 24) & 0x01000000)
132   -#define CLKMGR_SDRPLLGRP_VCO_SSRC_SET(x) (((x) << 22) & 0x00c00000)
133   -#define CLKMGR_SDRPLLGRP_VCO_DENOM_SET(x) (((x) << 16) & 0x003f0000)
134   -#define CLKMGR_SDRPLLGRP_VCO_NUMER_SET(x) (((x) << 3) & 0x0000fff8)
135   -#define CLKMGR_MAINPLLGRP_MPUCLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
136   -#define CLKMGR_MAINPLLGRP_MAINCLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
137   -#define CLKMGR_MAINPLLGRP_DBGATCLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
138   -#define CLKMGR_MAINPLLGRP_CFGS2FUSER0CLK_CNT_SET(x) \
139   - (((x) << 0) & 0x000001ff)
140   -#define CLKMGR_PERPLLGRP_EMAC0CLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
141   -#define CLKMGR_PERPLLGRP_EMAC1CLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
142   -#define CLKMGR_MAINPLLGRP_MAINQSPICLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
143   -#define CLKMGR_MAINPLLGRP_MAINNANDSDMMCCLK_CNT_SET(x) \
144   - (((x) << 0) & 0x000001ff)
145   -#define CLKMGR_PERPLLGRP_PERBASECLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
146   -#define CLKMGR_PERPLLGRP_S2FUSER1CLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
147   -#define CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
148   -#define CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_SET(x) (((x) << 9) & 0x00000e00)
149   -#define CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
150   -#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_SET(x) (((x) << 9) & 0x00000e00)
151   -#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
152   -#define CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_SET(x) (((x) << 9) & 0x00000e00)
153   -#define CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
154   -#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_SET(x) (((x) << 9) & 0x00000e00)
155   -#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
156   -#define CLKMGR_MAINPLLGRP_DBGDIV_DBGCLK_SET(x) (((x) << 2) & 0x0000000c)
157   -#define CLKMGR_MAINPLLGRP_DBGDIV_DBGATCLK_SET(x) (((x) << 0) & 0x00000003)
158   -#define CLKMGR_MAINPLLGRP_TRACEDIV_TRACECLK_SET(x) (((x) << 0) & 0x00000007)
159   -#define CLKMGR_MAINPLLGRP_MAINDIV_L3MPCLK_SET(x) (((x) << 0) & 0x00000003)
160   -#define CLKMGR_MAINPLLGRP_MAINDIV_L3SPCLK_SET(x) (((x) << 2) & 0x0000000c)
161   -#define CLKMGR_BYPASS_PERPLL_SET(x) (((x) << 3) & 0x00000008)
162   -#define CLKMGR_BYPASS_SDRPLL_SET(x) (((x) << 1) & 0x00000002)
163   -#define CLKMGR_BYPASS_MAINPLL_SET(x) (((x) << 0) & 0x00000001)
164   -#define CLKMGR_PERPLLGRP_DIV_USBCLK_SET(x) (((x) << 0) & 0x00000007)
165   -#define CLKMGR_PERPLLGRP_DIV_SPIMCLK_SET(x) (((x) << 3) & 0x00000038)
166   -#define CLKMGR_PERPLLGRP_DIV_CAN0CLK_SET(x) (((x) << 6) & 0x000001c0)
167   -#define CLKMGR_PERPLLGRP_DIV_CAN1CLK_SET(x) (((x) << 9) & 0x00000e00)
168   -#define CLKMGR_INTER_SDRPLLLOCKED_MASK 0x00000100
169   -#define CLKMGR_INTER_PERPLLLOCKED_MASK 0x00000080
170   -#define CLKMGR_INTER_MAINPLLLOCKED_MASK 0x00000040
171   -#define CLKMGR_CTRL_SAFEMODE_MASK 0x00000001
172   -#define CLKMGR_CTRL_SAFEMODE_SET(x) (((x) << 0) & 0x00000001)
173   -#define CLKMGR_SDRPLLGRP_VCO_OUTRESET_MASK 0x7e000000
174   -#define CLKMGR_SDRPLLGRP_VCO_OUTRESETALL_SET(x) (((x) << 24) & 0x01000000)
175   -#define CLKMGR_PERPLLGRP_PERQSPICLK_CNT_SET(x) (((x) << 0) & 0x000001ff)
176   -#define CLKMGR_PERPLLGRP_DIV_SPIMCLK_SET(x) (((x) << 3) & 0x00000038)
177   -#define CLKMGR_PERPLLGRP_GPIODIV_GPIODBCLK_SET(x) (((x) << 0) & 0x00ffffff)
178   -#define CLKMGR_BYPASS_PERPLLSRC_SET(x) (((x) << 4) & 0x00000010)
179   -#define CLKMGR_BYPASS_SDRPLLSRC_SET(x) (((x) << 2) & 0x00000004)
180   -#define CLKMGR_PERPLLGRP_SRC_RESET_VALUE 0x00000015
181   -#define CLKMGR_MAINPLLGRP_L4SRC_RESET_VALUE 0x00000000
182   -#define CLKMGR_MAINPLLGRP_VCO_REGEXTSEL_MASK 0x80000000
183   -#define CLKMGR_PERPLLGRP_VCO_REGEXTSEL_MASK 0x80000000
184   -#define CLKMGR_SDRPLLGRP_VCO_REGEXTSEL_MASK 0x80000000
185   -#define CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_MASK 0x001ffe00
186   -#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_MASK 0x001ffe00
187   -#define CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_MASK 0x001ffe00
188   -#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_MASK 0x001ffe00
189   -#define CLKMGR_MAINPLLGRP_VCO_OUTRESETALL_MASK 0x01000000
190   -#define CLKMGR_PERPLLGRP_VCO_OUTRESETALL_MASK 0x01000000
191   -#define CLKMGR_PERPLLGRP_EN_NANDCLK_MASK 0x00000400
192   -#define CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_MASK 0x000001ff
193   -#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_MASK 0x000001ff
194   -#define CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_MASK 0x000001ff
195   -#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_MASK 0x000001ff
  121 +#define CLKMGR_CTRL_SAFEMODE (1 << 0)
  122 +#define CLKMGR_CTRL_SAFEMODE_OFFSET 0
196 123  
197   -#define MAIN_VCO_BASE \
198   - (CLKMGR_MAINPLLGRP_VCO_DENOM_SET(CONFIG_HPS_MAINPLLGRP_VCO_DENOM) | \
199   - CLKMGR_MAINPLLGRP_VCO_NUMER_SET(CONFIG_HPS_MAINPLLGRP_VCO_NUMER))
  124 +#define CLKMGR_BYPASS_PERPLLSRC (1 << 4)
  125 +#define CLKMGR_BYPASS_PERPLLSRC_OFFSET 4
  126 +#define CLKMGR_BYPASS_PERPLL (1 << 3)
  127 +#define CLKMGR_BYPASS_PERPLL_OFFSET 3
  128 +#define CLKMGR_BYPASS_SDRPLLSRC (1 << 2)
  129 +#define CLKMGR_BYPASS_SDRPLLSRC_OFFSET 2
  130 +#define CLKMGR_BYPASS_SDRPLL (1 << 1)
  131 +#define CLKMGR_BYPASS_SDRPLL_OFFSET 1
  132 +#define CLKMGR_BYPASS_MAINPLL (1 << 0)
  133 +#define CLKMGR_BYPASS_MAINPLL_OFFSET 0
200 134  
201   -#define PERI_VCO_BASE \
202   - (CLKMGR_PERPLLGRP_VCO_PSRC_SET(CONFIG_HPS_PERPLLGRP_VCO_PSRC) | \
203   - CLKMGR_PERPLLGRP_VCO_DENOM_SET(CONFIG_HPS_PERPLLGRP_VCO_DENOM) | \
204   - CLKMGR_PERPLLGRP_VCO_NUMER_SET(CONFIG_HPS_PERPLLGRP_VCO_NUMER))
  135 +#define CLKMGR_INTER_SDRPLLLOCKED_MASK 0x00000100
  136 +#define CLKMGR_INTER_PERPLLLOCKED_MASK 0x00000080
  137 +#define CLKMGR_INTER_MAINPLLLOCKED_MASK 0x00000040
  138 +#define CLKMGR_INTER_PERPLLLOST_MASK 0x00000010
  139 +#define CLKMGR_INTER_SDRPLLLOST_MASK 0x00000020
  140 +#define CLKMGR_INTER_MAINPLLLOST_MASK 0x00000008
205 141  
206   -#define SDR_VCO_BASE \
207   - (CLKMGR_SDRPLLGRP_VCO_SSRC_SET(CONFIG_HPS_SDRPLLGRP_VCO_SSRC) | \
208   - CLKMGR_SDRPLLGRP_VCO_DENOM_SET(CONFIG_HPS_SDRPLLGRP_VCO_DENOM) | \
209   - CLKMGR_SDRPLLGRP_VCO_NUMER_SET(CONFIG_HPS_SDRPLLGRP_VCO_NUMER))
  142 +#define CLKMGR_STAT_BUSY (1 << 0)
  143 +
  144 +/* Main PLL */
  145 +#define CLKMGR_MAINPLLGRP_VCO_BGPWRDN (1 << 0)
  146 +#define CLKMGR_MAINPLLGRP_VCO_BGPWRDN_OFFSET 0
  147 +#define CLKMGR_MAINPLLGRP_VCO_DENOM_OFFSET 16
  148 +#define CLKMGR_MAINPLLGRP_VCO_DENOM_MASK 0x003f0000
  149 +#define CLKMGR_MAINPLLGRP_VCO_EN (1 << 1)
  150 +#define CLKMGR_MAINPLLGRP_VCO_EN_OFFSET 1
  151 +#define CLKMGR_MAINPLLGRP_VCO_NUMER_OFFSET 3
  152 +#define CLKMGR_MAINPLLGRP_VCO_NUMER_MASK 0x0000fff8
  153 +#define CLKMGR_MAINPLLGRP_VCO_OUTRESETALL_MASK 0x01000000
  154 +#define CLKMGR_MAINPLLGRP_VCO_PWRDN (1 << 2)
  155 +#define CLKMGR_MAINPLLGRP_VCO_PWRDN_OFFSET 2
  156 +#define CLKMGR_MAINPLLGRP_VCO_REGEXTSEL_MASK 0x80000000
  157 +#define CLKMGR_MAINPLLGRP_VCO_RESET_VALUE 0x8001000d
  158 +
  159 +#define CLKMGR_MAINPLLGRP_MPUCLK_CNT_OFFSET 0
  160 +#define CLKMGR_MAINPLLGRP_MPUCLK_CNT_MASK 0x000001ff
  161 +
  162 +#define CLKMGR_MAINPLLGRP_MAINCLK_CNT_OFFSET 0
  163 +#define CLKMGR_MAINPLLGRP_MAINCLK_CNT_MASK 0x000001ff
  164 +
  165 +#define CLKMGR_MAINPLLGRP_DBGATCLK_CNT_OFFSET 0
  166 +#define CLKMGR_MAINPLLGRP_DBGATCLK_CNT_MASK 0x000001ff
  167 +
  168 +#define CLKMGR_MAINPLLGRP_MAINQSPICLK_CNT_OFFSET 0
  169 +#define CLKMGR_MAINPLLGRP_MAINQSPICLK_CNT_MASK 0x000001ff
  170 +
  171 +#define CLKMGR_MAINPLLGRP_MAINNANDSDMMCCLK_CNT_OFFSET 0
  172 +#define CLKMGR_MAINPLLGRP_MAINNANDSDMMCCLK_CNT_MASK 0x000001ff
  173 +
  174 +#define CLKMGR_MAINPLLGRP_CFGS2FUSER0CLK_CNT_OFFSET 0
  175 +#define CLKMGR_MAINPLLGRP_CFGS2FUSER0CLK_CNT_MASK 0x000001ff
  176 +
  177 +#define CLKMGR_MAINPLLGRP_EN_DBGATCLK_MASK 0x00000010
  178 +#define CLKMGR_MAINPLLGRP_EN_DBGCLK_MASK 0x00000020
  179 +#define CLKMGR_MAINPLLGRP_EN_DBGTIMERCLK_MASK 0x00000080
  180 +#define CLKMGR_MAINPLLGRP_EN_DBGTRACECLK_MASK 0x00000040
  181 +#define CLKMGR_MAINPLLGRP_EN_L4MPCLK_MASK 0x00000004
  182 +#define CLKMGR_MAINPLLGRP_EN_S2FUSER0CLK_MASK 0x00000200
  183 +
  184 +#define CLKMGR_MAINPLLGRP_MAINDIV_L3MPCLK_OFFSET 0
  185 +#define CLKMGR_MAINPLLGRP_MAINDIV_L3MPCLK_MASK 0x00000003
  186 +#define CLKMGR_MAINPLLGRP_MAINDIV_L3SPCLK_OFFSET 2
  187 +#define CLKMGR_MAINPLLGRP_MAINDIV_L3SPCLK_MASK 0x0000000c
  188 +#define CLKMGR_MAINPLLGRP_MAINDIV_L4MPCLK_OFFSET 4
  189 +#define CLKMGR_MAINPLLGRP_MAINDIV_L4MPCLK_MASK 0x00000070
  190 +#define CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_OFFSET 7
  191 +#define CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_MASK 0x00000380
  192 +
  193 +#define CLKMGR_MAINPLLGRP_DBGDIV_DBGATCLK_OFFSET 0
  194 +#define CLKMGR_MAINPLLGRP_DBGDIV_DBGATCLK_MASK 0x00000003
  195 +#define CLKMGR_MAINPLLGRP_DBGDIV_DBGCLK_OFFSET 2
  196 +#define CLKMGR_MAINPLLGRP_DBGDIV_DBGCLK_MASK 0x0000000c
  197 +
  198 +#define CLKMGR_MAINPLLGRP_TRACEDIV_TRACECLK_OFFSET 0
  199 +#define CLKMGR_MAINPLLGRP_TRACEDIV_TRACECLK_MASK 0x00000007
  200 +
  201 +#define CLKMGR_MAINPLLGRP_L4SRC_L4MP (1 << 0)
  202 +#define CLKMGR_MAINPLLGRP_L4SRC_L4MP_OFFSET 0
  203 +#define CLKMGR_MAINPLLGRP_L4SRC_L4SP (1 << 1)
  204 +#define CLKMGR_MAINPLLGRP_L4SRC_L4SP_OFFSET 1
  205 +#define CLKMGR_MAINPLLGRP_L4SRC_RESET_VALUE 0x00000000
  206 +#define CLKMGR_L4_SP_CLK_SRC_MAINPLL 0x0
  207 +#define CLKMGR_L4_SP_CLK_SRC_PERPLL 0x1
  208 +
  209 +/* Per PLL */
  210 +#define CLKMGR_PERPLLGRP_VCO_DENOM_OFFSET 16
  211 +#define CLKMGR_PERPLLGRP_VCO_DENOM_MASK 0x003f0000
  212 +#define CLKMGR_PERPLLGRP_VCO_NUMER_OFFSET 3
  213 +#define CLKMGR_PERPLLGRP_VCO_NUMER_MASK 0x0000fff8
  214 +#define CLKMGR_PERPLLGRP_VCO_OUTRESETALL_MASK 0x01000000
  215 +#define CLKMGR_PERPLLGRP_VCO_PSRC_OFFSET 22
  216 +#define CLKMGR_PERPLLGRP_VCO_PSRC_MASK 0x00c00000
  217 +#define CLKMGR_PERPLLGRP_VCO_REGEXTSEL_MASK 0x80000000
  218 +#define CLKMGR_PERPLLGRP_VCO_RESET_VALUE 0x8001000d
  219 +#define CLKMGR_PERPLLGRP_VCO_SSRC_OFFSET 22
  220 +#define CLKMGR_PERPLLGRP_VCO_SSRC_MASK 0x00c00000
  221 +
  222 +#define CLKMGR_VCO_SSRC_EOSC1 0x0
  223 +#define CLKMGR_VCO_SSRC_EOSC2 0x1
  224 +#define CLKMGR_VCO_SSRC_F2S 0x2
  225 +
  226 +#define CLKMGR_PERPLLGRP_EMAC0CLK_CNT_OFFSET 0
  227 +#define CLKMGR_PERPLLGRP_EMAC0CLK_CNT_MASK 0x000001ff
  228 +
  229 +#define CLKMGR_PERPLLGRP_EMAC1CLK_CNT_OFFSET 0
  230 +#define CLKMGR_PERPLLGRP_EMAC1CLK_CNT_MASK 0x000001ff
  231 +
  232 +#define CLKMGR_PERPLLGRP_PERQSPICLK_CNT_OFFSET 0
  233 +#define CLKMGR_PERPLLGRP_PERQSPICLK_CNT_MASK 0x000001ff
  234 +
  235 +#define CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_OFFSET 0
  236 +#define CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_MASK 0x000001ff
  237 +
  238 +#define CLKMGR_PERPLLGRP_PERBASECLK_CNT_OFFSET 0
  239 +#define CLKMGR_PERPLLGRP_PERBASECLK_CNT_MASK 0x000001ff
  240 +
  241 +#define CLKMGR_PERPLLGRP_S2FUSER1CLK_CNT_OFFSET 0
  242 +#define CLKMGR_PERPLLGRP_S2FUSER1CLK_CNT_MASK 0x000001ff
  243 +
  244 +#define CLKMGR_PERPLLGRP_EN_NANDCLK_MASK 0x00000400
  245 +#define CLKMGR_PERPLLGRP_EN_SDMMCCLK_MASK 0x00000100
  246 +
  247 +#define CLKMGR_PERPLLGRP_DIV_CAN0CLK_OFFSET 6
  248 +#define CLKMGR_PERPLLGRP_DIV_CAN0CLK_MASK 0x000001c0
  249 +#define CLKMGR_PERPLLGRP_DIV_CAN1CLK_OFFSET 9
  250 +#define CLKMGR_PERPLLGRP_DIV_CAN1CLK_MASK 0x00000e00
  251 +#define CLKMGR_PERPLLGRP_DIV_SPIMCLK_OFFSET 3
  252 +#define CLKMGR_PERPLLGRP_DIV_SPIMCLK_OFFSET 3
  253 +#define CLKMGR_PERPLLGRP_DIV_USBCLK_OFFSET 0
  254 +#define CLKMGR_PERPLLGRP_DIV_USBCLK_MASK 0x00000007
  255 +
  256 +#define CLKMGR_PERPLLGRP_GPIODIV_GPIODBCLK_OFFSET 0
  257 +#define CLKMGR_PERPLLGRP_GPIODIV_GPIODBCLK_MASK 0x00ffffff
  258 +
  259 +#define CLKMGR_PERPLLGRP_SRC_NAND_OFFSET 2
  260 +#define CLKMGR_PERPLLGRP_SRC_NAND_MASK 0x0000000c
  261 +#define CLKMGR_PERPLLGRP_SRC_QSPI_OFFSET 4
  262 +#define CLKMGR_PERPLLGRP_SRC_QSPI_MASK 0x00000030
  263 +#define CLKMGR_PERPLLGRP_SRC_RESET_VALUE 0x00000015
  264 +#define CLKMGR_PERPLLGRP_SRC_SDMMC_OFFSET 0
  265 +#define CLKMGR_PERPLLGRP_SRC_SDMMC_MASK 0x00000003
  266 +#define CLKMGR_SDMMC_CLK_SRC_F2S 0x0
  267 +#define CLKMGR_SDMMC_CLK_SRC_MAIN 0x1
  268 +#define CLKMGR_SDMMC_CLK_SRC_PER 0x2
  269 +#define CLKMGR_QSPI_CLK_SRC_F2S 0x0
  270 +#define CLKMGR_QSPI_CLK_SRC_MAIN 0x1
  271 +#define CLKMGR_QSPI_CLK_SRC_PER 0x2
  272 +
  273 +/* SDR PLL */
  274 +#define CLKMGR_SDRPLLGRP_VCO_DENOM_OFFSET 16
  275 +#define CLKMGR_SDRPLLGRP_VCO_DENOM_MASK 0x003f0000
  276 +#define CLKMGR_SDRPLLGRP_VCO_NUMER_OFFSET 3
  277 +#define CLKMGR_SDRPLLGRP_VCO_NUMER_MASK 0x0000fff8
  278 +#define CLKMGR_SDRPLLGRP_VCO_OUTRESETALL (1 << 24)
  279 +#define CLKMGR_SDRPLLGRP_VCO_OUTRESETALL_OFFSET 24
  280 +#define CLKMGR_SDRPLLGRP_VCO_OUTRESET_OFFSET 25
  281 +#define CLKMGR_SDRPLLGRP_VCO_OUTRESET_MASK 0x7e000000
  282 +#define CLKMGR_SDRPLLGRP_VCO_REGEXTSEL_MASK 0x80000000
  283 +#define CLKMGR_SDRPLLGRP_VCO_RESET_VALUE 0x8001000d
  284 +#define CLKMGR_SDRPLLGRP_VCO_SSRC_OFFSET 22
  285 +#define CLKMGR_SDRPLLGRP_VCO_SSRC_MASK 0x00c00000
  286 +
  287 +#define CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_OFFSET 0
  288 +#define CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_MASK 0x000001ff
  289 +#define CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_OFFSET 9
  290 +#define CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_MASK 0x00000e00
  291 +
  292 +#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_OFFSET 0
  293 +#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_MASK 0x000001ff
  294 +#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_OFFSET 9
  295 +#define CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_MASK 0x00000e00
  296 +
  297 +#define CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_OFFSET 0
  298 +#define CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_MASK 0x000001ff
  299 +#define CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_OFFSET 9
  300 +#define CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_MASK 0x00000e00
  301 +
  302 +#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_OFFSET 0
  303 +#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_MASK 0x000001ff
  304 +#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_OFFSET 9
  305 +#define CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_MASK 0x00000e00
210 306  
211 307 #endif /* _CLOCK_MANAGER_H_ */
arch/arm/include/asm/arch-socfpga/fpga_manager.h
  1 +/*
  2 + * Copyright (C) 2012 Altera Corporation <www.altera.com>
  3 + * All rights reserved.
  4 + *
  5 + * SPDX-License-Identifier: BSD-3-Clause
  6 + */
  7 +
  8 +#ifndef _FPGA_MANAGER_H_
  9 +#define _FPGA_MANAGER_H_
  10 +
  11 +#include <altera.h>
  12 +
  13 +struct socfpga_fpga_manager {
  14 + /* FPGA Manager Module */
  15 + u32 stat; /* 0x00 */
  16 + u32 ctrl;
  17 + u32 dclkcnt;
  18 + u32 dclkstat;
  19 + u32 gpo; /* 0x10 */
  20 + u32 gpi;
  21 + u32 misci; /* 0x18 */
  22 + u32 _pad_0x1c_0x82c[517];
  23 +
  24 + /* Configuration Monitor (MON) Registers */
  25 + u32 gpio_inten; /* 0x830 */
  26 + u32 gpio_intmask;
  27 + u32 gpio_inttype_level;
  28 + u32 gpio_int_polarity;
  29 + u32 gpio_intstatus; /* 0x840 */
  30 + u32 gpio_raw_intstatus;
  31 + u32 _pad_0x848;
  32 + u32 gpio_porta_eoi;
  33 + u32 gpio_ext_porta; /* 0x850 */
  34 + u32 _pad_0x854_0x85c[3];
  35 + u32 gpio_1s_sync; /* 0x860 */
  36 + u32 _pad_0x864_0x868[2];
  37 + u32 gpio_ver_id_code;
  38 + u32 gpio_config_reg2; /* 0x870 */
  39 + u32 gpio_config_reg1;
  40 +};
  41 +
  42 +#define FPGAMGRREGS_STAT_MODE_MASK 0x7
  43 +#define FPGAMGRREGS_STAT_MSEL_MASK 0xf8
  44 +#define FPGAMGRREGS_STAT_MSEL_LSB 3
  45 +
  46 +#define FPGAMGRREGS_CTRL_CFGWDTH_MASK 0x200
  47 +#define FPGAMGRREGS_CTRL_AXICFGEN_MASK 0x100
  48 +#define FPGAMGRREGS_CTRL_NCONFIGPULL_MASK 0x4
  49 +#define FPGAMGRREGS_CTRL_NCE_MASK 0x2
  50 +#define FPGAMGRREGS_CTRL_EN_MASK 0x1
  51 +#define FPGAMGRREGS_CTRL_CDRATIO_LSB 6
  52 +
  53 +#define FPGAMGRREGS_MON_GPIO_EXT_PORTA_CRC_MASK 0x8
  54 +#define FPGAMGRREGS_MON_GPIO_EXT_PORTA_ID_MASK 0x4
  55 +#define FPGAMGRREGS_MON_GPIO_EXT_PORTA_CD_MASK 0x2
  56 +#define FPGAMGRREGS_MON_GPIO_EXT_PORTA_NS_MASK 0x1
  57 +
  58 +/* FPGA Mode */
  59 +#define FPGAMGRREGS_MODE_FPGAOFF 0x0
  60 +#define FPGAMGRREGS_MODE_RESETPHASE 0x1
  61 +#define FPGAMGRREGS_MODE_CFGPHASE 0x2
  62 +#define FPGAMGRREGS_MODE_INITPHASE 0x3
  63 +#define FPGAMGRREGS_MODE_USERMODE 0x4
  64 +#define FPGAMGRREGS_MODE_UNKNOWN 0x5
  65 +
  66 +/* FPGA CD Ratio Value */
  67 +#define CDRATIO_x1 0x0
  68 +#define CDRATIO_x2 0x1
  69 +#define CDRATIO_x4 0x2
  70 +#define CDRATIO_x8 0x3
  71 +
  72 +/* SoCFPGA support functions */
  73 +int fpgamgr_test_fpga_ready(void);
  74 +int fpgamgr_poll_fpga_ready(void);
  75 +int fpgamgr_get_mode(void);
  76 +
  77 +#endif /* _FPGA_MANAGER_H_ */
arch/arm/include/asm/arch-socfpga/nic301.h
  1 +/*
  2 + * Copyright (C) 2014 Marek Vasut <marex@denx.de>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#ifndef _NIC301_REGISTERS_H_
  8 +#define _NIC301_REGISTERS_H_
  9 +
  10 +struct nic301_registers {
  11 + u32 remap; /* 0x0 */
  12 + /* Security Register Group */
  13 + u32 _pad_0x4_0x8[1];
  14 + u32 l4main;
  15 + u32 l4sp;
  16 + u32 l4mp; /* 0x10 */
  17 + u32 l4osc1;
  18 + u32 l4spim;
  19 + u32 stm;
  20 + u32 lwhps2fpgaregs; /* 0x20 */
  21 + u32 _pad_0x24_0x28[1];
  22 + u32 usb1;
  23 + u32 nanddata;
  24 + u32 _pad_0x30_0x80[20];
  25 + u32 usb0; /* 0x80 */
  26 + u32 nandregs;
  27 + u32 qspidata;
  28 + u32 fpgamgrdata;
  29 + u32 hps2fpgaregs; /* 0x90 */
  30 + u32 acp;
  31 + u32 rom;
  32 + u32 ocram;
  33 + u32 sdrdata; /* 0xA0 */
  34 + u32 _pad_0xa4_0x1fd0[1995];
  35 + /* ID Register Group */
  36 + u32 periph_id_4; /* 0x1FD0 */
  37 + u32 _pad_0x1fd4_0x1fe0[3];
  38 + u32 periph_id_0; /* 0x1FE0 */
  39 + u32 periph_id_1;
  40 + u32 periph_id_2;
  41 + u32 periph_id_3;
  42 + u32 comp_id_0; /* 0x1FF0 */
  43 + u32 comp_id_1;
  44 + u32 comp_id_2;
  45 + u32 comp_id_3;
  46 + u32 _pad_0x2000_0x2008[2];
  47 + /* L4 MAIN */
  48 + u32 l4main_fn_mod_bm_iss;
  49 + u32 _pad_0x200c_0x3008[1023];
  50 + /* L4 SP */
  51 + u32 l4sp_fn_mod_bm_iss;
  52 + u32 _pad_0x300c_0x4008[1023];
  53 + /* L4 MP */
  54 + u32 l4mp_fn_mod_bm_iss;
  55 + u32 _pad_0x400c_0x5008[1023];
  56 + /* L4 OSC1 */
  57 + u32 l4osc_fn_mod_bm_iss;
  58 + u32 _pad_0x500c_0x6008[1023];
  59 + /* L4 SPIM */
  60 + u32 l4spim_fn_mod_bm_iss;
  61 + u32 _pad_0x600c_0x7008[1023];
  62 + /* STM */
  63 + u32 stm_fn_mod_bm_iss;
  64 + u32 _pad_0x700c_0x7108[63];
  65 + u32 stm_fn_mod;
  66 + u32 _pad_0x710c_0x8008[959];
  67 + /* LWHPS2FPGA */
  68 + u32 lwhps2fpga_fn_mod_bm_iss;
  69 + u32 _pad_0x800c_0x8108[63];
  70 + u32 lwhps2fpga_fn_mod;
  71 + u32 _pad_0x810c_0xa008[1983];
  72 + /* USB1 */
  73 + u32 usb1_fn_mod_bm_iss;
  74 + u32 _pad_0xa00c_0xa044[14];
  75 + u32 usb1_ahb_cntl;
  76 + u32 _pad_0xa048_0xb008[1008];
  77 + /* NANDDATA */
  78 + u32 nanddata_fn_mod_bm_iss;
  79 + u32 _pad_0xb00c_0xb108[63];
  80 + u32 nanddata_fn_mod;
  81 + u32 _pad_0xb10c_0x20008[21439];
  82 + /* USB0 */
  83 + u32 usb0_fn_mod_bm_iss;
  84 + u32 _pad_0x2000c_0x20044[14];
  85 + u32 usb0_ahb_cntl;
  86 + u32 _pad_0x20048_0x21008[1008];
  87 + /* NANDREGS */
  88 + u32 nandregs_fn_mod_bm_iss;
  89 + u32 _pad_0x2100c_0x21108[63];
  90 + u32 nandregs_fn_mod;
  91 + u32 _pad_0x2110c_0x22008[959];
  92 + /* QSPIDATA */
  93 + u32 qspidata_fn_mod_bm_iss;
  94 + u32 _pad_0x2200c_0x22044[14];
  95 + u32 qspidata_ahb_cntl;
  96 + u32 _pad_0x22048_0x23008[1008];
  97 + /* FPGAMGRDATA */
  98 + u32 fpgamgrdata_fn_mod_bm_iss;
  99 + u32 _pad_0x2300c_0x23040[13];
  100 + u32 fpgamgrdata_wr_tidemark; /* 0x23040 */
  101 + u32 _pad_0x23044_0x23108[49];
  102 + u32 fn_mod;
  103 + u32 _pad_0x2310c_0x24008[959];
  104 + /* HPS2FPGA */
  105 + u32 hps2fpga_fn_mod_bm_iss;
  106 + u32 _pad_0x2400c_0x24040[13];
  107 + u32 hps2fpga_wr_tidemark; /* 0x24040 */
  108 + u32 _pad_0x24044_0x24108[49];
  109 + u32 hps2fpga_fn_mod;
  110 + u32 _pad_0x2410c_0x25008[959];
  111 + /* ACP */
  112 + u32 acp_fn_mod_bm_iss;
  113 + u32 _pad_0x2500c_0x25108[63];
  114 + u32 acp_fn_mod;
  115 + u32 _pad_0x2510c_0x26008[959];
  116 + /* Boot ROM */
  117 + u32 bootrom_fn_mod_bm_iss;
  118 + u32 _pad_0x2600c_0x26108[63];
  119 + u32 bootrom_fn_mod;
  120 + u32 _pad_0x2610c_0x27008[959];
  121 + /* On-chip RAM */
  122 + u32 ocram_fn_mod_bm_iss;
  123 + u32 _pad_0x2700c_0x27040[13];
  124 + u32 ocram_wr_tidemark; /* 0x27040 */
  125 + u32 _pad_0x27044_0x27108[49];
  126 + u32 ocram_fn_mod;
  127 + u32 _pad_0x2710c_0x42024[27590];
  128 + /* DAP */
  129 + u32 dap_fn_mod2;
  130 + u32 dap_fn_mod_ahb;
  131 + u32 _pad_0x4202c_0x42100[53];
  132 + u32 dap_read_qos; /* 0x42100 */
  133 + u32 dap_write_qos;
  134 + u32 dap_fn_mod;
  135 + u32 _pad_0x4210c_0x43100[1021];
  136 + /* MPU */
  137 + u32 mpu_read_qos; /* 0x43100 */
  138 + u32 mpu_write_qos;
  139 + u32 mpu_fn_mod;
  140 + u32 _pad_0x4310c_0x44028[967];
  141 + /* SDMMC */
  142 + u32 sdmmc_fn_mod_ahb;
  143 + u32 _pad_0x4402c_0x44100[53];
  144 + u32 sdmmc_read_qos; /* 0x44100 */
  145 + u32 sdmmc_write_qos;
  146 + u32 sdmmc_fn_mod;
  147 + u32 _pad_0x4410c_0x45100[1021];
  148 + /* DMA */
  149 + u32 dma_read_qos; /* 0x45100 */
  150 + u32 dma_write_qos;
  151 + u32 dma_fn_mod;
  152 + u32 _pad_0x4510c_0x46040[973];
  153 + /* FPGA2HPS */
  154 + u32 fpga2hps_wr_tidemark; /* 0x46040 */
  155 + u32 _pad_0x46044_0x46100[47];
  156 + u32 fpga2hps_read_qos; /* 0x46100 */
  157 + u32 fpga2hps_write_qos;
  158 + u32 fpga2hps_fn_mod;
  159 + u32 _pad_0x4610c_0x47100[1021];
  160 + /* ETR */
  161 + u32 etr_read_qos; /* 0x47100 */
  162 + u32 etr_write_qos;
  163 + u32 etr_fn_mod;
  164 + u32 _pad_0x4710c_0x48100[1021];
  165 + /* EMAC0 */
  166 + u32 emac0_read_qos; /* 0x48100 */
  167 + u32 emac0_write_qos;
  168 + u32 emac0_fn_mod;
  169 + u32 _pad_0x4810c_0x49100[1021];
  170 + /* EMAC1 */
  171 + u32 emac1_read_qos; /* 0x49100 */
  172 + u32 emac1_write_qos;
  173 + u32 emac1_fn_mod;
  174 + u32 _pad_0x4910c_0x4a028[967];
  175 + /* USB0 */
  176 + u32 usb0_fn_mod_ahb;
  177 + u32 _pad_0x4a02c_0x4a100[53];
  178 + u32 usb0_read_qos; /* 0x4A100 */
  179 + u32 usb0_write_qos;
  180 + u32 usb0_fn_mod;
  181 + u32 _pad_0x4a10c_0x4b100[1021];
  182 + /* NAND */
  183 + u32 nand_read_qos; /* 0x4B100 */
  184 + u32 nand_write_qos;
  185 + u32 nand_fn_mod;
  186 + u32 _pad_0x4b10c_0x4c028[967];
  187 + /* USB1 */
  188 + u32 usb1_fn_mod_ahb;
  189 + u32 _pad_0x4c02c_0x4c100[53];
  190 + u32 usb1_read_qos; /* 0x4C100 */
  191 + u32 usb1_write_qos;
  192 + u32 usb1_fn_mod;
  193 +};
  194 +
  195 +#endif /* _NIC301_REGISTERS_H_ */
arch/arm/include/asm/arch-socfpga/reset_manager.h
... ... @@ -10,6 +10,11 @@
10 10 void reset_cpu(ulong addr);
11 11 void reset_deassert_peripherals_handoff(void);
12 12  
  13 +void socfpga_bridges_reset(int enable);
  14 +
  15 +void socfpga_emac_reset(int enable);
  16 +void socfpga_watchdog_reset(void);
  17 +
13 18 struct socfpga_reset_manager {
14 19 u32 status;
15 20 u32 ctrl;
... ... @@ -26,6 +31,10 @@
26 31 #else
27 32 #define RSTMGR_CTRL_SWWARMRSTREQ_LSB 1
28 33 #endif
  34 +
  35 +#define RSTMGR_PERMODRST_EMAC0_LSB 0
  36 +#define RSTMGR_PERMODRST_EMAC1_LSB 1
  37 +#define RSTMGR_PERMODRST_L4WD0_LSB 6
29 38  
30 39 #endif /* _RESET_MANAGER_H_ */
arch/arm/include/asm/arch-socfpga/scu.h
  1 +/*
  2 + * Copyright (C) 2014 Marek Vasut <marex@denx.de>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#ifndef __SOCFPGA_SCU_H__
  8 +#define __SOCFPGA_SCU_H__
  9 +
  10 +struct scu_registers {
  11 + u32 ctrl; /* 0x00 */
  12 + u32 cfg;
  13 + u32 cpsr;
  14 + u32 iassr;
  15 + u32 _pad_0x10_0x3c[12]; /* 0x10 */
  16 + u32 fsar; /* 0x40 */
  17 + u32 fear;
  18 + u32 _pad_0x48_0x50[2];
  19 + u32 acr; /* 0x54 */
  20 + u32 sacr;
  21 +};
  22 +
  23 +#endif /* __SOCFPGA_SCU_H__ */
arch/arm/include/asm/arch-socfpga/socfpga_base_addrs.h
... ... @@ -7,17 +7,57 @@
7 7 #ifndef _SOCFPGA_BASE_ADDRS_H_
8 8 #define _SOCFPGA_BASE_ADDRS_H_
9 9  
10   -#define SOCFPGA_L3REGS_ADDRESS 0xff800000
11   -#define SOCFPGA_UART0_ADDRESS 0xffc02000
12   -#define SOCFPGA_UART1_ADDRESS 0xffc03000
13   -#define SOCFPGA_OSC1TIMER0_ADDRESS 0xffd00000
14   -#define SOCFPGA_L4WD0_ADDRESS 0xffd02000
15   -#define SOCFPGA_CLKMGR_ADDRESS 0xffd04000
16   -#define SOCFPGA_RSTMGR_ADDRESS 0xffd05000
17   -#define SOCFPGA_SYSMGR_ADDRESS 0xffd08000
18   -#define SOCFPGA_SCANMGR_ADDRESS 0xfff02000
19   -#define SOCFPGA_EMAC0_ADDRESS 0xff700000
20   -#define SOCFPGA_EMAC1_ADDRESS 0xff702000
  10 +#define SOCFPGA_STM_ADDRESS 0xfc000000
  11 +#define SOCFPGA_DAP_ADDRESS 0xff000000
  12 +#define SOCFPGA_EMAC0_ADDRESS 0xff700000
  13 +#define SOCFPGA_EMAC1_ADDRESS 0xff702000
  14 +#define SOCFPGA_SDMMC_ADDRESS 0xff704000
  15 +#define SOCFPGA_QSPI_ADDRESS 0xff705000
  16 +#define SOCFPGA_GPIO0_ADDRESS 0xff708000
  17 +#define SOCFPGA_GPIO1_ADDRESS 0xff709000
  18 +#define SOCFPGA_GPIO2_ADDRESS 0xff70a000
  19 +#define SOCFPGA_L3REGS_ADDRESS 0xff800000
  20 +#define SOCFPGA_USB0_ADDRESS 0xffb00000
  21 +#define SOCFPGA_USB1_ADDRESS 0xffb40000
  22 +#define SOCFPGA_CAN0_ADDRESS 0xffc00000
  23 +#define SOCFPGA_CAN1_ADDRESS 0xffc01000
  24 +#define SOCFPGA_UART0_ADDRESS 0xffc02000
  25 +#define SOCFPGA_UART1_ADDRESS 0xffc03000
  26 +#define SOCFPGA_I2C0_ADDRESS 0xffc04000
  27 +#define SOCFPGA_I2C1_ADDRESS 0xffc05000
  28 +#define SOCFPGA_I2C2_ADDRESS 0xffc06000
  29 +#define SOCFPGA_I2C3_ADDRESS 0xffc07000
  30 +#define SOCFPGA_SDR_ADDRESS 0xffc20000
  31 +#define SOCFPGA_L4WD0_ADDRESS 0xffd02000
  32 +#define SOCFPGA_L4WD1_ADDRESS 0xffd03000
  33 +#define SOCFPGA_CLKMGR_ADDRESS 0xffd04000
  34 +#define SOCFPGA_RSTMGR_ADDRESS 0xffd05000
  35 +#define SOCFPGA_SYSMGR_ADDRESS 0xffd08000
  36 +#define SOCFPGA_SPIS0_ADDRESS 0xffe02000
  37 +#define SOCFPGA_SPIS1_ADDRESS 0xffe03000
  38 +#define SOCFPGA_SPIM0_ADDRESS 0xfff00000
  39 +#define SOCFPGA_SPIM1_ADDRESS 0xfff01000
  40 +#define SOCFPGA_SCANMGR_ADDRESS 0xfff02000
  41 +#define SOCFPGA_ROM_ADDRESS 0xfffd0000
  42 +#define SOCFPGA_MPUSCU_ADDRESS 0xfffec000
  43 +#define SOCFPGA_MPUL2_ADDRESS 0xfffef000
  44 +#define SOCFPGA_OCRAM_ADDRESS 0xffff0000
  45 +#define SOCFPGA_LWFPGASLAVES_ADDRESS 0xff200000
  46 +#define SOCFPGA_LWHPS2FPGAREGS_ADDRESS 0xff400000
  47 +#define SOCFPGA_HPS2FPGAREGS_ADDRESS 0xff500000
  48 +#define SOCFPGA_FPGA2HPSREGS_ADDRESS 0xff600000
  49 +#define SOCFPGA_FPGAMGRREGS_ADDRESS 0xff706000
  50 +#define SOCFPGA_ACPIDMAP_ADDRESS 0xff707000
  51 +#define SOCFPGA_NANDDATA_ADDRESS 0xff900000
  52 +#define SOCFPGA_QSPIDATA_ADDRESS 0xffa00000
  53 +#define SOCFPGA_NANDREGS_ADDRESS 0xffb80000
  54 +#define SOCFPGA_FPGAMGRDATA_ADDRESS 0xffb90000
  55 +#define SOCFPGA_SPTIMER0_ADDRESS 0xffc08000
  56 +#define SOCFPGA_SPTIMER1_ADDRESS 0xffc09000
  57 +#define SOCFPGA_OSC1TIMER0_ADDRESS 0xffd00000
  58 +#define SOCFPGA_OSC1TIMER1_ADDRESS 0xffd01000
  59 +#define SOCFPGA_DMANONSECURE_ADDRESS 0xffe00000
  60 +#define SOCFPGA_DMASECURE_ADDRESS 0xffe01000
21 61  
22 62 #endif /* _SOCFPGA_BASE_ADDRS_H_ */
arch/arm/include/asm/arch-socfpga/system_manager.h
1 1 /*
2   - * Copyright (C) 2013 Altera Corporation <www.altera.com>
  2 + * Copyright (C) 2013 Altera Corporation <www.altera.com>
3 3 *
4 4 * SPDX-License-Identifier: GPL-2.0+
5 5 */
6 6  
7 7  
8 8  
9 9  
10 10  
11 11  
12 12  
13 13  
14 14  
15 15  
16 16  
17 17  
18 18  
19 19  
20 20  
21 21  
22 22  
23 23  
24 24  
25 25  
26 26  
... ... @@ -16,73 +16,132 @@
16 16  
17 17 #endif
18 18  
19   -
20   -#define CONFIG_SYSMGR_PINMUXGRP_OFFSET (0x400)
21   -
22   -#define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \
23   - ((((drvsel) << 0) & 0x7) | (((smplsel) << 3) & 0x38))
24   -
25 19 struct socfpga_system_manager {
26   - u32 siliconid1;
  20 + /* System Manager Module */
  21 + u32 siliconid1; /* 0x00 */
27 22 u32 siliconid2;
28 23 u32 _pad_0x8_0xf[2];
29   - u32 wddbg;
  24 + u32 wddbg; /* 0x10 */
30 25 u32 bootinfo;
31 26 u32 hpsinfo;
32 27 u32 parityinj;
33   - u32 fpgaintfgrp_gbl;
  28 + /* FPGA Interface Group */
  29 + u32 fpgaintfgrp_gbl; /* 0x20 */
34 30 u32 fpgaintfgrp_indiv;
35 31 u32 fpgaintfgrp_module;
36 32 u32 _pad_0x2c_0x2f;
37   - u32 scanmgrgrp_ctrl;
  33 + /* Scan Manager Group */
  34 + u32 scanmgrgrp_ctrl; /* 0x30 */
38 35 u32 _pad_0x34_0x3f[3];
39   - u32 frzctrl_vioctrl;
  36 + /* Freeze Control Group */
  37 + u32 frzctrl_vioctrl; /* 0x40 */
40 38 u32 _pad_0x44_0x4f[3];
41   - u32 frzctrl_hioctrl;
  39 + u32 frzctrl_hioctrl; /* 0x50 */
42 40 u32 frzctrl_src;
43 41 u32 frzctrl_hwctrl;
44 42 u32 _pad_0x5c_0x5f;
45   - u32 emacgrp_ctrl;
  43 + /* EMAC Group */
  44 + u32 emacgrp_ctrl; /* 0x60 */
46 45 u32 emacgrp_l3master;
47 46 u32 _pad_0x68_0x6f[2];
48   - u32 dmagrp_ctrl;
  47 + /* DMA Controller Group */
  48 + u32 dmagrp_ctrl; /* 0x70 */
49 49 u32 dmagrp_persecurity;
50 50 u32 _pad_0x78_0x7f[2];
51   - u32 iswgrp_handoff[8];
52   - u32 _pad_0xa0_0xbf[8];
53   - u32 romcodegrp_ctrl;
  51 + /* Preloader (initial software) Group */
  52 + u32 iswgrp_handoff[8]; /* 0x80 */
  53 + u32 _pad_0xa0_0xbf[8]; /* 0xa0 */
  54 + /* Boot ROM Code Register Group */
  55 + u32 romcodegrp_ctrl; /* 0xc0 */
54 56 u32 romcodegrp_cpu1startaddr;
55 57 u32 romcodegrp_initswstate;
56 58 u32 romcodegrp_initswlastld;
57   - u32 romcodegrp_bootromswstate;
  59 + u32 romcodegrp_bootromswstate; /* 0xd0 */
58 60 u32 __pad_0xd4_0xdf[3];
59   - u32 romcodegrp_warmramgrp_enable;
  61 + /* Warm Boot from On-Chip RAM Group */
  62 + u32 romcodegrp_warmramgrp_enable; /* 0xe0 */
60 63 u32 romcodegrp_warmramgrp_datastart;
61 64 u32 romcodegrp_warmramgrp_length;
62 65 u32 romcodegrp_warmramgrp_execution;
63   - u32 romcodegrp_warmramgrp_crc;
  66 + u32 romcodegrp_warmramgrp_crc; /* 0xf0 */
64 67 u32 __pad_0xf4_0xff[3];
65   - u32 romhwgrp_ctrl;
  68 + /* Boot ROM Hardware Register Group */
  69 + u32 romhwgrp_ctrl; /* 0x100 */
66 70 u32 _pad_0x104_0x107;
  71 + /* SDMMC Controller Group */
67 72 u32 sdmmcgrp_ctrl;
68 73 u32 sdmmcgrp_l3master;
69   - u32 nandgrp_bootstrap;
  74 + /* NAND Flash Controller Register Group */
  75 + u32 nandgrp_bootstrap; /* 0x110 */
70 76 u32 nandgrp_l3master;
  77 + /* USB Controller Group */
71 78 u32 usbgrp_l3master;
72 79 u32 _pad_0x11c_0x13f[9];
73   - u32 eccgrp_l2;
  80 + /* ECC Management Register Group */
  81 + u32 eccgrp_l2; /* 0x140 */
74 82 u32 eccgrp_ocram;
75 83 u32 eccgrp_usb0;
76 84 u32 eccgrp_usb1;
77   - u32 eccgrp_emac0;
  85 + u32 eccgrp_emac0; /* 0x150 */
78 86 u32 eccgrp_emac1;
79 87 u32 eccgrp_dma;
80 88 u32 eccgrp_can0;
81   - u32 eccgrp_can1;
  89 + u32 eccgrp_can1; /* 0x160 */
82 90 u32 eccgrp_nand;
83 91 u32 eccgrp_qspi;
84 92 u32 eccgrp_sdmmc;
  93 + u32 _pad_0x170_0x3ff[164];
  94 + /* Pin Mux Control Group */
  95 + u32 emacio[20]; /* 0x400 */
  96 + u32 flashio[12]; /* 0x450 */
  97 + u32 generalio[28]; /* 0x480 */
  98 + u32 _pad_0x4f0_0x4ff[4];
  99 + u32 mixed1io[22]; /* 0x500 */
  100 + u32 mixed2io[8]; /* 0x558 */
  101 + u32 gplinmux[23]; /* 0x578 */
  102 + u32 gplmux[71]; /* 0x5d4 */
  103 + u32 nandusefpga; /* 0x6f0 */
  104 + u32 _pad_0x6f4;
  105 + u32 rgmii1usefpga; /* 0x6f8 */
  106 + u32 _pad_0x6fc_0x700[2];
  107 + u32 i2c0usefpga; /* 0x704 */
  108 + u32 sdmmcusefpga; /* 0x708 */
  109 + u32 _pad_0x70c_0x710[2];
  110 + u32 rgmii0usefpga; /* 0x714 */
  111 + u32 _pad_0x718_0x720[3];
  112 + u32 i2c3usefpga; /* 0x724 */
  113 + u32 i2c2usefpga; /* 0x728 */
  114 + u32 i2c1usefpga; /* 0x72c */
  115 + u32 spim1usefpga; /* 0x730 */
  116 + u32 _pad_0x734;
  117 + u32 spim0usefpga; /* 0x738 */
85 118 };
  119 +
  120 +#define SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGPINMUX (1 << 0)
  121 +#define SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO (1 << 1)
  122 +#define SYSMGR_ECC_OCRAM_EN (1 << 0)
  123 +#define SYSMGR_ECC_OCRAM_SERR (1 << 3)
  124 +#define SYSMGR_ECC_OCRAM_DERR (1 << 4)
  125 +#define SYSMGR_FPGAINTF_USEFPGA 0x1
  126 +#define SYSMGR_FPGAINTF_SPIM0 (1 << 0)
  127 +#define SYSMGR_FPGAINTF_SPIM1 (1 << 1)
  128 +#define SYSMGR_FPGAINTF_EMAC0 (1 << 2)
  129 +#define SYSMGR_FPGAINTF_EMAC1 (1 << 3)
  130 +#define SYSMGR_FPGAINTF_NAND (1 << 4)
  131 +#define SYSMGR_FPGAINTF_SDMMC (1 << 5)
  132 +
  133 +/* FIXME: This is questionable macro. */
  134 +#define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \
  135 + ((((drvsel) << 0) & 0x7) | (((smplsel) << 3) & 0x38))
  136 +
  137 +/* EMAC Group Bit definitions */
  138 +#define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0
  139 +#define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1
  140 +#define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII 0x2
  141 +
  142 +#define SYSMGR_EMACGRP_CTRL_PHYSEL0_LSB 0
  143 +#define SYSMGR_EMACGRP_CTRL_PHYSEL1_LSB 2
  144 +#define SYSMGR_EMACGRP_CTRL_PHYSEL_MASK 0x3
86 145  
87 146 #endif /* _SYSTEM_MANAGER_H_ */
arch/arm/include/asm/system.h
... ... @@ -185,6 +185,7 @@
185 185 DCACHE_OFF = 0x12,
186 186 DCACHE_WRITETHROUGH = 0x1a,
187 187 DCACHE_WRITEBACK = 0x1e,
  188 + DCACHE_WRITEALLOC = 0x16,
188 189 };
189 190  
190 191 /* Size of an MMU section */
arch/arm/lib/cache-cp15.c
... ... @@ -73,6 +73,8 @@
73 73 i++) {
74 74 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
75 75 set_section_dcache(i, DCACHE_WRITETHROUGH);
  76 +#elif defined(CONFIG_SYS_ARM_CACHE_WRITEALLOC)
  77 + set_section_dcache(i, DCACHE_WRITEALLOC);
76 78 #else
77 79 set_section_dcache(i, DCACHE_WRITEBACK);
78 80 #endif
board/altera/socfpga/pll_config.h
... ... @@ -94,6 +94,9 @@
94 94  
95 95 /* Info for driver */
96 96 #define CONFIG_HPS_CLK_OSC1_HZ (25000000)
  97 +#define CONFIG_HPS_CLK_OSC2_HZ 0
  98 +#define CONFIG_HPS_CLK_F2S_SDR_REF_HZ 0
  99 +#define CONFIG_HPS_CLK_F2S_PER_REF_HZ 0
97 100 #define CONFIG_HPS_CLK_MAINVCO_HZ (1600000000)
98 101 #define CONFIG_HPS_CLK_PERVCO_HZ (1000000000)
99 102 #ifdef CONFIG_SOCFPGA_ARRIA5
board/altera/socfpga/socfpga_cyclone5.c
... ... @@ -17,7 +17,7 @@
17 17 */
18 18 int checkboard(void)
19 19 {
20   - puts("BOARD : Altera SOCFPGA Cyclone5 Board\n");
  20 + puts("BOARD: Altera SoCFPGA Cyclone5 Board\n");
21 21 return 0;
22 22 }
23 23  
... ... @@ -34,7 +34,9 @@
34 34 */
35 35 int board_init(void)
36 36 {
37   - icache_enable();
  37 + /* Address of boot parameters for ATAG (if ATAG is used) */
  38 + gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  39 +
38 40 return 0;
39 41 }
... ... @@ -138,6 +138,7 @@
138 138 { IH_TYPE_PBLIMAGE, "pblimage", "Freescale PBL Boot Image",},
139 139 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
140 140 { IH_TYPE_SCRIPT, "script", "Script", },
  141 + { IH_TYPE_SOCFPGAIMAGE, "socfpgaimage", "Altera SOCFPGA preloader",},
141 142 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
142 143 { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
143 144 { IH_TYPE_MXSIMAGE, "mxsimage", "Freescale MXS Boot Image",},
drivers/fpga/Makefile
... ... @@ -17,5 +17,6 @@
17 17 obj-$(CONFIG_FPGA_ACEX1K) += ACEX1K.o
18 18 obj-$(CONFIG_FPGA_CYCLON2) += cyclon2.o
19 19 obj-$(CONFIG_FPGA_STRATIX_II) += stratixII.o
  20 +obj-$(CONFIG_FPGA_SOCFPGA) += socfpga.o
20 21 endif
drivers/fpga/altera.c
... ... @@ -12,217 +12,163 @@
12 12 * Altera FPGA support
13 13 */
14 14 #include <common.h>
  15 +#include <errno.h>
15 16 #include <ACEX1K.h>
16 17 #include <stratixII.h>
17 18  
18   -/* Define FPGA_DEBUG to get debug printf's */
19   -/* #define FPGA_DEBUG */
  19 +/* Define FPGA_DEBUG to 1 to get debug printf's */
  20 +#define FPGA_DEBUG 0
20 21  
21   -#ifdef FPGA_DEBUG
22   -#define PRINTF(fmt,args...) printf (fmt ,##args)
23   -#else
24   -#define PRINTF(fmt,args...)
25   -#endif
26   -
27   -/* Local Static Functions */
28   -static int altera_validate (Altera_desc * desc, const char *fn);
29   -
30   -/* ------------------------------------------------------------------------- */
31   -int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
32   -{
33   - int ret_val = FPGA_FAIL; /* assume a failure */
34   -
35   - if (!altera_validate (desc, (char *)__FUNCTION__)) {
36   - printf ("%s: Invalid device descriptor\n", __FUNCTION__);
37   - } else {
38   - switch (desc->family) {
39   - case Altera_ACEX1K:
40   - case Altera_CYC2:
  22 +static const struct altera_fpga {
  23 + enum altera_family family;
  24 + const char *name;
  25 + int (*load)(Altera_desc *, const void *, size_t);
  26 + int (*dump)(Altera_desc *, const void *, size_t);
  27 + int (*info)(Altera_desc *);
  28 +} altera_fpga[] = {
41 29 #if defined(CONFIG_FPGA_ACEX1K)
42   - PRINTF ("%s: Launching the ACEX1K Loader...\n",
43   - __FUNCTION__);
44   - ret_val = ACEX1K_load (desc, buf, bsize);
  30 + { Altera_ACEX1K, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info },
  31 + { Altera_CYC2, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info },
45 32 #elif defined(CONFIG_FPGA_CYCLON2)
46   - PRINTF ("%s: Launching the CYCLONE II Loader...\n",
47   - __FUNCTION__);
48   - ret_val = CYC2_load (desc, buf, bsize);
49   -#else
50   - printf ("%s: No support for ACEX1K devices.\n",
51   - __FUNCTION__);
  33 + { Altera_ACEX1K, "CycloneII", CYC2_load, CYC2_dump, CYC2_info },
  34 + { Altera_CYC2, "CycloneII", CYC2_load, CYC2_dump, CYC2_info },
52 35 #endif
53   - break;
54   -
55 36 #if defined(CONFIG_FPGA_STRATIX_II)
56   - case Altera_StratixII:
57   - PRINTF ("%s: Launching the Stratix II Loader...\n",
58   - __FUNCTION__);
59   - ret_val = StratixII_load (desc, buf, bsize);
60   - break;
  37 + { Altera_StratixII, "StratixII", StratixII_load,
  38 + StratixII_dump, StratixII_info },
61 39 #endif
62   - default:
63   - printf ("%s: Unsupported family type, %d\n",
64   - __FUNCTION__, desc->family);
65   - }
  40 +#if defined(CONFIG_FPGA_SOCFPGA)
  41 + { Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL },
  42 +#endif
  43 +};
  44 +
  45 +static int altera_validate(Altera_desc *desc, const char *fn)
  46 +{
  47 + if (!desc) {
  48 + printf("%s: NULL descriptor!\n", fn);
  49 + return -EINVAL;
66 50 }
67 51  
68   - return ret_val;
  52 + if ((desc->family < min_altera_type) ||
  53 + (desc->family > max_altera_type)) {
  54 + printf("%s: Invalid family type, %d\n", fn, desc->family);
  55 + return -EINVAL;
  56 + }
  57 +
  58 + if ((desc->iface < min_altera_iface_type) ||
  59 + (desc->iface > max_altera_iface_type)) {
  60 + printf("%s: Invalid Interface type, %d\n", fn, desc->iface);
  61 + return -EINVAL;
  62 + }
  63 +
  64 + if (!desc->size) {
  65 + printf("%s: NULL part size\n", fn);
  66 + return -EINVAL;
  67 + }
  68 +
  69 + return 0;
69 70 }
70 71  
71   -int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
  72 +static const struct altera_fpga *
  73 +altera_desc_to_fpga(Altera_desc *desc, const char *fn)
72 74 {
73   - int ret_val = FPGA_FAIL; /* assume a failure */
  75 + int i;
74 76  
75   - if (!altera_validate (desc, (char *)__FUNCTION__)) {
76   - printf ("%s: Invalid device descriptor\n", __FUNCTION__);
77   - } else {
78   - switch (desc->family) {
79   - case Altera_ACEX1K:
80   -#if defined(CONFIG_FPGA_ACEX)
81   - PRINTF ("%s: Launching the ACEX1K Reader...\n",
82   - __FUNCTION__);
83   - ret_val = ACEX1K_dump (desc, buf, bsize);
84   -#else
85   - printf ("%s: No support for ACEX1K devices.\n",
86   - __FUNCTION__);
87   -#endif
88   - break;
  77 + if (altera_validate(desc, fn)) {
  78 + printf("%s: Invalid device descriptor\n", fn);
  79 + return NULL;
  80 + }
89 81  
90   -#if defined(CONFIG_FPGA_STRATIX_II)
91   - case Altera_StratixII:
92   - PRINTF ("%s: Launching the Stratix II Reader...\n",
93   - __FUNCTION__);
94   - ret_val = StratixII_dump (desc, buf, bsize);
  82 + for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) {
  83 + if (desc->family == altera_fpga[i].family)
95 84 break;
96   -#endif
97   - default:
98   - printf ("%s: Unsupported family type, %d\n",
99   - __FUNCTION__, desc->family);
100   - }
101 85 }
102 86  
103   - return ret_val;
  87 + if (i == ARRAY_SIZE(altera_fpga)) {
  88 + printf("%s: Unsupported family type, %d\n", fn, desc->family);
  89 + return NULL;
  90 + }
  91 +
  92 + return &altera_fpga[i];
104 93 }
105 94  
106   -int altera_info( Altera_desc *desc )
  95 +int altera_load(Altera_desc *desc, const void *buf, size_t bsize)
107 96 {
108   - int ret_val = FPGA_FAIL;
  97 + const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
109 98  
110   - if (altera_validate (desc, (char *)__FUNCTION__)) {
111   - printf ("Family: \t");
112   - switch (desc->family) {
113   - case Altera_ACEX1K:
114   - printf ("ACEX1K\n");
115   - break;
116   - case Altera_CYC2:
117   - printf ("CYCLON II\n");
118   - break;
119   - case Altera_StratixII:
120   - printf ("Stratix II\n");
121   - break;
122   - /* Add new family types here */
123   - default:
124   - printf ("Unknown family type, %d\n", desc->family);
125   - }
  99 + if (!fpga)
  100 + return FPGA_FAIL;
126 101  
127   - printf ("Interface type:\t");
128   - switch (desc->iface) {
129   - case passive_serial:
130   - printf ("Passive Serial (PS)\n");
131   - break;
132   - case passive_parallel_synchronous:
133   - printf ("Passive Parallel Synchronous (PPS)\n");
134   - break;
135   - case passive_parallel_asynchronous:
136   - printf ("Passive Parallel Asynchronous (PPA)\n");
137   - break;
138   - case passive_serial_asynchronous:
139   - printf ("Passive Serial Asynchronous (PSA)\n");
140   - break;
141   - case altera_jtag_mode: /* Not used */
142   - printf ("JTAG Mode\n");
143   - break;
144   - case fast_passive_parallel:
145   - printf ("Fast Passive Parallel (FPP)\n");
146   - break;
147   - case fast_passive_parallel_security:
148   - printf
149   - ("Fast Passive Parallel with Security (FPPS) \n");
150   - break;
151   - /* Add new interface types here */
152   - default:
153   - printf ("Unsupported interface type, %d\n", desc->iface);
154   - }
  102 + debug_cond(FPGA_DEBUG, "%s: Launching the %s Loader...\n",
  103 + __func__, fpga->name);
  104 + if (fpga->load)
  105 + return fpga->load(desc, buf, bsize);
  106 + return 0;
  107 +}
155 108  
156   - printf("Device Size: \t%zd bytes\n"
157   - "Cookie: \t0x%x (%d)\n",
158   - desc->size, desc->cookie, desc->cookie);
  109 +int altera_dump(Altera_desc *desc, const void *buf, size_t bsize)
  110 +{
  111 + const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
159 112  
160   - if (desc->iface_fns) {
161   - printf ("Device Function Table @ 0x%p\n", desc->iface_fns);
162   - switch (desc->family) {
163   - case Altera_ACEX1K:
164   - case Altera_CYC2:
165   -#if defined(CONFIG_FPGA_ACEX1K)
166   - ACEX1K_info (desc);
167   -#elif defined(CONFIG_FPGA_CYCLON2)
168   - CYC2_info (desc);
169   -#else
170   - /* just in case */
171   - printf ("%s: No support for ACEX1K devices.\n",
172   - __FUNCTION__);
173   -#endif
174   - break;
175   -#if defined(CONFIG_FPGA_STRATIX_II)
176   - case Altera_StratixII:
177   - StratixII_info (desc);
178   - break;
179   -#endif
180   - /* Add new family types here */
181   - default:
182   - /* we don't need a message here - we give one up above */
183   - break;
184   - }
185   - } else {
186   - printf ("No Device Function Table.\n");
187   - }
  113 + if (!fpga)
  114 + return FPGA_FAIL;
188 115  
189   - ret_val = FPGA_SUCCESS;
190   - } else {
191   - printf ("%s: Invalid device descriptor\n", __FUNCTION__);
192   - }
193   -
194   - return ret_val;
  116 + debug_cond(FPGA_DEBUG, "%s: Launching the %s Reader...\n",
  117 + __func__, fpga->name);
  118 + if (fpga->dump)
  119 + return fpga->dump(desc, buf, bsize);
  120 + return 0;
195 121 }
196 122  
197   -/* ------------------------------------------------------------------------- */
198   -
199   -static int altera_validate (Altera_desc * desc, const char *fn)
  123 +int altera_info(Altera_desc *desc)
200 124 {
201   - int ret_val = false;
  125 + const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__);
202 126  
203   - if (desc) {
204   - if ((desc->family > min_altera_type) &&
205   - (desc->family < max_altera_type)) {
206   - if ((desc->iface > min_altera_iface_type) &&
207   - (desc->iface < max_altera_iface_type)) {
208   - if (desc->size) {
209   - ret_val = true;
210   - } else {
211   - printf ("%s: NULL part size\n", fn);
212   - }
213   - } else {
214   - printf ("%s: Invalid Interface type, %d\n",
215   - fn, desc->iface);
216   - }
217   - } else {
218   - printf ("%s: Invalid family type, %d\n", fn, desc->family);
219   - }
  127 + if (!fpga)
  128 + return FPGA_FAIL;
  129 +
  130 + printf("Family: \t%s\n", fpga->name);
  131 +
  132 + printf("Interface type:\t");
  133 + switch (desc->iface) {
  134 + case passive_serial:
  135 + printf("Passive Serial (PS)\n");
  136 + break;
  137 + case passive_parallel_synchronous:
  138 + printf("Passive Parallel Synchronous (PPS)\n");
  139 + break;
  140 + case passive_parallel_asynchronous:
  141 + printf("Passive Parallel Asynchronous (PPA)\n");
  142 + break;
  143 + case passive_serial_asynchronous:
  144 + printf("Passive Serial Asynchronous (PSA)\n");
  145 + break;
  146 + case altera_jtag_mode: /* Not used */
  147 + printf("JTAG Mode\n");
  148 + break;
  149 + case fast_passive_parallel:
  150 + printf("Fast Passive Parallel (FPP)\n");
  151 + break;
  152 + case fast_passive_parallel_security:
  153 + printf("Fast Passive Parallel with Security (FPPS)\n");
  154 + break;
  155 + /* Add new interface types here */
  156 + default:
  157 + printf("Unsupported interface type, %d\n", desc->iface);
  158 + }
  159 +
  160 + printf("Device Size: \t%zd bytes\n"
  161 + "Cookie: \t0x%x (%d)\n",
  162 + desc->size, desc->cookie, desc->cookie);
  163 +
  164 + if (desc->iface_fns) {
  165 + printf("Device Function Table @ 0x%p\n", desc->iface_fns);
  166 + if (fpga->info)
  167 + fpga->info(desc);
220 168 } else {
221   - printf ("%s: NULL descriptor!\n", fn);
  169 + printf("No Device Function Table.\n");
222 170 }
223 171  
224   - return ret_val;
  172 + return FPGA_SUCCESS;
225 173 }
226   -
227   -/* ------------------------------------------------------------------------- */
drivers/fpga/socfpga.c
  1 +/*
  2 + * Copyright (C) 2012 Altera Corporation <www.altera.com>
  3 + * All rights reserved.
  4 + *
  5 + * SPDX-License-Identifier: BSD-3-Clause
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <asm/io.h>
  10 +#include <asm/errno.h>
  11 +#include <asm/arch/fpga_manager.h>
  12 +#include <asm/arch/reset_manager.h>
  13 +#include <asm/arch/system_manager.h>
  14 +
  15 +DECLARE_GLOBAL_DATA_PTR;
  16 +
  17 +/* Timeout count */
  18 +#define FPGA_TIMEOUT_CNT 0x1000000
  19 +
  20 +static struct socfpga_fpga_manager *fpgamgr_regs =
  21 + (struct socfpga_fpga_manager *)SOCFPGA_FPGAMGRREGS_ADDRESS;
  22 +static struct socfpga_system_manager *sysmgr_regs =
  23 + (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  24 +
  25 +/* Set CD ratio */
  26 +static void fpgamgr_set_cd_ratio(unsigned long ratio)
  27 +{
  28 + clrsetbits_le32(&fpgamgr_regs->ctrl,
  29 + 0x3 << FPGAMGRREGS_CTRL_CDRATIO_LSB,
  30 + (ratio & 0x3) << FPGAMGRREGS_CTRL_CDRATIO_LSB);
  31 +}
  32 +
  33 +static int fpgamgr_dclkcnt_set(unsigned long cnt)
  34 +{
  35 + unsigned long i;
  36 +
  37 + /* Clear any existing done status */
  38 + if (readl(&fpgamgr_regs->dclkstat))
  39 + writel(0x1, &fpgamgr_regs->dclkstat);
  40 +
  41 + /* Write the dclkcnt */
  42 + writel(cnt, &fpgamgr_regs->dclkcnt);
  43 +
  44 + /* Wait till the dclkcnt done */
  45 + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  46 + if (!readl(&fpgamgr_regs->dclkstat))
  47 + continue;
  48 +
  49 + writel(0x1, &fpgamgr_regs->dclkstat);
  50 + return 0;
  51 + }
  52 +
  53 + return -ETIMEDOUT;
  54 +}
  55 +
  56 +/* Start the FPGA programming by initialize the FPGA Manager */
  57 +static int fpgamgr_program_init(void)
  58 +{
  59 + unsigned long msel, i;
  60 +
  61 + /* Get the MSEL value */
  62 + msel = readl(&fpgamgr_regs->stat);
  63 + msel &= FPGAMGRREGS_STAT_MSEL_MASK;
  64 + msel >>= FPGAMGRREGS_STAT_MSEL_LSB;
  65 +
  66 + /*
  67 + * Set the cfg width
  68 + * If MSEL[3] = 1, cfg width = 32 bit
  69 + */
  70 + if (msel & 0x8) {
  71 + setbits_le32(&fpgamgr_regs->ctrl,
  72 + FPGAMGRREGS_CTRL_CFGWDTH_MASK);
  73 +
  74 + /* To determine the CD ratio */
  75 + /* MSEL[1:0] = 0, CD Ratio = 1 */
  76 + if ((msel & 0x3) == 0x0)
  77 + fpgamgr_set_cd_ratio(CDRATIO_x1);
  78 + /* MSEL[1:0] = 1, CD Ratio = 4 */
  79 + else if ((msel & 0x3) == 0x1)
  80 + fpgamgr_set_cd_ratio(CDRATIO_x4);
  81 + /* MSEL[1:0] = 2, CD Ratio = 8 */
  82 + else if ((msel & 0x3) == 0x2)
  83 + fpgamgr_set_cd_ratio(CDRATIO_x8);
  84 +
  85 + } else { /* MSEL[3] = 0 */
  86 + clrbits_le32(&fpgamgr_regs->ctrl,
  87 + FPGAMGRREGS_CTRL_CFGWDTH_MASK);
  88 +
  89 + /* To determine the CD ratio */
  90 + /* MSEL[1:0] = 0, CD Ratio = 1 */
  91 + if ((msel & 0x3) == 0x0)
  92 + fpgamgr_set_cd_ratio(CDRATIO_x1);
  93 + /* MSEL[1:0] = 1, CD Ratio = 2 */
  94 + else if ((msel & 0x3) == 0x1)
  95 + fpgamgr_set_cd_ratio(CDRATIO_x2);
  96 + /* MSEL[1:0] = 2, CD Ratio = 4 */
  97 + else if ((msel & 0x3) == 0x2)
  98 + fpgamgr_set_cd_ratio(CDRATIO_x4);
  99 + }
  100 +
  101 + /* To enable FPGA Manager configuration */
  102 + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_NCE_MASK);
  103 +
  104 + /* To enable FPGA Manager drive over configuration line */
  105 + setbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_EN_MASK);
  106 +
  107 + /* Put FPGA into reset phase */
  108 + setbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_NCONFIGPULL_MASK);
  109 +
  110 + /* (1) wait until FPGA enter reset phase */
  111 + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  112 + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_RESETPHASE)
  113 + break;
  114 + }
  115 +
  116 + /* If not in reset state, return error */
  117 + if (fpgamgr_get_mode() != FPGAMGRREGS_MODE_RESETPHASE) {
  118 + puts("FPGA: Could not reset\n");
  119 + return -1;
  120 + }
  121 +
  122 + /* Release FPGA from reset phase */
  123 + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_NCONFIGPULL_MASK);
  124 +
  125 + /* (2) wait until FPGA enter configuration phase */
  126 + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  127 + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_CFGPHASE)
  128 + break;
  129 + }
  130 +
  131 + /* If not in configuration state, return error */
  132 + if (fpgamgr_get_mode() != FPGAMGRREGS_MODE_CFGPHASE) {
  133 + puts("FPGA: Could not configure\n");
  134 + return -2;
  135 + }
  136 +
  137 + /* Clear all interrupts in CB Monitor */
  138 + writel(0xFFF, &fpgamgr_regs->gpio_porta_eoi);
  139 +
  140 + /* Enable AXI configuration */
  141 + setbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_AXICFGEN_MASK);
  142 +
  143 + return 0;
  144 +}
  145 +
  146 +/* Write the RBF data to FPGA Manager */
  147 +static void fpgamgr_program_write(const void *rbf_data, unsigned long rbf_size)
  148 +{
  149 + uint32_t src = (uint32_t)rbf_data;
  150 + uint32_t dst = SOCFPGA_FPGAMGRDATA_ADDRESS;
  151 +
  152 + /* Number of loops for 32-byte long copying. */
  153 + uint32_t loops32 = rbf_size / 32;
  154 + /* Number of loops for 4-byte long copying + trailing bytes */
  155 + uint32_t loops4 = DIV_ROUND_UP(rbf_size % 32, 4);
  156 +
  157 + asm volatile(
  158 + "1: ldmia %0!, {r0-r7}\n"
  159 + " stmia %1!, {r0-r7}\n"
  160 + " sub %1, #32\n"
  161 + " subs %2, #1\n"
  162 + " bne 1b\n"
  163 + "2: ldr %2, [%0], #4\n"
  164 + " str %2, [%1]\n"
  165 + " subs %3, #1\n"
  166 + " bne 2b\n"
  167 + : "+r"(src), "+r"(dst), "+r"(loops32), "+r"(loops4) :
  168 + : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "cc");
  169 +}
  170 +
  171 +/* Ensure the FPGA entering config done */
  172 +static int fpgamgr_program_poll_cd(void)
  173 +{
  174 + const uint32_t mask = FPGAMGRREGS_MON_GPIO_EXT_PORTA_NS_MASK |
  175 + FPGAMGRREGS_MON_GPIO_EXT_PORTA_CD_MASK;
  176 + unsigned long reg, i;
  177 +
  178 + /* (3) wait until full config done */
  179 + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  180 + reg = readl(&fpgamgr_regs->gpio_ext_porta);
  181 +
  182 + /* Config error */
  183 + if (!(reg & mask)) {
  184 + printf("FPGA: Configuration error.\n");
  185 + return -3;
  186 + }
  187 +
  188 + /* Config done without error */
  189 + if (reg & mask)
  190 + break;
  191 + }
  192 +
  193 + /* Timeout happened, return error */
  194 + if (i == FPGA_TIMEOUT_CNT) {
  195 + printf("FPGA: Timeout waiting for program.\n");
  196 + return -4;
  197 + }
  198 +
  199 + /* Disable AXI configuration */
  200 + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_AXICFGEN_MASK);
  201 +
  202 + return 0;
  203 +}
  204 +
  205 +/* Ensure the FPGA entering init phase */
  206 +static int fpgamgr_program_poll_initphase(void)
  207 +{
  208 + unsigned long i;
  209 +
  210 + /* Additional clocks for the CB to enter initialization phase */
  211 + if (fpgamgr_dclkcnt_set(0x4))
  212 + return -5;
  213 +
  214 + /* (4) wait until FPGA enter init phase or user mode */
  215 + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  216 + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_INITPHASE)
  217 + break;
  218 + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_USERMODE)
  219 + break;
  220 + }
  221 +
  222 + /* If not in configuration state, return error */
  223 + if (i == FPGA_TIMEOUT_CNT)
  224 + return -6;
  225 +
  226 + return 0;
  227 +}
  228 +
  229 +/* Ensure the FPGA entering user mode */
  230 +static int fpgamgr_program_poll_usermode(void)
  231 +{
  232 + unsigned long i;
  233 +
  234 + /* Additional clocks for the CB to exit initialization phase */
  235 + if (fpgamgr_dclkcnt_set(0x5000))
  236 + return -7;
  237 +
  238 + /* (5) wait until FPGA enter user mode */
  239 + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
  240 + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_USERMODE)
  241 + break;
  242 + }
  243 + /* If not in configuration state, return error */
  244 + if (i == FPGA_TIMEOUT_CNT)
  245 + return -8;
  246 +
  247 + /* To release FPGA Manager drive over configuration line */
  248 + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_EN_MASK);
  249 +
  250 + return 0;
  251 +}
  252 +
  253 +/*
  254 + * FPGA Manager to program the FPGA. This is the interface used by FPGA driver.
  255 + * Return 0 for sucess, non-zero for error.
  256 + */
  257 +int socfpga_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size)
  258 +{
  259 + unsigned long status;
  260 +
  261 + if ((uint32_t)rbf_data & 0x3) {
  262 + puts("FPGA: Unaligned data, realign to 32bit boundary.\n");
  263 + return -EINVAL;
  264 + }
  265 +
  266 + /* Prior programming the FPGA, all bridges need to be shut off */
  267 +
  268 + /* Disable all signals from hps peripheral controller to fpga */
  269 + writel(0, &sysmgr_regs->fpgaintfgrp_module);
  270 +
  271 + /* Disable all signals from FPGA to HPS SDRAM */
  272 +#define SDR_CTRLGRP_FPGAPORTRST_ADDRESS 0x5080
  273 + writel(0, SOCFPGA_SDR_ADDRESS + SDR_CTRLGRP_FPGAPORTRST_ADDRESS);
  274 +
  275 + /* Disable all axi bridge (hps2fpga, lwhps2fpga & fpga2hps) */
  276 + socfpga_bridges_reset(1);
  277 +
  278 + /* Unmap the bridges from NIC-301 */
  279 + writel(0x1, SOCFPGA_L3REGS_ADDRESS);
  280 +
  281 + /* Initialize the FPGA Manager */
  282 + status = fpgamgr_program_init();
  283 + if (status)
  284 + return status;
  285 +
  286 + /* Write the RBF data to FPGA Manager */
  287 + fpgamgr_program_write(rbf_data, rbf_size);
  288 +
  289 + /* Ensure the FPGA entering config done */
  290 + status = fpgamgr_program_poll_cd();
  291 + if (status)
  292 + return status;
  293 +
  294 + /* Ensure the FPGA entering init phase */
  295 + status = fpgamgr_program_poll_initphase();
  296 + if (status)
  297 + return status;
  298 +
  299 + /* Ensure the FPGA entering user mode */
  300 + return fpgamgr_program_poll_usermode();
  301 +}
drivers/mmc/dw_mmc.c
... ... @@ -119,7 +119,7 @@
119 119  
120 120 while (dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY) {
121 121 if (get_timer(start) > timeout) {
122   - printf("Timeout on data busy\n");
  122 + printf("%s: Timeout on data busy\n", __func__);
123 123 return TIMEOUT;
124 124 }
125 125 }
126 126  
127 127  
... ... @@ -178,15 +178,23 @@
178 178 }
179 179  
180 180 if (i == retry) {
181   - printf("dwmci_send_cmd: timeout..\n");
  181 + printf("%s: Timeout.\n", __func__);
182 182 return TIMEOUT;
183 183 }
184 184  
185 185 if (mask & DWMCI_INTMSK_RTO) {
186   - printf("dwmci_send_cmd: Response Timeout..\n");
  186 + /*
  187 + * Timeout here is not necessarily fatal. (e)MMC cards
  188 + * will splat here when they receive CMD55 as they do
  189 + * not support this command and that is exactly the way
  190 + * to tell them apart from SD cards. Thus, this output
  191 + * below shall be debug(). eMMC cards also do not favor
  192 + * CMD8, please keep that in mind.
  193 + */
  194 + debug("%s: Response Timeout.\n", __func__);
187 195 return TIMEOUT;
188 196 } else if (mask & DWMCI_INTMSK_RE) {
189   - printf("dwmci_send_cmd: Response Error..\n");
  197 + printf("%s: Response Error.\n", __func__);
190 198 return -1;
191 199 }
192 200  
... ... @@ -206,7 +214,7 @@
206 214 do {
207 215 mask = dwmci_readl(host, DWMCI_RINTSTS);
208 216 if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) {
209   - printf("dwmci_send_cmd: DATA ERROR!\n");
  217 + printf("%s: DATA ERROR!\n", __func__);
210 218 return -1;
211 219 }
212 220 } while (!(mask & DWMCI_INTMSK_DTO));
... ... @@ -243,7 +251,7 @@
243 251 else if (host->bus_hz)
244 252 sclk = host->bus_hz;
245 253 else {
246   - printf("dwmci_setup_bus: Didn't get source clock value..\n");
  254 + printf("%s: Didn't get source clock value.\n", __func__);
247 255 return -EINVAL;
248 256 }
249 257  
... ... @@ -262,7 +270,7 @@
262 270 do {
263 271 status = dwmci_readl(host, DWMCI_CMD);
264 272 if (timeout-- < 0) {
265   - printf("dwmci_setup_bus: timeout!\n");
  273 + printf("%s: Timeout!\n", __func__);
266 274 return -ETIMEDOUT;
267 275 }
268 276 } while (status & DWMCI_CMD_START);
... ... @@ -277,7 +285,7 @@
277 285 do {
278 286 status = dwmci_readl(host, DWMCI_CMD);
279 287 if (timeout-- < 0) {
280   - printf("dwmci_setup_bus: timeout!\n");
  288 + printf("%s: Timeout!\n", __func__);
281 289 return -ETIMEDOUT;
282 290 }
283 291 } while (status & DWMCI_CMD_START);
drivers/mmc/socfpga_dw_mmc.c
... ... @@ -7,6 +7,7 @@
7 7 #include <common.h>
8 8 #include <malloc.h>
9 9 #include <dwmmc.h>
  10 +#include <errno.h>
10 11 #include <asm/arch/dwmmc.h>
11 12 #include <asm/arch/clock_manager.h>
12 13 #include <asm/arch/system_manager.h>
13 14  
14 15  
15 16  
... ... @@ -44,12 +45,18 @@
44 45 int socfpga_dwmmc_init(u32 regbase, int bus_width, int index)
45 46 {
46 47 struct dwmci_host *host;
  48 + unsigned long clk = cm_get_mmc_controller_clk_hz();
47 49  
  50 + if (clk == 0) {
  51 + printf("%s: MMC clock is zero!", __func__);
  52 + return -EINVAL;
  53 + }
  54 +
48 55 /* calloc for zero init */
49   - host = calloc(sizeof(struct dwmci_host), 1);
  56 + host = calloc(1, sizeof(struct dwmci_host));
50 57 if (!host) {
51   - printf("dwmci_host calloc fail!\n");
52   - return -1;
  58 + printf("%s: calloc() failed!\n", __func__);
  59 + return -ENOMEM;
53 60 }
54 61  
55 62 host->name = "SOCFPGA DWMMC";
... ... @@ -58,7 +65,7 @@
58 65 host->clksel = socfpga_dwmci_clksel;
59 66 host->dev_index = index;
60 67 /* fixed clock divide by 4 which due to the SDMMC wrapper */
61   - host->bus_hz = CONFIG_SOCFPGA_DWMMC_BUS_HZ;
  68 + host->bus_hz = clk;
62 69 host->fifoth_val = MSIZE(0x2) |
63 70 RX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2 - 1) |
64 71 TX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2);
drivers/net/designware.c
... ... @@ -279,19 +279,21 @@
279 279 struct eth_dma_regs *dma_p = priv->dma_regs_p;
280 280 u32 desc_num = priv->tx_currdescnum;
281 281 struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num];
282   -
  282 + uint32_t desc_start = (uint32_t)desc_p;
  283 + uint32_t desc_end = desc_start +
  284 + roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
  285 + uint32_t data_start = (uint32_t)desc_p->dmamac_addr;
  286 + uint32_t data_end = data_start +
  287 + roundup(length, ARCH_DMA_MINALIGN);
283 288 /*
284 289 * Strictly we only need to invalidate the "txrx_status" field
285 290 * for the following check, but on some platforms we cannot
286   - * invalidate only 4 bytes, so roundup to
287   - * ARCH_DMA_MINALIGN. This is safe because the individual
288   - * descriptors in the array are each aligned to
289   - * ARCH_DMA_MINALIGN.
  291 + * invalidate only 4 bytes, so we flush the entire descriptor,
  292 + * which is 16 bytes in total. This is safe because the
  293 + * individual descriptors in the array are each aligned to
  294 + * ARCH_DMA_MINALIGN and padded appropriately.
290 295 */
291   - invalidate_dcache_range(
292   - (unsigned long)desc_p,
293   - (unsigned long)desc_p +
294   - roundup(sizeof(desc_p->txrx_status), ARCH_DMA_MINALIGN));
  296 + invalidate_dcache_range(desc_start, desc_end);
295 297  
296 298 /* Check if the descriptor is owned by CPU */
297 299 if (desc_p->txrx_status & DESC_TXSTS_OWNBYDMA) {
298 300  
... ... @@ -299,11 +301,10 @@
299 301 return -1;
300 302 }
301 303  
302   - memcpy((void *)desc_p->dmamac_addr, packet, length);
  304 + memcpy(desc_p->dmamac_addr, packet, length);
303 305  
304 306 /* Flush data to be sent */
305   - flush_dcache_range((unsigned long)desc_p->dmamac_addr,
306   - (unsigned long)desc_p->dmamac_addr + length);
  307 + flush_dcache_range(data_start, data_end);
307 308  
308 309 #if defined(CONFIG_DW_ALTDESCRIPTOR)
309 310 desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST;
... ... @@ -321,8 +322,7 @@
321 322 #endif
322 323  
323 324 /* Flush modified buffer descriptor */
324   - flush_dcache_range((unsigned long)desc_p,
325   - (unsigned long)desc_p + sizeof(struct dmamacdescr));
  325 + flush_dcache_range(desc_start, desc_end);
326 326  
327 327 /* Test the wrap-around condition. */
328 328 if (++desc_num >= CONFIG_TX_DESCR_NUM)
329 329  
... ... @@ -342,11 +342,14 @@
342 342 u32 status, desc_num = priv->rx_currdescnum;
343 343 struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num];
344 344 int length = 0;
  345 + uint32_t desc_start = (uint32_t)desc_p;
  346 + uint32_t desc_end = desc_start +
  347 + roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
  348 + uint32_t data_start = (uint32_t)desc_p->dmamac_addr;
  349 + uint32_t data_end;
345 350  
346 351 /* Invalidate entire buffer descriptor */
347   - invalidate_dcache_range((unsigned long)desc_p,
348   - (unsigned long)desc_p +
349   - sizeof(struct dmamacdescr));
  352 + invalidate_dcache_range(desc_start, desc_end);
350 353  
351 354 status = desc_p->txrx_status;
352 355  
... ... @@ -357,9 +360,8 @@
357 360 DESC_RXSTS_FRMLENSHFT;
358 361  
359 362 /* Invalidate received data */
360   - invalidate_dcache_range((unsigned long)desc_p->dmamac_addr,
361   - (unsigned long)desc_p->dmamac_addr +
362   - roundup(length, ARCH_DMA_MINALIGN));
  363 + data_end = data_start + roundup(length, ARCH_DMA_MINALIGN);
  364 + invalidate_dcache_range(data_start, data_end);
363 365  
364 366 NetReceive(desc_p->dmamac_addr, length);
365 367  
... ... @@ -370,9 +372,7 @@
370 372 desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA;
371 373  
372 374 /* Flush only status field - others weren't changed */
373   - flush_dcache_range((unsigned long)&desc_p->txrx_status,
374   - (unsigned long)&desc_p->txrx_status +
375   - sizeof(desc_p->txrx_status));
  375 + flush_dcache_range(desc_start, desc_end);
376 376  
377 377 /* Test the wrap-around condition. */
378 378 if (++desc_num >= CONFIG_RX_DESCR_NUM)
drivers/net/phy/micrel.c
... ... @@ -25,8 +25,7 @@
25 25 #ifndef CONFIG_PHY_MICREL_KSZ9021
26 26 /*
27 27 * I can't believe Micrel used the exact same part number
28   - * for the KSZ9021
29   - * Shame Micrel, Shame!!!!!
  28 + * for the KSZ9021. Shame Micrel, Shame!
30 29 */
31 30 static struct phy_driver KS8721_driver = {
32 31 .name = "Micrel KS8721BL",
... ... @@ -40,7 +39,7 @@
40 39 #endif
41 40  
42 41  
43   -/**
  42 +/*
44 43 * KSZ9021 - KSZ9031 common
45 44 */
46 45  
47 46  
... ... @@ -69,8 +68,8 @@
69 68 phydev->speed = SPEED_10;
70 69 return 0;
71 70 }
72   -#ifdef CONFIG_PHY_MICREL_KSZ9021
73 71  
  72 +#ifdef CONFIG_PHY_MICREL_KSZ9021
74 73 /*
75 74 * KSZ9021
76 75 */
... ... @@ -10,36 +10,60 @@
10 10 #ifndef _ALTERA_H_
11 11 #define _ALTERA_H_
12 12  
13   -typedef enum { /* typedef Altera_iface */
14   - min_altera_iface_type, /* insert all new types after this */
15   - passive_serial, /* serial data and external clock */
16   - passive_parallel_synchronous, /* parallel data */
17   - passive_parallel_asynchronous, /* parallel data */
18   - passive_serial_asynchronous, /* serial data w/ internal clock (not used) */
19   - altera_jtag_mode, /* jtag/tap serial (not used ) */
20   - fast_passive_parallel, /* fast passive parallel (FPP) */
21   - fast_passive_parallel_security, /* fast passive parallel with security (FPPS) */
22   - max_altera_iface_type /* insert all new types before this */
23   -} Altera_iface; /* end, typedef Altera_iface */
  13 +enum altera_iface {
  14 + /* insert all new types after this */
  15 + min_altera_iface_type,
  16 + /* serial data and external clock */
  17 + passive_serial,
  18 + /* parallel data */
  19 + passive_parallel_synchronous,
  20 + /* parallel data */
  21 + passive_parallel_asynchronous,
  22 + /* serial data w/ internal clock (not used) */
  23 + passive_serial_asynchronous,
  24 + /* jtag/tap serial (not used ) */
  25 + altera_jtag_mode,
  26 + /* fast passive parallel (FPP) */
  27 + fast_passive_parallel,
  28 + /* fast passive parallel with security (FPPS) */
  29 + fast_passive_parallel_security,
  30 + /* insert all new types before this */
  31 + max_altera_iface_type,
  32 +};
24 33  
25   -typedef enum { /* typedef Altera_Family */
26   - min_altera_type, /* insert all new types after this */
27   - Altera_ACEX1K, /* ACEX1K Family */
28   - Altera_CYC2, /* CYCLONII Family */
29   - Altera_StratixII, /* StratixII Family */
30   -/* Add new models here */
31   - max_altera_type /* insert all new types before this */
32   -} Altera_Family; /* end, typedef Altera_Family */
  34 +enum altera_family {
  35 + /* insert all new types after this */
  36 + min_altera_type,
  37 + /* ACEX1K Family */
  38 + Altera_ACEX1K,
  39 + /* CYCLONII Family */
  40 + Altera_CYC2,
  41 + /* StratixII Family */
  42 + Altera_StratixII,
  43 + /* SoCFPGA Family */
  44 + Altera_SoCFPGA,
33 45  
34   -typedef struct { /* typedef Altera_desc */
35   - Altera_Family family; /* part type */
36   - Altera_iface iface; /* interface type */
37   - size_t size; /* bytes of data part can accept */
38   - void * iface_fns;/* interface function table */
39   - void * base; /* base interface address */
40   - int cookie; /* implementation specific cookie */
41   -} Altera_desc; /* end, typedef Altera_desc */
  46 + /* Add new models here */
42 47  
  48 + /* insert all new types before this */
  49 + max_altera_type,
  50 +};
  51 +
  52 +typedef struct {
  53 + /* part type */
  54 + enum altera_family family;
  55 + /* interface type */
  56 + enum altera_iface iface;
  57 + /* bytes of data part can accept */
  58 + size_t size;
  59 + /* interface function table */
  60 + void *iface_fns;
  61 + /* base interface address */
  62 + void *base;
  63 + /* implementation specific cookie */
  64 + int cookie;
  65 +} Altera_desc;
  66 +
43 67 /* Generic Altera Functions
44 68 *********************************************************************/
45 69 extern int altera_load(Altera_desc *desc, const void *image, size_t size);
... ... @@ -68,6 +92,10 @@
68 92 Altera_abort_fn abort;
69 93 Altera_post_fn post;
70 94 } altera_board_specific_func;
  95 +
  96 +#ifdef CONFIG_FPGA_SOCFPGA
  97 +int socfpga_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size);
  98 +#endif
71 99  
72 100 #endif /* _ALTERA_H_ */
include/configs/axs101.h
... ... @@ -125,7 +125,6 @@
125 125 */
126 126 #define CONFIG_DESIGNWARE_ETH
127 127 #define CONFIG_DW_AUTONEG
128   -#define CONFIG_DW_SEARCH_PHY
129 128 #define CONFIG_NET_MULTI
130 129  
131 130 /*
include/configs/socfpga_common.h
  1 +/*
  2 + * Copyright (C) 2012 Altera Corporation <www.altera.com>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +#ifndef __CONFIG_SOCFPGA_CYCLONE5_COMMON_H__
  7 +#define __CONFIG_SOCFPGA_CYCLONE5_COMMON_H__
  8 +
  9 +#define CONFIG_SYS_GENERIC_BOARD
  10 +
  11 +/* Virtual target or real hardware */
  12 +#undef CONFIG_SOCFPGA_VIRTUAL_TARGET
  13 +
  14 +#define CONFIG_ARMV7
  15 +#define CONFIG_SYS_THUMB_BUILD
  16 +
  17 +#define CONFIG_SOCFPGA
  18 +
  19 +/*
  20 + * High level configuration
  21 + */
  22 +#define CONFIG_DISPLAY_CPUINFO
  23 +#define CONFIG_DISPLAY_BOARDINFO
  24 +#define CONFIG_BOARD_EARLY_INIT_F
  25 +#define CONFIG_MISC_INIT_R
  26 +#define CONFIG_SYS_NO_FLASH
  27 +#define CONFIG_CLOCKS
  28 +
  29 +#define CONFIG_FIT
  30 +#define CONFIG_OF_LIBFDT
  31 +#define CONFIG_SYS_BOOTMAPSZ (64 * 1024 * 1024)
  32 +
  33 +#define CONFIG_TIMESTAMP /* Print image info with timestamp */
  34 +
  35 +/*
  36 + * Memory configurations
  37 + */
  38 +#define CONFIG_NR_DRAM_BANKS 1
  39 +#define PHYS_SDRAM_1 0x0
  40 +#define CONFIG_SYS_MALLOC_LEN (10 * 1024 * 1024)
  41 +#define CONFIG_SYS_MEMTEST_START PHYS_SDRAM_1
  42 +#define CONFIG_SYS_MEMTEST_END PHYS_SDRAM_1_SIZE
  43 +
  44 +#define CONFIG_SYS_INIT_RAM_ADDR 0xFFFF0000
  45 +#define CONFIG_SYS_INIT_RAM_SIZE (0x10000 - 0x100)
  46 +#define CONFIG_SYS_INIT_SP_ADDR \
  47 + (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE - \
  48 + GENERATED_GBL_DATA_SIZE)
  49 +
  50 +#define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1
  51 +#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
  52 +#define CONFIG_SYS_TEXT_BASE 0x08000040
  53 +#else
  54 +#define CONFIG_SYS_TEXT_BASE 0x01000040
  55 +#endif
  56 +
  57 +/*
  58 + * U-Boot general configurations
  59 + */
  60 +#define CONFIG_SYS_LONGHELP
  61 +#define CONFIG_SYS_CBSIZE 1024 /* Console I/O buffer size */
  62 +#define CONFIG_SYS_PBSIZE \
  63 + (CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
  64 + /* Print buffer size */
  65 +#define CONFIG_SYS_MAXARGS 32 /* Max number of command args */
  66 +#define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE
  67 + /* Boot argument buffer size */
  68 +#define CONFIG_VERSION_VARIABLE /* U-BOOT version */
  69 +#define CONFIG_AUTO_COMPLETE /* Command auto complete */
  70 +#define CONFIG_CMDLINE_EDITING /* Command history etc */
  71 +#define CONFIG_SYS_HUSH_PARSER
  72 +
  73 +/*
  74 + * Cache
  75 + */
  76 +#define CONFIG_SYS_ARM_CACHE_WRITEALLOC
  77 +#define CONFIG_SYS_CACHELINE_SIZE 32
  78 +#define CONFIG_SYS_L2_PL310
  79 +#define CONFIG_SYS_PL310_BASE SOCFPGA_MPUL2_ADDRESS
  80 +
  81 +/*
  82 + * Ethernet on SoC (EMAC)
  83 + */
  84 +#if defined(CONFIG_CMD_NET) && !defined(CONFIG_SOCFPGA_VIRTUAL_TARGET)
  85 +#define CONFIG_DESIGNWARE_ETH
  86 +#define CONFIG_NET_MULTI
  87 +#define CONFIG_DW_ALTDESCRIPTOR
  88 +#define CONFIG_MII
  89 +#define CONFIG_AUTONEG_TIMEOUT (15 * CONFIG_SYS_HZ)
  90 +#define CONFIG_PHYLIB
  91 +#define CONFIG_PHY_GIGE
  92 +#endif
  93 +
  94 +/*
  95 + * FPGA Driver
  96 + */
  97 +#ifdef CONFIG_CMD_FPGA
  98 +#define CONFIG_FPGA
  99 +#define CONFIG_FPGA_ALTERA
  100 +#define CONFIG_FPGA_SOCFPGA
  101 +#define CONFIG_FPGA_COUNT 1
  102 +#endif
  103 +
  104 +/*
  105 + * L4 OSC1 Timer 0
  106 + */
  107 +/* This timer uses eosc1, whose clock frequency is fixed at any condition. */
  108 +#define CONFIG_SYS_TIMERBASE SOCFPGA_OSC1TIMER0_ADDRESS
  109 +#define CONFIG_SYS_TIMER_COUNTS_DOWN
  110 +#define CONFIG_SYS_TIMER_COUNTER (CONFIG_SYS_TIMERBASE + 0x4)
  111 +#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
  112 +#define CONFIG_SYS_TIMER_RATE 2400000
  113 +#else
  114 +#define CONFIG_SYS_TIMER_RATE 25000000
  115 +#endif
  116 +
  117 +/*
  118 + * L4 Watchdog
  119 + */
  120 +#ifdef CONFIG_HW_WATCHDOG
  121 +#define CONFIG_DESIGNWARE_WATCHDOG
  122 +#define CONFIG_DW_WDT_BASE SOCFPGA_L4WD0_ADDRESS
  123 +#define CONFIG_DW_WDT_CLOCK_KHZ 25000
  124 +#define CONFIG_HW_WATCHDOG_TIMEOUT_MS 12000
  125 +#endif
  126 +
  127 +/*
  128 + * MMC Driver
  129 + */
  130 +#ifdef CONFIG_CMD_MMC
  131 +#define CONFIG_MMC
  132 +#define CONFIG_BOUNCE_BUFFER
  133 +#define CONFIG_GENERIC_MMC
  134 +#define CONFIG_DWMMC
  135 +#define CONFIG_SOCFPGA_DWMMC
  136 +#define CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH 1024
  137 +#define CONFIG_SOCFPGA_DWMMC_DRVSEL 3
  138 +#define CONFIG_SOCFPGA_DWMMC_SMPSEL 0
  139 +/* FIXME */
  140 +/* using smaller max blk cnt to avoid flooding the limited stack we have */
  141 +#define CONFIG_SYS_MMC_MAX_BLK_COUNT 256 /* FIXME -- SPL only? */
  142 +#endif
  143 +
  144 +/*
  145 + * Serial Driver
  146 + */
  147 +#define CONFIG_SYS_NS16550
  148 +#define CONFIG_SYS_NS16550_SERIAL
  149 +#define CONFIG_SYS_NS16550_REG_SIZE -4
  150 +#define CONFIG_SYS_NS16550_COM1 SOCFPGA_UART0_ADDRESS
  151 +#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
  152 +#define CONFIG_SYS_NS16550_CLK 1000000
  153 +#else
  154 +#define CONFIG_SYS_NS16550_CLK 100000000
  155 +#endif
  156 +#define CONFIG_CONS_INDEX 1
  157 +#define CONFIG_BAUDRATE 115200
  158 +
  159 +/*
  160 + * U-Boot environment
  161 + */
  162 +#define CONFIG_SYS_CONSOLE_IS_IN_ENV
  163 +#define CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
  164 +#define CONFIG_SYS_CONSOLE_ENV_OVERWRITE
  165 +#define CONFIG_ENV_IS_NOWHERE
  166 +#define CONFIG_ENV_SIZE 4096
  167 +
  168 +/*
  169 + * SPL
  170 + */
  171 +#define CONFIG_SPL_FRAMEWORK
  172 +#define CONFIG_SPL_BOARD_INIT
  173 +#define CONFIG_SPL_RAM_DEVICE
  174 +#define CONFIG_SPL_TEXT_BASE 0xFFFF0000
  175 +#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR
  176 +#define CONFIG_SPL_STACK_SIZE (4 * 1024)
  177 +#define CONFIG_SPL_MALLOC_SIZE (5 * 1024) /* FIXME */
  178 +#define CONFIG_SYS_SPL_MALLOC_START ((unsigned long) (&__malloc_start))
  179 +#define CONFIG_SYS_SPL_MALLOC_SIZE (&__malloc_end - &__malloc_start)
  180 +
  181 +#define CHUNKSZ_CRC32 (1 * 1024) /* FIXME: ewww */
  182 +#define CONFIG_CRC32_VERIFY
  183 +
  184 +/* Linker script for SPL */
  185 +#define CONFIG_SPL_LDSCRIPT "arch/arm/cpu/armv7/socfpga/u-boot-spl.lds"
  186 +
  187 +#define CONFIG_SPL_LIBCOMMON_SUPPORT
  188 +#define CONFIG_SPL_LIBGENERIC_SUPPORT
  189 +#define CONFIG_SPL_WATCHDOG_SUPPORT
  190 +#define CONFIG_SPL_SERIAL_SUPPORT
  191 +
  192 +#ifdef CONFIG_SPL_BUILD
  193 +#undef CONFIG_PARTITIONS
  194 +#endif
  195 +
  196 +#endif /* __CONFIG_SOCFPGA_CYCLONE5_COMMON_H__ */
include/configs/socfpga_cyclone5.h
1 1 /*
2   - * Copyright (C) 2012 Altera Corporation <www.altera.com>
  2 + * Copyright (C) 2014 Marek Vasut <marex@denx.de>
3 3 *
4 4 * SPDX-License-Identifier: GPL-2.0+
5 5 */
6   -#ifndef __CONFIG_H
7   -#define __CONFIG_H
  6 +#ifndef __CONFIG_SOCFPGA_CYCLONE5_H__
  7 +#define __CONFIG_SOCFPGA_CYCLONE5_H__
8 8  
9 9 #include <asm/arch/socfpga_base_addrs.h>
10 10 #include "../../board/altera/socfpga/pinmux_config.h"
11 11 #include "../../board/altera/socfpga/iocsr_config.h"
12 12 #include "../../board/altera/socfpga/pll_config.h"
13 13  
14   -/*
15   - * High level configuration
16   - */
17   -/* Virtual target or real hardware */
18   -#undef CONFIG_SOCFPGA_VIRTUAL_TARGET
  14 +/* U-Boot Commands */
  15 +#define CONFIG_SYS_NO_FLASH
  16 +#include <config_cmd_default.h>
  17 +#define CONFIG_DOS_PARTITION
  18 +#define CONFIG_FAT_WRITE
  19 +#define CONFIG_HW_WATCHDOG
19 20  
20   -#define CONFIG_ARMV7
21   -#define CONFIG_SYS_DCACHE_OFF
22   -#undef CONFIG_USE_IRQ
  21 +#define CONFIG_CMD_ASKENV
  22 +#define CONFIG_CMD_BOOTZ
  23 +#define CONFIG_CMD_CACHE
  24 +#define CONFIG_CMD_DHCP
  25 +#define CONFIG_CMD_EXT4
  26 +#define CONFIG_CMD_EXT4_WRITE
  27 +#define CONFIG_CMD_FAT
  28 +#define CONFIG_CMD_FPGA
  29 +#define CONFIG_CMD_FS_GENERIC
  30 +#define CONFIG_CMD_GREPENV
  31 +#define CONFIG_CMD_MII
  32 +#define CONFIG_CMD_MMC
  33 +#define CONFIG_CMD_NET
  34 +#define CONFIG_CMD_PING
  35 +#define CONFIG_CMD_SETEXPR
23 36  
24   -#define CONFIG_MISC_INIT_R
25   -#define CONFIG_SINGLE_BOOTLOADER
26   -#define CONFIG_SOCFPGA
  37 +#define CONFIG_REGEX /* Enable regular expression support */
27 38  
28   -/* base address for .text section */
  39 +/* Memory configurations */
  40 +#define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */
  41 +
  42 +/* Booting Linux */
  43 +#define CONFIG_BOOTDELAY 3
  44 +#define CONFIG_BOOTFILE "zImage"
  45 +#define CONFIG_BOOTARGS "console=ttyS0" __stringify(CONFIG_BAUDRATE)
29 46 #ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
30   -#define CONFIG_SYS_TEXT_BASE 0x08000040
  47 +#define CONFIG_BOOTCOMMAND "run ramboot"
31 48 #else
32   -#define CONFIG_SYS_TEXT_BASE 0x01000040
  49 +#define CONFIG_BOOTCOMMAND "run mmcload; run mmcboot"
33 50 #endif
34   -#define CONFIG_SYS_LOAD_ADDR 0x7fc0
  51 +#define CONFIG_LOADADDR 0x8000
  52 +#define CONFIG_SYS_LOAD_ADDR CONFIG_LOADADDR
35 53  
36   -/* Console I/O Buffer Size */
37   -#define CONFIG_SYS_CBSIZE 256
38   -/* Monitor Command Prompt */
39   -#define CONFIG_SYS_PROMPT "SOCFPGA_CYCLONE5 # "
40   -#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \
41   - sizeof(CONFIG_SYS_PROMPT) + 16)
  54 +/* Ethernet on SoC (EMAC) */
  55 +#if defined(CONFIG_CMD_NET)
  56 +#define CONFIG_EMAC_BASE SOCFPGA_EMAC0_ADDRESS
  57 +#define CONFIG_PHY_INTERFACE_MODE PHY_INTERFACE_MODE_RGMII
  58 +#define CONFIG_EPHY0_PHY_ADDR 0
42 59  
43   -/*
44   - * Display CPU and Board Info
45   - */
46   -#define CONFIG_DISPLAY_CPUINFO
47   -#define CONFIG_DISPLAY_BOARDINFO
  60 +/* PHY */
  61 +#define CONFIG_EPHY1_PHY_ADDR 4
  62 +#define CONFIG_PHY_MICREL
  63 +#define CONFIG_PHY_MICREL_KSZ9021
  64 +#define CONFIG_KSZ9021_CLK_SKEW_ENV "micrel-ksz9021-clk-skew"
  65 +#define CONFIG_KSZ9021_CLK_SKEW_VAL 0xf0f0
  66 +#define CONFIG_KSZ9021_DATA_SKEW_ENV "micrel-ksz9021-data-skew"
  67 +#define CONFIG_KSZ9021_DATA_SKEW_VAL 0x0
48 68  
49   -/*
50   - * Enable early stage initialization at C environment
51   - */
52   -#define CONFIG_BOARD_EARLY_INIT_F
53   -
54   -/* flat device tree */
55   -#define CONFIG_OF_LIBFDT
56   -/* skip updating the FDT blob */
57   -#define CONFIG_FDT_BLOB_SKIP_UPDATE
58   -/* Initial Memory map size for Linux, minus 4k alignment for DFT blob */
59   -#define CONFIG_SYS_BOOTMAPSZ ((256*1024*1024) - (4*1024))
60   -
61   -#define CONFIG_SPL_RAM_DEVICE
62   -#define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR
63   -#define CONFIG_SYS_SPL_MALLOC_START ((unsigned long) (&__malloc_start))
64   -#define CONFIG_SYS_SPL_MALLOC_SIZE (&__malloc_end - &__malloc_start)
65   -
66   -/*
67   - * Memory allocation (MALLOC)
68   - */
69   -/* Room required on the stack for the environment data */
70   -#define CONFIG_ENV_SIZE 1024
71   -/* Size of DRAM reserved for malloc() use */
72   -#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + 128*1024)
73   -
74   -/* SP location before relocation, must use scratch RAM */
75   -#define CONFIG_SYS_INIT_RAM_ADDR 0xFFFF0000
76   -/* Reserving 0x100 space at back of scratch RAM for debug info */
77   -#define CONFIG_SYS_INIT_RAM_SIZE (0x10000 - 0x100)
78   -/* Stack pointer prior relocation, must situated at on-chip RAM */
79   -#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \
80   - CONFIG_SYS_INIT_RAM_SIZE - \
81   - GENERATED_GBL_DATA_SIZE)
82   -
83   -
84   -/*
85   - * Command line configuration.
86   - */
87   -#define CONFIG_SYS_NO_FLASH
88   -#include <config_cmd_default.h>
89   -/* FAT file system support */
90   -#define CONFIG_CMD_FAT
91   -
92   -
93   -/*
94   - * Misc
95   - */
96   -#define CONFIG_DOS_PARTITION 1
97   -
98   -#ifdef CONFIG_SPL_BUILD
99   -#undef CONFIG_PARTITIONS
100 69 #endif
101 70  
102   -/*
103   - * Environment setup
104   - */
  71 +/* Extra Environment */
  72 +#define CONFIG_HOSTNAME socfpga_cyclone5
105 73  
106   -/* Delay before automatically booting the default image */
107   -#define CONFIG_BOOTDELAY 3
108   -/* Enable auto completion of commands using TAB */
109   -#define CONFIG_AUTO_COMPLETE
110   -/* use "hush" command parser */
111   -#define CONFIG_SYS_HUSH_PARSER
112   -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> "
113   -#define CONFIG_CMD_RUN
114   -
115   -#define CONFIG_BOOTCOMMAND "run ramboot"
116   -
117   -/*
118   - * arguments passed to the bootm command. The value of
119   - * CONFIG_BOOTARGS goes into the environment value "bootargs".
120   - * Do note the value will overide also the chosen node in FDT blob.
121   - */
122   -#define CONFIG_BOOTARGS "console=ttyS0,57600,mem=256M@0x0"
123   -
124 74 #define CONFIG_EXTRA_ENV_SETTINGS \
125 75 "verify=n\0" \
126 76 "loadaddr= " __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
127 77 "ramboot=setenv bootargs " CONFIG_BOOTARGS ";" \
128 78 "bootm ${loadaddr} - ${fdt_addr}\0" \
129   - "bootimage=uImageImage\0" \" \
  79 + "bootimage=zImageImage\0" \" \
130 80 "fdt_addr=100\0" \
131   - "fsloadcmd=ext2load\0" \
132   - "bootm ${loadaddr} - ${fdt_addr}\0" \
  81 + "fdtimage=socfpga.dtb\0" \
  82 + "fsloadcmd=ext2load\0" \
  83 + "bootm ${loadaddr} - ${fdt_addr}\0" \
  84 + "mmcroot=/dev/mmcblk0p2\0" \
  85 + "mmcboot=setenv bootargs " CONFIG_BOOTARGS \
  86 + " root=${mmcroot} rw rootwait;" \
  87 + "bootz ${loadaddr} - ${fdt_addr}\0" \
  88 + "mmcload=mmc rescan;" \
  89 + "load mmc 0:1 ${loadaddr} ${bootimage};" \
  90 + "load mmc 0:1 ${fdt_addr} ${fdtimage}\0" \
133 91 "qspiroot=/dev/mtdblock0\0" \
134 92 "qspirootfstype=jffs2\0" \
135 93 "qspiboot=setenv bootargs " CONFIG_BOOTARGS \
136 94 " root=${qspiroot} rw rootfstype=${qspirootfstype};"\
137 95 "bootm ${loadaddr} - ${fdt_addr}\0"
138 96  
139   -/* using environment setting for stdin, stdout, stderr */
140   -#define CONFIG_SYS_CONSOLE_IS_IN_ENV
141   -/* Enable the call to overwrite_console() */
142   -#define CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
143   -/* Enable overwrite of previous console environment settings */
144   -#define CONFIG_SYS_CONSOLE_ENV_OVERWRITE
  97 +/* The rest of the configuration is shared */
  98 +#include <configs/socfpga_common.h>
145 99  
146   -/* max number of command args */
147   -#define CONFIG_SYS_MAXARGS 16
148   -
149   -
150   -/*
151   - * Hardware drivers
152   - */
153   -
154   -/*
155   - * SDRAM Memory Map
156   - */
157   -/* We have 1 bank of DRAM */
158   -#define CONFIG_NR_DRAM_BANKS 1
159   -/* SDRAM Bank #1 */
160   -#define CONFIG_SYS_SDRAM_BASE 0x00000000
161   -/* SDRAM memory size */
162   -#define PHYS_SDRAM_1_SIZE 0x40000000
163   -
164   -#define PHYS_SDRAM_1 CONFIG_SYS_SDRAM_BASE
165   -#define CONFIG_SYS_MEMTEST_START 0x00000000
166   -#define CONFIG_SYS_MEMTEST_END PHYS_SDRAM_1_SIZE
167   -
168   -/*
169   - * NS16550 Configuration
170   - */
171   -#define UART0_BASE SOCFPGA_UART0_ADDRESS
172   -#define CONFIG_SYS_NS16550
173   -#define CONFIG_SYS_NS16550_SERIAL
174   -#define CONFIG_SYS_NS16550_REG_SIZE -4
175   -#define CONFIG_SYS_NS16550_CLK V_NS16550_CLK
176   -#define CONFIG_CONS_INDEX 1
177   -#define CONFIG_SYS_NS16550_COM1 UART0_BASE
178   -#define CONFIG_SYS_BAUDRATE_TABLE {4800, 9600, 19200, 38400, 57600, 115200}
179   -#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
180   -#define V_NS16550_CLK 1000000
181   -#else
182   -#define V_NS16550_CLK 100000000
183   -#endif
184   -#define CONFIG_BAUDRATE 115200
185   -
186   -/*
187   - * FLASH
188   - */
189   -#define CONFIG_SYS_NO_FLASH
190   -
191   -/*
192   - * L4 OSC1 Timer 0
193   - */
194   -/* This timer use eosc1 where the clock frequency is fixed
195   - * throughout any condition */
196   -#define CONFIG_SYS_TIMERBASE SOCFPGA_OSC1TIMER0_ADDRESS
197   -/* reload value when timer count to zero */
198   -#define TIMER_LOAD_VAL 0xFFFFFFFF
199   -/* Timer info */
200   -#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
201   -#define CONFIG_SYS_TIMER_RATE 2400000
202   -#else
203   -#define CONFIG_SYS_TIMER_RATE 25000000
204   -#endif
205   -#define CONFIG_SYS_TIMER_COUNTS_DOWN
206   -#define CONFIG_SYS_TIMER_COUNTER (CONFIG_SYS_TIMERBASE + 0x4)
207   -
208   -#define CONFIG_ENV_IS_NOWHERE
209   -
210   -/*
211   - * network support
212   - */
213   -#ifndef CONFIG_SOCFPGA_VIRTUAL_TARGET
214   -#define CONFIG_DESIGNWARE_ETH 1
215   -#endif
216   -
217   -#ifdef CONFIG_DESIGNWARE_ETH
218   -#define CONFIG_EMAC0_BASE SOCFPGA_EMAC0_ADDRESS
219   -#define CONFIG_EMAC1_BASE SOCFPGA_EMAC1_ADDRESS
220   -/* console support for network */
221   -#define CONFIG_CMD_DHCP
222   -#define CONFIG_CMD_MII
223   -#define CONFIG_CMD_NET
224   -#define CONFIG_CMD_PING
225   -/* designware */
226   -#define CONFIG_NET_MULTI
227   -#define CONFIG_DW_ALTDESCRIPTOR
228   -#define CONFIG_DW_SEARCH_PHY
229   -#define CONFIG_MII
230   -#define CONFIG_PHY_GIGE
231   -#define CONFIG_DW_AUTONEG
232   -#define CONFIG_AUTONEG_TIMEOUT (15 * CONFIG_SYS_HZ)
233   -#define CONFIG_PHYLIB
234   -#define CONFIG_PHY_MICREL
235   -#define CONFIG_PHY_MICREL_KSZ9021
236   -/* EMAC controller and PHY used */
237   -#define CONFIG_EMAC_BASE CONFIG_EMAC1_BASE
238   -#define CONFIG_EPHY_PHY_ADDR CONFIG_EPHY1_PHY_ADDR
239   -#define CONFIG_PHY_INTERFACE_MODE PHY_INTERFACE_MODE_RGMII
240   -#endif /* CONFIG_DESIGNWARE_ETH */
241   -
242   -/*
243   - * L4 Watchdog
244   - */
245   -#define CONFIG_HW_WATCHDOG
246   -#define CONFIG_HW_WATCHDOG_TIMEOUT_MS 2000
247   -#define CONFIG_DESIGNWARE_WATCHDOG
248   -#define CONFIG_DW_WDT_BASE SOCFPGA_L4WD0_ADDRESS
249   -/* Clocks source frequency to watchdog timer */
250   -#define CONFIG_DW_WDT_CLOCK_KHZ 25000
251   -
252   -
253   -/*
254   - * SPL "Second Program Loader" aka Initial Software
255   - */
256   -
257   -/* Enable building of SPL globally */
258   -#define CONFIG_SPL_FRAMEWORK
259   -
260   -/* TEXT_BASE for linking the SPL binary */
261   -#define CONFIG_SPL_TEXT_BASE 0xFFFF0000
262   -
263   -/* Stack size for SPL */
264   -#define CONFIG_SPL_STACK_SIZE (4 * 1024)
265   -
266   -/* MALLOC size for SPL */
267   -#define CONFIG_SPL_MALLOC_SIZE (5 * 1024)
268   -
269   -#define CONFIG_SPL_SERIAL_SUPPORT
270   -#define CONFIG_SPL_BOARD_INIT
271   -
272   -#define CHUNKSZ_CRC32 (1 * 1024)
273   -
274   -#define CONFIG_CRC32_VERIFY
275   -
276   -/* Linker script for SPL */
277   -#define CONFIG_SPL_LDSCRIPT "arch/arm/cpu/armv7/socfpga/u-boot-spl.lds"
278   -
279   -/* Support for common/libcommon.o in SPL binary */
280   -#define CONFIG_SPL_LIBCOMMON_SUPPORT
281   -/* Support for lib/libgeneric.o in SPL binary */
282   -#define CONFIG_SPL_LIBGENERIC_SUPPORT
283   -
284   -/* Support for watchdog */
285   -#define CONFIG_SPL_WATCHDOG_SUPPORT
286   -
287   -#endif /* __CONFIG_H */
  100 +#endif /* __CONFIG_SOCFPGA_CYCLONE5_H__ */
... ... @@ -157,7 +157,7 @@
157 157 u32 cnt;
158 158 u32 addr;
159 159 u32 next_addr;
160   -};
  160 +} __aligned(ARCH_DMA_MINALIGN);
161 161  
162 162 static inline void dwmci_writel(struct dwmci_host *host, int reg, u32 val)
163 163 {
... ... @@ -232,6 +232,7 @@
232 232 #define IH_TYPE_MXSIMAGE 16 /* Freescale MXSBoot Image */
233 233 #define IH_TYPE_GPIMAGE 17 /* TI Keystone GPHeader Image */
234 234 #define IH_TYPE_ATMELIMAGE 18 /* ATMEL ROM bootable Image */
  235 +#define IH_TYPE_SOCFPGAIMAGE 19 /* Altera SOCFPGA Preloader */
235 236  
236 237 /*
237 238 * Compression Types
... ... @@ -87,6 +87,7 @@
87 87 os_support.o \
88 88 pblimage.o \
89 89 pbl_crc32.o \
  90 + socfpgaimage.o \
90 91 lib/sha1.o \
91 92 lib/sha256.o \
92 93 ublimage.o \
... ... @@ -47,6 +47,8 @@
47 47 init_ubl_image_type();
48 48 /* Init Davinci AIS support */
49 49 init_ais_image_type();
  50 + /* Init Altera SOCFPGA support */
  51 + init_socfpga_image_type();
50 52 /* Init TI Keystone boot image generation/list support */
51 53 init_gpimage_type();
52 54 }
... ... @@ -168,6 +168,7 @@
168 168 void init_fit_image_type(void);
169 169 void init_ubl_image_type(void);
170 170 void init_omap_image_type(void);
  171 +void init_socfpga_image_type(void);
171 172 void init_gpimage_type(void);
172 173  
173 174 void pbl_load_uboot(int fd, struct image_tool_params *mparams);
tools/socfpgaimage.c
  1 +/*
  2 + * Copyright (C) 2014 Charles Manning <cdhmanning@gmail.com>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + *
  6 + * Reference doc http://www.altera.com.cn/literature/hb/cyclone-v/cv_5400A.pdf
  7 + * Note this doc is not entirely accurate. Of particular interest to us is the
  8 + * "header" length field being in U32s and not bytes.
  9 + *
  10 + * "Header" is a structure of the following format.
  11 + * this is positioned at 0x40.
  12 + *
  13 + * Endian is LSB.
  14 + *
  15 + * Offset Length Usage
  16 + * -----------------------
  17 + * 0x40 4 Validation word 0x31305341
  18 + * 0x44 1 Version (whatever, zero is fine)
  19 + * 0x45 1 Flags (unused, zero is fine)
  20 + * 0x46 2 Length (in units of u32, including the end checksum).
  21 + * 0x48 2 Zero
  22 + * 0x4A 2 Checksum over the header. NB Not CRC32
  23 + *
  24 + * At the end of the code we have a 32-bit CRC checksum over whole binary
  25 + * excluding the CRC.
  26 + *
  27 + * Note that the CRC used here is **not** the zlib/Adler crc32. It is the
  28 + * CRC-32 used in bzip2, ethernet and elsewhere.
  29 + *
  30 + * The image is padded out to 64k, because that is what is
  31 + * typically used to write the image to the boot medium.
  32 + */
  33 +
  34 +#include "pbl_crc32.h"
  35 +#include "imagetool.h"
  36 +#include <image.h>
  37 +
  38 +#define HEADER_OFFSET 0x40
  39 +#define VALIDATION_WORD 0x31305341
  40 +#define PADDED_SIZE 0x10000
  41 +
  42 +/* To allow for adding CRC, the max input size is a bit smaller. */
  43 +#define MAX_INPUT_SIZE (PADDED_SIZE - sizeof(uint32_t))
  44 +
  45 +static uint8_t buffer[PADDED_SIZE];
  46 +
  47 +static struct socfpga_header {
  48 + uint32_t validation;
  49 + uint8_t version;
  50 + uint8_t flags;
  51 + uint16_t length_u32;
  52 + uint16_t zero;
  53 + uint16_t checksum;
  54 +} header;
  55 +
  56 +/*
  57 + * The header checksum is just a very simple checksum over
  58 + * the header area.
  59 + * There is still a crc32 over the whole lot.
  60 + */
  61 +static uint16_t hdr_checksum(struct socfpga_header *header)
  62 +{
  63 + int len = sizeof(*header) - sizeof(header->checksum);
  64 + uint8_t *buf = (uint8_t *)header;
  65 + uint16_t ret = 0;
  66 +
  67 + while (--len)
  68 + ret += *buf++;
  69 +
  70 + return ret;
  71 +}
  72 +
  73 +
  74 +static void build_header(uint8_t *buf, uint8_t version, uint8_t flags,
  75 + uint16_t length_bytes)
  76 +{
  77 + header.validation = htole32(VALIDATION_WORD);
  78 + header.version = version;
  79 + header.flags = flags;
  80 + header.length_u32 = htole16(length_bytes/4);
  81 + header.zero = 0;
  82 + header.checksum = htole16(hdr_checksum(&header));
  83 +
  84 + memcpy(buf, &header, sizeof(header));
  85 +}
  86 +
  87 +/*
  88 + * Perform a rudimentary verification of header and return
  89 + * size of image.
  90 + */
  91 +static int verify_header(const uint8_t *buf)
  92 +{
  93 + memcpy(&header, buf, sizeof(header));
  94 +
  95 + if (le32toh(header.validation) != VALIDATION_WORD)
  96 + return -1;
  97 + if (le16toh(header.checksum) != hdr_checksum(&header))
  98 + return -1;
  99 +
  100 + return le16toh(header.length_u32) * 4;
  101 +}
  102 +
  103 +/* Sign the buffer and return the signed buffer size */
  104 +static int sign_buffer(uint8_t *buf,
  105 + uint8_t version, uint8_t flags,
  106 + int len, int pad_64k)
  107 +{
  108 + uint32_t calc_crc;
  109 +
  110 + /* Align the length up */
  111 + len = (len + 3) & (~3);
  112 +
  113 + /* Build header, adding 4 bytes to length to hold the CRC32. */
  114 + build_header(buf + HEADER_OFFSET, version, flags, len + 4);
  115 +
  116 + /* Calculate and apply the CRC */
  117 + calc_crc = ~pbl_crc32(0, (char *)buf, len);
  118 +
  119 + *((uint32_t *)(buf + len)) = htole32(calc_crc);
  120 +
  121 + if (!pad_64k)
  122 + return len + 4;
  123 +
  124 + return PADDED_SIZE;
  125 +}
  126 +
  127 +/* Verify that the buffer looks sane */
  128 +static int verify_buffer(const uint8_t *buf)
  129 +{
  130 + int len; /* Including 32bit CRC */
  131 + uint32_t calc_crc;
  132 + uint32_t buf_crc;
  133 +
  134 + len = verify_header(buf + HEADER_OFFSET);
  135 + if (len < 0) {
  136 + fprintf(stderr, "Invalid header\n");
  137 + return -1;
  138 + }
  139 +
  140 + if (len < HEADER_OFFSET || len > PADDED_SIZE) {
  141 + fprintf(stderr, "Invalid header length (%i)\n", len);
  142 + return -1;
  143 + }
  144 +
  145 + /*
  146 + * Adjust length to the base of the CRC.
  147 + * Check the CRC.
  148 + */
  149 + len -= 4;
  150 +
  151 + calc_crc = ~pbl_crc32(0, (const char *)buf, len);
  152 +
  153 + buf_crc = le32toh(*((uint32_t *)(buf + len)));
  154 +
  155 + if (buf_crc != calc_crc) {
  156 + fprintf(stderr, "CRC32 does not match (%08x != %08x)\n",
  157 + buf_crc, calc_crc);
  158 + return -1;
  159 + }
  160 +
  161 + return 0;
  162 +}
  163 +
  164 +/* mkimage glue functions */
  165 +static int socfpgaimage_verify_header(unsigned char *ptr, int image_size,
  166 + struct image_tool_params *params)
  167 +{
  168 + if (image_size != PADDED_SIZE)
  169 + return -1;
  170 +
  171 + return verify_buffer(ptr);
  172 +}
  173 +
  174 +static void socfpgaimage_print_header(const void *ptr)
  175 +{
  176 + if (verify_buffer(ptr) == 0)
  177 + printf("Looks like a sane SOCFPGA preloader\n");
  178 + else
  179 + printf("Not a sane SOCFPGA preloader\n");
  180 +}
  181 +
  182 +static int socfpgaimage_check_params(struct image_tool_params *params)
  183 +{
  184 + /* Not sure if we should be accepting fflags */
  185 + return (params->dflag && (params->fflag || params->lflag)) ||
  186 + (params->fflag && (params->dflag || params->lflag)) ||
  187 + (params->lflag && (params->dflag || params->fflag));
  188 +}
  189 +
  190 +static int socfpgaimage_check_image_types(uint8_t type)
  191 +{
  192 + if (type == IH_TYPE_SOCFPGAIMAGE)
  193 + return EXIT_SUCCESS;
  194 + return EXIT_FAILURE;
  195 +}
  196 +
  197 +/*
  198 + * To work in with the mkimage framework, we do some ugly stuff...
  199 + *
  200 + * First, socfpgaimage_vrec_header() is called.
  201 + * We prepend a fake header big enough to make the file PADDED_SIZE.
  202 + * This gives us enough space to do what we want later.
  203 + *
  204 + * Next, socfpgaimage_set_header() is called.
  205 + * We fix up the buffer by moving the image to the start of the buffer.
  206 + * We now have some room to do what we need (add CRC and padding).
  207 + */
  208 +
  209 +static int data_size;
  210 +#define FAKE_HEADER_SIZE (PADDED_SIZE - data_size)
  211 +
  212 +static int socfpgaimage_vrec_header(struct image_tool_params *params,
  213 + struct image_type_params *tparams)
  214 +{
  215 + struct stat sbuf;
  216 +
  217 + if (params->datafile &&
  218 + stat(params->datafile, &sbuf) == 0 &&
  219 + sbuf.st_size <= MAX_INPUT_SIZE) {
  220 + data_size = sbuf.st_size;
  221 + tparams->header_size = FAKE_HEADER_SIZE;
  222 + }
  223 + return 0;
  224 +}
  225 +
  226 +static void socfpgaimage_set_header(void *ptr, struct stat *sbuf, int ifd,
  227 + struct image_tool_params *params)
  228 +{
  229 + uint8_t *buf = (uint8_t *)ptr;
  230 +
  231 + /*
  232 + * This function is called after vrec_header() has been called.
  233 + * At this stage we have the FAKE_HEADER_SIZE dummy bytes followed by
  234 + * data_size image bytes. Total = PADDED_SIZE.
  235 + * We need to fix the buffer by moving the image bytes back to
  236 + * the beginning of the buffer, then actually do the signing stuff...
  237 + */
  238 + memmove(buf, buf + FAKE_HEADER_SIZE, data_size);
  239 + memset(buf + data_size, 0, FAKE_HEADER_SIZE);
  240 +
  241 + sign_buffer(buf, 0, 0, data_size, 0);
  242 +}
  243 +
  244 +static struct image_type_params socfpgaimage_params = {
  245 + .name = "Altera SOCFPGA preloader support",
  246 + .vrec_header = socfpgaimage_vrec_header,
  247 + .header_size = 0, /* This will be modified by vrec_header() */
  248 + .hdr = (void *)buffer,
  249 + .check_image_type = socfpgaimage_check_image_types,
  250 + .verify_header = socfpgaimage_verify_header,
  251 + .print_header = socfpgaimage_print_header,
  252 + .set_header = socfpgaimage_set_header,
  253 + .check_params = socfpgaimage_check_params,
  254 +};
  255 +
  256 +void init_socfpga_image_type(void)
  257 +{
  258 + register_image_type(&socfpgaimage_params);
  259 +}