drm/radeon: add a quirk for Toshiba Satellite L20-183
[linux/fpc-iii.git] / drivers / thermal / qcom / tsens-8996.c
blobe1f77818d8fa3bd4cf4608e47820b1974f4e65fb
1 /*
2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include <linux/platform_device.h>
16 #include <linux/regmap.h>
17 #include "tsens.h"
19 #define STATUS_OFFSET 0x10a0
20 #define LAST_TEMP_MASK 0xfff
21 #define STATUS_VALID_BIT BIT(21)
22 #define CODE_SIGN_BIT BIT(11)
24 static int get_temp_8996(struct tsens_device *tmdev, int id, int *temp)
26 struct tsens_sensor *s = &tmdev->sensor[id];
27 u32 code;
28 unsigned int sensor_addr;
29 int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret;
31 sensor_addr = STATUS_OFFSET + s->hw_id * 4;
32 ret = regmap_read(tmdev->map, sensor_addr, &code);
33 if (ret)
34 return ret;
35 last_temp = code & LAST_TEMP_MASK;
36 if (code & STATUS_VALID_BIT)
37 goto done;
39 /* Try a second time */
40 ret = regmap_read(tmdev->map, sensor_addr, &code);
41 if (ret)
42 return ret;
43 if (code & STATUS_VALID_BIT) {
44 last_temp = code & LAST_TEMP_MASK;
45 goto done;
46 } else {
47 last_temp2 = code & LAST_TEMP_MASK;
50 /* Try a third/last time */
51 ret = regmap_read(tmdev->map, sensor_addr, &code);
52 if (ret)
53 return ret;
54 if (code & STATUS_VALID_BIT) {
55 last_temp = code & LAST_TEMP_MASK;
56 goto done;
57 } else {
58 last_temp3 = code & LAST_TEMP_MASK;
61 if (last_temp == last_temp2)
62 last_temp = last_temp2;
63 else if (last_temp2 == last_temp3)
64 last_temp = last_temp3;
65 done:
66 /* Code sign bit is the sign extension for a negative value */
67 if (last_temp & CODE_SIGN_BIT)
68 last_temp |= ~CODE_SIGN_BIT;
70 /* Temperatures are in deciCelicius */
71 *temp = last_temp * 100;
73 return 0;
76 static const struct tsens_ops ops_8996 = {
77 .init = init_common,
78 .get_temp = get_temp_8996,
81 const struct tsens_data data_8996 = {
82 .num_sensors = 13,
83 .ops = &ops_8996,