]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
hwmon: (lis3) add axes module parameter for custom axis-mapping
authorTakashi Iwai <tiwai@suse.de>
Fri, 1 Oct 2010 21:14:25 +0000 (17:14 -0400)
committerGuenter Roeck <guenter.roeck@ericsson.com>
Mon, 25 Oct 2010 21:11:20 +0000 (14:11 -0700)
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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Eric Piel <eric.piel@tremplin-utc.net>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
drivers/hwmon/hp_accel.c
drivers/hwmon/lis3lv02d.c
drivers/hwmon/lis3lv02d.h
drivers/hwmon/lis3lv02d_i2c.c
drivers/hwmon/lis3lv02d_spi.c

index c5cd3db78c941e6d63468dbbb86ec354efcc8cff..a56a78412fcba4f9e8d42887cd40382d4418bd2d 100644 (file)
@@ -146,7 +146,7 @@ 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);
+       lis3_dev.ac = *((union axis_conversion *)dmi->driver_data);
        printk(KERN_INFO DRIVER_NAME ": hardware type %s found.\n", dmi->ident);
 
        return 1;
@@ -154,16 +154,19 @@ 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};
+#define DEFINE_CONV(name, x, y, z)                           \
+       static union axis_conversion lis3lv02d_axis_##name = \
+               { .as_array = { x, y, z } }
+DEFINE_CONV(normal, 1, 2, 3);
+DEFINE_CONV(y_inverted, 1, -2, 3);
+DEFINE_CONV(x_inverted, -1, 2, 3);
+DEFINE_CONV(z_inverted, 1, 2, -3);
+DEFINE_CONV(xy_swap, 2, 1, 3);
+DEFINE_CONV(xy_rotated_left, -2, 1, 3);
+DEFINE_CONV(xy_rotated_left_usd, -2, 1, -3);
+DEFINE_CONV(xy_swap_inverted, -2, -1, 3);
+DEFINE_CONV(xy_rotated_right, 2, -1, 3);
+DEFINE_CONV(xy_swap_yz_inverted, 2, -1, -3);
 
 #define AXIS_DMI_MATCH(_ident, _name, _axis) {         \
        .ident = _ident,                                \
@@ -299,7 +302,10 @@ 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.ac.x && lis3_dev.ac.y && lis3_dev.ac.z) {
+               printk(KERN_INFO DRIVER_NAME ": Using custom axes %d,%d,%d\n",
+                      lis3_dev.ac.x, lis3_dev.ac.y, lis3_dev.ac.z);
+       } 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;
index ef7510d83603e19d6fff2477f62a5c039480429f..25f3850109538b079fadec2fe22eb1220ff35f10 100644 (file)
@@ -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.ac.as_array, 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;
index 62c6652eb9d5a34fe3730307ebf27f66ef0c81ef..eb5db584eb0e646486465aa353afbe9509d1c87a 100644 (file)
@@ -223,10 +223,11 @@ enum lis3lv02d_click_src_8b {
        CLICK_IA        = 0x40,
 };
 
-struct axis_conversion {
-       s8      x;
-       s8      y;
-       s8      z;
+union axis_conversion {
+       struct {
+               int x, y, z;
+       };
+       int as_array[3];
 };
 
 struct lis3lv02d {
@@ -249,7 +250,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 */
+       union axis_conversion   ac;        /* hw -> logical axis */
        int                     mapped_btns[3];
 
        u32                     irq;       /* IRQ number */
index 8e5933b72d1956c2a931ea7176b1c589e3066968..c6f3f341127697669df47bb2133036fa64fed613 100644 (file)
@@ -61,9 +61,8 @@ 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 union axis_conversion lis3lv02d_axis_map =
+       { .as_array = { 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)
index b9be5e3a22b3825bc640d9c038c8c724e888c5b4..955544b1c71e4d9a05e0c95274ca6525500ba7ae 100644 (file)
@@ -54,7 +54,8 @@ static int lis3_spi_init(struct lis3lv02d *lis3)
        return lis3->write(lis3, CTRL_REG1, reg);
 }
 
-static struct axis_conversion lis3lv02d_axis_normal = { 1, 2, 3 };
+static union axis_conversion lis3lv02d_axis_normal =
+       { .as_array = { 1, 2, 3 } };
 
 static int __devinit lis302dl_spi_probe(struct spi_device *spi)
 {