Lines Matching full:chip

4  * Chip is combined proximity and ambient light sensor.
132 u32 lux_cf; /* Chip specific factor */
163 * Supported stand alone rates in ms from chip data sheet
170 * Supported stand alone rates in ms from chip data sheet
176 * interrupt control functions are called while keeping chip->mutex
179 static inline int bh1770_lux_interrupt_control(struct bh1770_chip *chip, in bh1770_lux_interrupt_control() argument
182 chip->int_mode_lux = lux; in bh1770_lux_interrupt_control()
184 return i2c_smbus_write_byte_data(chip->client, in bh1770_lux_interrupt_control()
186 (lux << 1) | chip->int_mode_prox); in bh1770_lux_interrupt_control()
189 static inline int bh1770_prox_interrupt_control(struct bh1770_chip *chip, in bh1770_prox_interrupt_control() argument
192 chip->int_mode_prox = ps; in bh1770_prox_interrupt_control()
193 return i2c_smbus_write_byte_data(chip->client, in bh1770_prox_interrupt_control()
195 (chip->int_mode_lux << 1) | (ps << 0)); in bh1770_prox_interrupt_control()
198 /* chip->mutex is always kept here */
199 static int bh1770_lux_rate(struct bh1770_chip *chip, int rate_index) in bh1770_lux_rate() argument
201 /* sysfs may call this when the chip is powered off */ in bh1770_lux_rate()
202 if (pm_runtime_suspended(&chip->client->dev)) in bh1770_lux_rate()
206 if (chip->prox_enable_count) in bh1770_lux_rate()
209 return i2c_smbus_write_byte_data(chip->client, in bh1770_lux_rate()
214 static int bh1770_prox_rate(struct bh1770_chip *chip, int mode) in bh1770_prox_rate() argument
219 chip->prox_rate_threshold : chip->prox_rate; in bh1770_prox_rate()
221 return i2c_smbus_write_byte_data(chip->client, in bh1770_prox_rate()
226 /* InfraredLED is controlled by the chip during proximity scanning */
227 static inline int bh1770_led_cfg(struct bh1770_chip *chip) in bh1770_led_cfg() argument
230 return i2c_smbus_write_byte_data(chip->client, in bh1770_led_cfg()
234 chip->prox_led); in bh1770_led_cfg()
243 static inline u8 bh1770_psraw_to_adjusted(struct bh1770_chip *chip, u8 psraw) in bh1770_psraw_to_adjusted() argument
246 adjusted = (u16)(((u32)(psraw + chip->prox_const) * chip->prox_coef) / in bh1770_psraw_to_adjusted()
253 static inline u8 bh1770_psadjusted_to_raw(struct bh1770_chip *chip, u8 ps) in bh1770_psadjusted_to_raw() argument
257 raw = (((u32)ps * BH1770_COEF_SCALER) / chip->prox_coef); in bh1770_psadjusted_to_raw()
258 if (raw > chip->prox_const) in bh1770_psadjusted_to_raw()
259 raw = raw - chip->prox_const; in bh1770_psadjusted_to_raw()
269 * versions. Chip->mutex is kept when this is called.
271 static int bh1770_prox_set_threshold(struct bh1770_chip *chip) in bh1770_prox_set_threshold() argument
275 /* sysfs may call this when the chip is powered off */ in bh1770_prox_set_threshold()
276 if (pm_runtime_suspended(&chip->client->dev)) in bh1770_prox_set_threshold()
279 tmp = bh1770_psadjusted_to_raw(chip, chip->prox_threshold); in bh1770_prox_set_threshold()
280 chip->prox_threshold_hw = tmp; in bh1770_prox_set_threshold()
282 return i2c_smbus_write_byte_data(chip->client, BH1770_PS_TH_LED1, in bh1770_prox_set_threshold()
286 static inline u16 bh1770_lux_raw_to_adjusted(struct bh1770_chip *chip, u16 raw) in bh1770_lux_raw_to_adjusted() argument
289 lux = ((u32)raw * chip->lux_corr) / BH1770_LUX_CORR_SCALE; in bh1770_lux_raw_to_adjusted()
293 static inline u16 bh1770_lux_adjusted_to_raw(struct bh1770_chip *chip, in bh1770_lux_adjusted_to_raw() argument
296 return (u32)adjusted * BH1770_LUX_CORR_SCALE / chip->lux_corr; in bh1770_lux_adjusted_to_raw()
299 /* chip->mutex is kept when this is called */
300 static int bh1770_lux_update_thresholds(struct bh1770_chip *chip, in bh1770_lux_update_thresholds() argument
306 /* sysfs may call this when the chip is powered off */ in bh1770_lux_update_thresholds()
307 if (pm_runtime_suspended(&chip->client->dev)) in bh1770_lux_update_thresholds()
316 threshold_hi = bh1770_lux_adjusted_to_raw(chip, threshold_hi); in bh1770_lux_update_thresholds()
319 threshold_lo = bh1770_lux_adjusted_to_raw(chip, threshold_lo); in bh1770_lux_update_thresholds()
321 if (chip->lux_thres_hi_onchip == threshold_hi && in bh1770_lux_update_thresholds()
322 chip->lux_thres_lo_onchip == threshold_lo) in bh1770_lux_update_thresholds()
325 chip->lux_thres_hi_onchip = threshold_hi; in bh1770_lux_update_thresholds()
326 chip->lux_thres_lo_onchip = threshold_lo; in bh1770_lux_update_thresholds()
333 ret = i2c_smbus_write_i2c_block_data(chip->client, in bh1770_lux_update_thresholds()
340 static int bh1770_lux_get_result(struct bh1770_chip *chip) in bh1770_lux_get_result() argument
345 ret = i2c_smbus_read_byte_data(chip->client, BH1770_ALS_DATA_0); in bh1770_lux_get_result()
350 ret = i2c_smbus_read_byte_data(chip->client, BH1770_ALS_DATA_1); in bh1770_lux_get_result()
354 chip->lux_data_raw = data | ((ret & 0xff) << 8); in bh1770_lux_get_result()
359 /* Calculate correction value which contains chip and device specific parts */
360 static u32 bh1770_get_corr_value(struct bh1770_chip *chip) in bh1770_get_corr_value() argument
364 tmp = (BH1770_LUX_CORR_SCALE * chip->lux_ga) / BH1770_LUX_GA_SCALE; in bh1770_get_corr_value()
365 /* Impact of chip factor correction */ in bh1770_get_corr_value()
366 tmp = (tmp * chip->lux_cf) / BH1770_LUX_CF_SCALE; in bh1770_get_corr_value()
368 tmp = (tmp * chip->lux_calib) / BH1770_CALIB_SCALER; in bh1770_get_corr_value()
372 static int bh1770_lux_read_result(struct bh1770_chip *chip) in bh1770_lux_read_result() argument
374 bh1770_lux_get_result(chip); in bh1770_lux_read_result()
375 return bh1770_lux_raw_to_adjusted(chip, chip->lux_data_raw); in bh1770_lux_read_result()
379 * Chip on / off functions are called while keeping mutex except probe
382 static int bh1770_chip_on(struct bh1770_chip *chip) in bh1770_chip_on() argument
384 int ret = regulator_bulk_enable(ARRAY_SIZE(chip->regs), in bh1770_chip_on()
385 chip->regs); in bh1770_chip_on()
391 /* Reset the chip */ in bh1770_chip_on()
392 i2c_smbus_write_byte_data(chip->client, BH1770_ALS_CONTROL, in bh1770_chip_on()
401 chip->lux_data_raw = 0; in bh1770_chip_on()
402 chip->prox_data = 0; in bh1770_chip_on()
403 ret = i2c_smbus_write_byte_data(chip->client, in bh1770_chip_on()
407 chip->lux_thres_hi_onchip = BH1770_LUX_RANGE; in bh1770_chip_on()
408 chip->lux_thres_lo_onchip = 0; in bh1770_chip_on()
413 static void bh1770_chip_off(struct bh1770_chip *chip) in bh1770_chip_off() argument
415 i2c_smbus_write_byte_data(chip->client, in bh1770_chip_off()
417 i2c_smbus_write_byte_data(chip->client, in bh1770_chip_off()
419 i2c_smbus_write_byte_data(chip->client, in bh1770_chip_off()
421 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); in bh1770_chip_off()
424 /* chip->mutex is kept when this is called */
425 static int bh1770_prox_mode_control(struct bh1770_chip *chip) in bh1770_prox_mode_control() argument
427 if (chip->prox_enable_count) { in bh1770_prox_mode_control()
428 chip->prox_force_update = true; /* Force immediate update */ in bh1770_prox_mode_control()
430 bh1770_lux_rate(chip, chip->lux_rate_index); in bh1770_prox_mode_control()
431 bh1770_prox_set_threshold(chip); in bh1770_prox_mode_control()
432 bh1770_led_cfg(chip); in bh1770_prox_mode_control()
433 bh1770_prox_rate(chip, PROX_BELOW_THRESHOLD); in bh1770_prox_mode_control()
434 bh1770_prox_interrupt_control(chip, BH1770_ENABLE); in bh1770_prox_mode_control()
435 i2c_smbus_write_byte_data(chip->client, in bh1770_prox_mode_control()
438 chip->prox_data = 0; in bh1770_prox_mode_control()
439 bh1770_lux_rate(chip, chip->lux_rate_index); in bh1770_prox_mode_control()
440 bh1770_prox_interrupt_control(chip, BH1770_DISABLE); in bh1770_prox_mode_control()
441 i2c_smbus_write_byte_data(chip->client, in bh1770_prox_mode_control()
447 /* chip->mutex is kept when this is called */
448 static int bh1770_prox_read_result(struct bh1770_chip *chip) in bh1770_prox_read_result() argument
454 ret = i2c_smbus_read_byte_data(chip->client, BH1770_PS_DATA_LED1); in bh1770_prox_read_result()
458 if (ret > chip->prox_threshold_hw) in bh1770_prox_read_result()
468 if (chip->lux_data_raw > PROX_IGNORE_LUX_LIMIT) in bh1770_prox_read_result()
471 chip->prox_data = bh1770_psraw_to_adjusted(chip, ret); in bh1770_prox_read_result()
474 if (chip->prox_data >= chip->prox_abs_thres || in bh1770_prox_read_result()
475 chip->prox_force_update) in bh1770_prox_read_result()
476 chip->prox_persistence_counter = chip->prox_persistence; in bh1770_prox_read_result()
478 chip->prox_force_update = false; in bh1770_prox_read_result()
482 if (chip->prox_persistence_counter < chip->prox_persistence) { in bh1770_prox_read_result()
483 chip->prox_persistence_counter++; in bh1770_prox_read_result()
490 chip->prox_persistence_counter = 0; in bh1770_prox_read_result()
492 chip->prox_data = 0; in bh1770_prox_read_result()
498 bh1770_prox_rate(chip, mode); in bh1770_prox_read_result()
499 sysfs_notify(&chip->client->dev.kobj, NULL, "prox0_raw"); in bh1770_prox_read_result()
505 static int bh1770_detect(struct bh1770_chip *chip) in bh1770_detect() argument
507 struct i2c_client *client = chip->client; in bh1770_detect()
521 chip->revision = (part & BH1770_REV_MASK) >> BH1770_REV_SHIFT; in bh1770_detect()
522 chip->prox_coef = BH1770_COEF_SCALER; in bh1770_detect()
523 chip->prox_const = 0; in bh1770_detect()
524 chip->lux_cf = BH1770_NEUTRAL_CF; in bh1770_detect()
528 snprintf(chip->chipname, sizeof(chip->chipname), "BH1770GLC"); in bh1770_detect()
534 snprintf(chip->chipname, sizeof(chip->chipname), "SFH7770"); in bh1770_detect()
536 chip->prox_coef = 819; /* 0.8 * BH1770_COEF_SCALER */ in bh1770_detect()
537 chip->prox_const = 40; in bh1770_detect()
559 struct bh1770_chip *chip = in bh1770_prox_work() local
562 mutex_lock(&chip->mutex); in bh1770_prox_work()
563 bh1770_prox_read_result(chip); in bh1770_prox_work()
564 mutex_unlock(&chip->mutex); in bh1770_prox_work()
570 struct bh1770_chip *chip = data; in bh1770_irq() local
574 mutex_lock(&chip->mutex); in bh1770_irq()
575 status = i2c_smbus_read_byte_data(chip->client, BH1770_ALS_PS_STATUS); in bh1770_irq()
578 i2c_smbus_read_byte_data(chip->client, BH1770_INTERRUPT); in bh1770_irq()
585 bh1770_lux_get_result(chip); in bh1770_irq()
586 if (unlikely(chip->lux_wait_result)) { in bh1770_irq()
587 chip->lux_wait_result = false; in bh1770_irq()
588 wake_up(&chip->wait); in bh1770_irq()
589 bh1770_lux_update_thresholds(chip, in bh1770_irq()
590 chip->lux_threshold_hi, in bh1770_irq()
591 chip->lux_threshold_lo); in bh1770_irq()
596 i2c_smbus_write_byte_data(chip->client, BH1770_INTERRUPT, in bh1770_irq()
600 sysfs_notify(&chip->client->dev.kobj, NULL, "lux0_input"); in bh1770_irq()
602 if (chip->int_mode_prox && (status & BH1770_INT_LEDS_INT)) { in bh1770_irq()
603 rate = prox_rates_ms[chip->prox_rate_threshold]; in bh1770_irq()
604 bh1770_prox_read_result(chip); in bh1770_irq()
608 i2c_smbus_write_byte_data(chip->client, BH1770_INTERRUPT, in bh1770_irq()
609 (chip->int_mode_lux << 1) | in bh1770_irq()
610 (chip->int_mode_prox << 0)); in bh1770_irq()
611 mutex_unlock(&chip->mutex); in bh1770_irq()
622 cancel_delayed_work_sync(&chip->prox_work); in bh1770_irq()
623 schedule_delayed_work(&chip->prox_work, in bh1770_irq()
633 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_power_state_store() local
641 mutex_lock(&chip->mutex); in bh1770_power_state_store()
645 ret = bh1770_lux_rate(chip, chip->lux_rate_index); in bh1770_power_state_store()
651 ret = bh1770_lux_interrupt_control(chip, BH1770_ENABLE); in bh1770_power_state_store()
658 bh1770_lux_update_thresholds(chip, BH1770_LUX_DEF_THRES, in bh1770_power_state_store()
661 chip->lux_wait_result = true; in bh1770_power_state_store()
662 bh1770_prox_mode_control(chip); in bh1770_power_state_store()
668 mutex_unlock(&chip->mutex); in bh1770_power_state_store()
681 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_lux_result_show() local
686 return -EIO; /* Chip is not enabled at all */ in bh1770_lux_result_show()
688 timeout = wait_event_interruptible_timeout(chip->wait, in bh1770_lux_result_show()
689 !chip->lux_wait_result, in bh1770_lux_result_show()
694 mutex_lock(&chip->mutex); in bh1770_lux_result_show()
695 ret = sprintf(buf, "%d\n", bh1770_lux_read_result(chip)); in bh1770_lux_result_show()
696 mutex_unlock(&chip->mutex); in bh1770_lux_result_show()
711 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_prox_enable_store() local
719 mutex_lock(&chip->mutex); in bh1770_prox_enable_store()
721 if (!chip->prox_enable_count) in bh1770_prox_enable_store()
722 chip->prox_data = 0; in bh1770_prox_enable_store()
725 chip->prox_enable_count++; in bh1770_prox_enable_store()
726 else if (chip->prox_enable_count > 0) in bh1770_prox_enable_store()
727 chip->prox_enable_count--; in bh1770_prox_enable_store()
731 /* Run control only when chip is powered on */ in bh1770_prox_enable_store()
733 bh1770_prox_mode_control(chip); in bh1770_prox_enable_store()
735 mutex_unlock(&chip->mutex); in bh1770_prox_enable_store()
742 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_prox_enable_show() local
745 mutex_lock(&chip->mutex); in bh1770_prox_enable_show()
746 len = sprintf(buf, "%d\n", chip->prox_enable_count); in bh1770_prox_enable_show()
747 mutex_unlock(&chip->mutex); in bh1770_prox_enable_show()
754 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_prox_result_show() local
757 mutex_lock(&chip->mutex); in bh1770_prox_result_show()
758 if (chip->prox_enable_count && !pm_runtime_suspended(dev)) in bh1770_prox_result_show()
759 ret = sprintf(buf, "%d\n", chip->prox_data); in bh1770_prox_result_show()
762 mutex_unlock(&chip->mutex); in bh1770_prox_result_show()
786 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_get_prox_rate_above() local
787 return sprintf(buf, "%d\n", prox_rates_hz[chip->prox_rate_threshold]); in bh1770_get_prox_rate_above()
793 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_get_prox_rate_below() local
794 return sprintf(buf, "%d\n", prox_rates_hz[chip->prox_rate]); in bh1770_get_prox_rate_below()
811 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_set_prox_rate_above() local
819 mutex_lock(&chip->mutex); in bh1770_set_prox_rate_above()
820 chip->prox_rate_threshold = bh1770_prox_rate_validate(value); in bh1770_set_prox_rate_above()
821 mutex_unlock(&chip->mutex); in bh1770_set_prox_rate_above()
829 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_set_prox_rate_below() local
837 mutex_lock(&chip->mutex); in bh1770_set_prox_rate_below()
838 chip->prox_rate = bh1770_prox_rate_validate(value); in bh1770_set_prox_rate_below()
839 mutex_unlock(&chip->mutex); in bh1770_set_prox_rate_below()
846 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_get_prox_thres() local
847 return sprintf(buf, "%d\n", chip->prox_threshold); in bh1770_get_prox_thres()
854 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_set_prox_thres() local
865 mutex_lock(&chip->mutex); in bh1770_set_prox_thres()
866 chip->prox_threshold = value; in bh1770_set_prox_thres()
867 ret = bh1770_prox_set_threshold(chip); in bh1770_set_prox_thres()
868 mutex_unlock(&chip->mutex); in bh1770_set_prox_thres()
877 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_prox_persistence_show() local
879 return sprintf(buf, "%u\n", chip->prox_persistence); in bh1770_prox_persistence_show()
886 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_prox_persistence_store() local
897 chip->prox_persistence = value; in bh1770_prox_persistence_store()
905 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_prox_abs_thres_show() local
906 return sprintf(buf, "%u\n", chip->prox_abs_thres); in bh1770_prox_abs_thres_show()
913 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_prox_abs_thres_store() local
924 chip->prox_abs_thres = value; in bh1770_prox_abs_thres_store()
932 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_chip_id_show() local
933 return sprintf(buf, "%s rev %d\n", chip->chipname, chip->revision); in bh1770_chip_id_show()
945 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_lux_calib_show() local
948 mutex_lock(&chip->mutex); in bh1770_lux_calib_show()
949 len = sprintf(buf, "%u\n", chip->lux_calib); in bh1770_lux_calib_show()
950 mutex_unlock(&chip->mutex); in bh1770_lux_calib_show()
958 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_lux_calib_store() local
968 mutex_lock(&chip->mutex); in bh1770_lux_calib_store()
969 old_calib = chip->lux_calib; in bh1770_lux_calib_store()
970 chip->lux_calib = value; in bh1770_lux_calib_store()
971 new_corr = bh1770_get_corr_value(chip); in bh1770_lux_calib_store()
973 chip->lux_calib = old_calib; in bh1770_lux_calib_store()
974 mutex_unlock(&chip->mutex); in bh1770_lux_calib_store()
977 chip->lux_corr = new_corr; in bh1770_lux_calib_store()
979 bh1770_lux_update_thresholds(chip, chip->lux_threshold_hi, in bh1770_lux_calib_store()
980 chip->lux_threshold_lo); in bh1770_lux_calib_store()
982 mutex_unlock(&chip->mutex); in bh1770_lux_calib_store()
1001 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_get_lux_rate() local
1002 return sprintf(buf, "%d\n", lux_rates_hz[chip->lux_rate_index]); in bh1770_get_lux_rate()
1009 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_set_lux_rate() local
1021 mutex_lock(&chip->mutex); in bh1770_set_lux_rate()
1022 chip->lux_rate_index = i; in bh1770_set_lux_rate()
1023 ret = bh1770_lux_rate(chip, i); in bh1770_set_lux_rate()
1024 mutex_unlock(&chip->mutex); in bh1770_set_lux_rate()
1035 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_get_lux_thresh_above() local
1036 return sprintf(buf, "%d\n", chip->lux_threshold_hi); in bh1770_get_lux_thresh_above()
1042 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_get_lux_thresh_below() local
1043 return sprintf(buf, "%d\n", chip->lux_threshold_lo); in bh1770_get_lux_thresh_below()
1046 static ssize_t bh1770_set_lux_thresh(struct bh1770_chip *chip, u16 *target, in bh1770_set_lux_thresh() argument
1059 mutex_lock(&chip->mutex); in bh1770_set_lux_thresh()
1065 if (!chip->lux_wait_result) in bh1770_set_lux_thresh()
1066 ret = bh1770_lux_update_thresholds(chip, in bh1770_set_lux_thresh()
1067 chip->lux_threshold_hi, in bh1770_set_lux_thresh()
1068 chip->lux_threshold_lo); in bh1770_set_lux_thresh()
1069 mutex_unlock(&chip->mutex); in bh1770_set_lux_thresh()
1078 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_set_lux_thresh_above() local
1079 int ret = bh1770_set_lux_thresh(chip, &chip->lux_threshold_hi, buf); in bh1770_set_lux_thresh_above()
1089 struct bh1770_chip *chip = dev_get_drvdata(dev); in bh1770_set_lux_thresh_below() local
1090 int ret = bh1770_set_lux_thresh(chip, &chip->lux_threshold_lo, buf); in bh1770_set_lux_thresh_below()
1168 struct bh1770_chip *chip; in bh1770_probe() local
1171 chip = devm_kzalloc(&client->dev, sizeof *chip, GFP_KERNEL); in bh1770_probe()
1172 if (!chip) in bh1770_probe()
1175 i2c_set_clientdata(client, chip); in bh1770_probe()
1176 chip->client = client; in bh1770_probe()
1178 mutex_init(&chip->mutex); in bh1770_probe()
1179 init_waitqueue_head(&chip->wait); in bh1770_probe()
1180 INIT_DELAYED_WORK(&chip->prox_work, bh1770_prox_work); in bh1770_probe()
1187 chip->pdata = client->dev.platform_data; in bh1770_probe()
1188 chip->lux_calib = BH1770_LUX_NEUTRAL_CALIB_VALUE; in bh1770_probe()
1189 chip->lux_rate_index = BH1770_LUX_DEFAULT_RATE; in bh1770_probe()
1190 chip->lux_threshold_lo = BH1770_LUX_DEF_THRES; in bh1770_probe()
1191 chip->lux_threshold_hi = BH1770_LUX_DEF_THRES; in bh1770_probe()
1193 if (chip->pdata->glass_attenuation == 0) in bh1770_probe()
1194 chip->lux_ga = BH1770_NEUTRAL_GA; in bh1770_probe()
1196 chip->lux_ga = chip->pdata->glass_attenuation; in bh1770_probe()
1198 chip->prox_threshold = BH1770_PROX_DEF_THRES; in bh1770_probe()
1199 chip->prox_led = chip->pdata->led_def_curr; in bh1770_probe()
1200 chip->prox_abs_thres = BH1770_PROX_DEF_ABS_THRES; in bh1770_probe()
1201 chip->prox_persistence = BH1770_DEFAULT_PERSISTENCE; in bh1770_probe()
1202 chip->prox_rate_threshold = BH1770_PROX_DEF_RATE_THRESH; in bh1770_probe()
1203 chip->prox_rate = BH1770_PROX_DEFAULT_RATE; in bh1770_probe()
1204 chip->prox_data = 0; in bh1770_probe()
1206 chip->regs[0].supply = reg_vcc; in bh1770_probe()
1207 chip->regs[1].supply = reg_vleds; in bh1770_probe()
1210 ARRAY_SIZE(chip->regs), chip->regs); in bh1770_probe()
1216 err = regulator_bulk_enable(ARRAY_SIZE(chip->regs), in bh1770_probe()
1217 chip->regs); in bh1770_probe()
1224 err = bh1770_detect(chip); in bh1770_probe()
1228 /* Start chip */ in bh1770_probe()
1229 bh1770_chip_on(chip); in bh1770_probe()
1233 chip->lux_corr = bh1770_get_corr_value(chip); in bh1770_probe()
1234 if (chip->lux_corr == 0) { in bh1770_probe()
1240 if (chip->pdata->setup_resources) { in bh1770_probe()
1241 err = chip->pdata->setup_resources(); in bh1770_probe()
1248 err = sysfs_create_group(&chip->client->dev.kobj, in bh1770_probe()
1251 dev_err(&chip->client->dev, "Sysfs registration failed\n"); in bh1770_probe()
1256 * Chip needs level triggered interrupt to work. However, in bh1770_probe()
1264 "bh1770", chip); in bh1770_probe()
1270 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); in bh1770_probe()
1273 sysfs_remove_group(&chip->client->dev.kobj, in bh1770_probe()
1276 if (chip->pdata->release_resources) in bh1770_probe()
1277 chip->pdata->release_resources(); in bh1770_probe()
1279 regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); in bh1770_probe()
1285 struct bh1770_chip *chip = i2c_get_clientdata(client); in bh1770_remove() local
1287 free_irq(client->irq, chip); in bh1770_remove()
1289 sysfs_remove_group(&chip->client->dev.kobj, in bh1770_remove()
1292 if (chip->pdata->release_resources) in bh1770_remove()
1293 chip->pdata->release_resources(); in bh1770_remove()
1295 cancel_delayed_work_sync(&chip->prox_work); in bh1770_remove()
1298 bh1770_chip_off(chip); in bh1770_remove()
1310 struct bh1770_chip *chip = i2c_get_clientdata(client); in bh1770_suspend() local
1312 bh1770_chip_off(chip); in bh1770_suspend()
1320 struct bh1770_chip *chip = i2c_get_clientdata(client); in bh1770_resume() local
1323 bh1770_chip_on(chip); in bh1770_resume()
1330 ret = bh1770_lux_rate(chip, chip->lux_rate_index); in bh1770_resume()
1331 ret |= bh1770_lux_interrupt_control(chip, BH1770_ENABLE); in bh1770_resume()
1334 bh1770_lux_update_thresholds(chip, BH1770_LUX_DEF_THRES, in bh1770_resume()
1337 chip->lux_wait_result = true; in bh1770_resume()
1338 bh1770_prox_mode_control(chip); in bh1770_resume()
1348 struct bh1770_chip *chip = i2c_get_clientdata(client); in bh1770_runtime_suspend() local
1350 bh1770_chip_off(chip); in bh1770_runtime_suspend()
1358 struct bh1770_chip *chip = i2c_get_clientdata(client); in bh1770_runtime_resume() local
1360 bh1770_chip_on(chip); in bh1770_runtime_resume()