Пример #1
0
static int smb136_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
	struct smb136_chg_data *chg;
	int ret = 0;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
		return -EIO;

	pr_info("%s : SMB136 Charger Driver Loading\n", __func__);

	chg = kzalloc(sizeof(struct smb136_chg_data), GFP_KERNEL);
	if (!chg)
		return -ENOMEM;

	chg->client = client;
	chg->pdata = client->dev.platform_data;
	chg->chgdev = chg->pdata->chgdev;

	i2c_set_clientdata(client, chg);
	smb136_chg = chg;  // set local

	printk("Smb136 charger attach success!!!\n");

	// Check whether battery already full charged or not.
	if(smb136_get_charging_status()==CHARGING_STATUS_FULL)
		chg->chgdev->set_charging_status(CHARGING_STATUS_FULL);


	if (!chg->pdata) {
		pr_err("%s : No platform data supplied\n", __func__);
		ret = -EINVAL;
		goto err_pdata;
	}

	chg->chgdev->charging_control = smb136_charging;
	chg->chgdev->get_connection_status = NULL;
	chg->chgdev->get_charging_status = smb136_get_charging_status;
	if(chg->pdata && chg->pdata->charger_dev_register)
		chg->pdata->charger_dev_register(chg->chgdev);

	charger_i2c_init = 1;

	ret = smb136_irq_init(chg);
	if (ret)
		goto err_pdata;

	if (device_create_file(&client->dev, &dev_attr_command) < 0)
		printk("Failed to create device file(%s)!\n", dev_attr_command.attr.name);
	
	smb136_test_read();
	
	return 0;

err_pdata:
	kfree(chg);
	return ret;
}
Пример #2
0
static int smb136_get_property(struct power_supply *psy,
			    enum power_supply_property psp,
			    union power_supply_propval *val)
{
	struct smb136_chip *chip = container_of(psy,
						  struct smb136_chip,
						  charger);
	u8 data;

	switch (psp) {
	case POWER_SUPPLY_PROP_STATUS:
		val->intval = smb136_get_charging_status(chip->client);
		break;
	case POWER_SUPPLY_PROP_CHARGE_TYPE:
		val->intval = chip->cable_type;
		break;
	case POWER_SUPPLY_PROP_ONLINE:
		val->intval = chip->is_enable;
		break;
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		smb136_i2c_read(chip->client, SMB_ChargeCurrent, &data);
		switch (data >> 5) {
		case 0:
			val->intval = 500;
			break;
		case 1:
			val->intval = 650;
			break;
		case 2:
			val->intval = 750;
			break;
		case 3:
			val->intval = 850;
			break;
		case 4:
			val->intval = 950;
			break;
		case 5:
			val->intval = 1100;
			break;
		case 6:
			val->intval = 1300;
			break;
		case 7:
			val->intval = 1500;
			break;
		}
		break;
	default:
		return -EINVAL;
	}

	dev_info(&chip->client->dev, "%s: smb136_get_property (%d,%d)\n",
		__func__, psp, val->intval);

	return 0;
}
Пример #3
0
static irqreturn_t smb136_irq_thread(int irq, void *data)
{
	struct smb136_chg_data *chg = data;

	printk("%s\n", __func__);

	smb136_test_read();
	
	if(gpio_get_value(GPIO_TA_nCHG)==1 && smb136_get_charging_status()==CHARGING_STATUS_FULL)
	{
		chg->chgdev->set_charging_status(CHARGING_STATUS_FULL);
	}

	return IRQ_HANDLED;
}
bool sec_hal_chg_get_property(struct i2c_client *client,
			      enum power_supply_property psp,
			      union power_supply_propval *val)
{
	switch (psp) {
	case POWER_SUPPLY_PROP_STATUS:
		val->intval = smb136_get_charging_status(client);
		break;
	case POWER_SUPPLY_PROP_HEALTH:
		val->intval = smb136_get_charging_health(client);
		break;
	default:
		return false;
	}
	return true;
}