1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
24#include <linux/clk.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/module.h>
28#include <linux/mtd/partitions.h>
29#include <linux/of.h>
30#include <linux/of_device.h>
31#include <linux/of_mtd.h>
32#include "gpmi-nand.h"
33
34
35#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME "gpmi-nand"
36#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME "bch"
37#define GPMI_NAND_BCH_INTERRUPT_RES_NAME "bch"
38
39
40static uint8_t scan_ff_pattern[] = { 0xff };
41static struct nand_bbt_descr gpmi_bbt_descr = {
42 .options = 0,
43 .offs = 0,
44 .len = 1,
45 .pattern = scan_ff_pattern
46};
47
48
49
50
51
52static struct nand_ecclayout gpmi_hw_ecclayout = {
53 .eccbytes = 0,
54 .eccpos = { 0, },
55 .oobfree = { {.offset = 0, .length = 0} }
56};
57
58static irqreturn_t bch_irq(int irq, void *cookie)
59{
60 struct gpmi_nand_data *this = cookie;
61
62 gpmi_clear_bch(this);
63 complete(&this->bch_done);
64 return IRQ_HANDLED;
65}
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85static inline int get_ecc_strength(struct gpmi_nand_data *this)
86{
87 struct bch_geometry *geo = &this->bch_geometry;
88 struct mtd_info *mtd = &this->mtd;
89 int ecc_strength;
90
91 ecc_strength = ((mtd->oobsize - geo->metadata_size) * 8)
92 / (geo->gf_len * geo->ecc_chunk_count);
93
94
95 return round_down(ecc_strength, 2);
96}
97
98static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
99{
100 struct bch_geometry *geo = &this->bch_geometry;
101
102
103 if (GPMI_IS_MX23(this) || GPMI_IS_MX28(this)) {
104
105 if (geo->gf_len == 14)
106 return false;
107
108 if (geo->ecc_strength > MXS_ECC_STRENGTH_MAX)
109 return false;
110 } else if (GPMI_IS_MX6Q(this)) {
111 if (geo->ecc_strength > MX6_ECC_STRENGTH_MAX)
112 return false;
113 }
114 return true;
115}
116
117
118
119
120
121
122
123static bool set_geometry_by_ecc_info(struct gpmi_nand_data *this)
124{
125 struct bch_geometry *geo = &this->bch_geometry;
126 struct mtd_info *mtd = &this->mtd;
127 struct nand_chip *chip = mtd->priv;
128 struct nand_oobfree *of = gpmi_hw_ecclayout.oobfree;
129 unsigned int block_mark_bit_offset;
130
131 if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
132 return false;
133
134 switch (chip->ecc_step_ds) {
135 case SZ_512:
136 geo->gf_len = 13;
137 break;
138 case SZ_1K:
139 geo->gf_len = 14;
140 break;
141 default:
142 dev_err(this->dev,
143 "unsupported nand chip. ecc bits : %d, ecc size : %d\n",
144 chip->ecc_strength_ds, chip->ecc_step_ds);
145 return false;
146 }
147 geo->ecc_chunk_size = chip->ecc_step_ds;
148 geo->ecc_strength = round_up(chip->ecc_strength_ds, 2);
149 if (!gpmi_check_ecc(this))
150 return false;
151
152
153 if (geo->ecc_chunk_size < mtd->oobsize) {
154 dev_err(this->dev,
155 "unsupported nand chip. ecc size: %d, oob size : %d\n",
156 chip->ecc_step_ds, mtd->oobsize);
157 return false;
158 }
159
160
161 geo->metadata_size = 10;
162
163 geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size;
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 geo->page_size = mtd->writesize + geo->metadata_size +
214 (geo->gf_len * geo->ecc_strength * geo->ecc_chunk_count) / 8;
215
216
217 if (geo->page_size < mtd->writesize + mtd->oobsize) {
218 of->offset = geo->page_size - mtd->writesize;
219 of->length = mtd->oobsize - of->offset;
220 }
221
222 geo->payload_size = mtd->writesize;
223
224 geo->auxiliary_status_offset = ALIGN(geo->metadata_size, 4);
225 geo->auxiliary_size = ALIGN(geo->metadata_size, 4)
226 + ALIGN(geo->ecc_chunk_count, 4);
227
228 if (!this->swap_block_mark)
229 return true;
230
231
232 block_mark_bit_offset = mtd->writesize * 8 -
233 (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - 1)
234 + geo->metadata_size * 8);
235
236 geo->block_mark_byte_offset = block_mark_bit_offset / 8;
237 geo->block_mark_bit_offset = block_mark_bit_offset % 8;
238 return true;
239}
240
241static int legacy_set_geometry(struct gpmi_nand_data *this)
242{
243 struct bch_geometry *geo = &this->bch_geometry;
244 struct mtd_info *mtd = &this->mtd;
245 unsigned int metadata_size;
246 unsigned int status_size;
247 unsigned int block_mark_bit_offset;
248
249
250
251
252
253
254 geo->metadata_size = 10;
255
256
257 geo->gf_len = 13;
258
259
260 geo->ecc_chunk_size = 512;
261 while (geo->ecc_chunk_size < mtd->oobsize) {
262 geo->ecc_chunk_size *= 2;
263 geo->gf_len = 14;
264 }
265
266 geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size;
267
268
269 geo->ecc_strength = get_ecc_strength(this);
270 if (!gpmi_check_ecc(this)) {
271 dev_err(this->dev,
272 "We can not support this nand chip."
273 " Its required ecc strength(%d) is beyond our"
274 " capability(%d).\n", geo->ecc_strength,
275 (GPMI_IS_MX6Q(this) ? MX6_ECC_STRENGTH_MAX
276 : MXS_ECC_STRENGTH_MAX));
277 return -EINVAL;
278 }
279
280 geo->page_size = mtd->writesize + mtd->oobsize;
281 geo->payload_size = mtd->writesize;
282
283
284
285
286
287
288
289 metadata_size = ALIGN(geo->metadata_size, 4);
290 status_size = ALIGN(geo->ecc_chunk_count, 4);
291
292 geo->auxiliary_size = metadata_size + status_size;
293 geo->auxiliary_status_offset = metadata_size;
294
295 if (!this->swap_block_mark)
296 return 0;
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344 block_mark_bit_offset = mtd->writesize * 8 -
345 (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - 1)
346 + geo->metadata_size * 8);
347
348 geo->block_mark_byte_offset = block_mark_bit_offset / 8;
349 geo->block_mark_bit_offset = block_mark_bit_offset % 8;
350 return 0;
351}
352
353int common_nfc_set_geometry(struct gpmi_nand_data *this)
354{
355 return legacy_set_geometry(this);
356}
357
358struct dma_chan *get_dma_chan(struct gpmi_nand_data *this)
359{
360
361 return this->dma_chans[0];
362}
363
364
365void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
366{
367 struct scatterlist *sgl = &this->data_sgl;
368 int ret;
369
370 this->direct_dma_map_ok = true;
371
372
373 sg_init_one(sgl, this->upper_buf, this->upper_len);
374 ret = dma_map_sg(this->dev, sgl, 1, dr);
375 if (ret == 0) {
376
377 sg_init_one(sgl, this->data_buffer_dma, PAGE_SIZE);
378
379 if (dr == DMA_TO_DEVICE)
380 memcpy(this->data_buffer_dma, this->upper_buf,
381 this->upper_len);
382
383 ret = dma_map_sg(this->dev, sgl, 1, dr);
384 if (ret == 0)
385 pr_err("DMA mapping failed.\n");
386
387 this->direct_dma_map_ok = false;
388 }
389}
390
391
392static void dma_irq_callback(void *param)
393{
394 struct gpmi_nand_data *this = param;
395 struct completion *dma_c = &this->dma_done;
396
397 switch (this->dma_type) {
398 case DMA_FOR_COMMAND:
399 dma_unmap_sg(this->dev, &this->cmd_sgl, 1, DMA_TO_DEVICE);
400 break;
401
402 case DMA_FOR_READ_DATA:
403 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_FROM_DEVICE);
404 if (this->direct_dma_map_ok == false)
405 memcpy(this->upper_buf, this->data_buffer_dma,
406 this->upper_len);
407 break;
408
409 case DMA_FOR_WRITE_DATA:
410 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_TO_DEVICE);
411 break;
412
413 case DMA_FOR_READ_ECC_PAGE:
414 case DMA_FOR_WRITE_ECC_PAGE:
415
416 break;
417
418 default:
419 pr_err("in wrong DMA operation.\n");
420 }
421
422 complete(dma_c);
423}
424
425int start_dma_without_bch_irq(struct gpmi_nand_data *this,
426 struct dma_async_tx_descriptor *desc)
427{
428 struct completion *dma_c = &this->dma_done;
429 int err;
430
431 init_completion(dma_c);
432
433 desc->callback = dma_irq_callback;
434 desc->callback_param = this;
435 dmaengine_submit(desc);
436 dma_async_issue_pending(get_dma_chan(this));
437
438
439 err = wait_for_completion_timeout(dma_c, msecs_to_jiffies(1000));
440 if (!err) {
441 pr_err("DMA timeout, last DMA :%d\n", this->last_dma_type);
442 gpmi_dump_info(this);
443 return -ETIMEDOUT;
444 }
445 return 0;
446}
447
448
449
450
451
452
453
454
455int start_dma_with_bch_irq(struct gpmi_nand_data *this,
456 struct dma_async_tx_descriptor *desc)
457{
458 struct completion *bch_c = &this->bch_done;
459 int err;
460
461
462 init_completion(bch_c);
463
464
465 start_dma_without_bch_irq(this, desc);
466
467
468 err = wait_for_completion_timeout(bch_c, msecs_to_jiffies(1000));
469 if (!err) {
470 pr_err("BCH timeout, last DMA :%d\n", this->last_dma_type);
471 gpmi_dump_info(this);
472 return -ETIMEDOUT;
473 }
474 return 0;
475}
476
477static int acquire_register_block(struct gpmi_nand_data *this,
478 const char *res_name)
479{
480 struct platform_device *pdev = this->pdev;
481 struct resources *res = &this->resources;
482 struct resource *r;
483 void __iomem *p;
484
485 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name);
486 if (!r) {
487 pr_err("Can't get resource for %s\n", res_name);
488 return -ENODEV;
489 }
490
491 p = ioremap(r->start, resource_size(r));
492 if (!p) {
493 pr_err("Can't remap %s\n", res_name);
494 return -ENOMEM;
495 }
496
497 if (!strcmp(res_name, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME))
498 res->gpmi_regs = p;
499 else if (!strcmp(res_name, GPMI_NAND_BCH_REGS_ADDR_RES_NAME))
500 res->bch_regs = p;
501 else
502 pr_err("unknown resource name : %s\n", res_name);
503
504 return 0;
505}
506
507static void release_register_block(struct gpmi_nand_data *this)
508{
509 struct resources *res = &this->resources;
510 if (res->gpmi_regs)
511 iounmap(res->gpmi_regs);
512 if (res->bch_regs)
513 iounmap(res->bch_regs);
514 res->gpmi_regs = NULL;
515 res->bch_regs = NULL;
516}
517
518static int acquire_bch_irq(struct gpmi_nand_data *this, irq_handler_t irq_h)
519{
520 struct platform_device *pdev = this->pdev;
521 struct resources *res = &this->resources;
522 const char *res_name = GPMI_NAND_BCH_INTERRUPT_RES_NAME;
523 struct resource *r;
524 int err;
525
526 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, res_name);
527 if (!r) {
528 pr_err("Can't get resource for %s\n", res_name);
529 return -ENODEV;
530 }
531
532 err = request_irq(r->start, irq_h, 0, res_name, this);
533 if (err) {
534 pr_err("Can't own %s\n", res_name);
535 return err;
536 }
537
538 res->bch_low_interrupt = r->start;
539 res->bch_high_interrupt = r->end;
540 return 0;
541}
542
543static void release_bch_irq(struct gpmi_nand_data *this)
544{
545 struct resources *res = &this->resources;
546 int i = res->bch_low_interrupt;
547
548 for (; i <= res->bch_high_interrupt; i++)
549 free_irq(i, this);
550}
551
552static void release_dma_channels(struct gpmi_nand_data *this)
553{
554 unsigned int i;
555 for (i = 0; i < DMA_CHANS; i++)
556 if (this->dma_chans[i]) {
557 dma_release_channel(this->dma_chans[i]);
558 this->dma_chans[i] = NULL;
559 }
560}
561
562static int acquire_dma_channels(struct gpmi_nand_data *this)
563{
564 struct platform_device *pdev = this->pdev;
565 struct dma_chan *dma_chan;
566
567
568 dma_chan = dma_request_slave_channel(&pdev->dev, "rx-tx");
569 if (!dma_chan) {
570 pr_err("Failed to request DMA channel.\n");
571 goto acquire_err;
572 }
573
574 this->dma_chans[0] = dma_chan;
575 return 0;
576
577acquire_err:
578 release_dma_channels(this);
579 return -EINVAL;
580}
581
582static void gpmi_put_clks(struct gpmi_nand_data *this)
583{
584 struct resources *r = &this->resources;
585 struct clk *clk;
586 int i;
587
588 for (i = 0; i < GPMI_CLK_MAX; i++) {
589 clk = r->clock[i];
590 if (clk) {
591 clk_put(clk);
592 r->clock[i] = NULL;
593 }
594 }
595}
596
597static char *extra_clks_for_mx6q[GPMI_CLK_MAX] = {
598 "gpmi_apb", "gpmi_bch", "gpmi_bch_apb", "per1_bch",
599};
600
601static int gpmi_get_clks(struct gpmi_nand_data *this)
602{
603 struct resources *r = &this->resources;
604 char **extra_clks = NULL;
605 struct clk *clk;
606 int err, i;
607
608
609 r->clock[0] = clk_get(this->dev, "gpmi_io");
610 if (IS_ERR(r->clock[0])) {
611 err = PTR_ERR(r->clock[0]);
612 goto err_clock;
613 }
614
615
616 if (GPMI_IS_MX6Q(this))
617 extra_clks = extra_clks_for_mx6q;
618 if (!extra_clks)
619 return 0;
620
621 for (i = 1; i < GPMI_CLK_MAX; i++) {
622 if (extra_clks[i - 1] == NULL)
623 break;
624
625 clk = clk_get(this->dev, extra_clks[i - 1]);
626 if (IS_ERR(clk)) {
627 err = PTR_ERR(clk);
628 goto err_clock;
629 }
630
631 r->clock[i] = clk;
632 }
633
634 if (GPMI_IS_MX6Q(this))
635
636
637
638
639
640
641 clk_set_rate(r->clock[0], 22000000);
642
643 return 0;
644
645err_clock:
646 dev_dbg(this->dev, "failed in finding the clocks.\n");
647 gpmi_put_clks(this);
648 return err;
649}
650
651static int acquire_resources(struct gpmi_nand_data *this)
652{
653 int ret;
654
655 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME);
656 if (ret)
657 goto exit_regs;
658
659 ret = acquire_register_block(this, GPMI_NAND_BCH_REGS_ADDR_RES_NAME);
660 if (ret)
661 goto exit_regs;
662
663 ret = acquire_bch_irq(this, bch_irq);
664 if (ret)
665 goto exit_regs;
666
667 ret = acquire_dma_channels(this);
668 if (ret)
669 goto exit_dma_channels;
670
671 ret = gpmi_get_clks(this);
672 if (ret)
673 goto exit_clock;
674 return 0;
675
676exit_clock:
677 release_dma_channels(this);
678exit_dma_channels:
679 release_bch_irq(this);
680exit_regs:
681 release_register_block(this);
682 return ret;
683}
684
685static void release_resources(struct gpmi_nand_data *this)
686{
687 gpmi_put_clks(this);
688 release_register_block(this);
689 release_bch_irq(this);
690 release_dma_channels(this);
691}
692
693static int init_hardware(struct gpmi_nand_data *this)
694{
695 int ret;
696
697
698
699
700
701
702 struct nand_timing safe_timing = {
703 .data_setup_in_ns = 80,
704 .data_hold_in_ns = 60,
705 .address_setup_in_ns = 25,
706 .gpmi_sample_delay_in_ns = 6,
707 .tREA_in_ns = -1,
708 .tRLOH_in_ns = -1,
709 .tRHOH_in_ns = -1,
710 };
711
712
713 ret = gpmi_init(this);
714 if (ret)
715 return ret;
716
717 this->timing = safe_timing;
718 return 0;
719}
720
721static int read_page_prepare(struct gpmi_nand_data *this,
722 void *destination, unsigned length,
723 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
724 void **use_virt, dma_addr_t *use_phys)
725{
726 struct device *dev = this->dev;
727
728 if (virt_addr_valid(destination)) {
729 dma_addr_t dest_phys;
730
731 dest_phys = dma_map_single(dev, destination,
732 length, DMA_FROM_DEVICE);
733 if (dma_mapping_error(dev, dest_phys)) {
734 if (alt_size < length) {
735 pr_err("%s, Alternate buffer is too small\n",
736 __func__);
737 return -ENOMEM;
738 }
739 goto map_failed;
740 }
741 *use_virt = destination;
742 *use_phys = dest_phys;
743 this->direct_dma_map_ok = true;
744 return 0;
745 }
746
747map_failed:
748 *use_virt = alt_virt;
749 *use_phys = alt_phys;
750 this->direct_dma_map_ok = false;
751 return 0;
752}
753
754static inline void read_page_end(struct gpmi_nand_data *this,
755 void *destination, unsigned length,
756 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
757 void *used_virt, dma_addr_t used_phys)
758{
759 if (this->direct_dma_map_ok)
760 dma_unmap_single(this->dev, used_phys, length, DMA_FROM_DEVICE);
761}
762
763static inline void read_page_swap_end(struct gpmi_nand_data *this,
764 void *destination, unsigned length,
765 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
766 void *used_virt, dma_addr_t used_phys)
767{
768 if (!this->direct_dma_map_ok)
769 memcpy(destination, alt_virt, length);
770}
771
772static int send_page_prepare(struct gpmi_nand_data *this,
773 const void *source, unsigned length,
774 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
775 const void **use_virt, dma_addr_t *use_phys)
776{
777 struct device *dev = this->dev;
778
779 if (virt_addr_valid(source)) {
780 dma_addr_t source_phys;
781
782 source_phys = dma_map_single(dev, (void *)source, length,
783 DMA_TO_DEVICE);
784 if (dma_mapping_error(dev, source_phys)) {
785 if (alt_size < length) {
786 pr_err("%s, Alternate buffer is too small\n",
787 __func__);
788 return -ENOMEM;
789 }
790 goto map_failed;
791 }
792 *use_virt = source;
793 *use_phys = source_phys;
794 return 0;
795 }
796map_failed:
797
798
799
800
801 memcpy(alt_virt, source, length);
802
803 *use_virt = alt_virt;
804 *use_phys = alt_phys;
805 return 0;
806}
807
808static void send_page_end(struct gpmi_nand_data *this,
809 const void *source, unsigned length,
810 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
811 const void *used_virt, dma_addr_t used_phys)
812{
813 struct device *dev = this->dev;
814 if (used_virt == source)
815 dma_unmap_single(dev, used_phys, length, DMA_TO_DEVICE);
816}
817
818static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)
819{
820 struct device *dev = this->dev;
821
822 if (this->page_buffer_virt && virt_addr_valid(this->page_buffer_virt))
823 dma_free_coherent(dev, this->page_buffer_size,
824 this->page_buffer_virt,
825 this->page_buffer_phys);
826 kfree(this->cmd_buffer);
827 kfree(this->data_buffer_dma);
828
829 this->cmd_buffer = NULL;
830 this->data_buffer_dma = NULL;
831 this->page_buffer_virt = NULL;
832 this->page_buffer_size = 0;
833}
834
835
836static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this)
837{
838 struct bch_geometry *geo = &this->bch_geometry;
839 struct device *dev = this->dev;
840
841
842 this->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL);
843 if (this->cmd_buffer == NULL)
844 goto error_alloc;
845
846
847 this->data_buffer_dma = kzalloc(PAGE_SIZE, GFP_DMA | GFP_KERNEL);
848 if (this->data_buffer_dma == NULL)
849 goto error_alloc;
850
851
852
853
854
855
856
857
858
859 this->page_buffer_size = geo->payload_size + geo->auxiliary_size;
860 this->page_buffer_virt = dma_alloc_coherent(dev, this->page_buffer_size,
861 &this->page_buffer_phys, GFP_DMA);
862 if (!this->page_buffer_virt)
863 goto error_alloc;
864
865
866
867 this->payload_virt = this->page_buffer_virt;
868 this->payload_phys = this->page_buffer_phys;
869 this->auxiliary_virt = this->payload_virt + geo->payload_size;
870 this->auxiliary_phys = this->payload_phys + geo->payload_size;
871 return 0;
872
873error_alloc:
874 gpmi_free_dma_buffer(this);
875 pr_err("Error allocating DMA buffers!\n");
876 return -ENOMEM;
877}
878
879static void gpmi_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl)
880{
881 struct nand_chip *chip = mtd->priv;
882 struct gpmi_nand_data *this = chip->priv;
883 int ret;
884
885
886
887
888
889
890
891
892
893
894
895
896 if ((ctrl & (NAND_ALE | NAND_CLE))) {
897 if (data != NAND_CMD_NONE)
898 this->cmd_buffer[this->command_length++] = data;
899 return;
900 }
901
902 if (!this->command_length)
903 return;
904
905 ret = gpmi_send_command(this);
906 if (ret)
907 pr_err("Chip: %u, Error %d\n", this->current_chip, ret);
908
909 this->command_length = 0;
910}
911
912static int gpmi_dev_ready(struct mtd_info *mtd)
913{
914 struct nand_chip *chip = mtd->priv;
915 struct gpmi_nand_data *this = chip->priv;
916
917 return gpmi_is_ready(this, this->current_chip);
918}
919
920static void gpmi_select_chip(struct mtd_info *mtd, int chipnr)
921{
922 struct nand_chip *chip = mtd->priv;
923 struct gpmi_nand_data *this = chip->priv;
924
925 if ((this->current_chip < 0) && (chipnr >= 0))
926 gpmi_begin(this);
927 else if ((this->current_chip >= 0) && (chipnr < 0))
928 gpmi_end(this);
929
930 this->current_chip = chipnr;
931}
932
933static void gpmi_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
934{
935 struct nand_chip *chip = mtd->priv;
936 struct gpmi_nand_data *this = chip->priv;
937
938 pr_debug("len is %d\n", len);
939 this->upper_buf = buf;
940 this->upper_len = len;
941
942 gpmi_read_data(this);
943}
944
945static void gpmi_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
946{
947 struct nand_chip *chip = mtd->priv;
948 struct gpmi_nand_data *this = chip->priv;
949
950 pr_debug("len is %d\n", len);
951 this->upper_buf = (uint8_t *)buf;
952 this->upper_len = len;
953
954 gpmi_send_data(this);
955}
956
957static uint8_t gpmi_read_byte(struct mtd_info *mtd)
958{
959 struct nand_chip *chip = mtd->priv;
960 struct gpmi_nand_data *this = chip->priv;
961 uint8_t *buf = this->data_buffer_dma;
962
963 gpmi_read_buf(mtd, buf, 1);
964 return buf[0];
965}
966
967
968
969
970
971
972static void block_mark_swapping(struct gpmi_nand_data *this,
973 void *payload, void *auxiliary)
974{
975 struct bch_geometry *nfc_geo = &this->bch_geometry;
976 unsigned char *p;
977 unsigned char *a;
978 unsigned int bit;
979 unsigned char mask;
980 unsigned char from_data;
981 unsigned char from_oob;
982
983 if (!this->swap_block_mark)
984 return;
985
986
987
988
989
990 bit = nfc_geo->block_mark_bit_offset;
991 p = payload + nfc_geo->block_mark_byte_offset;
992 a = auxiliary;
993
994
995
996
997
998
999
1000 from_data = (p[0] >> bit) | (p[1] << (8 - bit));
1001
1002
1003 from_oob = a[0];
1004
1005
1006 a[0] = from_data;
1007
1008 mask = (0x1 << bit) - 1;
1009 p[0] = (p[0] & mask) | (from_oob << bit);
1010
1011 mask = ~0 << bit;
1012 p[1] = (p[1] & mask) | (from_oob >> (8 - bit));
1013}
1014
1015static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1016 uint8_t *buf, int oob_required, int page)
1017{
1018 struct gpmi_nand_data *this = chip->priv;
1019 struct bch_geometry *nfc_geo = &this->bch_geometry;
1020 void *payload_virt;
1021 dma_addr_t payload_phys;
1022 void *auxiliary_virt;
1023 dma_addr_t auxiliary_phys;
1024 unsigned int i;
1025 unsigned char *status;
1026 unsigned int max_bitflips = 0;
1027 int ret;
1028
1029 pr_debug("page number is : %d\n", page);
1030 ret = read_page_prepare(this, buf, mtd->writesize,
1031 this->payload_virt, this->payload_phys,
1032 nfc_geo->payload_size,
1033 &payload_virt, &payload_phys);
1034 if (ret) {
1035 pr_err("Inadequate DMA buffer\n");
1036 ret = -ENOMEM;
1037 return ret;
1038 }
1039 auxiliary_virt = this->auxiliary_virt;
1040 auxiliary_phys = this->auxiliary_phys;
1041
1042
1043 ret = gpmi_read_page(this, payload_phys, auxiliary_phys);
1044 read_page_end(this, buf, mtd->writesize,
1045 this->payload_virt, this->payload_phys,
1046 nfc_geo->payload_size,
1047 payload_virt, payload_phys);
1048 if (ret) {
1049 pr_err("Error in ECC-based read: %d\n", ret);
1050 return ret;
1051 }
1052
1053
1054 block_mark_swapping(this, payload_virt, auxiliary_virt);
1055
1056
1057 status = auxiliary_virt + nfc_geo->auxiliary_status_offset;
1058
1059 for (i = 0; i < nfc_geo->ecc_chunk_count; i++, status++) {
1060 if ((*status == STATUS_GOOD) || (*status == STATUS_ERASED))
1061 continue;
1062
1063 if (*status == STATUS_UNCORRECTABLE) {
1064 mtd->ecc_stats.failed++;
1065 continue;
1066 }
1067 mtd->ecc_stats.corrected += *status;
1068 max_bitflips = max_t(unsigned int, max_bitflips, *status);
1069 }
1070
1071 if (oob_required) {
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082 memset(chip->oob_poi, ~0, mtd->oobsize);
1083 chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0];
1084 }
1085
1086 read_page_swap_end(this, buf, mtd->writesize,
1087 this->payload_virt, this->payload_phys,
1088 nfc_geo->payload_size,
1089 payload_virt, payload_phys);
1090
1091 return max_bitflips;
1092}
1093
1094static int gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
1095 const uint8_t *buf, int oob_required)
1096{
1097 struct gpmi_nand_data *this = chip->priv;
1098 struct bch_geometry *nfc_geo = &this->bch_geometry;
1099 const void *payload_virt;
1100 dma_addr_t payload_phys;
1101 const void *auxiliary_virt;
1102 dma_addr_t auxiliary_phys;
1103 int ret;
1104
1105 pr_debug("ecc write page.\n");
1106 if (this->swap_block_mark) {
1107
1108
1109
1110
1111
1112 memcpy(this->payload_virt, buf, mtd->writesize);
1113 payload_virt = this->payload_virt;
1114 payload_phys = this->payload_phys;
1115
1116 memcpy(this->auxiliary_virt, chip->oob_poi,
1117 nfc_geo->auxiliary_size);
1118 auxiliary_virt = this->auxiliary_virt;
1119 auxiliary_phys = this->auxiliary_phys;
1120
1121
1122 block_mark_swapping(this,
1123 (void *) payload_virt, (void *) auxiliary_virt);
1124 } else {
1125
1126
1127
1128
1129 ret = send_page_prepare(this,
1130 buf, mtd->writesize,
1131 this->payload_virt, this->payload_phys,
1132 nfc_geo->payload_size,
1133 &payload_virt, &payload_phys);
1134 if (ret) {
1135 pr_err("Inadequate payload DMA buffer\n");
1136 return 0;
1137 }
1138
1139 ret = send_page_prepare(this,
1140 chip->oob_poi, mtd->oobsize,
1141 this->auxiliary_virt, this->auxiliary_phys,
1142 nfc_geo->auxiliary_size,
1143 &auxiliary_virt, &auxiliary_phys);
1144 if (ret) {
1145 pr_err("Inadequate auxiliary DMA buffer\n");
1146 goto exit_auxiliary;
1147 }
1148 }
1149
1150
1151 ret = gpmi_send_page(this, payload_phys, auxiliary_phys);
1152 if (ret)
1153 pr_err("Error in ECC-based write: %d\n", ret);
1154
1155 if (!this->swap_block_mark) {
1156 send_page_end(this, chip->oob_poi, mtd->oobsize,
1157 this->auxiliary_virt, this->auxiliary_phys,
1158 nfc_geo->auxiliary_size,
1159 auxiliary_virt, auxiliary_phys);
1160exit_auxiliary:
1161 send_page_end(this, buf, mtd->writesize,
1162 this->payload_virt, this->payload_phys,
1163 nfc_geo->payload_size,
1164 payload_virt, payload_phys);
1165 }
1166
1167 return 0;
1168}
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
1239 int page)
1240{
1241 struct gpmi_nand_data *this = chip->priv;
1242
1243 pr_debug("page number is %d\n", page);
1244
1245 memset(chip->oob_poi, ~0, mtd->oobsize);
1246
1247
1248 chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1249 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
1250
1251
1252
1253
1254
1255
1256 if (!this->swap_block_mark) {
1257
1258 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
1259 chip->oob_poi[0] = chip->read_byte(mtd);
1260 }
1261
1262 return 0;
1263}
1264
1265static int
1266gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
1267{
1268 struct nand_oobfree *of = mtd->ecclayout->oobfree;
1269 int status = 0;
1270
1271
1272 if (!of->length)
1273 return -EPERM;
1274
1275 if (!nand_is_slc(chip))
1276 return -EPERM;
1277
1278 chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + of->offset, page);
1279 chip->write_buf(mtd, chip->oob_poi + of->offset, of->length);
1280 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1281
1282 status = chip->waitfunc(mtd, chip);
1283 return status & NAND_STATUS_FAIL ? -EIO : 0;
1284}
1285
1286static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
1287{
1288 struct nand_chip *chip = mtd->priv;
1289 struct gpmi_nand_data *this = chip->priv;
1290 int ret = 0;
1291 uint8_t *block_mark;
1292 int column, page, status, chipnr;
1293
1294 chipnr = (int)(ofs >> chip->chip_shift);
1295 chip->select_chip(mtd, chipnr);
1296
1297 column = this->swap_block_mark ? mtd->writesize : 0;
1298
1299
1300 block_mark = this->data_buffer_dma;
1301 block_mark[0] = 0;
1302
1303
1304 page = (int)(ofs >> chip->page_shift);
1305
1306 chip->cmdfunc(mtd, NAND_CMD_SEQIN, column, page);
1307 chip->write_buf(mtd, block_mark, 1);
1308 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1309
1310 status = chip->waitfunc(mtd, chip);
1311 if (status & NAND_STATUS_FAIL)
1312 ret = -EIO;
1313
1314 chip->select_chip(mtd, -1);
1315
1316 return ret;
1317}
1318
1319static int nand_boot_set_geometry(struct gpmi_nand_data *this)
1320{
1321 struct boot_rom_geometry *geometry = &this->rom_geometry;
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331 geometry->stride_size_in_pages = 64;
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341 geometry->search_area_stride_exponent = 2;
1342 return 0;
1343}
1344
1345static const char *fingerprint = "STMP";
1346static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
1347{
1348 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1349 struct device *dev = this->dev;
1350 struct mtd_info *mtd = &this->mtd;
1351 struct nand_chip *chip = &this->nand;
1352 unsigned int search_area_size_in_strides;
1353 unsigned int stride;
1354 unsigned int page;
1355 uint8_t *buffer = chip->buffers->databuf;
1356 int saved_chip_number;
1357 int found_an_ncb_fingerprint = false;
1358
1359
1360 search_area_size_in_strides = 1 << rom_geo->search_area_stride_exponent;
1361
1362 saved_chip_number = this->current_chip;
1363 chip->select_chip(mtd, 0);
1364
1365
1366
1367
1368 dev_dbg(dev, "Scanning for an NCB fingerprint...\n");
1369
1370 for (stride = 0; stride < search_area_size_in_strides; stride++) {
1371
1372 page = stride * rom_geo->stride_size_in_pages;
1373
1374 dev_dbg(dev, "Looking for a fingerprint in page 0x%x\n", page);
1375
1376
1377
1378
1379
1380 chip->cmdfunc(mtd, NAND_CMD_READ0, 12, page);
1381 chip->read_buf(mtd, buffer, strlen(fingerprint));
1382
1383
1384 if (!memcmp(buffer, fingerprint, strlen(fingerprint))) {
1385 found_an_ncb_fingerprint = true;
1386 break;
1387 }
1388
1389 }
1390
1391 chip->select_chip(mtd, saved_chip_number);
1392
1393 if (found_an_ncb_fingerprint)
1394 dev_dbg(dev, "\tFound a fingerprint\n");
1395 else
1396 dev_dbg(dev, "\tNo fingerprint found\n");
1397 return found_an_ncb_fingerprint;
1398}
1399
1400
1401static int mx23_write_transcription_stamp(struct gpmi_nand_data *this)
1402{
1403 struct device *dev = this->dev;
1404 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1405 struct mtd_info *mtd = &this->mtd;
1406 struct nand_chip *chip = &this->nand;
1407 unsigned int block_size_in_pages;
1408 unsigned int search_area_size_in_strides;
1409 unsigned int search_area_size_in_pages;
1410 unsigned int search_area_size_in_blocks;
1411 unsigned int block;
1412 unsigned int stride;
1413 unsigned int page;
1414 uint8_t *buffer = chip->buffers->databuf;
1415 int saved_chip_number;
1416 int status;
1417
1418
1419 block_size_in_pages = mtd->erasesize / mtd->writesize;
1420 search_area_size_in_strides = 1 << rom_geo->search_area_stride_exponent;
1421 search_area_size_in_pages = search_area_size_in_strides *
1422 rom_geo->stride_size_in_pages;
1423 search_area_size_in_blocks =
1424 (search_area_size_in_pages + (block_size_in_pages - 1)) /
1425 block_size_in_pages;
1426
1427 dev_dbg(dev, "Search Area Geometry :\n");
1428 dev_dbg(dev, "\tin Blocks : %u\n", search_area_size_in_blocks);
1429 dev_dbg(dev, "\tin Strides: %u\n", search_area_size_in_strides);
1430 dev_dbg(dev, "\tin Pages : %u\n", search_area_size_in_pages);
1431
1432
1433 saved_chip_number = this->current_chip;
1434 chip->select_chip(mtd, 0);
1435
1436
1437 dev_dbg(dev, "Erasing the search area...\n");
1438
1439 for (block = 0; block < search_area_size_in_blocks; block++) {
1440
1441 page = block * block_size_in_pages;
1442
1443
1444 dev_dbg(dev, "\tErasing block 0x%x\n", block);
1445 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
1446 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
1447
1448
1449 status = chip->waitfunc(mtd, chip);
1450 if (status & NAND_STATUS_FAIL)
1451 dev_err(dev, "[%s] Erase failed.\n", __func__);
1452 }
1453
1454
1455 memset(buffer, ~0, mtd->writesize);
1456 memset(chip->oob_poi, ~0, mtd->oobsize);
1457 memcpy(buffer + 12, fingerprint, strlen(fingerprint));
1458
1459
1460 dev_dbg(dev, "Writing NCB fingerprints...\n");
1461 for (stride = 0; stride < search_area_size_in_strides; stride++) {
1462
1463 page = stride * rom_geo->stride_size_in_pages;
1464
1465
1466 dev_dbg(dev, "Writing an NCB fingerprint in page 0x%x\n", page);
1467 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
1468 chip->ecc.write_page_raw(mtd, chip, buffer, 0);
1469 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1470
1471
1472 status = chip->waitfunc(mtd, chip);
1473 if (status & NAND_STATUS_FAIL)
1474 dev_err(dev, "[%s] Write failed.\n", __func__);
1475 }
1476
1477
1478 chip->select_chip(mtd, saved_chip_number);
1479 return 0;
1480}
1481
1482static int mx23_boot_init(struct gpmi_nand_data *this)
1483{
1484 struct device *dev = this->dev;
1485 struct nand_chip *chip = &this->nand;
1486 struct mtd_info *mtd = &this->mtd;
1487 unsigned int block_count;
1488 unsigned int block;
1489 int chipnr;
1490 int page;
1491 loff_t byte;
1492 uint8_t block_mark;
1493 int ret = 0;
1494
1495
1496
1497
1498
1499
1500
1501 if (mx23_check_transcription_stamp(this))
1502 return 0;
1503
1504
1505
1506
1507
1508 dev_dbg(dev, "Transcribing bad block marks...\n");
1509
1510
1511 block_count = chip->chipsize >> chip->phys_erase_shift;
1512
1513
1514
1515
1516
1517 for (block = 0; block < block_count; block++) {
1518
1519
1520
1521
1522 chipnr = block >> (chip->chip_shift - chip->phys_erase_shift);
1523 page = block << (chip->phys_erase_shift - chip->page_shift);
1524 byte = block << chip->phys_erase_shift;
1525
1526
1527 chip->select_chip(mtd, chipnr);
1528 chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1529 block_mark = chip->read_byte(mtd);
1530 chip->select_chip(mtd, -1);
1531
1532
1533
1534
1535
1536
1537 if (block_mark != 0xff) {
1538 dev_dbg(dev, "Transcribing mark in block %u\n", block);
1539 ret = chip->block_markbad(mtd, byte);
1540 if (ret)
1541 dev_err(dev, "Failed to mark block bad with "
1542 "ret %d\n", ret);
1543 }
1544 }
1545
1546
1547 mx23_write_transcription_stamp(this);
1548 return 0;
1549}
1550
1551static int nand_boot_init(struct gpmi_nand_data *this)
1552{
1553 nand_boot_set_geometry(this);
1554
1555
1556 if (GPMI_IS_MX23(this))
1557 return mx23_boot_init(this);
1558 return 0;
1559}
1560
1561static int gpmi_set_geometry(struct gpmi_nand_data *this)
1562{
1563 int ret;
1564
1565
1566 gpmi_free_dma_buffer(this);
1567
1568
1569 ret = bch_set_geometry(this);
1570 if (ret) {
1571 pr_err("Error setting BCH geometry : %d\n", ret);
1572 return ret;
1573 }
1574
1575
1576 return gpmi_alloc_dma_buffer(this);
1577}
1578
1579static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this)
1580{
1581
1582 if (GPMI_IS_MX23(this))
1583 this->swap_block_mark = false;
1584 else
1585 this->swap_block_mark = true;
1586
1587
1588 return gpmi_set_geometry(this);
1589
1590}
1591
1592static void gpmi_nfc_exit(struct gpmi_nand_data *this)
1593{
1594 nand_release(&this->mtd);
1595 gpmi_free_dma_buffer(this);
1596}
1597
1598static int gpmi_init_last(struct gpmi_nand_data *this)
1599{
1600 struct mtd_info *mtd = &this->mtd;
1601 struct nand_chip *chip = mtd->priv;
1602 struct nand_ecc_ctrl *ecc = &chip->ecc;
1603 struct bch_geometry *bch_geo = &this->bch_geometry;
1604 int ret;
1605
1606
1607 ret = gpmi_pre_bbt_scan(this);
1608 if (ret)
1609 return ret;
1610
1611
1612 ecc->read_page = gpmi_ecc_read_page;
1613 ecc->write_page = gpmi_ecc_write_page;
1614 ecc->read_oob = gpmi_ecc_read_oob;
1615 ecc->write_oob = gpmi_ecc_write_oob;
1616 ecc->mode = NAND_ECC_HW;
1617 ecc->size = bch_geo->ecc_chunk_size;
1618 ecc->strength = bch_geo->ecc_strength;
1619 ecc->layout = &gpmi_hw_ecclayout;
1620
1621
1622
1623
1624
1625
1626
1627 gpmi_extra_init(this);
1628
1629 return 0;
1630}
1631
1632static int gpmi_nfc_init(struct gpmi_nand_data *this)
1633{
1634 struct mtd_info *mtd = &this->mtd;
1635 struct nand_chip *chip = &this->nand;
1636 struct mtd_part_parser_data ppdata = {};
1637 int ret;
1638
1639
1640 this->current_chip = -1;
1641
1642
1643 mtd->priv = chip;
1644 mtd->name = "gpmi-nand";
1645 mtd->owner = THIS_MODULE;
1646
1647
1648 chip->priv = this;
1649 chip->select_chip = gpmi_select_chip;
1650 chip->cmd_ctrl = gpmi_cmd_ctrl;
1651 chip->dev_ready = gpmi_dev_ready;
1652 chip->read_byte = gpmi_read_byte;
1653 chip->read_buf = gpmi_read_buf;
1654 chip->write_buf = gpmi_write_buf;
1655 chip->badblock_pattern = &gpmi_bbt_descr;
1656 chip->block_markbad = gpmi_block_markbad;
1657 chip->options |= NAND_NO_SUBPAGE_WRITE;
1658 if (of_get_nand_on_flash_bbt(this->dev->of_node))
1659 chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
1660
1661
1662
1663
1664
1665 this->bch_geometry.payload_size = 1024;
1666 this->bch_geometry.auxiliary_size = 128;
1667 ret = gpmi_alloc_dma_buffer(this);
1668 if (ret)
1669 goto err_out;
1670
1671 ret = nand_scan_ident(mtd, GPMI_IS_MX6Q(this) ? 2 : 1, NULL);
1672 if (ret)
1673 goto err_out;
1674
1675 ret = gpmi_init_last(this);
1676 if (ret)
1677 goto err_out;
1678
1679 chip->options |= NAND_SKIP_BBTSCAN;
1680 ret = nand_scan_tail(mtd);
1681 if (ret)
1682 goto err_out;
1683
1684 ret = nand_boot_init(this);
1685 if (ret)
1686 goto err_out;
1687 chip->scan_bbt(mtd);
1688
1689 ppdata.of_node = this->pdev->dev.of_node;
1690 ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
1691 if (ret)
1692 goto err_out;
1693 return 0;
1694
1695err_out:
1696 gpmi_nfc_exit(this);
1697 return ret;
1698}
1699
1700static const struct platform_device_id gpmi_ids[] = {
1701 { .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
1702 { .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
1703 { .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
1704 {}
1705};
1706
1707static const struct of_device_id gpmi_nand_id_table[] = {
1708 {
1709 .compatible = "fsl,imx23-gpmi-nand",
1710 .data = (void *)&gpmi_ids[IS_MX23],
1711 }, {
1712 .compatible = "fsl,imx28-gpmi-nand",
1713 .data = (void *)&gpmi_ids[IS_MX28],
1714 }, {
1715 .compatible = "fsl,imx6q-gpmi-nand",
1716 .data = (void *)&gpmi_ids[IS_MX6Q],
1717 }, {}
1718};
1719MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
1720
1721static int gpmi_nand_probe(struct platform_device *pdev)
1722{
1723 struct gpmi_nand_data *this;
1724 const struct of_device_id *of_id;
1725 int ret;
1726
1727 of_id = of_match_device(gpmi_nand_id_table, &pdev->dev);
1728 if (of_id) {
1729 pdev->id_entry = of_id->data;
1730 } else {
1731 pr_err("Failed to find the right device id.\n");
1732 return -ENODEV;
1733 }
1734
1735 this = devm_kzalloc(&pdev->dev, sizeof(*this), GFP_KERNEL);
1736 if (!this) {
1737 pr_err("Failed to allocate per-device memory\n");
1738 return -ENOMEM;
1739 }
1740
1741 platform_set_drvdata(pdev, this);
1742 this->pdev = pdev;
1743 this->dev = &pdev->dev;
1744
1745 ret = acquire_resources(this);
1746 if (ret)
1747 goto exit_acquire_resources;
1748
1749 ret = init_hardware(this);
1750 if (ret)
1751 goto exit_nfc_init;
1752
1753 ret = gpmi_nfc_init(this);
1754 if (ret)
1755 goto exit_nfc_init;
1756
1757 dev_info(this->dev, "driver registered.\n");
1758
1759 return 0;
1760
1761exit_nfc_init:
1762 release_resources(this);
1763exit_acquire_resources:
1764 dev_err(this->dev, "driver registration failed: %d\n", ret);
1765
1766 return ret;
1767}
1768
1769static int gpmi_nand_remove(struct platform_device *pdev)
1770{
1771 struct gpmi_nand_data *this = platform_get_drvdata(pdev);
1772
1773 gpmi_nfc_exit(this);
1774 release_resources(this);
1775 return 0;
1776}
1777
1778static struct platform_driver gpmi_nand_driver = {
1779 .driver = {
1780 .name = "gpmi-nand",
1781 .of_match_table = gpmi_nand_id_table,
1782 },
1783 .probe = gpmi_nand_probe,
1784 .remove = gpmi_nand_remove,
1785 .id_table = gpmi_ids,
1786};
1787module_platform_driver(gpmi_nand_driver);
1788
1789MODULE_AUTHOR("Freescale Semiconductor, Inc.");
1790MODULE_DESCRIPTION("i.MX GPMI NAND Flash Controller Driver");
1791MODULE_LICENSE("GPL");
1792