Lines Matching refs:pin

112 static void cec_pin_update(struct cec_pin *pin, bool v, bool force)  in cec_pin_update()  argument
114 if (!force && v == pin->adap->cec_pin_is_high) in cec_pin_update()
117 pin->adap->cec_pin_is_high = v; in cec_pin_update()
118 if (atomic_read(&pin->work_pin_num_events) < CEC_NUM_PIN_EVENTS) { in cec_pin_update()
121 if (pin->work_pin_events_dropped) { in cec_pin_update()
122 pin->work_pin_events_dropped = false; in cec_pin_update()
125 pin->work_pin_events[pin->work_pin_events_wr] = ev; in cec_pin_update()
126 pin->work_pin_ts[pin->work_pin_events_wr] = ktime_get(); in cec_pin_update()
127 pin->work_pin_events_wr = in cec_pin_update()
128 (pin->work_pin_events_wr + 1) % CEC_NUM_PIN_EVENTS; in cec_pin_update()
129 atomic_inc(&pin->work_pin_num_events); in cec_pin_update()
131 pin->work_pin_events_dropped = true; in cec_pin_update()
132 pin->work_pin_events_dropped_cnt++; in cec_pin_update()
134 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_update()
137 static bool cec_pin_read(struct cec_pin *pin) in cec_pin_read() argument
139 bool v = call_pin_op(pin, read); in cec_pin_read()
141 cec_pin_update(pin, v, false); in cec_pin_read()
145 static void cec_pin_insert_glitch(struct cec_pin *pin, bool rising_edge) in cec_pin_insert_glitch() argument
153 if (!pin->tx_glitch_high_usecs || !pin->tx_glitch_low_usecs) in cec_pin_insert_glitch()
156 udelay(pin->tx_glitch_high_usecs); in cec_pin_insert_glitch()
157 call_void_pin_op(pin, low); in cec_pin_insert_glitch()
158 udelay(pin->tx_glitch_low_usecs); in cec_pin_insert_glitch()
159 call_void_pin_op(pin, high); in cec_pin_insert_glitch()
161 udelay(pin->tx_glitch_low_usecs); in cec_pin_insert_glitch()
162 call_void_pin_op(pin, high); in cec_pin_insert_glitch()
163 udelay(pin->tx_glitch_high_usecs); in cec_pin_insert_glitch()
164 call_void_pin_op(pin, low); in cec_pin_insert_glitch()
168 static void cec_pin_low(struct cec_pin *pin) in cec_pin_low() argument
170 call_void_pin_op(pin, low); in cec_pin_low()
171 if (pin->tx_glitch_falling_edge && pin->adap->cec_pin_is_high) in cec_pin_low()
172 cec_pin_insert_glitch(pin, false); in cec_pin_low()
173 cec_pin_update(pin, false, false); in cec_pin_low()
176 static bool cec_pin_high(struct cec_pin *pin) in cec_pin_high() argument
178 call_void_pin_op(pin, high); in cec_pin_high()
179 if (pin->tx_glitch_rising_edge && !pin->adap->cec_pin_is_high) in cec_pin_high()
180 cec_pin_insert_glitch(pin, true); in cec_pin_high()
181 return cec_pin_read(pin); in cec_pin_high()
184 static bool rx_error_inj(struct cec_pin *pin, unsigned int mode_offset, in rx_error_inj() argument
188 u16 cmd = cec_pin_rx_error_inj(pin); in rx_error_inj()
189 u64 e = pin->error_inj[cmd]; in rx_error_inj()
193 u8 pos = pin->error_inj_args[cmd][arg_idx]; in rx_error_inj()
197 else if (pos != pin->rx_bit) in rx_error_inj()
203 pin->error_inj[cmd] &= in rx_error_inj()
209 return pin->rx_toggle; in rx_error_inj()
218 static bool rx_nack(struct cec_pin *pin) in rx_nack() argument
220 return rx_error_inj(pin, CEC_ERROR_INJ_RX_NACK_OFFSET, -1, NULL); in rx_nack()
223 static bool rx_low_drive(struct cec_pin *pin) in rx_low_drive() argument
225 return rx_error_inj(pin, CEC_ERROR_INJ_RX_LOW_DRIVE_OFFSET, in rx_low_drive()
229 static bool rx_add_byte(struct cec_pin *pin) in rx_add_byte() argument
231 return rx_error_inj(pin, CEC_ERROR_INJ_RX_ADD_BYTE_OFFSET, -1, NULL); in rx_add_byte()
234 static bool rx_remove_byte(struct cec_pin *pin) in rx_remove_byte() argument
236 return rx_error_inj(pin, CEC_ERROR_INJ_RX_REMOVE_BYTE_OFFSET, -1, NULL); in rx_remove_byte()
239 static bool rx_arb_lost(struct cec_pin *pin, u8 *poll) in rx_arb_lost() argument
241 return pin->tx_msg.len == 0 && in rx_arb_lost()
242 rx_error_inj(pin, CEC_ERROR_INJ_RX_ARB_LOST_OFFSET, in rx_arb_lost()
246 static bool tx_error_inj(struct cec_pin *pin, unsigned int mode_offset, in tx_error_inj() argument
250 u16 cmd = cec_pin_tx_error_inj(pin); in tx_error_inj()
251 u64 e = pin->error_inj[cmd]; in tx_error_inj()
255 u8 pos = pin->error_inj_args[cmd][arg_idx]; in tx_error_inj()
259 else if (pos != pin->tx_bit) in tx_error_inj()
265 pin->error_inj[cmd] &= in tx_error_inj()
271 return pin->tx_toggle; in tx_error_inj()
280 static bool tx_no_eom(struct cec_pin *pin) in tx_no_eom() argument
282 return tx_error_inj(pin, CEC_ERROR_INJ_TX_NO_EOM_OFFSET, -1, NULL); in tx_no_eom()
285 static bool tx_early_eom(struct cec_pin *pin) in tx_early_eom() argument
287 return tx_error_inj(pin, CEC_ERROR_INJ_TX_EARLY_EOM_OFFSET, -1, NULL); in tx_early_eom()
290 static bool tx_short_bit(struct cec_pin *pin) in tx_short_bit() argument
292 return tx_error_inj(pin, CEC_ERROR_INJ_TX_SHORT_BIT_OFFSET, in tx_short_bit()
296 static bool tx_long_bit(struct cec_pin *pin) in tx_long_bit() argument
298 return tx_error_inj(pin, CEC_ERROR_INJ_TX_LONG_BIT_OFFSET, in tx_long_bit()
302 static bool tx_custom_bit(struct cec_pin *pin) in tx_custom_bit() argument
304 return tx_error_inj(pin, CEC_ERROR_INJ_TX_CUSTOM_BIT_OFFSET, in tx_custom_bit()
308 static bool tx_short_start(struct cec_pin *pin) in tx_short_start() argument
310 return tx_error_inj(pin, CEC_ERROR_INJ_TX_SHORT_START_OFFSET, -1, NULL); in tx_short_start()
313 static bool tx_long_start(struct cec_pin *pin) in tx_long_start() argument
315 return tx_error_inj(pin, CEC_ERROR_INJ_TX_LONG_START_OFFSET, -1, NULL); in tx_long_start()
318 static bool tx_custom_start(struct cec_pin *pin) in tx_custom_start() argument
320 return tx_error_inj(pin, CEC_ERROR_INJ_TX_CUSTOM_START_OFFSET, in tx_custom_start()
324 static bool tx_last_bit(struct cec_pin *pin) in tx_last_bit() argument
326 return tx_error_inj(pin, CEC_ERROR_INJ_TX_LAST_BIT_OFFSET, in tx_last_bit()
330 static u8 tx_add_bytes(struct cec_pin *pin) in tx_add_bytes() argument
334 if (tx_error_inj(pin, CEC_ERROR_INJ_TX_ADD_BYTES_OFFSET, in tx_add_bytes()
340 static bool tx_remove_byte(struct cec_pin *pin) in tx_remove_byte() argument
342 return tx_error_inj(pin, CEC_ERROR_INJ_TX_REMOVE_BYTE_OFFSET, -1, NULL); in tx_remove_byte()
345 static bool tx_low_drive(struct cec_pin *pin) in tx_low_drive() argument
347 return tx_error_inj(pin, CEC_ERROR_INJ_TX_LOW_DRIVE_OFFSET, in tx_low_drive()
351 static void cec_pin_to_idle(struct cec_pin *pin) in cec_pin_to_idle() argument
357 pin->rx_bit = pin->tx_bit = 0; in cec_pin_to_idle()
358 pin->rx_msg.len = 0; in cec_pin_to_idle()
359 memset(pin->rx_msg.msg, 0, sizeof(pin->rx_msg.msg)); in cec_pin_to_idle()
360 pin->ts = ns_to_ktime(0); in cec_pin_to_idle()
361 pin->tx_generated_poll = false; in cec_pin_to_idle()
362 pin->tx_post_eom = false; in cec_pin_to_idle()
363 if (pin->state >= CEC_ST_TX_WAIT && in cec_pin_to_idle()
364 pin->state <= CEC_ST_TX_LOW_DRIVE) in cec_pin_to_idle()
365 pin->tx_toggle ^= 1; in cec_pin_to_idle()
366 if (pin->state >= CEC_ST_RX_START_BIT_LOW && in cec_pin_to_idle()
367 pin->state <= CEC_ST_RX_LOW_DRIVE) in cec_pin_to_idle()
368 pin->rx_toggle ^= 1; in cec_pin_to_idle()
369 pin->state = CEC_ST_IDLE; in cec_pin_to_idle()
398 static void cec_pin_tx_states(struct cec_pin *pin, ktime_t ts) in cec_pin_tx_states() argument
403 switch (pin->state) { in cec_pin_tx_states()
405 if (cec_pin_read(pin)) in cec_pin_tx_states()
406 cec_pin_to_idle(pin); in cec_pin_tx_states()
410 if (tx_short_start(pin)) { in cec_pin_tx_states()
415 pin->state = CEC_ST_TX_START_BIT_HIGH_SHORT; in cec_pin_tx_states()
416 } else if (tx_long_start(pin)) { in cec_pin_tx_states()
421 pin->state = CEC_ST_TX_START_BIT_HIGH_LONG; in cec_pin_tx_states()
423 pin->state = CEC_ST_TX_START_BIT_HIGH; in cec_pin_tx_states()
426 cec_pin_high(pin); in cec_pin_tx_states()
430 pin->state = CEC_ST_TX_START_BIT_HIGH_CUSTOM; in cec_pin_tx_states()
432 cec_pin_high(pin); in cec_pin_tx_states()
438 if (pin->tx_nacked) { in cec_pin_tx_states()
439 cec_pin_to_idle(pin); in cec_pin_tx_states()
440 pin->tx_msg.len = 0; in cec_pin_tx_states()
441 if (pin->tx_generated_poll) in cec_pin_tx_states()
443 pin->work_tx_ts = ts; in cec_pin_tx_states()
444 pin->work_tx_status = CEC_TX_STATUS_NACK; in cec_pin_tx_states()
445 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_tx_states()
463 if (!cec_pin_read(pin) && !pin->tx_generated_poll) { in cec_pin_tx_states()
468 pin->tx_msg.len = 0; in cec_pin_tx_states()
469 pin->state = CEC_ST_TX_WAIT_FOR_HIGH; in cec_pin_tx_states()
470 pin->work_tx_ts = ts; in cec_pin_tx_states()
471 pin->work_tx_status = CEC_TX_STATUS_LOW_DRIVE; in cec_pin_tx_states()
472 pin->tx_low_drive_cnt++; in cec_pin_tx_states()
473 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_tx_states()
478 if (tx_last_bit(pin)) { in cec_pin_tx_states()
480 cec_pin_to_idle(pin); in cec_pin_tx_states()
481 pin->tx_msg.len = 0; in cec_pin_tx_states()
482 if (pin->tx_generated_poll) in cec_pin_tx_states()
484 pin->work_tx_ts = ts; in cec_pin_tx_states()
485 pin->work_tx_status = CEC_TX_STATUS_OK; in cec_pin_tx_states()
486 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_tx_states()
489 pin->tx_bit++; in cec_pin_tx_states()
495 if (tx_low_drive(pin)) { in cec_pin_tx_states()
497 cec_pin_low(pin); in cec_pin_tx_states()
498 pin->state = CEC_ST_TX_LOW_DRIVE; in cec_pin_tx_states()
499 pin->tx_msg.len = 0; in cec_pin_tx_states()
500 if (pin->tx_generated_poll) in cec_pin_tx_states()
502 pin->work_tx_ts = ts; in cec_pin_tx_states()
503 pin->work_tx_status = CEC_TX_STATUS_LOW_DRIVE; in cec_pin_tx_states()
504 pin->tx_low_drive_cnt++; in cec_pin_tx_states()
505 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_tx_states()
508 if (pin->tx_bit / 10 >= pin->tx_msg.len + pin->tx_extra_bytes) { in cec_pin_tx_states()
509 cec_pin_to_idle(pin); in cec_pin_tx_states()
510 pin->tx_msg.len = 0; in cec_pin_tx_states()
511 if (pin->tx_generated_poll) in cec_pin_tx_states()
513 pin->work_tx_ts = ts; in cec_pin_tx_states()
514 pin->work_tx_status = CEC_TX_STATUS_OK; in cec_pin_tx_states()
515 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_tx_states()
519 switch (pin->tx_bit % 10) { in cec_pin_tx_states()
527 unsigned int idx = (pin->tx_bit / 10); in cec_pin_tx_states()
530 if (idx < pin->tx_msg.len) in cec_pin_tx_states()
531 val = pin->tx_msg.msg[idx]; in cec_pin_tx_states()
532 v = val & (1 << (7 - (pin->tx_bit % 10))); in cec_pin_tx_states()
534 pin->state = v ? CEC_ST_TX_DATA_BIT_1_LOW : in cec_pin_tx_states()
539 unsigned int tot_len = pin->tx_msg.len + in cec_pin_tx_states()
540 pin->tx_extra_bytes; in cec_pin_tx_states()
541 unsigned int tx_byte_idx = pin->tx_bit / 10; in cec_pin_tx_states()
543 v = !pin->tx_post_eom && tx_byte_idx == tot_len - 1; in cec_pin_tx_states()
545 tx_early_eom(pin)) { in cec_pin_tx_states()
548 pin->tx_post_eom = true; in cec_pin_tx_states()
549 } else if (v && tx_no_eom(pin)) { in cec_pin_tx_states()
553 pin->state = v ? CEC_ST_TX_DATA_BIT_1_LOW : in cec_pin_tx_states()
558 pin->state = CEC_ST_TX_DATA_BIT_1_LOW; in cec_pin_tx_states()
561 if (tx_custom_bit(pin)) in cec_pin_tx_states()
562 pin->state = CEC_ST_TX_DATA_BIT_LOW_CUSTOM; in cec_pin_tx_states()
563 cec_pin_low(pin); in cec_pin_tx_states()
568 v = pin->state == CEC_ST_TX_DATA_BIT_1_LOW; in cec_pin_tx_states()
569 is_ack_bit = pin->tx_bit % 10 == ACK_BIT; in cec_pin_tx_states()
570 if (v && (pin->tx_bit < 4 || is_ack_bit)) { in cec_pin_tx_states()
571 pin->state = CEC_ST_TX_DATA_BIT_1_HIGH_PRE_SAMPLE; in cec_pin_tx_states()
572 } else if (!is_ack_bit && tx_short_bit(pin)) { in cec_pin_tx_states()
574 pin->state = v ? CEC_ST_TX_DATA_BIT_1_HIGH_SHORT : in cec_pin_tx_states()
576 } else if (!is_ack_bit && tx_long_bit(pin)) { in cec_pin_tx_states()
578 pin->state = v ? CEC_ST_TX_DATA_BIT_1_HIGH_LONG : in cec_pin_tx_states()
581 pin->state = v ? CEC_ST_TX_DATA_BIT_1_HIGH : in cec_pin_tx_states()
584 cec_pin_high(pin); in cec_pin_tx_states()
588 pin->state = CEC_ST_TX_DATA_BIT_HIGH_CUSTOM; in cec_pin_tx_states()
589 cec_pin_high(pin); in cec_pin_tx_states()
594 v = cec_pin_read(pin); in cec_pin_tx_states()
595 is_ack_bit = pin->tx_bit % 10 == ACK_BIT; in cec_pin_tx_states()
604 if (!v && !is_ack_bit && !pin->tx_generated_poll) { in cec_pin_tx_states()
605 pin->tx_msg.len = 0; in cec_pin_tx_states()
606 pin->work_tx_ts = ts; in cec_pin_tx_states()
607 pin->work_tx_status = CEC_TX_STATUS_ARB_LOST; in cec_pin_tx_states()
608 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_tx_states()
609 pin->rx_bit = pin->tx_bit; in cec_pin_tx_states()
610 pin->tx_bit = 0; in cec_pin_tx_states()
611 memset(pin->rx_msg.msg, 0, sizeof(pin->rx_msg.msg)); in cec_pin_tx_states()
612 pin->rx_msg.msg[0] = pin->tx_msg.msg[0]; in cec_pin_tx_states()
613 pin->rx_msg.msg[0] &= (0xff << (8 - pin->rx_bit)); in cec_pin_tx_states()
614 pin->rx_msg.len = 0; in cec_pin_tx_states()
615 pin->ts = ktime_sub_us(ts, CEC_TIM_DATA_BIT_SAMPLE); in cec_pin_tx_states()
616 pin->state = CEC_ST_RX_DATA_POST_SAMPLE; in cec_pin_tx_states()
617 pin->rx_bit++; in cec_pin_tx_states()
620 pin->state = CEC_ST_TX_DATA_BIT_1_HIGH_POST_SAMPLE; in cec_pin_tx_states()
621 if (!is_ack_bit && tx_short_bit(pin)) { in cec_pin_tx_states()
623 pin->state = CEC_ST_TX_DATA_BIT_1_HIGH_POST_SAMPLE_SHORT; in cec_pin_tx_states()
624 } else if (!is_ack_bit && tx_long_bit(pin)) { in cec_pin_tx_states()
626 pin->state = CEC_ST_TX_DATA_BIT_1_HIGH_POST_SAMPLE_LONG; in cec_pin_tx_states()
631 ack = cec_msg_is_broadcast(&pin->tx_msg) ? v : !v; in cec_pin_tx_states()
632 if (!ack && (!pin->tx_ignore_nack_until_eom || in cec_pin_tx_states()
633 pin->tx_bit / 10 == pin->tx_msg.len - 1) && in cec_pin_tx_states()
634 !pin->tx_post_eom) { in cec_pin_tx_states()
647 pin->tx_nacked = true; in cec_pin_tx_states()
652 cec_pin_high(pin); in cec_pin_tx_states()
653 pin->state = CEC_ST_TX_PULSE_HIGH_CUSTOM; in cec_pin_tx_states()
657 cec_pin_to_idle(pin); in cec_pin_tx_states()
680 static void cec_pin_rx_states(struct cec_pin *pin, ktime_t ts) in cec_pin_rx_states() argument
689 switch (pin->state) { in cec_pin_rx_states()
692 v = cec_pin_read(pin); in cec_pin_rx_states()
695 pin->state = CEC_ST_RX_START_BIT_HIGH; in cec_pin_rx_states()
696 delta = ktime_us_delta(ts, pin->ts); in cec_pin_rx_states()
699 if (!pin->rx_start_bit_low_too_short_cnt++) { in cec_pin_rx_states()
700 pin->rx_start_bit_low_too_short_ts = ktime_to_ns(pin->ts); in cec_pin_rx_states()
701 pin->rx_start_bit_low_too_short_delta = delta; in cec_pin_rx_states()
703 cec_pin_to_idle(pin); in cec_pin_rx_states()
706 if (rx_arb_lost(pin, &poll)) { in cec_pin_rx_states()
707 cec_msg_init(&pin->tx_msg, poll >> 4, poll & 0xf); in cec_pin_rx_states()
708 pin->tx_generated_poll = true; in cec_pin_rx_states()
709 pin->tx_extra_bytes = 0; in cec_pin_rx_states()
710 pin->state = CEC_ST_TX_START_BIT_HIGH; in cec_pin_rx_states()
711 pin->ts = ts; in cec_pin_rx_states()
716 v = cec_pin_read(pin); in cec_pin_rx_states()
717 delta = ktime_us_delta(ts, pin->ts); in cec_pin_rx_states()
723 pin->rx_start_bit_too_long_cnt++; in cec_pin_rx_states()
724 cec_pin_to_idle(pin); in cec_pin_rx_states()
731 if (!pin->rx_start_bit_too_short_cnt++) { in cec_pin_rx_states()
732 pin->rx_start_bit_too_short_ts = ktime_to_ns(pin->ts); in cec_pin_rx_states()
733 pin->rx_start_bit_too_short_delta = delta; in cec_pin_rx_states()
735 cec_pin_to_idle(pin); in cec_pin_rx_states()
738 if (rx_low_drive(pin)) { in cec_pin_rx_states()
740 cec_pin_low(pin); in cec_pin_rx_states()
741 pin->state = CEC_ST_RX_LOW_DRIVE; in cec_pin_rx_states()
742 pin->rx_low_drive_cnt++; in cec_pin_rx_states()
745 pin->state = CEC_ST_RX_DATA_SAMPLE; in cec_pin_rx_states()
746 pin->ts = ts; in cec_pin_rx_states()
747 pin->rx_eom = false; in cec_pin_rx_states()
751 v = cec_pin_read(pin); in cec_pin_rx_states()
752 pin->state = CEC_ST_RX_DATA_POST_SAMPLE; in cec_pin_rx_states()
753 switch (pin->rx_bit % 10) { in cec_pin_rx_states()
755 if (pin->rx_bit / 10 < CEC_MAX_MSG_SIZE) in cec_pin_rx_states()
756 pin->rx_msg.msg[pin->rx_bit / 10] |= in cec_pin_rx_states()
757 v << (7 - (pin->rx_bit % 10)); in cec_pin_rx_states()
760 pin->rx_eom = v; in cec_pin_rx_states()
761 pin->rx_msg.len = pin->rx_bit / 10 + 1; in cec_pin_rx_states()
766 pin->rx_bit++; in cec_pin_rx_states()
770 pin->state = CEC_ST_RX_DATA_WAIT_FOR_LOW; in cec_pin_rx_states()
774 v = cec_pin_read(pin); in cec_pin_rx_states()
775 delta = ktime_us_delta(ts, pin->ts); in cec_pin_rx_states()
781 pin->rx_data_bit_too_long_cnt++; in cec_pin_rx_states()
782 cec_pin_to_idle(pin); in cec_pin_rx_states()
788 if (rx_low_drive(pin)) { in cec_pin_rx_states()
790 cec_pin_low(pin); in cec_pin_rx_states()
791 pin->state = CEC_ST_RX_LOW_DRIVE; in cec_pin_rx_states()
792 pin->rx_low_drive_cnt++; in cec_pin_rx_states()
800 if (delta < CEC_TIM_DATA_BIT_TOTAL_MIN && !pin->rx_no_low_drive) { in cec_pin_rx_states()
801 if (!pin->rx_data_bit_too_short_cnt++) { in cec_pin_rx_states()
802 pin->rx_data_bit_too_short_ts = ktime_to_ns(pin->ts); in cec_pin_rx_states()
803 pin->rx_data_bit_too_short_delta = delta; in cec_pin_rx_states()
805 cec_pin_low(pin); in cec_pin_rx_states()
806 pin->state = CEC_ST_RX_LOW_DRIVE; in cec_pin_rx_states()
807 pin->rx_low_drive_cnt++; in cec_pin_rx_states()
810 pin->ts = ts; in cec_pin_rx_states()
811 if (pin->rx_bit % 10 != 9) { in cec_pin_rx_states()
812 pin->state = CEC_ST_RX_DATA_SAMPLE; in cec_pin_rx_states()
816 dest = cec_msg_destination(&pin->rx_msg); in cec_pin_rx_states()
819 for_us = bcast || (pin->la_mask & (1 << dest)); in cec_pin_rx_states()
823 if (for_us && rx_nack(pin)) { in cec_pin_rx_states()
830 pin->state = CEC_ST_RX_ACK_HIGH_POST; in cec_pin_rx_states()
833 cec_pin_low(pin); in cec_pin_rx_states()
834 pin->state = CEC_ST_RX_ACK_LOW; in cec_pin_rx_states()
838 cec_pin_high(pin); in cec_pin_rx_states()
839 pin->state = CEC_ST_RX_ACK_LOW_POST; in cec_pin_rx_states()
844 v = cec_pin_read(pin); in cec_pin_rx_states()
845 if (v && pin->rx_eom) { in cec_pin_rx_states()
846 pin->work_rx_msg = pin->rx_msg; in cec_pin_rx_states()
847 pin->work_rx_msg.rx_ts = ktime_to_ns(ts); in cec_pin_rx_states()
848 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_rx_states()
849 pin->ts = ts; in cec_pin_rx_states()
850 pin->state = CEC_ST_RX_ACK_FINISH; in cec_pin_rx_states()
853 pin->rx_bit++; in cec_pin_rx_states()
854 pin->state = CEC_ST_RX_DATA_WAIT_FOR_LOW; in cec_pin_rx_states()
858 cec_pin_to_idle(pin); in cec_pin_rx_states()
872 struct cec_pin *pin = container_of(timer, struct cec_pin, timer); in cec_pin_timer() local
873 struct cec_adapter *adap = pin->adap; in cec_pin_timer()
879 if (ktime_to_ns(pin->timer_ts)) { in cec_pin_timer()
880 delta = ktime_us_delta(ts, pin->timer_ts); in cec_pin_timer()
881 pin->timer_cnt++; in cec_pin_timer()
882 if (delta > 100 && pin->state != CEC_ST_IDLE) { in cec_pin_timer()
884 pin->timer_sum_overrun += delta; in cec_pin_timer()
885 pin->timer_100us_overruns++; in cec_pin_timer()
887 pin->timer_300us_overruns++; in cec_pin_timer()
888 if (delta > pin->timer_max_overrun) in cec_pin_timer()
889 pin->timer_max_overrun = delta; in cec_pin_timer()
893 cec_pin_read(pin); in cec_pin_timer()
895 if (pin->wait_usecs) { in cec_pin_timer()
900 if (pin->wait_usecs > 150) { in cec_pin_timer()
901 pin->wait_usecs -= 100; in cec_pin_timer()
902 pin->timer_ts = ktime_add_us(ts, 100); in cec_pin_timer()
906 if (pin->wait_usecs > 100) { in cec_pin_timer()
907 pin->wait_usecs /= 2; in cec_pin_timer()
908 pin->timer_ts = ktime_add_us(ts, pin->wait_usecs); in cec_pin_timer()
910 us_to_ktime(pin->wait_usecs)); in cec_pin_timer()
913 pin->timer_ts = ktime_add_us(ts, pin->wait_usecs); in cec_pin_timer()
915 us_to_ktime(pin->wait_usecs)); in cec_pin_timer()
916 pin->wait_usecs = 0; in cec_pin_timer()
920 switch (pin->state) { in cec_pin_timer()
945 cec_pin_tx_states(pin, ts); in cec_pin_timer()
958 cec_pin_rx_states(pin, ts); in cec_pin_timer()
963 if (!cec_pin_high(pin)) { in cec_pin_timer()
965 pin->ts = ts; in cec_pin_timer()
966 pin->state = CEC_ST_RX_START_BIT_LOW; in cec_pin_timer()
974 if (pin->tx_msg.len && pin->tx_signal_free_time > in cec_pin_timer()
976 pin->tx_signal_free_time = in cec_pin_timer()
980 if (ktime_to_ns(pin->ts) == 0) in cec_pin_timer()
981 pin->ts = ts; in cec_pin_timer()
982 if (pin->tx_msg.len) { in cec_pin_timer()
987 delta = ktime_us_delta(ts, pin->ts); in cec_pin_timer()
989 pin->tx_signal_free_time) { in cec_pin_timer()
990 pin->tx_nacked = false; in cec_pin_timer()
991 if (tx_custom_start(pin)) in cec_pin_timer()
992 pin->state = CEC_ST_TX_START_BIT_LOW_CUSTOM; in cec_pin_timer()
994 pin->state = CEC_ST_TX_START_BIT_LOW; in cec_pin_timer()
996 cec_pin_low(pin); in cec_pin_timer()
1000 pin->tx_signal_free_time - 1) in cec_pin_timer()
1001 pin->state = CEC_ST_TX_WAIT; in cec_pin_timer()
1004 if (pin->tx_custom_pulse && pin->state == CEC_ST_IDLE) { in cec_pin_timer()
1005 pin->tx_custom_pulse = false; in cec_pin_timer()
1007 cec_pin_low(pin); in cec_pin_timer()
1008 pin->state = CEC_ST_TX_PULSE_LOW_CUSTOM; in cec_pin_timer()
1011 if (pin->state != CEC_ST_IDLE || pin->ops->enable_irq == NULL || in cec_pin_timer()
1012 pin->enable_irq_failed || adap->is_configuring || in cec_pin_timer()
1016 atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_ENABLE); in cec_pin_timer()
1017 pin->state = CEC_ST_RX_IRQ; in cec_pin_timer()
1018 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_timer()
1023 cec_pin_high(pin); in cec_pin_timer()
1024 cec_pin_to_idle(pin); in cec_pin_timer()
1031 switch (pin->state) { in cec_pin_timer()
1035 usecs = pin->tx_custom_low_usecs; in cec_pin_timer()
1040 usecs = pin->tx_custom_high_usecs; in cec_pin_timer()
1043 usecs = states[pin->state].usecs; in cec_pin_timer()
1048 pin->wait_usecs = 0; in cec_pin_timer()
1049 pin->timer_ts = ktime_add_us(ts, usecs); in cec_pin_timer()
1053 pin->wait_usecs = usecs - 100; in cec_pin_timer()
1054 pin->timer_ts = ktime_add_us(ts, 100); in cec_pin_timer()
1062 struct cec_pin *pin = adap->pin; in cec_pin_thread_func() local
1064 pin->enabled_irq = false; in cec_pin_thread_func()
1065 pin->enable_irq_failed = false; in cec_pin_thread_func()
1067 wait_event_interruptible(pin->kthread_waitq, in cec_pin_thread_func()
1069 pin->work_rx_msg.len || in cec_pin_thread_func()
1070 pin->work_tx_status || in cec_pin_thread_func()
1071 atomic_read(&pin->work_irq_change) || in cec_pin_thread_func()
1072 atomic_read(&pin->work_pin_num_events)); in cec_pin_thread_func()
1077 if (pin->work_rx_msg.len) { in cec_pin_thread_func()
1078 struct cec_msg *msg = &pin->work_rx_msg; in cec_pin_thread_func()
1081 rx_add_byte(pin)) { in cec_pin_thread_func()
1085 if (msg->len > 2 && rx_remove_byte(pin)) { in cec_pin_thread_func()
1092 ns_to_ktime(pin->work_rx_msg.rx_ts)); in cec_pin_thread_func()
1096 if (pin->work_tx_status) { in cec_pin_thread_func()
1097 unsigned int tx_status = pin->work_tx_status; in cec_pin_thread_func()
1099 pin->work_tx_status = 0; in cec_pin_thread_func()
1101 pin->work_tx_ts); in cec_pin_thread_func()
1104 while (atomic_read(&pin->work_pin_num_events)) { in cec_pin_thread_func()
1105 unsigned int idx = pin->work_pin_events_rd; in cec_pin_thread_func()
1106 u8 v = pin->work_pin_events[idx]; in cec_pin_thread_func()
1111 pin->work_pin_ts[idx]); in cec_pin_thread_func()
1112 pin->work_pin_events_rd = (idx + 1) % CEC_NUM_PIN_EVENTS; in cec_pin_thread_func()
1113 atomic_dec(&pin->work_pin_num_events); in cec_pin_thread_func()
1116 switch (atomic_xchg(&pin->work_irq_change, in cec_pin_thread_func()
1119 if (pin->enabled_irq) { in cec_pin_thread_func()
1120 pin->ops->disable_irq(adap); in cec_pin_thread_func()
1121 pin->enabled_irq = false; in cec_pin_thread_func()
1122 pin->enable_irq_failed = false; in cec_pin_thread_func()
1124 cec_pin_high(pin); in cec_pin_thread_func()
1125 if (pin->state == CEC_ST_OFF) in cec_pin_thread_func()
1127 cec_pin_to_idle(pin); in cec_pin_thread_func()
1128 hrtimer_start(&pin->timer, ns_to_ktime(0), in cec_pin_thread_func()
1132 if (pin->enabled_irq || !pin->ops->enable_irq || in cec_pin_thread_func()
1133 pin->adap->devnode.unregistered) in cec_pin_thread_func()
1135 pin->enable_irq_failed = !pin->ops->enable_irq(adap); in cec_pin_thread_func()
1136 if (pin->enable_irq_failed) { in cec_pin_thread_func()
1137 cec_pin_to_idle(pin); in cec_pin_thread_func()
1138 hrtimer_start(&pin->timer, ns_to_ktime(0), in cec_pin_thread_func()
1141 pin->enabled_irq = true; in cec_pin_thread_func()
1149 if (pin->enabled_irq) { in cec_pin_thread_func()
1150 pin->ops->disable_irq(pin->adap); in cec_pin_thread_func()
1151 pin->enabled_irq = false; in cec_pin_thread_func()
1152 pin->enable_irq_failed = false; in cec_pin_thread_func()
1153 cec_pin_high(pin); in cec_pin_thread_func()
1160 struct cec_pin *pin = adap->pin; in cec_pin_adap_enable() local
1163 cec_pin_read(pin); in cec_pin_adap_enable()
1164 cec_pin_to_idle(pin); in cec_pin_adap_enable()
1165 pin->tx_msg.len = 0; in cec_pin_adap_enable()
1166 pin->timer_ts = ns_to_ktime(0); in cec_pin_adap_enable()
1167 atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_UNCHANGED); in cec_pin_adap_enable()
1168 if (!pin->kthread) { in cec_pin_adap_enable()
1169 pin->kthread = kthread_run(cec_pin_thread_func, adap, in cec_pin_adap_enable()
1171 if (IS_ERR(pin->kthread)) { in cec_pin_adap_enable()
1172 int err = PTR_ERR(pin->kthread); in cec_pin_adap_enable()
1175 pin->kthread = NULL; in cec_pin_adap_enable()
1179 hrtimer_start(&pin->timer, ns_to_ktime(0), in cec_pin_adap_enable()
1181 } else if (pin->kthread) { in cec_pin_adap_enable()
1182 hrtimer_cancel(&pin->timer); in cec_pin_adap_enable()
1183 cec_pin_high(pin); in cec_pin_adap_enable()
1184 cec_pin_to_idle(pin); in cec_pin_adap_enable()
1185 pin->state = CEC_ST_OFF; in cec_pin_adap_enable()
1186 pin->work_tx_status = 0; in cec_pin_adap_enable()
1187 atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_DISABLE); in cec_pin_adap_enable()
1188 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_adap_enable()
1195 struct cec_pin *pin = adap->pin; in cec_pin_adap_log_addr() local
1198 pin->la_mask = 0; in cec_pin_adap_log_addr()
1200 pin->la_mask |= (1 << log_addr); in cec_pin_adap_log_addr()
1204 void cec_pin_start_timer(struct cec_pin *pin) in cec_pin_start_timer() argument
1206 if (pin->state != CEC_ST_RX_IRQ) in cec_pin_start_timer()
1209 atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_DISABLE); in cec_pin_start_timer()
1210 wake_up_interruptible(&pin->kthread_waitq); in cec_pin_start_timer()
1216 struct cec_pin *pin = adap->pin; in cec_pin_adap_transmit() local
1223 if (pin->state != CEC_ST_IDLE && in cec_pin_adap_transmit()
1227 pin->tx_signal_free_time = signal_free_time; in cec_pin_adap_transmit()
1228 pin->tx_extra_bytes = 0; in cec_pin_adap_transmit()
1229 pin->tx_msg = *msg; in cec_pin_adap_transmit()
1232 pin->tx_extra_bytes = tx_add_bytes(pin); in cec_pin_adap_transmit()
1234 if (msg->len > 2 && tx_remove_byte(pin)) { in cec_pin_adap_transmit()
1236 pin->tx_msg.len--; in cec_pin_adap_transmit()
1238 pin->work_tx_status = 0; in cec_pin_adap_transmit()
1239 pin->tx_bit = 0; in cec_pin_adap_transmit()
1240 cec_pin_start_timer(pin); in cec_pin_adap_transmit()
1247 struct cec_pin *pin = adap->pin; in cec_pin_adap_status() local
1249 seq_printf(file, "state: %s\n", states[pin->state].name); in cec_pin_adap_status()
1250 seq_printf(file, "tx_bit: %d\n", pin->tx_bit); in cec_pin_adap_status()
1251 seq_printf(file, "rx_bit: %d\n", pin->rx_bit); in cec_pin_adap_status()
1252 seq_printf(file, "cec pin: %d\n", call_pin_op(pin, read)); in cec_pin_adap_status()
1254 pin->work_pin_events_dropped_cnt); in cec_pin_adap_status()
1255 if (pin->ops->enable_irq) in cec_pin_adap_status()
1256 seq_printf(file, "irq %s\n", pin->enabled_irq ? "enabled" : in cec_pin_adap_status()
1257 (pin->enable_irq_failed ? "failed" : "disabled")); in cec_pin_adap_status()
1258 if (pin->timer_100us_overruns) { in cec_pin_adap_status()
1260 pin->timer_100us_overruns, pin->timer_cnt); in cec_pin_adap_status()
1262 pin->timer_300us_overruns, pin->timer_cnt); in cec_pin_adap_status()
1264 pin->timer_max_overrun); in cec_pin_adap_status()
1266 pin->timer_sum_overrun / pin->timer_100us_overruns); in cec_pin_adap_status()
1268 if (pin->rx_start_bit_low_too_short_cnt) in cec_pin_adap_status()
1271 pin->rx_start_bit_low_too_short_cnt, in cec_pin_adap_status()
1272 pin->rx_start_bit_low_too_short_delta, in cec_pin_adap_status()
1273 pin->rx_start_bit_low_too_short_ts); in cec_pin_adap_status()
1274 if (pin->rx_start_bit_too_short_cnt) in cec_pin_adap_status()
1277 pin->rx_start_bit_too_short_cnt, in cec_pin_adap_status()
1278 pin->rx_start_bit_too_short_delta, in cec_pin_adap_status()
1279 pin->rx_start_bit_too_short_ts); in cec_pin_adap_status()
1280 if (pin->rx_start_bit_too_long_cnt) in cec_pin_adap_status()
1282 pin->rx_start_bit_too_long_cnt); in cec_pin_adap_status()
1283 if (pin->rx_data_bit_too_short_cnt) in cec_pin_adap_status()
1286 pin->rx_data_bit_too_short_cnt, in cec_pin_adap_status()
1287 pin->rx_data_bit_too_short_delta, in cec_pin_adap_status()
1288 pin->rx_data_bit_too_short_ts); in cec_pin_adap_status()
1289 if (pin->rx_data_bit_too_long_cnt) in cec_pin_adap_status()
1291 pin->rx_data_bit_too_long_cnt); in cec_pin_adap_status()
1292 seq_printf(file, "rx initiated low drive: %u\n", pin->rx_low_drive_cnt); in cec_pin_adap_status()
1293 seq_printf(file, "tx detected low drive: %u\n", pin->tx_low_drive_cnt); in cec_pin_adap_status()
1294 pin->work_pin_events_dropped_cnt = 0; in cec_pin_adap_status()
1295 pin->timer_cnt = 0; in cec_pin_adap_status()
1296 pin->timer_100us_overruns = 0; in cec_pin_adap_status()
1297 pin->timer_300us_overruns = 0; in cec_pin_adap_status()
1298 pin->timer_max_overrun = 0; in cec_pin_adap_status()
1299 pin->timer_sum_overrun = 0; in cec_pin_adap_status()
1300 pin->rx_start_bit_low_too_short_cnt = 0; in cec_pin_adap_status()
1301 pin->rx_start_bit_too_short_cnt = 0; in cec_pin_adap_status()
1302 pin->rx_start_bit_too_long_cnt = 0; in cec_pin_adap_status()
1303 pin->rx_data_bit_too_short_cnt = 0; in cec_pin_adap_status()
1304 pin->rx_data_bit_too_long_cnt = 0; in cec_pin_adap_status()
1305 pin->rx_low_drive_cnt = 0; in cec_pin_adap_status()
1306 pin->tx_low_drive_cnt = 0; in cec_pin_adap_status()
1307 call_void_pin_op(pin, status, file); in cec_pin_adap_status()
1313 struct cec_pin *pin = adap->pin; in cec_pin_adap_monitor_all_enable() local
1315 pin->monitor_all = enable; in cec_pin_adap_monitor_all_enable()
1321 struct cec_pin *pin = adap->pin; in cec_pin_adap_free() local
1323 if (pin->kthread) in cec_pin_adap_free()
1324 kthread_stop(pin->kthread); in cec_pin_adap_free()
1325 pin->kthread = NULL; in cec_pin_adap_free()
1326 if (pin->ops->free) in cec_pin_adap_free()
1327 pin->ops->free(adap); in cec_pin_adap_free()
1328 adap->pin = NULL; in cec_pin_adap_free()
1329 kfree(pin); in cec_pin_adap_free()
1334 struct cec_pin *pin = adap->pin; in cec_pin_received() local
1336 if (pin->ops->received && !adap->devnode.unregistered) in cec_pin_received()
1337 return pin->ops->received(adap, msg); in cec_pin_received()
1343 struct cec_pin *pin = adap->pin; in cec_pin_changed() local
1345 cec_pin_update(pin, value, false); in cec_pin_changed()
1348 atomic_set(&pin->work_irq_change, CEC_PIN_IRQ_DISABLE); in cec_pin_changed()
1370 struct cec_pin *pin = kzalloc(sizeof(*pin), GFP_KERNEL); in cec_pin_allocate_adapter() local
1372 if (pin == NULL) in cec_pin_allocate_adapter()
1374 pin->ops = pin_ops; in cec_pin_allocate_adapter()
1375 atomic_set(&pin->work_pin_num_events, 0); in cec_pin_allocate_adapter()
1376 hrtimer_setup(&pin->timer, cec_pin_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in cec_pin_allocate_adapter()
1377 init_waitqueue_head(&pin->kthread_waitq); in cec_pin_allocate_adapter()
1378 pin->tx_custom_low_usecs = CEC_TIM_CUSTOM_DEFAULT; in cec_pin_allocate_adapter()
1379 pin->tx_custom_high_usecs = CEC_TIM_CUSTOM_DEFAULT; in cec_pin_allocate_adapter()
1380 pin->tx_glitch_low_usecs = CEC_TIM_GLITCH_DEFAULT; in cec_pin_allocate_adapter()
1381 pin->tx_glitch_high_usecs = CEC_TIM_GLITCH_DEFAULT; in cec_pin_allocate_adapter()
1388 kfree(pin); in cec_pin_allocate_adapter()
1392 adap->pin = pin; in cec_pin_allocate_adapter()
1393 pin->adap = adap; in cec_pin_allocate_adapter()
1394 cec_pin_update(pin, cec_pin_high(pin), true); in cec_pin_allocate_adapter()