* [PATCH resent] lis3: Add axes module parameter for custom axis-mapping
@ 2010-09-22 11:31 Takashi Iwai
2010-09-23 19:23 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2010-09-22 11:31 UTC (permalink / raw)
To: Andrew Morton; +Cc: Éric Piel, linux-kernel
The axis-mapping of lis3dev device on many (rather most) HP machines
doesn't follow the standard. When each new model appears, users need
to adjust again. Testing this requires the rebuild of kernel, thus
it's not trivial for end-users.
This patch adds a module parameter "axes" to allow a custom
axis-mapping without patching and recompiling the kernel driver.
User can pass the parameter such as axes=3,2,1. Also it can be
changed via sysfs.
Acked-by: Éric Piel <eric.piel@tremplin-utc.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
Andrew, could you pick it up in mm tree? This driver isn't maintained
in any git tree yet.
v2->v3: add the sanity-check of the axes parameter values
v1->v2: change lis3_dev.ac to an int array to be written directly via
module axes parameter
drivers/hwmon/hp_accel.c | 35 ++++++++++++++++++++---------------
drivers/hwmon/lis3lv02d.c | 36 ++++++++++++++++++++++++++++++------
drivers/hwmon/lis3lv02d.h | 8 +-------
drivers/hwmon/lis3lv02d_i2c.c | 12 +++++-------
4 files changed, 56 insertions(+), 35 deletions(-)
diff --git a/drivers/hwmon/hp_accel.c b/drivers/hwmon/hp_accel.c
index 36e9575..7e52fea 100644
--- a/drivers/hwmon/hp_accel.c
+++ b/drivers/hwmon/hp_accel.c
@@ -146,7 +146,8 @@ int lis3lv02d_acpi_write(struct lis3lv02d *lis3, int reg, u8 val)
static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi)
{
- lis3_dev.ac = *((struct axis_conversion *)dmi->driver_data);
+ memcpy(lis3_dev.axis_map, (int *)dmi->driver_data,
+ sizeof(lis3_dev.axis_map));
printk(KERN_INFO DRIVER_NAME ": hardware type %s found.\n", dmi->ident);
return 1;
@@ -154,16 +155,16 @@ static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi)
/* Represents, for each axis seen by userspace, the corresponding hw axis (+1).
* If the value is negative, the opposite of the hw value is used. */
-static struct axis_conversion lis3lv02d_axis_normal = {1, 2, 3};
-static struct axis_conversion lis3lv02d_axis_y_inverted = {1, -2, 3};
-static struct axis_conversion lis3lv02d_axis_x_inverted = {-1, 2, 3};
-static struct axis_conversion lis3lv02d_axis_z_inverted = {1, 2, -3};
-static struct axis_conversion lis3lv02d_axis_xy_swap = {2, 1, 3};
-static struct axis_conversion lis3lv02d_axis_xy_rotated_left = {-2, 1, 3};
-static struct axis_conversion lis3lv02d_axis_xy_rotated_left_usd = {-2, 1, -3};
-static struct axis_conversion lis3lv02d_axis_xy_swap_inverted = {-2, -1, 3};
-static struct axis_conversion lis3lv02d_axis_xy_rotated_right = {2, -1, 3};
-static struct axis_conversion lis3lv02d_axis_xy_swap_yz_inverted = {2, -1, -3};
+static int lis3lv02d_axis_normal[3] = {1, 2, 3};
+static int lis3lv02d_axis_y_inverted[3] = {1, -2, 3};
+static int lis3lv02d_axis_x_inverted[3] = {-1, 2, 3};
+static int lis3lv02d_axis_z_inverted[3] = {1, 2, -3};
+static int lis3lv02d_axis_xy_swap[3] = {2, 1, 3};
+static int lis3lv02d_axis_xy_rotated_left[3] = {-2, 1, 3};
+static int lis3lv02d_axis_xy_rotated_left_usd[3] = {-2, 1, -3};
+static int lis3lv02d_axis_xy_swap_inverted[3] = {-2, -1, 3};
+static int lis3lv02d_axis_xy_rotated_right[3] = {2, -1, 3};
+static int lis3lv02d_axis_xy_swap_yz_inverted[3] = {2, -1, -3};
#define AXIS_DMI_MATCH(_ident, _name, _axis) { \
.ident = _ident, \
@@ -171,7 +172,7 @@ static struct axis_conversion lis3lv02d_axis_xy_swap_yz_inverted = {2, -1, -3};
.matches = { \
DMI_MATCH(DMI_PRODUCT_NAME, _name) \
}, \
- .driver_data = &lis3lv02d_axis_##_axis \
+ .driver_data = lis3lv02d_axis_##_axis \
}
#define AXIS_DMI_MATCH2(_ident, _class1, _name1, \
@@ -183,7 +184,7 @@ static struct axis_conversion lis3lv02d_axis_xy_swap_yz_inverted = {2, -1, -3};
DMI_MATCH(DMI_##_class1, _name1), \
DMI_MATCH(DMI_##_class2, _name2), \
}, \
- .driver_data = &lis3lv02d_axis_##_axis \
+ .driver_data = lis3lv02d_axis_##_axis \
}
static struct dmi_system_id lis3lv02d_dmi_ids[] = {
/* product names are truncated to match all kinds of a same model */
@@ -299,10 +300,14 @@ static int lis3lv02d_add(struct acpi_device *device)
lis3lv02d_enum_resources(device);
/* If possible use a "standard" axes order */
- if (dmi_check_system(lis3lv02d_dmi_ids) == 0) {
+ if (lis3_dev.axis_map[0] && lis3_dev.axis_map[1] && lis3_dev.axis_map[2]) {
+ printk(KERN_INFO DRIVER_NAME ": Using custom axes %d,%d,%d\n",
+ lis3_dev.axis_map[0], lis3_dev.axis_map[1], lis3_dev.axis_map[2]);
+ } else if (dmi_check_system(lis3lv02d_dmi_ids) == 0) {
printk(KERN_INFO DRIVER_NAME ": laptop model unknown, "
"using default axes configuration\n");
- lis3_dev.ac = lis3lv02d_axis_normal;
+ memcpy(lis3_dev.axis_map, lis3lv02d_axis_normal,
+ sizeof(lis3_dev.axis_map));
}
/* call the core layer do its init */
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index 6138f03..5e15967 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -75,6 +75,30 @@ struct lis3lv02d lis3_dev = {
EXPORT_SYMBOL_GPL(lis3_dev);
+/* just like param_set_int() but does sanity-check so that it won't point
+ * over the axis array size
+ */
+static int param_set_axis(const char *val, const struct kernel_param *kp)
+{
+ int ret = param_set_int(val, kp);
+ if (!ret) {
+ int val = *(int *)kp->arg;
+ if (val < 0)
+ val = -val;
+ if (!val || val > 3)
+ return -EINVAL;
+ }
+ return ret;
+}
+
+static struct kernel_param_ops param_ops_axis = {
+ .set = param_set_axis,
+ .get = param_get_int,
+};
+
+module_param_array_named(axes, lis3_dev.axis_map, axis, NULL, 0644);
+MODULE_PARM_DESC(axes, "Axis-mapping for x,y,z directions");
+
static s16 lis3lv02d_read_8(struct lis3lv02d *lis3, int reg)
{
s8 lo;
@@ -130,9 +154,9 @@ static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
for (i = 0; i < 3; i++)
position[i] = (position[i] * lis3->scale) / LIS3_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);
+ *x = lis3lv02d_get_axis(lis3->axis_map[0], position);
+ *y = lis3lv02d_get_axis(lis3->axis_map[1], position);
+ *z = lis3lv02d_get_axis(lis3->axis_map[2], position);
}
/* conversion btw sampling rate and the register values */
@@ -479,9 +503,9 @@ int lis3lv02d_joystick_enable(void)
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);
- lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.ac.x), btns);
- lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.ac.y), btns);
- lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.ac.z), btns);
+ lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.axis_map[0]), btns);
+ lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.axis_map[1]), btns);
+ lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.axis_map[2]), btns);
err = input_register_polled_device(lis3_dev.idev);
if (err) {
diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
index 8540913..51b9ba4 100644
--- a/drivers/hwmon/lis3lv02d.h
+++ b/drivers/hwmon/lis3lv02d.h
@@ -206,12 +206,6 @@ enum lis3lv02d_click_src_8b {
CLICK_IA = 0x40,
};
-struct axis_conversion {
- s8 x;
- s8 y;
- s8 z;
-};
-
struct lis3lv02d {
void *bus_priv; /* used by the bus layer only */
int (*init) (struct lis3lv02d *lis3);
@@ -232,7 +226,7 @@ struct lis3lv02d {
struct input_polled_dev *idev; /* input device */
struct platform_device *pdev; /* platform device */
atomic_t count; /* interrupt count after last read */
- struct axis_conversion ac; /* hw -> logical axis */
+ int axis_map[3]; /* hw -> logical axis */
int mapped_btns[3];
u32 irq; /* IRQ number */
diff --git a/drivers/hwmon/lis3lv02d_i2c.c b/drivers/hwmon/lis3lv02d_i2c.c
index 8e5933b..0d4a15b 100644
--- a/drivers/hwmon/lis3lv02d_i2c.c
+++ b/drivers/hwmon/lis3lv02d_i2c.c
@@ -61,9 +61,7 @@ static int lis3_i2c_init(struct lis3lv02d *lis3)
}
/* Default axis mapping but it can be overwritten by platform data */
-static struct axis_conversion lis3lv02d_axis_map = { LIS3_DEV_X,
- LIS3_DEV_Y,
- LIS3_DEV_Z };
+static int lis3lv02d_axis_map[3] = { LIS3_DEV_X, LIS3_DEV_Y, LIS3_DEV_Z };
static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
@@ -73,13 +71,13 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
if (pdata) {
if (pdata->axis_x)
- lis3lv02d_axis_map.x = pdata->axis_x;
+ lis3lv02d_axis_map[0] = pdata->axis_x;
if (pdata->axis_y)
- lis3lv02d_axis_map.y = pdata->axis_y;
+ lis3lv02d_axis_map[1] = pdata->axis_y;
if (pdata->axis_z)
- lis3lv02d_axis_map.z = pdata->axis_z;
+ lis3lv02d_axis_map[2] = pdata->axis_z;
if (pdata->setup_resources)
ret = pdata->setup_resources();
@@ -94,7 +92,7 @@ static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
lis3_dev.read = lis3_i2c_read;
lis3_dev.write = lis3_i2c_write;
lis3_dev.irq = client->irq;
- lis3_dev.ac = lis3lv02d_axis_map;
+ memcpy(&lis3_dev.axis_map, &lis3lv02d_axis_map, sizeof(lis3_dev.axis_map));
i2c_set_clientdata(client, &lis3_dev);
ret = lis3lv02d_init_device(&lis3_dev);
--
1.7.2.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH resent] lis3: Add axes module parameter for custom axis-mapping
2010-09-22 11:31 [PATCH resent] lis3: Add axes module parameter for custom axis-mapping Takashi Iwai
@ 2010-09-23 19:23 ` Andrew Morton
2010-09-23 19:37 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2010-09-23 19:23 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Éric Piel, linux-kernel
On Wed, 22 Sep 2010 13:31:19 +0200
Takashi Iwai <tiwai@suse.de> wrote:
> The axis-mapping of lis3dev device on many (rather most) HP machines
> doesn't follow the standard. When each new model appears, users need
> to adjust again. Testing this requires the rebuild of kernel, thus
> it's not trivial for end-users.
>
> This patch adds a module parameter "axes" to allow a custom
> axis-mapping without patching and recompiling the kernel driver.
> User can pass the parameter such as axes=3,2,1. Also it can be
> changed via sysfs.
Is the sysfs interface documented anywhere?
> --- a/drivers/hwmon/hp_accel.c
> +++ b/drivers/hwmon/hp_accel.c
> @@ -146,7 +146,8 @@ int lis3lv02d_acpi_write(struct lis3lv02d *lis3, int reg, u8 val)
>
> static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi)
> {
> - lis3_dev.ac = *((struct axis_conversion *)dmi->driver_data);
> + memcpy(lis3_dev.axis_map, (int *)dmi->driver_data,
> + sizeof(lis3_dev.axis_map));
It's unobvious why the (nice) three-member struct was converted to a
(nasty) three-element array? All those typesafe struct assignments
were turned into non-typesafe memcpys?
> +module_param_array_named(axes, lis3_dev.axis_map, axis, NULL, 0644);
Just to support module_param_array_named()? If so, could have used a
union?
union axis_conversion { /* should be called lis3_axis_conversion! */
struct {
int x;
int y;
int z;
};
int as_array[3];
};
or use a tyecast in the module_param_array_named() statement, perhaps?
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH resent] lis3: Add axes module parameter for custom axis-mapping
2010-09-23 19:23 ` Andrew Morton
@ 2010-09-23 19:37 ` Takashi Iwai
0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2010-09-23 19:37 UTC (permalink / raw)
To: Andrew Morton; +Cc: Éric Piel, linux-kernel
At Thu, 23 Sep 2010 12:23:08 -0700,
Andrew Morton wrote:
>
> On Wed, 22 Sep 2010 13:31:19 +0200
> Takashi Iwai <tiwai@suse.de> wrote:
>
> > The axis-mapping of lis3dev device on many (rather most) HP machines
> > doesn't follow the standard. When each new model appears, users need
> > to adjust again. Testing this requires the rebuild of kernel, thus
> > it's not trivial for end-users.
> >
> > This patch adds a module parameter "axes" to allow a custom
> > axis-mapping without patching and recompiling the kernel driver.
> > User can pass the parameter such as axes=3,2,1. Also it can be
> > changed via sysfs.
>
> Is the sysfs interface documented anywhere?
It's the generic module parameters sysfs interface.
> > --- a/drivers/hwmon/hp_accel.c
> > +++ b/drivers/hwmon/hp_accel.c
> > @@ -146,7 +146,8 @@ int lis3lv02d_acpi_write(struct lis3lv02d *lis3, int reg, u8 val)
> >
> > static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi)
> > {
> > - lis3_dev.ac = *((struct axis_conversion *)dmi->driver_data);
> > + memcpy(lis3_dev.axis_map, (int *)dmi->driver_data,
> > + sizeof(lis3_dev.axis_map));
>
> It's unobvious why the (nice) three-member struct was converted to a
> (nasty) three-element array? All those typesafe struct assignments
> were turned into non-typesafe memcpys?
>
> > +module_param_array_named(axes, lis3_dev.axis_map, axis, NULL, 0644);
>
> Just to support module_param_array_named()?
Yes, indeed.
> If so, could have used a union?
>
> union axis_conversion { /* should be called lis3_axis_conversion! */
> struct {
> int x;
> int y;
> int z;
> };
> int as_array[3];
> };
This should be possible, yes.
> or use a tyecast in the module_param_array_named() statement, perhaps?
Using non-array for module parameter would become tricky like my
first version. I'll try to rewrite with the union expression.
thanks,
Takashi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-09-23 19:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-22 11:31 [PATCH resent] lis3: Add axes module parameter for custom axis-mapping Takashi Iwai
2010-09-23 19:23 ` Andrew Morton
2010-09-23 19:37 ` Takashi Iwai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.