All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] thermal: Add multiple instance support
Date: Tue, 19 Mar 2019 09:23:00 +0800	[thread overview]
Message-ID: <CAPnjgZ1D5KEJn=Yi8b8zFAtGHLXpg8WQ6C6wy02ZW2k+oiv-HA@mail.gmail.com> (raw)
In-Reply-To: <20190311061259.31048-2-j-keerthy@ti.com>

Hi Keerthy,

On Mon, 11 Mar 2019 at 14:13, Keerthy <j-keerthy@ti.com> wrote:
>
> Currently single instance temperature read out is supported.
> Enhance the same to support multiple instances.
>
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> ---
>  arch/arm/mach-imx/cpu.c          |  2 +-
>  drivers/mmc/omap_hsmmc.c         |  2 +-
>  drivers/thermal/imx_thermal.c    |  2 +-
>  drivers/thermal/thermal-uclass.c |  4 ++--
>  drivers/thermal/ti-bandgap.c     | 13 ++++++++++---
>  include/thermal.h                |  6 ++++--
>  6 files changed, 19 insertions(+), 10 deletions(-)

Please can you add a simple test for the thermal uclass in test/dm?

>
> diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c
> index 6b83f92662..27d12b410e 100644
> --- a/arch/arm/mach-imx/cpu.c
> +++ b/arch/arm/mach-imx/cpu.c
> @@ -231,7 +231,7 @@ int print_cpuinfo(void)
>         printf("(%dC to %dC)", minc, maxc);
>         ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
>         if (!ret) {
> -               ret = thermal_get_temp(thermal_dev, &cpu_tmp);
> +               ret = thermal_get_temp(thermal_dev, 0, &cpu_tmp);
>
>                 if (!ret)
>                         printf(" at %dC\n", cpu_tmp);
> diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c
> index 826a39fad7..1872273dd9 100644
> --- a/drivers/mmc/omap_hsmmc.c
> +++ b/drivers/mmc/omap_hsmmc.c
> @@ -642,7 +642,7 @@ static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode)
>                 printf("Couldn't get thermal device for tuning\n");
>                 return ret;
>         }
> -       ret = thermal_get_temp(thermal_dev, &temperature);
> +       ret = thermal_get_temp(thermal_dev, 0, &temperature);
>         if (ret) {
>                 printf("Couldn't get temperature for tuning\n");
>                 return ret;
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index e50b85bd59..271a61356c 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
> @@ -207,7 +207,7 @@ static int read_cpu_temperature(struct udevice *dev)
>  }
>  #endif
>
> -int imx_thermal_get_temp(struct udevice *dev, int *temp)
> +int imx_thermal_get_temp(struct udevice *dev, int instance, int *temp)
>  {
>         struct thermal_data *priv = dev_get_priv(dev);
>         int cpu_tmp = 0;
> diff --git a/drivers/thermal/thermal-uclass.c b/drivers/thermal/thermal-uclass.c
> index a4ea1e2914..b4a31280cb 100644
> --- a/drivers/thermal/thermal-uclass.c
> +++ b/drivers/thermal/thermal-uclass.c
> @@ -13,14 +13,14 @@
>  #include <linux/list.h>
>
>
> -int thermal_get_temp(struct udevice *dev, int *temp)
> +int thermal_get_temp(struct udevice *dev, u8 instance, int *temp)
>  {
>         const struct dm_thermal_ops *ops = device_get_ops(dev);
>
>         if (!ops->get_temp)
>                 return -ENOSYS;
>
> -       return ops->get_temp(dev, temp);
> +       return ops->get_temp(dev, instance, temp);
>  }
>
>  UCLASS_DRIVER(thermal) = {
> diff --git a/drivers/thermal/ti-bandgap.c b/drivers/thermal/ti-bandgap.c
> index b490391e96..6d3606b0fc 100644
> --- a/drivers/thermal/ti-bandgap.c
> +++ b/drivers/thermal/ti-bandgap.c
> @@ -27,6 +27,7 @@
>  struct ti_bandgap {
>         ulong                   base;
>         int                     temperature;    /* in mili degree celsius */
> +       int                     sens_cnt;
>  };
>
>  /*
> @@ -158,11 +159,16 @@ static int dra752_adc_to_temp[] = {
>         123800, 124200, 124600, 124900, 125000, 125000,
>  };
>
> -static int ti_bandgap_get_temp(struct udevice *dev,  int *temp)
> +static int ti_bandgap_get_temp(struct udevice *dev, u8 instance, int *temp)
>  {
>         struct ti_bandgap *bgp = dev_get_priv(dev);
>
> -       bgp->temperature = 0x3ff & readl(bgp->base + CTRL_CORE_TEMP_SENSOR_MPU);
> +       if (instance >= bgp->sens_cnt) {
> +               printf("Only %d insatnces are supported\n", bgp->sens_cnt);
> +               return -EINVAL;
> +       }
> +
> +       bgp->temperature = 0x3ff & readl(bgp->base + instance * 4);
>         *temp = dra752_adc_to_temp[bgp->temperature - DRA752_ADC_START_VALUE];
>
>         return 0;
> @@ -177,13 +183,14 @@ static int ti_bandgap_probe(struct udevice *dev)
>         struct ti_bandgap *bgp = dev_get_priv(dev);
>
>         bgp->base = devfdt_get_addr_index(dev, 1);
> +       bgp->sens_cnt = dev_get_driver_data(dev);
>
>         return 0;
>  }
>
>  static const struct udevice_id of_ti_bandgap_match[] = {
>         {
> -               .compatible = "ti,dra752-bandgap",
> +               .compatible = "ti,dra752-bandgap", .data = 3,
>         },
>         {},
>  };
> diff --git a/include/thermal.h b/include/thermal.h
> index 11d75256e0..82d80f3ded 100644
> --- a/include/thermal.h
> +++ b/include/thermal.h
> @@ -9,7 +9,7 @@
>
>  #include <dm.h>
>
> -int thermal_get_temp(struct udevice *dev, int *temp);
> +int thermal_get_temp(struct udevice *dev, u8 instance, int *temp);

Please add function comment.

>
>  /**
>   * struct dm_thermal_ops - Driver model Thermal operations
> @@ -25,9 +25,11 @@ struct dm_thermal_ops {
>          * It will enable and initialize any Thermal hardware as necessary.
>          *
>          * @dev:        The Thermal device
> +        * @instance:   The instance of sensor in case multiple sensors are
> +        *              present if single sensor then this should be 0
>          * @temp:       pointer that returns the measured temperature
>          */
> -       int (*get_temp)(struct udevice *dev, int *temp);
> +       int (*get_temp)(struct udevice *dev, u8 instance, int *temp);

I don't like the name 'instance' very much. With pwm we use 'channel'.
Would that be OK?

>  };
>
>  #endif /* _THERMAL_H_ */
> --
> 2.17.1
>

Regards,
Simon

  reply	other threads:[~2019-03-19  1:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-11  6:12 [U-Boot] [PATCH 0/3] thermal: Add multiple instance support Keerthy
2019-03-11  6:12 ` [U-Boot] [PATCH 1/3] " Keerthy
2019-03-19  1:23   ` Simon Glass [this message]
2019-03-19 14:23     ` keerthy
2019-03-21  5:22       ` Simon Glass
2019-03-11  6:12 ` [U-Boot] [PATCH 2/3] cmd: thermal: Add command line interface to read out temperatures Keerthy
2019-03-22  7:53   ` Simon Glass
2019-03-11  6:12 ` [U-Boot] [PATCH 3/3] configs: dra7xx_evm_defconfig: Enable TI_DRA7_THERMAL & CMD_THERMAL Keerthy

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='CAPnjgZ1D5KEJn=Yi8b8zFAtGHLXpg8WQ6C6wy02ZW2k+oiv-HA@mail.gmail.com' \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.