Lines Matching +full:spi +full:- +full:present +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ADXRS290 SPI Gyroscope Driver
15 #include <linux/spi/spi.h>
68 struct spi_device *spi;
75 /* Ensure correct alignment of timestamp when present */
83 * Available cut-off frequencies of the low pass filter in Hz.
98 * Available cut-off frequencies of the high pass filter in Hz.
121 mutex_lock(&st->lock);
122 temp = spi_w8r16(st->spi, cmd);
131 mutex_unlock(&st->lock);
142 mutex_lock(&st->lock);
143 temp = spi_w8r16(st->spi, cmd);
153 mutex_unlock(&st->lock);
164 mutex_lock(&st->lock);
165 temp = spi_w8r8(st->spi, cmd);
175 mutex_unlock(&st->lock);
179 static int adxrs290_spi_write_reg(struct spi_device *spi, const u8 reg,
187 return spi_write_then_read(spi, buf, ARRAY_SIZE(buf), NULL, 0);
200 return -EINVAL;
212 return adxrs290_spi_write_reg(st->spi, ADXRS290_REG_FILTER, val);
220 if (st->mode == mode)
223 mutex_lock(&st->lock);
225 ret = spi_w8r8(st->spi, ADXRS290_READ_REG(ADXRS290_REG_POWER_CTL));
239 ret = -EINVAL;
243 ret = adxrs290_spi_write_reg(st->spi, ADXRS290_REG_POWER_CTL, val);
245 dev_err(&st->spi->dev, "unable to set mode: %d\n", ret);
250 st->mode = mode;
253 mutex_unlock(&st->lock);
267 struct spi_device *spi = st->spi;
270 ret = adxrs290_spi_write_reg(spi, ADXRS290_REG_POWER_CTL,
275 st->mode = ADXRS290_MODE_MEASUREMENT;
277 return devm_add_action_or_reset(&spi->dev, adxrs290_chip_off_action,
285 long mask)
291 switch (mask) {
297 switch (chan->type) {
300 ADXRS290_READ_REG(chan->address),
315 ret = -EINVAL;
322 switch (chan->type) {
333 return -EINVAL;
336 switch (chan->type) {
338 t = st->lpf_3db_freq_idx;
343 return -EINVAL;
346 switch (chan->type) {
348 t = st->hpf_3db_freq_idx;
353 return -EINVAL;
357 return -EINVAL;
364 long mask)
373 switch (mask) {
379 ret = -EINVAL;
383 /* caching the updated state of the low-pass filter */
384 st->lpf_3db_freq_idx = lpf_idx;
385 /* retrieving the current state of the high-pass filter */
386 hpf_idx = st->hpf_3db_freq_idx;
395 ret = -EINVAL;
399 /* caching the updated state of the high-pass filter */
400 st->hpf_3db_freq_idx = hpf_idx;
401 /* retrieving the current state of the low-pass filter */
402 lpf_idx = st->lpf_3db_freq_idx;
407 ret = -EINVAL;
418 long mask)
420 switch (mask) {
436 return -EINVAL;
440 static int adxrs290_reg_access_rw(struct spi_device *spi, unsigned int reg,
445 ret = spi_w8r8(spi, ADXRS290_READ_REG(reg));
460 return adxrs290_reg_access_rw(st->spi, reg, readval);
462 return adxrs290_spi_write_reg(st->spi, reg, writeval);
475 ret = adxrs290_spi_write_reg(st->spi, ADXRS290_REG_DATA_RDY, val);
477 dev_err(&st->spi->dev, "failed to start data rdy interrupt\n");
506 struct iio_dev *indio_dev = pf->indio_dev;
511 mutex_lock(&st->lock);
514 ret = spi_write_then_read(st->spi, &tx, sizeof(tx), st->buffer.channels,
515 sizeof(st->buffer.channels));
519 iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
520 pf->timestamp);
523 mutex_unlock(&st->lock);
524 iio_trigger_notify_done(indio_dev->trig);
586 if (!st->spi->irq) {
587 dev_info(&st->spi->dev, "no irq, using polling\n");
591 st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, "%s-dev%d",
592 indio_dev->name,
594 if (!st->dready_trig)
595 return -ENOMEM;
597 st->dready_trig->ops = &adxrs290_trigger_ops;
598 iio_trigger_set_drvdata(st->dready_trig, indio_dev);
600 ret = devm_request_irq(&st->spi->dev, st->spi->irq,
602 IRQF_ONESHOT, "adxrs290_irq", st->dready_trig);
604 return dev_err_probe(&st->spi->dev, ret,
605 "request irq %d failed\n", st->spi->irq);
607 ret = devm_iio_trigger_register(&st->spi->dev, st->dready_trig);
609 dev_err(&st->spi->dev, "iio trigger register failed\n");
613 indio_dev->trig = iio_trigger_get(st->dready_trig);
618 static int adxrs290_probe(struct spi_device *spi)
625 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
627 return -ENOMEM;
630 st->spi = spi;
632 indio_dev->name = "adxrs290";
633 indio_dev->modes = INDIO_DIRECT_MODE;
634 indio_dev->channels = adxrs290_channels;
635 indio_dev->num_channels = ARRAY_SIZE(adxrs290_channels);
636 indio_dev->info = &adxrs290_info;
637 indio_dev->available_scan_masks = adxrs290_avail_scan_masks;
639 mutex_init(&st->lock);
641 val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_ADI_ID));
643 dev_err(&spi->dev, "Wrong ADI ID 0x%02x\n", val);
644 return -ENODEV;
647 val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_MEMS_ID));
649 dev_err(&spi->dev, "Wrong MEMS ID 0x%02x\n", val);
650 return -ENODEV;
653 val = spi_w8r8(spi, ADXRS290_READ_REG(ADXRS290_REG_DEV_ID));
655 dev_err(&spi->dev, "Wrong DEV ID 0x%02x\n", val);
656 return -ENODEV;
660 st->mode = ADXRS290_MODE_STANDBY;
674 st->lpf_3db_freq_idx = val;
675 st->hpf_3db_freq_idx = val2;
677 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
681 return dev_err_probe(&spi->dev, ret,
688 return devm_iio_device_register(&spi->dev, indio_dev);
707 MODULE_DESCRIPTION("Analog Devices ADXRS290 Gyroscope SPI driver");