Skip to content

Commit 6bac8fc

Browse files
LeoCX-TsaiJohnAZoidberg
authored andcommitted
hx30: implement f75303 f75397 mk function
Signed-off-by: LeoCX_Tsai <LeoCX_Tsai@compal.com>
1 parent 3e9004d commit 6bac8fc

6 files changed

Lines changed: 180 additions & 13 deletions

File tree

board/hx30/board.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,19 +1007,19 @@ const struct temp_sensor_t temp_sensors[] = {
10071007
[TEMP_SENSOR_LOCAL] = {
10081008
.name = "F75303_Local",
10091009
.type = TEMP_SENSOR_TYPE_BOARD,
1010-
.read = f75303_get_val,
1010+
.read = f75303_get_val_mk,
10111011
.idx = F75303_IDX_LOCAL
10121012
},
10131013
[TEMP_SENSOR_CPU] = {
10141014
.name = "F75303_CPU",
10151015
.type = TEMP_SENSOR_TYPE_CPU,
1016-
.read = f75303_get_val,
1016+
.read = f75303_get_val_mk,
10171017
.idx = F75303_IDX_REMOTE2
10181018
},
10191019
[TEMP_SENSOR_DDR] = {
10201020
.name = "F75303_DDR",
10211021
.type = TEMP_SENSOR_TYPE_BOARD,
1022-
.read = f75303_get_val,
1022+
.read = f75303_get_val_mk,
10231023
.idx = F75303_IDX_REMOTE1
10241024
},
10251025
[TEMP_SENSOR_BATTERY] = {
@@ -1039,7 +1039,7 @@ const struct temp_sensor_t temp_sensors[] = {
10391039
[TEMP_SENSOR2_REMOTE] = {
10401040
.name = "F75397_VCCGT",
10411041
.type = TEMP_SENSOR_TYPE_BOARD,
1042-
.read = f75397_get_val,
1042+
.read = f75397_get_val_mk,
10431043
.idx = F75397_IDX_REMOTE1
10441044
},
10451045
};

driver/temp_sensor/f75303.c

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#include "hooks.h"
1212
#include "util.h"
1313
#include "console.h"
14+
#include "math_util.h"
15+
16+
#define F75303_RESOLUTION 11
17+
#define F75303_SHIFT1 (16 - F75303_RESOLUTION)
18+
#define F75303_SHIFT2 (F75303_RESOLUTION - 8)
1419

1520
static int temps[F75303_IDX_COUNT];
1621
static int8_t fake_temp[F75303_IDX_COUNT] = {-1, -1, -1};
@@ -33,6 +38,7 @@ static int raw_read8(const int offset, int *data)
3338
offset, data);
3439
}
3540

41+
#ifndef CONFIG_CUSTOMZIED_DESIGN
3642
static int get_temp(const int offset, int *temp)
3743
{
3844
int rv;
@@ -47,6 +53,40 @@ static int get_temp(const int offset, int *temp)
4753
*temp = C_TO_K(temp_raw);
4854
return EC_SUCCESS;
4955
}
56+
#else
57+
static int get_temp( const int offset, int *temp)
58+
{
59+
int rv;
60+
int data = 0;
61+
int temp_raw = 0;
62+
63+
/* read high byte (1 degree) and low byte (0.125 degree)*/
64+
switch (offset) {
65+
case F75303_TEMP_LOCAL_REGISTER:
66+
rv = raw_read8(offset, &temp_raw);
67+
rv = raw_read8(F75303_TEMP_LOCAL_LOW_REGISTER, &data);
68+
break;
69+
case F75303_TEMP_REMOTE1_REGISTER:
70+
rv = raw_read8(offset, &temp_raw);
71+
rv = raw_read8(F75303_TEMP_REMOTE1_LOW_REGISTER, &data);
72+
break;
73+
case F75303_TEMP_REMOTE2_REGISTER:
74+
rv = raw_read8(offset, &temp_raw);
75+
rv = raw_read8(F75303_TEMP_REMOTE2_LOW_REGISTER, &data);
76+
break;
77+
default:
78+
rv = EC_ERROR_INVAL;
79+
}
80+
81+
if (rv != 0)
82+
return rv;
83+
84+
temp_raw = (temp_raw * 1000) + ((data >> 4) * 125);
85+
*temp = MILLI_CELSIUS_TO_MILLI_KELVIN(temp_raw);
86+
87+
return EC_SUCCESS;
88+
}
89+
#endif /* !CONFIG_CUSTOMIZED_DESIGN */
5090

5191
int f75303_get_val(int idx, int *temp)
5292
{
@@ -64,12 +104,39 @@ int f75303_get_val(int idx, int *temp)
64104
return EC_SUCCESS;
65105
}
66106

