blob: d11af27a99b1032877f533fa5a050bdf23a6e12c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* G781 temperature sensor module for Chrome EC */
#include "common.h"
#include "console.h"
#include "i2c.h"
#include "temp_sensor_g781.h"
int g781_get_val(int idx, int *temp_ptr)
{
int command;
int rv;
int temp_raw = 0;
if (!board_g781_has_power())
return EC_ERROR_NOT_POWERED;
switch (idx) {
case 0:
command = G781_TEMP_LOCAL;
break;
case 1:
command = G781_TEMP_REMOTE;
break;
default:
return EC_ERROR_UNKNOWN;
}
rv = i2c_read8(I2C_PORT_THERMAL, G781_I2C_ADDR, command, &temp_raw);
if (rv < 0)
return rv;
/* Negative numbers are 2's compliment with sign bit 7 */
if (temp_raw & (1 << 7))
temp_raw = ~(~temp_raw & 0xff) + 1;
/* Temperature from sensor is in degrees Celsius */
*temp_ptr = temp_raw + 273;
return EC_SUCCESS;
}
|