1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (C) 2013-2015 ARM Limited
3*4882a593Smuzhiyun * Author: Liviu Dudau <Liviu.Dudau@arm.com>
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public
6*4882a593Smuzhiyun * License. See the file COPYING in the main directory of this archive
7*4882a593Smuzhiyun * for more details.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Implementation of a CRTC class for the HDLCD driver.
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include <linux/clk.h>
13*4882a593Smuzhiyun #include <linux/of_graph.h>
14*4882a593Smuzhiyun #include <linux/platform_data/simplefb.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <video/videomode.h>
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <drm/drm_atomic.h>
19*4882a593Smuzhiyun #include <drm/drm_atomic_helper.h>
20*4882a593Smuzhiyun #include <drm/drm_crtc.h>
21*4882a593Smuzhiyun #include <drm/drm_fb_cma_helper.h>
22*4882a593Smuzhiyun #include <drm/drm_fb_helper.h>
23*4882a593Smuzhiyun #include <drm/drm_gem_cma_helper.h>
24*4882a593Smuzhiyun #include <drm/drm_of.h>
25*4882a593Smuzhiyun #include <drm/drm_plane_helper.h>
26*4882a593Smuzhiyun #include <drm/drm_probe_helper.h>
27*4882a593Smuzhiyun #include <drm/drm_vblank.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include "hdlcd_drv.h"
30*4882a593Smuzhiyun #include "hdlcd_regs.h"
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /*
33*4882a593Smuzhiyun * The HDLCD controller is a dumb RGB streamer that gets connected to
34*4882a593Smuzhiyun * a single HDMI transmitter or in the case of the ARM Models it gets
35*4882a593Smuzhiyun * emulated by the software that does the actual rendering.
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun */
38*4882a593Smuzhiyun
hdlcd_crtc_cleanup(struct drm_crtc * crtc)39*4882a593Smuzhiyun static void hdlcd_crtc_cleanup(struct drm_crtc *crtc)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /* stop the controller on cleanup */
44*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0);
45*4882a593Smuzhiyun drm_crtc_cleanup(crtc);
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
hdlcd_crtc_enable_vblank(struct drm_crtc * crtc)48*4882a593Smuzhiyun static int hdlcd_crtc_enable_vblank(struct drm_crtc *crtc)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
51*4882a593Smuzhiyun unsigned int mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask | HDLCD_INTERRUPT_VSYNC);
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun return 0;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
hdlcd_crtc_disable_vblank(struct drm_crtc * crtc)58*4882a593Smuzhiyun static void hdlcd_crtc_disable_vblank(struct drm_crtc *crtc)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
61*4882a593Smuzhiyun unsigned int mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK);
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask & ~HDLCD_INTERRUPT_VSYNC);
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun static const struct drm_crtc_funcs hdlcd_crtc_funcs = {
67*4882a593Smuzhiyun .destroy = hdlcd_crtc_cleanup,
68*4882a593Smuzhiyun .set_config = drm_atomic_helper_set_config,
69*4882a593Smuzhiyun .page_flip = drm_atomic_helper_page_flip,
70*4882a593Smuzhiyun .reset = drm_atomic_helper_crtc_reset,
71*4882a593Smuzhiyun .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
72*4882a593Smuzhiyun .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
73*4882a593Smuzhiyun .enable_vblank = hdlcd_crtc_enable_vblank,
74*4882a593Smuzhiyun .disable_vblank = hdlcd_crtc_disable_vblank,
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun static struct simplefb_format supported_formats[] = SIMPLEFB_FORMATS;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun /*
80*4882a593Smuzhiyun * Setup the HDLCD registers for decoding the pixels out of the framebuffer
81*4882a593Smuzhiyun */
hdlcd_set_pxl_fmt(struct drm_crtc * crtc)82*4882a593Smuzhiyun static int hdlcd_set_pxl_fmt(struct drm_crtc *crtc)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun unsigned int btpp;
85*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
86*4882a593Smuzhiyun const struct drm_framebuffer *fb = crtc->primary->state->fb;
87*4882a593Smuzhiyun uint32_t pixel_format;
88*4882a593Smuzhiyun struct simplefb_format *format = NULL;
89*4882a593Smuzhiyun int i;
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun pixel_format = fb->format->format;
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
94*4882a593Smuzhiyun if (supported_formats[i].fourcc == pixel_format)
95*4882a593Smuzhiyun format = &supported_formats[i];
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun if (WARN_ON(!format))
99*4882a593Smuzhiyun return 0;
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun /* HDLCD uses 'bytes per pixel', zero means 1 byte */
102*4882a593Smuzhiyun btpp = (format->bits_per_pixel + 7) / 8;
103*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_PIXEL_FORMAT, (btpp - 1) << 3);
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * The format of the HDLCD_REG_<color>_SELECT register is:
107*4882a593Smuzhiyun * - bits[23:16] - default value for that color component
108*4882a593Smuzhiyun * - bits[11:8] - number of bits to extract for each color component
109*4882a593Smuzhiyun * - bits[4:0] - index of the lowest bit to extract
110*4882a593Smuzhiyun *
111*4882a593Smuzhiyun * The default color value is used when bits[11:8] are zero, when the
112*4882a593Smuzhiyun * pixel is outside the visible frame area or when there is a
113*4882a593Smuzhiyun * buffer underrun.
114*4882a593Smuzhiyun */
115*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_RED_SELECT, format->red.offset |
116*4882a593Smuzhiyun #ifdef CONFIG_DRM_HDLCD_SHOW_UNDERRUN
117*4882a593Smuzhiyun 0x00ff0000 | /* show underruns in red */
118*4882a593Smuzhiyun #endif
119*4882a593Smuzhiyun ((format->red.length & 0xf) << 8));
120*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_GREEN_SELECT, format->green.offset |
121*4882a593Smuzhiyun ((format->green.length & 0xf) << 8));
122*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_BLUE_SELECT, format->blue.offset |
123*4882a593Smuzhiyun ((format->blue.length & 0xf) << 8));
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun return 0;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
hdlcd_crtc_mode_set_nofb(struct drm_crtc * crtc)128*4882a593Smuzhiyun static void hdlcd_crtc_mode_set_nofb(struct drm_crtc *crtc)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
131*4882a593Smuzhiyun struct drm_display_mode *m = &crtc->state->adjusted_mode;
132*4882a593Smuzhiyun struct videomode vm;
133*4882a593Smuzhiyun unsigned int polarities, err;
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun vm.vfront_porch = m->crtc_vsync_start - m->crtc_vdisplay;
136*4882a593Smuzhiyun vm.vback_porch = m->crtc_vtotal - m->crtc_vsync_end;
137*4882a593Smuzhiyun vm.vsync_len = m->crtc_vsync_end - m->crtc_vsync_start;
138*4882a593Smuzhiyun vm.hfront_porch = m->crtc_hsync_start - m->crtc_hdisplay;
139*4882a593Smuzhiyun vm.hback_porch = m->crtc_htotal - m->crtc_hsync_end;
140*4882a593Smuzhiyun vm.hsync_len = m->crtc_hsync_end - m->crtc_hsync_start;
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun polarities = HDLCD_POLARITY_DATAEN | HDLCD_POLARITY_DATA;
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun if (m->flags & DRM_MODE_FLAG_PHSYNC)
145*4882a593Smuzhiyun polarities |= HDLCD_POLARITY_HSYNC;
146*4882a593Smuzhiyun if (m->flags & DRM_MODE_FLAG_PVSYNC)
147*4882a593Smuzhiyun polarities |= HDLCD_POLARITY_VSYNC;
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun /* Allow max number of outstanding requests and largest burst size */
150*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_BUS_OPTIONS,
151*4882a593Smuzhiyun HDLCD_BUS_MAX_OUTSTAND | HDLCD_BUS_BURST_16);
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_V_DATA, m->crtc_vdisplay - 1);
154*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_V_BACK_PORCH, vm.vback_porch - 1);
155*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_V_FRONT_PORCH, vm.vfront_porch - 1);
156*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_V_SYNC, vm.vsync_len - 1);
157*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_H_DATA, m->crtc_hdisplay - 1);
158*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_H_BACK_PORCH, vm.hback_porch - 1);
159*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_H_FRONT_PORCH, vm.hfront_porch - 1);
160*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_H_SYNC, vm.hsync_len - 1);
161*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_POLARITIES, polarities);
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun err = hdlcd_set_pxl_fmt(crtc);
164*4882a593Smuzhiyun if (err)
165*4882a593Smuzhiyun return;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun clk_set_rate(hdlcd->clk, m->crtc_clock * 1000);
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
hdlcd_crtc_atomic_enable(struct drm_crtc * crtc,struct drm_crtc_state * old_state)170*4882a593Smuzhiyun static void hdlcd_crtc_atomic_enable(struct drm_crtc *crtc,
171*4882a593Smuzhiyun struct drm_crtc_state *old_state)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun clk_prepare_enable(hdlcd->clk);
176*4882a593Smuzhiyun hdlcd_crtc_mode_set_nofb(crtc);
177*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 1);
178*4882a593Smuzhiyun drm_crtc_vblank_on(crtc);
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun
hdlcd_crtc_atomic_disable(struct drm_crtc * crtc,struct drm_crtc_state * old_state)181*4882a593Smuzhiyun static void hdlcd_crtc_atomic_disable(struct drm_crtc *crtc,
182*4882a593Smuzhiyun struct drm_crtc_state *old_state)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun drm_crtc_vblank_off(crtc);
187*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0);
188*4882a593Smuzhiyun clk_disable_unprepare(hdlcd->clk);
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun
hdlcd_crtc_mode_valid(struct drm_crtc * crtc,const struct drm_display_mode * mode)191*4882a593Smuzhiyun static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc,
192*4882a593Smuzhiyun const struct drm_display_mode *mode)
193*4882a593Smuzhiyun {
194*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
195*4882a593Smuzhiyun long rate, clk_rate = mode->clock * 1000;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun rate = clk_round_rate(hdlcd->clk, clk_rate);
198*4882a593Smuzhiyun /* 0.1% seems a close enough tolerance for the TDA19988 on Juno */
199*4882a593Smuzhiyun if (abs(rate - clk_rate) * 1000 > clk_rate) {
200*4882a593Smuzhiyun /* clock required by mode not supported by hardware */
201*4882a593Smuzhiyun return MODE_NOCLOCK;
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun return MODE_OK;
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
hdlcd_crtc_atomic_begin(struct drm_crtc * crtc,struct drm_crtc_state * state)207*4882a593Smuzhiyun static void hdlcd_crtc_atomic_begin(struct drm_crtc *crtc,
208*4882a593Smuzhiyun struct drm_crtc_state *state)
209*4882a593Smuzhiyun {
210*4882a593Smuzhiyun struct drm_pending_vblank_event *event = crtc->state->event;
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun if (event) {
213*4882a593Smuzhiyun crtc->state->event = NULL;
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun spin_lock_irq(&crtc->dev->event_lock);
216*4882a593Smuzhiyun if (drm_crtc_vblank_get(crtc) == 0)
217*4882a593Smuzhiyun drm_crtc_arm_vblank_event(crtc, event);
218*4882a593Smuzhiyun else
219*4882a593Smuzhiyun drm_crtc_send_vblank_event(crtc, event);
220*4882a593Smuzhiyun spin_unlock_irq(&crtc->dev->event_lock);
221*4882a593Smuzhiyun }
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun static const struct drm_crtc_helper_funcs hdlcd_crtc_helper_funcs = {
225*4882a593Smuzhiyun .mode_valid = hdlcd_crtc_mode_valid,
226*4882a593Smuzhiyun .atomic_begin = hdlcd_crtc_atomic_begin,
227*4882a593Smuzhiyun .atomic_enable = hdlcd_crtc_atomic_enable,
228*4882a593Smuzhiyun .atomic_disable = hdlcd_crtc_atomic_disable,
229*4882a593Smuzhiyun };
230*4882a593Smuzhiyun
hdlcd_plane_atomic_check(struct drm_plane * plane,struct drm_plane_state * state)231*4882a593Smuzhiyun static int hdlcd_plane_atomic_check(struct drm_plane *plane,
232*4882a593Smuzhiyun struct drm_plane_state *state)
233*4882a593Smuzhiyun {
234*4882a593Smuzhiyun int i;
235*4882a593Smuzhiyun struct drm_crtc *crtc;
236*4882a593Smuzhiyun struct drm_crtc_state *crtc_state;
237*4882a593Smuzhiyun u32 src_h = state->src_h >> 16;
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun /* only the HDLCD_REG_FB_LINE_COUNT register has a limit */
240*4882a593Smuzhiyun if (src_h >= HDLCD_MAX_YRES) {
241*4882a593Smuzhiyun DRM_DEBUG_KMS("Invalid source width: %d\n", src_h);
242*4882a593Smuzhiyun return -EINVAL;
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun for_each_new_crtc_in_state(state->state, crtc, crtc_state, i) {
246*4882a593Smuzhiyun /* we cannot disable the plane while the CRTC is active */
247*4882a593Smuzhiyun if (!state->fb && crtc_state->active)
248*4882a593Smuzhiyun return -EINVAL;
249*4882a593Smuzhiyun return drm_atomic_helper_check_plane_state(state, crtc_state,
250*4882a593Smuzhiyun DRM_PLANE_HELPER_NO_SCALING,
251*4882a593Smuzhiyun DRM_PLANE_HELPER_NO_SCALING,
252*4882a593Smuzhiyun false, true);
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun return 0;
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun
hdlcd_plane_atomic_update(struct drm_plane * plane,struct drm_plane_state * state)258*4882a593Smuzhiyun static void hdlcd_plane_atomic_update(struct drm_plane *plane,
259*4882a593Smuzhiyun struct drm_plane_state *state)
260*4882a593Smuzhiyun {
261*4882a593Smuzhiyun struct drm_framebuffer *fb = plane->state->fb;
262*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd;
263*4882a593Smuzhiyun u32 dest_h;
264*4882a593Smuzhiyun dma_addr_t scanout_start;
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun if (!fb)
267*4882a593Smuzhiyun return;
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun dest_h = drm_rect_height(&plane->state->dst);
270*4882a593Smuzhiyun scanout_start = drm_fb_cma_get_gem_addr(fb, plane->state, 0);
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun hdlcd = plane->dev->dev_private;
273*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, fb->pitches[0]);
274*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, fb->pitches[0]);
275*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_COUNT, dest_h - 1);
276*4882a593Smuzhiyun hdlcd_write(hdlcd, HDLCD_REG_FB_BASE, scanout_start);
277*4882a593Smuzhiyun }
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs = {
280*4882a593Smuzhiyun .atomic_check = hdlcd_plane_atomic_check,
281*4882a593Smuzhiyun .atomic_update = hdlcd_plane_atomic_update,
282*4882a593Smuzhiyun };
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun static const struct drm_plane_funcs hdlcd_plane_funcs = {
285*4882a593Smuzhiyun .update_plane = drm_atomic_helper_update_plane,
286*4882a593Smuzhiyun .disable_plane = drm_atomic_helper_disable_plane,
287*4882a593Smuzhiyun .destroy = drm_plane_cleanup,
288*4882a593Smuzhiyun .reset = drm_atomic_helper_plane_reset,
289*4882a593Smuzhiyun .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
290*4882a593Smuzhiyun .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
291*4882a593Smuzhiyun };
292*4882a593Smuzhiyun
hdlcd_plane_init(struct drm_device * drm)293*4882a593Smuzhiyun static struct drm_plane *hdlcd_plane_init(struct drm_device *drm)
294*4882a593Smuzhiyun {
295*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = drm->dev_private;
296*4882a593Smuzhiyun struct drm_plane *plane = NULL;
297*4882a593Smuzhiyun u32 formats[ARRAY_SIZE(supported_formats)], i;
298*4882a593Smuzhiyun int ret;
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL);
301*4882a593Smuzhiyun if (!plane)
302*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(supported_formats); i++)
305*4882a593Smuzhiyun formats[i] = supported_formats[i].fourcc;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun ret = drm_universal_plane_init(drm, plane, 0xff, &hdlcd_plane_funcs,
308*4882a593Smuzhiyun formats, ARRAY_SIZE(formats),
309*4882a593Smuzhiyun NULL,
310*4882a593Smuzhiyun DRM_PLANE_TYPE_PRIMARY, NULL);
311*4882a593Smuzhiyun if (ret)
312*4882a593Smuzhiyun return ERR_PTR(ret);
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun drm_plane_helper_add(plane, &hdlcd_plane_helper_funcs);
315*4882a593Smuzhiyun hdlcd->plane = plane;
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun return plane;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun
hdlcd_setup_crtc(struct drm_device * drm)320*4882a593Smuzhiyun int hdlcd_setup_crtc(struct drm_device *drm)
321*4882a593Smuzhiyun {
322*4882a593Smuzhiyun struct hdlcd_drm_private *hdlcd = drm->dev_private;
323*4882a593Smuzhiyun struct drm_plane *primary;
324*4882a593Smuzhiyun int ret;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun primary = hdlcd_plane_init(drm);
327*4882a593Smuzhiyun if (IS_ERR(primary))
328*4882a593Smuzhiyun return PTR_ERR(primary);
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun ret = drm_crtc_init_with_planes(drm, &hdlcd->crtc, primary, NULL,
331*4882a593Smuzhiyun &hdlcd_crtc_funcs, NULL);
332*4882a593Smuzhiyun if (ret)
333*4882a593Smuzhiyun return ret;
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun drm_crtc_helper_add(&hdlcd->crtc, &hdlcd_crtc_helper_funcs);
336*4882a593Smuzhiyun return 0;
337*4882a593Smuzhiyun }
338