Nami: Update for ALS and temperture sensor

Implement ALS code and add a new thermal sensor
(Fintek, F75303)

BUG=b:71839392
BRANCH=none
TEST=Verify Nami can read ALS and thermal data via I2C by ec console.

Change-Id: I0f8fd486f62508bbca30a57f435b9f26621cf34b
Signed-off-by: Elmo_Lan <elmo_lan@compal.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/863350
Commit-Ready: Elmo Lan <elmo_lan@compal.corp-partner.google.com>
Tested-by: Elmo Lan <elmo_lan@compal.corp-partner.google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Elmo Lan <elmo_lan@compal.corp-partner.google.com>
This commit is contained in:
Elmo_Lan
2018-01-12 03:45:06 -05:00
committed by chrome-bot
parent 4e39404604
commit e46d0fcbc8
6 changed files with 171 additions and 8 deletions

View File

@@ -18,10 +18,12 @@
#include "driver/pmic_tps650x30.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/accel_bma2x2.h"
#include "driver/als_opt3001.h"
#include "driver/baro_bmp280.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
#include "driver/tcpm/tcpm.h"
#include "driver/temp_sensor/f75303.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
@@ -246,9 +248,15 @@ uint16_t tcpc_get_alert_status(void)
return status;
}
/*
* F75303_Local is near CPU, and F75303_Remote is near 5V power ic.
*/
const struct temp_sensor_t temp_sensors[] = {
{"F75303_Local", TEMP_SENSOR_TYPE_BOARD, f75303_get_val,
F75303_IDX_LOCAL, 4},
{"F75303_Remote", TEMP_SENSOR_TYPE_BOARD, f75303_get_val,
F75303_IDX_REMOTE, 4},
{"Battery", TEMP_SENSOR_TYPE_BATTERY, charge_get_battery_temp, 0, 4},
/* dnojiri: Add temp sensors */
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
@@ -499,6 +507,11 @@ static struct bmi160_drv_data_t g_bmi160_data;
/* BMA255 private data */
static struct bma2x2_accel_data g_bma255_data;
static struct opt3001_drv_data_t g_opt3001_data = {
.scale = 1,
.uscale = 0,
.offset = 0,
};
/* Matrix to rotate accelrator into standard reference frame */
const matrix_3x3_t base_standard_ref = {
{ FLOAT_TO_FP(-1), 0, 0},
@@ -627,9 +640,51 @@ struct motion_sensor_t motion_sensors[] = {
},
},
},
[LID_ALS] = {
.name = "Light",
.active_mask = SENSOR_ACTIVE_S0,
.chip = MOTIONSENSE_CHIP_OPT3001,
.type = MOTIONSENSE_TYPE_LIGHT,
.location = MOTIONSENSE_LOC_LID,
.drv = &opt3001_drv,
.drv_data = &g_opt3001_data,
.port = I2C_PORT_ALS,
.addr = OPT3001_I2C_ADDR,
.rot_standard_ref = NULL,
.default_range = 0x10000, /* scale = 1; uscale = 0 */
.min_frequency = OPT3001_LIGHT_MIN_FREQ,
.max_frequency = OPT3001_LIGHT_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
.odr = 0,
.ec_rate = 0,
},
[SENSOR_CONFIG_EC_S0] = {
.odr = 1000,
.ec_rate = 0,
},
/* Sensor off in S3/S5 */
[SENSOR_CONFIG_EC_S3] = {
.odr = 0,
.ec_rate = 0,
},
/* Sensor off in S3/S5 */
[SENSOR_CONFIG_EC_S5] = {
.odr = 0,
.ec_rate = 0,
},
},
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
/* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */
const struct motion_sensor_t *motion_als_sensors[] = {
&motion_sensors[LID_ALS],
};
BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT);
/* Enable or disable input devices, based on chipset state and tablet mode */
#ifndef TEST_BUILD
void lid_angle_peripheral_enable(int enable)

View File

