Lines Matching +full:hall +full:- +full:effect
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"
131 * first-come-first-serve manner.
136 static const char *const tmag5273_angle_names[] = { "off", "x-y", "y-z", "x-z" };
140 * effect, but also increases conversion time.
165 mutex_lock(&data->lock); in tmag5273_get_measure()
173 ret = regmap_read_poll_timeout(data->map, TMAG5273_CONV_STATUS, status, in tmag5273_get_measure()
177 dev_err(data->dev, "timeout waiting for measurement\n"); in tmag5273_get_measure()
181 ret = regmap_bulk_read(data->map, TMAG5273_T_MSB_RESULT, reg_data, in tmag5273_get_measure()
190 ret = regmap_bulk_read(data->map, TMAG5273_ANGLE_RESULT_MSB, in tmag5273_get_measure()
201 ret = regmap_read(data->map, TMAG5273_MAGNITUDE_RESULT, &val); in tmag5273_get_measure()
207 mutex_unlock(&data->lock); in tmag5273_get_measure()
215 if (val == data->conv_avg) in tmag5273_write_osr()
223 return -EINVAL; in tmag5273_write_osr()
224 data->conv_avg = val; in tmag5273_write_osr()
226 return regmap_update_bits(data->map, TMAG5273_DEVICE_CONFIG_1, in tmag5273_write_osr()
237 if (tmag5273_scale[data->version][i].micro == scale_micro) in tmag5273_write_scale()
241 return -EINVAL; in tmag5273_write_scale()
242 data->scale_index = i; in tmag5273_write_scale()
244 if (data->scale_index == MAGN_RANGE_LOW) in tmag5273_write_scale()
249 return regmap_update_bits(data->map, TMAG5273_SENSOR_CONFIG_2, in tmag5273_write_scale()
267 switch (chan->type) { in tmag5273_read_avail()
270 *vals = (int *)tmag5273_scale[data->version]; in tmag5273_read_avail()
271 *length = ARRAY_SIZE(tmag5273_scale[data->version]) * in tmag5273_read_avail()
275 return -EINVAL; in tmag5273_read_avail()
278 return -EINVAL; in tmag5273_read_avail()
294 ret = pm_runtime_resume_and_get(data->dev); in tmag5273_read_raw()
300 pm_runtime_mark_last_busy(data->dev); in tmag5273_read_raw()
301 pm_runtime_put_autosuspend(data->dev); in tmag5273_read_raw()
306 switch (chan->address) { in tmag5273_read_raw()
326 return -EINVAL; in tmag5273_read_raw()
329 switch (chan->type) { in tmag5273_read_raw()
342 *val2 = tmag5273_scale[data->version] in tmag5273_read_raw()
343 [data->scale_index].micro; in tmag5273_read_raw()
354 return -EINVAL; in tmag5273_read_raw()
357 switch (chan->type) { in tmag5273_read_raw()
359 *val = -16005; in tmag5273_read_raw()
362 return -EINVAL; in tmag5273_read_raw()
365 *val = data->conv_avg; in tmag5273_read_raw()
369 return -EINVAL; in tmag5273_read_raw()
383 switch (chan->type) { in tmag5273_write_raw()
386 return -EINVAL; in tmag5273_write_raw()
389 return -EINVAL; in tmag5273_write_raw()
392 return -EINVAL; in tmag5273_write_raw()
494 return regmap_write(data->map, TMAG5273_DEVICE_CONFIG_2, val); in tmag5273_set_operating_mode()
499 struct device *dev = data->dev; in tmag5273_read_device_property()
503 data->angle_measurement = TMAG5273_ANGLE_EN_X_Y; in tmag5273_read_device_property()
505 ret = device_property_read_string(dev, "ti,angle-measurement", &str); in tmag5273_read_device_property()
512 data->angle_measurement = ret; in tmag5273_read_device_property()
520 regmap_read(data->map, TMAG5273_DEVICE_ID, &val); in tmag5273_wake_up()
522 * Time to go to stand-by mode from sleep mode is 50us in tmag5273_wake_up()
532 ret = regmap_write(data->map, TMAG5273_DEVICE_CONFIG_1, in tmag5273_chip_init()
536 data->conv_avg = 32; in tmag5273_chip_init()
538 ret = regmap_write(data->map, TMAG5273_DEVICE_CONFIG_2, in tmag5273_chip_init()
543 ret = regmap_write(data->map, TMAG5273_SENSOR_CONFIG_1, in tmag5273_chip_init()
549 ret = regmap_write(data->map, TMAG5273_SENSOR_CONFIG_2, in tmag5273_chip_init()
551 data->angle_measurement)); in tmag5273_chip_init()
554 data->scale_index = MAGN_RANGE_LOW; in tmag5273_chip_init()
556 return regmap_write(data->map, TMAG5273_T_CONFIG, TMAG5273_T_CH_EN); in tmag5273_chip_init()
564 ret = regmap_read(data->map, TMAG5273_DEVICE_ID, &val); in tmag5273_check_device_id()
566 return dev_err_probe(data->dev, ret, "failed to power on device\n"); in tmag5273_check_device_id()
567 data->version = FIELD_PREP(TMAG5273_VERSION_MASK, val); in tmag5273_check_device_id()
569 ret = regmap_bulk_read(data->map, TMAG5273_MANUFACTURER_ID_LSB, &devid, in tmag5273_check_device_id()
572 return dev_err_probe(data->dev, ret, "failed to read device ID\n"); in tmag5273_check_device_id()
573 data->devid = le16_to_cpu(devid); in tmag5273_check_device_id()
575 switch (data->devid) { in tmag5273_check_device_id()
583 snprintf(data->name, sizeof(data->name), "tmag5273x%1u", data->version); in tmag5273_check_device_id()
584 if (data->version < 1 || data->version > 2) in tmag5273_check_device_id()
585 dev_warn(data->dev, "Unsupported device %s\n", data->name); in tmag5273_check_device_id()
592 dev_warn(data->dev, "Unknown device ID 0x%x\n", data->devid); in tmag5273_check_device_id()
604 struct device *dev = &i2c->dev; in tmag5273_probe()
611 return -ENOMEM; in tmag5273_probe()
614 data->dev = dev; in tmag5273_probe()
617 data->map = devm_regmap_init_i2c(i2c, &tmag5273_regmap_config); in tmag5273_probe()
618 if (IS_ERR(data->map)) in tmag5273_probe()
619 return dev_err_probe(dev, PTR_ERR(data->map), in tmag5273_probe()
622 mutex_init(&data->lock); in tmag5273_probe()
671 indio_dev->info = &tmag5273_info; in tmag5273_probe()
672 indio_dev->modes = INDIO_DIRECT_MODE; in tmag5273_probe()
673 indio_dev->name = data->name; in tmag5273_probe()
674 indio_dev->channels = tmag5273_channels; in tmag5273_probe()
675 indio_dev->num_channels = ARRAY_SIZE(tmag5273_channels); in tmag5273_probe()
742 MODULE_DESCRIPTION("TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor driver");