1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun=================================== 4*4882a593SmuzhiyunBuilding support for a media device 5*4882a593Smuzhiyun=================================== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunThe first step is to download the Kernel's source code, either via a 8*4882a593Smuzhiyundistribution-specific source file or via the Kernel's main git tree\ [1]_. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunPlease notice, however, that, if: 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun- you're a braveheart and want to experiment with new stuff; 13*4882a593Smuzhiyun- if you want to report a bug; 14*4882a593Smuzhiyun- if you're developing new patches 15*4882a593Smuzhiyun 16*4882a593Smuzhiyunyou should use the main media development tree ``master`` branch: 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun https://git.linuxtv.org/media_tree.git/ 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunIn this case, you may find some useful information at the 21*4882a593Smuzhiyun`LinuxTv wiki pages <https://linuxtv.org/wiki>`_: 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun https://linuxtv.org/wiki/index.php/How_to_Obtain,_Build_and_Install_V4L-DVB_Device_Drivers 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun.. [1] The upstream Linux Kernel development tree is located at 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun https://git.kernel.org/pub/scm/li nux/kernel/git/torvalds/linux.git/ 28*4882a593Smuzhiyun 29*4882a593SmuzhiyunConfiguring the Linux Kernel 30*4882a593Smuzhiyun============================ 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunYou can access a menu of Kernel building options with:: 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun $ make menuconfig 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunThen, select all desired options and exit it, saving the configuration. 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunThe changed configuration will be at the ``.config`` file. It would 39*4882a593Smuzhiyunlook like:: 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun ... 42*4882a593Smuzhiyun # CONFIG_RC_CORE is not set 43*4882a593Smuzhiyun # CONFIG_CEC_CORE is not set 44*4882a593Smuzhiyun CONFIG_MEDIA_SUPPORT=m 45*4882a593Smuzhiyun CONFIG_MEDIA_SUPPORT_FILTER=y 46*4882a593Smuzhiyun ... 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunThe media subsystem is controlled by those menu configuration options:: 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun Device Drivers ---> 51*4882a593Smuzhiyun <M> Remote Controller support ---> 52*4882a593Smuzhiyun [ ] HDMI CEC RC integration 53*4882a593Smuzhiyun [ ] Enable CEC error injection support 54*4882a593Smuzhiyun [*] HDMI CEC drivers ---> 55*4882a593Smuzhiyun <*> Multimedia support ---> 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunThe ``Remote Controller support`` option enables the core support for 58*4882a593Smuzhiyunremote controllers\ [2]_. 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunThe ``HDMI CEC RC integration`` option enables integration of HDMI CEC 61*4882a593Smuzhiyunwith Linux, allowing to receive data via HDMI CEC as if it were produced 62*4882a593Smuzhiyunby a remote controller directly connected to the machine. 63*4882a593Smuzhiyun 64*4882a593SmuzhiyunThe ``HDMI CEC drivers`` option allow selecting platform and USB drivers 65*4882a593Smuzhiyunthat receives and/or transmits CEC codes via HDMI interfaces\ [3]_. 66*4882a593Smuzhiyun 67*4882a593SmuzhiyunThe last option (``Multimedia support``) enables support for cameras, 68*4882a593Smuzhiyunaudio/video grabbers and TV. 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunThe media subsystem support can either be built together with the main 71*4882a593SmuzhiyunKernel or as a module. For most use cases, it is preferred to have it 72*4882a593Smuzhiyunbuilt as modules. 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun.. note:: 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun Instead of using a menu, the Kernel provides a script with allows 77*4882a593Smuzhiyun enabling configuration options directly. To enable media support 78*4882a593Smuzhiyun and remote controller support using Kernel modules, you could use:: 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun $ scripts/config -m RC_CORE 81*4882a593Smuzhiyun $ scripts/config -m MEDIA_SUPPORT 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun.. [2] ``Remote Controller support`` should also be enabled if you 84*4882a593Smuzhiyun want to use some TV card drivers that may depend on the remote 85*4882a593Smuzhiyun controller core support. 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun.. [3] Please notice that the DRM subsystem also have drivers for GPUs 88*4882a593Smuzhiyun that use the media HDMI CEC support. 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun Those GPU-specific drivers are selected via the ``Graphics support`` 91*4882a593Smuzhiyun menu, under ``Device Drivers``. 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun When a GPU driver supports HDMI CEC, it will automatically 94*4882a593Smuzhiyun enable the CEC core support at the media subsystem. 95*4882a593Smuzhiyun 96*4882a593SmuzhiyunMedia dependencies 97*4882a593Smuzhiyun------------------ 98*4882a593Smuzhiyun 99*4882a593SmuzhiyunIt should be noticed that enabling the above from a clean config is 100*4882a593Smuzhiyunusually not enough. The media subsystem depends on several other Linux 101*4882a593Smuzhiyuncore support in order to work. 102*4882a593Smuzhiyun 103*4882a593SmuzhiyunFor example, most media devices use a serial communication bus in 104*4882a593Smuzhiyunorder to talk with some peripherals. Such bus is called I²C 105*4882a593Smuzhiyun(Inter-Integrated Circuit). In order to be able to build support 106*4882a593Smuzhiyunfor such hardware, the I²C bus support should be enabled, either via 107*4882a593Smuzhiyunmenu or with:: 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun ./scripts/config -m I2C 110*4882a593Smuzhiyun 111*4882a593SmuzhiyunAnother example: the remote controller core requires support for 112*4882a593Smuzhiyuninput devices, with can be enabled with:: 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun ./scripts/config -m INPUT 115*4882a593Smuzhiyun 116*4882a593SmuzhiyunOther core functionality may also be needed (like PCI and/or USB support), 117*4882a593Smuzhiyundepending on the specific driver(s) you would like to enable. 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunEnabling Remote Controller Support 120*4882a593Smuzhiyun---------------------------------- 121*4882a593Smuzhiyun 122*4882a593SmuzhiyunThe remote controller menu allows selecting drivers for specific devices. 123*4882a593SmuzhiyunIt's menu looks like this:: 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun --- Remote Controller support 126*4882a593Smuzhiyun <M> Compile Remote Controller keymap modules 127*4882a593Smuzhiyun [*] LIRC user interface 128*4882a593Smuzhiyun [*] Support for eBPF programs attached to lirc devices 129*4882a593Smuzhiyun [*] Remote controller decoders ---> 130*4882a593Smuzhiyun [*] Remote Controller devices ---> 131*4882a593Smuzhiyun 132*4882a593SmuzhiyunThe ``Compile Remote Controller keymap modules`` option creates key maps for 133*4882a593Smuzhiyunseveral popular remote controllers. 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunThe ``LIRC user interface`` option adds enhanced functionality when using the 136*4882a593Smuzhiyun``lirc`` program, by enabling an API that allows userspace to receive raw data 137*4882a593Smuzhiyunfrom remote controllers. 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunThe ``Support for eBPF programs attached to lirc devices`` option allows 140*4882a593Smuzhiyunthe usage of special programs (called eBPF) that would allow aplications 141*4882a593Smuzhiyunto add extra remote controller decoding functionality to the Linux Kernel. 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunThe ``Remote controller decoders`` option allows selecting the 144*4882a593Smuzhiyunprotocols that will be recognized by the Linux Kernel. Except if you 145*4882a593Smuzhiyunwant to disable some specific decoder, it is suggested to keep all 146*4882a593Smuzhiyunsub-options enabled. 147*4882a593Smuzhiyun 148*4882a593SmuzhiyunThe ``Remote Controller devices`` allows you to select the drivers 149*4882a593Smuzhiyunthat would be needed to support your device. 150*4882a593Smuzhiyun 151*4882a593SmuzhiyunThe same configuration can also be set via the ``script/config`` 152*4882a593Smuzhiyunscript. So, for instance, in order to support the ITE remote controller 153*4882a593Smuzhiyundriver (found on Intel NUCs and on some ASUS x86 desktops), you could do:: 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun $ scripts/config -e INPUT 156*4882a593Smuzhiyun $ scripts/config -e ACPI 157*4882a593Smuzhiyun $ scripts/config -e MODULES 158*4882a593Smuzhiyun $ scripts/config -m RC_CORE 159*4882a593Smuzhiyun $ scripts/config -e RC_DEVICES 160*4882a593Smuzhiyun $ scripts/config -e RC_DECODERS 161*4882a593Smuzhiyun $ scripts/config -m IR_RC5_DECODER 162*4882a593Smuzhiyun $ scripts/config -m IR_ITE_CIR 163*4882a593Smuzhiyun 164*4882a593SmuzhiyunEnabling HDMI CEC Support 165*4882a593Smuzhiyun------------------------- 166*4882a593Smuzhiyun 167*4882a593SmuzhiyunThe HDMI CEC support is set automatically when a driver requires it. So, 168*4882a593Smuzhiyunall you need to do is to enable support either for a graphics card 169*4882a593Smuzhiyunthat needs it or by one of the existing HDMI drivers. 170*4882a593Smuzhiyun 171*4882a593SmuzhiyunThe HDMI-specific drivers are available at the ``HDMI CEC drivers`` 172*4882a593Smuzhiyunmenu\ [4]_:: 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun --- HDMI CEC drivers 175*4882a593Smuzhiyun < > ChromeOS EC CEC driver 176*4882a593Smuzhiyun < > Amlogic Meson AO CEC driver 177*4882a593Smuzhiyun < > Amlogic Meson G12A AO CEC driver 178*4882a593Smuzhiyun < > Generic GPIO-based CEC driver 179*4882a593Smuzhiyun < > Samsung S5P CEC driver 180*4882a593Smuzhiyun < > STMicroelectronics STiH4xx HDMI CEC driver 181*4882a593Smuzhiyun < > STMicroelectronics STM32 HDMI CEC driver 182*4882a593Smuzhiyun < > Tegra HDMI CEC driver 183*4882a593Smuzhiyun < > SECO Boards HDMI CEC driver 184*4882a593Smuzhiyun [ ] SECO Boards IR RC5 support 185*4882a593Smuzhiyun < > Pulse Eight HDMI CEC 186*4882a593Smuzhiyun < > RainShadow Tech HDMI CEC 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun.. [4] The above contents is just an example. The actual options for 189*4882a593Smuzhiyun HDMI devices depends on the system's architecture and may vary 190*4882a593Smuzhiyun on new Kernels. 191*4882a593Smuzhiyun 192*4882a593SmuzhiyunEnabling Media Support 193*4882a593Smuzhiyun---------------------- 194*4882a593Smuzhiyun 195*4882a593SmuzhiyunThe Media menu has a lot more options than the remote controller menu. 196*4882a593SmuzhiyunOnce selected, you should see the following options:: 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun --- Media support 199*4882a593Smuzhiyun [ ] Filter media drivers 200*4882a593Smuzhiyun [*] Autoselect ancillary drivers 201*4882a593Smuzhiyun Media device types ---> 202*4882a593Smuzhiyun Media core support ---> 203*4882a593Smuzhiyun Video4Linux options ---> 204*4882a593Smuzhiyun Media controller options ---> 205*4882a593Smuzhiyun Digital TV options ---> 206*4882a593Smuzhiyun HDMI CEC options ---> 207*4882a593Smuzhiyun Media drivers ---> 208*4882a593Smuzhiyun Media ancillary drivers ---> 209*4882a593Smuzhiyun 210*4882a593SmuzhiyunExcept if you know exactly what you're doing, or if you want to build 211*4882a593Smuzhiyuna driver for a SoC platform, it is strongly recommended to keep the 212*4882a593Smuzhiyun``Autoselect ancillary drivers`` option turned on, as it will auto-select 213*4882a593Smuzhiyunthe needed I²C ancillary drivers. 214*4882a593Smuzhiyun 215*4882a593SmuzhiyunThere are now two ways to select media device drivers, as described 216*4882a593Smuzhiyunbelow. 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun``Filter media drivers`` menu 219*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 220*4882a593Smuzhiyun 221*4882a593SmuzhiyunThis menu is meant to easy setup for PC and Laptop hardware. It works 222*4882a593Smuzhiyunby letting the user to specify what kind of media drivers are desired, 223*4882a593Smuzhiyunwith those options:: 224*4882a593Smuzhiyun 225*4882a593Smuzhiyun [ ] Cameras and video grabbers 226*4882a593Smuzhiyun [ ] Analog TV 227*4882a593Smuzhiyun [ ] Digital TV 228*4882a593Smuzhiyun [ ] AM/FM radio receivers/transmitters 229*4882a593Smuzhiyun [ ] Software defined radio 230*4882a593Smuzhiyun [ ] Platform-specific devices 231*4882a593Smuzhiyun [ ] Test drivers 232*4882a593Smuzhiyun 233*4882a593SmuzhiyunSo, if you want to add support to a camera or video grabber only, 234*4882a593Smuzhiyunselect just the first option. Multiple options are allowed. 235*4882a593Smuzhiyun 236*4882a593SmuzhiyunOnce the options on this menu are selected, the building system will 237*4882a593Smuzhiyunauto-select the needed core drivers in order to support the selected 238*4882a593Smuzhiyunfunctionality. 239*4882a593Smuzhiyun 240*4882a593Smuzhiyun.. note:: 241*4882a593Smuzhiyun 242*4882a593Smuzhiyun Most TV cards are hybrid: they support both Analog TV and Digital TV. 243*4882a593Smuzhiyun 244*4882a593Smuzhiyun If you have an hybrid card, you may need to enable both ``Analog TV`` 245*4882a593Smuzhiyun and ``Digital TV`` at the menu. 246*4882a593Smuzhiyun 247*4882a593SmuzhiyunWhen using this option, the defaults for the media support core 248*4882a593Smuzhiyunfunctionality are usually good enough to provide the basic functionality 249*4882a593Smuzhiyunfor the driver. Yet, you could manually enable some desired extra (optional) 250*4882a593Smuzhiyunfunctionality using the settings under each of the following 251*4882a593Smuzhiyun``Media support`` sub-menus:: 252*4882a593Smuzhiyun 253*4882a593Smuzhiyun Media core support ---> 254*4882a593Smuzhiyun Video4Linux options ---> 255*4882a593Smuzhiyun Media controller options ---> 256*4882a593Smuzhiyun Digital TV options ---> 257*4882a593Smuzhiyun HDMI CEC options ---> 258*4882a593Smuzhiyun 259*4882a593SmuzhiyunOnce you select the desired filters, the drivers that matches the filtering 260*4882a593Smuzhiyuncriteria will be available at the ``Media support->Media drivers`` sub-menu. 261*4882a593Smuzhiyun 262*4882a593Smuzhiyun``Media Core Support`` menu without filtering 263*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 264*4882a593Smuzhiyun 265*4882a593SmuzhiyunIf you disable the ``Filter media drivers`` menu, all drivers available 266*4882a593Smuzhiyunfor your system whose dependencies are met should be shown at the 267*4882a593Smuzhiyun``Media drivers`` menu. 268*4882a593Smuzhiyun 269*4882a593SmuzhiyunPlease notice, however, that you should first ensure that the 270*4882a593Smuzhiyun``Media Core Support`` menu has all the core functionality your drivers 271*4882a593Smuzhiyunwould need, as otherwise the corresponding device drivers won't be shown. 272*4882a593Smuzhiyun 273*4882a593SmuzhiyunExample 274*4882a593Smuzhiyun------- 275*4882a593Smuzhiyun 276*4882a593SmuzhiyunIn order to enable modular support for one of the boards listed on 277*4882a593Smuzhiyun:doc:`this table <cx231xx-cardlist>`, with modular media core modules, the 278*4882a593Smuzhiyun``.config`` file should contain those lines:: 279*4882a593Smuzhiyun 280*4882a593Smuzhiyun CONFIG_MODULES=y 281*4882a593Smuzhiyun CONFIG_USB=y 282*4882a593Smuzhiyun CONFIG_I2C=y 283*4882a593Smuzhiyun CONFIG_INPUT=y 284*4882a593Smuzhiyun CONFIG_RC_CORE=m 285*4882a593Smuzhiyun CONFIG_MEDIA_SUPPORT=m 286*4882a593Smuzhiyun CONFIG_MEDIA_SUPPORT_FILTER=y 287*4882a593Smuzhiyun CONFIG_MEDIA_ANALOG_TV_SUPPORT=y 288*4882a593Smuzhiyun CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y 289*4882a593Smuzhiyun CONFIG_MEDIA_USB_SUPPORT=y 290*4882a593Smuzhiyun CONFIG_VIDEO_CX231XX=y 291*4882a593Smuzhiyun CONFIG_VIDEO_CX231XX_DVB=y 292*4882a593Smuzhiyun 293*4882a593SmuzhiyunBuilding and installing a new Kernel 294*4882a593Smuzhiyun==================================== 295*4882a593Smuzhiyun 296*4882a593SmuzhiyunOnce the ``.config`` file has everything needed, all it takes to build 297*4882a593Smuzhiyunis to run the ``make`` command:: 298*4882a593Smuzhiyun 299*4882a593Smuzhiyun $ make 300*4882a593Smuzhiyun 301*4882a593SmuzhiyunAnd then install the new Kernel and its modules:: 302*4882a593Smuzhiyun 303*4882a593Smuzhiyun $ sudo make modules_install 304*4882a593Smuzhiyun $ sudo make install 305*4882a593Smuzhiyun 306*4882a593SmuzhiyunBuilding just the new media drivers and core 307*4882a593Smuzhiyun============================================ 308*4882a593Smuzhiyun 309*4882a593SmuzhiyunRunning a new development Kernel from the development tree is usually risky, 310*4882a593Smuzhiyunbecause it may have experimental changes that may have bugs. So, there are 311*4882a593Smuzhiyunsome ways to build just the new drivers, using alternative trees. 312*4882a593Smuzhiyun 313*4882a593SmuzhiyunThere is the `Linux Kernel backports project 314*4882a593Smuzhiyun<https://backports.wiki.kernel.org/index.php/Main_Page>`_, with contains 315*4882a593Smuzhiyunnewer drivers meant to be compiled against stable Kernels. 316*4882a593Smuzhiyun 317*4882a593SmuzhiyunThe LinuxTV developers, with are responsible for maintaining the media 318*4882a593Smuzhiyunsubsystem also maintains a backport tree, with just the media drivers 319*4882a593Smuzhiyundaily updated from the newest kernel. Such tree is available at: 320*4882a593Smuzhiyun 321*4882a593Smuzhiyunhttps://git.linuxtv.org/media_build.git/ 322*4882a593Smuzhiyun 323*4882a593SmuzhiyunIt should be noticed that, while it should be relatively safe to use the 324*4882a593Smuzhiyun``media_build`` tree for testing purposes, there are not warranties that 325*4882a593Smuzhiyunit would work (or even build) on a random Kernel. This tree is maintained 326*4882a593Smuzhiyunusing a "best-efforts" principle, as time permits us to fix issues there. 327*4882a593Smuzhiyun 328*4882a593SmuzhiyunIf you notice anything wrong on it, feel free to submit patches at the 329*4882a593SmuzhiyunLinux media subsystem's mailing list: media@vger.kernel.org. Please 330*4882a593Smuzhiyunadd ``[PATCH media-build]`` at the e-mail's subject if you submit a new 331*4882a593Smuzhiyunpatch for the media-build. 332*4882a593Smuzhiyun 333*4882a593SmuzhiyunBefore using it, you should run:: 334*4882a593Smuzhiyun 335*4882a593Smuzhiyun $ ./build 336*4882a593Smuzhiyun 337*4882a593Smuzhiyun.. note:: 338*4882a593Smuzhiyun 339*4882a593Smuzhiyun 1) you may need to run it twice if the ``media-build`` tree gets 340*4882a593Smuzhiyun updated; 341*4882a593Smuzhiyun 2) you may need to do a ``make distclean`` if you had built it 342*4882a593Smuzhiyun in the past for a different Kernel version than the one you're 343*4882a593Smuzhiyun currently using; 344*4882a593Smuzhiyun 3) by default, it will use the same config options for media as 345*4882a593Smuzhiyun the ones defined on the Kernel you're running. 346*4882a593Smuzhiyun 347*4882a593SmuzhiyunIn order to select different drivers or different config options, 348*4882a593Smuzhiyunuse:: 349*4882a593Smuzhiyun 350*4882a593Smuzhiyun $ make menuconfig 351*4882a593Smuzhiyun 352*4882a593SmuzhiyunThen, you can build and install the new drivers:: 353*4882a593Smuzhiyun 354*4882a593Smuzhiyun $ make && sudo make install 355*4882a593Smuzhiyun 356*4882a593SmuzhiyunThis will override the previous media drivers that your Kernel were 357*4882a593Smuzhiyunusing. 358