Lines Matching full:line
64 * GPIO line handle management
235 * All line descriptors were created at once with the same in linehandle_ioctl()
357 * or output, else the line will be treated "as is". in linehandle_create()
373 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", in linehandle_create()
419 * struct line - contains the state of a requested line
421 * @desc: the GPIO descriptor for this line.
422 * @req: the corresponding line request
429 * events for the corresponding line request. This is drawn from the @req.
431 * events for this line.
435 * @level: the current debounced physical level of the line
437 * @raw_level: the line level at the time of event
441 struct line { struct
500 * HTE provider sets line level at the time of event. The valid argument
505 * when sw_debounce is set on HTE enabled line, this is running argument
510 * when sw_debounce is set on HTE enabled line, this variable records argument
521 * A line is determined to contain supplemental information by argument
529 * struct linereq - contains the state of a userspace line request
530 * @gdev: the GPIO device the line request pertains to
538 * this line request. Note that this is not used when @num_lines is 1, as
543 * @lines: the lines held by this line request, with @num_lines elements.
555 struct line lines[] __counted_by(num_lines);
558 static void supinfo_insert(struct line *line) in supinfo_insert() argument
561 struct line *entry; in supinfo_insert()
566 entry = container_of(*new, struct line, node); in supinfo_insert()
569 if (line->desc < entry->desc) { in supinfo_insert()
571 } else if (line->desc > entry->desc) { in supinfo_insert()
575 WARN(1, "duplicate line inserted"); in supinfo_insert()
580 rb_link_node(&line->node, parent, new); in supinfo_insert()
581 rb_insert_color(&line->node, &supinfo_tree); in supinfo_insert()
584 static void supinfo_erase(struct line *line) in supinfo_erase() argument
588 rb_erase(&line->node, &supinfo_tree); in supinfo_erase()
591 static struct line *supinfo_find(struct gpio_desc *desc) in supinfo_find()
594 struct line *line; in supinfo_find() local
597 line = container_of(node, struct line, node); in supinfo_find()
598 if (desc < line->desc) in supinfo_find()
600 else if (desc > line->desc) in supinfo_find()
603 return line; in supinfo_find()
612 struct line *line; in supinfo_to_lineinfo() local
616 line = supinfo_find(desc); in supinfo_to_lineinfo()
617 if (!line) in supinfo_to_lineinfo()
622 attr->debounce_period_us = READ_ONCE(line->debounce_period_us); in supinfo_to_lineinfo()
626 static inline bool line_has_supinfo(struct line *line) in line_has_supinfo() argument
628 return READ_ONCE(line->debounce_period_us); in line_has_supinfo()
634 * Called indirectly by linereq_create() or linereq_set_config() so line
637 static void line_set_debounce_period(struct line *line, in line_set_debounce_period() argument
640 bool was_suppl = line_has_supinfo(line); in line_set_debounce_period()
642 WRITE_ONCE(line->debounce_period_us, debounce_period_us); in line_set_debounce_period()
645 if (line_has_supinfo(line) == was_suppl) in line_set_debounce_period()
650 supinfo_erase(line); in line_set_debounce_period()
652 supinfo_insert(line); in line_set_debounce_period()
718 static u64 line_event_timestamp(struct line *line) in line_event_timestamp() argument
720 if (test_bit(FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags)) in line_event_timestamp()
723 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags)) in line_event_timestamp()
724 return line->timestamp_ns; in line_event_timestamp()
758 struct line *line; in process_hw_ts_thread() local
767 line = p; in process_hw_ts_thread()
768 lr = line->req; in process_hw_ts_thread()
772 le.timestamp_ns = line->timestamp_ns; in process_hw_ts_thread()
773 edflags = READ_ONCE(line->edflags); in process_hw_ts_thread()
777 level = (line->raw_level >= 0) ? in process_hw_ts_thread()
778 line->raw_level : in process_hw_ts_thread()
779 gpiod_get_raw_value_cansleep(line->desc); in process_hw_ts_thread()
795 le.line_seqno = line->line_seqno; in process_hw_ts_thread()
796 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in process_hw_ts_thread()
797 le.offset = gpio_chip_hwgpio(line->desc); in process_hw_ts_thread()
806 struct line *line; in process_hw_ts() local
813 line = p; in process_hw_ts()
814 line->timestamp_ns = ts->tsc; in process_hw_ts()
815 line->raw_level = ts->raw_level; in process_hw_ts()
816 lr = line->req; in process_hw_ts()
818 if (READ_ONCE(line->sw_debounced)) { in process_hw_ts()
819 line->total_discard_seq++; in process_hw_ts()
820 line->last_seqno = ts->seq; in process_hw_ts()
821 mod_delayed_work(system_wq, &line->work, in process_hw_ts()
822 usecs_to_jiffies(READ_ONCE(line->debounce_period_us))); in process_hw_ts()
824 if (unlikely(ts->seq < line->line_seqno)) in process_hw_ts()
827 diff_seqno = ts->seq - line->line_seqno; in process_hw_ts()
828 line->line_seqno = ts->seq; in process_hw_ts()
830 line->req_seqno = atomic_add_return(diff_seqno, in process_hw_ts()
839 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
843 struct hte_ts_desc *hdesc = &line->hdesc; in hte_edge_setup()
846 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
850 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
854 line->total_discard_seq = 0; in hte_edge_setup()
856 hte_init_line_attr(hdesc, desc_to_gpio(line->desc), flags, NULL, in hte_edge_setup()
857 line->desc); in hte_edge_setup()
864 line); in hte_edge_setup()
869 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
877 struct line *line = p; in edge_irq_thread() local
878 struct linereq *lr = line->req; in edge_irq_thread()
884 if (line->timestamp_ns) { in edge_irq_thread()
885 le.timestamp_ns = line->timestamp_ns; in edge_irq_thread()
892 le.timestamp_ns = line_event_timestamp(line); in edge_irq_thread()
894 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_thread()
896 line->timestamp_ns = 0; in edge_irq_thread()
898 switch (READ_ONCE(line->edflags) & GPIO_V2_LINE_EDGE_FLAGS) { in edge_irq_thread()
900 le.id = line_event_id(gpiod_get_value_cansleep(line->desc)); in edge_irq_thread()
911 line->line_seqno++; in edge_irq_thread()
912 le.line_seqno = line->line_seqno; in edge_irq_thread()
913 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in edge_irq_thread()
914 le.offset = gpio_chip_hwgpio(line->desc); in edge_irq_thread()
923 struct line *line = p; in edge_irq_handler() local
924 struct linereq *lr = line->req; in edge_irq_handler()
930 line->timestamp_ns = line_event_timestamp(line); in edge_irq_handler()
933 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_handler()
941 static bool debounced_value(struct line *line) in debounced_value() argument
950 value = READ_ONCE(line->level); in debounced_value()
952 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags)) in debounced_value()
960 struct line *line = p; in debounce_irq_handler() local
962 mod_delayed_work(system_wq, &line->work, in debounce_irq_handler()
963 usecs_to_jiffies(READ_ONCE(line->debounce_period_us))); in debounce_irq_handler()
971 struct line *line = container_of(work, struct line, work.work); in debounce_work_func() local
973 u64 eflags, edflags = READ_ONCE(line->edflags); in debounce_work_func()
979 level = line->raw_level; in debounce_work_func()
982 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_work_func()
984 pr_debug_ratelimited("debouncer failed to read line value\n"); in debounce_work_func()
988 if (READ_ONCE(line->level) == level) in debounce_work_func()
991 WRITE_ONCE(line->level, level); in debounce_work_func()
1010 lr = line->req; in debounce_work_func()
1011 le.timestamp_ns = line_event_timestamp(line); in debounce_work_func()
1012 le.offset = gpio_chip_hwgpio(line->desc); in debounce_work_func()
1016 line->total_discard_seq -= 1; in debounce_work_func()
1017 diff_seqno = line->last_seqno - line->total_discard_seq - in debounce_work_func()
1018 line->line_seqno; in debounce_work_func()
1019 line->line_seqno = line->last_seqno - line->total_discard_seq; in debounce_work_func()
1020 le.line_seqno = line->line_seqno; in debounce_work_func()
1026 line->line_seqno++; in debounce_work_func()
1027 le.line_seqno = line->line_seqno; in debounce_work_func()
1037 static int debounce_setup(struct line *line, unsigned int debounce_period_us) in debounce_setup() argument
1044 ret = gpiod_set_debounce(line->desc, debounce_period_us); in debounce_setup()
1046 line_set_debounce_period(line, debounce_period_us); in debounce_setup()
1054 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_setup()
1059 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags))) { in debounce_setup()
1060 irq = gpiod_to_irq(line->desc); in debounce_setup()
1064 label = make_irq_label(line->req->label); in debounce_setup()
1070 label, line); in debounce_setup()
1075 line->irq = irq; in debounce_setup()
1077 ret = hte_edge_setup(line, GPIO_V2_LINE_FLAG_EDGE_BOTH); in debounce_setup()
1082 WRITE_ONCE(line->level, level); in debounce_setup()
1083 WRITE_ONCE(line->sw_debounced, 1); in debounce_setup()
1116 static void edge_detector_stop(struct line *line) in edge_detector_stop() argument
1118 if (line->irq) { in edge_detector_stop()
1119 free_irq_label(free_irq(line->irq, line)); in edge_detector_stop()
1120 line->irq = 0; in edge_detector_stop()
1124 if (READ_ONCE(line->edflags) & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE) in edge_detector_stop()
1125 hte_ts_put(&line->hdesc); in edge_detector_stop()
1128 cancel_delayed_work_sync(&line->work); in edge_detector_stop()
1129 WRITE_ONCE(line->sw_debounced, 0); in edge_detector_stop()
1130 WRITE_ONCE(line->edflags, 0); in edge_detector_stop()
1131 line_set_debounce_period(line, 0); in edge_detector_stop()
1132 /* do not change line->level - see comment in debounced_value() */ in edge_detector_stop()
1143 static int edge_detector_setup(struct line *line, in edge_detector_setup() argument
1155 ret = edge_detector_fifo_init(line->req); in edge_detector_setup()
1161 ret = debounce_setup(line, debounce_period_us); in edge_detector_setup()
1164 line_set_debounce_period(line, debounce_period_us); in edge_detector_setup()
1168 if (!eflags || READ_ONCE(line->sw_debounced)) in edge_detector_setup()
1173 return hte_edge_setup(line, edflags); in edge_detector_setup()
1175 irq = gpiod_to_irq(line->desc); in edge_detector_setup()
1180 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1183 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1187 label = make_irq_label(line->req->label); in edge_detector_setup()
1193 irqflags, label, line); in edge_detector_setup()
1199 line->irq = irq; in edge_detector_setup()
1203 static int edge_detector_update(struct line *line, in edge_detector_update() argument
1207 u64 active_edflags = READ_ONCE(line->edflags); in edge_detector_update()
1212 (READ_ONCE(line->debounce_period_us) == debounce_period_us)) in edge_detector_update()
1216 if (debounce_period_us && READ_ONCE(line->sw_debounced)) { in edge_detector_update()
1217 line_set_debounce_period(line, debounce_period_us); in edge_detector_update()
1223 return edge_detector_fifo_init(line->req); in edge_detector_update()
1229 if ((line->irq && !READ_ONCE(line->sw_debounced)) || in edge_detector_update()
1231 (!debounce_period_us && READ_ONCE(line->sw_debounced))) in edge_detector_update()
1232 edge_detector_stop(line); in edge_detector_update()
1234 return edge_detector_setup(line, lc, line_idx, edflags); in edge_detector_update()
1519 struct line *line; in linereq_set_config() local
1534 line = &lr->lines[i]; in linereq_set_config()
1548 edge_detector_stop(line); in linereq_set_config()
1557 ret = edge_detector_update(line, &lc, i, edflags); in linereq_set_config()
1562 WRITE_ONCE(line->edflags, edflags); in linereq_set_config()
1672 struct line *line; in linereq_free() local
1680 line = &lr->lines[i]; in linereq_free()
1681 if (!line->desc) in linereq_free()
1684 edge_detector_stop(line); in linereq_free()
1685 if (line_has_supinfo(line)) in linereq_free()
1686 supinfo_erase(line); in linereq_free()
1687 gpiod_free(line->desc); in linereq_free()
1713 seq_printf(out, "gpio-line:\t%d\n", in linereq_show_fdinfo()
1816 * or output, else the line will be treated "as is". in linereq_create()
1839 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", in linereq_create()
1855 file = anon_inode_getfile("gpio-line", &line_fileops, lr, in linereq_create()
1890 * GPIO line event management
1898 * @eflags: the event flags this line was requested with
2055 * We can get the value for an event line but not set it, in lineevent_ioctl()
2385 * once. Worst case if the line is in transition and the calculation in gpio_desc_to_lineinfo()
2389 * The definitive test that a line is available to userspace is to in gpio_desc_to_lineinfo()