Lines Matching refs:line

485 struct line {  struct
575 struct line lines[];
630 static u64 line_event_timestamp(struct line *line) in line_event_timestamp() argument
632 if (test_bit(FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags)) in line_event_timestamp()
635 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags)) in line_event_timestamp()
636 return line->timestamp_ns; in line_event_timestamp()
651 struct line *line; in process_hw_ts_thread() local
660 line = p; in process_hw_ts_thread()
661 lr = line->req; in process_hw_ts_thread()
665 le.timestamp_ns = line->timestamp_ns; in process_hw_ts_thread()
666 edflags = READ_ONCE(line->edflags); in process_hw_ts_thread()
670 level = (line->raw_level >= 0) ? in process_hw_ts_thread()
671 line->raw_level : in process_hw_ts_thread()
672 gpiod_get_raw_value_cansleep(line->desc); in process_hw_ts_thread()
688 le.line_seqno = line->line_seqno; in process_hw_ts_thread()
689 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in process_hw_ts_thread()
690 le.offset = gpio_chip_hwgpio(line->desc); in process_hw_ts_thread()
699 struct line *line; in process_hw_ts() local
706 line = p; in process_hw_ts()
707 line->timestamp_ns = ts->tsc; in process_hw_ts()
708 line->raw_level = ts->raw_level; in process_hw_ts()
709 lr = line->req; in process_hw_ts()
711 if (READ_ONCE(line->sw_debounced)) { in process_hw_ts()
712 line->total_discard_seq++; in process_hw_ts()
713 line->last_seqno = ts->seq; in process_hw_ts()
714 mod_delayed_work(system_wq, &line->work, in process_hw_ts()
715 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); in process_hw_ts()
717 if (unlikely(ts->seq < line->line_seqno)) in process_hw_ts()
720 diff_seqno = ts->seq - line->line_seqno; in process_hw_ts()
721 line->line_seqno = ts->seq; in process_hw_ts()
723 line->req_seqno = atomic_add_return(diff_seqno, in process_hw_ts()
732 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
736 struct hte_ts_desc *hdesc = &line->hdesc; in hte_edge_setup()
739 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
743 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
747 line->total_discard_seq = 0; in hte_edge_setup()
749 hte_init_line_attr(hdesc, desc_to_gpio(line->desc), flags, NULL, in hte_edge_setup()
750 line->desc); in hte_edge_setup()
757 line); in hte_edge_setup()
762 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
770 struct line *line = p; in edge_irq_thread() local
771 struct linereq *lr = line->req; in edge_irq_thread()
777 if (line->timestamp_ns) { in edge_irq_thread()
778 le.timestamp_ns = line->timestamp_ns; in edge_irq_thread()
785 le.timestamp_ns = line_event_timestamp(line); in edge_irq_thread()
787 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_thread()
789 line->timestamp_ns = 0; in edge_irq_thread()
791 switch (READ_ONCE(line->edflags) & GPIO_V2_LINE_EDGE_FLAGS) { in edge_irq_thread()
793 le.id = line_event_id(gpiod_get_value_cansleep(line->desc)); in edge_irq_thread()
804 line->line_seqno++; in edge_irq_thread()
805 le.line_seqno = line->line_seqno; in edge_irq_thread()
806 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in edge_irq_thread()
807 le.offset = gpio_chip_hwgpio(line->desc); in edge_irq_thread()
816 struct line *line = p; in edge_irq_handler() local
817 struct linereq *lr = line->req; in edge_irq_handler()
823 line->timestamp_ns = line_event_timestamp(line); in edge_irq_handler()
826 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_handler()
834 static bool debounced_value(struct line *line) in debounced_value() argument
843 value = READ_ONCE(line->level); in debounced_value()
845 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags)) in debounced_value()
853 struct line *line = p; in debounce_irq_handler() local
855 mod_delayed_work(system_wq, &line->work, in debounce_irq_handler()
856 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); in debounce_irq_handler()
864 struct line *line = container_of(work, struct line, work.work); in debounce_work_func() local
866 u64 eflags, edflags = READ_ONCE(line->edflags); in debounce_work_func()
872 level = line->raw_level; in debounce_work_func()
875 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_work_func()
881 if (READ_ONCE(line->level) == level) in debounce_work_func()
884 WRITE_ONCE(line->level, level); in debounce_work_func()
903 lr = line->req; in debounce_work_func()
904 le.timestamp_ns = line_event_timestamp(line); in debounce_work_func()
905 le.offset = gpio_chip_hwgpio(line->desc); in debounce_work_func()
909 line->total_discard_seq -= 1; in debounce_work_func()
910 diff_seqno = line->last_seqno - line->total_discard_seq - in debounce_work_func()
911 line->line_seqno; in debounce_work_func()
912 line->line_seqno = line->last_seqno - line->total_discard_seq; in debounce_work_func()
913 le.line_seqno = line->line_seqno; in debounce_work_func()
919 line->line_seqno++; in debounce_work_func()
920 le.line_seqno = line->line_seqno; in debounce_work_func()
930 static int debounce_setup(struct line *line, unsigned int debounce_period_us) in debounce_setup() argument
936 ret = gpiod_set_debounce(line->desc, debounce_period_us); in debounce_setup()
938 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in debounce_setup()
946 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_setup()
951 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags))) { in debounce_setup()
952 irq = gpiod_to_irq(line->desc); in debounce_setup()
958 line->req->label, line); in debounce_setup()
961 line->irq = irq; in debounce_setup()
963 ret = hte_edge_setup(line, GPIO_V2_LINE_FLAG_EDGE_BOTH); in debounce_setup()
968 WRITE_ONCE(line->level, level); in debounce_setup()
969 WRITE_ONCE(line->sw_debounced, 1); in debounce_setup()
1002 static void edge_detector_stop(struct line *line) in edge_detector_stop() argument
1004 if (line->irq) { in edge_detector_stop()
1005 free_irq(line->irq, line); in edge_detector_stop()
1006 line->irq = 0; in edge_detector_stop()
1010 if (READ_ONCE(line->edflags) & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE) in edge_detector_stop()
1011 hte_ts_put(&line->hdesc); in edge_detector_stop()
1014 cancel_delayed_work_sync(&line->work); in edge_detector_stop()
1015 WRITE_ONCE(line->sw_debounced, 0); in edge_detector_stop()
1016 WRITE_ONCE(line->edflags, 0); in edge_detector_stop()
1017 if (line->desc) in edge_detector_stop()
1018 WRITE_ONCE(line->desc->debounce_period_us, 0); in edge_detector_stop()
1022 static int edge_detector_setup(struct line *line, in edge_detector_setup() argument
1032 if (eflags && !kfifo_initialized(&line->req->events)) { in edge_detector_setup()
1033 ret = kfifo_alloc(&line->req->events, in edge_detector_setup()
1034 line->req->event_buffer_size, GFP_KERNEL); in edge_detector_setup()
1040 ret = debounce_setup(line, debounce_period_us); in edge_detector_setup()
1043 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in edge_detector_setup()
1047 if (!eflags || READ_ONCE(line->sw_debounced)) in edge_detector_setup()
1052 return hte_edge_setup(line, edflags); in edge_detector_setup()
1054 irq = gpiod_to_irq(line->desc); in edge_detector_setup()
1059 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1062 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1068 irqflags, line->req->label, line); in edge_detector_setup()
1072 line->irq = irq; in edge_detector_setup()
1076 static int edge_detector_update(struct line *line, in edge_detector_update() argument
1080 u64 active_edflags = READ_ONCE(line->edflags); in edge_detector_update()
1085 (READ_ONCE(line->desc->debounce_period_us) == debounce_period_us)) in edge_detector_update()
1089 if (debounce_period_us && READ_ONCE(line->sw_debounced)) { in edge_detector_update()
1090 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in edge_detector_update()
1095 if ((line->irq && !READ_ONCE(line->sw_debounced)) || in edge_detector_update()
1097 (!debounce_period_us && READ_ONCE(line->sw_debounced))) in edge_detector_update()
1098 edge_detector_stop(line); in edge_detector_update()
1100 return edge_detector_setup(line, lc, line_idx, edflags); in edge_detector_update()
1375 struct line *line; in linereq_set_config_unlocked() local
1381 line = &lr->lines[i]; in linereq_set_config_unlocked()
1393 edge_detector_stop(line); in linereq_set_config_unlocked()
1402 ret = edge_detector_update(line, lc, i, edflags); in linereq_set_config_unlocked()
1407 WRITE_ONCE(line->edflags, edflags); in linereq_set_config_unlocked()