Пример #1
0
void max17047_set_rcomp(struct i2c_client *client, int state)
{
	u8 rst_cmd[2];

	if (state) {
		rst_cmd[1] = 0x00;
#if defined(CONFIG_MACH_GC1_USA_VZW)
		rst_cmd[0] = 0xC1;
#elif defined(CONFIG_MACH_GD2)
		rst_cmd[0] = 0x70;
#elif defined(CONFIG_GC2PD_LTE) || defined(CONFIG_MACH_GC2PD)
		rst_cmd[0] = 0x6A;
#else/*GC1 default*/
		rst_cmd[0] = 0xCF;
#endif
	} else {
		rst_cmd[1] = 0x00;
#if defined(CONFIG_MACH_GC1_USA_VZW)
		rst_cmd[0] = 0x8D;
#elif defined(CONFIG_MACH_GD2)
		rst_cmd[0] = 0x54;
#elif defined(CONFIG_GC2PD_LTE) || defined(CONFIG_MACH_GC2PD)
		rst_cmd[0] = 0x60;
#else/*GC1 default*/
		rst_cmd[0] = 0x8F;
#endif
	}

	max17047_i2c_write(client, MAX17047_REG_RCOMP, rst_cmd);
	pr_info("%s: state = %d\n", __func__, state);
}
Пример #2
0
static void max17047_reset_soc(struct i2c_client *client)
{
	struct max17047_fuelgauge_data *fg_data =
				i2c_get_clientdata(client);
	u8 data[2];
	pr_info("%s: Before quick-start - "
		"VFOCV(%d), VFSOC(%d), SOC(%d)\n", __func__,
				max17047_get_vfocv(client),
				max17047_get_rawsoc(client),
				max17047_get_soc(client));
	max17047_test_read(fg_data);

	if (max17047_i2c_read(client, MAX17047_REG_MISCCFG, data) < 0)
		return;

	/* Set bit10 makes quick start */
	data[1] |= (0x1 << 2);
	max17047_i2c_write(client, MAX17047_REG_MISCCFG, data);

	msleep(500);

	pr_info("%s: After quick-start - "
		"VFOCV(%d), VFSOC(%d), SOC(%d)\n", __func__,
				max17047_get_vfocv(client),
				max17047_get_rawsoc(client),
				max17047_get_soc(client));
	max17047_test_read(fg_data);

	return;
}
Пример #3
0
static void max17047_reg_init(struct max17047_fuelgauge_data *fg_data)
{
	struct i2c_client *client = fg_data->client;
	u8 i2c_data[2];
	pr_debug("%s\n", __func__);

	i2c_data[1] = 0x00;
	i2c_data[0] = 0x00;
	max17047_i2c_write(client, MAX17047_REG_CGAIN, i2c_data);

	i2c_data[1] = 0x00;
	i2c_data[0] = 0x03;
	max17047_i2c_write(client, MAX17047_REG_MISCCFG, i2c_data);

	i2c_data[1] = 0x07;
	i2c_data[0] = 0x00;
	max17047_i2c_write(client, MAX17047_REG_LEARNCFG, i2c_data);
}
static int max17047_alert_init(struct max17047_fuelgauge_data *fuelgauge_data)
{
	struct i2c_client *client = fuelgauge_data->client;
	u8 i2c_data[2];
	u16 i2c_w_data;
	pr_debug("%s\n", __func__);

	/* SALRT Threshold setting */
	i2c_data[1] = 0xFF;	/* disable high alert */
	i2c_data[0] = 0x01;	/* 1% low alert*/
	max17047_i2c_write(client, MAX17047_REG_SALRT_TH, i2c_data);

	/* Reset VALRT Threshold setting (disable) */
	i2c_data[1] = 0xFF;
	i2c_data[0] = 0x00;
	max17047_i2c_write(client, MAX17047_REG_VALRT_TH, i2c_data);
	max17047_i2c_read(client, MAX17047_REG_VALRT_TH, i2c_data);
	i2c_w_data = (i2c_data[1] << 8) | (i2c_data[0]);
	if (i2c_w_data != 0xff00)
		pr_err("%s: MAX17047_REG_VALRT_TH is not valid (0x%x)\n",
							__func__, i2c_w_data);

	/* Reset TALRT Threshold setting (disable) */
	i2c_data[1] = 0x7F;
	i2c_data[0] = 0x80;
	max17047_i2c_write(client, MAX17047_REG_TALRT_TH, i2c_data);
	max17047_i2c_read(client, MAX17047_REG_TALRT_TH, i2c_data);
	i2c_w_data = (i2c_data[1] << 8) | (i2c_data[0]);
	if (i2c_w_data != 0x7F80)
		pr_err("%s: MAX17047_REG_TALRT_TH is not valid (0x%x)\n",
							__func__, i2c_w_data);

	mdelay(100);

	/* Enable SOC alerts */
	max17047_i2c_read(client, MAX17047_REG_CONFIG, i2c_data);
	i2c_data[0] = i2c_data[0] | (0x1 << 2);
	max17047_i2c_write(client, MAX17047_REG_CONFIG, i2c_data);

	return 1;
}
Пример #5
0
void max17047_set_rcomp(struct i2c_client *client, int state)
{
	u8 rst_cmd[2];

	if (state) {
		rst_cmd[1] = 0x00;
		rst_cmd[0] = 0xCF;
	} else {
		rst_cmd[1] = 0x00;
		rst_cmd[0] = 0x8F;
	}

	max17047_i2c_write(client, MAX17047_REG_RCOMP, rst_cmd);
	pr_info("%s: state = %d\n", __func__, state);
}
Пример #6
0
/* Voltage alert, disabled(0xFF00) */
static void max17047_set_valrt(struct max17047_fuelgauge_data *fg_data,
								u8 min, u8 max)
{
	struct i2c_client *client = fg_data->client;
	u8 i2c_data[2];
	pr_info("%s: min(%dmV), max(%dmV)\n", __func__, min * 20, max * 20);

	i2c_data[1] = max;
	i2c_data[0] = min;
	max17047_i2c_write(client, MAX17047_REG_VALRT_TH, i2c_data);

	max17047_i2c_read(client, MAX17047_REG_VALRT_TH, i2c_data);
	if ((i2c_data[0] != min) || (i2c_data[1] != max))
		pr_err("%s: VALRT_TH is not valid (0x%02d%02d ? 0x%02d%02d)\n",
			__func__, i2c_data[1], i2c_data[0], max, min);
}
Пример #7
0
static int max17047_restore(struct device *dev)
{
	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
	struct max17047_fuelgauge_data *fg_data
						= i2c_get_clientdata(client);
	int i, j;

	if (!fg_data->reg_dump) {
		dev_err(dev, "Cannot allocate memory for hibernation dump.\n");
		return -ENOMEM;
	}

	for (i = 0, j = 0; i < ARRAY_SIZE(save_addr); i++, j += 2)
		max17047_i2c_write(client, save_addr[i]
					, &(fg_data->reg_dump[j]));

	kfree(fg_data->reg_dump);
	fg_data->reg_dump = NULL;

	return 0;
}
Пример #8
0
static void max17047_alert_init(struct max17047_fuelgauge_data *fg_data)
{
	struct i2c_client *client = fg_data->client;
	u8 i2c_data[2];
	pr_debug("%s\n", __func__);

	/* SALRT Threshold setting */
	/* min 1%, max disable */
	max17047_set_salrt(fg_data, 0x01, 0xFF);

	/* TALRT Threshold setting */
	/* min disable, max disable */
	max17047_set_talrt(fg_data, 0x80, 0x7F);

	/* VALRT Threshold setting */
	/* min disable, max disable */
	max17047_set_valrt(fg_data, 0x00, 0xFF);

	/* Enable SOC alerts */
	max17047_i2c_read(client, MAX17047_REG_CONFIG, i2c_data);
	i2c_data[0] |= (0x1 << 2);
	max17047_i2c_write(client, MAX17047_REG_CONFIG, i2c_data);
}
Пример #9
0
static void max17047_check_rcomp_update(struct i2c_client *client)
{
	u8 data[2];
	int ret, rcomp;

	/* read rcomp */
	ret = max17047_i2c_read(client, MAX17047_REG_RCOMP, data);
	if (ret < 0)
		return;

	rcomp = (data[1] << 8) | data[0];
	pr_info("%s: rcomp = 0x%04x\n", __func__, rcomp);

	/* check rcomp update */
	if (rcomp != MAX17047_NEW_RCOMP) {
		data[0] = MAX17047_NEW_RCOMP & 0xff;
		data[1] = MAX17047_NEW_RCOMP >> 8;
		max17047_i2c_write(client, MAX17047_REG_RCOMP, data);
		pr_info("%s: set new rcomp = 0x%04x\n",
				__func__, MAX17047_NEW_RCOMP);
		max17047_i2c_read(client, MAX17047_REG_RCOMP, data);
		rcomp = (data[1] << 8) | data[0];
		pr_info("%s: verify rcomp = 0x%04x\n", __func__, rcomp);
	}
Пример #10
0
static void max17047_reg_init(struct max17047_fuelgauge_data *fg_data)
{
	struct i2c_client *client = fg_data->client;
	u8 i2c_data[2];
	pr_debug("%s\n", __func__);


#if defined(CONFIG_BATTERY_SAMSUNG_S2PLUS)
	i2c_data[1] = 0x00;
	i2c_data[0] = 0x00;
	max17047_i2c_write(client, MAX17047_REG_CGAIN, i2c_data);

	i2c_data[1] = 0x00;
	i2c_data[0] = 0x03;
	max17047_i2c_write(client, MAX17047_REG_MISCCFG, i2c_data);

	i2c_data[1] = 0x00;
	i2c_data[0] = 0x07;
	max17047_i2c_write(client, MAX17047_REG_LEARNCFG, i2c_data);

	i2c_data[1] = 0x00;
	i2c_data[0] = 0x50;
	max17047_i2c_write(client, MAX17047_REG_RCOMP, i2c_data);
#else /* Use MG1 */
	i2c_data[1] = 0x00;
	i2c_data[0] = 0x00;
	max17047_i2c_write(client, MAX17047_REG_CGAIN, i2c_data);

	i2c_data[1] = 0x00;
	i2c_data[0] = 0x03;
	max17047_i2c_write(client, MAX17047_REG_MISCCFG, i2c_data);

	i2c_data[1] = 0x07;
	i2c_data[0] = 0x00;
	max17047_i2c_write(client, MAX17047_REG_LEARNCFG, i2c_data);
#endif
}