Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: Add a routine to set the current limit for QCOM PMIC VBUS

Add hooks to regulator_get_current_limit_regmap() and
regulator_set_current_limit_regmap() with an accompanying map of amperages.

This lets us use the existing helper functions to map requested current
settings to register bit-map/indicies.

This change is required to elevate the default 2 Amps set by the bootloader
to 3 Amps or indeed to constrain the value lower as the system design may
dictate.

The valid range is 500 mA to 3 A in increments of 500 mA.

Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Link: https://lore.kernel.org/r/20210427130712.2005456-2-bryan.odonoghue@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Bryan O'Donoghue and committed by
Mark Brown
67823d9d 6efb943b

+12
+12
drivers/regulator/qcom_usb_vbus-regulator.c
··· 16 16 17 17 #define CMD_OTG 0x40 18 18 #define OTG_EN BIT(0) 19 + #define OTG_CURRENT_LIMIT_CFG 0x52 20 + #define OTG_CURRENT_LIMIT_MASK GENMASK(2, 0) 19 21 #define OTG_CFG 0x53 20 22 #define OTG_EN_SRC_CFG BIT(1) 23 + 24 + static const unsigned int curr_table[] = { 25 + 500000, 1000000, 1500000, 2000000, 2500000, 3000000, 26 + }; 21 27 22 28 static const struct regulator_ops qcom_usb_vbus_reg_ops = { 23 29 .enable = regulator_enable_regmap, 24 30 .disable = regulator_disable_regmap, 25 31 .is_enabled = regulator_is_enabled_regmap, 32 + .get_current_limit = regulator_get_current_limit_regmap, 33 + .set_current_limit = regulator_set_current_limit_regmap, 26 34 }; 27 35 28 36 static struct regulator_desc qcom_usb_vbus_rdesc = { ··· 38 30 .ops = &qcom_usb_vbus_reg_ops, 39 31 .owner = THIS_MODULE, 40 32 .type = REGULATOR_VOLTAGE, 33 + .curr_table = curr_table, 34 + .n_current_limits = ARRAY_SIZE(curr_table), 41 35 }; 42 36 43 37 static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) ··· 71 61 72 62 qcom_usb_vbus_rdesc.enable_reg = base + CMD_OTG; 73 63 qcom_usb_vbus_rdesc.enable_mask = OTG_EN; 64 + qcom_usb_vbus_rdesc.csel_reg = base + OTG_CURRENT_LIMIT_CFG; 65 + qcom_usb_vbus_rdesc.csel_mask = OTG_CURRENT_LIMIT_MASK; 74 66 config.dev = dev; 75 67 config.init_data = init_data; 76 68 config.of_node = dev->of_node;