drivers/iio/industrialio-gts-helper.c
Source file repositories/reference/linux-study-clean/drivers/iio/industrialio-gts-helper.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/industrialio-gts-helper.c- Extension
.c- Size
- 34869 bytes
- Lines
- 1254
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/errno.hlinux/export.hlinux/minmax.hlinux/module.hlinux/overflow.hlinux/slab.hlinux/sort.hlinux/types.hlinux/units.hlinux/iio/iio-gts-helper.hlinux/iio/types.h
Detected Declarations
function Copyrightfunction gain_get_scale_fractionfunction iio_gts_delinearizefunction iio_gts_linearizefunction iio_gts_total_gain_to_scalefunction iio_gts_build_avail_scale_tablefunction scale_eqfunction scale_smallerfunction do_combined_scaletablefunction iio_gts_free_int_table_arrayfunction iio_gts_alloc_int_table_arrayfunction iio_gts_gain_cmpfunction fill_and_sort_scaletablesfunction compute_per_time_gainsfunction compute_per_time_tablesfunction iio_gts_purge_avail_scale_tablefunction iio_gts_us_to_int_microfunction iio_gts_purge_avail_time_tablefunction iio_gts_build_avail_time_tablefunction iio_gts_all_avail_scalesfunction iio_gts_build_avail_tablesfunction devm_iio_gts_avail_all_dropfunction iio_gts_all_avail_scalesfunction sanity_check_timefunction sanity_check_gainfunction iio_gts_sanity_checkfunction iio_init_iio_gtsfunction iio_gts_find_time_and_gain_sel_for_scalefunction iio_gts_all_avail_scalesfunction iio_gts_avail_scales_for_timefunction iio_gts_avail_timesfunction iio_gts_find_sel_by_gainfunction iio_gts_find_gain_by_selfunction iio_gts_get_min_gainfunction lowerfunction iio_gts_get_int_time_gain_multiplier_by_selfunction iio_gts_find_gain_for_scale_using_timefunction iio_gts_find_gain_for_scale_using_timefunction iio_gts_find_gain_for_scale_using_timefunction iio_gts_get_total_gainfunction iio_gts_get_scale_linearfunction iio_gts_get_scalefunction timefunction timefunction iio_gts_find_new_gain_by_old_gain_time
Annotated Snippet
if (scale_smaller(candidate, &all_scales[new_idx - 2])) {
all_scales[new_idx] = candidate[0];
all_scales[new_idx + 1] = candidate[1];
new_idx += 2;
continue;
}
for (chk = 0; chk < new_idx; chk += 2)
if (!scale_smaller(candidate, &all_scales[chk]))
break;
if (scale_eq(candidate, &all_scales[chk]))
continue;
memmove(&all_scales[chk + 2], &all_scales[chk],
(new_idx - chk) * sizeof(int));
all_scales[chk] = candidate[0];
all_scales[chk + 1] = candidate[1];
new_idx += 2;
}
}
gts->num_avail_all_scales = new_idx / 2;
gts->avail_all_scales_table = all_scales;
return 0;
}
static void iio_gts_free_int_table_array(int **arr, int num_tables)
{
int i;
for (i = 0; i < num_tables; i++)
kfree(arr[i]);
kfree(arr);
}
static int iio_gts_alloc_int_table_array(int ***arr, int num_tables, int num_table_items)
{
int i, **tmp;
tmp = kzalloc_objs(**arr, num_tables);
if (!tmp)
return -ENOMEM;
for (i = 0; i < num_tables; i++) {
tmp[i] = kzalloc_objs(int, num_table_items);
if (!tmp[i])
goto err_free;
}
*arr = tmp;
return 0;
err_free:
iio_gts_free_int_table_array(tmp, i);
return -ENOMEM;
}
static int iio_gts_gain_cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
static int fill_and_sort_scaletables(struct iio_gts *gts, int **gains, int **scales)
{
int i, j, ret;
for (i = 0; i < gts->num_itime; i++) {
/*
* Sort the tables for nice output and for easier finding of
* unique values.
*/
sort(gains[i], gts->num_hwgain, sizeof(int), iio_gts_gain_cmp,
NULL);
/* Convert gains to scales */
for (j = 0; j < gts->num_hwgain; j++) {
ret = iio_gts_total_gain_to_scale(gts, gains[i][j],
&scales[i][2 * j],
&scales[i][2 * j + 1]);
if (ret)
return ret;
}
}
return 0;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/errno.h`, `linux/export.h`, `linux/minmax.h`, `linux/module.h`, `linux/overflow.h`, `linux/slab.h`, `linux/sort.h`.
- Detected declarations: `function Copyright`, `function gain_get_scale_fraction`, `function iio_gts_delinearize`, `function iio_gts_linearize`, `function iio_gts_total_gain_to_scale`, `function iio_gts_build_avail_scale_table`, `function scale_eq`, `function scale_smaller`, `function do_combined_scaletable`, `function iio_gts_free_int_table_array`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.