static int __devinit isl9519q_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl_platform_data *pdata; struct isl9519q_struct *isl_chg; int ret; ret = 0; pdata = client->dev.platform_data; pr_debug("\n"); 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_WORD_DATA)) { ret = -EIO; goto out; } isl_chg = kzalloc(sizeof(*isl_chg), GFP_KERNEL); if (!isl_chg) { ret = -ENOMEM; goto out; } spin_lock_init(&isl_chg->lock); INIT_DELAYED_WORK(&isl_chg->charge_work, isl9519q_worker); isl_chg->client = client; isl_chg->chgcurrent = pdata->chgcurrent; isl_chg->term_current = pdata->term_current; isl_chg->input_current = pdata->input_current; isl_chg->max_system_voltage = pdata->max_system_voltage; isl_chg->min_system_voltage = pdata->min_system_voltage; isl_chg->valid_n_gpio = pdata->valid_n_gpio; /* h/w ignores lower 7 bits of charging current and input current */ isl_chg->chgcurrent &= ~0x7F; isl_chg->input_current &= ~0x7F; /** * ISL is Notified by PMIC to start/stop charging, rather than * handling interrupt from ISL for End-Of-Chargring, and * monitoring the charge-current periodically. The valid_n_gpio * is also not used, dc-present is detected by PMIC. */ isl_chg->notify_by_pmic = (client->irq == 0); i2c_set_clientdata(client, isl_chg); if (pdata->chg_detection_config) { ret = pdata->chg_detection_config(); if (ret) { dev_err(&client->dev, "%s valid config failed ret=%d\n", __func__, ret); goto free_isl_chg; } } isl_chg->max_system_voltage &= MAX_VOLTAGE_REG_MASK; isl_chg->min_system_voltage &= MIN_VOLTAGE_REG_MASK; if (isl_chg->max_system_voltage == 0) isl_chg->max_system_voltage = DEFAULT_MAX_VOLTAGE_REG_VALUE; if (isl_chg->min_system_voltage == 0) isl_chg->min_system_voltage = DEFAULT_MIN_VOLTAGE_REG_VALUE; ret = isl9519q_hwinit(isl_chg); if (ret) goto free_isl_chg; if (isl_chg->notify_by_pmic) ret = isl9519q_init_ext_chg(isl_chg); else ret = isl9519q_init_adapter(isl_chg); if (ret) goto free_isl_chg; the_isl_chg = isl_chg; create_debugfs_entries(isl_chg); pr_info("OK.\n"); return 0; free_isl_chg: kfree(isl_chg); out: return ret; }
static int __devinit isl9519q_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl_platform_data *pdata; struct isl9519q_struct *isl_chg; int ret; ret = 0; pdata = client->dev.platform_data; pr_debug("\n"); 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_WORD_DATA)) { ret = -EIO; goto out; } isl_chg = kzalloc(sizeof(*isl_chg), GFP_KERNEL); if (!isl_chg) { ret = -ENOMEM; goto out; } spin_lock_init(&isl_chg->lock); INIT_DELAYED_WORK(&isl_chg->charge_work, isl9519q_worker); isl_chg->client = client; isl_chg->chgcurrent = pdata->chgcurrent; isl_chg->term_current = pdata->term_current; isl_chg->input_current = pdata->input_current; isl_chg->max_system_voltage = pdata->max_system_voltage; isl_chg->min_system_voltage = pdata->min_system_voltage; isl_chg->valid_n_gpio = pdata->valid_n_gpio; isl_chg->chgcurrent &= ~0x7F; isl_chg->input_current &= ~0x7F; isl_chg->notify_by_pmic = (client->irq == 0); i2c_set_clientdata(client, isl_chg); if (pdata->chg_detection_config) { ret = pdata->chg_detection_config(); if (ret) { dev_err(&client->dev, "%s valid config failed ret=%d\n", __func__, ret); goto free_isl_chg; } } isl_chg->max_system_voltage &= MAX_VOLTAGE_REG_MASK; isl_chg->min_system_voltage &= MIN_VOLTAGE_REG_MASK; if (isl_chg->max_system_voltage == 0) isl_chg->max_system_voltage = DEFAULT_MAX_VOLTAGE_REG_VALUE; if (isl_chg->min_system_voltage == 0) isl_chg->min_system_voltage = DEFAULT_MIN_VOLTAGE_REG_VALUE; ret = isl9519q_hwinit(isl_chg); if (ret) goto free_isl_chg; if (isl_chg->notify_by_pmic) ret = isl9519q_init_ext_chg(isl_chg); else ret = isl9519q_init_adapter(isl_chg); if (ret) goto free_isl_chg; the_isl_chg = isl_chg; create_debugfs_entries(isl_chg); pr_info("OK.\n"); return 0; free_isl_chg: kfree(isl_chg); out: return ret; }