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
58 * gain_get_scale_fraction - get the gain or time based on scale and known one
63 * @scale: Linearized scale to compute the gain/time for.
64 * @known: Either integration time or gain depending on which one is known
65 * @unknown: Pointer to variable where the computed gain/time is stored
67 * Internal helper for computing unknown fraction of total gain.
68 * Compute either gain or time based on scale and either the gain or time
84 /* We require total gain to be exact multiple of known * unknown */ in gain_get_scale_fraction()
127 * iio_gts_total_gain_to_scale - convert gain to scale
128 * @gts: Gain time scale descriptor
129 * @total_gain: the gain to be converted
133 * Convert the total gain value to scale. NOTE: This does not separate gain
134 * generated by HW-gain or integration time. It is up to caller to decide what
135 * part of the total gain is due to integration time and what due to HW-gain.
154 * @gts: Gain time scale descriptor
274 * @gts: Gain time scale descriptor
277 * originally given gain and time tables. When both time and gain tables are
315 per_time_gains[i][j] = gts->hwgain_table[j].gain * in iio_gts_build_avail_scale_table()
353 * @gts: Gain time scale descriptor
416 * @gts: Gain time scale descriptor
431 * @gts: Gain time scale descriptor
435 * given gain and given time tables.
437 * When both time and gain tables are
471 * @gts: Gain time scale descriptor
490 * @gts: Gain time scale descriptor
494 * given gain and given time tables.
496 * When both time and gain tables are given this results:
533 if (g->sel < 0 || g->gain <= 0) in sanity_check_gain()
560 int gain, mul, res; in iio_gts_sanity_check() local
562 gain = gts->hwgain_table[g].gain; in iio_gts_sanity_check()
565 if (check_mul_overflow(gain, mul, &res)) in iio_gts_sanity_check()
596 * devm_iio_init_iio_gts - Initialize the gain-time-scale helper
602 * @num_gain: number of gains in the gain table
612 * Initialize the gain-time-scale helper for use. Note, gains, times, selectors
614 * checking. The total gain (maximum gain * maximum time multiplier) must not
637 * @gts: Gain time scale descriptor
660 * @gts: Gain time scale descriptor
694 * @gts: Gain time scale descriptor
716 * iio_gts_find_sel_by_gain - find selector corresponding to a HW-gain
717 * @gts: Gain time scale descriptor
718 * @gain: HW-gain for which matching selector is searched for
720 * Return: a selector matching given HW-gain or -EINVAL if selector was
723 int iio_gts_find_sel_by_gain(struct iio_gts *gts, int gain) in iio_gts_find_sel_by_gain() argument
728 if (gts->hwgain_table[i].gain == gain) in iio_gts_find_sel_by_gain()
736 * iio_gts_find_gain_by_sel - find HW-gain corresponding to a selector
737 * @gts: Gain time scale descriptor
738 * @sel: selector for which matching HW-gain is searched for
740 * Return: a HW-gain matching given selector or -EINVAL if HW-gain was not
749 return gts->hwgain_table[i].gain; in iio_gts_find_gain_by_sel()
756 * iio_gts_get_min_gain - find smallest valid HW-gain
757 * @gts: Gain time scale descriptor
759 * Return: The smallest HW-gain -EINVAL if no HW-gains were in the tables.
766 int gain = gts->hwgain_table[i].gain; in iio_gts_get_min_gain() local
769 min = gain; in iio_gts_get_min_gain()
771 min = min(min, gain); in iio_gts_get_min_gain()
779 * iio_find_closest_gain_low - Find the closest lower matching gain
780 * @gts: Gain time scale descriptor
781 * @gain: HW-gain for which the closest match is searched
782 * @in_range: indicate if the @gain was actually in the range of
785 * Search for closest supported gain that is lower than or equal to the
786 * gain given as a parameter. This is usable for drivers which do not require
787 * user to request exact matching gain but rather for rounding to a supported
788 * gain value which is equal or lower (setting lower gain is typical for
791 * Return: The closest matching supported gain or -EINVAL if @gain
792 * was smaller than the smallest supported gain.
794 int iio_find_closest_gain_low(struct iio_gts *gts, int gain, bool *in_range) in iio_find_closest_gain_low() argument
802 if (gain == gts->hwgain_table[i].gain) { in iio_find_closest_gain_low()
804 return gain; in iio_find_closest_gain_low()
807 if (gain > gts->hwgain_table[i].gain) { in iio_find_closest_gain_low()
809 diff = gain - gts->hwgain_table[i].gain; in iio_find_closest_gain_low()
812 int tmp = gain - gts->hwgain_table[i].gain; in iio_find_closest_gain_low()
821 * We found valid HW-gain which is greater than in iio_find_closest_gain_low()
823 * will have found an in-range gain in iio_find_closest_gain_low()
828 /* The requested gain was smaller than anything we support */ in iio_find_closest_gain_low()
835 return gts->hwgain_table[best].gain; in iio_find_closest_gain_low()
852 * iio_gts_find_gain_for_scale_using_time - Find gain by time and scale
853 * @gts: Gain time scale descriptor
854 * @time_sel: Integration time selector corresponding to the time gain is
858 * @gain: Pointer to value where gain is stored.
860 * In some cases the light sensors may want to find a gain setting which
862 * gain and time tables may use this helper to retrieve the gain.
864 * Return: 0 on success. -EINVAL if gain matching the parameters is not
869 int *gain) in iio_gts_find_gain_for_scale_using_time() argument
884 ret = gain_get_scale_fraction(gts->max_scale, scale_linear, mul, gain); in iio_gts_find_gain_for_scale_using_time()
888 if (!iio_gts_valid_gain(gts, *gain)) in iio_gts_find_gain_for_scale_using_time()
895 * iio_gts_find_gain_sel_for_scale_using_time - Fetch gain selector.
896 * @gts: Gain time scale descriptor
897 * @time_sel: Integration time selector corresponding to the time gain is
901 * @gain_sel: Pointer to value where gain selector is stored.
909 int gain, ret; in iio_gts_find_gain_sel_for_scale_using_time() local
912 scale_nano, &gain); in iio_gts_find_gain_sel_for_scale_using_time()
916 ret = iio_gts_find_sel_by_gain(gts, gain); in iio_gts_find_gain_sel_for_scale_using_time()
926 static int iio_gts_get_total_gain(struct iio_gts *gts, int gain, int time) in iio_gts_get_total_gain() argument
930 if (!iio_gts_valid_gain(gts, gain)) in iio_gts_get_total_gain()
934 return gain; in iio_gts_get_total_gain()
940 return gain * itime->mul; in iio_gts_get_total_gain()
943 static int iio_gts_get_scale_linear(struct iio_gts *gts, int gain, int time, in iio_gts_get_scale_linear() argument
949 total_gain = iio_gts_get_total_gain(gts, gain, time); in iio_gts_get_scale_linear()
963 * iio_gts_get_scale - get scale based on integration time and HW-gain
964 * @gts: Gain time scale descriptor
965 * @gain: HW-gain for which the scale is computed
970 * Compute scale matching the integration time and HW-gain given as parameter.
974 int iio_gts_get_scale(struct iio_gts *gts, int gain, int time, int *scale_int, in iio_gts_get_scale() argument
980 ret = iio_gts_get_scale_linear(gts, gain, time, &lin_scale); in iio_gts_get_scale()
990 * @gts: Gain time scale descriptor
991 * @old_gain: Previously set gain
994 * @new_gain: Pointer to value where new gain is to be written
997 * time (for a light sensor) by also updating the (HW)gain. This helper computes
998 * new gain value to maintain the scale with new integration time.
1000 * Return: 0 if an exactly matching supported new gain was found. When a
1002 * positive value. The negative value means that no gain could be computed.
1003 * Positive value will be the "best possible new gain there could be". There
1004 * can be two reasons why finding the "best possible" new gain is not deemed
1006 * gain required to maintain the scale would not be an integer. In this case,
1007 * the "best possible" new gain will be a floored optimal gain, which may or
1047 * @gts: Gain time scale descriptor
1048 * @old_gain: Previously set gain
1051 * @new_gain: Pointer to value where new gain is to be written
1054 * time (for a light sensor) by also updating the (HW)gain. This helper computes
1055 * new gain value to maintain the scale with new integration time.
1057 * Return: 0 if an exactly matching supported new gain was found. When a
1059 * positive value. The negative value means that no gain could be computed.
1060 * Positive value will be the "best possible new gain there could be". There
1061 * can be two reasons why finding the "best possible" new gain is not deemed
1063 * gain required to maintain the scale would not be an integer. In this case,
1064 * the "best possible" new gain will be a floored optimal gain, which may or
1099 MODULE_DESCRIPTION("IIO light sensor gain-time-scale helpers");