From nobody Fri Oct 24 20:22:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of _spf.google.com designates 209.85.217.195 as permitted sender) client-ip=209.85.217.195; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ua0-f195.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of _spf.google.com designates 209.85.217.195 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ua0-f195.google.com (mail-ua0-f195.google.com [209.85.217.195]) by mx.zohomail.com with SMTPS id 1518748206547834.4442193611322; Thu, 15 Feb 2018 18:30:06 -0800 (PST) Received: by mail-ua0-f195.google.com with SMTP id i5so1097594uai.10 for ; Thu, 15 Feb 2018 18:30:06 -0800 (PST) Return-Path: Return-Path: Received: from x1.lan ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id q5sm6295200uaj.17.2018.02.15.18.30.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 18:30:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DhxZ8leHQ9jxPBNjccOuKJijS6vbpElFzkXsMnebttU=; b=hk5NbUz7hj27yZM9TViOi7bSn19ZHmLzNa23PCAkCLiGzWmVVTIM0C34/Ol3rV4SGr XzRF1f+eP8xU019az+oEiku5fg7XrgQm6MkUp1kkauEB4cgZZN91fl8jcjxRE93XAajb lipvFvv3kTcauCR2m1w9NzFHv/xy3S2UvRmcdJN55gpIeprikoym53SdpZ4a9416FLNp 5L+AnUdND+Qd0E44GsCx2RDkap7nWxPqu9BeCa+3SkA4RTrdmSha6fX696XytG+YG7zQ OrG+HRZtMi9x+2IrRcV76xyS2SGW0Ydjs/4xoJuddDOF7r/p/z9eBucXs6++Zu+yLmUU a6jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=DhxZ8leHQ9jxPBNjccOuKJijS6vbpElFzkXsMnebttU=; b=hSuDC0KLClzUAsufGdDxedCV0/yiu8/W/MV4LU8bpPhfE62z2/nWeTI9JPzMscDKQO /GWpVD+fD/NJF2HqchaXpS/0h3EUlAkb8V++CrcpPRKdJZvm0L/DKX5iEvoR4jjpUOzk wvN4x8vwEfBDwhfZGaxBnyWh0wyYi9ysLwbtI5FLXMZNPAx13JMSAAdbuOGuv41UksW0 OnJNQ1rlb1jUkeaglXKb5uajWCDJ0k+ziuHJOl5dQGEKyLM2/1yoQr30Zd0HR2+SOYVi DQuxTrS/uT7BYvo4fdykBwWKjJlEtSH1SkeGhkT3+wORUYOL35qzOdh6rbPumpNTUIQN X16Q== X-Gm-Message-State: APf1xPC5ebzPB4A2S3ynXE4WP7FzqxZFWLU4JqzCorV0+2XDq+XkNSzN F0XnszKnRfzaTR+ihhWNNFM= X-Google-Smtp-Source: AH8x224E9stYdGcB+Ec7HoUklkKiMX/LK+G2ezwishz3tSqOpkbp3RwjqvcBcUutSNQK9LFTTEzdrw== X-Received: by 10.176.76.93 with SMTP id d29mr4024271uag.89.1518748205581; Thu, 15 Feb 2018 18:30:05 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Alistair Francis , Peter Maydell Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, "Edgar E . Iglesias" , Andrzej Zaborowski , Michael Walle , Stefan Weil Subject: [PATCH v3 4/7] hw/sd/ssi-sd: use the SDBus API, connect the SDCard to the bus Date: Thu, 15 Feb 2018 23:29:29 -0300 Message-Id: <20180216022933.10945-5-f4bug@amsat.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180216022933.10945-1-f4bug@amsat.org> References: <20180216022933.10945-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZohoMail: RDKM_0 RSF_0 Z_629925259 SPT_0 On reset the bus will reset the card, we can now drop the device_reset() call. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- hw/sd/ssi-sd.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index f88f509e0a..ae04b6641b 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -47,7 +47,7 @@ typedef struct { int32_t arglen; int32_t response_pos; int32_t stopping; - SDState *sd; + SDBus sdbus; } ssi_sd_state; =20 #define TYPE_SSI_SD "ssi-sd" @@ -100,7 +100,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t= val) request.arg =3D (s->cmdarg[0] << 24) | (s->cmdarg[1] << 16) | (s->cmdarg[2] << 8) | s->cmdarg[3]; DPRINTF("CMD%d arg 0x%08x\n", s->cmd, request.arg); - s->arglen =3D sd_do_command(s->sd, &request, longresp); + s->arglen =3D sdbus_do_command(&s->sdbus, &request, longresp); if (s->arglen <=3D 0) { s->arglen =3D 1; s->response[0] =3D 4; @@ -177,7 +177,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t= val) DPRINTF("Response 0x%02x\n", s->response[s->response_pos]); return s->response[s->response_pos++]; } - if (sd_data_ready(s->sd)) { + if (sdbus_data_ready(&s->sdbus)) { DPRINTF("Data read\n"); s->mode =3D SSI_SD_DATA_START; } else { @@ -190,8 +190,8 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t= val) s->mode =3D SSI_SD_DATA_READ; return 0xfe; case SSI_SD_DATA_READ: - val =3D sd_read_data(s->sd); - if (!sd_data_ready(s->sd)) { + val =3D sdbus_read_data(&s->sdbus); + if (!sdbus_data_ready(&s->sdbus)) { DPRINTF("Data read end\n"); s->mode =3D SSI_SD_CMD; } @@ -242,13 +242,24 @@ static const VMStateDescription vmstate_ssi_sd =3D { static void ssi_sd_realize(SSISlave *d, Error **errp) { ssi_sd_state *s =3D FROM_SSI_SLAVE(ssi_sd_state, d); + DeviceState *carddev; DriveInfo *dinfo; + Error *err =3D NULL; =20 + qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, + DEVICE(d), "sd-bus"); + + /* Create and plug in the sd card */ /* FIXME use a qdev drive property instead of drive_get_next() */ dinfo =3D drive_get_next(IF_SD); - s->sd =3D sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, true); - if (s->sd =3D=3D NULL) { - error_setg(errp, "Device initialization failed."); + carddev =3D qdev_create(&s->sdbus.qbus, TYPE_SD_CARD); + if (dinfo) { + qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo), = &err); + } + object_property_set_bool(OBJECT(carddev), true, "spi", &err); + object_property_set_bool(OBJECT(carddev), true, "realized", &err); + if (err) { + error_setg(errp, "failed to init SD card: %s", error_get_pretty(er= r)); return; } } @@ -264,11 +275,6 @@ static void ssi_sd_reset(DeviceState *dev) s->arglen =3D 0; s->response_pos =3D 0; s->stopping =3D 0; - - /* Since we're still using the legacy SD API the card is not plugged - * into any bus, and we must reset it manually. - */ - device_reset(DEVICE(s->sd)); } =20 static void ssi_sd_class_init(ObjectClass *klass, void *data) --=20 2.16.1