Lines Matching +full:tx +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
12 #include <linux/device.h>
27 * __adis_write_reg() - write N bytes to register (unlocked version)
28 * @adis: The adis device
30 * @value: The value to write to device (up to 4 bytes)
41 .tx_buf = adis->tx, in __adis_write_reg()
45 .delay.value = adis->data->write_delay, in __adis_write_reg()
48 .tx_buf = adis->tx + 2, in __adis_write_reg()
52 .delay.value = adis->data->write_delay, in __adis_write_reg()
55 .tx_buf = adis->tx + 4, in __adis_write_reg()
59 .delay.value = adis->data->write_delay, in __adis_write_reg()
62 .tx_buf = adis->tx + 6, in __adis_write_reg()
65 .delay.value = adis->data->write_delay, in __adis_write_reg()
68 .tx_buf = adis->tx + 8, in __adis_write_reg()
71 .delay.value = adis->data->write_delay, in __adis_write_reg()
78 if (adis->current_page != page) { in __adis_write_reg()
79 adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); in __adis_write_reg()
80 adis->tx[1] = page; in __adis_write_reg()
86 adis->tx[8] = ADIS_WRITE_REG(reg + 3); in __adis_write_reg()
87 adis->tx[9] = (value >> 24) & 0xff; in __adis_write_reg()
88 adis->tx[6] = ADIS_WRITE_REG(reg + 2); in __adis_write_reg()
89 adis->tx[7] = (value >> 16) & 0xff; in __adis_write_reg()
92 adis->tx[4] = ADIS_WRITE_REG(reg + 1); in __adis_write_reg()
93 adis->tx[5] = (value >> 8) & 0xff; in __adis_write_reg()
96 adis->tx[2] = ADIS_WRITE_REG(reg); in __adis_write_reg()
97 adis->tx[3] = value & 0xff; in __adis_write_reg()
100 return -EINVAL; in __adis_write_reg()
108 ret = spi_sync(adis->spi, &msg); in __adis_write_reg()
110 dev_err(&adis->spi->dev, "Failed to write register 0x%02X: %d\n", in __adis_write_reg()
113 adis->current_page = page; in __adis_write_reg()
121 * __adis_read_reg() - read N bytes from register (unlocked version)
122 * @adis: The adis device
124 * @val: The value read back from the device
135 .tx_buf = adis->tx, in __adis_read_reg()
139 .delay.value = adis->data->write_delay, in __adis_read_reg()
142 .tx_buf = adis->tx + 2, in __adis_read_reg()
146 .delay.value = adis->data->read_delay, in __adis_read_reg()
149 .tx_buf = adis->tx + 4, in __adis_read_reg()
150 .rx_buf = adis->rx, in __adis_read_reg()
154 .delay.value = adis->data->read_delay, in __adis_read_reg()
157 .rx_buf = adis->rx + 2, in __adis_read_reg()
160 .delay.value = adis->data->read_delay, in __adis_read_reg()
167 if (adis->current_page != page) { in __adis_read_reg()
168 adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); in __adis_read_reg()
169 adis->tx[1] = page; in __adis_read_reg()
175 adis->tx[2] = ADIS_READ_REG(reg + 2); in __adis_read_reg()
176 adis->tx[3] = 0; in __adis_read_reg()
180 adis->tx[4] = ADIS_READ_REG(reg); in __adis_read_reg()
181 adis->tx[5] = 0; in __adis_read_reg()
186 return -EINVAL; in __adis_read_reg()
189 ret = spi_sync(adis->spi, &msg); in __adis_read_reg()
191 dev_err(&adis->spi->dev, "Failed to read register 0x%02X: %d\n", in __adis_read_reg()
196 adis->current_page = page; in __adis_read_reg()
200 *val = get_unaligned_be32(adis->rx); in __adis_read_reg()
203 *val = get_unaligned_be16(adis->rx + 2); in __adis_read_reg()
211 * __adis_update_bits_base() - ADIS Update bits function - Unlocked version
212 * @adis: The adis device
261 * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked)
262 * @adis: The adis device
272 if (adis->data->enable_irq) in __adis_enable_irq()
273 return adis->data->enable_irq(adis, enable); in __adis_enable_irq()
275 if (adis->data->unmasked_drdy) { in __adis_enable_irq()
277 enable_irq(adis->spi->irq); in __adis_enable_irq()
279 disable_irq(adis->spi->irq); in __adis_enable_irq()
284 ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc); in __adis_enable_irq()
295 return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc); in __adis_enable_irq()
300 * __adis_check_status() - Check the device for error conditions (unlocked)
301 * @adis: The adis device
311 ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg, &status); in __adis_check_status()
315 status &= adis->data->status_error_mask; in __adis_check_status()
322 dev_err(&adis->spi->dev, "%s.\n", in __adis_check_status()
323 adis->data->status_error_msgs[i]); in __adis_check_status()
327 return -EIO; in __adis_check_status()
332 * __adis_reset() - Reset the device (unlocked version)
333 * @adis: The adis device
340 const struct adis_timeout *timeouts = adis->data->timeouts; in __adis_reset()
342 ret = __adis_write_reg_8(adis, adis->data->glob_cmd_reg, in __adis_reset()
345 dev_err(&adis->spi->dev, "Failed to reset device: %d\n", ret); in __adis_reset()
349 msleep(timeouts->sw_reset_ms); in __adis_reset()
358 const struct adis_timeout *timeouts = adis->data->timeouts; in adis_self_test()
360 ret = __adis_write_reg_16(adis, adis->data->self_test_reg, in adis_self_test()
361 adis->data->self_test_mask); in adis_self_test()
363 dev_err(&adis->spi->dev, "Failed to initiate self test: %d\n", in adis_self_test()
368 msleep(timeouts->self_test_ms); in adis_self_test()
372 if (adis->data->self_test_no_autoclear) in adis_self_test()
373 __adis_write_reg_16(adis, adis->data->self_test_reg, 0x00); in adis_self_test()
379 * __adis_initial_startup() - Device initial setup
380 * @adis: The adis device
386 * After the self-test operation is performed, the function will also check
390 * Returns 0 if the device is operational, a negative error code otherwise.
392 * This function should be called early on in the device initialization sequence
393 * to ensure that the device is in a sane and known state and that it is usable.
397 const struct adis_timeout *timeouts = adis->data->timeouts; in __adis_initial_startup()
402 /* check if the device has rst pin low */ in __adis_initial_startup()
403 gpio = devm_gpiod_get_optional(&adis->spi->dev, "reset", GPIOD_OUT_HIGH); in __adis_initial_startup()
409 /* bring device out of reset */ in __adis_initial_startup()
411 msleep(timeouts->reset_ms); in __adis_initial_startup()
427 if (!adis->data->unmasked_drdy) in __adis_initial_startup()
430 if (!adis->data->prod_id_reg) in __adis_initial_startup()
433 ret = adis_read_reg_16(adis, adis->data->prod_id_reg, &prod_id); in __adis_initial_startup()
437 if (prod_id != adis->data->prod_id) in __adis_initial_startup()
438 dev_warn(&adis->spi->dev, in __adis_initial_startup()
439 "Device ID(%u) and product ID(%u) do not match.\n", in __adis_initial_startup()
440 adis->data->prod_id, prod_id); in __adis_initial_startup()
447 * adis_single_conversion() - Performs a single sample conversion
448 * @indio_dev: The IIO device
458 * is set the function will perform a self-check. If the device does not report
469 guard(mutex)(&adis->state_lock); in adis_single_conversion()
471 ret = __adis_read_reg(adis, chan->address, &uval, in adis_single_conversion()
472 chan->scan_type.storagebits / 8); in adis_single_conversion()
482 if (chan->scan_type.sign == 's') in adis_single_conversion()
483 *val = sign_extend32(uval, chan->scan_type.realbits - 1); in adis_single_conversion()
485 *val = uval & ((1 << chan->scan_type.realbits) - 1); in adis_single_conversion()
492 * adis_init() - Initialize adis device structure
493 * @adis: The adis device
494 * @indio_dev: The iio device
495 * @spi: The spi device
506 if (!data || !data->timeouts) { in adis_init()
507 dev_err(&spi->dev, "No config data or timeouts not defined!\n"); in adis_init()
508 return -EINVAL; in adis_init()
511 mutex_init(&adis->state_lock); in adis_init()
513 if (!spi->cs_inactive.value) { in adis_init()
514 spi->cs_inactive.value = data->cs_change_delay; in adis_init()
515 spi->cs_inactive.unit = SPI_DELAY_UNIT_USECS; in adis_init()
518 adis->spi = spi; in adis_init()
519 adis->data = data; in adis_init()
522 if (data->has_paging) { in adis_init()
524 adis->current_page = -1; in adis_init()
527 adis->current_page = 0; in adis_init()
535 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");