xref: /openbmc/linux/include/drm/drm_fourcc.h (revision 9c71a668)
1ae4df11aSLaurent Pinchart /*
2ae4df11aSLaurent Pinchart  * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3ae4df11aSLaurent Pinchart  *
4ae4df11aSLaurent Pinchart  * Permission to use, copy, modify, distribute, and sell this software and its
5ae4df11aSLaurent Pinchart  * documentation for any purpose is hereby granted without fee, provided that
6ae4df11aSLaurent Pinchart  * the above copyright notice appear in all copies and that both that copyright
7ae4df11aSLaurent Pinchart  * notice and this permission notice appear in supporting documentation, and
8ae4df11aSLaurent Pinchart  * that the name of the copyright holders not be used in advertising or
9ae4df11aSLaurent Pinchart  * publicity pertaining to distribution of the software without specific,
10ae4df11aSLaurent Pinchart  * written prior permission.  The copyright holders make no representations
11ae4df11aSLaurent Pinchart  * about the suitability of this software for any purpose.  It is provided "as
12ae4df11aSLaurent Pinchart  * is" without express or implied warranty.
13ae4df11aSLaurent Pinchart  *
14ae4df11aSLaurent Pinchart  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15ae4df11aSLaurent Pinchart  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16ae4df11aSLaurent Pinchart  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17ae4df11aSLaurent Pinchart  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18ae4df11aSLaurent Pinchart  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19ae4df11aSLaurent Pinchart  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20ae4df11aSLaurent Pinchart  * OF THIS SOFTWARE.
21ae4df11aSLaurent Pinchart  */
22ae4df11aSLaurent Pinchart #ifndef __DRM_FOURCC_H__
23ae4df11aSLaurent Pinchart #define __DRM_FOURCC_H__
24ae4df11aSLaurent Pinchart 
25ae4df11aSLaurent Pinchart #include <linux/types.h>
26ae4df11aSLaurent Pinchart #include <uapi/drm/drm_fourcc.h>
27ae4df11aSLaurent Pinchart 
28ec2fae25SGerd Hoffmann /*
29ec2fae25SGerd Hoffmann  * DRM formats are little endian.  Define host endian variants for the
30ec2fae25SGerd Hoffmann  * most common formats here, to reduce the #ifdefs needed in drivers.
31ec2fae25SGerd Hoffmann  *
32ec2fae25SGerd Hoffmann  * Note that the DRM_FORMAT_BIG_ENDIAN flag should only be used in
33ec2fae25SGerd Hoffmann  * case the format can't be specified otherwise, so we don't end up
34ec2fae25SGerd Hoffmann  * with two values describing the same format.
35ec2fae25SGerd Hoffmann  */
36ec2fae25SGerd Hoffmann #ifdef __BIG_ENDIAN
37ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_XRGB1555     (DRM_FORMAT_XRGB1555         |	\
38ec2fae25SGerd Hoffmann 				       DRM_FORMAT_BIG_ENDIAN)
39ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_RGB565       (DRM_FORMAT_RGB565           |	\
40ec2fae25SGerd Hoffmann 				       DRM_FORMAT_BIG_ENDIAN)
41ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_XRGB8888     DRM_FORMAT_BGRX8888
42ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_ARGB8888     DRM_FORMAT_BGRA8888
43ec2fae25SGerd Hoffmann #else
44ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_XRGB1555     DRM_FORMAT_XRGB1555
45ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_RGB565       DRM_FORMAT_RGB565
46ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_XRGB8888     DRM_FORMAT_XRGB8888
47ec2fae25SGerd Hoffmann # define DRM_FORMAT_HOST_ARGB8888     DRM_FORMAT_ARGB8888
48ec2fae25SGerd Hoffmann #endif
49ec2fae25SGerd Hoffmann 
506a0f9ebfSVille Syrjälä struct drm_device;
516a0f9ebfSVille Syrjälä struct drm_mode_fb_cmd2;
526a0f9ebfSVille Syrjälä 
5384770cc2SLaurent Pinchart /**
5484770cc2SLaurent Pinchart  * struct drm_format_info - information about a DRM format
5584770cc2SLaurent Pinchart  */
5684770cc2SLaurent Pinchart struct drm_format_info {
579c71a668SAlexandru Gheorghe 	/** @format: 4CC format identifier (DRM_FORMAT_*) */
5884770cc2SLaurent Pinchart 	u32 format;
599c71a668SAlexandru Gheorghe 
609c71a668SAlexandru Gheorghe 	/**
619c71a668SAlexandru Gheorghe 	 * @depth:
629c71a668SAlexandru Gheorghe 	 *
639c71a668SAlexandru Gheorghe 	 * Color depth (number of bits per pixel excluding padding bits),
649c71a668SAlexandru Gheorghe 	 * valid for a subset of RGB formats only. This is a legacy field, do
659c71a668SAlexandru Gheorghe 	 * not use in new code and set to 0 for new formats.
669c71a668SAlexandru Gheorghe 	 */
6784770cc2SLaurent Pinchart 	u8 depth;
689c71a668SAlexandru Gheorghe 
699c71a668SAlexandru Gheorghe 	/** @num_planes: Number of color planes (1 to 3) */
7084770cc2SLaurent Pinchart 	u8 num_planes;
719c71a668SAlexandru Gheorghe 
729c71a668SAlexandru Gheorghe 	/** @cpp: Number of bytes per pixel (per plane) */
7384770cc2SLaurent Pinchart 	u8 cpp[3];
749c71a668SAlexandru Gheorghe 
759c71a668SAlexandru Gheorghe 	/** @hsub: Horizontal chroma subsampling factor */
7684770cc2SLaurent Pinchart 	u8 hsub;
779c71a668SAlexandru Gheorghe 	/** @vsub: Vertical chroma subsampling factor */
7884770cc2SLaurent Pinchart 	u8 vsub;
799c71a668SAlexandru Gheorghe 
809c71a668SAlexandru Gheorghe 	/** @has_alpha: Does the format embeds an alpha component? */
814cc4e1b4SMaxime Ripard 	bool has_alpha;
829c71a668SAlexandru Gheorghe 
839c71a668SAlexandru Gheorghe 	/** @is_yuv: Is it a YUV format? */
84ce2d5461SAyan Kumar Halder 	bool is_yuv;
8584770cc2SLaurent Pinchart };
8684770cc2SLaurent Pinchart 
87b3c11ac2SEric Engestrom /**
88b3c11ac2SEric Engestrom  * struct drm_format_name_buf - name of a DRM format
89b3c11ac2SEric Engestrom  * @str: string buffer containing the format name
90b3c11ac2SEric Engestrom  */
91b3c11ac2SEric Engestrom struct drm_format_name_buf {
92b3c11ac2SEric Engestrom 	char str[32];
93b3c11ac2SEric Engestrom };
94b3c11ac2SEric Engestrom 
95333d2da5SLaurent Pinchart const struct drm_format_info *__drm_format_info(u32 format);
9684770cc2SLaurent Pinchart const struct drm_format_info *drm_format_info(u32 format);
976a0f9ebfSVille Syrjälä const struct drm_format_info *
986a0f9ebfSVille Syrjälä drm_get_format_info(struct drm_device *dev,
996a0f9ebfSVille Syrjälä 		    const struct drm_mode_fb_cmd2 *mode_cmd);
100ec5e3047SDaniel Vetter uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
101059b5eb5SGerd Hoffmann uint32_t drm_driver_legacy_fb_format(struct drm_device *dev,
102059b5eb5SGerd Hoffmann 				     uint32_t bpp, uint32_t depth);
103ae4df11aSLaurent Pinchart int drm_format_num_planes(uint32_t format);
104ae4df11aSLaurent Pinchart int drm_format_plane_cpp(uint32_t format, int plane);
105ae4df11aSLaurent Pinchart int drm_format_horz_chroma_subsampling(uint32_t format);
106ae4df11aSLaurent Pinchart int drm_format_vert_chroma_subsampling(uint32_t format);
107ae4df11aSLaurent Pinchart int drm_format_plane_width(int width, uint32_t format, int plane);
108ae4df11aSLaurent Pinchart int drm_format_plane_height(int height, uint32_t format, int plane);
109b3c11ac2SEric Engestrom const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
110ae4df11aSLaurent Pinchart 
111ae4df11aSLaurent Pinchart #endif /* __DRM_FOURCC_H__ */
112