int bq51221_set_voreg(struct i2c_client *client, int default_value)
{
	u8 data = 0;
	int ret = 0;
	int retry_cnt =0;
	union power_supply_propval value;
	struct bq51221_charger_data *charger = i2c_get_clientdata(client);

	return 0; // concept chagned, vout is always 5V

	if (charger->pdata->pad_mode == BQ51221_PAD_MODE_PMA) {
		pr_info("%s PMA MODE, do not set Voreg \n", __func__);
		return 0;
	}

	psy_do_property("battery", get,
				POWER_SUPPLY_PROP_CAPACITY, value);

	if ((value.intval >= charger->pdata->wireless_cc_cv) && !default_value)
		default_value = 1;

	if (default_value) {
		/* init VOREG with default value */
		ret = bq51221_reg_write(client, BQ51221_REG_CURRENT_REGISTER, 0x01);
		if(ret < 0) {
			while(retry_cnt++ < 3) {
				msleep(50);
				pr_debug("%s retry_cnt = %d, ret =%d \n",__func__, retry_cnt, ret);
				/* init VOREG with default value */
				ret = bq51221_reg_write(client, BQ51221_REG_CURRENT_REGISTER, 0x01);
				data = bq51221_reg_read(client, BQ51221_REG_CURRENT_REGISTER);
				if(ret >= 0) {
					pr_debug("%s VOREG = 0x%x \n", __func__, data);
					break;
				}
			}
		}
		data = bq51221_reg_read(client, BQ51221_REG_CURRENT_REGISTER);
		pr_info("%s VOREG = 0x%x 5.0V, cnt(%d)\n", __func__, data, retry_cnt);
	} else {
		ret = bq51221_reg_write(client, BQ51221_REG_CURRENT_REGISTER, 0x02);
		if(ret < 0) {
			while(retry_cnt++ < 3) {
				msleep(50);
				pr_debug("%s retry_cnt = %d, ret =%d \n",__func__, retry_cnt, ret);
				/* init VOREG with default value */
				ret = bq51221_reg_write(client, BQ51221_REG_CURRENT_REGISTER, 0x02);
				data = bq51221_reg_read(client, BQ51221_REG_CURRENT_REGISTER);
				if(ret >= 0) {
					pr_debug("%s VOREG = 0x%x \n", __func__, data);
					break;
				}
			}
		}
		data = bq51221_reg_read(client, BQ51221_REG_CURRENT_REGISTER);
		pr_info("%s VOREG = 0x%x 5.5V, cnt(%d)\n", __func__, data, retry_cnt);
	}
	return ret;
}
int bq51221_set_full_charge_info(struct i2c_client *client)
{
	int data = 0;
	int ret = 0, i = 0;
	int retry_cnt =0;

	pr_info("%s\n", __func__);

	for(i=0; i< 3; i++) {
		/* send cs100 */
		ret = bq51221_reg_write(client, BQ51221_REG_USER_HEADER, BQ51221_EPT_HEADER_CS100);
		ret = bq51221_reg_write(client, BQ51221_REG_PROP_PACKET_PAYLOAD, BQ51221_CS100_VALUE);

		if(ret < 0) {
			while(retry_cnt++ < 3) {
				msleep(50);
				pr_info("%s retry_cnt = %d, ret =%d \n",__func__, retry_cnt, ret);
				/* send cs100 */
				ret = bq51221_reg_write(client, BQ51221_REG_USER_HEADER, BQ51221_EPT_HEADER_CS100);
				ret = bq51221_reg_write(client, BQ51221_REG_PROP_PACKET_PAYLOAD, BQ51221_CS100_VALUE);

				if(ret >= 0)
					break;
			}
			return ret;
		}

		/* send end packet */
		data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);

		data &= !BQ51221_SEND_USER_PKT_DONE_MASK;
		ret = bq51221_reg_write(client, BQ51221_REG_MAILBOX, data);

		/* check packet error */
		data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
		data &= BQ51221_SEND_USER_PKT_ERR_MASK;
		data = data >> 5;

		pr_info("%s error pkt = 0x%x \n",__func__, data);

		if(data == BQ51221_PTK_ERR_NO_ERR) {
			pr_err("%s sent CS100!\n",__func__);
			ret = 1;
		} else {
			pr_err("%s can not send CS100! err pkt = 0x%x\n",__func__, data);
			ret = -1;
		}
		msleep(300);
	}
	return ret;
}
void bq51221_wireless_chg_init(struct i2c_client *client)
{
	int data = 0;
	union power_supply_propval value;
	struct bq51221_charger_data *charger = i2c_get_clientdata(client);

	pr_info("%s\n", __func__);

	psy_do_property("battery", get,
				POWER_SUPPLY_PROP_CAPACITY, value);
	/* init I limit(IOREG) */
	bq51221_reg_write(client, BQ51221_REG_CURRENT_REGISTER2, BQ51221_IOREG_100_VALUE);
	data = bq51221_reg_read(client, BQ51221_REG_CURRENT_REGISTER2);
	pr_info("%s IOREG = 0x%x \n", __func__, data);

	/* init CEP timing */

	/* init RCVD PWR */

	/* read pad mode */
	bq51221_get_pad_mode(client);

	pr_info("%s siop = %d \n" ,__func__, charger->pdata->siop_level );
	if ((value.intval < charger->pdata->wireless_cc_cv) &&
		(charger->pdata->pad_mode == BQ51221_PAD_MODE_WPC) &&
		(charger->pdata->siop_level == 100) &&
		!charger->pdata->default_voreg) {
		/* set VOREG set 5.5V*/
		bq51221_set_voreg(charger->client, 0);
	} else {
		/* init VOREG with default value */
		bq51221_set_voreg(charger->client, 1);
	}
}
int bq51221_set_over_temperuture_info(struct i2c_client *client)
{
	int pad_mode = 0;
	int data = 0;
	int ret = 0;

	pr_info("%s\n", __func__);

	/* read pad mode PMA = 1, WPC = 0 (Status bit)*/
	pad_mode = bq51221_reg_read(client, BQ51221_REG_INDICATOR);

	pr_info("%s pad_mode = %d \n", __func__,pad_mode);

	if(pad_mode > 0)
		pad_mode &= BQ51221_POWER_MODE_MASK;

	if(pad_mode) {
		pr_info("%s PMA MODE, send EOC \n", __func__);

		data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
		data |= BQ51221_SEND_EOC_MASK;
		ret = bq51221_reg_write(client, BQ51221_REG_MAILBOX, data);
	} else {
		pr_info("%s WPC MODE, send EPT-OT \n", __func__);

		ret = bq51221_reg_write(client, BQ51221_REG_USER_HEADER, BQ51221_EPT_HEADER_EPT);
		ret = bq51221_reg_write(client, BQ51221_REG_PROP_PACKET_PAYLOAD, BQ51221_EPT_CODE_OVER_TEMPERATURE);

		/* send end packet */
		data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
		data &= !BQ51221_SEND_USER_PKT_DONE_MASK;
		ret = bq51221_reg_write(client, BQ51221_REG_MAILBOX, data);

		/* check packet error */
		data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
		data &= BQ51221_SEND_USER_PKT_ERR_MASK;
		data = data >> 5;

		pr_info("%s error pkt = 0x%x \n",__func__, data);

		if(data != BQ51221_PTK_ERR_NO_ERR) {
			pr_err("%s can not send CS100! err pkt = 0x%x\n",__func__, data);
			ret = -1;
		}
	}
	return ret;
}
static void bq51221_charger_shutdown(struct i2c_client *client)
{
	struct bq51221_charger_data *charger = i2c_get_clientdata(client);
	int data = 0;

	if(charger->pdata->pad_mode != BQ51221_PAD_MODE_NONE) {
		/* init VOREG set 5.0V*/
		bq51221_reg_write(client, BQ51221_REG_CURRENT_REGISTER, 0x01);
		data = bq51221_reg_read(client, BQ51221_REG_CURRENT_REGISTER);
		pr_info("%s VOREG = 0x%x \n", __func__, data);
	}
}
static int bq51221_get_pad_mode(struct i2c_client *client)
{
	int ret = 0;
	int retry_cnt =0;
	struct bq51221_charger_data *charger = i2c_get_clientdata(client);

	if(charger->pdata->pad_mode != BQ51221_PAD_MODE_NONE) {
		/* read pad mode PMA = 1, WPC = 0 (Status bit)*/
		ret = bq51221_reg_read(client, BQ51221_REG_INDICATOR);
		if(ret < 0) {
			while(retry_cnt++ < 3) {
				msleep(50);
				pr_info("%s retry_cnt = %d, ret =%d \n",__func__, retry_cnt, ret);
				/* read pad mode PMA = 1, WPC = 0 (Status bit)*/
				ret = bq51221_reg_read(client, BQ51221_REG_INDICATOR);
				if(ret >= 0)
					break;
			}
		}
		pr_info("%s pad_mode = %d \n", __func__,ret);

		if(ret >= 0) {
			ret &= BQ51221_POWER_MODE_MASK;

			if(ret == 0)
				charger->pdata->pad_mode = BQ51221_PAD_MODE_WPC;
			else if (ret == 1)
				charger->pdata->pad_mode = BQ51221_PAD_MODE_PMA;
			else
				charger->pdata->pad_mode = BQ51221_PAD_MODE_WPC;
		}
		else
			ret = 0;
	}
	return ret;
}
void bq51221_wireless_chg_init(struct i2c_client *client)
{
	int data = 0;
	union power_supply_propval value;

	pr_info("%s\n", __func__);

	psy_do_property("battery", get,
				POWER_SUPPLY_PROP_CAPACITY, value);
	/* init I limit(IOREG) */
	bq51221_reg_write(client, BQ51221_REG_CURRENT_REGISTER2, BQ51221_IOREG_100_VALUE);
	data = bq51221_reg_read(client, BQ51221_REG_CURRENT_REGISTER2);
	pr_info("%s IOREG = 0x%x \n", __func__, data);

	/* init CEP timing */

	/* init RCVD PWR */

	/* read pad mode */
	bq51221_get_pad_mode(client);
}
int bq51221_set_end_power_transfer(struct i2c_client *client, int ept_mode)
{

	int pad_mode = 0;
	int data = 0;
	int ret = 0;

	pr_info("%s\n", __func__);

	switch(ept_mode)
	{
		case END_POWER_TRANSFER_CODE_OVER_TEMPERATURE:
			/* read pad mode PMA = 1, WPC = 0 (Status bit)*/
			pad_mode = bq51221_reg_read(client, BQ51221_REG_INDICATOR);
			pr_info("%s pad_mode = %d \n", __func__,pad_mode);

			if(pad_mode > 0)
				pad_mode &= BQ51221_POWER_MODE_MASK;

			if(pad_mode) {
				pr_info("%s PMA MODE, send EOC \n", __func__);

				data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
				data |= BQ51221_SEND_EOC_MASK;
				ret = bq51221_reg_write(client, BQ51221_REG_MAILBOX, data);
			} else {
				pr_info("%s WPC MODE, send EPT-OT \n", __func__);

				ret = bq51221_reg_write(client, BQ51221_REG_USER_HEADER, BQ51221_EPT_HEADER_EPT);
				ret = bq51221_reg_write(client, BQ51221_REG_PROP_PACKET_PAYLOAD, BQ51221_EPT_CODE_OVER_TEMPERATURE);

				/* send end packet */
				data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
				data &= !BQ51221_SEND_USER_PKT_DONE_MASK;
				ret = bq51221_reg_write(client, BQ51221_REG_MAILBOX, data);

				/* check packet error */
				data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
				data &= BQ51221_SEND_USER_PKT_ERR_MASK;
				data = data >> 5;

				pr_info("%s error pkt = 0x%x \n",__func__, data);

				if(data != BQ51221_PTK_ERR_NO_ERR) {
					pr_err("%s can not send ept! err pkt = 0x%x\n",__func__, data);
					ret = -1;
				}
			}
			break;
		case END_POWER_TRANSFER_CODE_RECONFIGURE:
			pr_info("%s send EPT-Reconfigure \n", __func__);

			ret = bq51221_reg_write(client, BQ51221_REG_USER_HEADER, BQ51221_EPT_HEADER_EPT);
			ret = bq51221_reg_write(client, BQ51221_REG_PROP_PACKET_PAYLOAD, BQ51221_EPT_CODE_RECONFIGURE);

			/* send end packet */
			data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
			data &= !BQ51221_SEND_USER_PKT_DONE_MASK;
			ret = bq51221_reg_write(client, BQ51221_REG_MAILBOX, data);

			/* check packet error */
			data = bq51221_reg_read(client, BQ51221_REG_MAILBOX);
			data &= BQ51221_SEND_USER_PKT_ERR_MASK;
			data = data >> 5;

			pr_info("%s error pkt = 0x%x \n",__func__, data);

			if(data != BQ51221_PTK_ERR_NO_ERR) {
				pr_err("%s can not send ept! err pkt = 0x%x\n",__func__, data);
				ret = -1;
			}
			break;
		default:
			pr_info("%s this ept mode is not reserved \n",__func__);
			ret = -1;
			break;
	}

	return ret;
}