mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-14 08:36:12 -04:00
iio: qcom-spmi-adc5: add support to read current channels
Add support to read current channels on PM8350B and SMB139x charge pumps. IIN_FB - Input current drawn by main charger (PM8350B) ICHG_FB - Charging current from main charger (PM8350B) IIN_SMB - Input current drawn by one of SMB139x ICHG_SMB - Charging current from one of SMB139x Since, most of these channels needs prescale ratios post reading ADC code and before scaling, add the necessary prescale ratios. Change-Id: Id9b866f684d574813904a5fd8e658f59b1d7bcbf Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
This commit is contained in:
parent
ace4dec329
commit
338debf2e5
3 changed files with 73 additions and 1 deletions
|
|
@ -165,7 +165,13 @@ static const struct vadc_prescale_ratio adc5_prescale_ratios[] = {
|
|||
{.num = 1, .den = 8},
|
||||
{.num = 10, .den = 81},
|
||||
{.num = 1, .den = 10},
|
||||
{.num = 1, .den = 16}
|
||||
{.num = 1, .den = 16},
|
||||
/* Prescale ratios for current channels below */
|
||||
{.num = 32, .den = 100}, /* IIN_FB */
|
||||
{.num = 14, .den = 100}, /* ICHG_SMB */
|
||||
{.num = 28, .den = 100}, /* IIN_SMB */
|
||||
{.num = 1000, .den = 305185}, /* ICHG_FB */
|
||||
{.num = 1000, .den = 610370}, /* ICHG_FB_2X */
|
||||
};
|
||||
|
||||
static int adc5_read(struct adc5_chip *adc, u16 offset, u8 *data, int len)
|
||||
|
|
@ -612,6 +618,11 @@ struct adc5_channels {
|
|||
BIT(IIO_CHAN_INFO_PROCESSED), \
|
||||
_pre, _scale) \
|
||||
|
||||
#define ADC5_CHAN_CUR(_dname, _pre, _scale) \
|
||||
ADC5_CHAN(_dname, IIO_CURRENT, \
|
||||
BIT(IIO_CHAN_INFO_PROCESSED), \
|
||||
_pre, _scale) \
|
||||
|
||||
static const struct adc5_channels adc5_chans_pmic[ADC5_MAX_CHANNEL] = {
|
||||
[ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 0,
|
||||
SCALE_HW_CALIB_DEFAULT)
|
||||
|
|
@ -677,6 +688,14 @@ static const struct adc5_channels adc7_chans_pmic[ADC5_MAX_CHANNEL] = {
|
|||
SCALE_HW_CALIB_PM7_SMB_TEMP)
|
||||
[ADC7_CHG_TEMP] = ADC5_CHAN_TEMP("chg_temp", 0,
|
||||
SCALE_HW_CALIB_PM7_CHG_TEMP)
|
||||
[ADC7_IIN_FB] = ADC5_CHAN_CUR("iin_fb", 9,
|
||||
SCALE_HW_CALIB_CUR)
|
||||
[ADC7_ICHG_SMB] = ADC5_CHAN_CUR("ichg_smb", 10,
|
||||
SCALE_HW_CALIB_CUR)
|
||||
[ADC7_IIN_SMB] = ADC5_CHAN_CUR("iin_smb", 11,
|
||||
SCALE_HW_CALIB_CUR)
|
||||
[ADC7_ICHG_FB] = ADC5_CHAN_CUR("ichg_fb", 12,
|
||||
SCALE_HW_CALIB_CUR_RAW)
|
||||
[ADC7_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 0,
|
||||
SCALE_HW_CALIB_PMIC_THERM_PM7)
|
||||
[ADC7_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_pu2", 0,
|
||||
|
|
|
|||
|
|
@ -512,6 +512,14 @@ 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_current(
|
||||
const struct vadc_prescale_ratio *prescale,
|
||||
const struct adc5_data *data,
|
||||
u16 adc_code, int *result_ua);
|
||||
static int qcom_vadc_scale_hw_calib_current_raw(
|
||||
const struct vadc_prescale_ratio *prescale,
|
||||
const struct adc5_data *data,
|
||||
u16 adc_code, int *result_ua);
|
||||
static int qcom_vadc_scale_hw_calib_therm(
|
||||
const struct vadc_prescale_ratio *prescale,
|
||||
const struct adc5_data *data,
|
||||
|
|
@ -563,6 +571,8 @@ static int qcom_vadc7_scale_hw_calib_die_temp(
|
|||
|
||||
static struct qcom_adc5_scale_type scale_adc5_fn[] = {
|
||||
[SCALE_HW_CALIB_DEFAULT] = {qcom_vadc_scale_hw_calib_volt},
|
||||
[SCALE_HW_CALIB_CUR] = {qcom_vadc_scale_hw_calib_current},
|
||||
[SCALE_HW_CALIB_CUR_RAW] = {qcom_vadc_scale_hw_calib_current_raw},
|
||||
[SCALE_HW_CALIB_THERM_100K_PULLUP] = {qcom_vadc_scale_hw_calib_therm},
|
||||
[SCALE_HW_CALIB_BATT_THERM_100K] = {
|
||||
qcom_vadc_scale_hw_calib_batt_therm_100},
|
||||
|
|
@ -782,6 +792,44 @@ static int qcom_vadc7_scale_hw_calib_therm(
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_vadc_scale_hw_calib_current_raw(
|
||||
const struct vadc_prescale_ratio *prescale,
|
||||
const struct adc5_data *data,
|
||||
u16 adc_code, int *result_ua)
|
||||
{
|
||||
s64 temp;
|
||||
|
||||
if (!prescale->num)
|
||||
return -EINVAL;
|
||||
|
||||
temp = div_s64((s64)(s16)adc_code * prescale->den, prescale->num);
|
||||
*result_ua = (int) temp;
|
||||
pr_debug("raw adc_code: %#x result_ua: %d\n", adc_code, *result_ua);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_vadc_scale_hw_calib_current(
|
||||
const struct vadc_prescale_ratio *prescale,
|
||||
const struct adc5_data *data,
|
||||
u16 adc_code, int *result_ua)
|
||||
{
|
||||
u32 adc_vdd_ref_mv = 1875;
|
||||
s64 voltage;
|
||||
|
||||
if (!prescale->num)
|
||||
return -EINVAL;
|
||||
|
||||
/* (ADC code * vref_vadc (1.875V)) / full_scale_code */
|
||||
voltage = (s64)(s16) adc_code * adc_vdd_ref_mv * 1000;
|
||||
voltage = div_s64(voltage, data->full_scale_code_volt);
|
||||
voltage = div_s64(voltage * prescale->den, prescale->num);
|
||||
*result_ua = (int) voltage;
|
||||
pr_debug("adc_code: %#x result_ua: %d\n", adc_code, *result_ua);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_vadc_scale_hw_calib_volt(
|
||||
const struct vadc_prescale_ratio *prescale,
|
||||
const struct adc5_data *data,
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ struct vadc_prescale_ratio {
|
|||
* 100k pullup. The hardware applies offset/slope to adc code.
|
||||
* SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade.
|
||||
* The hardware applies offset/slope to adc code.
|
||||
* SCALE_HW_CALIB_CUR: Returns result in microamperes for PMIC7 channels that
|
||||
* uses voltage scaling.
|
||||
* SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5
|
||||
* charger temperature.
|
||||
* SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5
|
||||
|
|
@ -146,6 +148,8 @@ struct vadc_prescale_ratio {
|
|||
* SMB139x temperature.
|
||||
* SCALE_HW_CALIB_PM7_CHG_TEMP: Returns result in millidegrees for PMIC7
|
||||
* charger temperature.
|
||||
* SCALE_HW_CALIB_CUR_RAW: Returns result in microamperes for PMIC7 channels
|
||||
* that uses raw ADC code.
|
||||
*/
|
||||
enum vadc_scale_fn_type {
|
||||
SCALE_DEFAULT = 0,
|
||||
|
|
@ -168,6 +172,7 @@ enum vadc_scale_fn_type {
|
|||
SCALE_HW_CALIB_PMIC_THERM_PM7,
|
||||
SCALE_HW_CALIB_PM7_SMB_TEMP,
|
||||
SCALE_HW_CALIB_PM7_CHG_TEMP,
|
||||
SCALE_HW_CALIB_CUR_RAW,
|
||||
SCALE_HW_CALIB_INVALID,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue