omap_mmc.c 16.5 KB
Newer Older
B
balrog 已提交
1 2 3
/*
 * OMAP on-chip MMC/SD host emulation.
 *
4 5
 * Datasheet: TI Multimedia Card (MMC/SD/SDIO) Interface (SPRU765A)
 *
B
balrog 已提交
6 7 8 9
 * Copyright (C) 2006-2007 Andrzej Zaborowski  <balrog@zabor.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
B
balrog 已提交
10 11
 * published by the Free Software Foundation; either version 2 or
 * (at your option) version 3 of the License.
B
balrog 已提交
12 13 14 15 16 17
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
18
 * You should have received a copy of the GNU General Public License along
19
 * with this program; if not, see <http://www.gnu.org/licenses/>.
B
balrog 已提交
20
 */
P
Peter Maydell 已提交
21
#include "qemu/osdep.h"
22
#include "qemu/log.h"
23
#include "hw/hw.h"
P
Paolo Bonzini 已提交
24
#include "hw/arm/omap.h"
25
#include "hw/sd/sd.h"
B
balrog 已提交
26 27 28 29

struct omap_mmc_s {
    qemu_irq irq;
    qemu_irq *dma;
B
balrog 已提交
30
    qemu_irq coverswitch;
A
Avi Kivity 已提交
31
    MemoryRegion iomem;
B
balrog 已提交
32 33 34 35 36 37
    omap_clk clk;
    SDState *card;
    uint16_t last_cmd;
    uint16_t sdio;
    uint16_t rsp[8];
    uint32_t arg;
B
balrog 已提交
38
    int lines;
B
balrog 已提交
39 40 41
    int dw;
    int mode;
    int enable;
B
balrog 已提交
42 43
    int be;
    int rev;
B
balrog 已提交
44 45 46 47
    uint16_t status;
    uint16_t mask;
    uint8_t cto;
    uint16_t dto;
B
balrog 已提交
48
    int clkdiv;
B
balrog 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62
    uint16_t fifo[32];
    int fifo_start;
    int fifo_len;
    uint16_t blen;
    uint16_t blen_counter;
    uint16_t nblk;
    uint16_t nblk_counter;
    int tx_dma;
    int rx_dma;
    int af_level;
    int ae_level;

    int ddir;
    int transfer;
B
balrog 已提交
63 64 65 66 67

    int cdet_wakeup;
    int cdet_enable;
    int cdet_state;
    qemu_irq cdet;
B
balrog 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
};

static void omap_mmc_interrupts_update(struct omap_mmc_s *s)
{
    qemu_set_irq(s->irq, !!(s->status & s->mask));
}

static void omap_mmc_fifolevel_update(struct omap_mmc_s *host)
{
    if (!host->transfer && !host->fifo_len) {
        host->status &= 0xf3ff;
        return;
    }

    if (host->fifo_len > host->af_level && host->ddir) {
        if (host->rx_dma) {
            host->status &= 0xfbff;
            qemu_irq_raise(host->dma[1]);
        } else
            host->status |= 0x0400;
    } else {
        host->status &= 0xfbff;
        qemu_irq_lower(host->dma[1]);
    }

    if (host->fifo_len < host->ae_level && !host->ddir) {
        if (host->tx_dma) {
            host->status &= 0xf7ff;
            qemu_irq_raise(host->dma[0]);
        } else
            host->status |= 0x0800;
    } else {
        qemu_irq_lower(host->dma[0]);
        host->status &= 0xf7ff;
    }
}

typedef enum {
    sd_nore = 0,	/* no response */
    sd_r1,		/* normal response command */
    sd_r2,		/* CID, CSD registers */
    sd_r3,		/* OCR register */
    sd_r6 = 6,		/* Published RCA response */
    sd_r1b = -1,
A
Anthony Liguori 已提交
112
} sd_rsp_type_t;
B
balrog 已提交
113 114

static void omap_mmc_command(struct omap_mmc_s *host, int cmd, int dir,
A
Anthony Liguori 已提交
115
                sd_cmd_type_t type, int busy, sd_rsp_type_t resptype, int init)
