static int pinctrl_init(struct i2c_client *client)
{
    struct lge_touch_data *ts = i2c_get_clientdata(client);

    /* Get pinctrl if target uses pinctrl */
    ts->ts_pinctrl = devm_pinctrl_get(&(client->dev));
    if (IS_ERR(ts->ts_pinctrl)) {
        if (PTR_ERR(ts->ts_pinctrl) == -EPROBE_DEFER) {
            LGTC_ERR("ts_pinctrl == -EPROBE_DEFER\n");
            return -EPROBE_DEFER;
        }
        LGTC_DBG("Target does not use pinctrl(ts->ts_pinctrl == NULL) \n");
        ts->ts_pinctrl = NULL;
    }

    if (ts->ts_pinctrl) {
        ts->ts_pinset_state_active = pinctrl_lookup_state(ts->ts_pinctrl, "pmx_ts_active");
        if (IS_ERR(ts->ts_pinset_state_active))
            LGTC_DBG("cannot get ts pinctrl active state\n");

        ts->ts_pinset_state_suspend = pinctrl_lookup_state(ts->ts_pinctrl, "pmx_ts_suspend");
        if (IS_ERR(ts->ts_pinset_state_suspend))
            LGTC_DBG("cannot get ts pinctrl active state\n");

        if (ts->ts_pinset_state_active) {
            DO_SAFE(pinctrl_select_state(ts->ts_pinctrl, ts->ts_pinset_state_active), error);
        } else {
            LGTC_DBG("pinctrl active == NULL \n");
        }
    }

    return NO_ERROR;
error:
    return ERROR;
}
enum error_type ext_watch_set_position(struct spi_device *spi, struct ext_watch_cfg *cfg)
{
	u8 *ptr = (u8 *)(&cfg->position);	

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

	DO_SAFE(sic_spi_write(spi, EXT_WATCH_POSITION, ptr, sizeof(u32) * 5), error);
	#if 0
	TOUCH_I("Set Hour Position [%d][%d] \n",
		cfg->position.h10x_pos, cfg->position.h1x_pos);
	TOUCH_I("Set Min Position [%d][%d] \n",
		cfg->position.m10x_pos, cfg->position.m1x_pos);
	TOUCH_I("Set Colon Position [%d] \n", cfg->position.clx_pos);
	TOUCH_I("Set Zero Display [%d] \n", cfg->position.zero_disp);
	TOUCH_I("Set 24H Mode [%d] \n", cfg->position.h24_en);
	TOUCH_I("Set Display Mode [%d] \n", cfg->position.clock_disp_mode);
	TOUCH_I("Set Clock Mode [%d] \n", cfg->position.clock_disp_mode);
	TOUCH_I("Set Blink period [%d] \n", cfg->position.bhprd);
	#endif

	return NO_ERROR;
error:
	TOUCH_I("%s Fail \n", __func__);
	return ERROR;
}
/* Function to handle report reads based on user input*/
int ReadReport(unsigned char input, char *buf)
{
	int ret = 0;
	unsigned char data;

	/*Set the GetReport bit to run the AutoScan*/
	data = 0x01;
	DO_SAFE(Write8BitRegisters(F54CommandBase, &data, 1), error);
	
	count = 0;
	do {
		DO_SAFE(Read8BitRegisters(F54CommandBase, &data, 1), error);
		msleep(1);
		count++;
	} while (data != 0x00 && (count < DefaultTimeout));
	if (count >= DefaultTimeout) {
		TOUCH_LOG("Timeout - Not supported Report Type in FW\n");
		Reset();
		return -EAGAIN;
	}

	do_gettimeofday(&t_interval[ENDTIME]);

	TOUCH_LOG("Takes %lu ticks\n",
			get_time_interval(t_interval[ENDTIME].tv_sec,
				t_interval[STARTTIME].tv_sec));

	switch (input) {
	case 'p':
		ret = ReadRT78(buf);
		break;
    case 'q':
		ret = GetImageRT78(buf);
		break;
    case 'r':
		ret = ReadElectodeShortRT78(buf);
		break;
	default:
		break;
	}

	return ret;

error:
	TOUCH_ERR("[%s] ReadReport fail\n", __func__);
	return -EAGAIN;
}
/* ext_watch_set_onoff
 *
 * 'power state' can has only 'ON' or 'OFF'. (not 'SLEEP' or 'WAKE') 
 */
