From nobody Tue Nov 26 19:58:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=telecom-paris.fr ARC-Seal: i=1; a=rsa-sha256; t=1705957830; cv=none; d=zohomail.com; s=zohoarc; b=eL1k74gY0RVUhIgpzVImkf8rgG9/K3/iKWqmBd1MDqjqYoCDMVxzBCJWw33m4lGhjl7FqJROzF6aBLQ3BJUID0eyQknTsozekyCueQ1j30++iYMVAgtEvrHDcviat+Kpp9VWvR6HhI/vXwKbJP10o1l3o+wZyTYog0SipFUTVVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705957830; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AEMspFx50s/SZFaO4v/dcT+iEvoomUtdcbA0mNzRCig=; b=YiQ3NHRTpMRTm4X29/tn1yq9QXo2wteEAyvbMa3qOHmNFjp01wa606Q8a1j+EcHp6LZE8lvw0L6XPyHEuHbwN23SSi84vz3ercWh/CmW/VvTPnoIndi1si2ALavyLAxR8LEmGxuu8ggfL4Q0ObcSTlCxeUPE18eIgHBp5jkwaKU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705957830179877.7176425006074; Mon, 22 Jan 2024 13:10:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS1Xd-0000ZF-Hu; Mon, 22 Jan 2024 16:09:13 -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 1rS1XF-0000Qi-0U; Mon, 22 Jan 2024 16:08:49 -0500 Received: from zproxy4.enst.fr ([2001:660:330f:2::df]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rS1X9-00012M-LT; Mon, 22 Jan 2024 16:08:48 -0500 Received: from localhost (localhost [IPv6:::1]) by zproxy4.enst.fr (Postfix) with ESMTP id B4ACB205DA; Mon, 22 Jan 2024 22:08:40 +0100 (CET) Received: from zproxy4.enst.fr ([IPv6:::1]) by localhost (zproxy4.enst.fr [IPv6:::1]) (amavis, port 10032) with ESMTP id V1cZrhEFQO9U; Mon, 22 Jan 2024 22:08:40 +0100 (CET) Received: from localhost (localhost [IPv6:::1]) by zproxy4.enst.fr (Postfix) with ESMTP id D7AAF20639; Mon, 22 Jan 2024 22:08:39 +0100 (CET) Received: from zproxy4.enst.fr ([IPv6:::1]) by localhost (zproxy4.enst.fr [IPv6:::1]) (amavis, port 10026) with ESMTP id snZ8lwjrH-4e; Mon, 22 Jan 2024 22:08:39 +0100 (CET) Received: from localhost.localdomain (74.0.125.80.rev.sfr.net [80.125.0.74]) by zproxy4.enst.fr (Postfix) with ESMTPSA id 2CA1C2011B; Mon, 22 Jan 2024 22:08:39 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 zproxy4.enst.fr D7AAF20639 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telecom-paris.fr; s=A35C7578-1106-11E5-A17F-C303FDDA8F2E; t=1705957719; bh=AEMspFx50s/SZFaO4v/dcT+iEvoomUtdcbA0mNzRCig=; h=From:To:Date:Message-ID:MIME-Version; b=JR9csNiqjYmXDYDl6S9YAfATS72mwKOW+CotWNjom20ZkLwwb9haXaLBgTeOa3pMl d4dguHwv4m/7NlXsi+KIpUHWC762coTfBuIjRu7pPux0hTBOa3aVkrimT/04wCNaJR iRjpmJJfFQrrw1Wx7KOckyhxdEMv06I8TPEMyTdI= X-Virus-Scanned: amavis at enst.fr From: =?UTF-8?q?In=C3=A8s=20Varhol?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Paolo Bonzini , qemu-arm@nongnu.org, Arnaud Minier , Peter Maydell , Thomas Huth , Laurent Vivier , Samuel Tardieu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?In=C3=A8s=20Varhol?= Subject: [PATCH v2 2/3] hw/arm: Connect STM32L4x5 GPIO to STM32L4x5 SoC Date: Mon, 22 Jan 2024 22:02:03 +0100 Message-ID: <20240122210829.127691-3-ines.varhol@telecom-paris.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122210829.127691-1-ines.varhol@telecom-paris.fr> References: <20240122210829.127691-1-ines.varhol@telecom-paris.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:660:330f:2::df; envelope-from=ines.varhol@telecom-paris.fr; helo=zproxy4.enst.fr 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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @telecom-paris.fr) X-ZM-MESSAGEID: 1705957832415100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Arnaud Minier Signed-off-by: In=C3=A8s Varhol --- hw/arm/Kconfig | 3 +- hw/arm/stm32l4x5_soc.c | 79 ++++++++++++++++++++++++++++------ include/hw/arm/stm32l4x5_soc.h | 2 + 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 6bd7ba424f..3e49b913f8 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -459,9 +459,10 @@ config STM32L4X5_SOC bool select ARM_V7M select OR_IRQ - select STM32L4X5_SYSCFG select STM32L4X5_EXTI + select STM32L4X5_SYSCFG select STM32L4X5_RCC + select STM32L4X5_GPIO =20 config XLNX_ZYNQMP_ARM bool diff --git a/hw/arm/stm32l4x5_soc.c b/hw/arm/stm32l4x5_soc.c index bcdad69e92..0333cbb81a 100644 --- a/hw/arm/stm32l4x5_soc.c +++ b/hw/arm/stm32l4x5_soc.c @@ -78,13 +78,45 @@ static const int exti_irq[NUM_EXTI_IRQ] =3D { #define RCC_BASE_ADDRESS 0x40021000 #define RCC_IRQ 5 =20 +static const uint32_t gpio_addr[] =3D { + 0x48000000, + 0x48000400, + 0x48000800, + 0x48000C00, + 0x48001000, + 0x48001400, + 0x48001800, + 0x48001C00, +}; + +static const struct { + uint32_t moder; + uint32_t ospeedr; + uint32_t pupdr; +} stm32l4x5_gpio_initval[NUM_GPIOS] =3D { + { 0xABFFFFFF, 0x0C000000, 0x64000000 }, + { 0xFFFFFEBF, 0x00000000, 0x00000100 }, + { 0xFFFFFFFF, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0x00000000, 0x00000000 }, + { 0x0000000F, 0x00000000, 0x00000000 }, +}; + static void stm32l4x5_soc_initfn(Object *obj) { Stm32l4x5SocState *s =3D STM32L4X5_SOC(obj); + g_autofree char *name =3D NULL; =20 object_initialize_child(obj, "exti", &s->exti, TYPE_STM32L4X5_EXTI); object_initialize_child(obj, "syscfg", &s->syscfg, TYPE_STM32L4X5_SYSC= FG); object_initialize_child(obj, "rcc", &s->rcc, TYPE_STM32L4X5_RCC); + + for (unsigned i =3D 0; i < NUM_GPIOS; i++) { + name =3D g_strdup_printf("gpio%c", 'a' + i); + object_initialize_child(obj, name, &s->gpio[i], TYPE_STM32L4X5_GPI= O); + } } =20 static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) @@ -93,8 +125,10 @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc,= Error **errp) Stm32l4x5SocState *s =3D STM32L4X5_SOC(dev_soc); const Stm32l4x5SocClass *sc =3D STM32L4X5_SOC_GET_CLASS(dev_soc); MemoryRegion *system_memory =3D get_system_memory(); - DeviceState *armv7m; + DeviceState *armv7m, *dev; SysBusDevice *busdev; + uint32_t pin_index; + g_autofree char *name =3D NULL; =20 if (!memory_region_init_rom(&s->flash, OBJECT(dev_soc), "flash", sc->flash_size, errp)) { @@ -134,17 +168,42 @@ static void stm32l4x5_soc_realize(DeviceState *dev_so= c, Error **errp) return; } =20 + /* GPIOs */ + for (unsigned i =3D 0; i < NUM_GPIOS; i++) { + dev =3D DEVICE(&s->gpio[i]); + name =3D g_strdup_printf("%c", 'A' + i); + qdev_prop_set_string(dev, "name", name); + qdev_prop_set_uint32(dev, "mode-reset", + stm32l4x5_gpio_initval[i].moder); + qdev_prop_set_uint32(dev, "ospeed-reset", + stm32l4x5_gpio_initval[i].ospeedr); + qdev_prop_set_uint32(dev, "pupd-reset", + stm32l4x5_gpio_initval[i].pupdr); + busdev =3D SYS_BUS_DEVICE(&s->gpio[i]); + name =3D g_strdup_printf("gpio%c-out", 'a' + i); + qdev_connect_clock_in(DEVICE(&s->gpio[i]), "clk", + qdev_get_clock_out(DEVICE(&(s->rcc)), name)); + if (!sysbus_realize(busdev, errp)) { + return; + } + sysbus_mmio_map(busdev, 0, gpio_addr[i]); + } + /* System configuration controller */ busdev =3D SYS_BUS_DEVICE(&s->syscfg); if (!sysbus_realize(busdev, errp)) { return; } sysbus_mmio_map(busdev, 0, SYSCFG_ADDR); - /* - * TODO: when the GPIO device is implemented, connect it - * to SYCFG using `qdev_connect_gpio_out`, NUM_GPIOS and - * GPIO_NUM_PINS. - */ + + for (unsigned i =3D 0; i < NUM_GPIOS; i++) { + for (unsigned j =3D 0; j < GPIO_NUM_PINS; j++) { + pin_index =3D GPIO_NUM_PINS * i + j; + qdev_connect_gpio_out(DEVICE(&s->gpio[i]), j, + qdev_get_gpio_in(DEVICE(&s->syscfg), + pin_index)); + } + } =20 /* EXTI device */ busdev =3D SYS_BUS_DEVICE(&s->exti); @@ -241,14 +300,6 @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc= , Error **errp) /* RESERVED: 0x40024400, 0x7FDBC00 */ =20 /* AHB2 BUS */ - create_unimplemented_device("GPIOA", 0x48000000, 0x400); - create_unimplemented_device("GPIOB", 0x48000400, 0x400); - create_unimplemented_device("GPIOC", 0x48000800, 0x400); - create_unimplemented_device("GPIOD", 0x48000C00, 0x400); - create_unimplemented_device("GPIOE", 0x48001000, 0x400); - create_unimplemented_device("GPIOF", 0x48001400, 0x400); - create_unimplemented_device("GPIOG", 0x48001800, 0x400); - create_unimplemented_device("GPIOH", 0x48001C00, 0x400); /* RESERVED: 0x48002000, 0x7FDBC00 */ create_unimplemented_device("OTG_FS", 0x50000000, 0x40000); create_unimplemented_device("ADC", 0x50040000, 0x400); diff --git a/include/hw/arm/stm32l4x5_soc.h b/include/hw/arm/stm32l4x5_soc.h index 1f71298b45..cb4da08629 100644 --- a/include/hw/arm/stm32l4x5_soc.h +++ b/include/hw/arm/stm32l4x5_soc.h @@ -29,6 +29,7 @@ #include "hw/misc/stm32l4x5_syscfg.h" #include "hw/misc/stm32l4x5_exti.h" #include "hw/misc/stm32l4x5_rcc.h" +#include "hw/gpio/stm32l4x5_gpio.h" #include "qom/object.h" =20 #define TYPE_STM32L4X5_SOC "stm32l4x5-soc" @@ -45,6 +46,7 @@ struct Stm32l4x5SocState { Stm32l4x5ExtiState exti; Stm32l4x5SyscfgState syscfg; Stm32l4x5RccState rcc; + Stm32l4x5GpioState gpio[NUM_GPIOS]; =20 MemoryRegion sram1; MemoryRegion sram2; --=20 2.43.0