B
balrog 已提交
116 117 118
{
    uint32_t rspstatus, mask;
    int rsplen, timeout;
P
Paul Brook 已提交
119
    SDRequest request;
B
balrog 已提交
120 121
    uint8_t response[16];

B
balrog 已提交
122 123 124 125 126
    if (init && cmd == 0) {
        host->status |= 0x0001;
        return;
    }

B
balrog 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    if (resptype == sd_r1 && busy)
        resptype = sd_r1b;

    if (type == sd_adtc) {
        host->fifo_start = 0;
        host->fifo_len = 0;
        host->transfer = 1;
        host->ddir = dir;
    } else
        host->transfer = 0;
    timeout = 0;
    mask = 0;
    rspstatus = 0;

    request.cmd = cmd;
    request.arg = host->arg;
    request.crc = 0; /* FIXME */

    rsplen = sd_do_command(host->card, &request, response);

    /* TODO: validate CRCs */
    switch (resptype) {
    case sd_nore:
        rsplen = 0;
        break;

    case sd_r1:
    case sd_r1b:
        if (rsplen < 4) {
            timeout = 1;
            break;
        }
        rsplen = 4;

        mask = OUT_OF_RANGE | ADDRESS_ERROR | BLOCK_LEN_ERROR |
                ERASE_SEQ_ERROR | ERASE_PARAM | WP_VIOLATION |
                LOCK_UNLOCK_FAILED | COM_CRC_ERROR | ILLEGAL_COMMAND |
                CARD_ECC_FAILED | CC_ERROR | SD_ERROR |
                CID_CSD_OVERWRITE;
        if (host->sdio & (1 << 13))
            mask |= AKE_SEQ_ERROR;
168
        rspstatus = ldl_be_p(response);
B
balrog 已提交
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        break;

    case sd_r2:
        if (rsplen < 16) {
            timeout = 1;
            break;
        }
        rsplen = 16;
        break;

    case sd_r3:
        if (rsplen < 4) {
            timeout = 1;
            break;
        }
        rsplen = 4;

186
        rspstatus = ldl_be_p(response);
B
balrog 已提交
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
        if (rspstatus & 0x80000000)
            host->status &= 0xe000;
        else
            host->status |= 0x1000;
        break;

    case sd_r6:
        if (rsplen < 4) {
            timeout = 1;
            break;
        }
        rsplen = 4;

        mask = 0xe000 | AKE_SEQ_ERROR;
        rspstatus = (response[2] << 8) | (response[3] << 0);
    }

    if (rspstatus & mask)
        host->status |= 0x4000;
    else
        host->status &= 0xb000;

    if (rsplen)
        for (rsplen = 0; rsplen < 8; rsplen ++)
            host->rsp[~rsplen & 7] = response[(rsplen << 1) | 1] |
                    (response[(rsplen << 1) | 0] << 8);

    if (timeout)
        host->status |= 0x0080;
    else if (cmd == 12)
        host->status |= 0x0005;	/* Makes it more real */
    else
        host->status |= 0x0001;
}

static void omap_mmc_transfer(struct omap_mmc_s *host)
{
    uint8_t value;

    if (!host->transfer)
        return;

    while (1) {
        if (host->ddir) {
            if (host->fifo_len > host->af_level)
                break;

            value = sd_read_data(host->card);
            host->fifo[(host->fifo_start + host->fifo_len) & 31] = value;
            if (-- host->blen_counter) {
                value = sd_read_data(host->card);
                host->fifo[(host->fifo_start + host->fifo_len) & 31] |=
                        value << 8;
                host->blen_counter --;
            }

            host->fifo_len ++;
        } else {
            if (!host->fifo_len)
                break;

            value = host->fifo[host->fifo_start] & 0xff;
            sd_write_data(host->card, value);
            if (-- host->blen_counter) {
                value = host->fifo[host->fifo_start] >> 8;
                sd_write_data(host->card, value);
                host->blen_counter --;
            }

            host->fifo_start ++;
            host->fifo_len --;
            host->fifo_start &= 31;
        }

        if (host->blen_counter == 0) {
            host->nblk_counter --;
            host->blen_counter = host->blen;

            if (host->nblk_counter == 0) {
                host->nblk_counter = host->nblk;
                host->transfer = 0;
                host->status |= 0x0008;
                break;
            }
        }
    }
}

