Lines Matching +full:reset +full:- +full:delay
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
9 #include <linux/delay.h>
27 * __adis_write_reg() - write N bytes to register (unlocked version)
41 .tx_buf = adis->tx, in __adis_write_reg()
45 .delay.value = adis->data->write_delay, in __adis_write_reg()
46 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_write_reg()
47 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_write_reg()
50 .tx_buf = adis->tx + 2, in __adis_write_reg()
54 .delay.value = adis->data->write_delay, in __adis_write_reg()
55 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_write_reg()
56 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_write_reg()
59 .tx_buf = adis->tx + 4, in __adis_write_reg()
63 .delay.value = adis->data->write_delay, in __adis_write_reg()
64 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_write_reg()
65 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_write_reg()
68 .tx_buf = adis->tx + 6, in __adis_write_reg()
71 .delay.value = adis->data->write_delay, in __adis_write_reg()
72 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_write_reg()
74 .tx_buf = adis->tx + 8, in __adis_write_reg()
77 .delay.value = adis->data->write_delay, in __adis_write_reg()
78 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_write_reg()
84 if (adis->current_page != page) { in __adis_write_reg()
85 adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); in __adis_write_reg()
86 adis->tx[1] = page; in __adis_write_reg()
92 adis->tx[8] = ADIS_WRITE_REG(reg + 3); in __adis_write_reg()
93 adis->tx[9] = (value >> 24) & 0xff; in __adis_write_reg()
94 adis->tx[6] = ADIS_WRITE_REG(reg + 2); in __adis_write_reg()
95 adis->tx[7] = (value >> 16) & 0xff; in __adis_write_reg()
98 adis->tx[4] = ADIS_WRITE_REG(reg + 1); in __adis_write_reg()
99 adis->tx[5] = (value >> 8) & 0xff; in __adis_write_reg()
102 adis->tx[2] = ADIS_WRITE_REG(reg); in __adis_write_reg()
103 adis->tx[3] = value & 0xff; in __adis_write_reg()
106 return -EINVAL; in __adis_write_reg()
114 ret = spi_sync(adis->spi, &msg); in __adis_write_reg()
116 dev_err(&adis->spi->dev, "Failed to write register 0x%02X: %d\n", in __adis_write_reg()
119 adis->current_page = page; in __adis_write_reg()
127 * __adis_read_reg() - read N bytes from register (unlocked version)
141 .tx_buf = adis->tx, in __adis_read_reg()
145 .delay.value = adis->data->write_delay, in __adis_read_reg()
146 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_read_reg()
147 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_read_reg()
150 .tx_buf = adis->tx + 2, in __adis_read_reg()
154 .delay.value = adis->data->read_delay, in __adis_read_reg()
155 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_read_reg()
156 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_read_reg()
159 .tx_buf = adis->tx + 4, in __adis_read_reg()
160 .rx_buf = adis->rx, in __adis_read_reg()
164 .delay.value = adis->data->read_delay, in __adis_read_reg()
165 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_read_reg()
166 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_read_reg()
169 .rx_buf = adis->rx + 2, in __adis_read_reg()
172 .delay.value = adis->data->read_delay, in __adis_read_reg()
173 .delay.unit = SPI_DELAY_UNIT_USECS, in __adis_read_reg()
179 if (adis->current_page != page) { in __adis_read_reg()
180 adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); in __adis_read_reg()
181 adis->tx[1] = page; in __adis_read_reg()
187 adis->tx[2] = ADIS_READ_REG(reg + 2); in __adis_read_reg()
188 adis->tx[3] = 0; in __adis_read_reg()
192 adis->tx[4] = ADIS_READ_REG(reg); in __adis_read_reg()
193 adis->tx[5] = 0; in __adis_read_reg()
198 return -EINVAL; in __adis_read_reg()
201 ret = spi_sync(adis->spi, &msg); in __adis_read_reg()
203 dev_err(&adis->spi->dev, "Failed to read register 0x%02X: %d\n", in __adis_read_reg()
208 adis->current_page = page; in __adis_read_reg()
212 *val = get_unaligned_be32(adis->rx); in __adis_read_reg()
215 *val = get_unaligned_be16(adis->rx + 2); in __adis_read_reg()
223 * __adis_update_bits_base() - ADIS Update bits function - Unlocked version
273 * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked)
284 if (adis->data->enable_irq) in __adis_enable_irq()
285 return adis->data->enable_irq(adis, enable); in __adis_enable_irq()
287 if (adis->data->unmasked_drdy) { in __adis_enable_irq()
289 enable_irq(adis->spi->irq); in __adis_enable_irq()
291 disable_irq(adis->spi->irq); in __adis_enable_irq()
296 ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc); in __adis_enable_irq()
307 return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc); in __adis_enable_irq()
312 * __adis_check_status() - Check the device for error conditions (unlocked)
323 ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg, &status); in __adis_check_status()
327 status &= adis->data->status_error_mask; in __adis_check_status()
334 dev_err(&adis->spi->dev, "%s.\n", in __adis_check_status()
335 adis->data->status_error_msgs[i]); in __adis_check_status()
339 return -EIO; in __adis_check_status()
344 * __adis_reset() - Reset the device (unlocked version)
352 const struct adis_timeout *timeouts = adis->data->timeouts; in __adis_reset()
354 ret = __adis_write_reg_8(adis, adis->data->glob_cmd_reg, in __adis_reset()
357 dev_err(&adis->spi->dev, "Failed to reset device: %d\n", ret); in __adis_reset()
361 msleep(timeouts->sw_reset_ms); in __adis_reset()
370 const struct adis_timeout *timeouts = adis->data->timeouts; in adis_self_test()
372 ret = __adis_write_reg_16(adis, adis->data->self_test_reg, in adis_self_test()
373 adis->data->self_test_mask); in adis_self_test()
375 dev_err(&adis->spi->dev, "Failed to initiate self test: %d\n", in adis_self_test()
380 msleep(timeouts->self_test_ms); in adis_self_test()
384 if (adis->data->self_test_no_autoclear) in adis_self_test()
385 __adis_write_reg_16(adis, adis->data->self_test_reg, 0x00); in adis_self_test()
391 * __adis_initial_startup() - Device initial setup
394 * The function performs a HW reset via a reset pin that should be specified
395 * via GPIOLIB. If no pin is configured a SW reset will be performed.
398 * After the self-test operation is performed, the function will also check
409 const struct adis_timeout *timeouts = adis->data->timeouts; in __adis_initial_startup()
415 gpio = devm_gpiod_get_optional(&adis->spi->dev, "reset", GPIOD_OUT_HIGH); in __adis_initial_startup()
421 /* bring device out of reset */ in __adis_initial_startup()
423 msleep(timeouts->reset_ms); in __adis_initial_startup()
439 if (!adis->data->unmasked_drdy) in __adis_initial_startup()
442 if (!adis->data->prod_id_reg) in __adis_initial_startup()
445 ret = adis_read_reg_16(adis, adis->data->prod_id_reg, &prod_id); in __adis_initial_startup()
449 if (prod_id != adis->data->prod_id) in __adis_initial_startup()
450 dev_warn(&adis->spi->dev, in __adis_initial_startup()
452 adis->data->prod_id, prod_id); in __adis_initial_startup()
459 * adis_single_conversion() - Performs a single sample conversion
470 * is set the function will perform a self-check. If the device does not report
481 mutex_lock(&adis->state_lock); in adis_single_conversion()
483 ret = __adis_read_reg(adis, chan->address, &uval, in adis_single_conversion()
484 chan->scan_type.storagebits / 8); in adis_single_conversion()
494 if (chan->scan_type.sign == 's') in adis_single_conversion()
495 *val = sign_extend32(uval, chan->scan_type.realbits - 1); in adis_single_conversion()
497 *val = uval & ((1 << chan->scan_type.realbits) - 1); in adis_single_conversion()
501 mutex_unlock(&adis->state_lock); in adis_single_conversion()
507 * adis_init() - Initialize adis device structure
521 if (!data || !data->timeouts) { in adis_init()
522 dev_err(&spi->dev, "No config data or timeouts not defined!\n"); in adis_init()
523 return -EINVAL; in adis_init()
526 mutex_init(&adis->state_lock); in adis_init()
527 adis->spi = spi; in adis_init()
528 adis->data = data; in adis_init()
531 if (data->has_paging) { in adis_init()
533 adis->current_page = -1; in adis_init()
536 adis->current_page = 0; in adis_init()
544 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");