Merge "power: qpnp-smbcharger: Add voltage now property in usb psy"
This commit is contained in:
commit
fe304a42ba
2 changed files with 55 additions and 1 deletions
|
@ -281,6 +281,7 @@ Optional Properties:
|
||||||
suspending USB path for fake
|
suspending USB path for fake
|
||||||
battery.
|
battery.
|
||||||
- qcom,vchg_sns-vadc Phandle of the VADC node.
|
- qcom,vchg_sns-vadc Phandle of the VADC node.
|
||||||
|
- qcom,usbin-vadc Phandle of the VADC node.
|
||||||
- qcom,vchg-adc-channel-id The ADC channel to which the VCHG is routed.
|
- qcom,vchg-adc-channel-id The ADC channel to which the VCHG is routed.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
|
@ -277,6 +277,7 @@ struct smbchg_chip {
|
||||||
bool skip_usb_notification;
|
bool skip_usb_notification;
|
||||||
u32 vchg_adc_channel;
|
u32 vchg_adc_channel;
|
||||||
struct qpnp_vadc_chip *vchg_vadc_dev;
|
struct qpnp_vadc_chip *vchg_vadc_dev;
|
||||||
|
struct qpnp_vadc_chip *vusb_vadc_dev;
|
||||||
|
|
||||||
/* voters */
|
/* voters */
|
||||||
struct votable *fcc_votable;
|
struct votable *fcc_votable;
|
||||||
|
@ -5744,9 +5745,43 @@ static void update_typec_otg_status(struct smbchg_chip *chip, int mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int smbchg_get_vusb(struct smbchg_chip *chip)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
struct qpnp_vadc_result adc_result;
|
||||||
|
|
||||||
|
if (!is_usb_present(chip))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (chip->vusb_vadc_dev) {
|
||||||
|
rc = qpnp_vadc_read(chip->vusb_vadc_dev,
|
||||||
|
USBIN, &adc_result);
|
||||||
|
if (rc < 0) {
|
||||||
|
pr_smb(PR_STATUS,
|
||||||
|
"error in vusb_uv read rc = %d\n", rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return -ENODATA;
|
||||||
|
}
|
||||||
|
pr_smb(PR_STATUS, "The value of vusb_uv %lld\n", adc_result.physical);
|
||||||
|
|
||||||
|
return adc_result.physical;
|
||||||
|
}
|
||||||
|
|
||||||
static int smbchg_set_sdp_current(struct smbchg_chip *chip, int current_ma)
|
static int smbchg_set_sdp_current(struct smbchg_chip *chip, int current_ma)
|
||||||
{
|
{
|
||||||
if (chip->usb_supply_type == POWER_SUPPLY_TYPE_USB) {
|
if (chip->usb_supply_type == POWER_SUPPLY_TYPE_USB) {
|
||||||
|
if (current_ma == -ETIMEDOUT) {
|
||||||
|
/* float charger */
|
||||||
|
current_ma = CURRENT_1500_MA;
|
||||||
|
pr_smb(PR_MISC,
|
||||||
|
"Update usb_type to FLOAT current=%dmA\n",
|
||||||
|
current_ma);
|
||||||
|
chip->usb_psy_d.type = POWER_SUPPLY_TYPE_USB_FLOAT;
|
||||||
|
} else {
|
||||||
|
current_ma = current_ma / 1000;
|
||||||
|
}
|
||||||
/* Override if type-c charger used */
|
/* Override if type-c charger used */
|
||||||
if (chip->typec_current_ma > 500 &&
|
if (chip->typec_current_ma > 500 &&
|
||||||
current_ma < chip->typec_current_ma) {
|
current_ma < chip->typec_current_ma) {
|
||||||
|
@ -5789,6 +5824,9 @@ static int smbchg_usb_get_property(struct power_supply *psy,
|
||||||
case POWER_SUPPLY_PROP_HEALTH:
|
case POWER_SUPPLY_PROP_HEALTH:
|
||||||
val->intval = chip->usb_health;
|
val->intval = chip->usb_health;
|
||||||
break;
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
|
||||||
|
val->intval = smbchg_get_vusb(chip);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -5807,7 +5845,7 @@ static int smbchg_usb_set_property(struct power_supply *psy,
|
||||||
break;
|
break;
|
||||||
case POWER_SUPPLY_PROP_CURRENT_MAX:
|
case POWER_SUPPLY_PROP_CURRENT_MAX:
|
||||||
case POWER_SUPPLY_PROP_SDP_CURRENT_MAX:
|
case POWER_SUPPLY_PROP_SDP_CURRENT_MAX:
|
||||||
smbchg_set_sdp_current(chip, val->intval / 1000);
|
smbchg_set_sdp_current(chip, val->intval);
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -5844,6 +5882,7 @@ static enum power_supply_property smbchg_usb_properties[] = {
|
||||||
POWER_SUPPLY_PROP_REAL_TYPE,
|
POWER_SUPPLY_PROP_REAL_TYPE,
|
||||||
POWER_SUPPLY_PROP_HEALTH,
|
POWER_SUPPLY_PROP_HEALTH,
|
||||||
POWER_SUPPLY_PROP_SDP_CURRENT_MAX,
|
POWER_SUPPLY_PROP_SDP_CURRENT_MAX,
|
||||||
|
POWER_SUPPLY_PROP_VOLTAGE_NOW,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CHARGE_OUTPUT_VTG_RATIO 840
|
#define CHARGE_OUTPUT_VTG_RATIO 840
|
||||||
|
@ -8191,6 +8230,7 @@ static int smbchg_probe(struct platform_device *pdev)
|
||||||
struct smbchg_chip *chip;
|
struct smbchg_chip *chip;
|
||||||
struct power_supply *typec_psy = NULL;
|
struct power_supply *typec_psy = NULL;
|
||||||
struct qpnp_vadc_chip *vadc_dev = NULL, *vchg_vadc_dev = NULL;
|
struct qpnp_vadc_chip *vadc_dev = NULL, *vchg_vadc_dev = NULL;
|
||||||
|
struct qpnp_vadc_chip *vusb_vadc_dev = NULL;
|
||||||
const char *typec_psy_name;
|
const char *typec_psy_name;
|
||||||
struct power_supply_config usb_psy_cfg = {};
|
struct power_supply_config usb_psy_cfg = {};
|
||||||
struct power_supply_config batt_psy_cfg = {};
|
struct power_supply_config batt_psy_cfg = {};
|
||||||
|
@ -8239,6 +8279,18 @@ static int smbchg_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vusb_vadc_dev = NULL;
|
||||||
|
if (of_find_property(pdev->dev.of_node, "qcom,usbin-vadc", NULL)) {
|
||||||
|
vusb_vadc_dev = qpnp_get_vadc(&pdev->dev, "usbin");
|
||||||
|
if (IS_ERR(vusb_vadc_dev)) {
|
||||||
|
rc = PTR_ERR(vusb_vadc_dev);
|
||||||
|
if (rc != -EPROBE_DEFER)
|
||||||
|
dev_err(&pdev->dev, "Couldn't get vadc 'usbin' rc=%d\n",
|
||||||
|
rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
|
chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
|
||||||
if (!chip)
|
if (!chip)
|
||||||
|
@ -8344,6 +8396,7 @@ static int smbchg_probe(struct platform_device *pdev)
|
||||||
init_completion(&chip->usbin_uv_raised);
|
init_completion(&chip->usbin_uv_raised);
|
||||||
chip->vadc_dev = vadc_dev;
|
chip->vadc_dev = vadc_dev;
|
||||||
chip->vchg_vadc_dev = vchg_vadc_dev;
|
chip->vchg_vadc_dev = vchg_vadc_dev;
|
||||||
|
chip->vusb_vadc_dev = vusb_vadc_dev;
|
||||||
chip->pdev = pdev;
|
chip->pdev = pdev;
|
||||||
chip->dev = &pdev->dev;
|
chip->dev = &pdev->dev;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue