static int smb136_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct smb136_state *state; state = kzalloc(sizeof(struct smb136_state), GFP_KERNEL); if (state == NULL) { printk("failed to allocate memory \n"); return -ENOMEM; } state->client = client; i2c_set_clientdata(client, state); /* rest of the initialisation goes here. */ printk("Smb136 charger attach success!!!\n"); smb136_i2c_client = client; charger_i2c_init = 1; smb136_test_read(); return 0; }
static irqreturn_t smb136_irq_thread(int irq, void *data) { struct smb136_chip *chip = data; #if defined (CONFIG_MACH_Q1_CHN) && defined (CONFIG_SMB136_CHARGER) int ret = 0; u8 data1=0; #endif dev_info(&chip->client->dev, "%s\n", __func__); smb136_test_read(chip->client); #if defined (CONFIG_MACH_Q1_CHN) && defined (CONFIG_SMB136_CHARGER) smb136_i2c_read(chip->client, 0x33, &data1); if (data1 & 0x02) { if(is_ovp_status == false) { is_ovp_status = true; if (chip->pdata->ovp_cb) ret = chip->pdata->ovp_cb(true); dev_info(&chip->client->dev, "$s OVP!!\n"); } } else { if(is_ovp_status == true) { is_ovp_status = false; if(chip->pdata->ovp_cb) ret = chip->pdata->ovp_cb(false); dev_info(&chip->client->dev, "$s ovp status released!!\n"); } } #endif return IRQ_HANDLED; }
bool sec_hal_chg_set_property(struct i2c_client *client, enum power_supply_property psp, const union power_supply_propval *val) { struct sec_charger_info *charger = i2c_get_clientdata(client); switch (psp) { /* val->intval : type */ case POWER_SUPPLY_PROP_ONLINE: /* val->intval : charging current */ case POWER_SUPPLY_PROP_CURRENT_NOW: if (charger->charging_current < 0) smb136_charger_otg_conrol(client); else if (charger->charging_current > 0) smb136_charger_function_conrol(client); else { smb136_charger_function_conrol(client); smb136_charger_otg_conrol(client); } smb136_test_read(client); break; default: return false; } return true; }
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 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; }
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->callbacks = kzalloc(sizeof(struct smb_charger_callbacks) , GFP_KERNEL); if (!chg->callbacks) { pr_err("%s : No callbacks\n", __func__); ret = -ENOMEM; goto err_callbacks; } chg->client = client; if (!chg->client) { pr_err("%s : No client\n", __func__); ret = -EINVAL; goto err_client; } chg->pdata = client->dev.platform_data; if (!chg->pdata) { pr_err("%s : No platform data supplied\n", __func__); ret = -EINVAL; goto err_pdata; } i2c_set_clientdata(client, chg); smb136_chg = chg; pr_info("register callback functions!\n"); chg->callbacks->set_charging_state = smb136_set_charging_state; chg->callbacks->get_charging_state = smb136_get_charging_state; chg->callbacks->set_charging_current = smb136_set_charging_current; chg->callbacks->get_charging_current = smb136_get_charging_current; if (chg->pdata && chg->pdata->register_callbacks) chg->pdata->register_callbacks(chg->callbacks); charger_i2c_init = 1; pr_info("Smb136 charger attach success!!!\n"); smb136_test_read(); return 0; err_pdata: err_client: err_callbacks: kfree(chg); return ret; }
void smb136_set_otg_mode(int enable) { struct i2c_client *client = smb136_i2c_client; u8 data; printk("[SMB136] %s (enable : %d)\n", __func__, enable); if(!charger_i2c_init) { printk("%s : smb136 charger IC i2c is not initialized!!\n", __func__); return ; } if(enable) // Enable OTG Mode { // 1. Set OTG Mode (Clear Bit5 of Pin Control) smb136_i2c_read(client, SMB_PinControl, &data); data &= ~(0x1 << 5); smb136_i2c_write(client, SMB_PinControl, data); udelay(10); // 2. Enable OTG Mode (Set Bit1 of Command Register A) smb136_i2c_read(client, SMB_CommandA, &data); data |= (0x1 << 1); smb136_i2c_write(client, SMB_CommandA, data); udelay(10); } else // Re-init charger IC { // 1. Allow volatile writes to 00~09h, USB 500mA Mode, USB5/1 Mode data = 0x88; smb136_i2c_write(client, SMB_CommandA, data); udelay(10); // 2. Change USB5/1/HC Control from Pin to I2C data = 0x08; smb136_i2c_write(client, SMB_PinControl, data); udelay(10); // 3. Allow volatile writes to 00~09h, USB 500mA Mode, USB5/1 Mode data = 0x88; smb136_i2c_write(client, SMB_CommandA, data); udelay(10); // 4. Disable Automatic Input Current Limit data = 0xe6; smb136_i2c_write(client, SMB_InputCurrentLimit, data); udelay(10); //5. Fast Charge Current set 500mA #ifdef CONFIG_TARGET_LOCALE_VZW data = 0xf2; #else data = 0xf4; #endif smb136_i2c_write(client, SMB_ChargeCurrent, data); udelay(10); //6. Automatic Recharge Disabed data = 0x8c; smb136_i2c_write(client, SMB_ControlA, data); udelay(10); //7. Safty timer Disabled data = 0x28; smb136_i2c_write(client, SMB_ControlB, data); udelay(10); //8. Disable USB D+/D- Detection data = 0x28; smb136_i2c_write(client, SMB_OTGControl, data); udelay(10); //9. Set Output Polarity for STAT data = 0xca; smb136_i2c_write(client, SMB_FloatVoltage, data); udelay(10); //10. Re-load Enable data = 0x4b; smb136_i2c_write(client, SMB_SafetyTimer, data); udelay(10); } smb136_test_read(); }
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; }
bool sec_hal_chg_init(struct i2c_client *client) { smb136_test_read(client); return true; }