summaryrefslogtreecommitdiffstats
path: root/drivers/video/sdl.c
blob: ed083d76f5b09c92089daaa849f7e160c593a063 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
 *
 * GPL v2
 */

#include <common.h>
#include <driver.h>
#include <init.h>
#include <malloc.h>
#include <mach/linux.h>
#include <fb.h>
#include <errno.h>
#include <graphic_utils.h>

static void sdlfb_enable(struct fb_info *info)
{
	sdl_start_timer();
}

static void sdlfb_disable(struct fb_info *info)
{
	sdl_stop_timer();
}

static struct fb_ops sdlfb_ops = {
	.fb_enable	= sdlfb_enable,
	.fb_disable	= sdlfb_disable,
};

static int sdlfb_probe(struct device_d *dev)
{
	struct fb_info *fb;
	int ret = -EIO;

	if (!dev->platform_data)
		return -EIO;

	fb = xzalloc(sizeof(*fb));
	fb->mode_list = fb->mode = dev->platform_data;
	fb->num_modes = 1;
	fb->bits_per_pixel = 4 << 3;
	fb->xres = fb->mode->xres;
	fb->yres = fb->mode->yres;

	fb->priv = fb;
	fb->fbops = &sdlfb_ops,

	fb->dev.parent = dev;
	fb->screen_base = xzalloc(fb->xres * fb->yres *
				  fb->bits_per_pixel >> 3);

	if (sdl_open(fb->xres, fb->yres, fb->bits_per_pixel,
		     fb->screen_base))
		goto err;

	sdl_get_bitfield_rgba(&fb->red, &fb->green, &fb->blue, &fb->transp);

	dev_dbg(dev, "red: length = %d, offset = %d\n",
		fb->red.length, fb->red.offset);
	dev_dbg(dev, "green: length = %d, offset = %d\n",
		fb->green.length, fb->green.offset);
	dev_dbg(dev, "blue: length = %d, offset = %d\n",
		fb->blue.length, fb->blue.offset);
	dev_dbg(dev, "transp: length = %d, offset = %d\n",
		fb->transp.length, fb->transp.offset);

	/* add runtime hardware info */
	dev->priv = fb;

	ret = register_framebuffer(fb);
	if (!ret)
		return 0;

err:
	kfree(fb->screen_base);
	kfree(fb);
	sdl_close();
	return ret;
}

static void sdlfb_remove(struct device_d *dev)
{
	struct fb_info *fb = dev->priv;

	kfree(fb->screen_base);
	kfree(fb);
	sdl_close();
}

static struct driver_d sdlfb_driver = {
	.name	= "sdlfb",
	.probe	= sdlfb_probe,
	.remove	= sdlfb_remove,
};

static int sdlfb_init(void)
{
	return register_driver(&sdlfb_driver);
}
device_initcall(sdlfb_init);