Lines Matching +full:0 +full:- +full:987

1 // SPDX-License-Identifier: GPL-2.0+
3 * lmp91000.c - Support for Texas Instruments digital potentiostats
23 #define LMP91000_REG_LOCK 0x01
24 #define LMP91000_REG_TIACN 0x10
27 #define LMP91000_REG_REFCN 0x11
28 #define LMP91000_REG_REFCN_EXT_REF 0x20
29 #define LMP91000_REG_REFCN_50_ZERO 0x80
31 #define LMP91000_REG_MODECN 0x12
32 #define LMP91000_REG_MODECN_3LEAD 0x03
33 #define LMP91000_REG_MODECN_TEMP 0x07
37 static const int lmp91000_tia_gain[] = { 0, 2750, 3500, 7000, 14000, 35000,
42 #define LMP91000_TEMP_BASE -40
56 987, 979, 971, 962, 954, 945, 937, 929, 920, 912,
75 u32 buffer[4]; /* 64-bit data + 64-bit timestamp */
81 .channel = 0,
86 .scan_index = 0,
99 .scan_index = -1,
107 ret = regmap_read(data->regmap, LMP91000_REG_MODECN, &state); in lmp91000_read()
109 return -EINVAL; in lmp91000_read()
111 ret = regmap_write(data->regmap, LMP91000_REG_MODECN, channel); in lmp91000_read()
113 return -EINVAL; in lmp91000_read()
119 data->chan_select = channel != LMP91000_REG_MODECN_3LEAD; in lmp91000_read()
121 iio_trigger_poll_chained(data->trig); in lmp91000_read()
123 ret = wait_for_completion_timeout(&data->completion, HZ); in lmp91000_read()
124 reinit_completion(&data->completion); in lmp91000_read()
127 return -ETIMEDOUT; in lmp91000_read()
129 *val = data->buffer[data->chan_select]; in lmp91000_read()
131 return 0; in lmp91000_read()
137 struct iio_dev *indio_dev = pf->indio_dev; in lmp91000_buffer_handler()
141 memset(data->buffer, 0, sizeof(data->buffer)); in lmp91000_buffer_handler()
145 data->buffer[0] = val; in lmp91000_buffer_handler()
146 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, in lmp91000_buffer_handler()
150 iio_trigger_notify_done(indio_dev->trig); in lmp91000_buffer_handler()
164 int ret = iio_channel_start_all_cb(data->cb_buffer); in lmp91000_read_raw()
169 ret = lmp91000_read(data, chan->address, val); in lmp91000_read_raw()
171 iio_channel_stop_all_cb(data->cb_buffer); in lmp91000_read_raw()
179 ret = iio_convert_raw_to_processed(data->adc_chan, in lmp91000_read_raw()
184 for (i = 0; i < ARRAY_SIZE(lmp91000_temp_lut); i++) in lmp91000_read_raw()
193 return iio_read_channel_offset(data->adc_chan, val, val2); in lmp91000_read_raw()
195 return iio_read_channel_scale(data->adc_chan, val, val2); in lmp91000_read_raw()
198 return -EINVAL; in lmp91000_read_raw()
207 struct device *dev = data->dev; in lmp91000_read_config()
211 ret = device_property_read_u32(dev, "ti,tia-gain-ohm", &val); in lmp91000_read_config()
213 if (!device_property_read_bool(dev, "ti,external-tia-resistor")) { in lmp91000_read_config()
214 dev_err(dev, "no ti,tia-gain-ohm defined and external resistor not specified\n"); in lmp91000_read_config()
217 val = 0; in lmp91000_read_config()
220 ret = -EINVAL; in lmp91000_read_config()
221 for (i = 0; i < ARRAY_SIZE(lmp91000_tia_gain); i++) { in lmp91000_read_config()
224 ret = 0; in lmp91000_read_config()
230 dev_err(dev, "invalid ti,tia-gain-ohm %d\n", val); in lmp91000_read_config()
234 ret = device_property_read_u32(dev, "ti,rload-ohm", &val); in lmp91000_read_config()
237 dev_info(dev, "no ti,rload-ohm defined, default to %d\n", val); in lmp91000_read_config()
240 ret = -EINVAL; in lmp91000_read_config()
241 for (i = 0; i < ARRAY_SIZE(lmp91000_rload); i++) { in lmp91000_read_config()
244 ret = 0; in lmp91000_read_config()
250 dev_err(dev, "invalid ti,rload-ohm %d\n", val); in lmp91000_read_config()
254 regmap_write(data->regmap, LMP91000_REG_LOCK, 0); in lmp91000_read_config()
255 regmap_write(data->regmap, LMP91000_REG_TIACN, reg); in lmp91000_read_config()
256 regmap_write(data->regmap, LMP91000_REG_REFCN, in lmp91000_read_config()
258 regmap_write(data->regmap, LMP91000_REG_LOCK, 1); in lmp91000_read_config()
260 return 0; in lmp91000_read_config()
268 data->buffer[data->chan_select] = *((int *)val); in lmp91000_buffer_cb()
269 complete_all(&data->completion); in lmp91000_buffer_cb()
271 return 0; in lmp91000_buffer_cb()
281 return iio_channel_start_all_cb(data->cb_buffer); in lmp91000_buffer_postenable()
288 iio_channel_stop_all_cb(data->cb_buffer); in lmp91000_buffer_predisable()
290 return 0; in lmp91000_buffer_predisable()
301 struct device *dev = &client->dev; in lmp91000_probe()
308 return -ENOMEM; in lmp91000_probe()
310 indio_dev->info = &lmp91000_info; in lmp91000_probe()
311 indio_dev->channels = lmp91000_channels; in lmp91000_probe()
312 indio_dev->num_channels = ARRAY_SIZE(lmp91000_channels); in lmp91000_probe()
313 indio_dev->name = LMP91000_DRV_NAME; in lmp91000_probe()
314 indio_dev->modes = INDIO_DIRECT_MODE; in lmp91000_probe()
318 data->dev = dev; in lmp91000_probe()
319 data->regmap = devm_regmap_init_i2c(client, &lmp91000_regmap_config); in lmp91000_probe()
320 if (IS_ERR(data->regmap)) { in lmp91000_probe()
322 return PTR_ERR(data->regmap); in lmp91000_probe()
325 data->trig = devm_iio_trigger_alloc(data->dev, "%s-mux%d", in lmp91000_probe()
326 indio_dev->name, indio_dev->id); in lmp91000_probe()
327 if (!data->trig) { in lmp91000_probe()
329 return -ENOMEM; in lmp91000_probe()
332 data->trig->ops = &lmp91000_trigger_ops; in lmp91000_probe()
333 data->trig->dev.parent = dev; in lmp91000_probe()
334 init_completion(&data->completion); in lmp91000_probe()
340 ret = iio_trigger_set_immutable(iio_channel_cb_get_iio_dev(data->cb_buffer), in lmp91000_probe()
341 data->trig); in lmp91000_probe()
347 ret = iio_trigger_register(data->trig); in lmp91000_probe()
359 data->cb_buffer = iio_channel_get_all_cb(dev, &lmp91000_buffer_cb, in lmp91000_probe()
362 if (IS_ERR(data->cb_buffer)) { in lmp91000_probe()
363 if (PTR_ERR(data->cb_buffer) == -ENODEV) in lmp91000_probe()
364 ret = -EPROBE_DEFER; in lmp91000_probe()
366 ret = PTR_ERR(data->cb_buffer); in lmp91000_probe()
371 data->adc_chan = iio_channel_cb_get_channels(data->cb_buffer); in lmp91000_probe()
377 return 0; in lmp91000_probe()
380 iio_channel_release_all_cb(data->cb_buffer); in lmp91000_probe()
386 iio_trigger_unregister(data->trig); in lmp91000_probe()
398 iio_channel_stop_all_cb(data->cb_buffer); in lmp91000_remove()
399 iio_channel_release_all_cb(data->cb_buffer); in lmp91000_remove()
402 iio_trigger_unregister(data->trig); in lmp91000_remove()
404 return 0; in lmp91000_remove()
415 { "lmp91000", 0 },
416 { "lmp91002", 0 },