Lines Matching +full:long +full:- +full:press +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MPRLS0025PA - Honeywell MicroPressure pressure sensor series driver
5 * Copyright (c) Andreas Klinger <ak@it-klinger.de>
8 * https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/
9 * products/sensors/pressure-sensors/board-mount-pressure-sensors/
10 * micropressure-mpr-series/documents/
11 * sps-siot-mpr-series-datasheet-32332628-ciid-172626.pdf
13 * 7-bit I2C default slave address: 0x18
46 * pressure = (press_cnt - outputmin) * scale + pmin
48 * * pressure - measured pressure in Pascal
49 * * press_cnt - raw value read from sensor
50 * * pmin - minimum pressure range value of sensor (data->pmin)
51 * * pmax - maximum pressure range value of sensor (data->pmax)
52 * * outputmin - minimum numerical range raw value delivered by sensor
54 * * outputmax - maximum numerical range raw value delivered by sensor
56 * * scale - (pmax - pmin) / (outputmax - outputmin)
62 * * raw - press_cnt
63 * * offset - (-1 * outputmin) - pmin / scale
65 * which reduces the offset to (-1 * outputmin)
148 if (data->gpiod_reset) { in mpr_reset()
149 gpiod_set_value(data->gpiod_reset, 0); in mpr_reset()
151 gpiod_set_value(data->gpiod_reset, 1); in mpr_reset()
156 * mpr_read_pressure() - Read pressure value from sensor via I2C
158 * @press: Output value read from sensor.
165 * Context: The function can sleep and data->lock should be held when calling it
167 * * 0 - OK, the pressure value could be read
168 * * -ETIMEDOUT - Timeout while waiting for the EOC interrupt or busy flag is
171 static int mpr_read_pressure(struct mpr_data *data, s32 *press) in mpr_read_pressure() argument
173 struct device *dev = &data->client->dev; in mpr_read_pressure()
180 reinit_completion(&data->completion); in mpr_read_pressure()
182 ret = i2c_master_send(data->client, wdata, sizeof(wdata)); in mpr_read_pressure()
188 dev_err(dev, "received size doesn't fit - ret: %d / %u\n", ret, in mpr_read_pressure()
190 return -EIO; in mpr_read_pressure()
193 if (data->irq > 0) { in mpr_read_pressure()
194 ret = wait_for_completion_timeout(&data->completion, HZ); in mpr_read_pressure()
197 return -ETIMEDOUT; in mpr_read_pressure()
203 * datasheet only says to wait at least 5 ms for the in mpr_read_pressure()
205 * --> let's try it nloops (10) times which seems to be in mpr_read_pressure()
206 * quite long in mpr_read_pressure()
209 status = i2c_smbus_read_byte(data->client); in mpr_read_pressure()
221 return -ETIMEDOUT; in mpr_read_pressure()
225 ret = i2c_master_recv(data->client, buf, sizeof(buf)); in mpr_read_pressure()
231 dev_err(dev, "received size doesn't fit - ret: %d / %u\n", ret, in mpr_read_pressure()
233 return -EIO; in mpr_read_pressure()
242 return -ETIMEDOUT; in mpr_read_pressure()
245 *press = get_unaligned_be24(&buf[1]); in mpr_read_pressure()
247 dev_dbg(dev, "received: %*ph cnt: %d\n", ret, buf, *press); in mpr_read_pressure()
256 complete(&data->completion); in mpr_eoc_handler()
265 struct iio_dev *indio_dev = pf->indio_dev; in mpr_trigger_handler()
268 mutex_lock(&data->lock); in mpr_trigger_handler()
269 ret = mpr_read_pressure(data, &data->chan.pres); in mpr_trigger_handler()
273 iio_push_to_buffers_with_timestamp(indio_dev, &data->chan, in mpr_trigger_handler()
277 mutex_unlock(&data->lock); in mpr_trigger_handler()
278 iio_trigger_notify_done(indio_dev->trig); in mpr_trigger_handler()
284 struct iio_chan_spec const *chan, int *val, int *val2, long mask) in mpr_read_raw()
290 if (chan->type != IIO_PRESSURE) in mpr_read_raw()
291 return -EINVAL; in mpr_read_raw()
295 mutex_lock(&data->lock); in mpr_read_raw()
297 mutex_unlock(&data->lock); in mpr_read_raw()
303 *val = data->scale; in mpr_read_raw()
304 *val2 = data->scale2; in mpr_read_raw()
307 *val = data->offset; in mpr_read_raw()
308 *val2 = data->offset2; in mpr_read_raw()
311 return -EINVAL; in mpr_read_raw()
324 struct device *dev = &client->dev; in mpr_probe()
328 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE)) in mpr_probe()
329 return dev_err_probe(dev, -EOPNOTSUPP, in mpr_probe()
334 return dev_err_probe(dev, -ENOMEM, "couldn't get iio_dev\n"); in mpr_probe()
337 data->client = client; in mpr_probe()
338 data->irq = client->irq; in mpr_probe()
340 mutex_init(&data->lock); in mpr_probe()
341 init_completion(&data->completion); in mpr_probe()
343 indio_dev->name = "mprls0025pa"; in mpr_probe()
344 indio_dev->info = &mpr_info; in mpr_probe()
345 indio_dev->channels = mpr_channels; in mpr_probe()
346 indio_dev->num_channels = ARRAY_SIZE(mpr_channels); in mpr_probe()
347 indio_dev->modes = INDIO_DIRECT_MODE; in mpr_probe()
355 ret = device_property_read_u32(dev, "honeywell,pmin-pascal", in mpr_probe()
356 &data->pmin); in mpr_probe()
359 "honeywell,pmin-pascal could not be read\n"); in mpr_probe()
360 ret = device_property_read_u32(dev, "honeywell,pmax-pascal", in mpr_probe()
361 &data->pmax); in mpr_probe()
364 "honeywell,pmax-pascal could not be read\n"); in mpr_probe()
366 "honeywell,transfer-function", &func); in mpr_probe()
369 "honeywell,transfer-function could not be read\n"); in mpr_probe()
370 data->function = func - 1; in mpr_probe()
371 if (data->function > MPR_FUNCTION_C) in mpr_probe()
372 return dev_err_probe(dev, -EINVAL, in mpr_probe()
373 "honeywell,transfer-function %d invalid\n", in mpr_probe()
374 data->function); in mpr_probe()
378 data->pmin = 0; in mpr_probe()
379 data->pmax = 172369; /* 25 psi */ in mpr_probe()
380 data->function = MPR_FUNCTION_A; in mpr_probe()
383 data->outmin = mpr_func_spec[data->function].output_min; in mpr_probe()
384 data->outmax = mpr_func_spec[data->function].output_max; in mpr_probe()
387 scale = div_s64(((s64)(data->pmax - data->pmin)) * NANO, in mpr_probe()
388 data->outmax - data->outmin); in mpr_probe()
389 data->scale = div_s64_rem(scale, NANO, &data->scale2); in mpr_probe()
394 offset = ((-1LL) * (s64)data->outmin) * NANO - in mpr_probe()
395 div_s64(div_s64((s64)data->pmin * NANO, scale), NANO); in mpr_probe()
396 data->offset = div_s64_rem(offset, NANO, &data->offset2); in mpr_probe()
398 if (data->irq > 0) { in mpr_probe()
399 ret = devm_request_irq(dev, data->irq, mpr_eoc_handler, in mpr_probe()
400 IRQF_TRIGGER_RISING, client->name, data); in mpr_probe()
403 "request irq %d failed\n", data->irq); in mpr_probe()
406 data->gpiod_reset = devm_gpiod_get_optional(dev, "reset", in mpr_probe()
408 if (IS_ERR(data->gpiod_reset)) in mpr_probe()
409 return dev_err_probe(dev, PTR_ERR(data->gpiod_reset), in mpr_probe()
410 "request reset-gpio failed\n"); in mpr_probe()
450 MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");