Lines Matching +full:led +full:- +full:current +full:- +full:microamp

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max30102.c - Support for MAX30102 heart rate and pulse oximeter sensor
8 * Copyright (C) 2017 Peter Meerwald-Stadler <pmeerw@pmeerw.net>
10 * 7-bit I2C chip address: 0x57
71 #define MAX30102_REG_MODE_CONFIG_MODE_HR 0x02 /* red LED */
72 #define MAX30102_REG_MODE_CONFIG_MODE_HR_SPO2 0x03 /* red + IR LED */
73 #define MAX30102_REG_MODE_CONFIG_MODE_MULTI 0x07 /* multi-LED mode */
77 #define MAX30102_REG_MODE_CONTROL_SLOT21 0x11 /* multi-LED control */
111 __be32 processed_buffer[3]; /* 3 x 18-bit (padded to 32-bits) */
154 .scan_index = -1,
166 .scan_index = -1,
172 return regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG, in max30102_set_power()
184 return regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG, in max30102_set_powermode()
198 switch (*indio_dev->active_scan_mask) { in max30102_buffer_postenable()
204 ret = regmap_update_bits(data->regmap, in max30102_buffer_postenable()
211 ret = regmap_update_bits(data->regmap, in max30102_buffer_postenable()
221 return -EINVAL; in max30102_buffer_postenable()
245 ret = regmap_read(data->regmap, MAX30102_REG_INT_STATUS, &val); in max30102_fifo_count()
257 memcpy(&data->processed_buffer[(i)], \
265 u8 *buffer = (u8 *) &data->buffer; in max30102_read_measurement()
267 ret = i2c_smbus_read_i2c_block_data(data->client, in max30102_read_measurement()
284 return -EINVAL; in max30102_read_measurement()
288 0 : -EINVAL; in max30102_read_measurement()
295 unsigned int measurements = bitmap_weight(indio_dev->active_scan_mask, in max30102_interrupt_handler()
299 mutex_lock(&data->lock); in max30102_interrupt_handler()
306 iio_push_to_buffers(data->indio_dev, data->processed_buffer); in max30102_interrupt_handler()
307 cnt--; in max30102_interrupt_handler()
310 mutex_unlock(&data->lock); in max30102_interrupt_handler()
320 return *reg > 0xff ? -EINVAL : 0; in max30102_get_current_idx()
325 struct device *dev = &data->client->dev; in max30102_led_init()
329 ret = device_property_read_u32(dev, "maxim,red-led-current-microamp", &val); in max30102_led_init()
331 dev_info(dev, "no red-led-current-microamp set\n"); in max30102_led_init()
333 /* Default to 7 mA RED LED */ in max30102_led_init()
339 dev_err(dev, "invalid RED LED current setting %d\n", val); in max30102_led_init()
343 ret = regmap_write(data->regmap, MAX30102_REG_RED_LED_CONFIG, reg); in max30102_led_init()
347 if (data->chip_id == max30105) { in max30102_led_init()
349 "maxim,green-led-current-microamp", &val); in max30102_led_init()
351 dev_info(dev, "no green-led-current-microamp set\n"); in max30102_led_init()
353 /* Default to 7 mA green LED */ in max30102_led_init()
359 dev_err(dev, "invalid green LED current setting %d\n", in max30102_led_init()
364 ret = regmap_write(data->regmap, MAX30105_REG_GREEN_LED_CONFIG, in max30102_led_init()
370 ret = device_property_read_u32(dev, "maxim,ir-led-current-microamp", &val); in max30102_led_init()
372 dev_info(dev, "no ir-led-current-microamp set\n"); in max30102_led_init()
374 /* Default to 7 mA IR LED */ in max30102_led_init()
380 dev_err(dev, "invalid IR LED current setting %d\n", val); in max30102_led_init()
384 return regmap_write(data->regmap, MAX30102_REG_IR_LED_CONFIG, reg); in max30102_led_init()
391 /* setup LED current settings */ in max30102_chip_init()
396 /* configure 18-bit HR + SpO2 readings at 400Hz */ in max30102_chip_init()
397 ret = regmap_write(data->regmap, MAX30102_REG_SPO2_CONFIG, in max30102_chip_init()
407 ret = regmap_write(data->regmap, MAX30102_REG_FIFO_CONFIG, in max30102_chip_init()
415 return regmap_update_bits(data->regmap, MAX30102_REG_INT_ENABLE, in max30102_chip_init()
425 ret = regmap_read(data->regmap, MAX30102_REG_TEMP_INTEGER, &reg); in max30102_read_temp()
430 ret = regmap_read(data->regmap, MAX30102_REG_TEMP_FRACTION, &reg); in max30102_read_temp()
451 ret = regmap_set_bits(data->regmap, MAX30102_REG_TEMP_CONFIG, in max30102_get_temp()
471 int ret = -EINVAL; in max30102_read_raw()
523 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in max30102_probe()
525 return -ENOMEM; in max30102_probe()
527 indio_dev->name = MAX30102_DRV_NAME; in max30102_probe()
528 indio_dev->info = &max30102_info; in max30102_probe()
529 indio_dev->modes = INDIO_DIRECT_MODE; in max30102_probe()
532 data->indio_dev = indio_dev; in max30102_probe()
533 data->client = client; in max30102_probe()
534 data->chip_id = id->driver_data; in max30102_probe()
536 mutex_init(&data->lock); in max30102_probe()
539 switch (data->chip_id) { in max30102_probe()
541 indio_dev->channels = max30105_channels; in max30102_probe()
542 indio_dev->num_channels = ARRAY_SIZE(max30105_channels); in max30102_probe()
543 indio_dev->available_scan_masks = max30105_scan_masks; in max30102_probe()
546 indio_dev->channels = max30102_channels; in max30102_probe()
547 indio_dev->num_channels = ARRAY_SIZE(max30102_channels); in max30102_probe()
548 indio_dev->available_scan_masks = max30102_scan_masks; in max30102_probe()
551 return -ENODEV; in max30102_probe()
554 ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev, in max30102_probe()
559 data->regmap = devm_regmap_init_i2c(client, &max30102_regmap_config); in max30102_probe()
560 if (IS_ERR(data->regmap)) { in max30102_probe()
561 dev_err(&client->dev, "regmap initialization failed\n"); in max30102_probe()
562 return PTR_ERR(data->regmap); in max30102_probe()
566 ret = regmap_read(data->regmap, MAX30102_REG_PART_ID, &reg); in max30102_probe()
570 return -ENODEV; in max30102_probe()
573 ret = regmap_read(data->regmap, MAX30102_REG_REV_ID, &reg); in max30102_probe()
576 dev_dbg(&client->dev, "max3010x revision %02x\n", reg); in max30102_probe()
588 if (client->irq <= 0) { in max30102_probe()
589 dev_err(&client->dev, "no valid irq defined\n"); in max30102_probe()
590 return -EINVAL; in max30102_probe()
593 ret = devm_request_threaded_irq(&client->dev, client->irq, in max30102_probe()
598 dev_err(&client->dev, "request irq (%d) failed\n", client->irq); in max30102_probe()