Lines Matching +full:dark +full:- +full:ths
1 // SPDX-License-Identifier: GPL-2.0-only
46 * Registers for tuning the auto dark current cancelling feature.
47 * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling.
48 * when ALS > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark
49 * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark
56 /* Thresholds for events: px low (0x08-l, 0x09-h), px high (0x0a-l 0x0b-h) */
101 * roughly between 12-32 lux
124 /* Dark gain tuning */
202 ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); in us5182d_oneshot_en()
212 return i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret); in us5182d_oneshot_en()
219 if (mode == data->opmode) in us5182d_set_opmode()
222 ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); in us5182d_set_opmode()
233 * register (auto-clearing). in us5182d_set_opmode()
235 ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret); in us5182d_set_opmode()
239 ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_MODE_STORE, in us5182d_set_opmode()
244 data->opmode = mode; in us5182d_set_opmode()
255 if (data->power_mode == US5182D_ONESHOT) { in us5182d_als_enable()
259 data->px_enabled = false; in us5182d_als_enable()
262 if (data->als_enabled) in us5182d_als_enable()
265 mode = data->px_enabled ? US5182D_ALS_PX : US5182D_ALS_ONLY; in us5182d_als_enable()
271 data->als_enabled = true; in us5182d_als_enable()
281 if (data->power_mode == US5182D_ONESHOT) { in us5182d_px_enable()
285 data->als_enabled = false; in us5182d_px_enable()
288 if (data->px_enabled) in us5182d_px_enable()
291 mode = data->als_enabled ? US5182D_ALS_PX : US5182D_PX_ONLY; in us5182d_px_enable()
297 data->px_enabled = true; in us5182d_px_enable()
311 ret = i2c_smbus_read_word_data(data->client, in us5182d_get_als()
316 result = ret * data->ga / US5182D_GA_RESOLUTION; in us5182d_get_als()
331 return i2c_smbus_read_word_data(data->client, in us5182d_get_px()
339 if (data->power_mode == US5182D_ONESHOT) in us5182d_shutdown_en()
342 ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); in us5182d_shutdown_en()
349 ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret); in us5182d_shutdown_en()
354 data->als_enabled = false; in us5182d_shutdown_en()
355 data->px_enabled = false; in us5182d_shutdown_en()
366 if (data->power_mode == US5182D_ONESHOT) in us5182d_set_power_state()
370 ret = pm_runtime_resume_and_get(&data->client->dev); in us5182d_set_power_state()
372 pm_runtime_mark_last_busy(&data->client->dev); in us5182d_set_power_state()
373 ret = pm_runtime_put_autosuspend(&data->client->dev); in us5182d_set_power_state()
384 mutex_lock(&data->lock); in us5182d_read_value()
386 if (data->power_mode == US5182D_ONESHOT) { in us5182d_read_value()
396 if (chan->type == IIO_LIGHT) in us5182d_read_value()
409 mutex_unlock(&data->lock); in us5182d_read_value()
415 mutex_unlock(&data->lock); in us5182d_read_value()
434 ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG1); in us5182d_read_raw()
441 return -EINVAL; in us5182d_read_raw()
446 * us5182d_update_dark_th - update Darh_Th registers
456 __be16 dark_th = cpu_to_be16(data->us5182d_dark_ths[index]); in us5182d_update_dark_th()
459 ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_UDARK_TH, in us5182d_update_dark_th()
464 return i2c_smbus_write_byte_data(data->client, US5182D_REG_UDARK_TH + 1, in us5182d_update_dark_th()
469 * us5182d_apply_scale - update the ALS scale
480 ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG1); in us5182d_apply_scale()
487 ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG1, ret); in us5182d_apply_scale()
504 return -EINVAL; in us5182d_write_raw()
507 mutex_lock(&data->lock); in us5182d_write_raw()
509 mutex_unlock(&data->lock); in us5182d_write_raw()
514 return -EINVAL; in us5182d_write_raw()
517 return -EINVAL; in us5182d_write_raw()
526 return i2c_smbus_write_word_data(data->client, in us5182d_setup_prox()
529 return i2c_smbus_write_word_data(data->client, in us5182d_setup_prox()
544 mutex_lock(&data->lock); in us5182d_read_thresh()
545 *val = data->px_high_th; in us5182d_read_thresh()
546 mutex_unlock(&data->lock); in us5182d_read_thresh()
549 mutex_lock(&data->lock); in us5182d_read_thresh()
550 *val = data->px_low_th; in us5182d_read_thresh()
551 mutex_unlock(&data->lock); in us5182d_read_thresh()
554 return -EINVAL; in us5182d_read_thresh()
569 return -EINVAL; in us5182d_write_thresh()
573 mutex_lock(&data->lock); in us5182d_write_thresh()
574 if (data->rising_en) { in us5182d_write_thresh()
579 data->px_high_th = val; in us5182d_write_thresh()
580 mutex_unlock(&data->lock); in us5182d_write_thresh()
583 mutex_lock(&data->lock); in us5182d_write_thresh()
584 if (data->falling_en) { in us5182d_write_thresh()
589 data->px_low_th = val; in us5182d_write_thresh()
590 mutex_unlock(&data->lock); in us5182d_write_thresh()
593 return -EINVAL; in us5182d_write_thresh()
598 mutex_unlock(&data->lock); in us5182d_write_thresh()
611 mutex_lock(&data->lock); in us5182d_read_event_config()
612 ret = data->rising_en; in us5182d_read_event_config()
613 mutex_unlock(&data->lock); in us5182d_read_event_config()
616 mutex_lock(&data->lock); in us5182d_read_event_config()
617 ret = data->falling_en; in us5182d_read_event_config()
618 mutex_unlock(&data->lock); in us5182d_read_event_config()
621 ret = -EINVAL; in us5182d_read_event_config()
636 mutex_lock(&data->lock); in us5182d_write_event_config()
640 if (data->rising_en == state) { in us5182d_write_event_config()
641 mutex_unlock(&data->lock); in us5182d_write_event_config()
646 data->power_mode = US5182D_CONTINUOUS; in us5182d_write_event_config()
653 new_th = data->px_high_th; in us5182d_write_event_config()
658 data->rising_en = state; in us5182d_write_event_config()
661 if (data->falling_en == state) { in us5182d_write_event_config()
662 mutex_unlock(&data->lock); in us5182d_write_event_config()
667 data->power_mode = US5182D_CONTINUOUS; in us5182d_write_event_config()
674 new_th = data->px_low_th; in us5182d_write_event_config()
679 data->falling_en = state; in us5182d_write_event_config()
682 ret = -EINVAL; in us5182d_write_event_config()
692 if (!data->falling_en && !data->rising_en && !data->default_continuous) in us5182d_write_event_config()
693 data->power_mode = US5182D_ONESHOT; in us5182d_write_event_config()
695 mutex_unlock(&data->lock); in us5182d_write_event_config()
702 mutex_unlock(&data->lock); in us5182d_write_event_config()
720 return i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG3, in us5182d_reset()
733 data->opmode = 0; in us5182d_init()
734 data->power_mode = US5182D_CONTINUOUS; in us5182d_init()
735 data->px_low_th = US5182D_REG_PXL_TH_DEFAULT; in us5182d_init()
736 data->px_high_th = US5182D_REG_PXH_TH_DEFAULT; in us5182d_init()
739 ret = i2c_smbus_write_byte_data(data->client, in us5182d_init()
746 data->als_enabled = true; in us5182d_init()
747 data->px_enabled = true; in us5182d_init()
749 if (!data->default_continuous) { in us5182d_init()
753 data->power_mode = US5182D_ONESHOT; in us5182d_init()
763 if (device_property_read_u32(&data->client->dev, "upisemi,glass-coef", in us5182d_get_platform_data()
764 &data->ga)) in us5182d_get_platform_data()
765 data->ga = US5182D_GA_RESOLUTION; in us5182d_get_platform_data()
766 if (device_property_read_u16_array(&data->client->dev, in us5182d_get_platform_data()
767 "upisemi,dark-ths", in us5182d_get_platform_data()
768 data->us5182d_dark_ths, in us5182d_get_platform_data()
770 data->us5182d_dark_ths = us5182d_dark_ths_vals; in us5182d_get_platform_data()
771 if (device_property_read_u8(&data->client->dev, in us5182d_get_platform_data()
772 "upisemi,upper-dark-gain", in us5182d_get_platform_data()
773 &data->upper_dark_gain)) in us5182d_get_platform_data()
774 data->upper_dark_gain = US5182D_REG_AUTO_HDARK_GAIN_DEFAULT; in us5182d_get_platform_data()
775 if (device_property_read_u8(&data->client->dev, in us5182d_get_platform_data()
776 "upisemi,lower-dark-gain", in us5182d_get_platform_data()
777 &data->lower_dark_gain)) in us5182d_get_platform_data()
778 data->lower_dark_gain = US5182D_REG_AUTO_LDARK_GAIN_DEFAULT; in us5182d_get_platform_data()
779 data->default_continuous = device_property_read_bool(&data->client->dev, in us5182d_get_platform_data()
792 ret = i2c_smbus_write_byte_data(data->client, in us5182d_dark_gain_config()
794 data->lower_dark_gain); in us5182d_dark_gain_config()
798 ret = i2c_smbus_write_byte_data(data->client, in us5182d_dark_gain_config()
800 data->upper_dark_gain); in us5182d_dark_gain_config()
804 return i2c_smbus_write_byte_data(data->client, US5182D_REG_DARK_AUTO_EN, in us5182d_dark_gain_config()
816 ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0); in us5182d_irq_thread_handler()
818 dev_err(&data->client->dev, "i2c transfer error in irq\n"); in us5182d_irq_thread_handler()
827 ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, in us5182d_irq_thread_handler()
830 dev_err(&data->client->dev, "i2c transfer error in irq\n"); in us5182d_irq_thread_handler()
841 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in us5182d_probe()
843 return -ENOMEM; in us5182d_probe()
847 data->client = client; in us5182d_probe()
849 mutex_init(&data->lock); in us5182d_probe()
851 indio_dev->info = &us5182d_info; in us5182d_probe()
852 indio_dev->name = US5182D_DRV_NAME; in us5182d_probe()
853 indio_dev->channels = us5182d_channels; in us5182d_probe()
854 indio_dev->num_channels = ARRAY_SIZE(us5182d_channels); in us5182d_probe()
855 indio_dev->modes = INDIO_DIRECT_MODE; in us5182d_probe()
857 ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CHIPID); in us5182d_probe()
859 dev_err(&data->client->dev, in us5182d_probe()
861 return (ret < 0) ? ret : -ENODEV; in us5182d_probe()
864 if (client->irq > 0) { in us5182d_probe()
865 ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, in us5182d_probe()
868 "us5182d-irq", indio_dev); in us5182d_probe()
872 dev_warn(&client->dev, "no valid irq found\n"); in us5182d_probe()
883 if (data->default_continuous) { in us5182d_probe()
884 ret = pm_runtime_set_active(&client->dev); in us5182d_probe()
889 pm_runtime_enable(&client->dev); in us5182d_probe()
890 pm_runtime_set_autosuspend_delay(&client->dev, in us5182d_probe()
892 pm_runtime_use_autosuspend(&client->dev); in us5182d_probe()
913 pm_runtime_disable(&client->dev); in us5182d_remove()
914 pm_runtime_set_suspended(&client->dev); in us5182d_remove()
918 dev_warn(&client->dev, "Failed to shut down (%pe)\n", in us5182d_remove()
927 if (data->power_mode == US5182D_CONTINUOUS) in us5182d_suspend()
938 if (data->power_mode == US5182D_CONTINUOUS) in us5182d_resume()