public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Dinh Nguyen <dinguyen@opensource.altera.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv1 01/22] arm: socfpga: spl: Add main sdram code
Date: Tue, 20 Jan 2015 17:51:10 -0600	[thread overview]
Message-ID: <54BEE9EE.4020003@opensource.altera.com> (raw)
In-Reply-To: <201501150034.16486.marex@denx.de>

On 01/14/2015 05:34 PM, Marek Vasut wrote:
> On Wednesday, January 14, 2015 at 05:40:41 PM, dinguyen at opensource.altera.com 
> wrote:
>> From: Dinh Nguyen <dinguyen@opensource.altera.com>
> 
> Hi!
> 
>> This adds the code to configure the SDRAM controller that is found in the
>> SoCFGPA Cyclone5 and Arria5 platforms.
>>
>> Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
>> ---
>>  arch/arm/cpu/armv7/socfpga/config.mk               |    3 +-
>>  board/altera/socfpga/Makefile                      |    1 +
>>  board/altera/socfpga/sdram/Makefile                |   12 +
>>  board/altera/socfpga/sdram/sdram_config.h          |  100 +
>>  board/altera/socfpga/sdram/sdram_io.h              |   44 +
>>  board/altera/socfpga/sdram/sequencer.c             | 7993
> 
> A general remark: SDRAM stuff should most likely reside in drivers/ddr/ , don't 
> you think so ?

Yes, I suppose. Move it to drivers/ddr/altera?

> 
>> ++++++++++++++++++++ board/altera/socfpga/sdram/sequencer.h             | 
>> 504 ++
>>  board/altera/socfpga/sdram/sequencer_auto.h        |  216 +
>>  .../altera/socfpga/sdram/sequencer_auto_ac_init.c  |   88 +

<snip>

>> @@ -0,0 +1,44 @@
>> +/*
>> + * Copyright Altera Corporation (C) 2012-2014. All rights reserved
>> + *
>> + * SPDX-License-Identifier:    BSD-3-Clause
> 
> Any chance we can get these files under GPL-2.0+ ? It's not a showstopper, but 
> it'd be nice :)
> 
>> + */
>> +
>> +#include <asm/io.h>
>> +
>> +#ifdef CONFIG_SPL_SERIAL_SUPPORT
>> +#define HPS_HW_SERIAL_SUPPORT
> 
> Are these redundant definitions really needed ?

Probably not, but I can check again.

> 
>> +#endif
>> +
>> +#define	HPS_SDR_BASE		SOCFPGA_SDR_ADDRESS
> 
> This here as well, just use SOCFPGA_SDR_ADDRESS in the code. Besides, it'd be 
> nice to consistently use <space> after #define keyword.
> 
>> +#define MGR_SELECT_MASK		0xf8000
>> +
>> +#define APB_BASE_SCC_MGR	SDR_PHYGRP_SCCGRP_ADDRESS
>> +#define APB_BASE_PHY_MGR	SDR_PHYGRP_PHYMGRGRP_ADDRESS
>> +#define APB_BASE_RW_MGR		SDR_PHYGRP_RWMGRGRP_ADDRESS
>> +#define APB_BASE_DATA_MGR	SDR_PHYGRP_DATAMGRGRP_ADDRESS
>> +#define APB_BASE_REG_FILE	SDR_PHYGRP_REGFILEGRP_ADDRESS
>> +#define APB_BASE_MMR		SDR_CTRLGRP_ADDRESS
> 
> More redundancy here.

Will fix in v2.

> 
>> +#define __AVL_TO_APB(ADDR) \
>> +	((((ADDR) & MGR_SELECT_MASK) == (BASE_PHY_MGR))  ? \
>> +	(APB_BASE_PHY_MGR)  | (((ADDR) >> (14-6)) & (0x1<<6))  | \
>> +	((ADDR) & 0x3f) : \
>> +	(((ADDR) & MGR_SELECT_MASK) == (BASE_RW_MGR))   ? \
>> +	(APB_BASE_RW_MGR)   | ((ADDR) & 0x1fff) : \
>> +	(((ADDR) & MGR_SELECT_MASK) == (BASE_DATA_MGR)) ? \
>> +	(APB_BASE_DATA_MGR) | ((ADDR) & 0x7ff) : \
>> +	(((ADDR) & MGR_SELECT_MASK) == (BASE_SCC_MGR))  ? \
>> +	(APB_BASE_SCC_MGR)  | ((ADDR) & 0xfff) : \
>> +	(((ADDR) & MGR_SELECT_MASK) == (BASE_REG_FILE)) ? \
>> +	(APB_BASE_REG_FILE) | ((ADDR) & 0x7ff) : \
>> +	(((ADDR) & MGR_SELECT_MASK) == (BASE_MMR))      ? \
>> +	(APB_BASE_MMR)      | ((ADDR) & 0xfff) : -1)
>> +
> 
> This stuff here should be a function, to get a proper typechecking on it.

