ret = axp20x_read_variable_width(info->regmap, chan->address, size); if (ret < 0) return ret;
*val = ret; return IIO_VAL_INT;
}
staticint axp20x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev); int ret, size;
/* * N.B.: Unlike the Chinese datasheets tell, the charging current is * stored on 12 bits, not 13 bits. Only discharging current is on 13 * bits.
*/ if (chan->type == IIO_CURRENT && chan->channel == AXP20X_BATT_DISCHRG_I)
size = 13; else
size = 12;
ret = axp20x_read_variable_width(info->regmap, chan->address, size); if (ret < 0) return ret;
*val = ret; return IIO_VAL_INT;
}
staticint axp22x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev); int ret;
ret = axp20x_read_variable_width(info->regmap, chan->address, 12); if (ret < 0) return ret;
*val = ret; return IIO_VAL_INT;
}
staticint axp717_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev);
u8 bulk_reg[2]; int ret;
/* * A generic "ADC data" channel is used for TS, tdie, vmid, * and vbackup. This channel must both first be enabled and * also selected before it can be read.
*/ switch (chan->channel) { case AXP717_TS_IN:
regmap_write(info->regmap, AXP717_ADC_DATA_SEL,
AXP717_ADC_DATA_TS); break; case AXP717_DIE_TEMP_V:
regmap_write(info->regmap, AXP717_ADC_DATA_SEL,
AXP717_ADC_DATA_TEMP); break; case AXP717_VMID_V:
regmap_write(info->regmap, AXP717_ADC_DATA_SEL,
AXP717_ADC_DATA_VMID); break; case AXP717_BKUP_BATT_V:
regmap_write(info->regmap, AXP717_ADC_DATA_SEL,
AXP717_ADC_DATA_BKUP_BATT); break; default: break;
}
/* * All channels are 14 bits, with the first 2 bits on the high * register reserved and the remaining bits as the ADC value.
*/
ret = regmap_bulk_read(info->regmap, chan->address, bulk_reg, 2); if (ret < 0) return ret;
staticint axp813_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev); int ret;
ret = axp20x_read_variable_width(info->regmap, chan->address, 12); if (ret < 0) return ret;
*val = ret; return IIO_VAL_INT;
}
staticint axp192_adc_scale_voltage(int channel, int *val, int *val2)
{ switch (channel) { case AXP192_ACIN_V: case AXP192_VBUS_V:
*val = 1;
*val2 = 700000; return IIO_VAL_INT_PLUS_MICRO;
case AXP192_GPIO0_V: case AXP192_GPIO1_V: case AXP192_GPIO2_V: case AXP192_GPIO3_V:
*val = 0;
*val2 = 500000; return IIO_VAL_INT_PLUS_MICRO;
case AXP192_BATT_V:
*val = 1;
*val2 = 100000; return IIO_VAL_INT_PLUS_MICRO;
case AXP192_IPSOUT_V:
*val = 1;
*val2 = 400000; return IIO_VAL_INT_PLUS_MICRO;
case AXP192_TS_IN: /* 0.8 mV per LSB */
*val = 0;
*val2 = 800000; return IIO_VAL_INT_PLUS_MICRO;
default: return -EINVAL;
}
}
staticint axp20x_adc_scale_voltage(int channel, int *val, int *val2)
{ switch (channel) { case AXP20X_ACIN_V: case AXP20X_VBUS_V:
*val = 1;
*val2 = 700000; return IIO_VAL_INT_PLUS_MICRO;
case AXP20X_GPIO0_V: case AXP20X_GPIO1_V:
*val = 0;
*val2 = 500000; return IIO_VAL_INT_PLUS_MICRO;
case AXP20X_BATT_V:
*val = 1;
*val2 = 100000; return IIO_VAL_INT_PLUS_MICRO;
case AXP20X_IPSOUT_V:
*val = 1;
*val2 = 400000; return IIO_VAL_INT_PLUS_MICRO;
case AXP20X_TS_IN: /* 0.8 mV per LSB */
*val = 0;
*val2 = 800000; return IIO_VAL_INT_PLUS_MICRO;
default: return -EINVAL;
}
}
staticint axp22x_adc_scale_voltage(int channel, int *val, int *val2)
{ switch (channel) { case AXP22X_BATT_V: /* 1.1 mV per LSB */
*val = 1;
*val2 = 100000; return IIO_VAL_INT_PLUS_MICRO;
case AXP22X_TS_IN: /* 0.8 mV per LSB */
*val = 0;
*val2 = 800000; return IIO_VAL_INT_PLUS_MICRO;
default: return -EINVAL;
}
} staticint axp813_adc_scale_voltage(int channel, int *val, int *val2)
{ switch (channel) { case AXP813_GPIO0_V:
*val = 0;
*val2 = 800000; return IIO_VAL_INT_PLUS_MICRO;
case AXP813_BATT_V:
*val = 1;
*val2 = 100000; return IIO_VAL_INT_PLUS_MICRO;
case AXP813_TS_IN: /* 0.8 mV per LSB */
*val = 0;
*val2 = 800000; return IIO_VAL_INT_PLUS_MICRO;
default: return -EINVAL;
}
}
staticint axp20x_adc_scale_current(int channel, int *val, int *val2)
{ switch (channel) { case AXP20X_ACIN_I:
*val = 0;
*val2 = 625000; return IIO_VAL_INT_PLUS_MICRO;
case AXP20X_VBUS_I:
*val = 0;
*val2 = 375000; return IIO_VAL_INT_PLUS_MICRO;
case AXP20X_BATT_DISCHRG_I: case AXP20X_BATT_CHRG_I:
*val = 0;
*val2 = 500000; return IIO_VAL_INT_PLUS_MICRO;
default: return -EINVAL;
}
}
staticint axp192_adc_scale(struct iio_chan_spec const *chan, int *val, int *val2)
{ switch (chan->type) { case IIO_VOLTAGE: return axp192_adc_scale_voltage(chan->channel, val, val2);
case IIO_CURRENT: /* * AXP192 current channels are identical to the AXP20x, * therefore we can re-use the scaling function.
*/ return axp20x_adc_scale_current(chan->channel, val, val2);
case IIO_TEMP:
*val = 100; return IIO_VAL_INT;
default: return -EINVAL;
}
}
staticint axp20x_adc_scale(struct iio_chan_spec const *chan, int *val, int *val2)
{ switch (chan->type) { case IIO_VOLTAGE: return axp20x_adc_scale_voltage(chan->channel, val, val2);
case IIO_CURRENT: return axp20x_adc_scale_current(chan->channel, val, val2);
case IIO_TEMP:
*val = 100; return IIO_VAL_INT;
default: return -EINVAL;
}
}
staticint axp22x_adc_scale(struct iio_chan_spec const *chan, int *val, int *val2)
{ switch (chan->type) { case IIO_VOLTAGE: return axp22x_adc_scale_voltage(chan->channel, val, val2);
case IIO_CURRENT:
*val = 1; return IIO_VAL_INT;
case IIO_TEMP:
*val = 100; return IIO_VAL_INT;
default: return -EINVAL;
}
}
staticint axp717_adc_scale(struct iio_chan_spec const *chan, int *val, int *val2)
{ switch (chan->type) { case IIO_VOLTAGE:
*val = 1; return IIO_VAL_INT;
case IIO_CURRENT:
*val = 1; return IIO_VAL_INT;
case IIO_TEMP:
*val = 100; return IIO_VAL_INT;
default: return -EINVAL;
}
}
staticint axp813_adc_scale(struct iio_chan_spec const *chan, int *val, int *val2)
{ switch (chan->type) { case IIO_VOLTAGE: return axp813_adc_scale_voltage(chan->channel, val, val2);
case IIO_CURRENT:
*val = 1; return IIO_VAL_INT;
case IIO_TEMP:
*val = 100; return IIO_VAL_INT;
default: return -EINVAL;
}
}
staticint axp192_adc_offset_voltage(struct iio_dev *indio_dev, int channel, int *val)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev); unsignedint regval; int ret;
ret = regmap_read(info->regmap, AXP192_GPIO30_IN_RANGE, ®val); if (ret < 0) return ret;
switch (channel) { case AXP192_GPIO0_V:
regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO0, regval); break;
case AXP192_GPIO1_V:
regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO1, regval); break;
case AXP192_GPIO2_V:
regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO2, regval); break;
case AXP192_GPIO3_V:
regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO3, regval); break;
default: return -EINVAL;
}
*val = regval ? 700000 : 0; return IIO_VAL_INT;
}
staticint axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel, int *val)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev); unsignedint regval; int ret;
ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, ®val); if (ret < 0) return ret;
switch (channel) { case AXP20X_GPIO0_V:
regval = FIELD_GET(AXP20X_GPIO10_IN_RANGE_GPIO0, regval); break;
case AXP20X_GPIO1_V:
regval = FIELD_GET(AXP20X_GPIO10_IN_RANGE_GPIO1, regval); break;
default: return -EINVAL;
}
*val = regval ? 700000 : 0; return IIO_VAL_INT;
}
staticint axp192_adc_offset(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val)
{ switch (chan->type) { case IIO_VOLTAGE: return axp192_adc_offset_voltage(indio_dev, chan->channel, val);
case IIO_TEMP:
*val = -1447; return IIO_VAL_INT;
default: return -EINVAL;
}
}
staticint axp20x_adc_offset(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val)
{ switch (chan->type) { case IIO_VOLTAGE: return axp20x_adc_offset_voltage(indio_dev, chan->channel, val);
case IIO_TEMP:
*val = -1447; return IIO_VAL_INT;
default: return -EINVAL;
}
}
staticint axp192_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ switch (mask) { case IIO_CHAN_INFO_OFFSET: return axp192_adc_offset(indio_dev, chan, val);
case IIO_CHAN_INFO_SCALE: return axp192_adc_scale(chan, val, val2);
case IIO_CHAN_INFO_RAW: return axp192_adc_raw(indio_dev, chan, val);
default: return -EINVAL;
}
}
staticint axp20x_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ switch (mask) { case IIO_CHAN_INFO_OFFSET: return axp20x_adc_offset(indio_dev, chan, val);
case IIO_CHAN_INFO_SCALE: return axp20x_adc_scale(chan, val, val2);
case IIO_CHAN_INFO_RAW: return axp20x_adc_raw(indio_dev, chan, val);
default: return -EINVAL;
}
}
staticint axp22x_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ switch (mask) { case IIO_CHAN_INFO_OFFSET: /* For PMIC temp only */
*val = -2677; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: return axp22x_adc_scale(chan, val, val2);
case IIO_CHAN_INFO_RAW: return axp22x_adc_raw(indio_dev, chan, val);
default: return -EINVAL;
}
}
staticint axp717_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ switch (mask) { case IIO_CHAN_INFO_SCALE: return axp717_adc_scale(chan, val, val2);
case IIO_CHAN_INFO_RAW: return axp717_adc_raw(indio_dev, chan, val);
default: return -EINVAL;
}
}
staticint axp813_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ switch (mask) { case IIO_CHAN_INFO_OFFSET:
*val = -2667; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: return axp813_adc_scale(chan, val, val2);
case IIO_CHAN_INFO_RAW: return axp813_adc_raw(indio_dev, chan, val);
default: return -EINVAL;
}
}
staticint axp192_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev); unsignedint regmask, regval;
/* * The AXP192 PMIC allows the user to choose between 0V and 0.7V offsets * for (independently) GPIO0-3 when in ADC mode.
*/ if (mask != IIO_CHAN_INFO_OFFSET) return -EINVAL;
staticint axp20x_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask)
{ struct axp20x_adc_iio *info = iio_priv(indio_dev); unsignedint regmask, regval;
/* * The AXP20X PMIC allows the user to choose between 0V and 0.7V offsets * for (independently) GPIO0 and GPIO1 when in ADC mode.
*/ if (mask != IIO_CHAN_INFO_OFFSET) return -EINVAL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.