lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190220103753.0b64f5cc@archlinux>
Date:   Wed, 20 Feb 2019 10:37:53 +0000
From:   Jonathan Cameron <jic23@...nel.org>
To:     Stefan Popa <stefan.popa@...log.com>
Cc:     <robh+dt@...nel.org>, <Michael.Hennerich@...log.com>,
        <knaack.h@....de>, <lars@...afoo.de>, <pmeerw@...erw.net>,
        <gregkh@...uxfoundation.org>, <linux-kernel@...r.kernel.org>,
        <linux-iio@...r.kernel.org>
Subject: Re: [PATCH 4/6] iio: imu: adis16480: Treat temperature scale in a
 generic way

On Tue, 19 Feb 2019 19:12:16 +0200
Stefan Popa <stefan.popa@...log.com> wrote:

> All supported devices provide internal temperature measurement from -40 C
> to +85 C, with +25 C representing value 0x00.
> 
> This patch treats the temperature scale in a generic way, similar to the
> accelerometer and gyroscope scales. So far, there are no temperature max
> scale differences between the supported devices. However, devices that
> will make use of this feature will be added in the future.
> 
> Signed-off-by: Stefan Popa <stefan.popa@...log.com>


Given the datasheet (well 16480 anyway as I'm lazy and only checked that
one) give the scale directly in deg C / LSB, why not just provide directly?
For 16480 it is 0.00565.

For the other channel types it also gives them this way so we could change
them all over, but probably best not to touch something that is 'working' :)

Jonathan

> ---
>  drivers/iio/imu/adis16480.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
> index 7ae71f4..cc53825 100644
> --- a/drivers/iio/imu/adis16480.c
> +++ b/drivers/iio/imu/adis16480.c
> @@ -124,6 +124,7 @@ struct adis16480_chip_info {
>  	unsigned int gyro_max_scale;
>  	unsigned int accel_max_val;
>  	unsigned int accel_max_scale;
> +	unsigned int temp_max_scale;
>  };
>  
>  enum adis16480_int_pin {
> @@ -530,6 +531,7 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
>  	const struct iio_chan_spec *chan, int *val, int *val2, long info)
>  {
>  	struct adis16480 *st = iio_priv(indio_dev);
> +	unsigned int temp, scale;
>  
>  	switch (info) {
>  	case IIO_CHAN_INFO_RAW:
> @@ -549,8 +551,15 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
>  			*val2 = 100; /* 0.0001 gauss */
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_TEMP:
> -			*val = 5;
> -			*val2 = 650000; /* 5.65 milli degree Celsius */
> +			/*
> +			 * +85 degrees Celsius = temp_max_scale
> +			 * +25 degrees Celsius = 0
> +			 * LSB, 25 degrees Celsius  = 60 / temp_max_scale
> +			 */
> +			scale = DIV_ROUND_CLOSEST_ULL(60 * 1000000LL,
> +					st->chip_info->temp_max_scale);
> +			*val = scale / 1000;
> +			*val2 = (scale % 1000) * 1000;
>  			return IIO_VAL_INT_PLUS_MICRO;
>  		case IIO_PRESSURE:
>  			*val = 0;
> @@ -561,7 +570,10 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
>  		}
>  	case IIO_CHAN_INFO_OFFSET:
>  		/* Only the temperature channel has a offset */
> -		*val = 4425; /* 25 degree Celsius = 0x0000 */
> +		temp = 25 * 1000000LL; /* 25 degree Celsius = 0x0000 */
> +		scale = DIV_ROUND_CLOSEST_ULL(60 * 1000000LL,
> +				st->chip_info->temp_max_scale);
> +		*val = DIV_ROUND_CLOSEST_ULL(temp, scale);
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		return adis16480_get_calibbias(indio_dev, chan, val);
> @@ -717,6 +729,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.gyro_max_scale = 300,
>  		.accel_max_val = IIO_M_S_2_TO_G(21973),
>  		.accel_max_scale = 18,
> +		.temp_max_scale = 10619,
>  	},
>  	[ADIS16480] = {
>  		.channels = adis16480_channels,
> @@ -725,6 +738,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.gyro_max_scale = 450,
>  		.accel_max_val = IIO_M_S_2_TO_G(12500),
>  		.accel_max_scale = 10,
> +		.temp_max_scale = 10619,
>  	},
>  	[ADIS16485] = {
>  		.channels = adis16485_channels,
> @@ -733,6 +747,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.gyro_max_scale = 450,
>  		.accel_max_val = IIO_M_S_2_TO_G(20000),
>  		.accel_max_scale = 5,
> +		.temp_max_scale = 10619,
>  	},
>  	[ADIS16488] = {
>  		.channels = adis16480_channels,
> @@ -741,6 +756,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.gyro_max_scale = 450,
>  		.accel_max_val = IIO_M_S_2_TO_G(22500),
>  		.accel_max_scale = 18,
> +		.temp_max_scale = 10619,
>  	},
>  };
>  

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