Lines Matching refs:line

105  * GPIO line handle management
219 * or output, else the line will be treated "as is".
270 * All line descriptors were created at once with the same
401 * or output, else the line will be treated "as is".
417 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n",
463 * struct line - contains the state of a requested line
464 * @desc: the GPIO descriptor for this line.
465 * @req: the corresponding line request
472 * events for the corresponding line request. This is drawn from the @req.
474 * events for this line.
477 * @level: the current debounced physical level of the line
479 * @raw_level: the line level at the time of event
483 struct line {
532 * HTE provider sets line level at the time of event. The valid
537 * when sw_debounce is set on HTE enabled line, this is running
542 * when sw_debounce is set on HTE enabled line, this variable records
550 * struct linereq - contains the state of a userspace line request
551 * @gdev: the GPIO device the line request pertains to
559 * this line request. Note that this is not used when @num_lines is 1, as
563 * @lines: the lines held by this line request, with @num_lines elements.
575 struct line lines[];
641 static u64 line_event_timestamp(struct line *line)
643 if (test_bit(FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags))
646 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags))
647 return line->timestamp_ns;
662 struct line *line;
671 line = p;
672 lr = line->req;
676 le.timestamp_ns = line->timestamp_ns;
677 edflags = READ_ONCE(line->edflags);
681 level = (line->raw_level >= 0) ?
682 line->raw_level :
683 gpiod_get_raw_value_cansleep(line->desc);
699 le.line_seqno = line->line_seqno;
700 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno;
701 le.offset = gpio_chip_hwgpio(line->desc);
710 struct line *line;
717 line = p;
718 line->timestamp_ns = ts->tsc;
719 line->raw_level = ts->raw_level;
720 lr = line->req;
722 if (READ_ONCE(line->sw_debounced)) {
723 line->total_discard_seq++;
724 line->last_seqno = ts->seq;
725 mod_delayed_work(system_wq, &line->work,
726 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us)));
728 if (unlikely(ts->seq < line->line_seqno))
731 diff_seqno = ts->seq - line->line_seqno;
732 line->line_seqno = ts->seq;
734 line->req_seqno = atomic_add_return(diff_seqno,
743 static int hte_edge_setup(struct line *line, u64 eflags)
747 struct hte_ts_desc *hdesc = &line->hdesc;
750 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ?
754 flags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ?
758 line->total_discard_seq = 0;
760 hte_init_line_attr(hdesc, desc_to_gpio(line->desc), flags, NULL,
761 line->desc);
768 line);
773 static int hte_edge_setup(struct line *line, u64 eflags)
781 struct line *line = p;
782 struct linereq *lr = line->req;
788 if (line->timestamp_ns) {
789 le.timestamp_ns = line->timestamp_ns;
796 le.timestamp_ns = line_event_timestamp(line);
798 line->req_seqno = atomic_inc_return(&lr->seqno);
800 line->timestamp_ns = 0;
802 switch (READ_ONCE(line->edflags) & GPIO_V2_LINE_EDGE_FLAGS) {
804 le.id = line_event_id(gpiod_get_value_cansleep(line->desc));
815 line->line_seqno++;
816 le.line_seqno = line->line_seqno;
817 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno;
818 le.offset = gpio_chip_hwgpio(line->desc);
827 struct line *line = p;
828 struct linereq *lr = line->req;
834 line->timestamp_ns = line_event_timestamp(line);
837 line->req_seqno = atomic_inc_return(&lr->seqno);
845 static bool debounced_value(struct line *line)
854 value = READ_ONCE(line->level);
856 if (test_bit(FLAG_ACTIVE_LOW, &line->desc->flags))
864 struct line *line = p;
866 mod_delayed_work(system_wq, &line->work,
867 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us)));
875 struct line *line = container_of(work, struct line, work.work);
877 u64 eflags, edflags = READ_ONCE(line->edflags);
883 level = line->raw_level;
886 level = gpiod_get_raw_value_cansleep(line->desc);
888 pr_debug_ratelimited("debouncer failed to read line value\n");
892 if (READ_ONCE(line->level) == level)
895 WRITE_ONCE(line->level, level);
914 lr = line->req;
915 le.timestamp_ns = line_event_timestamp(line);
916 le.offset = gpio_chip_hwgpio(line->desc);
920 line->total_discard_seq -= 1;
921 diff_seqno = line->last_seqno - line->total_discard_seq -
922 line->line_seqno;
923 line->line_seqno = line->last_seqno - line->total_discard_seq;
924 le.line_seqno = line->line_seqno;
930 line->line_seqno++;
931 le.line_seqno = line->line_seqno;
941 static int debounce_setup(struct line *line, unsigned int debounce_period_us)
947 ret = gpiod_set_debounce(line->desc, debounce_period_us);
949 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us);
957 level = gpiod_get_raw_value_cansleep(line->desc);
962 test_bit(FLAG_EVENT_CLOCK_HTE, &line->desc->flags))) {
963 irq = gpiod_to_irq(line->desc);
969 line->req->label, line);
972 line->irq = irq;
974 ret = hte_edge_setup(line, GPIO_V2_LINE_FLAG_EDGE_BOTH);
979 WRITE_ONCE(line->level, level);
980 WRITE_ONCE(line->sw_debounced, 1);
1013 static void edge_detector_stop(struct line *line)
1015 if (line->irq) {
1016 free_irq(line->irq, line);
1017 line->irq = 0;
1021 if (READ_ONCE(line->edflags) & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE)
1022 hte_ts_put(&line->hdesc);
1025 cancel_delayed_work_sync(&line->work);
1026 WRITE_ONCE(line->sw_debounced, 0);
1027 WRITE_ONCE(line->edflags, 0);
1028 if (line->desc)
1029 WRITE_ONCE(line->desc->debounce_period_us, 0);
1030 /* do not change line->level - see comment in debounced_value() */
1033 static int edge_detector_setup(struct line *line,
1043 if (eflags && !kfifo_initialized(&line->req->events)) {
1044 ret = kfifo_alloc(&line->req->events,
1045 line->req->event_buffer_size, GFP_KERNEL);
1051 ret = debounce_setup(line, debounce_period_us);
1054 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us);
1058 if (!eflags || READ_ONCE(line->sw_debounced))
1063 return hte_edge_setup(line, edflags);
1065 irq = gpiod_to_irq(line->desc);
1070 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ?
1073 irqflags |= test_bit(FLAG_ACTIVE_LOW, &line->desc->flags) ?
1079 irqflags, line->req->label, line);
1083 line->irq = irq;
1087 static int edge_detector_update(struct line *line,
1091 u64 active_edflags = READ_ONCE(line->edflags);
1096 (READ_ONCE(line->desc->debounce_period_us) == debounce_period_us))
1100 if (debounce_period_us && READ_ONCE(line->sw_debounced)) {
1101 WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us);
1106 if ((line->irq && !READ_ONCE(line->sw_debounced)) ||
1108 (!debounce_period_us && READ_ONCE(line->sw_debounced)))
1109 edge_detector_stop(line);
1111 return edge_detector_setup(line, lc, line_idx, edflags);
1386 struct line *line;
1392 line = &lr->lines[i];
1399 * or output, else the line will be treated "as is".
1404 edge_detector_stop(line);
1413 ret = edge_detector_update(line, lc, i, edflags);
1418 WRITE_ONCE(line->edflags, edflags);
1612 seq_printf(out, "gpio-line:\t%d\n",
1714 * or output, else the line will be treated "as is".
1737 dev_dbg(&gdev->dev, "registered chardev handle for line %d\n",
1753 file = anon_inode_getfile("gpio-line", &line_fileops, lr,
1788 * GPIO line event management
1796 * @eflags: the event flags this line was requested with
1971 * We can get the value for an event line but not set it,