static void hwinit_worker(struct work_struct *work)
{
    int ret;
    struct smb349_struct *smb349_chg = container_of(work,
                                       struct smb349_struct, hwinit_work);

    ret = smb349_hwinit(smb349_chg);
    if (ret)
        pr_err("Failed to re-initilaze registers\n");
}
Esempio n. 2
0
static void chg_worker(struct work_struct *work)
{
	struct smb349_struct *smb349_chg = container_of(work,
				struct smb349_struct, chg_work);
	int ret = 0;

	gpio_set_value_cansleep(smb349_chg->en_n_gpio, smb349_chg->charging);

	/*
	 * Write non-default values, charger chip reloads from
	 * non-volatile memory if it was in suspend mode
	 *
	 */
	if (smb349_chg->charging)
		ret = smb349_hwinit(smb349_chg);
	if (ret)
		pr_err("Failed to re-initilaze registers\n");

	power_supply_changed(&smb349_chg->dc_psy);
}
static int __devinit smb349_probe(struct i2c_client *client,
                                  const struct i2c_device_id *id)
{
    const struct smb349_platform_data *pdata;
    struct smb349_struct *smb349_chg;
    int ret = 0;

    pdata = client->dev.platform_data;

    if (pdata == NULL) {
        dev_err(&client->dev, "%s no platform data\n", __func__);
        ret = -EINVAL;
        goto out;
    }

    if (!i2c_check_functionality(client->adapter,
                                 I2C_FUNC_SMBUS_BYTE_DATA)) {
        ret = -EIO;
        goto out;
    }

    smb349_chg = kzalloc(sizeof(*smb349_chg), GFP_KERNEL);
    if (!smb349_chg) {
        ret = -ENOMEM;
        goto out;
    }

    smb349_chg->client = client;
    smb349_chg->chg_current_ma = pdata->chg_current_ma;
    ret = gpio_request(pdata->chg_susp_gpio, "smb349_suspend");
    if (ret) {
        dev_err(&client->dev, "%s gpio_request failed for %d ret=%d\n",
                __func__, pdata->chg_susp_gpio, ret);
        goto free_smb349_chg;
    }
    smb349_chg->chg_susp_gpio = pdata->chg_susp_gpio;

    ret = gpio_request(pdata->en_n_gpio, "smb349_charger_enable");
    if (ret) {
        dev_err(&client->dev, "%s gpio_request failed for %d ret=%d\n",
                __func__, pdata->en_n_gpio, ret);
        goto chg_susp_gpio_fail;
    }
    smb349_chg->en_n_gpio = pdata->en_n_gpio;

    i2c_set_clientdata(client, smb349_chg);

    ret = smb349_hwinit(smb349_chg);
    if (ret)
        goto free_smb349_chg;

    ret = smb349_init_ext_chg(smb349_chg);
    if (ret)
        goto chg_en_gpio_fail;

    the_smb349_chg = smb349_chg;

    create_debugfs_entries(smb349_chg);
    INIT_WORK(&smb349_chg->hwinit_work, hwinit_worker);

    pr_info("OK connector present = %d\n", smb349_chg->present);
    return 0;

chg_en_gpio_fail:
    gpio_free(smb349_chg->en_n_gpio);
chg_susp_gpio_fail:
    gpio_free(smb349_chg->chg_susp_gpio);
free_smb349_chg:
    kfree(smb349_chg);
out:
    return ret;
}