summaryrefslogtreecommitdiff
path: root/board/wmt/flash/spi_flash.h
blob: e2b873e4042a7e509064ad102759cc3e2a0bd6be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (c) 2006
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * Copyright (c) 2008 WonderMedia Technologies, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software Foundation,
 * either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * WonderMedia Technologies, Inc.
 * 10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
 */

#ifndef __SPI_FLASH_H_
#define __SPI_FLASH_H_

#include <asm/arch/common_def.h>	/* WMT common definitions and macros */
/* GPIO reg */
#define GPIO_BASE_ADDR 0xD8110000
#define GPIO_ENABLE_SF_REG  REG32_PTR(GPIO_BASE_ADDR+0x0)
#define GPIO_STRAPPING_REG  REG32_PTR(GPIO_BASE_ADDR+0x0100)

/* PMC module reg */
#define PMC_BASE_ADDR 0XD8130000
#define PMC_SF_CLK_REG  REG32_PTR(PMC_BASE_ADDR + 0x314)
#define PMC_PLLB_MULTIPLIER_REG  REG32_PTR(PMC_BASE_ADDR + 0x204)
#define PMC_PLLA_MULTIPLIER_REG  REG32_PTR(PMC_BASE_ADDR + 0x200)
#define PMC_PLLC_MULTIPLIER_REG  REG32_PTR(PMC_BASE_ADDR + 0x208)
#define PMC_PLLD_MULTIPLIER_REG  REG32_PTR(PMC_BASE_ADDR + 0x20C)

#define SF_BASE_ADDR 0xD8002000

typedef struct sfreg_s {
	unsigned long volatile     CHIP_SEL_0_CFG ;    /* 0xD8002000 */
	unsigned long volatile     Res1 ;              /* 0x04 */
	unsigned long volatile     CHIP_SEL_1_CFG ;    /* 0xD8002008 */
	unsigned long volatile     Res2[13] ;          /* 0x0C */
	unsigned long volatile     SPI_INTF_CFG ;      /* 0xD8002040 */
	unsigned long volatile     Res3[3] ;           /* 0x44 */
	unsigned long volatile     SPI_RD_WR_CTR ;     /* 0xD8002050 */
	unsigned long volatile     Res4[3] ;           /* 0x54 */
	unsigned long volatile     SPI_WR_EN_CTR ;     /* 0xD8002060 */
	unsigned long volatile     Res5[3] ;           /* 0x64 */
	unsigned long volatile     SPI_ER_CTR ;        /* 0xD8002070 */
	unsigned long volatile     SPI_ER_START_ADDR ; /* 0xD8002074 */
	unsigned long volatile     Res6[2] ;           /* 0x78 */
	unsigned long volatile     SPI_ERROR_STATUS ;  /* 0xD8002080 */
	unsigned long volatile     Res7[31] ;          /* 0x84 */
	unsigned long volatile     SPI_MEM_0_SR_ACC ;  /* 0xD8002100 */
	unsigned long volatile     Res8[3] ;           /* 0x104 */
	unsigned long volatile     SPI_MEM_1_SR_ACC ;  /* 0xD8002110 */
	unsigned long volatile     Res9[27] ;          /* 0x114 */
	unsigned long volatile     SPI_PDWN_CTR_0 ;    /* 0xD8002180 */
	unsigned long volatile     Res10[3] ;          /* 0x184 */
	unsigned long volatile     SPI_PDWN_CTR_1 ;    /* 0xD8002190 */
	unsigned long volatile     Res11[27] ;         /* 0x194 */
	unsigned long volatile     SPI_PROG_CMD_CTR ;  /* 0xD8002200 */
	unsigned long volatile     Res12[3] ;          /* 0x204 */
	unsigned long volatile     SPI_USER_CMD_VAL ;  /* 0xD8002210 */
	unsigned long volatile     Res13[59] ;         /* 0x214 */
	unsigned char volatile     SPI_PROG_CMD_WBF[64] ;  /* 0xD8002300 */
	unsigned long volatile     Res14[16] ;         /* 0x340 */
	unsigned char volatile     SPI_PROG_CMD_RBF[64] ;  /* 0xD8002380 */
} sfreg_t ;

