Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * Multimedia device API
0004  *
0005  * Copyright (C) 2010 Nokia Corporation
0006  *
0007  * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
0008  *       Sakari Ailus <sakari.ailus@iki.fi>
0009  *
0010  * This program is free software; you can redistribute it and/or modify
0011  * it under the terms of the GNU General Public License version 2 as
0012  * published by the Free Software Foundation.
0013  *
0014  * This program is distributed in the hope that it will be useful,
0015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  * GNU General Public License for more details.
0018  */
0019 
0020 #ifndef __LINUX_MEDIA_H
0021 #define __LINUX_MEDIA_H
0022 
0023 #include <linux/ioctl.h>
0024 #include <linux/types.h>
0025 
0026 struct media_device_info {
0027     char driver[16];
0028     char model[32];
0029     char serial[40];
0030     char bus_info[32];
0031     __u32 media_version;
0032     __u32 hw_revision;
0033     __u32 driver_version;
0034     __u32 reserved[31];
0035 };
0036 
0037 /*
0038  * Base number ranges for entity functions
0039  *
0040  * NOTE: Userspace should not rely on these ranges to identify a group
0041  * of function types, as newer functions can be added with any name within
0042  * the full u32 range.
0043  *
0044  * Some older functions use the MEDIA_ENT_F_OLD_*_BASE range. Do not
0045  * change this, this is for backwards compatibility. When adding new
0046  * functions always use MEDIA_ENT_F_BASE.
0047  */
0048 #define MEDIA_ENT_F_BASE            0x00000000
0049 #define MEDIA_ENT_F_OLD_BASE            0x00010000
0050 #define MEDIA_ENT_F_OLD_SUBDEV_BASE     0x00020000
0051 
0052 /*
0053  * Initial value to be used when a new entity is created
0054  * Drivers should change it to something useful.
0055  */
0056 #define MEDIA_ENT_F_UNKNOWN         MEDIA_ENT_F_BASE
0057 
0058 /*
0059  * Subdevs are initialized with MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN in order
0060  * to preserve backward compatibility. Drivers must change to the proper
0061  * subdev type before registering the entity.
0062  */
0063 #define MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN     MEDIA_ENT_F_OLD_SUBDEV_BASE
0064 
0065 /*
0066  * DVB entity functions
0067  */
0068 #define MEDIA_ENT_F_DTV_DEMOD           (MEDIA_ENT_F_BASE + 0x00001)
0069 #define MEDIA_ENT_F_TS_DEMUX            (MEDIA_ENT_F_BASE + 0x00002)
0070 #define MEDIA_ENT_F_DTV_CA          (MEDIA_ENT_F_BASE + 0x00003)
0071 #define MEDIA_ENT_F_DTV_NET_DECAP       (MEDIA_ENT_F_BASE + 0x00004)
0072 
0073 /*
0074  * I/O entity functions
0075  */
0076 #define MEDIA_ENT_F_IO_V4L          (MEDIA_ENT_F_OLD_BASE + 1)
0077 #define MEDIA_ENT_F_IO_DTV          (MEDIA_ENT_F_BASE + 0x01001)
0078 #define MEDIA_ENT_F_IO_VBI          (MEDIA_ENT_F_BASE + 0x01002)
0079 #define MEDIA_ENT_F_IO_SWRADIO          (MEDIA_ENT_F_BASE + 0x01003)
0080 
0081 /*
0082  * Sensor functions
0083  */
0084 #define MEDIA_ENT_F_CAM_SENSOR          (MEDIA_ENT_F_OLD_SUBDEV_BASE + 1)
0085 #define MEDIA_ENT_F_FLASH           (MEDIA_ENT_F_OLD_SUBDEV_BASE + 2)
0086 #define MEDIA_ENT_F_LENS            (MEDIA_ENT_F_OLD_SUBDEV_BASE + 3)
0087 
0088 /*
0089  * Digital TV, analog TV, radio and/or software defined radio tuner functions.
0090  *
0091  * It is a responsibility of the master/bridge drivers to add connectors
0092  * and links for MEDIA_ENT_F_TUNER. Please notice that some old tuners
0093  * may require the usage of separate I2C chips to decode analog TV signals,
0094  * when the master/bridge chipset doesn't have its own TV standard decoder.
0095  * On such cases, the IF-PLL staging is mapped via one or two entities:
0096  * MEDIA_ENT_F_IF_VID_DECODER and/or MEDIA_ENT_F_IF_AUD_DECODER.
0097  */
0098 #define MEDIA_ENT_F_TUNER           (MEDIA_ENT_F_OLD_SUBDEV_BASE + 5)
0099 
0100 /*
0101  * Analog TV IF-PLL decoder functions
0102  *
0103  * It is a responsibility of the master/bridge drivers to create links
0104  * for MEDIA_ENT_F_IF_VID_DECODER and MEDIA_ENT_F_IF_AUD_DECODER.
0105  */
0106 #define MEDIA_ENT_F_IF_VID_DECODER      (MEDIA_ENT_F_BASE + 0x02001)
0107 #define MEDIA_ENT_F_IF_AUD_DECODER      (MEDIA_ENT_F_BASE + 0x02002)
0108 
0109 /*
0110  * Audio entity functions
0111  */
0112 #define MEDIA_ENT_F_AUDIO_CAPTURE       (MEDIA_ENT_F_BASE + 0x03001)
0113 #define MEDIA_ENT_F_AUDIO_PLAYBACK      (MEDIA_ENT_F_BASE + 0x03002)
0114 #define MEDIA_ENT_F_AUDIO_MIXER         (MEDIA_ENT_F_BASE + 0x03003)
0115 
0116 /*
0117  * Processing entity functions
0118  */
0119 #define MEDIA_ENT_F_PROC_VIDEO_COMPOSER     (MEDIA_ENT_F_BASE + 0x4001)
0120 #define MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER  (MEDIA_ENT_F_BASE + 0x4002)
0121 #define MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV   (MEDIA_ENT_F_BASE + 0x4003)
0122 #define MEDIA_ENT_F_PROC_VIDEO_LUT      (MEDIA_ENT_F_BASE + 0x4004)
0123 #define MEDIA_ENT_F_PROC_VIDEO_SCALER       (MEDIA_ENT_F_BASE + 0x4005)
0124 #define MEDIA_ENT_F_PROC_VIDEO_STATISTICS   (MEDIA_ENT_F_BASE + 0x4006)
0125 #define MEDIA_ENT_F_PROC_VIDEO_ENCODER      (MEDIA_ENT_F_BASE + 0x4007)
0126 #define MEDIA_ENT_F_PROC_VIDEO_DECODER      (MEDIA_ENT_F_BASE + 0x4008)
0127 #define MEDIA_ENT_F_PROC_VIDEO_ISP      (MEDIA_ENT_F_BASE + 0x4009)
0128 
0129 /*
0130  * Switch and bridge entity functions
0131  */
0132 #define MEDIA_ENT_F_VID_MUX         (MEDIA_ENT_F_BASE + 0x5001)
0133 #define MEDIA_ENT_F_VID_IF_BRIDGE       (MEDIA_ENT_F_BASE + 0x5002)
0134 
0135 /*
0136  * Video decoder/encoder functions
0137  */
0138 #define MEDIA_ENT_F_ATV_DECODER         (MEDIA_ENT_F_OLD_SUBDEV_BASE + 4)
0139 #define MEDIA_ENT_F_DV_DECODER          (MEDIA_ENT_F_BASE + 0x6001)
0140 #define MEDIA_ENT_F_DV_ENCODER          (MEDIA_ENT_F_BASE + 0x6002)
0141 
0142 /* Entity flags */
0143 #define MEDIA_ENT_FL_DEFAULT            (1 << 0)
0144 #define MEDIA_ENT_FL_CONNECTOR          (1 << 1)
0145 
0146 /* OR with the entity id value to find the next entity */
0147 #define MEDIA_ENT_ID_FLAG_NEXT          (1U << 31)
0148 
0149 struct media_entity_desc {
0150     __u32 id;
0151     char name[32];
0152     __u32 type;
0153     __u32 revision;
0154     __u32 flags;
0155     __u32 group_id;
0156     __u16 pads;
0157     __u16 links;
0158 
0159     __u32 reserved[4];
0160 
0161     union {
0162         /* Node specifications */
0163         struct {
0164             __u32 major;
0165             __u32 minor;
0166         } dev;
0167 
0168 #if !defined(__KERNEL__)
0169         /*
0170          * TODO: this shouldn't have been added without
0171          * actual drivers that use this. When the first real driver
0172          * appears that sets this information, special attention
0173          * should be given whether this information is 1) enough, and
0174          * 2) can deal with udev rules that rename devices. The struct
0175          * dev would not be sufficient for this since that does not
0176          * contain the subdevice information. In addition, struct dev
0177          * can only refer to a single device, and not to multiple (e.g.
0178          * pcm and mixer devices).
0179          */
0180         struct {
0181             __u32 card;
0182             __u32 device;
0183             __u32 subdevice;
0184         } alsa;
0185 
0186         /*
0187          * DEPRECATED: previous node specifications. Kept just to
0188          * avoid breaking compilation. Use media_entity_desc.dev
0189          * instead.
0190          */
0191         struct {
0192             __u32 major;
0193             __u32 minor;
0194         } v4l;
0195         struct {
0196             __u32 major;
0197             __u32 minor;
0198         } fb;
0199         int dvb;
0200 #endif
0201 
0202         /* Sub-device specifications */
0203         /* Nothing needed yet */
0204         __u8 raw[184];
0205     };
0206 };
0207 
0208 #define MEDIA_PAD_FL_SINK           (1 << 0)
0209 #define MEDIA_PAD_FL_SOURCE         (1 << 1)
0210 #define MEDIA_PAD_FL_MUST_CONNECT       (1 << 2)
0211 
0212 struct media_pad_desc {
0213     __u32 entity;       /* entity ID */
0214     __u16 index;        /* pad index */
0215     __u32 flags;        /* pad flags */
0216     __u32 reserved[2];
0217 };
0218 
0219 #define MEDIA_LNK_FL_ENABLED            (1 << 0)
0220 #define MEDIA_LNK_FL_IMMUTABLE          (1 << 1)
0221 #define MEDIA_LNK_FL_DYNAMIC            (1 << 2)
0222 
0223 #define MEDIA_LNK_FL_LINK_TYPE          (0xf << 28)
0224 #  define MEDIA_LNK_FL_DATA_LINK        (0 << 28)
0225 #  define MEDIA_LNK_FL_INTERFACE_LINK       (1 << 28)
0226 #  define MEDIA_LNK_FL_ANCILLARY_LINK       (2 << 28)
0227 
0228 struct media_link_desc {
0229     struct media_pad_desc source;
0230     struct media_pad_desc sink;
0231     __u32 flags;
0232     __u32 reserved[2];
0233 };
0234 
0235 struct media_links_enum {
0236     __u32 entity;
0237     /* Should have enough room for pads elements */
0238     struct media_pad_desc __user *pads;
0239     /* Should have enough room for links elements */
0240     struct media_link_desc __user *links;
0241     __u32 reserved[4];
0242 };
0243 
0244 /* Interface type ranges */
0245 
0246 #define MEDIA_INTF_T_DVB_BASE           0x00000100
0247 #define MEDIA_INTF_T_V4L_BASE           0x00000200
0248 
0249 /* Interface types */
0250 
0251 #define MEDIA_INTF_T_DVB_FE         (MEDIA_INTF_T_DVB_BASE)
0252 #define MEDIA_INTF_T_DVB_DEMUX          (MEDIA_INTF_T_DVB_BASE + 1)
0253 #define MEDIA_INTF_T_DVB_DVR            (MEDIA_INTF_T_DVB_BASE + 2)
0254 #define MEDIA_INTF_T_DVB_CA         (MEDIA_INTF_T_DVB_BASE + 3)
0255 #define MEDIA_INTF_T_DVB_NET            (MEDIA_INTF_T_DVB_BASE + 4)
0256 
0257 #define MEDIA_INTF_T_V4L_VIDEO          (MEDIA_INTF_T_V4L_BASE)
0258 #define MEDIA_INTF_T_V4L_VBI            (MEDIA_INTF_T_V4L_BASE + 1)
0259 #define MEDIA_INTF_T_V4L_RADIO          (MEDIA_INTF_T_V4L_BASE + 2)
0260 #define MEDIA_INTF_T_V4L_SUBDEV         (MEDIA_INTF_T_V4L_BASE + 3)
0261 #define MEDIA_INTF_T_V4L_SWRADIO        (MEDIA_INTF_T_V4L_BASE + 4)
0262 #define MEDIA_INTF_T_V4L_TOUCH          (MEDIA_INTF_T_V4L_BASE + 5)
0263 
0264 #define MEDIA_INTF_T_ALSA_BASE          0x00000300
0265 #define MEDIA_INTF_T_ALSA_PCM_CAPTURE       (MEDIA_INTF_T_ALSA_BASE)
0266 #define MEDIA_INTF_T_ALSA_PCM_PLAYBACK      (MEDIA_INTF_T_ALSA_BASE + 1)
0267 #define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
0268 
0269 #if defined(__KERNEL__)
0270 
0271 /*
0272  * Connector functions
0273  *
0274  * For now these should not be used in userspace, as some definitions may
0275  * change.
0276  *
0277  * It is the responsibility of the entity drivers to add connectors and links.
0278  */
0279 #define MEDIA_ENT_F_CONN_RF         (MEDIA_ENT_F_BASE + 0x30001)
0280 #define MEDIA_ENT_F_CONN_SVIDEO         (MEDIA_ENT_F_BASE + 0x30002)
0281 #define MEDIA_ENT_F_CONN_COMPOSITE      (MEDIA_ENT_F_BASE + 0x30003)
0282 
0283 #endif
0284 
0285 /*
0286  * MC next gen API definitions
0287  */
0288 
0289 /*
0290  * Appeared in 4.19.0.
0291  *
0292  * The media_version argument comes from the media_version field in
0293  * struct media_device_info.
0294  */
0295 #define MEDIA_V2_ENTITY_HAS_FLAGS(media_version) \
0296     ((media_version) >= ((4 << 16) | (19 << 8) | 0))
0297 
0298 struct media_v2_entity {
0299     __u32 id;
0300     char name[64];
0301     __u32 function;     /* Main function of the entity */
0302     __u32 flags;
0303     __u32 reserved[5];
0304 } __attribute__ ((packed));
0305 
0306 /* Should match the specific fields at media_intf_devnode */
0307 struct media_v2_intf_devnode {
0308     __u32 major;
0309     __u32 minor;
0310 } __attribute__ ((packed));
0311 
0312 struct media_v2_interface {
0313     __u32 id;
0314     __u32 intf_type;
0315     __u32 flags;
0316     __u32 reserved[9];
0317 
0318     union {
0319         struct media_v2_intf_devnode devnode;
0320         __u32 raw[16];
0321     };
0322 } __attribute__ ((packed));
0323 
0324 /*
0325  * Appeared in 4.19.0.
0326  *
0327  * The media_version argument comes from the media_version field in
0328  * struct media_device_info.
0329  */
0330 #define MEDIA_V2_PAD_HAS_INDEX(media_version) \
0331     ((media_version) >= ((4 << 16) | (19 << 8) | 0))
0332 
0333 struct media_v2_pad {
0334     __u32 id;
0335     __u32 entity_id;
0336     __u32 flags;
0337     __u32 index;
0338     __u32 reserved[4];
0339 } __attribute__ ((packed));
0340 
0341 struct media_v2_link {
0342     __u32 id;
0343     __u32 source_id;
0344     __u32 sink_id;
0345     __u32 flags;
0346     __u32 reserved[6];
0347 } __attribute__ ((packed));
0348 
0349 struct media_v2_topology {
0350     __u64 topology_version;
0351 
0352     __u32 num_entities;
0353     __u32 reserved1;
0354     __u64 ptr_entities;
0355 
0356     __u32 num_interfaces;
0357     __u32 reserved2;
0358     __u64 ptr_interfaces;
0359 
0360     __u32 num_pads;
0361     __u32 reserved3;
0362     __u64 ptr_pads;
0363 
0364     __u32 num_links;
0365     __u32 reserved4;
0366     __u64 ptr_links;
0367 } __attribute__ ((packed));
0368 
0369 /* ioctls */
0370 
0371 #define MEDIA_IOC_DEVICE_INFO   _IOWR('|', 0x00, struct media_device_info)
0372 #define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc)
0373 #define MEDIA_IOC_ENUM_LINKS    _IOWR('|', 0x02, struct media_links_enum)
0374 #define MEDIA_IOC_SETUP_LINK    _IOWR('|', 0x03, struct media_link_desc)
0375 #define MEDIA_IOC_G_TOPOLOGY    _IOWR('|', 0x04, struct media_v2_topology)
0376 #define MEDIA_IOC_REQUEST_ALLOC _IOR ('|', 0x05, int)
0377 
0378 /*
0379  * These ioctls are called on the request file descriptor as returned
0380  * by MEDIA_IOC_REQUEST_ALLOC.
0381  */
0382 #define MEDIA_REQUEST_IOC_QUEUE     _IO('|',  0x80)
0383 #define MEDIA_REQUEST_IOC_REINIT    _IO('|',  0x81)
0384 
0385 #ifndef __KERNEL__
0386 
0387 /*
0388  * Legacy symbols used to avoid userspace compilation breakages.
0389  * Do not use any of this in new applications!
0390  *
0391  * Those symbols map the entity function into types and should be
0392  * used only on legacy programs for legacy hardware. Don't rely
0393  * on those for MEDIA_IOC_G_TOPOLOGY.
0394  */
0395 #define MEDIA_ENT_TYPE_SHIFT            16
0396 #define MEDIA_ENT_TYPE_MASK         0x00ff0000
0397 #define MEDIA_ENT_SUBTYPE_MASK          0x0000ffff
0398 
0399 #define MEDIA_ENT_T_DEVNODE_UNKNOWN     (MEDIA_ENT_F_OLD_BASE | \
0400                          MEDIA_ENT_SUBTYPE_MASK)
0401 
0402 #define MEDIA_ENT_T_DEVNODE         MEDIA_ENT_F_OLD_BASE
0403 #define MEDIA_ENT_T_DEVNODE_V4L         MEDIA_ENT_F_IO_V4L
0404 #define MEDIA_ENT_T_DEVNODE_FB          (MEDIA_ENT_F_OLD_BASE + 2)
0405 #define MEDIA_ENT_T_DEVNODE_ALSA        (MEDIA_ENT_F_OLD_BASE + 3)
0406 #define MEDIA_ENT_T_DEVNODE_DVB         (MEDIA_ENT_F_OLD_BASE + 4)
0407 
0408 #define MEDIA_ENT_T_UNKNOWN         MEDIA_ENT_F_UNKNOWN
0409 #define MEDIA_ENT_T_V4L2_VIDEO          MEDIA_ENT_F_IO_V4L
0410 #define MEDIA_ENT_T_V4L2_SUBDEV         MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
0411 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR      MEDIA_ENT_F_CAM_SENSOR
0412 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH       MEDIA_ENT_F_FLASH
0413 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS        MEDIA_ENT_F_LENS
0414 #define MEDIA_ENT_T_V4L2_SUBDEV_DECODER     MEDIA_ENT_F_ATV_DECODER
0415 #define MEDIA_ENT_T_V4L2_SUBDEV_TUNER       MEDIA_ENT_F_TUNER
0416 
0417 #define MEDIA_ENT_F_DTV_DECODER         MEDIA_ENT_F_DV_DECODER
0418 
0419 /*
0420  * There is still no full ALSA support in the media controller. These
0421  * defines should not have been added and we leave them here only
0422  * in case some application tries to use these defines.
0423  *
0424  * The ALSA defines that are in use have been moved into __KERNEL__
0425  * scope. As support gets added to these interface types, they should
0426  * be moved into __KERNEL__ scope with the code that uses them.
0427  */
0428 #define MEDIA_INTF_T_ALSA_COMPRESS             (MEDIA_INTF_T_ALSA_BASE + 3)
0429 #define MEDIA_INTF_T_ALSA_RAWMIDI              (MEDIA_INTF_T_ALSA_BASE + 4)
0430 #define MEDIA_INTF_T_ALSA_HWDEP                (MEDIA_INTF_T_ALSA_BASE + 5)
0431 #define MEDIA_INTF_T_ALSA_SEQUENCER            (MEDIA_INTF_T_ALSA_BASE + 6)
0432 #define MEDIA_INTF_T_ALSA_TIMER                (MEDIA_INTF_T_ALSA_BASE + 7)
0433 
0434 /* Obsolete symbol for media_version, no longer used in the kernel */
0435 #define MEDIA_API_VERSION           ((0 << 16) | (1 << 8) | 0)
0436 
0437 #endif
0438 
0439 #endif /* __LINUX_MEDIA_H */