xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/cec/cec-ioc-g-mode.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_MODE:
5*4882a593Smuzhiyun.. _CEC_G_MODE:
6*4882a593Smuzhiyun.. _CEC_S_MODE:
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun********************************
9*4882a593Smuzhiyunioctls CEC_G_MODE and CEC_S_MODE
10*4882a593Smuzhiyun********************************
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunCEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunSynopsis
15*4882a593Smuzhiyun========
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun.. c:macro:: CEC_G_MODE
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun``int ioctl(int fd, CEC_G_MODE, __u32 *argp)``
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun.. c:macro:: CEC_S_MODE
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun``int ioctl(int fd, CEC_S_MODE, __u32 *argp)``
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunArguments
26*4882a593Smuzhiyun=========
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun``fd``
29*4882a593Smuzhiyun    File descriptor returned by :c:func:`open()`.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun``argp``
32*4882a593Smuzhiyun    Pointer to CEC mode.
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunDescription
35*4882a593Smuzhiyun===========
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunBy default any filehandle can use :ref:`CEC_TRANSMIT`, but in order to prevent
38*4882a593Smuzhiyunapplications from stepping on each others toes it must be possible to
39*4882a593Smuzhiyunobtain exclusive access to the CEC adapter. This ioctl sets the
40*4882a593Smuzhiyunfilehandle to initiator and/or follower mode which can be exclusive
41*4882a593Smuzhiyundepending on the chosen mode. The initiator is the filehandle that is
42*4882a593Smuzhiyunused to initiate messages, i.e. it commands other CEC devices. The
43*4882a593Smuzhiyunfollower is the filehandle that receives messages sent to the CEC
44*4882a593Smuzhiyunadapter and processes them. The same filehandle can be both initiator
45*4882a593Smuzhiyunand follower, or this role can be taken by two different filehandles.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunWhen a CEC message is received, then the CEC framework will decide how
48*4882a593Smuzhiyunit will be processed. If the message is a reply to an earlier
49*4882a593Smuzhiyuntransmitted message, then the reply is sent back to the filehandle that
50*4882a593Smuzhiyunis waiting for it. In addition the CEC framework will process it.
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunIf the message is not a reply, then the CEC framework will process it
53*4882a593Smuzhiyunfirst. If there is no follower, then the message is just discarded and a
54*4882a593Smuzhiyunfeature abort is sent back to the initiator if the framework couldn't
55*4882a593Smuzhiyunprocess it. If there is a follower, then the message is passed on to the
56*4882a593Smuzhiyunfollower who will use :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` to dequeue
57*4882a593Smuzhiyunthe new message. The framework expects the follower to make the right
58*4882a593Smuzhiyundecisions.
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunThe CEC framework will process core messages unless requested otherwise
61*4882a593Smuzhiyunby the follower. The follower can enable the passthrough mode. In that
62*4882a593Smuzhiyuncase, the CEC framework will pass on most core messages without
63*4882a593Smuzhiyunprocessing them and the follower will have to implement those messages.
64*4882a593SmuzhiyunThere are some messages that the core will always process, regardless of
65*4882a593Smuzhiyunthe passthrough mode. See :ref:`cec-core-processing` for details.
66*4882a593Smuzhiyun
67*4882a593SmuzhiyunIf there is no initiator, then any CEC filehandle can use
68*4882a593Smuzhiyun:ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If there is an exclusive
69*4882a593Smuzhiyuninitiator then only that initiator can call
70*4882a593Smuzhiyun:ref:`CEC_TRANSMIT`. The follower can of course
71*4882a593Smuzhiyunalways call :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunAvailable initiator modes are:
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun.. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun.. _cec-mode-initiator_e:
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun.. flat-table:: Initiator Modes
80*4882a593Smuzhiyun    :header-rows:  0
81*4882a593Smuzhiyun    :stub-columns: 0
82*4882a593Smuzhiyun    :widths:       3 1 16
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun    * .. _`CEC-MODE-NO-INITIATOR`:
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun      - ``CEC_MODE_NO_INITIATOR``
87*4882a593Smuzhiyun      - 0x0
88*4882a593Smuzhiyun      - This is not an initiator, i.e. it cannot transmit CEC messages or
89*4882a593Smuzhiyun	make any other changes to the CEC adapter.
90*4882a593Smuzhiyun    * .. _`CEC-MODE-INITIATOR`:
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun      - ``CEC_MODE_INITIATOR``
93*4882a593Smuzhiyun      - 0x1
94*4882a593Smuzhiyun      - This is an initiator (the default when the device is opened) and
95*4882a593Smuzhiyun	it can transmit CEC messages and make changes to the CEC adapter,
96*4882a593Smuzhiyun	unless there is an exclusive initiator.
97*4882a593Smuzhiyun    * .. _`CEC-MODE-EXCL-INITIATOR`:
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun      - ``CEC_MODE_EXCL_INITIATOR``
100*4882a593Smuzhiyun      - 0x2
101*4882a593Smuzhiyun      - This is an exclusive initiator and this file descriptor is the
102*4882a593Smuzhiyun	only one that can transmit CEC messages and make changes to the
103*4882a593Smuzhiyun	CEC adapter. If someone else is already the exclusive initiator
104*4882a593Smuzhiyun	then an attempt to become one will return the ``EBUSY`` error code
105*4882a593Smuzhiyun	error.
106*4882a593Smuzhiyun
107*4882a593SmuzhiyunAvailable follower modes are:
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun.. tabularcolumns:: |p{6.6cm}|p{0.9cm}|p{10.0cm}|
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun.. _cec-mode-follower_e:
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun.. cssclass:: longtable
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun.. flat-table:: Follower Modes
116*4882a593Smuzhiyun    :header-rows:  0
117*4882a593Smuzhiyun    :stub-columns: 0
118*4882a593Smuzhiyun    :widths:       3 1 16
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun    * .. _`CEC-MODE-NO-FOLLOWER`:
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun      - ``CEC_MODE_NO_FOLLOWER``
123*4882a593Smuzhiyun      - 0x00
124*4882a593Smuzhiyun      - This is not a follower (the default when the device is opened).
125*4882a593Smuzhiyun    * .. _`CEC-MODE-FOLLOWER`:
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun      - ``CEC_MODE_FOLLOWER``
128*4882a593Smuzhiyun      - 0x10
129*4882a593Smuzhiyun      - This is a follower and it will receive CEC messages unless there
130*4882a593Smuzhiyun	is an exclusive follower. You cannot become a follower if
131*4882a593Smuzhiyun	:ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
132*4882a593Smuzhiyun	was specified, the ``EINVAL`` error code is returned in that case.
133*4882a593Smuzhiyun    * .. _`CEC-MODE-EXCL-FOLLOWER`:
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun      - ``CEC_MODE_EXCL_FOLLOWER``
136*4882a593Smuzhiyun      - 0x20
137*4882a593Smuzhiyun      - This is an exclusive follower and only this file descriptor will
138*4882a593Smuzhiyun	receive CEC messages for processing. If someone else is already
139*4882a593Smuzhiyun	the exclusive follower then an attempt to become one will return
140*4882a593Smuzhiyun	the ``EBUSY`` error code. You cannot become a follower if
141*4882a593Smuzhiyun	:ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
142*4882a593Smuzhiyun	was specified, the ``EINVAL`` error code is returned in that case.
143*4882a593Smuzhiyun    * .. _`CEC-MODE-EXCL-FOLLOWER-PASSTHRU`:
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun      - ``CEC_MODE_EXCL_FOLLOWER_PASSTHRU``
146*4882a593Smuzhiyun      - 0x30
147*4882a593Smuzhiyun      - This is an exclusive follower and only this file descriptor will
148*4882a593Smuzhiyun	receive CEC messages for processing. In addition it will put the
149*4882a593Smuzhiyun	CEC device into passthrough mode, allowing the exclusive follower
150*4882a593Smuzhiyun	to handle most core messages instead of relying on the CEC
151*4882a593Smuzhiyun	framework for that. If someone else is already the exclusive
152*4882a593Smuzhiyun	follower then an attempt to become one will return the ``EBUSY`` error
153*4882a593Smuzhiyun	code. You cannot become a follower if :ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>`
154*4882a593Smuzhiyun	is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>` was specified,
155*4882a593Smuzhiyun	the ``EINVAL`` error code is returned in that case.
156*4882a593Smuzhiyun    * .. _`CEC-MODE-MONITOR-PIN`:
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun      - ``CEC_MODE_MONITOR_PIN``
159*4882a593Smuzhiyun      - 0xd0
160*4882a593Smuzhiyun      - Put the file descriptor into pin monitoring mode. Can only be used in
161*4882a593Smuzhiyun	combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
162*4882a593Smuzhiyun	otherwise the ``EINVAL`` error code will be returned.
163*4882a593Smuzhiyun	This mode requires that the :ref:`CEC_CAP_MONITOR_PIN <CEC-CAP-MONITOR-PIN>`
164*4882a593Smuzhiyun	capability is set, otherwise the ``EINVAL`` error code is returned.
165*4882a593Smuzhiyun	While in pin monitoring mode this file descriptor can receive the
166*4882a593Smuzhiyun	``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events to see the
167*4882a593Smuzhiyun	low-level CEC pin transitions. This is very useful for debugging.
168*4882a593Smuzhiyun	This mode is only allowed if the process has the ``CAP_NET_ADMIN``
169*4882a593Smuzhiyun	capability. If that is not set, then the ``EPERM`` error code is returned.
170*4882a593Smuzhiyun    * .. _`CEC-MODE-MONITOR`:
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun      - ``CEC_MODE_MONITOR``
173*4882a593Smuzhiyun      - 0xe0
174*4882a593Smuzhiyun      - Put the file descriptor into monitor mode. Can only be used in
175*4882a593Smuzhiyun	combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
176*4882a593Smuzhiyun	otherwise the ``EINVAL`` error code will be returned.
177*4882a593Smuzhiyun	In monitor mode all messages this CEC
178*4882a593Smuzhiyun	device transmits and all messages it receives (both broadcast
179*4882a593Smuzhiyun	messages and directed messages for one its logical addresses) will
180*4882a593Smuzhiyun	be reported. This is very useful for debugging. This is only
181*4882a593Smuzhiyun	allowed if the process has the ``CAP_NET_ADMIN`` capability. If
182*4882a593Smuzhiyun	that is not set, then the ``EPERM`` error code is returned.
183*4882a593Smuzhiyun    * .. _`CEC-MODE-MONITOR-ALL`:
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun      - ``CEC_MODE_MONITOR_ALL``
186*4882a593Smuzhiyun      - 0xf0
187*4882a593Smuzhiyun      - Put the file descriptor into 'monitor all' mode. Can only be used
188*4882a593Smuzhiyun	in combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`, otherwise
189*4882a593Smuzhiyun	the ``EINVAL`` error code will be returned. In 'monitor all' mode all messages
190*4882a593Smuzhiyun	this CEC device transmits and all messages it receives, including
191*4882a593Smuzhiyun	directed messages for other CEC devices will be reported. This is
192*4882a593Smuzhiyun	very useful for debugging, but not all devices support this. This
193*4882a593Smuzhiyun	mode requires that the :ref:`CEC_CAP_MONITOR_ALL <CEC-CAP-MONITOR-ALL>` capability is set,
194*4882a593Smuzhiyun	otherwise the ``EINVAL`` error code is returned. This is only allowed if
195*4882a593Smuzhiyun	the process has the ``CAP_NET_ADMIN`` capability. If that is not
196*4882a593Smuzhiyun	set, then the ``EPERM`` error code is returned.
197*4882a593Smuzhiyun
198*4882a593SmuzhiyunCore message processing details:
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun.. tabularcolumns:: |p{6.6cm}|p{10.9cm}|
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun.. _cec-core-processing:
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun.. flat-table:: Core Message Processing
205*4882a593Smuzhiyun    :header-rows:  0
206*4882a593Smuzhiyun    :stub-columns: 0
207*4882a593Smuzhiyun    :widths: 1 8
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun    * .. _`CEC-MSG-GET-CEC-VERSION`:
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun      - ``CEC_MSG_GET_CEC_VERSION``
212*4882a593Smuzhiyun      - The core will return the CEC version that was set with
213*4882a593Smuzhiyun	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
214*4882a593Smuzhiyun	except when in passthrough mode. In passthrough mode the core
215*4882a593Smuzhiyun	does nothing and this message has to be handled by a follower
216*4882a593Smuzhiyun	instead.
217*4882a593Smuzhiyun    * .. _`CEC-MSG-GIVE-DEVICE-VENDOR-ID`:
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun      - ``CEC_MSG_GIVE_DEVICE_VENDOR_ID``
220*4882a593Smuzhiyun      - The core will return the vendor ID that was set with
221*4882a593Smuzhiyun	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
222*4882a593Smuzhiyun	except when in passthrough mode. In passthrough mode the core
223*4882a593Smuzhiyun	does nothing and this message has to be handled by a follower
224*4882a593Smuzhiyun	instead.
225*4882a593Smuzhiyun    * .. _`CEC-MSG-ABORT`:
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun      - ``CEC_MSG_ABORT``
228*4882a593Smuzhiyun      - The core will return a Feature Abort message with reason
229*4882a593Smuzhiyun        'Feature Refused' as per the specification, except when in
230*4882a593Smuzhiyun	passthrough mode. In passthrough mode the core does nothing
231*4882a593Smuzhiyun	and this message has to be handled by a follower instead.
232*4882a593Smuzhiyun    * .. _`CEC-MSG-GIVE-PHYSICAL-ADDR`:
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun      - ``CEC_MSG_GIVE_PHYSICAL_ADDR``
235*4882a593Smuzhiyun      - The core will report the current physical address, except when
236*4882a593Smuzhiyun        in passthrough mode. In passthrough mode the core does nothing
237*4882a593Smuzhiyun	and this message has to be handled by a follower instead.
238*4882a593Smuzhiyun    * .. _`CEC-MSG-GIVE-OSD-NAME`:
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun      - ``CEC_MSG_GIVE_OSD_NAME``
241*4882a593Smuzhiyun      - The core will report the current OSD name that was set with
242*4882a593Smuzhiyun	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
243*4882a593Smuzhiyun	except when in passthrough mode. In passthrough mode the core
244*4882a593Smuzhiyun	does nothing and this message has to be handled by a follower
245*4882a593Smuzhiyun	instead.
246*4882a593Smuzhiyun    * .. _`CEC-MSG-GIVE-FEATURES`:
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun      - ``CEC_MSG_GIVE_FEATURES``
249*4882a593Smuzhiyun      - The core will do nothing if the CEC version is older than 2.0,
250*4882a593Smuzhiyun        otherwise it will report the current features that were set with
251*4882a593Smuzhiyun	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
252*4882a593Smuzhiyun	except when in passthrough mode. In passthrough mode the core
253*4882a593Smuzhiyun	does nothing (for any CEC version) and this message has to be handled
254*4882a593Smuzhiyun	by a follower instead.
255*4882a593Smuzhiyun    * .. _`CEC-MSG-USER-CONTROL-PRESSED`:
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun      - ``CEC_MSG_USER_CONTROL_PRESSED``
258*4882a593Smuzhiyun      - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
259*4882a593Smuzhiyun        :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
260*4882a593Smuzhiyun	is set, then generate a remote control key
261*4882a593Smuzhiyun	press. This message is always passed on to the follower(s).
262*4882a593Smuzhiyun    * .. _`CEC-MSG-USER-CONTROL-RELEASED`:
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun      - ``CEC_MSG_USER_CONTROL_RELEASED``
265*4882a593Smuzhiyun      - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
266*4882a593Smuzhiyun        :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
267*4882a593Smuzhiyun        is set, then generate a remote control key
268*4882a593Smuzhiyun	release. This message is always passed on to the follower(s).
269*4882a593Smuzhiyun    * .. _`CEC-MSG-REPORT-PHYSICAL-ADDR`:
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun      - ``CEC_MSG_REPORT_PHYSICAL_ADDR``
272*4882a593Smuzhiyun      - The CEC framework will make note of the reported physical address
273*4882a593Smuzhiyun	and then just pass the message on to the follower(s).
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun
276*4882a593SmuzhiyunReturn Value
277*4882a593Smuzhiyun============
278*4882a593Smuzhiyun
279*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set
280*4882a593Smuzhiyunappropriately. The generic error codes are described at the
281*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter.
282*4882a593Smuzhiyun
283*4882a593SmuzhiyunThe :ref:`ioctl CEC_S_MODE <CEC_S_MODE>` can return the following
284*4882a593Smuzhiyunerror codes:
285*4882a593Smuzhiyun
286*4882a593SmuzhiyunEINVAL
287*4882a593Smuzhiyun    The requested mode is invalid.
288*4882a593Smuzhiyun
289*4882a593SmuzhiyunEPERM
290*4882a593Smuzhiyun    Monitor mode is requested, but the process does have the ``CAP_NET_ADMIN``
291*4882a593Smuzhiyun    capability.
292*4882a593Smuzhiyun
293*4882a593SmuzhiyunEBUSY
294*4882a593Smuzhiyun    Someone else is already an exclusive follower or initiator.
295