License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-04 12:08:18 +00:00
|
|
|
#include <linux/bug.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/bitops.h>
|
2020-12-04 02:54:58 +00:00
|
|
|
#include <linux/fixp-arith.h>
|
2020-12-04 02:54:59 +00:00
|
|
|
#include <linux/iio/adc/qcom-vadc-common.h>
|
2017-04-04 12:08:18 +00:00
|
|
|
#include <linux/math64.h>
|
|
|
|
#include <linux/log2.h>
|
|
|
|
#include <linux/err.h>
|
2017-11-13 10:29:55 +00:00
|
|
|
#include <linux/module.h>
|
2020-01-31 06:16:13 +00:00
|
|
|
#include <linux/units.h>
|
2017-04-04 12:08:18 +00:00
|
|
|
|
2020-12-04 02:55:02 +00:00
|
|
|
/**
|
|
|
|
* struct vadc_map_pt - Map the graph representation for ADC channel
|
|
|
|
* @x: Represent the ADC digitized code.
|
|
|
|
* @y: Represent the physical data which can be temperature, voltage,
|
|
|
|
* resistance.
|
|
|
|
*/
|
|
|
|
struct vadc_map_pt {
|
|
|
|
s32 x;
|
|
|
|
s32 y;
|
|
|
|
};
|
|
|
|
|
2017-04-04 12:08:18 +00:00
|
|
|
/* Voltage to temperature */
|
|
|
|
static const struct vadc_map_pt adcmap_100k_104ef_104fb[] = {
|
2020-12-04 02:55:05 +00:00
|
|
|
{1758, -40000 },
|
|
|
|
{1742, -35000 },
|
|
|
|
{1719, -30000 },
|
|
|
|
{1691, -25000 },
|
|
|
|
{1654, -20000 },
|
|
|
|
{1608, -15000 },
|
|
|
|
{1551, -10000 },
|
|
|
|
{1483, -5000 },
|
|
|
|
{1404, 0 },
|
|
|
|
{1315, 5000 },
|
|
|
|
{1218, 10000 },
|
|
|
|
{1114, 15000 },
|
|
|
|
{1007, 20000 },
|
|
|
|
{900, 25000 },
|
|
|
|
{795, 30000 },
|
|
|
|
{696, 35000 },
|
|
|
|
{605, 40000 },
|
|
|
|
{522, 45000 },
|
|
|
|
{448, 50000 },
|
|
|
|
{383, 55000 },
|
|
|
|
{327, 60000 },
|
|
|
|
{278, 65000 },
|
|
|
|
{237, 70000 },
|
|
|
|
{202, 75000 },
|
|
|
|
{172, 80000 },
|
|
|
|
{146, 85000 },
|
|
|
|
{125, 90000 },
|
|
|
|
{107, 95000 },
|
|
|
|
{92, 100000 },
|
|
|
|
{79, 105000 },
|
|
|
|
{68, 110000 },
|
|
|
|
{59, 115000 },
|
|
|
|
{51, 120000 },
|
|
|
|
{44, 125000 }
|
2017-04-04 12:08:18 +00:00
|
|
|
};
|
|
|
|
|
2018-08-03 01:43:53 +00:00
|
|
|
/*
|
|
|
|
* Voltage to temperature table for 100k pull up for NTCG104EF104 with
|
|
|
|
* 1.875V reference.
|
|
|
|
*/
|
|
|
|
static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
|
|
|
|
{ 1831, -40000 },
|
|
|
|
{ 1814, -35000 },
|
|
|
|
{ 1791, -30000 },
|
|
|
|
{ 1761, -25000 },
|
|
|
|
{ 1723, -20000 },
|
|
|
|
{ 1675, -15000 },
|
|
|
|
{ 1616, -10000 },
|
|
|
|
{ 1545, -5000 },
|
|
|
|
{ 1463, 0 },
|
|
|
|
{ 1370, 5000 },
|
|
|
|
{ 1268, 10000 },
|
|
|
|
{ 1160, 15000 },
|
|
|
|
{ 1049, 20000 },
|
|
|
|
{ 937, 25000 },
|
|
|
|
{ 828, 30000 },
|
|
|
|
{ 726, 35000 },
|
|
|
|
{ 630, 40000 },
|
|
|
|
{ 544, 45000 },
|
|
|
|
{ 467, 50000 },
|
|
|
|
{ 399, 55000 },
|
|
|
|
{ 340, 60000 },
|
|
|
|
{ 290, 65000 },
|
|
|
|
{ 247, 70000 },
|
|
|
|
{ 209, 75000 },
|
|
|
|
{ 179, 80000 },
|
|
|
|
{ 153, 85000 },
|
|
|
|
{ 130, 90000 },
|
|
|
|
{ 112, 95000 },
|
|
|
|
{ 96, 100000 },
|
|
|
|
{ 82, 105000 },
|
|
|
|
{ 71, 110000 },
|
|
|
|
{ 62, 115000 },
|
|
|
|
{ 53, 120000 },
|
|
|
|
{ 46, 125000 },
|
|
|
|
};
|
|
|
|
|
2020-05-28 16:54:26 +00:00
|
|
|
static const struct vadc_map_pt adcmap7_die_temp[] = {
|
2020-12-04 02:55:03 +00:00
|
|
|
{ 857300, 160000 },
|
|
|
|
{ 820100, 140000 },
|
|
|
|
{ 782500, 120000 },
|
|
|
|
{ 744600, 100000 },
|
|
|
|
{ 706400, 80000 },
|
|
|
|
{ 667900, 60000 },
|
|
|
|
{ 629300, 40000 },
|
|
|
|
{ 590500, 20000 },
|
|
|
|
{ 551500, 0 },
|
|
|
|
{ 512400, -20000 },
|
|
|
|
{ 473100, -40000 },
|
|
|
|
{ 433700, -60000 },
|
2020-05-28 16:54:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resistance to temperature table for 100k pull up for NTCG104EF104.
|
|
|
|
*/
|
|
|
|
static const struct vadc_map_pt adcmap7_100k[] = {
|
|
|
|
{ 4250657, -40960 },
|
|
|
|
{ 3962085, -39936 },
|
|
|
|
{ 3694875, -38912 },
|
|
|
|
{ 3447322, -37888 },
|
|
|
|
{ 3217867, -36864 },
|
|
|
|
{ 3005082, -35840 },
|
|
|
|
{ 2807660, -34816 },
|
|
|
|
{ 2624405, -33792 },
|
|
|
|
{ 2454218, -32768 },
|
|
|
|
{ 2296094, -31744 },
|
|
|
|
{ 2149108, -30720 },
|
|
|
|
{ 2012414, -29696 },
|
|
|
|
{ 1885232, -28672 },
|
|
|
|
{ 1766846, -27648 },
|
|
|
|
{ 1656598, -26624 },
|
|
|
|
{ 1553884, -25600 },
|
|
|
|
{ 1458147, -24576 },
|
|
|
|
{ 1368873, -23552 },
|
|
|
|
{ 1285590, -22528 },
|
|
|
|
{ 1207863, -21504 },
|
|
|
|
{ 1135290, -20480 },
|
|
|
|
{ 1067501, -19456 },
|
|
|
|
{ 1004155, -18432 },
|
|
|
|
{ 944935, -17408 },
|
|
|
|
{ 889550, -16384 },
|
|
|
|
{ 837731, -15360 },
|
|
|
|
{ 789229, -14336 },
|
|
|
|
{ 743813, -13312 },
|
|
|
|
{ 701271, -12288 },
|
|
|
|
{ 661405, -11264 },
|
|
|
|
{ 624032, -10240 },
|
|
|
|
{ 588982, -9216 },
|
|
|
|
{ 556100, -8192 },
|
|
|
|
{ 525239, -7168 },
|
|
|
|
{ 496264, -6144 },
|
|
|
|
{ 469050, -5120 },
|
|
|
|
{ 443480, -4096 },
|
|
|
|
{ 419448, -3072 },
|
|
|
|
{ 396851, -2048 },
|
|
|
|
{ 375597, -1024 },
|
|
|
|
{ 355598, 0 },
|
|
|
|
{ 336775, 1024 },
|
|
|
|
{ 319052, 2048 },
|
|
|
|
{ 302359, 3072 },
|
|
|
|
{ 286630, 4096 },
|
|
|
|
{ 271806, 5120 },
|
|
|
|
{ 257829, 6144 },
|
|
|
|
{ 244646, 7168 },
|
|
|
|
{ 232209, 8192 },
|
|
|
|
{ 220471, 9216 },
|
|
|
|
{ 209390, 10240 },
|
|
|
|
{ 198926, 11264 },
|
|
|
|
{ 189040, 12288 },
|
|
|
|
{ 179698, 13312 },
|
|
|
|
{ 170868, 14336 },
|
|
|
|
{ 162519, 15360 },
|
|
|
|
{ 154622, 16384 },
|
|
|
|
{ 147150, 17408 },
|
|
|
|
{ 140079, 18432 },
|
|
|
|
{ 133385, 19456 },
|
|
|
|
{ 127046, 20480 },
|
|
|
|
{ 121042, 21504 },
|
|
|
|
{ 115352, 22528 },
|
|
|
|
{ 109960, 23552 },
|
|
|
|
{ 104848, 24576 },
|
|
|
|
{ 100000, 25600 },
|
|
|
|
{ 95402, 26624 },
|
|
|
|
{ 91038, 27648 },
|
|
|
|
{ 86897, 28672 },
|
|
|
|
{ 82965, 29696 },
|
|
|
|
{ 79232, 30720 },
|
|
|
|
{ 75686, 31744 },
|
|
|
|
{ 72316, 32768 },
|
|
|
|
{ 69114, 33792 },
|
|
|
|
{ 66070, 34816 },
|
|
|
|
{ 63176, 35840 },
|
|
|
|
{ 60423, 36864 },
|
|
|
|
{ 57804, 37888 },
|
|
|
|
{ 55312, 38912 },
|
|
|
|
{ 52940, 39936 },
|
|
|
|
{ 50681, 40960 },
|
|
|
|
{ 48531, 41984 },
|
|
|
|
{ 46482, 43008 },
|
|
|
|
{ 44530, 44032 },
|
|
|
|
{ 42670, 45056 },
|
|
|
|
{ 40897, 46080 },
|
|
|
|
{ 39207, 47104 },
|
|
|
|
{ 37595, 48128 },
|
|
|
|
{ 36057, 49152 },
|
|
|
|
{ 34590, 50176 },
|
|
|
|
{ 33190, 51200 },
|
|
|
|
{ 31853, 52224 },
|
|
|
|
{ 30577, 53248 },
|
|
|
|
{ 29358, 54272 },
|
|
|
|
{ 28194, 55296 },
|
|
|
|
{ 27082, 56320 },
|
|
|
|
{ 26020, 57344 },
|
|
|
|
{ 25004, 58368 },
|
|
|
|
{ 24033, 59392 },
|
|
|
|
{ 23104, 60416 },
|
|
|
|
{ 22216, 61440 },
|
|
|
|
{ 21367, 62464 },
|
|
|
|
{ 20554, 63488 },
|
|
|
|
{ 19776, 64512 },
|
|
|
|
{ 19031, 65536 },
|
|
|
|
{ 18318, 66560 },
|
|
|
|
{ 17636, 67584 },
|
|
|
|
{ 16982, 68608 },
|
|
|
|
{ 16355, 69632 },
|
|
|
|
{ 15755, 70656 },
|
|
|
|
{ 15180, 71680 },
|
|
|
|
{ 14628, 72704 },
|
|
|
|
{ 14099, 73728 },
|
|
|
|
{ 13592, 74752 },
|
|
|
|
{ 13106, 75776 },
|
|
|
|
{ 12640, 76800 },
|
|
|
|
{ 12192, 77824 },
|
|
|
|
{ 11762, 78848 },
|
|
|
|
{ 11350, 79872 },
|
|
|
|
{ 10954, 80896 },
|
|
|
|
{ 10574, 81920 },
|
|
|
|
{ 10209, 82944 },
|
|
|
|
{ 9858, 83968 },
|
|
|
|
{ 9521, 84992 },
|
|
|
|
{ 9197, 86016 },
|
|
|
|
{ 8886, 87040 },
|
|
|
|
{ 8587, 88064 },
|
|
|
|
{ 8299, 89088 },
|
|
|
|
{ 8023, 90112 },
|
|
|
|
{ 7757, 91136 },
|
|
|
|
{ 7501, 92160 },
|
|
|
|
{ 7254, 93184 },
|
|
|
|
{ 7017, 94208 },
|
|
|
|
{ 6789, 95232 },
|
|
|
|
{ 6570, 96256 },
|
|
|
|
{ 6358, 97280 },
|
|
|
|
{ 6155, 98304 },
|
|
|
|
{ 5959, 99328 },
|
|
|
|
{ 5770, 100352 },
|
|
|
|
{ 5588, 101376 },
|
|
|
|
{ 5412, 102400 },
|
|
|
|
{ 5243, 103424 },
|
|
|
|
{ 5080, 104448 },
|
|
|
|
{ 4923, 105472 },
|
|
|
|
{ 4771, 106496 },
|
|
|
|
{ 4625, 107520 },
|
|
|
|
{ 4484, 108544 },
|
|
|
|
{ 4348, 109568 },
|
|
|
|
{ 4217, 110592 },
|
|
|
|
{ 4090, 111616 },
|
|
|
|
{ 3968, 112640 },
|
|
|
|
{ 3850, 113664 },
|
|
|
|
{ 3736, 114688 },
|
|
|
|
{ 3626, 115712 },
|
|
|
|
{ 3519, 116736 },
|
|
|
|
{ 3417, 117760 },
|
|
|
|
{ 3317, 118784 },
|
|
|
|
{ 3221, 119808 },
|
|
|
|
{ 3129, 120832 },
|
|
|
|
{ 3039, 121856 },
|
|
|
|
{ 2952, 122880 },
|
|
|
|
{ 2868, 123904 },
|
|
|
|
{ 2787, 124928 },
|
|
|
|
{ 2709, 125952 },
|
|
|
|
{ 2633, 126976 },
|
|
|
|
{ 2560, 128000 },
|
|
|
|
{ 2489, 129024 },
|
|
|
|
{ 2420, 130048 }
|
|
|
|
};
|
|
|
|
|
2020-12-04 02:54:57 +00:00
|
|
|
static const struct vadc_prescale_ratio adc5_prescale_ratios[] = {
|
|
|
|
{.num = 1, .den = 1},
|
|
|
|
{.num = 1, .den = 3},
|
|
|
|
{.num = 1, .den = 4},
|
|
|
|
{.num = 1, .den = 6},
|
|
|
|
{.num = 1, .den = 20},
|
|
|
|
{.num = 1, .den = 8},
|
|
|
|
{.num = 10, .den = 81},
|
|
|
|
{.num = 1, .den = 10},
|
|
|
|
{.num = 1, .den = 16}
|
|
|
|
};
|
|
|
|
|
2018-08-03 01:43:53 +00:00
|
|
|
static int qcom_vadc_scale_hw_calib_volt(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_uv);
|
|
|
|
static int qcom_vadc_scale_hw_calib_therm(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec);
|
2020-05-28 16:54:26 +00:00
|
|
|
static int qcom_vadc7_scale_hw_calib_therm(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec);
|
2018-08-03 01:43:53 +00:00
|
|
|
static int qcom_vadc_scale_hw_smb_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec);
|
|
|
|
static int qcom_vadc_scale_hw_chg5_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec);
|
|
|
|
static int qcom_vadc_scale_hw_calib_die_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec);
|
2020-05-28 16:54:26 +00:00
|
|
|
static int qcom_vadc7_scale_hw_calib_die_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec);
|
2018-08-03 01:43:53 +00:00
|
|
|
|
|
|
|
static struct qcom_adc5_scale_type scale_adc5_fn[] = {
|
|
|
|
[SCALE_HW_CALIB_DEFAULT] = {qcom_vadc_scale_hw_calib_volt},
|
|
|
|
[SCALE_HW_CALIB_THERM_100K_PULLUP] = {qcom_vadc_scale_hw_calib_therm},
|
|
|
|
[SCALE_HW_CALIB_XOTHERM] = {qcom_vadc_scale_hw_calib_therm},
|
2020-05-28 16:54:26 +00:00
|
|
|
[SCALE_HW_CALIB_THERM_100K_PU_PM7] = {
|
|
|
|
qcom_vadc7_scale_hw_calib_therm},
|
2018-08-03 01:43:53 +00:00
|
|
|
[SCALE_HW_CALIB_PMIC_THERM] = {qcom_vadc_scale_hw_calib_die_temp},
|
2020-05-28 16:54:26 +00:00
|
|
|
[SCALE_HW_CALIB_PMIC_THERM_PM7] = {
|
|
|
|
qcom_vadc7_scale_hw_calib_die_temp},
|
2018-08-03 01:43:53 +00:00
|
|
|
[SCALE_HW_CALIB_PM5_CHG_TEMP] = {qcom_vadc_scale_hw_chg5_temp},
|
|
|
|
[SCALE_HW_CALIB_PM5_SMB_TEMP] = {qcom_vadc_scale_hw_smb_temp},
|
|
|
|
};
|
|
|
|
|
2017-04-04 12:08:18 +00:00
|
|
|
static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
|
2018-08-03 01:43:53 +00:00
|
|
|
u32 tablesize, s32 input, int *output)
|
2017-04-04 12:08:18 +00:00
|
|
|
{
|
|
|
|
u32 i = 0;
|
|
|
|
|
|
|
|
if (!pts)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-12-04 02:55:04 +00:00
|
|
|
while (i < tablesize && pts[i].x > input)
|
2017-04-04 12:08:18 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
*output = pts[0].y;
|
|
|
|
} else if (i == tablesize) {
|
|
|
|
*output = pts[tablesize - 1].y;
|
|
|
|
} else {
|
|
|
|
/* interpolate linearly */
|
2020-12-04 02:54:58 +00:00
|
|
|
*output = fixp_linear_interpolate(pts[i - 1].x, pts[i - 1].y,
|
|
|
|
pts[i].x, pts[i].y,
|
|
|
|
input);
|
2017-04-04 12:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-05 00:01:18 +00:00
|
|
|
static s32 qcom_vadc_map_temp_voltage(const struct vadc_map_pt *pts,
|
|
|
|
u32 tablesize, int input)
|
|
|
|
{
|
|
|
|
u32 i = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Table must be sorted, find the interval of 'y' which contains value
|
|
|
|
* 'input' and map it to proper 'x' value
|
|
|
|
*/
|
|
|
|
while (i < tablesize && pts[i].y < input)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
return pts[0].x;
|
|
|
|
if (i == tablesize)
|
|
|
|
return pts[tablesize - 1].x;
|
|
|
|
|
|
|
|
/* interpolate linearly */
|
|
|
|
return fixp_linear_interpolate(pts[i - 1].y, pts[i - 1].x,
|
|
|
|
pts[i].y, pts[i].x, input);
|
|
|
|
}
|
|
|
|
|
2017-04-04 12:08:18 +00:00
|
|
|
static void qcom_vadc_scale_calib(const struct vadc_linear_graph *calib_graph,
|
|
|
|
u16 adc_code,
|
|
|
|
bool absolute,
|
|
|
|
s64 *scale_voltage)
|
|
|
|
{
|
|
|
|
*scale_voltage = (adc_code - calib_graph->gnd);
|
|
|
|
*scale_voltage *= calib_graph->dx;
|
|
|
|
*scale_voltage = div64_s64(*scale_voltage, calib_graph->dy);
|
|
|
|
if (absolute)
|
|
|
|
*scale_voltage += calib_graph->dx;
|
|
|
|
|
|
|
|
if (*scale_voltage < 0)
|
|
|
|
*scale_voltage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qcom_vadc_scale_volt(const struct vadc_linear_graph *calib_graph,
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
bool absolute, u16 adc_code,
|
|
|
|
int *result_uv)
|
|
|
|
{
|
|
|
|
s64 voltage = 0, result = 0;
|
|
|
|
|
|
|
|
qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage);
|
|
|
|
|
|
|
|
voltage = voltage * prescale->den;
|
|
|
|
result = div64_s64(voltage, prescale->num);
|
|
|
|
*result_uv = result;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qcom_vadc_scale_therm(const struct vadc_linear_graph *calib_graph,
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
bool absolute, u16 adc_code,
|
|
|
|
int *result_mdec)
|
|
|
|
{
|
2018-08-03 01:43:53 +00:00
|
|
|
s64 voltage = 0;
|
2017-04-04 12:08:18 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage);
|
|
|
|
|
|
|
|
if (absolute)
|
|
|
|
voltage = div64_s64(voltage, 1000);
|
|
|
|
|
|
|
|
ret = qcom_vadc_map_voltage_temp(adcmap_100k_104ef_104fb,
|
|
|
|
ARRAY_SIZE(adcmap_100k_104ef_104fb),
|
2018-08-03 01:43:53 +00:00
|
|
|
voltage, result_mdec);
|
2017-04-04 12:08:18 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qcom_vadc_scale_die_temp(const struct vadc_linear_graph *calib_graph,
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
bool absolute,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
s64 voltage = 0;
|
|
|
|
u64 temp; /* Temporary variable for do_div */
|
|
|
|
|
|
|
|
qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage);
|
|
|
|
|
|
|
|
if (voltage > 0) {
|
|
|
|
temp = voltage * prescale->den;
|
|
|
|
do_div(temp, prescale->num * 2);
|
|
|
|
voltage = temp;
|
|
|
|
} else {
|
|
|
|
voltage = 0;
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:16:13 +00:00
|
|
|
*result_mdec = milli_kelvin_to_millicelsius(voltage);
|
2017-04-04 12:08:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qcom_vadc_scale_chg_temp(const struct vadc_linear_graph *calib_graph,
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
bool absolute,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
s64 voltage = 0, result = 0;
|
|
|
|
|
|
|
|
qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage);
|
|
|
|
|
|
|
|
voltage = voltage * prescale->den;
|
|
|
|
voltage = div64_s64(voltage, prescale->num);
|
|
|
|
voltage = ((PMI_CHG_SCALE_1) * (voltage * 2));
|
|
|
|
voltage = (voltage + PMI_CHG_SCALE_2);
|
|
|
|
result = div64_s64(voltage, 1000000);
|
|
|
|
*result_mdec = result;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-05 00:01:18 +00:00
|
|
|
/* convert voltage to ADC code, using 1.875V reference */
|
|
|
|
static u16 qcom_vadc_scale_voltage_code(s32 voltage,
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const u32 full_scale_code_volt,
|
|
|
|
unsigned int factor)
|
|
|
|
{
|
|
|
|
s64 volt = voltage;
|
|
|
|
s64 adc_vdd_ref_mv = 1875; /* reference voltage */
|
|
|
|
|
|
|
|
volt *= prescale->num * factor * full_scale_code_volt;
|
|
|
|
volt = div64_s64(volt, (s64)prescale->den * adc_vdd_ref_mv * 1000);
|
|
|
|
|
|
|
|
return volt;
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:43:53 +00:00
|
|
|
static int qcom_vadc_scale_code_voltage_factor(u16 adc_code,
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
unsigned int factor)
|
|
|
|
{
|
|
|
|
s64 voltage, temp, adc_vdd_ref_mv = 1875;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The normal data range is between 0V to 1.875V. On cases where
|
|
|
|
* we read low voltage values, the ADC code can go beyond the
|
|
|
|
* range and the scale result is incorrect so we clamp the values
|
|
|
|
* for the cases where the code represents a value below 0V
|
|
|
|
*/
|
|
|
|
if (adc_code > VADC5_MAX_CODE)
|
|
|
|
adc_code = 0;
|
|
|
|
|
|
|
|
/* (ADC code * vref_vadc (1.875V)) / full_scale_code */
|
|
|
|
voltage = (s64) adc_code * adc_vdd_ref_mv * 1000;
|
|
|
|
voltage = div64_s64(voltage, data->full_scale_code_volt);
|
|
|
|
if (voltage > 0) {
|
|
|
|
voltage *= prescale->den;
|
|
|
|
temp = prescale->num * factor;
|
|
|
|
voltage = div64_s64(voltage, temp);
|
|
|
|
} else {
|
|
|
|
voltage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) voltage;
|
|
|
|
}
|
|
|
|
|
2020-05-28 16:54:26 +00:00
|
|
|
static int qcom_vadc7_scale_hw_calib_therm(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
s64 resistance = adc_code;
|
|
|
|
int ret, result;
|
|
|
|
|
|
|
|
if (adc_code >= RATIO_MAX_ADC7)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* (ADC code * R_PULLUP (100Kohm)) / (full_scale_code - ADC code)*/
|
|
|
|
resistance *= R_PU_100K;
|
|
|
|
resistance = div64_s64(resistance, RATIO_MAX_ADC7 - adc_code);
|
|
|
|
|
|
|
|
ret = qcom_vadc_map_voltage_temp(adcmap7_100k,
|
|
|
|
ARRAY_SIZE(adcmap7_100k),
|
|
|
|
resistance, &result);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
*result_mdec = result;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:43:53 +00:00
|
|
|
static int qcom_vadc_scale_hw_calib_volt(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_uv)
|
|
|
|
{
|
|
|
|
*result_uv = qcom_vadc_scale_code_voltage_factor(adc_code,
|
|
|
|
prescale, data, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qcom_vadc_scale_hw_calib_therm(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
int voltage;
|
|
|
|
|
|
|
|
voltage = qcom_vadc_scale_code_voltage_factor(adc_code,
|
|
|
|
prescale, data, 1000);
|
|
|
|
|
|
|
|
/* Map voltage to temperature from look-up table */
|
|
|
|
return qcom_vadc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
|
|
|
|
ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
|
|
|
|
voltage, result_mdec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qcom_vadc_scale_hw_calib_die_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
*result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code,
|
|
|
|
prescale, data, 2);
|
2020-01-31 06:16:13 +00:00
|
|
|
*result_mdec = milli_kelvin_to_millicelsius(*result_mdec);
|
2018-08-03 01:43:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-28 16:54:26 +00:00
|
|
|
static int qcom_vadc7_scale_hw_calib_die_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
|
2020-12-04 02:55:03 +00:00
|
|
|
int voltage;
|
2020-05-28 16:54:26 +00:00
|
|
|
|
|
|
|
voltage = qcom_vadc_scale_code_voltage_factor(adc_code,
|
|
|
|
prescale, data, 1);
|
|
|
|
|
2020-12-04 02:55:03 +00:00
|
|
|
return qcom_vadc_map_voltage_temp(adcmap7_die_temp, ARRAY_SIZE(adcmap7_die_temp),
|
|
|
|
voltage, result_mdec);
|
2020-05-28 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 01:43:53 +00:00
|
|
|
static int qcom_vadc_scale_hw_smb_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
*result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code * 100,
|
|
|
|
prescale, data, PMIC5_SMB_TEMP_SCALE_FACTOR);
|
|
|
|
*result_mdec = PMIC5_SMB_TEMP_CONSTANT - *result_mdec;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qcom_vadc_scale_hw_chg5_temp(
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result_mdec)
|
|
|
|
{
|
|
|
|
*result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code,
|
|
|
|
prescale, data, 4);
|
|
|
|
*result_mdec = PMIC5_CHG_TEMP_SCALE_FACTOR - *result_mdec;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-04 12:08:18 +00:00
|
|
|
int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
|
|
|
|
const struct vadc_linear_graph *calib_graph,
|
|
|
|
const struct vadc_prescale_ratio *prescale,
|
|
|
|
bool absolute,
|
|
|
|
u16 adc_code, int *result)
|
|
|
|
{
|
|
|
|
switch (scaletype) {
|
|
|
|
case SCALE_DEFAULT:
|
|
|
|
return qcom_vadc_scale_volt(calib_graph, prescale,
|
|
|
|
absolute, adc_code,
|
|
|
|
result);
|
|
|
|
case SCALE_THERM_100K_PULLUP:
|
|
|
|
case SCALE_XOTHERM:
|
|
|
|
return qcom_vadc_scale_therm(calib_graph, prescale,
|
|
|
|
absolute, adc_code,
|
|
|
|
result);
|
|
|
|
case SCALE_PMIC_THERM:
|
|
|
|
return qcom_vadc_scale_die_temp(calib_graph, prescale,
|
|
|
|
absolute, adc_code,
|
|
|
|
result);
|
|
|
|
case SCALE_PMI_CHG_TEMP:
|
|
|
|
return qcom_vadc_scale_chg_temp(calib_graph, prescale,
|
|
|
|
absolute, adc_code,
|
|
|
|
result);
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_vadc_scale);
|
|
|
|
|
2021-02-05 00:01:18 +00:00
|
|
|
u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio,
|
|
|
|
u32 full_scale_code_volt, int temp)
|
|
|
|
{
|
|
|
|
const struct vadc_prescale_ratio *prescale = &adc5_prescale_ratios[prescale_ratio];
|
|
|
|
s32 voltage;
|
|
|
|
|
|
|
|
voltage = qcom_vadc_map_temp_voltage(adcmap_100k_104ef_104fb_1875_vref,
|
|
|
|
ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
|
|
|
|
temp);
|
|
|
|
return qcom_vadc_scale_voltage_code(voltage, prescale, full_scale_code_volt, 1000);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_adc_tm5_temp_volt_scale);
|
|
|
|
|
2018-08-03 01:43:53 +00:00
|
|
|
int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
|
2020-12-04 02:54:57 +00:00
|
|
|
unsigned int prescale_ratio,
|
2018-08-03 01:43:53 +00:00
|
|
|
const struct adc5_data *data,
|
|
|
|
u16 adc_code, int *result)
|
|
|
|
{
|
2020-12-04 02:54:57 +00:00
|
|
|
const struct vadc_prescale_ratio *prescale = &adc5_prescale_ratios[prescale_ratio];
|
|
|
|
|
2018-08-03 01:43:53 +00:00
|
|
|
if (!(scaletype >= SCALE_HW_CALIB_DEFAULT &&
|
|
|
|
scaletype < SCALE_HW_CALIB_INVALID)) {
|
|
|
|
pr_err("Invalid scale type %d\n", scaletype);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scale_adc5_fn[scaletype].scale_fn(prescale, data,
|
|
|
|
adc_code, result);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_adc5_hw_scale);
|
|
|
|
|
2020-12-04 02:54:57 +00:00
|
|
|
int qcom_adc5_prescaling_from_dt(u32 num, u32 den)
|
|
|
|
{
|
|
|
|
unsigned int pre;
|
|
|
|
|
|
|
|
for (pre = 0; pre < ARRAY_SIZE(adc5_prescale_ratios); pre++)
|
|
|
|
if (adc5_prescale_ratios[pre].num == num &&
|
|
|
|
adc5_prescale_ratios[pre].den == den)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (pre == ARRAY_SIZE(adc5_prescale_ratios))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return pre;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_adc5_prescaling_from_dt);
|
|
|
|
|
|
|
|
int qcom_adc5_hw_settle_time_from_dt(u32 value,
|
|
|
|
const unsigned int *hw_settle)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < VADC_HW_SETTLE_SAMPLES_MAX; i++) {
|
|
|
|
if (value == hw_settle[i])
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_adc5_hw_settle_time_from_dt);
|
|
|
|
|
|
|
|
int qcom_adc5_avg_samples_from_dt(u32 value)
|
|
|
|
{
|
|
|
|
if (!is_power_of_2(value) || value > ADC5_AVG_SAMPLES_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return __ffs(value);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_adc5_avg_samples_from_dt);
|
|
|
|
|
|
|
|
int qcom_adc5_decimation_from_dt(u32 value, const unsigned int *decimation)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ADC5_DECIMATION_SAMPLES_MAX; i++) {
|
|
|
|
if (value == decimation[i])
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_adc5_decimation_from_dt);
|
|
|
|
|
2017-04-04 12:08:18 +00:00
|
|
|
int qcom_vadc_decimation_from_dt(u32 value)
|
|
|
|
{
|
|
|
|
if (!is_power_of_2(value) || value < VADC_DECIMATION_MIN ||
|
|
|
|
value > VADC_DECIMATION_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return __ffs64(value / VADC_DECIMATION_MIN);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(qcom_vadc_decimation_from_dt);
|
2017-11-13 10:29:55 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("Qualcomm ADC common functionality");
|