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

1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/device.h>
67 * struct adxrs450_state - device instance specific data
69 * @buf_lock: mutex to protect tx and rx
70 * @tx: transmit buffer
76 __be32 tx __aligned(IIO_DMA_MINALIGN);
82 * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair
83 * @indio_dev: device associated with child of actual iio_dev
93 u32 tx; in adxrs450_spi_read_reg_16() local
97 .tx_buf = &st->tx, in adxrs450_spi_read_reg_16()
99 .len = sizeof(st->tx), in adxrs450_spi_read_reg_16()
102 .rx_buf = &st->rx, in adxrs450_spi_read_reg_16()
104 .len = sizeof(st->rx), in adxrs450_spi_read_reg_16()
108 mutex_lock(&st->buf_lock); in adxrs450_spi_read_reg_16()
109 tx = ADXRS450_READ_DATA | (reg_address << 17); in adxrs450_spi_read_reg_16()
111 if (!(hweight32(tx) & 1)) in adxrs450_spi_read_reg_16()
112 tx |= ADXRS450_P; in adxrs450_spi_read_reg_16()
114 st->tx = cpu_to_be32(tx); in adxrs450_spi_read_reg_16()
115 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); in adxrs450_spi_read_reg_16()
117 dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", in adxrs450_spi_read_reg_16()
122 *val = (be32_to_cpu(st->rx) >> 5) & 0xFFFF; in adxrs450_spi_read_reg_16()
125 mutex_unlock(&st->buf_lock); in adxrs450_spi_read_reg_16()
130 * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair
131 * @indio_dev: device associated with child of actual actual iio_dev
141 u32 tx; in adxrs450_spi_write_reg_16() local
144 mutex_lock(&st->buf_lock); in adxrs450_spi_write_reg_16()
145 tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1); in adxrs450_spi_write_reg_16()
147 if (!(hweight32(tx) & 1)) in adxrs450_spi_write_reg_16()
148 tx |= ADXRS450_P; in adxrs450_spi_write_reg_16()
150 st->tx = cpu_to_be32(tx); in adxrs450_spi_write_reg_16()
151 ret = spi_write(st->us, &st->tx, sizeof(st->tx)); in adxrs450_spi_write_reg_16()
153 dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", in adxrs450_spi_write_reg_16()
156 mutex_unlock(&st->buf_lock); in adxrs450_spi_write_reg_16()
161 * adxrs450_spi_sensor_data() - read 2 bytes sensor data
162 * @indio_dev: device associated with child of actual iio_dev
171 .tx_buf = &st->tx, in adxrs450_spi_sensor_data()
173 .len = sizeof(st->tx), in adxrs450_spi_sensor_data()
176 .rx_buf = &st->rx, in adxrs450_spi_sensor_data()
178 .len = sizeof(st->rx), in adxrs450_spi_sensor_data()
182 mutex_lock(&st->buf_lock); in adxrs450_spi_sensor_data()
183 st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA); in adxrs450_spi_sensor_data()
185 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers)); in adxrs450_spi_sensor_data()
187 dev_err(&st->us->dev, "Problem while reading sensor data\n"); in adxrs450_spi_sensor_data()
191 *val = (be32_to_cpu(st->rx) >> 10) & 0xFFFF; in adxrs450_spi_sensor_data()
194 mutex_unlock(&st->buf_lock); in adxrs450_spi_sensor_data()
199 * adxrs450_spi_initial() - use for initializing procedure.
200 * @st: device instance specific data
208 u32 tx; in adxrs450_spi_initial() local
210 .tx_buf = &st->tx, in adxrs450_spi_initial()
211 .rx_buf = &st->rx, in adxrs450_spi_initial()
213 .len = sizeof(st->tx), in adxrs450_spi_initial()
216 mutex_lock(&st->buf_lock); in adxrs450_spi_initial()
217 tx = ADXRS450_SENSOR_DATA; in adxrs450_spi_initial()
219 tx |= (ADXRS450_CHK | ADXRS450_P); in adxrs450_spi_initial()
220 st->tx = cpu_to_be32(tx); in adxrs450_spi_initial()
221 ret = spi_sync_transfer(st->us, &xfers, 1); in adxrs450_spi_initial()
223 dev_err(&st->us->dev, "Problem while reading initializing data\n"); in adxrs450_spi_initial()
227 *val = be32_to_cpu(st->rx); in adxrs450_spi_initial()
230 mutex_unlock(&st->buf_lock); in adxrs450_spi_initial()
247 dev_warn(&st->us->dev, "The initial power on response is not correct! Restart without reset?\n"); in adxrs450_initial_setup()
259 dev_err(&st->us->dev, "The second response is not correct!\n"); in adxrs450_initial_setup()
260 return -EIO; in adxrs450_initial_setup()
267 dev_err(&st->us->dev, "The third response is not correct!\n"); in adxrs450_initial_setup()
268 return -EIO; in adxrs450_initial_setup()
275 dev_err(&st->us->dev, "The device is not in normal status!\n"); in adxrs450_initial_setup()
276 return -EINVAL; in adxrs450_initial_setup()
291 if (val < -0x400 || val >= 0x400) in adxrs450_write_raw()
292 return -EINVAL; in adxrs450_write_raw()
297 ret = -EINVAL; in adxrs450_write_raw()
314 switch (chan->type) { in adxrs450_read_raw()
331 ret = -EINVAL; in adxrs450_read_raw()
336 switch (chan->type) { in adxrs450_read_raw()
346 return -EINVAL; in adxrs450_read_raw()
363 ret = -EINVAL; in adxrs450_read_raw()
418 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adxrs450_probe()
420 return -ENOMEM; in adxrs450_probe()
422 st->us = spi; in adxrs450_probe()
423 mutex_init(&st->buf_lock); in adxrs450_probe()
427 indio_dev->info = &adxrs450_info; in adxrs450_probe()
428 indio_dev->modes = INDIO_DIRECT_MODE; in adxrs450_probe()
429 indio_dev->channels = in adxrs450_probe()
430 adxrs450_channels[spi_get_device_id(spi)->driver_data]; in adxrs450_probe()
431 indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels); in adxrs450_probe()
432 indio_dev->name = spi->dev.driver->name; in adxrs450_probe()
434 ret = devm_iio_device_register(&spi->dev, indio_dev); in adxrs450_probe()
438 /* Get the device into a sane initial state */ in adxrs450_probe()