~ubuntu-branches/ubuntu/trusty/linux-linaro-omap/trusty

« back to all changes in this revision

Viewing changes to drivers/media/video/cx18/cx18-streams.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-57i0gl3v99b3lkfg
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        .unlocked_ioctl = cx18_v4l2_ioctl,
45
45
        .release = cx18_v4l2_close,
46
46
        .poll = cx18_v4l2_enc_poll,
 
47
        .mmap = cx18_v4l2_mmap,
47
48
};
48
49
 
49
50
/* offset from 0 to register ts v4l2 minors on */
97
98
        },
98
99
};
99
100
 
 
101
 
 
102
void cx18_dma_free(struct videobuf_queue *q,
 
103
        struct cx18_stream *s, struct cx18_videobuf_buffer *buf)
 
104
{
 
105
        videobuf_waiton(q, &buf->vb, 0, 0);
 
106
        videobuf_vmalloc_free(&buf->vb);
 
107
        buf->vb.state = VIDEOBUF_NEEDS_INIT;
 
108
}
 
109
 
 
110
static int cx18_prepare_buffer(struct videobuf_queue *q,
 
111
        struct cx18_stream *s,
 
112
        struct cx18_videobuf_buffer *buf,
 
113
        u32 pixelformat,
 
114
        unsigned int width, unsigned int height,
 
115
        enum v4l2_field field)
 
116
{
 
117
        struct cx18 *cx = s->cx;
 
118
        int rc = 0;
 
119
 
 
120
        /* check settings */
 
121
        buf->bytes_used = 0;
 
122
 
 
123
        if ((width  < 48) || (height < 32))
 
124
                return -EINVAL;
 
125
 
 
126
        buf->vb.size = (width * height * 2);
 
127
        if ((buf->vb.baddr != 0) && (buf->vb.bsize < buf->vb.size))
 
128
                return -EINVAL;
 
129
 
 
130
        /* alloc + fill struct (if changed) */
 
131
        if (buf->vb.width != width || buf->vb.height != height ||
 
132
            buf->vb.field != field || s->pixelformat != pixelformat ||
 
133
            buf->tvnorm != cx->std) {
 
134
 
 
135
                buf->vb.width  = width;
 
136
                buf->vb.height = height;
 
137
                buf->vb.field  = field;
 
138
                buf->tvnorm    = cx->std;
 
139
                s->pixelformat = pixelformat;
 
140
 
 
141
                cx18_dma_free(q, s, buf);
 
142
        }
 
143
 
 
144
        if ((buf->vb.baddr != 0) && (buf->vb.bsize < buf->vb.size))
 
145
                return -EINVAL;
 
146
 
 
147
        if (buf->vb.field == 0)
 
148
                buf->vb.field = V4L2_FIELD_INTERLACED;
 
149
 
 
150
        if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
 
151
                buf->vb.width  = width;
 
152
                buf->vb.height = height;
 
153
                buf->vb.field  = field;
 
154
                buf->tvnorm    = cx->std;
 
155
                s->pixelformat = pixelformat;
 
156
 
 
157
                rc = videobuf_iolock(q, &buf->vb, NULL);
 
158
                if (rc != 0)
 
159
                        goto fail;
 
160
        }
 
161
        buf->vb.state = VIDEOBUF_PREPARED;
 
162
        return 0;
 
163
 
 
164
fail:
 
165
        cx18_dma_free(q, s, buf);
 
166
        return rc;
 
167
 
 
168
}
 
169
 
 
170
/* VB_MIN_BUFSIZE is lcm(1440 * 480, 1440 * 576)
 
171
   1440 is a single line of 4:2:2 YUV at 720 luma samples wide
 
172
*/
 
173
#define VB_MIN_BUFFERS 32
 
174
#define VB_MIN_BUFSIZE 4147200
 
175
 
 
176
static int buffer_setup(struct videobuf_queue *q,
 
177
        unsigned int *count, unsigned int *size)
 
178
{
 
179
        struct cx18_stream *s = q->priv_data;
 
180
        struct cx18 *cx = s->cx;
 
181
 
 
182
        *size = 2 * cx->cxhdl.width * cx->cxhdl.height;
 
183
        if (*count == 0)
 
184
                *count = VB_MIN_BUFFERS;
 
185
 
 
186
        while (*size * *count > VB_MIN_BUFFERS * VB_MIN_BUFSIZE)
 
187
                (*count)--;
 
188
 
 
189
        q->field = V4L2_FIELD_INTERLACED;
 
190
        q->last = V4L2_FIELD_INTERLACED;
 
191
 
 
192
        return 0;
 
193
}
 
194
 
 
195
static int buffer_prepare(struct videobuf_queue *q,
 
196
        struct videobuf_buffer *vb,
 
197
        enum v4l2_field field)
 
198
{
 
199
        struct cx18_videobuf_buffer *buf =
 
200
                container_of(vb, struct cx18_videobuf_buffer, vb);
 
201
        struct cx18_stream *s = q->priv_data;
 
202
        struct cx18 *cx = s->cx;
 
203
 
 
204
        return cx18_prepare_buffer(q, s, buf, s->pixelformat,
 
205
                cx->cxhdl.width, cx->cxhdl.height, field);
 
206
}
 