static void omap_mmc_update(void *opaque)
{
    struct omap_mmc_s *s = opaque;
    omap_mmc_transfer(s);
    omap_mmc_fifolevel_update(s);
    omap_mmc_interrupts_update(s);
}

283 284 285 286 287 288
static void omap_mmc_pseudo_reset(struct omap_mmc_s *host)
{
    host->status = 0;
    host->fifo_len = 0;
}

B
balrog 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
void omap_mmc_reset(struct omap_mmc_s *host)
{
    host->last_cmd = 0;
    memset(host->rsp, 0, sizeof(host->rsp));
    host->arg = 0;
    host->dw = 0;
    host->mode = 0;
    host->enable = 0;
    host->mask = 0;
    host->cto = 0;
    host->dto = 0;
    host->blen = 0;
    host->blen_counter = 0;
    host->nblk = 0;
    host->nblk_counter = 0;
    host->tx_dma = 0;
    host->rx_dma = 0;
    host->ae_level = 0x00;
    host->af_level = 0x1f;
    host->transfer = 0;
    host->cdet_wakeup = 0;
    host->cdet_enable = 0;
    qemu_set_irq(host->coverswitch, host->cdet_state);
    host->clkdiv = 0;
313

314 315
    omap_mmc_pseudo_reset(host);

316 317 318 319 320
    /* Since we're still using the legacy SD API the card is not plugged
     * into any bus, and we must reset it manually. When omap_mmc is
     * QOMified this must move into the QOM reset function.
     */
    device_reset(DEVICE(host->card));
B
balrog 已提交
321 322
}

A
Avi Kivity 已提交
323
static uint64_t omap_mmc_read(void *opaque, hwaddr offset,
A
Avi Kivity 已提交
324
                              unsigned size)
B
balrog 已提交
325 326 327
{
    uint16_t i;
    struct omap_mmc_s *s = (struct omap_mmc_s *) opaque;
A
Avi Kivity 已提交
328 329 330 331

    if (size != 2) {
        return omap_badwidth_read16(opaque, offset);
    }
B
balrog 已提交
332 333 334 335 336 337 338 339 340 341 342 343

    switch (offset) {
    case 0x00:	/* MMC_CMD */
        return s->last_cmd;

    case 0x04:	/* MMC_ARGL */
        return s->arg & 0x0000ffff;

    case 0x08:	/* MMC_ARGH */
        return s->arg >> 16;

    case 0x0c:	/* MMC_CON */
B
balrog 已提交
344 345
        return (s->dw << 15) | (s->mode << 12) | (s->enable << 11) | 
                (s->be << 10) | s->clkdiv;
B
balrog 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386

    case 0x10:	/* MMC_STAT */
        return s->status;

    case 0x14:	/* MMC_IE */
        return s->mask;

    case 0x18:	/* MMC_CTO */
        return s->cto;

    case 0x1c:	/* MMC_DTO */
        return s->dto;

    case 0x20:	/* MMC_DATA */
        /* TODO: support 8-bit access */
        i = s->fifo[s->fifo_start];
        if (s->fifo_len == 0) {
            printf("MMC: FIFO underrun\n");
            return i;
        }
        s->fifo_start ++;
        s->fifo_len --;
        s->fifo_start &= 31;
        omap_mmc_transfer(s);
        omap_mmc_fifolevel_update(s);
        omap_mmc_interrupts_update(s);
        return i;

    case 0x24:	/* MMC_BLEN */
        return s->blen_counter;

    case 0x28:	/* MMC_NBLK */
        return s->nblk_counter;

    case 0x2c:	/* MMC_BUF */
        return (s->rx_dma << 15) | (s->af_level << 8) |
            (s->tx_dma << 7) | s->ae_level;

    case 0x30:	/* MMC_SPI */
        return 0x0000;
    case 0x34:	/* MMC_SDIO */
B
balrog 已提交
387
        return (s->cdet_wakeup << 2) | (s->cdet_enable) | s->sdio;
B
balrog 已提交
388 389 390 391
    case 0x38:	/* MMC_SYST */
        return 0x0000;

    case 0x3c:	/* MMC_REV */
B
balrog 已提交
392
        return s->rev;
B
balrog 已提交
393 394 395 396 397 398 399 400 401 402

    case 0x40:	/* MMC_RSP0 */
    case 0x44:	/* MMC_RSP1 */
    case 0x48:	/* MMC_RSP2 */
    case 0x4c:	/* MMC_RSP3 */
    case 0x50:	/* MMC_RSP4 */
    case 0x54:	/* MMC_RSP5 */
    case 0x58:	/* MMC_RSP6 */
    case 0x5c:	/* MMC_RSP7 */
        return s->rsp[(offset - 0x40) >> 2];
B
balrog 已提交
403 404 405 406 407 408 409

    /* OMAP2-specific */
    case 0x60:	/* MMC_IOSR */
    case 0x64:	/* MMC_SYSC */
        return 0;
    case 0x68:	/* MMC_SYSS */
        return 1;						/* RSTD */
B
balrog 已提交
410 411 412 413 414 415
    }

    OMAP_BAD_REG(offset);
    return 0;
}

