qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Sergey Kambalin <serg.oker@gmail.com>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	 Sergey Kambalin <sergey.kambalin@auriga.com>
Subject: Re: [PATCH v4 20/45] Implement BCM2838 thermal sensor
Date: Mon, 15 Jan 2024 14:42:23 +0000	[thread overview]
Message-ID: <CAFEAcA-Uc0DGUdSUHf+SLdUwaEksawGErdRUMarbHOndKCFCxw@mail.gmail.com> (raw)
In-Reply-To: <20231208023145.1385775-21-sergey.kambalin@auriga.com>

On Fri, 8 Dec 2023 at 02:33, Sergey Kambalin <serg.oker@gmail.com> wrote:
>
> Signed-off-by: Sergey Kambalin <sergey.kambalin@auriga.com>
> ---
>  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);
>
> +    /* Thermal */
> +    object_initialize_child(obj, "thermal", &s->thermal, TYPE_BCM2838_THERMAL);
> +
>      /* 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 = BCM_SOC_PERIPHERALS_BASE(dev);
>      MemoryRegion *regs_mr;
>      MemoryRegion *mmio_mr;
> +    MemoryRegion *rng200_mr;
> +    MemoryRegion *thermal_mr;
> +    qemu_irq rng_200_irq;
>
>      int n;
>
> @@ -92,12 +98,20 @@ static void bcm2838_peripherals_realize(DeviceState *dev, 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 = 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 = 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);

These parts related to the RNG should presumably have been in
the patch which added the RNG device.

> +
> +
> +    /* THERMAL */
> +    if (!sysbus_realize(SYS_BUS_DEVICE(&s->thermal), errp)) {
> +        return;
> +    }
> +    thermal_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->thermal), 0);
> +    memory_region_add_subregion( &s->peri_low_mr, 0x15D2000, thermal_mr);
>
>      /* 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 *dev, 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;

Stray extra whitespace change -- should probably be in whichever patch
is adding the PCI device to the SoC.

> 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)
>
>      /* Temporarily disable following devices until they are implemented*/
>      const char *to_be_removed_from_dt_as_wa[] = {
> -        "brcm,bcm2711-thermal",
>          "brcm,bcm2711-genet-v5",
>      };
>
> 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 <maksim.kopusov@auriga.com>
> + *
> + * 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 size)
> +{
> +    uint32_t val = 0;
> +
> +    switch (addr) {
> +    case A_STAT:
> +        /* Temperature is always 25°C */
> +        val = FIELD_DP32(val, STAT, DATA, bcm2838_thermal_temp2adc(25));
> +        val = FIELD_DP32(val, STAT, VALID_1, 1);
> +        val = FIELD_DP32(val, STAT, VALID_2, 1);
> +
> +        break;
> +    default:
> +        qemu_log_mask(LOG_GUEST_ERROR, "%s can't access addr: 0x%"PRIx64,

addr here is a hwaddr, so HWADDR_PRIx is the right format string.

> +                     TYPE_BCM2838_THERMAL, addr);
> +    }
> +    return val;
> +}

> 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'

If you always keep a trailing comma at the end of this kind of list,
then when you add a new item to it you don't need to also edit
the previous line.

>  ))
>  system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c'))
>  system_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c'))

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


  reply	other threads:[~2024-01-15 14:43 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08  2:31 [PATCH v4 00/45] Raspberry Pi 4B machine Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 01/45] Split out common part of BCM283X classes Sergey Kambalin
