ivshmem: Compile debug prints unconditionally to prevent bit-rot
[qemu/kevin.git] / hw / sd / core.c
blob14c2bdf27bb27d31b2d3f726bf79c0ffd3b299ef
1 /*
2 * SD card bus interface code.
4 * Copyright (c) 2015 Linaro Limited
6 * Author:
7 * Peter Maydell <peter.maydell@linaro.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2 or later, as published by the Free Software Foundation.
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "qemu/osdep.h"
23 #include "hw/qdev-core.h"
24 #include "sysemu/block-backend.h"
25 #include "hw/sd/sd.h"
27 static SDState *get_card(SDBus *sdbus)
29 /* We only ever have one child on the bus so just return it */
30 BusChild *kid = QTAILQ_FIRST(&sdbus->qbus.children);
32 if (!kid) {
33 return NULL;
35 return SD_CARD(kid->child);
38 int sdbus_do_command(SDBus *sdbus, SDRequest *req, uint8_t *response)
40 SDState *card = get_card(sdbus);
42 if (card) {
43 SDCardClass *sc = SD_CARD_GET_CLASS(card);
45 return sc->do_command(card, req, response);
48 return 0;
51 void sdbus_write_data(SDBus *sdbus, uint8_t value)
53 SDState *card = get_card(sdbus);
55 if (card) {
56 SDCardClass *sc = SD_CARD_GET_CLASS(card);
58 sc->write_data(card, value);
62 uint8_t sdbus_read_data(SDBus *sdbus)
64 SDState *card = get_card(sdbus);
66 if (card) {
67 SDCardClass *sc = SD_CARD_GET_CLASS(card);
69 return sc->read_data(card);
72 return 0;
75 bool sdbus_data_ready(SDBus *sdbus)
77 SDState *card = get_card(sdbus);
79 if (card) {
80 SDCardClass *sc = SD_CARD_GET_CLASS(card);
82 return sc->data_ready(card);
85 return false;
88 bool sdbus_get_inserted(SDBus *sdbus)
90 SDState *card = get_card(sdbus);
92 if (card) {
93 SDCardClass *sc = SD_CARD_GET_CLASS(card);
95 return sc->get_inserted(card);
98 return false;
101 bool sdbus_get_readonly(SDBus *sdbus)
103 SDState *card = get_card(sdbus);
105 if (card) {
106 SDCardClass *sc = SD_CARD_GET_CLASS(card);
108 return sc->get_readonly(card);
111 return false;
114 void sdbus_set_inserted(SDBus *sdbus, bool inserted)
116 SDBusClass *sbc = SD_BUS_GET_CLASS(sdbus);
117 BusState *qbus = BUS(sdbus);
119 if (sbc->set_inserted) {
120 sbc->set_inserted(qbus->parent, inserted);
124 void sdbus_set_readonly(SDBus *sdbus, bool readonly)
126 SDBusClass *sbc = SD_BUS_GET_CLASS(sdbus);
127 BusState *qbus = BUS(sdbus);
129 if (sbc->set_readonly) {
130 sbc->set_readonly(qbus->parent, readonly);
134 static const TypeInfo sd_bus_info = {
135 .name = TYPE_SD_BUS,
136 .parent = TYPE_BUS,
137 .instance_size = sizeof(SDBus),
138 .class_size = sizeof(SDBusClass),
141 static void sd_bus_register_types(void)
143 type_register_static(&sd_bus_info);
146 type_init(sd_bus_register_types)