diff options
Diffstat (limited to 'drivers/hwmon/lis3lv02d.c')
-rw-r--r-- | drivers/hwmon/lis3lv02d.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c index ba97ed8516bf..b2f2277cad3c 100644 --- a/drivers/hwmon/lis3lv02d.c +++ b/drivers/hwmon/lis3lv02d.c | |||
@@ -53,6 +53,20 @@ | |||
53 | #define LIS3_PWRON_DELAY_WAI_12B (5000) | 53 | #define LIS3_PWRON_DELAY_WAI_12B (5000) |
54 | #define LIS3_PWRON_DELAY_WAI_8B (3000) | 54 | #define LIS3_PWRON_DELAY_WAI_8B (3000) |
55 | 55 | ||
56 | /* | ||
57 | * LIS3LV02D spec says 1024 LSBs corresponds 1 G -> 1LSB is 1000/1024 mG | ||
58 | * LIS302D spec says: 18 mG / digit | ||
59 | * LIS3_ACCURACY is used to increase accuracy of the intermediate | ||
60 | * calculation results. | ||
61 | */ | ||
62 | #define LIS3_ACCURACY 1024 | ||
63 | /* Sensitivity values for -2G +2G scale */ | ||
64 | #define LIS3_SENSITIVITY_12B ((LIS3_ACCURACY * 1000) / 1024) | ||
65 | #define LIS3_SENSITIVITY_8B (18 * LIS3_ACCURACY) | ||
66 | |||
67 | #define LIS3_DEFAULT_FUZZ 3 | ||
68 | #define LIS3_DEFAULT_FLAT 3 | ||
69 | |||
56 | struct lis3lv02d lis3_dev = { | 70 | struct lis3lv02d lis3_dev = { |
57 | .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait), | 71 | .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait), |
58 | }; | 72 | }; |
@@ -105,6 +119,7 @@ static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3]) | |||
105 | static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z) | 119 | static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z) |
106 | { | 120 | { |
107 | int position[3]; | 121 | int position[3]; |
122 | int i; | ||
108 | 123 | ||
109 | mutex_lock(&lis3->mutex); | 124 | mutex_lock(&lis3->mutex); |
110 | position[0] = lis3->read_data(lis3, OUTX); | 125 | position[0] = lis3->read_data(lis3, OUTX); |
@@ -112,6 +127,9 @@ static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z) | |||
112 | position[2] = lis3->read_data(lis3, OUTZ); | 127 | position[2] = lis3->read_data(lis3, OUTZ); |
113 | mutex_unlock(&lis3->mutex); | 128 | mutex_unlock(&lis3->mutex); |
114 | 129 | ||
130 | for (i = 0; i < 3; i++) | ||
131 | position[i] = (position[i] * lis3->scale) / LIS3_ACCURACY; | ||
132 | |||
115 | *x = lis3lv02d_get_axis(lis3->ac.x, position); | 133 | *x = lis3lv02d_get_axis(lis3->ac.x, position); |
116 | *y = lis3lv02d_get_axis(lis3->ac.y, position); | 134 | *y = lis3lv02d_get_axis(lis3->ac.y, position); |
117 | *z = lis3lv02d_get_axis(lis3->ac.z, position); | 135 | *z = lis3lv02d_get_axis(lis3->ac.z, position); |
@@ -377,6 +395,7 @@ int lis3lv02d_joystick_enable(void) | |||
377 | { | 395 | { |
378 | struct input_dev *input_dev; | 396 | struct input_dev *input_dev; |
379 | int err; | 397 | int err; |
398 | int max_val, fuzz, flat; | ||
380 | 399 | ||
381 | if (lis3_dev.idev) | 400 | if (lis3_dev.idev) |
382 | return -EINVAL; | 401 | return -EINVAL; |
@@ -396,9 +415,12 @@ int lis3lv02d_joystick_enable(void) | |||
396 | input_dev->dev.parent = &lis3_dev.pdev->dev; | 415 | input_dev->dev.parent = &lis3_dev.pdev->dev; |
397 | 416 | ||
398 | set_bit(EV_ABS, input_dev->evbit); | 417 | set_bit(EV_ABS, input_dev->evbit); |
399 | input_set_abs_params(input_dev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); | 418 | max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY; |
400 | input_set_abs_params(input_dev, ABS_Y, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); | 419 | fuzz = (LIS3_DEFAULT_FUZZ * lis3_dev.scale) / LIS3_ACCURACY; |
401 | input_set_abs_params(input_dev, ABS_Z, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); | 420 | flat = (LIS3_DEFAULT_FLAT * lis3_dev.scale) / LIS3_ACCURACY; |
421 | input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat); | ||
422 | input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); | ||
423 | input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); | ||
402 | 424 | ||
403 | err = input_register_polled_device(lis3_dev.idev); | 425 | err = input_register_polled_device(lis3_dev.idev); |
404 | if (err) { | 426 | if (err) { |
@@ -515,6 +537,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev) | |||
515 | dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; | 537 | dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; |
516 | dev->odrs = lis3_12_rates; | 538 | dev->odrs = lis3_12_rates; |
517 | dev->odr_mask = CTRL1_DF0 | CTRL1_DF1; | 539 | dev->odr_mask = CTRL1_DF0 | CTRL1_DF1; |
540 | dev->scale = LIS3_SENSITIVITY_12B; | ||
518 | break; | 541 | break; |
519 | case WAI_8B: | 542 | case WAI_8B: |
520 | printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); | 543 | printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); |
@@ -523,6 +546,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev) | |||
523 | dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; | 546 | dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; |
524 | dev->odrs = lis3_8_rates; | 547 | dev->odrs = lis3_8_rates; |
525 | dev->odr_mask = CTRL1_DR; | 548 | dev->odr_mask = CTRL1_DR; |
549 | dev->scale = LIS3_SENSITIVITY_8B; | ||
526 | break; | 550 | break; |
527 | default: | 551 | default: |
528 | printk(KERN_ERR DRIVER_NAME | 552 | printk(KERN_ERR DRIVER_NAME |