A
Avi Kivity 已提交
416
static void omap_mmc_write(void *opaque, hwaddr offset,
A
Avi Kivity 已提交
417
                           uint64_t value, unsigned size)
B
balrog 已提交
418 419 420
{
    int i;
    struct omap_mmc_s *s = (struct omap_mmc_s *) opaque;
A
Avi Kivity 已提交
421 422

    if (size != 2) {
S
Stefan Weil 已提交
423 424
        omap_badwidth_write16(opaque, offset, value);
        return;
A
Avi Kivity 已提交
425
    }
B
balrog 已提交
426 427 428 429 430 431 432 433 434 435

    switch (offset) {
    case 0x00:	/* MMC_CMD */
        if (!s->enable)
            break;

        s->last_cmd = value;
        for (i = 0; i < 8; i ++)
            s->rsp[i] = 0x0000;
        omap_mmc_command(s, value & 63, (value >> 15) & 1,
A
Anthony Liguori 已提交
436
                (sd_cmd_type_t) ((value >> 12) & 3),
B
balrog 已提交
437
                (value >> 11) & 1,
A
Anthony Liguori 已提交
438
                (sd_rsp_type_t) ((value >> 8) & 7),
B
balrog 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
                (value >> 7) & 1);
        omap_mmc_update(s);
        break;

    case 0x04:	/* MMC_ARGL */
        s->arg &= 0xffff0000;
        s->arg |= 0x0000ffff & value;
        break;

    case 0x08:	/* MMC_ARGH */
        s->arg &= 0x0000ffff;
        s->arg |= value << 16;
        break;

    case 0x0c:	/* MMC_CON */
        s->dw = (value >> 15) & 1;
        s->mode = (value >> 12) & 3;
        s->enable = (value >> 11) & 1;
B
balrog 已提交
457 458
        s->be = (value >> 10) & 1;
        s->clkdiv = (value >> 0) & (s->rev >= 2 ? 0x3ff : 0xff);
459 460 461 462 463 464 465 466
        if (s->mode != 0) {
            qemu_log_mask(LOG_UNIMP,
                          "omap_mmc_wr: mode #%i unimplemented\n", s->mode);
        }
        if (s->be != 0) {
            qemu_log_mask(LOG_UNIMP,
                          "omap_mmc_wr: Big Endian not implemented\n");
        }
B
balrog 已提交
467
        if (s->dw != 0 && s->lines < 4)
B
balrog 已提交
468
            printf("4-bit SD bus enabled\n");
B
balrog 已提交
469
        if (!s->enable)
470
            omap_mmc_pseudo_reset(s);
B
balrog 已提交
471 472 473 474 475 476 477 478
        break;

    case 0x10:	/* MMC_STAT */
        s->status &= ~value;
        omap_mmc_interrupts_update(s);
        break;

    case 0x14:	/* MMC_IE */
B
balrog 已提交
479
        s->mask = value & 0x7fff;
B
balrog 已提交
480 481 482 483 484
        omap_mmc_interrupts_update(s);
        break;

    case 0x18:	/* MMC_CTO */
        s->cto = value & 0xff;
B
balrog 已提交
485
        if (s->cto > 0xfd && s->rev <= 1)
B
balrog 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
            printf("MMC: CTO of 0xff and 0xfe cannot be used!\n");
        break;

    case 0x1c:	/* MMC_DTO */
        s->dto = value & 0xffff;
        break;

    case 0x20:	/* MMC_DATA */
        /* TODO: support 8-bit access */
        if (s->fifo_len == 32)
            break;
        s->fifo[(s->fifo_start + s->fifo_len) & 31] = value;
        s->fifo_len ++;
        omap_mmc_transfer(s);
        omap_mmc_fifolevel_update(s);
        omap_mmc_interrupts_update(s);
        break;

    case 0x24:	/* MMC_BLEN */
        s->blen = (value & 0x07ff) + 1;
        s->blen_counter = s->blen;
        break;

    case 0x28:	/* MMC_NBLK */
        s->nblk = (value & 0x07ff) + 1;
        s->nblk_counter = s->nblk;
        s->blen_counter = s->blen;
        break;

    case 0x2c:	/* MMC_BUF */
        s->rx_dma = (value >> 15) & 1;
        s->af_level = (value >> 8) & 0x1f;
        s->tx_dma = (value >> 7) & 1;
        s->ae_level = value & 0x1f;

        if (s->rx_dma)
            s->status &= 0xfbff;
        if (s->tx_dma)
            s->status &= 0xf7ff;
        omap_mmc_fifolevel_update(s);
        omap_mmc_interrupts_update(s);
        break;

    /* SPI, SDIO and TEST modes unimplemented */
B
balrog 已提交
530
    case 0x30:	/* MMC_SPI (OMAP1 only) */
B
balrog 已提交
531 532
        break;
    case 0x34:	/* MMC_SDIO */
B
balrog 已提交
533 534 535
        s->sdio = value & (s->rev >= 2 ? 0xfbf3 : 0x2020);
        s->cdet_wakeup = (value >> 9) & 1;
        s->cdet_enable = (value >> 2) & 1;
B
balrog 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
        break;
    case 0x38:	/* MMC_SYST */
        break;

    case 0x3c:	/* MMC_REV */
    case 0x40:	/* MMC_RSP0 */
    case 0x44:	/* MMC_RSP1 */
    case 0x48:	/* MMC_RSP2 */
    case 0x4c:	/* MMC_RSP3 */
    case 0x50:	/* MMC_RSP4 */
    case 0x54:	/* MMC_RSP5 */
    case 0x58:	/* MMC_RSP6 */
    case 0x5c:	/* MMC_RSP7 */
        OMAP_RO_REG(offset);
        break;

B
balrog 已提交
552 553 554 555 556 557 558 559 560 561 562 563 564
    /* OMAP2-specific */
    case 0x60:	/* MMC_IOSR */
        if (value & 0xf)
            printf("MMC: SDIO bits used!\n");
        break;
    case 0x64:	/* MMC_SYSC */
        if (value & (1 << 2))					/* SRTS */
            omap_mmc_reset(s);
        break;
    case 0x68:	/* MMC_SYSS */
        OMAP_RO_REG(offset);
        break;

B
balrog 已提交
565 566 567 568 569
    default:
        OMAP_BAD_REG(offset);
    }
}