/* Chip select 0-1 configuration register, 0x0 & 0x8 */
#define SF_START_ADDR          0xFF800000 /* [36:16] */
#define SF_MEM_SIZE_8M         0x00000800 /* [11:8] */

/* SPI interface configuration register, 0x40 */
#define SF_PDWN_DELY           0x0  /* [31:28] */
#define SF_RES_DELY            0x0  /* [27:24] */
#define SF_CS_DELY             0x0  /* [18:16] */
#define SF_PROG_CMD_MOD_EN     0x40 /* [6:6] */
#define SF_PROG_CMD_MOD_DIS    0x0  /* [6:6] */
#define SF_USR_WR_CMD_MOD_EN   0x20 /* [5:5] */
#define SF_USR_WR_CMD_MOD_DIS  0x0  /* [5:5] */
#define SF_USR_RD_CMD_MOD_EN   0x10 /* [4:4] */
#define SF_USR_RD_CMD_MOD_DIS  0x0  /* [4:4] */
#define SF_ADDR_WIDTH_24       0x0  /* [0:0] */
#define SF_ADDR_WIDTH_32       0x1  /* [0:0] */
/* SPI flash read/write control register, 0x50 */
#define SF_ID_RD               0x10 /* [4:4] */
#define SF_STATUS_RD           0x0  /* [4:4] */
#define SF_RD_SPD_FAST         0x1  /* [0:0] */
#define SF_RD_SPD_NOR          0x0  /* [0:0] */

/* SPI flash write enable control register, 0x60 */
#define SF_CS1_WR_EN           0x2 /* [1:1] */
#define SF_CS1_WR_DIS          0x0 /* [1:1] */
#define SF_CS0_WR_EN           0x1 /* [0:0] */
#define SF_CS0_WR_DIS          0x0 /* [0:0] */

/* SPI flash erase control register, 0x70 */
#define SF_SEC_ER_EN           0x8000 /* [15:15] */
#define SF_SEC_ER_DIS          0x0 /* [15:15] */
#define SF_CHIP_ER_EN          0x1 /* [0:0] */
#define SF_CHIP_ER_DIS         0x0 /* [0:0] */

/* SPI flash erase start address register, 0x74 */
#define SF_ER_START_ADDR       0x0 /* [31:16] */
#define CHIP_ER_CS1            0x2 /* [1:1] */
#define CHIP_ER_CS0            0x1 /* [0:0] */

/* SPI flash error status register, 0x80 */
#define SF_WR_PROT_ERR         0x20 /* [5:5] */
#define SF_MEM_REGION_ERR      0x10 /* [4:4] */
#define SF_PWR_DWN_ACC_ERR     0x8  /* [3:3] */
#define SF_PCMD_OP_ERR         0x4  /* [2:2] */
#define SF_PCMD_ACC_ERR        0x2  /* [1:1] */
#define SF_MASLOCK_ERR         0x1  /* [0:0] */
/* SPI power down control register, 0x180 & 0x190 */
#define PWR_DWN_EN             0x1 /* [0:0] */
#define PWR_DWN_DIS            0x0 /* [0:0] */
/* SPI programmable command mode control register, 0x200 */
#define SF_TX_DATA_SIZE        0x0 /* MACRO [30:24] */
#define SF_RX_DATA_SIZE        0x0 /* MACRO [22:16] */
#define SF_CMD_CS1             0x2 /* MACRO [1:1] */
#define SF_CMD_CS0             0x0 /* MACRO [1:1] */
#define SF_CMD_EN              0x1 /* [0:0] */
#define SF_CMD_DIS             0x0 /* [0:0] */
/* SPI user command value register, 0x210 */
#define SF_USR_WR_CMD          0x0 /* MACRO [23:16] */
#define SF_USR_RD_CMD          0x0 /* MACRO [7:0] */

unsigned long spi_flash_init(void);
int spi_flash_erase(flash_info_t *info, int s_first, int s_last);
int spi_write_buff(flash_info_t *info, unsigned char *src, unsigned long addr, unsigned long cnt);
void spi_flash_print_info(flash_info_t *info);
#ifdef CFG_FLASH_PROTECTION
int spi_flash_real_protect(flash_info_t *info, long sector, int prot);
int spi_flash_write_status(int chip, int value);
int spi_flash_read_status(int chip, int *value);
#endif

#endif	/* __SPI_FLASH_H_ */