[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230908194509.6a4f4adc@jic23-huawei>
Date: Fri, 8 Sep 2023 19:45:09 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Matti Vaittinen <mazziesaccount@...il.com>
Cc: Matti Vaittinen <matti.vaittinen@...rohmeurope.com>,
Lars-Peter Clausen <lars@...afoo.de>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>,
Angel Iglesias <ang.iglesiasg@...il.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Andreas Klinger <ak@...klinger.de>, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/3] iio: pressure: Support ROHM BU1390
> +static int bm1390_read_temp(struct bm1390_data *data, int *temp)
> +{
> + u8 temp_reg[2] __aligned(2);
> + __be16 *temp_raw;
> + int ret;
> + s16 val;
> + bool negative;
> +
> + ret = regmap_bulk_read(data->regmap, BM1390_REG_TEMP_HI, &temp_reg,
> + sizeof(temp_reg));
> + if (ret)
> + return ret;
> +
> + if (temp_reg[0] & 0x80)
> + negative = true;
> + else
> + negative = false;
> +
> + temp_raw = (__be16 *)&temp_reg[0];
> + val = be16_to_cpu(*temp_raw);
> +
> + if (negative) {
> + /*
> + * Two's complement. I am not sure if all supported
> + * architectures actually use 2's complement represantation of
AFAIK they do. Many IIO drivers would be broken if not..
> + * signed ints. If yes, then we could just do the endianes
> + * conversion and say this is the s16 value. However, as I
> + * don't know, and as the conversion is pretty simple. let's
> + * just convert the signed 2's complement to absolute value and
> + * multiply by -1.
> + */
> + val = ~val + 1;
> + val *= -1;
> + }
> +
> + *temp = val;
> +
> + return 0;
> +}
Powered by blists - more mailing lists