enum error_type ext_watch_onoff(struct spi_device *spi, u32 onoff)
{
	TOUCH_I("%s %d\n", __func__, onoff);

	DO_SAFE(sic_spi_write(spi, EXT_WATCH_RTC_CTRL,
			(u8 *)&onoff, sizeof(u32)), error);

	return NO_ERROR;
error:
	TOUCH_I("%s Fail \n", __func__);
	return ERROR;
}
enum error_type ext_watch_font_dump(struct spi_device *spi, char *font_dump)
{
	u32 font_sel = 0;
	u32 font_data_offset = 0;
	u32 wdata = 0;
	u32 size = 0;

	TOUCH_I("%s start\n", __func__);
	// Font memory access enable
	wdata = 1;
	DO_SAFE(sic_spi_write(spi, EXT_WATCH_FONT_ACC_EN,
		(u8 *)&wdata, sizeof(u32)), error);

	size = sizeof(u32) * EXT_WATCH_FONT_NUM_SIZE;

	for (font_sel = 0; font_sel < 10; font_sel++) {
		// Font select : '0' ~ '9'
		font_data_offset = font_sel * size;
		DO_SAFE(sic_spi_font_read(spi, (u8 *)&font_sel,
			font_dump+font_data_offset, size), error);
	}

	// Font select : ':'
	font_data_offset = font_sel * size;
	size = sizeof(u32) * EXT_WATCH_FONT_CHAR_SIZE;
	DO_SAFE(sic_spi_font_read(spi, (u8 *)&font_sel,
		font_dump+font_data_offset, size), error);

	// Font memory access disable
	wdata = 0;
	DO_SAFE(sic_spi_write(spi, EXT_WATCH_FONT_ACC_EN,
		(u8 *)&wdata, sizeof(u32)), error);

	TOUCH_I("%s done\n", __func__);
	return NO_ERROR;

error:
	TOUCH_I("%s Fail\n", __func__);
	return ERROR;
}
enum error_type ext_watch_get_position(struct spi_device *spi, struct ext_watch_cfg *cfg)
{
	u8 *ptr = (u8 *)(&cfg->position);
	struct ext_watch_status_cfg status_cfg;

	TOUCH_I("%s start \n", __func__);

	DO_SAFE(sic_spi_read(spi, EXT_WATCH_POSITION_R, ptr, sizeof(u32) * 3), error);
	TOUCH_I("Get Hour Position [%d][%d] \n",
		cfg->position.h10x_pos, cfg->position.h1x_pos);
	TOUCH_I("Get Min Position [%d][%d] \n",
		cfg->position.m10x_pos, cfg->position.m1x_pos);
	TOUCH_I("Get Colon Position [%d] \n", cfg->position.clx_pos);

	DO_SAFE(sic_spi_read(spi, EXT_WATCH_SATATE, (u8 *)&status_cfg, sizeof(u32)), error);
	cfg->position.zero_disp = status_cfg.zero_en;
	cfg->position.h24_en = status_cfg.en_24;
	cfg->position.clock_disp_mode = status_cfg.disp_mode;
	cfg->position.bhprd = status_cfg.bhprd;

	TOUCH_I("Get Zero Display [%d] \n", cfg->position.zero_disp);
	TOUCH_I("Get 24H Mode [%d] \n", cfg->position.h24_en);
	TOUCH_I("Get Clock Mode [%d] \n", cfg->position.clock_disp_mode);
	TOUCH_I("Get Blink period [%d] \n", cfg->position.bhprd);
	TOUCH_I("Get Current Watch[%d] \n", status_cfg.step);
	TOUCH_I("Get Watch Enable[%d] \n", status_cfg.en);

	if ( cfg->position.clock_disp_mode )
		TOUCH_I("Get Current Time[%02d][%02d] \n",
			status_cfg.cur_min, status_cfg.cur_sec);
	else
		TOUCH_I("Get Current Time[%02d][%02d][%03d] \n", status_cfg.cur_hour,
			status_cfg.cur_min, cfg->time.rtc_sctcnt);

