Lines Matching +full:angle +full:- +full:measurement

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for the TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor
57 * 16-bit unique manufacturer ID 0x49 / 0x54 = "TI"
104 ANGLE, enumerator
126 * Locks the sensor for exclusive use during a measurement (which
129 * first-come-first-serve manner.
134 static const char *const tmag5273_angle_names[] = { "off", "x-y", "y-z", "x-z" };
157 s16 *y, s16 *z, u16 *angle, u16 *magnitude) in tmag5273_get_measure() argument
163 mutex_lock(&data->lock); in tmag5273_get_measure()
167 * channels. Since we are in continuous measurement mode, a measurement in tmag5273_get_measure()
168 * may already be there, so poll for completed measurement with in tmag5273_get_measure()
171 ret = regmap_read_poll_timeout(data->map, TMAG5273_CONV_STATUS, status, in tmag5273_get_measure()
175 dev_err(data->dev, "timeout waiting for measurement\n"); in tmag5273_get_measure()
179 ret = regmap_bulk_read(data->map, TMAG5273_T_MSB_RESULT, reg_data, in tmag5273_get_measure()
188 ret = regmap_bulk_read(data->map, TMAG5273_ANGLE_RESULT_MSB, in tmag5273_get_measure()
193 * angle has 9 bits integer value and 4 bits fractional part in tmag5273_get_measure()
197 *angle = be16_to_cpu(reg_data[0]); in tmag5273_get_measure()
199 ret = regmap_read(data->map, TMAG5273_MAGNITUDE_RESULT, &val); in tmag5273_get_measure()
205 mutex_unlock(&data->lock); in tmag5273_get_measure()
213 if (val == data->conv_avg) in tmag5273_write_osr()
221 return -EINVAL; in tmag5273_write_osr()
222 data->conv_avg = val; in tmag5273_write_osr()
224 return regmap_update_bits(data->map, TMAG5273_DEVICE_CONFIG_1, in tmag5273_write_osr()
235 if (tmag5273_scale[data->version][i].micro == scale_micro) in tmag5273_write_scale()
239 return -EINVAL; in tmag5273_write_scale()
240 data->scale_index = i; in tmag5273_write_scale()
242 if (data->scale_index == MAGN_RANGE_LOW) in tmag5273_write_scale()
247 return regmap_update_bits(data->map, TMAG5273_SENSOR_CONFIG_2, in tmag5273_write_scale()
265 switch (chan->type) { in tmag5273_read_avail()
268 *vals = (int *)tmag5273_scale[data->version]; in tmag5273_read_avail()
269 *length = ARRAY_SIZE(tmag5273_scale[data->version]) * in tmag5273_read_avail()
273 return -EINVAL; in tmag5273_read_avail()
276 return -EINVAL; in tmag5273_read_avail()
286 u16 angle, magnitude; in tmag5273_read_raw() local
292 ret = pm_runtime_resume_and_get(data->dev); in tmag5273_read_raw()
296 ret = tmag5273_get_measure(data, &t, &x, &y, &z, &angle, &magnitude); in tmag5273_read_raw()
298 pm_runtime_mark_last_busy(data->dev); in tmag5273_read_raw()
299 pm_runtime_put_autosuspend(data->dev); in tmag5273_read_raw()
304 switch (chan->address) { in tmag5273_read_raw()
317 case ANGLE: in tmag5273_read_raw()
318 *val = angle; in tmag5273_read_raw()
324 return -EINVAL; in tmag5273_read_raw()
327 switch (chan->type) { in tmag5273_read_raw()
340 *val2 = tmag5273_scale[data->version] in tmag5273_read_raw()
341 [data->scale_index].micro; in tmag5273_read_raw()
345 * Angle is in degrees and has four fractional bits, in tmag5273_read_raw()
352 return -EINVAL; in tmag5273_read_raw()
355 switch (chan->type) { in tmag5273_read_raw()
357 *val = -16005; in tmag5273_read_raw()
360 return -EINVAL; in tmag5273_read_raw()
363 *val = data->conv_avg; in tmag5273_read_raw()
367 return -EINVAL; in tmag5273_read_raw()
381 switch (chan->type) { in tmag5273_write_raw()
384 return -EINVAL; in tmag5273_write_raw()
387 return -EINVAL; in tmag5273_write_raw()
390 return -EINVAL; in tmag5273_write_raw()
443 .address = ANGLE,
444 .scan_index = ANGLE,
492 return regmap_write(data->map, TMAG5273_DEVICE_CONFIG_2, val); in tmag5273_set_operating_mode()
497 struct device *dev = data->dev; in tmag5273_read_device_property()
500 data->angle_measurement = TMAG5273_ANGLE_EN_X_Y; in tmag5273_read_device_property()
502 ret = device_property_match_property_string(dev, "ti,angle-measurement", in tmag5273_read_device_property()
506 data->angle_measurement = ret; in tmag5273_read_device_property()
514 regmap_read(data->map, TMAG5273_DEVICE_ID, &val); in tmag5273_wake_up()
516 * Time to go to stand-by mode from sleep mode is 50us in tmag5273_wake_up()
526 ret = regmap_write(data->map, TMAG5273_DEVICE_CONFIG_1, in tmag5273_chip_init()
530 data->conv_avg = 32; in tmag5273_chip_init()
532 ret = regmap_write(data->map, TMAG5273_DEVICE_CONFIG_2, in tmag5273_chip_init()
537 ret = regmap_write(data->map, TMAG5273_SENSOR_CONFIG_1, in tmag5273_chip_init()
543 ret = regmap_write(data->map, TMAG5273_SENSOR_CONFIG_2, in tmag5273_chip_init()
545 data->angle_measurement)); in tmag5273_chip_init()
548 data->scale_index = MAGN_RANGE_LOW; in tmag5273_chip_init()
550 return regmap_write(data->map, TMAG5273_T_CONFIG, TMAG5273_T_CH_EN); in tmag5273_chip_init()
558 ret = regmap_read(data->map, TMAG5273_DEVICE_ID, &val); in tmag5273_check_device_id()
560 return dev_err_probe(data->dev, ret, "failed to power on device\n"); in tmag5273_check_device_id()
561 data->version = FIELD_PREP(TMAG5273_VERSION_MASK, val); in tmag5273_check_device_id()
563 ret = regmap_bulk_read(data->map, TMAG5273_MANUFACTURER_ID_LSB, &devid, in tmag5273_check_device_id()
566 return dev_err_probe(data->dev, ret, "failed to read device ID\n"); in tmag5273_check_device_id()
567 data->devid = le16_to_cpu(devid); in tmag5273_check_device_id()
569 switch (data->devid) { in tmag5273_check_device_id()
577 snprintf(data->name, sizeof(data->name), "tmag5273x%1u", data->version); in tmag5273_check_device_id()
578 if (data->version < 1 || data->version > 2) in tmag5273_check_device_id()
579 dev_warn(data->dev, "Unsupported device %s\n", data->name); in tmag5273_check_device_id()
586 dev_warn(data->dev, "Unknown device ID 0x%x\n", data->devid); in tmag5273_check_device_id()
598 struct device *dev = &i2c->dev; in tmag5273_probe()
605 return -ENOMEM; in tmag5273_probe()
608 data->dev = dev; in tmag5273_probe()
611 data->map = devm_regmap_init_i2c(i2c, &tmag5273_regmap_config); in tmag5273_probe()
612 if (IS_ERR(data->map)) in tmag5273_probe()
613 return dev_err_probe(dev, PTR_ERR(data->map), in tmag5273_probe()
616 mutex_init(&data->lock); in tmag5273_probe()
665 indio_dev->info = &tmag5273_info; in tmag5273_probe()
666 indio_dev->modes = INDIO_DIRECT_MODE; in tmag5273_probe()
667 indio_dev->name = data->name; in tmag5273_probe()
668 indio_dev->channels = tmag5273_channels; in tmag5273_probe()
669 indio_dev->num_channels = ARRAY_SIZE(tmag5273_channels); in tmag5273_probe()
736 MODULE_DESCRIPTION("TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor driver");