static void bq27541_hw_config(struct work_struct *work) { int ret = 0, flags = 0, type = 0, fw_ver = 0; struct bq27541_device_info *di; di = container_of(work, struct bq27541_device_info, hw_config.work); ret = bq27541_chip_config(di); if (ret) { dev_err(di->dev, "Failed to config Bq27541\n"); return; } msm_battery_gauge_register(&bq27541_batt_gauge); bq27541_cntl_cmd(di, BQ27541_SUBCMD_CTNL_STATUS); udelay(66); bq27541_read(BQ27541_REG_CNTL, &flags, 0, di); bq27541_cntl_cmd(di, BQ27541_SUBCMD_DEVCIE_TYPE); udelay(66); bq27541_read(BQ27541_REG_CNTL, &type, 0, di); bq27541_cntl_cmd(di, BQ27541_SUBCMD_FW_VER); udelay(66); bq27541_read(BQ27541_REG_CNTL, &fw_ver, 0, di); dev_info(di->dev, "DEVICE_TYPE is 0x%02X, FIRMWARE_VERSION is 0x%02X\n", type, fw_ver); dev_info(di->dev, "Complete bq27541 configuration 0x%02X\n", flags); }
static ssize_t bq27541_read_subcmd(struct device *dev, struct device_attribute *attr, char *buf) { int ret; int temp = 0; struct platform_device *client; struct bq27541_device_info *di; client = to_platform_device(dev); di = platform_get_drvdata(client); if (subcmd == BQ27541_SUBCMD_DEVCIE_TYPE || subcmd == BQ27541_SUBCMD_FW_VER || subcmd == BQ27541_SUBCMD_HW_VER || subcmd == BQ27541_SUBCMD_CHEM_ID) { bq27541_cntl_cmd(di, subcmd); /* Retrieve Chip status */ udelay(66); ret = bq27541_read(BQ27541_REG_CNTL, &temp, 0, di); if (ret) ret = snprintf(buf, PAGE_SIZE, "Read Error!\n"); else ret = snprintf(buf, PAGE_SIZE, "0x%02x\n", temp); } else ret = snprintf(buf, PAGE_SIZE, "Register Error!\n"); return ret; }
static int bq27541_battery_remove(struct i2c_client *client) { struct bq27541_device_info *di = i2c_get_clientdata(client); msm_battery_gauge_unregister(&bq27541_batt_gauge); bq27541_cntl_cmd(di, BQ27541_SUBCMD_DISABLE_DLOG); udelay(66); bq27541_cntl_cmd(di, BQ27541_SUBCMD_DISABLE_IT); cancel_delayed_work_sync(&di->hw_config); kfree(di->bus); mutex_lock(&battery_mutex); idr_remove(&battery_id, di->id); mutex_unlock(&battery_mutex); kfree(di); return 0; }
static void bq27541_hw_config(struct work_struct *work) { int ret = 0, flags = 0, type = 0, fw_ver = 0; struct bq27541_device_info *di; di = container_of(work, struct bq27541_device_info, hw_config.work); ret = bq27541_chip_config(di); if (ret) { dev_err(di->dev, "Failed to config Bq27541\n"); #ifdef CONFIG_MACH_OPPO di->retry_count--; if (di->retry_count > 0) { schedule_delayed_work(&di->hw_config, HZ); } #endif return; } #ifdef CONFIG_MACH_OPPO qpnp_battery_gauge_register(&bq27541_batt_gauge); #else msm_battery_gauge_register(&bq27541_batt_gauge); #endif bq27541_cntl_cmd(di, BQ27541_SUBCMD_CTNL_STATUS); udelay(66); bq27541_read(BQ27541_REG_CNTL, &flags, 0, di); bq27541_cntl_cmd(di, BQ27541_SUBCMD_DEVCIE_TYPE); udelay(66); bq27541_read(BQ27541_REG_CNTL, &type, 0, di); bq27541_cntl_cmd(di, BQ27541_SUBCMD_FW_VER); udelay(66); bq27541_read(BQ27541_REG_CNTL, &fw_ver, 0, di); #ifdef CONFIG_MACH_OPPO di->is_authenticated = bq27541_authenticate(di->client); di->battery_type = bq27541_batt_type_detect(di->client); #endif dev_info(di->dev, "DEVICE_TYPE is 0x%02X, FIRMWARE_VERSION is 0x%02X\n", type, fw_ver); dev_info(di->dev, "Complete bq27541 configuration 0x%02X\n", flags); }
static int bq27541_chip_config(struct bq27541_device_info *di) { int flags = 0, ret = 0; bq27541_cntl_cmd(di, BQ27541_SUBCMD_CTNL_STATUS); udelay(66); ret = bq27541_read(BQ27541_REG_CNTL, &flags, 0, di); if (ret < 0) { dev_err(di->dev, "error reading register %02x ret = %d\n", BQ27541_REG_CNTL, ret); return ret; } udelay(66); bq27541_cntl_cmd(di, BQ27541_SUBCMD_ENABLE_IT); udelay(66); if (!(flags & BQ27541_CS_DLOGEN)) { bq27541_cntl_cmd(di, BQ27541_SUBCMD_ENABLE_DLOG); udelay(66); } return 0; }