From patchwork Tue Feb 27 13:32:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 776214 Delivered-To: patch@linaro.org Received: by 2002:adf:a113:0:b0:33d:f458:43ce with SMTP id o19csp159308wro; Tue, 27 Feb 2024 05:42:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUD4Z6q89dAuIJ92LuhsWWpU34vXoaiCpjl4WnGEst6INeFkJTr1d11g4AOQqLeC0+4PN1GnitsUgPnxfcjUE2a X-Google-Smtp-Source: AGHT+IFWYnjg3rVJNIfeV1fpNBFxnNLPR4yNAaycaH/O16O5Jyx7TCDrQK3h+cYDKNts3BUpFu9K X-Received: by 2002:a05:6358:7251:b0:17b:5635:454e with SMTP id i17-20020a056358725100b0017b5635454emr11812206rwa.32.1709041354282; Tue, 27 Feb 2024 05:42:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709041354; cv=none; d=google.com; s=arc-20160816; b=vVW+Ewfcj69p+ORYzEuyaA6yiIsGgHHU0N3ANNO3q0wBQrJo7cxm5TowaPdMZ6eSys NxmyphKIeAtFxZSk3jmlblP6cxLz2eVW+vmXnq5q6jlunHDswDgXz3nF7MhuMKuZtDZo TO3svL4uE/+8ggRrOU1N5ciFt+Rqfql2+oQJY1VVg4q4c4IFpC4+glTHb1FLgKUOuI+B oVOUnR/DXICduq8wXDKWNqh4tgk7GZMM50q3Su5Azvo1KUv55bWl7+vNYUnWKyLC8+HL dKF/YKPIy06+BkzE/2+Z0YwrQK8RWBFGtNjo+530RNMw0Q+STuVhRklbQlKJ2o3vITXW VqTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KGqC5ypYFTpj73/g0BzMEjHLRiV0ye31/N/3xIe2N+0=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=U24jzW8vfN1P2cDrVe2yj39YKGJjJf2GWboQfxgrftboOC4CQyq3hk+7AiKjp/3lz9 7/+t5tsfW/rj0EqZ1moh+4PYxH5OCqnh76TOAzRPlUikElu9Z2pqHIFbBhzAxOHVav23 WqwHGhnlu5p9d7yYKNd0eS+UC5hLSkUNrZkhW8AXLWJ7FlfthRzWe1N3lyYrZRivjGAu d4kutaN6fZOYhDkdWi+2SMsuGIkfGU2K+iUYrKlQSQRcgBsWmwe7OwHyth5iXuqzbAkh 1VwCjK/YulkhX4gqhisvh48VeUKiHBjlVh9t/42YB6clOKdxNC56pDd9xfWSjxqnNzyg yaXg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LeSqz6ou; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m9-20020a0562141bc900b0068f4553e43dsi7690055qvc.39.2024.02.27.05.42.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2024 05:42:34 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LeSqz6ou; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rexaw-00014z-Fs; Tue, 27 Feb 2024 08:34:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rexaT-0000mN-Ro for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:37 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rexaO-0002uP-EA for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:37 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33da51fd636so2564887f8f.3 for ; Tue, 27 Feb 2024 05:33:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709040810; x=1709645610; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KGqC5ypYFTpj73/g0BzMEjHLRiV0ye31/N/3xIe2N+0=; b=LeSqz6ouiBiA311Y9iJpd/ReqGP43NnoVb91ASMogJbiDkVk2vr0mATBQeX4UmHqwp sIbqgr7uhPDx/hkmZECMX8l3rIYWfDfEedTkeVu8Zc1fPLlC43JkI3lHFMN8akQYhVcO 6zC0SqYppU4p++YejOwyaBY2YoB3BBAyYDBYZL+VS1oIAhhAeJQTsUCZ+NDUs9iJNDRr AB/Dim+nRycNPvPRnaUTO9Iko9yvFqwpryG7VlApr71d2/+qntIwWV90c2NcA80sUjJO EEQt8BjbjK7EmMxwibCO0gRWIF74G24wdXZTTBk8PpIxIzJeELFL0Dym3YEu/K+M3bih MT+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709040810; x=1709645610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KGqC5ypYFTpj73/g0BzMEjHLRiV0ye31/N/3xIe2N+0=; b=e7sOwJq18TluJK6Mg/cPRSGcK/pDnEt864fCE27UtqNGIqd0kD+XEhuCz+Sxu1T57g a3sqfJsJp004K3IJaRcBA1zB+Vu6i6NRoeCZ44aN/C8YC6n+9mwbLSs5x7f098tvb+5N em/qjXA29bjLGxpPJAWvkCHNzGiXCRWaRPakxT+7eikT28HvnGOmEH2EVaXlJFMm14nM ATz+Sk0q3TpPoPN6Ot4NrQBRnK1sfe4Elvcl3ReIWDOYMQoTJAaNX50HnOK8260HAIcr 5fMvQQZCqG3+Gfm61DEpO0n3X7czk4XCSQNYSTU7Myn4cTlFu9TsvBVfW5hY9yrX0phh HMsg== X-Gm-Message-State: AOJu0YwS13KyWKVUaEYVChRJ+5fSZXuMjnK6PkHsoqv32YOW60WLwFY6 yFBDc/1St65OTYnoTBb8eGd28LLUDkP8R9j7m7RcuEpxnQ2dzrpBV/b8L2Ob0i2YHF62ydXrtPr P X-Received: by 2002:a5d:42c1:0:b0:33d:11e1:47d9 with SMTP id t1-20020a5d42c1000000b0033d11e147d9mr6202495wrr.68.1709040810526; Tue, 27 Feb 2024 05:33:30 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id i13-20020adfe48d000000b0033ae7d768b2sm11319552wrm.117.2024.02.27.05.33.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 05:33:30 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 28/45] hw/gpio: Connect SD controller to BCM2838 GPIO Date: Tue, 27 Feb 2024 13:32:57 +0000 Message-Id: <20240227133314.1721857-29-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227133314.1721857-1-peter.maydell@linaro.org> References: <20240227133314.1721857-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Sergey Kambalin Signed-off-by: Sergey Kambalin Reviewed-by: Peter Maydell Message-id: 20240226000259.2752893-9-sergey.kambalin@auriga.com Signed-off-by: Peter Maydell --- include/hw/gpio/bcm2838_gpio.h | 5 ++++ hw/gpio/bcm2838_gpio.c | 52 +++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/hw/gpio/bcm2838_gpio.h b/include/hw/gpio/bcm2838_gpio.h index 06d48e0c191..f2a57a697f2 100644 --- a/include/hw/gpio/bcm2838_gpio.h +++ b/include/hw/gpio/bcm2838_gpio.h @@ -14,6 +14,7 @@ #ifndef BCM2838_GPIO_H #define BCM2838_GPIO_H +#include "hw/sd/sd.h" #include "hw/sysbus.h" #include "qom/object.h" @@ -29,6 +30,10 @@ struct BCM2838GpioState { MemoryRegion iomem; + /* SDBus selector */ + SDBus sdbus; + SDBus *sdbus_sdhci; + SDBus *sdbus_sdhost; uint8_t fsel[BCM2838_GPIO_NUM]; uint32_t lev0, lev1; diff --git a/hw/gpio/bcm2838_gpio.c b/hw/gpio/bcm2838_gpio.c index 69d15dbb497..2ddf62f6959 100644 --- a/hw/gpio/bcm2838_gpio.c +++ b/hw/gpio/bcm2838_gpio.c @@ -17,6 +17,7 @@ #include "qapi/error.h" #include "hw/sysbus.h" #include "migration/vmstate.h" +#include "hw/sd/sd.h" #include "hw/gpio/bcm2838_gpio.h" #include "hw/irq.h" @@ -63,6 +64,16 @@ #define BYTES_IN_WORD 4 +/* bcm,function property */ +#define BCM2838_FSEL_GPIO_IN 0 +#define BCM2838_FSEL_GPIO_OUT 1 +#define BCM2838_FSEL_ALT5 2 +#define BCM2838_FSEL_ALT4 3 +#define BCM2838_FSEL_ALT0 4 +#define BCM2838_FSEL_ALT1 5 +#define BCM2838_FSEL_ALT2 6 +#define BCM2838_FSEL_ALT3 7 + static uint32_t gpfsel_get(BCM2838GpioState *s, uint8_t reg) { int i; @@ -86,6 +97,31 @@ static void gpfsel_set(BCM2838GpioState *s, uint8_t reg, uint32_t value) s->fsel[index] = fsel; } } + + /* SD controller selection (48-53) */ + if (s->sd_fsel != BCM2838_FSEL_GPIO_IN + && (s->fsel[48] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[49] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[50] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[51] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[52] == BCM2838_FSEL_GPIO_IN) + && (s->fsel[53] == BCM2838_FSEL_GPIO_IN) + ) { + /* SDHCI controller selected */ + sdbus_reparent_card(s->sdbus_sdhost, s->sdbus_sdhci); + s->sd_fsel = BCM2838_FSEL_GPIO_IN; + } else if (s->sd_fsel != BCM2838_FSEL_ALT0 + && (s->fsel[48] == BCM2838_FSEL_ALT0) /* SD_CLK_R */ + && (s->fsel[49] == BCM2838_FSEL_ALT0) /* SD_CMD_R */ + && (s->fsel[50] == BCM2838_FSEL_ALT0) /* SD_DATA0_R */ + && (s->fsel[51] == BCM2838_FSEL_ALT0) /* SD_DATA1_R */ + && (s->fsel[52] == BCM2838_FSEL_ALT0) /* SD_DATA2_R */ + && (s->fsel[53] == BCM2838_FSEL_ALT0) /* SD_DATA3_R */ + ) { + /* SDHost controller selected */ + sdbus_reparent_card(s->sdbus_sdhci, s->sdbus_sdhost); + s->sd_fsel = BCM2838_FSEL_ALT0; + } } static int gpfsel_is_out(BCM2838GpioState *s, int index) @@ -266,6 +302,11 @@ static void bcm2838_gpio_reset(DeviceState *dev) memset(s->fsel, 0, sizeof(s->fsel)); + s->sd_fsel = 0; + + /* SDHCI is selected by default */ + sdbus_reparent_card(&s->sdbus, s->sdbus_sdhci); + s->lev0 = 0; s->lev1 = 0; @@ -304,6 +345,8 @@ static void bcm2838_gpio_init(Object *obj) DeviceState *dev = DEVICE(obj); SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, DEVICE(s), "sd-bus"); + memory_region_init_io(&s->iomem, obj, &bcm2838_gpio_ops, s, "bcm2838_gpio", BCM2838_GPIO_REGS_SIZE); sysbus_init_mmio(sbd, &s->iomem); @@ -312,7 +355,14 @@ static void bcm2838_gpio_init(Object *obj) static void bcm2838_gpio_realize(DeviceState *dev, Error **errp) { - /* Temporary stub. Do nothing */ + BCM2838GpioState *s = BCM2838_GPIO(dev); + Object *obj; + + obj = object_property_get_link(OBJECT(dev), "sdbus-sdhci", &error_abort); + s->sdbus_sdhci = SD_BUS(obj); + + obj = object_property_get_link(OBJECT(dev), "sdbus-sdhost", &error_abort); + s->sdbus_sdhost = SD_BUS(obj); } static void bcm2838_gpio_class_init(ObjectClass *klass, void *data)