aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform/vivid/vivid-sdr-cap.c
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2015-10-20 23:52:40 +0200
committerHans Verkuil <hans.verkuil@cisco.com>2015-12-18 09:54:45 +0100
commitc0d2262161694c430037a39c143cbcbddc8ac703 (patch)
treed9ed070983d920a7ce5b4ef2687c7860194bb534 /drivers/media/platform/vivid/vivid-sdr-cap.c
parent52d60eb7e6d6429a766ea1b8f67e01c3b2dcd3c5 (diff)
vivid: wip for sdr output
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Diffstat (limited to 'drivers/media/platform/vivid/vivid-sdr-cap.c')
-rw-r--r--drivers/media/platform/vivid/vivid-sdr-cap.c135
1 files changed, 33 insertions, 102 deletions
diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.c b/drivers/media/platform/vivid/vivid-sdr-cap.c
index 082c401764ce..b6dedd257c2b 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
@@ -33,30 +33,12 @@
#include "vivid-core.h"
#include "vivid-ctrls.h"
#include "vivid-sdr-cap.h"
-
-/* stream formats */
-struct vivid_format {
- u32 pixelformat;
- u32 buffersize;
-};
-
-/* format descriptions for capture and preview */
-static const struct vivid_format formats[] = {
- {
- .pixelformat = V4L2_SDR_FMT_CU8,
- .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2,
- }, {
- .pixelformat = V4L2_SDR_FMT_CS8,
- .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2,
- },
-};
-
-static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
+#include "vivid-sdr-common.h"
static const struct v4l2_frequency_band bands_adc[] = {
{
.tuner = 0,
- .type = V4L2_TUNER_ADC,
+ .type = V4L2_TUNER_SDR,
.index = 0,
.capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
.rangelow = 300000,
@@ -64,7 +46,7 @@ static const struct v4l2_frequency_band bands_adc[] = {
},
{
.tuner = 0,
- .type = V4L2_TUNER_ADC,
+ .type = V4L2_TUNER_SDR,
.index = 1,
.capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
.rangelow = 900001,
@@ -72,7 +54,7 @@ static const struct v4l2_frequency_band bands_adc[] = {
},
{
.tuner = 0,
- .type = V4L2_TUNER_ADC,
+ .type = V4L2_TUNER_SDR,
.index = 2,
.capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
.rangelow = 3200000,
@@ -163,9 +145,9 @@ static int vivid_thread_sdr_cap(void *data)
jiffies_since_start = cur_jiffies - dev->jiffies_sdr_cap;
/* Get the number of buffers streamed since the start */
buffers_since_start =
- (u64)jiffies_since_start * dev->sdr_adc_freq +
- (HZ * SDR_CAP_SAMPLES_PER_BUF) / 2;
- do_div(buffers_since_start, HZ * SDR_CAP_SAMPLES_PER_BUF);
+ (u64)jiffies_since_start * dev->sdr_cap_adc_freq +
+ (HZ * SDR_SAMPLES_PER_BUF) / 2;
+ do_div(buffers_since_start, HZ * SDR_SAMPLES_PER_BUF);
/*
* After more than 0xf0000000 (rounded down to a multiple of
@@ -188,20 +170,20 @@ static int vivid_thread_sdr_cap(void *data)
* Calculate the number of samples streamed since we started,
* not including the current buffer.
*/
- samples_since_start = buffers_since_start * SDR_CAP_SAMPLES_PER_BUF;
+ samples_since_start = buffers_since_start * SDR_SAMPLES_PER_BUF;
/* And the number of jiffies since we started */
jiffies_since_start = jiffies - dev->jiffies_sdr_cap;
/* Increase by the number of samples in one buffer */
- samples_since_start += SDR_CAP_SAMPLES_PER_BUF;
+ samples_since_start += SDR_SAMPLES_PER_BUF;
/*
* Calculate when that next buffer is supposed to start
* in jiffies since we started streaming.
*/
next_jiffies_since_start = samples_since_start * HZ +
- dev->sdr_adc_freq / 2;
- do_div(next_jiffies_since_start, dev->sdr_adc_freq);
+ dev->sdr_cap_adc_freq / 2;
+ do_div(next_jiffies_since_start, dev->sdr_cap_adc_freq);
/* If it is in the past, then just schedule asap */
if (next_jiffies_since_start < jiffies_since_start)
next_jiffies_since_start = jiffies_since_start;
@@ -218,7 +200,7 @@ static int sdr_cap_queue_setup(struct vb2_queue *vq, const void *parg,
unsigned sizes[], void *alloc_ctxs[])
{
/* 2 = max 16-bit sample returned */
- sizes[0] = SDR_CAP_SAMPLES_PER_BUF * 2;
+ sizes[0] = SDR_SAMPLES_PER_BUF * 2;
*nplanes = 1;
return 0;
}
@@ -226,7 +208,7 @@ static int sdr_cap_queue_setup(struct vb2_queue *vq, const void *parg,
static int sdr_cap_buf_prepare(struct vb2_buffer *vb)
{
struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
- unsigned size = SDR_CAP_SAMPLES_PER_BUF * 2;
+ unsigned size = SDR_SAMPLES_PER_BUF * 2;
dprintk(dev, 1, "%s\n", __func__);
@@ -327,37 +309,18 @@ const struct vb2_ops vivid_sdr_cap_qops = {
.wait_finish = vb2_ops_wait_finish,
};
-int vivid_sdr_enum_freq_bands(struct file *file, void *fh,
- struct v4l2_frequency_band *band)
-{
- switch (band->tuner) {
- case 0:
- if (band->index >= ARRAY_SIZE(bands_adc))
- return -EINVAL;
- *band = bands_adc[band->index];
- return 0;
- case 1:
- if (band->index >= ARRAY_SIZE(bands_fm))
- return -EINVAL;
- *band = bands_fm[band->index];
- return 0;
- default:
- return -EINVAL;
- }
-}
-
-int vivid_sdr_g_frequency(struct file *file, void *fh,
+int vivid_sdr_cap_g_frequency(struct file *file, void *fh,
struct v4l2_frequency *vf)
{
struct vivid_dev *dev = video_drvdata(file);
switch (vf->tuner) {
case 0:
- vf->frequency = dev->sdr_adc_freq;
- vf->type = V4L2_TUNER_ADC;
+ vf->frequency = dev->sdr_cap_adc_freq;
+ vf->type = V4L2_TUNER_SDR;
return 0;
case 1:
- vf->frequency = dev->sdr_fm_freq;
+ vf->frequency = dev->sdr_cap_fm_freq;
vf->type = V4L2_TUNER_RF;
return 0;
default:
@@ -365,7 +328,7 @@ int vivid_sdr_g_frequency(struct file *file, void *fh,
}
}
-int vivid_sdr_s_frequency(struct file *file, void *fh,
+int vivid_sdr_cap_s_frequency(struct file *file, void *fh,
const struct v4l2_frequency *vf)
{
struct vivid_dev *dev = video_drvdata(file);
@@ -374,7 +337,7 @@ int vivid_sdr_s_frequency(struct file *file, void *fh,
switch (vf->tuner) {
case 0:
- if (vf->type != V4L2_TUNER_ADC)
+ if (vf->type != V4L2_TUNER_SDR)
return -EINVAL;
if (freq < BAND_ADC_0)
band = 0;
@@ -388,16 +351,16 @@ int vivid_sdr_s_frequency(struct file *file, void *fh,
bands_adc[band].rangehigh);
if (vb2_is_streaming(&dev->vb_sdr_cap_q) &&
- freq != dev->sdr_adc_freq) {
+ freq != dev->sdr_cap_adc_freq) {
/* resync the thread's timings */
dev->sdr_cap_seq_resync = true;
}
- dev->sdr_adc_freq = freq;
+ dev->sdr_cap_adc_freq = freq;
return 0;
case 1:
if (vf->type != V4L2_TUNER_RF)
return -EINVAL;
- dev->sdr_fm_freq = clamp_t(unsigned, freq,
+ dev->sdr_cap_fm_freq = clamp_t(unsigned, freq,
bands_fm[0].rangelow,
bands_fm[0].rangehigh);
return 0;
@@ -411,7 +374,7 @@ int vivid_sdr_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
switch (vt->index) {
case 0:
strlcpy(vt->name, "ADC", sizeof(vt->name));
- vt->type = V4L2_TUNER_ADC;
+ vt->type = V4L2_TUNER_SDR;
vt->capability =
V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
vt->rangelow = bands_adc[0].rangelow;
@@ -437,20 +400,14 @@ int vivid_sdr_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt)
return 0;
}
-int vidioc_enum_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
-{
- if (f->index >= ARRAY_SIZE(formats))
- return -EINVAL;
- f->pixelformat = formats[f->index].pixelformat;
- return 0;
-}
-
int vidioc_g_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
{
struct vivid_dev *dev = video_drvdata(file);
+ const struct vivid_sdr_fmt *fmt;
- f->fmt.sdr.pixelformat = dev->sdr_pixelformat;
- f->fmt.sdr.buffersize = dev->sdr_buffersize;
+ fmt = vivid_sdr_get_format(dev, dev->sdr_cap_pixelformat);
+ f->fmt.sdr.pixelformat = fmt->pixelformat;
+ f->fmt.sdr.buffersize = fmt->buffersize;
memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
return 0;
}
@@ -459,40 +416,14 @@ int vidioc_s_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
{
struct vivid_dev *dev = video_drvdata(file);
struct vb2_queue *q = &dev->vb_sdr_cap_q;
- int i;
+ const struct vivid_sdr_fmt *fmt;
if (vb2_is_busy(q))
return -EBUSY;
- memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
- for (i = 0; i < ARRAY_SIZE(formats); i++) {
- if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
- dev->sdr_pixelformat = formats[i].pixelformat;
- dev->sdr_buffersize = formats[i].buffersize;
- f->fmt.sdr.buffersize = formats[i].buffersize;
- return 0;
- }
- }
- dev->sdr_pixelformat = formats[0].pixelformat;
- dev->sdr_buffersize = formats[0].buffersize;
- f->fmt.sdr.pixelformat = formats[0].pixelformat;
- f->fmt.sdr.buffersize = formats[0].buffersize;
- return 0;
-}
-
-int vidioc_try_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
-{
- int i;
-
- memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
- for (i = 0; i < ARRAY_SIZE(formats); i++) {
- if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
- f->fmt.sdr.buffersize = formats[i].buffersize;
- return 0;
- }
- }
- f->fmt.sdr.pixelformat = formats[0].pixelformat;
- f->fmt.sdr.buffersize = formats[0].buffersize;
+ vivid_try_fmt_sdr(file, fh, f);
+ fmt = vivid_sdr_get_format(dev, dev->sdr_cap_pixelformat);
+ dev->sdr_cap_pixelformat = f->fmt.sdr.pixelformat;
return 0;
}
@@ -515,7 +446,7 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
/* calculate phase step */
#define BEEP_FREQ 1000 /* 1kHz beep */
src_phase_step = DIV_ROUND_CLOSEST(FIXP_2PI * BEEP_FREQ,
- dev->sdr_adc_freq);
+ dev->sdr_cap_adc_freq);
for (i = 0; i < plane_size; i += 2) {
mod_phase_step = fixp_cos32_rad(dev->sdr_fixp_src_phase,
@@ -544,7 +475,7 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
fixp_i >>= (31 - FIXP_N);
fixp_q >>= (31 - FIXP_N);
- switch (dev->sdr_pixelformat) {
+ switch (dev->sdr_cap_pixelformat) {
case V4L2_SDR_FMT_CU8:
/* convert 'fixp float' to u8 [0, +255] */
/* u8 = X * 127.5 + 127.5; X is float [-1.0, +1.0] */

Privacy Policy