Ok.

> 
>> +#define IOWR_32DIRECT(BASE, OFFSET, DATA) \
>> +	writel(DATA, HPS_SDR_BASE + __AVL_TO_APB((uint32_t)((BASE) + \
>> +	(OFFSET))))
>> +
>> +#define IORD_32DIRECT(BASE, OFFSET) \
>> +	readl(HPS_SDR_BASE + __AVL_TO_APB((uint32_t)((BASE) + (OFFSET))))
> 
> OK, these macros look really questionable.  You might want to make them into a 
> function too, but before you do so, I'd rather suggest you rethink this entire
> _AVL_TO_APB usage and make this entire section more readable. The code is really 
> confusing here.
> 

Will look to fix in V2.

>> +
>> diff --git a/board/altera/socfpga/sdram/sequencer.c
>> b/board/altera/socfpga/sdram/sequencer.c new file mode 100644
>> index 0000000..c0ba0e5
>> --- /dev/null
>> +++ b/board/altera/socfpga/sdram/sequencer.c
>> @@ -0,0 +1,7993 @@
>> +/*
>> + * Copyright Altera Corporation (C) 2012-2014. All rights reserved
>> + *
>> + * SPDX-License-Identifier:    BSD-3-Clause
>> + */
>> +
>> +#include <common.h>
>> +#include <asm/io.h>
>> +#include <asm/arch/sdram.h>
>> +#include "sdram_io.h"
>> +#include "sequencer.h"
>> +#include "sequencer_auto.h"
>> +#include "sequencer_defines.h"
>> +#include "system.h"
>> +
>> +static void scc_mgr_load_dqs_for_write_group(uint32_t write_group);
>> +static void rw_mgr_mem_dll_lock_wait(void);
>> +
>> +/*************************************************************************
>> ***** +
>> **************************************************************************
>> **** + ** NOTE: Special Rules for Globale Variables                        
>>        ** + **                                                            
>>              ** + ** All global variables that are explicitly initialized
>> (including          ** + ** explicitly initialized to zero), are only
>> initialized once, during       ** + ** configuration time, and not again
>> on reset.  This means that they        ** + ** preserve their current
>> contents across resets, which is needed for some  ** + ** special cases
>> involving communication with external modules.  In         ** + **
>> addition, this avoids paying the price to have the memory initialized,  
>> ** + ** even for zeroed data, provided it is explicitly set to zero in the
>> code, ** + ** and doesn't rely on implicit initialization.                
>>             ** +
>> **************************************************************************
>> **** +
>> **************************************************************************
>> ****/ +
>> +#if ARRIAV
>> +/*
>> + * Temporary workaround to place the initial stack pointer at a safe
>> + * offset from end
>> + */
>> +#define STRINGIFY(s)		STRINGIFY_STR(s)
>> +#define STRINGIFY_STR(s)	#s
> 
> There's already a macro named __stringify(), no need to duplicate it here.

Ok.