2023-12-18 15:58   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 02/45] Split out common part of peripherals Sergey Kambalin
2023-12-18 15:58   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 03/45] Split out raspi machine common part Sergey Kambalin
2023-12-18 15:59   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 04/45] Introduce BCM2838 SoC Sergey Kambalin
2023-12-18 16:07   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 05/45] Add GIC-400 to " Sergey Kambalin
2023-12-18 16:23   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 06/45] Add BCM2838 GPIO stub Sergey Kambalin
2023-12-18 16:28   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 07/45] Implement BCM2838 GPIO functionality Sergey Kambalin
2023-12-18 16:35   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 08/45] Connect SD controller to BCM2838 GPIO Sergey Kambalin
2023-12-18 16:38   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 09/45] Add GPIO and SD to BCM2838 periph Sergey Kambalin
2023-12-18 16:41   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 10/45] Add BCM2838 checkpoint support Sergey Kambalin
2023-12-18 16:42   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 11/45] Introduce Raspberry PI 4 machine Sergey Kambalin
2024-01-15 12:32   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 12/45] Temporarily disable unimplemented rpi4b devices Sergey Kambalin
2024-01-15 12:37   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 13/45] Add memory region for BCM2837 RPiVid ASB Sergey Kambalin
2024-01-15 13:12   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 14/45] Add BCM2838 PCIE Root Complex Sergey Kambalin
2024-01-15 13:57   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 15/45] Add BCM2838 PCIE host Sergey Kambalin
2024-01-15 14:08   ` Peter Maydell
2024-01-29  3:18   ` Sergei Kambalin
2023-12-08  2:31 ` [PATCH v4 16/45] Enable BCM2838 PCIE Sergey Kambalin
2024-01-15 14:10   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 17/45] Add RNG200 skeleton Sergey Kambalin
2024-01-15 14:19   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 18/45] Add RNG200 RNG and RBG Sergey Kambalin
2024-01-15 14:29   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 19/45] Get rid of RNG200 timer Sergey Kambalin
2024-01-15 14:33   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 20/45] Implement BCM2838 thermal sensor Sergey Kambalin
2024-01-15 14:42   ` Peter Maydell [this message]
2023-12-08  2:31 ` [PATCH v4 21/45] Add clock_isp stub Sergey Kambalin
2024-01-15 14:43   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 22/45] Add GENET stub Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 23/45] Add GENET register structs. Part 1 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 24/45] Add GENET register structs. Part 2 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 25/45] Add GENET register structs. Part 3 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 26/45] Add GENET register structs. Part 4 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 27/45] Add GENET register access macros Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 28/45] Implement GENET register ops Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 29/45] Implement GENET MDIO Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 30/45] Implement GENET TX path Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 31/45] Implement GENET RX path Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 32/45] Enable BCM2838 GENET controller Sergey Kambalin
2024-01-15 15:13   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 33/45] Connect RNG200, PCIE and GENET to GIC Sergey Kambalin
2024-01-15 14:48   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 34/45] Add Rpi4b boot tests Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 35/45] Add mailbox test stub Sergey Kambalin
2024-01-15 14:52   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 36/45] Add mailbox test constants Sergey Kambalin
2024-01-15 14:55   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 37/45] Add mailbox tests tags. Part 1 Sergey Kambalin
2024-01-15 14:58   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 38/45] Add mailbox tests tags. Part 2 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 39/45] Add mailbox tests tags. Part 3 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 40/45] Add mailbox property tests. Part 1 Sergey Kambalin
2024-01-15 15:01   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 41/45] Add mailbox property tests. Part 2 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 42/45] Add mailbox property tests. Part 3 Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 43/45] Add missed BCM2835 properties Sergey Kambalin
2024-01-15 15:07   ` Peter Maydell
2023-12-08  2:31 ` [PATCH v4 44/45] Append added properties to mailbox test Sergey Kambalin
2023-12-08  2:31 ` [PATCH v4 45/45] Add RPi4B to paspi4.rst Sergey Kambalin
2024-01-15 15:02   ` Peter Maydell
2023-12-09 10:47 ` [PATCH v4 00/45] Raspberry Pi 4B machine Philippe Mathieu-Daudé
2023-12-19 16:11 ` Peter Maydell
2023-12-19 16:18   ` Kambalin, Sergey
2023-12-19 16:39     ` Peter Maydell
2023-12-19 17:07       ` Kambalin, Sergey
2024-01-15 15:17   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFEAcA-Uc0DGUdSUHf+SLdUwaEksawGErdRUMarbHOndKCFCxw@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=serg.oker@gmail.com \
    --cc=sergey.kambalin@auriga.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).