Lines Matching refs:line
442 struct line { struct
534 struct line lines[] __counted_by(num_lines);
600 static u64 line_event_timestamp(struct line *line) in line_event_timestamp() argument
602 if (test_bit(FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags)) in line_event_timestamp()
605 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags)) in line_event_timestamp()
606 return line->timestamp_ns; in line_event_timestamp()
640 struct line *line; in process_hw_ts_thread() local
649 line = p; in process_hw_ts_thread()
650 lr = line->req; in process_hw_ts_thread()
654 le.timestamp_ns = line->timestamp_ns; in process_hw_ts_thread()
655 edflags = READ_ONCE(line->edflags); in process_hw_ts_thread()
659 level = (line->raw_level >= 0) ? in process_hw_ts_thread()
660 line->raw_level : in process_hw_ts_thread()
661 gpiod_get_raw_value_cansleep(line->desc); in process_hw_ts_thread()
677 le.line_seqno = line->line_seqno; in process_hw_ts_thread()
678 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in process_hw_ts_thread()
679 le.offset = gpio_chip_hwgpio(line->desc); in process_hw_ts_thread()
688 struct line *line; in process_hw_ts() local
695 line = p; in process_hw_ts()
696 line->timestamp_ns = ts->tsc; in process_hw_ts()
697 line->raw_level = ts->raw_level; in process_hw_ts()
698 lr = line->req; in process_hw_ts()
700 if (READ_ONCE(line->sw_debounced)) { in process_hw_ts()
701 line->total_discard_seq++; in process_hw_ts()
702 line->last_seqno = ts->seq; in process_hw_ts()
703 mod_delayed_work(system_wq, &line->work, in process_hw_ts()
704 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); in process_hw_ts()
706 if (unlikely(ts->seq < line->line_seqno)) in process_hw_ts()
709 diff_seqno = ts->seq - line->line_seqno; in process_hw_ts()
710 line->line_seqno = ts->seq; in process_hw_ts()
712 line->req_seqno = atomic_add_return(diff_seqno, in process_hw_ts()
721 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
725 struct hte_ts_desc *hdesc = &line->hdesc; in hte_edge_setup()
728 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
732 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
736 line->total_discard_seq = 0; in hte_edge_setup()
738 hte_init_line_attr(hdesc, desc_to_gpio(line->desc), flags, NULL, in hte_edge_setup()
739 line->desc); in hte_edge_setup()
746 line); in hte_edge_setup()
751 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
759 struct line *line = p; in edge_irq_thread() local
760 struct linereq *lr = line->req; in edge_irq_thread()
766 if (line->timestamp_ns) { in edge_irq_thread()
767 le.timestamp_ns = line->timestamp_ns; in edge_irq_thread()
774 le.timestamp_ns = line_event_timestamp(line); in edge_irq_thread()
776 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_thread()
778 line->timestamp_ns = 0; in edge_irq_thread()
780 switch (READ_ONCE(line->edflags) & GPIO_V2_LINE_EDGE_FLAGS) { in edge_irq_thread()
782 le.id = line_event_id(gpiod_get_value_cansleep(line->desc)); in edge_irq_thread()
793 line->line_seqno++; in edge_irq_thread()
794 le.line_seqno = line->line_seqno; in edge_irq_thread()
795 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in edge_irq_thread()
796 le.offset = gpio_chip_hwgpio(line->desc); in edge_irq_thread()
805 struct line *line = p; in edge_irq_handler() local
806 struct linereq *lr = line->req; in edge_irq_handler()
812 line->timestamp_ns = line_event_timestamp(line); in edge_irq_handler()
815 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_handler()
823 static bool debounced_value(struct line *line) in debounced_value() argument
832 value = READ_ONCE(line->level); in debounced_value()
834 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags)) in debounced_value()
842 struct line *line = p; in debounce_irq_handler() local
844 mod_delayed_work(system_wq, &line->work, in debounce_irq_handler()
845 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); in debounce_irq_handler()
853 struct line *line = container_of(work, struct line, work.work); in debounce_work_func() local
855 u64 eflags, edflags = READ_ONCE(line->edflags); in debounce_work_func()
861 level = line->raw_level; in debounce_work_func()
864 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_work_func()
870 if (READ_ONCE(line->level) == level) in debounce_work_func()
873 WRITE_ONCE(line->level, level); in debounce_work_func()
892 lr = line->req; in debounce_work_func()
893 le.timestamp_ns = line_event_timestamp(line); in debounce_work_func()
894 le.offset = gpio_chip_hwgpio(line->desc); in debounce_work_func()
898 line->total_discard_seq -= 1; in debounce_work_func()
899 diff_seqno = line->last_seqno - line->total_discard_seq - in debounce_work_func()
900 line->line_seqno; in debounce_work_func()
901 line->line_seqno = line->last_seqno - line->total_discard_seq; in debounce_work_func()
902 le.line_seqno = line->line_seqno; in debounce_work_func()
908 line->line_seqno++; in debounce_work_func()
909 le.line_seqno = line->line_seqno; in debounce_work_func()
919 static int debounce_setup(struct line *line, unsigned int debounce_period_us) in debounce_setup() argument
929 ret = gpio_do_set_config(line->desc, in debounce_setup()
937 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_setup()
942 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags))) { in debounce_setup()
943 irq = gpiod_to_irq(line->desc); in debounce_setup()
947 label = make_irq_label(line->req->label); in debounce_setup()
953 label, line); in debounce_setup()
958 line->irq = irq; in debounce_setup()
960 ret = hte_edge_setup(line, GPIO_V2_LINE_FLAG_EDGE_BOTH); in debounce_setup()
965 WRITE_ONCE(line->level, level); in debounce_setup()
966 WRITE_ONCE(line->sw_debounced, 1); in debounce_setup()
999 static void edge_detector_stop(struct line *line) in edge_detector_stop() argument
1001 if (line->irq) { in edge_detector_stop()
1002 free_irq_label(free_irq(line->irq, line)); in edge_detector_stop()
1003 line->irq = 0; in edge_detector_stop()
1007 if (READ_ONCE(line->edflags) & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE) in edge_detector_stop()
1008 hte_ts_put(&line->hdesc); in edge_detector_stop()
1011 cancel_delayed_work_sync(&line->work); in edge_detector_stop()
1012 WRITE_ONCE(line->sw_debounced, 0); in edge_detector_stop()
1013 WRITE_ONCE(line->edflags, 0); in edge_detector_stop()
1014 if (line->desc) in edge_detector_stop()
1015 WRITE_ONCE(line->desc->debounce_period_us, 0); in edge_detector_stop()
1027 static int edge_detector_setup(struct line *line, in edge_detector_setup() argument
1039 ret = edge_detector_fifo_init(line->req); in edge_detector_setup()
1045 ret = debounce_setup(line, debounce_period_us); in edge_detector_setup()
1048 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in edge_detector_setup()
1052 if (!eflags || READ_ONCE(line->sw_debounced)) in edge_detector_setup()
1057 return hte_edge_setup(line, edflags); in edge_detector_setup()
1059 irq = gpiod_to_irq(line->desc); in edge_detector_setup()
1064 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1067 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1071 label = make_irq_label(line->req->label); in edge_detector_setup()
1077 irqflags, label, line); in edge_detector_setup()
1083 line->irq = irq; in edge_detector_setup()
1087 static int edge_detector_update(struct line *line, in edge_detector_update() argument
1091 u64 active_edflags = READ_ONCE(line->edflags); in edge_detector_update()
1096 (READ_ONCE(line->desc->debounce_period_us) == debounce_period_us)) in edge_detector_update()
1100 if (debounce_period_us && READ_ONCE(line->sw_debounced)) { in edge_detector_update()
1101 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in edge_detector_update()
1107 return edge_detector_fifo_init(line->req); in edge_detector_update()
1113 if ((line->irq && !READ_ONCE(line->sw_debounced)) || in edge_detector_update()
1115 (!debounce_period_us && READ_ONCE(line->sw_debounced))) in edge_detector_update()
1116 edge_detector_stop(line); in edge_detector_update()
1118 return edge_detector_setup(line, lc, line_idx, edflags); in edge_detector_update()
1407 struct line *line; in linereq_set_config() local
1422 line = &lr->lines[i]; in linereq_set_config()
1436 edge_detector_stop(line); in linereq_set_config()
1445 ret = edge_detector_update(line, &lc, i, edflags); in linereq_set_config()
1450 WRITE_ONCE(line->edflags, edflags); in linereq_set_config()