> 
>> +asm(".global __alt_stack_pointer");
>> +asm("__alt_stack_pointer = " STRINGIFY(STACK_POINTER));
>> +#endif
> 
> [...]
> 
>> +/* For HPS running on actual hardware */
>> +
>> +#define DLEVEL 0
>> +#ifdef HPS_HW_SERIAL_SUPPORT
>> +/*
>> + * space around comma is required for varargs macro to remove comma if
>> args + * is empty
>> + */
>> +#define DPRINT(level, fmt, args...)	if (DLEVEL >= (level)) \
>> +					printf("SEQ.C: " fmt "\n" , ## args)
> 
> This could just use __FILE__ instead of hard-coding seq.c (which is not even the 
> filename anymore) .

Ok..

> 
>> +#define IPRINT(fmt, args...)	        printf("SEQ.C: " fmt "\n" , ## 
> args)
>> +#else
>> +#define DPRINT(level, fmt, args...)
>> +#define IPRINT(fmt, args...)
>> +#endif
>> +#define BFM_GBL_SET(field, value)
>> +#define BFM_GBL_GET(field)		((long unsigned int)0)
>> +#define BFM_STAGE(stage)
>> +#define BFM_INC_VFIFO
>> +#define COV(label)
>> +
>> +#define TRACE_FUNC(fmt, args...) \
>> +	DPRINT(1, "%s[%d]: " fmt, __func__, __LINE__ , ## args)
> 
> I suspect you can use debug() or debug_cond() macro to avoid re-implementing
> the entire debug infrastructure here ;-)

Will fix up in V2.

> [...]
> 
>> +void wait_di_buffer(void)
>> +{
>> +	if (debug_data->di_report.cur_samples == NUM_DI_SAMPLE)	{
>> +		debug_data->di_report.flags |= DI_REPORT_FLAGS_READY;
>> +		while (debug_data->di_report.cur_samples != 0)
>> +			;
> 
> Please get rid of such endless loops, since the platform might get stuck forever 
> in them.
> 
>> +		debug_data->di_report.flags = 0;
>> +	}
>> +}
> 
> [...]
> 
>> diff --git a/board/altera/socfpga/sdram/sequencer.h
>> b/board/altera/socfpga/sdram/sequencer.h new file mode 100644
>> index 0000000..ce4c7bf
>> --- /dev/null
>> +++ b/board/altera/socfpga/sdram/sequencer.h
>> @@ -0,0 +1,504 @@
>> +/*
>> + * Copyright Altera Corporation (C) 2012-2014. All rights reserved
>> + *
>> + * SPDX-License-Identifier:    BSD-3-Clause
>> + */
>> +
>> +#ifndef _SEQUENCER_H_
>> +#define _SEQUENCER_H_
>> +
>> +extern int32_t inst_rom_init_size;
>> +extern uint32_t inst_rom_init[];
>> +extern uint32_t ac_rom_init_size;
>> +extern uint32_t ac_rom_init[];
> 
> Extern variables usually mean the code is not well contained. You might
> want to review whether making these variables visible globally is really
> needed or not.

Will fix up in V2.

> 
>> +#if ENABLE_ASSERT
>> +#define ERR_IE_TEXT "Internal Error: Sub-system: %s, File: %s, Line:
>> %d\n%s%s"
> 
> This might just use debug_cond() in some way, no ?

Probably...

> 
>>
>> +extern void err_report_internal_error(const char *description,
>> +	const char *module, const char *file, int line);
> 
> In case of functions, the extern is really not needed. Just define the prototype 
> without the extern keyword.

Ok.

> 
>> +#define ALTERA_INTERNAL_ERROR(string) \
>> +	{err_report_internal_error(string, "SEQ", __FILE__, __LINE__); \
>> +	exit(-1); }
>> +
>> +#define ALTERA_ASSERT(condition) \
>> +	if (!(condition)) {\
>> +		ALTERA_INTERNAL_ERROR(#condition); }
>> +#define ALTERA_INFO_ASSERT(condition, text) \
>> +	if (!(condition)) {\
>> +		ALTERA_INTERNAL_ERROR(text); }
> 
> Oh wow, debug_cond() would help, really ;-)

Ok..

> 
>> +#else
>> +
>> +#define ALTERA_ASSERT(condition)
>> +#define ALTERA_INFO_ASSERT(condition, text)
> 
> [...]
> 
>> +
>> +#if LRDIMM
>> +/* USER RTT_NOM: bits {4,3,2} of the SPD = bits {9,6,2} of the MR */
>> +#define LRDIMM_SPD_MR_RTT_NOM(spd_byte)                              \
>> +	((((spd_byte) & (1 << 4)) << (9-4))                       \
>> +	| (((spd_byte) & (1 << 3)) << (6-3))                         \
>> +	| (((spd_byte) & (1 << 2)) << (2-2)))
>> +
>> +/* USER RTT_DRV: bits {1,0} of the SPD = bits {5,1} of the MR */
>> +#define LRDIMM_SPD_MR_RTT_DRV(spd_byte)                                  
>> \ +	((((spd_byte) & (1 << 1)) << (5-1))                         \
>> +	| (((spd_byte) & (1 << 0)) << (1-0)))
>> +
>> +/* USER RTT_WR: bits {7,6} of the SPD = bits {10,9} of the MR */
>> +#define LRDIMM_SPD_MR_RTT_WR(spd_byte)                                   
>> \ +	(((spd_byte) & (3 << 6)) << (9-6))
> 
> We already have multiple SPD parsers in U-Boot (git grep 'spd' should give you 
> an idea , for example see common/ddr_spd.c ). Could that be used to replace your
> SPD code ? I might be wrong here, so please correct me if I am ... :)

