Lines Matching +full:pressure +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0-only
3 * BM1390 ROHM pressure sensor
6 * https://fscdn.rohm.com/en/products/databook/datasheet/ic/sensor/pressure/bm1390glv-z-e.pdf
39 * Data-sheet states that when the IIR is used, the AVE_NUM must be set to
139 u32 pressure; member
144 /* BM1390 has FIFO for 4 pressure samples */
158 /* Prevent accessing sensor during FIFO read sequence */
200 * We can't skip reading the pressure because the watermark IRQ is acked
201 * only when the pressure data is read from the FIFO.
214 ret = regmap_bulk_read(data->regmap, BM1390_REG_TEMP_HI, &temp_raw, in bm1390_read_temp()
224 static int bm1390_pressure_read(struct bm1390_data *data, u32 *pressure) in bm1390_pressure_read() argument
226 /* Pressure data is in 3 8-bit registers */ in bm1390_pressure_read()
230 ret = regmap_bulk_read(data->regmap, BM1390_REG_PRESSURE_BASE, in bm1390_pressure_read()
235 *pressure = (u32)(raw[2] >> 2 | raw[1] << 6 | raw[0] << 14); in bm1390_pressure_read()
249 return regmap_update_bits(data->regmap, BM1390_REG_MODE_CTRL, in bm1390_meas_set()
255 * completed. The data-sheet says maximum measurement cycle (regardless
266 mutex_lock(&data->mutex); in bm1390_read_data()
269 * data-sheet an one-shot mode can't be used with IIR filter. in bm1390_read_data()
275 switch (chan->type) { in bm1390_read_data()
285 ret = -EINVAL; in bm1390_read_data()
289 dev_warn(data->dev, "Failed to stop measurement (%d)\n", warn); in bm1390_read_data()
291 mutex_unlock(&data->mutex); in bm1390_read_data()
305 if (chan->type == IIO_TEMP) { in bm1390_read_raw()
310 } else if (chan->type == IIO_PRESSURE) { in bm1390_read_raw()
312 * pressure in hPa is register value divided by 2048. in bm1390_read_raw()
321 return -EINVAL; in bm1390_read_raw()
334 return -EINVAL; in bm1390_read_raw()
348 ret = regmap_read(data->regmap, BM1390_REG_FIFO_LVL, &smp_lvl); in __bm1390_fifo_flush()
359 * should be 0, 1, 2, 3, 4 - rest are probably bit errors in __bm1390_fifo_flush()
362 dev_err(data->dev, "bad FIFO level %d\n", smp_lvl); in __bm1390_fifo_flush()
366 sample_period = timestamp - data->old_timestamp; in __bm1390_fifo_flush()
376 * to read the all pressure values to memory and read the temperature in __bm1390_fifo_flush()
381 * When we start reading data from the FIFO the sensor goes to in __bm1390_fifo_flush()
387 if (test_bit(BM1390_CHAN_PRESSURE, idev->active_scan_mask)) { in __bm1390_fifo_flush()
388 ret = bm1390_pressure_read(data, &buffer[i].pressure); in __bm1390_fifo_flush()
395 * previous flush-time or, if this was first sample, the enable in __bm1390_fifo_flush()
397 * best approximation of the time-stamp we are handling. in __bm1390_fifo_flush()
402 data->old_timestamp += sample_period; in __bm1390_fifo_flush()
403 buffer[i].ts = data->old_timestamp; in __bm1390_fifo_flush()
406 warn = regmap_read(data->regmap, BM1390_REG_FIFO_LVL, &dummy); in __bm1390_fifo_flush()
408 dev_warn(data->dev, "Closing FIFO sequence failed\n"); in __bm1390_fifo_flush()
413 if (test_bit(BM1390_CHAN_TEMP, idev->active_scan_mask)) { in __bm1390_fifo_flush()
414 ret = regmap_bulk_read(data->regmap, BM1390_REG_TEMP_HI, &temp, in __bm1390_fifo_flush()
444 * We need to have the IRQ disabled or we risk of messing-up in bm1390_fifo_flush()
446 * IRQF_ONESHOT has us covered - but if we are ran by the in bm1390_fifo_flush()
447 * user-space read we need to disable the IRQ to be on a safe in bm1390_fifo_flush()
454 mutex_lock(&data->mutex); in bm1390_fifo_flush()
456 mutex_unlock(&data->mutex); in bm1390_fifo_flush()
466 return -EINVAL; in bm1390_set_watermark()
468 mutex_lock(&data->mutex); in bm1390_set_watermark()
469 data->watermark = val; in bm1390_set_watermark()
470 mutex_unlock(&data->mutex); in bm1390_set_watermark()
489 ret = regmap_write_bits(data->regmap, BM1390_REG_POWER, in bm1390_chip_init()
496 ret = regmap_write_bits(data->regmap, BM1390_REG_RESET, in bm1390_chip_init()
503 ret = regmap_write_bits(data->regmap, BM1390_REG_RESET, in bm1390_chip_init()
510 ret = regmap_reinit_cache(data->regmap, &bm1390_regmap); in bm1390_chip_init()
512 dev_err(data->dev, "Failed to reinit reg cache\n"); in bm1390_chip_init()
520 ret = regmap_update_bits(data->regmap, BM1390_REG_MODE_CTRL, in bm1390_chip_init()
525 return regmap_update_bits(data->regmap, BM1390_REG_FIFO_CTRL, in bm1390_chip_init()
534 data->watermark - BM1390_WMI_MIN); in bm1390_fifo_set_wmi()
536 return regmap_update_bits(data->regmap, BM1390_REG_FIFO_CTRL, in bm1390_fifo_set_wmi()
546 if (data->irq <= 0) in bm1390_fifo_enable()
547 return -EINVAL; in bm1390_fifo_enable()
549 mutex_lock(&data->mutex); in bm1390_fifo_enable()
550 if (data->trigger_enabled) { in bm1390_fifo_enable()
551 ret = -EBUSY; in bm1390_fifo_enable()
561 ret = regmap_set_bits(data->regmap, BM1390_REG_MODE_CTRL, in bm1390_fifo_enable()
567 ret = regmap_set_bits(data->regmap, BM1390_REG_FIFO_CTRL, in bm1390_fifo_enable()
572 data->state = BM1390_STATE_FIFO; in bm1390_fifo_enable()
574 data->old_timestamp = iio_get_time_ns(idev); in bm1390_fifo_enable()
578 mutex_unlock(&data->mutex); in bm1390_fifo_enable()
590 mutex_lock(&data->mutex); in bm1390_fifo_disable()
596 ret = regmap_clear_bits(data->regmap, BM1390_REG_FIFO_CTRL, in bm1390_fifo_disable()
601 data->state = BM1390_STATE_SAMPLE; in bm1390_fifo_disable()
604 ret = regmap_clear_bits(data->regmap, BM1390_REG_MODE_CTRL, in bm1390_fifo_disable()
608 mutex_unlock(&data->mutex); in bm1390_fifo_disable()
616 * If we use data-ready trigger, then the IRQ masks should be handled by in bm1390_buffer_postenable()
618 * results to the IIO FIFO when data-ready triggers. in bm1390_buffer_postenable()
642 struct iio_dev *idev = pf->indio_dev; in bm1390_trigger_handler()
647 ret = regmap_read(data->regmap, BM1390_REG_STATUS, &status); in bm1390_trigger_handler()
651 dev_dbg(data->dev, "DRDY trig status 0x%x\n", status); in bm1390_trigger_handler()
653 if (test_bit(BM1390_CHAN_PRESSURE, idev->active_scan_mask)) { in bm1390_trigger_handler()
654 ret = bm1390_pressure_read(data, &data->buf.pressure); in bm1390_trigger_handler()
656 dev_warn(data->dev, "sample read failed %d\n", ret); in bm1390_trigger_handler()
661 if (test_bit(BM1390_CHAN_TEMP, idev->active_scan_mask)) { in bm1390_trigger_handler()
662 ret = regmap_bulk_read(data->regmap, BM1390_REG_TEMP_HI, in bm1390_trigger_handler()
663 &data->buf.temp, sizeof(data->buf.temp)); in bm1390_trigger_handler()
665 dev_warn(data->dev, "temp read failed %d\n", ret); in bm1390_trigger_handler()
670 iio_push_to_buffers_with_timestamp(idev, &data->buf, data->timestamp); in bm1390_trigger_handler()
671 iio_trigger_notify_done(idev->trig); in bm1390_trigger_handler()
682 data->timestamp = iio_get_time_ns(idev); in bm1390_irq_handler()
684 if (data->state == BM1390_STATE_FIFO || data->trigger_enabled) in bm1390_irq_handler()
696 mutex_lock(&data->mutex); in bm1390_irq_thread_handler()
698 if (data->trigger_enabled) { in bm1390_irq_thread_handler()
699 iio_trigger_poll_nested(data->trig); in bm1390_irq_thread_handler()
701 } else if (data->state == BM1390_STATE_FIFO) { in bm1390_irq_thread_handler()
705 data->timestamp); in bm1390_irq_thread_handler()
710 mutex_unlock(&data->mutex); in bm1390_irq_thread_handler()
718 return regmap_set_bits(data->regmap, BM1390_REG_MODE_CTRL, in bm1390_set_drdy_irq()
720 return regmap_clear_bits(data->regmap, BM1390_REG_MODE_CTRL, in bm1390_set_drdy_irq()
730 mutex_lock(&data->mutex); in bm1390_trigger_set_state()
732 if (data->trigger_enabled == state) in bm1390_trigger_set_state()
735 if (data->state == BM1390_STATE_FIFO) { in bm1390_trigger_set_state()
736 dev_warn(data->dev, "Can't set trigger when FIFO enabled\n"); in bm1390_trigger_set_state()
737 ret = -EBUSY; in bm1390_trigger_set_state()
741 data->trigger_enabled = state; in bm1390_trigger_set_state()
756 * data-ready which may have been generated just before we in bm1390_trigger_set_state()
759 ret = regmap_read(data->regmap, BM1390_REG_STATUS, &dummy); in bm1390_trigger_set_state()
761 dev_warn(data->dev, "status read failed\n"); in bm1390_trigger_set_state()
767 mutex_unlock(&data->mutex); in bm1390_trigger_set_state()
780 ret = devm_iio_triggered_buffer_setup(data->dev, idev, in bm1390_setup_buffer()
786 return dev_err_probe(data->dev, ret, in bm1390_setup_buffer()
789 idev->available_scan_masks = bm1390_scan_masks; in bm1390_setup_buffer()
801 itrig = devm_iio_trigger_alloc(data->dev, "%sdata-rdy-dev%d", idev->name, in bm1390_setup_trigger()
804 return -ENOMEM; in bm1390_setup_trigger()
806 data->trig = itrig; in bm1390_setup_trigger()
808 itrig->ops = &bm1390_trigger_ops; in bm1390_setup_trigger()
811 name = devm_kasprintf(data->dev, GFP_KERNEL, "%s-bm1390", in bm1390_setup_trigger()
812 dev_name(data->dev)); in bm1390_setup_trigger()
814 return -ENOMEM; in bm1390_setup_trigger()
816 ret = devm_request_threaded_irq(data->dev, irq, bm1390_irq_handler, in bm1390_setup_trigger()
820 return dev_err_probe(data->dev, ret, "Could not request IRQ\n"); in bm1390_setup_trigger()
823 ret = devm_iio_trigger_register(data->dev, itrig); in bm1390_setup_trigger()
825 return dev_err_probe(data->dev, ret, in bm1390_setup_trigger()
840 dev = &i2c->dev; in bm1390_probe()
853 return dev_err_probe(dev, ret, "Failed to access sensor\n"); in bm1390_probe()
860 return -ENOMEM; in bm1390_probe()
863 data->regmap = regmap; in bm1390_probe()
864 data->dev = dev; in bm1390_probe()
865 data->irq = i2c->irq; in bm1390_probe()
870 data->watermark = BM1390_WMI_MAX; in bm1390_probe()
871 mutex_init(&data->mutex); in bm1390_probe()
873 idev->channels = bm1390_channels; in bm1390_probe()
874 idev->num_channels = ARRAY_SIZE(bm1390_channels); in bm1390_probe()
875 idev->name = "bm1390"; in bm1390_probe()
876 idev->modes = INDIO_DIRECT_MODE; in bm1390_probe()
880 return dev_err_probe(dev, ret, "sensor init failed\n"); in bm1390_probe()
886 /* No trigger if we don't have IRQ for data-ready and WMI */ in bm1390_probe()
887 if (i2c->irq > 0) { in bm1390_probe()
888 idev->info = &bm1390_info; in bm1390_probe()
889 idev->modes |= INDIO_BUFFER_SOFTWARE; in bm1390_probe()
890 ret = bm1390_setup_trigger(data, idev, i2c->irq); in bm1390_probe()
894 idev->info = &bm1390_noirq_info; in bm1390_probe()
906 { .compatible = "rohm,bm1390glv-z" },
912 { "bm1390glv-z", },
933 MODULE_DESCRIPTION("Driver for ROHM BM1390 pressure sensor");