All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 6/6] rtc: isl12022: add support for temperature sensor
Date: Wed, 14 Sep 2022 17:12:30 +0200	[thread overview]
Message-ID: <YyHvXh1Zhy/wsHsD@mail.local> (raw)
In-Reply-To: <20220830100152.698506-7-linux@rasmusvillemoes.dk>

On 30/08/2022 12:01:52+0200, Rasmus Villemoes wrote:
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  drivers/rtc/rtc-isl12022.c | 81 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 81 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
> index b295ec92ee17..1bd72f436318 100644
> --- a/drivers/rtc/rtc-isl12022.c
> +++ b/drivers/rtc/rtc-isl12022.c
> @@ -17,6 +17,8 @@
>  #include <linux/of.h>
>  #include <linux/of_device.h>
>  #include <linux/regmap.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>

You should keep that list ordered

>  
>  /* ISL register offsets */
>  #define ISL12022_REG_SC		0x00
> @@ -30,6 +32,9 @@
>  #define ISL12022_REG_SR		0x07
>  #define ISL12022_REG_INT	0x08
>  
> +#define ISL12022_REG_BETA	0x0d
> +#define ISL12022_REG_TEMP_L	0x28
> +
>  /* ISL register bits */
>  #define ISL12022_HR_MIL		(1 << 7)	/* military or 24 hour time */
>  
> @@ -38,6 +43,7 @@
>  
>  #define ISL12022_INT_WRTC	(1 << 6)
>  
> +#define ISL12022_BETA_TSE	(1 << 7)
>  
>  static struct i2c_driver isl12022_driver;
>  
> @@ -48,6 +54,79 @@ struct isl12022 {
>  	bool write_enabled;	/* true if write enable is set */
>  };
>  
> +/*
> + * A user-initiated temperature conversion is not started by this function,
> + * so the temperature is updated once every ~60 seconds.
> + */
> +static int isl12022_hwmon_read_temp(struct device *dev, s32 *mC)
> +{
> +	struct isl12022 *isl12022 = dev_get_drvdata(dev);
> +	struct regmap *regmap = isl12022->regmap;
> +	u8 temp_buf[2];
> +	s32 temp;
> +	int ret;
> +
> +	ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L,
> +			       temp_buf, sizeof(temp_buf));
> +	if (ret)
> +		return ret;
> +	/*
> +	 * Temperature is represented as a 10-bit number, unit half-Kelvins.
> +	 */
> +	temp = (temp_buf[1] << 8) | temp_buf[0];
> +	temp *= 500;
> +	temp -= 273000;
> +
> +	*mC = temp;
> +
> +	return 0;
> +}
> +
> +static ssize_t
> +isl12022_hwmon_show_temp(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> +	int ret;
> +	s32 temp;
> +
> +	ret = isl12022_hwmon_read_temp(dev, &temp);
> +	if (ret)
> +		return ret;
> +
> +	return sprintf(buf, "%d\n", temp);
> +}
> +static SENSOR_DEVICE_ATTR(temp1_input, 0444, isl12022_hwmon_show_temp,
> +			  NULL, 0);
> +
> +static struct attribute *isl12022_hwmon_attrs[] = {
> +	&sensor_dev_attr_temp1_input.dev_attr.attr,
> +	NULL,
> +};
> +ATTRIBUTE_GROUPS(isl12022_hwmon);
> +
> +static void isl12022_hwmon_register(struct device *dev)
> +{
> +	struct isl12022 *isl12022;
> +	struct device *hwmon;
> +	int ret;
> +
> +	if (!IS_REACHABLE(CONFIG_HWMON))
> +		return;
> +
> +	isl12022 = dev_get_drvdata(dev);
> +
> +	ret = regmap_update_bits(isl12022->regmap, ISL12022_REG_BETA,
> +				 ISL12022_BETA_TSE, ISL12022_BETA_TSE);
> +	if (ret) {
> +		dev_warn(dev, "unable to enable temperature sensor\n");
> +		return;
> +	}
> +
> +	hwmon = devm_hwmon_device_register_with_groups(dev, "isl12022", isl12022,
> +						       isl12022_hwmon_groups);
> +	if (IS_ERR(hwmon))
> +		dev_warn(dev, "unable to register hwmon device: %pe\n", hwmon);
> +}
> +
>  /*
>   * In the routines that deal directly with the isl12022 hardware, we use
>   * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
> @@ -179,6 +258,8 @@ static int isl12022_probe(struct i2c_client *client)
>  		return PTR_ERR(isl12022->regmap);
>  	}
>  
> +	isl12022_hwmon_register(&client->dev);
> +
>  	isl12022->rtc = devm_rtc_allocate_device(&client->dev);
>  	if (IS_ERR(isl12022->rtc))
>  		return PTR_ERR(isl12022->rtc);
> -- 
> 2.37.2
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  parent reply	other threads:[~2022-09-14 15:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 10:01 [PATCH 0/6] rtc: isl12022: cleanups and hwmon support Rasmus Villemoes
2022-08-30 10:01 ` [PATCH 1/6] rtc: isl12022: stop using deprecated devm_rtc_device_register() Rasmus Villemoes
2022-08-30 10:01 ` [PATCH 2/6] rtc: isl12022: simplify some expressions Rasmus Villemoes
2022-09-14 15:08   ` Alexandre Belloni
2022-09-21  7:08     ` Rasmus Villemoes
2022-09-21  7:12       ` Alexandre Belloni
2022-08-30 10:01 ` [PATCH 3/6] rtc: isl12022: use dev_set_drvdata() instead of i2c_set_clientdata() Rasmus Villemoes
2022-08-30 10:01 ` [PATCH 4/6] rtc: isl12022: drop redundant write to HR register Rasmus Villemoes
2022-08-30 10:01 ` [PATCH 5/6] rtc: isl12022: switch to using regmap API Rasmus Villemoes
2022-08-30 10:01 ` [PATCH 6/6] rtc: isl12022: add support for temperature sensor Rasmus Villemoes
2022-08-30 13:13   ` Guenter Roeck
2022-09-14 15:12   ` Alexandre Belloni [this message]
2022-09-21  7:58     ` Rasmus Villemoes
2022-09-21  9:10       ` Alexandre Belloni
2022-09-09  8:15 ` [PATCH 0/6] rtc: isl12022: cleanups and hwmon support Rasmus Villemoes
2022-09-14 15:16   ` Alexandre Belloni
2022-09-21 11:46 ` [PATCH v2 0/9] " Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 1/9] rtc: isl12022: stop using deprecated devm_rtc_device_register() Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 2/9] rtc: isl12022: specify range_min and range_max Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 3/9] rtc: isl12022: drop a dev_info() Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 4/9] rtc: isl12022: simplify some expressions Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 5/9] rtc: isl12022: use %ptR Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 6/9] rtc: isl12022: use dev_set_drvdata() instead of i2c_set_clientdata() Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 7/9] rtc: isl12022: drop redundant write to HR register Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 8/9] rtc: isl12022: switch to using regmap API Rasmus Villemoes
2022-09-21 11:46   ` [PATCH v2 9/9] rtc: isl12022: add support for temperature sensor Rasmus Villemoes
2022-09-21 14:13     ` Guenter Roeck
2022-09-23  8:40       ` Rasmus Villemoes
2022-09-23 13:51         ` Guenter Roeck
2022-10-26 13:38     ` [PATCH v3 " Rasmus Villemoes
2022-10-26 14:46       ` Guenter Roeck
2022-11-04 11:02       ` [PATCH v4] " Rasmus Villemoes
2022-11-14 21:41         ` Alexandre Belloni
2022-10-07 13:51   ` [PATCH v2 0/9] rtc: isl12022: cleanups and hwmon support Rasmus Villemoes
2022-10-13 21:31   ` Alexandre Belloni

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=YyHvXh1Zhy/wsHsD@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=a.zummo@towertech.it \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linux@roeck-us.net \
    /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.