static int bq24157_get_charging_status(struct i2c_client *client)
{
	int status = POWER_SUPPLY_STATUS_UNKNOWN;
	u8 data = 0;

	bq24157_i2c_read(client, BQ24157_STATUS, &data);
	dev_info(&client->dev,
		"%s : charger status(0x%02x)\n", __func__, data);

	data = (data & 0x30);

	switch (data) {
	case 0x00:
		status = POWER_SUPPLY_STATUS_DISCHARGING;
		break;
	case 0x10:
		status = POWER_SUPPLY_STATUS_CHARGING;
		break;
	case 0x20:
		status = POWER_SUPPLY_STATUS_FULL;
		break;
	case 0x30:
		status = POWER_SUPPLY_STATUS_NOT_CHARGING;
		break;
	}

	return (int)status;
}
Пример #2
0
static void bq24157_read_regs(struct i2c_client *client, char *str)
{
    u8 data = 0;
    u32 addr = 0;

    for (addr = 0; addr <= 0x06; addr++) {
        bq24157_i2c_read(client, addr, &data);
        sprintf(str+strlen(str), "0x%x, ", data);
    }
}
static void bq24157_test_read(struct i2c_client *client)
{
	u8 data = 0;
	u32 addr = 0;
	for (addr = 0; addr <= 0x06; addr++) {
		bq24157_i2c_read(client, addr, &data);
		dev_dbg(&client->dev,
			"bq24157 addr : 0x%02x data : 0x%02x\n", addr, data);
	}
}
static void bq24157_read_regs(struct i2c_client *client, char *str, int maxlen)
{
	u8 data = 0;
	u32 addr = 0;
	int len = 0;

	for (addr = 0; addr <= 0x06; addr++) {
		bq24157_i2c_read(client, addr, &data);
		len += snprintf(str+len, maxlen-len, "0x%x, ", data);
	}
}
static void bq24157_set_command(struct i2c_client *client,
				int reg, int datum)
{
	int val;
	u8 data = 0;
	val = bq24157_i2c_read(client, reg, &data);
	if (val >= 0) {
		dev_dbg(&client->dev, "%s : reg(0x%02x): 0x%02x(0x%02x)",
			__func__, reg, data, datum);
		if (data != datum) {
			data = datum;
			if (bq24157_i2c_write(client, reg, &data) < 0)
				dev_err(&client->dev,
					"%s : error!\n", __func__);
			val = bq24157_i2c_read(client, reg, &data);
			if (val >= 0)
				dev_dbg(&client->dev, " => 0x%02x\n", data);
		}
	}
}
static void bq24157_charger_otg_conrol(
				struct i2c_client *client)
{
	struct sec_charger_info *charger = i2c_get_clientdata(client);
	u8 data;

