bh1770glc.c (6e9041c6ddd6cbdc61d87bcaca8ca7bb17c28377) bh1770glc.c (f7b41276b6b07f47c5f5212fa244385b0e3aaa30)
1/*
2 * This file is part of the ROHM BH1770GLC / OSRAM SFH7770 sensor driver.
3 * Chip is combined proximity and ambient light sensor.
4 *
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 *
7 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
8 *

--- 637 unchanged lines hidden (view full) ---

646static ssize_t bh1770_power_state_store(struct device *dev,
647 struct device_attribute *attr,
648 const char *buf, size_t count)
649{
650 struct bh1770_chip *chip = dev_get_drvdata(dev);
651 unsigned long value;
652 ssize_t ret;
653
1/*
2 * This file is part of the ROHM BH1770GLC / OSRAM SFH7770 sensor driver.
3 * Chip is combined proximity and ambient light sensor.
4 *
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 *
7 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
8 *

--- 637 unchanged lines hidden (view full) ---

646static ssize_t bh1770_power_state_store(struct device *dev,
647 struct device_attribute *attr,
648 const char *buf, size_t count)
649{
650 struct bh1770_chip *chip = dev_get_drvdata(dev);
651 unsigned long value;
652 ssize_t ret;
653
654 if (strict_strtoul(buf, 0, &value))
655 return -EINVAL;
654 ret = kstrtoul(buf, 0, &value);
655 if (ret)
656 return ret;
656
657 mutex_lock(&chip->mutex);
658 if (value) {
659 pm_runtime_get_sync(dev);
660
661 ret = bh1770_lux_rate(chip, chip->lux_rate_index);
662 if (ret < 0) {
663 pm_runtime_put(dev);

--- 57 unchanged lines hidden (view full) ---

721}
722
723static ssize_t bh1770_prox_enable_store(struct device *dev,
724 struct device_attribute *attr,
725 const char *buf, size_t count)
726{
727 struct bh1770_chip *chip = dev_get_drvdata(dev);
728 unsigned long value;
657
658 mutex_lock(&chip->mutex);
659 if (value) {
660 pm_runtime_get_sync(dev);
661
662 ret = bh1770_lux_rate(chip, chip->lux_rate_index);
663 if (ret < 0) {
664 pm_runtime_put(dev);

--- 57 unchanged lines hidden (view full) ---

722}
723
724static ssize_t bh1770_prox_enable_store(struct device *dev,
725 struct device_attribute *attr,
726 const char *buf, size_t count)
727{
728 struct bh1770_chip *chip = dev_get_drvdata(dev);
729 unsigned long value;
730 int ret;
729
731
730 if (strict_strtoul(buf, 0, &value))
731 return -EINVAL;
732 ret = kstrtoul(buf, 0, &value);
733 if (ret)
734 return ret;
732
733 mutex_lock(&chip->mutex);
734 /* Assume no proximity. Sensor will tell real state soon */
735 if (!chip->prox_enable_count)
736 chip->prox_data = 0;
737
738 if (value)
739 chip->prox_enable_count++;

--- 79 unchanged lines hidden (view full) ---

