|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | #include <linux/regmap.h>
|
| 8 | +#include <linux/bitops.h> |
8 | 9 | #include "tsens.h"
|
9 | 10 |
|
10 | 11 | #define STATUS_OFFSET 0xa0
|
11 | 12 | #define LAST_TEMP_MASK 0xfff
|
12 | 13 | #define STATUS_VALID_BIT BIT(21)
|
13 |
| -#define CODE_SIGN_BIT BIT(11) |
14 | 14 |
|
15 | 15 | static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp)
|
16 | 16 | {
|
17 | 17 | struct tsens_sensor *s = &tmdev->sensor[id];
|
18 | 18 | u32 code;
|
19 | 19 | unsigned int status_reg;
|
20 |
| - int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret; |
| 20 | + u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0; |
| 21 | + int ret; |
21 | 22 |
|
22 | 23 | status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * 4;
|
23 | 24 | ret = regmap_read(tmdev->map, status_reg, &code);
|
@@ -54,12 +55,8 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp)
|
54 | 55 | else if (last_temp2 == last_temp3)
|
55 | 56 | last_temp = last_temp3;
|
56 | 57 | done:
|
57 |
| - /* Code sign bit is the sign extension for a negative value */ |
58 |
| - if (last_temp & CODE_SIGN_BIT) |
59 |
| - last_temp |= ~CODE_SIGN_BIT; |
60 |
| - |
61 |
| - /* Temperatures are in deciCelicius */ |
62 |
| - *temp = last_temp * 100; |
| 58 | + /* Convert temperature from deciCelsius to milliCelsius */ |
| 59 | + *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; |
63 | 60 |
|
64 | 61 | return 0;
|
65 | 62 | }
|
|
0 commit comments