Lines Matching +full:data +full:- +full:shift
1 // SPDX-License-Identifier: GPL-2.0+
7 …* Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/AD5110_5112_5114.…
27 /* AD5110_EEPROM_RD data */
36 int shift; member
52 [AD5112_05] = { .max_pos = 64, .kohms = 5, .shift = 1 },
53 [AD5112_10] = { .max_pos = 64, .kohms = 10, .shift = 1 },
54 [AD5112_80] = { .max_pos = 64, .kohms = 80, .shift = 1 },
55 [AD5114_10] = { .max_pos = 32, .kohms = 10, .shift = 2 },
56 [AD5114_80] = { .max_pos = 32, .kohms = 80, .shift = 2 },
81 static int ad5110_read(struct ad5110_data *data, u8 cmd, int *val) in ad5110_read() argument
85 mutex_lock(&data->lock); in ad5110_read()
86 data->buf[0] = cmd; in ad5110_read()
87 data->buf[1] = *val; in ad5110_read()
89 ret = i2c_master_send_dmasafe(data->client, data->buf, sizeof(data->buf)); in ad5110_read()
92 } else if (ret != sizeof(data->buf)) { in ad5110_read()
93 ret = -EIO; in ad5110_read()
97 ret = i2c_master_recv_dmasafe(data->client, data->buf, 1); in ad5110_read()
101 ret = -EIO; in ad5110_read()
105 *val = data->buf[0]; in ad5110_read()
109 mutex_unlock(&data->lock); in ad5110_read()
113 static int ad5110_write(struct ad5110_data *data, u8 cmd, u8 val) in ad5110_write() argument
117 mutex_lock(&data->lock); in ad5110_write()
118 data->buf[0] = cmd; in ad5110_write()
119 data->buf[1] = val; in ad5110_write()
121 ret = i2c_master_send_dmasafe(data->client, data->buf, sizeof(data->buf)); in ad5110_write()
124 } else if (ret != sizeof(data->buf)) { in ad5110_write()
125 ret = -EIO; in ad5110_write()
132 mutex_unlock(&data->lock); in ad5110_write()
136 static int ad5110_resistor_tol(struct ad5110_data *data, u8 cmd, int val) in ad5110_resistor_tol() argument
140 ret = ad5110_read(data, cmd, &val); in ad5110_resistor_tol()
144 data->tol = data->cfg->kohms * (val & GENMASK(6, 0)) * 10 / 8; in ad5110_resistor_tol()
146 data->tol *= -1; in ad5110_resistor_tol()
156 struct ad5110_data *data = iio_priv(indio_dev); in store_eeprom_show() local
160 ret = ad5110_read(data, AD5110_EEPROM_RD, &val); in store_eeprom_show()
164 val = val >> data->cfg->shift; in store_eeprom_show()
173 struct ad5110_data *data = iio_priv(indio_dev); in store_eeprom_store() local
176 ret = ad5110_write(data, AD5110_EEPROM_WR, 0); in store_eeprom_store()
178 dev_err(&data->client->dev, "RDAC to EEPROM write failed\n"); in store_eeprom_store()
182 /* The storing of EEPROM data takes approximately 18 ms. */ in store_eeprom_store()
203 struct ad5110_data *data = iio_priv(indio_dev); in ad5110_read_raw() local
208 ret = ad5110_read(data, AD5110_RDAC_RD, val); in ad5110_read_raw()
212 *val = *val >> data->cfg->shift; in ad5110_read_raw()
215 *val = AD5110_WIPER_RESISTANCE * data->cfg->max_pos; in ad5110_read_raw()
216 *val2 = 1000 * data->cfg->kohms + data->tol; in ad5110_read_raw()
219 *val = 1000 * data->cfg->kohms + data->tol; in ad5110_read_raw()
220 *val2 = data->cfg->max_pos; in ad5110_read_raw()
223 *val = data->enable; in ad5110_read_raw()
226 return -EINVAL; in ad5110_read_raw()
234 struct ad5110_data *data = iio_priv(indio_dev); in ad5110_write_raw() local
239 if (val > data->cfg->max_pos || val < 0) in ad5110_write_raw()
240 return -EINVAL; in ad5110_write_raw()
242 return ad5110_write(data, AD5110_RDAC_WR, val << data->cfg->shift); in ad5110_write_raw()
245 return -EINVAL; in ad5110_write_raw()
246 if (data->enable == val) in ad5110_write_raw()
248 ret = ad5110_write(data, AD5110_SHUTDOWN, val ? 0 : 1); in ad5110_write_raw()
251 data->enable = val; in ad5110_write_raw()
254 return -EINVAL; in ad5110_write_raw()
266 .data = &ad5110_cfg[cfg], \
270 AD5110_COMPATIBLE("adi,ad5110-10", AD5110_10),
271 AD5110_COMPATIBLE("adi,ad5110-80", AD5110_80),
272 AD5110_COMPATIBLE("adi,ad5112-05", AD5112_05),
273 AD5110_COMPATIBLE("adi,ad5112-10", AD5112_10),
274 AD5110_COMPATIBLE("adi,ad5112-80", AD5112_80),
275 AD5110_COMPATIBLE("adi,ad5114-10", AD5114_10),
276 AD5110_COMPATIBLE("adi,ad5114-80", AD5114_80),
282 { "ad5110-10", AD5110_10 },
283 { "ad5110-80", AD5110_80 },
284 { "ad5112-05", AD5112_05 },
285 { "ad5112-10", AD5112_10 },
286 { "ad5112-80", AD5112_80 },
287 { "ad5114-10", AD5114_10 },
288 { "ad5114-80", AD5114_80 },
295 struct device *dev = &client->dev; in ad5110_probe()
297 struct ad5110_data *data; in ad5110_probe() local
300 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); in ad5110_probe()
302 return -ENOMEM; in ad5110_probe()
304 data = iio_priv(indio_dev); in ad5110_probe()
305 data->client = client; in ad5110_probe()
306 mutex_init(&data->lock); in ad5110_probe()
307 data->enable = 1; in ad5110_probe()
308 data->cfg = device_get_match_data(dev); in ad5110_probe()
311 ret = ad5110_write(data, AD5110_RESET, 0); in ad5110_probe()
317 ret = ad5110_resistor_tol(data, AD5110_EEPROM_RD, AD5110_RESISTOR_TOL); in ad5110_probe()
323 indio_dev->modes = INDIO_DIRECT_MODE; in ad5110_probe()
324 indio_dev->info = &ad5110_info; in ad5110_probe()
325 indio_dev->channels = ad5110_channels; in ad5110_probe()
326 indio_dev->num_channels = ARRAY_SIZE(ad5110_channels); in ad5110_probe()
327 indio_dev->name = client->name; in ad5110_probe()