Example #1
0
int max8907c_pwr_en_config(void)
{
	int ret;
	u8 data;

	if (!max8907c_client)
		return -EINVAL;

	/*
	 * Enable/disable PWREN h/w control mechanism (PWREN signal must be
	 * inactive = high at this time)
	 */
	ret = max8907c_set_bits(max8907c_client, MAX8907C_REG_RESET_CNFG,
					MAX8907C_MASK_PWR_EN, MAX8907C_PWR_EN);
	if (ret != 0)
		return ret;

	/*
	 * When enabled, connect PWREN to SEQ2 by clearing SEQ2 configuration
	 * settings for silicon revision that requires s/w WAR. On other
	 * MAX8907B revisions PWREN is always connected to SEQ2.
	 */
	data = max8907c_reg_read(max8907c_client, MAX8907C_REG_II2RR);

	if (data == MAX8907B_II2RR_PWREN_WAR) {
		data = 0x00;
		ret = max8907c_reg_write(max8907c_client, MAX8907C_REG_SEQ2CNFG, data);
	}
	return ret;
}
Example #2
0
static int max8907c_charger_get_property(struct power_supply *psy,
				enum power_supply_property psp,
				union power_supply_propval *val)
{
	const static int types[] = {
		POWER_SUPPLY_CHARGE_TYPE_TRICKLE,
		POWER_SUPPLY_CHARGE_TYPE_FAST,
		POWER_SUPPLY_CHARGE_TYPE_FAST,
		POWER_SUPPLY_CHARGE_TYPE_NONE,
	};
	int ret = -ENODEV;
	int status;

	struct max8907c_charger *charger = dev_get_drvdata(psy->dev->parent);

	switch (psp) {
	case POWER_SUPPLY_PROP_ONLINE:
		val->intval = charger->online;
		ret = 0;
		break;

	case POWER_SUPPLY_PROP_STATUS:
		/* Get charger status from CHG_EN_STAT */
		status = max8907c_reg_read(charger->i2c, MAX8907C_REG_CHG_STAT);
		val->intval = ((status & 0x10) == 0x10) ?
				POWER_SUPPLY_STATUS_CHARGING :
				POWER_SUPPLY_STATUS_NOT_CHARGING;
		ret = 0;
		break;

	case POWER_SUPPLY_PROP_CHARGE_TYPE:
		/* Get charging type from CHG_MODE */
		status = max8907c_reg_read(charger->i2c, MAX8907C_REG_CHG_STAT);
		val->intval = types[(status & 0x0C) >> 2];
		ret = 0;
		break;

	default:
		val->intval = 0;
		ret = -EINVAL;
		break;
	}
	return ret;
}
Example #3
0
static __devinit int max8907c_charger_probe(struct platform_device *pdev)
{
	struct max8907c_charger_pdata *pdata = pdev->dev.platform_data;
	struct max8907c_charger *charger = 0;
	struct max8907c *chip = dev_get_drvdata(pdev->dev.parent);
	int ret;

	charger = kzalloc(sizeof(*charger), GFP_KERNEL);
	if (!charger)
		return -ENOMEM;

	charger->pdata = pdata;
	charger->online = 0;
	charger->chip = chip;
	charger->i2c = chip->i2c_power;

	platform_set_drvdata(pdev, charger);

	ret = max8907c_reg_read(charger->i2c, MAX8907C_REG_CHG_STAT);
	if (ret & (1 << 7)) {
		charger->online = 1;
		max8907c_set_charger(charger);
	}

	ret = request_threaded_irq(chip->irq_base + MAX8907C_IRQ_VCHG_DC_F, NULL,
				   max8907c_charger_isr, IRQF_ONESHOT,
				   "power-remove", charger);
	if (unlikely(ret < 0)) {
		pr_debug("max8907c: failed to request IRQ	%X\n", ret);
		goto out;
	}

	ret = request_threaded_irq(chip->irq_base + MAX8907C_IRQ_VCHG_DC_R, NULL,
				   max8907c_charger_isr, IRQF_ONESHOT,
				   "power-insert", charger);
	if (unlikely(ret < 0)) {
		pr_debug("max8907c: failed to request IRQ	%X\n", ret);
		goto out1;
	}


	ret = power_supply_register(&pdev->dev, &max8907c_charger_ps);
	if (unlikely(ret != 0)) {
		pr_err("Failed to register max8907c_charger driver: %d\n", ret);
		goto out2;
	}

	return 0;
out2:
	free_irq(chip->irq_base + MAX8907C_IRQ_VCHG_DC_R, charger);
out1:
	free_irq(chip->irq_base + MAX8907C_IRQ_VCHG_DC_F, charger);
out:
	kfree(charger);
	return ret;
}