	return NO_ERROR;
error:
	TOUCH_I("%s Fail \n", __func__);
	return ERROR;
}
enum error_type ext_watch_get_current_time(struct spi_device *spi, struct ext_watch_cfg *cfg)
{
	DO_SAFE(sic_spi_read(spi, EXT_WATCH_RTC_CTST,
		(u8 *)&cfg->time.rtc_ctst, sizeof(u32)), error);

	TOUCH_I("%s : %02d:%02d:%02d\n", __func__,
		cfg->time.rtc_ctst.hour, cfg->time.rtc_ctst.min, cfg->time.rtc_ctst.sec);

	return NO_ERROR;

error:
	TOUCH_I("%s Fail \n", __func__);
	return ERROR;
}
static error_type ReadChCount(struct synaptics_ts_data *ts)
{
	u8 data[64] = {0};
	u8 rx_max_cnt = 0;
	u8 tx_max_cnt = 0;
	int i;

	RxChNum = TxChNum = 0;

	/*Read channel count*/
	touch_i2c_read(ts->client, RX_CH_CNT_REG, 1, &rx_max_cnt);
	touch_i2c_read(ts->client, TX_CH_CNT_REG, 1, &tx_max_cnt);

	DO_SAFE(touch_i2c_write_byte(ts->client, PAGE_SELECT_REG, ts->sensor_fc.function_page), error);

	touch_i2c_read(ts->client, ts->sensor_fc.dsc.data_base+1, rx_max_cnt, data);

	for (i = 0; i < (int)rx_max_cnt; i++) {
		if (data[i] != 0xFF)
			RxChNum++;
	}

	touch_i2c_read(ts->client, ts->sensor_fc.dsc.data_base+2, tx_max_cnt, data);

	for (i = 0; i < (int)tx_max_cnt; i++) {
		if (data[i] != 0xFF)
			TxChNum++;
	}

	LGTC_DBG("rx ch cnt = %d, tx ch cnt = %d\n", RxChNum, TxChNum);

	DO_SAFE(touch_i2c_write_byte(ts->client, PAGE_SELECT_REG, ts->analog_fc.function_page), error);

	return NO_ERROR;
error:
	return ERROR;
}
enum error_type ext_watch_set_current_time(struct spi_device *spi, struct ext_watch_cfg *cfg)
{
	u32 rtc_ctrl = EXT_WATCH_RTC_STOP;
	u16 rtc_count = 305;		/* for time, 1 /rtc_ecnt */


	cfg->time.rtc_ecnt = 32764;
	cfg->time.rtc_sctcnt = (int)((cfg->time.rtc_sctcnt * rtc_count) / 10);

	DO_SAFE(sic_spi_write(spi, EXT_WATCH_RTC_RUN,
		(u8 *)&rtc_ctrl, sizeof(u32)), error);

	DO_SAFE(sic_spi_write(spi, EXT_WATCH_RTC_SCT,
		(u8 *)&cfg->time.rtc_sct, sizeof(u32)), error);

	DO_SAFE(sic_spi_write(spi, EXT_WATCH_RTC_SCTCNT,
		(u8 *)&cfg->time.rtc_sctcnt, sizeof(u32)), error);

	rtc_ctrl = cfg->time.rtc_ecnt & 0xFFFF;
	DO_SAFE(sic_spi_write(spi, EXT_WATCH_RTC_ECNT,
		(u8 *)&rtc_ctrl, sizeof(u32)), error);

	rtc_ctrl = EXT_WATCH_RTC_START;
	DO_SAFE(sic_spi_write(spi, EXT_WATCH_RTC_RUN,
		(u8 *)&rtc_ctrl, sizeof(u32)), error);

	TOUCH_I("%s : %02d:%02d:%02d CLK[%d Hz]\n", __func__,
		cfg->time.rtc_sct.hour, cfg->time.rtc_sct.min,
		cfg->time.rtc_sct.sec, cfg->time.rtc_ecnt);