A
Avi Kivity 已提交
570 571 572 573
static const MemoryRegionOps omap_mmc_ops = {
    .read = omap_mmc_read,
    .write = omap_mmc_write,
    .endianness = DEVICE_NATIVE_ENDIAN,
B
balrog 已提交
574 575
};

B
balrog 已提交
576
static void omap_mmc_cover_cb(void *opaque, int line, int level)
B
balrog 已提交
577
{
B
balrog 已提交
578 579 580 581 582
    struct omap_mmc_s *host = (struct omap_mmc_s *) opaque;

    if (!host->cdet_state && level) {
        host->status |= 0x0002;
        omap_mmc_interrupts_update(host);
B
Blue Swirl 已提交
583 584 585
        if (host->cdet_wakeup) {
            /* TODO: Assert wake-up */
        }
B
balrog 已提交
586 587 588 589 590 591
    }

    if (host->cdet_state != level) {
        qemu_set_irq(host->coverswitch, level);
        host->cdet_state = level;
    }
B
balrog 已提交
592 593
}

A
Avi Kivity 已提交
594
struct omap_mmc_s *omap_mmc_init(hwaddr base,
A
Avi Kivity 已提交
595
                MemoryRegion *sysmem,
596
                BlockBackend *blk,
B
balrog 已提交
597 598
                qemu_irq irq, qemu_irq dma[], omap_clk clk)
{
599
    struct omap_mmc_s *s = g_new0(struct omap_mmc_s, 1);
B
balrog 已提交
600 601 602 603

    s->irq = irq;
    s->dma = dma;
    s->clk = clk;
B
balrog 已提交
604 605 606
    s->lines = 1;	/* TODO: needs to be settable per-board */
    s->rev = 1;

607
    memory_region_init_io(&s->iomem, NULL, &omap_mmc_ops, s, "omap.mmc", 0x800);
A
Avi Kivity 已提交
608
    memory_region_add_subregion(sysmem, base, &s->iomem);
B
balrog 已提交
609 610

    /* Instantiate the storage */
611
    s->card = sd_init(blk, false);
612 613 614
    if (s->card == NULL) {
        exit(1);
    }
B
balrog 已提交
615

616 617
    omap_mmc_reset(s);

B
balrog 已提交
618 619 620
    return s;
}

