Skip to content

Commit 7b0b43d

Browse files
committed
update for new flash chip support
1 parent bccb49c commit 7b0b43d

File tree

12 files changed

+8254
-0
lines changed

12 files changed

+8254
-0
lines changed
Binary file not shown.
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/*
2+
* drivers/block/sunxi_nand/nfc/nfc.h
3+
*
4+
* (C) Copyright 2007-2012
5+
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License as
9+
* published by the Free Software Foundation; either version 2 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20+
* MA 02111-1307 USA
21+
*/
22+
23+
#ifndef _NFC_H_
24+
#define _NFC_H_
25+
26+
#include <mach/platform.h>
27+
28+
#define NAND_IO_BASE SW_VA_NANDFLASHC_IO_BASE
29+
#define __NFC_REG(x) (*(volatile unsigned int *)(NAND_IO_BASE + x))
30+
/*
31+
*********************************************************************************************************
32+
* Nand Flash Controller define < maintained by Richard >
33+
*********************************************************************************************************
34+
*/
35+
/* offset */
36+
#define NFC_REG_o_CTL 0x0000
37+
#define NFC_REG_o_ST 0x0004
38+
#define NFC_REG_o_INT 0x0008
39+
#define NFC_REG_o_TIMING_CTL 0x000C
40+
#define NFC_REG_o_TIMING_CFG 0x0010
41+
#define NFC_REG_o_ADDR_LOW 0x0014
42+
#define NFC_REG_o_ADDR_HIGH 0x0018
43+
#define NFC_REG_o_SECTOR_NUM 0x001C
44+
#define NFC_REG_o_CNT 0x0020
45+
#define NFC_REG_o_CMD 0x0024
46+
#define NFC_REG_o_RCMD_SET 0x0028
47+
#define NFC_REG_o_WCMD_SET 0x002C
48+
#define NFC_REG_o_IO_DATA 0x0030
49+
#define NFC_REG_o_ECC_CTL 0x0034
50+
#define NFC_REG_o_ECC_ST 0x0038
51+
#define NFC_REG_o_DEBUG 0x003C
52+
#define NFC_REG_o_ECC_CNT0 0x0040
53+
#define NFC_REG_o_ECC_CNT1 0x0044
54+
#define NFC_REG_o_ECC_CNT2 0x0048
55+
#define NFC_REG_o_ECC_CNT3 0x004c
56+
#define NFC_REG_o_USER_DATA_BASE 0x0050
57+
#define NFC_REG_o_SPARE_AREA 0x00A0
58+
#define NFC_o_RAM0_BASE 0x0400
59+
#define NFC_o_RAM1_BASE 0x0800
60+
/* registers */
61+
#define NFC_REG_CTL __NFC_REG( NFC_REG_o_CTL )
62+
#define NFC_REG_ST __NFC_REG( NFC_REG_o_ST )
63+
#define NFC_REG_INT __NFC_REG( NFC_REG_o_INT )
64+
#define NFC_REG_TIMING_CTL __NFC_REG( NFC_REG_o_TIMING_CTL )
65+
#define NFC_REG_TIMING_CFG __NFC_REG( NFC_REG_o_TIMING_CFG )
66+
#define NFC_REG_ADDR_LOW __NFC_REG( NFC_REG_o_ADDR_LOW )
67+
#define NFC_REG_ADDR_HIGH __NFC_REG( NFC_REG_o_ADDR_HIGH )
68+
#define NFC_REG_SECTOR_NUM __NFC_REG( NFC_REG_o_SECTOR_NUM )
69+
#define NFC_REG_CNT __NFC_REG( NFC_REG_o_CNT )
70+
#define NFC_REG_CMD __NFC_REG( NFC_REG_o_CMD )
71+
#define NFC_REG_RCMD_SET __NFC_REG( NFC_REG_o_RCMD_SET )
72+
#define NFC_REG_WCMD_SET __NFC_REG( NFC_REG_o_WCMD_SET )
73+
#define NFC_REG_IO_DATA __NFC_REG( NFC_REG_o_IO_DATA )
74+
#define NFC_REG_ECC_CTL __NFC_REG( NFC_REG_o_ECC_CTL )
75+
#define NFC_REG_ECC_ST __NFC_REG( NFC_REG_o_ECC_ST )
76+
#define NFC_REG_ECC_CNT0 __NFC_REG( NFC_REG_o_ECC_CNT0 )
77+
#define NFC_REG_ECC_CNT1 __NFC_REG( NFC_REG_o_ECC_CNT1 )
78+
#define NFC_REG_ECC_CNT2 __NFC_REG( NFC_REG_o_ECC_CNT2 )
79+
#define NFC_REG_ECC_CNT3 __NFC_REG( NFC_REG_o_ECC_CNT3 )
80+
#define NFC_REG_DEBUG __NFC_REG( NFC_REG_o_DEBUG )
81+
#define NFC_REG_USER_DATA(sct_num) __NFC_REG( NFC_REG_o_USER_DATA_BASE + 4 * sct_num )
82+
#define NFC_REG_SPARE_AREA __NFC_REG( NFC_REG_o_SPARE_AREA )
83+
#define NFC_RAM0_BASE ( NFC_o_RAM0_BASE )
84+
#define NFC_RAM1_BASE ( NFC_o_RAM1_BASE )
85+
86+
/*define bit use in NFC_CTL*/
87+
#define NFC_EN (1 << 0)
88+
#define NFC_RESET (1 << 1)
89+
#define NFC_BUS_WIDYH (1 << 2)
90+
#define NFC_RB_SEL (1 << 3)
91+
#define NFC_CE_SEL (7 << 24)
92+
#define NFC_CE_CTL (1 << 6)
93+
#define NFC_CE_CTL1 (1 << 7)
94+
#define NFC_PAGE_SIZE (0xf << 8)
95+
#define NFC_SAM (1 << 12)
96+
#define NFC_RAM_METHOD (1 << 14)
97+
#define NFC_DEBUG_CTL (1 << 31)
98+
99+
/*define bit use in NFC_ST*/
100+
#define NFC_RB_B2R (1 << 0)
101+
#define NFC_CMD_INT_FLAG (1 << 1)
102+
#define NFC_DMA_INT_FLAG (1 << 2)
103+
#define NFC_CMD_FIFO_STATUS (1 << 3)
104+
#define NFC_STA (1 << 4)
105+
#define NFC_NATCH_INT_FLAG (1 << 5)
106+
#define NFC_RB_STATE0 (1 << 8)
107+
#define NFC_RB_STATE1 (1 << 9)
108+
#define NFC_RB_STATE2 (1 << 10)
109+
#define NFC_RB_STATE3 (1 << 11)
110+
111+
/*define bit use in NFC_INT*/
112+
#define NFC_B2R_INT_ENABLE (1 << 0)
113+
#define NFC_CMD_INT_ENABLE (1 << 1)
114+
#define NFC_DMA_INT_ENABLE (1 << 2)
115+
116+
117+
/*define bit use in NFC_CMD*/
118+
#define NFC_CMD_LOW_BYTE (0xff << 0)
119+
#define NFC_CMD_HIGH_BYTE (0xff << 8)
120+
#define NFC_ADR_NUM (0x7 << 16)
121+
#define NFC_SEND_ADR (1 << 19)
122+
#define NFC_ACCESS_DIR (1 << 20)
123+
#define NFC_DATA_TRANS (1 << 21)
124+
#define NFC_SEND_CMD1 (1 << 22)
125+
#define NFC_WAIT_FLAG (1 << 23)
126+
#define NFC_SEND_CMD2 (1 << 24)
127+
#define NFC_SEQ (1 << 25)
128+
#define NFC_DATA_SWAP_METHOD (1 << 26)
129+
#define NFC_ROW_AUTO_INC (1 << 27)
130+
#define NFC_SEND_CMD3 (1 << 28)
131+
#define NFC_SEND_CMD4 (1 << 29)
132+
#define NFC_CMD_TYPE (3 << 30)
133+
134+
/* define bit use in NFC_RCMD_SET*/
135+
#define NFC_READ_CMD (0xff<< 0)
136+
#define NFC_RANDOM_READ_CMD0 (0xff << 8)
137+
#define NFC_RANDOM_READ_CMD1 (0xff << 16)
138+
139+
/*define bit use in NFC_WCMD_SET*/
140+
#define NFC_PROGRAM_CMD (0xff << 0)
141+
#define NFC_RANDOM_WRITE_CMD (0xff << 8)
142+
#define NFC_READ_CMD0 (0xff << 16)
143+
#define NFC_READ_CMD1 (0xff << 24)
144+
145+
/*define bit use in NFC_ECC_CTL*/
146+
#define NFC_ECC_EN (1 << 0)
147+
#define NFC_ECC_PIPELINE (1 << 3)
148+
#define NFC_ECC_EXCEPTION (1 << 4)
149+
#define NFC_ECC_BLOCK_SIZE (1 << 5)
150+
#define NFC_RANDOM_EN (1 << 9 )
151+
#define NFC_RANDOM_DIRECTION (1 << 10 )
152+
#define NFC_ECC_MODE (0xf << 12)
153+
#define NFC_RANDOM_SEED (0x7fff << 16))
154+
155+
#define NFC_IRQ_MAJOR 13
156+
/*cmd flag bit*/
157+
#define NFC_PAGE_MODE 0x1
158+
#define NFC_NORMAL_MODE 0x0
159+
160+
#define NFC_DATA_FETCH 0x1
161+
#define NFC_NO_DATA_FETCH 0x0
162+
#define NFC_MAIN_DATA_FETCH 0x1
163+
#define NFC_SPARE_DATA_FETCH 0X0
164+
#define NFC_WAIT_RB 0x1
165+
#define NFC_NO_WAIT_RB 0x0
166+
#define NFC_IGNORE 0x0
167+
168+
#define NFC_INT_RB 0
169+
#define NFC_INT_CMD 1
170+
#define NFC_INT_DMA 2
171+
#define NFC_INT_BATCh 5
172+
173+
typedef struct cmd_list{
174+
struct cmd_list *next;
175+
__u8 *addr;
176+
__u8 addr_cycle;
177+
__u8 data_fetch_flag;
178+
__u8 main_data_fetch;
179+
__u8 wait_rb_flag;
180+
__u32 bytecnt;
181+
__u32 value;
182+
}NFC_CMD_LIST;
183+
184+
typedef struct NFC_init_info{
185+
__u8 bus_width;// bus width 8 bit
186+
__u8 rb_sel; // ready busy
187+
__u8 ce_ctl; // chip select
188+
__u8 ce_ctl1;
189+
__u8 pagesize; // 1024 ,2048 ,
190+
__u8 serial_access_mode; // SAM0 SAM1
191+
__u8 ddr_type;
192+
__u8 debug;
193+
}NFC_INIT_INFO;
194+
195+
__s32 NFC_ReadRetryInit(__u32 read_retry_type);
196+
__s32 NFC_ReadRetryExit(__u32 read_retry_type);
197+
__s32 NFC_ReadRetry_off(__u32 chip); //sandisk readretry exit
198+
void NFC_GetOTPValue(__u32 chip, __u8* otp_value, __u32 read_retry_type);
199+
__s32 NFC_GetDefaultParam(__u32 chip, __u8 *defautl_value, __u32 read_retry_type);
200+
__s32 NFC_SetDefaultParam(__u32 chip, __u8 *defautl_value, __u32 read_retry_type);
201+
__s32 NFC_ReadRetry(__u32 chip, __u32 retry_count, __u32 read_retry_type);
202+
__s32 NFC_LSBEnable(__u32 chip, __u32 read_retry_type);
203+
__s32 NFC_LSBDisable(__u32 chip, __u32 read_retry_type);
204+
__s32 NFC_LSBInit(__u32 read_retry_type);
205+
__s32 NFC_LSBExit(__u32 read_retry_type);
206+
__s32 NFC_SetRandomSeed(__u32 random_seed);
207+
__s32 NFC_RandomEnable(void);
208+
__s32 NFC_RandomDisable(void);
209+
__s32 NFC_Init(NFC_INIT_INFO * nand_info);
210+
void NFC_Exit(void);
211+
__s32 NFC_Read(NFC_CMD_LIST * rcmd, void * mainbuf, void * sparebuf, __u8 dma_wait_mode, __u8 page_mode);
212+
__s32 NFC_Read_1K(NFC_CMD_LIST * rcmd, void * mainbuf, void * sparebuf, __u8 dma_wait_mode, __u8 page_mode);
213+
__s32 NFC_Read_Seq(NFC_CMD_LIST * rcmd, void * mainbuf, void * sparebuf, __u8 dma_wait_mode, __u8 page_mode);
214+
__s32 NFC_Read_Spare(NFC_CMD_LIST * rcmd, void * mainbuf, void * sparebuf, __u8 dma_wait_mode, __u8 page_mode);
215+
__s32 NFC_Write(NFC_CMD_LIST * wcmd, void * mainbuf, void * sparebuf, __u8 dma_wait_mode, __u8 rb_wait_mode, __u8 page_mode);
216+
__s32 NFC_Write_Seq(NFC_CMD_LIST * wcmd, void * mainbuf, void * sparebuf, __u8 dma_wait_mode, __u8 rb_wait_mode, __u8 page_mode);
217+
__s32 NFC_Write_1K(NFC_CMD_LIST * wcmd, void * mainbuf, void * sparebuf, __u8 dma_wait_mode, __u8 rb_wait_mode, __u8 page_mode);
218+
__s32 NFC_Erase(NFC_CMD_LIST * ecmd, __u8 rb_wait_mode);
219+
__s32 NFC_CopyBackRead(NFC_CMD_LIST * crcmd);
220+
__s32 NFC_CopyBackWrite(NFC_CMD_LIST * cwcmd, __u8 rb_wait_mode);
221+
__s32 NFC_GetId(NFC_CMD_LIST * idcmd, __u8 * idbuf);
222+
__s32 NFC_GetUniqueId(NFC_CMD_LIST * idcmd, __u8 * idbuf);
223+
__s32 NFC_SelectChip(__u32 chip);
224+
__s32 NFC_DeSelectChip(__u32 chip);
225+
__s32 NFC_SelectRb(__u32 rb);
226+
__s32 NFC_DeSelectRb(__u32 rb);
227+
__s32 NFC_GetStatus(NFC_CMD_LIST * scmd);
228+
__s32 NFC_CheckRbReady(__u32 rb);
229+
__s32 NFC_ChangMode(NFC_INIT_INFO * nand_info);
230+
__s32 NFC_SetEccMode(__u8 ecc_mode);
231+
__s32 NFC_ResetChip(NFC_CMD_LIST * reset_cmd);
232+
__u32 NFC_QueryINT(void);
233+
void NFC_EnableInt(__u8 minor_int);
234+
void NFC_DisableInt(__u8 minor_int);
235+
void NFC_InitDDRParam(__u32 chip, __u32 param);
236+
237+
#endif // #ifndef _NFC_H_
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* drivers/block/sunxi_nand/nfc/nfc_i.h
3+
*
4+
* (C) Copyright 2007-2012
5+
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License as
9+
* published by the Free Software Foundation; either version 2 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20+
* MA 02111-1307 USA
21+
*/
22+
23+
#ifndef _NFC_I_H_
24+
#define _NFC_I_H_
25+
26+
#include "../include/type_def.h"
27+
#include "nfc.h"
28+
//#include "../nfd/dma_for_nand.h"
29+
//#include "ebios_i.h"
30+
//#define MAX_ECC_BIT_CNT 8
31+
32+
#define NFC_READ_REG(reg) (reg)
33+
#define NFC_WRITE_REG(reg,data) (reg) = (data)
34+
35+
36+
#define ERR_ECC 12
37+
#define ECC_LIMIT 10
38+
#define ERR_TIMEOUT 14
39+
#define READ_RETRY_MAX_TYPE_NUM 5
40+
#define READ_RETRY_MAX_REG_NUM 16
41+
#define READ_RETRY_MAX_CYCLE 10
42+
#define LSB_MODE_MAX_REG_NUM 8
43+
/* define various unit data input or output*/
44+
#define NFC_READ_RAM_B(ram) (*((volatile __u8 *)(NAND_IO_BASE + ram)))
45+
#define NFC_WRITE_RAM_B(ram,data) (*((volatile __u8 *)(NAND_IO_BASE + ram)) = (data))
46+
#define NFC_READ_RAM_HW(ram) (*((volatile __u16 *)(NAND_IO_BASE + ram)))
47+
#define NFC_WRITE_RAM_HW(ram,data) (*((volatile __u16 *)(NAND_IO_BASE + ram)) = (data))
48+
#define NFC_READ_RAM_W(ram) (*((volatile __u32 *)(NAND_IO_BASE + ram)))
49+
#define NFC_WRITE_RAM_W(ram,data) (*((volatile __u32 *)(NAND_IO_BASE + ram)) = (data))
50+
51+
52+
53+
#ifdef USE_PHYSICAL_ADDRESS
54+
#define NFC_IS_SDRAM(addr) ((addr >= DRAM_BASE)?1:0)
55+
#else
56+
#define NFC_IS_SDRAM(addr) ( ((addr >= DRAM_BASE))&&(addr < SRAM_BASE)?1:0)
57+
#endif
58+
59+
extern __hdle NAND_RequestDMA(__u32 dmatype);
60+
extern __s32 NAND_ReleaseDMA(__hdle hDma);
61+
extern __s32 NAND_QueryDmaStat(__hdle hDma);
62+
extern __s32 NAND_SettingDMA(__hdle hDMA, void * pArg);
63+
extern __s32 NAND_StartDMA(__u8 rw,__hdle hDMA, __u32 saddr, __u32 daddr, __u32 bytes);
64+
extern __s32 NAND_GetPin(void);
65+
extern __s32 NAND_ReleasePin(void);
66+
extern __u32 NAND_GetBoardVersion(void);
67+
extern __s32 NAND_WaitDmaFinish(void);
68+
extern __s32 NAND_DMAEqueueBuf(__hdle hDma, __u32 buff_addr, __u32 len);
69+
extern void NAND_ClearRbInt(void);
70+
extern void NAND_EnRbInt(void);
71+
72+
extern void NAND_RbInterrupt(void);
73+
extern __s32 NAND_WaitRbReady(void);
74+
75+
#endif /* _NFC_I_H_ */
76+

0 commit comments

Comments
 (0)