Lines Matching refs:sigma_delta

39 void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, uint8_t comm)  in ad_sd_set_comm()  argument
43 sigma_delta->comm = comm & AD_SD_COMM_CHAN_MASK; in ad_sd_set_comm()
57 int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg, in ad_sd_write_reg() argument
60 uint8_t *data = sigma_delta->data; in ad_sd_write_reg()
64 .cs_change = sigma_delta->keep_cs_asserted, in ad_sd_write_reg()
69 data[0] = (reg << sigma_delta->info->addr_shift) | sigma_delta->comm; in ad_sd_write_reg()
92 if (sigma_delta->bus_locked) in ad_sd_write_reg()
93 ret = spi_sync_locked(sigma_delta->spi, &m); in ad_sd_write_reg()
95 ret = spi_sync(sigma_delta->spi, &m); in ad_sd_write_reg()
101 static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta, in ad_sd_read_reg_raw() argument
104 uint8_t *data = sigma_delta->data; in ad_sd_read_reg_raw()
113 .cs_change = sigma_delta->bus_locked, in ad_sd_read_reg_raw()
120 if (sigma_delta->info->has_registers) { in ad_sd_read_reg_raw()
121 data[0] = reg << sigma_delta->info->addr_shift; in ad_sd_read_reg_raw()
122 data[0] |= sigma_delta->info->read_mask; in ad_sd_read_reg_raw()
123 data[0] |= sigma_delta->comm; in ad_sd_read_reg_raw()
128 if (sigma_delta->bus_locked) in ad_sd_read_reg_raw()
129 ret = spi_sync_locked(sigma_delta->spi, &m); in ad_sd_read_reg_raw()
131 ret = spi_sync(sigma_delta->spi, &m); in ad_sd_read_reg_raw()
146 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, in ad_sd_read_reg() argument
151 ret = ad_sd_read_reg_raw(sigma_delta, reg, size, sigma_delta->data); in ad_sd_read_reg()
157 *val = get_unaligned_be32(sigma_delta->data); in ad_sd_read_reg()
160 *val = (sigma_delta->data[0] << 16) | in ad_sd_read_reg()
161 (sigma_delta->data[1] << 8) | in ad_sd_read_reg()
162 sigma_delta->data[2]; in ad_sd_read_reg()
165 *val = get_unaligned_be16(sigma_delta->data); in ad_sd_read_reg()
168 *val = sigma_delta->data[0]; in ad_sd_read_reg()
188 int ad_sd_reset(struct ad_sigma_delta *sigma_delta, in ad_sd_reset() argument
201 ret = spi_write(sigma_delta->spi, buf, size); in ad_sd_reset()
208 static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta, in ad_sd_calibrate() argument
214 ret = ad_sigma_delta_set_channel(sigma_delta, channel); in ad_sd_calibrate()
218 spi_bus_lock(sigma_delta->spi->master); in ad_sd_calibrate()
219 sigma_delta->bus_locked = true; in ad_sd_calibrate()
220 sigma_delta->keep_cs_asserted = true; in ad_sd_calibrate()
221 reinit_completion(&sigma_delta->completion); in ad_sd_calibrate()
223 ret = ad_sigma_delta_set_mode(sigma_delta, mode); in ad_sd_calibrate()
227 sigma_delta->irq_dis = false; in ad_sd_calibrate()
228 enable_irq(sigma_delta->spi->irq); in ad_sd_calibrate()
229 timeout = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ); in ad_sd_calibrate()
231 sigma_delta->irq_dis = true; in ad_sd_calibrate()
232 disable_irq_nosync(sigma_delta->spi->irq); in ad_sd_calibrate()
238 sigma_delta->keep_cs_asserted = false; in ad_sd_calibrate()
239 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE); in ad_sd_calibrate()
240 sigma_delta->bus_locked = false; in ad_sd_calibrate()
241 spi_bus_unlock(sigma_delta->spi->master); in ad_sd_calibrate()
254 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta, in ad_sd_calibrate_all() argument
261 ret = ad_sd_calibrate(sigma_delta, cb[i].mode, cb[i].channel); in ad_sd_calibrate_all()
281 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); in ad_sigma_delta_single_conversion() local
290 ad_sigma_delta_set_channel(sigma_delta, chan->address); in ad_sigma_delta_single_conversion()
292 spi_bus_lock(sigma_delta->spi->master); in ad_sigma_delta_single_conversion()
293 sigma_delta->bus_locked = true; in ad_sigma_delta_single_conversion()
294 sigma_delta->keep_cs_asserted = true; in ad_sigma_delta_single_conversion()
295 reinit_completion(&sigma_delta->completion); in ad_sigma_delta_single_conversion()
297 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_SINGLE); in ad_sigma_delta_single_conversion()
299 sigma_delta->irq_dis = false; in ad_sigma_delta_single_conversion()
300 enable_irq(sigma_delta->spi->irq); in ad_sigma_delta_single_conversion()
302 &sigma_delta->completion, HZ); in ad_sigma_delta_single_conversion()
309 if (sigma_delta->info->data_reg != 0) in ad_sigma_delta_single_conversion()
310 data_reg = sigma_delta->info->data_reg; in ad_sigma_delta_single_conversion()
314 ret = ad_sd_read_reg(sigma_delta, data_reg, in ad_sigma_delta_single_conversion()
319 if (!sigma_delta->irq_dis) { in ad_sigma_delta_single_conversion()
320 disable_irq_nosync(sigma_delta->spi->irq); in ad_sigma_delta_single_conversion()
321 sigma_delta->irq_dis = true; in ad_sigma_delta_single_conversion()
324 sigma_delta->keep_cs_asserted = false; in ad_sigma_delta_single_conversion()
325 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE); in ad_sigma_delta_single_conversion()
326 sigma_delta->bus_locked = false; in ad_sigma_delta_single_conversion()
327 spi_bus_unlock(sigma_delta->spi->master); in ad_sigma_delta_single_conversion()
337 ret = ad_sigma_delta_postprocess_sample(sigma_delta, raw_sample); in ad_sigma_delta_single_conversion()
347 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); in ad_sd_buffer_postenable() local
357 ret = ad_sigma_delta_set_channel(sigma_delta, in ad_sd_buffer_postenable()
362 spi_bus_lock(sigma_delta->spi->master); in ad_sd_buffer_postenable()
363 sigma_delta->bus_locked = true; in ad_sd_buffer_postenable()
364 sigma_delta->keep_cs_asserted = true; in ad_sd_buffer_postenable()
366 ret = ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_CONTINUOUS); in ad_sd_buffer_postenable()
370 sigma_delta->irq_dis = false; in ad_sd_buffer_postenable()
371 enable_irq(sigma_delta->spi->irq); in ad_sd_buffer_postenable()
376 spi_bus_unlock(sigma_delta->spi->master); in ad_sd_buffer_postenable()
383 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); in ad_sd_buffer_postdisable() local
385 reinit_completion(&sigma_delta->completion); in ad_sd_buffer_postdisable()
386 wait_for_completion_timeout(&sigma_delta->completion, HZ); in ad_sd_buffer_postdisable()
388 if (!sigma_delta->irq_dis) { in ad_sd_buffer_postdisable()
389 disable_irq_nosync(sigma_delta->spi->irq); in ad_sd_buffer_postdisable()
390 sigma_delta->irq_dis = true; in ad_sd_buffer_postdisable()
393 sigma_delta->keep_cs_asserted = false; in ad_sd_buffer_postdisable()
394 ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE); in ad_sd_buffer_postdisable()
396 sigma_delta->bus_locked = false; in ad_sd_buffer_postdisable()
397 return spi_bus_unlock(sigma_delta->spi->master); in ad_sd_buffer_postdisable()
404 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); in ad_sd_trigger_handler() local
416 if (sigma_delta->info->data_reg != 0) in ad_sd_trigger_handler()
417 data_reg = sigma_delta->info->data_reg; in ad_sd_trigger_handler()
425 ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size, in ad_sd_trigger_handler()
431 ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size, in ad_sd_trigger_handler()
439 sigma_delta->irq_dis = false; in ad_sd_trigger_handler()
440 enable_irq(sigma_delta->spi->irq); in ad_sd_trigger_handler()
454 struct ad_sigma_delta *sigma_delta = private; in ad_sd_data_rdy_trig_poll() local
456 complete(&sigma_delta->completion); in ad_sd_data_rdy_trig_poll()
458 sigma_delta->irq_dis = true; in ad_sd_data_rdy_trig_poll()
459 iio_trigger_poll(sigma_delta->trig); in ad_sd_data_rdy_trig_poll()
474 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); in ad_sd_validate_trigger() local
476 if (sigma_delta->trig != trig) in ad_sd_validate_trigger()
488 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); in ad_sd_probe_trigger() local
491 sigma_delta->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, in ad_sd_probe_trigger()
493 if (sigma_delta->trig == NULL) { in ad_sd_probe_trigger()
497 sigma_delta->trig->ops = &ad_sd_trigger_ops; in ad_sd_probe_trigger()
498 init_completion(&sigma_delta->completion); in ad_sd_probe_trigger()
500 ret = request_irq(sigma_delta->spi->irq, in ad_sd_probe_trigger()
504 sigma_delta); in ad_sd_probe_trigger()
508 if (!sigma_delta->irq_dis) { in ad_sd_probe_trigger()
509 sigma_delta->irq_dis = true; in ad_sd_probe_trigger()
510 disable_irq_nosync(sigma_delta->spi->irq); in ad_sd_probe_trigger()
512 sigma_delta->trig->dev.parent = &sigma_delta->spi->dev; in ad_sd_probe_trigger()
513 iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta); in ad_sd_probe_trigger()
515 ret = iio_trigger_register(sigma_delta->trig); in ad_sd_probe_trigger()
520 indio_dev->trig = iio_trigger_get(sigma_delta->trig); in ad_sd_probe_trigger()
525 free_irq(sigma_delta->spi->irq, sigma_delta); in ad_sd_probe_trigger()
527 iio_trigger_free(sigma_delta->trig); in ad_sd_probe_trigger()
534 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); in ad_sd_remove_trigger() local
536 iio_trigger_unregister(sigma_delta->trig); in ad_sd_remove_trigger()
537 free_irq(sigma_delta->spi->irq, sigma_delta); in ad_sd_remove_trigger()
538 iio_trigger_free(sigma_delta->trig); in ad_sd_remove_trigger()
585 int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev, in ad_sd_init() argument
588 sigma_delta->spi = spi; in ad_sd_init()
589 sigma_delta->info = info; in ad_sd_init()
590 iio_device_set_drvdata(indio_dev, sigma_delta); in ad_sd_init()