| .. | .. |
|---|
| 15 | 15 | |
|---|
| 16 | 16 | struct tpl0102_cfg { |
|---|
| 17 | 17 | int wipers; |
|---|
| 18 | | - int max_pos; |
|---|
| 18 | + int avail[3]; |
|---|
| 19 | 19 | int kohms; |
|---|
| 20 | 20 | }; |
|---|
| 21 | 21 | |
|---|
| .. | .. |
|---|
| 28 | 28 | |
|---|
| 29 | 29 | static const struct tpl0102_cfg tpl0102_cfg[] = { |
|---|
| 30 | 30 | /* on-semiconductor parts */ |
|---|
| 31 | | - [CAT5140_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, }, |
|---|
| 32 | | - [CAT5140_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, }, |
|---|
| 31 | + [CAT5140_503] = { .wipers = 1, .avail = { 0, 1, 255 }, .kohms = 50, }, |
|---|
| 32 | + [CAT5140_104] = { .wipers = 1, .avail = { 0, 1, 255 }, .kohms = 100, }, |
|---|
| 33 | 33 | /* ti parts */ |
|---|
| 34 | | - [TPL0102_104] = { .wipers = 2, .max_pos = 256, .kohms = 100 }, |
|---|
| 35 | | - [TPL0401_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, }, |
|---|
| 34 | + [TPL0102_104] = { .wipers = 2, .avail = { 0, 1, 255 }, .kohms = 100 }, |
|---|
| 35 | + [TPL0401_103] = { .wipers = 1, .avail = { 0, 1, 127 }, .kohms = 10, }, |
|---|
| 36 | 36 | }; |
|---|
| 37 | 37 | |
|---|
| 38 | 38 | struct tpl0102_data { |
|---|
| 39 | 39 | struct regmap *regmap; |
|---|
| 40 | | - unsigned long devid; |
|---|
| 40 | + const struct tpl0102_cfg *cfg; |
|---|
| 41 | 41 | }; |
|---|
| 42 | 42 | |
|---|
| 43 | 43 | static const struct regmap_config tpl0102_regmap_config = { |
|---|
| .. | .. |
|---|
| 52 | 52 | .channel = (ch), \ |
|---|
| 53 | 53 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
|---|
| 54 | 54 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
|---|
| 55 | + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW), \ |
|---|
| 55 | 56 | } |
|---|
| 56 | 57 | |
|---|
| 57 | 58 | static const struct iio_chan_spec tpl0102_channels[] = { |
|---|
| .. | .. |
|---|
| 72 | 73 | return ret ? ret : IIO_VAL_INT; |
|---|
| 73 | 74 | } |
|---|
| 74 | 75 | case IIO_CHAN_INFO_SCALE: |
|---|
| 75 | | - *val = 1000 * tpl0102_cfg[data->devid].kohms; |
|---|
| 76 | | - *val2 = tpl0102_cfg[data->devid].max_pos; |
|---|
| 76 | + *val = 1000 * data->cfg->kohms; |
|---|
| 77 | + *val2 = data->cfg->avail[2] + 1; |
|---|
| 77 | 78 | return IIO_VAL_FRACTIONAL; |
|---|
| 79 | + } |
|---|
| 80 | + |
|---|
| 81 | + return -EINVAL; |
|---|
| 82 | +} |
|---|
| 83 | + |
|---|
| 84 | +static int tpl0102_read_avail(struct iio_dev *indio_dev, |
|---|
| 85 | + struct iio_chan_spec const *chan, |
|---|
| 86 | + const int **vals, int *type, int *length, |
|---|
| 87 | + long mask) |
|---|
| 88 | +{ |
|---|
| 89 | + struct tpl0102_data *data = iio_priv(indio_dev); |
|---|
| 90 | + |
|---|
| 91 | + switch (mask) { |
|---|
| 92 | + case IIO_CHAN_INFO_RAW: |
|---|
| 93 | + *length = ARRAY_SIZE(data->cfg->avail); |
|---|
| 94 | + *vals = data->cfg->avail; |
|---|
| 95 | + *type = IIO_VAL_INT; |
|---|
| 96 | + return IIO_AVAIL_RANGE; |
|---|
| 78 | 97 | } |
|---|
| 79 | 98 | |
|---|
| 80 | 99 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 89 | 108 | if (mask != IIO_CHAN_INFO_RAW) |
|---|
| 90 | 109 | return -EINVAL; |
|---|
| 91 | 110 | |
|---|
| 92 | | - if (val >= tpl0102_cfg[data->devid].max_pos || val < 0) |
|---|
| 111 | + if (val > data->cfg->avail[2] || val < 0) |
|---|
| 93 | 112 | return -EINVAL; |
|---|
| 94 | 113 | |
|---|
| 95 | 114 | return regmap_write(data->regmap, chan->channel, val); |
|---|
| .. | .. |
|---|
| 97 | 116 | |
|---|
| 98 | 117 | static const struct iio_info tpl0102_info = { |
|---|
| 99 | 118 | .read_raw = tpl0102_read_raw, |
|---|
| 119 | + .read_avail = tpl0102_read_avail, |
|---|
| 100 | 120 | .write_raw = tpl0102_write_raw, |
|---|
| 101 | 121 | }; |
|---|
| 102 | 122 | |
|---|
| .. | .. |
|---|
| 113 | 133 | data = iio_priv(indio_dev); |
|---|
| 114 | 134 | i2c_set_clientdata(client, indio_dev); |
|---|
| 115 | 135 | |
|---|
| 116 | | - data->devid = id->driver_data; |
|---|
| 136 | + data->cfg = &tpl0102_cfg[id->driver_data]; |
|---|
| 117 | 137 | data->regmap = devm_regmap_init_i2c(client, &tpl0102_regmap_config); |
|---|
| 118 | 138 | if (IS_ERR(data->regmap)) { |
|---|
| 119 | 139 | dev_err(dev, "regmap initialization failed\n"); |
|---|
| 120 | 140 | return PTR_ERR(data->regmap); |
|---|
| 121 | 141 | } |
|---|
| 122 | 142 | |
|---|
| 123 | | - indio_dev->dev.parent = dev; |
|---|
| 124 | 143 | indio_dev->info = &tpl0102_info; |
|---|
| 125 | 144 | indio_dev->channels = tpl0102_channels; |
|---|
| 126 | | - indio_dev->num_channels = tpl0102_cfg[data->devid].wipers; |
|---|
| 145 | + indio_dev->num_channels = data->cfg->wipers; |
|---|
| 127 | 146 | indio_dev->name = client->name; |
|---|
| 128 | 147 | |
|---|
| 129 | 148 | return devm_iio_device_register(dev, indio_dev); |
|---|