omap_wb.c
4.1 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* linux/drivers/gpu/drm/omapdrm/omap_wb.c
*
* Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
* Author: Benoit Parrot, <bparrot@ti.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/module.h>
#include <linux/init.h>
#include "omap_wb.h"
unsigned wbdebug;
module_param(wbdebug, uint, 0644);
MODULE_PARM_DESC(wbdebug, "activates debug info");
struct wb_fmt wb_formats[] = {
{
.fourcc = V4L2_PIX_FMT_NV12,
.coplanar = 1,
.depth = {8, 4},
},
{
.fourcc = V4L2_PIX_FMT_YUYV,
.coplanar = 0,
.depth = {16, 0},
},
{
.fourcc = V4L2_PIX_FMT_UYVY,
.coplanar = 0,
.depth = {16, 0},
},
{
/* "XR24", DRM_FORMAT_XRGB8888 */
.fourcc = V4L2_PIX_FMT_XBGR32,
.coplanar = 0,
.depth = {32, 0},
},
};
unsigned int num_wb_formats = ARRAY_SIZE(wb_formats);
/* find our format description corresponding to the passed v4l2_format */
struct wb_fmt *find_format(struct v4l2_format *f)
{
struct wb_fmt *fmt;
unsigned int k;
for (k = 0; k < num_wb_formats; k++) {
fmt = &wb_formats[k];
if (fmt->fourcc == f->fmt.pix_mp.pixelformat)
return fmt;
}
return NULL;
}
enum omap_color_mode fourcc_to_dss(u32 fourcc)
{
switch (fourcc) {
case DRM_FORMAT_XRGB8888:
return OMAP_DSS_COLOR_RGB24U;
case DRM_FORMAT_NV12:
return OMAP_DSS_COLOR_NV12;
case DRM_FORMAT_YUYV:
return OMAP_DSS_COLOR_YUV2;
case DRM_FORMAT_UYVY:
return OMAP_DSS_COLOR_UYVY;
default:
WARN_ONCE(1, "WB: unsupported fourcc code: 0x%x\n", fourcc);
return OMAP_DSS_COLOR_UYVY;
}
}
static void wb_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
{
struct wb_dev *dev = container_of(irq, struct wb_dev, wb_irq);
if (!atomic_read(&dev->irq_enabled))
return;
switch (dev->mode) {
case OMAP_WB_NOT_CONFIGURED:
break;
case OMAP_WB_MEM2MEM_OVL:
wbm2m_irq(dev->m2m, irqstatus);
break;
case OMAP_WB_MEM2MEM_MGR:
/* To be added */
break;
case OMAP_WB_CAPTURE_MGR:
wbcap_irq(dev->cap, irqstatus);
break;
default:
WARN_ONCE(1, "WB: unknown WB mode: 0x%x\n", dev->mode);
break;
}
}
/*
* The initial setup of this device instance. Note that the initial state of
* the driver should be complete. So the initial format, standard, timings
* and video input should all be initialized to some reasonable value.
*/
int wb_init(struct drm_device *drmdev)
{
struct omap_drm_private *priv = drmdev->dev_private;
struct wb_dev *dev;
int ret = 0;
/* Allocate a new instance */
dev = devm_kzalloc(drmdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
dev->drm_dev = drmdev;
/* set pseudo v4l2 device name so we can use v4l2_printk */
strlcpy(dev->v4l2_dev.name, WB_MODULE_NAME,
sizeof(dev->v4l2_dev.name));
priv->wb_private = dev;
mutex_init(&dev->lock);
atomic_set(&dev->irq_enabled, 0);
dev->wb_irq.irqmask = DISPC_IRQ_FRAMEDONEWB |
DISPC_IRQ_WBBUFFEROVERFLOW |
DISPC_IRQ_WBUNCOMPLETEERROR |
DISPC_IRQ_VSYNC |
DISPC_IRQ_VSYNC2 |
DISPC_IRQ_VSYNC3 |
DISPC_IRQ_EVSYNC_EVEN |
DISPC_IRQ_EVSYNC_ODD;
dev->wb_irq.irq = wb_irq;
omap_irq_register(drmdev, &dev->wb_irq);
dev->mode = OMAP_WB_NOT_CONFIGURED;
ret = wbcap_init(dev);
if (ret) {
log_err(dev, "Failed to initialize wb capture\n");
goto free_irq;
}
ret = wbm2m_init(dev);
if (ret) {
log_err(dev, "Failed to initialize wb m2m\n");
goto free_cap;
}
log_dbg(dev, "WB loaded\n");
return 0;
free_cap:
wbcap_cleanup(dev);
free_irq:
omap_irq_unregister(drmdev, &dev->wb_irq);
return ret;
}
void wb_cleanup(struct drm_device *drmdev)
{
struct omap_drm_private *priv = drmdev->dev_private;
struct wb_dev *dev = priv->wb_private;
log_dbg(dev, "Cleanup WB\n");
omap_irq_unregister(drmdev, &dev->wb_irq);
wbcap_cleanup(dev);
wbm2m_cleanup(dev);
}