2 * Freescale GPMI NFC NAND Flash Driver
4 * Copyright (C) 2010 Freescale Semiconductor, Inc.
5 * Copyright (C) 2008 Embedded Alley Solutions, Inc.
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.
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef __DRIVERS_MTD_NAND_GPMI_NFC_H
23 #define __DRIVERS_MTD_NAND_GPMI_NFC_H
26 *------------------------------------------------------------------------------
28 *------------------------------------------------------------------------------
31 #define NFC_DMA_DESCRIPTOR_COUNT 4
33 /* Define this macro to enable detailed information messages. */
36 /* Define this macro to enable event reporting. */
37 /*#define EVENT_REPORTING*/
40 *------------------------------------------------------------------------------
41 * Fundamental Data Structures
42 *------------------------------------------------------------------------------
45 #define COMMAND_BUFFER_SIZE 10
48 * struct gpmi_nfc_timing - GPMI NFC timing parameters.
50 * This structure contains the fundamental timing attributes for the NAND Flash
51 * bus and the GPMI NFC hardware.
53 * @data_setup_in_ns: The data setup time, in nanoseconds. Usually the
54 * maximum of tDS and tWP. A negative value
55 * indicates this characteristic isn't known.
56 * @data_hold_in_ns: The data hold time, in nanoseconds. Usually the
57 * maximum of tDH, tWH and tREH. A negative value
58 * indicates this characteristic isn't known.
59 * @address_setup_in_ns: The address setup time, in nanoseconds. Usually
60 * the maximum of tCLS, tCS and tALS. A negative
61 * value indicates this characteristic isn't known.
62 * @gpmi_sample_time_in_ns: A GPMI-specific timing parameter. A negative
63 * value indicates this characteristic isn't known.
64 * @tREA_in_ns: tREA, in nanoseconds, from the data sheet. A
65 * negative value indicates this characteristic
67 * @tRLOH_in_ns: tRLOH, in nanoseconds, from the data sheet. A
68 * negative value indicates this characteristic
70 * @tRHOH_in_ns: tRHOH, in nanoseconds, from the data sheet. A
71 * negative value indicates this characteristic
74 struct gpmi_nfc_timing {
75 int8_t data_setup_in_ns;
76 int8_t data_hold_in_ns;
77 int8_t address_setup_in_ns;
78 int8_t gpmi_sample_delay_in_ns;
84 enum nand_device_cell_technology {
85 NAND_DEVICE_CELL_TECH_SLC = 0,
86 NAND_DEVICE_CELL_TECH_MLC = 1,
89 struct nand_device_info {
90 /* End of table marker */
93 /* Manufacturer and Device codes */
94 uint8_t manufacturer_code;
98 enum nand_device_cell_technology cell_technology;
101 uint64_t chip_size_in_bytes;
102 uint32_t block_size_in_pages;
103 uint16_t page_total_size_in_bytes;
106 uint8_t ecc_strength_in_bits;
107 uint16_t ecc_size_in_bytes;
110 int8_t data_setup_in_ns;
111 int8_t data_hold_in_ns;
112 int8_t address_setup_in_ns;
113 int8_t gpmi_sample_delay_in_ns;
118 /* human readable device description */
119 const char *description;
123 * struct gpmi_nfc_data - i.MX NFC per-device data.
125 * Note that the "device" managed by this driver represents the NAND Flash
126 * controller *and* the NAND Flash medium behind it. Thus, the per-device data
127 * structure has information about the controller, the chips to which it is
128 * connected, and properties of the medium as a whole.
130 * @dev: A pointer to the owning struct device.
131 * @pdev: A pointer to the owning struct platform_device.
132 * @pdata: A pointer to the device's platform data.
133 * @device_info: A structure that contains detailed information about
134 * the NAND Flash device.
135 * @nfc: A pointer to a structure that represents the underlying
137 * @rom: A pointer to a structure that represents the underlying
139 * @mil: A collection of information used by the MTD Interface
142 struct gpmi_nfc_data {
143 /* System Interface */
145 struct platform_device *pdev;
146 struct gpmi_nfc_platform_data *pdata;
150 void __iomem *gpmi_regs;
151 void __iomem *bch_regs;
152 unsigned int bch_interrupt;
153 unsigned int dma_low_channel;
154 unsigned int dma_high_channel;
155 unsigned int dma_interrupt;
157 // struct resources resources;
160 /* Hardware attributes. */
161 unsigned int max_chip_count;
163 /* Working variables. */
164 struct mxs_dma_desc *dma_descriptors[NFC_DMA_DESCRIPTOR_COUNT];
166 struct completion dma_done;
167 struct completion bch_done;
168 struct gpmi_nfc_timing timing;
169 // struct nfc_hal *nfc;
172 /* MTD Interface Layer */
174 struct nand_chip chip;
175 struct nand_ecclayout oob_layout;
176 struct mtd_partition *partitions;
177 unsigned int partition_count;
182 unsigned int command_length;
184 void *page_buffer_virt;
185 dma_addr_t page_buffer_phys;
186 unsigned int page_buffer_size;
189 dma_addr_t payload_phys;
191 void *auxiliary_virt;
192 dma_addr_t auxiliary_phys;
196 * struct nfc_hal - GPMI NFC HAL
198 * This structure embodies an abstract interface to the underlying NFC hardware.
200 * @version: The NFC hardware version.
201 * @description: A pointer to a human-readable description of
203 * @max_chip_count: The maximum number of chips the NFC can
204 * possibly support (this value is a constant
205 * for each NFC version). This may *not* be the
206 * actual number of chips connected.
207 * @max_data_setup_cycles: The maximum number of data setup cycles
208 * that can be expressed in the hardware.
209 * @max_data_sample_delay_cycles: The maximum number of data sample delay
210 * cycles that can be expressed in the hardware.
211 * @max_dll_clock_period_in_ns: The maximum period of the GPMI clock that the
212 * sample delay DLL hardware can possibly work
213 * with (the DLL is unusable with longer
214 * periods). At HALF this value, the DLL must be
215 * configured to use half-periods.
216 * @dma_descriptors: A pool of DMA descriptors.
217 * @isr_dma_channel: The DMA channel with which the NFC HAL is
218 * working. We record this here so the ISR knows
219 * which DMA channel to acknowledge.
220 * @dma_done: The completion structure used for DMA
222 * @bch_done: The completion structure used for BCH
224 * @timing: The current timing configuration.
225 * @init: Initializes the NFC hardware and data
226 * structures. This function will be called
227 * after everything has been set up for
228 * communication with the NFC itself, but before
229 * the platform has set up off-chip
230 * communication. Thus, this function must not
231 * attempt to communicate with the NAND Flash
233 * @set_geometry: Configures the NFC hardware and data
234 * structures to match the physical NAND Flash
236 * @set_geometry: Configures the NFC hardware and data
237 * structures to match the physical NAND Flash
239 * @exit: Shuts down the NFC hardware and data
240 * structures. This function will be called
241 * after the platform has shut down off-chip
242 * communication but while communication with
243 * the NFC itself still works.
244 * @clear_bch: Clears a BCH interrupt (intended to be called
245 * by a more general interrupt handler to do
246 * device-specific clearing).
247 * @is_ready: Returns true if the given chip is ready.
248 * @begin: Begins an interaction with the NFC. This
249 * function must be called before *any* of the
250 * following functions so the NFC can prepare
252 * @end: Ends interaction with the NFC. This function
253 * should be called to give the NFC a chance to,
254 * among other things, enter a lower-power
256 * @send_command: Sends the given buffer of command bytes.
257 * @send_data: Sends the given buffer of data bytes.
258 * @read_data: Reads data bytes into the given buffer.
259 * @send_page: Sends the given given data and OOB bytes,
260 * using the ECC engine.
261 * @read_page: Reads a page through the ECC engine and
262 * delivers the data and OOB bytes to the given
267 /* Hardware attributes. */
268 const unsigned int version;
269 const char *description;
270 const unsigned int max_chip_count;
271 const unsigned int max_data_setup_cycles;
272 const unsigned int max_data_sample_delay_cycles;
273 const unsigned int max_dll_clock_period_in_ns;
275 /* Working variables. */
276 struct mxs_dma_desc *dma_descriptors[NFC_DMA_DESCRIPTOR_COUNT];
278 struct completion dma_done;
279 struct completion bch_done;
280 struct gpmi_nfc_timing timing;
282 /* Configuration functions. */
283 int (*init) (struct gpmi_nfc_data *);
284 int (*set_geometry)(struct gpmi_nfc_data *);
285 int (*set_timing) (struct gpmi_nfc_data *,
286 const struct gpmi_nfc_timing *);
287 void (*exit) (struct gpmi_nfc_data *);
289 /* Call these functions to begin and end I/O. */
291 void (*begin) (struct gpmi_nfc_data *);
292 void (*end) (struct gpmi_nfc_data *);
294 /* Call these I/O functions only between begin() and end(). */
296 void (*clear_bch) (struct gpmi_nfc_data *);
297 int (*is_ready) (struct gpmi_nfc_data *, unsigned chip);
298 int (*send_command)(struct gpmi_nfc_data *, unsigned chip,
299 dma_addr_t buffer, unsigned length);
300 int (*send_data) (struct gpmi_nfc_data *, unsigned chip,
301 dma_addr_t buffer, unsigned length);
302 int (*read_data) (struct gpmi_nfc_data *, unsigned chip,
303 dma_addr_t buffer, unsigned length);
304 int (*send_page) (struct gpmi_nfc_data *, unsigned chip,
305 dma_addr_t payload, dma_addr_t auxiliary);
306 int (*read_page) (struct gpmi_nfc_data *, unsigned chip,
307 dma_addr_t payload, dma_addr_t auxiliary);
311 * struct boot_rom_helper - Boot ROM Helper
313 * This structure embodies the interface to an object that assists the driver
314 * in making decisions that relate to the Boot ROM.
316 * @version: The Boot ROM version.
317 * @description: A pointer to a human-readable description of the
319 * @swap_block_mark: Indicates that the Boot ROM will swap the block
320 * mark with the first byte of the OOB.
321 * @set_geometry: Configures the Boot ROM geometry.
322 * @check_transcription_stamp: Checks for a transcription stamp. This pointer
323 * is ignored if swap_block_mark is set.
324 * @write_transcription_stamp: Writes a transcription stamp. This pointer
325 * is ignored if swap_block_mark is set.
328 struct boot_rom_helper {
329 const unsigned int version;
330 const char *description;
331 const int swap_block_mark;
332 int (*set_geometry) (struct gpmi_nfc_data *);
333 int (*check_transcription_stamp)(struct gpmi_nfc_data *);
334 int (*write_transcription_stamp)(struct gpmi_nfc_data *);
338 *------------------------------------------------------------------------------
340 *------------------------------------------------------------------------------
343 /* Event Reporting */
345 #if defined(EVENT_REPORTING)
347 extern void gpmi_nfc_start_event_trace(char *description);
348 extern void gpmi_nfc_add_event(char *description, int delta);
349 extern void gpmi_nfc_stop_event_trace(char *description);
350 extern void gpmi_nfc_dump_event_trace(void);
353 #define gpmi_nfc_start_event_trace(description) do {} while (0)
354 #define gpmi_nfc_add_event(description, delta) do {} while (0)
355 #define gpmi_nfc_stop_event_trace(description) do {} while (0)
356 #define gpmi_nfc_dump_event_trace() do {} while (0)
357 #endif /* EVENT_REPORTING */
361 #endif /* __DRIVERS_MTD_NAND_GPMI_NFC_H */