Loading...
1/*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25/*
26 * Authors: Dave Airlie <airlied@redhat.com>
27 */
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/string.h>
32#include <linux/mm.h>
33#include <linux/tty.h>
34#include <linux/sysrq.h>
35#include <linux/delay.h>
36#include <linux/fb.h>
37#include <linux/init.h>
38
39
40#include <drm/drmP.h>
41#include <drm/drm_crtc.h>
42#include <drm/drm_fb_helper.h>
43#include <drm/drm_crtc_helper.h>
44#include "ast_drv.h"
45
46static void ast_dirty_update(struct ast_fbdev *afbdev,
47 int x, int y, int width, int height)
48{
49 int i;
50 struct drm_gem_object *obj;
51 struct ast_bo *bo;
52 int src_offset, dst_offset;
53 int bpp = (afbdev->afb.base.bits_per_pixel + 7)/8;
54 int ret = -EBUSY;
55 bool unmap = false;
56 bool store_for_later = false;
57 int x2, y2;
58 unsigned long flags;
59
60 obj = afbdev->afb.obj;
61 bo = gem_to_ast_bo(obj);
62
63 /*
64 * try and reserve the BO, if we fail with busy
65 * then the BO is being moved and we should
66 * store up the damage until later.
67 */
68 if (drm_can_sleep())
69 ret = ast_bo_reserve(bo, true);
70 if (ret) {
71 if (ret != -EBUSY)
72 return;
73
74 store_for_later = true;
75 }
76
77 x2 = x + width - 1;
78 y2 = y + height - 1;
79 spin_lock_irqsave(&afbdev->dirty_lock, flags);
80
81 if (afbdev->y1 < y)
82 y = afbdev->y1;
83 if (afbdev->y2 > y2)
84 y2 = afbdev->y2;
85 if (afbdev->x1 < x)
86 x = afbdev->x1;
87 if (afbdev->x2 > x2)
88 x2 = afbdev->x2;
89
90 if (store_for_later) {
91 afbdev->x1 = x;
92 afbdev->x2 = x2;
93 afbdev->y1 = y;
94 afbdev->y2 = y2;
95 spin_unlock_irqrestore(&afbdev->dirty_lock, flags);
96 return;
97 }
98
99 afbdev->x1 = afbdev->y1 = INT_MAX;
100 afbdev->x2 = afbdev->y2 = 0;
101 spin_unlock_irqrestore(&afbdev->dirty_lock, flags);
102
103 if (!bo->kmap.virtual) {
104 ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
105 if (ret) {
106 DRM_ERROR("failed to kmap fb updates\n");
107 ast_bo_unreserve(bo);
108 return;
109 }
110 unmap = true;
111 }
112 for (i = y; i <= y2; i++) {
113 /* assume equal stride for now */
114 src_offset = dst_offset = i * afbdev->afb.base.pitches[0] + (x * bpp);
115 memcpy_toio(bo->kmap.virtual + src_offset, afbdev->sysram + src_offset, (x2 - x + 1) * bpp);
116
117 }
118 if (unmap)
119 ttm_bo_kunmap(&bo->kmap);
120
121 ast_bo_unreserve(bo);
122}
123
124static void ast_fillrect(struct fb_info *info,
125 const struct fb_fillrect *rect)
126{
127 struct ast_fbdev *afbdev = info->par;
128 drm_fb_helper_sys_fillrect(info, rect);
129 ast_dirty_update(afbdev, rect->dx, rect->dy, rect->width,
130 rect->height);
131}
132
133static void ast_copyarea(struct fb_info *info,
134 const struct fb_copyarea *area)
135{
136 struct ast_fbdev *afbdev = info->par;
137 drm_fb_helper_sys_copyarea(info, area);
138 ast_dirty_update(afbdev, area->dx, area->dy, area->width,
139 area->height);
140}
141
142static void ast_imageblit(struct fb_info *info,
143 const struct fb_image *image)
144{
145 struct ast_fbdev *afbdev = info->par;
146 drm_fb_helper_sys_imageblit(info, image);
147 ast_dirty_update(afbdev, image->dx, image->dy, image->width,
148 image->height);
149}
150
151static struct fb_ops astfb_ops = {
152 .owner = THIS_MODULE,
153 .fb_check_var = drm_fb_helper_check_var,
154 .fb_set_par = drm_fb_helper_set_par,
155 .fb_fillrect = ast_fillrect,
156 .fb_copyarea = ast_copyarea,
157 .fb_imageblit = ast_imageblit,
158 .fb_pan_display = drm_fb_helper_pan_display,
159 .fb_blank = drm_fb_helper_blank,
160 .fb_setcmap = drm_fb_helper_setcmap,
161 .fb_debug_enter = drm_fb_helper_debug_enter,
162 .fb_debug_leave = drm_fb_helper_debug_leave,
163};
164
165static int astfb_create_object(struct ast_fbdev *afbdev,
166 const struct drm_mode_fb_cmd2 *mode_cmd,
167 struct drm_gem_object **gobj_p)
168{
169 struct drm_device *dev = afbdev->helper.dev;
170 u32 bpp, depth;
171 u32 size;
172 struct drm_gem_object *gobj;
173
174 int ret = 0;
175 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
176
177 size = mode_cmd->pitches[0] * mode_cmd->height;
178 ret = ast_gem_create(dev, size, true, &gobj);
179 if (ret)
180 return ret;
181
182 *gobj_p = gobj;
183 return ret;
184}
185
186static int astfb_create(struct drm_fb_helper *helper,
187 struct drm_fb_helper_surface_size *sizes)
188{
189 struct ast_fbdev *afbdev =
190 container_of(helper, struct ast_fbdev, helper);
191 struct drm_device *dev = afbdev->helper.dev;
192 struct drm_mode_fb_cmd2 mode_cmd;
193 struct drm_framebuffer *fb;
194 struct fb_info *info;
195 int size, ret;
196 void *sysram;
197 struct drm_gem_object *gobj = NULL;
198 struct ast_bo *bo = NULL;
199 mode_cmd.width = sizes->surface_width;
200 mode_cmd.height = sizes->surface_height;
201 mode_cmd.pitches[0] = mode_cmd.width * ((sizes->surface_bpp + 7)/8);
202
203 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
204 sizes->surface_depth);
205
206 size = mode_cmd.pitches[0] * mode_cmd.height;
207
208 ret = astfb_create_object(afbdev, &mode_cmd, &gobj);
209 if (ret) {
210 DRM_ERROR("failed to create fbcon backing object %d\n", ret);
211 return ret;
212 }
213 bo = gem_to_ast_bo(gobj);
214
215 sysram = vmalloc(size);
216 if (!sysram)
217 return -ENOMEM;
218
219 info = drm_fb_helper_alloc_fbi(helper);
220 if (IS_ERR(info)) {
221 ret = PTR_ERR(info);
222 goto err_free_vram;
223 }
224 info->par = afbdev;
225
226 ret = ast_framebuffer_init(dev, &afbdev->afb, &mode_cmd, gobj);
227 if (ret)
228 goto err_release_fbi;
229
230 afbdev->sysram = sysram;
231 afbdev->size = size;
232
233 fb = &afbdev->afb.base;
234 afbdev->helper.fb = fb;
235
236 strcpy(info->fix.id, "astdrmfb");
237
238 info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
239 info->fbops = &astfb_ops;
240
241 info->apertures->ranges[0].base = pci_resource_start(dev->pdev, 0);
242 info->apertures->ranges[0].size = pci_resource_len(dev->pdev, 0);
243
244 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
245 drm_fb_helper_fill_var(info, &afbdev->helper, sizes->fb_width, sizes->fb_height);
246
247 info->screen_base = sysram;
248 info->screen_size = size;
249
250 info->pixmap.flags = FB_PIXMAP_SYSTEM;
251
252 DRM_DEBUG_KMS("allocated %dx%d\n",
253 fb->width, fb->height);
254
255 return 0;
256
257err_release_fbi:
258 drm_fb_helper_release_fbi(helper);
259err_free_vram:
260 vfree(afbdev->sysram);
261 return ret;
262}
263
264static void ast_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
265 u16 blue, int regno)
266{
267 struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
268 ast_crtc->lut_r[regno] = red >> 8;
269 ast_crtc->lut_g[regno] = green >> 8;
270 ast_crtc->lut_b[regno] = blue >> 8;
271}
272
273static void ast_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
274 u16 *blue, int regno)
275{
276 struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
277 *red = ast_crtc->lut_r[regno] << 8;
278 *green = ast_crtc->lut_g[regno] << 8;
279 *blue = ast_crtc->lut_b[regno] << 8;
280}
281
282static const struct drm_fb_helper_funcs ast_fb_helper_funcs = {
283 .gamma_set = ast_fb_gamma_set,
284 .gamma_get = ast_fb_gamma_get,
285 .fb_probe = astfb_create,
286};
287
288static void ast_fbdev_destroy(struct drm_device *dev,
289 struct ast_fbdev *afbdev)
290{
291 struct ast_framebuffer *afb = &afbdev->afb;
292
293 drm_fb_helper_unregister_fbi(&afbdev->helper);
294 drm_fb_helper_release_fbi(&afbdev->helper);
295
296 if (afb->obj) {
297 drm_gem_object_unreference_unlocked(afb->obj);
298 afb->obj = NULL;
299 }
300 drm_fb_helper_fini(&afbdev->helper);
301
302 vfree(afbdev->sysram);
303 drm_framebuffer_unregister_private(&afb->base);
304 drm_framebuffer_cleanup(&afb->base);
305}
306
307int ast_fbdev_init(struct drm_device *dev)
308{
309 struct ast_private *ast = dev->dev_private;
310 struct ast_fbdev *afbdev;
311 int ret;
312
313 afbdev = kzalloc(sizeof(struct ast_fbdev), GFP_KERNEL);
314 if (!afbdev)
315 return -ENOMEM;
316
317 ast->fbdev = afbdev;
318 spin_lock_init(&afbdev->dirty_lock);
319
320 drm_fb_helper_prepare(dev, &afbdev->helper, &ast_fb_helper_funcs);
321
322 ret = drm_fb_helper_init(dev, &afbdev->helper,
323 1, 1);
324 if (ret)
325 goto free;
326
327 ret = drm_fb_helper_single_add_all_connectors(&afbdev->helper);
328 if (ret)
329 goto fini;
330
331 /* disable all the possible outputs/crtcs before entering KMS mode */
332 drm_helper_disable_unused_functions(dev);
333
334 ret = drm_fb_helper_initial_config(&afbdev->helper, 32);
335 if (ret)
336 goto fini;
337
338 return 0;
339
340fini:
341 drm_fb_helper_fini(&afbdev->helper);
342free:
343 kfree(afbdev);
344 return ret;
345}
346
347void ast_fbdev_fini(struct drm_device *dev)
348{
349 struct ast_private *ast = dev->dev_private;
350
351 if (!ast->fbdev)
352 return;
353
354 ast_fbdev_destroy(dev, ast->fbdev);
355 kfree(ast->fbdev);
356 ast->fbdev = NULL;
357}
358
359void ast_fbdev_set_suspend(struct drm_device *dev, int state)
360{
361 struct ast_private *ast = dev->dev_private;
362
363 if (!ast->fbdev)
364 return;
365
366 drm_fb_helper_set_suspend(&ast->fbdev->helper, state);
367}
368
369void ast_fbdev_set_base(struct ast_private *ast, unsigned long gpu_addr)
370{
371 ast->fbdev->helper.fbdev->fix.smem_start =
372 ast->fbdev->helper.fbdev->apertures->ranges[0].base + gpu_addr;
373 ast->fbdev->helper.fbdev->fix.smem_len = ast->vram_size - gpu_addr;
374}
1/*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25/*
26 * Authors: Dave Airlie <airlied@redhat.com>
27 */
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/string.h>
32#include <linux/mm.h>
33#include <linux/tty.h>
34#include <linux/sysrq.h>
35#include <linux/delay.h>
36#include <linux/init.h>
37
38
39#include <drm/drmP.h>
40#include <drm/drm_crtc.h>
41#include <drm/drm_fb_helper.h>
42#include <drm/drm_crtc_helper.h>
43#include "ast_drv.h"
44
45static void ast_dirty_update(struct ast_fbdev *afbdev,
46 int x, int y, int width, int height)
47{
48 int i;
49 struct drm_gem_object *obj;
50 struct ast_bo *bo;
51 int src_offset, dst_offset;
52 int bpp = afbdev->afb.base.format->cpp[0];
53 int ret = -EBUSY;
54 bool unmap = false;
55 bool store_for_later = false;
56 int x2, y2;
57 unsigned long flags;
58
59 obj = afbdev->afb.obj;
60 bo = gem_to_ast_bo(obj);
61
62 /*
63 * try and reserve the BO, if we fail with busy
64 * then the BO is being moved and we should
65 * store up the damage until later.
66 */
67 if (drm_can_sleep())
68 ret = ast_bo_reserve(bo, true);
69 if (ret) {
70 if (ret != -EBUSY)
71 return;
72
73 store_for_later = true;
74 }
75
76 x2 = x + width - 1;
77 y2 = y + height - 1;
78 spin_lock_irqsave(&afbdev->dirty_lock, flags);
79
80 if (afbdev->y1 < y)
81 y = afbdev->y1;
82 if (afbdev->y2 > y2)
83 y2 = afbdev->y2;
84 if (afbdev->x1 < x)
85 x = afbdev->x1;
86 if (afbdev->x2 > x2)
87 x2 = afbdev->x2;
88
89 if (store_for_later) {
90 afbdev->x1 = x;
91 afbdev->x2 = x2;
92 afbdev->y1 = y;
93 afbdev->y2 = y2;
94 spin_unlock_irqrestore(&afbdev->dirty_lock, flags);
95 return;
96 }
97
98 afbdev->x1 = afbdev->y1 = INT_MAX;
99 afbdev->x2 = afbdev->y2 = 0;
100 spin_unlock_irqrestore(&afbdev->dirty_lock, flags);
101
102 if (!bo->kmap.virtual) {
103 ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
104 if (ret) {
105 DRM_ERROR("failed to kmap fb updates\n");
106 ast_bo_unreserve(bo);
107 return;
108 }
109 unmap = true;
110 }
111 for (i = y; i <= y2; i++) {
112 /* assume equal stride for now */
113 src_offset = dst_offset = i * afbdev->afb.base.pitches[0] + (x * bpp);
114 memcpy_toio(bo->kmap.virtual + src_offset, afbdev->sysram + src_offset, (x2 - x + 1) * bpp);
115
116 }
117 if (unmap)
118 ttm_bo_kunmap(&bo->kmap);
119
120 ast_bo_unreserve(bo);
121}
122
123static void ast_fillrect(struct fb_info *info,
124 const struct fb_fillrect *rect)
125{
126 struct ast_fbdev *afbdev = info->par;
127 drm_fb_helper_sys_fillrect(info, rect);
128 ast_dirty_update(afbdev, rect->dx, rect->dy, rect->width,
129 rect->height);
130}
131
132static void ast_copyarea(struct fb_info *info,
133 const struct fb_copyarea *area)
134{
135 struct ast_fbdev *afbdev = info->par;
136 drm_fb_helper_sys_copyarea(info, area);
137 ast_dirty_update(afbdev, area->dx, area->dy, area->width,
138 area->height);
139}
140
141static void ast_imageblit(struct fb_info *info,
142 const struct fb_image *image)
143{
144 struct ast_fbdev *afbdev = info->par;
145 drm_fb_helper_sys_imageblit(info, image);
146 ast_dirty_update(afbdev, image->dx, image->dy, image->width,
147 image->height);
148}
149
150static struct fb_ops astfb_ops = {
151 .owner = THIS_MODULE,
152 .fb_check_var = drm_fb_helper_check_var,
153 .fb_set_par = drm_fb_helper_set_par,
154 .fb_fillrect = ast_fillrect,
155 .fb_copyarea = ast_copyarea,
156 .fb_imageblit = ast_imageblit,
157 .fb_pan_display = drm_fb_helper_pan_display,
158 .fb_blank = drm_fb_helper_blank,
159 .fb_setcmap = drm_fb_helper_setcmap,
160 .fb_debug_enter = drm_fb_helper_debug_enter,
161 .fb_debug_leave = drm_fb_helper_debug_leave,
162};
163
164static int astfb_create_object(struct ast_fbdev *afbdev,
165 const struct drm_mode_fb_cmd2 *mode_cmd,
166 struct drm_gem_object **gobj_p)
167{
168 struct drm_device *dev = afbdev->helper.dev;
169 u32 size;
170 struct drm_gem_object *gobj;
171 int ret = 0;
172
173 size = mode_cmd->pitches[0] * mode_cmd->height;
174 ret = ast_gem_create(dev, size, true, &gobj);
175 if (ret)
176 return ret;
177
178 *gobj_p = gobj;
179 return ret;
180}
181
182static int astfb_create(struct drm_fb_helper *helper,
183 struct drm_fb_helper_surface_size *sizes)
184{
185 struct ast_fbdev *afbdev =
186 container_of(helper, struct ast_fbdev, helper);
187 struct drm_device *dev = afbdev->helper.dev;
188 struct drm_mode_fb_cmd2 mode_cmd;
189 struct drm_framebuffer *fb;
190 struct fb_info *info;
191 int size, ret;
192 void *sysram;
193 struct drm_gem_object *gobj = NULL;
194 struct ast_bo *bo = NULL;
195 mode_cmd.width = sizes->surface_width;
196 mode_cmd.height = sizes->surface_height;
197 mode_cmd.pitches[0] = mode_cmd.width * ((sizes->surface_bpp + 7)/8);
198
199 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
200 sizes->surface_depth);
201
202 size = mode_cmd.pitches[0] * mode_cmd.height;
203
204 ret = astfb_create_object(afbdev, &mode_cmd, &gobj);
205 if (ret) {
206 DRM_ERROR("failed to create fbcon backing object %d\n", ret);
207 return ret;
208 }
209 bo = gem_to_ast_bo(gobj);
210
211 sysram = vmalloc(size);
212 if (!sysram)
213 return -ENOMEM;
214
215 info = drm_fb_helper_alloc_fbi(helper);
216 if (IS_ERR(info)) {
217 ret = PTR_ERR(info);
218 goto out;
219 }
220 info->par = afbdev;
221
222 ret = ast_framebuffer_init(dev, &afbdev->afb, &mode_cmd, gobj);
223 if (ret)
224 goto out;
225
226 afbdev->sysram = sysram;
227 afbdev->size = size;
228
229 fb = &afbdev->afb.base;
230 afbdev->helper.fb = fb;
231
232 strcpy(info->fix.id, "astdrmfb");
233
234 info->fbops = &astfb_ops;
235
236 info->apertures->ranges[0].base = pci_resource_start(dev->pdev, 0);
237 info->apertures->ranges[0].size = pci_resource_len(dev->pdev, 0);
238
239 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);
240 drm_fb_helper_fill_var(info, &afbdev->helper, sizes->fb_width, sizes->fb_height);
241
242 info->screen_base = sysram;
243 info->screen_size = size;
244
245 info->pixmap.flags = FB_PIXMAP_SYSTEM;
246
247 DRM_DEBUG_KMS("allocated %dx%d\n",
248 fb->width, fb->height);
249
250 return 0;
251
252out:
253 vfree(sysram);
254 return ret;
255}
256
257static const struct drm_fb_helper_funcs ast_fb_helper_funcs = {
258 .fb_probe = astfb_create,
259};
260
261static void ast_fbdev_destroy(struct drm_device *dev,
262 struct ast_fbdev *afbdev)
263{
264 struct ast_framebuffer *afb = &afbdev->afb;
265
266 drm_fb_helper_unregister_fbi(&afbdev->helper);
267
268 if (afb->obj) {
269 drm_gem_object_put_unlocked(afb->obj);
270 afb->obj = NULL;
271 }
272 drm_fb_helper_fini(&afbdev->helper);
273
274 vfree(afbdev->sysram);
275 drm_framebuffer_unregister_private(&afb->base);
276 drm_framebuffer_cleanup(&afb->base);
277}
278
279int ast_fbdev_init(struct drm_device *dev)
280{
281 struct ast_private *ast = dev->dev_private;
282 struct ast_fbdev *afbdev;
283 int ret;
284
285 afbdev = kzalloc(sizeof(struct ast_fbdev), GFP_KERNEL);
286 if (!afbdev)
287 return -ENOMEM;
288
289 ast->fbdev = afbdev;
290 spin_lock_init(&afbdev->dirty_lock);
291
292 drm_fb_helper_prepare(dev, &afbdev->helper, &ast_fb_helper_funcs);
293
294 ret = drm_fb_helper_init(dev, &afbdev->helper, 1);
295 if (ret)
296 goto free;
297
298 ret = drm_fb_helper_single_add_all_connectors(&afbdev->helper);
299 if (ret)
300 goto fini;
301
302 /* disable all the possible outputs/crtcs before entering KMS mode */
303 drm_helper_disable_unused_functions(dev);
304
305 ret = drm_fb_helper_initial_config(&afbdev->helper, 32);
306 if (ret)
307 goto fini;
308
309 return 0;
310
311fini:
312 drm_fb_helper_fini(&afbdev->helper);
313free:
314 kfree(afbdev);
315 return ret;
316}
317
318void ast_fbdev_fini(struct drm_device *dev)
319{
320 struct ast_private *ast = dev->dev_private;
321
322 if (!ast->fbdev)
323 return;
324
325 ast_fbdev_destroy(dev, ast->fbdev);
326 kfree(ast->fbdev);
327 ast->fbdev = NULL;
328}
329
330void ast_fbdev_set_suspend(struct drm_device *dev, int state)
331{
332 struct ast_private *ast = dev->dev_private;
333
334 if (!ast->fbdev)
335 return;
336
337 drm_fb_helper_set_suspend(&ast->fbdev->helper, state);
338}
339
340void ast_fbdev_set_base(struct ast_private *ast, unsigned long gpu_addr)
341{
342 ast->fbdev->helper.fbdev->fix.smem_start =
343 ast->fbdev->helper.fbdev->apertures->ranges[0].base + gpu_addr;
344 ast->fbdev->helper.fbdev->fix.smem_len = ast->vram_size - gpu_addr;
345}