static int max17048_masked_write_word(struct i2c_client *client, int reg, u16 mask, u16 val) { s32 rc; u16 temp; temp = max17048_read_word(client, reg); if (temp < 0) { pr_err("max17048_read_word failed: reg=%03X, rc=%d\n", reg, temp); return temp; } if ((temp & mask) == (val & mask)) return 0; temp &= ~mask; temp |= val & mask; rc = max17048_write_word(client, reg, temp); if (rc) { pr_err("max17048_write_word failed: reg=%03X, rc=%d\n", reg, rc); return rc; } return 0; }
static void max17048_get_vcell(struct i2c_client *client) { struct max17048_chip *chip = i2c_get_clientdata(client); int vcell; vcell = max17048_read_word(client, MAX17048_VCELL); if (vcell < 0) dev_err(&client->dev, "%s: err %d\n", __func__, vcell); else chip->vcell = (uint16_t)vcell; g_max17048_chip->vcell = chip->vcell; }
static int get_reg(void *data, u64 *val) { u32 addr = (u32) data; int ret; struct i2c_client *client = ref->client; ret = max17048_read_word(client, addr); if (ret < 0) return ret; *val = ret; return 0; }
static int max17048_get_status(struct i2c_client *client) { struct max17048_chip *chip = i2c_get_clientdata(client); int status; status = max17048_read_word(client, MAX17048_STATUS); if (status < 0) { dev_err(&client->dev, "%s: err %d\n", __func__, status); return status; } else { printk(KERN_ERR "%s : status = 0x%x\n", __func__, status); chip->status = status; return 0; } }
static int max17048_get_config(struct i2c_client *client) { struct max17048_chip *chip = i2c_get_clientdata(client); int config; config = max17048_read_word(client, MAX17048_CONFIG); if (config < 0) { dev_err(&client->dev, "%s: err %d\n", __func__, config); return config; } else { printk(KERN_ERR "%s : config = 0x%x\n", __func__, config); chip->config = config; return 0; } }
static int max17048_get_vcell(struct max17048_chip *chip) { int vcell; vcell = max17048_read_word(chip->client, VCELL_REG); if (vcell < 0) { pr_err("%s: err %d\n", __func__, vcell); return vcell; } else { chip->vcell = vcell >> 4; chip->voltage = (chip->vcell * 5) >> 2; } return 0; }
static int max17048_get_soc(struct max17048_chip *chip) { int soc; soc = max17048_read_word(chip->client, SOC_REG); if (soc < 0) { pr_err("%s: err %d\n", __func__, soc); return soc; } else { chip->soc = soc; chip->capacity_level = max17048_get_capacity_from_soc(chip); } return 0; }
static void max17048_get_soc(struct i2c_client *client) { struct max17048_chip *chip = i2c_get_clientdata(client); struct max17048_battery_model *mdata = chip->model_data; int soc; soc = max17048_read_word(client, MAX17048_SOC); if (soc < 0) dev_err(&client->dev, "%s: err %d\n", __func__, soc); else { if(batt_id==2) mdata->bits = 18; if (mdata->bits == 19) chip->soc = (uint16_t)soc >> 9; else if (mdata->bits == 18) chip->soc = (uint16_t)soc >> 8; }
static uint16_t max17048_get_version(struct max17048_chip *chip) { return (uint16_t) max17048_read_word(chip->client, VERSION_REG); }