107+
static inline int f75303_reg_to_mk(int16_t reg)
108+
{
109+
int temp_mc;
110+
111+
temp_mc = (((reg >> F75303_SHIFT1) * 1000) >> F75303_SHIFT2);
112+
113+
return MILLI_CELSIUS_TO_MILLI_KELVIN(temp_mc);
114+
}
115+
116+
int f75303_get_val_k(int idx, int *temp_k_ptr)
117+
{
118+
if (idx >= F75303_IDX_COUNT)
119+
return EC_ERROR_INVAL;
120+
121+
*temp_k_ptr = MILLI_KELVIN_TO_KELVIN(temps[idx]);
122+
return EC_SUCCESS;
123+
}
124+
125+
int f75303_get_val_mk(int idx, int *temp_mk_ptr)
126+
{
127+
if (idx >= F75303_IDX_COUNT)
128+
return EC_ERROR_INVAL;
129+
130+
*temp_mk_ptr = temps[idx];
131+
return EC_SUCCESS;
132+
}
133+
67134
static void f75303_sensor_poll(void)
68135
{
69136
if (f75303_enabled) {
70-
get_temp(F75303_TEMP_LOCAL, &temps[F75303_IDX_LOCAL]);
71-
get_temp(F75303_TEMP_REMOTE1, &temps[F75303_IDX_REMOTE1]);
72-
get_temp(F75303_TEMP_REMOTE2, &temps[F75303_IDX_REMOTE2]);
137+
get_temp(F75303_TEMP_LOCAL_REGISTER, &temps[F75303_IDX_LOCAL]);
138+
get_temp(F75303_TEMP_REMOTE1_REGISTER, &temps[F75303_IDX_REMOTE1]);
139+
get_temp(F75303_TEMP_REMOTE2_REGISTER, &temps[F75303_IDX_REMOTE2]);
73140
}
74141
}
75142
DECLARE_HOOK(HOOK_SECOND, f75303_sensor_poll, HOOK_PRIO_TEMP_SENSOR);

driver/temp_sensor/f75303.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
#endif
1717

1818
enum f75303_index {
19-
F75303_IDX_LOCAL = 0,
19+
F75303_IDX_LOCAL,
2020
F75303_IDX_REMOTE1,
2121
F75303_IDX_REMOTE2,
2222
F75303_IDX_COUNT,
2323
};
24-
2524
/* F75303 register */
26-
#define F75303_TEMP_LOCAL 0x00
27-
#define F75303_TEMP_REMOTE1 0x01
28-
#define F75303_TEMP_REMOTE2 0x23
25+
#define F75303_TEMP_LOCAL_REGISTER 0x00
26+
#define F75303_TEMP_LOCAL_LOW_REGISTER 0x29
27+
#define F75303_TEMP_REMOTE1_REGISTER 0x01
28+
#define F75303_TEMP_REMOTE1_LOW_REGISTER 0x10
29+
#define F75303_TEMP_REMOTE2_REGISTER 0x23
30+
#define F75303_TEMP_REMOTE2_LOW_REGISTER 0x24
2931

3032
/**
3133
* Get the last polled value of a sensor.
@@ -38,6 +40,30 @@ enum f75303_index {
3840
*/
3941
int f75303_get_val(int idx, int *temp);
4042

