Commit 2ee32144 authored by Takashi Iwai's avatar Takashi Iwai Committed by Guenter Roeck

hwmon: (lis3) add axes module parameter for custom axis-mapping

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: default avatarTakashi Iwai <tiwai@suse.de>
Acked-by: default avatarEric Piel <eric.piel@tremplin-utc.net>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGuenter Roeck <guenter.roeck@ericsson.com>
parent 37394050
...@@ -146,7 +146,7 @@ int lis3lv02d_acpi_write(struct lis3lv02d *lis3, int reg, u8 val) ...@@ -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) 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); printk(KERN_INFO DRIVER_NAME ": hardware type %s found.\n", dmi->ident);
return 1; return 1;
...@@ -154,16 +154,19 @@ static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi) ...@@ -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). /* 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. */ * If the value is negative, the opposite of the hw value is used. */
static struct axis_conversion lis3lv02d_axis_normal = {1, 2, 3}; #define DEFINE_CONV(name, x, y, z) \
static struct axis_conversion lis3lv02d_axis_y_inverted = {1, -2, 3}; static union axis_conversion lis3lv02d_axis_##name = \
static struct axis_conversion lis3lv02d_axis_x_inverted = {-1, 2, 3}; { .as_array = { x, y, z } }
static struct axis_conversion lis3lv02d_axis_z_inverted = {1, 2, -3}; DEFINE_CONV(normal, 1, 2, 3);
static struct axis_conversion lis3lv02d_axis_xy_swap = {2, 1, 3}; DEFINE_CONV(y_inverted, 1, -2, 3);
static struct axis_conversion lis3lv02d_axis_xy_rotated_left = {-2, 1, 3}; DEFINE_CONV(x_inverted, -1, 2, 3);
static struct axis_conversion lis3lv02d_axis_xy_rotated_left_usd = {-2, 1, -3}; DEFINE_CONV(z_inverted, 1, 2, -3);
static struct axis_conversion lis3lv02d_axis_xy_swap_inverted = {-2, -1, 3}; DEFINE_CONV(xy_swap, 2, 1, 3);
static struct axis_conversion lis3lv02d_axis_xy_rotated_right = {2, -1, 3}; DEFINE_CONV(xy_rotated_left, -2, 1, 3);
static struct axis_conversion lis3lv02d_axis_xy_swap_yz_inverted = {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) { \ #define AXIS_DMI_MATCH(_ident, _name, _axis) { \
.ident = _ident, \ .ident = _ident, \
...@@ -299,7 +302,10 @@ static int lis3lv02d_add(struct acpi_device *device) ...@@ -299,7 +302,10 @@ static int lis3lv02d_add(struct acpi_device *device)
lis3lv02d_enum_resources(device); lis3lv02d_enum_resources(device);
/* If possible use a "standard" axes order */ /* 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, " printk(KERN_INFO DRIVER_NAME ": laptop model unknown, "
"using default axes configuration\n"); "using default axes configuration\n");
lis3_dev.ac = lis3lv02d_axis_normal; lis3_dev.ac = lis3lv02d_axis_normal;
......
...@@ -75,6 +75,30 @@ struct lis3lv02d lis3_dev = { ...@@ -75,6 +75,30 @@ struct lis3lv02d lis3_dev = {
EXPORT_SYMBOL_GPL(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) static s16 lis3lv02d_read_8(struct lis3lv02d *lis3, int reg)
{ {
s8 lo; s8 lo;
......
...@@ -223,10 +223,11 @@ enum lis3lv02d_click_src_8b { ...@@ -223,10 +223,11 @@ enum lis3lv02d_click_src_8b {
CLICK_IA = 0x40, CLICK_IA = 0x40,
}; };
struct axis_conversion { union axis_conversion {
s8 x; struct {
s8 y; int x, y, z;
s8 z; };
int as_array[3];
}; };
struct lis3lv02d { struct lis3lv02d {
...@@ -249,7 +250,7 @@ struct lis3lv02d { ...@@ -249,7 +250,7 @@ struct lis3lv02d {
struct input_polled_dev *idev; /* input device */ struct input_polled_dev *idev; /* input device */
struct platform_device *pdev; /* platform device */ struct platform_device *pdev; /* platform device */
atomic_t count; /* interrupt count after last read */ 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]; int mapped_btns[3];
u32 irq; /* IRQ number */ u32 irq; /* IRQ number */
......
...@@ -61,9 +61,8 @@ static int lis3_i2c_init(struct lis3lv02d *lis3) ...@@ -61,9 +61,8 @@ static int lis3_i2c_init(struct lis3lv02d *lis3)
} }
/* Default axis mapping but it can be overwritten by platform data */ /* Default axis mapping but it can be overwritten by platform data */
static struct axis_conversion lis3lv02d_axis_map = { LIS3_DEV_X, static union axis_conversion lis3lv02d_axis_map =
LIS3_DEV_Y, { .as_array = { LIS3_DEV_X, LIS3_DEV_Y, LIS3_DEV_Z } };
LIS3_DEV_Z };
static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client, static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
......
...@@ -54,7 +54,8 @@ static int lis3_spi_init(struct lis3lv02d *lis3) ...@@ -54,7 +54,8 @@ static int lis3_spi_init(struct lis3lv02d *lis3)
return lis3->write(lis3, CTRL_REG1, reg); 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) static int __devinit lis302dl_spi_probe(struct spi_device *spi)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment