blob: 717881a3d1b88cc64ad87e12fe0a0d68716254b5 [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 * 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 */
Fabio Estevam3d100952012-09-05 10:27:33 -030021
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Huang Shijie10a2bca2011-09-08 10:47:09 +080024#include <linux/clk.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
Wolfram Sangdf16c862011-11-23 15:57:06 +010027#include <linux/module.h>
Huang Shijie10a2bca2011-09-08 10:47:09 +080028#include <linux/mtd/partitions.h>
Shawn Guo39febc02012-05-06 22:57:41 +080029#include <linux/pinctrl/consumer.h>
Huang Shijiee10db1f2012-05-04 21:42:05 -040030#include <linux/of.h>
31#include <linux/of_device.h>
Huang Shijiec50c6942012-07-03 16:24:32 +080032#include <linux/of_mtd.h>
Huang Shijie10a2bca2011-09-08 10:47:09 +080033#include "gpmi-nand.h"
34
Huang Shijie5de0b522012-10-13 13:03:29 -040035/* Resource names for the GPMI NAND driver. */
36#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME "gpmi-nand"
37#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME "bch"
38#define GPMI_NAND_BCH_INTERRUPT_RES_NAME "bch"
39#define GPMI_NAND_DMA_INTERRUPT_RES_NAME "gpmi-dma"
40
Huang Shijie10a2bca2011-09-08 10:47:09 +080041/* add our owner bbt descriptor */
42static uint8_t scan_ff_pattern[] = { 0xff };
43static struct nand_bbt_descr gpmi_bbt_descr = {
44 .options = 0,
45 .offs = 0,
46 .len = 1,
47 .pattern = scan_ff_pattern
48};
49
50/* We will use all the (page + OOB). */
51static struct nand_ecclayout gpmi_hw_ecclayout = {
52 .eccbytes = 0,
53 .eccpos = { 0, },
54 .oobfree = { {.offset = 0, .length = 0} }
55};
56
57static irqreturn_t bch_irq(int irq, void *cookie)
58{
59 struct gpmi_nand_data *this = cookie;
60
61 gpmi_clear_bch(this);
62 complete(&this->bch_done);
63 return IRQ_HANDLED;
64}
65
66/*
67 * Calculate the ECC strength by hand:
68 * E : The ECC strength.
69 * G : the length of Galois Field.
70 * N : The chunk count of per page.
71 * O : the oobsize of the NAND chip.
72 * M : the metasize of per page.
73 *
74 * The formula is :
75 * E * G * N
76 * ------------ <= (O - M)
77 * 8
78 *
79 * So, we get E by:
80 * (O - M) * 8
81 * E <= -------------
82 * G * N
83 */
84static inline int get_ecc_strength(struct gpmi_nand_data *this)
85{
86 struct bch_geometry *geo = &this->bch_geometry;
87 struct mtd_info *mtd = &this->mtd;
88 int ecc_strength;
89
90 ecc_strength = ((mtd->oobsize - geo->metadata_size) * 8)
91 / (geo->gf_len * geo->ecc_chunk_count);
92
93 /* We need the minor even number. */
94 return round_down(ecc_strength, 2);
95}
96
Huang Shijie92d0e092013-01-29 09:23:38 +080097static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
98{
99 struct bch_geometry *geo = &this->bch_geometry;
100
101 /* Do the sanity check. */
102 if (GPMI_IS_MX23(this) || GPMI_IS_MX28(this)) {
103 /* The mx23/mx28 only support the GF13. */
104 if (geo->gf_len == 14)
105 return false;
106
107 if (geo->ecc_strength > MXS_ECC_STRENGTH_MAX)
108 return false;
109 } else if (GPMI_IS_MX6Q(this)) {
110 if (geo->ecc_strength > MX6_ECC_STRENGTH_MAX)
111 return false;
112 }
113 return true;
114}
115
Huang Shijie10a2bca2011-09-08 10:47:09 +0800116int common_nfc_set_geometry(struct gpmi_nand_data *this)
117{
118 struct bch_geometry *geo = &this->bch_geometry;
119 struct mtd_info *mtd = &this->mtd;
120 unsigned int metadata_size;
121 unsigned int status_size;
122 unsigned int block_mark_bit_offset;
123
124 /*
125 * The size of the metadata can be changed, though we set it to 10
126 * bytes now. But it can't be too large, because we have to save
127 * enough space for BCH.
128 */
129 geo->metadata_size = 10;
130
131 /* The default for the length of Galois Field. */
132 geo->gf_len = 13;
133
Huang Shijie9ff16f02013-01-25 14:04:07 +0800134 /* The default for chunk size. */
Huang Shijie10a2bca2011-09-08 10:47:09 +0800135 geo->ecc_chunk_size = 512;
Huang Shijie9ff16f02013-01-25 14:04:07 +0800136 while (geo->ecc_chunk_size < mtd->oobsize) {
Huang Shijie10a2bca2011-09-08 10:47:09 +0800137 geo->ecc_chunk_size *= 2; /* keep C >= O */
Huang Shijie9ff16f02013-01-25 14:04:07 +0800138 geo->gf_len = 14;
139 }
Huang Shijie10a2bca2011-09-08 10:47:09 +0800140
141 geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size;
142
143 /* We use the same ECC strength for all chunks. */
144 geo->ecc_strength = get_ecc_strength(this);
Huang Shijie92d0e092013-01-29 09:23:38 +0800145 if (!gpmi_check_ecc(this)) {
146 dev_err(this->dev,
147 "We can not support this nand chip."
148 " Its required ecc strength(%d) is beyond our"
149 " capability(%d).\n", geo->ecc_strength,
150 (GPMI_IS_MX6Q(this) ? MX6_ECC_STRENGTH_MAX
151 : MXS_ECC_STRENGTH_MAX));
Huang Shijie10a2bca2011-09-08 10:47:09 +0800152 return -EINVAL;
153 }
154
155 geo->page_size = mtd->writesize + mtd->oobsize;
156 geo->payload_size = mtd->writesize;
157
158 /*
159 * The auxiliary buffer contains the metadata and the ECC status. The
160 * metadata is padded to the nearest 32-bit boundary. The ECC status
161 * contains one byte for every ECC chunk, and is also padded to the
162 * nearest 32-bit boundary.
163 */
164 metadata_size = ALIGN(geo->metadata_size, 4);
165 status_size = ALIGN(geo->ecc_chunk_count, 4);
166
167 geo->auxiliary_size = metadata_size + status_size;
168 geo->auxiliary_status_offset = metadata_size;
169
170 if (!this->swap_block_mark)
171 return 0;
172
173 /*
174 * We need to compute the byte and bit offsets of
175 * the physical block mark within the ECC-based view of the page.
176 *
177 * NAND chip with 2K page shows below:
178 * (Block Mark)
179 * | |
180 * | D |
181 * |<---->|
182 * V V
183 * +---+----------+-+----------+-+----------+-+----------+-+
184 * | M | data |E| data |E| data |E| data |E|
185 * +---+----------+-+----------+-+----------+-+----------+-+
186 *
187 * The position of block mark moves forward in the ECC-based view
188 * of page, and the delta is:
189 *
190 * E * G * (N - 1)
191 * D = (---------------- + M)
192 * 8
193 *
194 * With the formula to compute the ECC strength, and the condition
195 * : C >= O (C is the ecc chunk size)
196 *
197 * It's easy to deduce to the following result:
198 *
199 * E * G (O - M) C - M C - M
200 * ----------- <= ------- <= -------- < ---------
201 * 8 N N (N - 1)
202 *
203 * So, we get:
204 *
205 * E * G * (N - 1)
206 * D = (---------------- + M) < C
207 * 8
208 *
209 * The above inequality means the position of block mark
210 * within the ECC-based view of the page is still in the data chunk,
211 * and it's NOT in the ECC bits of the chunk.
212 *
213 * Use the following to compute the bit position of the
214 * physical block mark within the ECC-based view of the page:
215 * (page_size - D) * 8
216 *
217 * --Huang Shijie
218 */
219 block_mark_bit_offset = mtd->writesize * 8 -
220 (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - 1)
221 + geo->metadata_size * 8);
222
223 geo->block_mark_byte_offset = block_mark_bit_offset / 8;
224 geo->block_mark_bit_offset = block_mark_bit_offset % 8;
225 return 0;
226}
227
228struct dma_chan *get_dma_chan(struct gpmi_nand_data *this)
229{
230 int chipnr = this->current_chip;
231
232 return this->dma_chans[chipnr];
233}
234
235/* Can we use the upper's buffer directly for DMA? */
236void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
237{
238 struct scatterlist *sgl = &this->data_sgl;
239 int ret;
240
241 this->direct_dma_map_ok = true;
242
243 /* first try to map the upper buffer directly */
244 sg_init_one(sgl, this->upper_buf, this->upper_len);
245 ret = dma_map_sg(this->dev, sgl, 1, dr);
246 if (ret == 0) {
247 /* We have to use our own DMA buffer. */
248 sg_init_one(sgl, this->data_buffer_dma, PAGE_SIZE);
249
250 if (dr == DMA_TO_DEVICE)
251 memcpy(this->data_buffer_dma, this->upper_buf,
252 this->upper_len);
253
254 ret = dma_map_sg(this->dev, sgl, 1, dr);
255 if (ret == 0)
Vikram Narayanan2d350e52012-09-23 15:18:32 +0530256 pr_err("DMA mapping failed.\n");
Huang Shijie10a2bca2011-09-08 10:47:09 +0800257
258 this->direct_dma_map_ok = false;
259 }
260}
261
262/* This will be called after the DMA operation is finished. */
263static void dma_irq_callback(void *param)
264{
265 struct gpmi_nand_data *this = param;
266 struct completion *dma_c = &this->dma_done;
267
268 complete(dma_c);
269
270 switch (this->dma_type) {
271 case DMA_FOR_COMMAND:
272 dma_unmap_sg(this->dev, &this->cmd_sgl, 1, DMA_TO_DEVICE);
273 break;
274
275 case DMA_FOR_READ_DATA:
276 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_FROM_DEVICE);
277 if (this->direct_dma_map_ok == false)
278 memcpy(this->upper_buf, this->data_buffer_dma,
279 this->upper_len);
280 break;
281
282 case DMA_FOR_WRITE_DATA:
283 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_TO_DEVICE);
284 break;
285
286 case DMA_FOR_READ_ECC_PAGE:
287 case DMA_FOR_WRITE_ECC_PAGE:
288 /* We have to wait the BCH interrupt to finish. */
289 break;
290
291 default:
292 pr_err("in wrong DMA operation.\n");
293 }
294}
295
296int start_dma_without_bch_irq(struct gpmi_nand_data *this,
297 struct dma_async_tx_descriptor *desc)
298{
299 struct completion *dma_c = &this->dma_done;
300 int err;
301
302 init_completion(dma_c);
303
304 desc->callback = dma_irq_callback;
305 desc->callback_param = this;
306 dmaengine_submit(desc);
Shawn Guod04525e2012-04-11 13:29:31 +0800307 dma_async_issue_pending(get_dma_chan(this));
Huang Shijie10a2bca2011-09-08 10:47:09 +0800308
309 /* Wait for the interrupt from the DMA block. */
310 err = wait_for_completion_timeout(dma_c, msecs_to_jiffies(1000));
311 if (!err) {
312 pr_err("DMA timeout, last DMA :%d\n", this->last_dma_type);
313 gpmi_dump_info(this);
314 return -ETIMEDOUT;
315 }
316 return 0;
317}
318
319/*
320 * This function is used in BCH reading or BCH writing pages.
321 * It will wait for the BCH interrupt as long as ONE second.
322 * Actually, we must wait for two interrupts :
323 * [1] firstly the DMA interrupt and
324 * [2] secondly the BCH interrupt.
325 */
326int start_dma_with_bch_irq(struct gpmi_nand_data *this,
327 struct dma_async_tx_descriptor *desc)
328{
329 struct completion *bch_c = &this->bch_done;
330 int err;
331
332 /* Prepare to receive an interrupt from the BCH block. */
333 init_completion(bch_c);
334
335 /* start the DMA */
336 start_dma_without_bch_irq(this, desc);
337
338 /* Wait for the interrupt from the BCH block. */
339 err = wait_for_completion_timeout(bch_c, msecs_to_jiffies(1000));
340 if (!err) {
341 pr_err("BCH timeout, last DMA :%d\n", this->last_dma_type);
342 gpmi_dump_info(this);
343 return -ETIMEDOUT;
344 }
345 return 0;
346}
347
Greg Kroah-Hartmand8929942012-12-21 13:19:05 -0800348static int acquire_register_block(struct gpmi_nand_data *this,
349 const char *res_name)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800350{
351 struct platform_device *pdev = this->pdev;
352 struct resources *res = &this->resources;
353 struct resource *r;
Huang Shijie513d57e2012-07-17 14:14:02 +0800354 void __iomem *p;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800355
356 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name);
357 if (!r) {
358 pr_err("Can't get resource for %s\n", res_name);
359 return -ENXIO;
360 }
361
362 p = ioremap(r->start, resource_size(r));
363 if (!p) {
364 pr_err("Can't remap %s\n", res_name);
365 return -ENOMEM;
366 }
367
368 if (!strcmp(res_name, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME))
369 res->gpmi_regs = p;
370 else if (!strcmp(res_name, GPMI_NAND_BCH_REGS_ADDR_RES_NAME))
371 res->bch_regs = p;
372 else
373 pr_err("unknown resource name : %s\n", res_name);
374
375 return 0;
376}
377
378static void release_register_block(struct gpmi_nand_data *this)
379{
380 struct resources *res = &this->resources;
381 if (res->gpmi_regs)
382 iounmap(res->gpmi_regs);
383 if (res->bch_regs)
384 iounmap(res->bch_regs);
385 res->gpmi_regs = NULL;
386 res->bch_regs = NULL;
387}
388
Greg Kroah-Hartmand8929942012-12-21 13:19:05 -0800389static int acquire_bch_irq(struct gpmi_nand_data *this, irq_handler_t irq_h)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800390{
391 struct platform_device *pdev = this->pdev;
392 struct resources *res = &this->resources;
393 const char *res_name = GPMI_NAND_BCH_INTERRUPT_RES_NAME;
394 struct resource *r;
395 int err;
396
397 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, res_name);
398 if (!r) {
399 pr_err("Can't get resource for %s\n", res_name);
400 return -ENXIO;
401 }
402
403 err = request_irq(r->start, irq_h, 0, res_name, this);
404 if (err) {
405 pr_err("Can't own %s\n", res_name);
406 return err;
407 }
408
409 res->bch_low_interrupt = r->start;
410 res->bch_high_interrupt = r->end;
411 return 0;
412}
413
414static void release_bch_irq(struct gpmi_nand_data *this)
415{
416 struct resources *res = &this->resources;
417 int i = res->bch_low_interrupt;
418
419 for (; i <= res->bch_high_interrupt; i++)
420 free_irq(i, this);
421}
422
423static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
424{
425 struct gpmi_nand_data *this = param;
Huang Shijiee10db1f2012-05-04 21:42:05 -0400426 int dma_channel = (int)this->private;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800427
428 if (!mxs_dma_is_apbh(chan))
429 return false;
430 /*
431 * only catch the GPMI dma channels :
432 * for mx23 : MX23_DMA_GPMI0 ~ MX23_DMA_GPMI3
433 * (These four channels share the same IRQ!)
434 *
435 * for mx28 : MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
436 * (These eight channels share the same IRQ!)
437 */
Huang Shijiee10db1f2012-05-04 21:42:05 -0400438 if (dma_channel == chan->chan_id) {
Huang Shijie10a2bca2011-09-08 10:47:09 +0800439 chan->private = &this->dma_data;
440 return true;
441 }
442 return false;
443}
444
445static void release_dma_channels(struct gpmi_nand_data *this)
446{
447 unsigned int i;
448 for (i = 0; i < DMA_CHANS; i++)
449 if (this->dma_chans[i]) {
450 dma_release_channel(this->dma_chans[i]);
451 this->dma_chans[i] = NULL;
452 }
453}
454
Bill Pemberton06f25512012-11-19 13:23:07 -0500455static int acquire_dma_channels(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800456{
457 struct platform_device *pdev = this->pdev;
Huang Shijiee10db1f2012-05-04 21:42:05 -0400458 struct resource *r_dma;
459 struct device_node *dn;
Huang Shijie513d57e2012-07-17 14:14:02 +0800460 u32 dma_channel;
461 int ret;
Huang Shijiee10db1f2012-05-04 21:42:05 -0400462 struct dma_chan *dma_chan;
463 dma_cap_mask_t mask;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800464
Huang Shijiee10db1f2012-05-04 21:42:05 -0400465 /* dma channel, we only use the first one. */
466 dn = pdev->dev.of_node;
467 ret = of_property_read_u32(dn, "fsl,gpmi-dma-channel", &dma_channel);
468 if (ret) {
469 pr_err("unable to get DMA channel from dt.\n");
470 goto acquire_err;
471 }
472 this->private = (void *)dma_channel;
473
474 /* gpmi dma interrupt */
Huang Shijie10a2bca2011-09-08 10:47:09 +0800475 r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
476 GPMI_NAND_DMA_INTERRUPT_RES_NAME);
Huang Shijiee10db1f2012-05-04 21:42:05 -0400477 if (!r_dma) {
Huang Shijie10a2bca2011-09-08 10:47:09 +0800478 pr_err("Can't get resource for DMA\n");
Huang Shijiee10db1f2012-05-04 21:42:05 -0400479 goto acquire_err;
480 }
481 this->dma_data.chan_irq = r_dma->start;
482
483 /* request dma channel */
484 dma_cap_zero(mask);
485 dma_cap_set(DMA_SLAVE, mask);
486
487 dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
488 if (!dma_chan) {
Vikram Narayanan2d350e52012-09-23 15:18:32 +0530489 pr_err("Failed to request DMA channel.\n");
Huang Shijiee10db1f2012-05-04 21:42:05 -0400490 goto acquire_err;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800491 }
492
Huang Shijiee10db1f2012-05-04 21:42:05 -0400493 this->dma_chans[0] = dma_chan;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800494 return 0;
495
496acquire_err:
Huang Shijie10a2bca2011-09-08 10:47:09 +0800497 release_dma_channels(this);
498 return -EINVAL;
499}
500
Huang Shijieff506172012-07-02 21:39:32 -0400501static void gpmi_put_clks(struct gpmi_nand_data *this)
502{
503 struct resources *r = &this->resources;
504 struct clk *clk;
505 int i;
506
507 for (i = 0; i < GPMI_CLK_MAX; i++) {
508 clk = r->clock[i];
509 if (clk) {
510 clk_put(clk);
511 r->clock[i] = NULL;
512 }
513 }
514}
515
516static char *extra_clks_for_mx6q[GPMI_CLK_MAX] = {
517 "gpmi_apb", "gpmi_bch", "gpmi_bch_apb", "per1_bch",
518};
519
Bill Pemberton06f25512012-11-19 13:23:07 -0500520static int gpmi_get_clks(struct gpmi_nand_data *this)
Huang Shijieff506172012-07-02 21:39:32 -0400521{
522 struct resources *r = &this->resources;
523 char **extra_clks = NULL;
524 struct clk *clk;
525 int i;
526
527 /* The main clock is stored in the first. */
528 r->clock[0] = clk_get(this->dev, "gpmi_io");
529 if (IS_ERR(r->clock[0]))
530 goto err_clock;
531
532 /* Get extra clocks */
533 if (GPMI_IS_MX6Q(this))
534 extra_clks = extra_clks_for_mx6q;
535 if (!extra_clks)
536 return 0;
537
538 for (i = 1; i < GPMI_CLK_MAX; i++) {
539 if (extra_clks[i - 1] == NULL)
540 break;
541
542 clk = clk_get(this->dev, extra_clks[i - 1]);
543 if (IS_ERR(clk))
544 goto err_clock;
545
546 r->clock[i] = clk;
547 }
548
Huang Shijiee1ca95e2012-09-13 14:57:58 +0800549 if (GPMI_IS_MX6Q(this))
Huang Shijieff506172012-07-02 21:39:32 -0400550 /*
Huang Shijiee1ca95e2012-09-13 14:57:58 +0800551 * Set the default value for the gpmi clock in mx6q:
Huang Shijieff506172012-07-02 21:39:32 -0400552 *
Huang Shijiee1ca95e2012-09-13 14:57:58 +0800553 * If you want to use the ONFI nand which is in the
554 * Synchronous Mode, you should change the clock as you need.
Huang Shijieff506172012-07-02 21:39:32 -0400555 */
556 clk_set_rate(r->clock[0], 22000000);
Huang Shijiee1ca95e2012-09-13 14:57:58 +0800557
Huang Shijieff506172012-07-02 21:39:32 -0400558 return 0;
559
560err_clock:
561 dev_dbg(this->dev, "failed in finding the clocks.\n");
562 gpmi_put_clks(this);
563 return -ENOMEM;
564}
565
Bill Pemberton06f25512012-11-19 13:23:07 -0500566static int acquire_resources(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800567{
Shawn Guo39febc02012-05-06 22:57:41 +0800568 struct pinctrl *pinctrl;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800569 int ret;
570
571 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME);
572 if (ret)
573 goto exit_regs;
574
575 ret = acquire_register_block(this, GPMI_NAND_BCH_REGS_ADDR_RES_NAME);
576 if (ret)
577 goto exit_regs;
578
579 ret = acquire_bch_irq(this, bch_irq);
580 if (ret)
581 goto exit_regs;
582
583 ret = acquire_dma_channels(this);
584 if (ret)
585 goto exit_dma_channels;
586
Shawn Guo3e48b1b2012-05-19 21:06:13 +0800587 pinctrl = devm_pinctrl_get_select_default(&this->pdev->dev);
Shawn Guo39febc02012-05-06 22:57:41 +0800588 if (IS_ERR(pinctrl)) {
589 ret = PTR_ERR(pinctrl);
590 goto exit_pin;
591 }
592
Huang Shijieff506172012-07-02 21:39:32 -0400593 ret = gpmi_get_clks(this);
594 if (ret)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800595 goto exit_clock;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800596 return 0;
597
598exit_clock:
Shawn Guo39febc02012-05-06 22:57:41 +0800599exit_pin:
Huang Shijie10a2bca2011-09-08 10:47:09 +0800600 release_dma_channels(this);
601exit_dma_channels:
602 release_bch_irq(this);
603exit_regs:
604 release_register_block(this);
605 return ret;
606}
607
608static void release_resources(struct gpmi_nand_data *this)
609{
Huang Shijieff506172012-07-02 21:39:32 -0400610 gpmi_put_clks(this);
Huang Shijie10a2bca2011-09-08 10:47:09 +0800611 release_register_block(this);
612 release_bch_irq(this);
613 release_dma_channels(this);
614}
615
Bill Pemberton06f25512012-11-19 13:23:07 -0500616static int init_hardware(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800617{
618 int ret;
619
620 /*
621 * This structure contains the "safe" GPMI timing that should succeed
622 * with any NAND Flash device
623 * (although, with less-than-optimal performance).
624 */
625 struct nand_timing safe_timing = {
626 .data_setup_in_ns = 80,
627 .data_hold_in_ns = 60,
628 .address_setup_in_ns = 25,
629 .gpmi_sample_delay_in_ns = 6,
630 .tREA_in_ns = -1,
631 .tRLOH_in_ns = -1,
632 .tRHOH_in_ns = -1,
633 };
634
635 /* Initialize the hardwares. */
636 ret = gpmi_init(this);
637 if (ret)
638 return ret;
639
640 this->timing = safe_timing;
641 return 0;
642}
643
644static int read_page_prepare(struct gpmi_nand_data *this,
645 void *destination, unsigned length,
646 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
647 void **use_virt, dma_addr_t *use_phys)
648{
649 struct device *dev = this->dev;
650
651 if (virt_addr_valid(destination)) {
652 dma_addr_t dest_phys;
653
654 dest_phys = dma_map_single(dev, destination,
655 length, DMA_FROM_DEVICE);
656 if (dma_mapping_error(dev, dest_phys)) {
657 if (alt_size < length) {
Vikram Narayanan2d350e52012-09-23 15:18:32 +0530658 pr_err("%s, Alternate buffer is too small\n",
659 __func__);
Huang Shijie10a2bca2011-09-08 10:47:09 +0800660 return -ENOMEM;
661 }
662 goto map_failed;
663 }
664 *use_virt = destination;
665 *use_phys = dest_phys;
666 this->direct_dma_map_ok = true;
667 return 0;
668 }
669
670map_failed:
671 *use_virt = alt_virt;
672 *use_phys = alt_phys;
673 this->direct_dma_map_ok = false;
674 return 0;
675}
676
677static inline void read_page_end(struct gpmi_nand_data *this,
678 void *destination, unsigned length,
679 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
680 void *used_virt, dma_addr_t used_phys)
681{
682 if (this->direct_dma_map_ok)
683 dma_unmap_single(this->dev, used_phys, length, DMA_FROM_DEVICE);
684}
685
686static inline void read_page_swap_end(struct gpmi_nand_data *this,
687 void *destination, unsigned length,
688 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
689 void *used_virt, dma_addr_t used_phys)
690{
691 if (!this->direct_dma_map_ok)
692 memcpy(destination, alt_virt, length);
693}
694
695static int send_page_prepare(struct gpmi_nand_data *this,
696 const void *source, unsigned length,
697 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
698 const void **use_virt, dma_addr_t *use_phys)
699{
700 struct device *dev = this->dev;
701
702 if (virt_addr_valid(source)) {
703 dma_addr_t source_phys;
704
705 source_phys = dma_map_single(dev, (void *)source, length,
706 DMA_TO_DEVICE);
707 if (dma_mapping_error(dev, source_phys)) {
708 if (alt_size < length) {
Vikram Narayanan2d350e52012-09-23 15:18:32 +0530709 pr_err("%s, Alternate buffer is too small\n",
710 __func__);
Huang Shijie10a2bca2011-09-08 10:47:09 +0800711 return -ENOMEM;
712 }
713 goto map_failed;
714 }
715 *use_virt = source;
716 *use_phys = source_phys;
717 return 0;
718 }
719map_failed:
720 /*
721 * Copy the content of the source buffer into the alternate
722 * buffer and set up the return values accordingly.
723 */
724 memcpy(alt_virt, source, length);
725
726 *use_virt = alt_virt;
727 *use_phys = alt_phys;
728 return 0;
729}
730
731static void send_page_end(struct gpmi_nand_data *this,
732 const void *source, unsigned length,
733 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
734 const void *used_virt, dma_addr_t used_phys)
735{
736 struct device *dev = this->dev;
737 if (used_virt == source)
738 dma_unmap_single(dev, used_phys, length, DMA_TO_DEVICE);
739}
740
741static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)
742{
743 struct device *dev = this->dev;
744
745 if (this->page_buffer_virt && virt_addr_valid(this->page_buffer_virt))
746 dma_free_coherent(dev, this->page_buffer_size,
747 this->page_buffer_virt,
748 this->page_buffer_phys);
749 kfree(this->cmd_buffer);
750 kfree(this->data_buffer_dma);
751
752 this->cmd_buffer = NULL;
753 this->data_buffer_dma = NULL;
754 this->page_buffer_virt = NULL;
755 this->page_buffer_size = 0;
756}
757
758/* Allocate the DMA buffers */
759static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this)
760{
761 struct bch_geometry *geo = &this->bch_geometry;
762 struct device *dev = this->dev;
763
764 /* [1] Allocate a command buffer. PAGE_SIZE is enough. */
Huang Shijie513d57e2012-07-17 14:14:02 +0800765 this->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL);
Huang Shijie10a2bca2011-09-08 10:47:09 +0800766 if (this->cmd_buffer == NULL)
767 goto error_alloc;
768
769 /* [2] Allocate a read/write data buffer. PAGE_SIZE is enough. */
Huang Shijie513d57e2012-07-17 14:14:02 +0800770 this->data_buffer_dma = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL);
Huang Shijie10a2bca2011-09-08 10:47:09 +0800771 if (this->data_buffer_dma == NULL)
772 goto error_alloc;
773
774 /*
775 * [3] Allocate the page buffer.
776 *
777 * Both the payload buffer and the auxiliary buffer must appear on
778 * 32-bit boundaries. We presume the size of the payload buffer is a
779 * power of two and is much larger than four, which guarantees the
780 * auxiliary buffer will appear on a 32-bit boundary.
781 */
782 this->page_buffer_size = geo->payload_size + geo->auxiliary_size;
783 this->page_buffer_virt = dma_alloc_coherent(dev, this->page_buffer_size,
784 &this->page_buffer_phys, GFP_DMA);
785 if (!this->page_buffer_virt)
786 goto error_alloc;
787
788
789 /* Slice up the page buffer. */
790 this->payload_virt = this->page_buffer_virt;
791 this->payload_phys = this->page_buffer_phys;
792 this->auxiliary_virt = this->payload_virt + geo->payload_size;
793 this->auxiliary_phys = this->payload_phys + geo->payload_size;
794 return 0;
795
796error_alloc:
797 gpmi_free_dma_buffer(this);
Vikram Narayanan2d350e52012-09-23 15:18:32 +0530798 pr_err("Error allocating DMA buffers!\n");
Huang Shijie10a2bca2011-09-08 10:47:09 +0800799 return -ENOMEM;
800}
801
802static void gpmi_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl)
803{
804 struct nand_chip *chip = mtd->priv;
805 struct gpmi_nand_data *this = chip->priv;
806 int ret;
807
808 /*
809 * Every operation begins with a command byte and a series of zero or
810 * more address bytes. These are distinguished by either the Address
811 * Latch Enable (ALE) or Command Latch Enable (CLE) signals being
812 * asserted. When MTD is ready to execute the command, it will deassert
813 * both latch enables.
814 *
815 * Rather than run a separate DMA operation for every single byte, we
816 * queue them up and run a single DMA operation for the entire series
817 * of command and data bytes. NAND_CMD_NONE means the END of the queue.
818 */
819 if ((ctrl & (NAND_ALE | NAND_CLE))) {
820 if (data != NAND_CMD_NONE)
821 this->cmd_buffer[this->command_length++] = data;
822 return;
823 }
824
825 if (!this->command_length)
826 return;
827
828 ret = gpmi_send_command(this);
829 if (ret)
830 pr_err("Chip: %u, Error %d\n", this->current_chip, ret);
831
832 this->command_length = 0;
833}
834
835static int gpmi_dev_ready(struct mtd_info *mtd)
836{
837 struct nand_chip *chip = mtd->priv;
838 struct gpmi_nand_data *this = chip->priv;
839
840 return gpmi_is_ready(this, this->current_chip);
841}
842
843static void gpmi_select_chip(struct mtd_info *mtd, int chipnr)
844{
845 struct nand_chip *chip = mtd->priv;
846 struct gpmi_nand_data *this = chip->priv;
847
848 if ((this->current_chip < 0) && (chipnr >= 0))
849 gpmi_begin(this);
850 else if ((this->current_chip >= 0) && (chipnr < 0))
851 gpmi_end(this);
852
853 this->current_chip = chipnr;
854}
855
856static void gpmi_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
857{
858 struct nand_chip *chip = mtd->priv;
859 struct gpmi_nand_data *this = chip->priv;
860
861 pr_debug("len is %d\n", len);
862 this->upper_buf = buf;
863 this->upper_len = len;
864
865 gpmi_read_data(this);
866}
867
868static void gpmi_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
869{
870 struct nand_chip *chip = mtd->priv;
871 struct gpmi_nand_data *this = chip->priv;
872
873 pr_debug("len is %d\n", len);
874 this->upper_buf = (uint8_t *)buf;
875 this->upper_len = len;
876
877 gpmi_send_data(this);
878}
879
880static uint8_t gpmi_read_byte(struct mtd_info *mtd)
881{
882 struct nand_chip *chip = mtd->priv;
883 struct gpmi_nand_data *this = chip->priv;
884 uint8_t *buf = this->data_buffer_dma;
885
886 gpmi_read_buf(mtd, buf, 1);
887 return buf[0];
888}
889
890/*
891 * Handles block mark swapping.
892 * It can be called in swapping the block mark, or swapping it back,
893 * because the the operations are the same.
894 */
895static void block_mark_swapping(struct gpmi_nand_data *this,
896 void *payload, void *auxiliary)
897{
898 struct bch_geometry *nfc_geo = &this->bch_geometry;
899 unsigned char *p;
900 unsigned char *a;
901 unsigned int bit;
902 unsigned char mask;
903 unsigned char from_data;
904 unsigned char from_oob;
905
906 if (!this->swap_block_mark)
907 return;
908
909 /*
910 * If control arrives here, we're swapping. Make some convenience
911 * variables.
912 */
913 bit = nfc_geo->block_mark_bit_offset;
914 p = payload + nfc_geo->block_mark_byte_offset;
915 a = auxiliary;
916
917 /*
918 * Get the byte from the data area that overlays the block mark. Since
919 * the ECC engine applies its own view to the bits in the page, the
920 * physical block mark won't (in general) appear on a byte boundary in
921 * the data.
922 */
923 from_data = (p[0] >> bit) | (p[1] << (8 - bit));
924
925 /* Get the byte from the OOB. */
926 from_oob = a[0];
927
928 /* Swap them. */
929 a[0] = from_data;
930
931 mask = (0x1 << bit) - 1;
932 p[0] = (p[0] & mask) | (from_oob << bit);
933
934 mask = ~0 << bit;
935 p[1] = (p[1] & mask) | (from_oob >> (8 - bit));
936}
937
938static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
Brian Norris1fbb9382012-05-02 10:14:55 -0700939 uint8_t *buf, int oob_required, int page)
Huang Shijie10a2bca2011-09-08 10:47:09 +0800940{
941 struct gpmi_nand_data *this = chip->priv;
942 struct bch_geometry *nfc_geo = &this->bch_geometry;
943 void *payload_virt;
944 dma_addr_t payload_phys;
945 void *auxiliary_virt;
946 dma_addr_t auxiliary_phys;
947 unsigned int i;
948 unsigned char *status;
Zach Sadeckib23b7462012-12-13 20:36:29 -0600949 unsigned int max_bitflips = 0;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800950 int ret;
951
952 pr_debug("page number is : %d\n", page);
953 ret = read_page_prepare(this, buf, mtd->writesize,
954 this->payload_virt, this->payload_phys,
955 nfc_geo->payload_size,
956 &payload_virt, &payload_phys);
957 if (ret) {
958 pr_err("Inadequate DMA buffer\n");
959 ret = -ENOMEM;
960 return ret;
961 }
962 auxiliary_virt = this->auxiliary_virt;
963 auxiliary_phys = this->auxiliary_phys;
964
965 /* go! */
966 ret = gpmi_read_page(this, payload_phys, auxiliary_phys);
967 read_page_end(this, buf, mtd->writesize,
968 this->payload_virt, this->payload_phys,
969 nfc_geo->payload_size,
970 payload_virt, payload_phys);
971 if (ret) {
972 pr_err("Error in ECC-based read: %d\n", ret);
Zach Sadeckib23b7462012-12-13 20:36:29 -0600973 return ret;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800974 }
975
976 /* handle the block mark swapping */
977 block_mark_swapping(this, payload_virt, auxiliary_virt);
978
979 /* Loop over status bytes, accumulating ECC status. */
Zach Sadeckib23b7462012-12-13 20:36:29 -0600980 status = auxiliary_virt + nfc_geo->auxiliary_status_offset;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800981
982 for (i = 0; i < nfc_geo->ecc_chunk_count; i++, status++) {
983 if ((*status == STATUS_GOOD) || (*status == STATUS_ERASED))
984 continue;
985
986 if (*status == STATUS_UNCORRECTABLE) {
Zach Sadeckib23b7462012-12-13 20:36:29 -0600987 mtd->ecc_stats.failed++;
Huang Shijie10a2bca2011-09-08 10:47:09 +0800988 continue;
989 }
Zach Sadeckib23b7462012-12-13 20:36:29 -0600990 mtd->ecc_stats.corrected += *status;
991 max_bitflips = max_t(unsigned int, max_bitflips, *status);
Huang Shijie10a2bca2011-09-08 10:47:09 +0800992 }
993
Brian Norris7725cc82012-05-02 10:15:02 -0700994 if (oob_required) {
995 /*
996 * It's time to deliver the OOB bytes. See gpmi_ecc_read_oob()
997 * for details about our policy for delivering the OOB.
998 *
999 * We fill the caller's buffer with set bits, and then copy the
1000 * block mark to th caller's buffer. Note that, if block mark
1001 * swapping was necessary, it has already been done, so we can
1002 * rely on the first byte of the auxiliary buffer to contain
1003 * the block mark.
1004 */
1005 memset(chip->oob_poi, ~0, mtd->oobsize);
1006 chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0];
Brian Norris7725cc82012-05-02 10:15:02 -07001007 }
Sascha Hauer6023813a2012-06-26 17:26:16 +02001008
1009 read_page_swap_end(this, buf, mtd->writesize,
1010 this->payload_virt, this->payload_phys,
1011 nfc_geo->payload_size,
1012 payload_virt, payload_phys);
Zach Sadeckib23b7462012-12-13 20:36:29 -06001013
1014 return max_bitflips;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001015}
1016
Josh Wufdbad98d2012-06-25 18:07:45 +08001017static int gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
Brian Norris1fbb9382012-05-02 10:14:55 -07001018 const uint8_t *buf, int oob_required)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001019{
1020 struct gpmi_nand_data *this = chip->priv;
1021 struct bch_geometry *nfc_geo = &this->bch_geometry;
1022 const void *payload_virt;
1023 dma_addr_t payload_phys;
1024 const void *auxiliary_virt;
1025 dma_addr_t auxiliary_phys;
1026 int ret;
1027
1028 pr_debug("ecc write page.\n");
1029 if (this->swap_block_mark) {
1030 /*
1031 * If control arrives here, we're doing block mark swapping.
1032 * Since we can't modify the caller's buffers, we must copy them
1033 * into our own.
1034 */
1035 memcpy(this->payload_virt, buf, mtd->writesize);
1036 payload_virt = this->payload_virt;
1037 payload_phys = this->payload_phys;
1038
1039 memcpy(this->auxiliary_virt, chip->oob_poi,
1040 nfc_geo->auxiliary_size);
1041 auxiliary_virt = this->auxiliary_virt;
1042 auxiliary_phys = this->auxiliary_phys;
1043
1044 /* Handle block mark swapping. */
1045 block_mark_swapping(this,
1046 (void *) payload_virt, (void *) auxiliary_virt);
1047 } else {
1048 /*
1049 * If control arrives here, we're not doing block mark swapping,
1050 * so we can to try and use the caller's buffers.
1051 */
1052 ret = send_page_prepare(this,
1053 buf, mtd->writesize,
1054 this->payload_virt, this->payload_phys,
1055 nfc_geo->payload_size,
1056 &payload_virt, &payload_phys);
1057 if (ret) {
1058 pr_err("Inadequate payload DMA buffer\n");
Josh Wufdbad98d2012-06-25 18:07:45 +08001059 return 0;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001060 }
1061
1062 ret = send_page_prepare(this,
1063 chip->oob_poi, mtd->oobsize,
1064 this->auxiliary_virt, this->auxiliary_phys,
1065 nfc_geo->auxiliary_size,
1066 &auxiliary_virt, &auxiliary_phys);
1067 if (ret) {
1068 pr_err("Inadequate auxiliary DMA buffer\n");
1069 goto exit_auxiliary;
1070 }
1071 }
1072
1073 /* Ask the NFC. */
1074 ret = gpmi_send_page(this, payload_phys, auxiliary_phys);
1075 if (ret)
1076 pr_err("Error in ECC-based write: %d\n", ret);
1077
1078 if (!this->swap_block_mark) {
1079 send_page_end(this, chip->oob_poi, mtd->oobsize,
1080 this->auxiliary_virt, this->auxiliary_phys,
1081 nfc_geo->auxiliary_size,
1082 auxiliary_virt, auxiliary_phys);
1083exit_auxiliary:
1084 send_page_end(this, buf, mtd->writesize,
1085 this->payload_virt, this->payload_phys,
1086 nfc_geo->payload_size,
1087 payload_virt, payload_phys);
1088 }
Josh Wufdbad98d2012-06-25 18:07:45 +08001089
1090 return 0;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001091}
1092
1093/*
1094 * There are several places in this driver where we have to handle the OOB and
1095 * block marks. This is the function where things are the most complicated, so
1096 * this is where we try to explain it all. All the other places refer back to
1097 * here.
1098 *
1099 * These are the rules, in order of decreasing importance:
1100 *
1101 * 1) Nothing the caller does can be allowed to imperil the block mark.
1102 *
1103 * 2) In read operations, the first byte of the OOB we return must reflect the
1104 * true state of the block mark, no matter where that block mark appears in
1105 * the physical page.
1106 *
1107 * 3) ECC-based read operations return an OOB full of set bits (since we never
1108 * allow ECC-based writes to the OOB, it doesn't matter what ECC-based reads
1109 * return).
1110 *
1111 * 4) "Raw" read operations return a direct view of the physical bytes in the
1112 * page, using the conventional definition of which bytes are data and which
1113 * are OOB. This gives the caller a way to see the actual, physical bytes
1114 * in the page, without the distortions applied by our ECC engine.
1115 *
1116 *
1117 * What we do for this specific read operation depends on two questions:
1118 *
1119 * 1) Are we doing a "raw" read, or an ECC-based read?
1120 *
1121 * 2) Are we using block mark swapping or transcription?
1122 *
1123 * There are four cases, illustrated by the following Karnaugh map:
1124 *
1125 * | Raw | ECC-based |
1126 * -------------+-------------------------+-------------------------+
1127 * | Read the conventional | |
1128 * | OOB at the end of the | |
1129 * Swapping | page and return it. It | |
1130 * | contains exactly what | |
1131 * | we want. | Read the block mark and |
1132 * -------------+-------------------------+ return it in a buffer |
1133 * | Read the conventional | full of set bits. |
1134 * | OOB at the end of the | |
1135 * | page and also the block | |
1136 * Transcribing | mark in the metadata. | |
1137 * | Copy the block mark | |
1138 * | into the first byte of | |
1139 * | the OOB. | |
1140 * -------------+-------------------------+-------------------------+
1141 *
1142 * Note that we break rule #4 in the Transcribing/Raw case because we're not
1143 * giving an accurate view of the actual, physical bytes in the page (we're
1144 * overwriting the block mark). That's OK because it's more important to follow
1145 * rule #2.
1146 *
1147 * It turns out that knowing whether we want an "ECC-based" or "raw" read is not
1148 * easy. When reading a page, for example, the NAND Flash MTD code calls our
1149 * ecc.read_page or ecc.read_page_raw function. Thus, the fact that MTD wants an
1150 * ECC-based or raw view of the page is implicit in which function it calls
1151 * (there is a similar pair of ECC-based/raw functions for writing).
1152 *
Brian Norris271b874b2012-05-11 13:30:35 -07001153 * FIXME: The following paragraph is incorrect, now that there exist
1154 * ecc.read_oob_raw and ecc.write_oob_raw functions.
1155 *
Huang Shijie10a2bca2011-09-08 10:47:09 +08001156 * Since MTD assumes the OOB is not covered by ECC, there is no pair of
1157 * ECC-based/raw functions for reading or or writing the OOB. The fact that the
1158 * caller wants an ECC-based or raw view of the page is not propagated down to
1159 * this driver.
1160 */
1161static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
Shmulik Ladkani5c2ffb12012-05-09 13:06:35 +03001162 int page)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001163{
1164 struct gpmi_nand_data *this = chip->priv;
1165
1166 pr_debug("page number is %d\n", page);
1167 /* clear the OOB buffer */
1168 memset(chip->oob_poi, ~0, mtd->oobsize);
1169
1170 /* Read out the conventional OOB. */
1171 chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1172 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
1173
1174 /*
1175 * Now, we want to make sure the block mark is correct. In the
1176 * Swapping/Raw case, we already have it. Otherwise, we need to
1177 * explicitly read it.
1178 */
1179 if (!this->swap_block_mark) {
1180 /* Read the block mark into the first byte of the OOB buffer. */
1181 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
1182 chip->oob_poi[0] = chip->read_byte(mtd);
1183 }
1184
Shmulik Ladkani5c2ffb12012-05-09 13:06:35 +03001185 return 0;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001186}
1187
1188static int
1189gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
1190{
1191 /*
1192 * The BCH will use all the (page + oob).
1193 * Our gpmi_hw_ecclayout can only prohibit the JFFS2 to write the oob.
1194 * But it can not stop some ioctls such MEMWRITEOOB which uses
Brian Norris0612b9d2011-08-30 18:45:40 -07001195 * MTD_OPS_PLACE_OOB. So We have to implement this function to prohibit
Huang Shijie10a2bca2011-09-08 10:47:09 +08001196 * these ioctls too.
1197 */
1198 return -EPERM;
1199}
1200
1201static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
1202{
1203 struct nand_chip *chip = mtd->priv;
1204 struct gpmi_nand_data *this = chip->priv;
1205 int block, ret = 0;
1206 uint8_t *block_mark;
1207 int column, page, status, chipnr;
1208
1209 /* Get block number */
1210 block = (int)(ofs >> chip->bbt_erase_shift);
1211 if (chip->bbt)
1212 chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
1213
1214 /* Do we have a flash based bad block table ? */
Wolfram Sang52899662012-01-31 13:10:43 +01001215 if (chip->bbt_options & NAND_BBT_USE_FLASH)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001216 ret = nand_update_bbt(mtd, ofs);
1217 else {
1218 chipnr = (int)(ofs >> chip->chip_shift);
1219 chip->select_chip(mtd, chipnr);
1220
1221 column = this->swap_block_mark ? mtd->writesize : 0;
1222
1223 /* Write the block mark. */
1224 block_mark = this->data_buffer_dma;
1225 block_mark[0] = 0; /* bad block marker */
1226
1227 /* Shift to get page */
1228 page = (int)(ofs >> chip->page_shift);
1229
1230 chip->cmdfunc(mtd, NAND_CMD_SEQIN, column, page);
1231 chip->write_buf(mtd, block_mark, 1);
1232 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1233
1234 status = chip->waitfunc(mtd, chip);
1235 if (status & NAND_STATUS_FAIL)
1236 ret = -EIO;
1237
1238 chip->select_chip(mtd, -1);
1239 }
1240 if (!ret)
1241 mtd->ecc_stats.badblocks++;
1242
1243 return ret;
1244}
1245
Wolfram Sanga78da282012-03-21 19:29:17 +01001246static int nand_boot_set_geometry(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001247{
1248 struct boot_rom_geometry *geometry = &this->rom_geometry;
1249
1250 /*
1251 * Set the boot block stride size.
1252 *
1253 * In principle, we should be reading this from the OTP bits, since
1254 * that's where the ROM is going to get it. In fact, we don't have any
1255 * way to read the OTP bits, so we go with the default and hope for the
1256 * best.
1257 */
1258 geometry->stride_size_in_pages = 64;
1259
1260 /*
1261 * Set the search area stride exponent.
1262 *
1263 * In principle, we should be reading this from the OTP bits, since
1264 * that's where the ROM is going to get it. In fact, we don't have any
1265 * way to read the OTP bits, so we go with the default and hope for the
1266 * best.
1267 */
1268 geometry->search_area_stride_exponent = 2;
1269 return 0;
1270}
1271
1272static const char *fingerprint = "STMP";
Wolfram Sanga78da282012-03-21 19:29:17 +01001273static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001274{
1275 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1276 struct device *dev = this->dev;
1277 struct mtd_info *mtd = &this->mtd;
1278 struct nand_chip *chip = &this->nand;
1279 unsigned int search_area_size_in_strides;
1280 unsigned int stride;
1281 unsigned int page;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001282 uint8_t *buffer = chip->buffers->databuf;
1283 int saved_chip_number;
1284 int found_an_ncb_fingerprint = false;
1285
1286 /* Compute the number of strides in a search area. */
1287 search_area_size_in_strides = 1 << rom_geo->search_area_stride_exponent;
1288
1289 saved_chip_number = this->current_chip;
1290 chip->select_chip(mtd, 0);
1291
1292 /*
1293 * Loop through the first search area, looking for the NCB fingerprint.
1294 */
1295 dev_dbg(dev, "Scanning for an NCB fingerprint...\n");
1296
1297 for (stride = 0; stride < search_area_size_in_strides; stride++) {
Huang Shijie513d57e2012-07-17 14:14:02 +08001298 /* Compute the page addresses. */
Huang Shijie10a2bca2011-09-08 10:47:09 +08001299 page = stride * rom_geo->stride_size_in_pages;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001300
1301 dev_dbg(dev, "Looking for a fingerprint in page 0x%x\n", page);
1302
1303 /*
1304 * Read the NCB fingerprint. The fingerprint is four bytes long
1305 * and starts in the 12th byte of the page.
1306 */
1307 chip->cmdfunc(mtd, NAND_CMD_READ0, 12, page);
1308 chip->read_buf(mtd, buffer, strlen(fingerprint));
1309
1310 /* Look for the fingerprint. */
1311 if (!memcmp(buffer, fingerprint, strlen(fingerprint))) {
1312 found_an_ncb_fingerprint = true;
1313 break;
1314 }
1315
1316 }
1317
1318 chip->select_chip(mtd, saved_chip_number);
1319
1320 if (found_an_ncb_fingerprint)
1321 dev_dbg(dev, "\tFound a fingerprint\n");
1322 else
1323 dev_dbg(dev, "\tNo fingerprint found\n");
1324 return found_an_ncb_fingerprint;
1325}
1326
1327/* Writes a transcription stamp. */
Wolfram Sanga78da282012-03-21 19:29:17 +01001328static int mx23_write_transcription_stamp(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001329{
1330 struct device *dev = this->dev;
1331 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1332 struct mtd_info *mtd = &this->mtd;
1333 struct nand_chip *chip = &this->nand;
1334 unsigned int block_size_in_pages;
1335 unsigned int search_area_size_in_strides;
1336 unsigned int search_area_size_in_pages;
1337 unsigned int search_area_size_in_blocks;
1338 unsigned int block;
1339 unsigned int stride;
1340 unsigned int page;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001341 uint8_t *buffer = chip->buffers->databuf;
1342 int saved_chip_number;
1343 int status;
1344
1345 /* Compute the search area geometry. */
1346 block_size_in_pages = mtd->erasesize / mtd->writesize;
1347 search_area_size_in_strides = 1 << rom_geo->search_area_stride_exponent;
1348 search_area_size_in_pages = search_area_size_in_strides *
1349 rom_geo->stride_size_in_pages;
1350 search_area_size_in_blocks =
1351 (search_area_size_in_pages + (block_size_in_pages - 1)) /
1352 block_size_in_pages;
1353
1354 dev_dbg(dev, "Search Area Geometry :\n");
1355 dev_dbg(dev, "\tin Blocks : %u\n", search_area_size_in_blocks);
1356 dev_dbg(dev, "\tin Strides: %u\n", search_area_size_in_strides);
1357 dev_dbg(dev, "\tin Pages : %u\n", search_area_size_in_pages);
1358
1359 /* Select chip 0. */
1360 saved_chip_number = this->current_chip;
1361 chip->select_chip(mtd, 0);
1362
1363 /* Loop over blocks in the first search area, erasing them. */
1364 dev_dbg(dev, "Erasing the search area...\n");
1365
1366 for (block = 0; block < search_area_size_in_blocks; block++) {
1367 /* Compute the page address. */
1368 page = block * block_size_in_pages;
1369
1370 /* Erase this block. */
1371 dev_dbg(dev, "\tErasing block 0x%x\n", block);
1372 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
1373 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
1374
1375 /* Wait for the erase to finish. */
1376 status = chip->waitfunc(mtd, chip);
1377 if (status & NAND_STATUS_FAIL)
1378 dev_err(dev, "[%s] Erase failed.\n", __func__);
1379 }
1380
1381 /* Write the NCB fingerprint into the page buffer. */
1382 memset(buffer, ~0, mtd->writesize);
1383 memset(chip->oob_poi, ~0, mtd->oobsize);
1384 memcpy(buffer + 12, fingerprint, strlen(fingerprint));
1385
1386 /* Loop through the first search area, writing NCB fingerprints. */
1387 dev_dbg(dev, "Writing NCB fingerprints...\n");
1388 for (stride = 0; stride < search_area_size_in_strides; stride++) {
Huang Shijie513d57e2012-07-17 14:14:02 +08001389 /* Compute the page addresses. */
Huang Shijie10a2bca2011-09-08 10:47:09 +08001390 page = stride * rom_geo->stride_size_in_pages;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001391
1392 /* Write the first page of the current stride. */
1393 dev_dbg(dev, "Writing an NCB fingerprint in page 0x%x\n", page);
1394 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
Brian Norris1fbb9382012-05-02 10:14:55 -07001395 chip->ecc.write_page_raw(mtd, chip, buffer, 0);
Huang Shijie10a2bca2011-09-08 10:47:09 +08001396 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1397
1398 /* Wait for the write to finish. */
1399 status = chip->waitfunc(mtd, chip);
1400 if (status & NAND_STATUS_FAIL)
1401 dev_err(dev, "[%s] Write failed.\n", __func__);
1402 }
1403
1404 /* Deselect chip 0. */
1405 chip->select_chip(mtd, saved_chip_number);
1406 return 0;
1407}
1408
Wolfram Sanga78da282012-03-21 19:29:17 +01001409static int mx23_boot_init(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001410{
1411 struct device *dev = this->dev;
1412 struct nand_chip *chip = &this->nand;
1413 struct mtd_info *mtd = &this->mtd;
1414 unsigned int block_count;
1415 unsigned int block;
1416 int chipnr;
1417 int page;
1418 loff_t byte;
1419 uint8_t block_mark;
1420 int ret = 0;
1421
1422 /*
1423 * If control arrives here, we can't use block mark swapping, which
1424 * means we're forced to use transcription. First, scan for the
1425 * transcription stamp. If we find it, then we don't have to do
1426 * anything -- the block marks are already transcribed.
1427 */
1428 if (mx23_check_transcription_stamp(this))
1429 return 0;
1430
1431 /*
1432 * If control arrives here, we couldn't find a transcription stamp, so
1433 * so we presume the block marks are in the conventional location.
1434 */
1435 dev_dbg(dev, "Transcribing bad block marks...\n");
1436
1437 /* Compute the number of blocks in the entire medium. */
1438 block_count = chip->chipsize >> chip->phys_erase_shift;
1439
1440 /*
1441 * Loop over all the blocks in the medium, transcribing block marks as
1442 * we go.
1443 */
1444 for (block = 0; block < block_count; block++) {
1445 /*
1446 * Compute the chip, page and byte addresses for this block's
1447 * conventional mark.
1448 */
1449 chipnr = block >> (chip->chip_shift - chip->phys_erase_shift);
1450 page = block << (chip->phys_erase_shift - chip->page_shift);
1451 byte = block << chip->phys_erase_shift;
1452
1453 /* Send the command to read the conventional block mark. */
1454 chip->select_chip(mtd, chipnr);
1455 chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1456 block_mark = chip->read_byte(mtd);
1457 chip->select_chip(mtd, -1);
1458
1459 /*
1460 * Check if the block is marked bad. If so, we need to mark it
1461 * again, but this time the result will be a mark in the
1462 * location where we transcribe block marks.
1463 */
1464 if (block_mark != 0xff) {
1465 dev_dbg(dev, "Transcribing mark in block %u\n", block);
1466 ret = chip->block_markbad(mtd, byte);
1467 if (ret)
1468 dev_err(dev, "Failed to mark block bad with "
1469 "ret %d\n", ret);
1470 }
1471 }
1472
1473 /* Write the stamp that indicates we've transcribed the block marks. */
1474 mx23_write_transcription_stamp(this);
1475 return 0;
1476}
1477
Wolfram Sanga78da282012-03-21 19:29:17 +01001478static int nand_boot_init(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001479{
1480 nand_boot_set_geometry(this);
1481
1482 /* This is ROM arch-specific initilization before the BBT scanning. */
1483 if (GPMI_IS_MX23(this))
1484 return mx23_boot_init(this);
1485 return 0;
1486}
1487
Wolfram Sanga78da282012-03-21 19:29:17 +01001488static int gpmi_set_geometry(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001489{
1490 int ret;
1491
1492 /* Free the temporary DMA memory for reading ID. */
1493 gpmi_free_dma_buffer(this);
1494
1495 /* Set up the NFC geometry which is used by BCH. */
1496 ret = bch_set_geometry(this);
1497 if (ret) {
Vikram Narayanan2d350e52012-09-23 15:18:32 +05301498 pr_err("Error setting BCH geometry : %d\n", ret);
Huang Shijie10a2bca2011-09-08 10:47:09 +08001499 return ret;
1500 }
1501
1502 /* Alloc the new DMA buffers according to the pagesize and oobsize */
1503 return gpmi_alloc_dma_buffer(this);
1504}
1505
1506static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this)
1507{
1508 int ret;
1509
1510 /* Set up swap_block_mark, must be set before the gpmi_set_geometry() */
1511 if (GPMI_IS_MX23(this))
1512 this->swap_block_mark = false;
1513 else
1514 this->swap_block_mark = true;
1515
1516 /* Set up the medium geometry */
1517 ret = gpmi_set_geometry(this);
1518 if (ret)
1519 return ret;
1520
Marek Vasut5636ce02012-05-21 22:59:27 +02001521 /* Adjust the ECC strength according to the chip. */
1522 this->nand.ecc.strength = this->bch_geometry.ecc_strength;
1523 this->mtd.ecc_strength = this->bch_geometry.ecc_strength;
Huang Shijiee0dd89c2012-07-03 16:24:33 +08001524 this->mtd.bitflip_threshold = this->bch_geometry.ecc_strength;
Marek Vasut5636ce02012-05-21 22:59:27 +02001525
Huang Shijie10a2bca2011-09-08 10:47:09 +08001526 /* NAND boot init, depends on the gpmi_set_geometry(). */
1527 return nand_boot_init(this);
1528}
1529
1530static int gpmi_scan_bbt(struct mtd_info *mtd)
1531{
1532 struct nand_chip *chip = mtd->priv;
1533 struct gpmi_nand_data *this = chip->priv;
1534 int ret;
1535
1536 /* Prepare for the BBT scan. */
1537 ret = gpmi_pre_bbt_scan(this);
1538 if (ret)
1539 return ret;
1540
Huang Shijie995fbbf2012-09-13 14:57:59 +08001541 /*
1542 * Can we enable the extra features? such as EDO or Sync mode.
1543 *
1544 * We do not check the return value now. That's means if we fail in
1545 * enable the extra features, we still can run in the normal way.
1546 */
1547 gpmi_extra_init(this);
1548
Huang Shijie10a2bca2011-09-08 10:47:09 +08001549 /* use the default BBT implementation */
1550 return nand_default_bbt(mtd);
1551}
1552
Huang Shijie513d57e2012-07-17 14:14:02 +08001553static void gpmi_nfc_exit(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001554{
1555 nand_release(&this->mtd);
1556 gpmi_free_dma_buffer(this);
1557}
1558
Bill Pemberton06f25512012-11-19 13:23:07 -05001559static int gpmi_nfc_init(struct gpmi_nand_data *this)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001560{
Huang Shijie10a2bca2011-09-08 10:47:09 +08001561 struct mtd_info *mtd = &this->mtd;
1562 struct nand_chip *chip = &this->nand;
Huang Shijiee10db1f2012-05-04 21:42:05 -04001563 struct mtd_part_parser_data ppdata = {};
Huang Shijie10a2bca2011-09-08 10:47:09 +08001564 int ret;
1565
1566 /* init current chip */
1567 this->current_chip = -1;
1568
1569 /* init the MTD data structures */
1570 mtd->priv = chip;
1571 mtd->name = "gpmi-nand";
1572 mtd->owner = THIS_MODULE;
1573
1574 /* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */
1575 chip->priv = this;
1576 chip->select_chip = gpmi_select_chip;
1577 chip->cmd_ctrl = gpmi_cmd_ctrl;
1578 chip->dev_ready = gpmi_dev_ready;
1579 chip->read_byte = gpmi_read_byte;
1580 chip->read_buf = gpmi_read_buf;
1581 chip->write_buf = gpmi_write_buf;
1582 chip->ecc.read_page = gpmi_ecc_read_page;
1583 chip->ecc.write_page = gpmi_ecc_write_page;
1584 chip->ecc.read_oob = gpmi_ecc_read_oob;
1585 chip->ecc.write_oob = gpmi_ecc_write_oob;
1586 chip->scan_bbt = gpmi_scan_bbt;
1587 chip->badblock_pattern = &gpmi_bbt_descr;
1588 chip->block_markbad = gpmi_block_markbad;
1589 chip->options |= NAND_NO_SUBPAGE_WRITE;
1590 chip->ecc.mode = NAND_ECC_HW;
1591 chip->ecc.size = 1;
Marek Vasut5636ce02012-05-21 22:59:27 +02001592 chip->ecc.strength = 8;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001593 chip->ecc.layout = &gpmi_hw_ecclayout;
Huang Shijiec50c6942012-07-03 16:24:32 +08001594 if (of_get_nand_on_flash_bbt(this->dev->of_node))
1595 chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001596
1597 /* Allocate a temporary DMA buffer for reading ID in the nand_scan() */
1598 this->bch_geometry.payload_size = 1024;
1599 this->bch_geometry.auxiliary_size = 128;
1600 ret = gpmi_alloc_dma_buffer(this);
1601 if (ret)
1602 goto err_out;
1603
Huang Shijiee10db1f2012-05-04 21:42:05 -04001604 ret = nand_scan(mtd, 1);
Huang Shijie10a2bca2011-09-08 10:47:09 +08001605 if (ret) {
1606 pr_err("Chip scan failed\n");
1607 goto err_out;
1608 }
1609
Huang Shijiee10db1f2012-05-04 21:42:05 -04001610 ppdata.of_node = this->pdev->dev.of_node;
1611 ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
Huang Shijie10a2bca2011-09-08 10:47:09 +08001612 if (ret)
1613 goto err_out;
1614 return 0;
1615
1616err_out:
1617 gpmi_nfc_exit(this);
1618 return ret;
1619}
1620
Huang Shijiee10db1f2012-05-04 21:42:05 -04001621static const struct platform_device_id gpmi_ids[] = {
1622 { .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
1623 { .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
Huang Shijie9013bb42012-05-04 21:42:06 -04001624 { .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
Huang Shijiee10db1f2012-05-04 21:42:05 -04001625 {},
1626};
1627
1628static const struct of_device_id gpmi_nand_id_table[] = {
1629 {
1630 .compatible = "fsl,imx23-gpmi-nand",
1631 .data = (void *)&gpmi_ids[IS_MX23]
1632 }, {
1633 .compatible = "fsl,imx28-gpmi-nand",
1634 .data = (void *)&gpmi_ids[IS_MX28]
Huang Shijie9013bb42012-05-04 21:42:06 -04001635 }, {
1636 .compatible = "fsl,imx6q-gpmi-nand",
1637 .data = (void *)&gpmi_ids[IS_MX6Q]
Huang Shijiee10db1f2012-05-04 21:42:05 -04001638 }, {}
1639};
1640MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
1641
Bill Pemberton06f25512012-11-19 13:23:07 -05001642static int gpmi_nand_probe(struct platform_device *pdev)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001643{
Huang Shijie10a2bca2011-09-08 10:47:09 +08001644 struct gpmi_nand_data *this;
Huang Shijiee10db1f2012-05-04 21:42:05 -04001645 const struct of_device_id *of_id;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001646 int ret;
1647
Huang Shijiee10db1f2012-05-04 21:42:05 -04001648 of_id = of_match_device(gpmi_nand_id_table, &pdev->dev);
1649 if (of_id) {
1650 pdev->id_entry = of_id->data;
1651 } else {
1652 pr_err("Failed to find the right device id.\n");
1653 return -ENOMEM;
1654 }
1655
Huang Shijie10a2bca2011-09-08 10:47:09 +08001656 this = kzalloc(sizeof(*this), GFP_KERNEL);
1657 if (!this) {
1658 pr_err("Failed to allocate per-device memory\n");
1659 return -ENOMEM;
1660 }
1661
1662 platform_set_drvdata(pdev, this);
1663 this->pdev = pdev;
1664 this->dev = &pdev->dev;
Huang Shijie10a2bca2011-09-08 10:47:09 +08001665
1666 ret = acquire_resources(this);
1667 if (ret)
1668 goto exit_acquire_resources;
1669
1670 ret = init_hardware(this);
1671 if (ret)
1672 goto exit_nfc_init;
1673
1674 ret = gpmi_nfc_init(this);
1675 if (ret)
1676 goto exit_nfc_init;
1677
Fabio Estevam490e2802012-09-05 11:35:24 -03001678 dev_info(this->dev, "driver registered.\n");
1679
Huang Shijie10a2bca2011-09-08 10:47:09 +08001680 return 0;
1681
1682exit_nfc_init:
1683 release_resources(this);
Huang Shijie10a2bca2011-09-08 10:47:09 +08001684exit_acquire_resources:
1685 platform_set_drvdata(pdev, NULL);
Fabio Estevam490e2802012-09-05 11:35:24 -03001686 dev_err(this->dev, "driver registration failed: %d\n", ret);
Huang Shijie26738dd2013-01-23 16:20:53 +08001687 kfree(this);
Fabio Estevam490e2802012-09-05 11:35:24 -03001688
Huang Shijie10a2bca2011-09-08 10:47:09 +08001689 return ret;
1690}
1691
Bill Pemberton810b7e02012-11-19 13:26:04 -05001692static int gpmi_nand_remove(struct platform_device *pdev)
Huang Shijie10a2bca2011-09-08 10:47:09 +08001693{
1694 struct gpmi_nand_data *this = platform_get_drvdata(pdev);
1695
1696 gpmi_nfc_exit(this);
1697 release_resources(this);
1698 platform_set_drvdata(pdev, NULL);
1699 kfree(this);
1700 return 0;
1701}
1702
Huang Shijie10a2bca2011-09-08 10:47:09 +08001703static struct platform_driver gpmi_nand_driver = {
1704 .driver = {
1705 .name = "gpmi-nand",
Huang Shijiee10db1f2012-05-04 21:42:05 -04001706 .of_match_table = gpmi_nand_id_table,
Huang Shijie10a2bca2011-09-08 10:47:09 +08001707 },
1708 .probe = gpmi_nand_probe,
Bill Pemberton5153b882012-11-19 13:21:24 -05001709 .remove = gpmi_nand_remove,
Huang Shijie10a2bca2011-09-08 10:47:09 +08001710 .id_table = gpmi_ids,
1711};
Fabio Estevam490e2802012-09-05 11:35:24 -03001712module_platform_driver(gpmi_nand_driver);
Huang Shijie10a2bca2011-09-08 10:47:09 +08001713
1714MODULE_AUTHOR("Freescale Semiconductor, Inc.");
1715MODULE_DESCRIPTION("i.MX GPMI NAND Flash Controller Driver");
1716MODULE_LICENSE("GPL");