• Home
  • Raw
  • Download

Lines Matching +full:ch0 +full:- +full:2

2  * apds9300.c - IIO driver for Avago APDS9300 ambient light sensor
6 * This file is subject to the terms and conditions of version 2 of
60 /* Calculated values 1000 * (CH1/CH0)^1.4 for CH1/CH0 from 0 to 0.52 */
62 0, 2, 4, 7, 11, 15, 19, 24, 29, 34, 40, 45, 51, 57, 64, 70, 77, 84, 91,
68 static unsigned long apds9300_calculate_lux(u16 ch0, u16 ch1) in apds9300_calculate_lux() argument
73 if (ch0 == 0) in apds9300_calculate_lux()
76 tmp = DIV_ROUND_UP(ch1 * 100, ch0); in apds9300_calculate_lux()
78 lux = 3150 * ch0 - (unsigned long)DIV_ROUND_UP_ULL(ch0 in apds9300_calculate_lux()
81 lux = 2290 * ch0 - 2910 * ch1; in apds9300_calculate_lux()
83 lux = 1570 * ch0 - 1800 * ch1; in apds9300_calculate_lux()
85 lux = 338 * ch0 - 260 * ch1; in apds9300_calculate_lux()
98 if (!data->power_state) in apds9300_get_adc_val()
99 return -EBUSY; in apds9300_get_adc_val()
104 ret = i2c_smbus_read_word_data(data->client, flags); in apds9300_get_adc_val()
106 dev_err(&data->client->dev, in apds9300_get_adc_val()
116 if (!data->power_state) in apds9300_set_thresh_low()
117 return -EBUSY; in apds9300_set_thresh_low()
120 return -EINVAL; in apds9300_set_thresh_low()
122 ret = i2c_smbus_write_word_data(data->client, APDS9300_THRESHLOWLOW in apds9300_set_thresh_low()
125 dev_err(&data->client->dev, "failed to set thresh_low\n"); in apds9300_set_thresh_low()
128 data->thresh_low = value; in apds9300_set_thresh_low()
137 if (!data->power_state) in apds9300_set_thresh_hi()
138 return -EBUSY; in apds9300_set_thresh_hi()
141 return -EINVAL; in apds9300_set_thresh_hi()
143 ret = i2c_smbus_write_word_data(data->client, APDS9300_THRESHHIGHLOW in apds9300_set_thresh_hi()
146 dev_err(&data->client->dev, "failed to set thresh_hi\n"); in apds9300_set_thresh_hi()
149 data->thresh_hi = value; in apds9300_set_thresh_hi()
159 if (!data->power_state) in apds9300_set_intr_state()
160 return -EBUSY; in apds9300_set_intr_state()
163 ret = i2c_smbus_write_byte_data(data->client, in apds9300_set_intr_state()
166 dev_err(&data->client->dev, in apds9300_set_intr_state()
170 data->intr_en = state; in apds9300_set_intr_state()
181 ret = i2c_smbus_write_byte_data(data->client, in apds9300_set_power_state()
184 dev_err(&data->client->dev, in apds9300_set_power_state()
188 data->power_state = state; in apds9300_set_power_state()
197 ret = i2c_smbus_write_byte(data->client, APDS9300_CLEAR | APDS9300_CMD); in apds9300_clear_intr()
199 dev_err(&data->client->dev, "failed to clear interrupt\n"); in apds9300_clear_intr()
217 ret = i2c_smbus_read_byte_data(data->client, in apds9300_chip_init()
220 ret = -ENODEV; in apds9300_chip_init()
234 dev_err(&data->client->dev, "failed to init the chip\n"); in apds9300_chip_init()
242 int ch0, ch1, ret = -EINVAL; in apds9300_read_raw() local
245 mutex_lock(&data->mutex); in apds9300_read_raw()
246 switch (chan->type) { in apds9300_read_raw()
248 ch0 = apds9300_get_adc_val(data, 0); in apds9300_read_raw()
249 if (ch0 < 0) { in apds9300_read_raw()
250 ret = ch0; in apds9300_read_raw()
258 *val = apds9300_calculate_lux(ch0, ch1); in apds9300_read_raw()
262 ret = apds9300_get_adc_val(data, chan->channel); in apds9300_read_raw()
271 mutex_unlock(&data->mutex); in apds9300_read_raw()
285 *val = data->thresh_hi; in apds9300_read_thresh()
288 *val = data->thresh_low; in apds9300_read_thresh()
291 return -EINVAL; in apds9300_read_thresh()
305 mutex_lock(&data->mutex); in apds9300_write_thresh()
310 mutex_unlock(&data->mutex); in apds9300_write_thresh()
322 return data->intr_en; in apds9300_read_interrupt_config()
332 mutex_lock(&data->mutex); in apds9300_write_interrupt_config()
334 mutex_unlock(&data->mutex); in apds9300_write_interrupt_config()
411 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in apds9300_probe()
413 return -ENOMEM; in apds9300_probe()
417 data->client = client; in apds9300_probe()
423 mutex_init(&data->mutex); in apds9300_probe()
425 indio_dev->dev.parent = &client->dev; in apds9300_probe()
426 indio_dev->channels = apds9300_channels; in apds9300_probe()
427 indio_dev->num_channels = ARRAY_SIZE(apds9300_channels); in apds9300_probe()
428 indio_dev->name = APDS9300_DRV_NAME; in apds9300_probe()
429 indio_dev->modes = INDIO_DIRECT_MODE; in apds9300_probe()
431 if (client->irq) in apds9300_probe()
432 indio_dev->info = &apds9300_info; in apds9300_probe()
434 indio_dev->info = &apds9300_info_no_irq; in apds9300_probe()
436 if (client->irq) { in apds9300_probe()
437 ret = devm_request_threaded_irq(&client->dev, client->irq, in apds9300_probe()
442 dev_err(&client->dev, "irq request error %d\n", -ret); in apds9300_probe()
480 mutex_lock(&data->mutex); in apds9300_suspend()
482 mutex_unlock(&data->mutex); in apds9300_suspend()
493 mutex_lock(&data->mutex); in apds9300_resume()
495 mutex_unlock(&data->mutex); in apds9300_resume()