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", ATLAS_PH_SM },
593 { "atlas-ec-sm", ATLAS_EC_SM },
594 { "atlas-orp-sm", ATLAS_ORP_SM },
595 { "atlas-do-sm", ATLAS_DO_SM },
596 { "atlas-rtd-sm", ATLAS_RTD_SM },
602 { .compatible = "atlas,ph-sm", .data = (void *)ATLAS_PH_SM, },
603 { .compatible = "atlas,ec-sm", .data = (void *)ATLAS_EC_SM, },
604 { .compatible = "atlas,orp-sm", .data = (void *)ATLAS_ORP_SM, },
605 { .compatible = "atlas,do-sm", .data = (void *)ATLAS_DO_SM, },
606 { .compatible = "atlas,rtd-sm", .data = (void *)ATLAS_RTD_SM, },
614 struct atlas_data *data; in atlas_probe() local
620 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in atlas_probe()
622 return -ENOMEM; in atlas_probe()
624 if (!dev_fwnode(&client->dev)) in atlas_probe()
625 chip = &atlas_devices[id->driver_data]; in atlas_probe()
627 chip = &atlas_devices[(unsigned long)device_get_match_data(&client->dev)]; in atlas_probe()
629 indio_dev->info = &atlas_info; in atlas_probe()
630 indio_dev->name = ATLAS_DRV_NAME; in atlas_probe()
631 indio_dev->channels = chip->channels; in atlas_probe()
632 indio_dev->num_channels = chip->num_channels; in atlas_probe()
633 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE; in atlas_probe()
635 trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d", in atlas_probe()
636 indio_dev->name, iio_device_id(indio_dev)); in atlas_probe()
639 return -ENOMEM; in atlas_probe()
641 data = iio_priv(indio_dev); in atlas_probe()
642 data->client = client; in atlas_probe()
643 data->trig = trig; in atlas_probe()
644 data->chip = chip; in atlas_probe()
649 data->regmap = devm_regmap_init_i2c(client, &atlas_regmap_config); in atlas_probe()
650 if (IS_ERR(data->regmap)) { in atlas_probe()
651 dev_err(&client->dev, "regmap initialization failed\n"); in atlas_probe()
652 return PTR_ERR(data->regmap); in atlas_probe()
655 ret = pm_runtime_set_active(&client->dev); in atlas_probe()
659 ret = chip->calibration(data); in atlas_probe()
665 dev_err(&client->dev, "failed to register trigger\n"); in atlas_probe()
672 dev_err(&client->dev, "cannot setup iio trigger\n"); in atlas_probe()
676 init_irq_work(&data->work, atlas_work_handler); in atlas_probe()
678 if (client->irq > 0) { in atlas_probe()
680 ret = devm_request_threaded_irq(&client->dev, client->irq, in atlas_probe()
688 dev_warn(&client->dev, in atlas_probe()
689 "request irq (%d) failed\n", client->irq); in atlas_probe()
691 data->interrupt_enabled = 1; in atlas_probe()
694 ret = atlas_set_powermode(data, 1); in atlas_probe()
696 dev_err(&client->dev, "cannot power device on"); in atlas_probe()
700 pm_runtime_enable(&client->dev); in atlas_probe()
701 pm_runtime_set_autosuspend_delay(&client->dev, 2500); in atlas_probe()
702 pm_runtime_use_autosuspend(&client->dev); in atlas_probe()
706 dev_err(&client->dev, "unable to register device\n"); in atlas_probe()
713 pm_runtime_disable(&client->dev); in atlas_probe()
714 atlas_set_powermode(data, 0); in atlas_probe()
720 iio_trigger_unregister(data->trig); in atlas_probe()
728 struct atlas_data *data = iio_priv(indio_dev); in atlas_remove() local
733 iio_trigger_unregister(data->trig); in atlas_remove()
735 pm_runtime_disable(&client->dev); in atlas_remove()
736 pm_runtime_set_suspended(&client->dev); in atlas_remove()
738 ret = atlas_set_powermode(data, 0); in atlas_remove()
740 dev_err(&client->dev, "Failed to power down device (%pe)\n", in atlas_remove()
746 struct atlas_data *data = in atlas_runtime_suspend() local
749 return atlas_set_powermode(data, 0); in atlas_runtime_suspend()
754 struct atlas_data *data = in atlas_runtime_resume() local
757 return atlas_set_powermode(data, 1); in atlas_runtime_resume()