xref: /rk3399_rockchip-uboot/include/linux/mtd/omap_elm.h (revision dab5e3469d294a4e1ffed8407d296a78e02cc01f)
12eda892fSpekon gupta /*
22eda892fSpekon gupta  * (C) Copyright 2010-2011 Texas Instruments, <www.ti.com>
32eda892fSpekon gupta  * Mansoor Ahamed <mansoor.ahamed@ti.com>
42eda892fSpekon gupta  *
52eda892fSpekon gupta  * Derived from work done by Rohit Choraria <rohitkc@ti.com> for omap3
62eda892fSpekon gupta  *
72eda892fSpekon gupta  * SPDX-License-Identifier:	GPL-2.0+
82eda892fSpekon gupta  */
92eda892fSpekon gupta #ifndef __ASM_ARCH_ELM_H
102eda892fSpekon gupta #define __ASM_ARCH_ELM_H
112eda892fSpekon gupta /*
122eda892fSpekon gupta  * ELM Module Registers
132eda892fSpekon gupta  */
142eda892fSpekon gupta 
152eda892fSpekon gupta /* ELM registers bit fields */
162eda892fSpekon gupta #define ELM_SYSCONFIG_SOFTRESET_MASK			(0x2)
172eda892fSpekon gupta #define ELM_SYSCONFIG_SOFTRESET			(0x2)
182eda892fSpekon gupta #define ELM_SYSSTATUS_RESETDONE_MASK			(0x1)
192eda892fSpekon gupta #define ELM_SYSSTATUS_RESETDONE			(0x1)
202eda892fSpekon gupta #define ELM_LOCATION_CONFIG_ECC_BCH_LEVEL_MASK		(0x3)
212eda892fSpekon gupta #define ELM_LOCATION_CONFIG_ECC_SIZE_MASK		(0x7FF0000)
222eda892fSpekon gupta #define ELM_LOCATION_CONFIG_ECC_SIZE_POS		(16)
232eda892fSpekon gupta #define ELM_SYNDROME_FRAGMENT_6_SYNDROME_VALID		(0x00010000)
242eda892fSpekon gupta #define ELM_LOCATION_STATUS_ECC_CORRECTABLE_MASK	(0x100)
252eda892fSpekon gupta #define ELM_LOCATION_STATUS_ECC_NB_ERRORS_MASK		(0x1F)
262eda892fSpekon gupta 
27*0439d752Spekon gupta #define ELM_MAX_CHANNELS				8
28*0439d752Spekon gupta #define ELM_MAX_ERROR_COUNT				16
29*0439d752Spekon gupta 
302eda892fSpekon gupta #ifndef __ASSEMBLY__
312eda892fSpekon gupta 
322eda892fSpekon gupta enum bch_level {
332eda892fSpekon gupta 	BCH_4_BIT = 0,
342eda892fSpekon gupta 	BCH_8_BIT,
352eda892fSpekon gupta 	BCH_16_BIT
362eda892fSpekon gupta };
372eda892fSpekon gupta 
382eda892fSpekon gupta 
392eda892fSpekon gupta /* BCH syndrome registers */
402eda892fSpekon gupta struct syndrome {
412eda892fSpekon gupta 	u32 syndrome_fragment_x[7];	/* 0x400, 0x404.... 0x418 */
422eda892fSpekon gupta 	u8 res1[36];			/* 0x41c */
432eda892fSpekon gupta };
442eda892fSpekon gupta 
452eda892fSpekon gupta /* BCH error status & location register */
462eda892fSpekon gupta struct location {
472eda892fSpekon gupta 	u32 location_status;		/* 0x800 */
482eda892fSpekon gupta 	u8 res1[124];			/* 0x804 */
49*0439d752Spekon gupta 	u32 error_location_x[ELM_MAX_ERROR_COUNT]; /* 0x880, 0x980, .. */
502eda892fSpekon gupta 	u8 res2[64];			/* 0x8c0 */
512eda892fSpekon gupta };
522eda892fSpekon gupta 
532eda892fSpekon gupta /* BCH ELM register map - do not try to allocate memmory for this structure.
542eda892fSpekon gupta  * We have used plenty of reserved variables to fill the slots in the ELM
552eda892fSpekon gupta  * register memory map.
562eda892fSpekon gupta  * Directly initialize the struct pointer to ELM base address.
572eda892fSpekon gupta  */
582eda892fSpekon gupta struct elm {
592eda892fSpekon gupta 	u32 rev;				/* 0x000 */
602eda892fSpekon gupta 	u8 res1[12];				/* 0x004 */
612eda892fSpekon gupta 	u32 sysconfig;				/* 0x010 */
622eda892fSpekon gupta 	u32 sysstatus;				/* 0x014 */
632eda892fSpekon gupta 	u32 irqstatus;				/* 0x018 */
642eda892fSpekon gupta 	u32 irqenable;				/* 0x01c */
652eda892fSpekon gupta 	u32 location_config;			/* 0x020 */
662eda892fSpekon gupta 	u8 res2[92];				/* 0x024 */
672eda892fSpekon gupta 	u32 page_ctrl;				/* 0x080 */
682eda892fSpekon gupta 	u8 res3[892];				/* 0x084 */
69*0439d752Spekon gupta 	struct  syndrome syndrome_fragments[ELM_MAX_CHANNELS]; /* 0x400,0x420 */
702eda892fSpekon gupta 	u8 res4[512];				/* 0x600 */
71*0439d752Spekon gupta 	struct location  error_location[ELM_MAX_CHANNELS]; /* 0x800,0x900 ... */
722eda892fSpekon gupta };
732eda892fSpekon gupta 
7441bbe4ddSpekon gupta int elm_check_error(u8 *syndrome, enum bch_level bch_type, u32 *error_count,
752eda892fSpekon gupta 		u32 *error_locations);
762eda892fSpekon gupta int elm_config(enum bch_level level);
772eda892fSpekon gupta void elm_reset(void);
782eda892fSpekon gupta void elm_init(void);
792eda892fSpekon gupta #endif /* __ASSEMBLY__ */
802eda892fSpekon gupta #endif /* __ASM_ARCH_ELM_H */
81