aboutsummaryrefslogtreecommitdiff
path: root/drivers/video/display/panel-dvi.c
blob: 01cea099fc3b92f147f77e6adad5f54c1de0441d (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Generic DVI monitor
 *
 * Copyright (C) 2012 Texas Instruments
 *
 * Contacts: Tomi Valkeinen <tomi.valkeinen@ti.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>

#include <video/display.h>
#include <video/panel-dvi.h>

struct panel_data {
	struct display_entity entity;
	struct video_source *in;
};

#define to_panel(p) container_of(p, struct panel_data, entity)

static int panel_dvi_set_state(struct display_entity *entity,
			       enum display_entity_state state)
{
	struct panel_data *data = to_panel(entity);
	struct video_source *in = data->in;

	switch (state) {
	case DISPLAY_ENTITY_STATE_OFF:
	case DISPLAY_ENTITY_STATE_STANDBY:
		in->common_ops->set_stream(in, DISPLAY_ENTITY_STREAM_STOPPED);
		break;

	case DISPLAY_ENTITY_STATE_ON:
		in->common_ops->set_stream(in, DISPLAY_ENTITY_STREAM_CONTINUOUS);
		break;
	}

	return 0;
}

static const struct videomode vga_mode = {
	.pixelclock = 23500,

	.hactive = 640,
	.hfront_porch = 48,
	.hback_porch = 80,
	.hsync_len = 32,

	.vactive = 480,
	.vfront_porch = 3,
	.vback_porch = 7,
	.vsync_len = 4,

	.hah = true,
	.vah = true,
	.de = true,
};

static int panel_dvi_get_modes(struct display_entity *entity,
			       const struct videomode **modes)
{
	//struct panel_data *data = to_panel(entity);

	*modes = &vga_mode;
	return 1;
}

static int panel_dvi_get_size(struct display_entity *entity,
			      unsigned int *width, unsigned int *height)
{
	//struct panel_data *data = to_panel(entity);

	*width = 10;
	*height = 10;
	return 0;
}

static const struct display_entity_control_ops panel_dvi_control_ops = {
	.set_state = panel_dvi_set_state,
	.get_modes = panel_dvi_get_modes,
	.get_size = panel_dvi_get_size,
};

static void panel_dvi_release(struct display_entity *entity)
{
	printk("panel dvi release\n");
}

static int __devinit panel_dvi_probe(struct platform_device *pdev)
{
	const struct panel_dvi_platform_data *pdata = pdev->dev.platform_data;
	struct panel_data *data;
	int ret;

	if (pdata == NULL)
		return -ENODEV;

	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
	if (data == NULL)
		return -ENOMEM;

	/* setup input */
	data->in = video_source_find(pdata->video_source);
	if (data->in == NULL) {
		printk("failed to get video source\n");
		return -EINVAL;
	}

	/* setup default mode */
	data->in->ops.dvi->set_videomode(data->in, &vga_mode);

	/* setup panel entity */

	data->entity.dev = &pdev->dev;
	data->entity.release = panel_dvi_release;
	data->entity.ops = &panel_dvi_control_ops;

	ret = display_entity_register(&data->entity);
	if (ret < 0) {
		video_source_put(data->in);
		return ret;
	}

	platform_set_drvdata(pdev, data);

	return 0;
}

static int panel_dvi_remove(struct platform_device *pdev)
{
	struct panel_data *data = platform_get_drvdata(pdev);

	display_entity_unregister(&data->entity);

	video_source_put(data->in);

	return 0;
}


static const struct dev_pm_ops panel_dvi_dev_pm_ops = {
};

static struct platform_driver panel_dvi_driver = {
	.probe = panel_dvi_probe,
	.remove = panel_dvi_remove,
	.driver = {
		.name = "panel_dvi",
		.owner = THIS_MODULE,
		.pm = &panel_dvi_dev_pm_ops,
	},
};

module_platform_driver(panel_dvi_driver);

MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
MODULE_DESCRIPTION("DVI Monitor");
MODULE_LICENSE("GPL");