207
 
 
208
static void buffer_release(struct videobuf_queue *q,
 
209
        struct videobuf_buffer *vb)
 
210
{
 
211
        struct cx18_videobuf_buffer *buf =
 
212
                container_of(vb, struct cx18_videobuf_buffer, vb);
 
213
        struct cx18_stream *s = q->priv_data;
 
214
 
 
215
        cx18_dma_free(q, s, buf);
 
216
}
 
217
 
 
218
static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
 
219
{
 
220
        struct cx18_videobuf_buffer *buf =
 
221
                container_of(vb, struct cx18_videobuf_buffer, vb);
 
222
        struct cx18_stream *s = q->priv_data;
 
223
 
 
224
        buf->vb.state = VIDEOBUF_QUEUED;
 
225
 
 
226
        list_add_tail(&buf->vb.queue, &s->vb_capture);
 
227
}
 
228
 
 
229
static struct videobuf_queue_ops cx18_videobuf_qops = {
 
230
        .buf_setup    = buffer_setup,
 
231
        .buf_prepare  = buffer_prepare,
 
232
        .buf_queue    = buffer_queue,
 
233
        .buf_release  = buffer_release,
 
234
};
 
235
 
100
236
static void cx18_stream_init(struct cx18 *cx, int type)
101
237
{
102
238
        struct cx18_stream *s = &cx->streams[type];
132
268
        cx18_queue_init(&s->q_idle);
133
269
 
134
270
        INIT_WORK(&s->out_work_order, cx18_out_work_handler);
 
271
 
 
272
        INIT_LIST_HEAD(&s->vb_capture);
 
273
        s->vb_timeout.function = cx18_vb_timeout;
 
274
        s->vb_timeout.data = (unsigned long)s;
 
275
        init_timer(&s->vb_timeout);
 
276
        spin_lock_init(&s->vb_lock);
 
277
        if (type == CX18_ENC_STREAM_TYPE_YUV) {
 
278
                spin_lock_init(&s->vbuf_q_lock);
 
279
 
 
280
                s->vb_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
281
                videobuf_queue_vmalloc_init(&s->vbuf_q, &cx18_videobuf_qops,
 
282
                        &cx->pci_dev->dev, &s->vbuf_q_lock,
 
283
                        V4L2_BUF_TYPE_VIDEO_CAPTURE,
 
284
                        V4L2_FIELD_INTERLACED,
 
285
                        sizeof(struct cx18_videobuf_buffer),
 
286
                        s, &cx->serialize_lock);
 
287
 
 
288
                /* Assume the previous pixel default */
 
289
                s->pixelformat = V4L2_PIX_FMT_HM12;
 
290
        }
135
291
}
136
292
 
137
293
static int cx18_prep_dev(struct cx18 *cx, int type)
372
528
                if (vdev == NULL)
373
529
                        continue;
374
530
 
 
531
                if (type == CX18_ENC_STREAM_TYPE_YUV)
 
532
                        videobuf_mmap_free(&cx->streams[type].vbuf_q);
 
533
 
375
534
                cx18_stream_free(&cx->streams[type]);
376
535
 
377
536
                /* Unregister or release device */
581
740
                 * Set the MDL size to the exact size needed for one frame.
582
741
                 * Use enough buffers per MDL to cover the MDL size
583
742
                 */
584
 
                s->mdl_size = 720 * s->cx->cxhdl.height * 3 / 2;
 
743
                if (s->pixelformat == V4L2_PIX_FMT_HM12)
 
744
                        s->mdl_size = 720 * s->cx->cxhdl.height * 3 / 2;
 
745
                else
 
746
                        s->mdl_size = 720 * s->cx->cxhdl.height * 2;
585
747
                s->bufs_per_mdl = s->mdl_size / s->buf_size;
586
748
                if (s->mdl_size % s->buf_size)
587
749
                        s->bufs_per_mdl++;
729
891
                    test_bit(CX18_F_I_RADIO_USER, &cx->i_flags))
730
892
                        cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2, s->handle,
731
893
                          (v4l2_ctrl_g_ctrl(cx->cxhdl.video_mute_yuv) << 8) | 1);
 
894
 
 
895
                /* Enable the Video Format Converter for UYVY 4:2:2 support,
 
896
                 * rather than the default HM12 Macroblovk 4:2:0 support.
 
897
                 */
 
898
                if (captype == CAPTURE_CHANNEL_TYPE_YUV) {
 
899
                        if (s->pixelformat == V4L2_PIX_FMT_UYVY)
 
900
                                cx18_vapi(cx, CX18_CPU_SET_VFC_PARAM, 2,
 
901
                                        s->handle, 1);
 
902
                        else
 
903
                                /* If in doubt, default to HM12 */
 
904
                                cx18_vapi(cx, CX18_CPU_SET_VFC_PARAM, 2,
 
905
                                        s->handle, 0);
 
906
                }
732
907
        }
733
908
 
734
909
        if (atomic_read(&cx->tot_capturing) == 0) {