# HDMI CEC

---

# Part V - Consumer Electronics Control API

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> This part describes the CEC: Consumer Electronics Control

<a id="rst-part-v-consumer-electronics-control-api"></a>
<a id="rst-cec"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

This part describes the CEC: Consumer Electronics Control

**Table of Contents**

1. [Introduction](</kernel/userspace/userspace-api/media-cec/cec-intro.md>)
2. [Function Reference](</kernel/userspace/userspace-api/media-cec/cec-funcs.md>)
3. [CEC Pin Framework Error Injection](</kernel/userspace/userspace-api/media-cec/cec-pin-error-inj.md>)
4. [cec-header](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/cec/cec-header.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

<a id="rst-revision-and-copyright"></a>

## Revision and Copyright

Authors:

- Verkuil, Hans &lt;[hverkuil@kernel.org](<mailto:hverkuil@kernel.org>)&gt;

> - Initial version.

**Copyright** © 2016 : Hans Verkuil

<a id="rst-revision-history"></a>

## Revision History

**revision:** 1.0.0 / 2016-03-17 (*hv*)

Initial revision

---

# cec close()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-close - Close a cec device

<a id="rst-cec-close"></a>
<a id="rst-cec-func-close"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

cec-close - Close a cec device

<a id="rst-synopsis"></a>

## Synopsis



```c
#include <unistd.h>
```





<a id="c-close"></a>

```c
int close( int fd )
```

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

<a id="rst-description"></a>

## Description

Closes the cec device. Resources associated with the file descriptor are freed. The device configuration remain unchanged.

<a id="rst-return-value"></a>

## Return Value

`close()` returns 0 on success. On error, -1 is returned, and `errno` is set appropriately. Possible error codes are:

- **`EBADF`**

  `fd` is not a valid open file descriptor.

---

# cec ioctl()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-ioctl - Control a cec device

<a id="rst-cec-ioctl"></a>
<a id="rst-cec-func-ioctl"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

cec-ioctl - Control a cec device

<a id="rst-synopsis"></a>

## Synopsis



```c
#include <sys/ioctl.h>
```

`int ioctl(int fd, int request, void *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`request`**

  CEC ioctl request code as defined in the cec.h header file, for example [CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps>).

- **`argp`**

  Pointer to a request-specific structure.

<a id="rst-description"></a>

## Description

The `ioctl()` function manipulates cec device parameters. The argument `fd` must be an open file descriptor.

The ioctl `request` code specifies the cec function to be called. It has encoded in it whether the argument is an input, output or read/write parameter, and the size of the argument `argp` in bytes.

Macros and structures definitions specifying cec ioctl requests and their parameters are located in the cec.h header file. All cec ioctl requests, their respective function and parameters are specified in [Function Reference](</kernel/userspace/userspace-api/media-cec/cec-funcs.md#rst-cec-user-func>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

Request-specific error codes are listed in the individual requests descriptions.

When an ioctl that takes an output or read/write parameter fails, the parameter remains unmodified.

---

# cec open()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-open - Open a cec device

<a id="rst-cec-open"></a>
<a id="rst-cec-func-open"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

cec-open - Open a cec device

<a id="rst-synopsis"></a>

## Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int open( const char *device_name, int flags )
```

<a id="rst-arguments"></a>

## Arguments

- **`device_name`**

  Device to be opened.

- **`flags`**

  Open flags. Access mode must be `O_RDWR`.

  When the `O_NONBLOCK` flag is given, the [CEC_RECEIVE](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-receive>) and [CEC_DQEVENT](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-dqevent>) ioctls will return the `EAGAIN` error code when no message or event is available, and ioctls [CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>), [CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr>) and [CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>) all return 0.

  Other flags have no effect.

<a id="rst-description"></a>

## Description

To open a cec device applications call `open()` with the desired device name. The function has no side effects; the device configuration remain unchanged.

When the device is opened in read-only mode, attempts to modify its configuration will result in an error, and `errno` will be set to EBADF.

<a id="rst-return-value"></a>

## Return Value

`open()` returns the new file descriptor on success. On error, -1 is returned, and `errno` is set appropriately. Possible error codes include:

- **`EACCES`**

  The requested access to the file is not allowed.

- **`EMFILE`**

  The process already has the maximum number of files open.

- **`ENFILE`**

  The system limit on the total number of open files has been reached.

- **`ENOMEM`**

  Insufficient kernel memory was available.

- **`ENODEV`**

  Device not found or was removed.

---

# cec poll()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-poll - Wait for some event on a file descriptor

<a id="rst-cec-poll"></a>
<a id="rst-cec-func-poll"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

cec-poll - Wait for some event on a file descriptor

<a id="rst-synopsis"></a>

## Synopsis



```c
#include <sys/poll.h>
```





<a id="c-poll"></a>

```c
int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
```

<a id="rst-arguments"></a>

## Arguments

- **`ufds`**

  List of FD events to be watched

- **`nfds`**

  Number of FD events at the \*ufds array

- **`timeout`**

  Timeout to wait for events

<a id="rst-description"></a>

## Description

With the `poll()` function applications can wait for CEC events.

On success `poll()` returns the number of file descriptors that have been selected (that is, file descriptors for which the `revents` field of the respective struct `pollfd` is non-zero). CEC devices set the `POLLIN` and `POLLRDNORM` flags in the `revents` field if there are messages in the receive queue. If the transmit queue has room for new messages, the `POLLOUT` and `POLLWRNORM` flags are set. If there are events in the event queue, then the `POLLPRI` flag is set. When the function times out it returns a value of zero, on failure it returns -1 and the `errno` variable is set appropriately.

For more details see the `poll()` manual page.

<a id="rst-return-value"></a>

## Return Value

On success, `poll()` returns the number structures which have non-zero `revents` fields, or zero if the call timed out. On error -1 is returned, and the `errno` variable is set appropriately:

- **`EBADF`**

  One or more of the `ufds` members specify an invalid file descriptor.

- **`EFAULT`**

  `ufds` references an inaccessible memory area.

- **`EINTR`**

  The call was interrupted by a signal.

- **`EINVAL`**

  The `nfds` value exceeds the `RLIMIT_NOFILE` value. Use `getrlimit()` to obtain this value.

---

# Function Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> Reference for Function Reference.

<a id="rst-function-reference"></a>
<a id="rst-cec-user-func"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

- [cec open()](</kernel/userspace/userspace-api/media-cec/cec-func-open.md>)
- [cec close()](</kernel/userspace/userspace-api/media-cec/cec-func-close.md>)
- [cec ioctl()](</kernel/userspace/userspace-api/media-cec/cec-func-ioctl.md>)
- [cec poll()](</kernel/userspace/userspace-api/media-cec/cec-func-poll.md>)
- [ioctl CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md>)
- [ioctls CEC_ADAP_G_LOG_ADDRS and CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md>)
- [ioctls CEC_ADAP_G_PHYS_ADDR and CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md>)
- [ioctl CEC_ADAP_G_CONNECTOR_INFO](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md>)
- [ioctl CEC_DQEVENT](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md>)
- [ioctls CEC_G_MODE and CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md>)
- [ioctls CEC_RECEIVE and CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md>)

---

# CEC uAPI Symbols

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> Reference for CEC uAPI Symbols.

<a id="rst-cec-uapi-symbols"></a>
<a id="rst-cec-header"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->


## IOCTL Commands

- [`CEC_ADAP_G_CAPS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps): `include/uapi/linux/cec.h`, line 503
- [`CEC_ADAP_G_CONNECTOR_INFO`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-adap-g-connector-info): `include/uapi/linux/cec.h`, line 545
- [`CEC_ADAP_G_LOG_ADDRS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-g-log-addrs): `include/uapi/linux/cec.h`, line 528
- [`CEC_ADAP_G_PHYS_ADDR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-g-phys-addr): `include/uapi/linux/cec.h`, line 517
- [`CEC_ADAP_S_LOG_ADDRS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs): `include/uapi/linux/cec.h`, line 529
- [`CEC_ADAP_S_PHYS_ADDR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr): `include/uapi/linux/cec.h`, line 518
- [`CEC_DQEVENT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-dqevent): `include/uapi/linux/cec.h`, line 536
- [`CEC_G_MODE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-g-mode): `include/uapi/linux/cec.h`, line 541
- [`CEC_RECEIVE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-receive): `include/uapi/linux/cec.h`, line 533
- [`CEC_S_MODE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode): `include/uapi/linux/cec.h`, line 542
- [`CEC_TRANSMIT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit): `include/uapi/linux/cec.h`, line 532

## Macros and Definitions

- [`CEC_CAP_CONNECTOR_INFO`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-connector-info): `include/uapi/linux/cec.h`, line 346
- [`CEC_CAP_LOG_ADDRS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-log-addrs): `include/uapi/linux/cec.h`, line 330
- [`CEC_CAP_MONITOR_ALL`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-all): `include/uapi/linux/cec.h`, line 340
- [`CEC_CAP_MONITOR_PIN`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-pin): `include/uapi/linux/cec.h`, line 344
- [`CEC_CAP_NEEDS_HPD`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-needs-hpd): `include/uapi/linux/cec.h`, line 342
- [`CEC_CAP_PASSTHROUGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-passthrough): `include/uapi/linux/cec.h`, line 336
- [`CEC_CAP_PHYS_ADDR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-phys-addr): `include/uapi/linux/cec.h`, line 328
- [`CEC_CAP_RC`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-rc): `include/uapi/linux/cec.h`, line 338
- [`CEC_CAP_REPLY_VENDOR_ID`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-reply-vendor-id): `include/uapi/linux/cec.h`, line 348
- [`CEC_CAP_TRANSMIT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit): `include/uapi/linux/cec.h`, line 332
- [`CEC_CONNECTOR_TYPE_DRM`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-connector-type-drm): `include/uapi/linux/cec.h`, line 419
- [`CEC_CONNECTOR_TYPE_NO_CONNECTOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-connector-type-no-connector): `include/uapi/linux/cec.h`, line 418
- [`CEC_EVENT_FL_DROPPED_EVENTS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-fl-dropped-events): `include/uapi/linux/cec.h`, line 453
- [`CEC_EVENT_FL_INITIAL_STATE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-fl-initial-state): `include/uapi/linux/cec.h`, line 452
- [`CEC_EVENT_LOST_MSGS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-lost-msgs): `include/uapi/linux/cec.h`, line 444
- [`CEC_EVENT_PIN_5V_HIGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-5v-high): `include/uapi/linux/cec.h`, line 450
- [`CEC_EVENT_PIN_5V_LOW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-5v-low): `include/uapi/linux/cec.h`, line 449
- [`CEC_EVENT_PIN_CEC_HIGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-cec-high): `include/uapi/linux/cec.h`, line 446
- [`CEC_EVENT_PIN_CEC_LOW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-cec-low): `include/uapi/linux/cec.h`, line 445
- [`CEC_EVENT_PIN_HPD_HIGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-hpd-high): `include/uapi/linux/cec.h`, line 448
- [`CEC_EVENT_PIN_HPD_LOW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-hpd-low): `include/uapi/linux/cec.h`, line 447
- [`CEC_EVENT_STATE_CHANGE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-state-change): `include/uapi/linux/cec.h`, line 439
- [`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-rc-passthru): `include/uapi/linux/cec.h`, line 403
- [`CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-unreg-fallback): `include/uapi/linux/cec.h`, line 401
- [`CEC_LOG_ADDRS_FL_CDC_ONLY`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-cdc-only): `include/uapi/linux/cec.h`, line 405
- [`CEC_LOG_ADDR_TYPE_AUDIOSYSTEM`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-audiosystem): `include/uapi/linux/cec.h`, line 234
- [`CEC_LOG_ADDR_TYPE_PLAYBACK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-playback): `include/uapi/linux/cec.h`, line 233
- [`CEC_LOG_ADDR_TYPE_RECORD`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-record): `include/uapi/linux/cec.h`, line 231
- [`CEC_LOG_ADDR_TYPE_SPECIFIC`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-specific): `include/uapi/linux/cec.h`, line 235
- [`CEC_LOG_ADDR_TYPE_TUNER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-tuner): `include/uapi/linux/cec.h`, line 232
- [`CEC_LOG_ADDR_TYPE_TV`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-tv): `include/uapi/linux/cec.h`, line 230
- [`CEC_LOG_ADDR_TYPE_UNREGISTERED`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-unregistered): `include/uapi/linux/cec.h`, line 236
- [`CEC_MODE_EXCL_FOLLOWER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-excl-follower): `include/uapi/linux/cec.h`, line 320
- [`CEC_MODE_EXCL_FOLLOWER_PASSTHRU`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-excl-follower-passthru): `include/uapi/linux/cec.h`, line 321
- [`CEC_MODE_EXCL_INITIATOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-excl-initiator): `include/uapi/linux/cec.h`, line 314
- [`CEC_MODE_FOLLOWER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-follower): `include/uapi/linux/cec.h`, line 319
- [`CEC_MODE_INITIATOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-initiator): `include/uapi/linux/cec.h`, line 313
- [`CEC_MODE_MONITOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-monitor): `include/uapi/linux/cec.h`, line 323
- [`CEC_MODE_MONITOR_ALL`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-monitor-all): `include/uapi/linux/cec.h`, line 324
- [`CEC_MODE_MONITOR_PIN`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-monitor-pin): `include/uapi/linux/cec.h`, line 322
- [`CEC_MODE_NO_FOLLOWER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-no-follower): `include/uapi/linux/cec.h`, line 318
- [`CEC_MODE_NO_INITIATOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-no-initiator): `include/uapi/linux/cec.h`, line 312
- [`CEC_MSG_FL_RAW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-fl-raw): `include/uapi/linux/cec.h`, line 171
- [`CEC_MSG_FL_REPLY_TO_FOLLOWERS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-fl-reply-to-followers): `include/uapi/linux/cec.h`, line 170
- [`CEC_MSG_FL_REPLY_VENDOR_ID`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-fl-reply-vendor-id): `include/uapi/linux/cec.h`, line 172
- [`CEC_RX_STATUS_ABORTED`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-aborted): `include/uapi/linux/cec.h`, line 187
- [`CEC_RX_STATUS_FEATURE_ABORT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-feature-abort): `include/uapi/linux/cec.h`, line 186
- [`CEC_RX_STATUS_OK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-ok): `include/uapi/linux/cec.h`, line 184
- [`CEC_RX_STATUS_TIMEOUT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-timeout): `include/uapi/linux/cec.h`, line 185
- [`CEC_TX_STATUS_ABORTED`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-aborted): `include/uapi/linux/cec.h`, line 181
- [`CEC_TX_STATUS_ARB_LOST`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-arb-lost): `include/uapi/linux/cec.h`, line 176
- [`CEC_TX_STATUS_ERROR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-error): `include/uapi/linux/cec.h`, line 179
- [`CEC_TX_STATUS_LOW_DRIVE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-low-drive): `include/uapi/linux/cec.h`, line 178
- [`CEC_TX_STATUS_MAX_RETRIES`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-max-retries): `include/uapi/linux/cec.h`, line 180
- [`CEC_TX_STATUS_NACK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-nack): `include/uapi/linux/cec.h`, line 177
- [`CEC_TX_STATUS_OK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-ok): `include/uapi/linux/cec.h`, line 175
- [`CEC_TX_STATUS_TIMEOUT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-timeout): `include/uapi/linux/cec.h`, line 182

## Structures

- [`cec_caps`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#c-cec_caps): `include/uapi/linux/cec.h`, line 358
- [`cec_connector_info`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#c-cec_connector_info): `include/uapi/linux/cec.h`, line 428
- [`cec_drm_connector_info`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#c-cec_drm_connector_info): `include/uapi/linux/cec.h`, line 413
- [`cec_event`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#c-cec_event): `include/uapi/linux/cec.h`, line 489
- [`cec_event_lost_msgs`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#c-cec_event_lost_msgs): `include/uapi/linux/cec.h`, line 476
- [`cec_event_state_change`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#c-cec_event_state_change): `include/uapi/linux/cec.h`, line 466
- [`cec_log_addrs`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#c-cec_log_addrs): `include/uapi/linux/cec.h`, line 384
- [`cec_msg`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#c-cec_msg): `include/uapi/linux/cec.h`, line 57

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> HDMI connectors provide a single pin for use by the Consumer Electronics Control protocol. This protocol allows different devices connected by an HDMI cable to communicate. The protocol for CEC version 1.4 is defined in supplements 1 (CEC)…

<a id="rst-introduction"></a>
<a id="rst-cec-intro"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

HDMI connectors provide a single pin for use by the Consumer Electronics Control protocol. This protocol allows different devices connected by an HDMI cable to communicate. The protocol for CEC version 1.4 is defined in supplements 1 (CEC) and 2 (HEAC or HDMI Ethernet and Audio Return Channel) of the HDMI 1.4a ([HDMI](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hdmi-1>)) specification and the extensions added to CEC version 2.0 are defined in chapter 11 of the HDMI 2.0 ([HDMI2](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hdmi2-1>)) specification.

The bitrate is very slow (effectively no more than 36 bytes per second) and is based on the ancient AV.link protocol used in old SCART connectors. The protocol closely resembles a crazy Rube Goldberg contraption and is an unholy mix of low and high level messages. Some messages, especially those part of the HEAC protocol layered on top of CEC, need to be handled by the kernel, others can be handled either by the kernel or by userspace.

In addition, CEC can be implemented in HDMI receivers, transmitters and in USB devices that have an HDMI input and an HDMI output and that control just the CEC pin.

Drivers that support CEC will create a CEC device node (/dev/cecX) to give userspace access to the CEC adapter. The [ioctl CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps>) ioctl will tell userspace what it is allowed to do.

In order to check the support and test it, it is suggested to download the [v4l-utils](<https://git.linuxtv.org/v4l-utils.git/>)<a id="rst-v4l-utils"></a> package. It provides three tools to handle CEC:

- cec-ctl: the Swiss army knife of CEC. Allows you to configure, transmit and monitor CEC messages.

- cec-compliance: does a CEC compliance test of a remote CEC device to determine how compliant the CEC implementation is.

- cec-follower: emulates a CEC follower.

---

# ioctl CEC_ADAP_G_CAPS

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_CAPS - Query device capabilities

<a id="rst-ioctl-cec-adap-g-caps"></a>
<a id="rst-cec-adap-g-caps"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

CEC_ADAP_G_CAPS - Query device capabilities

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-CEC_ADAP_G_CAPS"></a>

```c
CEC_ADAP_G_CAPS
```

`int ioctl(int fd, CEC_ADAP_G_CAPS, struct cec_caps *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

`argp`

<a id="rst-description"></a>

## Description

All cec devices must support [ioctl CEC_ADAP_G_CAPS](<#rst-cec-adap-g-caps>). To query device information, applications call the ioctl with a pointer to a struct `cec_caps`. The driver fills the structure and returns the information to the application. The ioctl never fails.

<!-- tabularcolumns: |p{1.2cm}|p{2.5cm}|p{13.6cm}| -->





<a id="c-cec_caps"></a>

```c
cec_caps
```


<table>
<caption>struct cec_caps</caption>
<tbody>
<tr>
<td>


char

</td>
<td>


`driver[32]`

</td>
<td>


The name of the cec adapter driver.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`name[32]`

</td>
<td>


The name of this CEC adapter. The combination `driver` and `name` must be unique.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`available_log_addrs`

</td>
<td>


The maximum number of logical addresses that can be configured.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


The capabilities of the CEC adapter, see [cec-capabilities](<#rst-cec-capabilities>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`version`

</td>
<td>


CEC Framework API version, formatted with the `KERNEL_VERSION()` macro.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{2.5cm}|p{10.4cm}| -->

<a id="rst-cec-capabilities"></a>


<table>
<caption>CEC Capabilities Flags</caption>
<tbody>
<tr>
<td>


`CEC_CAP_PHYS_ADDR`

</td>
<td>


0x00000001

</td>
<td>


<a id="rst-cec-cap-phys-addr"></a>

Userspace has to configure the physical address by calling [ioctl CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr>). If this capability isn't set, then setting the physical address is handled by the kernel whenever the EDID is set (for an HDMI receiver) or read (for an HDMI transmitter).

</td>
</tr>
<tr>
<td>


`CEC_CAP_LOG_ADDRS`

</td>
<td>


0x00000002

</td>
<td>


<a id="rst-cec-cap-log-addrs"></a>

Userspace has to configure the logical addresses by calling [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>). If this capability isn't set, then the kernel will have configured this.

</td>
</tr>
<tr>
<td>


`CEC_CAP_TRANSMIT`

</td>
<td>


0x00000004

</td>
<td>


<a id="rst-cec-cap-transmit"></a>

Userspace can transmit CEC messages by calling [ioctl CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>). This implies that userspace can be a follower as well, since being able to transmit messages is a prerequisite of becoming a follower. If this capability isn't set, then the kernel will handle all CEC transmits and process all CEC messages it receives.

</td>
</tr>
<tr>
<td>


`CEC_CAP_PASSTHROUGH`

</td>
<td>


0x00000008

</td>
<td>


<a id="rst-cec-cap-passthrough"></a>

Userspace can use the passthrough mode by calling [ioctl CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode>).

</td>
</tr>
<tr>
<td>


`CEC_CAP_RC`

</td>
<td>


0x00000010

</td>
<td>


<a id="rst-cec-cap-rc"></a>

This adapter supports the remote control protocol.

</td>
</tr>
<tr>
<td>


`CEC_CAP_MONITOR_ALL`

</td>
<td>


0x00000020

</td>
<td>


<a id="rst-cec-cap-monitor-all"></a>

The CEC hardware can monitor all messages, not just directed and broadcast messages.

</td>
</tr>
<tr>
<td>


`CEC_CAP_NEEDS_HPD`

</td>
<td>


0x00000040

</td>
<td>


<a id="rst-cec-cap-needs-hpd"></a>

The CEC hardware is only active if the HDMI Hotplug Detect pin is high. This makes it impossible to use CEC to wake up displays that set the HPD pin low when in standby mode, but keep the CEC bus alive.

</td>
</tr>
<tr>
<td>


`CEC_CAP_MONITOR_PIN`

</td>
<td>


0x00000080

</td>
<td>


<a id="rst-cec-cap-monitor-pin"></a>

The CEC hardware can monitor CEC pin changes from low to high voltage and vice versa. When in pin monitoring mode the application will receive `CEC_EVENT_PIN_CEC_LOW` and `CEC_EVENT_PIN_CEC_HIGH` events.

</td>
</tr>
<tr>
<td>


`CEC_CAP_CONNECTOR_INFO`

</td>
<td>


0x00000100

</td>
<td>


<a id="rst-cec-cap-connector-info"></a>

If this capability is set, then [ioctl CEC_ADAP_G_CONNECTOR_INFO](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-adap-g-connector-info>) can be used.

</td>
</tr>
<tr>
<td>


`CEC_CAP_REPLY_VENDOR_ID`

</td>
<td>


0x00000200

</td>
<td>


<a id="rst-cec-cap-reply-vendor-id"></a>

If this capability is set, then [CEC_MSG_FL_REPLY_VENDOR_ID](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-flags>) can be used.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl CEC_ADAP_G_CONNECTOR_INFO

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_CONNECTOR_INFO - Query HDMI connector information

<a id="rst-ioctl-cec-adap-g-connector-info"></a>
<a id="rst-cec-adap-g-connector-info"></a>

<!-- SPDX-License-Identifier: GPL-2.0 -->

<!--  -->

<!-- Copyright 2019 Google LLC -->

<!--  -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

CEC_ADAP_G_CONNECTOR_INFO - Query HDMI connector information

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-CEC_ADAP_G_CONNECTOR_INFO"></a>

```c
CEC_ADAP_G_CONNECTOR_INFO
```

`int ioctl(int fd, CEC_ADAP_G_CONNECTOR_INFO, struct cec_connector_info *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

`argp`

<a id="rst-description"></a>

## Description

Using this ioctl an application can learn which HDMI connector this CEC device corresponds to. While calling this ioctl the application should provide a pointer to a cec_connector_info struct which will be populated by the kernel with the info provided by the adapter's driver. This ioctl is only available if the `CEC_CAP_CONNECTOR_INFO` capability is set.

<!-- tabularcolumns: |p{1.0cm}|p{4.4cm}|p{2.5cm}|p{9.2cm}| -->





<a id="c-cec_connector_info"></a>

```c
cec_connector_info
```


<table>
<caption>struct cec_connector_info</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


The type of connector this adapter is associated with.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


`(anonymous)`

</td>
</tr>
<tr>
<td>


`struct cec_drm_connector_info`

</td>
<td>


drm

</td>
<td>


[cec-drm-connector-info](<#rst-cec-drm-connector-info>)

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{2.5cm}|p{10.4cm}| -->

<a id="rst-connector-type"></a>


<table>
<caption>Connector types</caption>
<tbody>
<tr>
<td>


`CEC_CONNECTOR_TYPE_NO_CONNECTOR`

</td>
<td>


0

</td>
<td>


<a id="rst-cec-connector-type-no-connector"></a>

No connector is associated with the adapter/the information is not provided by the driver.

</td>
</tr>
<tr>
<td>


`CEC_CONNECTOR_TYPE_DRM`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-connector-type-drm"></a>

Indicates that a DRM connector is associated with this adapter. Information about the connector can be found in [cec-drm-connector-info](<#rst-cec-drm-connector-info>).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{2.5cm}|p{10.4cm}| -->





<a id="c-cec_drm_connector_info"></a>

```c
cec_drm_connector_info
```

<a id="rst-cec-drm-connector-info"></a>


<table>
<caption>struct cec_drm_connector_info</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`card_no`

</td>
<td>


<a id="rst-cec-drm-connector-type-card-no"></a>

DRM card number: the number from a card's path, e.g. 0 in case of /dev/card0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`connector_id`

</td>
<td>


<a id="rst-cec-drm-connector-type-connector-id"></a>

DRM connector ID.

</td>
</tr>
</tbody>
</table>

---

# ioctls CEC_ADAP_G_LOG_ADDRS and CEC_ADAP_S_LOG_ADDRS

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_LOG_ADDRS, CEC_ADAP_S_LOG_ADDRS - Get or set the logical addresses

<a id="rst-ioctls-cec-adap-g-log-addrs-and-cec-adap-s-log-addrs"></a>
<a id="rst-cec-adap-s-log-addrs"></a>
<a id="rst-cec-adap-g-log-addrs"></a>
<a id="rst-cec-adap-log-addrs"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

CEC_ADAP_G_LOG_ADDRS, CEC_ADAP_S_LOG_ADDRS - Get or set the logical addresses

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-CEC_ADAP_G_LOG_ADDRS"></a>

```c
CEC_ADAP_G_LOG_ADDRS
```

`int ioctl(int fd, CEC_ADAP_G_LOG_ADDRS, struct cec_log_addrs *argp)`





<a id="c-CEC_ADAP_S_LOG_ADDRS"></a>

```c
CEC_ADAP_S_LOG_ADDRS
```

`int ioctl(int fd, CEC_ADAP_S_LOG_ADDRS, struct cec_log_addrs *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `cec_log_addrs`.

<a id="rst-description"></a>

## Description

To query the current CEC logical addresses, applications call [ioctl CEC_ADAP_G_LOG_ADDRS](<#rst-cec-adap-g-log-addrs>) with a pointer to a struct `cec_log_addrs` where the driver stores the logical addresses.

To set new logical addresses, applications fill in struct `cec_log_addrs` and call [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) with a pointer to this struct. The [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) is only available if `CEC_CAP_LOG_ADDRS` is set (the `ENOTTY` error code is returned otherwise). The [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) can only be called by a file descriptor in initiator mode (see [ioctls CEC_G_MODE and CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode>)), if not the `EBUSY` error code will be returned.

To clear existing logical addresses set `num_log_addrs` to 0. All other fields will be ignored in that case. The adapter will go to the unconfigured state and the `cec_version`, `vendor_id` and `osd_name` fields are all reset to their default values (CEC version 2.0, no vendor ID and an empty OSD name).

If the physical address is valid (see [ioctl CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr>)), then this ioctl will block until all requested logical addresses have been claimed. If the file descriptor is in non-blocking mode then it will not wait for the logical addresses to be claimed, instead it just returns 0.

A [CEC_EVENT_STATE_CHANGE](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-state-change>) event is sent when the logical addresses are claimed or cleared.

Attempting to call [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) when logical address types are already defined will return with error `EBUSY`.





<a id="c-cec_log_addrs"></a>

```c
cec_log_addrs
```

<!-- tabularcolumns: |p{1.0cm}|p{8.0cm}|p{8.0cm}| -->


<table>
<caption>struct cec_log_addrs</caption>
<tbody>
<tr>
<td>


\__u8

</td>
<td>


`log_addr[CEC_MAX_LOG_ADDRS]`

</td>
<td>


The actual logical addresses that were claimed. This is set by the driver. If no logical address could be claimed, then it is set to `CEC_LOG_ADDR_INVALID`. If this adapter is Unregistered, then `log_addr[0]` is set to 0xf and all others to `CEC_LOG_ADDR_INVALID`.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`log_addr_mask`

</td>
<td>


The bitmask of all logical addresses this adapter has claimed. If this adapter is Unregistered then `log_addr_mask` sets bit 15 and clears all other bits. If this adapter is not configured at all, then `log_addr_mask` is set to 0. Set by the driver.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`cec_version`

</td>
<td>


The CEC version that this adapter shall use. See [cec-versions](<#rst-cec-versions>). Used to implement the `CEC_MSG_CEC_VERSION` and `CEC_MSG_REPORT_FEATURES` messages. Note that [CEC_OP_CEC_VERSION_1_3A](<#rst-cec-op-cec-version-1-3a>) is not allowed by the CEC framework.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`num_log_addrs`

</td>
<td>


Number of logical addresses to set up. Must be ≤ `available_log_addrs` as returned by [ioctl CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps>). All arrays in this structure are only filled up to index `available_log_addrs`-1. The remaining array elements will be ignored. Note that the CEC 2.0 standard allows for a maximum of 2 logical addresses, although some hardware has support for more. `CEC_MAX_LOG_ADDRS` is 4. The driver will return the actual number of logical addresses it could claim, which may be less than what was requested. If this field is set to 0, then the CEC adapter shall clear all claimed logical addresses and all other fields will be ignored.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`vendor_id`

</td>
<td>


The vendor ID is a 24-bit number that identifies the specific vendor or entity. Based on this ID vendor specific commands may be defined. If you do not want a vendor ID then set it to `CEC_VENDOR_ID_NONE`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags. See [cec-log-addrs-flags](<#rst-cec-log-addrs-flags>) for a list of available flags.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`osd_name[15]`

</td>
<td>


The On-Screen Display name as is returned by the `CEC_MSG_SET_OSD_NAME` message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`primary_device_type[CEC_MAX_LOG_ADDRS]`

</td>
<td>


Primary device type for each logical address. See [cec-prim-dev-types](<#rst-cec-prim-dev-types>) for possible types.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`log_addr_type[CEC_MAX_LOG_ADDRS]`

</td>
<td>


Logical address types. See [cec-log-addr-types](<#rst-cec-log-addr-types>) for possible types. The driver will update this with the actual logical address type that it claimed (e.g. it may have to fallback to [CEC_LOG_ADDR_TYPE_UNREGISTERED](<#rst-cec-log-addr-type-unregistered>)).

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`all_device_types[CEC_MAX_LOG_ADDRS]`

</td>
<td>


CEC 2.0 specific: the bit mask of all device types. See [cec-all-dev-types-flags](<#rst-cec-all-dev-types-flags>). It is used in the CEC 2.0 `CEC_MSG_REPORT_FEATURES` message. For CEC 1.4 you can either leave this field to 0, or fill it in according to the CEC 2.0 guidelines to give the CEC framework more information about the device type, even though the framework won't use it directly in the CEC message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`features[CEC_MAX_LOG_ADDRS][12]`

</td>
<td>


Features for each logical address. It is used in the CEC 2.0 `CEC_MSG_REPORT_FEATURES` message. The 12 bytes include both the RC Profile and the Device Features. For CEC 1.4 you can either leave this field to all 0, or fill it in according to the CEC 2.0 guidelines to give the CEC framework more information about the device type, even though the framework won't use it directly in the CEC message.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.8cm}|p{1.0cm}|p{8.5cm}| -->

<a id="rst-cec-log-addrs-flags"></a>


<table>
<caption>Flags for struct cec_log_addrs</caption>
<tbody>
<tr>
<td>


`CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-log-addrs-fl-allow-unreg-fallback"></a>

By default if no logical address of the requested type can be claimed, then it will go back to the unconfigured state. If this flag is set, then it will fallback to the Unregistered logical address. Note that if the Unregistered logical address was explicitly requested, then this flag has no effect.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-log-addrs-fl-allow-rc-passthru"></a>

By default the `CEC_MSG_USER_CONTROL_PRESSED` and `CEC_MSG_USER_CONTROL_RELEASED` messages are only passed on to the follower(s), if any. If this flag is set, then these messages are also passed on to the remote control input subsystem and will appear as keystrokes. This features needs to be enabled explicitly. If CEC is used to enter e.g. passwords, then you may not want to enable this to avoid trivial snooping of the keystrokes.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDRS_FL_CDC_ONLY`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-log-addrs-fl-cdc-only"></a>

If this flag is set, then the device is CDC-Only. CDC-Only CEC devices are CEC devices that can only handle CDC messages.

All other messages are ignored.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.8cm}|p{1.0cm}|p{8.5cm}| -->

<a id="rst-cec-versions"></a>


<table>
<caption>CEC Versions</caption>
<tbody>
<tr>
<td>


`CEC_OP_CEC_VERSION_1_3A`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-op-cec-version-1-3a"></a>

CEC version according to the HDMI 1.3a standard.

</td>
</tr>
<tr>
<td>


`CEC_OP_CEC_VERSION_1_4B`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-op-cec-version-1-4b"></a>

CEC version according to the HDMI 1.4b standard.

</td>
</tr>
<tr>
<td>


`CEC_OP_CEC_VERSION_2_0`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-op-cec-version-2-0"></a>

CEC version according to the HDMI 2.0 standard.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-cec-prim-dev-types"></a>


<table>
<caption>CEC Primary Device Types</caption>
<tbody>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_TV`

</td>
<td>


0

</td>
<td>


<a id="rst-cec-op-prim-devtype-tv"></a>

Use for a TV.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_RECORD`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-op-prim-devtype-record"></a>

Use for a recording device.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_TUNER`

</td>
<td>


3

</td>
<td>


<a id="rst-cec-op-prim-devtype-tuner"></a>

Use for a device with a tuner.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_PLAYBACK`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-op-prim-devtype-playback"></a>

Use for a playback device.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-op-prim-devtype-audiosystem"></a>

Use for an audio system (e.g. an audio/video receiver).

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_SWITCH`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-op-prim-devtype-switch"></a>

Use for a CEC switch.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_VIDEOPROC`

</td>
<td>


7

</td>
<td>


<a id="rst-cec-op-prim-devtype-videoproc"></a>

Use for a video processor device.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-cec-log-addr-types"></a>


<table>
<caption>CEC Logical Address Types</caption>
<tbody>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_TV`

</td>
<td>


0

</td>
<td>


<a id="rst-cec-log-addr-type-tv"></a>

Use for a TV.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_RECORD`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-log-addr-type-record"></a>

Use for a recording device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_TUNER`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-log-addr-type-tuner"></a>

Use for a tuner device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_PLAYBACK`

</td>
<td>


3

</td>
<td>


<a id="rst-cec-log-addr-type-playback"></a>

Use for a playback device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_AUDIOSYSTEM`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-log-addr-type-audiosystem"></a>

Use for an audio system device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_SPECIFIC`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-log-addr-type-specific"></a>

Use for a second TV or for a video processor device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_UNREGISTERED`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-log-addr-type-unregistered"></a>

Use this if you just want to remain unregistered. Used for pure CEC switches or CDC-only devices (CDC: Capability Discovery and Control).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-cec-all-dev-types-flags"></a>


<table>
<caption>CEC All Device Types Flags</caption>
<tbody>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_TV`

</td>
<td>


0x80

</td>
<td>


<a id="rst-cec-op-all-devtype-tv"></a>

This supports the TV type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_RECORD`

</td>
<td>


0x40

</td>
<td>


<a id="rst-cec-op-all-devtype-record"></a>

This supports the Recording type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_TUNER`

</td>
<td>


0x20

</td>
<td>


<a id="rst-cec-op-all-devtype-tuner"></a>

This supports the Tuner type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_PLAYBACK`

</td>
<td>


0x10

</td>
<td>


<a id="rst-cec-op-all-devtype-playback"></a>

This supports the Playback type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM`

</td>
<td>


0x08

</td>
<td>


<a id="rst-cec-op-all-devtype-audiosystem"></a>

This supports the Audio System type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_SWITCH`

</td>
<td>


0x04

</td>
<td>


<a id="rst-cec-op-all-devtype-switch"></a>

This supports the CEC Switch or Video Processing type.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) can return the following error codes:

- **ENOTTY**

  The `CEC_CAP_LOG_ADDRS` capability wasn't set, so this ioctl is not supported.

- **EBUSY**

  The CEC adapter is currently configuring itself, or it is already configured and `num_log_addrs` is non-zero, or another filehandle is in exclusive follower or initiator mode, or the filehandle is in mode `CEC_MODE_NO_INITIATOR`.

- **EINVAL**

  The contents of struct `cec_log_addrs` is invalid.

---

# ioctls CEC_ADAP_G_PHYS_ADDR and CEC_ADAP_S_PHYS_ADDR

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_PHYS_ADDR, CEC_ADAP_S_PHYS_ADDR - Get or set the physical address

<a id="rst-ioctls-cec-adap-g-phys-addr-and-cec-adap-s-phys-addr"></a>
<a id="rst-cec-adap-s-phys-addr"></a>
<a id="rst-cec-adap-g-phys-addr"></a>
<a id="rst-cec-adap-phys-addr"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

CEC_ADAP_G_PHYS_ADDR, CEC_ADAP_S_PHYS_ADDR - Get or set the physical address

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-CEC_ADAP_G_PHYS_ADDR"></a>

```c
CEC_ADAP_G_PHYS_ADDR
```

`int ioctl(int fd, CEC_ADAP_G_PHYS_ADDR, __u16 *argp)`





<a id="c-CEC_ADAP_S_PHYS_ADDR"></a>

```c
CEC_ADAP_S_PHYS_ADDR
```

`int ioctl(int fd, CEC_ADAP_S_PHYS_ADDR, __u16 *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to the CEC address.

<a id="rst-description"></a>

## Description

To query the current physical address applications call [ioctl CEC_ADAP_G_PHYS_ADDR](<#rst-cec-adap-g-phys-addr>) with a pointer to a \__u16 where the driver stores the physical address.

To set a new physical address applications store the physical address in a \__u16 and call [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) with a pointer to this integer. The [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) is only available if `CEC_CAP_PHYS_ADDR` is set (the `ENOTTY` error code will be returned otherwise). The [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) can only be called by a file descriptor in initiator mode (see [ioctls CEC_G_MODE and CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode>)), if not the `EBUSY` error code will be returned.

To clear an existing physical address use `CEC_PHYS_ADDR_INVALID`. The adapter will go to the unconfigured state.

If logical address types have been defined (see [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>)), then this ioctl will block until all requested logical addresses have been claimed. If the file descriptor is in non-blocking mode then it will not wait for the logical addresses to be claimed, instead it just returns 0.

A [CEC_EVENT_STATE_CHANGE](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-state-change>) event is sent when the physical address changes.

The physical address is a 16-bit number where each group of 4 bits represent a digit of the physical address a.b.c.d where the most significant 4 bits represent 'a'. The CEC root device (usually the TV) has address 0.0.0.0. Every device that is hooked up to an input of the TV has address a.0.0.0 (where 'a' is ≥ 1), devices hooked up to those in turn have addresses a.b.0.0, etc. So a topology of up to 5 devices deep is supported. The physical address a device shall use is stored in the EDID of the sink.

For example, the EDID for each HDMI input of the TV will have a different physical address of the form a.0.0.0 that the sources will read out and use as their physical address.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) can return the following error codes:

- **ENOTTY**

  The `CEC_CAP_PHYS_ADDR` capability wasn't set, so this ioctl is not supported.

- **EBUSY**

  Another filehandle is in exclusive follower or initiator mode, or the filehandle is in mode `CEC_MODE_NO_INITIATOR`.

- **EINVAL**

  The physical address is malformed.

---

# ioctl CEC_DQEVENT

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_DQEVENT - Dequeue a CEC event

<a id="rst-ioctl-cec-dqevent"></a>
<a id="rst-cec-dqevent"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

CEC_DQEVENT - Dequeue a CEC event

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-CEC_DQEVENT"></a>

```c
CEC_DQEVENT
```

`int ioctl(int fd, CEC_DQEVENT, struct cec_event *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

`argp`

<a id="rst-description"></a>

## Description

CEC devices can send asynchronous events. These can be retrieved by calling `CEC_DQEVENT()`. If the file descriptor is in non-blocking mode and no event is pending, then it will return -1 and set errno to the `EAGAIN` error code.

The internal event queues are per-filehandle and per-event type. If there is no more room in a queue then the last event is overwritten with the new one. This means that intermediate results can be thrown away but that the latest event is always available. This also means that is it possible to read two successive events that have the same value (e.g. two [CEC_EVENT_STATE_CHANGE](<#rst-cec-event-state-change>) events with the same state). In that case the intermediate state changes were lost but it is guaranteed that the state did change in between the two events.

<!-- tabularcolumns: |p{1.2cm}|p{2.9cm}|p{13.2cm}| -->





<a id="c-cec_event_state_change"></a>

```c
cec_event_state_change
```


<table>
<caption>struct cec_event_state_change</caption>
<tbody>
<tr>
<td>


\__u16

</td>
<td>


`phys_addr`

</td>
<td>


The current physical address. This is `CEC_PHYS_ADDR_INVALID` if no valid physical address is set.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`log_addr_mask`

</td>
<td>


The current set of claimed logical addresses. This is 0 if no logical addresses are claimed or if `phys_addr` is `CEC_PHYS_ADDR_INVALID`. If bit 15 is set (`1 << CEC_LOG_ADDR_UNREGISTERED`) then this device has the unregistered logical address. In that case all other bits are 0.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`have_conn_info`

</td>
<td>


If non-zero, then HDMI connector information is available. This field is only valid if `CEC_CAP_CONNECTOR_INFO` is set. If that capability is set and `have_conn_info` is zero, then that indicates that the HDMI connector device is not instantiated, either because the HDMI driver is still configuring the device or because the HDMI device was unbound.

</td>
</tr>
</tbody>
</table>





<a id="c-cec_event_lost_msgs"></a>

```c
cec_event_lost_msgs
```

<!-- tabularcolumns: |p{1.0cm}|p{2.0cm}|p{14.3cm}| -->


<table>
<caption>struct cec_event_lost_msgs</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`lost_msgs`

</td>
<td>


Set to the number of lost messages since the filehandle was opened or since the last time this event was dequeued for this filehandle. The messages lost are the oldest messages. So when a new message arrives and there is no more room, then the oldest message is discarded to make room for the new one. The internal size of the message queue guarantees that all messages received in the last two seconds will be stored. Since messages should be replied to within a second according to the CEC specification, this is more than enough.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.0cm}|p{4.4cm}|p{2.5cm}|p{9.2cm}| -->





<a id="c-cec_event"></a>

```c
cec_event
```


<table>
<caption>struct cec_event</caption>
<tbody>
<tr>
<td>


\__u64

</td>
<td>


`ts`

</td>
<td>


Timestamp of the event in ns.

The timestamp has been taken from the `CLOCK_MONOTONIC` clock.

To access the same clock from userspace use `clock_gettime()`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`event`

</td>
<td>


The CEC event type, see [cec-events](<#rst-cec-events>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Event flags, see [cec-event-flags](<#rst-cec-event-flags>).

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


struct cec_event_state_change

</td>
<td>


`state_change`

</td>
<td>


The new adapter state as sent by the [CEC_EVENT_STATE_CHANGE](<#rst-cec-event-state-change>) event.

</td>
</tr>
<tr>
<td>


struct cec_event_lost_msgs

</td>
<td>


`lost_msgs`

</td>
<td>


The number of lost messages as sent by the [CEC_EVENT_LOST_MSGS](<#rst-cec-event-lost-msgs>) event.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-events"></a>


<table>
<caption>CEC Events Types</caption>
<tbody>
<tr>
<td>


`CEC_EVENT_STATE_CHANGE`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-event-state-change"></a>

Generated when the CEC Adapter's state changes. When open() is called an initial event will be generated for that filehandle with the CEC Adapter's state at that time.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_LOST_MSGS`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-event-lost-msgs"></a>

Generated if one or more CEC messages were lost because the application didn't dequeue CEC messages fast enough.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_CEC_LOW`

</td>
<td>


3

</td>
<td>


<a id="rst-cec-event-pin-cec-low"></a>

Generated if the CEC pin goes from a high voltage to a low voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_CEC_HIGH`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-event-pin-cec-high"></a>

Generated if the CEC pin goes from a low voltage to a high voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_HPD_LOW`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-event-pin-hpd-low"></a>

Generated if the HPD pin goes from a high voltage to a low voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the HPD pin can be read and if the HPD is low, then an initial event will be generated for that filehandle.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_HPD_HIGH`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-event-pin-hpd-high"></a>

Generated if the HPD pin goes from a low voltage to a high voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the HPD pin can be read and if the HPD is high, then an initial event will be generated for that filehandle.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_5V_LOW`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-event-pin-5v-low"></a>

Generated if the 5V pin goes from a high voltage to a low voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the 5V pin can be read and if the 5V is low, then an initial event will be generated for that filehandle.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_5V_HIGH`

</td>
<td>


7

</td>
<td>


<a id="rst-cec-event-pin-5v-high"></a>

Generated if the 5V pin goes from a low voltage to a high voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the 5V pin can be read and if the 5V is high, then an initial event will be generated for that filehandle.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.0cm}|p{0.6cm}|p{10.7cm}| -->

<a id="rst-cec-event-flags"></a>


<table>
<caption>CEC Event Flags</caption>
<tbody>
<tr>
<td>


`CEC_EVENT_FL_INITIAL_STATE`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-event-fl-initial-state"></a>

Set for the initial events that are generated when the device is opened. See the table above for which events do this. This allows applications to learn the initial state of the CEC adapter at open() time.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_FL_DROPPED_EVENTS`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-event-fl-dropped-events"></a>

Set if one or more events of the given event type have been dropped. This is an indication that the application cannot keep up.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_DQEVENT](<#rst-cec-dqevent>) can return the following error codes:

- **EAGAIN**

  This is returned when the filehandle is in non-blocking mode and there are no pending events.

- **ERESTARTSYS**

  An interrupt (e.g. Ctrl-C) arrived while in blocking mode waiting for events to arrive.

---

# ioctls CEC_G_MODE and CEC_S_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-ioctls-cec-g-mode-and-cec-s-mode"></a>
<a id="rst-cec-s-mode"></a>
<a id="rst-cec-g-mode"></a>
<a id="rst-cec-mode"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

CEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-CEC_G_MODE"></a>

```c
CEC_G_MODE
```

`int ioctl(int fd, CEC_G_MODE, __u32 *argp)`





<a id="c-CEC_S_MODE"></a>

```c
CEC_S_MODE
```

`int ioctl(int fd, CEC_S_MODE, __u32 *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to CEC mode.

<a id="rst-description"></a>

## Description

By default any filehandle can use [ioctls CEC_RECEIVE and CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>), but in order to prevent applications from stepping on each others toes it must be possible to obtain exclusive access to the CEC adapter. This ioctl sets the filehandle to initiator and/or follower mode which can be exclusive depending on the chosen mode. The initiator is the filehandle that is used to initiate messages, i.e. it commands other CEC devices. The follower is the filehandle that receives messages sent to the CEC adapter and processes them. The same filehandle can be both initiator and follower, or this role can be taken by two different filehandles.

When a CEC message is received, then the CEC framework will decide how it will be processed. If the message is a reply to an earlier transmitted message, then the reply is sent back to the filehandle that is waiting for it. In addition the CEC framework will process it.

If the message is not a reply, then the CEC framework will process it first. If there is no follower, then the message is just discarded and a feature abort is sent back to the initiator if the framework couldn't process it. If there is a follower, then the message is passed on to the follower who will use [ioctl CEC_RECEIVE](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-receive>) to dequeue the new message. The framework expects the follower to make the right decisions.

The CEC framework will process core messages unless requested otherwise by the follower. The follower can enable the passthrough mode. In that case, the CEC framework will pass on most core messages without processing them and the follower will have to implement those messages. There are some messages that the core will always process, regardless of the passthrough mode. See [cec-core-processing](<#rst-cec-core-processing>) for details.

If there is no initiator, then any CEC filehandle can use [ioctl CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>). If there is an exclusive initiator then only that initiator can call [ioctls CEC_RECEIVE and CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>). The follower can of course always call [ioctl CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>).

Available initiator modes are:

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-mode-initiator-e"></a>


<table>
<caption>Initiator Modes</caption>
<tbody>
<tr>
<td>


`CEC_MODE_NO_INITIATOR`

</td>
<td>


0x0

</td>
<td>


<a id="rst-cec-mode-no-initiator"></a>

This is not an initiator, i.e. it cannot transmit CEC messages or make any other changes to the CEC adapter.

</td>
</tr>
<tr>
<td>


`CEC_MODE_INITIATOR`

</td>
<td>


0x1

</td>
<td>


<a id="rst-cec-mode-initiator"></a>

This is an initiator (the default when the device is opened) and it can transmit CEC messages and make changes to the CEC adapter, unless there is an exclusive initiator.

</td>
</tr>
<tr>
<td>


`CEC_MODE_EXCL_INITIATOR`

</td>
<td>


0x2

</td>
<td>


<a id="rst-cec-mode-excl-initiator"></a>

This is an exclusive initiator and this file descriptor is the only one that can transmit CEC messages and make changes to the CEC adapter. If someone else is already the exclusive initiator then an attempt to become one will return the `EBUSY` error code error.

</td>
</tr>
</tbody>
</table>

Available follower modes are:

<!-- tabularcolumns: |p{6.6cm}|p{0.9cm}|p{9.8cm}| -->

<a id="rst-cec-mode-follower-e"></a>


<table>
<caption>Follower Modes</caption>
<tbody>
<tr>
<td>


`CEC_MODE_NO_FOLLOWER`

</td>
<td>


0x00

</td>
<td>


<a id="rst-cec-mode-no-follower"></a>

This is not a follower (the default when the device is opened).

</td>
</tr>
<tr>
<td>


`CEC_MODE_FOLLOWER`

</td>
<td>


0x10

</td>
<td>


<a id="rst-cec-mode-follower"></a>

This is a follower and it will receive CEC messages unless there is an exclusive follower. You cannot become a follower if [CEC_CAP_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit>) is not set or if [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>) was specified, the `EINVAL` error code is returned in that case.

</td>
</tr>
<tr>
<td>


`CEC_MODE_EXCL_FOLLOWER`

</td>
<td>


0x20

</td>
<td>


<a id="rst-cec-mode-excl-follower"></a>

This is an exclusive follower and only this file descriptor will receive CEC messages for processing. If someone else is already the exclusive follower then an attempt to become one will return the `EBUSY` error code. You cannot become a follower if [CEC_CAP_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit>) is not set or if [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>) was specified, the `EINVAL` error code is returned in that case.

</td>
</tr>
<tr>
<td>


`CEC_MODE_EXCL_FOLLOWER_PASSTHRU`

</td>
<td>


0x30

</td>
<td>


<a id="rst-cec-mode-excl-follower-passthru"></a>

This is an exclusive follower and only this file descriptor will receive CEC messages for processing. In addition it will put the CEC device into passthrough mode, allowing the exclusive follower to handle most core messages instead of relying on the CEC framework for that. If someone else is already the exclusive follower then an attempt to become one will return the `EBUSY` error code. You cannot become a follower if [CEC_CAP_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit>) is not set or if [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>) was specified, the `EINVAL` error code is returned in that case.

</td>
</tr>
<tr>
<td>


`CEC_MODE_MONITOR_PIN`

</td>
<td>


0xd0

</td>
<td>


<a id="rst-cec-mode-monitor-pin"></a>

Put the file descriptor into pin monitoring mode. Can only be used in combination with [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>), otherwise the `EINVAL` error code will be returned. This mode requires that the [CEC_CAP_MONITOR_PIN](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-pin>) capability is set, otherwise the `EINVAL` error code is returned. While in pin monitoring mode this file descriptor can receive the `CEC_EVENT_PIN_CEC_LOW` and `CEC_EVENT_PIN_CEC_HIGH` events to see the low-level CEC pin transitions. This is very useful for debugging. This mode is only allowed if the process has the `CAP_NET_ADMIN` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
<tr>
<td>


`CEC_MODE_MONITOR`

</td>
<td>


0xe0

</td>
<td>


<a id="rst-cec-mode-monitor"></a>

Put the file descriptor into monitor mode. Can only be used in combination with [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>), otherwise the `EINVAL` error code will be returned. In monitor mode all messages this CEC device transmits and all messages it receives (both broadcast messages and directed messages for one its logical addresses) will be reported. This is very useful for debugging. This is only allowed if the process has the `CAP_NET_ADMIN` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
<tr>
<td>


`CEC_MODE_MONITOR_ALL`

</td>
<td>


0xf0

</td>
<td>


<a id="rst-cec-mode-monitor-all"></a>

Put the file descriptor into 'monitor all' mode. Can only be used in combination with [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>), otherwise the `EINVAL` error code will be returned. In 'monitor all' mode all messages this CEC device transmits and all messages it receives, including directed messages for other CEC devices, will be reported. This is very useful for debugging, but not all devices support this. This mode requires that the [CEC_CAP_MONITOR_ALL](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-all>) capability is set, otherwise the `EINVAL` error code is returned. This is only allowed if the process has the `CAP_NET_ADMIN` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
</tbody>
</table>

Core message processing details:

<!-- tabularcolumns: |p{6.6cm}|p{10.9cm}| -->

<a id="rst-cec-core-processing"></a>


<table>
<caption>Core Message Processing</caption>
<tbody>
<tr>
<td>


`CEC_MSG_GET_CEC_VERSION`

</td>
<td>


<a id="rst-cec-msg-get-cec-version"></a>

The core will return the CEC version that was set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_DEVICE_VENDOR_ID`

</td>
<td>


<a id="rst-cec-msg-give-device-vendor-id"></a>

The core will return the vendor ID that was set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_ABORT`

</td>
<td>


<a id="rst-cec-msg-abort"></a>

The core will return a Feature Abort message with reason 'Feature Refused' as per the specification, except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_PHYSICAL_ADDR`

</td>
<td>


<a id="rst-cec-msg-give-physical-addr"></a>

The core will report the current physical address, except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_OSD_NAME`

</td>
<td>


<a id="rst-cec-msg-give-osd-name"></a>

The core will report the current OSD name that was set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_FEATURES`

</td>
<td>


<a id="rst-cec-msg-give-features"></a>

The core will do nothing if the CEC version is older than 2.0, otherwise it will report the current features that were set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing (for any CEC version) and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_USER_CONTROL_PRESSED`

</td>
<td>


<a id="rst-cec-msg-user-control-pressed"></a>

If [CEC_CAP_RC](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-rc>) is set and if [CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-rc-passthru>) is set, then generate a remote control key press. This message is always passed on to the follower(s).

</td>
</tr>
<tr>
<td>


`CEC_MSG_USER_CONTROL_RELEASED`

</td>
<td>


<a id="rst-cec-msg-user-control-released"></a>

If [CEC_CAP_RC](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-rc>) is set and if [CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-rc-passthru>) is set, then generate a remote control key release. This message is always passed on to the follower(s).

</td>
</tr>
<tr>
<td>


`CEC_MSG_REPORT_PHYSICAL_ADDR`

</td>
<td>


<a id="rst-cec-msg-report-physical-addr"></a>

The CEC framework will make note of the reported physical address and then just pass the message on to the follower(s).

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_S_MODE](<#rst-cec-s-mode>) can return the following error codes:

- **EINVAL**

  The requested mode is invalid.

- **EPERM**

  Monitor mode is requested, but the process does have the `CAP_NET_ADMIN` capability.

- **EBUSY**

  Someone else is already an exclusive follower or initiator.

---

# ioctls CEC_RECEIVE and CEC_TRANSMIT

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-ioctls-cec-receive-and-cec-transmit"></a>
<a id="rst-cec-receive"></a>
<a id="rst-cec-transmit"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

<a id="rst-name"></a>

## Name

CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-CEC_RECEIVE"></a>

```c
CEC_RECEIVE
```

`int ioctl(int fd, CEC_RECEIVE, struct cec_msg *argp)`





<a id="c-CEC_TRANSMIT"></a>

```c
CEC_TRANSMIT
```

`int ioctl(int fd, CEC_TRANSMIT, struct cec_msg *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct cec_msg.

<a id="rst-description"></a>

## Description

To receive a CEC message the application has to fill in the `timeout` field of struct `cec_msg` and pass it to [ioctl CEC_RECEIVE](<#rst-cec-receive>). If the file descriptor is in non-blocking mode and there are no received messages pending, then it will return -1 and set errno to the `EAGAIN` error code. If the file descriptor is in blocking mode and `timeout` is non-zero and no message arrived within `timeout` milliseconds, then it will return -1 and set errno to the `ETIMEDOUT` error code.

A received message can be:

1. a message received from another CEC device (the `sequence` field will be 0, `tx_status` will be 0 and `rx_status` will be non-zero).

2. the transmit result of an earlier non-blocking transmit (the `sequence` field will be non-zero, `tx_status` will be non-zero and `rx_status` will be 0).

3. the reply to an earlier non-blocking transmit (the `sequence` field will be non-zero, `tx_status` will be 0 and `rx_status` will be non-zero).

To send a CEC message the application has to fill in the struct `cec_msg` and pass it to [ioctl CEC_TRANSMIT](<#rst-cec-transmit>). The [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) is only available if `CEC_CAP_TRANSMIT` is set. If there is no more room in the transmit queue, then it will return -1 and set errno to the `EBUSY` error code. The transmit queue has enough room for 18 messages (about 1 second worth of 2-byte messages). Note that the CEC kernel framework will also reply to core messages (see [cec-core-processing](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-core-processing>)), so it is not a good idea to fully fill up the transmit queue.

If the file descriptor is in non-blocking mode then the transmit will return 0 and the result of the transmit will be available via [ioctl CEC_RECEIVE](<#rst-cec-receive>) once the transmit has finished. If a non-blocking transmit also specified waiting for a reply, then the reply will arrive in a later message. The `sequence` field can be used to associate both transmit results and replies with the original transmit.

Normally calling [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) when the physical address is invalid (due to e.g. a disconnect) will return `ENONET`.

However, the CEC specification allows sending messages from 'Unregistered' to 'TV' when the physical address is invalid since some TVs pull the hotplug detect pin of the HDMI connector low when they go into standby, or when switching to another input.

When the hotplug detect pin goes low the EDID disappears, and thus the physical address, but the cable is still connected and CEC still works. In order to detect/wake up the device it is allowed to send poll and 'Image/Text View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').

<!-- tabularcolumns: |p{1.0cm}|p{3.5cm}|p{12.8cm}| -->





<a id="c-cec_msg"></a>

```c
cec_msg
```


<table>
<caption>struct cec_msg</caption>
<tbody>
<tr>
<td>


\__u64

</td>
<td>


`tx_ts`

</td>
<td>


Timestamp in ns of when the last byte of the message was transmitted. The timestamp has been taken from the `CLOCK_MONOTONIC` clock. To access the same clock from userspace use `clock_gettime()`.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`rx_ts`

</td>
<td>


Timestamp in ns of when the last byte of the message was received. The timestamp has been taken from the `CLOCK_MONOTONIC` clock. To access the same clock from userspace use `clock_gettime()`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`len`

</td>
<td>


The length of the message. For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) this is filled in by the application. The driver will fill this in for [ioctl CEC_RECEIVE](<#rst-cec-receive>). For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) it will be filled in by the driver with the length of the reply message if `reply` was set.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`timeout`

</td>
<td>


The timeout in milliseconds. This is the time the device will wait for a message to be received before timing out. If it is set to 0, then it will wait indefinitely when it is called by [ioctl CEC_RECEIVE](<#rst-cec-receive>). If it is 0 and it is called by [ioctl CEC_TRANSMIT](<#rst-cec-transmit>), then it will be replaced by 1000 if the `reply` is non-zero or ignored if `reply` is 0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`sequence`

</td>
<td>


A non-zero sequence number is automatically assigned by the CEC framework for all transmitted messages. It is used by the CEC framework when it queues the transmit result for a non-blocking transmit. This allows the application to associate the received message with the original transmit.

In addition, if a non-blocking transmit will wait for a reply (ii.e. `timeout` was not 0), then the `sequence` field of the reply will be set to the sequence value of the original transmit. This allows the application to associate the received message with the original transmit.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags. See [cec-msg-flags](<#rst-cec-msg-flags>) for a list of available flags.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`msg[16]`

</td>
<td>


The message payload. For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) this is filled in by the application. The driver will fill this in for [ioctl CEC_RECEIVE](<#rst-cec-receive>). For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) it will be filled in by the driver with the payload of the reply message if `timeout` was set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`reply`

</td>
<td>


Wait until this message is replied. If `reply` is 0 and the `timeout` is 0, then don't wait for a reply but return after transmitting the message. Ignored by [ioctl CEC_RECEIVE](<#rst-cec-receive>). The case where `reply` is 0 (this is the opcode for the Feature Abort message) and `timeout` is non-zero is specifically allowed to make it possible to send a message and wait up to `timeout` milliseconds for a Feature Abort reply. In this case `rx_status` will either be set to [CEC_RX_STATUS_TIMEOUT](<#rst-cec-rx-status-timeout>) or [CEC_RX_STATUS_FEATURE_ABORT](<#rst-cec-rx-status-feature-abort>).

If the transmitter message is `CEC_MSG_INITIATE_ARC` then the `reply` values `CEC_MSG_REPORT_ARC_INITIATED` and `CEC_MSG_REPORT_ARC_TERMINATED` are processed differently: either value will match both possible replies. The reason is that the `CEC_MSG_INITIATE_ARC` message is the only CEC message that has two possible replies other than Feature Abort. The `reply` field will be updated with the actual reply so that it is synchronized with the contents of the received message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`rx_status`

</td>
<td>


The status bits of the received message. See [cec-rx-status](<#rst-cec-rx-status>) for the possible status values.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_status`

</td>
<td>


The status bits of the transmitted message. See [cec-tx-status](<#rst-cec-tx-status>) for the possible status values. When calling [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) in non-blocking mode, this field will be 0 if the transmit started, or non-0 if the transmit result is known immediately. The latter would be the case when attempting to transmit a Poll message to yourself. That results in a [CEC_TX_STATUS_NACK](<#rst-cec-tx-status-nack>) without ever actually transmitting the Poll message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_arb_lost_cnt`

</td>
<td>


A counter of the number of transmit attempts that resulted in the Arbitration Lost error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_ARB_LOST](<#rst-cec-tx-status-arb-lost>) status bit is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_nack_cnt`

</td>
<td>


A counter of the number of transmit attempts that resulted in the Not Acknowledged error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_NACK](<#rst-cec-tx-status-nack>) status bit is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_low_drive_cnt`

</td>
<td>


A counter of the number of transmit attempts that resulted in the Arbitration Lost error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_LOW_DRIVE](<#rst-cec-tx-status-low-drive>) status bit is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_error_cnt`

</td>
<td>


A counter of the number of transmit errors other than Arbitration Lost or Not Acknowledged. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_ERROR](<#rst-cec-tx-status-error>) status bit is set.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.2cm}|p{1.0cm}|p{10.1cm}| -->

<a id="rst-cec-msg-flags"></a>


<table>
<caption>Flags for struct cec_msg</caption>
<tbody>
<tr>
<td>


`CEC_MSG_FL_REPLY_TO_FOLLOWERS`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-msg-fl-reply-to-followers"></a>

If a CEC transmit expects a reply, then by default that reply is only sent to the filehandle that called [ioctl CEC_TRANSMIT](<#rst-cec-transmit>). If this flag is set, then the reply is also sent to all followers, if any. If the filehandle that called [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) is also a follower, then that filehandle will receive the reply twice: once as the result of the [ioctl CEC_TRANSMIT](<#rst-cec-transmit>), and once via [ioctl CEC_RECEIVE](<#rst-cec-receive>).

</td>
</tr>
<tr>
<td>


`CEC_MSG_FL_RAW`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-msg-fl-raw"></a>

Normally CEC messages are validated before transmitting them. If this flag is set when [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) is called, then no validation takes place and the message is transmitted as-is. This is useful when debugging CEC issues. This flag is only allowed if the process has the `CAP_SYS_RAWIO` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
<tr>
<td>


`CEC_MSG_FL_REPLY_VENDOR_ID`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-msg-fl-reply-vendor-id"></a>

This flag is only available if the `CEC_CAP_REPLY_VENDOR_ID` capability is set. If this flag is set, then the reply is expected to consist of the `CEC_MSG_VENDOR_COMMAND_WITH_ID` opcode followed by the Vendor ID (in bytes 1-4 of the message), followed by the `struct cec_msg` `reply` field.

Note that this assumes that the byte after the Vendor ID is a vendor-specific opcode.

This flag makes it easier to wait for replies to vendor commands.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-tx-status"></a>


<table>
<caption>CEC Transmit Status</caption>
<tbody>
<tr>
<td>


`CEC_TX_STATUS_OK`

</td>
<td>


0x01

</td>
<td>


<a id="rst-cec-tx-status-ok"></a>

The message was transmitted successfully. This is mutually exclusive with [CEC_TX_STATUS_MAX_RETRIES](<#rst-cec-tx-status-max-retries>). Other bits can still be set if earlier attempts met with failure before the transmit was eventually successful.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_ARB_LOST`

</td>
<td>


0x02

</td>
<td>


<a id="rst-cec-tx-status-arb-lost"></a>

CEC line arbitration was lost, i.e. another transmit started at the same time with a higher priority. Optional status, not all hardware can detect this error condition.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_NACK`

</td>
<td>


0x04

</td>
<td>


<a id="rst-cec-tx-status-nack"></a>

Message was not acknowledged. Note that some hardware cannot tell apart a 'Not Acknowledged' status from other error conditions, i.e. the result of a transmit is just OK or FAIL. In that case this status will be returned when the transmit failed.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_LOW_DRIVE`

</td>
<td>


0x08

</td>
<td>


<a id="rst-cec-tx-status-low-drive"></a>

Low drive was detected on the CEC bus. This indicates that a follower detected an error on the bus and requests a retransmission. Optional status, not all hardware can detect this error condition.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_ERROR`

</td>
<td>


0x10

</td>
<td>


<a id="rst-cec-tx-status-error"></a>

Some error occurred. This is used for any errors that do not fit `CEC_TX_STATUS_ARB_LOST` or `CEC_TX_STATUS_LOW_DRIVE`, either because the hardware could not tell which error occurred, or because the hardware tested for other conditions besides those two. Optional status.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_MAX_RETRIES`

</td>
<td>


0x20

</td>
<td>


<a id="rst-cec-tx-status-max-retries"></a>

The transmit failed after one or more retries. This status bit is mutually exclusive with [CEC_TX_STATUS_OK](<#rst-cec-tx-status-ok>). Other bits can still be set to explain which failures were seen.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_ABORTED`

</td>
<td>


0x40

</td>
<td>


<a id="rst-cec-tx-status-aborted"></a>

The transmit was aborted due to an HDMI disconnect, or the adapter was unconfigured, or a transmit was interrupted, or the driver returned an error when attempting to start a transmit.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_TIMEOUT`

</td>
<td>


0x80

</td>
<td>


<a id="rst-cec-tx-status-timeout"></a>

The transmit timed out. This should not normally happen and this indicates a driver problem.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-rx-status"></a>


<table>
<caption>CEC Receive Status</caption>
<tbody>
<tr>
<td>


`CEC_RX_STATUS_OK`

</td>
<td>


0x01

</td>
<td>


<a id="rst-cec-rx-status-ok"></a>

The message was received successfully.

</td>
</tr>
<tr>
<td>


`CEC_RX_STATUS_TIMEOUT`

</td>
<td>


0x02

</td>
<td>


<a id="rst-cec-rx-status-timeout"></a>

The reply to an earlier transmitted message timed out.

</td>
</tr>
<tr>
<td>


`CEC_RX_STATUS_FEATURE_ABORT`

</td>
<td>


0x04

</td>
<td>


<a id="rst-cec-rx-status-feature-abort"></a>

The message was received successfully but the reply was `CEC_MSG_FEATURE_ABORT`. This status is only set if this message was the reply to an earlier transmitted message.

</td>
</tr>
<tr>
<td>


`CEC_RX_STATUS_ABORTED`

</td>
<td>


0x08

</td>
<td>


<a id="rst-cec-rx-status-aborted"></a>

The wait for a reply to an earlier transmitted message was aborted because the HDMI cable was disconnected, the adapter was unconfigured or the [CEC_TRANSMIT](<#rst-cec-receive>) that waited for a reply was interrupted.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_RECEIVE](<#rst-cec-receive>) can return the following error codes:

- **EAGAIN**

  No messages are in the receive queue, and the filehandle is in non-blocking mode.

- **ETIMEDOUT**

  The `timeout` was reached while waiting for a message.

- **ERESTARTSYS**

  The wait for a message was interrupted (e.g. by Ctrl-C).

The [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) can return the following error codes:

- **ENOTTY**

  The `CEC_CAP_TRANSMIT` capability wasn't set, so this ioctl is not supported.

- **EPERM**

  The CEC adapter is not configured, i.e. [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>) has never been called, or `CEC_MSG_FL_RAW` was used from a process that did not have the `CAP_SYS_RAWIO` capability.

- **ENONET**

  The CEC adapter is not configured, i.e. [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>) was called, but the physical address is invalid so no logical address was claimed. An exception is made in this case for transmits from initiator 0xf ('Unregistered') to destination 0 ('TV'). In that case the transmit will proceed as usual.

- **EBUSY**

  Another filehandle is in exclusive follower or initiator mode, or the filehandle is in mode `CEC_MODE_NO_INITIATOR`. This is also returned if the transmit queue is full.

- **EINVAL**

  The contents of struct `cec_msg` is invalid.

- **ERESTARTSYS**

  The wait for a successful transmit was interrupted (e.g. by Ctrl-C).

---

# CEC Pin Framework Error Injection

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> The CEC Pin Framework is a core CEC framework for CEC hardware that only has low-level support for the CEC bus. Most hardware today will have high-level CEC support where the hardware deals with driving the CEC bus, but some older devices…

<a id="rst-cec-pin-framework-error-injection"></a>
<a id="rst-cec-pin-error-inj"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The CEC Pin Framework is a core CEC framework for CEC hardware that only has low-level support for the CEC bus. Most hardware today will have high-level CEC support where the hardware deals with driving the CEC bus, but some older devices aren't that fancy. However, this framework also allows you to connect the CEC pin to a GPIO on e.g. a Raspberry Pi and you have now made a CEC adapter.

What makes doing this so interesting is that since we have full control over the bus it is easy to support error injection. This is ideal to test how well CEC adapters can handle error conditions.

Currently only the cec-gpio driver (when the CEC line is directly connected to a pull-up GPIO line) and the AllWinner A10/A20 drm driver support this framework.

If `CONFIG_CEC_PIN_ERROR_INJ` is enabled, then error injection is available through debugfs. Specifically, in `/sys/kernel/debug/cec/cecX/` there is now an `error-inj` file.

> [!NOTE]
>
> The error injection commands are not a stable ABI and may change in the future.

With `cat error-inj` you can see both the possible commands and the current error injection status:



```text
$ cat /sys/kernel/debug/cec/cec0/error-inj
# Clear error injections:
#   clear          clear all rx and tx error injections
#   rx-clear       clear all rx error injections
#   tx-clear       clear all tx error injections
#   <op> clear     clear all rx and tx error injections for <op>
#   <op> rx-clear  clear all rx error injections for <op>
#   <op> tx-clear  clear all tx error injections for <op>
#
# RX error injection settings:
#   rx-no-low-drive                    do not generate low-drive pulses
#
# RX error injection:
#   <op>[,<mode>] rx-nack              NACK the message instead of sending an ACK
#   <op>[,<mode>] rx-low-drive <bit>   force a low-drive condition at this bit position
#   <op>[,<mode>] rx-add-byte          add a spurious byte to the received CEC message
#   <op>[,<mode>] rx-remove-byte       remove the last byte from the received CEC message
#    any[,<mode>] rx-arb-lost [<poll>] generate a POLL message to trigger an arbitration lost
#
# TX error injection settings:
#   tx-ignore-nack-until-eom           ignore early NACKs until EOM
#   tx-custom-low-usecs <usecs>        define the 'low' time for the custom pulse
#   tx-custom-high-usecs <usecs>       define the 'high' time for the custom pulse
#   tx-custom-pulse                    transmit the custom pulse once the bus is idle
#   tx-glitch-low-usecs <usecs>        define the 'low' time for the glitch pulse
#   tx-glitch-high-usecs <usecs>       define the 'high' time for the glitch pulse
#   tx-glitch-falling-edge             send the glitch pulse after every falling edge
#   tx-glitch-rising-edge              send the glitch pulse after every rising edge
#
# TX error injection:
#   <op>[,<mode>] tx-no-eom            don't set the EOM bit
#   <op>[,<mode>] tx-early-eom         set the EOM bit one byte too soon
#   <op>[,<mode>] tx-add-bytes <num>   append <num> (1-255) spurious bytes to the message
#   <op>[,<mode>] tx-remove-byte       drop the last byte from the message
#   <op>[,<mode>] tx-short-bit <bit>   make this bit shorter than allowed
#   <op>[,<mode>] tx-long-bit <bit>    make this bit longer than allowed
#   <op>[,<mode>] tx-custom-bit <bit>  send the custom pulse instead of this bit
#   <op>[,<mode>] tx-short-start       send a start pulse that's too short
#   <op>[,<mode>] tx-long-start        send a start pulse that's too long
#   <op>[,<mode>] tx-custom-start      send the custom pulse instead of the start pulse
#   <op>[,<mode>] tx-last-bit <bit>    stop sending after this bit
#   <op>[,<mode>] tx-low-drive <bit>   force a low-drive condition at this bit position
#
# <op>       CEC message opcode (0-255) or 'any'
# <mode>     'once' (default), 'always', 'toggle' or 'off'
# <bit>      CEC message bit (0-159)
#            10 bits per 'byte': bits 0-7: data, bit 8: EOM, bit 9: ACK
# <poll>     CEC poll message used to test arbitration lost (0x00-0xff, default 0x0f)
# <usecs>    microseconds (0-10000000, default 1000)

clear
```

You can write error injection commands to `error-inj` using `echo 'cmd' >error-inj` or `cat cmd.txt >error-inj`. The `cat error-inj` output contains the current error commands. You can save the output to a file and use it as an input to `error-inj` later.

<a id="rst-basic-syntax"></a>

## Basic Syntax

Leading spaces/tabs are ignored. If the next character is a `#` or the end of the line was reached, then the whole line is ignored. Otherwise a command is expected.

The error injection commands fall in two main groups: those relating to receiving CEC messages and those relating to transmitting CEC messages. In addition, there are commands to clear existing error injection commands and to create custom pulses on the CEC bus.

Most error injection commands can be executed for specific CEC opcodes or for all opcodes (`any`). Each command also has a 'mode' which can be `off` (can be used to turn off an existing error injection command), `once` (the default) which will trigger the error injection only once for the next received or transmitted message, `always` to always trigger the error injection and `toggle` to toggle the error injection on or off for every transmit or receive.

So '`any rx-nack`' will NACK the next received CEC message, '`any,always rx-nack`' will NACK all received CEC messages and '`0x82,toggle rx-nack`' will only NACK if an Active Source message was received and do that only for every other received message.

After an error was injected with mode `once` the error injection command is cleared automatically, so `once` is a one-time deal.

All combinations of `<op>` and error injection commands can co-exist. So this is fine:



```text
0x9e tx-add-bytes 1
0x9e tx-early-eom
0x9f tx-add-bytes 2
any rx-nack
```

All four error injection commands will be active simultaneously.

However, if the same `<op>` and command combination is specified, but with different arguments:



```text
0x9e tx-add-bytes 1
0x9e tx-add-bytes 2
```

Then the second will overwrite the first.

<a id="rst-clear-error-injections"></a>

## Clear Error Injections

- **`clear`**

  Clear all error injections.

- **`rx-clear`**

  Clear all receive error injections

- **`tx-clear`**

  Clear all transmit error injections

- **`<op> clear`**

  Clear all error injections for the given opcode.

- **`<op> rx-clear`**

  Clear all receive error injections for the given opcode.

- **`<op> tx-clear`**

  Clear all transmit error injections for the given opcode.

<a id="rst-receive-messages"></a>

## Receive Messages

- **`<op>[,<mode>] rx-nack`**

  NACK broadcast messages and messages directed to this CEC adapter. Every byte of the message will be NACKed in case the transmitter keeps transmitting after the first byte was NACKed.

- **`<op>[,<mode>] rx-low-drive <bit>`**

  Force a Low Drive condition at this bit position. If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. This tests if the transmitter can handle the Low Drive condition correctly and reports the error correctly. Note that a Low Drive in the first 4 bits can also be interpreted as an Arbitration Lost condition by the transmitter. This is implementation dependent.

- **`<op>[,<mode>] rx-add-byte`**

  Add a spurious 0x55 byte to the received CEC message, provided the message was 15 bytes long or less. This is useful to test the high-level protocol since spurious bytes should be ignored.

- **`<op>[,<mode>] rx-remove-byte`**

  Remove the last byte from the received CEC message, provided it was at least 2 bytes long. This is useful to test the high-level protocol since messages that are too short should be ignored.

- **`<op>[,<mode>] rx-arb-lost <poll>`**

  Generate a POLL message to trigger an Arbitration Lost condition. This command is only allowed for `<op>` values of `next` or `all`. As soon as a start bit has been received the CEC adapter will switch to transmit mode and it will transmit a POLL message. By default this is 0x0f, but it can also be specified explicitly via the `<poll>` argument.

  This command can be used to test the Arbitration Lost condition in the remote CEC transmitter. Arbitration happens when two CEC adapters start sending a message at the same time. In that case the initiator with the most leading zeroes wins and the other transmitter has to stop transmitting ('Arbitration Lost'). This is very hard to test, except by using this error injection command.

  This does not work if the remote CEC transmitter has logical address 0 ('TV') since that will always win.

- **`rx-no-low-drive`**

  The receiver will ignore situations that would normally generate a Low Drive pulse (3.6 ms). This is typically done if a spurious pulse is detected when receiving a message, and it indicates to the transmitter that the message has to be retransmitted since the receiver got confused. Disabling this is useful to test how other CEC devices handle glitches by ensuring we will not be the one that generates a Low Drive.

<a id="rst-transmit-messages"></a>

## Transmit Messages

- **`tx-ignore-nack-until-eom`**

  This setting changes the behavior of transmitting CEC messages. Normally as soon as the receiver NACKs a byte the transmit will stop, but the specification also allows that the full message is transmitted and only at the end will the transmitter look at the ACK bit. This is not recommended behavior since there is no point in keeping the CEC bus busy for longer than is strictly needed. Especially given how slow the bus is.

  This setting can be used to test how well a receiver deals with transmitters that ignore NACKs until the very end of the message.

- **`<op>[,<mode>] tx-no-eom`**

  Don't set the EOM bit. Normally the last byte of the message has the EOM (End-Of-Message) bit set. With this command the transmit will just stop without ever sending an EOM. This can be used to test how a receiver handles this case. Normally receivers have a time-out after which they will go back to the Idle state.

- **`<op>[,<mode>] tx-early-eom`**

  Set the EOM bit one byte too soon. This obviously only works for messages of two bytes or more. The EOM bit will be set for the second-to-last byte and not for the final byte. The receiver should ignore the last byte in this case. Since the resulting message is likely to be too short for this same reason the whole message is typically ignored. The receiver should be in Idle state after the last byte was transmitted.

- **`<op>[,<mode>] tx-add-bytes <num>`**

  Append `<num>` (1-255) spurious bytes to the message. The extra bytes have the value of the byte position in the message. So if you transmit a two byte message (e.g. a Get CEC Version message) and add 2 bytes, then the full message received by the remote CEC adapter is `0x40 0x9f 0x02 0x03`.

  This command can be used to test buffer overflows in the receiver. E.g. what does it do when it receives more than the maximum message size of 16 bytes.

- **`<op>[,<mode>] tx-remove-byte`**

  Drop the last byte from the message, provided the message is at least two bytes long. The receiver should ignore messages that are too short.

- **`<op>[,<mode>] tx-short-bit <bit>`**

  Make this bit period shorter than allowed. The bit position cannot be an Ack bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. Normally the period of a data bit is between 2.05 and 2.75 milliseconds. With this command the period of this bit is 1.8 milliseconds, this is done by reducing the time the CEC bus is high. This bit period is less than is allowed and the receiver should respond with a Low Drive condition.

  This command is ignored for 0 bits in bit positions 0 to 3. This is because the receiver also looks for an Arbitration Lost condition in those first four bits and it is undefined what will happen if it sees a too-short 0 bit.

- **`<op>[,<mode>] tx-long-bit <bit>`**

  Make this bit period longer than is valid. The bit position cannot be an Ack bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. Normally the period of a data bit is between 2.05 and 2.75 milliseconds. With this command the period of this bit is 2.9 milliseconds, this is done by increasing the time the CEC bus is high.

  Even though this bit period is longer than is valid it is undefined what a receiver will do. It might just accept it, or it might time out and return to Idle state. Unfortunately the CEC specification is silent about this.

  This command is ignored for 0 bits in bit positions 0 to 3. This is because the receiver also looks for an Arbitration Lost condition in those first four bits and it is undefined what will happen if it sees a too-long 0 bit.

- **`<op>[,<mode>] tx-short-start`**

  Make this start bit period shorter than allowed. Normally the period of a start bit is between 4.3 and 4.7 milliseconds. With this command the period of the start bit is 4.1 milliseconds, this is done by reducing the time the CEC bus is high. This start bit period is less than is allowed and the receiver should return to Idle state when this is detected.

- **`<op>[,<mode>] tx-long-start`**

  Make this start bit period longer than is valid. Normally the period of a start bit is between 4.3 and 4.7 milliseconds. With this command the period of the start bit is 5 milliseconds, this is done by increasing the time the CEC bus is high. This start bit period is more than is valid and the receiver should return to Idle state when this is detected.

  Even though this start bit period is longer than is valid it is undefined what a receiver will do. It might just accept it, or it might time out and return to Idle state. Unfortunately the CEC specification is silent about this.

- **`<op>[,<mode>] tx-last-bit <bit>`**

  Just stop transmitting after this bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. This command can be used to test how the receiver reacts when a message just suddenly stops. It should time out and go back to Idle state.

- **`<op>[,<mode>] tx-low-drive <bit>`**

  Force a Low Drive condition at this bit position. If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. This can be used to test how the receiver handles Low Drive conditions. Note that if this happens at bit positions 0-3 the receiver can interpret this as an Arbitration Lost condition. This is implementation dependent.

<a id="rst-custom-pulses"></a>

## Custom Pulses

- **`tx-custom-low-usecs <usecs>`**

  This defines the duration in microseconds that the custom pulse pulls the CEC line low. The default is 1000 microseconds.

- **`tx-custom-high-usecs <usecs>`**

  This defines the duration in microseconds that the custom pulse keeps the CEC line high (unless another CEC adapter pulls it low in that time). The default is 1000 microseconds. The total period of the custom pulse is `tx-custom-low-usecs + tx-custom-high-usecs`.

- **`<op>[,<mode>] tx-custom-bit <bit>`**

  Send the custom bit instead of a regular data bit. The bit position cannot be an Ack bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet.

- **`<op>[,<mode>] tx-custom-start`**

  Send the custom bit instead of a regular start bit.

- **`tx-custom-pulse`**

  Transmit a single custom pulse as soon as the CEC bus is idle.

<a id="rst-glitch-pulses"></a>

## Glitch Pulses

This emulates what happens if the signal on the CEC line is seeing spurious pulses. Typically this happens after the falling or rising edge where there is a short voltage fluctuation that, if the CEC hardware doesn't do deglitching, can be seen as a spurious pulse and can cause a Low Drive condition or corrupt data.

- **`tx-glitch-low-usecs <usecs>`**

  This defines the duration in microseconds that the glitch pulse pulls the CEC line low. The default is 1 microsecond. The range is 0-100 microseconds. If 0, then no glitch pulse will be generated.

- **`tx-glitch-high-usecs <usecs>`**

  This defines the duration in microseconds that the glitch pulse keeps the CEC line high (unless another CEC adapter pulls it low in that time). The default is 1 microseconds. The range is 0-100 microseconds. If 0, then no glitch pulse will be generated.The total period of the glitch pulse is `tx-custom-low-usecs + tx-custom-high-usecs`.

- **`tx-glitch-falling-edge`**

  Send the glitch pulse right after the falling edge.

- **`tx-glitch-rising-edge`**

  Send the glitch pulse right after the rising edge.