Ok..

> 
>> +#endif /* LRDIMM */
>> +#endif /* DDR3 */
>> +
>> +#define RW_MGR_MEM_NUMBER_OF_RANKS	1
>> +#define NUM_SHADOW_REGS			1
>> +
>> +#define RW_MGR_LOAD_CNTR_0		(BASE_RW_MGR + 0x0800)
>> +#define RW_MGR_LOAD_CNTR_1		(BASE_RW_MGR + 0x0804)
>> +#define RW_MGR_LOAD_CNTR_2		(BASE_RW_MGR + 0x0808)
>> +#define RW_MGR_LOAD_CNTR_3		(BASE_RW_MGR + 0x080C)
> 
> Can you please rework these register definitions to struct-based ones?

Ok..

> 
> [...]
> 
> Thank you for all the work you put into this !
> 

Really appreciate all the comments.

Dinh

  parent reply	other threads:[~2015-01-20 23:51 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14 16:40 [U-Boot] [PATCHv1 00/22] Add SPL support for SoCFGPA dinguyen at opensource.altera.com
2015-01-14 16:40 ` [U-Boot] [PATCHv1 01/22] arm: socfpga: spl: Add main sdram code dinguyen at opensource.altera.com
2015-01-14 23:34   ` Marek Vasut
2015-01-16 19:04     ` Pavel Machek
2015-01-17  2:39       ` Marek Vasut
2015-02-04 13:36         ` Pavel Machek
2015-01-20 23:51     ` Dinh Nguyen [this message]
2015-01-21  8:03       ` Stefan Roese
2015-02-15 23:11   ` Pavel Machek
2015-02-15 23:25   ` Pavel Machek
2015-02-23 16:37     ` Dinh Nguyen
2015-02-23 16:39       ` Dinh Nguyen
2015-02-23 16:57         ` Marek Vasut
2015-02-23 17:00           ` Dinh Nguyen
2015-02-24 17:48             ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 02/22] arm: socfpga: enable saveenv to mmc partition dinguyen at opensource.altera.com
2015-01-14 23:39   ` Marek Vasut
2015-01-15 22:00   ` Pavel Machek
2015-01-15 22:08     ` Marek Vasut
2015-01-16  4:50       ` Stefan Roese
2015-01-16  5:14         ` Marek Vasut
2015-01-16 18:35       ` Pavel Machek
2015-01-17 13:51         ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 03/22] arm: socfpga: Add sdram initialization code dinguyen at opensource.altera.com
2015-01-14 23:41   ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 04/22] arm: socfpga: spl: Add SRAM section dinguyen at opensource.altera.com
2015-01-14 23:40   ` Marek Vasut
2015-01-15 22:01   ` Pavel Machek
2015-01-14 16:40 ` [U-Boot] [PATCHv1 05/22] arm: socfpga: spl: put SPL in sram dinguyen at opensource.altera.com
2015-01-16 19:05   ` Pavel Machek
2015-01-14 16:40 ` [U-Boot] [PATCHv1 06/22] arm: socfpga: add functions to bring sdram, timer, and uart out of reset dinguyen at opensource.altera.com
2015-01-14 23:42   ` Marek Vasut
2015-01-16 19:06   ` Pavel Machek
2015-01-14 16:40 ` [U-Boot] [PATCHv1 07/22] arm: socfpga: spl: enable sdram, timer and uart dinguyen at opensource.altera.com
2015-01-14 23:44   ` Marek Vasut
2015-02-16 21:35   ` Pavel Machek
2015-01-14 16:40 ` [U-Boot] [PATCHv1 08/22] arm: socfpga: spl: Add call to timer_init dinguyen at opensource.altera.com
2015-01-14 23:45   ` Marek Vasut
2015-02-04  3:58     ` Dinh Nguyen
2015-01-14 16:40 ` [U-Boot] [PATCHv1 09/22] arm: socfpga: spl: allow bootrom to enable IOs after warm reset dinguyen at opensource.altera.com
2015-01-14 23:46   ` Marek Vasut
2015-02-16 21:36   ` Pavel Machek
2015-02-17  7:09     ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 10/22] arm: socfpga: spl: add sdram init and calibration dinguyen at opensource.altera.com
2015-01-14 23:47   ` Marek Vasut
2015-02-16 21:37   ` Pavel Machek
2015-01-14 16:40 ` [U-Boot] [PATCHv1 11/22] arm: socfpga: spl: printout sdram size dinguyen at opensource.altera.com
2015-01-14 23:49   ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 12/22] arm: socfpga: spl: Use common lowlevel_init dinguyen at opensource.altera.com
2015-01-14 23:51   ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 13/22] arm: socfpga: spl: Add s_init dinguyen at opensource.altera.com
2015-01-14 23:54   ` Marek Vasut
2015-02-05 21:16     ` Dinh Nguyen
2015-02-07 13:34       ` Marek Vasut
2015-02-09 16:50         ` Dinh Nguyen
2015-02-09 17:05           ` Marek Vasut
2015-02-07 17:07       ` Simon Glass
2015-01-14 16:40 ` [U-Boot] [PATCHv1 14/22] arm: socfpga: spl: update lowlevel_init dinguyen at opensource.altera.com
2015-01-14 23:56   ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 15/22] arm: socfpga: spl: add relocate_stack_to_sdram to lowlevel_init.S dinguyen at opensource.altera.com
2015-01-14 23:58   ` Marek Vasut
2015-01-15 19:19     ` Dinh Nguyen
2015-01-15 22:00       ` Marek Vasut
2015-01-16  0:07         ` Dinh Nguyen
2015-01-16  0:48           ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 16/22] arm: socfpga: spl: add the stack in OCRAM dinguyen at opensource.altera.com
2015-01-14 23:59   ` Marek Vasut
2015-01-14 16:40 ` [U-Boot] [PATCHv1 17/22] arm: socfpga: spl: add CONFIG_SPL_STACK to socfpga_common.h dinguyen at opensource.altera.com
2015-01-15  0:00   ` Marek Vasut
2015-01-16 21:56   ` Pavel Machek
2015-01-14 16:40 ` [U-Boot] [PATCHv1 18/22] arm: socfpga: add sdram stack to SPL dinguyen at opensource.altera.com
2015-01-14 16:40 ` [U-Boot] [PATCHv1 19/22] arm: socfpga: spl: set SPL_MALLOC_SIZE dinguyen at opensource.altera.com
2015-01-15  0:01   ` Marek Vasut
2015-01-14 16:41 ` [U-Boot] [PATCHv1 20/22] arm: socfpga: spl: add a malloc section in sram dinguyen at opensource.altera.com
2015-01-15  0:03   ` Marek Vasut
2015-01-14 16:41 ` [U-Boot] [PATCHv1 21/22] arm: socfpga: spl: Add SDRAM check dinguyen at opensource.altera.com
2015-01-15  0:04   ` Marek Vasut
2015-01-16 21:59     ` Pavel Machek
2015-01-17 11:00       ` Marek Vasut
2015-01-14 16:41 ` [U-Boot] [PATCHv1 22/22] arm: socfpga: spl: update pll_config for dev kit dinguyen at opensource.altera.com
2015-01-15  0:05   ` Marek Vasut
2015-01-14 23:01 ` [U-Boot] [PATCHv1 00/22] Add SPL support for SoCFGPA Marek Vasut
2015-01-15 21:57 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54BEE9EE.4020003@opensource.altera.com \
    --to=dinguyen@opensource.altera.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox