Lines Matching +full:3 +full:- +full:axis
1 // SPDX-License-Identifier: GPL-2.0
24 #define SCMI_IIO_NUM_OF_AXIS 3
49 if (sensor_update->readings_count == 0) in scmi_iio_sensor_update_cb()
54 for (i = 0; i < sensor_update->readings_count; i++) in scmi_iio_sensor_update_cb()
55 sensor->iio_buf[i] = sensor_update->readings[i].value; in scmi_iio_sensor_update_cb()
57 if (!sensor->sensor_info->timestamped) { in scmi_iio_sensor_update_cb()
58 time_ns = ktime_to_ns(sensor_update->timestamp); in scmi_iio_sensor_update_cb()
62 * We are just using the values from the Axis 0 here. in scmi_iio_sensor_update_cb()
64 time = sensor_update->readings[0].timestamp; in scmi_iio_sensor_update_cb()
68 * time * power-of-10 multiplier(tstamp_scale) seconds. in scmi_iio_sensor_update_cb()
71 tstamp_scale = sensor->sensor_info->tstamp_scale + in scmi_iio_sensor_update_cb()
81 scmi_iio_dev = sensor->indio_dev; in scmi_iio_sensor_update_cb()
82 iio_push_to_buffers_with_timestamp(scmi_iio_dev, sensor->iio_buf, in scmi_iio_sensor_update_cb()
93 if (sensor->sensor_info->timestamped) in scmi_iio_buffer_preenable()
99 err = sensor->sensor_ops->config_set(sensor->ph, in scmi_iio_buffer_preenable()
100 sensor->sensor_info->id, in scmi_iio_buffer_preenable()
103 dev_err(&iio_dev->dev, "Error in enabling sensor %s err %d", in scmi_iio_buffer_preenable()
104 sensor->sensor_info->name, err); in scmi_iio_buffer_preenable()
117 err = sensor->sensor_ops->config_set(sensor->ph, in scmi_iio_buffer_postdisable()
118 sensor->sensor_info->id, in scmi_iio_buffer_postdisable()
121 dev_err(&iio_dev->dev, in scmi_iio_buffer_postdisable()
123 sensor->sensor_info->name, err); in scmi_iio_buffer_postdisable()
141 int err = sensor->sensor_ops->config_get(sensor->ph, in scmi_iio_set_odr_val()
142 sensor->sensor_info->id, in scmi_iio_set_odr_val()
145 dev_err(&iio_dev->dev, in scmi_iio_set_odr_val()
147 sensor->sensor_info->name, err); in scmi_iio_set_odr_val()
163 mult = scnprintf(buf, sizeof(buf), "%llu", sf) - 1; in scmi_iio_set_odr_val()
168 dev_err(&iio_dev->dev, in scmi_iio_set_odr_val()
170 sensor->sensor_info->name); in scmi_iio_set_odr_val()
171 return -EINVAL; in scmi_iio_set_odr_val()
177 sensor_config |= FIELD_PREP(SCMI_SENS_CFG_UPDATE_EXP_MASK, -mult); in scmi_iio_set_odr_val()
179 if (sensor->sensor_info->timestamped) { in scmi_iio_set_odr_val()
189 err = sensor->sensor_ops->config_set(sensor->ph, in scmi_iio_set_odr_val()
190 sensor->sensor_info->id, in scmi_iio_set_odr_val()
193 dev_err(&iio_dev->dev, in scmi_iio_set_odr_val()
195 sensor->sensor_info->name, sensor_config, err); in scmi_iio_set_odr_val()
209 mutex_lock(&sensor->lock); in scmi_iio_write_raw()
211 mutex_unlock(&sensor->lock); in scmi_iio_write_raw()
214 return -EINVAL; in scmi_iio_write_raw()
227 *vals = sensor->freq_avail; in scmi_iio_read_avail()
229 *length = sensor->sensor_info->intervals.count * 2; in scmi_iio_read_avail()
230 if (sensor->sensor_info->intervals.segmented) in scmi_iio_read_avail()
235 return -EINVAL; in scmi_iio_read_avail()
257 int err = sensor->sensor_ops->config_get(sensor->ph, in scmi_iio_get_odr_val()
258 sensor->sensor_info->id, in scmi_iio_get_odr_val()
261 dev_err(&iio_dev->dev, in scmi_iio_get_odr_val()
263 sensor->sensor_info->name, err); in scmi_iio_get_odr_val()
296 err = sensor->sensor_ops->config_set( in scmi_iio_read_channel_data()
297 sensor->ph, sensor->sensor_info->id, sensor_config); in scmi_iio_read_channel_data()
299 dev_err(&iio_dev->dev, in scmi_iio_read_channel_data()
301 sensor->sensor_info->name, err); in scmi_iio_read_channel_data()
305 err = sensor->sensor_ops->reading_get_timestamped( in scmi_iio_read_channel_data()
306 sensor->ph, sensor->sensor_info->id, in scmi_iio_read_channel_data()
307 sensor->sensor_info->num_axis, readings); in scmi_iio_read_channel_data()
309 dev_err(&iio_dev->dev, in scmi_iio_read_channel_data()
311 sensor->sensor_info->name, err); in scmi_iio_read_channel_data()
317 err = sensor->sensor_ops->config_set( in scmi_iio_read_channel_data()
318 sensor->ph, sensor->sensor_info->id, sensor_config); in scmi_iio_read_channel_data()
320 dev_err(&iio_dev->dev, in scmi_iio_read_channel_data()
322 sensor->sensor_info->name, err); in scmi_iio_read_channel_data()
326 *val = lower_32_bits(readings[ch->scan_index].value); in scmi_iio_read_channel_data()
327 *val2 = upper_32_bits(readings[ch->scan_index].value); in scmi_iio_read_channel_data()
342 scale = sensor->sensor_info->axis[ch->scan_index].scale; in scmi_iio_read_raw()
362 return -EINVAL; in scmi_iio_read_raw()
385 * We are just using the values from the Axis 0 here. in scmi_iio_get_raw_available()
387 if (sensor->sensor_info->axis[0].extended_attrs) { in scmi_iio_get_raw_available()
388 min_range = sensor->sensor_info->axis[0].attrs.min_range; in scmi_iio_get_raw_available()
389 max_range = sensor->sensor_info->axis[0].attrs.max_range; in scmi_iio_get_raw_available()
390 resolution = sensor->sensor_info->axis[0].resolution; in scmi_iio_get_raw_available()
391 exponent = sensor->sensor_info->axis[0].exponent; in scmi_iio_get_raw_available()
392 scale = sensor->sensor_info->axis[0].scale; in scmi_iio_get_raw_available()
398 exponent = exponent - scale; in scmi_iio_get_raw_available()
427 iio_chan->type = IIO_TIMESTAMP; in scmi_iio_set_timestamp_channel()
428 iio_chan->channel = -1; in scmi_iio_set_timestamp_channel()
429 iio_chan->scan_index = scan_index; in scmi_iio_set_timestamp_channel()
430 iio_chan->scan_type.sign = 'u'; in scmi_iio_set_timestamp_channel()
431 iio_chan->scan_type.realbits = 64; in scmi_iio_set_timestamp_channel()
432 iio_chan->scan_type.storagebits = 64; in scmi_iio_set_timestamp_channel()
439 iio_chan->type = type; in scmi_iio_set_data_channel()
440 iio_chan->modified = 1; in scmi_iio_set_data_channel()
441 iio_chan->channel2 = mod; in scmi_iio_set_data_channel()
442 iio_chan->info_mask_separate = in scmi_iio_set_data_channel()
444 iio_chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ); in scmi_iio_set_data_channel()
445 iio_chan->info_mask_shared_by_type_available = in scmi_iio_set_data_channel()
447 iio_chan->scan_index = scan_index; in scmi_iio_set_data_channel()
448 iio_chan->scan_type.sign = 's'; in scmi_iio_set_data_channel()
449 iio_chan->scan_type.realbits = 64; in scmi_iio_set_data_channel()
450 iio_chan->scan_type.storagebits = 64; in scmi_iio_set_data_channel()
451 iio_chan->scan_type.endianness = IIO_LE; in scmi_iio_set_data_channel()
452 iio_chan->ext_info = scmi_iio_ext_info; in scmi_iio_set_data_channel()
461 return -EINVAL; in scmi_iio_get_chan_modifier()
465 return -EINVAL; in scmi_iio_get_chan_modifier()
479 return -EINVAL; in scmi_iio_get_chan_modifier()
493 return -EINVAL; in scmi_iio_get_chan_type()
524 sensor->freq_avail = in scmi_iio_set_sampling_freq_avail()
525 devm_kzalloc(&iio_dev->dev, in scmi_iio_set_sampling_freq_avail()
526 sizeof(*sensor->freq_avail) * in scmi_iio_set_sampling_freq_avail()
527 (sensor->sensor_info->intervals.count * 2), in scmi_iio_set_sampling_freq_avail()
529 if (!sensor->freq_avail) in scmi_iio_set_sampling_freq_avail()
530 return -ENOMEM; in scmi_iio_set_sampling_freq_avail()
532 if (sensor->sensor_info->intervals.segmented) { in scmi_iio_set_sampling_freq_avail()
533 low_interval = sensor->sensor_info->intervals in scmi_iio_set_sampling_freq_avail()
537 sensor->freq_avail[0] = hz; in scmi_iio_set_sampling_freq_avail()
538 sensor->freq_avail[1] = uhz; in scmi_iio_set_sampling_freq_avail()
540 step_size = sensor->sensor_info->intervals in scmi_iio_set_sampling_freq_avail()
544 sensor->freq_avail[2] = hz; in scmi_iio_set_sampling_freq_avail()
545 sensor->freq_avail[3] = uhz; in scmi_iio_set_sampling_freq_avail()
547 high_interval = sensor->sensor_info->intervals in scmi_iio_set_sampling_freq_avail()
552 sensor->freq_avail[4] = hz; in scmi_iio_set_sampling_freq_avail()
553 sensor->freq_avail[5] = uhz; in scmi_iio_set_sampling_freq_avail()
555 for (i = 0; i < sensor->sensor_info->intervals.count; i++) { in scmi_iio_set_sampling_freq_avail()
556 cur_interval = sensor->sensor_info->intervals.desc[i]; in scmi_iio_set_sampling_freq_avail()
560 sensor->freq_avail[i * 2] = hz; in scmi_iio_set_sampling_freq_avail()
561 sensor->freq_avail[i * 2 + 1] = uhz; in scmi_iio_set_sampling_freq_avail()
578 struct device *dev = &sdev->dev; in scmi_alloc_iiodev()
579 const struct scmi_handle *handle = sdev->handle; in scmi_alloc_iiodev()
584 return ERR_PTR(-ENOMEM); in scmi_alloc_iiodev()
586 iiodev->modes = INDIO_DIRECT_MODE; in scmi_alloc_iiodev()
588 sensor->sensor_ops = ops; in scmi_alloc_iiodev()
589 sensor->ph = ph; in scmi_alloc_iiodev()
590 sensor->sensor_info = sensor_info; in scmi_alloc_iiodev()
591 sensor->sensor_update_nb.notifier_call = scmi_iio_sensor_update_cb; in scmi_alloc_iiodev()
592 sensor->indio_dev = iiodev; in scmi_alloc_iiodev()
593 mutex_init(&sensor->lock); in scmi_alloc_iiodev()
596 iiodev->num_channels = sensor_info->num_axis + 1; in scmi_alloc_iiodev()
597 iiodev->name = sensor_info->name; in scmi_alloc_iiodev()
598 iiodev->info = &scmi_iio_info; in scmi_alloc_iiodev()
602 sizeof(*iio_channels) * (iiodev->num_channels), in scmi_alloc_iiodev()
605 return ERR_PTR(-ENOMEM); in scmi_alloc_iiodev()
611 for (i = 0; i < sensor_info->num_axis; i++) { in scmi_alloc_iiodev()
612 ret = scmi_iio_get_chan_type(sensor_info->axis[i].type, &type); in scmi_alloc_iiodev()
616 ret = scmi_iio_get_chan_modifier(sensor_info->axis[i].name, in scmi_alloc_iiodev()
622 sensor_info->axis[i].id); in scmi_alloc_iiodev()
625 ret = handle->notify_ops->devm_event_notifier_register(sdev, in scmi_alloc_iiodev()
627 &sensor->sensor_info->id, in scmi_alloc_iiodev()
628 &sensor->sensor_update_nb); in scmi_alloc_iiodev()
630 return dev_err_ptr_probe(&iiodev->dev, ret, in scmi_alloc_iiodev()
632 sensor->sensor_info->name); in scmi_alloc_iiodev()
635 iiodev->channels = iio_channels; in scmi_alloc_iiodev()
642 struct scmi_handle *handle = sdev->handle; in scmi_iio_dev_probe()
645 struct device *dev = &sdev->dev; in scmi_iio_dev_probe()
648 int err = -ENODEV, i; in scmi_iio_dev_probe()
651 return -ENODEV; in scmi_iio_dev_probe()
653 sensor_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_SENSOR, &ph); in scmi_iio_dev_probe()
658 nr_sensors = sensor_ops->count_get(ph); in scmi_iio_dev_probe()
661 return -ENODEV; in scmi_iio_dev_probe()
665 sensor_info = sensor_ops->info_get(ph, i); in scmi_iio_dev_probe()
667 return dev_err_probe(dev, -EINVAL, in scmi_iio_dev_probe()
671 /* This driver only supports 3-axis accel and gyro, skipping other sensors */ in scmi_iio_dev_probe()
672 if (sensor_info->num_axis != SCMI_IIO_NUM_OF_AXIS) in scmi_iio_dev_probe()
675 /* This driver only supports 3-axis accel and gyro, skipping other sensors */ in scmi_iio_dev_probe()
676 if (sensor_info->axis[0].type != METERS_SEC_SQUARED && in scmi_iio_dev_probe()
677 sensor_info->axis[0].type != RADIANS_SEC) in scmi_iio_dev_probe()
685 sensor_info->name); in scmi_iio_dev_probe()
688 err = devm_iio_kfifo_buffer_setup(&scmi_iio_dev->dev, in scmi_iio_dev_probe()
694 sensor_info->name); in scmi_iio_dev_probe()
701 sensor_info->name); in scmi_iio_dev_probe()
714 .name = "scmi-sensor-iiodev",