Lines Matching refs:line
429 struct line { struct
517 struct line lines[];
566 static u64 line_event_timestamp(struct line *line) in line_event_timestamp() argument
568 if (test_bit(FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags)) in line_event_timestamp()
570 else if (test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags)) in line_event_timestamp()
571 return line->timestamp_ns; in line_event_timestamp()
578 struct line *line; in process_hw_ts_thread() local
587 line = p; in process_hw_ts_thread()
588 lr = line->req; in process_hw_ts_thread()
592 le.timestamp_ns = line->timestamp_ns; in process_hw_ts_thread()
593 eflags = READ_ONCE(line->eflags); in process_hw_ts_thread()
596 if (line->raw_level >= 0) { in process_hw_ts_thread()
597 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags)) in process_hw_ts_thread()
598 level = !line->raw_level; in process_hw_ts_thread()
600 level = line->raw_level; in process_hw_ts_thread()
602 level = gpiod_get_value_cansleep(line->desc); in process_hw_ts_thread()
618 le.line_seqno = line->line_seqno; in process_hw_ts_thread()
619 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in process_hw_ts_thread()
620 le.offset = gpio_chip_hwgpio(line->desc); in process_hw_ts_thread()
629 struct line *line; in process_hw_ts() local
636 line = p; in process_hw_ts()
637 line->timestamp_ns = ts->tsc; in process_hw_ts()
638 line->raw_level = ts->raw_level; in process_hw_ts()
639 lr = line->req; in process_hw_ts()
641 if (READ_ONCE(line->sw_debounced)) { in process_hw_ts()
642 line->total_discard_seq++; in process_hw_ts()
643 line->last_seqno = ts->seq; in process_hw_ts()
644 mod_delayed_work(system_wq, &line->work, in process_hw_ts()
645 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); in process_hw_ts()
647 if (unlikely(ts->seq < line->line_seqno)) in process_hw_ts()
650 diff_seqno = ts->seq - line->line_seqno; in process_hw_ts()
651 line->line_seqno = ts->seq; in process_hw_ts()
653 line->req_seqno = atomic_add_return(diff_seqno, in process_hw_ts()
664 struct line *line = p; in edge_irq_thread() local
665 struct linereq *lr = line->req; in edge_irq_thread()
672 if (line->timestamp_ns) { in edge_irq_thread()
673 le.timestamp_ns = line->timestamp_ns; in edge_irq_thread()
680 le.timestamp_ns = line_event_timestamp(line); in edge_irq_thread()
682 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_thread()
684 line->timestamp_ns = 0; in edge_irq_thread()
686 eflags = READ_ONCE(line->eflags); in edge_irq_thread()
688 int level = gpiod_get_value_cansleep(line->desc); in edge_irq_thread()
705 line->line_seqno++; in edge_irq_thread()
706 le.line_seqno = line->line_seqno; in edge_irq_thread()
707 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in edge_irq_thread()
708 le.offset = gpio_chip_hwgpio(line->desc); in edge_irq_thread()
717 struct line *line = p; in edge_irq_handler() local
718 struct linereq *lr = line->req; in edge_irq_handler()
724 line->timestamp_ns = line_event_timestamp(line); in edge_irq_handler()
727 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_handler()
735 static bool debounced_value(struct line *line) in debounced_value() argument
744 value = READ_ONCE(line->level); in debounced_value()
746 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags)) in debounced_value()
754 struct line *line = p; in debounce_irq_handler() local
756 mod_delayed_work(system_wq, &line->work, in debounce_irq_handler()
757 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); in debounce_irq_handler()
765 struct line *line = container_of(work, struct line, work.work); in debounce_work_func() local
770 if (test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags)) { in debounce_work_func()
771 level = line->raw_level; in debounce_work_func()
773 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_work_func()
775 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_work_func()
782 if (READ_ONCE(line->level) == level) in debounce_work_func()
785 WRITE_ONCE(line->level, level); in debounce_work_func()
788 eflags = READ_ONCE(line->eflags); in debounce_work_func()
793 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags)) in debounce_work_func()
804 lr = line->req; in debounce_work_func()
805 le.timestamp_ns = line_event_timestamp(line); in debounce_work_func()
806 le.offset = gpio_chip_hwgpio(line->desc); in debounce_work_func()
807 if (test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags)) { in debounce_work_func()
809 line->total_discard_seq -= 1; in debounce_work_func()
810 diff_seqno = line->last_seqno - line->total_discard_seq - in debounce_work_func()
811 line->line_seqno; in debounce_work_func()
812 line->line_seqno = line->last_seqno - line->total_discard_seq; in debounce_work_func()
813 le.line_seqno = line->line_seqno; in debounce_work_func()
817 line->line_seqno++; in debounce_work_func()
818 le.line_seqno = line->line_seqno; in debounce_work_func()
833 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
837 struct hte_ts_desc *hdesc = &line->hdesc; in hte_edge_setup()
840 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
843 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
846 line->total_discard_seq = 0; in hte_edge_setup()
848 hte_init_line_attr(hdesc, desc_to_gpio(line->desc), flags, in hte_edge_setup()
849 NULL, line->desc); in hte_edge_setup()
856 process_hw_ts_thread, line); in hte_edge_setup()
859 static int debounce_setup(struct line *line, in debounce_setup() argument
866 ret = gpiod_set_debounce(line->desc, debounce_period_us); in debounce_setup()
868 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in debounce_setup()
876 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_setup()
881 irq = gpiod_to_irq(line->desc); in debounce_setup()
887 line->req->label, line); in debounce_setup()
890 line->irq = irq; in debounce_setup()
892 ret = hte_edge_setup(line, in debounce_setup()
899 WRITE_ONCE(line->level, level); in debounce_setup()
900 WRITE_ONCE(line->sw_debounced, 1); in debounce_setup()
933 static void edge_detector_stop(struct line *line, bool hte_en) in edge_detector_stop() argument
935 if (line->irq && !hte_en) { in edge_detector_stop()
936 free_irq(line->irq, line); in edge_detector_stop()
937 line->irq = 0; in edge_detector_stop()
941 hte_ts_put(&line->hdesc); in edge_detector_stop()
943 cancel_delayed_work_sync(&line->work); in edge_detector_stop()
944 WRITE_ONCE(line->sw_debounced, 0); in edge_detector_stop()
945 WRITE_ONCE(line->eflags, 0); in edge_detector_stop()
946 if (line->desc) in edge_detector_stop()
947 WRITE_ONCE(line->desc->debounce_period_us, 0); in edge_detector_stop()
951 static int edge_detector_setup(struct line *line, in edge_detector_setup() argument
960 if (eflags && !kfifo_initialized(&line->req->events)) { in edge_detector_setup()
961 ret = kfifo_alloc(&line->req->events, in edge_detector_setup()
962 line->req->event_buffer_size, GFP_KERNEL); in edge_detector_setup()
966 WRITE_ONCE(line->eflags, eflags); in edge_detector_setup()
969 ret = debounce_setup(line, debounce_period_us, hte_req); in edge_detector_setup()
972 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in edge_detector_setup()
976 if (!eflags || READ_ONCE(line->sw_debounced)) in edge_detector_setup()
980 return hte_edge_setup(line, eflags); in edge_detector_setup()
982 irq = gpiod_to_irq(line->desc); in edge_detector_setup()
987 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
990 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
996 irqflags, line->req->label, line); in edge_detector_setup()
1000 line->irq = irq; in edge_detector_setup()
1004 static int edge_detector_update(struct line *line, in edge_detector_update() argument
1016 if ((READ_ONCE(line->eflags) == eflags) && !polarity_change && in edge_detector_update()
1017 (READ_ONCE(line->desc->debounce_period_us) == debounce_period_us) in edge_detector_update()
1022 if (debounce_period_us && READ_ONCE(line->sw_debounced)) { in edge_detector_update()
1023 WRITE_ONCE(line->eflags, eflags); in edge_detector_update()
1024 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us); in edge_detector_update()
1029 if ((line->irq && !READ_ONCE(line->sw_debounced)) || prev_hte_flag || in edge_detector_update()
1030 (!debounce_period_us && READ_ONCE(line->sw_debounced))) in edge_detector_update()
1031 edge_detector_stop(line, prev_hte_flag); in edge_detector_update()
1033 return edge_detector_setup(line, lc, line_idx, eflags, in edge_detector_update()