blob: 8bcf299cb9bff78dca762b66a9ee85e4d9164566 [file] [log] [blame]
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +09001/*
2 * SuperH FLCTL nand controller
3 *
4 * Copyright © 2008 Renesas Solutions Corp.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef __SH_FLCTL_H__
21#define __SH_FLCTL_H__
22
23#include <linux/mtd/mtd.h>
24#include <linux/mtd/nand.h>
25#include <linux/mtd/partitions.h>
26
27/* FLCTL registers */
28#define FLCMNCR(f) (f->reg + 0x0)
29#define FLCMDCR(f) (f->reg + 0x4)
30#define FLCMCDR(f) (f->reg + 0x8)
31#define FLADR(f) (f->reg + 0xC)
32#define FLADR2(f) (f->reg + 0x3C)
33#define FLDATAR(f) (f->reg + 0x10)
34#define FLDTCNTR(f) (f->reg + 0x14)
35#define FLINTDMACR(f) (f->reg + 0x18)
36#define FLBSYTMR(f) (f->reg + 0x1C)
37#define FLBSYCNT(f) (f->reg + 0x20)
38#define FLDTFIFO(f) (f->reg + 0x24)
39#define FLECFIFO(f) (f->reg + 0x28)
40#define FLTRCR(f) (f->reg + 0x2C)
Bastian Hecht3f2e9242012-03-01 10:48:40 +010041#define FLHOLDCR(f) (f->reg + 0x38)
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +090042#define FL4ECCRESULT0(f) (f->reg + 0x80)
43#define FL4ECCRESULT1(f) (f->reg + 0x84)
44#define FL4ECCRESULT2(f) (f->reg + 0x88)
45#define FL4ECCRESULT3(f) (f->reg + 0x8C)
46#define FL4ECCCR(f) (f->reg + 0x90)
47#define FL4ECCCNT(f) (f->reg + 0x94)
48#define FLERRADR(f) (f->reg + 0x98)
49
50/* FLCMNCR control bits */
51#define ECCPOS2 (0x1 << 25)
52#define _4ECCCNTEN (0x1 << 24)
53#define _4ECCEN (0x1 << 23)
54#define _4ECCCORRECT (0x1 << 22)
Magnus Damm010ab822010-01-27 09:17:21 +000055#define SHBUSSEL (0x1 << 20)
56#define SEL_16BIT (0x1 << 19)
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +090057#define SNAND_E (0x1 << 18) /* SNAND (0=512 1=2048)*/
58#define QTSEL_E (0x1 << 17)
59#define ENDIAN (0x1 << 16) /* 1 = little endian */
60#define FCKSEL_E (0x1 << 15)
61#define ECCPOS_00 (0x00 << 12)
62#define ECCPOS_01 (0x01 << 12)
63#define ECCPOS_02 (0x02 << 12)
64#define ACM_SACCES_MODE (0x01 << 10)
65#define NANWF_E (0x1 << 9)
66#define SE_D (0x1 << 8) /* Spare area disable */
67#define CE1_ENABLE (0x1 << 4) /* Chip Enable 1 */
68#define CE0_ENABLE (0x1 << 3) /* Chip Enable 0 */
69#define TYPESEL_SET (0x1 << 0)
70
Bastian Hechtb6a55882012-03-01 10:48:35 +010071/*
72 * Clock settings using the PULSEx registers from FLCMNCR
73 *
74 * Some hardware uses bits called PULSEx instead of FCKSEL_E and QTSEL_E
75 * to control the clock divider used between the High-Speed Peripheral Clock
76 * and the FLCTL internal clock. If so, use CLK_8_BIT_xxx for connecting 8 bit
77 * and CLK_16_BIT_xxx for connecting 16 bit bus bandwith NAND chips. For the 16
78 * bit version the divider is seperate for the pulse width of high and low
79 * signals.
80 */
81#define PULSE3 (0x1 << 27)
82#define PULSE2 (0x1 << 17)
83#define PULSE1 (0x1 << 15)
84#define PULSE0 (0x1 << 9)
85#define CLK_8B_0_5 PULSE1
86#define CLK_8B_1 0x0
87#define CLK_8B_1_5 (PULSE1 | PULSE2)
88#define CLK_8B_2 PULSE0
89#define CLK_8B_3 (PULSE0 | PULSE1 | PULSE2)
90#define CLK_8B_4 (PULSE0 | PULSE2)
91#define CLK_16B_6L_2H PULSE0
92#define CLK_16B_9L_3H (PULSE0 | PULSE1 | PULSE2)
93#define CLK_16B_12L_4H (PULSE0 | PULSE2)
94
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +090095/* FLCMDCR control bits */
96#define ADRCNT2_E (0x1 << 31) /* 5byte address enable */
97#define ADRMD_E (0x1 << 26) /* Sector address access */
98#define CDSRC_E (0x1 << 25) /* Data buffer selection */
99#define DOSR_E (0x1 << 24) /* Status read check */
100#define SELRW (0x1 << 21) /* 0:read 1:write */
101#define DOADR_E (0x1 << 20) /* Address stage execute */
102#define ADRCNT_1 (0x00 << 18) /* Address data bytes: 1byte */
103#define ADRCNT_2 (0x01 << 18) /* Address data bytes: 2byte */
104#define ADRCNT_3 (0x02 << 18) /* Address data bytes: 3byte */
105#define ADRCNT_4 (0x03 << 18) /* Address data bytes: 4byte */
106#define DOCMD2_E (0x1 << 17) /* 2nd cmd stage execute */
107#define DOCMD1_E (0x1 << 16) /* 1st cmd stage execute */
108
109/* FLTRCR control bits */
110#define TRSTRT (0x1 << 0) /* translation start */
111#define TREND (0x1 << 1) /* translation end */
112
Bastian Hecht3f2e9242012-03-01 10:48:40 +0100113/*
114 * FLHOLDCR control bits
115 *
116 * HOLDEN: Bus Occupancy Enable (inverted)
117 * Enable this bit when the external bus might be used in between transfers.
118 * If not set and the bus gets used by other modules, a deadlock occurs.
119 */
120#define HOLDEN (0x1 << 0)
121
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +0900122/* FL4ECCCR control bits */
123#define _4ECCFA (0x1 << 2) /* 4 symbols correct fault */
124#define _4ECCEND (0x1 << 1) /* 4 symbols end */
125#define _4ECCEXST (0x1 << 0) /* 4 symbols exist */
126
127#define INIT_FL4ECCRESULT_VAL 0x03FF03FF
128#define LOOP_TIMEOUT_MAX 0x00010000
129
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +0900130struct sh_flctl {
131 struct mtd_info mtd;
132 struct nand_chip chip;
Magnus Dammb79c7ad2010-02-02 13:01:25 +0900133 struct platform_device *pdev;
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +0900134 void __iomem *reg;
135
136 uint8_t done_buff[2048 + 64]; /* max size 2048 + 64 */
137 int read_bytes;
138 int index;
139 int seqin_column; /* column in SEQIN cmd */
140 int seqin_page_addr; /* page_addr in SEQIN cmd */
141 uint32_t seqin_read_cmd; /* read cmd in SEQIN cmd */
142 int erase1_page_addr; /* page_addr in ERASE1 cmd */
143 uint32_t erase_ADRCNT; /* bits of FLCMDCR in ERASE1 cmd */
144 uint32_t rw_ADRCNT; /* bits of FLCMDCR in READ WRITE cmd */
Bastian Hecht0b3f0d12012-03-01 10:48:39 +0100145 uint32_t flcmncr_base; /* base value of FLCMNCR */
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +0900146
147 int hwecc_cant_correct[4];
148
149 unsigned page_size:1; /* NAND page size (0 = 512, 1 = 2048) */
150 unsigned hwecc:1; /* Hardware ECC (0 = disabled, 1 = enabled) */
Bastian Hecht3f2e9242012-03-01 10:48:40 +0100151 unsigned holden:1; /* Hardware has FLHOLDCR and HOLDEN is set */
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +0900152};
153
154struct sh_flctl_platform_data {
155 struct mtd_partition *parts;
156 int nr_parts;
157 unsigned long flcmncr_val;
158
159 unsigned has_hwecc:1;
Bastian Hecht3f2e9242012-03-01 10:48:40 +0100160 unsigned use_holden:1;
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +0900161};
162
Peter Huewe1cd26202010-05-13 00:06:54 +0200163static inline struct sh_flctl *mtd_to_flctl(struct mtd_info *mtdinfo)
164{
165 return container_of(mtdinfo, struct sh_flctl, mtd);
166}
167
Yoshihiro Shimoda6028aa02008-10-14 21:23:26 +0900168#endif /* __SH_FLCTL_H__ */