Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 348f0631 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "drivers: bcl_pmic5: Add ibat scaling factor support for ibat conversion"

parents e375eb21 04ada42d
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ struct bcl_device {

static struct bcl_device *bcl_devices[MAX_PERPH_COUNT];
static int bcl_device_ct;
static bool ibat_use_qg_adc;

static int bcl_read_register(struct bcl_device *bcl_perph, int16_t reg_offset,
				unsigned int *data)
@@ -159,12 +160,20 @@ static void convert_ibat_to_adc_val(int *val)
	 * Threshold register is bit shifted from ADC MSB.
	 * So the scaling factor is half.
	 */
	*val = (*val * 2000) / BCL_IBAT_SCALING_UA;
	if (ibat_use_qg_adc)
		*val = (int)div_s64(*val * 2000 * 2, BCL_IBAT_SCALING_UA);
	else
		*val = (int)div_s64(*val * 2000, BCL_IBAT_SCALING_UA);

}

static void convert_adc_to_ibat_val(int *val)
{
	*val = (*val * BCL_IBAT_SCALING_UA) / 1000;
	/* Scaling factor will be half if ibat_use_qg_adc is true */
	if (ibat_use_qg_adc)
		*val = (int)div_s64(*val * BCL_IBAT_SCALING_UA, 2 * 1000);
	else
		*val = (int)div_s64(*val * BCL_IBAT_SCALING_UA, 1000);
}

static int bcl_set_ibat(void *data, int low, int high)
@@ -443,6 +452,9 @@ static int bcl_get_devicetree_data(struct platform_device *pdev,
		return -ENODEV;
	}

	ibat_use_qg_adc =  of_property_read_bool(dev_node,
				"qcom,ibat-use-qg-adc-5a");

	return ret;
}