1
From f0a8899fc97a07be328a903ba2e055a772461baa Mon Sep 17 00:00:00 2001
2
From: Peter Maydell <peter.maydell@linaro.org>
3
Date: Mon, 18 Feb 2013 16:58:30 +0000
4
Subject: [PATCH 43/70] add hw/omap3_mmc.c
6
Content-Type: text/plain; charset=UTF-8
7
Content-Transfer-Encoding: 8bit
9
Add omap3 specific mmc/sd driver
11
omap3_mmc: fix cmd12/52 handling during inactive data transfer
13
Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
15
omap3_mmc qdev conversion
17
Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
19
make-omap3_mmc-status-register
21
make omap3_mmc status register directly accessible
23
Changes in the status register are immediately in effect, i.e. the guest
24
does not need to read the status register first before writing changes to it.
25
This change may cause problems if guest code does not handle properly the
26
case where transfers get completed immediately when initiated.
28
Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
30
hw-omap3_mmc-c-use-symbolic-co
32
hw/omap3_mmc.c: Use symbolic constants for status register bits
34
Use symbolic constants rather than hardcoded numeric values for the
35
OMAP3 MMC status register bits, to improve readability.
37
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
39
hw-omap3_mmc-c-set-tc-status-b
41
hw/omap3_mmc.c: Set TC status bit for R1b no-data commands
43
We emulate MMC commands with response type R1b and no data transfer
44
instantaneously, so we must set the TC bit as well as the CC bit,
45
to indicate that the "busy" period has ended.
47
Without this fix the Linux driver will hang waiting for a TC interrupt
48
that never happens when it tries to do a block erase.
50
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
52
hw/sd/Makefile.objs | 1 +
53
hw/sd/omap3_mmc.c | 801 ++++++++++++++++++++++++++++++++++++++++++++++++++
54
include/hw/arm/omap.h | 4 +
55
3 files changed, 806 insertions(+)
56
create mode 100644 hw/sd/omap3_mmc.c
58
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
59
index f1aed83..aee6af2 100644
60
--- a/hw/sd/Makefile.objs
61
+++ b/hw/sd/Makefile.objs
62
@@ -5,4 +5,5 @@ common-obj-$(CONFIG_SDHCI) += sdhci.o
64
obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
65
obj-$(CONFIG_OMAP) += omap_mmc.o
66
+obj-$(CONFIG_OMAP) += omap3_mmc.o
67
obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
68
diff --git a/hw/sd/omap3_mmc.c b/hw/sd/omap3_mmc.c
70
index 0000000..1aa233d
72
+++ b/hw/sd/omap3_mmc.c
75
+ * OMAP3 MMC/SD/SDIO interface emulation
77
+ * Copyright (C) 2008 yajin <yajin@vm-kernel.org>
78
+ * Copyright (C) 2009 Nokia Corporation
80
+ * This program is free software; you can redistribute it and/or
81
+ * modify it under the terms of the GNU General Public License as
82
+ * published by the Free Software Foundation; either version 2 or
83
+ * (at your option) version 3 of the License.
85
+ * This program is distributed in the hope that it will be useful,
86
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
87
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88
+ * GNU General Public License for more details.
90
+ * You should have received a copy of the GNU General Public License
91
+ * along with this program; if not, write to the Free Software
92
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
96
+#include "hw/arm/omap.h"
98
+#include "hw/sysbus.h"
102
+ 1 - print non-fatal errors
103
+ 2 - print out all commands in processing order
104
+ 3 - dump all register accesses and buffer management */
105
+#define MMC_DEBUG_LEVEL 0
107
+#if MMC_DEBUG_LEVEL>0
108
+#define TRACE(fmt,...) fprintf(stderr, "%s: " fmt "\n", \
109
+ __FUNCTION__, ##__VA_ARGS__)
114
+#if MMC_DEBUG_LEVEL>1
115
+#define TRACE1(...) TRACE(__VA_ARGS__)
120
+#if MMC_DEBUG_LEVEL>2
121
+#define TRACE2(...) TRACE(__VA_ARGS__)
126
+#define TYPE_OMAP3_MMC "omap3_mmc"
127
+#define OMAP3_MMC(obj) OBJECT_CHECK(OMAP3MMCState, (obj), TYPE_OMAP3_MMC)
129
+typedef struct OMAP3MMCState {
130
+ SysBusDevice parent_obj;
132
+ MemoryRegion iomem;
135
+ qemu_irq coverswitch;
139
+ uint32_t sysconfig;
140
+ uint32_t sysstatus;
164
+ uint16_t blen_counter;
165
+ uint16_t nblk_counter;
167
+ uint32_t fifo[256];
176
+/* Bit names for STAT/IC/IE registers */
177
+#define STAT_CC (1 << 0)
178
+#define STAT_TC (1 << 1)
179
+#define STAT_BGE (1 << 2)
180
+#define STAT_BWR (1 << 4)
181
+#define STAT_BRR (1 << 5)
182
+#define STAT_CIRQ (1 << 8)
183
+#define STAT_OBI (1 << 9)
184
+#define STAT_ERRI (1 << 15)
185
+#define STAT_CTO (1 << 16)
186
+#define STAT_CCRC (1 << 17)
187
+#define STAT_CEB (1 << 18)
188
+#define STAT_CIE (1 << 19)
189
+#define STAT_DTO (1 << 20)
190
+#define STAT_DCRC (1 << 21)
191
+#define STAT_DEB (1 << 22)
192
+#define STAT_ACE (1 << 24)
193
+#define STAT_CERR (1 << 28)
194
+#define STAT_BADA (1 << 29)
197
+ (STAT_CC|STAT_TC|STAT_BGE| \
198
+ STAT_BWR|STAT_BRR| \
199
+ STAT_CIRQ|STAT_OBI| \
201
+ STAT_CTO|STAT_CCRC|STAT_CEB|STAT_CIE| \
202
+ STAT_DTO|STAT_DCRC|STAT_DEB| \
203
+ STAT_ACE|STAT_CERR|STAT_BADA)
205
+static void omap3_mmc_reset(DeviceState *dev)
207
+ OMAP3MMCState *s = OMAP3_MMC(dev);
209
+ s->sysconfig = 0x00000015;
213
+ s->con = 0x00000500;
223
+ s->pstate = 0x00040000;
230
+ s->capa = 0x00e10080;
232
+ s->rev = 0x26000000;
234
+ s->blen_counter = 0;
235
+ s->nblk_counter = 0;
237
+ memset(s->fifo, 0, sizeof(s->fifo));
252
+ sd_nore = 0, /* no response */
253
+ sd_136_bits = 1, /* response length 136 bits */
254
+ sd_48_bits = 2, /* response length 48 bits */
255
+ sd_48b_bits = 3, /* response length 48 bits with busy after response */
256
+} omap3_sd_rsp_type_t;
258
+static void omap3_mmc_command(OMAP3MMCState *host);
260
+static void omap3_mmc_interrupts_update(OMAP3MMCState *s)
262
+ qemu_set_irq(s->irq, !!(s->stat & s->ie & s->ise));
265
+static void omap3_mmc_fifolevel_update(OMAP3MMCState *host)
267
+ enum { ongoing, ready, aborted } state = ongoing;
269
+ if ((host->cmd & (1 << 21))) { /* DP */
271
+ TRACE2("receive, dma=%d, fifo_len=%d bytes",
272
+ host->cmd & 1, host->fifo_len * 4);
274
+ /* omap3_mmc_transfer ensures we always have data in FIFO
275
+ during receive as long as all data has not been transferred -
276
+ NOTE that the actual transfer may be finished already (i.e.
277
+ host->transfer is cleared) but not all data has been read out
279
+ if (host->fifo_len) {
280
+ if (host->cmd & 1) { /* DE */
281
+ if (host->fifo_len * 4 == (host->blk & 0x7ff)) { /* BLEN */
285
+ qemu_irq_raise(host->dma[1]);
287
+ qemu_irq_lower(host->dma[1]);
290
+ && host->fifo_len * 4 == (host->blk & 0x7ff))
293
+ host->pstate |= 0x0800; /* BRE */
294
+ host->stat |= STAT_BRR;
299
+ state = host->stop ? aborted : ready;
301
+ /* omap3_mmc_transfer keeps FIFO empty during transmit so
302
+ we just check all blocks have been transferred or not */
303
+ if (host->transfer) {
304
+ if (host->cmd & 1) { /* DE */
305
+ if (host->blen_counter == (host->blk & 0x7ff)) { /* BLEN */
309
+ qemu_irq_raise(host->dma[0]);
311
+ qemu_irq_lower(host->dma[0]);
314
+ && host->blen_counter == (host->blk & 0x7ff))
317
+ host->pstate |= 0x0400; /* BWE */
318
+ host->stat |= STAT_BWR;
322
+ state = host->stop ? aborted : ready;
325
+ if ((host->cmd & 1) || state != ongoing) { /* DE */
326
+ host->pstate &= ~0x0c00; /* BRE | BWE */
327
+ host->stat &= ~(STAT_BRR | STAT_BWR);
328
+ if (state != ongoing) {
329
+ TRACE2("transfer %s",
332
+ : "aborted --> complete");
333
+ host->stat |= STAT_TC;
334
+ if (host->cmd & 0x04) { /* ACEN */
335
+ host->stop = 0x0cc30000;
338
+ if (state == aborted) {
339
+ host->cmd = host->stop;
341
+ omap3_mmc_command(host);
348
+static void omap3_mmc_transfer(OMAP3MMCState *host)
352
+#if MMC_DEBUG_LEVEL>1
354
+ uint8_t c, sym[17];
357
+ /* IF data transfer is inactive
358
+ OR block count enabled with zero block count
359
+ OR in receive mode and we have unread data in FIFO
360
+ OR in transmit mode and we have no data in FIFO,
361
+ THEN don't do anything */
362
+ if (!host->transfer
363
+ || ((host->cmd & 2) && !host->nblk_counter)
364
+ || (host->ddir && host->fifo_len)
365
+ || (!host->ddir && !host->fifo_len))
369
+ TRACE2("begin, %d blocks (%d bytes/block) left to receive, %d bytes in FIFO",
370
+ (host->cmd & 2) ? host->nblk_counter : 1,
372
+ host->fifo_len * 4);
373
+ while (host->blen_counter && host->fifo_len < 255) {
374
+ for (i = 0, x = 0; i < 32 && host->blen_counter; i += 8, host->blen_counter--)
375
+ x |= sd_read_data(host->card) << i;
376
+ host->fifo[(host->fifo_start + host->fifo_len) & 0xff] = x;
379
+ TRACE2("end, %d bytes in FIFO:", host->fifo_len * 4);
380
+#if MMC_DEBUG_LEVEL>1
381
+ for (i = 0; i < host->fifo_len; ) {
382
+ fprintf(stderr, "%s: [0x%03x] ", __FUNCTION__, i * 4);
384
+ x = host->fifo[(host->fifo_start + i) & 0xff];
385
+ for (j = 0; j < 4; j++) {
386
+ c = (x >> (j * 8)) & 0xff;
387
+ fprintf(stderr, "%02x ", c);
388
+ sym[(i & 3) * 4 + j] = (c < 32 || c > 126) ? '.' : c;
390
+ } while (((++i) & 3));
392
+ fprintf(stderr, "%s\n", sym);
396
+ TRACE2("%d bytes left to transmit in current block", host->blen_counter);
397
+ while (host->blen_counter && host->fifo_len) {
398
+ for (i = 0; i < 32 && host->blen_counter; i += 8, host->blen_counter--)
399
+ sd_write_data(host->card, (host->fifo[host->fifo_start] >> i) & 0xff);
400
+ host->fifo_start++;
402
+ host->fifo_start &= 0xff;
406
+ if (!host->blen_counter) {
407
+ if (host->cmd & 2) /* BCE */
408
+ host->nblk_counter--;
409
+ TRACE2("block done, %d blocks left",
410
+ (host->cmd & (1 << 5)) ? host->nblk_counter : 0);
411
+ host->blen_counter = host->blk & 0x7ff;
412
+ if (!(host->cmd & (1 << 5)) /* MSBS */
413
+ || !host->nblk_counter) {
414
+ host->nblk_counter = (host->blk >> 16) & 0xffff;
415
+ host->transfer = 0;
416
+ host->pstate &= ~0x0306; /* RTA | WTA | DLA | DATI */
421
+static void omap3_mmc_command(OMAP3MMCState *s)
423
+ uint32_t rspstatus, mask;
424
+ int rsplen, timeout;
426
+ uint8_t response[16];
427
+ int cmd = (s->cmd >> 24) & 0x3f; /* INDX */
428
+ int rsptype = (s->cmd >> 16) & 3;
429
+ int dp = s->cmd & (1 << 21);
431
+ TRACE1("%d type=%d rsp=%d arg=0x%08x blk=0x%08x, fifo=%d/%d",
432
+ cmd, (s->cmd >> 22) & 3, (s->cmd >> 16) & 3, s->arg,
433
+ s->blk, s->fifo_start, s->fifo_len);
435
+ if ((s->con & 2) && !cmd) { /* INIT and CMD0 */
436
+ s->stat |= STAT_CC;
437
+ s->pstate &= 0xfffffffe;
445
+ s->ddir = (s->cmd >> 4) & 1;
446
+ /* DLA | DATI | (RTA/WTA) */
447
+ s->pstate |= 0x6 | (s->ddir ? 0x200 : 0x100);
450
+ s->pstate &= ~0x306; /* RTA | WTA | DLA | DATI */
458
+ request.arg = s->arg;
459
+ request.crc = 0; /* FIXME */
461
+ rsplen = sd_do_command(s->card, &request, response);
473
+ s->rsp76 = (response[0] << 24) | (response[1] << 16) |
474
+ (response[2] << 8) | (response[3] << 0);
475
+ s->rsp54 = (response[4] << 24) | (response[5] << 16) |
476
+ (response[6] << 8) | (response[7] << 0);
477
+ s->rsp32 = (response[8] << 24) | (response[9] << 16) |
478
+ (response[10] << 8) | (response[11] << 0);
479
+ s->rsp10 = (response[12] << 24) | (response[13] << 16) |
480
+ (response[14] << 8) | (response[15] << 0);
489
+ s->rsp10 = (response[0] << 24) | (response[1] << 16) |
490
+ (response[2] << 8) | (response[3] << 0);
496
+ rspstatus = (response[2] << 8) | response[3];
499
+ if (cmd == 8 && !sd_is_mmc(s->card)) {
503
+ mask = OUT_OF_RANGE | ADDRESS_ERROR | BLOCK_LEN_ERROR |
504
+ ERASE_SEQ_ERROR | ERASE_PARAM | WP_VIOLATION |
505
+ LOCK_UNLOCK_FAILED | COM_CRC_ERROR | ILLEGAL_COMMAND |
506
+ CARD_ECC_FAILED | CC_ERROR | SD_ERROR |
507
+ CID_CSD_OVERWRITE | WP_ERASE_SKIP;
508
+ rspstatus = (response[0] << 24) | (response[1] << 16) |
509
+ (response[2] << 8) | (response[3] << 0);
516
+ if (cmd == 12 || cmd == 52) { /* stop transfer commands */
517
+ /*s->fifo_start = 0;*/
518
+ /*s->fifo_len = 0;*/
520
+ s->pstate &= ~0x0f06; /* BRE | BWE | RTA | WTA | DLA | DATI */
521
+ s->stat &= ~(STAT_BRR | STAT_BWR);
522
+ s->stat |= STAT_TC;
523
+ qemu_irq_lower(s->dma[0]);
524
+ qemu_irq_lower(s->dma[1]);
527
+ if (rspstatus & mask & s->csre) {
528
+ s->stat |= STAT_CERR;
529
+ s->pstate &= ~0x306; /* RTA | WTA | DLA | DATI */
532
+ s->stat &= ~STAT_CERR;
533
+ /* If this is an R1b command with no data transfer and
534
+ * there wasn't an error, then we have effectively
535
+ * emulated the command as having a zero length "busy"
536
+ * response. Set TC to tell the driver the "busy" period
539
+ if (!timeout && !dp && rsptype == sd_48b_bits) {
540
+ s->stat |= STAT_TC;
543
+ s->stat |= timeout ? STAT_CTO : STAT_CC;
546
+static uint32_t omap3_mmc_read(void *opaque, hwaddr addr)
548
+ OMAP3MMCState *s = (OMAP3MMCState *) opaque;
553
+ TRACE2("SYSCONFIG = %08x", s->sysconfig);
554
+ return s->sysconfig;
556
+ TRACE2("SYSSTATUS = %08x", s->sysstatus | 0x1);
557
+ return s->sysstatus | 0x1; /*reset completed */
559
+ TRACE2("CSRE = %08x", s->csre);
562
+ TRACE2("SYSTEST = %08x", s->systest);
564
+ case 0x2c: /* MMCHS_CON */
565
+ TRACE2("CON = %08x", s->con);
568
+ TRACE2("PWCNT = %08x", s->pwcnt);
570
+ case 0x104: /* MMCHS_BLK */
571
+ TRACE2("BLK = %08x", s->blk);
573
+ case 0x108: /* MMCHS_ARG */
574
+ TRACE2("ARG = %08x", s->arg);
577
+ TRACE2("CMD = %08x", s->cmd);
580
+ TRACE2("RSP10 = %08x", s->rsp10);
583
+ TRACE2("RSP32 = %08x", s->rsp32);
586
+ TRACE2("RSP54 = %08x", s->rsp54);
589
+ TRACE2("RSP76 = %08x", s->rsp76);
592
+ /* in PIO mode, access allowed only when BRE is set */
593
+ if (!(s->cmd & 1) && !(s->pstate & 0x0800)) {
594
+ s->stat |= STAT_BADA;
597
+ i = s->fifo[s->fifo_start];
598
+ s->fifo[s->fifo_start] = 0;
599
+ if (s->fifo_len == 0) {
600
+ TRACE("FIFO underrun");
605
+ s->fifo_start &= 255;
606
+ omap3_mmc_transfer(s);
607
+ omap3_mmc_fifolevel_update(s);
609
+ omap3_mmc_interrupts_update(s);
611
+ case 0x124: /* MMCHS_PSTATE */
612
+ TRACE2("PSTATE = %08x", s->pstate);
615
+ TRACE2("HCTL = %08x", s->hctl);
617
+ case 0x12c: /* MMCHS_SYSCTL */
618
+ TRACE2("SYSCTL = %08x", s->sysctl);
620
+ case 0x130: /* MMCHS_STAT */
621
+ if (s->stat & 0xffff0000)
622
+ s->stat |= STAT_ERRI;
624
+ s->stat &= ~STAT_ERRI;
625
+ TRACE2("STAT = %08x", s->stat);
628
+ TRACE2("IE = %08x", s->ie);
631
+ TRACE2("ISE = %08x", s->ise);
634
+ TRACE2("AC12 = %08x", s->ac12);
636
+ case 0x140: /* MMCHS_CAPA */
637
+ TRACE2("CAPA = %08x", s->capa);
640
+ TRACE2("CUR_CAPA = %08x", s->cur_capa);
641
+ return s->cur_capa;
643
+ TRACE2("REV = %08x", s->rev);
646
+ OMAP_BAD_REG(addr);
652
+static void omap3_mmc_write(void *opaque, hwaddr addr,
655
+ OMAP3MMCState *s = (OMAP3MMCState *) opaque;
669
+ TRACE2("SYSCONFIG = %08x", value);
671
+ omap3_mmc_reset(DEVICE(s));
672
+ s->sysconfig = value & 0x31d;
675
+ TRACE2("CSRE = %08x", value);
679
+ TRACE2("SYSTEST = %08x", value);
680
+ s->systest = value;
682
+ case 0x02c: /* MMCHS_CON */
683
+ TRACE2("CON = %08x", value);
684
+ if (value & 0x10) { /* MODE */
685
+ TRACE("SYSTEST mode is not supported");
687
+ if ((value & 0x20) && !sd_is_mmc(s->card)) { /* DW8 */
688
+ TRACE("8-bit data width is not supported for SD cards");
690
+ if (value & 0x1000) { /* CEATA */
691
+ TRACE("CE-ATA control mode not supported");
693
+ s->con = value & 0x1ffff;
696
+ TRACE2("PWCNT = %08x", value);
699
+ case 0x104: /* MMCHS_BLK */
700
+ TRACE2("BLK = %08x", value);
701
+ s->blk = value & 0xffff07ff;
702
+ s->blen_counter = value & 0x7ff;
703
+ s->nblk_counter = (value >> 16) & 0xffff;
705
+ case 0x108: /* MMCHS_ARG */
706
+ TRACE2("ARG = %08x", value);
709
+ case 0x10c: /* MMCHS_CMD */
710
+ TRACE2("CMD = %08x", value);
712
+ s->stat |= STAT_CTO;
714
+ /* TODO: writing to bits 0-15 should have no effect during
715
+ an active data transfer */
716
+ if (s->transfer && !s->stop
717
+ && (((value >> 24) & 0x3f) == 12
718
+ || ((value >> 24) & 0x3f) == 52)) {
719
+ s->stop = value & 0x3ffb0037;
721
+ s->cmd = value & 0x3ffb0037;
722
+ omap3_mmc_command(s);
724
+ omap3_mmc_transfer(s);
725
+ omap3_mmc_fifolevel_update(s);
727
+ omap3_mmc_interrupts_update(s);
730
+ /* in PIO mode, access allowed only when BWE is set */
731
+ if (!(s->cmd & 1) && !(s->pstate & 0x0400)) {
732
+ s->stat |= STAT_BADA;
734
+ if (s->fifo_len == 256) {
735
+ TRACE("FIFO overrun");
738
+ s->fifo[(s->fifo_start + s->fifo_len) & 255] = value;
740
+ omap3_mmc_transfer(s);
741
+ omap3_mmc_fifolevel_update(s);
743
+ omap3_mmc_interrupts_update(s);
745
+ case 0x128: /* MMCHS_HCTL */
746
+ TRACE2("HCTL = %08x", value);
747
+ s->hctl = value & 0xf0f0f02;
748
+ if (s->hctl & (1 << 16)) { /* SBGR */
749
+ TRACE("Stop at block gap feature not implemented!");
752
+ case 0x12c: /* MMCHS_SYSCTL */
753
+ TRACE2("SYSCTL = %08x", value);
754
+ if (value & 0x04000000) { /* SRD */
756
+ s->pstate &= ~0x00000f06; /* BRE, BWE, RTA, WTA, DLA, DATI */
757
+ s->hctl &= ~0x00030000; /* SGBR, CR */
758
+ s->stat &= ~(STAT_BRR|STAT_BWR|STAT_BGE);
762
+ if (value & 0x02000000) { /* SRC */
763
+ s->pstate &= ~0x00000001; /* CMDI */
765
+ if (value & 0x01000000) { /* SRA */
766
+ uint32_t capa = s->capa;
767
+ uint32_t cur_capa = s->cur_capa;
768
+ omap3_mmc_reset(DEVICE(s));
770
+ s->cur_capa = cur_capa;
772
+ value = (value & ~2) | ((value & 1) << 1); /* copy ICE directly to ICS */
773
+ s->sysctl = value & 0x000fffc7;
776
+ TRACE2("STAT = %08x", value);
777
+ /* STAT_CIRQ and STAT_ERRI are write-ignored */
778
+ value = value & (STAT_MASK & ~(STAT_CIRQ|STAT_ERRI));
780
+ omap3_mmc_interrupts_update(s);
782
+ case 0x134: /* MMCHS_IE */
783
+ TRACE2("IE = %08x", value);
784
+ if (!(s->con & 0x4000)) {
785
+ /* if CON:OBIE is clear, ignore write to OBI_ENABLE */
786
+ value = (value & ~STAT_OBI) | (s->ie & STAT_OBI);
788
+ s->ie = value & (STAT_MASK & ~STAT_ERRI);
789
+ if (!(s->ie & STAT_CIRQ)) {
790
+ s->stat &= ~STAT_CIRQ;
792
+ omap3_mmc_interrupts_update(s);
795
+ TRACE2("ISE = %08x", value);
796
+ s->ise = value & (STAT_MASK & ~STAT_ERRI);
797
+ omap3_mmc_interrupts_update(s);
799
+ case 0x140: /* MMCHS_CAPA */
800
+ TRACE2("CAPA = %08x", value);
801
+ s->capa &= ~0x07000000;
802
+ s->capa |= value & 0x07000000;
805
+ TRACE2("CUR_CAPA = %08x", value);
806
+ s->cur_capa = value & 0xffffff;
809
+ OMAP_BAD_REG(addr);
814
+static const MemoryRegionOps omap3_mmc_ops = {
817
+ omap_badwidth_read32,
818
+ omap_badwidth_read32,
822
+ omap_badwidth_write32,
823
+ omap_badwidth_write32,
827
+ .endianness = DEVICE_NATIVE_ENDIAN,
830
+static int omap3_mmc_init(SysBusDevice *dev)
832
+ OMAP3MMCState *s = OMAP3_MMC(dev);
834
+ sysbus_init_irq(dev, &s->irq);
835
+ sysbus_init_irq(dev, &s->dma[0]);
836
+ sysbus_init_irq(dev, &s->dma[1]);
837
+ memory_region_init_io(&s->iomem, OBJECT(s), &omap3_mmc_ops, s,
838
+ "omap3_mmc", 0x1000);
839
+ sysbus_init_mmio(dev, &s->iomem);
843
+static void omap3_mmc_class_init(ObjectClass *klass, void *data)
845
+ DeviceClass *dc = DEVICE_CLASS(klass);
846
+ SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
847
+ k->init = omap3_mmc_init;
848
+ dc->reset = omap3_mmc_reset;
851
+static TypeInfo omap3_mmc_info = {
852
+ .name = TYPE_OMAP3_MMC,
853
+ .parent = TYPE_SYS_BUS_DEVICE,
854
+ .instance_size = sizeof(OMAP3MMCState),
855
+ .class_init = omap3_mmc_class_init,
858
+static void omap3_mmc_register_types(void)
860
+ type_register_static(&omap3_mmc_info);
863
+void omap3_mmc_attach(DeviceState *dev, BlockDriverState *bs,
864
+ int is_spi, int is_mmc)
866
+ OMAP3MMCState *s = OMAP3_MMC(dev);
869
+ hw_error("%s: card already attached!", __FUNCTION__);
871
+ s->card = sd_init(bs, is_spi, is_mmc);
874
+type_init(omap3_mmc_register_types)
875
diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h
876
index 30046d1..a357510 100644
877
--- a/include/hw/arm/omap.h
878
+++ b/include/hw/arm/omap.h
879
@@ -960,6 +960,10 @@ void omap_mmc_reset(struct omap_mmc_s *s);
880
void omap_mmc_handlers(struct omap_mmc_s *s, qemu_irq ro, qemu_irq cover);
881
void omap_mmc_enable(struct omap_mmc_s *s, int enable);
884
+void omap3_mmc_attach(DeviceState *dev, BlockDriverState *bs,
885
+ int is_spi, int is_mmc);
888
i2c_bus *omap_i2c_bus(DeviceState *omap_i2c);