Lines Matching +full:calibration +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0+
3 * atlas-sensor.c - Support for Atlas Scientific OEM SM sensors
5 * Copyright (C) 2015-2019 Konsulko Group
94 /* 96-bit data + 32-bit pad + 64-bit timestamp */
108 for (; spec->type != IIO_TIMESTAMP; spec++) in atlas_buffer_num_channels()
135 .scan_index = -1
179 .scan_index = -1
221 .scan_index = -1
241 static int atlas_check_ph_calibration(struct atlas_data *data) in atlas_check_ph_calibration() argument
243 struct device *dev = &data->client->dev; in atlas_check_ph_calibration()
247 ret = regmap_read(data->regmap, ATLAS_REG_PH_CALIB_STATUS, &val); in atlas_check_ph_calibration()
257 dev_warn(dev, "device missing low point calibration\n"); in atlas_check_ph_calibration()
260 dev_warn(dev, "device missing mid point calibration\n"); in atlas_check_ph_calibration()
263 dev_warn(dev, "device missing high point calibration\n"); in atlas_check_ph_calibration()
268 static int atlas_check_ec_calibration(struct atlas_data *data) in atlas_check_ec_calibration() argument
270 struct device *dev = &data->client->dev; in atlas_check_ec_calibration()
275 ret = regmap_bulk_read(data->regmap, ATLAS_REG_EC_PROBE, &rval, 2); in atlas_check_ec_calibration()
282 ret = regmap_read(data->regmap, ATLAS_REG_EC_CALIB_STATUS, &val); in atlas_check_ec_calibration()
292 dev_warn(dev, "device missing dry point calibration\n"); in atlas_check_ec_calibration()
295 dev_warn(dev, "device using single point calibration\n"); in atlas_check_ec_calibration()
298 dev_warn(dev, "device missing low point calibration\n"); in atlas_check_ec_calibration()
301 dev_warn(dev, "device missing high point calibration\n"); in atlas_check_ec_calibration()
307 static int atlas_check_orp_calibration(struct atlas_data *data) in atlas_check_orp_calibration() argument
309 struct device *dev = &data->client->dev; in atlas_check_orp_calibration()
313 ret = regmap_read(data->regmap, ATLAS_REG_ORP_CALIB_STATUS, &val); in atlas_check_orp_calibration()
323 static int atlas_check_do_calibration(struct atlas_data *data) in atlas_check_do_calibration() argument
325 struct device *dev = &data->client->dev; in atlas_check_do_calibration()
329 ret = regmap_read(data->regmap, ATLAS_REG_DO_CALIB_STATUS, &val); in atlas_check_do_calibration()
339 dev_warn(dev, "device missing atmospheric pressure calibration\n"); in atlas_check_do_calibration()
342 dev_warn(dev, "device missing dissolved oxygen calibration\n"); in atlas_check_do_calibration()
352 int (*calibration)(struct atlas_data *data); member
361 .calibration = &atlas_check_ph_calibration,
368 .calibration = &atlas_check_ec_calibration,
375 .calibration = &atlas_check_orp_calibration,
382 .calibration = &atlas_check_do_calibration,
393 static int atlas_set_powermode(struct atlas_data *data, int on) in atlas_set_powermode() argument
395 return regmap_write(data->regmap, ATLAS_REG_PWR_CONTROL, on); in atlas_set_powermode()
398 static int atlas_set_interrupt(struct atlas_data *data, bool state) in atlas_set_interrupt() argument
400 if (!data->interrupt_enabled) in atlas_set_interrupt()
403 return regmap_update_bits(data->regmap, ATLAS_REG_INT_CONTROL, in atlas_set_interrupt()
410 struct atlas_data *data = iio_priv(indio_dev); in atlas_buffer_postenable() local
413 ret = pm_runtime_resume_and_get(&data->client->dev); in atlas_buffer_postenable()
417 return atlas_set_interrupt(data, true); in atlas_buffer_postenable()
422 struct atlas_data *data = iio_priv(indio_dev); in atlas_buffer_predisable() local
425 ret = atlas_set_interrupt(data, false); in atlas_buffer_predisable()
429 pm_runtime_mark_last_busy(&data->client->dev); in atlas_buffer_predisable()
430 ret = pm_runtime_put_autosuspend(&data->client->dev); in atlas_buffer_predisable()
444 struct atlas_data *data = container_of(work, struct atlas_data, work); in atlas_work_handler() local
446 iio_trigger_poll(data->trig); in atlas_work_handler()
452 struct iio_dev *indio_dev = pf->indio_dev; in atlas_trigger_handler()
453 struct atlas_data *data = iio_priv(indio_dev); in atlas_trigger_handler() local
454 int channels = atlas_buffer_num_channels(data->chip->channels); in atlas_trigger_handler()
457 ret = regmap_bulk_read(data->regmap, data->chip->data_reg, in atlas_trigger_handler()
458 &data->buffer, sizeof(__be32) * channels); in atlas_trigger_handler()
461 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, in atlas_trigger_handler()
464 iio_trigger_notify_done(indio_dev->trig); in atlas_trigger_handler()
472 struct atlas_data *data = iio_priv(indio_dev); in atlas_interrupt_handler() local
474 irq_work_queue(&data->work); in atlas_interrupt_handler()
479 static int atlas_read_measurement(struct atlas_data *data, int reg, __be32 *val) in atlas_read_measurement() argument
481 struct device *dev = &data->client->dev; in atlas_read_measurement()
490 msleep(data->chip->delay); in atlas_read_measurement()
492 ret = regmap_bulk_read(data->regmap, reg, val, sizeof(*val)); in atlas_read_measurement()
504 struct atlas_data *data = iio_priv(indio_dev); in atlas_read_raw() local
512 switch (chan->type) { in atlas_read_raw()
514 ret = regmap_bulk_read(data->regmap, chan->address, in atlas_read_raw()
525 ret = atlas_read_measurement(data, chan->address, &reg); in atlas_read_raw()
530 ret = -EINVAL; in atlas_read_raw()
540 switch (chan->type) { in atlas_read_raw()
561 return -EINVAL; in atlas_read_raw()
566 return -EINVAL; in atlas_read_raw()
573 struct atlas_data *data = iio_priv(indio_dev); in atlas_write_raw() local
577 return -EINVAL; in atlas_write_raw()
579 if (mask != IIO_CHAN_INFO_RAW || chan->type != IIO_TEMP) in atlas_write_raw()
580 return -EINVAL; in atlas_write_raw()
582 return regmap_bulk_write(data->regmap, chan->address, in atlas_write_raw()
592 { "atlas-ph-sm", (kernel_ulong_t)&atlas_devices[ATLAS_PH_SM] },
593 { "atlas-ec-sm", (kernel_ulong_t)&atlas_devices[ATLAS_EC_SM] },
594 { "atlas-orp-sm", (kernel_ulong_t)&atlas_devices[ATLAS_ORP_SM] },
595 { "atlas-do-sm", (kernel_ulong_t)&atlas_devices[ATLAS_DO_SM] },
596 { "atlas-rtd-sm", (kernel_ulong_t)&atlas_devices[ATLAS_RTD_SM] },
602 { .compatible = "atlas,ph-sm", .data = &atlas_devices[ATLAS_PH_SM] },
603 { .compatible = "atlas,ec-sm", .data = &atlas_devices[ATLAS_EC_SM] },
604 { .compatible = "atlas,orp-sm", .data = &atlas_devices[ATLAS_ORP_SM] },
605 { .compatible = "atlas,do-sm", .data = &atlas_devices[ATLAS_DO_SM] },
606 { .compatible = "atlas,rtd-sm", .data = &atlas_devices[ATLAS_RTD_SM] },
613 struct atlas_data *data; in atlas_probe() local
619 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in atlas_probe()
621 return -ENOMEM; in atlas_probe()
625 indio_dev->info = &atlas_info; in atlas_probe()
626 indio_dev->name = ATLAS_DRV_NAME; in atlas_probe()
627 indio_dev->channels = chip->channels; in atlas_probe()
628 indio_dev->num_channels = chip->num_channels; in atlas_probe()
629 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE; in atlas_probe()
631 trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d", in atlas_probe()
632 indio_dev->name, iio_device_id(indio_dev)); in atlas_probe()
635 return -ENOMEM; in atlas_probe()
637 data = iio_priv(indio_dev); in atlas_probe()
638 data->client = client; in atlas_probe()
639 data->trig = trig; in atlas_probe()
640 data->chip = chip; in atlas_probe()
645 data->regmap = devm_regmap_init_i2c(client, &atlas_regmap_config); in atlas_probe()
646 if (IS_ERR(data->regmap)) { in atlas_probe()
647 dev_err(&client->dev, "regmap initialization failed\n"); in atlas_probe()
648 return PTR_ERR(data->regmap); in atlas_probe()
651 ret = pm_runtime_set_active(&client->dev); in atlas_probe()
655 ret = chip->calibration(data); in atlas_probe()
661 dev_err(&client->dev, "failed to register trigger\n"); in atlas_probe()
668 dev_err(&client->dev, "cannot setup iio trigger\n"); in atlas_probe()
672 init_irq_work(&data->work, atlas_work_handler); in atlas_probe()
674 if (client->irq > 0) { in atlas_probe()
676 ret = devm_request_threaded_irq(&client->dev, client->irq, in atlas_probe()
684 dev_warn(&client->dev, in atlas_probe()
685 "request irq (%d) failed\n", client->irq); in atlas_probe()
687 data->interrupt_enabled = 1; in atlas_probe()
690 ret = atlas_set_powermode(data, 1); in atlas_probe()
692 dev_err(&client->dev, "cannot power device on"); in atlas_probe()
696 pm_runtime_enable(&client->dev); in atlas_probe()
697 pm_runtime_set_autosuspend_delay(&client->dev, 2500); in atlas_probe()
698 pm_runtime_use_autosuspend(&client->dev); in atlas_probe()
702 dev_err(&client->dev, "unable to register device\n"); in atlas_probe()
709 pm_runtime_disable(&client->dev); in atlas_probe()
710 atlas_set_powermode(data, 0); in atlas_probe()
716 iio_trigger_unregister(data->trig); in atlas_probe()
724 struct atlas_data *data = iio_priv(indio_dev); in atlas_remove() local
729 iio_trigger_unregister(data->trig); in atlas_remove()
731 pm_runtime_disable(&client->dev); in atlas_remove()
732 pm_runtime_set_suspended(&client->dev); in atlas_remove()
734 ret = atlas_set_powermode(data, 0); in atlas_remove()
736 dev_err(&client->dev, "Failed to power down device (%pe)\n", in atlas_remove()
742 struct atlas_data *data = in atlas_runtime_suspend() local
745 return atlas_set_powermode(data, 0); in atlas_runtime_suspend()
750 struct atlas_data *data = in atlas_runtime_resume() local
753 return atlas_set_powermode(data, 1); in atlas_runtime_resume()