Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / gpu / drm / shmobile / shmob_drm_kms.c
blobd36919b14da76bacf8b23e8e9a92f8b5fb90c89a
1 /*
2 * shmob_drm_kms.c -- SH Mobile DRM Mode Setting
4 * Copyright (C) 2012 Renesas Electronics Corporation
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <drm/drmP.h>
15 #include <drm/drm_crtc.h>
16 #include <drm/drm_crtc_helper.h>
17 #include <drm/drm_fb_cma_helper.h>
18 #include <drm/drm_gem_cma_helper.h>
19 #include <drm/drm_gem_framebuffer_helper.h>
21 #include <video/sh_mobile_meram.h>
23 #include "shmob_drm_crtc.h"
24 #include "shmob_drm_drv.h"
25 #include "shmob_drm_kms.h"
26 #include "shmob_drm_regs.h"
28 /* -----------------------------------------------------------------------------
29 * Format helpers
32 static const struct shmob_drm_format_info shmob_drm_format_infos[] = {
34 .fourcc = DRM_FORMAT_RGB565,
35 .bpp = 16,
36 .yuv = false,
37 .lddfr = LDDFR_PKF_RGB16,
38 .meram = SH_MOBILE_MERAM_PF_RGB,
39 }, {
40 .fourcc = DRM_FORMAT_RGB888,
41 .bpp = 24,
42 .yuv = false,
43 .lddfr = LDDFR_PKF_RGB24,
44 .meram = SH_MOBILE_MERAM_PF_RGB,
45 }, {
46 .fourcc = DRM_FORMAT_ARGB8888,
47 .bpp = 32,
48 .yuv = false,
49 .lddfr = LDDFR_PKF_ARGB32,
50 .meram = SH_MOBILE_MERAM_PF_RGB,
51 }, {
52 .fourcc = DRM_FORMAT_NV12,
53 .bpp = 12,
54 .yuv = true,
55 .lddfr = LDDFR_CC | LDDFR_YF_420,
56 .meram = SH_MOBILE_MERAM_PF_NV,
57 }, {
58 .fourcc = DRM_FORMAT_NV21,
59 .bpp = 12,
60 .yuv = true,
61 .lddfr = LDDFR_CC | LDDFR_YF_420,
62 .meram = SH_MOBILE_MERAM_PF_NV,
63 }, {
64 .fourcc = DRM_FORMAT_NV16,
65 .bpp = 16,
66 .yuv = true,
67 .lddfr = LDDFR_CC | LDDFR_YF_422,
68 .meram = SH_MOBILE_MERAM_PF_NV,
69 }, {
70 .fourcc = DRM_FORMAT_NV61,
71 .bpp = 16,
72 .yuv = true,
73 .lddfr = LDDFR_CC | LDDFR_YF_422,
74 .meram = SH_MOBILE_MERAM_PF_NV,
75 }, {
76 .fourcc = DRM_FORMAT_NV24,
77 .bpp = 24,
78 .yuv = true,
79 .lddfr = LDDFR_CC | LDDFR_YF_444,
80 .meram = SH_MOBILE_MERAM_PF_NV24,
81 }, {
82 .fourcc = DRM_FORMAT_NV42,
83 .bpp = 24,
84 .yuv = true,
85 .lddfr = LDDFR_CC | LDDFR_YF_444,
86 .meram = SH_MOBILE_MERAM_PF_NV24,
90 const struct shmob_drm_format_info *shmob_drm_format_info(u32 fourcc)
92 unsigned int i;
94 for (i = 0; i < ARRAY_SIZE(shmob_drm_format_infos); ++i) {
95 if (shmob_drm_format_infos[i].fourcc == fourcc)
96 return &shmob_drm_format_infos[i];
99 return NULL;
102 /* -----------------------------------------------------------------------------
103 * Frame buffer
106 static struct drm_framebuffer *
107 shmob_drm_fb_create(struct drm_device *dev, struct drm_file *file_priv,
108 const struct drm_mode_fb_cmd2 *mode_cmd)
110 const struct shmob_drm_format_info *format;
112 format = shmob_drm_format_info(mode_cmd->pixel_format);
113 if (format == NULL) {
114 dev_dbg(dev->dev, "unsupported pixel format %08x\n",
115 mode_cmd->pixel_format);
116 return ERR_PTR(-EINVAL);
119 if (mode_cmd->pitches[0] & 7 || mode_cmd->pitches[0] >= 65536) {
120 dev_dbg(dev->dev, "invalid pitch value %u\n",
121 mode_cmd->pitches[0]);
122 return ERR_PTR(-EINVAL);
125 if (format->yuv) {
126 unsigned int chroma_cpp = format->bpp == 24 ? 2 : 1;
128 if (mode_cmd->pitches[1] != mode_cmd->pitches[0] * chroma_cpp) {
129 dev_dbg(dev->dev,
130 "luma and chroma pitches do not match\n");
131 return ERR_PTR(-EINVAL);
135 return drm_gem_fb_create(dev, file_priv, mode_cmd);
138 static const struct drm_mode_config_funcs shmob_drm_mode_config_funcs = {
139 .fb_create = shmob_drm_fb_create,
142 int shmob_drm_modeset_init(struct shmob_drm_device *sdev)
144 drm_mode_config_init(sdev->ddev);
146 shmob_drm_crtc_create(sdev);
147 shmob_drm_encoder_create(sdev);
148 shmob_drm_connector_create(sdev, &sdev->encoder.encoder);
150 drm_kms_helper_poll_init(sdev->ddev);
152 sdev->ddev->mode_config.min_width = 0;
153 sdev->ddev->mode_config.min_height = 0;
154 sdev->ddev->mode_config.max_width = 4095;
155 sdev->ddev->mode_config.max_height = 4095;
156 sdev->ddev->mode_config.funcs = &shmob_drm_mode_config_funcs;
158 drm_helper_disable_unused_functions(sdev->ddev);
160 return 0;