2 * cec-pin-priv.h - internal cec-pin header
4 * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 * This program is free software; you may redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
14 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
15 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 #ifndef LINUX_CEC_PIN_PRIV_H
21 #define LINUX_CEC_PIN_PRIV_H
23 #include <linux/types.h>
24 #include <linux/atomic.h>
25 #include <media/cec-pin.h>
30 /* CEC is idle, waiting for Rx or Tx */
35 /* Pending Tx, waiting for Signal Free Time to expire */
37 /* Low-drive was detected, wait for bus to go high */
38 CEC_ST_TX_WAIT_FOR_HIGH
,
39 /* Drive CEC low for the start bit */
40 CEC_ST_TX_START_BIT_LOW
,
41 /* Drive CEC high for the start bit */
42 CEC_ST_TX_START_BIT_HIGH
,
43 /* Drive CEC low for the 0 bit */
44 CEC_ST_TX_DATA_BIT_0_LOW
,
45 /* Drive CEC high for the 0 bit */
46 CEC_ST_TX_DATA_BIT_0_HIGH
,
47 /* Drive CEC low for the 1 bit */
48 CEC_ST_TX_DATA_BIT_1_LOW
,
49 /* Drive CEC high for the 1 bit */
50 CEC_ST_TX_DATA_BIT_1_HIGH
,
52 * Wait for start of sample time to check for Ack bit or first
53 * four initiator bits to check for Arbitration Lost.
55 CEC_ST_TX_DATA_BIT_1_HIGH_PRE_SAMPLE
,
56 /* Wait for end of bit period after sampling */
57 CEC_ST_TX_DATA_BIT_1_HIGH_POST_SAMPLE
,
61 /* Start bit low detected */
62 CEC_ST_RX_START_BIT_LOW
,
63 /* Start bit high detected */
64 CEC_ST_RX_START_BIT_HIGH
,
65 /* Wait for bit sample time */
66 CEC_ST_RX_DATA_SAMPLE
,
67 /* Wait for earliest end of bit period after sampling */
68 CEC_ST_RX_DATA_POST_SAMPLE
,
69 /* Wait for CEC to go high (i.e. end of bit period */
71 /* Drive CEC low to send 0 Ack bit */
73 /* End of 0 Ack time, wait for earliest end of bit period */
74 CEC_ST_RX_ACK_LOW_POST
,
75 /* Wait for CEC to go high (i.e. end of bit period */
76 CEC_ST_RX_ACK_HIGH_POST
,
77 /* Wait for earliest end of bit period and end of message */
82 /* Monitor pin using interrupts */
85 /* Total number of pin states */
89 #define CEC_NUM_PIN_EVENTS 128
91 #define CEC_PIN_IRQ_UNCHANGED 0
92 #define CEC_PIN_IRQ_DISABLE 1
93 #define CEC_PIN_IRQ_ENABLE 2
96 struct cec_adapter
*adap
;
97 const struct cec_pin_ops
*ops
;
98 struct task_struct
*kthread
;
99 wait_queue_head_t kthread_waitq
;
100 struct hrtimer timer
;
102 unsigned int wait_usecs
;
107 bool enable_irq_failed
;
108 enum cec_pin_state state
;
109 struct cec_msg tx_msg
;
112 u32 tx_signal_free_time
;
113 struct cec_msg rx_msg
;
116 struct cec_msg work_rx_msg
;
119 atomic_t work_irq_change
;
120 atomic_t work_pin_events
;
121 unsigned int work_pin_events_wr
;
122 unsigned int work_pin_events_rd
;
123 ktime_t work_pin_ts
[CEC_NUM_PIN_EVENTS
];
124 bool work_pin_is_high
[CEC_NUM_PIN_EVENTS
];
127 u32 timer_100ms_overruns
;
128 u32 timer_300ms_overruns
;
129 u32 timer_max_overrun
;
130 u32 timer_sum_overrun
;