19 #include <linux/device.h>
21 #include <linux/module.h>
24 #include <linux/slab.h>
30 static int pow_10(
unsigned power)
34 for (i = 0; i < power; ++
i)
40 static void simple_div(
int dividend,
int divisor,
int *whole,
54 while (rem <= divisor) {
58 *micro_frac = (rem /
divisor) * pow_10(6-exp);
62 static void split_micro_fraction(
unsigned int no,
int exp,
int *val1,
int *val2)
64 *val1 = no/pow_10(exp);
65 *val2 = no%pow_10(exp) * pow_10(6-exp);
76 static void convert_from_vtf_format(
u32 value,
int size,
int exp,
81 if (value &
BIT(size*8 - 1)) {
82 value = ((1
LL << (size * 8)) -
value);
85 exp = hid_sensor_convert_exponent(exp);
87 *val1 = sign * value * pow_10(exp);
90 split_micro_fraction(value, -exp, val1, val2);
92 *val1 = sign * (*val1);
94 *val2 = sign * (*val2);
98 static u32 convert_to_vtf_format(
int size,
int exp,
int val1,
int val2)
103 if (val1 < 0 || val2 < 0)
105 exp = hid_sensor_convert_exponent(exp);
107 value =
abs(val1) * pow_10(-exp);
108 value +=
abs(val2) / pow_10(6+exp);
110 value =
abs(val1) / pow_10(exp);
112 value = ((1
LL << (size * 8)) -
value);
118 int *val1,
int *val2)
125 st->
poll.index, &value);
126 if (ret < 0 || value < 0) {
131 simple_div(1000, value, val1, val2);
133 simple_div(1, value, val1, val2);
150 if (val1 < 0 || val2 < 0)
153 value = val1 * pow_10(6) + val2;
156 value = pow_10(9)/
value;
158 value = pow_10(6)/
value;
164 st->
poll.index, value);
165 if (ret < 0 || value < 0)
173 int *val1,
int *val2)
181 if (ret < 0 || value < 0) {
185 convert_from_vtf_format(value, st->
sensitivity.size,
200 value = convert_to_vtf_format(st->
sensitivity.size,
206 if (ret < 0 || value < 0)
238 hid_dbg(hsdev->
hdev,
"common attributes: %x:%x, %x:%x, %x:%x %x:%x\n",