Lines Matching full:cd

198 static bool goodix_berlin_is_dummy_data(struct goodix_berlin_core *cd,  in goodix_berlin_is_dummy_data()  argument
215 static int goodix_berlin_dev_confirm(struct goodix_berlin_core *cd) in goodix_berlin_dev_confirm() argument
223 error = regmap_raw_write(cd->regmap, in goodix_berlin_dev_confirm()
229 error = regmap_raw_read(cd->regmap, in goodix_berlin_dev_confirm()
241 dev_err(cd->dev, "device confirm failed, rx_buf: %*ph\n", in goodix_berlin_dev_confirm()
247 static int goodix_berlin_power_on(struct goodix_berlin_core *cd) in goodix_berlin_power_on() argument
251 error = regulator_enable(cd->iovdd); in goodix_berlin_power_on()
253 dev_err(cd->dev, "Failed to enable iovdd: %d\n", error); in goodix_berlin_power_on()
260 error = regulator_enable(cd->avdd); in goodix_berlin_power_on()
262 dev_err(cd->dev, "Failed to enable avdd: %d\n", error); in goodix_berlin_power_on()
269 gpiod_set_value_cansleep(cd->reset_gpio, 0); in goodix_berlin_power_on()
274 error = goodix_berlin_dev_confirm(cd); in goodix_berlin_power_on()
284 gpiod_set_value_cansleep(cd->reset_gpio, 1); in goodix_berlin_power_on()
285 regulator_disable(cd->avdd); in goodix_berlin_power_on()
287 regulator_disable(cd->iovdd); in goodix_berlin_power_on()
291 static void goodix_berlin_power_off(struct goodix_berlin_core *cd) in goodix_berlin_power_off() argument
293 gpiod_set_value_cansleep(cd->reset_gpio, 1); in goodix_berlin_power_off()
294 regulator_disable(cd->avdd); in goodix_berlin_power_off()
295 regulator_disable(cd->iovdd); in goodix_berlin_power_off()
298 static int goodix_berlin_read_version(struct goodix_berlin_core *cd) in goodix_berlin_read_version() argument
302 error = regmap_raw_read(cd->regmap, GOODIX_BERLIN_FW_VERSION_INFO_ADDR, in goodix_berlin_read_version()
303 &cd->fw_version, sizeof(cd->fw_version)); in goodix_berlin_read_version()
305 dev_err(cd->dev, "error reading fw version, %d\n", error); in goodix_berlin_read_version()
309 if (!goodix_berlin_checksum_valid((u8 *)&cd->fw_version, in goodix_berlin_read_version()
310 sizeof(cd->fw_version))) { in goodix_berlin_read_version()
311 dev_err(cd->dev, "invalid fw version: checksum error\n"); in goodix_berlin_read_version()
319 static int goodix_berlin_parse_ic_info(struct goodix_berlin_core *cd, in goodix_berlin_parse_ic_info() argument
349 cd->touch_data_addr = le32_to_cpu(misc->touch_data_addr); in goodix_berlin_parse_ic_info()
354 dev_err(cd->dev, "ic_info length is invalid (offset %d length %d)\n", in goodix_berlin_parse_ic_info()
359 static int goodix_berlin_get_ic_info(struct goodix_berlin_core *cd) in goodix_berlin_get_ic_info() argument
370 error = regmap_raw_read(cd->regmap, GOODIX_BERLIN_IC_INFO_ADDR, in goodix_berlin_get_ic_info()
373 dev_err(cd->dev, "failed get ic info length, %d\n", error); in goodix_berlin_get_ic_info()
379 dev_err(cd->dev, "invalid ic info length %d\n", length); in goodix_berlin_get_ic_info()
383 error = regmap_raw_read(cd->regmap, GOODIX_BERLIN_IC_INFO_ADDR, in goodix_berlin_get_ic_info()
386 dev_err(cd->dev, "failed get ic info data, %d\n", error); in goodix_berlin_get_ic_info()
391 if (goodix_berlin_is_dummy_data(cd, afe_data, length)) { in goodix_berlin_get_ic_info()
392 dev_err(cd->dev, "fw info data invalid\n"); in goodix_berlin_get_ic_info()
397 dev_err(cd->dev, "fw info checksum error\n"); in goodix_berlin_get_ic_info()
401 error = goodix_berlin_parse_ic_info(cd, afe_data, length); in goodix_berlin_get_ic_info()
406 if (!cd->touch_data_addr) { in goodix_berlin_get_ic_info()
407 dev_err(cd->dev, "touch_data_addr is null\n"); in goodix_berlin_get_ic_info()
414 static int goodix_berlin_get_remaining_contacts(struct goodix_berlin_core *cd, in goodix_berlin_get_remaining_contacts() argument
419 u32 addr = cd->touch_data_addr + GOODIX_BERLIN_HEADER_SIZE + offset; in goodix_berlin_get_remaining_contacts()
422 error = regmap_raw_read(cd->regmap, addr, in goodix_berlin_get_remaining_contacts()
423 &cd->event.data[offset], in goodix_berlin_get_remaining_contacts()
426 dev_err_ratelimited(cd->dev, "failed to get touch data, %d\n", in goodix_berlin_get_remaining_contacts()
434 static void goodix_berlin_report_state(struct goodix_berlin_core *cd, int n) in goodix_berlin_report_state() argument
437 (struct goodix_berlin_touch *)cd->event.data; in goodix_berlin_report_state()
448 dev_warn_once(cd->dev, "Stylus event type not handled\n"); in goodix_berlin_report_state()
454 dev_warn_ratelimited(cd->dev, "invalid finger id %d\n", id); in goodix_berlin_report_state()
458 input_mt_slot(cd->input_dev, id); in goodix_berlin_report_state()
459 input_mt_report_slot_state(cd->input_dev, MT_TOOL_FINGER, true); in goodix_berlin_report_state()
461 touchscreen_report_pos(cd->input_dev, &cd->props, in goodix_berlin_report_state()
464 input_report_abs(cd->input_dev, ABS_MT_TOUCH_MAJOR, in goodix_berlin_report_state()
468 input_mt_sync_frame(cd->input_dev); in goodix_berlin_report_state()
469 input_sync(cd->input_dev); in goodix_berlin_report_state()
472 static void goodix_berlin_touch_handler(struct goodix_berlin_core *cd) in goodix_berlin_touch_handler() argument
478 cd->event.hdr.request_type); in goodix_berlin_touch_handler()
480 dev_warn(cd->dev, "invalid touch num %d\n", touch_num); in goodix_berlin_touch_handler()
486 error = goodix_berlin_get_remaining_contacts(cd, touch_num); in goodix_berlin_touch_handler()
494 if (!goodix_berlin_checksum_valid(cd->event.data, len)) { in goodix_berlin_touch_handler()
495 dev_err(cd->dev, "touch data checksum error: %*ph\n", in goodix_berlin_touch_handler()
496 len, cd->event.data); in goodix_berlin_touch_handler()
501 goodix_berlin_report_state(cd, touch_num); in goodix_berlin_touch_handler()
504 static int goodix_berlin_request_handle_reset(struct goodix_berlin_core *cd) in goodix_berlin_request_handle_reset() argument
506 gpiod_set_value_cansleep(cd->reset_gpio, 1); in goodix_berlin_request_handle_reset()
508 gpiod_set_value_cansleep(cd->reset_gpio, 0); in goodix_berlin_request_handle_reset()
517 struct goodix_berlin_core *cd = data; in goodix_berlin_irq() local
555 error = regmap_raw_read(cd->regmap, cd->touch_data_addr, in goodix_berlin_irq()
556 &cd->event, in goodix_berlin_irq()
561 dev_warn_ratelimited(cd->dev, in goodix_berlin_irq()
566 if (cd->event.hdr.status == 0) in goodix_berlin_irq()
569 if (!goodix_berlin_checksum_valid((u8 *)&cd->event.hdr, in goodix_berlin_irq()
571 dev_warn_ratelimited(cd->dev, in goodix_berlin_irq()
574 &cd->event.hdr); in goodix_berlin_irq()
578 if (cd->event.hdr.status & GOODIX_BERLIN_TOUCH_EVENT) in goodix_berlin_irq()
579 goodix_berlin_touch_handler(cd); in goodix_berlin_irq()
581 if (cd->event.hdr.status & GOODIX_BERLIN_REQUEST_EVENT) { in goodix_berlin_irq()
582 switch (cd->event.hdr.request_type) { in goodix_berlin_irq()
584 if (cd->reset_gpio) in goodix_berlin_irq()
585 goodix_berlin_request_handle_reset(cd); in goodix_berlin_irq()
589 dev_warn(cd->dev, "unsupported request code 0x%x\n", in goodix_berlin_irq()
590 cd->event.hdr.request_type); in goodix_berlin_irq()
597 regmap_write(cd->regmap, cd->touch_data_addr, 0); in goodix_berlin_irq()
603 static int goodix_berlin_input_dev_config(struct goodix_berlin_core *cd, in goodix_berlin_input_dev_config() argument
609 input_dev = devm_input_allocate_device(cd->dev); in goodix_berlin_input_dev_config()
613 cd->input_dev = input_dev; in goodix_berlin_input_dev_config()
614 input_set_drvdata(input_dev, cd); in goodix_berlin_input_dev_config()
621 input_set_abs_params(cd->input_dev, ABS_MT_POSITION_X, in goodix_berlin_input_dev_config()
623 input_set_abs_params(cd->input_dev, ABS_MT_POSITION_Y, in goodix_berlin_input_dev_config()
625 input_set_abs_params(cd->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); in goodix_berlin_input_dev_config()
627 touchscreen_parse_properties(cd->input_dev, true, &cd->props); in goodix_berlin_input_dev_config()
629 error = input_mt_init_slots(cd->input_dev, GOODIX_BERLIN_MAX_TOUCH, in goodix_berlin_input_dev_config()
634 error = input_register_device(cd->input_dev); in goodix_berlin_input_dev_config()
643 struct goodix_berlin_core *cd = dev_get_drvdata(dev); in goodix_berlin_suspend() local
645 disable_irq(cd->irq); in goodix_berlin_suspend()
646 goodix_berlin_power_off(cd); in goodix_berlin_suspend()
653 struct goodix_berlin_core *cd = dev_get_drvdata(dev); in goodix_berlin_resume() local
656 error = goodix_berlin_power_on(cd); in goodix_berlin_resume()
660 enable_irq(cd->irq); in goodix_berlin_resume()
670 struct goodix_berlin_core *cd = data; in goodix_berlin_power_off_act() local
672 goodix_berlin_power_off(cd); in goodix_berlin_power_off_act()
680 struct goodix_berlin_core *cd = dev_get_drvdata(dev); in registers_read() local
683 error = regmap_raw_read(cd->regmap, off, buf, count); in registers_read()
693 struct goodix_berlin_core *cd = dev_get_drvdata(dev); in registers_write() local
696 error = regmap_raw_write(cd->regmap, off, buf, count); in registers_write()
721 struct goodix_berlin_core *cd; in goodix_berlin_probe() local
729 cd = devm_kzalloc(dev, sizeof(*cd), GFP_KERNEL); in goodix_berlin_probe()
730 if (!cd) in goodix_berlin_probe()
733 cd->dev = dev; in goodix_berlin_probe()
734 cd->regmap = regmap; in goodix_berlin_probe()
735 cd->irq = irq; in goodix_berlin_probe()
737 cd->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in goodix_berlin_probe()
738 if (IS_ERR(cd->reset_gpio)) in goodix_berlin_probe()
739 return dev_err_probe(dev, PTR_ERR(cd->reset_gpio), in goodix_berlin_probe()
742 cd->avdd = devm_regulator_get(dev, "avdd"); in goodix_berlin_probe()
743 if (IS_ERR(cd->avdd)) in goodix_berlin_probe()
744 return dev_err_probe(dev, PTR_ERR(cd->avdd), in goodix_berlin_probe()
747 cd->iovdd = devm_regulator_get(dev, "iovdd"); in goodix_berlin_probe()
748 if (IS_ERR(cd->iovdd)) in goodix_berlin_probe()
749 return dev_err_probe(dev, PTR_ERR(cd->iovdd), in goodix_berlin_probe()
752 error = goodix_berlin_power_on(cd); in goodix_berlin_probe()
758 error = devm_add_action_or_reset(dev, goodix_berlin_power_off_act, cd); in goodix_berlin_probe()
762 error = goodix_berlin_read_version(cd); in goodix_berlin_probe()
768 error = goodix_berlin_get_ic_info(cd); in goodix_berlin_probe()
774 error = goodix_berlin_input_dev_config(cd, id); in goodix_berlin_probe()
780 error = devm_request_threaded_irq(dev, cd->irq, NULL, goodix_berlin_irq, in goodix_berlin_probe()
781 IRQF_ONESHOT, "goodix-berlin", cd); in goodix_berlin_probe()
787 dev_set_drvdata(dev, cd); in goodix_berlin_probe()
790 cd->fw_version.patch_pid); in goodix_berlin_probe()