blob: 18f9127a66317710dd5e42e247fffd0d49f961ff [file] [log] [blame]
Linus Walleij6c009ab2010-09-13 00:35:22 +02001/*
2 * incude/mtd/fsmc.h
3 *
4 * ST Microelectronics
5 * Flexible Static Memory Controller (FSMC)
6 * platform data interface and header file
7 *
8 * Copyright © 2010 ST Microelectronics
9 * Vipin Kumar <vipin.kumar@st.com>
10 *
11 * This file is licensed under the terms of the GNU General Public
12 * License version 2. This program is licensed "as is" without any
13 * warranty of any kind, whether express or implied.
14 */
15
16#ifndef __MTD_FSMC_H
17#define __MTD_FSMC_H
18
Viresh Kumar65ab2202010-11-08 11:17:54 +053019#include <linux/io.h>
Linus Walleij6c009ab2010-09-13 00:35:22 +020020#include <linux/platform_device.h>
21#include <linux/mtd/physmap.h>
22#include <linux/types.h>
23#include <linux/mtd/partitions.h>
24#include <asm/param.h>
25
26#define FSMC_NAND_BW8 1
27#define FSMC_NAND_BW16 2
28
Linus Walleij6c009ab2010-09-13 00:35:22 +020029#define FSMC_MAX_NOR_BANKS 4
30#define FSMC_MAX_NAND_BANKS 4
31
32#define FSMC_FLASH_WIDTH8 1
33#define FSMC_FLASH_WIDTH16 2
34
35struct fsmc_nor_bank_regs {
36 uint32_t ctrl;
37 uint32_t ctrl_tim;
38};
39
40/* ctrl register definitions */
41#define BANK_ENABLE (1 << 0)
42#define MUXED (1 << 1)
43#define NOR_DEV (2 << 2)
44#define WIDTH_8 (0 << 4)
45#define WIDTH_16 (1 << 4)
46#define RSTPWRDWN (1 << 6)
47#define WPROT (1 << 7)
48#define WRT_ENABLE (1 << 12)
49#define WAIT_ENB (1 << 13)
50
51/* ctrl_tim register definitions */
52
Linus Walleijb5602e82010-11-29 13:52:27 +010053struct fsmc_nand_bank_regs {
Linus Walleij6c009ab2010-09-13 00:35:22 +020054 uint32_t pc;
55 uint32_t sts;
56 uint32_t comm;
57 uint32_t attrib;
58 uint32_t ioata;
59 uint32_t ecc1;
60 uint32_t ecc2;
61 uint32_t ecc3;
62};
63
64#define FSMC_NOR_REG_SIZE 0x40
65
66struct fsmc_regs {
67 struct fsmc_nor_bank_regs nor_bank_regs[FSMC_MAX_NOR_BANKS];
68 uint8_t reserved_1[0x40 - 0x20];
Linus Walleijb5602e82010-11-29 13:52:27 +010069 struct fsmc_nand_bank_regs bank_regs[FSMC_MAX_NAND_BANKS];
Linus Walleij6c009ab2010-09-13 00:35:22 +020070 uint8_t reserved_2[0xfe0 - 0xc0];
71 uint32_t peripid0; /* 0xfe0 */
72 uint32_t peripid1; /* 0xfe4 */
73 uint32_t peripid2; /* 0xfe8 */
74 uint32_t peripid3; /* 0xfec */
75 uint32_t pcellid0; /* 0xff0 */
76 uint32_t pcellid1; /* 0xff4 */
77 uint32_t pcellid2; /* 0xff8 */
78 uint32_t pcellid3; /* 0xffc */
79};
80
81#define FSMC_BUSY_WAIT_TIMEOUT (1 * HZ)
82
83/* pc register definitions */
84#define FSMC_RESET (1 << 0)
85#define FSMC_WAITON (1 << 1)
86#define FSMC_ENABLE (1 << 2)
87#define FSMC_DEVTYPE_NAND (1 << 3)
88#define FSMC_DEVWID_8 (0 << 4)
89#define FSMC_DEVWID_16 (1 << 4)
90#define FSMC_ECCEN (1 << 6)
91#define FSMC_ECCPLEN_512 (0 << 7)
92#define FSMC_ECCPLEN_256 (1 << 7)
Vipin Kumare2f6bce2012-03-14 11:47:14 +053093#define FSMC_TCLR_1 (1)
94#define FSMC_TCLR_SHIFT (9)
95#define FSMC_TCLR_MASK (0xF)
96#define FSMC_TAR_1 (1)
97#define FSMC_TAR_SHIFT (13)
98#define FSMC_TAR_MASK (0xF)
Linus Walleij6c009ab2010-09-13 00:35:22 +020099
100/* sts register definitions */
101#define FSMC_CODE_RDY (1 << 15)
102
103/* comm register definitions */
Vipin Kumare2f6bce2012-03-14 11:47:14 +0530104#define FSMC_TSET_0 0
105#define FSMC_TSET_SHIFT 0
106#define FSMC_TSET_MASK 0xFF
107#define FSMC_TWAIT_6 6
108#define FSMC_TWAIT_SHIFT 8
109#define FSMC_TWAIT_MASK 0xFF
110#define FSMC_THOLD_4 4
111#define FSMC_THOLD_SHIFT 16
112#define FSMC_THOLD_MASK 0xFF
113#define FSMC_THIZ_1 1
114#define FSMC_THIZ_SHIFT 24
115#define FSMC_THIZ_MASK 0xFF
Linus Walleij6c009ab2010-09-13 00:35:22 +0200116
Linus Walleij6c009ab2010-09-13 00:35:22 +0200117/*
118 * There are 13 bytes of ecc for every 512 byte block in FSMC version 8
119 * and it has to be read consecutively and immediately after the 512
120 * byte data block for hardware to generate the error bit offsets
121 * Managing the ecc bytes in the following way is easier. This way is
122 * similar to oobfree structure maintained already in u-boot nand driver
123 */
124#define MAX_ECCPLACE_ENTRIES 32
125
126struct fsmc_nand_eccplace {
127 uint8_t offset;
128 uint8_t length;
129};
130
131struct fsmc_eccplace {
132 struct fsmc_nand_eccplace eccplace[MAX_ECCPLACE_ENTRIES];
133};
134
Vipin Kumare2f6bce2012-03-14 11:47:14 +0530135struct fsmc_nand_timings {
136 uint8_t tclr;
137 uint8_t tar;
138 uint8_t thiz;
139 uint8_t thold;
140 uint8_t twait;
141 uint8_t tset;
142};
143
Vipin Kumar604e7542012-03-14 11:47:17 +0530144enum access_mode {
145 USE_DMA_ACCESS = 1,
146 USE_WORD_ACCESS,
147};
148
Linus Walleij6c009ab2010-09-13 00:35:22 +0200149/**
150 * fsmc_nand_platform_data - platform specific NAND controller config
151 * @partitions: partition table for the platform, use a default fallback
152 * if this is NULL
153 * @nr_partitions: the number of partitions in the previous entry
154 * @options: different options for the driver
155 * @width: bus width
156 * @bank: default bank
157 * @select_bank: callback to select a certain bank, this is
158 * platform-specific. If the controller only supports one bank
159 * this may be set to NULL
160 */
161struct fsmc_nand_platform_data {
Vipin Kumare2f6bce2012-03-14 11:47:14 +0530162 struct fsmc_nand_timings *nand_timings;
Linus Walleij6c009ab2010-09-13 00:35:22 +0200163 struct mtd_partition *partitions;
164 unsigned int nr_partitions;
165 unsigned int options;
166 unsigned int width;
167 unsigned int bank;
Shiraz Hashimb2acc922012-03-07 17:00:51 +0530168
169 /* CLE, ALE offsets */
170 unsigned long cle_off;
171 unsigned long ale_off;
Vipin Kumar604e7542012-03-14 11:47:17 +0530172 enum access_mode mode;
Shiraz Hashimb2acc922012-03-07 17:00:51 +0530173
Linus Walleij6c009ab2010-09-13 00:35:22 +0200174 void (*select_bank)(uint32_t bank, uint32_t busw);
Vipin Kumar4774fb02012-03-14 11:47:18 +0530175
176 /* priv structures for dma accesses */
177 void *read_dma_priv;
178 void *write_dma_priv;
Linus Walleij6c009ab2010-09-13 00:35:22 +0200179};
180
181extern int __init fsmc_nor_init(struct platform_device *pdev,
182 unsigned long base, uint32_t bank, uint32_t width);
183extern void __init fsmc_init_board_info(struct platform_device *pdev,
184 struct mtd_partition *partitions, unsigned int nr_partitions,
185 unsigned int width);
186
187#endif /* __MTD_FSMC_H */