162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: CEC
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _CEC_MODE:
562306a36Sopenharmony_ci.. _CEC_G_MODE:
662306a36Sopenharmony_ci.. _CEC_S_MODE:
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci********************************
962306a36Sopenharmony_ciioctls CEC_G_MODE and CEC_S_MODE
1062306a36Sopenharmony_ci********************************
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciCEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciSynopsis
1562306a36Sopenharmony_ci========
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci.. c:macro:: CEC_G_MODE
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci``int ioctl(int fd, CEC_G_MODE, __u32 *argp)``
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci.. c:macro:: CEC_S_MODE
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci``int ioctl(int fd, CEC_S_MODE, __u32 *argp)``
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciArguments
2662306a36Sopenharmony_ci=========
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci``fd``
2962306a36Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci``argp``
3262306a36Sopenharmony_ci    Pointer to CEC mode.
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ciDescription
3562306a36Sopenharmony_ci===========
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciBy default any filehandle can use :ref:`CEC_TRANSMIT`, but in order to prevent
3862306a36Sopenharmony_ciapplications from stepping on each others toes it must be possible to
3962306a36Sopenharmony_ciobtain exclusive access to the CEC adapter. This ioctl sets the
4062306a36Sopenharmony_cifilehandle to initiator and/or follower mode which can be exclusive
4162306a36Sopenharmony_cidepending on the chosen mode. The initiator is the filehandle that is
4262306a36Sopenharmony_ciused to initiate messages, i.e. it commands other CEC devices. The
4362306a36Sopenharmony_cifollower is the filehandle that receives messages sent to the CEC
4462306a36Sopenharmony_ciadapter and processes them. The same filehandle can be both initiator
4562306a36Sopenharmony_ciand follower, or this role can be taken by two different filehandles.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ciWhen a CEC message is received, then the CEC framework will decide how
4862306a36Sopenharmony_ciit will be processed. If the message is a reply to an earlier
4962306a36Sopenharmony_citransmitted message, then the reply is sent back to the filehandle that
5062306a36Sopenharmony_ciis waiting for it. In addition the CEC framework will process it.
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciIf the message is not a reply, then the CEC framework will process it
5362306a36Sopenharmony_cifirst. If there is no follower, then the message is just discarded and a
5462306a36Sopenharmony_cifeature abort is sent back to the initiator if the framework couldn't
5562306a36Sopenharmony_ciprocess it. If there is a follower, then the message is passed on to the
5662306a36Sopenharmony_cifollower who will use :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` to dequeue
5762306a36Sopenharmony_cithe new message. The framework expects the follower to make the right
5862306a36Sopenharmony_cidecisions.
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciThe CEC framework will process core messages unless requested otherwise
6162306a36Sopenharmony_ciby the follower. The follower can enable the passthrough mode. In that
6262306a36Sopenharmony_cicase, the CEC framework will pass on most core messages without
6362306a36Sopenharmony_ciprocessing them and the follower will have to implement those messages.
6462306a36Sopenharmony_ciThere are some messages that the core will always process, regardless of
6562306a36Sopenharmony_cithe passthrough mode. See :ref:`cec-core-processing` for details.
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ciIf there is no initiator, then any CEC filehandle can use
6862306a36Sopenharmony_ci:ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If there is an exclusive
6962306a36Sopenharmony_ciinitiator then only that initiator can call
7062306a36Sopenharmony_ci:ref:`CEC_TRANSMIT`. The follower can of course
7162306a36Sopenharmony_cialways call :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ciAvailable initiator modes are:
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci.. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci.. _cec-mode-initiator_e:
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci.. flat-table:: Initiator Modes
8062306a36Sopenharmony_ci    :header-rows:  0
8162306a36Sopenharmony_ci    :stub-columns: 0
8262306a36Sopenharmony_ci    :widths:       3 1 16
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci    * .. _`CEC-MODE-NO-INITIATOR`:
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci      - ``CEC_MODE_NO_INITIATOR``
8762306a36Sopenharmony_ci      - 0x0
8862306a36Sopenharmony_ci      - This is not an initiator, i.e. it cannot transmit CEC messages or
8962306a36Sopenharmony_ci	make any other changes to the CEC adapter.
9062306a36Sopenharmony_ci    * .. _`CEC-MODE-INITIATOR`:
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci      - ``CEC_MODE_INITIATOR``
9362306a36Sopenharmony_ci      - 0x1
9462306a36Sopenharmony_ci      - This is an initiator (the default when the device is opened) and
9562306a36Sopenharmony_ci	it can transmit CEC messages and make changes to the CEC adapter,
9662306a36Sopenharmony_ci	unless there is an exclusive initiator.
9762306a36Sopenharmony_ci    * .. _`CEC-MODE-EXCL-INITIATOR`:
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci      - ``CEC_MODE_EXCL_INITIATOR``
10062306a36Sopenharmony_ci      - 0x2
10162306a36Sopenharmony_ci      - This is an exclusive initiator and this file descriptor is the
10262306a36Sopenharmony_ci	only one that can transmit CEC messages and make changes to the
10362306a36Sopenharmony_ci	CEC adapter. If someone else is already the exclusive initiator
10462306a36Sopenharmony_ci	then an attempt to become one will return the ``EBUSY`` error code
10562306a36Sopenharmony_ci	error.
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciAvailable follower modes are:
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{0.9cm}|p{9.8cm}|
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci.. _cec-mode-follower_e:
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci.. cssclass:: longtable
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci.. flat-table:: Follower Modes
11662306a36Sopenharmony_ci    :header-rows:  0
11762306a36Sopenharmony_ci    :stub-columns: 0
11862306a36Sopenharmony_ci    :widths:       3 1 16
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci    * .. _`CEC-MODE-NO-FOLLOWER`:
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci      - ``CEC_MODE_NO_FOLLOWER``
12362306a36Sopenharmony_ci      - 0x00
12462306a36Sopenharmony_ci      - This is not a follower (the default when the device is opened).
12562306a36Sopenharmony_ci    * .. _`CEC-MODE-FOLLOWER`:
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci      - ``CEC_MODE_FOLLOWER``
12862306a36Sopenharmony_ci      - 0x10
12962306a36Sopenharmony_ci      - This is a follower and it will receive CEC messages unless there
13062306a36Sopenharmony_ci	is an exclusive follower. You cannot become a follower if
13162306a36Sopenharmony_ci	:ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
13262306a36Sopenharmony_ci	was specified, the ``EINVAL`` error code is returned in that case.
13362306a36Sopenharmony_ci    * .. _`CEC-MODE-EXCL-FOLLOWER`:
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci      - ``CEC_MODE_EXCL_FOLLOWER``
13662306a36Sopenharmony_ci      - 0x20
13762306a36Sopenharmony_ci      - This is an exclusive follower and only this file descriptor will
13862306a36Sopenharmony_ci	receive CEC messages for processing. If someone else is already
13962306a36Sopenharmony_ci	the exclusive follower then an attempt to become one will return
14062306a36Sopenharmony_ci	the ``EBUSY`` error code. You cannot become a follower if
14162306a36Sopenharmony_ci	:ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
14262306a36Sopenharmony_ci	was specified, the ``EINVAL`` error code is returned in that case.
14362306a36Sopenharmony_ci    * .. _`CEC-MODE-EXCL-FOLLOWER-PASSTHRU`:
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci      - ``CEC_MODE_EXCL_FOLLOWER_PASSTHRU``
14662306a36Sopenharmony_ci      - 0x30
14762306a36Sopenharmony_ci      - This is an exclusive follower and only this file descriptor will
14862306a36Sopenharmony_ci	receive CEC messages for processing. In addition it will put the
14962306a36Sopenharmony_ci	CEC device into passthrough mode, allowing the exclusive follower
15062306a36Sopenharmony_ci	to handle most core messages instead of relying on the CEC
15162306a36Sopenharmony_ci	framework for that. If someone else is already the exclusive
15262306a36Sopenharmony_ci	follower then an attempt to become one will return the ``EBUSY`` error
15362306a36Sopenharmony_ci	code. You cannot become a follower if :ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>`
15462306a36Sopenharmony_ci	is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>` was specified,
15562306a36Sopenharmony_ci	the ``EINVAL`` error code is returned in that case.
15662306a36Sopenharmony_ci    * .. _`CEC-MODE-MONITOR-PIN`:
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci      - ``CEC_MODE_MONITOR_PIN``
15962306a36Sopenharmony_ci      - 0xd0
16062306a36Sopenharmony_ci      - Put the file descriptor into pin monitoring mode. Can only be used in
16162306a36Sopenharmony_ci	combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
16262306a36Sopenharmony_ci	otherwise the ``EINVAL`` error code will be returned.
16362306a36Sopenharmony_ci	This mode requires that the :ref:`CEC_CAP_MONITOR_PIN <CEC-CAP-MONITOR-PIN>`
16462306a36Sopenharmony_ci	capability is set, otherwise the ``EINVAL`` error code is returned.
16562306a36Sopenharmony_ci	While in pin monitoring mode this file descriptor can receive the
16662306a36Sopenharmony_ci	``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events to see the
16762306a36Sopenharmony_ci	low-level CEC pin transitions. This is very useful for debugging.
16862306a36Sopenharmony_ci	This mode is only allowed if the process has the ``CAP_NET_ADMIN``
16962306a36Sopenharmony_ci	capability. If that is not set, then the ``EPERM`` error code is returned.
17062306a36Sopenharmony_ci    * .. _`CEC-MODE-MONITOR`:
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ci      - ``CEC_MODE_MONITOR``
17362306a36Sopenharmony_ci      - 0xe0
17462306a36Sopenharmony_ci      - Put the file descriptor into monitor mode. Can only be used in
17562306a36Sopenharmony_ci	combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
17662306a36Sopenharmony_ci	otherwise the ``EINVAL`` error code will be returned.
17762306a36Sopenharmony_ci	In monitor mode all messages this CEC
17862306a36Sopenharmony_ci	device transmits and all messages it receives (both broadcast
17962306a36Sopenharmony_ci	messages and directed messages for one its logical addresses) will
18062306a36Sopenharmony_ci	be reported. This is very useful for debugging. This is only
18162306a36Sopenharmony_ci	allowed if the process has the ``CAP_NET_ADMIN`` capability. If
18262306a36Sopenharmony_ci	that is not set, then the ``EPERM`` error code is returned.
18362306a36Sopenharmony_ci    * .. _`CEC-MODE-MONITOR-ALL`:
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci      - ``CEC_MODE_MONITOR_ALL``
18662306a36Sopenharmony_ci      - 0xf0
18762306a36Sopenharmony_ci      - Put the file descriptor into 'monitor all' mode. Can only be used
18862306a36Sopenharmony_ci	in combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`, otherwise
18962306a36Sopenharmony_ci	the ``EINVAL`` error code will be returned. In 'monitor all' mode all messages
19062306a36Sopenharmony_ci	this CEC device transmits and all messages it receives, including
19162306a36Sopenharmony_ci	directed messages for other CEC devices, will be reported. This is
19262306a36Sopenharmony_ci	very useful for debugging, but not all devices support this. This
19362306a36Sopenharmony_ci	mode requires that the :ref:`CEC_CAP_MONITOR_ALL <CEC-CAP-MONITOR-ALL>` capability is set,
19462306a36Sopenharmony_ci	otherwise the ``EINVAL`` error code is returned. This is only allowed if
19562306a36Sopenharmony_ci	the process has the ``CAP_NET_ADMIN`` capability. If that is not
19662306a36Sopenharmony_ci	set, then the ``EPERM`` error code is returned.
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ciCore message processing details:
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{10.9cm}|
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci.. _cec-core-processing:
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci.. flat-table:: Core Message Processing
20562306a36Sopenharmony_ci    :header-rows:  0
20662306a36Sopenharmony_ci    :stub-columns: 0
20762306a36Sopenharmony_ci    :widths: 1 8
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci    * .. _`CEC-MSG-GET-CEC-VERSION`:
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci      - ``CEC_MSG_GET_CEC_VERSION``
21262306a36Sopenharmony_ci      - The core will return the CEC version that was set with
21362306a36Sopenharmony_ci	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
21462306a36Sopenharmony_ci	except when in passthrough mode. In passthrough mode the core
21562306a36Sopenharmony_ci	does nothing and this message has to be handled by a follower
21662306a36Sopenharmony_ci	instead.
21762306a36Sopenharmony_ci    * .. _`CEC-MSG-GIVE-DEVICE-VENDOR-ID`:
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci      - ``CEC_MSG_GIVE_DEVICE_VENDOR_ID``
22062306a36Sopenharmony_ci      - The core will return the vendor ID that was set with
22162306a36Sopenharmony_ci	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
22262306a36Sopenharmony_ci	except when in passthrough mode. In passthrough mode the core
22362306a36Sopenharmony_ci	does nothing and this message has to be handled by a follower
22462306a36Sopenharmony_ci	instead.
22562306a36Sopenharmony_ci    * .. _`CEC-MSG-ABORT`:
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci      - ``CEC_MSG_ABORT``
22862306a36Sopenharmony_ci      - The core will return a Feature Abort message with reason
22962306a36Sopenharmony_ci        'Feature Refused' as per the specification, except when in
23062306a36Sopenharmony_ci	passthrough mode. In passthrough mode the core does nothing
23162306a36Sopenharmony_ci	and this message has to be handled by a follower instead.
23262306a36Sopenharmony_ci    * .. _`CEC-MSG-GIVE-PHYSICAL-ADDR`:
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci      - ``CEC_MSG_GIVE_PHYSICAL_ADDR``
23562306a36Sopenharmony_ci      - The core will report the current physical address, except when
23662306a36Sopenharmony_ci        in passthrough mode. In passthrough mode the core does nothing
23762306a36Sopenharmony_ci	and this message has to be handled by a follower instead.
23862306a36Sopenharmony_ci    * .. _`CEC-MSG-GIVE-OSD-NAME`:
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci      - ``CEC_MSG_GIVE_OSD_NAME``
24162306a36Sopenharmony_ci      - The core will report the current OSD name that was set with
24262306a36Sopenharmony_ci	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
24362306a36Sopenharmony_ci	except when in passthrough mode. In passthrough mode the core
24462306a36Sopenharmony_ci	does nothing and this message has to be handled by a follower
24562306a36Sopenharmony_ci	instead.
24662306a36Sopenharmony_ci    * .. _`CEC-MSG-GIVE-FEATURES`:
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci      - ``CEC_MSG_GIVE_FEATURES``
24962306a36Sopenharmony_ci      - The core will do nothing if the CEC version is older than 2.0,
25062306a36Sopenharmony_ci        otherwise it will report the current features that were set with
25162306a36Sopenharmony_ci	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
25262306a36Sopenharmony_ci	except when in passthrough mode. In passthrough mode the core
25362306a36Sopenharmony_ci	does nothing (for any CEC version) and this message has to be handled
25462306a36Sopenharmony_ci	by a follower instead.
25562306a36Sopenharmony_ci    * .. _`CEC-MSG-USER-CONTROL-PRESSED`:
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci      - ``CEC_MSG_USER_CONTROL_PRESSED``
25862306a36Sopenharmony_ci      - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
25962306a36Sopenharmony_ci        :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
26062306a36Sopenharmony_ci	is set, then generate a remote control key
26162306a36Sopenharmony_ci	press. This message is always passed on to the follower(s).
26262306a36Sopenharmony_ci    * .. _`CEC-MSG-USER-CONTROL-RELEASED`:
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci      - ``CEC_MSG_USER_CONTROL_RELEASED``
26562306a36Sopenharmony_ci      - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
26662306a36Sopenharmony_ci        :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
26762306a36Sopenharmony_ci        is set, then generate a remote control key
26862306a36Sopenharmony_ci	release. This message is always passed on to the follower(s).
26962306a36Sopenharmony_ci    * .. _`CEC-MSG-REPORT-PHYSICAL-ADDR`:
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci      - ``CEC_MSG_REPORT_PHYSICAL_ADDR``
27262306a36Sopenharmony_ci      - The CEC framework will make note of the reported physical address
27362306a36Sopenharmony_ci	and then just pass the message on to the follower(s).
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ciReturn Value
27762306a36Sopenharmony_ci============
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
28062306a36Sopenharmony_ciappropriately. The generic error codes are described at the
28162306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ciThe :ref:`ioctl CEC_S_MODE <CEC_S_MODE>` can return the following
28462306a36Sopenharmony_cierror codes:
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ciEINVAL
28762306a36Sopenharmony_ci    The requested mode is invalid.
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ciEPERM
29062306a36Sopenharmony_ci    Monitor mode is requested, but the process does have the ``CAP_NET_ADMIN``
29162306a36Sopenharmony_ci    capability.
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ciEBUSY
29462306a36Sopenharmony_ci    Someone else is already an exclusive follower or initiator.
295