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] [day] [month] [year] [list]
Message-ID: <502CAC6F.20105@metafoo.de>
Date:	Thu, 16 Aug 2012 10:16:47 +0200
From:	Lars-Peter Clausen <lars@...afoo.de>
To:	"Kim, Milo" <Milo.Kim@...com>
CC:	Jonathan Cameron <jic23@...nel.org>,
	"jic23@....ac.uk" <jic23@....ac.uk>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
	Sangwook Lee <sangwook.lee@...aro.org>
Subject: Re: [PATCH v3 3/3] iio: adc: add new lp8788 adc driver

On 08/16/2012 09:39 AM, Kim, Milo wrote:
> Patch v3.
> (a) Delete unnecessary blank line of description
> (b) Sort alphabetical order for header
> (c) Replace udelay() with usleep_range()
> (d) Change read_raw() in case of scale and offset
>     : result can be calculated as raw * (scaleint + scalepart * 1000000) + offset.
>       (scale: micro unit)

For IIO it should actually be (raw + offset) * scale and the result should be
in the unit which is specified in the IIO sysfs ABI document. E.g. milivolts
for voltages.

[...]
> +
> +	if (lp8788_read_multi_bytes(adc->lp, LP8788_ADC_RAW, rawdata, size))
> +		goto err;
> +
> +	msb = (rawdata[0] << 4) & 0x00000ff0;
> +	lsb = (rawdata[1] >> 4) & 0x0000000f;
> +	result = msb | lsb;
> +
> +	/* iio consumer: result = raw * scale + offset */
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		*val = result;
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_SCALE:
> +		*val = lp8788_scale[id];
> +		*val2 = 0;

Scale should be the number of millivolts per bit. Given the number in the table
above I somehow doubt that this is what you return here. Well or maybe this
part is actually used to measure up to a few kilo volts ;)

> +		return IIO_VAL_INT_PLUS_MICRO;
> +	case IIO_CHAN_INFO_OFFSET:
> +		*val = lp8788_scale[id] / 2;
> +		return IIO_VAL_INT;

As said above offset should be in the same unit as the raw result. I'd expect
it to be same for each channel.

Btw. how does the voltage mapping look in you case?

0x000 raw -> ? V
0x800 raw -> ? V
0xfff raw -> ? V

> +	default:
> +		break;
> +	}
> +
> +err:
> +	return -EINVAL;
> +}
> +
> +static const struct iio_info lp8788_adc_info = {
> +	.read_raw = &lp8788_adc_read_raw,
> +	.driver_module = THIS_MODULE,
> +};
> +
> +#define LP8788_CHAN(_id, _type) {				\
> +		.type = _type,					\
> +		.indexed = 1,					\
> +		.channel = LPADC_##_id,				\
> +		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |	\
> +			IIO_CHAN_INFO_SCALE_SEPARATE_BIT,	\
> +		.address = LP8788_ADC_RAW,			\
> +		.scan_type = IIO_ST('u', 8, 12, 4),		\

This says your sample has 8 bits and you want to store them in a 12 bit word.
This seems wrong.


> +		.scan_index = 1,				\
> +		.datasheet_name = #_id,				\
> +}
> +
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