xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/cec/cec-ioc-dqevent.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun.. c:namespace:: CEC
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun.. _CEC_DQEVENT:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun*****************
7*4882a593Smuzhiyunioctl CEC_DQEVENT
8*4882a593Smuzhiyun*****************
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunName
11*4882a593Smuzhiyun====
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunCEC_DQEVENT - Dequeue a CEC event
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSynopsis
16*4882a593Smuzhiyun========
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun.. c:macro:: CEC_DQEVENT
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun``int ioctl(int fd, CEC_DQEVENT, struct cec_event *argp)``
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunArguments
23*4882a593Smuzhiyun=========
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun``fd``
26*4882a593Smuzhiyun    File descriptor returned by :c:func:`open()`.
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun``argp``
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunDescription
31*4882a593Smuzhiyun===========
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunCEC devices can send asynchronous events. These can be retrieved by
34*4882a593Smuzhiyuncalling :c:func:`CEC_DQEVENT`. If the file descriptor is in
35*4882a593Smuzhiyunnon-blocking mode and no event is pending, then it will return -1 and
36*4882a593Smuzhiyunset errno to the ``EAGAIN`` error code.
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunThe internal event queues are per-filehandle and per-event type. If
39*4882a593Smuzhiyunthere is no more room in a queue then the last event is overwritten with
40*4882a593Smuzhiyunthe new one. This means that intermediate results can be thrown away but
41*4882a593Smuzhiyunthat the latest event is always available. This also means that is it
42*4882a593Smuzhiyunpossible to read two successive events that have the same value (e.g.
43*4882a593Smuzhiyuntwo :ref:`CEC_EVENT_STATE_CHANGE <CEC-EVENT-STATE-CHANGE>` events with
44*4882a593Smuzhiyunthe same state). In that case the intermediate state changes were lost but
45*4882a593Smuzhiyunit is guaranteed that the state did change in between the two events.
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun.. tabularcolumns:: |p{1.2cm}|p{2.9cm}|p{13.4cm}|
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun.. c:type:: cec_event_state_change
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun.. flat-table:: struct cec_event_state_change
52*4882a593Smuzhiyun    :header-rows:  0
53*4882a593Smuzhiyun    :stub-columns: 0
54*4882a593Smuzhiyun    :widths:       1 1 8
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun    * - __u16
57*4882a593Smuzhiyun      - ``phys_addr``
58*4882a593Smuzhiyun      - The current physical address. This is ``CEC_PHYS_ADDR_INVALID`` if no
59*4882a593Smuzhiyun        valid physical address is set.
60*4882a593Smuzhiyun    * - __u16
61*4882a593Smuzhiyun      - ``log_addr_mask``
62*4882a593Smuzhiyun      - The current set of claimed logical addresses. This is 0 if no logical
63*4882a593Smuzhiyun        addresses are claimed or if ``phys_addr`` is ``CEC_PHYS_ADDR_INVALID``.
64*4882a593Smuzhiyun	If bit 15 is set (``1 << CEC_LOG_ADDR_UNREGISTERED``) then this device
65*4882a593Smuzhiyun	has the unregistered logical address. In that case all other bits are 0.
66*4882a593Smuzhiyun    * - __u16
67*4882a593Smuzhiyun      - ``have_conn_info``
68*4882a593Smuzhiyun      - If non-zero, then HDMI connector information is available.
69*4882a593Smuzhiyun        This field is only valid if ``CEC_CAP_CONNECTOR_INFO`` is set. If that
70*4882a593Smuzhiyun        capability is set and ``have_conn_info`` is zero, then that indicates
71*4882a593Smuzhiyun        that the HDMI connector device is not instantiated, either because
72*4882a593Smuzhiyun        the HDMI driver is still configuring the device or because the HDMI
73*4882a593Smuzhiyun        device was unbound.
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun.. c:type:: cec_event_lost_msgs
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun.. tabularcolumns:: |p{1.0cm}|p{2.0cm}|p{14.5cm}|
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun.. flat-table:: struct cec_event_lost_msgs
80*4882a593Smuzhiyun    :header-rows:  0
81*4882a593Smuzhiyun    :stub-columns: 0
82*4882a593Smuzhiyun    :widths:       1 1 16
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun    * - __u32
85*4882a593Smuzhiyun      - ``lost_msgs``
86*4882a593Smuzhiyun      - Set to the number of lost messages since the filehandle was opened
87*4882a593Smuzhiyun	or since the last time this event was dequeued for this
88*4882a593Smuzhiyun	filehandle. The messages lost are the oldest messages. So when a
89*4882a593Smuzhiyun	new message arrives and there is no more room, then the oldest
90*4882a593Smuzhiyun	message is discarded to make room for the new one. The internal
91*4882a593Smuzhiyun	size of the message queue guarantees that all messages received in
92*4882a593Smuzhiyun	the last two seconds will be stored. Since messages should be
93*4882a593Smuzhiyun	replied to within a second according to the CEC specification,
94*4882a593Smuzhiyun	this is more than enough.
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun.. tabularcolumns:: |p{1.0cm}|p{4.4cm}|p{2.5cm}|p{9.6cm}|
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun.. c:type:: cec_event
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun.. flat-table:: struct cec_event
101*4882a593Smuzhiyun    :header-rows:  0
102*4882a593Smuzhiyun    :stub-columns: 0
103*4882a593Smuzhiyun    :widths:       1 1 8
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun    * - __u64
106*4882a593Smuzhiyun      - ``ts``
107*4882a593Smuzhiyun      - Timestamp of the event in ns.
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun	The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock.
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun	To access the same clock from userspace use :c:func:`clock_gettime`.
112*4882a593Smuzhiyun    * - __u32
113*4882a593Smuzhiyun      - ``event``
114*4882a593Smuzhiyun      - The CEC event type, see :ref:`cec-events`.
115*4882a593Smuzhiyun    * - __u32
116*4882a593Smuzhiyun      - ``flags``
117*4882a593Smuzhiyun      - Event flags, see :ref:`cec-event-flags`.
118*4882a593Smuzhiyun    * - union {
119*4882a593Smuzhiyun      - (anonymous)
120*4882a593Smuzhiyun    * - struct cec_event_state_change
121*4882a593Smuzhiyun      - ``state_change``
122*4882a593Smuzhiyun      - The new adapter state as sent by the :ref:`CEC_EVENT_STATE_CHANGE <CEC-EVENT-STATE-CHANGE>`
123*4882a593Smuzhiyun	event.
124*4882a593Smuzhiyun    * - struct cec_event_lost_msgs
125*4882a593Smuzhiyun      - ``lost_msgs``
126*4882a593Smuzhiyun      - The number of lost messages as sent by the :ref:`CEC_EVENT_LOST_MSGS <CEC-EVENT-LOST-MSGS>`
127*4882a593Smuzhiyun	event.
128*4882a593Smuzhiyun    * - }
129*4882a593Smuzhiyun      -
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun.. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun.. _cec-events:
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun.. flat-table:: CEC Events Types
136*4882a593Smuzhiyun    :header-rows:  0
137*4882a593Smuzhiyun    :stub-columns: 0
138*4882a593Smuzhiyun    :widths:       3 1 16
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun    * .. _`CEC-EVENT-STATE-CHANGE`:
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun      - ``CEC_EVENT_STATE_CHANGE``
143*4882a593Smuzhiyun      - 1
144*4882a593Smuzhiyun      - Generated when the CEC Adapter's state changes. When open() is
145*4882a593Smuzhiyun	called an initial event will be generated for that filehandle with
146*4882a593Smuzhiyun	the CEC Adapter's state at that time.
147*4882a593Smuzhiyun    * .. _`CEC-EVENT-LOST-MSGS`:
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun      - ``CEC_EVENT_LOST_MSGS``
150*4882a593Smuzhiyun      - 2
151*4882a593Smuzhiyun      - Generated if one or more CEC messages were lost because the
152*4882a593Smuzhiyun	application didn't dequeue CEC messages fast enough.
153*4882a593Smuzhiyun    * .. _`CEC-EVENT-PIN-CEC-LOW`:
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun      - ``CEC_EVENT_PIN_CEC_LOW``
156*4882a593Smuzhiyun      - 3
157*4882a593Smuzhiyun      - Generated if the CEC pin goes from a high voltage to a low voltage.
158*4882a593Smuzhiyun        Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
159*4882a593Smuzhiyun	capability set.
160*4882a593Smuzhiyun    * .. _`CEC-EVENT-PIN-CEC-HIGH`:
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun      - ``CEC_EVENT_PIN_CEC_HIGH``
163*4882a593Smuzhiyun      - 4
164*4882a593Smuzhiyun      - Generated if the CEC pin goes from a low voltage to a high voltage.
165*4882a593Smuzhiyun        Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
166*4882a593Smuzhiyun	capability set.
167*4882a593Smuzhiyun    * .. _`CEC-EVENT-PIN-HPD-LOW`:
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun      - ``CEC_EVENT_PIN_HPD_LOW``
170*4882a593Smuzhiyun      - 5
171*4882a593Smuzhiyun      - Generated if the HPD pin goes from a high voltage to a low voltage.
172*4882a593Smuzhiyun	Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
173*4882a593Smuzhiyun	capability set. When open() is called, the HPD pin can be read and
174*4882a593Smuzhiyun	if the HPD is low, then an initial event will be generated for that
175*4882a593Smuzhiyun	filehandle.
176*4882a593Smuzhiyun    * .. _`CEC-EVENT-PIN-HPD-HIGH`:
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun      - ``CEC_EVENT_PIN_HPD_HIGH``
179*4882a593Smuzhiyun      - 6
180*4882a593Smuzhiyun      - Generated if the HPD pin goes from a low voltage to a high voltage.
181*4882a593Smuzhiyun	Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
182*4882a593Smuzhiyun	capability set. When open() is called, the HPD pin can be read and
183*4882a593Smuzhiyun	if the HPD is high, then an initial event will be generated for that
184*4882a593Smuzhiyun	filehandle.
185*4882a593Smuzhiyun    * .. _`CEC-EVENT-PIN-5V-LOW`:
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun      - ``CEC_EVENT_PIN_5V_LOW``
188*4882a593Smuzhiyun      - 6
189*4882a593Smuzhiyun      - Generated if the 5V pin goes from a high voltage to a low voltage.
190*4882a593Smuzhiyun	Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
191*4882a593Smuzhiyun	capability set. When open() is called, the 5V pin can be read and
192*4882a593Smuzhiyun	if the 5V is low, then an initial event will be generated for that
193*4882a593Smuzhiyun	filehandle.
194*4882a593Smuzhiyun    * .. _`CEC-EVENT-PIN-5V-HIGH`:
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun      - ``CEC_EVENT_PIN_5V_HIGH``
197*4882a593Smuzhiyun      - 7
198*4882a593Smuzhiyun      - Generated if the 5V pin goes from a low voltage to a high voltage.
199*4882a593Smuzhiyun	Only applies to adapters that have the ``CEC_CAP_MONITOR_PIN``
200*4882a593Smuzhiyun	capability set. When open() is called, the 5V pin can be read and
201*4882a593Smuzhiyun	if the 5V is high, then an initial event will be generated for that
202*4882a593Smuzhiyun	filehandle.
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun.. tabularcolumns:: |p{6.0cm}|p{0.6cm}|p{10.9cm}|
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun.. _cec-event-flags:
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun.. flat-table:: CEC Event Flags
209*4882a593Smuzhiyun    :header-rows:  0
210*4882a593Smuzhiyun    :stub-columns: 0
211*4882a593Smuzhiyun    :widths:       3 1 8
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun    * .. _`CEC-EVENT-FL-INITIAL-STATE`:
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun      - ``CEC_EVENT_FL_INITIAL_STATE``
216*4882a593Smuzhiyun      - 1
217*4882a593Smuzhiyun      - Set for the initial events that are generated when the device is
218*4882a593Smuzhiyun	opened. See the table above for which events do this. This allows
219*4882a593Smuzhiyun	applications to learn the initial state of the CEC adapter at
220*4882a593Smuzhiyun	open() time.
221*4882a593Smuzhiyun    * .. _`CEC-EVENT-FL-DROPPED-EVENTS`:
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun      - ``CEC_EVENT_FL_DROPPED_EVENTS``
224*4882a593Smuzhiyun      - 2
225*4882a593Smuzhiyun      - Set if one or more events of the given event type have been dropped.
226*4882a593Smuzhiyun        This is an indication that the application cannot keep up.
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun
229*4882a593SmuzhiyunReturn Value
230*4882a593Smuzhiyun============
231*4882a593Smuzhiyun
232*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set
233*4882a593Smuzhiyunappropriately. The generic error codes are described at the
234*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter.
235*4882a593Smuzhiyun
236*4882a593SmuzhiyunThe :ref:`ioctl CEC_DQEVENT <CEC_DQEVENT>` can return the following
237*4882a593Smuzhiyunerror codes:
238*4882a593Smuzhiyun
239*4882a593SmuzhiyunEAGAIN
240*4882a593Smuzhiyun    This is returned when the filehandle is in non-blocking mode and there
241*4882a593Smuzhiyun    are no pending events.
242*4882a593Smuzhiyun
243*4882a593SmuzhiyunERESTARTSYS
244*4882a593Smuzhiyun    An interrupt (e.g. Ctrl-C) arrived while in blocking mode waiting for
245*4882a593Smuzhiyun    events to arrive.
246