cec.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ========
  3. HDMI CEC
  4. ========
  5. Supported hardware in mainline
  6. ==============================
  7. HDMI Transmitters:
  8. - Exynos4
  9. - Exynos5
  10. - STIH4xx HDMI CEC
  11. - V4L2 adv7511 (same HW, but a different driver from the drm adv7511)
  12. - stm32
  13. - Allwinner A10 (sun4i)
  14. - Raspberry Pi
  15. - dw-hdmi (Synopsis IP)
  16. - amlogic (meson ao-cec and ao-cec-g12a)
  17. - drm adv7511/adv7533
  18. - omap4
  19. - tegra
  20. - rk3288, rk3399
  21. - tda998x
  22. - DisplayPort CEC-Tunneling-over-AUX on i915, nouveau and amdgpu
  23. - ChromeOS EC CEC
  24. - CEC for SECO boards (UDOO x86).
  25. - Chrontel CH7322
  26. HDMI Receivers:
  27. - adv7604/11/12
  28. - adv7842
  29. - tc358743
  30. USB Dongles (see below for additional information on how to use these
  31. dongles):
  32. - Pulse-Eight: the pulse8-cec driver implements the following module option:
  33. ``persistent_config``: by default this is off, but when set to 1 the driver
  34. will store the current settings to the device's internal eeprom and restore
  35. it the next time the device is connected to the USB port.
  36. - RainShadow Tech. Note: this driver does not support the persistent_config
  37. module option of the Pulse-Eight driver. The hardware supports it, but I
  38. have no plans to add this feature. But I accept patches :-)
  39. - Extron DA HD 4K PLUS HDMI Distribution Amplifier. See
  40. :ref:`extron_da_hd_4k_plus` for more information.
  41. Miscellaneous:
  42. - vivid: emulates a CEC receiver and CEC transmitter.
  43. Can be used to test CEC applications without actual CEC hardware.
  44. - cec-gpio. If the CEC pin is hooked up to a GPIO pin then
  45. you can control the CEC line through this driver. This supports error
  46. injection as well.
  47. - cec-gpio and Allwinner A10 (or any other driver that uses the CEC pin
  48. framework to drive the CEC pin directly): the CEC pin framework uses
  49. high-resolution timers. These timers are affected by NTP daemons that
  50. speed up or slow down the clock to sync with the official time. The
  51. chronyd server will by default increase or decrease the clock by
  52. 1/12th. This will cause the CEC timings to go out of spec. To fix this,
  53. add a 'maxslewrate 40000' line to chronyd.conf. This limits the clock
  54. frequency change to 1/25th, which keeps the CEC timings within spec.
  55. Utilities
  56. =========
  57. Utilities are available here: https://git.linuxtv.org/v4l-utils.git
  58. ``utils/cec-ctl``: control a CEC device
  59. ``utils/cec-compliance``: test compliance of a remote CEC device
  60. ``utils/cec-follower``: emulate a CEC follower device
  61. Note that ``cec-ctl`` has support for the CEC Hospitality Profile as is
  62. used in some hotel displays. See http://www.htng.org.
  63. Note that the libcec library (https://github.com/Pulse-Eight/libcec) supports
  64. the linux CEC framework.
  65. If you want to get the CEC specification, then look at the References of
  66. the HDMI wikipedia page: https://en.wikipedia.org/wiki/HDMI. CEC is part
  67. of the HDMI specification. HDMI 1.3 is freely available (very similar to
  68. HDMI 1.4 w.r.t. CEC) and should be good enough for most things.
  69. DisplayPort to HDMI Adapters with working CEC
  70. =============================================
  71. Background: most adapters do not support the CEC Tunneling feature,
  72. and of those that do many did not actually connect the CEC pin.
  73. Unfortunately, this means that while a CEC device is created, it
  74. is actually all alone in the world and will never be able to see other
  75. CEC devices.
  76. This is a list of known working adapters that have CEC Tunneling AND
  77. that properly connected the CEC pin. If you find adapters that work
  78. but are not in this list, then drop me a note.
  79. To test: hook up your DP-to-HDMI adapter to a CEC capable device
  80. (typically a TV), then run::
  81. cec-ctl --playback # Configure the PC as a CEC Playback device
  82. cec-ctl -S # Show the CEC topology
  83. The ``cec-ctl -S`` command should show at least two CEC devices,
  84. ourselves and the CEC device you are connected to (i.e. typically the TV).
  85. General note: I have only seen this work with the Parade PS175, PS176 and
  86. PS186 chipsets and the MegaChips 2900. While MegaChips 28x0 claims CEC support,
  87. I have never seen it work.
  88. USB-C to HDMI
  89. -------------
  90. Samsung Multiport Adapter EE-PW700: https://www.samsung.com/ie/support/model/EE-PW700BBEGWW/
  91. Kramer ADC-U31C/HF: https://www.kramerav.com/product/ADC-U31C/HF
  92. Club3D CAC-2504: https://www.club-3d.com/en/detail/2449/usb_3.1_type_c_to_hdmi_2.0_uhd_4k_60hz_active_adapter/
  93. DisplayPort to HDMI
  94. -------------------
  95. Club3D CAC-1080: https://www.club-3d.com/en/detail/2442/displayport_1.4_to_hdmi_2.0b_hdr/
  96. CableCreation (SKU: CD0712): https://www.cablecreation.com/products/active-displayport-to-hdmi-adapter-4k-hdr
  97. HP DisplayPort to HDMI True 4k Adapter (P/N 2JA63AA): https://www.hp.com/us-en/shop/pdp/hp-displayport-to-hdmi-true-4k-adapter
  98. Mini-DisplayPort to HDMI
  99. ------------------------
  100. Club3D CAC-1180: https://www.club-3d.com/en/detail/2443/mini_displayport_1.4_to_hdmi_2.0b_hdr/
  101. Note that passive adapters will never work, you need an active adapter.
  102. The Club3D adapters in this list are all MegaChips 2900 based. Other Club3D adapters
  103. are PS176 based and do NOT have the CEC pin hooked up, so only the three Club3D
  104. adapters above are known to work.
  105. I suspect that MegaChips 2900 based designs in general are likely to work
  106. whereas with the PS176 it is more hit-and-miss (mostly miss). The PS186 is
  107. likely to have the CEC pin hooked up, it looks like they changed the reference
  108. design for that chipset.
  109. USB CEC Dongles
  110. ===============
  111. These dongles appear as ``/dev/ttyACMX`` devices and need the ``inputattach``
  112. utility to create the ``/dev/cecX`` devices. Support for the Pulse-Eight
  113. has been added to ``inputattach`` 1.6.0. Support for the Rainshadow Tech has
  114. been added to ``inputattach`` 1.6.1.
  115. You also need udev rules to automatically start systemd services::
  116. SUBSYSTEM=="tty", KERNEL=="ttyACM[0-9]*", ATTRS{idVendor}=="2548", ATTRS{idProduct}=="1002", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="pulse8-cec-inputattach@%k.service"
  117. SUBSYSTEM=="tty", KERNEL=="ttyACM[0-9]*", ATTRS{idVendor}=="2548", ATTRS{idProduct}=="1001", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="pulse8-cec-inputattach@%k.service"
  118. SUBSYSTEM=="tty", KERNEL=="ttyACM[0-9]*", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="ff59", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="rainshadow-cec-inputattach@%k.service"
  119. and these systemd services:
  120. For Pulse-Eight make /lib/systemd/system/pulse8-cec-inputattach@.service::
  121. [Unit]
  122. Description=inputattach for pulse8-cec device on %I
  123. [Service]
  124. Type=simple
  125. ExecStart=/usr/bin/inputattach --pulse8-cec /dev/%I
  126. For the RainShadow Tech make /lib/systemd/system/rainshadow-cec-inputattach@.service::
  127. [Unit]
  128. Description=inputattach for rainshadow-cec device on %I
  129. [Service]
  130. Type=simple
  131. ExecStart=/usr/bin/inputattach --rainshadow-cec /dev/%I
  132. For proper suspend/resume support create: /lib/systemd/system/restart-cec-inputattach.service::
  133. [Unit]
  134. Description=restart inputattach for cec devices
  135. After=suspend.target
  136. [Service]
  137. Type=forking
  138. ExecStart=/bin/bash -c 'for d in /dev/serial/by-id/usb-Pulse-Eight*; do /usr/bin/inputattach --daemon --pulse8-cec $d; done; for d in /dev/serial/by-id/usb-RainShadow_Tech*; do /usr/bin/inputattach --daemon --rainshadow-cec $d; done'
  139. [Install]
  140. WantedBy=suspend.target
  141. And run ``systemctl enable restart-cec-inputattach``.
  142. To automatically set the physical address of the CEC device whenever the
  143. EDID changes, you can use ``cec-ctl`` with the ``-E`` option::
  144. cec-ctl -E /sys/class/drm/card0-DP-1/edid
  145. This assumes the dongle is connected to the card0-DP-1 output (``xrandr`` will tell
  146. you which output is used) and it will poll for changes to the EDID and update
  147. the Physical Address whenever they occur.
  148. To automatically run this command you can use cron. Edit crontab with
  149. ``crontab -e`` and add this line::
  150. @reboot /usr/local/bin/cec-ctl -E /sys/class/drm/card0-DP-1/edid
  151. This only works for display drivers that expose the EDID in ``/sys/class/drm``,
  152. such as the i915 driver.
  153. CEC Without HPD
  154. ===============
  155. Some displays when in standby mode have no HDMI Hotplug Detect signal, but
  156. CEC is still enabled so connected devices can send an <Image View On> CEC
  157. message in order to wake up such displays. Unfortunately, not all CEC
  158. adapters can support this. An example is the Odroid-U3 SBC that has a
  159. level-shifter that is powered off when the HPD signal is low, thus
  160. blocking the CEC pin. Even though the SoC can use CEC without a HPD,
  161. the level-shifter will prevent this from functioning.
  162. There is a CEC capability flag to signal this: ``CEC_CAP_NEEDS_HPD``.
  163. If set, then the hardware cannot wake up displays with this behavior.
  164. Note for CEC application implementers: the <Image View On> message must
  165. be the first message you send, don't send any other messages before.
  166. Certain very bad but unfortunately not uncommon CEC implementations
  167. get very confused if they receive anything else but this message and
  168. they won't wake up.
  169. When writing a driver it can be tricky to test this. There are two
  170. ways to do this:
  171. 1) Get a Pulse-Eight USB CEC dongle, connect an HDMI cable from your
  172. device to the Pulse-Eight, but do not connect the Pulse-Eight to
  173. the display.
  174. Now configure the Pulse-Eight dongle::
  175. cec-ctl -p0.0.0.0 --tv
  176. and start monitoring::
  177. sudo cec-ctl -M
  178. On the device you are testing run::
  179. cec-ctl --playback
  180. It should report a physical address of f.f.f.f. Now run this
  181. command::
  182. cec-ctl -t0 --image-view-on
  183. The Pulse-Eight should see the <Image View On> message. If not,
  184. then something (hardware and/or software) is preventing the CEC
  185. message from going out.
  186. To make sure you have the wiring correct just connect the
  187. Pulse-Eight to a CEC-enabled display and run the same command
  188. on your device: now there is a HPD, so you should see the command
  189. arriving at the Pulse-Eight.
  190. 2) If you have another linux device supporting CEC without HPD, then
  191. you can just connect your device to that device. Yes, you can connect
  192. two HDMI outputs together. You won't have a HPD (which is what we
  193. want for this test), but the second device can monitor the CEC pin.
  194. Otherwise use the same commands as in 1.
  195. If CEC messages do not come through when there is no HPD, then you
  196. need to figure out why. Typically it is either a hardware restriction
  197. or the software powers off the CEC core when the HPD goes low. The
  198. first cannot be corrected of course, the second will likely required
  199. driver changes.
  200. Microcontrollers & CEC
  201. ======================
  202. We have seen some CEC implementations in displays that use a microcontroller
  203. to sample the bus. This does not have to be a problem, but some implementations
  204. have timing issues. This is hard to discover unless you can hook up a low-level
  205. CEC debugger (see the next section).
  206. You will see cases where the CEC transmitter holds the CEC line high or low for
  207. a longer time than is allowed. For directed messages this is not a problem since
  208. if that happens the message will not be Acked and it will be retransmitted.
  209. For broadcast messages no such mechanism exists.
  210. It's not clear what to do about this. It is probably wise to transmit some
  211. broadcast messages twice to reduce the chance of them being lost. Specifically
  212. <Standby> and <Active Source> are candidates for that.
  213. Making a CEC debugger
  214. =====================
  215. By using a Raspberry Pi 4B and some cheap components you can make
  216. your own low-level CEC debugger.
  217. The critical component is one of these HDMI female-female passthrough connectors
  218. (full soldering type 1):
  219. https://elabbay.myshopify.com/collections/camera/products/hdmi-af-af-v1a-hdmi-type-a-female-to-hdmi-type-a-female-pass-through-adapter-breakout-board?variant=45533926147
  220. The video quality is variable and certainly not enough to pass-through 4kp60
  221. (594 MHz) video. You might be able to support 4kp30, but more likely you will
  222. be limited to 1080p60 (148.5 MHz). But for CEC testing that is fine.
  223. You need a breadboard and some breadboard wires:
  224. http://www.dx.com/p/diy-40p-male-to-female-male-to-male-female-to-female-dupont-line-wire-3pcs-356089#.WYLOOXWGN7I
  225. If you want to monitor the HPD and/or 5V lines as well, then you need one of
  226. these 5V to 3.3V level shifters:
  227. https://www.adafruit.com/product/757
  228. (This is just where I got these components, there are many other places you
  229. can get similar things).
  230. The ground pin of the HDMI connector needs to be connected to a ground
  231. pin of the Raspberry Pi, of course.
  232. The CEC pin of the HDMI connector needs to be connected to these pins:
  233. GPIO 6 and GPIO 7. The optional HPD pin of the HDMI connector should
  234. be connected via the level shifter to these pins: GPIO 23 and GPIO 12.
  235. The optional 5V pin of the HDMI connector should be connected via the
  236. level shifter to these pins: GPIO 25 and GPIO 22. Monitoring the HPD and
  237. 5V lines is not necessary, but it is helpful.
  238. This device tree addition in ``arch/arm/boot/dts/bcm2711-rpi-4-b.dts``
  239. will hook up the cec-gpio driver correctly::
  240. cec@6 {
  241. compatible = "cec-gpio";
  242. cec-gpios = <&gpio 6 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
  243. hpd-gpios = <&gpio 23 GPIO_ACTIVE_HIGH>;
  244. v5-gpios = <&gpio 25 GPIO_ACTIVE_HIGH>;
  245. };
  246. cec@7 {
  247. compatible = "cec-gpio";
  248. cec-gpios = <&gpio 7 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
  249. hpd-gpios = <&gpio 12 GPIO_ACTIVE_HIGH>;
  250. v5-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
  251. };
  252. If you haven't hooked up the HPD and/or 5V lines, then just delete those
  253. lines.
  254. This dts change will enable two cec GPIO devices: I typically use one to
  255. send/receive CEC commands and the other to monitor. If you monitor using
  256. an unconfigured CEC adapter then it will use GPIO interrupts which makes
  257. monitoring very accurate.
  258. If you just want to monitor traffic, then a single instance is sufficient.
  259. The minimum configuration is one HDMI female-female passthrough connector
  260. and two female-female breadboard wires: one for connecting the HDMI ground
  261. pin to a ground pin on the Raspberry Pi, and the other to connect the HDMI
  262. CEC pin to GPIO 6 on the Raspberry Pi.
  263. The documentation on how to use the error injection is here: :ref:`cec_pin_error_inj`.
  264. ``cec-ctl --monitor-pin`` will do low-level CEC bus sniffing and analysis.
  265. You can also store the CEC traffic to file using ``--store-pin`` and analyze
  266. it later using ``--analyze-pin``.
  267. You can also use this as a full-fledged CEC device by configuring it
  268. using ``cec-ctl --tv -p0.0.0.0`` or ``cec-ctl --playback -p1.0.0.0``.
  269. .. _extron_da_hd_4k_plus:
  270. Extron DA HD 4K PLUS CEC Adapter driver
  271. =======================================
  272. This driver is for the Extron DA HD 4K PLUS series of HDMI Distribution
  273. Amplifiers: https://www.extron.com/product/dahd4kplusseries
  274. The 2, 4 and 6 port models are supported.
  275. Firmware version 1.02.0001 or higher is required.
  276. Note that older Extron hardware revisions have a problem with the CEC voltage,
  277. which may mean that CEC will not work. This is fixed in hardware revisions
  278. E34814 and up.
  279. The CEC support has two modes: the first is a manual mode where userspace has
  280. to manually control CEC for the HDMI Input and all HDMI Outputs. While this gives
  281. full control, it is also complicated.
  282. The second mode is an automatic mode, which is selected if the module option
  283. ``vendor_id`` is set. In that case the driver controls CEC and CEC messages
  284. received in the input will be distributed to the outputs. It is still possible
  285. to use the /dev/cecX devices to talk to the connected devices directly, but it is
  286. the driver that configures everything and deals with things like Hotplug Detect
  287. changes.
  288. The driver also takes care of the EDIDs: /dev/videoX devices are created to
  289. read the EDIDs and (for the HDMI Input port) to set the EDID.
  290. By default userspace is responsible to set the EDID for the HDMI Input
  291. according to the EDIDs of the connected displays. But if the ``manufacturer_name``
  292. module option is set, then the driver will take care of setting the EDID
  293. of the HDMI Input based on the supported resolutions of the connected displays.
  294. Currently the driver only supports resolutions 1080p60 and 4kp60: if all connected
  295. displays support 4kp60, then it will advertise 4kp60 on the HDMI input, otherwise
  296. it will fall back to an EDID that just reports 1080p60.
  297. The status of the Extron is reported in ``/sys/kernel/debug/cec/cecX/status``.
  298. The extron-da-hd-4k-plus driver implements the following module options:
  299. ``debug``
  300. ---------
  301. If set to 1, then all serial port traffic is shown.
  302. ``vendor_id``
  303. -------------
  304. The CEC Vendor ID to report to connected displays.
  305. If set, then the driver will take care of distributing CEC messages received
  306. on the input to the HDMI outputs. This is done for the following CEC messages:
  307. - <Standby>
  308. - <Image View On> and <Text View On>
  309. - <Give Device Power Status>
  310. - <Set System Audio Mode>
  311. - <Request Current Latency>
  312. If not set, then userspace is responsible for this, and it will have to
  313. configure the CEC devices for HDMI Input and the HDMI Outputs manually.
  314. ``manufacturer_name``
  315. ---------------------
  316. A three character manufacturer name that is used in the EDID for the HDMI
  317. Input. If not set, then userspace is reponsible for configuring an EDID.
  318. If set, then the driver will update the EDID automatically based on the
  319. resolutions supported by the connected displays, and it will not be possible
  320. anymore to manually set the EDID for the HDMI Input.
  321. ``hpd_never_low``
  322. -----------------
  323. If set, then the Hotplug Detect pin of the HDMI Input will always be high,
  324. even if nothing is connected to the HDMI Outputs. If not set (the default)
  325. then the Hotplug Detect pin of the HDMI input will go low if all the detected
  326. Hotplug Detect pins of the HDMI Outputs are also low.
  327. This option may be changed dynamically.