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; }
static int smb136_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct smb136_chip *chip; int ret = 0; int gpio = 0; u8 data; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) return -EIO; if (smb136_i2c_read(client, 0x36, &data)<0) /* check HW */ return -EIO; dev_info(&client->dev, "%s : SMB136 Charger Driver Loading\n", __func__); chip = kzalloc(sizeof(struct smb136_chip), GFP_KERNEL); if (!chip) return -ENOMEM; chip->client = client; chip->pdata = client->dev.platform_data; i2c_set_clientdata(client, chip); if (!chip->pdata) { dev_err(&client->dev, "%s : No platform data supplied\n", __func__); ret = -EINVAL; goto err_pdata; } if (chip->pdata->set_charger_name) chip->pdata->set_charger_name(); chip->is_enable = false; chip->cable_type = CABLE_TYPE_NONE; chip->charger.name = "smb136-charger"; chip->charger.type = POWER_SUPPLY_TYPE_BATTERY; chip->charger.get_property = smb136_get_property; chip->charger.set_property = smb136_set_property; chip->charger.properties = smb136_charger_props; chip->charger.num_properties = ARRAY_SIZE(smb136_charger_props); ret = power_supply_register(&client->dev, &chip->charger); if (ret) { dev_err(&client->dev, "failed: power supply register\n"); kfree(chip); return ret; } /* CHG_EN pin control - active low */ if (chip->pdata->gpio_chg_en) { s3c_gpio_cfgpin(chip->pdata->gpio_chg_en, S3C_GPIO_OUTPUT); s3c_gpio_setpull(chip->pdata->gpio_chg_en, S3C_GPIO_PULL_NONE); gpio = gpio_request(chip->pdata->gpio_chg_en, "CHG_EN"); if (!gpio) { gpio_direction_output(chip->pdata->gpio_chg_en, GPIO_LEVEL_HIGH); gpio_free(chip->pdata->gpio_chg_en); } else dev_err(&client->dev, "faile to request gpio(CHG_EN)\n"); } if (chip->pdata->gpio_otg_en) { s3c_gpio_cfgpin(chip->pdata->gpio_otg_en, S3C_GPIO_OUTPUT); s3c_gpio_setpull(chip->pdata->gpio_otg_en, S3C_GPIO_PULL_NONE); gpio = gpio_request(chip->pdata->gpio_otg_en, "OTG_EN"); if (!gpio) { gpio_direction_output(chip->pdata->gpio_otg_en, GPIO_LEVEL_LOW); gpio_free(chip->pdata->gpio_otg_en); } else dev_err(&client->dev, "faile to request gpio(OTG_EN)\n"); } if (chip->pdata->gpio_ta_nconnected) { s3c_gpio_cfgpin(chip->pdata->gpio_ta_nconnected, S3C_GPIO_INPUT); s3c_gpio_setpull(chip->pdata->gpio_ta_nconnected, S3C_GPIO_PULL_NONE); } if (chip->pdata->gpio_chg_ing) { #if 1 #if defined (CONFIG_MACH_Q1_CHN) && defined (CONFIG_SMB136_CHARGER) s3c_gpio_cfgpin(chip->pdata->gpio_chg_ing, S3C_GPIO_SFN(0xf)); #endif client->irq = gpio_to_irq(chip->pdata->gpio_chg_ing); ret = smb136_irq_init(chip); if (ret) goto err_pdata; #else s3c_gpio_cfgpin(chip->pdata->gpio_chg_ing, S3C_GPIO_INPUT); s3c_gpio_setpull(chip->pdata->gpio_chg_ing, S3C_GPIO_PULL_NONE); #endif } smb136_test_read(client); return 0; err_pdata: kfree(chip); return ret; }