	return NO_ERROR;

error:
	TOUCH_I("%s Fail \n", __func__);
	return ERROR;
}
static int ext_watch_set_mcs_ctrl(struct spi_device *spi, u8 enable)
{
	u8 mcs_value = 0;

	if (enable)
		mcs_value = 0xAC;
	else
		mcs_value = 0xCA;

	DO_SAFE(sic_spi_write(spi, EXT_WATCH_MCS_ACCESS, (u8 *)&mcs_value, sizeof(u8)), error);
	//TOUCH_I("MCS Access onoff : %X  \n", mcs_value);
	return NO_ERROR;
error:
	TOUCH_E("MCS Access Fail\n");
	return ERROR;
}
/* ext_watch_shutdown
 *
 * 'power state' can has only  'SLEEP' or 'WAKE' (not 'ON' or 'OFF')
 */
enum error_type ext_watch_shutdown(struct spi_device *spi, u8 onoff)
{
	u32 rtc_ctrl = EXT_WATCH_RTC_STOP;
	TOUCH_I("%s start \n", __func__ );

	if ( onoff == EXT_WATCH_RTC_START )
		rtc_ctrl = EXT_WATCH_RTC_START;

	DO_SAFE(sic_spi_write(spi, EXT_WATCH_RTC_RUN,
		(u8 *)&rtc_ctrl, sizeof(u32)), error);

	return NO_ERROR;
error:
	TOUCH_I("%s Fail \n", __func__);
	return ERROR;

}
enum error_type ext_watch_get_mode(struct spi_device *spi, struct ext_watch_cfg *cfg)
{
	u8 *ptr = NULL;
	u16 offset = EXT_WATCH_CTRL;
	u16 idx = 0;
	u32 size = sizeof(u8);

	TOUCH_I("%s start \n", __func__);

	ext_watch_set_mcs_ctrl(spi, EXT_WATCH_MCS_ENABLE);
	
	ptr = (u8 *)(&cfg->mode.watch_ctrl);
	offset = EXT_WATCH_CTRL;
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[0], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[1], size), error);
	TOUCH_I("Get Offet[%X] watch_ctrl %02X %02X\n",
		EXT_WATCH_CTRL, ptr[0], ptr[1]);

	ptr = (u8 *)(&cfg->mode.watch_area);
	offset = EXT_WATCH_AREA;
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[0], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[1], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[2], size), error);
	TOUCH_I("Get Offet[%X] watch_area %02X %02X %02X\n",
		EXT_WATCH_AREA, ptr[0], ptr[1], ptr[2]);

	ptr = (u8 *)(&cfg->mode.blink_area);
	offset = EXT_WATCH_BLINK_AREA;
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[0], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[1], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[2], size), error);
	TOUCH_I("Get Offet[%X] blink_area %02X %02X %02X\n",
		EXT_WATCH_BLINK_AREA, ptr[0], ptr[1], ptr[2]);

	ptr = (u8 *)(&cfg->mode.grad);
	offset = EXT_WATCH_GRAD;
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[0], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[1], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[2], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[3], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[4], size), error);
	DO_SAFE(sic_spi_read(spi,  offset++, &ptr[5], size), error);
	TOUCH_I("Get Offet[%X] grad %02X %02X %02X %02X %02X %02X\n",
		EXT_WATCH_GRAD, ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);

	offset = EXT_WATCH_LUT;
	for (idx = 0; idx < EXT_WATCH_LUT_NUM; idx++) {
		ptr = (u8 *)(&cfg->mode.lut[idx]);
		DO_SAFE(sic_spi_read(spi,  offset++, &ptr[0], size), error);
		DO_SAFE(sic_spi_read(spi,  offset++, &ptr[1], size), error);
		DO_SAFE(sic_spi_read(spi,  offset++, &ptr[2], size), error);
		TOUCH_I("Get Offet[%X] LUT[%d] : B[%02X] G[%02X] R[%02X] \n",
			offset - 3, idx, ptr[0],ptr[1],ptr[2]);
	}

	ext_watch_set_mcs_ctrl(spi, EXT_WATCH_MCS_DISABLE);
	TOUCH_I("%s end \n", __func__);
	return NO_ERROR;
	
error:
	TOUCH_I("%s failed \n", __func__);
	return ERROR;
}