• Home
  • Raw
  • Download

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>
31 * __adis_write_reg() - write N bytes to register (unlocked version)
32 * @adis: The adis device
34 * @value: The value to write to device (up to 4 bytes)
45 .tx_buf = adis->tx, in __adis_write_reg()
49 .delay.value = adis->data->write_delay, in __adis_write_reg()
51 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_write_reg()
54 .tx_buf = adis->tx + 2, in __adis_write_reg()
58 .delay.value = adis->data->write_delay, in __adis_write_reg()
60 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_write_reg()
63 .tx_buf = adis->tx + 4, in __adis_write_reg()
67 .delay.value = adis->data->write_delay, in __adis_write_reg()
69 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_write_reg()
72 .tx_buf = adis->tx + 6, in __adis_write_reg()
75 .delay.value = adis->data->write_delay, in __adis_write_reg()
78 .tx_buf = adis->tx + 8, in __adis_write_reg()
81 .delay.value = adis->data->write_delay, in __adis_write_reg()
88 if (adis->current_page != page) { in __adis_write_reg()
89 adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); in __adis_write_reg()
90 adis->tx[1] = page; in __adis_write_reg()
96 adis->tx[8] = ADIS_WRITE_REG(reg + 3); in __adis_write_reg()
97 adis->tx[9] = (value >> 24) & 0xff; in __adis_write_reg()
98 adis->tx[6] = ADIS_WRITE_REG(reg + 2); in __adis_write_reg()
99 adis->tx[7] = (value >> 16) & 0xff; in __adis_write_reg()
102 adis->tx[4] = ADIS_WRITE_REG(reg + 1); in __adis_write_reg()
103 adis->tx[5] = (value >> 8) & 0xff; in __adis_write_reg()
106 adis->tx[2] = ADIS_WRITE_REG(reg); in __adis_write_reg()
107 adis->tx[3] = value & 0xff; in __adis_write_reg()
110 return -EINVAL; in __adis_write_reg()
118 ret = spi_sync(adis->spi, &msg); in __adis_write_reg()
120 dev_err(&adis->spi->dev, "Failed to write register 0x%02X: %d\n", in __adis_write_reg()
123 adis->current_page = page; in __adis_write_reg()
131 * __adis_read_reg() - read N bytes from register (unlocked version)
132 * @adis: The adis device
134 * @val: The value read back from the device
145 .tx_buf = adis->tx, in __adis_read_reg()
149 .delay.value = adis->data->write_delay, in __adis_read_reg()
151 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_read_reg()
154 .tx_buf = adis->tx + 2, in __adis_read_reg()
158 .delay.value = adis->data->read_delay, in __adis_read_reg()
160 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_read_reg()
163 .tx_buf = adis->tx + 4, in __adis_read_reg()
164 .rx_buf = adis->rx, in __adis_read_reg()
168 .delay.value = adis->data->read_delay, in __adis_read_reg()
170 .cs_change_delay.value = adis->data->cs_change_delay, in __adis_read_reg()
173 .rx_buf = adis->rx + 2, in __adis_read_reg()
176 .delay.value = adis->data->read_delay, in __adis_read_reg()
183 if (adis->current_page != page) { in __adis_read_reg()
184 adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); in __adis_read_reg()
185 adis->tx[1] = page; in __adis_read_reg()
191 adis->tx[2] = ADIS_READ_REG(reg + 2); in __adis_read_reg()
192 adis->tx[3] = 0; in __adis_read_reg()
196 adis->tx[4] = ADIS_READ_REG(reg); in __adis_read_reg()
197 adis->tx[5] = 0; in __adis_read_reg()
202 return -EINVAL; in __adis_read_reg()
205 ret = spi_sync(adis->spi, &msg); in __adis_read_reg()
207 dev_err(&adis->spi->dev, "Failed to read register 0x%02X: %d\n", in __adis_read_reg()
212 adis->current_page = page; in __adis_read_reg()
216 *val = get_unaligned_be32(adis->rx); in __adis_read_reg()
219 *val = get_unaligned_be16(adis->rx + 2); in __adis_read_reg()
227 * __adis_update_bits_base() - ADIS Update bits function - Unlocked version
228 * @adis: The adis device
277 * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked)
278 * @adis: The adis device
288 if (adis->data->enable_irq) in __adis_enable_irq()
289 return adis->data->enable_irq(adis, enable); in __adis_enable_irq()
291 if (adis->data->unmasked_drdy) { in __adis_enable_irq()
293 enable_irq(adis->spi->irq); in __adis_enable_irq()
295 disable_irq(adis->spi->irq); in __adis_enable_irq()
300 ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc); in __adis_enable_irq()
311 return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc); in __adis_enable_irq()
316 * __adis_check_status() - Check the device for error conditions (unlocked)
317 * @adis: The adis device
327 ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg, &status); in __adis_check_status()
331 status &= adis->data->status_error_mask; in __adis_check_status()
338 dev_err(&adis->spi->dev, "%s.\n", in __adis_check_status()
339 adis->data->status_error_msgs[i]); in __adis_check_status()
343 return -EIO; in __adis_check_status()
348 * __adis_reset() - Reset the device (unlocked version)
349 * @adis: The adis device
356 const struct adis_timeout *timeouts = adis->data->timeouts; in __adis_reset()
358 ret = __adis_write_reg_8(adis, adis->data->glob_cmd_reg, in __adis_reset()
361 dev_err(&adis->spi->dev, "Failed to reset device: %d\n", ret); in __adis_reset()
365 msleep(timeouts->sw_reset_ms); in __adis_reset()
374 const struct adis_timeout *timeouts = adis->data->timeouts; in adis_self_test()
376 ret = __adis_write_reg_16(adis, adis->data->self_test_reg, in adis_self_test()
377 adis->data->self_test_mask); in adis_self_test()
379 dev_err(&adis->spi->dev, "Failed to initiate self test: %d\n", in adis_self_test()
384 msleep(timeouts->self_test_ms); in adis_self_test()
388 if (adis->data->self_test_no_autoclear) in adis_self_test()
389 __adis_write_reg_16(adis, adis->data->self_test_reg, 0x00); in adis_self_test()
395 * __adis_initial_startup() - Device initial setup
396 * @adis: The adis device
402 * After the self-test operation is performed, the function will also check
406 * Returns 0 if the device is operational, a negative error code otherwise.
408 * This function should be called early on in the device initialization sequence
409 * to ensure that the device is in a sane and known state and that it is usable.
413 const struct adis_timeout *timeouts = adis->data->timeouts; in __adis_initial_startup()
418 /* check if the device has rst pin low */ in __adis_initial_startup()
419 gpio = devm_gpiod_get_optional(&adis->spi->dev, "reset", GPIOD_OUT_HIGH); in __adis_initial_startup()
425 /* bring device out of reset */ in __adis_initial_startup()
427 msleep(timeouts->reset_ms); in __adis_initial_startup()
443 if (!adis->data->unmasked_drdy) in __adis_initial_startup()
446 if (!adis->data->prod_id_reg) in __adis_initial_startup()
449 ret = adis_read_reg_16(adis, adis->data->prod_id_reg, &prod_id); in __adis_initial_startup()
453 if (prod_id != adis->data->prod_id) in __adis_initial_startup()
454 dev_warn(&adis->spi->dev, in __adis_initial_startup()
455 "Device ID(%u) and product ID(%u) do not match.\n", in __adis_initial_startup()
456 adis->data->prod_id, prod_id); in __adis_initial_startup()
463 * adis_single_conversion() - Performs a single sample conversion
464 * @indio_dev: The IIO device
474 * is set the function will perform a self-check. If the device does not report
485 mutex_lock(&adis->state_lock); in adis_single_conversion()
487 ret = __adis_read_reg(adis, chan->address, &uval, in adis_single_conversion()
488 chan->scan_type.storagebits / 8); in adis_single_conversion()
498 if (chan->scan_type.sign == 's') in adis_single_conversion()
499 *val = sign_extend32(uval, chan->scan_type.realbits - 1); in adis_single_conversion()
501 *val = uval & ((1 << chan->scan_type.realbits) - 1); in adis_single_conversion()
505 mutex_unlock(&adis->state_lock); in adis_single_conversion()
511 * adis_init() - Initialize adis device structure
512 * @adis: The adis device
513 * @indio_dev: The iio device
514 * @spi: The spi device
525 if (!data || !data->timeouts) { in adis_init()
526 dev_err(&spi->dev, "No config data or timeouts not defined!\n"); in adis_init()
527 return -EINVAL; in adis_init()
530 mutex_init(&adis->state_lock); in adis_init()
531 adis->spi = spi; in adis_init()
532 adis->data = data; in adis_init()
535 if (data->has_paging) { in adis_init()
537 adis->current_page = -1; in adis_init()
540 adis->current_page = 0; in adis_init()
548 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");