819}
820
821static ssize_t bh1770_set_prox_rate_above(struct device *dev,
822 struct device_attribute *attr,
823 const char *buf, size_t count)
824{
825 struct bh1770_chip *chip = dev_get_drvdata(dev);
826 unsigned long value;
735
736 mutex_lock(&chip->mutex);
737 /* Assume no proximity. Sensor will tell real state soon */
738 if (!chip->prox_enable_count)
739 chip->prox_data = 0;
740
741 if (value)
742 chip->prox_enable_count++;

--- 79 unchanged lines hidden (view full) ---

822}
823
824static ssize_t bh1770_set_prox_rate_above(struct device *dev,
825 struct device_attribute *attr,
826 const char *buf, size_t count)
827{
828 struct bh1770_chip *chip = dev_get_drvdata(dev);
829 unsigned long value;
830 int ret;
827
831
828 if (strict_strtoul(buf, 0, &value))
829 return -EINVAL;
832 ret = kstrtoul(buf, 0, &value);
833 if (ret)
834 return ret;
830
831 mutex_lock(&chip->mutex);
832 chip->prox_rate_threshold = bh1770_prox_rate_validate(value);
833 mutex_unlock(&chip->mutex);
834 return count;
835}
836
837static ssize_t bh1770_set_prox_rate_below(struct device *dev,
838 struct device_attribute *attr,
839 const char *buf, size_t count)
840{
841 struct bh1770_chip *chip = dev_get_drvdata(dev);
842 unsigned long value;
835
836 mutex_lock(&chip->mutex);
837 chip->prox_rate_threshold = bh1770_prox_rate_validate(value);
838 mutex_unlock(&chip->mutex);
839 return count;
840}
841
842static ssize_t bh1770_set_prox_rate_below(struct device *dev,
843 struct device_attribute *attr,
844 const char *buf, size_t count)
845{
846 struct bh1770_chip *chip = dev_get_drvdata(dev);
847 unsigned long value;
848 int ret;
843
849
844 if (strict_strtoul(buf, 0, &value))
845 return -EINVAL;
850 ret = kstrtoul(buf, 0, &value);
851 if (ret)
852 return ret;
846
847 mutex_lock(&chip->mutex);
848 chip->prox_rate = bh1770_prox_rate_validate(value);
849 mutex_unlock(&chip->mutex);
850 return count;
851}
852
853static ssize_t bh1770_get_prox_thres(struct device *dev,

--- 6 unchanged lines hidden (view full) ---

860static ssize_t bh1770_set_prox_thres(struct device *dev,
861 struct device_attribute *attr,
862 const char *buf, size_t count)
863{
864 struct bh1770_chip *chip = dev_get_drvdata(dev);
865 unsigned long value;
866 int ret;
867
853
854 mutex_lock(&chip->mutex);
855 chip->prox_rate = bh1770_prox_rate_validate(value);
856 mutex_unlock(&chip->mutex);
857 return count;
858}
859
860static ssize_t bh1770_get_prox_thres(struct device *dev,

--- 6 unchanged lines hidden (view full) ---

867static ssize_t bh1770_set_prox_thres(struct device *dev,
868 struct device_attribute *attr,
869 const char *buf, size_t count)
870{
871 struct bh1770_chip *chip = dev_get_drvdata(dev);
872 unsigned long value;
873 int ret;
874
868 if (strict_strtoul(buf, 0, &value))
869 return -EINVAL;
875 ret = kstrtoul(buf, 0, &value);
876 if (ret)
877 return ret;
878
870 if (value > BH1770_PROX_RANGE)
871 return -EINVAL;
872
873 mutex_lock(&chip->mutex);
874 chip->prox_threshold = value;
875 ret = bh1770_prox_set_threshold(chip);
876 mutex_unlock(&chip->mutex);
877 if (ret < 0)

--- 10 unchanged lines hidden (view full) ---

888}
889
890static ssize_t bh1770_prox_persistence_store(struct device *dev,
891 struct device_attribute *attr,
892 const char *buf, size_t len)
893{
894 struct bh1770_chip *chip = dev_get_drvdata(dev);
895 unsigned long value;
879 if (value > BH1770_PROX_RANGE)
880 return -EINVAL;
881
882 mutex_lock(&chip->mutex);
883 chip->prox_threshold = value;
884 ret = bh1770_prox_set_threshold(chip);
885 mutex_unlock(&chip->mutex);
886 if (ret < 0)

--- 10 unchanged lines hidden (view full) ---

897}
898
899static ssize_t bh1770_prox_persistence_store(struct device *dev,
900 struct device_attribute *attr,
901 const char *buf, size_t len)
902{
903 struct bh1770_chip *chip = dev_get_drvdata(dev);
904 unsigned long value;
905 int ret;
896
906
897 if (strict_strtoul(buf, 0, &value))
898 return -EINVAL;
907 ret = kstrtoul(buf, 0, &value);
908 if (ret)
909 return ret;
899
900 if (value > BH1770_PROX_MAX_PERSISTENCE)
901 return -EINVAL;
902
903 chip->prox_persistence = value;
904
905 return len;
906}

--- 6 unchanged lines hidden (view full) ---

913}
914
915static ssize_t bh1770_prox_abs_thres_store(struct device *dev,
916 struct device_attribute *attr,
917 const char *buf, size_t len)
918{
919 struct bh1770_chip *chip = dev_get_drvdata(dev);
920 unsigned long value;
910
911 if (value > BH1770_PROX_MAX_PERSISTENCE)
912 return -EINVAL;
913
914 chip->prox_persistence = value;
915
916 return len;
917}

--- 6 unchanged lines hidden (view full) ---

924}
925
926static ssize_t bh1770_prox_abs_thres_store(struct device *dev,
927 struct device_attribute *attr,
928 const char *buf, size_t len)
929{
930 struct bh1770_chip *chip = dev_get_drvdata(dev);
931 unsigned long value;
932 int ret;
921
933
922 if (strict_strtoul(buf, 0, &value))
923 return -EINVAL;
934 ret = kstrtoul(buf, 0, &value);
935 if (ret)
936 return ret;
924
925 if (value > BH1770_PROX_RANGE)
926 return -EINVAL;
927
928 chip->prox_abs_thres = value;
929
930 return len;
931}

--- 26 unchanged lines hidden (view full) ---

