cec-pin-priv.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * cec-pin-priv.h - internal cec-pin header
  4. *
  5. * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  6. */
  7. #ifndef LINUX_CEC_PIN_PRIV_H
  8. #define LINUX_CEC_PIN_PRIV_H
  9. #include <linux/types.h>
  10. #include <linux/atomic.h>
  11. #include <media/cec-pin.h>
  12. enum cec_pin_state {
  13. /* CEC is off */
  14. CEC_ST_OFF,
  15. /* CEC is idle, waiting for Rx or Tx */
  16. CEC_ST_IDLE,
  17. /* Tx states */
  18. /* Pending Tx, waiting for Signal Free Time to expire */
  19. CEC_ST_TX_WAIT,
  20. /* Low-drive was detected, wait for bus to go high */
  21. CEC_ST_TX_WAIT_FOR_HIGH,
  22. /* Drive CEC low for the start bit */
  23. CEC_ST_TX_START_BIT_LOW,
  24. /* Drive CEC high for the start bit */
  25. CEC_ST_TX_START_BIT_HIGH,
  26. /* Generate a start bit period that is too short */
  27. CEC_ST_TX_START_BIT_HIGH_SHORT,
  28. /* Generate a start bit period that is too long */
  29. CEC_ST_TX_START_BIT_HIGH_LONG,
  30. /* Drive CEC low for the start bit using the custom timing */
  31. CEC_ST_TX_START_BIT_LOW_CUSTOM,
  32. /* Drive CEC high for the start bit using the custom timing */
  33. CEC_ST_TX_START_BIT_HIGH_CUSTOM,
  34. /* Drive CEC low for the 0 bit */
  35. CEC_ST_TX_DATA_BIT_0_LOW,
  36. /* Drive CEC high for the 0 bit */
  37. CEC_ST_TX_DATA_BIT_0_HIGH,
  38. /* Generate a bit period that is too short */
  39. CEC_ST_TX_DATA_BIT_0_HIGH_SHORT,
  40. /* Generate a bit period that is too long */
  41. CEC_ST_TX_DATA_BIT_0_HIGH_LONG,
  42. /* Drive CEC low for the 1 bit */
  43. CEC_ST_TX_DATA_BIT_1_LOW,
  44. /* Drive CEC high for the 1 bit */
  45. CEC_ST_TX_DATA_BIT_1_HIGH,
  46. /* Generate a bit period that is too short */
  47. CEC_ST_TX_DATA_BIT_1_HIGH_SHORT,
  48. /* Generate a bit period that is too long */
  49. CEC_ST_TX_DATA_BIT_1_HIGH_LONG,
  50. /*
  51. * Wait for start of sample time to check for Ack bit or first
  52. * four initiator bits to check for Arbitration Lost.
  53. */
  54. CEC_ST_TX_DATA_BIT_1_HIGH_PRE_SAMPLE,
  55. /* Wait for end of bit period after sampling */
  56. CEC_ST_TX_DATA_BIT_1_HIGH_POST_SAMPLE,
  57. /* Generate a bit period that is too short */
  58. CEC_ST_TX_DATA_BIT_1_HIGH_POST_SAMPLE_SHORT,
  59. /* Generate a bit period that is too long */
  60. CEC_ST_TX_DATA_BIT_1_HIGH_POST_SAMPLE_LONG,
  61. /* Drive CEC low for a data bit using the custom timing */
  62. CEC_ST_TX_DATA_BIT_LOW_CUSTOM,
  63. /* Drive CEC high for a data bit using the custom timing */
  64. CEC_ST_TX_DATA_BIT_HIGH_CUSTOM,
  65. /* Drive CEC low for a standalone pulse using the custom timing */
  66. CEC_ST_TX_PULSE_LOW_CUSTOM,
  67. /* Drive CEC high for a standalone pulse using the custom timing */
  68. CEC_ST_TX_PULSE_HIGH_CUSTOM,
  69. /* Start low drive */
  70. CEC_ST_TX_LOW_DRIVE,
  71. /* Rx states */
  72. /* Start bit low detected */
  73. CEC_ST_RX_START_BIT_LOW,
  74. /* Start bit high detected */
  75. CEC_ST_RX_START_BIT_HIGH,
  76. /* Wait for bit sample time */
  77. CEC_ST_RX_DATA_SAMPLE,
  78. /* Wait for earliest end of bit period after sampling */
  79. CEC_ST_RX_DATA_POST_SAMPLE,
  80. /* Wait for CEC to go low (i.e. end of bit period) */
  81. CEC_ST_RX_DATA_WAIT_FOR_LOW,
  82. /* Drive CEC low to send 0 Ack bit */
  83. CEC_ST_RX_ACK_LOW,
  84. /* End of 0 Ack time, wait for earliest end of bit period */
  85. CEC_ST_RX_ACK_LOW_POST,
  86. /* Wait for CEC to go high (i.e. end of bit period */
  87. CEC_ST_RX_ACK_HIGH_POST,
  88. /* Wait for earliest end of bit period and end of message */
  89. CEC_ST_RX_ACK_FINISH,
  90. /* Start low drive */
  91. CEC_ST_RX_LOW_DRIVE,
  92. /* Monitor pin using interrupts */
  93. CEC_ST_RX_IRQ,
  94. /* Total number of pin states */
  95. CEC_PIN_STATES
  96. };
  97. /* Error Injection */
  98. /* Error injection modes */
  99. #define CEC_ERROR_INJ_MODE_OFF 0
  100. #define CEC_ERROR_INJ_MODE_ONCE 1
  101. #define CEC_ERROR_INJ_MODE_ALWAYS 2
  102. #define CEC_ERROR_INJ_MODE_TOGGLE 3
  103. #define CEC_ERROR_INJ_MODE_MASK 3ULL
  104. /* Receive error injection options */
  105. #define CEC_ERROR_INJ_RX_NACK_OFFSET 0
  106. #define CEC_ERROR_INJ_RX_LOW_DRIVE_OFFSET 2
  107. #define CEC_ERROR_INJ_RX_ADD_BYTE_OFFSET 4
  108. #define CEC_ERROR_INJ_RX_REMOVE_BYTE_OFFSET 6
  109. #define CEC_ERROR_INJ_RX_ARB_LOST_OFFSET 8
  110. #define CEC_ERROR_INJ_RX_MASK 0xffffULL
  111. /* Transmit error injection options */
  112. #define CEC_ERROR_INJ_TX_NO_EOM_OFFSET 16
  113. #define CEC_ERROR_INJ_TX_EARLY_EOM_OFFSET 18
  114. #define CEC_ERROR_INJ_TX_SHORT_BIT_OFFSET 20
  115. #define CEC_ERROR_INJ_TX_LONG_BIT_OFFSET 22
  116. #define CEC_ERROR_INJ_TX_CUSTOM_BIT_OFFSET 24
  117. #define CEC_ERROR_INJ_TX_SHORT_START_OFFSET 26
  118. #define CEC_ERROR_INJ_TX_LONG_START_OFFSET 28
  119. #define CEC_ERROR_INJ_TX_CUSTOM_START_OFFSET 30
  120. #define CEC_ERROR_INJ_TX_LAST_BIT_OFFSET 32
  121. #define CEC_ERROR_INJ_TX_ADD_BYTES_OFFSET 34
  122. #define CEC_ERROR_INJ_TX_REMOVE_BYTE_OFFSET 36
  123. #define CEC_ERROR_INJ_TX_LOW_DRIVE_OFFSET 38
  124. #define CEC_ERROR_INJ_TX_MASK 0xffffffffffff0000ULL
  125. #define CEC_ERROR_INJ_RX_LOW_DRIVE_ARG_IDX 0
  126. #define CEC_ERROR_INJ_RX_ARB_LOST_ARG_IDX 1
  127. #define CEC_ERROR_INJ_TX_ADD_BYTES_ARG_IDX 2
  128. #define CEC_ERROR_INJ_TX_SHORT_BIT_ARG_IDX 3
  129. #define CEC_ERROR_INJ_TX_LONG_BIT_ARG_IDX 4
  130. #define CEC_ERROR_INJ_TX_CUSTOM_BIT_ARG_IDX 5
  131. #define CEC_ERROR_INJ_TX_LAST_BIT_ARG_IDX 6
  132. #define CEC_ERROR_INJ_TX_LOW_DRIVE_ARG_IDX 7
  133. #define CEC_ERROR_INJ_NUM_ARGS 8
  134. /* Special CEC op values */
  135. #define CEC_ERROR_INJ_OP_ANY 0x00000100
  136. /* The default for the low/high time of the custom pulse */
  137. #define CEC_TIM_CUSTOM_DEFAULT 1000
  138. #define CEC_NUM_PIN_EVENTS 128
  139. #define CEC_PIN_EVENT_FL_IS_HIGH (1 << 0)
  140. #define CEC_PIN_EVENT_FL_DROPPED (1 << 1)
  141. #define CEC_PIN_IRQ_UNCHANGED 0
  142. #define CEC_PIN_IRQ_DISABLE 1
  143. #define CEC_PIN_IRQ_ENABLE 2
  144. struct cec_pin {
  145. struct cec_adapter *adap;
  146. const struct cec_pin_ops *ops;
  147. struct task_struct *kthread;
  148. wait_queue_head_t kthread_waitq;
  149. struct hrtimer timer;
  150. ktime_t ts;
  151. unsigned int wait_usecs;
  152. u16 la_mask;
  153. bool enabled;
  154. bool monitor_all;
  155. bool rx_eom;
  156. bool enable_irq_failed;
  157. enum cec_pin_state state;
  158. struct cec_msg tx_msg;
  159. u32 tx_bit;
  160. bool tx_nacked;
  161. u32 tx_signal_free_time;
  162. bool tx_toggle;
  163. struct cec_msg rx_msg;
  164. u32 rx_bit;
  165. bool rx_toggle;
  166. u32 rx_start_bit_low_too_short_cnt;
  167. u64 rx_start_bit_low_too_short_ts;
  168. u32 rx_start_bit_low_too_short_delta;
  169. u32 rx_start_bit_too_short_cnt;
  170. u64 rx_start_bit_too_short_ts;
  171. u32 rx_start_bit_too_short_delta;
  172. u32 rx_start_bit_too_long_cnt;
  173. u32 rx_data_bit_too_short_cnt;
  174. u64 rx_data_bit_too_short_ts;
  175. u32 rx_data_bit_too_short_delta;
  176. u32 rx_data_bit_too_long_cnt;
  177. u32 rx_low_drive_cnt;
  178. struct cec_msg work_rx_msg;
  179. u8 work_tx_status;
  180. ktime_t work_tx_ts;
  181. atomic_t work_irq_change;
  182. atomic_t work_pin_num_events;
  183. unsigned int work_pin_events_wr;
  184. unsigned int work_pin_events_rd;
  185. ktime_t work_pin_ts[CEC_NUM_PIN_EVENTS];
  186. u8 work_pin_events[CEC_NUM_PIN_EVENTS];
  187. bool work_pin_events_dropped;
  188. u32 work_pin_events_dropped_cnt;
  189. ktime_t timer_ts;
  190. u32 timer_cnt;
  191. u32 timer_100ms_overruns;
  192. u32 timer_300ms_overruns;
  193. u32 timer_max_overrun;
  194. u32 timer_sum_overrun;
  195. u32 tx_custom_low_usecs;
  196. u32 tx_custom_high_usecs;
  197. bool tx_ignore_nack_until_eom;
  198. bool tx_custom_pulse;
  199. bool tx_generated_poll;
  200. bool tx_post_eom;
  201. u8 tx_extra_bytes;
  202. u32 tx_low_drive_cnt;
  203. #ifdef CONFIG_CEC_PIN_ERROR_INJ
  204. u64 error_inj[CEC_ERROR_INJ_OP_ANY + 1];
  205. u8 error_inj_args[CEC_ERROR_INJ_OP_ANY + 1][CEC_ERROR_INJ_NUM_ARGS];
  206. #endif
  207. };
  208. void cec_pin_start_timer(struct cec_pin *pin);
  209. #ifdef CONFIG_CEC_PIN_ERROR_INJ
  210. bool cec_pin_error_inj_parse_line(struct cec_adapter *adap, char *line);
  211. int cec_pin_error_inj_show(struct cec_adapter *adap, struct seq_file *sf);
  212. u16 cec_pin_rx_error_inj(struct cec_pin *pin);
  213. u16 cec_pin_tx_error_inj(struct cec_pin *pin);
  214. #endif
  215. #endif