Lines Matching +full:wp +full:- +full:content

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Driver for InvenSense ICP-1010xx barometric pressure and temperature sensor.
8 * http://www.invensense.com/wp-content/uploads/2018/01/DS-000186-ICP-101xx-v1.2.pdf
115 return -EIO; in icp10100_i2c_xfer()
124 size_t size = cmd->response_word_nb * ICP10100_RESPONSE_WORD_LENGTH; in icp10100_send_cmd()
130 .addr = st->client->addr, in icp10100_send_cmd()
133 .buf = (uint8_t *)&cmd->cmd, in icp10100_send_cmd()
135 .addr = st->client->addr, in icp10100_send_cmd()
146 return -EINVAL; in icp10100_send_cmd()
148 if (cmd->response_word_nb > 0 && in icp10100_send_cmd()
149 (buf == NULL || buf_len < (cmd->response_word_nb * 2))) in icp10100_send_cmd()
150 return -EINVAL; in icp10100_send_cmd()
152 dev_dbg(&st->client->dev, "sending cmd %#x\n", be16_to_cpu(cmd->cmd)); in icp10100_send_cmd()
154 if (cmd->response_word_nb > 0 && cmd->wait_us == 0) { in icp10100_send_cmd()
155 /* direct command-response without waiting */ in icp10100_send_cmd()
156 ret = icp10100_i2c_xfer(st->client->adapter, msgs, in icp10100_send_cmd()
162 ret = icp10100_i2c_xfer(st->client->adapter, &msgs[0], 1); in icp10100_send_cmd()
165 if (cmd->wait_us > 0) in icp10100_send_cmd()
166 usleep_range(cmd->wait_us, cmd->wait_max_us); in icp10100_send_cmd()
168 if (cmd->response_word_nb > 0) { in icp10100_send_cmd()
169 ret = icp10100_i2c_xfer(st->client->adapter, &msgs[1], 1); in icp10100_send_cmd()
178 for (i = 0; i < cmd->response_word_nb; ++i) { in icp10100_send_cmd()
183 dev_err(&st->client->dev, "crc error recv=%#x calc=%#x\n", in icp10100_send_cmd()
185 return -EIO; in icp10100_send_cmd()
201 ret = i2c_master_send(st->client, icp10100_switch_mode_otp, in icp10100_read_cal_otp()
206 return -EIO; in icp10100_read_cal_otp()
214 st->cal[i] = be16_to_cpu(val); in icp10100_read_cal_otp()
215 dev_dbg(&st->client->dev, "cal[%d] = %d\n", i, st->cal[i]); in icp10100_read_cal_otp()
233 dev_err(&st->client->dev, "invalid id %#x\n", id); in icp10100_init_chip()
234 return -ENODEV; in icp10100_init_chip()
253 ret = pm_runtime_resume_and_get(&st->client->dev); in icp10100_get_measures()
257 mutex_lock(&st->lock); in icp10100_get_measures()
258 cmd = &icp10100_cmd_measure[st->mode]; in icp10100_get_measures()
260 mutex_unlock(&st->lock); in icp10100_get_measures()
268 pm_runtime_mark_last_busy(&st->client->dev); in icp10100_get_measures()
270 pm_runtime_put_autosuspend(&st->client->dev); in icp10100_get_measures()
288 dev_dbg(&st->client->dev, "raw: pressure = %u, temp = %u\n", in icp10100_get_pressure()
292 t = (int32_t)raw_temp - 32768; in icp10100_get_pressure()
294 val1 = (int64_t)st->cal[0] * (int64_t)t_square; in icp10100_get_pressure()
296 val1 = (int64_t)st->cal[1] * (int64_t)t_square; in icp10100_get_pressure()
297 p_lut[1] = offset_factor * st->cal[3] + in icp10100_get_pressure()
299 val1 = (int64_t)st->cal[2] * (int64_t)t_square; in icp10100_get_pressure()
301 dev_dbg(&st->client->dev, "p_lut = [%d, %d, %d]\n", in icp10100_get_pressure()
306 (int64_t)(p_calib[0] - p_calib[1]) + in icp10100_get_pressure()
308 (int64_t)(p_calib[1] - p_calib[2]) + in icp10100_get_pressure()
310 (int64_t)(p_calib[2] - p_calib[0]); in icp10100_get_pressure()
311 val2 = (int64_t)p_lut[2] * (int64_t)(p_calib[0] - p_calib[1]) + in icp10100_get_pressure()
312 (int64_t)p_lut[0] * (int64_t)(p_calib[1] - p_calib[2]) + in icp10100_get_pressure()
313 (int64_t)p_lut[1] * (int64_t)(p_calib[2] - p_calib[0]); in icp10100_get_pressure()
315 dev_dbg(&st->client->dev, "val1 = %lld, val2 = %lld, c = %lld\n", in icp10100_get_pressure()
317 val1 = (int64_t)p_calib[0] * (int64_t)p_lut[0] - in icp10100_get_pressure()
318 (int64_t)p_calib[1] * (int64_t)p_lut[1] - in icp10100_get_pressure()
319 (int64_t)(p_calib[1] - p_calib[0]) * c; in icp10100_get_pressure()
320 val2 = (int64_t)p_lut[0] - (int64_t)p_lut[1]; in icp10100_get_pressure()
322 dev_dbg(&st->client->dev, "val1 = %lld, val2 = %lld, a = %lld\n", in icp10100_get_pressure()
324 b = ((int64_t)p_calib[0] - a) * ((int64_t)p_lut[0] + c); in icp10100_get_pressure()
325 dev_dbg(&st->client->dev, "b = %lld\n", b); in icp10100_get_pressure()
354 switch (chan->type) { in icp10100_read_raw_measures()
368 ret = -EINVAL; in icp10100_read_raw_measures()
388 switch (chan->type) { in icp10100_read_raw()
395 return -EINVAL; in icp10100_read_raw()
399 switch (chan->type) { in icp10100_read_raw()
401 /* 1000 * -45°C in m°C */ in icp10100_read_raw()
402 *val = -45000; in icp10100_read_raw()
405 return -EINVAL; in icp10100_read_raw()
409 mutex_lock(&st->lock); in icp10100_read_raw()
410 *val = 1 << st->mode; in icp10100_read_raw()
411 mutex_unlock(&st->lock); in icp10100_read_raw()
414 return -EINVAL; in icp10100_read_raw()
432 return -EINVAL; in icp10100_read_avail()
448 return -EINVAL; in icp10100_write_raw()
451 return -EINVAL; in icp10100_write_raw()
455 mutex_lock(&st->lock); in icp10100_write_raw()
456 st->mode = mode; in icp10100_write_raw()
457 mutex_unlock(&st->lock); in icp10100_write_raw()
461 return -EINVAL; in icp10100_write_raw()
473 return -EINVAL; in icp10100_write_raw_get_fmt()
508 ret = regulator_enable(st->vdd); in icp10100_enable_regulator()
521 ret = regulator_disable(st->vdd); in icp10100_disable_regulator_action()
523 dev_err(&st->client->dev, "error %d disabling vdd\n", ret); in icp10100_disable_regulator_action()
540 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in icp10100_probe()
541 dev_err(&client->dev, "plain i2c transactions not supported\n"); in icp10100_probe()
542 return -ENODEV; in icp10100_probe()
545 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); in icp10100_probe()
547 return -ENOMEM; in icp10100_probe()
550 indio_dev->name = client->name; in icp10100_probe()
551 indio_dev->modes = INDIO_DIRECT_MODE; in icp10100_probe()
552 indio_dev->channels = icp10100_channels; in icp10100_probe()
553 indio_dev->num_channels = ARRAY_SIZE(icp10100_channels); in icp10100_probe()
554 indio_dev->info = &icp10100_info; in icp10100_probe()
557 mutex_init(&st->lock); in icp10100_probe()
558 st->client = client; in icp10100_probe()
559 st->mode = ICP10100_MODE_N; in icp10100_probe()
561 st->vdd = devm_regulator_get(&client->dev, "vdd"); in icp10100_probe()
562 if (IS_ERR(st->vdd)) in icp10100_probe()
563 return PTR_ERR(st->vdd); in icp10100_probe()
569 ret = devm_add_action_or_reset(&client->dev, in icp10100_probe()
579 dev_err(&client->dev, "init chip error %d\n", ret); in icp10100_probe()
584 pm_runtime_get_noresume(&client->dev); in icp10100_probe()
585 pm_runtime_set_active(&client->dev); in icp10100_probe()
586 pm_runtime_enable(&client->dev); in icp10100_probe()
587 pm_runtime_set_autosuspend_delay(&client->dev, 2000); in icp10100_probe()
588 pm_runtime_use_autosuspend(&client->dev); in icp10100_probe()
589 pm_runtime_put(&client->dev); in icp10100_probe()
590 ret = devm_add_action_or_reset(&client->dev, icp10100_pm_disable, in icp10100_probe()
591 &client->dev); in icp10100_probe()
595 return devm_iio_device_register(&client->dev, indio_dev); in icp10100_probe()
603 mutex_lock(&st->lock); in icp10100_suspend()
604 ret = regulator_disable(st->vdd); in icp10100_suspend()
605 mutex_unlock(&st->lock); in icp10100_suspend()
615 mutex_lock(&st->lock); in icp10100_resume()
625 mutex_unlock(&st->lock); in icp10100_resume()