1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Device driver for monitoring ambient light intensity (lux) 4*4882a593Smuzhiyun * and proximity (prox) within the TAOS TSL2772 family of devices. 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * Copyright (c) 2012, TAOS Corporation. 7*4882a593Smuzhiyun * Copyright (c) 2017-2018 Brian Masney <masneyb@onstation.org> 8*4882a593Smuzhiyun */ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #ifndef __TSL2772_H 11*4882a593Smuzhiyun #define __TSL2772_H 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun struct tsl2772_lux { 14*4882a593Smuzhiyun unsigned int ch0; 15*4882a593Smuzhiyun unsigned int ch1; 16*4882a593Smuzhiyun }; 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun /* Max number of segments allowable in LUX table */ 19*4882a593Smuzhiyun #define TSL2772_MAX_LUX_TABLE_SIZE 6 20*4882a593Smuzhiyun /* The default LUX tables all have 3 elements. */ 21*4882a593Smuzhiyun #define TSL2772_DEF_LUX_TABLE_SZ 3 22*4882a593Smuzhiyun #define TSL2772_DEFAULT_TABLE_BYTES (sizeof(struct tsl2772_lux) * \ 23*4882a593Smuzhiyun TSL2772_DEF_LUX_TABLE_SZ) 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun /* Proximity diode to use */ 26*4882a593Smuzhiyun #define TSL2772_DIODE0 0x01 27*4882a593Smuzhiyun #define TSL2772_DIODE1 0x02 28*4882a593Smuzhiyun #define TSL2772_DIODE_BOTH 0x03 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /* LED Power */ 31*4882a593Smuzhiyun #define TSL2772_100_mA 0x00 32*4882a593Smuzhiyun #define TSL2772_50_mA 0x01 33*4882a593Smuzhiyun #define TSL2772_25_mA 0x02 34*4882a593Smuzhiyun #define TSL2772_13_mA 0x03 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun /** 37*4882a593Smuzhiyun * struct tsl2772_settings - Settings for the tsl2772 driver 38*4882a593Smuzhiyun * @als_time: Integration time of the ALS channel ADCs in 2.73 ms 39*4882a593Smuzhiyun * increments. Total integration time is 40*4882a593Smuzhiyun * (256 - als_time) * 2.73. 41*4882a593Smuzhiyun * @als_gain: Index into the tsl2772_als_gain array. 42*4882a593Smuzhiyun * @als_gain_trim: Default gain trim to account for aperture effects. 43*4882a593Smuzhiyun * @wait_time: Time between proximity and ALS cycles in 2.73 44*4882a593Smuzhiyun * periods. 45*4882a593Smuzhiyun * @prox_time: Integration time of the proximity ADC in 2.73 ms 46*4882a593Smuzhiyun * increments. Total integration time is 47*4882a593Smuzhiyun * (256 - prx_time) * 2.73. 48*4882a593Smuzhiyun * @prox_gain: Index into the tsl2772_prx_gain array. 49*4882a593Smuzhiyun * @als_prox_config: The value of the ALS / Proximity configuration 50*4882a593Smuzhiyun * register. 51*4882a593Smuzhiyun * @als_cal_target: Known external ALS reading for calibration. 52*4882a593Smuzhiyun * @als_persistence: H/W Filters, Number of 'out of limits' ALS readings. 53*4882a593Smuzhiyun * @als_interrupt_en: Enable/Disable ALS interrupts 54*4882a593Smuzhiyun * @als_thresh_low: CH0 'low' count to trigger interrupt. 55*4882a593Smuzhiyun * @als_thresh_high: CH0 'high' count to trigger interrupt. 56*4882a593Smuzhiyun * @prox_persistence: H/W Filters, Number of 'out of limits' proximity 57*4882a593Smuzhiyun * readings. 58*4882a593Smuzhiyun * @prox_interrupt_en: Enable/Disable proximity interrupts. 59*4882a593Smuzhiyun * @prox_thres_low: Low threshold proximity detection. 60*4882a593Smuzhiyun * @prox_thres_high: High threshold proximity detection. 61*4882a593Smuzhiyun * @prox_pulse_count: Number if proximity emitter pulses. 62*4882a593Smuzhiyun * @prox_max_samples_cal: The number of samples that are taken when performing 63*4882a593Smuzhiyun * a proximity calibration. 64*4882a593Smuzhiyun * @prox_diode Which diode(s) to use for driving the external 65*4882a593Smuzhiyun * LED(s) for proximity sensing. 66*4882a593Smuzhiyun * @prox_power The amount of power to use for the external LED(s). 67*4882a593Smuzhiyun */ 68*4882a593Smuzhiyun struct tsl2772_settings { 69*4882a593Smuzhiyun int als_time; 70*4882a593Smuzhiyun int als_gain; 71*4882a593Smuzhiyun int als_gain_trim; 72*4882a593Smuzhiyun int wait_time; 73*4882a593Smuzhiyun int prox_time; 74*4882a593Smuzhiyun int prox_gain; 75*4882a593Smuzhiyun int als_prox_config; 76*4882a593Smuzhiyun int als_cal_target; 77*4882a593Smuzhiyun u8 als_persistence; 78*4882a593Smuzhiyun bool als_interrupt_en; 79*4882a593Smuzhiyun int als_thresh_low; 80*4882a593Smuzhiyun int als_thresh_high; 81*4882a593Smuzhiyun u8 prox_persistence; 82*4882a593Smuzhiyun bool prox_interrupt_en; 83*4882a593Smuzhiyun int prox_thres_low; 84*4882a593Smuzhiyun int prox_thres_high; 85*4882a593Smuzhiyun int prox_pulse_count; 86*4882a593Smuzhiyun int prox_max_samples_cal; 87*4882a593Smuzhiyun int prox_diode; 88*4882a593Smuzhiyun int prox_power; 89*4882a593Smuzhiyun }; 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun /** 92*4882a593Smuzhiyun * struct tsl2772_platform_data - Platform callback, glass and defaults 93*4882a593Smuzhiyun * @platform_lux_table: Device specific glass coefficents 94*4882a593Smuzhiyun * @platform_default_settings: Device specific power on defaults 95*4882a593Smuzhiyun */ 96*4882a593Smuzhiyun struct tsl2772_platform_data { 97*4882a593Smuzhiyun struct tsl2772_lux platform_lux_table[TSL2772_MAX_LUX_TABLE_SIZE]; 98*4882a593Smuzhiyun struct tsl2772_settings *platform_default_settings; 99*4882a593Smuzhiyun }; 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun #endif /* __TSL2772_H */ 102