From: "Éric Piel" <eric.piel@tremplin-utc.net>
To: Samu Onkalo <samu.p.onkalo@nokia.com>
Cc: daniel@caiaq.de, pavel@ucw.cz, linux-kernel@vger.kernel.org,
lm-sensors@lm-sensors.org
Subject: Re: [PATCH v2 09/10] lis3: Scale output values to mg
Date: Sun, 15 Nov 2009 16:32:02 +0100 [thread overview]
Message-ID: <4B001EF2.2090605@tremplin-utc.net> (raw)
In-Reply-To: <1257856872-11612-10-git-send-email-samu.p.onkalo@nokia.com>
Op 10-11-09 13:41, Samu Onkalo schreef:
> Report output values as 1/1000 of earth gravity.
After the discussion started by Daniel, I'm willing to accept this patch
"as is", just with a better log explaining why it's ok to break
userspace ABI:
* the sysfs "position" attribute was never safe to be read as it could
have different scales depending on the underlying hardware. It's now
featuring a consistent scale, which is more or less identical to the one
used by the 12-bits sensors
* the joystick interface reports the same values as before, excepted of
course if "raw" values are requested, in which case the same remark as
for "position" applies.
Eric
>
> Signed-off-by: Samu Onkalo <samu.p.onkalo@nokia.com>
> ---
> drivers/hwmon/lis3lv02d.c | 31 ++++++++++++++++++++++++++++---
> drivers/hwmon/lis3lv02d.h | 4 ++++
> 2 files changed, 32 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
> index be2eb97..7e72836 100644
> --- a/drivers/hwmon/lis3lv02d.c
> +++ b/drivers/hwmon/lis3lv02d.c
> @@ -53,6 +53,19 @@
> #define LIS3_PWRON_DELAY_WAI_12B (5000)
> #define LIS3_PWRON_DELAY_WAI_8B (3000)
>
> +/*
> + * LIS3LV02D spec says 1024 LSBs corresponds 1 G -> 1LSB is 1000/1024 mG
> + * LIS302D spec says: 18 mG / digit
> + * SCALING_ACCURACY is used to increase accuracy of the intermediate
> + * calculation results.
> + */
> +#define LIS3_SCALING_ACCURACY 1024
> +#define LIS3_2G2G_SENSITIVITY_WAI_12B ((LIS3_SCALING_ACCURACY * 1000) / 1024)
> +#define LIS3_2G2G_SENSITIVITY_WAI_8B (18 * LIS3_SCALING_ACCURACY)
> +
> +#define LIS3_DEFAULT_FUZZ 3
> +#define LIS3_DEFAULT_FLAT 3
> +
> struct lis3lv02d lis3_dev = {
> .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait),
> };
> @@ -105,11 +118,16 @@ static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3])
> static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
> {
> int position[3];
> + int i;
>
> position[0] = lis3->read_data(lis3, OUTX);
> position[1] = lis3->read_data(lis3, OUTY);
> position[2] = lis3->read_data(lis3, OUTZ);
>
> + for (i = 0; i < 3; i++)
> + position[i] = (position[i] * lis3->scale) /
> + LIS3_SCALING_ACCURACY;
> +
> *x = lis3lv02d_get_axis(lis3->ac.x, position);
> *y = lis3lv02d_get_axis(lis3->ac.y, position);
> *z = lis3lv02d_get_axis(lis3->ac.z, position);
> @@ -385,6 +403,7 @@ int lis3lv02d_joystick_enable(void)
> {
> struct input_dev *input_dev;
> int err;
> + int max_val, fuzz, flat;
>
> if (lis3_dev.idev)
> return -EINVAL;
> @@ -404,9 +423,13 @@ int lis3lv02d_joystick_enable(void)
> input_dev->dev.parent = &lis3_dev.pdev->dev;
>
> set_bit(EV_ABS, input_dev->evbit);
> - input_set_abs_params(input_dev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
> - input_set_abs_params(input_dev, ABS_Y, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
> - input_set_abs_params(input_dev, ABS_Z, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3);
> + max_val = (lis3_dev.mdps_max_val * lis3_dev.scale)
> + / LIS3_SCALING_ACCURACY;
> + fuzz = (LIS3_DEFAULT_FUZZ * lis3_dev.scale) / LIS3_SCALING_ACCURACY;
> + flat = (LIS3_DEFAULT_FLAT * lis3_dev.scale) / LIS3_SCALING_ACCURACY;
> + input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat);
> + input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat);
> + input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat);
>
> err = input_register_polled_device(lis3_dev.idev);
> if (err) {
> @@ -521,12 +544,14 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
> dev->read_data = lis3lv02d_read_12;
> dev->mdps_max_val = 2048;
> dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
> + dev->scale = LIS3_2G2G_SENSITIVITY_WAI_12B;
> break;
> case WAI_8B:
> printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n");
> dev->read_data = lis3lv02d_read_8;
> dev->mdps_max_val = 128;
> dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
> + dev->scale = LIS3_2G2G_SENSITIVITY_WAI_8B;
> break;
> default:
> printk(KERN_ERR DRIVER_NAME
> diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
> index a692116..42618b8 100644
> --- a/drivers/hwmon/lis3lv02d.h
> +++ b/drivers/hwmon/lis3lv02d.h
> @@ -212,6 +212,10 @@ struct lis3lv02d {
> s16 (*read_data) (struct lis3lv02d *lis3, int reg);
> int mdps_max_val;
> int pwron_delay;
> + int scale; /*
> + * relationship between 1 LBS and mG
> + * (1/1000th of earth gravity)
> + */
>
> struct input_polled_dev *idev; /* input device */
> struct platform_device *pdev; /* platform device */
next prev parent reply other threads:[~2009-11-15 15:32 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-10 12:41 [PATCH v2 00/10] LIS3: Feature updates and corrections Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 01/10] LIS3LV02D: Send sync event Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 02/10] LIS3LV02D: Correct memory leak in module unload Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 03/10] lis3: Update documentation and comments Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 04/10] lis3: fix show rate for 8 bits chips Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 05/10] LIS3LV02D: Proper power on sequence Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 06/10] LIS3LV02D: Selftest support Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 07/10] LIS3LV02D: Remove calibaration functionality Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 08/10] lis3: Sysfs entry for setting chip measurement rate Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 09/10] lis3: Scale output values to mg Samu Onkalo
2009-11-10 12:41 ` [PATCH v2 10/10] LIS3: Update documentation to match latest changes Samu Onkalo
2009-11-15 15:43 ` Éric Piel
2009-11-15 15:32 ` Éric Piel [this message]
2009-11-15 18:04 ` [PATCH v2 09/10] lis3: Scale output values to mg Pavel Machek
2009-11-15 15:20 ` [PATCH v2 08/10] lis3: Sysfs entry for setting chip measurement rate Éric Piel
2009-11-15 15:54 ` [PATCH v2 07/10] LIS3LV02D: Remove calibaration functionality Éric Piel
2009-11-15 15:08 ` [PATCH v2 06/10] LIS3LV02D: Selftest support Éric Piel
2009-11-15 15:54 ` [PATCH v2 05/10] LIS3LV02D: Proper power on sequence Éric Piel
2009-11-15 15:53 ` [PATCH v2 04/10] lis3: fix show rate for 8 bits chips Éric Piel
2009-11-15 15:49 ` [PATCH v2 02/10] LIS3LV02D: Correct memory leak in module unload Éric Piel
2009-11-15 15:49 ` [PATCH v2 01/10] LIS3LV02D: Send sync event Éric Piel
2009-11-15 16:01 ` [PATCH v2 00/10] LIS3: Feature updates and corrections Éric Piel
2009-11-16 20:03 ` Andrew Morton
2009-11-16 20:37 ` Éric Piel
2009-11-17 6:04 ` samu.p.onkalo
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=4B001EF2.2090605@tremplin-utc.net \
--to=eric.piel@tremplin-utc.net \
--cc=daniel@caiaq.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
--cc=pavel@ucw.cz \
--cc=samu.p.onkalo@nokia.com \
/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