关于PMIC上CHG_LED_SINK引脚控制

CHG_LED_SINK 为PMIC上一个专门用来控制充电指示灯的管脚。

PMIC上关于这个管脚控制的寄存器地址为:

关于PMIC上CHG_LED_SINK引脚控制_第1张图片

在dts中配置 qcom,chgr-led-support; 可以通过系统控制chg-led灯的状态。

获取是否支持PMIC控制LED灯。

	/* Get the charger led support property */
	chip->cfg_chgr_led_support =
			of_property_read_bool(chip->spmi->dev.of_node,
					"qcom,chgr-led-support");

 

static int qpnp_lbc_main_probe(struct spmi_device *spmi)
{
    ..........
    
    if (chip->cfg_chgr_led_support) {
		rc = qpnp_lbc_register_chgr_led(chip);
		if (rc) {
			pr_err("unable to register charger led rc=%d\n", rc);
			return rc;
		}
	}

    ........
}
static int qpnp_lbc_register_chgr_led(struct qpnp_lbc_chip *chip)
{
	int rc;

	chip->led_cdev.name = "red";
	chip->led_cdev.brightness_set = qpnp_lbc_chgr_led_brightness_set;
	chip->led_cdev.brightness_get = qpnp_lbc_chgr_led_brightness_get;

	rc = led_classdev_register(chip->dev, &chip->led_cdev);
	if (rc)
		dev_err(chip->dev, "unable to register charger led, rc=%d\n",
				rc);

	return rc;
};
#define LBC_CHGR_LED	0x4D
#define CHGR_LED_ON	BIT(0)
#define CHGR_LED_OFF	0x0
#define CHGR_LED_STAT_MASK	LBC_MASK(1, 0)
static void qpnp_lbc_chgr_led_brightness_set(struct led_classdev *cdev,
		enum led_brightness value)
{
	struct qpnp_lbc_chip *chip = container_of(cdev, struct qpnp_lbc_chip,
			led_cdev);
	u8 reg;
	int rc;

	if (value > LED_FULL)
		value = LED_FULL;

	pr_debug("set the charger led brightness to value=%d\n", value);
	reg = (value > LED_OFF) ? CHGR_LED_ON : CHGR_LED_OFF;

	rc = qpnp_lbc_masked_write(chip, chip->chgr_base + LBC_CHGR_LED,
				CHGR_LED_STAT_MASK, reg);
	if (rc)
		pr_err("Failed to write charger led rc=%d\n", rc);
}

static enum
led_brightness qpnp_lbc_chgr_led_brightness_get(struct led_classdev *cdev)
{

	struct qpnp_lbc_chip *chip = container_of(cdev, struct qpnp_lbc_chip,
			led_cdev);
	u8 reg_val, chgr_led_sts;
	int rc;

	rc = qpnp_lbc_read(chip, chip->chgr_base + LBC_CHGR_LED,
				®_val, 1);
	if (rc) {
		pr_err("Failed to read charger led rc=%d\n", rc);
		return rc;
	}

	chgr_led_sts = reg_val & CHGR_LED_STAT_MASK;
	pr_debug("charger led brightness chgr_led_sts=%d\n", chgr_led_sts);

	return (chgr_led_sts == CHGR_LED_ON) ? LED_FULL : LED_OFF;
}

 

你可能感兴趣的:(高通)