From nobody Wed Nov 27 04:48:13 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701650171; cv=none; d=zohomail.com; s=zohoarc; b=UycVVXAlVUqQMcSZi8T5h5USJIjGp1Cbwr38KnsE61Udy2oattW6MejjHV4blI8ufNwe4HD3gnppmup1yvcqrURGWFVdd9eL1UUMs8DW6Al3f4PCA9KW+uSYyogNkqEmZvCueokbRy2w//x3Jeqg8pUxIPh3yh/g5C1ZtAV4Lg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701650171; 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=Hn3L+Coco1H6/YNonu1EoHLfU3MXIUyQ7hkFiSOQ2kE=; b=YjR4wif5ywMpSr4zyTb24wGk42Z+99zKYfdj9PkYIQxouPHA6WjwF27Hwr5Z9187A4kwGw9WFC++5PRB1ZS0yAeRxCqHKuTbwYd92XOlEyCMJL3g6B9BPSjTj3Nemy/UKY0JDnQ8YrINHh/dkZd2s7kp+Uhz19JjSTUfl+C6X68= 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 1701650171586963.0962208220717; Sun, 3 Dec 2023 16:36:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9wnn-0004m5-Gi; Sun, 03 Dec 2023 19:27:11 -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 1r9wnV-0004YQ-3j; Sun, 03 Dec 2023 19:27:00 -0500 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9wnT-0000B8-2e; Sun, 03 Dec 2023 19:26:52 -0500 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5d81c24cef2so6941467b3.2; Sun, 03 Dec 2023 16:26:49 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id l63-20020a0de242000000b005d3e6ce07e7sm2443187ywe.6.2023.12.03.16.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 16:26:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701649608; x=1702254408; 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=Hn3L+Coco1H6/YNonu1EoHLfU3MXIUyQ7hkFiSOQ2kE=; b=TMq6JgZVtfbhJ94l0DLCIgt+M0QTLFMy9/0Kfo7jbe1i7qntcgFADNAcV6aPwbuj8T d2LO6Efi6aJw+VY9AJeeB22DbJ1LHl9ubfuvj4LJROKNf1wtcfMobfcwBpB5j88qDn6z l8n+blxC6XS4CMZZWRWK9cMwH1c8gi1VeX+OVm7WJtJ+BMezhsVUMxtla9EaLT9kdKYB GohtJjtao/ZRNCiWnUfoYH1h6pcvtzU85wlRruLhQSw9ViCMgpFRzG2Uaq3dP6hSQ6j2 wgfpcn2rUbohK8eiwCVlaYD6JP+2+bIMr7renHgS8KIelDnbf7YKm1q0o95Vu4KgVQiv 1kDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701649608; x=1702254408; 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=Hn3L+Coco1H6/YNonu1EoHLfU3MXIUyQ7hkFiSOQ2kE=; b=nRXpc4y5XE/b9vV4z0o9SP6lxh2mJDBWF1QjDWpWSfI1MyUJvvicDVXIpU2zR3QfCp gZnoM/JtCGK9uH4dkz+R5iaOE8mPeOBuwpA/hTXSKmGMnI89lHJoRO/Yw0xvFhOHfCvT OSxouRXApXATtV1i3XM69PKrPhMCgV+LlWjp7r8Py1DpE5XN4WXaJ25Q+/J2qEh8V28B ZmKMjBVKh2uHB6mhV+fUn535fRDu/hDnygTnEcFu9I61NkZ+LvOkDArxI2OM4ZfmMUQD sUi3fHq4VbT9/Fu4OtFiTKSBsbdV9FLWWUoOUhZnN60HGqAXyuJIsi72JAcgg5DNuAyC vJcA== X-Gm-Message-State: AOJu0YzEIlPSql3KXH2TlczqmUayjdBUDzgjFAUv7KsFNgGNFdH4uVJQ CIiMatJPqCJIqmi+W3QQKbB8kPH89Apjlg== X-Google-Smtp-Source: AGHT+IHcK894hQ1ZjP7EK+2cnnOTgUySHfy+NHAhB8KTTleMVmURPuF2gR/dzC9QGR5QP+7cAb86bQ== X-Received: by 2002:a81:b147:0:b0:5d8:5727:80fb with SMTP id p68-20020a81b147000000b005d8572780fbmr823983ywh.84.1701649608660; Sun, 03 Dec 2023 16:26:48 -0800 (PST) From: Sergey Kambalin X-Google-Original-From: Sergey Kambalin To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, Sergey Kambalin Subject: [PATCH v3 20/45] Implement BCM2838 thermal sensor Date: Sun, 3 Dec 2023 18:25:54 -0600 Message-Id: <20231204002619.1367044-21-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204002619.1367044-1-sergey.kambalin@auriga.com> References: <20231204002619.1367044-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2607:f8b0:4864:20::112e; envelope-from=serg.oker@gmail.com; helo=mail-yw1-x112e.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-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 @gmail.com) X-ZM-MESSAGEID: 1701650415348100005 Signed-off-by: Sergey Kambalin --- hw/arm/bcm2838_peripherals.c | 27 ++++++-- hw/arm/raspi4b.c | 1 - hw/misc/bcm2838_thermal.c | 98 ++++++++++++++++++++++++++++ hw/misc/meson.build | 3 +- include/hw/arm/bcm2838_peripherals.h | 2 + include/hw/misc/bcm2838_thermal.h | 24 +++++++ 6 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 hw/misc/bcm2838_thermal.c create mode 100644 include/hw/misc/bcm2838_thermal.h diff --git a/hw/arm/bcm2838_peripherals.c b/hw/arm/bcm2838_peripherals.c index 7c489c8e8a..e9c6d47ba6 100644 --- a/hw/arm/bcm2838_peripherals.c +++ b/hw/arm/bcm2838_peripherals.c @@ -37,6 +37,9 @@ static void bcm2838_peripherals_init(Object *obj) /* Random Number Generator */ object_initialize_child(obj, "rng200", &s->rng200, TYPE_BCM2838_RNG200= ); =20 + /* Thermal */ + object_initialize_child(obj, "thermal", &s->thermal, TYPE_BCM2838_THER= MAL); + /* PCIe Host Bridge */ object_initialize_child(obj, "pcie-host", &s->pcie_host, TYPE_BCM2838_PCIE_HOST); @@ -75,6 +78,9 @@ static void bcm2838_peripherals_realize(DeviceState *dev,= Error **errp) BCMSocPeripheralBaseState *s_base =3D BCM_SOC_PERIPHERALS_BASE(dev); MemoryRegion *regs_mr; MemoryRegion *mmio_mr; + MemoryRegion *rng200_mr; + MemoryRegion *thermal_mr; + qemu_irq rng_200_irq; =20 int n; =20 @@ -92,12 +98,20 @@ static void bcm2838_peripherals_realize(DeviceState *de= v, Error **errp) if (!sysbus_realize(SYS_BUS_DEVICE(&s->rng200), errp)) { return; } - memory_region_add_subregion( - &s_base->peri_mr, RNG_OFFSET, - sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng200), 0)); - sysbus_connect_irq(SYS_BUS_DEVICE(&s->rng200), 0, - qdev_get_gpio_in_named(DEVICE(&s_base->ic), BCM2835_IC_GPU_IRQ, - INTERRUPT_RNG)); + rng200_mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng200), 0); + memory_region_add_subregion(&s_base->peri_mr, RNG_OFFSET, rng200_mr); + + rng_200_irq =3D qdev_get_gpio_in_named(DEVICE(&s_base->ic), + BCM2835_IC_GPU_IRQ, INTERRUPT_RNG= ); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->rng200), 0, rng_200_irq); + =20 + + /* THERMAL */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->thermal), errp)) { + return; + } + thermal_mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->thermal), 0); + memory_region_add_subregion( &s->peri_low_mr, 0x15D2000, thermal_mr); =20 /* Extended Mass Media Controller 2 */ object_property_set_uint(OBJECT(&s->emmc2), "sd-spec-version", 3, @@ -198,6 +212,7 @@ static void bcm2838_peripherals_realize(DeviceState *de= v, Error **errp) BCM2838_MPHI_SIZE); memory_region_add_subregion(&s_base->peri_mr, BCM2838_MPHI_OFFSET, &s->mphi_mr_alias); + /* PCIe Root Complex */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie_host), errp)) { return; diff --git a/hw/arm/raspi4b.c b/hw/arm/raspi4b.c index 7b5385b8dd..fda27d36cb 100644 --- a/hw/arm/raspi4b.c +++ b/hw/arm/raspi4b.c @@ -67,7 +67,6 @@ static void raspi4_modify_dtb(const struct arm_boot_info = *info, void *fdt) =20 /* Temporarily disable following devices until they are implemented*/ const char *to_be_removed_from_dt_as_wa[] =3D { - "brcm,bcm2711-thermal", "brcm,bcm2711-genet-v5", }; =20 diff --git a/hw/misc/bcm2838_thermal.c b/hw/misc/bcm2838_thermal.c new file mode 100644 index 0000000000..2301f657d0 --- /dev/null +++ b/hw/misc/bcm2838_thermal.c @@ -0,0 +1,98 @@ +/* + * BCM2838 dummy thermal sensor + * + * Copyright (C) 2022 Maksim Kopusov + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "hw/misc/bcm2838_thermal.h" +#include "hw/registerfields.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" + +REG32(STAT, 0x200) +FIELD(STAT, DATA, 0, 10) +FIELD(STAT, VALID_1, 10, 1) +FIELD(STAT, VALID_2, 16, 1) + +#define BCM2838_THERMAL_SIZE 0xf00 + +#define THERMAL_OFFSET_C 410040 +#define THERMAL_COEFF (-487.0f) +#define MILLIDEGREE_COEFF 1000 + +static uint16_t bcm2838_thermal_temp2adc(int temp_C) +{ + return (temp_C * MILLIDEGREE_COEFF - THERMAL_OFFSET_C) / THERMAL_COEFF; +} + +static uint64_t bcm2838_thermal_read(void *opaque, hwaddr addr, unsigned s= ize) +{ + uint32_t val =3D 0; + + switch (addr) { + case A_STAT: + /* Temperature is always 25=C2=B0C */ + val =3D FIELD_DP32(val, STAT, DATA, bcm2838_thermal_temp2adc(25)); + val =3D FIELD_DP32(val, STAT, VALID_1, 1); + val =3D FIELD_DP32(val, STAT, VALID_2, 1); + + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s can't access addr: 0x%"PRIx64, + TYPE_BCM2838_THERMAL, addr); + } + return val; +} + +static void bcm2838_thermal_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size) +{ + qemu_log_mask(LOG_GUEST_ERROR, "%s: write 0x%" PRIx64 + " to 0x%" HWADDR_PRIx "\n", + __func__, value, addr); +} + +static const MemoryRegionOps bcm2838_thermal_ops =3D { + .read =3D bcm2838_thermal_read, + .write =3D bcm2838_thermal_write, + .impl.max_access_size =3D 4, + .valid.min_access_size =3D 4, + .endianness =3D DEVICE_NATIVE_ENDIAN, +}; + +static void bcm2838_thermal_realize(DeviceState *dev, Error **errp) +{ + Bcm2838ThermalState *s =3D BCM2838_THERMAL(dev); + + memory_region_init_io(&s->iomem, OBJECT(s), &bcm2838_thermal_ops, + s, TYPE_BCM2838_THERMAL, BCM2838_THERMAL_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); +} + +static void bcm2838_thermal_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D bcm2838_thermal_realize; + + /* This device has no state: no need for vmstate or reset */ +} + +static const TypeInfo bcm2838_thermal_info =3D { + .name =3D TYPE_BCM2838_THERMAL, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(Bcm2838ThermalState), + .class_init =3D bcm2838_thermal_class_init, +}; + +static void bcm2838_thermal_register_types(void) +{ + type_register_static(&bcm2838_thermal_info); +} + +type_init(bcm2838_thermal_register_types) diff --git a/hw/misc/meson.build b/hw/misc/meson.build index b899e6b596..386471a5e4 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -91,7 +91,8 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2835_thermal.c', 'bcm2835_cprman.c', 'bcm2835_powermgt.c', - 'bcm2838_rng200.c' + 'bcm2838_rng200.c', + 'bcm2838_thermal.c' )) system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c')) diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_= peripherals.h index 317df005bf..0e8465ba34 100644 --- a/include/hw/arm/bcm2838_peripherals.h +++ b/include/hw/arm/bcm2838_peripherals.h @@ -11,6 +11,7 @@ =20 #include "hw/arm/bcm2835_peripherals.h" #include "hw/misc/bcm2838_rng200.h" +#include "hw/misc/bcm2838_thermal.h" #include "hw/arm/bcm2838_pcie.h" #include "hw/sd/sdhci.h" #include "hw/gpio/bcm2838_gpio.h" @@ -67,6 +68,7 @@ struct BCM2838PeripheralState { MemoryRegion pcie_mmio_alias; =20 BCM2838Rng200State rng200; + Bcm2838ThermalState thermal; SDHCIState emmc2; BCM2838PcieHostState pcie_host; BCM2838GpioState gpio; diff --git a/include/hw/misc/bcm2838_thermal.h b/include/hw/misc/bcm2838_th= ermal.h new file mode 100644 index 0000000000..bb6302a037 --- /dev/null +++ b/include/hw/misc/bcm2838_thermal.h @@ -0,0 +1,24 @@ +/* + * BCM2838 dummy thermal sensor + * + * Copyright (C) 2022 Maksim Kopusov + * + * 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_THERMAL_H +#define BCM2838_THERMAL_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_BCM2838_THERMAL "bcm2838-thermal" +OBJECT_DECLARE_SIMPLE_TYPE(Bcm2838ThermalState, BCM2838_THERMAL) + +struct Bcm2838ThermalState { + SysBusDevice busdev; + MemoryRegion iomem; +}; + +#endif /* BCM2838_THERMAL_H */ --=20 2.34.1