18 #include <linux/module.h>
21 #include <linux/slab.h>
24 #define LP8788_ADC_CONF 0x60
25 #define LP8788_ADC_RAW 0x61
26 #define LP8788_ADC_DONE 0x63
28 #define ADC_CONV_START 1
36 static const int lp8788_scale[
LPADC_MAX] = {
86 msb = (rawdata[0] << 4) & 0x00000ff0;
87 lsb = (rawdata[1] >> 4) & 0x0000000f;
97 static int lp8788_adc_read_raw(
struct iio_dev *indio_dev,
99 int *val,
int *val2,
long mask)
112 *val = lp8788_scale[
id] / 1000000;
113 *val2 = lp8788_scale[
id] % 1000000;
126 static const struct iio_info lp8788_adc_info = {
127 .read_raw = &lp8788_adc_read_raw,
131 #define LP8788_CHAN(_id, _type) { \
134 .channel = LPADC_##_id, \
135 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
136 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
137 .datasheet_name = #_id, \
156 static struct iio_map lp8788_default_iio_maps[] = {
158 .consumer_dev_name =
"lp8788-charger",
159 .consumer_channel =
"lp8788_vbatt_5p0",
160 .adc_channel_label =
"VBATT_5P0",
163 .consumer_dev_name =
"lp8788-charger",
164 .consumer_channel =
"lp8788_adc1",
165 .adc_channel_label =
"ADC1",
170 static int lp8788_iio_map_register(
struct iio_dev *indio_dev,
178 lp8788_default_iio_maps : pdata->
adc_pdata;
182 dev_err(adc->
lp->dev,
"iio map err: %d\n", ret);
190 static inline void lp8788_iio_map_unregister(
struct iio_dev *indio_dev,
207 adc = iio_priv(indio_dev);
209 platform_set_drvdata(pdev, indio_dev);
211 ret = lp8788_iio_map_register(indio_dev, lp->
pdata, adc);
217 indio_dev->
dev.parent = lp->
dev;
220 indio_dev->
info = &lp8788_adc_info;
221 indio_dev->
channels = lp8788_adc_channels;
226 dev_err(lp->
dev,
"iio dev register err: %d\n", ret);
233 lp8788_iio_map_unregister(indio_dev, adc);
241 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
245 lp8788_iio_map_unregister(indio_dev, adc);
252 .probe = lp8788_adc_probe,