linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Octavian Purdila
	<octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org,
	pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org,
	robert.moore-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	rafael.j.wysocki-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [RFC PATCH 1/3] iio: export mounting matrix information
Date: Mon, 04 May 2015 12:25:04 +0100	[thread overview]
Message-ID: <55475710.9050707@kernel.org> (raw)
In-Reply-To: <1430146908-27919-2-git-send-email-octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

On 27/04/15 16:01, Octavian Purdila wrote:
> Export a new sysfs attribute that describes the placement of the
> sensor on the device in the form of a mounting matrix so that
> userspace can do the required correction to get accurate data:
> 
> corrected X = MM[0] * X + MM[1] Y + MM[2] * Z
> corrected Y = MM[3] * X + MM[4] Y + MM[5] * Z
> corrected Z = MM[6] * X + MM[7] Y + MM[8] * Z
> 
> This information is read from the device properties of the parent of
> the IIO device.
> 
> Signed-off-by: Octavian Purdila <octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Hmm.  This could be done with existing code and a new info_mask element.
The disadvantage is you'd have to change the read_raw to read_raw_multi
callback, but that's hardly a big job.  If I could be bothered, I'd
move the whole subsystem over and drop read_raw entirely.

It was introduced precisely for this sort of element.

As I mentioned deeper in the thread.  If we are going to introduce a mounting
matrix, I'd prefer a version that includes translation.  It might not matter
to many devices but it has mattered a lot to me in the past and doesn't hurt
others that much (I used to write papers on how to estimate this stuff
from black box devices).
> ---
>  Documentation/ABI/testing/sysfs-bus-iio | 11 +++++++++
>  drivers/iio/industrialio-core.c         | 42 +++++++++++++++++++++++++++++++++
>  include/linux/iio/iio.h                 |  9 +++++++
>  3 files changed, 62 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 866b4ec..d36476e 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -1375,3 +1375,14 @@ Description:
>  		The emissivity ratio of the surface in the field of view of the
>  		contactless temperature sensor.  Emissivity varies from 0 to 1,
>  		with 1 being the emissivity of a black body.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/mounting_matrix
> +KernelVersion:	4.2
> +Contact:	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> +Description:
> +		A list of 9 floating point values that describes the
> +		transformation needed to account for the way the sensor has been
> +		placed on the PCB:
> +		corrected X = MM[0] * X + MM[1] Y + MM[2] * Z
> +		corrected Y = MM[3] * X + MM[4] Y + MM[5] * Z
> +		corrected Z = MM[6] * X + MM[7] Y + MM[8] * Z
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 7c98bc1..9000c53 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -871,6 +871,45 @@ static ssize_t iio_show_dev_name(struct device *dev,
>  
>  static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
>  
> +static bool iio_get_mounting_matrix(struct iio_dev *indio_dev)
> +{
> +	int i, err;
> +
> +	err = device_property_read_u32_array(&indio_dev->dev, "mounting-matrix",
> +					     indio_dev->mounting_matrix, 9);
> +	if (!err) {
> +		int *mm = indio_dev->mounting_matrix;
> +
> +		for (i = IIO_MM_SIZE - 2; i > 0; i -= 2) {
> +			mm[i] = mm[i / 2];
> +			mm[i + 1] = 0;
> +		}
> +
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
> +static ssize_t iio_show_mounting_matrix(struct device *dev,
> +					struct device_attribute *attr,
> +					char *buf)
> +{
> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> +	char *tmp = buf;
> +	int i;
> +
> +	for (i = 0; i < IIO_MM_SIZE; i += 2) {
> +		tmp += iio_format_value(tmp, IIO_VAL_INT_PLUS_MICRO, 2,
> +					&indio_dev->mounting_matrix[i]);
> +		if (((i + 2) / 2) % 3)
Hmm. if (i != 8) should also do the job with slightly less feedling of
magic..
> +			tmp[-1] = ' ';
> +	}
> +	return tmp - buf;
> +}
> +
> +static DEVICE_ATTR(mounting_matrix, S_IRUGO, iio_show_mounting_matrix, NULL);
> +
>  static int iio_device_register_sysfs(struct iio_dev *indio_dev)
>  {
>  	int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
> @@ -920,6 +959,9 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
>  		indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
>  	if (indio_dev->name)
>  		indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
> +	if (iio_get_mounting_matrix(indio_dev))
> +		indio_dev->chan_attr_group.attrs[attrn++] =
> +			&dev_attr_mounting_matrix.attr;
>  
>  	indio_dev->groups[indio_dev->groupcounter++] =
>  		&indio_dev->chan_attr_group;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index b1e46ae..c1fa852 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -434,6 +434,8 @@ struct iio_buffer_setup_ops {
>  				   const unsigned long *scan_mask);
>  };
>  
> +#define IIO_MM_SIZE		18
> +
>  /**
>   * struct iio_dev - industrial I/O device
>   * @id:			[INTERN] used to identify device internally
> @@ -469,6 +471,12 @@ struct iio_buffer_setup_ops {
>   * @groups:		[INTERN] attribute groups
>   * @groupcounter:	[INTERN] index of next attribute group
>   * @flags:		[INTERN] file ops related flags including busy flag.
Hmm. No absolute need to have this new data in the iio_dev.  I'd do it
via the read_raw_multi callback, though this will require converting read_raw
over to that more flexible version.
> + * @mounting_matrix:	[INTERN] the mounting matrix is a series of 9
> + *			IIO_VAL_INT_PLUS_MICRO pairs that describes the
> + *			transformation needed to account for the way the sensor
> + *			has been placed on the PCB. See the mounting_matrix
> + *			entry in Documentation/ABI/testing/sysfs-bus-iio about
> + *			details of the transformation operations.
>   * @debugfs_dentry:	[INTERN] device specific debugfs dentry.
>   * @cached_reg_addr:	[INTERN] cached register address for debugfs reads.
>   */
> @@ -509,6 +517,7 @@ struct iio_dev {
>  	int				groupcounter;
>  
>  	unsigned long			flags;
> +	int				mounting_matrix[IIO_MM_SIZE];
>  #if defined(CONFIG_DEBUG_FS)
>  	struct dentry			*debugfs_dentry;
>  	unsigned			cached_reg_addr;
> 

  parent reply	other threads:[~2015-05-04 11:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 15:01 [RFC PATCH 0/3] iio: export mounting matrix Octavian Purdila
2015-04-27 15:01 ` [RFC PATCH 1/3] iio: export mounting matrix information Octavian Purdila
     [not found]   ` <1430146908-27919-2-git-send-email-octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-05-04 11:25     ` Jonathan Cameron [this message]
     [not found]       ` <55475710.9050707-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-05-04 17:48         ` Octavian Purdila
     [not found]           ` <CAE1zot+X5RV7iexE4dUPY_YBGP4Zet1S1hSmauP8-e5P59nXRQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-05 13:55             ` Jonathan Cameron
     [not found] ` <1430146908-27919-1-git-send-email-octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-04-27 15:01   ` [RFC PATCH 2/3] ACPICA: Add _PLD front and back panel constants Octavian Purdila
2015-04-27 15:01   ` [RFC PATCH 3/3] iio: derive the mounting matrix from ACPI _PLD objects Octavian Purdila
2015-04-27 15:42     ` Kuppuswamy Sathyanarayanan
     [not found]       ` <64714.10.254.87.235.1430149342.squirrel-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-04-27 15:54         ` Octavian Purdila
2015-04-27 21:57           ` sathyanarayanan kuppuswamy
2015-04-28  2:23             ` Octavian Purdila
     [not found]               ` <CAE1zot+fusrvow+s2+CmoctcSD=c2BxoSyd2b=7MBv-pg68A+Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-04  1:11                 ` Sathyanarayanan Kuppuswamy
     [not found]                   ` <5546C72E.2040101-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-05-04  8:21                     ` Octavian Purdila
     [not found]                       ` <CAE1zot+1qGPhquFH8+=MhiXNb-OoqKuiYJae3aATqntFO6Q-Jw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-04 15:23                         ` Srinivas Pandruvada
2015-05-04 11:23               ` Jonathan Cameron
2015-05-04 11:31     ` Jonathan Cameron

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=55475710.9050707@kernel.org \
    --to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
    --cc=lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=octavian.purdila-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
    --cc=rafael.j.wysocki-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=robert.moore-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).