Lines Matching +full:gain +full:- +full:scaling +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0-only
9 * 7-bit I2C slave address 0x4a
88 /* Scale can be multiplied by up to 128x via ALSPGA for measurement gain */
95 * This scaling factor is hidden from userspace and instead accounted for when
165 .scan_index = -1,
174 ret = regmap_read(data->regmap, MAX44000_REG_CFG_RX, &val); in max44000_read_alstim()
182 return regmap_write_bits(data->regmap, MAX44000_REG_CFG_RX, in max44000_write_alstim()
192 ret = regmap_read(data->regmap, MAX44000_REG_CFG_RX, &val); in max44000_read_alspga()
200 return regmap_write_bits(data->regmap, MAX44000_REG_CFG_RX, in max44000_write_alspga()
211 ret = regmap_bulk_read(data->regmap, MAX44000_REG_ALS_DATA_HI, in max44000_read_alsval()
240 return -ERANGE; in max44000_write_led_current_raw()
243 return regmap_write_bits(data->regmap, MAX44000_REG_CFG_TX, in max44000_write_led_current_raw()
252 ret = regmap_read(data->regmap, MAX44000_REG_CFG_TX, ®val); in max44000_read_led_current_raw()
257 regval -= 4; in max44000_read_led_current_raw()
272 switch (chan->type) { in max44000_read_raw()
274 mutex_lock(&data->lock); in max44000_read_raw()
276 mutex_unlock(&data->lock); in max44000_read_raw()
283 mutex_lock(&data->lock); in max44000_read_raw()
284 ret = regmap_read(data->regmap, MAX44000_REG_PRX_DATA, ®val); in max44000_read_raw()
285 mutex_unlock(&data->lock); in max44000_read_raw()
292 mutex_lock(&data->lock); in max44000_read_raw()
294 mutex_unlock(&data->lock); in max44000_read_raw()
301 return -EINVAL; in max44000_read_raw()
305 switch (chan->type) { in max44000_read_raw()
312 mutex_lock(&data->lock); in max44000_read_raw()
314 mutex_unlock(&data->lock); in max44000_read_raw()
322 - max44000_alspga_shift[alspga]; in max44000_read_raw()
326 return -EINVAL; in max44000_read_raw()
330 mutex_lock(&data->lock); in max44000_read_raw()
332 mutex_unlock(&data->lock); in max44000_read_raw()
341 return -EINVAL; in max44000_read_raw()
352 if (mask == IIO_CHAN_INFO_RAW && chan->type == IIO_CURRENT) { in max44000_write_raw()
353 mutex_lock(&data->lock); in max44000_write_raw()
355 mutex_unlock(&data->lock); in max44000_write_raw()
357 } else if (mask == IIO_CHAN_INFO_INT_TIME && chan->type == IIO_LIGHT) { in max44000_write_raw()
362 mutex_lock(&data->lock); in max44000_write_raw()
364 mutex_unlock(&data->lock); in max44000_write_raw()
366 } else if (mask == IIO_CHAN_INFO_SCALE && chan->type == IIO_LIGHT) { in max44000_write_raw()
371 mutex_lock(&data->lock); in max44000_write_raw()
373 mutex_unlock(&data->lock); in max44000_write_raw()
377 return -EINVAL; in max44000_write_raw()
384 if (mask == IIO_CHAN_INFO_INT_TIME && chan->type == IIO_LIGHT) in max44000_write_raw_get_fmt()
386 else if (mask == IIO_CHAN_INFO_SCALE && chan->type == IIO_LIGHT) in max44000_write_raw_get_fmt()
491 static irqreturn_t max44000_trigger_handler(int irq, void *p) in max44000_trigger_handler() argument
493 struct iio_poll_func *pf = p; in max44000_trigger_handler()
494 struct iio_dev *indio_dev = pf->indio_dev; in max44000_trigger_handler()
500 mutex_lock(&data->lock); in max44000_trigger_handler()
501 if (test_bit(MAX44000_SCAN_INDEX_ALS, indio_dev->active_scan_mask)) { in max44000_trigger_handler()
505 data->scan.channels[index++] = ret; in max44000_trigger_handler()
507 if (test_bit(MAX44000_SCAN_INDEX_PRX, indio_dev->active_scan_mask)) { in max44000_trigger_handler()
508 ret = regmap_read(data->regmap, MAX44000_REG_PRX_DATA, ®val); in max44000_trigger_handler()
511 data->scan.channels[index] = regval; in max44000_trigger_handler()
513 mutex_unlock(&data->lock); in max44000_trigger_handler()
515 iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, in max44000_trigger_handler()
517 iio_trigger_notify_done(indio_dev->trig); in max44000_trigger_handler()
521 mutex_unlock(&data->lock); in max44000_trigger_handler()
522 iio_trigger_notify_done(indio_dev->trig); in max44000_trigger_handler()
532 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in max44000_probe()
534 return -ENOMEM; in max44000_probe()
536 data->regmap = devm_regmap_init_i2c(client, &max44000_regmap_config); in max44000_probe()
537 if (IS_ERR(data->regmap)) { in max44000_probe()
538 dev_err(&client->dev, "regmap_init failed!\n"); in max44000_probe()
539 return PTR_ERR(data->regmap); in max44000_probe()
542 mutex_init(&data->lock); in max44000_probe()
543 indio_dev->info = &max44000_info; in max44000_probe()
544 indio_dev->name = MAX44000_DRV_NAME; in max44000_probe()
545 indio_dev->channels = max44000_channels; in max44000_probe()
546 indio_dev->num_channels = ARRAY_SIZE(max44000_channels); in max44000_probe()
556 /* Reset ALS scaling bits */ in max44000_probe()
557 ret = regmap_write(data->regmap, MAX44000_REG_CFG_RX, in max44000_probe()
560 dev_err(&client->dev, "failed to write default CFG_RX: %d\n", in max44000_probe()
571 dev_err(&client->dev, "failed to write init config: %d\n", ret); in max44000_probe()
577 ret = regmap_write(data->regmap, MAX44000_REG_CFG_MAIN, reg); in max44000_probe()
579 dev_err(&client->dev, "failed to write init config: %d\n", ret); in max44000_probe()
584 ret = regmap_read(data->regmap, MAX44000_REG_STATUS, ®); in max44000_probe()
586 dev_err(&client->dev, "failed to read init status: %d\n", ret); in max44000_probe()
590 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, in max44000_probe()
593 dev_err(&client->dev, "iio triggered buffer setup failed\n"); in max44000_probe()
597 return devm_iio_device_register(&client->dev, indio_dev); in max44000_probe()