43+
/**
44+
* Get the last polled value of a sensor.
45+
*
46+
* @param idx Index to read, from board's enum f75303_sensor
47+
* definition
48+
*
49+
* @param temp_k_ptr Destination for temperature in K.
50+
*
51+
* @return EC_SUCCESS if successful, non-zero if error.
52+
*/
53+
int f75303_get_val_k(int idx, int *temp_k_ptr);
54+
55+
/**
56+
* Get the last polled value of a sensor.
57+
*
58+
* @param idx Index to read, from board's enum f75303_sensor
59+
* definition
60+
*
61+
* @param temp_mk_ptr Destination for temperature in mK.
62+
*
63+
* @return EC_SUCCESS if successful, non-zero if error.
64+
*/
65+
int f75303_get_val_mk(int idx, int *temp_mk_ptr);
66+
4167
/**
4268
* Set if the underlying polling task will read the sensor
4369
* or if it will skip, as the rail this sensor is on

driver/temp_sensor/f75397.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "hooks.h"
1212
#include "util.h"
1313
#include "console.h"
14+
#include "math_util.h"
1415

1516
static int temps[F75397_IDX_COUNT];
1617
static int8_t fake_temp[F75397_IDX_COUNT] = {-1, -1};
@@ -32,7 +33,7 @@ static int raw_read8(const int offset, int *data)
3233
return i2c_read8(I2C_PORT_THERMAL, F75397_I2C_ADDR_FLAGS,
3334
offset, data);
3435
}
35-
36+
#ifndef CONFIG_CUSTOMIZED_DESIGN
3637
static int get_temp(const int offset, int *temp)
3738
{
3839
int rv;
@@ -47,6 +48,35 @@ static int get_temp(const int offset, int *temp)
4748
*temp = C_TO_K(temp_raw);
4849
return EC_SUCCESS;
4950
}
51+
#else
52+
static int get_temp(const int offset, int *temp)
53+
{
54+
int rv;
55+
int data = 0;
56+
int temp_raw = 0;
57+
58+
/* read high byte (1 degree) and low byte (0.125 degree)*/
59+
switch (offset) {
60+
case F75397_TEMP_LOCAL:
61+
rv = raw_read8(offset, &temp_raw);
62+
break;
63+
case F75397_TEMP_REMOTE1:
64+
rv = raw_read8(offset, &temp_raw);
65+
rv = raw_read8(F75397_TEMP_REMOTE1_LOW_REGISTER, &data);
66+
break;
67+
default:
68+
rv = EC_ERROR_INVAL;
69+
}
70+
71+
if (rv != 0)
72+
return rv;
73+
74+
temp_raw = (temp_raw * 1000) + ((data >> 4) * 125);
75+
*temp = MILLI_CELSIUS_TO_MILLI_KELVIN(temp_raw);
76+
77+
return EC_SUCCESS;
78+
}
79+
#endif /* !CONFIG_CUSTOMIZED_DESIGN */
5080

5181
int f75397_get_val(int idx, int *temp)
5282
{
@@ -64,6 +94,24 @@ int f75397_get_val(int idx, int *temp)
6494
return EC_SUCCESS;
6595
}
6696

97+
int f75397_get_val_k(int idx, int *temp_k_ptr)
98+
{
99+
if (idx >= F75397_IDX_COUNT)
100+
return EC_ERROR_INVAL;
101+
102+
*temp_k_ptr = MILLI_KELVIN_TO_KELVIN(temps[idx]);
103+
return EC_SUCCESS;
104+
}
105+
106+
int f75397_get_val_mk(int idx, int *temp_mk_ptr)
107+
{
108+
if (idx >= F75397_IDX_COUNT)
109+
return EC_ERROR_INVAL;
110+
111+
*temp_mk_ptr = temps[idx];
112+
return EC_SUCCESS;
113+
}
114+
67115
static void f75397_sensor_poll(void)
68116
{
69117
if (f75397_enabled) {

driver/temp_sensor/f75397.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum f75397_index {
2020
/* F75397 register */
2121
#define F75397_TEMP_LOCAL 0x00
2222
#define F75397_TEMP_REMOTE1 0x01
23+
#define F75397_TEMP_REMOTE1_LOW_REGISTER 0x10
2324

2425
/**
2526
* Get the last polled value of a sensor.
@@ -32,6 +33,29 @@ enum f75397_index {
3233
*/
3334
int f75397_get_val(int idx, int *temp);
3435

36+
/**
37+
* Get the last polled value of a sensor.
38+
*
39+
* @param idx Index to read. Idx indicates whether to read die
40+
* temperature or external temperature.
41+
* @param temp Destination for temperature in mK.
42+
*
43+
* @return EC_SUCCESS if successful, non-zero if error.
44+
*/
45+
int f75397_get_val_k(int idx, int *temp_k_ptr);
46+
47+
/**
48+
* Get the last polled value of a sensor.
49+
*
50+
* @param idx Index to read, from board's enum f75397_sensor
51+
* definition
52+
*
53+
* @param temp_mk_ptr Destination for temperature in mK.
54+
*
55+
* @return EC_SUCCESS if successful, non-zero if error.
56+
*/
57+
int f75397_get_val_mk(int idx, int *temp_mk_ptr);
58+
3559
/**
3660
* Set if the underlying polling task will read the sensor
3761
* or if it will skip, as the rail this sensor is on

include/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@
199199
#define C_TO_K(temp_c) ((temp_c) + 273)
200200
#define K_TO_C(temp_c) ((temp_c) - 273)
201201
#define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731)
202+
#define MILLI_CELSIUS_TO_MILLI_KELVIN(temp_mc) ((temp_mc) + 273150)
202203
#define DECI_KELVIN_TO_CELSIUS(temp_dk) ((temp_dk - 2731) / 10)
204+
#define MILLI_KELVIN_TO_KELVIN(temp_mk) (round_divide((temp_mk), 1000))
203205

204206
/* Calculate a value with error margin considered. For example,
205207
* TARGET_WITH_MARGIN(X, 5) returns X' where X' * 100.5% is almost equal to

0 commit comments

Comments
 (0)