	if (charger->cable_type ==
		POWER_SUPPLY_TYPE_BATTERY) {
		dev_info(&client->dev, "%s : turn off OTG\n", __func__);
		/* turn off OTG */
		bq24157_i2c_read(client, BQ24157_VOLTAGE, &data);
		data &= 0xfe;
		bq24157_set_command(client,
			BQ24157_VOLTAGE, data);
	} else {
		dev_info(&client->dev, "%s : turn on OTG\n", __func__);
		/* turn on OTG */
		bq24157_i2c_read(client, BQ24157_VOLTAGE, &data);
		data |= 0x01;
		bq24157_set_command(client,
			BQ24157_VOLTAGE, data);
	}
}
static int bq24157_read_chip_info(void)
{
	unsigned char data = 0;	
	int ret = 0;

	ret = bq24157_i2c_read(1, BQ24157_VENDER_PART_REVISION, &data);
	if(ret < 0)
	{
		printk("%s bq24157_i2c_read failed %d\n", __func__, ret);
		return ret;
	}

	printk("%s chip info 0x%x\n", __func__, data);

	return 0;
}
bool sec_hal_chg_get_property(struct i2c_client *client,
			      enum power_supply_property psp,
			      union power_supply_propval *val)
{
	struct sec_charger_info *charger = i2c_get_clientdata(client);
	u8 data;
	switch (psp) {
	case POWER_SUPPLY_PROP_STATUS:
		val->intval = bq24157_get_charging_status(client);
		break;
	case POWER_SUPPLY_PROP_HEALTH:
		val->intval = bq24157_get_charging_health(client);
		break;
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		if (charger->charging_current) {
			/* Rsns 0.068 Ohm */
			bq24157_i2c_read(client, BQ24157_CURRENT, &data);
			val->intval = ((data & 0x78) >> 3) * 100;
		} else
static int bq24157_set_bit(unsigned int reg_num, unsigned char mask, unsigned char bit)
{
	unsigned char data = 0;
	int ret = 0;
	
	ret = bq24157_i2c_read(1, reg_num, &data);
	if(ret < 0)
	{
		printk("%s bq24157_i2c_read failed %d\n", __func__, ret);
		return ret;
	}

	data &= ~mask;
	data |= (mask & bit); 

	ret = bq24157_i2c_write(1, reg_num, &data);
	if(ret < 0)
	{
		printk("%s bq24157_i2c_read failed %d\n", __func__, ret);
		return ret;
	}

	return 0;
}
Пример #10
0
static int bq24157_get_charging_health(struct i2c_client *client)
{
	int health = POWER_SUPPLY_HEALTH_GOOD;
	u8 data = 0;

	bq24157_i2c_read(client, BQ24157_STATUS, &data);
	dev_info(&client->dev,
		"%s : charger status(0x%02x)\n", __func__, data);

	if ((data & 0x30) == 0x30) {	/* check for fault */
		data = (data & 0x07);

		switch (data) {
		case 0x01:
			health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
			break;
		case 0x03:
			health = POWER_SUPPLY_HEALTH_UNDERVOLTAGE;
			break;
		}
	}

	return (int)health;
}
static void bq24157_stat_irq_work(struct work_struct *work)
{
	struct bq24157_platform_data *pdata = container_of(work, struct bq24157_platform_data, stat_irq_work.work);
	unsigned char data = 0;
	int ret = 0;
	int stat = gpio_get_value(GPIO_IRQ(bq24157_client->irq))? 1 : 0; 

	printk("%s \n", __func__);
	if((bq24157_is_ovp==1) && (stat == 0))
	{
		bq24157_is_ovp = 0;	
#if defined(CONFIG_SPA)
                if(spa_external_event)
		{
			spa_external_event(SPA_CATEGORY_BATTERY, SPA_BATTERY_EVENT_OVP_CHARGE_RESTART);
		}
#endif
		goto ovp_restart;
	}

	ret = bq24157_i2c_read(1, BQ24157_STATUS_CONTROL, &data);
	if(ret < 0)
	{
		printk("%s bq24157_i2c_read failed %d\n", __func__, ret);
		goto err_read_status_control;
	}

	printk("%s 0x%x stat : %d\n", __func__, data, stat);	

	switch(data & STAT)
	{
		case STAT_READY:
			break;
		case STAT_INPROGRESS:
			break;
		case STAT_CHARGE_DONE:
#if defined(CONFIG_SPA)
			if(spa_external_event)
			{
				spa_external_event(SPA_CATEGORY_BATTERY, SPA_BATTERY_EVENT_CHARGE_FULL);
			}
#endif
			break;
		case STAT_FAULT:
			switch(data & FAULT)
			{
				case FAULT_NORMAL:
					break;
				case FAULT_VBUS_OVP:
#if defined(CONFIG_SPA)
		                        if(spa_external_event)
					{
						spa_external_event(SPA_CATEGORY_BATTERY, SPA_BATTERY_EVENT_OVP_CHARGE_STOP);
					}
#endif
					break;
				case FAULT_SLEEP_MODE:
					break;
				case FAULT_BAD_ADAPTOR:
					break;
				case FAULT_OUTPUT_OVP:
					break;
				case FAULT_THEMAL_SHUTDOWN:
					break;
				case FAULT_TIMER_FAULT:
					break;
				case FAULT_NO_BATTERY:
					break;
				default:
					break;
			}
			break;

		default:
			break;
	}

ovp_restart:
err_read_status_control:
	wake_unlock(&pdata->stat_irq_wakelock);
}
Пример #12
0
static void bq24157_charger_function_conrol(
				struct i2c_client *client)
{
	struct sec_charger_info *charger = i2c_get_clientdata(client);
	u8 data;

	if (charger->charging_current < 0) {
		dev_dbg(&client->dev,
			"%s : OTG is activated. Ignore command!\n", __func__);
		return;
	}

	if (charger->cable_type ==
		POWER_SUPPLY_TYPE_BATTERY) {
		/* USB100 mode, turn off charger */
		bq24157_set_command(client,
			BQ24157_CONTROL, 0x04);
	} else {
		data = 0x02;
		dev_dbg(&client->dev, "%s : float voltage (%dmV)\n",
			__func__, charger->pdata->chg_float_voltage);
		data |= bq24157_get_float_voltage_data(
			charger->pdata->chg_float_voltage);
		bq24157_set_command(client,
			BQ24157_VOLTAGE, data);

		data = 0x00;
		dev_dbg(&client->dev, "%s : fast charging current (%dmA)\n",
				__func__, charger->charging_current);
		data |= bq24157_get_fast_charging_current_data(
			charger->charging_current);
		dev_dbg(&client->dev, "%s : termination current (%dmA)\n",
			__func__, charger->pdata->charging_current[
			charger->cable_type].full_check_current_1st);
		data |= bq24157_get_termination_current_limit_data(
			charger->pdata->charging_current[
			charger->cable_type].full_check_current_1st);
		bq24157_set_command(client,
			BQ24157_CURRENT, data);

		/* Input current limit */
		bq24157_i2c_read(client, BQ24157_CONTROL, &data);
		dev_dbg(&client->dev, "%s : input current (%dmA)\n",
			__func__, charger->pdata->charging_current
			[charger->cable_type].input_current_limit);
		data |= bq24157_get_input_current_limit_data(
			charger->pdata->charging_current
			[charger->cable_type].input_current_limit);
		bq24157_set_command(client,
			BQ24157_CONTROL, data);

		/* Special Charger Voltage : 4.520V
		 * Normal charge current
		 */
		bq24157_i2c_read(client, BQ24157_SPECIAL, &data);
		data &= 0xdf;
		bq24157_set_command(client,
			BQ24157_SPECIAL, data);

		bq24157_i2c_read(client, BQ24157_CONTROL, &data);
		/* Enable charging */
		data &= 0xfb;
		/* Termination setting */
		switch (charger->pdata->full_check_type) {
		case SEC_BATTERY_FULLCHARGED_CHGGPIO:
		case SEC_BATTERY_FULLCHARGED_CHGINT:
		case SEC_BATTERY_FULLCHARGED_CHGPSY:
			/* Enable Current Termination */
			data |= 0x08;
			break;
		case SEC_BATTERY_FULLCHARGED_ADC:
		case SEC_BATTERY_FULLCHARGED_ADC_DUAL:
		case SEC_BATTERY_FULLCHARGED_FG_CURRENT:
		case SEC_BATTERY_FULLCHARGED_FG_CURRENT_DUAL:
			break;

		}
		bq24157_set_command(client,
				BQ24157_CONTROL, data);
	}
}