1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "hw.h"
22#include "flash.h"
23#include "omap.h"
24#include "memory.h"
25#include "exec-memory.h"
26
27
28struct omap_gpmc_s {
29 qemu_irq irq;
30 qemu_irq drq;
31 MemoryRegion iomem;
32 int accept_256;
33
34 uint8_t revision;
35 uint8_t sysconfig;
36 uint16_t irqst;
37 uint16_t irqen;
38 uint16_t lastirq;
39 uint16_t timeout;
40 uint16_t config;
41 struct omap_gpmc_cs_file_s {
42 uint32_t config[7];
43 MemoryRegion *iomem;
44 MemoryRegion container;
45 MemoryRegion nandiomem;
46 DeviceState *dev;
47 } cs_file[8];
48 int ecc_cs;
49 int ecc_ptr;
50 uint32_t ecc_cfg;
51 ECCState ecc[9];
52 struct prefetch {
53 uint32_t config1;
54 uint32_t transfercount;
55 int startengine;
56 int fifopointer;
57 int count;
58 MemoryRegion iomem;
59 uint8_t fifo[64];
60 } prefetch;
61};
62
63#define OMAP_GPMC_8BIT 0
64#define OMAP_GPMC_16BIT 1
65#define OMAP_GPMC_NOR 0
66#define OMAP_GPMC_NAND 2
67
68static int omap_gpmc_devtype(struct omap_gpmc_cs_file_s *f)
69{
70 return (f->config[0] >> 10) & 3;
71}
72
73static int omap_gpmc_devsize(struct omap_gpmc_cs_file_s *f)
74{
75
76
77
78
79 return (f->config[0] >> 12) & 1;
80}
81
82
83static int prefetch_cs(uint32_t config1)
84{
85 return (config1 >> 24) & 7;
86}
87
88static int prefetch_threshold(uint32_t config1)
89{
90 return (config1 >> 8) & 0x7f;
91}
92
93static void omap_gpmc_int_update(struct omap_gpmc_s *s)
94{
95
96
97
98
99
100
101
102
103
104 if (s->prefetch.fifopointer >= prefetch_threshold(s->prefetch.config1)) {
105 s->irqst |= 1;
106 }
107 if ((s->irqen & s->irqst) != s->lastirq) {
108 s->lastirq = s->irqen & s->irqst;
109 qemu_set_irq(s->irq, s->lastirq);
110 }
111}
112
113static void omap_gpmc_dma_update(struct omap_gpmc_s *s, int value)
114{
115 if (s->prefetch.config1 & 4) {
116 qemu_set_irq(s->drq, value);
117 }
118}
119
120
121
122
123
124static uint64_t omap_nand_read(void *opaque, hwaddr addr,
125 unsigned size)
126{
127 struct omap_gpmc_cs_file_s *f = (struct omap_gpmc_cs_file_s *)opaque;
128 uint64_t v;
129 nand_setpins(f->dev, 0, 0, 0, 1, 0);
130 switch (omap_gpmc_devsize(f)) {
131 case OMAP_GPMC_8BIT:
132 v = nand_getio(f->dev);
133 if (size == 1) {
134 return v;
135 }
136 v |= (nand_getio(f->dev) << 8);
137 if (size == 2) {
138 return v;
139 }
140 v |= (nand_getio(f->dev) << 16);
141 v |= (nand_getio(f->dev) << 24);
142 return v;
143 case OMAP_GPMC_16BIT:
144 v = nand_getio(f->dev);
145 if (size == 1) {
146
147 return v & 0xff;
148 }
149 if (size == 2) {
150 return v;
151 }
152 v |= (nand_getio(f->dev) << 16);
153 return v;
154 default:
155 abort();
156 }
157}
158
159static void omap_nand_setio(DeviceState *dev, uint64_t value,
160 int nandsize, int size)
161{
162
163
164
165 switch (nandsize) {
166 case OMAP_GPMC_8BIT:
167 switch (size) {
168 case 1:
169 nand_setio(dev, value & 0xff);
170 break;
171 case 2:
172 nand_setio(dev, value & 0xff);
173 nand_setio(dev, (value >> 8) & 0xff);
174 break;
175 case 4:
176 default:
177 nand_setio(dev, value & 0xff);
178 nand_setio(dev, (value >> 8) & 0xff);
179 nand_setio(dev, (value >> 16) & 0xff);
180 nand_setio(dev, (value >> 24) & 0xff);
181 break;
182 }
183 break;
184 case OMAP_GPMC_16BIT:
185 switch (size) {
186 case 1:
187
188
189
190 case 2:
191 nand_setio(dev, value & 0xffff);
192 break;
193 case 4:
194 default:
195 nand_setio(dev, value & 0xffff);
196 nand_setio(dev, (value >> 16) & 0xffff);
197 break;
198 }
199 break;
200 }
201}
202
203static void omap_nand_write(void *opaque, hwaddr addr,
204 uint64_t value, unsigned size)
205{
206 struct omap_gpmc_cs_file_s *f = (struct omap_gpmc_cs_file_s *)opaque;
207 nand_setpins(f->dev, 0, 0, 0, 1, 0);
208 omap_nand_setio(f->dev, value, omap_gpmc_devsize(f), size);
209}
210
211static const MemoryRegionOps omap_nand_ops = {
212 .read = omap_nand_read,
213 .write = omap_nand_write,
214 .endianness = DEVICE_NATIVE_ENDIAN,
215};
216
217static void fill_prefetch_fifo(struct omap_gpmc_s *s)
218{
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233 int fptr;
234 int cs = prefetch_cs(s->prefetch.config1);
235 int is16bit = (((s->cs_file[cs].config[0] >> 12) & 3) != 0);
236 int bytes;
237
238
239
240
241 bytes = 64 - s->prefetch.fifopointer;
242 if (bytes > s->prefetch.count) {
243 bytes = s->prefetch.count;
244 }
245 s->prefetch.count -= bytes;
246 s->prefetch.fifopointer += bytes;
247 fptr = 64 - s->prefetch.fifopointer;
248
249
250
251 while (fptr < (64 - bytes)) {
252 s->prefetch.fifo[fptr] = s->prefetch.fifo[fptr + bytes];
253 fptr++;
254 }
255 while (fptr < 64) {
256 if (is16bit) {
257 uint32_t v = omap_nand_read(&s->cs_file[cs], 0, 2);
258 s->prefetch.fifo[fptr++] = v & 0xff;
259 s->prefetch.fifo[fptr++] = (v >> 8) & 0xff;
260 } else {
261 s->prefetch.fifo[fptr++] = omap_nand_read(&s->cs_file[cs], 0, 1);
262 }
263 }
264 if (s->prefetch.startengine && (s->prefetch.count == 0)) {
265
266 s->irqst |= 2;
267 s->prefetch.startengine = 0;
268 }
269
270
271
272
273
274 if (s->prefetch.fifopointer != 0) {
275 omap_gpmc_dma_update(s, 1);
276 }
277 omap_gpmc_int_update(s);
278}
279
280
281
282
283
284static uint64_t omap_gpmc_prefetch_read(void *opaque, hwaddr addr,
285 unsigned size)
286{
287 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
288 uint32_t data;
289 if (s->prefetch.config1 & 1) {
290
291
292
293
294 return 0;
295 }
296
297 if (s->prefetch.fifopointer) {
298 s->prefetch.fifopointer--;
299 }
300 data = s->prefetch.fifo[63 - s->prefetch.fifopointer];
301 if (s->prefetch.fifopointer ==
302 (64 - prefetch_threshold(s->prefetch.config1))) {
303
304
305
306
307 omap_gpmc_dma_update(s, 0);
308 fill_prefetch_fifo(s);
309 }
310 omap_gpmc_int_update(s);
311 return data;
312}
313
314static void omap_gpmc_prefetch_write(void *opaque, hwaddr addr,
315 uint64_t value, unsigned size)
316{
317 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
318 int cs = prefetch_cs(s->prefetch.config1);
319 if ((s->prefetch.config1 & 1) == 0) {
320
321
322
323
324 return;
325 }
326 if (s->prefetch.count == 0) {
327
328
329
330 return;
331 }
332
333
334
335
336
337 int is16bit = (((s->cs_file[cs].config[0] >> 12) & 3) != 0);
338 if (is16bit) {
339
340
341
342 if (s->prefetch.fifopointer == 64) {
343 s->prefetch.fifo[0] = value;
344 s->prefetch.fifopointer--;
345 } else {
346 value = (value << 8) | s->prefetch.fifo[0];
347 omap_nand_write(&s->cs_file[cs], 0, value, 2);
348 s->prefetch.count--;
349 s->prefetch.fifopointer = 64;
350 }
351 } else {
352
353 omap_nand_write(&s->cs_file[cs], 0, value, 1);
354 s->prefetch.count--;
355 }
356 if (s->prefetch.count == 0) {
357
358 s->irqst |= 2;
359 s->prefetch.startengine = 0;
360 }
361 omap_gpmc_int_update(s);
362}
363
364static const MemoryRegionOps omap_prefetch_ops = {
365 .read = omap_gpmc_prefetch_read,
366 .write = omap_gpmc_prefetch_write,
367 .endianness = DEVICE_NATIVE_ENDIAN,
368 .impl.min_access_size = 1,
369 .impl.max_access_size = 1,
370};
371
372static MemoryRegion *omap_gpmc_cs_memregion(struct omap_gpmc_s *s, int cs)
373{
374
375 struct omap_gpmc_cs_file_s *f = &s->cs_file[cs];
376 if (omap_gpmc_devtype(f) == OMAP_GPMC_NOR) {
377 return f->iomem;
378 }
379 if ((s->prefetch.config1 & 0x80) &&
380 (prefetch_cs(s->prefetch.config1) == cs)) {
381
382 return &s->prefetch.iomem;
383 }
384 return &f->nandiomem;
385}
386
387static void omap_gpmc_cs_map(struct omap_gpmc_s *s, int cs)
388{
389 struct omap_gpmc_cs_file_s *f = &s->cs_file[cs];
390 uint32_t mask = (f->config[6] >> 8) & 0xf;
391 uint32_t base = f->config[6] & 0x3f;
392 uint32_t size;
393
394 if (!f->iomem && !f->dev) {
395 return;
396 }
397
398 if (!(f->config[6] & (1 << 6))) {
399
400 return;
401 }
402
403
404 if (mask != 0x8 && mask != 0xc && mask != 0xe && mask != 0xf
405 && !(s->accept_256 && !mask)) {
406 fprintf(stderr, "%s: invalid chip-select mask address (0x%x)\n",
407 __func__, mask);
408 }
409
410 base <<= 24;
411 size = (0x0fffffff & ~(mask << 24)) + 1;
412
413
414
415
416 memory_region_init(&f->container, "omap-gpmc-file", size);
417 memory_region_add_subregion(&f->container, 0,
418 omap_gpmc_cs_memregion(s, cs));
419 memory_region_add_subregion(get_system_memory(), base,
420 &f->container);
421}
422
423static void omap_gpmc_cs_unmap(struct omap_gpmc_s *s, int cs)
424{
425 struct omap_gpmc_cs_file_s *f = &s->cs_file[cs];
426 if (!(f->config[6] & (1 << 6))) {
427
428 return;
429 }
430 if (!f->iomem && !f->dev) {
431 return;
432 }
433 memory_region_del_subregion(get_system_memory(), &f->container);
434 memory_region_del_subregion(&f->container, omap_gpmc_cs_memregion(s, cs));
435 memory_region_destroy(&f->container);
436}
437
438void omap_gpmc_reset(struct omap_gpmc_s *s)
439{
440 int i;
441
442 s->sysconfig = 0;
443 s->irqst = 0;
444 s->irqen = 0;
445 omap_gpmc_int_update(s);
446 for (i = 0; i < 8; i++) {
447
448
449
450 omap_gpmc_cs_unmap(s, i);
451 }
452 s->timeout = 0;
453 s->config = 0xa00;
454 s->prefetch.config1 = 0x00004000;
455 s->prefetch.transfercount = 0x00000000;
456 s->prefetch.startengine = 0;
457 s->prefetch.fifopointer = 0;
458 s->prefetch.count = 0;
459 for (i = 0; i < 8; i ++) {
460 s->cs_file[i].config[1] = 0x101001;
461 s->cs_file[i].config[2] = 0x020201;
462 s->cs_file[i].config[3] = 0x10031003;
463 s->cs_file[i].config[4] = 0x10f1111;
464 s->cs_file[i].config[5] = 0;
465 s->cs_file[i].config[6] = 0xf00 | (i ? 0 : 1 << 6);
466
467 s->cs_file[i].config[6] = 0xf00;
468
469
470
471
472 if (i == 0) {
473 s->cs_file[i].config[0] &= 0x00433e00;
474 s->cs_file[i].config[6] |= 1 << 6;
475 omap_gpmc_cs_map(s, i);
476 } else {
477 s->cs_file[i].config[0] &= 0x00403c00;
478 }
479 }
480 s->ecc_cs = 0;
481 s->ecc_ptr = 0;
482 s->ecc_cfg = 0x3fcff000;
483 for (i = 0; i < 9; i ++)
484 ecc_reset(&s->ecc[i]);
485}
486
487static int gpmc_wordaccess_only(hwaddr addr)
488{
489
490
491
492
493
494 if (addr >= 0x60 && addr <= 0x1d4) {
495 int cs = (addr - 0x60) / 0x30;
496 addr -= cs * 0x30;
497 if (addr >= 0x7c && addr < 0x88) {
498
499 return 0;
500 }
501 }
502 return 1;
503}
504
505static uint64_t omap_gpmc_read(void *opaque, hwaddr addr,
506 unsigned size)
507{
508 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
509 int cs;
510 struct omap_gpmc_cs_file_s *f;
511
512 if (size != 4 && gpmc_wordaccess_only(addr)) {
513 return omap_badwidth_read32(opaque, addr);
514 }
515
516 switch (addr) {
517 case 0x000:
518 return s->revision;
519
520 case 0x010:
521 return s->sysconfig;
522
523 case 0x014:
524 return 1;
525
526 case 0x018:
527 return s->irqst;
528
529 case 0x01c:
530 return s->irqen;
531
532 case 0x040:
533 return s->timeout;
534
535 case 0x044:
536 case 0x048:
537 return 0;
538
539 case 0x050:
540 return s->config;
541
542 case 0x054:
543 return 0x001;
544
545 case 0x060 ... 0x1d4:
546 cs = (addr - 0x060) / 0x30;
547 addr -= cs * 0x30;
548 f = s->cs_file + cs;
549 switch (addr) {
550 case 0x60:
551 return f->config[0];
552 case 0x64:
553 return f->config[1];
554 case 0x68:
555 return f->config[2];
556 case 0x6c:
557 return f->config[3];
558 case 0x70:
559 return f->config[4];
560 case 0x74:
561 return f->config[5];
562 case 0x78:
563 return f->config[6];
564 case 0x84 ... 0x87:
565 if (omap_gpmc_devtype(f) == OMAP_GPMC_NAND) {
566 return omap_nand_read(f, 0, size);
567 }
568 return 0;
569 }
570 break;
571
572 case 0x1e0:
573 return s->prefetch.config1;
574 case 0x1e4:
575 return s->prefetch.transfercount;
576 case 0x1ec:
577 return s->prefetch.startengine;
578 case 0x1f0:
579
580
581
582
583
584
585
586 return (s->prefetch.fifopointer << 24) |
587 ((s->prefetch.fifopointer >=
588 ((s->prefetch.config1 >> 8) & 0x7f) ? 1 : 0) << 16) |
589 s->prefetch.count;
590
591 case 0x1f4:
592 return s->ecc_cs;
593 case 0x1f8:
594 return s->ecc_ptr;
595 case 0x1fc:
596 return s->ecc_cfg;
597 case 0x200 ... 0x220:
598 cs = (addr & 0x1f) >> 2;
599
600 return
601 ((s->ecc[cs].cp & 0x07) << 0) |
602 ((s->ecc[cs].cp & 0x38) << 13) |
603 ((s->ecc[cs].lp[0] & 0x1ff) << 3) |
604 ((s->ecc[cs].lp[1] & 0x1ff) << 19);
605
606 case 0x230:
607 return 0;
608 case 0x234:
609 case 0x238:
610 return 0x00000000;
611 }
612
613 OMAP_BAD_REG(addr);
614 return 0;
615}
616
617static void omap_gpmc_write(void *opaque, hwaddr addr,
618 uint64_t value, unsigned size)
619{
620 struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque;
621 int cs;
622 struct omap_gpmc_cs_file_s *f;
623
624 if (size != 4 && gpmc_wordaccess_only(addr)) {
625 return omap_badwidth_write32(opaque, addr, value);
626 }
627
628 switch (addr) {
629 case 0x000:
630 case 0x014:
631 case 0x054:
632 case 0x1f0:
633 case 0x200 ... 0x220:
634 case 0x234:
635 case 0x238:
636 OMAP_RO_REG(addr);
637 break;
638
639 case 0x010:
640 if ((value >> 3) == 0x3)
641 fprintf(stderr, "%s: bad SDRAM idle mode %"PRIi64"\n",
642 __FUNCTION__, value >> 3);
643 if (value & 2)
644 omap_gpmc_reset(s);
645 s->sysconfig = value & 0x19;
646 break;
647
648 case 0x018:
649 s->irqst &= ~value;
650 omap_gpmc_int_update(s);
651 break;
652
653 case 0x01c:
654 s->irqen = value & 0xf03;
655 omap_gpmc_int_update(s);
656 break;
657
658 case 0x040:
659 s->timeout = value & 0x1ff1;
660 break;
661
662 case 0x044:
663 case 0x048:
664 break;
665
666 case 0x050:
667 s->config = value & 0xf13;
668 break;
669
670 case 0x060 ... 0x1d4:
671 cs = (addr - 0x060) / 0x30;
672 addr -= cs * 0x30;
673 f = s->cs_file + cs;
674 switch (addr) {
675 case 0x60:
676 f->config[0] = value & 0xffef3e13;
677 break;
678 case 0x64:
679 f->config[1] = value & 0x001f1f8f;
680 break;
681 case 0x68:
682 f->config[2] = value & 0x001f1f8f;
683 break;
684 case 0x6c:
685 f->config[3] = value & 0x1f8f1f8f;
686 break;
687 case 0x70:
688 f->config[4] = value & 0x0f1f1f1f;
689 break;
690 case 0x74:
691 f->config[5] = value & 0x00000fcf;
692 break;
693 case 0x78:
694 if ((f->config[6] ^ value) & 0xf7f) {
695 omap_gpmc_cs_unmap(s, cs);
696 f->config[6] = value & 0x00000f7f;
697 omap_gpmc_cs_map(s, cs);
698 }
699 break;
700 case 0x7c ... 0x7f:
701 if (omap_gpmc_devtype(f) == OMAP_GPMC_NAND) {
702 nand_setpins(f->dev, 1, 0, 0, 1, 0);
703 omap_nand_setio(f->dev, value, omap_gpmc_devsize(f), size);
704 }
705 break;
706 case 0x80 ... 0x83:
707 if (omap_gpmc_devtype(f) == OMAP_GPMC_NAND) {
708 nand_setpins(f->dev, 0, 1, 0, 1, 0);
709 omap_nand_setio(f->dev, value, omap_gpmc_devsize(f), size);
710 }
711 break;
712 case 0x84 ... 0x87:
713 if (omap_gpmc_devtype(f) == OMAP_GPMC_NAND) {
714 omap_nand_write(f, 0, value, size);
715 }
716 break;
717 default:
718 goto bad_reg;
719 }
720 break;
721
722 case 0x1e0:
723 if (!s->prefetch.startengine) {
724 uint32_t newconfig1 = value & 0x7f8f7fbf;
725 uint32_t changed;
726 changed = newconfig1 ^ s->prefetch.config1;
727 if (changed & (0x80 | 0x7000000)) {
728
729
730
731
732
733
734
735
736 int oldcs = prefetch_cs(s->prefetch.config1);
737 int newcs = prefetch_cs(newconfig1);
738 omap_gpmc_cs_unmap(s, oldcs);
739 if (oldcs != newcs) {
740 omap_gpmc_cs_unmap(s, newcs);
741 }
742 s->prefetch.config1 = newconfig1;
743 omap_gpmc_cs_map(s, oldcs);
744 if (oldcs != newcs) {
745 omap_gpmc_cs_map(s, newcs);
746 }
747 } else {
748 s->prefetch.config1 = newconfig1;
749 }
750 }
751 break;
752
753 case 0x1e4:
754 if (!s->prefetch.startengine) {
755 s->prefetch.transfercount = value & 0x3fff;
756 }
757 break;
758
759 case 0x1ec:
760 if (s->prefetch.startengine != (value & 1)) {
761 s->prefetch.startengine = value & 1;
762 if (s->prefetch.startengine) {
763
764 s->prefetch.count = s->prefetch.transfercount;
765 if (s->prefetch.config1 & 1) {
766
767 s->prefetch.fifopointer = 64;
768 } else {
769
770 s->prefetch.fifopointer = 0;
771 fill_prefetch_fifo(s);
772 }
773 } else {
774
775
776
777
778
779
780
781 s->prefetch.count = 0;
782 }
783 omap_gpmc_int_update(s);
784 }
785 break;
786
787 case 0x1f4:
788 s->ecc_cs = 0x8f;
789 break;
790 case 0x1f8:
791 if (value & (1 << 8))
792 for (cs = 0; cs < 9; cs ++)
793 ecc_reset(&s->ecc[cs]);
794 s->ecc_ptr = value & 0xf;
795 if (s->ecc_ptr == 0 || s->ecc_ptr > 9) {
796 s->ecc_ptr = 0;
797 s->ecc_cs &= ~1;
798 }
799 break;
800 case 0x1fc:
801 s->ecc_cfg = value & 0x3fcff1ff;
802 break;
803 case 0x230:
804 if (value & 7)
805 fprintf(stderr, "%s: test mode enable attempt\n", __FUNCTION__);
806 break;
807
808 default:
809 bad_reg:
810 OMAP_BAD_REG(addr);
811 return;
812 }
813}
814
815static const MemoryRegionOps omap_gpmc_ops = {
816 .read = omap_gpmc_read,
817 .write = omap_gpmc_write,
818 .endianness = DEVICE_NATIVE_ENDIAN,
819};
820
821struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu,
822 hwaddr base,
823 qemu_irq irq, qemu_irq drq)
824{
825 int cs;
826 struct omap_gpmc_s *s = (struct omap_gpmc_s *)
827 g_malloc0(sizeof(struct omap_gpmc_s));
828
829 memory_region_init_io(&s->iomem, &omap_gpmc_ops, s, "omap-gpmc", 0x1000);
830 memory_region_add_subregion(get_system_memory(), base, &s->iomem);
831
832 s->irq = irq;
833 s->drq = drq;
834 s->accept_256 = cpu_is_omap3630(mpu);
835 s->revision = cpu_class_omap3(mpu) ? 0x50 : 0x20;
836 s->lastirq = 0;
837 omap_gpmc_reset(s);
838
839
840
841
842
843
844
845 for (cs = 0; cs < 8; cs++) {
846 memory_region_init_io(&s->cs_file[cs].nandiomem,
847 &omap_nand_ops,
848 &s->cs_file[cs],
849 "omap-nand",
850 256 * 1024 * 1024);
851 }
852
853 memory_region_init_io(&s->prefetch.iomem, &omap_prefetch_ops, s,
854 "omap-gpmc-prefetch", 256 * 1024 * 1024);
855 return s;
856}
857
858void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, MemoryRegion *iomem)
859{
860 struct omap_gpmc_cs_file_s *f;
861 assert(iomem);
862
863 if (cs < 0 || cs >= 8) {
864 fprintf(stderr, "%s: bad chip-select %i\n", __FUNCTION__, cs);
865 exit(-1);
866 }
867 f = &s->cs_file[cs];
868
869 omap_gpmc_cs_unmap(s, cs);
870 f->config[0] &= ~(0xf << 10);
871 f->iomem = iomem;
872 omap_gpmc_cs_map(s, cs);
873}
874
875void omap_gpmc_attach_nand(struct omap_gpmc_s *s, int cs, DeviceState *nand)
876{
877 struct omap_gpmc_cs_file_s *f;
878 assert(nand);
879
880 if (cs < 0 || cs >= 8) {
881 fprintf(stderr, "%s: bad chip-select %i\n", __func__, cs);
882 exit(-1);
883 }
884 f = &s->cs_file[cs];
885
886 omap_gpmc_cs_unmap(s, cs);
887 f->config[0] &= ~(0xf << 10);
888 f->config[0] |= (OMAP_GPMC_NAND << 10);
889 f->dev = nand;
890 if (nand_getbuswidth(f->dev) == 16) {
891 f->config[0] |= OMAP_GPMC_16BIT << 12;
892 }
893 omap_gpmc_cs_map(s, cs);
894}
895