Example #1
0
/* Charging power state initialization */
int charger_post_init(void)
{
	int rv, option;
#ifdef CONFIG_CHARGER_ILIM_PIN_DISABLED
	int option2;
#endif

	rv = charger_get_option(&option);
	if (rv)
		return rv;

	option &= ~OPTION0_LEARN_ENABLE;

	rv = charger_set_option(option);
	if (rv)
		return rv;

#ifndef BOARD_SAMUS
	/* Turn off PROCHOT warning */
	rv = raw_read16(REG_PROCHOT_OPTION1, &option);
	if (rv)
		return rv;

	option &= ~PROCHOT_OPTION1_SELECTOR_MASK;

	rv = raw_write16(REG_PROCHOT_OPTION1, option);
#else
	/* On Samus, use PROCHOT warning to detect charging problems */
	/* Turn on PROCHOT warning */
	rv = raw_write16(REG_PROCHOT_OPTION1, 0x8120);
	/* Set PROCHOT ICRIT warning when IADP is >120% of IDPM */
	rv |= raw_write16(REG_PROCHOT_OPTION0, 0x1b54);
#endif

	if (rv)
		return rv;

#ifdef CONFIG_CHARGER_ILIM_PIN_DISABLED
	/* Read the external ILIM pin enabled flag. */
	rv = raw_read16(REG_CHARGE_OPTION2, &option2);
	if (rv)
		return rv;

	/* Set ILIM pin disabled if it is currently enabled. */
	if (option2 & OPTION2_EN_EXTILIM) {
		option2 &= ~OPTION2_EN_EXTILIM;
		rv = raw_write16(REG_CHARGE_OPTION2, option2);
	}
	return rv;
#else
	return EC_SUCCESS;
#endif
}
Example #2
0
int charger_device_id(int *id)
{
#ifdef CONFIG_CHARGER_BQ24770
	return raw_read16(REG_DEVICE_ADDRESS, id);
#elif defined(CONFIG_CHARGER_BQ24773)
	return raw_read8(REG_DEVICE_ADDRESS, id);
#endif
}
Example #3
0
int charger_manufacturer_id(int *id)
{
#ifdef CONFIG_CHARGER_BQ24770
	return raw_read16(REG_MANUFACTURE_ID, id);
#elif defined(CONFIG_CHARGER_BQ24773)
	*id = 0x40; /* TI */
	return EC_SUCCESS;
#endif
}
Example #4
0
int charger_get_current(int *current)
{
	int rv;
	int reg;

	rv = raw_read16(REG_CHARGE_CURRENT, &reg);

	if (rv)
		return rv;

	*current = REG_TO_CURRENT(reg, R_SNS);
	return EC_SUCCESS;
}
Example #5
0
int charger_get_input_current(int *input_current)
{
	int rv;
	int reg;

#ifdef CONFIG_CHARGER_BQ24770
	rv = raw_read16(REG_INPUT_CURRENT, &reg);
#elif defined(CONFIG_CHARGER_BQ24773)
	rv = raw_read8(REG_INPUT_CURRENT, &reg);
#endif
	if (rv)
		return rv;

#ifdef CONFIG_CHARGER_BQ24770
	*input_current = REG_TO_CURRENT(reg, R_AC);
#elif defined(CONFIG_CHARGER_BQ24773)
	*input_current = REG8_TO_CURRENT(reg, R_AC);
#endif
	return EC_SUCCESS;
}
Example #6
0
static int si114x_read_results(struct motion_sensor_t *s, int nb)
{
	int i, ret, val;
	struct si114x_drv_data_t *data = SI114X_GET_DATA(s);
	struct si114x_typed_data_t *type_data = SI114X_GET_TYPED_DATA(s);
#ifdef CONFIG_ACCEL_FIFO
	struct ec_response_motion_sensor_data vector;
#endif

	/* Read ALX result */
	for (i = 0; i < nb; i++) {
		ret = raw_read16(s->port, s->addr,
				 type_data->base_data_reg + i * 2,
				 &val);
		if (ret)
			break;
		/* Add offset, calibration */
		if (val + type_data->offset <= 0) {
			val = 1;
		} else if (val != SI114X_OVERFLOW) {
			val += type_data->offset;
			/*
			 * Proxmitiy sensor data is inverse of the distance.
			 * Return back something proportional to distance,
			 * we affine with the scale parmeter.
			 */
			if (s->type == MOTIONSENSE_TYPE_PROX)
				val = SI114X_PS_INVERSION(val);
			val = val * type_data->scale +
			      val * type_data->uscale / 10000;
		}
		s->raw_xyz[i] = val;
	}

	if (ret != EC_SUCCESS)
		return ret;

	if (s->type == MOTIONSENSE_TYPE_PROX)
		data->covered = (s->raw_xyz[0] < SI114X_COVERED_THRESHOLD);
	else if (data->covered)
		/*
		 * The sensor (proximity & light) is covered. The light data
		 * will most likely be incorrect (darker than expected), so
		 * ignore the measurement.
		 */
		return EC_SUCCESS;

	/* Add in fifo if changed only */
	for (i = 0; i < nb; i++) {
		if (s->raw_xyz[i] != s->xyz[i])
			break;
	}
	if (i == nb)
		return EC_SUCCESS;

#ifdef CONFIG_ACCEL_FIFO
	vector.flags = 0;
	for (i = 0; i < nb; i++)
		vector.data[i] = s->raw_xyz[i];
	for (i = nb; i < 3; i++)
		vector.data[i] = 0;
	vector.sensor_num = s - motion_sensors;
	motion_sense_fifo_add_unit(&vector, s, nb);
#else
	/* We need to copy raw_xyz into xyz with mutex */
#endif
	return EC_SUCCESS;
}
Example #7
0
int charger_get_option(int *option)
{
	return raw_read16(REG_CHARGE_OPTION0, option);
}
Example #8
0
int charger_get_voltage(int *voltage)
{
	return raw_read16(REG_MAX_CHARGE_VOLTAGE, voltage);
}