Lines Matching +full:lo +full:- +full:x2 +full:- +full:en
1 // SPDX-License-Identifier: GPL-2.0
3 * max44009.c - Support for MAX44009 Ambient Light Sensor
7 * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf
31 #define MAX44009_REG_CFG 0x2
51 /* The max44009 always scales raw readings by 0.045 and is non-configurable */
55 /* The fixed-point fractional multiplier for de-scaling threshold values */
112 int ret = i2c_smbus_read_byte_data(data->client, MAX44009_REG_CFG); in max44009_read_int_time()
123 struct i2c_client *client = data->client; in max44009_write_int_time()
156 if (mask == IIO_CHAN_INFO_INT_TIME && chan->type == IIO_LIGHT) { in max44009_write_raw()
157 mutex_lock(&data->lock); in max44009_write_raw()
159 mutex_unlock(&data->lock); in max44009_write_raw()
162 return -EINVAL; in max44009_write_raw()
172 static int max44009_lux_raw(u8 hi, u8 lo) in max44009_lux_raw() argument
181 mantissa = ((hi & 0xf) << 4) | (lo & 0xf); in max44009_lux_raw()
201 u8 lo = 0; in max44009_read_lux_raw() local
206 .addr = data->client->addr, in max44009_read_lux_raw()
212 .addr = data->client->addr, in max44009_read_lux_raw()
218 .addr = data->client->addr, in max44009_read_lux_raw()
224 .addr = data->client->addr, in max44009_read_lux_raw()
226 .len = sizeof(lo), in max44009_read_lux_raw()
227 .buf = &lo, in max44009_read_lux_raw()
237 ret = i2c_transfer(data->client->adapter, in max44009_read_lux_raw()
241 return -EIO; in max44009_read_lux_raw()
243 return max44009_lux_raw(hi, lo); in max44009_read_lux_raw()
256 switch (chan->type) { in max44009_read_raw()
267 return -EINVAL; in max44009_read_raw()
270 switch (chan->type) { in max44009_read_raw()
280 return -EINVAL; in max44009_read_raw()
283 return -EINVAL; in max44009_read_raw()
306 return -EINVAL; in max44009_threshold_byte_from_fraction()
308 /* Reverse scaling of fixed-point integral */ in max44009_threshold_byte_from_fraction()
312 /* Reverse scaling of fixed-point fractional */ in max44009_threshold_byte_from_fraction()
334 return -EINVAL; in max44009_get_thr_reg()
348 if (info != IIO_EV_INFO_VALUE || chan->type != IIO_LIGHT) in max44009_write_event_value()
349 return -EINVAL; in max44009_write_event_value()
359 return i2c_smbus_write_byte_data(data->client, reg, threshold); in max44009_write_event_value()
373 byte = i2c_smbus_read_byte_data(data->client, reg); in max44009_read_threshold()
407 if (chan->type != IIO_LIGHT || type != IIO_EV_TYPE_THRESH) in max44009_read_event_value()
408 return -EINVAL; in max44009_read_event_value()
430 if (chan->type != IIO_LIGHT || type != IIO_EV_TYPE_THRESH) in max44009_write_event_config()
431 return -EINVAL; in max44009_write_event_config()
433 ret = i2c_smbus_write_byte_data(data->client, in max44009_write_event_config()
442 return i2c_smbus_write_byte_data(data->client, in max44009_write_event_config()
453 if (chan->type != IIO_LIGHT || type != IIO_EV_TYPE_THRESH) in max44009_read_event_config()
454 return -EINVAL; in max44009_read_event_config()
456 return i2c_smbus_read_byte_data(data->client, MAX44009_REG_INT_EN); in max44009_read_event_config()
476 ret = i2c_smbus_read_byte_data(data->client, MAX44009_REG_INT_STATUS); in max44009_threaded_irq_handler()
497 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in max44009_probe()
499 return -ENOMEM; in max44009_probe()
503 data->client = client; in max44009_probe()
504 indio_dev->info = &max44009_info; in max44009_probe()
505 indio_dev->modes = INDIO_DIRECT_MODE; in max44009_probe()
506 indio_dev->name = MAX44009_DRV_NAME; in max44009_probe()
507 indio_dev->channels = max44009_channels; in max44009_probe()
508 indio_dev->num_channels = ARRAY_SIZE(max44009_channels); in max44009_probe()
509 mutex_init(&data->lock); in max44009_probe()
516 if (client->irq > 0) { in max44009_probe()
517 ret = devm_request_threaded_irq(&client->dev, client->irq, in max44009_probe()
528 return devm_iio_device_register(&client->dev, indio_dev); in max44009_probe()