Lines Matching full:line
70 * GPIO line handle management
184 * or output, else the line will be treated "as is". in linehandle_set_config()
237 * All line descriptors were created at once with the same in linehandle_ioctl()
359 * or output, else the line will be treated "as is". in linehandle_create()
375 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", in linehandle_create()
421 * struct line - contains the state of a requested line
423 * @desc: the GPIO descriptor for this line.
424 * @req: the corresponding line request
431 * events for the corresponding line request. This is drawn from the @req.
433 * events for this line.
437 * @level: the current debounced physical level of the line
439 * @raw_level: the line level at the time of event
443 struct line { struct
502 * HTE provider sets line level at the time of event. The valid argument
507 * when sw_debounce is set on HTE enabled line, this is running argument
512 * when sw_debounce is set on HTE enabled line, this variable records argument
523 * A line is determined to contain supplemental information by argument
531 * struct linereq - contains the state of a userspace line request
532 * @gdev: the GPIO device the line request pertains to
540 * this line request. Note that this is not used when @num_lines is 1, as
545 * @lines: the lines held by this line request, with @num_lines elements.
557 struct line lines[] __counted_by(num_lines);
560 static void supinfo_insert(struct line *line) in supinfo_insert() argument
563 struct line *entry; in supinfo_insert()
568 entry = container_of(*new, struct line, node); in supinfo_insert()
571 if (line->desc < entry->desc) { in supinfo_insert()
573 } else if (line->desc > entry->desc) { in supinfo_insert()
577 WARN(1, "duplicate line inserted"); in supinfo_insert()
582 rb_link_node(&line->node, parent, new); in supinfo_insert()
583 rb_insert_color(&line->node, &supinfo_tree); in supinfo_insert()
586 static void supinfo_erase(struct line *line) in supinfo_erase() argument
590 rb_erase(&line->node, &supinfo_tree); in supinfo_erase()
593 static struct line *supinfo_find(struct gpio_desc *desc) in supinfo_find()
596 struct line *line; in supinfo_find() local
599 line = container_of(node, struct line, node); in supinfo_find()
600 if (desc < line->desc) in supinfo_find()
602 else if (desc > line->desc) in supinfo_find()
605 return line; in supinfo_find()
614 struct line *line; in supinfo_to_lineinfo() local
618 line = supinfo_find(desc); in supinfo_to_lineinfo()
619 if (!line) in supinfo_to_lineinfo()
624 attr->debounce_period_us = READ_ONCE(line->debounce_period_us); in supinfo_to_lineinfo()
628 static inline bool line_has_supinfo(struct line *line) in line_has_supinfo() argument
630 return READ_ONCE(line->debounce_period_us); in line_has_supinfo()
636 * Called indirectly by linereq_create() or linereq_set_config() so line
639 static void line_set_debounce_period(struct line *line, in line_set_debounce_period() argument
642 bool was_suppl = line_has_supinfo(line); in line_set_debounce_period()
644 WRITE_ONCE(line->debounce_period_us, debounce_period_us); in line_set_debounce_period()
647 if (line_has_supinfo(line) == was_suppl) in line_set_debounce_period()
652 supinfo_erase(line); in line_set_debounce_period()
654 supinfo_insert(line); in line_set_debounce_period()
720 static u64 line_event_timestamp(struct line *line) in line_event_timestamp() argument
722 if (test_bit(FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags)) in line_event_timestamp()
725 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags)) in line_event_timestamp()
726 return line->timestamp_ns; in line_event_timestamp()
741 struct line *line; in process_hw_ts_thread() local
750 line = p; in process_hw_ts_thread()
751 lr = line->req; in process_hw_ts_thread()
755 le.timestamp_ns = line->timestamp_ns; in process_hw_ts_thread()
756 edflags = READ_ONCE(line->edflags); in process_hw_ts_thread()
760 level = (line->raw_level >= 0) ? in process_hw_ts_thread()
761 line->raw_level : in process_hw_ts_thread()
762 gpiod_get_raw_value_cansleep(line->desc); in process_hw_ts_thread()
778 le.line_seqno = line->line_seqno; in process_hw_ts_thread()
779 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in process_hw_ts_thread()
780 le.offset = gpio_chip_hwgpio(line->desc); in process_hw_ts_thread()
789 struct line *line; in process_hw_ts() local
796 line = p; in process_hw_ts()
797 line->timestamp_ns = ts->tsc; in process_hw_ts()
798 line->raw_level = ts->raw_level; in process_hw_ts()
799 lr = line->req; in process_hw_ts()
801 if (READ_ONCE(line->sw_debounced)) { in process_hw_ts()
802 line->total_discard_seq++; in process_hw_ts()
803 line->last_seqno = ts->seq; in process_hw_ts()
804 mod_delayed_work(system_wq, &line->work, in process_hw_ts()
805 usecs_to_jiffies(READ_ONCE(line->debounce_period_us))); in process_hw_ts()
807 if (unlikely(ts->seq < line->line_seqno)) in process_hw_ts()
810 diff_seqno = ts->seq - line->line_seqno; in process_hw_ts()
811 line->line_seqno = ts->seq; in process_hw_ts()
813 line->req_seqno = atomic_add_return(diff_seqno, in process_hw_ts()
822 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
826 struct hte_ts_desc *hdesc = &line->hdesc; in hte_edge_setup()
829 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
833 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in hte_edge_setup()
837 line->total_discard_seq = 0; in hte_edge_setup()
839 hte_init_line_attr(hdesc, desc_to_gpio(line->desc), flags, NULL, in hte_edge_setup()
840 line->desc); in hte_edge_setup()
847 line); in hte_edge_setup()
852 static int hte_edge_setup(struct line *line, u64 eflags) in hte_edge_setup() argument
860 struct line *line = p; in edge_irq_thread() local
861 struct linereq *lr = line->req; in edge_irq_thread()
867 if (line->timestamp_ns) { in edge_irq_thread()
868 le.timestamp_ns = line->timestamp_ns; in edge_irq_thread()
875 le.timestamp_ns = line_event_timestamp(line); in edge_irq_thread()
877 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_thread()
879 line->timestamp_ns = 0; in edge_irq_thread()
881 switch (READ_ONCE(line->edflags) & GPIO_V2_LINE_EDGE_FLAGS) { in edge_irq_thread()
883 le.id = line_event_id(gpiod_get_value_cansleep(line->desc)); in edge_irq_thread()
894 line->line_seqno++; in edge_irq_thread()
895 le.line_seqno = line->line_seqno; in edge_irq_thread()
896 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; in edge_irq_thread()
897 le.offset = gpio_chip_hwgpio(line->desc); in edge_irq_thread()
906 struct line *line = p; in edge_irq_handler() local
907 struct linereq *lr = line->req; in edge_irq_handler()
913 line->timestamp_ns = line_event_timestamp(line); in edge_irq_handler()
916 line->req_seqno = atomic_inc_return(&lr->seqno); in edge_irq_handler()
924 static bool debounced_value(struct line *line) in debounced_value() argument
933 value = READ_ONCE(line->level); in debounced_value()
935 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags)) in debounced_value()
943 struct line *line = p; in debounce_irq_handler() local
945 mod_delayed_work(system_wq, &line->work, in debounce_irq_handler()
946 usecs_to_jiffies(READ_ONCE(line->debounce_period_us))); in debounce_irq_handler()
954 struct line *line = container_of(work, struct line, work.work); in debounce_work_func() local
956 u64 eflags, edflags = READ_ONCE(line->edflags); in debounce_work_func()
962 level = line->raw_level; in debounce_work_func()
965 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_work_func()
967 pr_debug_ratelimited("debouncer failed to read line value\n"); in debounce_work_func()
971 if (READ_ONCE(line->level) == level) in debounce_work_func()
974 WRITE_ONCE(line->level, level); in debounce_work_func()
993 lr = line->req; in debounce_work_func()
994 le.timestamp_ns = line_event_timestamp(line); in debounce_work_func()
995 le.offset = gpio_chip_hwgpio(line->desc); in debounce_work_func()
999 line->total_discard_seq -= 1; in debounce_work_func()
1000 diff_seqno = line->last_seqno - line->total_discard_seq - in debounce_work_func()
1001 line->line_seqno; in debounce_work_func()
1002 line->line_seqno = line->last_seqno - line->total_discard_seq; in debounce_work_func()
1003 le.line_seqno = line->line_seqno; in debounce_work_func()
1009 line->line_seqno++; in debounce_work_func()
1010 le.line_seqno = line->line_seqno; in debounce_work_func()
1020 static int debounce_setup(struct line *line, unsigned int debounce_period_us) in debounce_setup() argument
1026 ret = gpiod_set_debounce(line->desc, debounce_period_us); in debounce_setup()
1028 line_set_debounce_period(line, debounce_period_us); in debounce_setup()
1036 level = gpiod_get_raw_value_cansleep(line->desc); in debounce_setup()
1041 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags))) { in debounce_setup()
1042 irq = gpiod_to_irq(line->desc); in debounce_setup()
1048 line->req->label, line); in debounce_setup()
1051 line->irq = irq; in debounce_setup()
1053 ret = hte_edge_setup(line, GPIO_V2_LINE_FLAG_EDGE_BOTH); in debounce_setup()
1058 WRITE_ONCE(line->level, level); in debounce_setup()
1059 WRITE_ONCE(line->sw_debounced, 1); in debounce_setup()
1092 static void edge_detector_stop(struct line *line) in edge_detector_stop() argument
1094 if (line->irq) { in edge_detector_stop()
1095 free_irq(line->irq, line); in edge_detector_stop()
1096 line->irq = 0; in edge_detector_stop()
1100 if (READ_ONCE(line->edflags) & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE) in edge_detector_stop()
1101 hte_ts_put(&line->hdesc); in edge_detector_stop()
1104 cancel_delayed_work_sync(&line->work); in edge_detector_stop()
1105 WRITE_ONCE(line->sw_debounced, 0); in edge_detector_stop()
1106 WRITE_ONCE(line->edflags, 0); in edge_detector_stop()
1107 line_set_debounce_period(line, 0); in edge_detector_stop()
1108 /* do not change line->level - see comment in debounced_value() */ in edge_detector_stop()
1111 static int edge_detector_setup(struct line *line, in edge_detector_setup() argument
1121 if (eflags && !kfifo_initialized(&line->req->events)) { in edge_detector_setup()
1122 ret = kfifo_alloc(&line->req->events, in edge_detector_setup()
1123 line->req->event_buffer_size, GFP_KERNEL); in edge_detector_setup()
1129 ret = debounce_setup(line, debounce_period_us); in edge_detector_setup()
1132 line_set_debounce_period(line, debounce_period_us); in edge_detector_setup()
1136 if (!eflags || READ_ONCE(line->sw_debounced)) in edge_detector_setup()
1141 return hte_edge_setup(line, edflags); in edge_detector_setup()
1143 irq = gpiod_to_irq(line->desc); in edge_detector_setup()
1148 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1151 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ? in edge_detector_setup()
1157 irqflags, line->req->label, line); in edge_detector_setup()
1161 line->irq = irq; in edge_detector_setup()
1165 static int edge_detector_update(struct line *line, in edge_detector_update() argument
1169 u64 active_edflags = READ_ONCE(line->edflags); in edge_detector_update()
1174 (READ_ONCE(line->debounce_period_us) == debounce_period_us)) in edge_detector_update()
1178 if (debounce_period_us && READ_ONCE(line->sw_debounced)) { in edge_detector_update()
1179 line_set_debounce_period(line, debounce_period_us); in edge_detector_update()
1184 if ((line->irq && !READ_ONCE(line->sw_debounced)) || in edge_detector_update()
1186 (!debounce_period_us && READ_ONCE(line->sw_debounced))) in edge_detector_update()
1187 edge_detector_stop(line); in edge_detector_update()
1189 return edge_detector_setup(line, lc, line_idx, edflags); in edge_detector_update()
1474 struct line *line; in linereq_set_config() local
1489 line = &lr->lines[i]; in linereq_set_config()
1496 * or output, else the line will be treated "as is". in linereq_set_config()
1501 edge_detector_stop(line); in linereq_set_config()
1510 ret = edge_detector_update(line, &lc, i, edflags); in linereq_set_config()
1515 WRITE_ONCE(line->edflags, edflags); in linereq_set_config()
1626 struct line *line; in linereq_free() local
1634 line = &lr->lines[i]; in linereq_free()
1635 if (!line->desc) in linereq_free()
1638 edge_detector_stop(line); in linereq_free()
1639 if (line_has_supinfo(line)) in linereq_free()
1640 supinfo_erase(line); in linereq_free()
1641 gpiod_free(line->desc); in linereq_free()
1667 seq_printf(out, "gpio-line:\t%d\n", in linereq_show_fdinfo()
1769 * or output, else the line will be treated "as is". in linereq_create()
1792 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", in linereq_create()
1808 file = anon_inode_getfile("gpio-line", &line_fileops, lr, in linereq_create()
1843 * GPIO line event management
1851 * @eflags: the event flags this line was requested with
2009 * We can get the value for an event line but not set it, in lineevent_ioctl()
2325 * once. Worst case if the line is in transition and the calculation in gpio_desc_to_lineinfo()
2329 * The definitive test that a line is available to userspace is to in gpio_desc_to_lineinfo()