From nobody Tue Nov 26 08:53:40 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709041446; cv=none; d=zohomail.com; s=zohoarc; b=j0+CzWO+69fzRc78iYGxvi5Tfq85sBwM56mNFcCtb4vtL5QYHm7zqFYT8K0Qfu6Y6TqM3qOHInj+8Sw7RvelhecVtdH69nLwbvf14H0iCr3sOogkiV3VTlry+nSYiaI1+onEHswxzTs5OMWDjZJtcNQb/uIBPLiNlMV3Ynk81Uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709041446; h=Content-Transfer-Encoding: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:Cc; bh=et9wQQONF7VZ2a7S3QKT8lccx9rqc3WZuS0iWjrpOdw=; b=chgN1Q4OIqN6EO9hf6eYAHHyV1kp5IjHGPTbJiJikaSR0Cl/4WRz6astQONIi0zrO8ezhKOT8Fdy/Si+uzx3HRzFYWM9bdNs+Uzq+XAGd8rvEiQl/k0m9enW1Dc/3nuGaeQHVlc4QkBtR2LDHnF720AIxWkJmQaUpueQsugxkNM= 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 1709041446694909.5789659514829; Tue, 27 Feb 2024 05:44:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rexaw-00014y-FM; 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 1rexaU-0000mr-Jn for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:39 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rexaO-0002to-Dx for qemu-devel@nongnu.org; Tue, 27 Feb 2024 08:33:38 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33ddd1624beso1083911f8f.1 for ; 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.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 05:33:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709040809; x=1709645609; 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=et9wQQONF7VZ2a7S3QKT8lccx9rqc3WZuS0iWjrpOdw=; b=IVqQYTJkwFPY88q4EbjhxckEGWjf9xe2YuX3gKCBZQoB7sTNFGOJ8jJNBXgdre29an qoEu1VRGeqUo9F7SWTjeTRmnBdAUUtYv5QK6nCUWT7xgCeVpMKPjdOcgrjU5OuK4/eSg dY96oAqu2X8+336RD9Z6EUlQ5uiOpVwQuPdJ5vknxPyjIYAtGDVe64f9e+P+0L2wB02D iTtyD+VNiAooeAGaOjv95ydGFm/jK7uf21QXe3jP37m2cFkkYdAqC+M3xkUMK0iSLkut sc3MmQizYTn5WWMDrgyUqxiW/tfO8kcSJo8uU0scQEOYizrY5Bl398gqUalbdO6qOLLw 6crA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709040809; x=1709645609; 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=et9wQQONF7VZ2a7S3QKT8lccx9rqc3WZuS0iWjrpOdw=; b=eTMfGYn2OxKCY6R8vmyGpJOMfz7R6t5T55IRC25Dpm8RCI25rfRN5Qbu26l54O0zwZ NAgOzeLiSLsk8s5cECl7AN6nr90BmRy13Gat7qnleAbrjoFytzvSFet1Y16rDbtSenUr X4tOGwoZu8GNhhOF6tD2KMB0yqCvK6sPqbHqE2dIPpGIj4vsM8GzaRRBFlf9VkXm5Cba Y/RyI4sL5LuidkLIHDZjCDN0tSMG9h96xvoDi5U3i5pNOfVbJF6WjNjCAiJE4+AOMCIn rLnvgWcFhkZoeK46cUQKTQXM8pbdOxdCpwFoLoWC7chHrlDwelz9v0XigefarIG83OMV hiLQ== X-Gm-Message-State: AOJu0YwlJj9zYES4osYyjqgn44dU0N2RVVA0dgeSv5+apkFqp2amKssq Cod9uHTOs33vD9C/eldxhAS8cGO/q1qRjq9rOY59U3b4cqDuVIbNuIYWlOhDrrvULrF5Zc8LEbk r X-Google-Smtp-Source: AGHT+IG68jtgQ9+phyNdpn4qZsYENUVJPkveR8Lz2xnnFZM1wiRoPVN273kmYngBhhC/bWDZOkXwEg== X-Received: by 2002:a5d:64e4:0:b0:33d:d843:ecd2 with SMTP id g4-20020a5d64e4000000b0033dd843ecd2mr7044120wri.24.1709040809676; Tue, 27 Feb 2024 05:33:29 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 26/45] hw/gpio: Add BCM2838 GPIO stub Date: Tue, 27 Feb 2024 13:32:55 +0000 Message-Id: <20240227133314.1721857-27-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 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=2a00:1450:4864:20::433; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x433.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709041448803100002 Content-Type: text/plain; charset="utf-8" From: Sergey Kambalin Signed-off-by: Sergey Kambalin Reviewed-by: Peter Maydell Message-id: 20240226000259.2752893-7-sergey.kambalin@auriga.com Signed-off-by: Peter Maydell --- include/hw/gpio/bcm2838_gpio.h | 40 +++++++++ hw/gpio/bcm2838_gpio.c | 153 +++++++++++++++++++++++++++++++++ hw/gpio/meson.build | 5 +- 3 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 include/hw/gpio/bcm2838_gpio.h create mode 100644 hw/gpio/bcm2838_gpio.c diff --git a/include/hw/gpio/bcm2838_gpio.h b/include/hw/gpio/bcm2838_gpio.h new file mode 100644 index 00000000000..06d48e0c191 --- /dev/null +++ b/include/hw/gpio/bcm2838_gpio.h @@ -0,0 +1,40 @@ +/* + * Raspberry Pi (BCM2838) GPIO Controller + * This implementation is based on bcm2835_gpio (hw/gpio/bcm2835_gpio.c) + * + * Copyright (c) 2022 Auriga LLC + * + * Authors: + * Lotosh, Aleksey + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef BCM2838_GPIO_H +#define BCM2838_GPIO_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_BCM2838_GPIO "bcm2838-gpio" +OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GpioState, BCM2838_GPIO) + +#define BCM2838_GPIO_REGS_SIZE 0x1000 +#define BCM2838_GPIO_NUM 58 +#define GPIO_PUP_PDN_CNTRL_NUM 4 + +struct BCM2838GpioState { + SysBusDevice parent_obj; + + MemoryRegion iomem; + + + uint8_t fsel[BCM2838_GPIO_NUM]; + uint32_t lev0, lev1; + uint8_t sd_fsel; + qemu_irq out[BCM2838_GPIO_NUM]; + uint32_t pup_cntrl_reg[GPIO_PUP_PDN_CNTRL_NUM]; +}; + +#endif diff --git a/hw/gpio/bcm2838_gpio.c b/hw/gpio/bcm2838_gpio.c new file mode 100644 index 00000000000..a312490bbd0 --- /dev/null +++ b/hw/gpio/bcm2838_gpio.c @@ -0,0 +1,153 @@ +/* + * Raspberry Pi (BCM2838) GPIO Controller + * This implementation is based on bcm2835_gpio (hw/gpio/bcm2835_gpio.c) + * + * Copyright (c) 2022 Auriga LLC + * + * Authors: + * Lotosh, Aleksey + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qapi/error.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "hw/gpio/bcm2838_gpio.h" + +#define GPFSEL0 0x00 +#define GPFSEL1 0x04 +#define GPFSEL2 0x08 +#define GPFSEL3 0x0C +#define GPFSEL4 0x10 +#define GPFSEL5 0x14 +#define GPSET0 0x1C +#define GPSET1 0x20 +#define GPCLR0 0x28 +#define GPCLR1 0x2C +#define GPLEV0 0x34 +#define GPLEV1 0x38 +#define GPEDS0 0x40 +#define GPEDS1 0x44 +#define GPREN0 0x4C +#define GPREN1 0x50 +#define GPFEN0 0x58 +#define GPFEN1 0x5C +#define GPHEN0 0x64 +#define GPHEN1 0x68 +#define GPLEN0 0x70 +#define GPLEN1 0x74 +#define GPAREN0 0x7C +#define GPAREN1 0x80 +#define GPAFEN0 0x88 +#define GPAFEN1 0x8C + +#define GPIO_PUP_PDN_CNTRL_REG0 0xE4 +#define GPIO_PUP_PDN_CNTRL_REG1 0xE8 +#define GPIO_PUP_PDN_CNTRL_REG2 0xEC +#define GPIO_PUP_PDN_CNTRL_REG3 0xF0 + +#define RESET_VAL_CNTRL_REG0 0xAAA95555 +#define RESET_VAL_CNTRL_REG1 0xA0AAAAAA +#define RESET_VAL_CNTRL_REG2 0x50AAA95A +#define RESET_VAL_CNTRL_REG3 0x00055555 + +#define BYTES_IN_WORD 4 + +static uint64_t bcm2838_gpio_read(void *opaque, hwaddr offset, unsigned si= ze) +{ + uint64_t value =3D 0; + + qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n= ", + TYPE_BCM2838_GPIO, __func__, offset); + + return value; +} + +static void bcm2838_gpio_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + qemu_log_mask(LOG_UNIMP, "%s: %s: not implemented for %"HWADDR_PRIx"\n= ", + TYPE_BCM2838_GPIO, __func__, offset); +} + +static void bcm2838_gpio_reset(DeviceState *dev) +{ + BCM2838GpioState *s =3D BCM2838_GPIO(dev); + + s->lev0 =3D 0; + s->lev1 =3D 0; + + memset(s->fsel, 0, sizeof(s->fsel)); + + s->pup_cntrl_reg[0] =3D RESET_VAL_CNTRL_REG0; + s->pup_cntrl_reg[1] =3D RESET_VAL_CNTRL_REG1; + s->pup_cntrl_reg[2] =3D RESET_VAL_CNTRL_REG2; + s->pup_cntrl_reg[3] =3D RESET_VAL_CNTRL_REG3; +} + +static const MemoryRegionOps bcm2838_gpio_ops =3D { + .read =3D bcm2838_gpio_read, + .write =3D bcm2838_gpio_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, +}; + +static const VMStateDescription vmstate_bcm2838_gpio =3D { + .name =3D "bcm2838_gpio", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8_ARRAY(fsel, BCM2838GpioState, BCM2838_GPIO_NUM), + VMSTATE_UINT32(lev0, BCM2838GpioState), + VMSTATE_UINT32(lev1, BCM2838GpioState), + VMSTATE_UINT8(sd_fsel, BCM2838GpioState), + VMSTATE_UINT32_ARRAY(pup_cntrl_reg, BCM2838GpioState, + GPIO_PUP_PDN_CNTRL_NUM), + VMSTATE_END_OF_LIST() + } +}; + +static void bcm2838_gpio_init(Object *obj) +{ + BCM2838GpioState *s =3D BCM2838_GPIO(obj); + DeviceState *dev =3D DEVICE(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + + memory_region_init_io(&s->iomem, obj, &bcm2838_gpio_ops, s, + "bcm2838_gpio", BCM2838_GPIO_REGS_SIZE); + sysbus_init_mmio(sbd, &s->iomem); + qdev_init_gpio_out(dev, s->out, BCM2838_GPIO_NUM); +} + +static void bcm2838_gpio_realize(DeviceState *dev, Error **errp) +{ + /* Temporary stub. Do nothing */ +} + +static void bcm2838_gpio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->vmsd =3D &vmstate_bcm2838_gpio; + dc->realize =3D &bcm2838_gpio_realize; + dc->reset =3D &bcm2838_gpio_reset; +} + +static const TypeInfo bcm2838_gpio_info =3D { + .name =3D TYPE_BCM2838_GPIO, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(BCM2838GpioState), + .instance_init =3D bcm2838_gpio_init, + .class_init =3D bcm2838_gpio_class_init, +}; + +static void bcm2838_gpio_register_types(void) +{ + type_register_static(&bcm2838_gpio_info); +} + +type_init(bcm2838_gpio_register_types) diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build index 066ea96480f..8a8d03d885b 100644 --- a/hw/gpio/meson.build +++ b/hw/gpio/meson.build @@ -9,6 +9,9 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.= c')) system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c')) system_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c')) system_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) -system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) +system_ss.add(when: 'CONFIG_RASPI', if_true: files( + 'bcm2835_gpio.c', + 'bcm2838_gpio.c' +)) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) --=20 2.34.1