@@ -102,6 +102,12 @@
/* Sensor */
#define CONFIG_TEMP_SENSOR
#define CONFIG_TEMP_SENSOR_F75303
#define CONFIG_ALS
#define CONFIG_ALS_OPT3001
#define ALS_COUNT 1
#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
#define CONFIG_MKBP_EVENT
#define CONFIG_MKBP_USE_HOST_EVENT
@@ -171,6 +177,7 @@
#define I2C_PORT_GYRO NPCX_I2C_PORT3
#define I2C_PORT_ACCEL NPCX_I2C_PORT3
#define I2C_PORT_THERMAL NPCX_I2C_PORT3
#define I2C_PORT_ALS NPCX_I2C_PORT3
/* dnojiri: ALS, G-sensor */
/* I2C addresses */
@@ -190,12 +197,14 @@ enum power_signal {
X86_SLP_SUS_DEASSERTED,
X86_RSMRST_L_PGOOD,
X86_PMIC_DPWROK,
POWER_SIGNAL_COUNT
POWER_SIGNAL_COUNT,
};
enum temp_sensor_id {
TEMP_SENSOR_I2C_F75303_LOCAL = 0,
TEMP_SENSOR_I2C_F75303_REMOTE,
TEMP_SENSOR_BATTERY,
TEMP_SENSOR_COUNT
TEMP_SENSOR_COUNT,
};
/*
@@ -206,16 +215,17 @@ enum temp_sensor_id {
*/
enum sensor_id {
BASE_ACCEL = 0,
BASE_GYRO,
LID_ACCEL,
BASE_ACCEL = 0,
BASE_GYRO,
LID_ACCEL,
LID_ALS,
};
enum adc_channel {
ADC_BASE_DET,
ADC_VBUS,
ADC_AMON_BMON,
ADC_CH_COUNT
ADC_CH_COUNT,
};
enum pwm_channel {
@@ -223,7 +233,7 @@ enum pwm_channel {
PWM_CH_LED_GREEN,
PWM_CH_FAN,
/* Number of PWM channels */
PWM_CH_COUNT
PWM_CH_COUNT,
};
/* TODO(crosbug.com/p/61098): Verify the numbers below. */

View File

@@ -84,6 +84,7 @@ driver-$(CONFIG_TEMP_SENSOR_TMP006)+=temp_sensor/tmp006.o
driver-$(CONFIG_TEMP_SENSOR_TMP112)+=temp_sensor/tmp112.o
driver-$(CONFIG_TEMP_SENSOR_TMP411)+=temp_sensor/tmp411.o
driver-$(CONFIG_TEMP_SENSOR_TMP432)+=temp_sensor/tmp432.o
driver-$(CONFIG_TEMP_SENSOR_F75303)+=temp_sensor/f75303.o
# Touchpads
driver-$(CONFIG_TOUCHPAD_ELAN)+=touchpad_elan.o

View File

@@ -0,0 +1,63 @@
/* Copyright 2018 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.
*/
/* F75303 temperature sensor module for Chrome EC */
#include "common.h"
#include "f75303.h"
#include "i2c.h"
#include "hooks.h"
#include "util.h"
static int temp_val_local;
static int temp_val_remote1;
/**
* Read 8 bits register from temp sensor.
*/
static int raw_read8(const int offset, int *data_ptr)
{
return i2c_read8(I2C_PORT_THERMAL, F75303_I2C_ADDR, offset, data_ptr);
}
static int get_temp(const int offset, int *temp_ptr)
{
int rv;
int temp_raw = 0;
rv = raw_read8(offset, &temp_raw);
if (rv != 0)
return rv;
*temp_ptr = temp_raw;
return EC_SUCCESS;
}
int f75303_get_val(int idx, int *temp_ptr)
{
switch (idx) {
case F75303_IDX_LOCAL:
*temp_ptr = temp_val_local;
break;
case F75303_IDX_REMOTE:
*temp_ptr = temp_val_remote1;
break;
default:
return EC_ERROR_UNKNOWN;
}
return EC_SUCCESS;
}
static void f75303_sensor_poll(void)
{
get_temp(F75303_TEMP_LOCAL, &temp_val_local);
temp_val_local = C_TO_K(temp_val_local);
get_temp(F75303_TEMP_REMOTE, &temp_val_remote1);
temp_val_remote1 = C_TO_K(temp_val_remote1);
}
DECLARE_HOOK(HOOK_SECOND, f75303_sensor_poll, HOOK_PRIO_TEMP_SENSOR);

View File

@@ -0,0 +1,33 @@
/* Copyright 2018 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.
*/
/* F75303 temperature sensor module for Chrome EC */
#ifndef __CROS_EC_F75303_H
#define __CROS_EC_F75303_H
#define F75303_I2C_ADDR 0x9A /* 7-bit address is 0x4C */
enum f75303_index {
F75303_IDX_LOCAL = 0,
F75303_IDX_REMOTE,
};
/* F75303 register */
#define F75303_TEMP_LOCAL 0x00
#define F75303_TEMP_REMOTE 0x01
/**
* Get the last polled value of a sensor.
*
* @param idx Index to read. Idx indicates whether to read die
* temperature or external temperature.
* @param temp_ptr Destination for temperature in K.
*
* @return EC_SUCCESS if successful, non-zero if error.
*/
int f75303_get_val(int idx, int *temp_ptr);
#endif /* __CROS_EC_F75303_H */

View File

@@ -2450,6 +2450,7 @@
#undef CONFIG_TEMP_SENSOR_TMP006 /* TI TMP006 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_TMP411 /* TI TMP411 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_TMP432 /* TI TMP432 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_F75303 /* Fintek F75303 sensor, on I2C bus */
#undef CONFIG_THERMISTOR_NCP15WB /* NCP15WB thermistor */