]> Git Repo - linux.git/blob - drivers/gpu/drm/shmobile/shmob_drm_kms.c
Merge branch 'sched-wait-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / drivers / gpu / drm / shmobile / shmob_drm_kms.c
1 /*
2  * shmob_drm_kms.c  --  SH Mobile DRM Mode Setting
3  *
4  * Copyright (C) 2012 Renesas Electronics Corporation
5  *
6  * Laurent Pinchart ([email protected])
7  *
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.
12  */
13
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>
20
21 #include <video/sh_mobile_meram.h>
22
23 #include "shmob_drm_crtc.h"
24 #include "shmob_drm_drv.h"
25 #include "shmob_drm_kms.h"
26 #include "shmob_drm_regs.h"
27
28 /* -----------------------------------------------------------------------------
29  * Format helpers
30  */
31
32 static const struct shmob_drm_format_info shmob_drm_format_infos[] = {
33         {
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,
87         },
88 };
89
90 const struct shmob_drm_format_info *shmob_drm_format_info(u32 fourcc)
91 {
92         unsigned int i;
93
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];
97         }
98
99         return NULL;
100 }
101
102 /* -----------------------------------------------------------------------------
103  * Frame buffer
104  */
105
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)
109 {
110         const struct shmob_drm_format_info *format;
111
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);
117         }
118
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);
123         }
124
125         if (format->yuv) {
126                 unsigned int chroma_cpp = format->bpp == 24 ? 2 : 1;
127
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);
132                 }
133         }
134
135         return drm_gem_fb_create(dev, file_priv, mode_cmd);
136 }
137
138 static const struct drm_mode_config_funcs shmob_drm_mode_config_funcs = {
139         .fb_create = shmob_drm_fb_create,
140 };
141
142 int shmob_drm_modeset_init(struct shmob_drm_device *sdev)
143 {
144         drm_mode_config_init(sdev->ddev);
145
146         shmob_drm_crtc_create(sdev);
147         shmob_drm_encoder_create(sdev);
148         shmob_drm_connector_create(sdev, &sdev->encoder.encoder);
149
150         drm_kms_helper_poll_init(sdev->ddev);
151
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;
157
158         drm_helper_disable_unused_functions(sdev->ddev);
159
160         return 0;
161 }
This page took 0.042919 seconds and 4 git commands to generate.