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