Lines Matching full:gain

2 /* gain-time-scale conversion helpers for IIO light sensors
22 * iio_gts_get_gain - Convert scale to total gain
24 * Internal helper for converting scale to total gain.
29 * @scale: Linearized scale to compute the gain for.
31 * Return: (floored) gain corresponding to the scale. -EINVAL if scale
45 * gain_get_scale_fraction - get the gain or time based on scale and known one
50 * @scale: Linearized scale to compute the gain/time for.
51 * @known: Either integration time or gain depending on which one is known
52 * @unknown: Pointer to variable where the computed gain/time is stored
54 * Internal helper for computing unknown fraction of total gain.
55 * Compute either gain or time based on scale and either the gain or time
71 /* We require total gain to be exact multiple of known * unknown */ in gain_get_scale_fraction()
114 * iio_gts_total_gain_to_scale - convert gain to scale
115 * @gts: Gain time scale descriptor
116 * @total_gain: the gain to be converted
120 * Convert the total gain value to scale. NOTE: This does not separate gain
121 * generated by HW-gain or integration time. It is up to caller to decide what
122 * part of the total gain is due to integration time and what due to HW-gain.
141 * @gts: Gain time scale descriptor
261 * @gts: Gain time scale descriptor
264 * originally given gain and time tables. When both time and gain tables are
302 per_time_gains[i][j] = gts->hwgain_table[j].gain * in iio_gts_build_avail_scale_table()
342 * @gts: Gain time scale descriptor
408 * @gts: Gain time scale descriptor
423 * @gts: Gain time scale descriptor
427 * given gain and given time tables.
429 * When both time and gain tables are
463 * @gts: Gain time scale descriptor
482 * @gts: Gain time scale descriptor
486 * given gain and given time tables.
488 * When both time and gain tables are given this results:
525 if (g->sel < 0 || g->gain <= 0) in sanity_check_gain()
552 int gain, mul, res; in iio_gts_sanity_check() local
554 gain = gts->hwgain_table[g].gain; in iio_gts_sanity_check()
557 if (check_mul_overflow(gain, mul, &res)) in iio_gts_sanity_check()
588 * devm_iio_init_iio_gts - Initialize the gain-time-scale helper
594 * @num_gain: number of gains in the gain table
604 * Initialize the gain-time-scale helper for use. Note, gains, times, selectors
606 * checking. The total gain (maximum gain * maximum time multiplier) must not
629 * @gts: Gain time scale descriptor
652 * @gts: Gain time scale descriptor
686 * @gts: Gain time scale descriptor
708 * iio_gts_find_sel_by_gain - find selector corresponding to a HW-gain
709 * @gts: Gain time scale descriptor
710 * @gain: HW-gain for which matching selector is searched for
712 * Return: a selector matching given HW-gain or -EINVAL if selector was
715 int iio_gts_find_sel_by_gain(struct iio_gts *gts, int gain) in iio_gts_find_sel_by_gain() argument
720 if (gts->hwgain_table[i].gain == gain) in iio_gts_find_sel_by_gain()
728 * iio_gts_find_gain_by_sel - find HW-gain corresponding to a selector
729 * @gts: Gain time scale descriptor
730 * @sel: selector for which matching HW-gain is searched for
732 * Return: a HW-gain matching given selector or -EINVAL if HW-gain was not
741 return gts->hwgain_table[i].gain; in iio_gts_find_gain_by_sel()
748 * iio_gts_get_min_gain - find smallest valid HW-gain
749 * @gts: Gain time scale descriptor
751 * Return: The smallest HW-gain -EINVAL if no HW-gains were in the tables.
758 int gain = gts->hwgain_table[i].gain; in iio_gts_get_min_gain() local
761 min = gain; in iio_gts_get_min_gain()
763 min = min(min, gain); in iio_gts_get_min_gain()
771 * iio_find_closest_gain_low - Find the closest lower matching gain
772 * @gts: Gain time scale descriptor
773 * @gain: HW-gain for which the closest match is searched
774 * @in_range: indicate if the @gain was actually in the range of
777 * Search for closest supported gain that is lower than or equal to the
778 * gain given as a parameter. This is usable for drivers which do not require
779 * user to request exact matching gain but rather for rounding to a supported
780 * gain value which is equal or lower (setting lower gain is typical for
783 * Return: The closest matching supported gain or -EINVAL if @gain
784 * was smaller than the smallest supported gain.
786 int iio_find_closest_gain_low(struct iio_gts *gts, int gain, bool *in_range) in iio_find_closest_gain_low() argument
794 if (gain == gts->hwgain_table[i].gain) { in iio_find_closest_gain_low()
796 return gain; in iio_find_closest_gain_low()
799 if (gain > gts->hwgain_table[i].gain) { in iio_find_closest_gain_low()
801 diff = gain - gts->hwgain_table[i].gain; in iio_find_closest_gain_low()
804 int tmp = gain - gts->hwgain_table[i].gain; in iio_find_closest_gain_low()
813 * We found valid HW-gain which is greater than in iio_find_closest_gain_low()
815 * will have found an in-range gain in iio_find_closest_gain_low()
820 /* The requested gain was smaller than anything we support */ in iio_find_closest_gain_low()
827 return gts->hwgain_table[best].gain; in iio_find_closest_gain_low()
844 * iio_gts_find_gain_for_scale_using_time - Find gain by time and scale
845 * @gts: Gain time scale descriptor
846 * @time_sel: Integration time selector corresponding to the time gain is
850 * @gain: Pointer to value where gain is stored.
852 * In some cases the light sensors may want to find a gain setting which
854 * gain and time tables may use this helper to retrieve the gain.
856 * Return: 0 on success. -EINVAL if gain matching the parameters is not
861 int *gain) in iio_gts_find_gain_for_scale_using_time() argument
876 ret = gain_get_scale_fraction(gts->max_scale, scale_linear, mul, gain); in iio_gts_find_gain_for_scale_using_time()
880 if (!iio_gts_valid_gain(gts, *gain)) in iio_gts_find_gain_for_scale_using_time()
887 * iio_gts_find_gain_sel_for_scale_using_time - Fetch gain selector.
888 * @gts: Gain time scale descriptor
889 * @time_sel: Integration time selector corresponding to the time gain is
893 * @gain_sel: Pointer to value where gain selector is stored.
901 int gain, ret; in iio_gts_find_gain_sel_for_scale_using_time() local
904 scale_nano, &gain); in iio_gts_find_gain_sel_for_scale_using_time()
908 ret = iio_gts_find_sel_by_gain(gts, gain); in iio_gts_find_gain_sel_for_scale_using_time()
918 static int iio_gts_get_total_gain(struct iio_gts *gts, int gain, int time) in iio_gts_get_total_gain() argument
922 if (!iio_gts_valid_gain(gts, gain)) in iio_gts_get_total_gain()
926 return gain; in iio_gts_get_total_gain()
932 return gain * itime->mul; in iio_gts_get_total_gain()
935 static int iio_gts_get_scale_linear(struct iio_gts *gts, int gain, int time, in iio_gts_get_scale_linear() argument
941 total_gain = iio_gts_get_total_gain(gts, gain, time); in iio_gts_get_scale_linear()
955 * iio_gts_get_scale - get scale based on integration time and HW-gain
956 * @gts: Gain time scale descriptor
957 * @gain: HW-gain for which the scale is computed
962 * Compute scale matching the integration time and HW-gain given as parameter.
966 int iio_gts_get_scale(struct iio_gts *gts, int gain, int time, int *scale_int, in iio_gts_get_scale() argument
972 ret = iio_gts_get_scale_linear(gts, gain, time, &lin_scale); in iio_gts_get_scale()
982 * @gts: Gain time scale descriptor
983 * @old_gain: Previously set gain
986 * @new_gain: Pointer to value where new gain is to be written
989 * time (for a light sensor) by also updating the (HW)gain. This helper computes
990 * new gain value to maintain the scale with new integration time.
992 * Return: 0 if an exactly matching supported new gain was found. When a
994 * positive value. The negative value means that no gain could be computed.
995 * Positive value will be the "best possible new gain there could be". There
996 * can be two reasons why finding the "best possible" new gain is not deemed
998 * gain required to maintain the scale would not be an integer. In this case,
999 * the "best possible" new gain will be a floored optimal gain, which may or
1039 * @gts: Gain time scale descriptor
1040 * @old_gain: Previously set gain
1043 * @new_gain: Pointer to value where new gain is to be written
1046 * time (for a light sensor) by also updating the (HW)gain. This helper computes
1047 * new gain value to maintain the scale with new integration time.
1049 * Return: 0 if an exactly matching supported new gain was found. When a
1051 * positive value. The negative value means that no gain could be computed.
1052 * Positive value will be the "best possible new gain there could be". There
1053 * can be two reasons why finding the "best possible" new gain is not deemed
1055 * gain required to maintain the scale would not be an integer. In this case,
1056 * the "best possible" new gain will be a floored optimal gain, which may or
1091 MODULE_DESCRIPTION("IIO light sensor gain-time-scale helpers");