]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/nand/mxs_gpmi.h
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / drivers / mtd / nand / mxs_gpmi.h
1 /*
2  * Freescale GPMI NFC NAND Flash Driver
3  *
4  * Copyright (C) 2010 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  * 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.
20  */
21
22 #ifndef __DRIVERS_MTD_NAND_GPMI_NFC_H
23 #define __DRIVERS_MTD_NAND_GPMI_NFC_H
24
25 /*
26  *------------------------------------------------------------------------------
27  * Fundamental Macros
28  *------------------------------------------------------------------------------
29  */
30
31 #define  NFC_DMA_DESCRIPTOR_COUNT  4
32
33 /* Define this macro to enable detailed information messages. */
34 #define DETAILED_INFO
35
36 /* Define this macro to enable event reporting. */
37 /*#define EVENT_REPORTING*/
38
39 /*
40  *------------------------------------------------------------------------------
41  * Fundamental Data Structures
42  *------------------------------------------------------------------------------
43  */
44
45 #define COMMAND_BUFFER_SIZE 10
46
47 /**
48  * struct gpmi_nfc_timing - GPMI NFC timing parameters.
49  *
50  * This structure contains the fundamental timing attributes for the NAND Flash
51  * bus and the GPMI NFC hardware.
52  *
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
66  *                             isn't known.
67  * @tRLOH_in_ns:               tRLOH, in nanoseconds, from the data sheet. A
68  *                             negative value indicates this characteristic
69  *                             isn't known.
70  * @tRHOH_in_ns:               tRHOH, in nanoseconds, from the data sheet. A
71  *                             negative value indicates this characteristic
72  *                             isn't known.
73  */
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;
79         int8_t    tREA_in_ns;
80         int8_t    tRLOH_in_ns;
81         int8_t    tRHOH_in_ns;
82 };
83 #if 0
84 enum nand_device_cell_technology {
85         NAND_DEVICE_CELL_TECH_SLC = 0,
86         NAND_DEVICE_CELL_TECH_MLC = 1,
87 };
88
89 struct nand_device_info {
90         /* End of table marker */
91         bool      end_of_table;
92
93         /* Manufacturer and Device codes */
94         uint8_t   manufacturer_code;
95         uint8_t   device_code;
96
97         /* Technology */
98         enum nand_device_cell_technology  cell_technology;
99
100         /* Geometry */
101         uint64_t  chip_size_in_bytes;
102         uint32_t  block_size_in_pages;
103         uint16_t  page_total_size_in_bytes;
104
105         /* ECC */
106         uint8_t   ecc_strength_in_bits;
107         uint16_t  ecc_size_in_bytes;
108
109         /* Timing */
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;
114         int8_t    tREA_in_ns;
115         int8_t    tRLOH_in_ns;
116         int8_t    tRHOH_in_ns;
117
118         /* human readable device description */
119         const char  *description;
120 };
121
122 /**
123  * struct gpmi_nfc_data - i.MX NFC per-device data.
124  *
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.
129  *
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
136  *                       NFC hardware.
137  * @rom:                 A pointer to a structure that represents the underlying
138  *                       Boot ROM.
139  * @mil:                 A collection of information used by the MTD Interface
140  *                       Layer.
141  */
142 struct gpmi_nfc_data {
143         /* System Interface */
144         struct device                  *dev;
145         struct platform_device         *pdev;
146         struct gpmi_nfc_platform_data  *pdata;
147
148         /* Resources */
149         struct clk    *clock;
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;
156
157 //      struct resources               resources;
158
159         /* NFC HAL */
160         /* Hardware attributes. */
161         unsigned int    max_chip_count;
162
163         /* Working variables. */
164         struct mxs_dma_desc     *dma_descriptors[NFC_DMA_DESCRIPTOR_COUNT];
165         int                     isr_dma_channel;
166         struct completion       dma_done;
167         struct completion       bch_done;
168         struct gpmi_nfc_timing  timing;
169 //      struct nfc_hal          *nfc;
170         int                     current_chip;
171
172         /* MTD Interface Layer */
173         struct mtd_info        mtd;
174         struct nand_chip       chip;
175         struct nand_ecclayout  oob_layout;
176         struct mtd_partition   *partitions;
177         unsigned int           partition_count;
178
179         /* DMA Buffers */
180         u8                     *cmd_virt;
181         dma_addr_t             cmd_phys;
182         unsigned int           command_length;
183
184         void                   *page_buffer_virt;
185         dma_addr_t             page_buffer_phys;
186         unsigned int           page_buffer_size;
187
188         void                   *payload_virt;
189         dma_addr_t             payload_phys;
190
191         void                   *auxiliary_virt;
192         dma_addr_t             auxiliary_phys;
193 };
194
195 /**
196  * struct nfc_hal - GPMI NFC HAL
197  *
198  * This structure embodies an abstract interface to the underlying NFC hardware.
199  *
200  * @version:                       The NFC hardware version.
201  * @description:                   A pointer to a human-readable description of
202  *                                 the NFC hardware.
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
221  *                                 interrupts.
222  * @bch_done:                      The completion structure used for BCH
223  *                                 interrupts.
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
232  *                                 hardware.
233  * @set_geometry:                  Configures the NFC hardware and data
234  *                                 structures to match the physical NAND Flash
235  *                                 geometry.
236  * @set_geometry:                  Configures the NFC hardware and data
237  *                                 structures to match the physical NAND Flash
238  *                                 geometry.
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
251  *                                 itself.
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
255  *                                 state.
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
263  *                                 buffers.
264  */
265
266 struct nfc_hal {
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;
274
275         /* Working variables. */
276         struct mxs_dma_desc     *dma_descriptors[NFC_DMA_DESCRIPTOR_COUNT];
277         int                     isr_dma_channel;
278         struct completion       dma_done;
279         struct completion       bch_done;
280         struct gpmi_nfc_timing  timing;
281
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 *);
288
289         /* Call these functions to begin and end I/O. */
290
291         void  (*begin)       (struct gpmi_nfc_data *);
292         void  (*end)         (struct gpmi_nfc_data *);
293
294         /* Call these I/O functions only between begin() and end(). */
295
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);
308 };
309
310 /**
311  * struct boot_rom_helper - Boot ROM Helper
312  *
313  * This structure embodies the interface to an object that assists the driver
314  * in making decisions that relate to the Boot ROM.
315  *
316  * @version:                    The Boot ROM version.
317  * @description:                A pointer to a human-readable description of the
318  *                              Boot ROM.
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.
326  */
327
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 *);
335 };
336
337 /*
338  *------------------------------------------------------------------------------
339  * External Symbols
340  *------------------------------------------------------------------------------
341  */
342
343 /* Event Reporting */
344
345 #if defined(EVENT_REPORTING)
346 #if 0
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);
351 #endif
352 #else
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 */
358
359 #endif /* 0 */
360
361 #endif /* __DRIVERS_MTD_NAND_GPMI_NFC_H */