B
balrog 已提交
621
struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
622
                BlockBackend *blk, qemu_irq irq, qemu_irq dma[],
B
balrog 已提交
623 624
                omap_clk fclk, omap_clk iclk)
{
625
    struct omap_mmc_s *s = g_new0(struct omap_mmc_s, 1);
B
balrog 已提交
626 627 628 629 630 631 632

    s->irq = irq;
    s->dma = dma;
    s->clk = fclk;
    s->lines = 4;
    s->rev = 2;

633
    memory_region_init_io(&s->iomem, NULL, &omap_mmc_ops, s, "omap.mmc",
A
Avi Kivity 已提交
634
                          omap_l4_region_size(ta, 0));
635
    omap_l4_attach(ta, 0, &s->iomem);
B
balrog 已提交
636 637

    /* Instantiate the storage */
638
    s->card = sd_init(blk, false);
639 640 641
    if (s->card == NULL) {
        exit(1);
    }
B
balrog 已提交
642

643
    s->cdet = qemu_allocate_irq(omap_mmc_cover_cb, s, 0);
644
    sd_set_cb(s->card, NULL, s->cdet);
B
balrog 已提交
645

646 647
    omap_mmc_reset(s);

B
balrog 已提交
648 649 650
    return s;
}

651 652
void omap_mmc_handlers(struct omap_mmc_s *s, qemu_irq ro, qemu_irq cover)
{
B
balrog 已提交
653 654 655 656 657 658 659 660 661 662 663
    if (s->cdet) {
        sd_set_cb(s->card, ro, s->cdet);
        s->coverswitch = cover;
        qemu_set_irq(cover, s->cdet_state);
    } else
        sd_set_cb(s->card, ro, cover);
}

void omap_mmc_enable(struct omap_mmc_s *s, int enable)
{
    sd_enable(s->card, enable);
664
}