Lines Matching +full:sens +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
3 * MMC35240 - MEMSIC 3-axis Magnetic Sensor
7 * IIO driver for MMC35240 (7-bit I2C slave address 0x30).
61 * #define OTP_CONVERT(REG) ((float)((REG) >=32 ? (32 - (REG)) : (REG)) * 0.006
72 #define MMC35240_OTP_CONVERT_Y(REG) (((REG) >= 32 ? (32 - (REG)) : (REG)) * 6)
75 #define MMC35240_OTP_CONVERT_Z(REG) (((REG) >= 32 ? (32 - (REG)) : (REG)) * 81)
97 int sens[3]; /* sensitivity per X, Y, Z axis */ member
177 return -EINVAL; in mmc35240_get_samp_freq_index()
189 ret = regmap_set_bits(data->regmap, MMC35240_REG_CTRL0, in mmc35240_hw_set()
200 return regmap_set_bits(data->regmap, MMC35240_REG_CTRL0, coil_bit); in mmc35240_hw_set()
210 ret = regmap_read(data->regmap, MMC35240_REG_ID, ®_id); in mmc35240_init()
212 dev_err(&data->client->dev, "Error reading product id\n"); in mmc35240_init()
216 dev_dbg(&data->client->dev, "MMC35240 chip id %x\n", reg_id); in mmc35240_init()
233 ret = regmap_update_bits(data->regmap, MMC35240_REG_CTRL1, in mmc35240_init()
235 data->res << MMC35240_CTRL1_BW_SHIFT); in mmc35240_init()
239 ret = regmap_bulk_read(data->regmap, MMC35240_OTP_START_ADDR, in mmc35240_init()
248 data->axis_coef[0] = MMC35240_X_COEFF(1); in mmc35240_init()
249 data->axis_coef[1] = MMC35240_Y_COEFF(y_convert); in mmc35240_init()
250 data->axis_coef[2] = MMC35240_Z_COEFF(z_convert); in mmc35240_init()
252 data->axis_scale[0] = 1; in mmc35240_init()
253 data->axis_scale[1] = 1000; in mmc35240_init()
254 data->axis_scale[2] = 10000; in mmc35240_init()
264 ret = regmap_write(data->regmap, MMC35240_REG_CTRL0, in mmc35240_take_measurement()
269 while (tries-- > 0) { in mmc35240_take_measurement()
270 ret = regmap_read(data->regmap, MMC35240_REG_STATUS, in mmc35240_take_measurement()
281 dev_err(&data->client->dev, "data not ready\n"); in mmc35240_take_measurement()
282 return -EIO; in mmc35240_take_measurement()
296 return regmap_bulk_read(data->regmap, MMC35240_REG_XOUT_L, buf, in mmc35240_read_measurement()
301 * mmc35240_raw_to_mgauss - convert raw readings to milli gauss. Also apply
309 * Returns: 0 in case of success, -EINVAL when @index is not valid
315 int sens[3]; in mmc35240_raw_to_mgauss() local
322 sens[AXIS_X] = mmc35240_props_table[data->res].sens[AXIS_X]; in mmc35240_raw_to_mgauss()
323 sens[AXIS_Y] = mmc35240_props_table[data->res].sens[AXIS_Y]; in mmc35240_raw_to_mgauss()
324 sens[AXIS_Z] = mmc35240_props_table[data->res].sens[AXIS_Z]; in mmc35240_raw_to_mgauss()
326 nfo = mmc35240_props_table[data->res].nfo; in mmc35240_raw_to_mgauss()
330 *val = (raw[AXIS_X] - nfo) * 1000 / sens[AXIS_X]; in mmc35240_raw_to_mgauss()
333 *val = (raw[AXIS_Y] - nfo) * 1000 / sens[AXIS_Y] - in mmc35240_raw_to_mgauss()
334 (raw[AXIS_Z] - nfo) * 1000 / sens[AXIS_Z]; in mmc35240_raw_to_mgauss()
337 *val = (raw[AXIS_Y] - nfo) * 1000 / sens[AXIS_Y] + in mmc35240_raw_to_mgauss()
338 (raw[AXIS_Z] - nfo) * 1000 / sens[AXIS_Z]; in mmc35240_raw_to_mgauss()
341 return -EINVAL; in mmc35240_raw_to_mgauss()
344 *val = (*val) * data->axis_coef[index] / data->axis_scale[index]; in mmc35240_raw_to_mgauss()
360 mutex_lock(&data->mutex); in mmc35240_read_raw()
362 mutex_unlock(&data->mutex); in mmc35240_read_raw()
365 ret = mmc35240_raw_to_mgauss(data, chan->address, buf, val); in mmc35240_read_raw()
374 mutex_lock(&data->mutex); in mmc35240_read_raw()
375 ret = regmap_read(data->regmap, MMC35240_REG_CTRL1, ®); in mmc35240_read_raw()
376 mutex_unlock(&data->mutex); in mmc35240_read_raw()
382 return -EINVAL; in mmc35240_read_raw()
388 return -EINVAL; in mmc35240_read_raw()
403 return -EINVAL; in mmc35240_write_raw()
404 mutex_lock(&data->mutex); in mmc35240_write_raw()
405 ret = regmap_update_bits(data->regmap, MMC35240_REG_CTRL1, in mmc35240_write_raw()
408 mutex_unlock(&data->mutex); in mmc35240_write_raw()
411 return -EINVAL; in mmc35240_write_raw()
489 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in mmc35240_probe()
491 return -ENOMEM; in mmc35240_probe()
495 dev_err(&client->dev, "regmap initialization failed\n"); in mmc35240_probe()
501 data->client = client; in mmc35240_probe()
502 data->regmap = regmap; in mmc35240_probe()
503 data->res = MMC35240_16_BITS_SLOW; in mmc35240_probe()
505 mutex_init(&data->mutex); in mmc35240_probe()
507 indio_dev->info = &mmc35240_info; in mmc35240_probe()
508 indio_dev->name = MMC35240_DRV_NAME; in mmc35240_probe()
509 indio_dev->channels = mmc35240_channels; in mmc35240_probe()
510 indio_dev->num_channels = ARRAY_SIZE(mmc35240_channels); in mmc35240_probe()
511 indio_dev->modes = INDIO_DIRECT_MODE; in mmc35240_probe()
515 dev_err(&client->dev, "mmc35240 chip init failed\n"); in mmc35240_probe()
518 return devm_iio_device_register(&client->dev, indio_dev); in mmc35240_probe()
526 regcache_cache_only(data->regmap, true); in mmc35240_suspend()
537 regcache_mark_dirty(data->regmap); in mmc35240_resume()
538 ret = regcache_sync_region(data->regmap, MMC35240_REG_CTRL0, in mmc35240_resume()
543 regcache_cache_only(data->regmap, false); in mmc35240_resume()