All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andreas Bießmann" <andreas.devel@googlemail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/3] mtd: atmel_nand: runtime to build gf table for pmecc
Date: Wed, 29 Oct 2014 04:06:03 +0100	[thread overview]
Message-ID: <5450599B.8010509@googlemail.com> (raw)
In-Reply-To: <1414549973-23558-2-git-send-email-voice.shen@atmel.com>

Hi Bo,

On 29.10.14 03:32, Bo Shen wrote:
> From: Josh Wu <josh.wu@atmel.com>
> 
> As in SAMA5D4 SoC, the gf table in ROM code can not be seen.
> So, when we try to use PMECC, we need to build it when do
> initialization.
> Add a macro NO_GALOIS_TABLE_IN_ROM in soc header file. If it
> is defined we will build gf table runtime.
> 
> The PMECC use the BCH algorithm, so based on the build_gf_tables()
> function in lib/bch.c, we can build the Galois Field lookup table.
> 
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
> Signed-off-by: Bo Shen <voice.shen@atmel.com>
> ---
> Changes in v2:
>   - rewrite the gf table build function by Josh.
> 
>  drivers/mtd/nand/atmel_nand.c     | 75 ++++++++++++++++++++++++++++++++++++++-
>  drivers/mtd/nand/atmel_nand_ecc.h |  4 +++
>  2 files changed, 78 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 9114a86..20fcecb 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -762,6 +762,62 @@ static int pmecc_choose_ecc(struct atmel_nand_host *host,
>  }
>  #endif
>  
> +#if defined(NO_GALOIS_TABLE_IN_ROM)
> +static uint16_t *pmecc_galois_table;
> +static inline int deg(unsigned int poly)
> +{
> +	/* polynomial degree is the most-significant bit index */
> +	return fls(poly) - 1;
> +}
> +
> +static int build_gf_tables(int mm, unsigned int poly,
> +			   int16_t *index_of, int16_t *alpha_to)
> +{
> +	unsigned int i, x = 1;
> +	const unsigned int k = 1 << deg(poly);
> +	unsigned int nn = (1 << mm) - 1;
> +
> +	/* primitive polynomial must be of degree m */
> +	if (k != (1u << mm))
> +		return -EINVAL;
> +
> +	for (i = 0; i < nn; i++) {
> +		alpha_to[i] = x;
> +		index_of[x] = i;
> +		if (i && (x == 1))
> +			/* polynomial is not primitive (a^i=1 with 0<i<2^m-1) */
> +			return -EINVAL;
> +		x <<= 1;
> +		if (x & k)
> +			x ^= poly;
> +	}
> +
> +	alpha_to[nn] = 1;
> +	index_of[0] = 0;
> +
> +	return 0;
> +}
> +
> +static uint16_t *create_lookup_table(int sector_size)
> +{
> +	int degree = (sector_size == 512) ?
> +			PMECC_GF_DIMENSION_13 :
> +			PMECC_GF_DIMENSION_14;
> +	unsigned int poly = (sector_size == 512) ?
> +			PMECC_GF_13_PRIMITIVE_POLY :
> +			PMECC_GF_14_PRIMITIVE_POLY;
> +	int table_size = (sector_size == 512) ?
> +			PMECC_INDEX_TABLE_SIZE_512 :
> +			PMECC_INDEX_TABLE_SIZE_1024;
> +
> +	int16_t *addr = kzalloc(2 * table_size * sizeof(uint16_t), GFP_KERNEL);
> +	if (addr && build_gf_tables(degree, poly, addr, addr + table_size))
> +		return NULL;
> +
> +	return (uint16_t *)addr;
> +}
> +#endif
> +
>  static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
>  		struct mtd_info *mtd)
>  {
> @@ -809,11 +865,18 @@ static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
>  	sector_size = host->pmecc_sector_size;
>  
>  	/* TODO: need check whether cap & sector_size is validate */
> -
> +#if defined(NO_GALOIS_TABLE_IN_ROM)
> +	/*
> +	 * As pmecc_rom_base is the begin of the gallois field table, So the
> +	 * index offset just set as 0.
> +	 */
> +	host->pmecc_index_table_offset = 0;
> +#else
>  	if (host->pmecc_sector_size == 512)
>  		host->pmecc_index_table_offset = ATMEL_PMECC_INDEX_OFFSET_512;
>  	else
>  		host->pmecc_index_table_offset = ATMEL_PMECC_INDEX_OFFSET_1024;
> +#endif
>  
>  	MTDDEBUG(MTD_DEBUG_LEVEL1,
>  		"Initialize PMECC params, cap: %d, sector: %d\n",
> @@ -822,7 +885,17 @@ static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
>  	host->pmecc = (struct pmecc_regs __iomem *) ATMEL_BASE_PMECC;
>  	host->pmerrloc = (struct pmecc_errloc_regs __iomem *)
>  			ATMEL_BASE_PMERRLOC;
> +#if defined(NO_GALOIS_TABLE_IN_ROM)
> +	pmecc_galois_table = create_lookup_table(host->pmecc_sector_size);
> +	if (!pmecc_galois_table) {
> +		dev_err(host->dev, "out of memory\n");
> +		return -ENOMEM;
> +	}
> +
> +	host->pmecc_rom_base = (void __iomem *)pmecc_galois_table;
> +#else
>  	host->pmecc_rom_base = (void __iomem *) ATMEL_BASE_ROM;
> +#endif
>  
>  	/* ECC is calculated for the whole page (1 step) */
>  	nand->ecc.size = mtd->writesize;
> diff --git a/drivers/mtd/nand/atmel_nand_ecc.h b/drivers/mtd/nand/atmel_nand_ecc.h
> index 92d4ec5..eac860d 100644
> --- a/drivers/mtd/nand/atmel_nand_ecc.h
> +++ b/drivers/mtd/nand/atmel_nand_ecc.h
> @@ -141,6 +141,10 @@ struct pmecc_errloc_regs {
>  #define PMECC_GF_DIMENSION_13			13
>  #define PMECC_GF_DIMENSION_14			14
>  
> +/* Primitive Polynomial used by PMECC */
> +#define PMECC_GF_13_PRIMITIVE_POLY		0x201b
> +#define PMECC_GF_14_PRIMITIVE_POLY		0x4443
> +
>  #define PMECC_INDEX_TABLE_SIZE_512		0x2000
>  #define PMECC_INDEX_TABLE_SIZE_1024		0x4000
>  
> 

looks way better! I'll apply this these days.

Best regards

Andreas Bie?mann

  reply	other threads:[~2014-10-29  3:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-29  2:32 [U-Boot] [PATCH v2 0/3] ARM: atmel: add sama5d4ek board support Bo Shen
2014-10-29  2:32 ` [U-Boot] [PATCH v2 1/3] mtd: atmel_nand: runtime to build gf table for pmecc Bo Shen
2014-10-29  3:06   ` Andreas Bießmann [this message]
2014-10-29  2:32 ` [U-Boot] [PATCH v2 2/3] net: macb: enable GMAC IP without GE feature support Bo Shen
2014-10-29  2:32 ` [U-Boot] [PATCH v2 3/3] ARM: atmel: add sama5d4ek board support Bo Shen
2014-10-29  3:24   ` Andreas Bießmann
2014-10-29  3:27     ` Andreas Bießmann
2014-10-29  3:38     ` Bo Shen

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=5450599B.8010509@googlemail.com \
    --to=andreas.devel@googlemail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.