Lines Matching refs:sca_data

251 static int sca3300_transfer(struct sca3300_data *sca_data, int *val)  in sca3300_transfer()  argument
260 .tx_buf = sca_data->txbuf, in sca3300_transfer()
261 .len = ARRAY_SIZE(sca_data->txbuf), in sca3300_transfer()
266 .rx_buf = sca_data->rxbuf, in sca3300_transfer()
267 .len = ARRAY_SIZE(sca_data->rxbuf), in sca3300_transfer()
273 crc = ~crc8(sca3300_crc_table, &sca_data->txbuf[0], 3, CRC8_INIT_VALUE); in sca3300_transfer()
274 sca_data->txbuf[3] = crc; in sca3300_transfer()
276 ret = spi_sync_transfer(sca_data->spi, xfers, ARRAY_SIZE(xfers)); in sca3300_transfer()
278 dev_err(&sca_data->spi->dev, in sca3300_transfer()
283 crc = ~crc8(sca3300_crc_table, &sca_data->rxbuf[0], 3, CRC8_INIT_VALUE); in sca3300_transfer()
284 if (sca_data->rxbuf[3] != crc) { in sca3300_transfer()
285 dev_err(&sca_data->spi->dev, "CRC checksum mismatch"); in sca3300_transfer()
290 rs = sca_data->rxbuf[0] & SCA3300_MASK_RS_STATUS; in sca3300_transfer()
294 *val = sign_extend32(get_unaligned_be16(&sca_data->rxbuf[1]), 15); in sca3300_transfer()
299 static int sca3300_error_handler(struct sca3300_data *sca_data) in sca3300_error_handler() argument
304 mutex_lock(&sca_data->lock); in sca3300_error_handler()
305 sca_data->txbuf[0] = SCA3300_REG_STATUS << 2; in sca3300_error_handler()
306 ret = sca3300_transfer(sca_data, &val); in sca3300_error_handler()
307 mutex_unlock(&sca_data->lock); in sca3300_error_handler()
313 dev_err(&sca_data->spi->dev, in sca3300_error_handler()
318 dev_err(&sca_data->spi->dev, "device status: 0x%lx\n", in sca3300_error_handler()
324 static int sca3300_read_reg(struct sca3300_data *sca_data, u8 reg, int *val) in sca3300_read_reg() argument
328 mutex_lock(&sca_data->lock); in sca3300_read_reg()
329 sca_data->txbuf[0] = reg << 2; in sca3300_read_reg()
330 ret = sca3300_transfer(sca_data, val); in sca3300_read_reg()
331 mutex_unlock(&sca_data->lock); in sca3300_read_reg()
335 return sca3300_error_handler(sca_data); in sca3300_read_reg()
338 static int sca3300_write_reg(struct sca3300_data *sca_data, u8 reg, int val) in sca3300_write_reg() argument
343 mutex_lock(&sca_data->lock); in sca3300_write_reg()
345 sca_data->txbuf[0] = BIT(7) | (reg << 2); in sca3300_write_reg()
346 put_unaligned_be16(val, &sca_data->txbuf[1]); in sca3300_write_reg()
347 ret = sca3300_transfer(sca_data, &reg_val); in sca3300_write_reg()
348 mutex_unlock(&sca_data->lock); in sca3300_write_reg()
352 return sca3300_error_handler(sca_data); in sca3300_write_reg()
355 static int sca3300_set_op_mode(struct sca3300_data *sca_data, int index) in sca3300_set_op_mode() argument
357 if ((index < 0) || (index >= sca_data->chip->num_avail_modes)) in sca3300_set_op_mode()
360 return sca3300_write_reg(sca_data, SCA3300_REG_MODE, in sca3300_set_op_mode()
361 sca_data->chip->avail_modes_table[index]); in sca3300_set_op_mode()
364 static int sca3300_get_op_mode(struct sca3300_data *sca_data, int *index) in sca3300_get_op_mode() argument
370 ret = sca3300_read_reg(sca_data, SCA3300_REG_MODE, &reg_val); in sca3300_get_op_mode()
374 for (i = 0; i < sca_data->chip->num_avail_modes; i++) { in sca3300_get_op_mode()
375 if (sca_data->chip->avail_modes_table[i] == reg_val) in sca3300_get_op_mode()
378 if (i == sca_data->chip->num_avail_modes) in sca3300_get_op_mode()
520 static int sca3300_init(struct sca3300_data *sca_data, in sca3300_init() argument
527 ret = sca3300_write_reg(sca_data, SCA3300_REG_MODE, in sca3300_init()
539 ret = sca3300_read_reg(sca_data, SCA3300_REG_WHOAMI, &value); in sca3300_init()
548 dev_err(&sca_data->spi->dev, "unknown chip id %x\n", value); in sca3300_init()
552 sca_data->chip = &sca3300_chip_tbl[i]; in sca3300_init()
554 if (sca_data->chip->angle_supported) { in sca3300_init()
555 ret = sca3300_write_reg(sca_data, SCL3300_REG_ANG_CTRL, in sca3300_init()
628 struct sca3300_data *sca_data; in sca3300_probe() local
632 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*sca_data)); in sca3300_probe()
636 sca_data = iio_priv(indio_dev); in sca3300_probe()
637 mutex_init(&sca_data->lock); in sca3300_probe()
638 sca_data->spi = spi; in sca3300_probe()
644 ret = sca3300_init(sca_data, indio_dev); in sca3300_probe()
650 indio_dev->name = sca_data->chip->name; in sca3300_probe()
652 indio_dev->channels = sca_data->chip->channels; in sca3300_probe()
653 indio_dev->num_channels = sca_data->chip->num_channels; in sca3300_probe()
654 indio_dev->available_scan_masks = sca_data->chip->scan_masks; in sca3300_probe()