Received: by 2002:a17:906:724b:b0:a35:eedd:80b0 with SMTP id n11csp464507ejk; Mon, 29 Jan 2024 14:21:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5kEp1ae4PFw8Zh6o+aqKyDWZYspd1zXqAZlKntr61m3Y6VexnRlGEhz7Ag0+hQhcfpxud X-Received: by 2002:a05:6214:194c:b0:681:974e:6f16 with SMTP id q12-20020a056214194c00b00681974e6f16mr7342954qvk.125.1706566869554; Mon, 29 Jan 2024 14:21:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706566869; cv=none; d=google.com; s=arc-20160816; b=fpDN7918W9OIYZZOR8CNdrg6MAFzHhu7EGHgjnp8nvvfAg7RSq5XkeaRHPuGT/pTw5 c8lRHVptZ8wl8R55s7oXGrrIpN2N1cwmHlix1DdqSZGbwuNIc9wC7QyW1CAYaQTGt2gs 9+XMBAkX/tJfkIp4QVaSAQeKFImsfKJuaqpaeQjZD1ahgGyx4RsHpflvLIRjZS4GUvS8 SKcxY6sBQu6ywfE0qajg3OQN2xVVnnayQ9xT8dvPrvD8zR6DnnZ6DamM/kPVoAihdszY lJnT19D/2fG6eq23rfwATt+tNXJsJ9XpE4NmHs1LuA1228+yd5FsBRanI4YQ7AK0PiYV b7xQ== 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:cc:to :from:dkim-signature; bh=ZcGi/Mj/JFxvcBR5sflXEQbX73rifjp+JmFM1JHIyqs=; fh=4MpYe3g2WjWqUr93l7JvWw+qx/t1yDCg/+zCriEMnZ0=; b=Y8Q3NwUvYJ2tg+7xgCXKlC/AdaCAhtcOkIr0nt9BLiy7JqA0SjSjwEeSQfrC6aZ8xE V3+leW2vCur8sJPWcKhp4PAo49/gwN9/a/Kl+D3HTN+5nO6yr9Sj0cUFpE583lxp2JhO vuzClwM7lz/qKzHBvlF5h1Irk/tJegYcTO1MtX09bQQEJGkU7fFBEqj+k7F8b2bdP/0n TFt3PU+N8vzAXiYXwPItv4d+qgtJC2vaEOUS0BuFyAHav4lEhIzAufkru2whoJwM+dto pA8p3JA4YbxGUeL+GoIjXWcfKK1SvZZCpcVYprSYL75QCa/Ti/7Cn2EkfvzrN2lVZGUM im1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OUwHotqR; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id jk8-20020ad45d48000000b0068664c0fd57si9213623qvb.540.2024.01.29.14.21.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jan 2024 14:21:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=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=@gmail.com header.s=20230601 header.b=OUwHotqR; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rUZyx-00016h-U7; Mon, 29 Jan 2024 17:19:59 -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 1rUZyw-000160-7G; Mon, 29 Jan 2024 17:19:58 -0500 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rUZyu-0000mu-IL; Mon, 29 Jan 2024 17:19:57 -0500 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6dde5d308c6so2231029a34.0; Mon, 29 Jan 2024 14:19:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706566794; x=1707171594; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZcGi/Mj/JFxvcBR5sflXEQbX73rifjp+JmFM1JHIyqs=; b=OUwHotqRz4KwaC9Z/k1q6aM5Vo3bG7XPkjW8rHzIfLKdmbKheenZCLCcbBp1pmhJwP TQ4OtcvibI9bfUXSAAXKp8g1Eow7UbZ2wv4xnIwOtTqV1o4AO/totvsQQl4bf7tsIjSz fd+UOv0RtFOwo0V7sybSvAMlfrJhh7ZsN6rWu0n2fddL8t+Ak2S0hS1BJFxxTsGGHHXx X6FU5petxbYnW/aV/1i/TH92q8yGROecYTOUiMuJ37T3rG/fn18opW6OzlRnry3i7E3M 0mvJHgNPMEVLn6UrUMnESYa0mkJoQZU8oWzibighuHPpRAUI/7k6UFIIMUmbjN25k2I8 cxBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706566794; x=1707171594; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZcGi/Mj/JFxvcBR5sflXEQbX73rifjp+JmFM1JHIyqs=; b=tM4xWKJ10eZyV9tqO2OzsnFBe2dw2C1UFpZC3ZiAlB79WtYg/cpPoOOJWYkHw+GtxX HMXGbOj2Bfru5XgIOR9SvhihuDPTc/67aiS4JPzy0k6/Ex0AP6OZ3r9epxglluu+x1Vk Ueqot422uI49ZLS5ARZKGjcxbJeHCQQWnCzqRR4nbnSJUtr6sENtL9OsywjLa3K6vug5 NvkIPajQLobJLVboMPOjArmOo9L9sN92Q71DUs/eW6l+zuIhtBDb2rblrH+NDQl6BtjV 1jUq8a99BucJWwMi4j3O2nyIff0Q4bt6+moQ0OYVDcgOyb/erTDl/KcAxPk8l8kMlX5T 1Wpw== X-Gm-Message-State: AOJu0YzAcWwtHzuUvqIMUO+4hWiFimqUuqZ3HcfMxi1+ipCtxBrgAjwI ThB1neTYTHW2X4nKuBQOb2U1p0o9a2obSMtM1knth2b1Kwn+MphPNxSpf/J6CsJMDg== X-Received: by 2002:a05:6358:5e0d:b0:176:5918:c3c6 with SMTP id q13-20020a0563585e0d00b001765918c3c6mr3837439rwn.9.1706566794465; Mon, 29 Jan 2024 14:19:54 -0800 (PST) Received: from localhost.localdomain ([49.47.195.100]) by smtp.gmail.com with ESMTPSA id r19-20020aa78453000000b006ddc1ae04eesm6353084pfn.192.2024.01.29.14.19.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 14:19:54 -0800 (PST) From: Rayhan Faizel To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, philmd@linaro.org, alistair@alistair23.me, pbonzini@redhat.com, qemu-arm@nongnu.org, Rayhan Faizel Subject: [PATCH v4 2/2] hw/arm: Connect SPI Controller to BCM2835 Date: Tue, 30 Jan 2024 03:48:08 +0530 Message-Id: <20240129221807.2983148-3-rayhan.faizel@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240129221807.2983148-1-rayhan.faizel@gmail.com> References: <20240129221807.2983148-1-rayhan.faizel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::330; envelope-from=rayhan.faizel@gmail.com; helo=mail-ot1-x330.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, FREEMAIL_FROM=0.001, 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-arm@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-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: gkwuU3is5e5l This patch will allow the SPI controller to be accessible from BCM2835 based boards as SPI0. SPI driver is usually disabled by default and config.txt does not work. Instead, dtmerge can be used to apply spi=on on a bcm2835 dtb file. Signed-off-by: Rayhan Faizel --- hw/arm/Kconfig | 1 + hw/arm/bcm2835_peripherals.c | 16 +++++++++++++++- include/hw/arm/bcm2835_peripherals.h | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 218b454e97..c8e0f2d78c 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -425,6 +425,7 @@ config RASPI select PL011 # UART select SDHCI select USB_DWC2 + select BCM2835_SPI config STM32F100_SOC bool diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c index 0233038b95..6b94bffb9b 100644 --- a/hw/arm/bcm2835_peripherals.c +++ b/hw/arm/bcm2835_peripherals.c @@ -144,6 +144,10 @@ static void bcm2835_peripherals_init(Object *obj) /* Power Management */ object_initialize_child(obj, "powermgt", &s->powermgt, TYPE_BCM2835_POWERMGT); + + /* SPI */ + object_initialize_child(obj, "bcm2835-spi0", &s->spi[0], + TYPE_BCM2835_SPI); } static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) @@ -402,11 +406,21 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) memory_region_add_subregion(&s->peri_mr, PM_OFFSET, sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->powermgt), 0)); + /* SPI */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[0]), errp)) { + return; + } + + memory_region_add_subregion(&s->peri_mr, SPI0_OFFSET, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->spi[0]), 0)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[0]), 0, + qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ, + INTERRUPT_SPI)); + create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); - create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20); create_unimp(s, &s->bscsl, "bcm2835-spis", BSC_SL_OFFSET, 0x100); create_unimp(s, &s->i2c[0], "bcm2835-i2c0", BSC0_OFFSET, 0x20); create_unimp(s, &s->i2c[1], "bcm2835-i2c1", BSC1_OFFSET, 0x20); diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h index d724a2fc28..0203bb79d8 100644 --- a/include/hw/arm/bcm2835_peripherals.h +++ b/include/hw/arm/bcm2835_peripherals.h @@ -31,6 +31,7 @@ #include "hw/gpio/bcm2835_gpio.h" #include "hw/timer/bcm2835_systmr.h" #include "hw/usb/hcd-dwc2.h" +#include "hw/ssi/bcm2835_spi.h" #include "hw/misc/unimp.h" #include "qom/object.h" @@ -66,7 +67,7 @@ struct BCM2835PeripheralState { BCM2835GpioState gpio; Bcm2835ThermalState thermal; UnimplementedDeviceState i2s; - UnimplementedDeviceState spi[1]; + BCM2835SPIState spi[1]; UnimplementedDeviceState i2c[3]; UnimplementedDeviceState otp; UnimplementedDeviceState dbus; -- 2.34.1