Ejemplo n.º 1
0
static void temp_sensor_poll(void)
{
	int temp_c;

	if (!has_power())
		return;

	if (get_temp(TMP432_LOCAL, &temp_c) == EC_SUCCESS)
		temp_val_local = C_TO_K(temp_c);

	if (get_temp(TMP432_REMOTE1, &temp_c) == EC_SUCCESS)
		temp_val_remote1 = C_TO_K(temp_c);

	if (get_temp(TMP432_REMOTE2, &temp_c) == EC_SUCCESS)
		temp_val_remote2 = C_TO_K(temp_c);
}
Ejemplo n.º 2
0
int gotemp_update(struct usense_device *dev, void *priv)
{
	/* From the GoIO_SDK */
	const double conversion = 0.0078125;
	struct gotemp *gotemp = priv;
	double kelvin;
	char buff[64];
	int len;

	assert(sizeof(gotemp->packet) == 8);

	do {
		len = usb_interrupt_read(gotemp->usb, 0x81, (void *)&gotemp->packet, sizeof(gotemp->packet), 1000);
		if (len < 0 || len != sizeof(gotemp->packet)) {
			if (len == -EAGAIN) {
				continue;
			}
			return -EINVAL;
		}
	} while (0);

	kelvin = C_TO_K(((double) gotemp->packet.measurement0) * conversion);
	snprintf(buff, sizeof(buff), "%g", kelvin);
	return usense_prop_set(dev, "reading", buff);
}
Ejemplo n.º 3
0
int charge_temp_sensor_get_val(int idx, int *temp_ptr)
{
	const struct batt_params *batt = &task_ctx.curr.batt;

	if (!(batt->flags & BATT_FLAG_RESPONSIVE))
		return EC_ERROR_UNKNOWN;

	*temp_ptr = C_TO_K(DECI_KELVIN_TO_CELSIUS(batt->temperature));
	return EC_SUCCESS;
}
Ejemplo n.º 4
0
int board_get_ambient_temp(int idx, int *temp_ptr)
{
	int mv = adc_read_channel(NPCX_ADC_CH1);

	if (mv < 0)
		return -1;

	*temp_ptr = thermistor_linear_interpolate(mv, &amb_thermistor_info);
	*temp_ptr = C_TO_K(*temp_ptr);
	return 0;
}
Ejemplo n.º 5
0
static int TEMPer_update(struct usense_device *dev, void *priv)
{
	int16_t temp;
	struct temper *temper = priv;
	int err;

	/* Reset device */
	temp_reset(&temper->adap);

	/* Dump temp */
	err = temp_read(&temper->adap, REG_TEMP, &temp);
	if (err < 0) {
		fprintf(stderr, "%s: Can't read temperature\n", usense_device_name(dev));
		return -EINVAL;
	} else {
		/* microKelvin */
		char buff[48];
		double kelvin = C_TO_K(temp / 256.0);
		snprintf(buff, sizeof(buff), "%g", kelvin);
		usense_prop_set(dev, "reading", buff);
	}

	return 0;
}
Ejemplo n.º 6
0
/* Copyright (c) 2014 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.
 */

/* Temperature sensor module for Chrome EC */

#include "adc.h"
#include "adc_chip.h"
#include "common.h"
#include "hooks.h"

/* Initialize temperature reading to a sane value (27 C) */
static int last_val = C_TO_K(27);

static void chip_temp_sensor_poll(void)
{
#ifdef CONFIG_CMD_ECTEMP
	last_val = adc_read_channel(ADC_CH_EC_TEMP);
#endif
}
DECLARE_HOOK(HOOK_SECOND, chip_temp_sensor_poll, HOOK_PRIO_TEMP_SENSOR);

int chip_temp_sensor_get_val(int idx, int *temp_ptr)
{
	if (last_val == ADC_READ_ERROR)
		return EC_ERROR_UNKNOWN;

	*temp_ptr = last_val;

	return EC_SUCCESS;
Ejemplo n.º 7
0
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);

/* ALS instances. Must be in same order as enum als_id. */
struct als_t als[] = {
	{"ISL", isl29035_read_lux},
};
BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT);


/* Thermal limits for each temp sensor. All temps are in degrees K. Must be in
 * same order as enum temp_sensor_id. To always ignore any temp, use 0.
 */
struct ec_thermal_config thermal_params[] = {
	/* Only the AP affects the thermal limits and fan speed. */
	{{C_TO_K(95), C_TO_K(97), C_TO_K(99)}, C_TO_K(55), C_TO_K(85)},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
	{{0, 0, 0}, 0, 0},
};
BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT);
Ejemplo n.º 8
0
/* Get temperature from requested sensor */
int bd99992gw_get_val(int idx, int *temp_ptr)
{
	uint16_t adc;
	int i, read, ret;
	enum bd99992gw_adc_channel channel;

	/* ADC unit is only functional in S0 */
	if (!chipset_in_state(CHIPSET_STATE_ON))
		return EC_ERROR_NOT_POWERED;

	/* Find requested channel */
	for (i = 0; i < ARRAY_SIZE(active_channels); ++i) {
		channel = active_channels[i];
		if (channel == idx ||
		    channel == BD99992GW_ADC_CHANNEL_NONE)
			break;
	}

	/* Make sure we found it */
	if (i == ARRAY_SIZE(active_channels) ||
	    active_channels[i] != idx) {
		CPRINTS("Bad ADC channel %d\n", idx);
		return EC_ERROR_INVAL;
	}

	/* Pause conversions */
	ret = raw_write8(0x80,
			 ADC_LOOP_PERIOD |
			 BD99992GW_ADC1CNTL1_ADEN |
			 BD99992GW_ADC1CNTL1_ADSTRT |
			 BD99992GW_ADC1CNTL1_ADPAUSE);
	if (ret)
		return ret;

	/* Read 10-bit ADC result */
	ret = raw_read8(BD99992GW_REG_ADC1DATA0L + 2 * i, &read);
	if (ret)
		return ret;
	adc = read;
	ret = raw_read8(BD99992GW_REG_ADC1DATA0H + 2 * i, &read);
	if (ret)
		return ret;
	adc |= read << 2;

	/* Convert temperature to C / K */
	*temp_ptr = C_TO_K(bd99992gw_get_temp(adc));

	/* Clear interrupts */
	ret = raw_write8(BD99992GW_REG_ADC1INT, BD99992GW_ADC1INT_RND);
	if (ret)
		return ret;
	ret = raw_write8(BD99992GW_REG_IRQLVL1, BD99992GW_IRQLVL1_ADC);
	if (ret)
		return ret;

	/* Resume conversions */
	ret = raw_write8(BD99992GW_REG_ADC1CNTL1, ADC_LOOP_PERIOD |
		   BD99992GW_ADC1CNTL1_ADEN | BD99992GW_ADC1CNTL1_ADSTRT);
	if (ret)
		return ret;

	return EC_SUCCESS;
}