Пример #1
0
static int mux_read_raw(struct iio_dev *indio_dev,
			struct iio_chan_spec const *chan,
			int *val, int *val2, long mask)
{
	struct mux *mux = iio_priv(indio_dev);
	int idx = chan - mux->chan;
	int ret;

	ret = iio_mux_select(mux, idx);
	if (ret < 0)
		return ret;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		ret = iio_read_channel_raw(mux->parent, val);
		break;

	case IIO_CHAN_INFO_SCALE:
		ret = iio_read_channel_scale(mux->parent, val, val2);
		break;

	default:
		ret = -EINVAL;
	}

	iio_mux_deselect(mux);

	return ret;
}
Пример #2
0
static int lp8788_get_battery_temperature(struct lp8788_charger *pchg,
				union power_supply_propval *val)
{
	struct iio_channel *channel = pchg->chan[LP8788_BATT_TEMP];
	int scaleint;
	int scalepart;
	int ret;

	if (!channel)
		return -EINVAL;

	ret = iio_read_channel_scale(channel, &scaleint, &scalepart);
	if (ret != IIO_VAL_INT_PLUS_MICRO)
		return -EINVAL;

	/* unit: 0.1 'C */
	val->intval = (scaleint + scalepart * 1000000) / 100;

	return 0;
}
Пример #3
0
static int lp8788_get_vbatt_adc(struct lp8788_charger *pchg,
				unsigned int *result)
{
	struct iio_channel *channel = pchg->chan[LP8788_VBATT];
	int scaleint;
	int scalepart;
	int ret;

	if (!channel)
		return -EINVAL;

	ret = iio_read_channel_scale(channel, &scaleint, &scalepart);
	if (ret != IIO_VAL_INT_PLUS_MICRO)
		return -EINVAL;

	/* unit: mV */
	*result = (scaleint + scalepart * 1000000) / 1000;

	return 0;
}