958static ssize_t bh1770_lux_calib_store(struct device *dev,
959 struct device_attribute *attr,
960 const char *buf, size_t len)
961{
962 struct bh1770_chip *chip = dev_get_drvdata(dev);
963 unsigned long value;
964 u32 old_calib;
965 u32 new_corr;
937
938 if (value > BH1770_PROX_RANGE)
939 return -EINVAL;
940
941 chip->prox_abs_thres = value;
942
943 return len;
944}

--- 26 unchanged lines hidden (view full) ---

971static ssize_t bh1770_lux_calib_store(struct device *dev,
972 struct device_attribute *attr,
973 const char *buf, size_t len)
974{
975 struct bh1770_chip *chip = dev_get_drvdata(dev);
976 unsigned long value;
977 u32 old_calib;
978 u32 new_corr;
979 int ret;
966
980
967 if (strict_strtoul(buf, 0, &value))
968 return -EINVAL;
981 ret = kstrtoul(buf, 0, &value);
982 if (ret)
983 return ret;
969
970 mutex_lock(&chip->mutex);
971 old_calib = chip->lux_calib;
972 chip->lux_calib = value;
973 new_corr = bh1770_get_corr_value(chip);
974 if (new_corr == 0) {
975 chip->lux_calib = old_calib;
976 mutex_unlock(&chip->mutex);

--- 30 unchanged lines hidden (view full) ---

1007static ssize_t bh1770_set_lux_rate(struct device *dev,
1008 struct device_attribute *attr,
1009 const char *buf, size_t count)
1010{
1011 struct bh1770_chip *chip = dev_get_drvdata(dev);
1012 unsigned long rate_hz;
1013 int ret, i;
1014
984
985 mutex_lock(&chip->mutex);
986 old_calib = chip->lux_calib;
987 chip->lux_calib = value;
988 new_corr = bh1770_get_corr_value(chip);
989 if (new_corr == 0) {
990 chip->lux_calib = old_calib;
991 mutex_unlock(&chip->mutex);

--- 30 unchanged lines hidden (view full) ---

1022static ssize_t bh1770_set_lux_rate(struct device *dev,
1023 struct device_attribute *attr,
1024 const char *buf, size_t count)
1025{
1026 struct bh1770_chip *chip = dev_get_drvdata(dev);
1027 unsigned long rate_hz;
1028 int ret, i;
1029
1015 if (strict_strtoul(buf, 0, &rate_hz))
1016 return -EINVAL;
1030 ret = kstrtoul(buf, 0, &rate_hz);
1031 if (ret)
1032 return ret;
1017
1018 for (i = 0; i < ARRAY_SIZE(lux_rates_hz) - 1; i++)
1019 if (rate_hz >= lux_rates_hz[i])
1020 break;
1021
1022 mutex_lock(&chip->mutex);
1023 chip->lux_rate_index = i;
1024 ret = bh1770_lux_rate(chip, i);

--- 17 unchanged lines hidden (view full) ---

1042{
1043 struct bh1770_chip *chip = dev_get_drvdata(dev);
1044 return sprintf(buf, "%d\n", chip->lux_threshold_lo);
1045}
1046
1047static ssize_t bh1770_set_lux_thresh(struct bh1770_chip *chip, u16 *target,
1048 const char *buf)
1049{
1033
1034 for (i = 0; i < ARRAY_SIZE(lux_rates_hz) - 1; i++)
1035 if (rate_hz >= lux_rates_hz[i])
1036 break;
1037
1038 mutex_lock(&chip->mutex);
1039 chip->lux_rate_index = i;
1040 ret = bh1770_lux_rate(chip, i);

--- 17 unchanged lines hidden (view full) ---

1058{
1059 struct bh1770_chip *chip = dev_get_drvdata(dev);
1060 return sprintf(buf, "%d\n", chip->lux_threshold_lo);
1061}
1062
1063static ssize_t bh1770_set_lux_thresh(struct bh1770_chip *chip, u16 *target,
1064 const char *buf)
1065{
1050 int ret = 0;
1051 unsigned long thresh;
1066 unsigned long thresh;
1067 int ret;
1052
1068
1053 if (strict_strtoul(buf, 0, &thresh))
1054 return -EINVAL;
1069 ret = kstrtoul(buf, 0, &thresh);
1070 if (ret)
1071 return ret;
1055
1056 if (thresh > BH1770_LUX_RANGE)
1057 return -EINVAL;
1058
1059 mutex_lock(&chip->mutex);
1060 *target = thresh;
1061 /*
1062 * Don't update values in HW if we are still waiting for

--- 339 unchanged lines hidden ---
1072
1073 if (thresh > BH1770_LUX_RANGE)
1074 return -EINVAL;
1075
1076 mutex_lock(&chip->mutex);
1077 *target = thresh;
1078 /*
1079 * Don't update values in HW if we are still waiting for

--- 339 unchanged lines hidden ---