blob: 5c11e761a32e6b3aa3307954aaad173ebd1b4ac9 [file] [log] [blame]
Huang Shijie10a2bca2011-09-08 10:47:09 +08001/*
2 * Freescale GPMI NAND Flash Driver
3 *
4 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
5 * Copyright (C) 2008 Embedded Alley Solutions, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (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#ifndef __DRIVERS_MTD_NAND_GPMI_NAND_H
18#define __DRIVERS_MTD_NAND_GPMI_NAND_H
19
20#include <linux/mtd/nand.h>
21#include <linux/platform_device.h>
22#include <linux/dma-mapping.h>
Huang Shijie39468602012-02-16 14:17:32 +080023#include <linux/fsl/mxs-dma.h>
Huang Shijie10a2bca2011-09-08 10:47:09 +080024
Huang Shijieff506172012-07-02 21:39:32 -040025#define GPMI_CLK_MAX 5 /* MX6Q needs five clocks */
Huang Shijie10a2bca2011-09-08 10:47:09 +080026struct resources {
Huang Shijie513d57e2012-07-17 14:14:02 +080027 void __iomem *gpmi_regs;
28 void __iomem *bch_regs;
Huang Shijie10a2bca2011-09-08 10:47:09 +080029 unsigned int bch_low_interrupt;
30 unsigned int bch_high_interrupt;
31 unsigned int dma_low_channel;
32 unsigned int dma_high_channel;
Huang Shijieff506172012-07-02 21:39:32 -040033 struct clk *clock[GPMI_CLK_MAX];
Huang Shijie10a2bca2011-09-08 10:47:09 +080034};
35
36/**
37 * struct bch_geometry - BCH geometry description.
38 * @gf_len: The length of Galois Field. (e.g., 13 or 14)
39 * @ecc_strength: A number that describes the strength of the ECC
40 * algorithm.
41 * @page_size: The size, in bytes, of a physical page, including
42 * both data and OOB.
43 * @metadata_size: The size, in bytes, of the metadata.
44 * @ecc_chunk_size: The size, in bytes, of a single ECC chunk. Note
45 * the first chunk in the page includes both data and
46 * metadata, so it's a bit larger than this value.
47 * @ecc_chunk_count: The number of ECC chunks in the page,
48 * @payload_size: The size, in bytes, of the payload buffer.
49 * @auxiliary_size: The size, in bytes, of the auxiliary buffer.
50 * @auxiliary_status_offset: The offset into the auxiliary buffer at which
51 * the ECC status appears.
52 * @block_mark_byte_offset: The byte offset in the ECC-based page view at
53 * which the underlying physical block mark appears.
54 * @block_mark_bit_offset: The bit offset into the ECC-based page view at
55 * which the underlying physical block mark appears.
56 */
57struct bch_geometry {
58 unsigned int gf_len;
59 unsigned int ecc_strength;
60 unsigned int page_size;
61 unsigned int metadata_size;
62 unsigned int ecc_chunk_size;
63 unsigned int ecc_chunk_count;
64 unsigned int payload_size;
65 unsigned int auxiliary_size;
66 unsigned int auxiliary_status_offset;
67 unsigned int block_mark_byte_offset;
68 unsigned int block_mark_bit_offset;
69};
70
71/**
72 * struct boot_rom_geometry - Boot ROM geometry description.
73 * @stride_size_in_pages: The size of a boot block stride, in pages.
74 * @search_area_stride_exponent: The logarithm to base 2 of the size of a
75 * search area in boot block strides.
76 */
77struct boot_rom_geometry {
78 unsigned int stride_size_in_pages;
79 unsigned int search_area_stride_exponent;
80};
81
82/* DMA operations types */
83enum dma_ops_type {
84 DMA_FOR_COMMAND = 1,
85 DMA_FOR_READ_DATA,
86 DMA_FOR_WRITE_DATA,
87 DMA_FOR_READ_ECC_PAGE,
88 DMA_FOR_WRITE_ECC_PAGE
89};
90
91/**
92 * struct nand_timing - Fundamental timing attributes for NAND.
93 * @data_setup_in_ns: The data setup time, in nanoseconds. Usually the
94 * maximum of tDS and tWP. A negative value
95 * indicates this characteristic isn't known.
96 * @data_hold_in_ns: The data hold time, in nanoseconds. Usually the
97 * maximum of tDH, tWH and tREH. A negative value
98 * indicates this characteristic isn't known.
99 * @address_setup_in_ns: The address setup time, in nanoseconds. Usually
100 * the maximum of tCLS, tCS and tALS. A negative
101 * value indicates this characteristic isn't known.
102 * @gpmi_sample_delay_in_ns: A GPMI-specific timing parameter. A negative value
103 * indicates this characteristic isn't known.
104 * @tREA_in_ns: tREA, in nanoseconds, from the data sheet. A
105 * negative value indicates this characteristic isn't
106 * known.
107 * @tRLOH_in_ns: tRLOH, in nanoseconds, from the data sheet. A
108 * negative value indicates this characteristic isn't
109 * known.
110 * @tRHOH_in_ns: tRHOH, in nanoseconds, from the data sheet. A
111 * negative value indicates this characteristic isn't
112 * known.
113 */
114struct nand_timing {
115 int8_t data_setup_in_ns;
116 int8_t data_hold_in_ns;
117 int8_t address_setup_in_ns;
118 int8_t gpmi_sample_delay_in_ns;
119 int8_t tREA_in_ns;
120 int8_t tRLOH_in_ns;
121 int8_t tRHOH_in_ns;
122};
123
124struct gpmi_nand_data {
125 /* System Interface */
126 struct device *dev;
127 struct platform_device *pdev;
128 struct gpmi_nand_platform_data *pdata;
129
130 /* Resources */
131 struct resources resources;
132
133 /* Flash Hardware */
134 struct nand_timing timing;
135
136 /* BCH */
137 struct bch_geometry bch_geometry;
138 struct completion bch_done;
139
140 /* NAND Boot issue */
141 bool swap_block_mark;
142 struct boot_rom_geometry rom_geometry;
143
144 /* MTD / NAND */
145 struct nand_chip nand;
146 struct mtd_info mtd;
147
148 /* General-use Variables */
149 int current_chip;
150 unsigned int command_length;
151
152 /* passed from upper layer */
153 uint8_t *upper_buf;
154 int upper_len;
155
156 /* for DMA operations */
157 bool direct_dma_map_ok;
158
159 struct scatterlist cmd_sgl;
160 char *cmd_buffer;
161
162 struct scatterlist data_sgl;
163 char *data_buffer_dma;
164
165 void *page_buffer_virt;
166 dma_addr_t page_buffer_phys;
167 unsigned int page_buffer_size;
168
169 void *payload_virt;
170 dma_addr_t payload_phys;
171
172 void *auxiliary_virt;
173 dma_addr_t auxiliary_phys;
174
175 /* DMA channels */
176#define DMA_CHANS 8
177 struct dma_chan *dma_chans[DMA_CHANS];
178 struct mxs_dma_data dma_data;
179 enum dma_ops_type last_dma_type;
180 enum dma_ops_type dma_type;
181 struct completion dma_done;
182
183 /* private */
184 void *private;
185};
186
187/**
188 * struct gpmi_nfc_hardware_timing - GPMI hardware timing parameters.
189 * @data_setup_in_cycles: The data setup time, in cycles.
190 * @data_hold_in_cycles: The data hold time, in cycles.
191 * @address_setup_in_cycles: The address setup time, in cycles.
Huang Shijieddab3832012-09-13 14:57:54 +0800192 * @device_busy_timeout: The timeout waiting for NAND Ready/Busy,
193 * this value is the number of cycles multiplied
194 * by 4096.
Huang Shijie10a2bca2011-09-08 10:47:09 +0800195 * @use_half_periods: Indicates the clock is running slowly, so the
196 * NFC DLL should use half-periods.
197 * @sample_delay_factor: The sample delay factor.
Huang Shijied37e02d2012-09-13 14:57:56 +0800198 * @wrn_dly_sel: The delay on the GPMI write strobe.
Huang Shijie10a2bca2011-09-08 10:47:09 +0800199 */
200struct gpmi_nfc_hardware_timing {
Huang Shijieddab3832012-09-13 14:57:54 +0800201 /* for HW_GPMI_TIMING0 */
Huang Shijie10a2bca2011-09-08 10:47:09 +0800202 uint8_t data_setup_in_cycles;
203 uint8_t data_hold_in_cycles;
204 uint8_t address_setup_in_cycles;
Huang Shijieddab3832012-09-13 14:57:54 +0800205
206 /* for HW_GPMI_TIMING1 */
207 uint16_t device_busy_timeout;
208#define GPMI_DEFAULT_BUSY_TIMEOUT 0x500 /* default busy timeout value.*/
209
210 /* for HW_GPMI_CTRL1 */
Huang Shijie10a2bca2011-09-08 10:47:09 +0800211 bool use_half_periods;
212 uint8_t sample_delay_factor;
Huang Shijied37e02d2012-09-13 14:57:56 +0800213 uint8_t wrn_dly_sel;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800214};
215
216/**
217 * struct timing_threshod - Timing threshold
218 * @max_data_setup_cycles: The maximum number of data setup cycles that
219 * can be expressed in the hardware.
220 * @internal_data_setup_in_ns: The time, in ns, that the NFC hardware requires
221 * for data read internal setup. In the Reference
222 * Manual, see the chapter "High-Speed NAND
223 * Timing" for more details.
224 * @max_sample_delay_factor: The maximum sample delay factor that can be
225 * expressed in the hardware.
226 * @max_dll_clock_period_in_ns: The maximum period of the GPMI clock that the
227 * sample delay DLL hardware can possibly work
228 * with (the DLL is unusable with longer periods).
229 * If the full-cycle period is greater than HALF
230 * this value, the DLL must be configured to use
231 * half-periods.
232 * @max_dll_delay_in_ns: The maximum amount of delay, in ns, that the
233 * DLL can implement.
234 * @clock_frequency_in_hz: The clock frequency, in Hz, during the current
235 * I/O transaction. If no I/O transaction is in
236 * progress, this is the clock frequency during
237 * the most recent I/O transaction.
238 */
239struct timing_threshod {
240 const unsigned int max_chip_count;
241 const unsigned int max_data_setup_cycles;
242 const unsigned int internal_data_setup_in_ns;
243 const unsigned int max_sample_delay_factor;
244 const unsigned int max_dll_clock_period_in_ns;
245 const unsigned int max_dll_delay_in_ns;
246 unsigned long clock_frequency_in_hz;
247
248};
249
250/* Common Services */
251extern int common_nfc_set_geometry(struct gpmi_nand_data *);
252extern struct dma_chan *get_dma_chan(struct gpmi_nand_data *);
253extern void prepare_data_dma(struct gpmi_nand_data *,
254 enum dma_data_direction dr);
255extern int start_dma_without_bch_irq(struct gpmi_nand_data *,
256 struct dma_async_tx_descriptor *);
257extern int start_dma_with_bch_irq(struct gpmi_nand_data *,
258 struct dma_async_tx_descriptor *);
259
260/* GPMI-NAND helper function library */
261extern int gpmi_init(struct gpmi_nand_data *);
262extern void gpmi_clear_bch(struct gpmi_nand_data *);
263extern void gpmi_dump_info(struct gpmi_nand_data *);
264extern int bch_set_geometry(struct gpmi_nand_data *);
265extern int gpmi_is_ready(struct gpmi_nand_data *, unsigned chip);
266extern int gpmi_send_command(struct gpmi_nand_data *);
267extern void gpmi_begin(struct gpmi_nand_data *);
268extern void gpmi_end(struct gpmi_nand_data *);
269extern int gpmi_read_data(struct gpmi_nand_data *);
270extern int gpmi_send_data(struct gpmi_nand_data *);
271extern int gpmi_send_page(struct gpmi_nand_data *,
272 dma_addr_t payload, dma_addr_t auxiliary);
273extern int gpmi_read_page(struct gpmi_nand_data *,
274 dma_addr_t payload, dma_addr_t auxiliary);
275
276/* BCH : Status Block Completion Codes */
277#define STATUS_GOOD 0x00
278#define STATUS_ERASED 0xff
279#define STATUS_UNCORRECTABLE 0xfe
280
281/* Use the platform_id to distinguish different Archs. */
Huang Shijiee10db1f2012-05-04 21:42:05 -0400282#define IS_MX23 0x0
283#define IS_MX28 0x1
Huang Shijie9013bb42012-05-04 21:42:06 -0400284#define IS_MX6Q 0x2
Huang Shijie10a2bca2011-09-08 10:47:09 +0800285#define GPMI_IS_MX23(x) ((x)->pdev->id_entry->driver_data == IS_MX23)
286#define GPMI_IS_MX28(x) ((x)->pdev->id_entry->driver_data == IS_MX28)
Huang Shijie9013bb42012-05-04 21:42:06 -0400287#define GPMI_IS_MX6Q(x) ((x)->pdev->id_entry->driver_data == IS_MX6Q)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800288#endif