Lines Matching refs:ts
179 static int hideep_pgm_w_mem(struct hideep_ts *ts, u32 addr, in hideep_pgm_w_mem() argument
182 struct pgm_packet *packet = (void *)ts->xfer_buf; in hideep_pgm_w_mem()
185 .addr = ts->client->addr, in hideep_pgm_w_mem()
199 ret = i2c_transfer(ts->client->adapter, &msg, 1); in hideep_pgm_w_mem()
206 static int hideep_pgm_r_mem(struct hideep_ts *ts, u32 addr, in hideep_pgm_r_mem() argument
209 struct pgm_packet *packet = (void *)ts->xfer_buf; in hideep_pgm_r_mem()
213 .addr = ts->client->addr, in hideep_pgm_r_mem()
219 .addr = ts->client->addr, in hideep_pgm_r_mem()
233 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in hideep_pgm_r_mem()
240 static int hideep_pgm_r_reg(struct hideep_ts *ts, u32 addr, u32 *val) in hideep_pgm_r_reg() argument
245 error = hideep_pgm_r_mem(ts, addr, &data, 1); in hideep_pgm_r_reg()
247 dev_err(&ts->client->dev, in hideep_pgm_r_reg()
257 static int hideep_pgm_w_reg(struct hideep_ts *ts, u32 addr, u32 val) in hideep_pgm_w_reg() argument
262 error = hideep_pgm_w_mem(ts, addr, &data, 1); in hideep_pgm_w_reg()
264 dev_err(&ts->client->dev, in hideep_pgm_w_reg()
276 hideep_pgm_w_reg(ts, HIDEEP_SYSCON_WDT_CNT, (clk)); \
277 hideep_pgm_w_reg(ts, HIDEEP_SYSCON_WDT_CON, 0x03); \
282 hideep_pgm_w_mem(ts, HIDEEP_SYSCON_WDT_CON, &data, 1); \
286 hideep_pgm_w_reg(ts, HIDEEP_FLASH_CON, \
290 hideep_pgm_w_reg(ts, HIDEEP_FLASH_PIO_SIG + (x), (y))
293 hideep_pgm_w_reg(ts, HIDEEP_FLASH_CON, 0x00)
302 static void hideep_pgm_set(struct hideep_ts *ts) in hideep_pgm_set() argument
304 hideep_pgm_w_reg(ts, HIDEEP_SYSCON_WDT_CON, 0x00); in hideep_pgm_set()
305 hideep_pgm_w_reg(ts, HIDEEP_SYSCON_SPC_CON, 0x00); in hideep_pgm_set()
306 hideep_pgm_w_reg(ts, HIDEEP_SYSCON_CLK_ENA, 0xFF); in hideep_pgm_set()
307 hideep_pgm_w_reg(ts, HIDEEP_SYSCON_CLK_CON, 0x01); in hideep_pgm_set()
308 hideep_pgm_w_reg(ts, HIDEEP_SYSCON_PWR_CON, 0x01); in hideep_pgm_set()
309 hideep_pgm_w_reg(ts, HIDEEP_FLASH_TIM, 0x03); in hideep_pgm_set()
310 hideep_pgm_w_reg(ts, HIDEEP_FLASH_CACHE_CFG, 0x00); in hideep_pgm_set()
313 static int hideep_pgm_get_pattern(struct hideep_ts *ts, u32 *pattern) in hideep_pgm_get_pattern() argument
319 error = regmap_bulk_write(ts->reg, p1, &p2, 1); in hideep_pgm_get_pattern()
321 dev_err(&ts->client->dev, in hideep_pgm_get_pattern()
330 error = hideep_pgm_w_reg(ts, HIDEEP_ESI_TX_INVALID, 0x01); in hideep_pgm_get_pattern()
334 error = hideep_pgm_r_reg(ts, HIDEEP_SYSCON_PGM_ID, pattern); in hideep_pgm_get_pattern()
341 static int hideep_enter_pgm(struct hideep_ts *ts) in hideep_enter_pgm() argument
348 error = hideep_pgm_get_pattern(ts, &pattern); in hideep_enter_pgm()
350 dev_err(&ts->client->dev, in hideep_enter_pgm()
353 dev_err(&ts->client->dev, "%s: bad pattern: %#08x\n", in hideep_enter_pgm()
356 dev_dbg(&ts->client->dev, "found magic code"); in hideep_enter_pgm()
358 hideep_pgm_set(ts); in hideep_enter_pgm()
365 dev_err(&ts->client->dev, "failed to enter pgm mode\n"); in hideep_enter_pgm()
370 static int hideep_nvm_unlock(struct hideep_ts *ts) in hideep_nvm_unlock() argument
375 hideep_pgm_w_reg(ts, HIDEEP_FLASH_CFG, HIDEEP_NVM_SFR_RPAGE); in hideep_nvm_unlock()
376 error = hideep_pgm_r_reg(ts, 0x0000000C, &unmask_code); in hideep_nvm_unlock()
377 hideep_pgm_w_reg(ts, HIDEEP_FLASH_CFG, HIDEEP_NVM_DEFAULT_PAGE); in hideep_nvm_unlock()
385 if (unmask_code != ts->nvm_mask) in hideep_nvm_unlock()
386 dev_warn(&ts->client->dev, in hideep_nvm_unlock()
388 unmask_code, ts->nvm_mask); in hideep_nvm_unlock()
390 hideep_pgm_w_reg(ts, HIDEEP_FLASH_CFG, HIDEEP_NVM_SFR_WPAGE); in hideep_nvm_unlock()
393 NVM_W_SFR(HIDEEP_NVM_MASK_OFS, ts->nvm_mask); in hideep_nvm_unlock()
395 hideep_pgm_w_reg(ts, HIDEEP_FLASH_CFG, HIDEEP_NVM_DEFAULT_PAGE); in hideep_nvm_unlock()
400 static int hideep_check_status(struct hideep_ts *ts) in hideep_check_status() argument
407 error = hideep_pgm_r_reg(ts, HIDEEP_FLASH_STA, &status); in hideep_check_status()
417 static int hideep_program_page(struct hideep_ts *ts, u32 addr, in hideep_program_page() argument
423 error = hideep_check_status(ts); in hideep_program_page()
437 error = hideep_check_status(ts); in hideep_program_page()
447 hideep_pgm_w_mem(ts, HIDEEP_FLASH_PIO_SIG | HIDEEP_WRONLY, in hideep_program_page()
457 error = hideep_check_status(ts); in hideep_program_page()
466 static int hideep_program_nvm(struct hideep_ts *ts, in hideep_program_nvm() argument
469 struct pgm_packet *packet_r = (void *)ts->xfer_buf; in hideep_program_nvm()
476 error = hideep_nvm_unlock(ts); in hideep_program_nvm()
484 error = hideep_pgm_r_mem(ts, 0x00000000 + addr, in hideep_program_nvm()
487 dev_err(&ts->client->dev, in hideep_program_nvm()
495 error = hideep_program_page(ts, addr, in hideep_program_nvm()
498 dev_err(&ts->client->dev, in hideep_program_nvm()
515 static int hideep_verify_nvm(struct hideep_ts *ts, in hideep_verify_nvm() argument
518 struct pgm_packet *packet_r = (void *)ts->xfer_buf; in hideep_verify_nvm()
530 error = hideep_pgm_r_mem(ts, 0x00000000 + addr, in hideep_verify_nvm()
533 dev_err(&ts->client->dev, in hideep_verify_nvm()
545 dev_err(&ts->client->dev, in hideep_verify_nvm()
562 static int hideep_load_dwz(struct hideep_ts *ts) in hideep_load_dwz() argument
567 error = hideep_enter_pgm(ts); in hideep_load_dwz()
573 error = hideep_pgm_r_mem(ts, HIDEEP_DWZ_INFO, in hideep_load_dwz()
574 (void *)&ts->dwz_info, in hideep_load_dwz()
575 sizeof(ts->dwz_info) / sizeof(__be32)); in hideep_load_dwz()
581 dev_err(&ts->client->dev, in hideep_load_dwz()
586 product_code = be16_to_cpu(ts->dwz_info.product_code); in hideep_load_dwz()
590 dev_dbg(&ts->client->dev, "used crimson IC"); in hideep_load_dwz()
591 ts->fw_size = 1024 * 48; in hideep_load_dwz()
592 ts->nvm_mask = 0x00310000; in hideep_load_dwz()
595 dev_dbg(&ts->client->dev, "used lime IC"); in hideep_load_dwz()
596 ts->fw_size = 1024 * 64; in hideep_load_dwz()
597 ts->nvm_mask = 0x0030027B; in hideep_load_dwz()
600 dev_err(&ts->client->dev, "product code is wrong: %#04x", in hideep_load_dwz()
605 dev_dbg(&ts->client->dev, "firmware release version: %#04x", in hideep_load_dwz()
606 be16_to_cpu(ts->dwz_info.release_ver)); in hideep_load_dwz()
611 static int hideep_flash_firmware(struct hideep_ts *ts, in hideep_flash_firmware() argument
618 error = hideep_program_nvm(ts, ucode, ucode_len); in hideep_flash_firmware()
620 error = hideep_verify_nvm(ts, ucode, ucode_len); in hideep_flash_firmware()
629 static int hideep_update_firmware(struct hideep_ts *ts, in hideep_update_firmware() argument
634 dev_dbg(&ts->client->dev, "starting firmware update"); in hideep_update_firmware()
637 error = hideep_enter_pgm(ts); in hideep_update_firmware()
641 error = hideep_flash_firmware(ts, ucode, ucode_len); in hideep_update_firmware()
643 dev_err(&ts->client->dev, in hideep_update_firmware()
646 dev_dbg(&ts->client->dev, "firmware updated successfully\n"); in hideep_update_firmware()
650 error2 = hideep_load_dwz(ts); in hideep_update_firmware()
652 dev_err(&ts->client->dev, in hideep_update_firmware()
659 static int hideep_power_on(struct hideep_ts *ts) in hideep_power_on() argument
663 error = regulator_enable(ts->vcc_vdd); in hideep_power_on()
665 dev_err(&ts->client->dev, in hideep_power_on()
670 error = regulator_enable(ts->vcc_vid); in hideep_power_on()
672 dev_err(&ts->client->dev, in hideep_power_on()
678 if (ts->reset_gpio) { in hideep_power_on()
679 gpiod_set_value_cansleep(ts->reset_gpio, 0); in hideep_power_on()
681 error = regmap_write(ts->reg, HIDEEP_RESET_CMD, 0x01); in hideep_power_on()
683 dev_err(&ts->client->dev, in hideep_power_on()
694 struct hideep_ts *ts = data; in hideep_power_off() local
696 if (ts->reset_gpio) in hideep_power_off()
697 gpiod_set_value(ts->reset_gpio, 1); in hideep_power_off()
699 regulator_disable(ts->vcc_vid); in hideep_power_off()
700 regulator_disable(ts->vcc_vdd); in hideep_power_off()
723 static void hideep_parse_and_report(struct hideep_ts *ts) in hideep_parse_and_report() argument
726 (void *)&ts->xfer_buf[HIDEEP_TOUCH_EVENT_INDEX]; in hideep_parse_and_report()
727 const u8 *keys = &ts->xfer_buf[HIDEEP_KEY_EVENT_INDEX]; in hideep_parse_and_report()
728 int touch_count = ts->xfer_buf[0]; in hideep_parse_and_report()
729 int key_count = ts->xfer_buf[1] & 0x0f; in hideep_parse_and_report()
730 int lpm_count = ts->xfer_buf[1] & 0xf0; in hideep_parse_and_report()
734 dev_dbg(&ts->client->dev, "mt = %d, key = %d, lpm = %02x", in hideep_parse_and_report()
739 hideep_report_slot(ts->input_dev, events + i); in hideep_parse_and_report()
745 input_report_key(ts->input_dev, in hideep_parse_and_report()
746 ts->key_codes[key_data & HIDEEP_KEY_IDX_MASK], in hideep_parse_and_report()
750 input_mt_sync_frame(ts->input_dev); in hideep_parse_and_report()
751 input_sync(ts->input_dev); in hideep_parse_and_report()
756 struct hideep_ts *ts = handle; in hideep_irq() local
761 error = regmap_bulk_read(ts->reg, HIDEEP_EVENT_ADDR, in hideep_irq()
762 ts->xfer_buf, HIDEEP_MAX_EVENT / 2); in hideep_irq()
764 dev_err(&ts->client->dev, "failed to read events: %d\n", error); in hideep_irq()
768 hideep_parse_and_report(ts); in hideep_irq()
774 static int hideep_get_axis_info(struct hideep_ts *ts) in hideep_get_axis_info() argument
779 error = regmap_bulk_read(ts->reg, 0x28, val, ARRAY_SIZE(val)); in hideep_get_axis_info()
783 ts->prop.max_x = le16_to_cpup(val); in hideep_get_axis_info()
784 ts->prop.max_y = le16_to_cpup(val + 1); in hideep_get_axis_info()
786 dev_dbg(&ts->client->dev, "X: %d, Y: %d", in hideep_get_axis_info()
787 ts->prop.max_x, ts->prop.max_y); in hideep_get_axis_info()
792 static int hideep_init_input(struct hideep_ts *ts) in hideep_init_input() argument
794 struct device *dev = &ts->client->dev; in hideep_init_input()
798 ts->input_dev = devm_input_allocate_device(dev); in hideep_init_input()
799 if (!ts->input_dev) { in hideep_init_input()
804 ts->input_dev->name = HIDEEP_TS_NAME; in hideep_init_input()
805 ts->input_dev->id.bustype = BUS_I2C; in hideep_init_input()
806 input_set_drvdata(ts->input_dev, ts); in hideep_init_input()
808 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X); in hideep_init_input()
809 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y); in hideep_init_input()
810 input_set_abs_params(ts->input_dev, ABS_MT_PRESSURE, 0, 65535, 0, 0); in hideep_init_input()
811 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); in hideep_init_input()
812 input_set_abs_params(ts->input_dev, ABS_MT_TOOL_TYPE, in hideep_init_input()
814 touchscreen_parse_properties(ts->input_dev, true, &ts->prop); in hideep_init_input()
816 if (ts->prop.max_x == 0 || ts->prop.max_y == 0) { in hideep_init_input()
817 error = hideep_get_axis_info(ts); in hideep_init_input()
822 error = input_mt_init_slots(ts->input_dev, HIDEEP_MT_MAX, in hideep_init_input()
827 ts->key_num = device_property_count_u32(dev, "linux,keycodes"); in hideep_init_input()
828 if (ts->key_num > HIDEEP_KEY_MAX) { in hideep_init_input()
830 ts->key_num); in hideep_init_input()
834 if (ts->key_num <= 0) { in hideep_init_input()
839 ts->key_codes, in hideep_init_input()
840 ts->key_num); in hideep_init_input()
846 if (ts->key_num) { in hideep_init_input()
847 ts->input_dev->keycode = ts->key_codes; in hideep_init_input()
848 ts->input_dev->keycodesize = sizeof(ts->key_codes[0]); in hideep_init_input()
849 ts->input_dev->keycodemax = ts->key_num; in hideep_init_input()
851 for (i = 0; i < ts->key_num; i++) in hideep_init_input()
852 input_set_capability(ts->input_dev, EV_KEY, in hideep_init_input()
853 ts->key_codes[i]); in hideep_init_input()
857 error = input_register_device(ts->input_dev); in hideep_init_input()
871 struct hideep_ts *ts = i2c_get_clientdata(client); in hideep_update_fw() local
882 be16_to_cpu(ts->dwz_info.product_id)); in hideep_update_fw()
899 if (fw_entry->size > ts->fw_size) { in hideep_update_fw()
901 fw_entry->size, ts->fw_size); in hideep_update_fw()
906 mutex_lock(&ts->dev_mutex); in hideep_update_fw()
909 error = hideep_update_firmware(ts, (const __be32 *)fw_entry->data, in hideep_update_fw()
913 mutex_unlock(&ts->dev_mutex); in hideep_update_fw()
927 struct hideep_ts *ts = i2c_get_clientdata(client); in hideep_fw_version_show() local
930 mutex_lock(&ts->dev_mutex); in hideep_fw_version_show()
932 be16_to_cpu(ts->dwz_info.release_ver)); in hideep_fw_version_show()
933 mutex_unlock(&ts->dev_mutex); in hideep_fw_version_show()
942 struct hideep_ts *ts = i2c_get_clientdata(client); in hideep_product_id_show() local
945 mutex_lock(&ts->dev_mutex); in hideep_product_id_show()
947 be16_to_cpu(ts->dwz_info.product_id)); in hideep_product_id_show()
948 mutex_unlock(&ts->dev_mutex); in hideep_product_id_show()
968 static void hideep_set_work_mode(struct hideep_ts *ts) in hideep_set_work_mode() argument
979 if (device_property_read_bool(&ts->client->dev, "hideep,force-native-protocol")) in hideep_set_work_mode()
980 regmap_write(ts->reg, HIDEEP_WORK_MODE, 0x00); in hideep_set_work_mode()
986 struct hideep_ts *ts = i2c_get_clientdata(client); in hideep_suspend() local
989 hideep_power_off(ts); in hideep_suspend()
997 struct hideep_ts *ts = i2c_get_clientdata(client); in hideep_resume() local
1000 error = hideep_power_on(ts); in hideep_resume()
1006 hideep_set_work_mode(ts); in hideep_resume()
1025 struct hideep_ts *ts; in hideep_probe() local
1039 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in hideep_probe()
1040 if (!ts) in hideep_probe()
1043 ts->client = client; in hideep_probe()
1044 i2c_set_clientdata(client, ts); in hideep_probe()
1045 mutex_init(&ts->dev_mutex); in hideep_probe()
1047 ts->reg = devm_regmap_init_i2c(client, &hideep_regmap_config); in hideep_probe()
1048 if (IS_ERR(ts->reg)) { in hideep_probe()
1049 error = PTR_ERR(ts->reg); in hideep_probe()
1055 ts->vcc_vdd = devm_regulator_get(&client->dev, "vdd"); in hideep_probe()
1056 if (IS_ERR(ts->vcc_vdd)) in hideep_probe()
1057 return PTR_ERR(ts->vcc_vdd); in hideep_probe()
1059 ts->vcc_vid = devm_regulator_get(&client->dev, "vid"); in hideep_probe()
1060 if (IS_ERR(ts->vcc_vid)) in hideep_probe()
1061 return PTR_ERR(ts->vcc_vid); in hideep_probe()
1063 ts->reset_gpio = devm_gpiod_get_optional(&client->dev, in hideep_probe()
1065 if (IS_ERR(ts->reset_gpio)) in hideep_probe()
1066 return PTR_ERR(ts->reset_gpio); in hideep_probe()
1068 error = hideep_power_on(ts); in hideep_probe()
1074 error = devm_add_action_or_reset(&client->dev, hideep_power_off, ts); in hideep_probe()
1078 error = hideep_load_dwz(ts); in hideep_probe()
1084 hideep_set_work_mode(ts); in hideep_probe()
1086 error = hideep_init_input(ts); in hideep_probe()
1092 client->name, ts); in hideep_probe()