vivid-sdr-cap.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * vivid-sdr-cap.c - software defined radio support functions.
  3. *
  4. * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  5. *
  6. * This program is free software; you may redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  11. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  14. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  15. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. * SOFTWARE.
  18. */
  19. #include <linux/errno.h>
  20. #include <linux/kernel.h>
  21. #include <linux/delay.h>
  22. #include <linux/kthread.h>
  23. #include <linux/freezer.h>
  24. #include <linux/videodev2.h>
  25. #include <linux/v4l2-dv-timings.h>
  26. #include <media/v4l2-common.h>
  27. #include <media/v4l2-event.h>
  28. #include <media/v4l2-dv-timings.h>
  29. #include <linux/fixp-arith.h>
  30. #include "vivid-core.h"
  31. #include "vivid-ctrls.h"
  32. #include "vivid-sdr-cap.h"
  33. /* stream formats */
  34. struct vivid_format {
  35. u32 pixelformat;
  36. u32 buffersize;
  37. };
  38. /* format descriptions for capture and preview */
  39. static struct vivid_format formats[] = {
  40. {
  41. .pixelformat = V4L2_SDR_FMT_CU8,
  42. .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2,
  43. }, {
  44. .pixelformat = V4L2_SDR_FMT_CS8,
  45. .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2,
  46. },
  47. };
  48. static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
  49. static const struct v4l2_frequency_band bands_adc[] = {
  50. {
  51. .tuner = 0,
  52. .type = V4L2_TUNER_ADC,
  53. .index = 0,
  54. .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
  55. .rangelow = 300000,
  56. .rangehigh = 300000,
  57. },
  58. {
  59. .tuner = 0,
  60. .type = V4L2_TUNER_ADC,
  61. .index = 1,
  62. .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
  63. .rangelow = 900001,
  64. .rangehigh = 2800000,
  65. },
  66. {
  67. .tuner = 0,
  68. .type = V4L2_TUNER_ADC,
  69. .index = 2,
  70. .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
  71. .rangelow = 3200000,
  72. .rangehigh = 3200000,
  73. },
  74. };
  75. /* ADC band midpoints */
  76. #define BAND_ADC_0 ((bands_adc[0].rangehigh + bands_adc[1].rangelow) / 2)
  77. #define BAND_ADC_1 ((bands_adc[1].rangehigh + bands_adc[2].rangelow) / 2)
  78. static const struct v4l2_frequency_band bands_fm[] = {
  79. {
  80. .tuner = 1,
  81. .type = V4L2_TUNER_RF,
  82. .index = 0,
  83. .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
  84. .rangelow = 50000000,
  85. .rangehigh = 2000000000,
  86. },
  87. };
  88. static void vivid_thread_sdr_cap_tick(struct vivid_dev *dev)
  89. {
  90. struct vivid_buffer *sdr_cap_buf = NULL;
  91. dprintk(dev, 1, "SDR Capture Thread Tick\n");
  92. /* Drop a certain percentage of buffers. */
  93. if (dev->perc_dropped_buffers &&
  94. prandom_u32_max(100) < dev->perc_dropped_buffers)
  95. return;
  96. spin_lock(&dev->slock);
  97. if (!list_empty(&dev->sdr_cap_active)) {
  98. sdr_cap_buf = list_entry(dev->sdr_cap_active.next,
  99. struct vivid_buffer, list);
  100. list_del(&sdr_cap_buf->list);
  101. }
  102. spin_unlock(&dev->slock);
  103. if (sdr_cap_buf) {
  104. sdr_cap_buf->vb.v4l2_buf.sequence = dev->sdr_cap_seq_count;
  105. vivid_sdr_cap_process(dev, sdr_cap_buf);
  106. v4l2_get_timestamp(&sdr_cap_buf->vb.v4l2_buf.timestamp);
  107. sdr_cap_buf->vb.v4l2_buf.timestamp.tv_sec += dev->time_wrap_offset;
  108. vb2_buffer_done(&sdr_cap_buf->vb, dev->dqbuf_error ?
  109. VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
  110. dev->dqbuf_error = false;
  111. }
  112. }
  113. static int vivid_thread_sdr_cap(void *data)
  114. {
  115. struct vivid_dev *dev = data;
  116. u64 samples_since_start;
  117. u64 buffers_since_start;
  118. u64 next_jiffies_since_start;
  119. unsigned long jiffies_since_start;
  120. unsigned long cur_jiffies;
  121. unsigned wait_jiffies;
  122. dprintk(dev, 1, "SDR Capture Thread Start\n");
  123. set_freezable();
  124. /* Resets frame counters */
  125. dev->sdr_cap_seq_offset = 0;
  126. if (dev->seq_wrap)
  127. dev->sdr_cap_seq_offset = 0xffffff80U;
  128. dev->jiffies_sdr_cap = jiffies;
  129. dev->sdr_cap_seq_resync = false;
  130. for (;;) {
  131. try_to_freeze();
  132. if (kthread_should_stop())
  133. break;
  134. mutex_lock(&dev->mutex);
  135. cur_jiffies = jiffies;
  136. if (dev->sdr_cap_seq_resync) {
  137. dev->jiffies_sdr_cap = cur_jiffies;
  138. dev->sdr_cap_seq_offset = dev->sdr_cap_seq_count + 1;
  139. dev->sdr_cap_seq_count = 0;
  140. dev->sdr_cap_seq_resync = false;
  141. }
  142. /* Calculate the number of jiffies since we started streaming */
  143. jiffies_since_start = cur_jiffies - dev->jiffies_sdr_cap;
  144. /* Get the number of buffers streamed since the start */
  145. buffers_since_start = (u64)jiffies_since_start * dev->sdr_adc_freq +
  146. (HZ * SDR_CAP_SAMPLES_PER_BUF) / 2;
  147. do_div(buffers_since_start, HZ * SDR_CAP_SAMPLES_PER_BUF);
  148. /*
  149. * After more than 0xf0000000 (rounded down to a multiple of
  150. * 'jiffies-per-day' to ease jiffies_to_msecs calculation)
  151. * jiffies have passed since we started streaming reset the
  152. * counters and keep track of the sequence offset.
  153. */
  154. if (jiffies_since_start > JIFFIES_RESYNC) {
  155. dev->jiffies_sdr_cap = cur_jiffies;
  156. dev->sdr_cap_seq_offset = buffers_since_start;
  157. buffers_since_start = 0;
  158. }
  159. dev->sdr_cap_seq_count = buffers_since_start + dev->sdr_cap_seq_offset;
  160. vivid_thread_sdr_cap_tick(dev);
  161. mutex_unlock(&dev->mutex);
  162. /*
  163. * Calculate the number of samples streamed since we started,
  164. * not including the current buffer.
  165. */
  166. samples_since_start = buffers_since_start * SDR_CAP_SAMPLES_PER_BUF;
  167. /* And the number of jiffies since we started */
  168. jiffies_since_start = jiffies - dev->jiffies_sdr_cap;
  169. /* Increase by the number of samples in one buffer */
  170. samples_since_start += SDR_CAP_SAMPLES_PER_BUF;
  171. /*
  172. * Calculate when that next buffer is supposed to start
  173. * in jiffies since we started streaming.
  174. */
  175. next_jiffies_since_start = samples_since_start * HZ +
  176. dev->sdr_adc_freq / 2;
  177. do_div(next_jiffies_since_start, dev->sdr_adc_freq);
  178. /* If it is in the past, then just schedule asap */
  179. if (next_jiffies_since_start < jiffies_since_start)
  180. next_jiffies_since_start = jiffies_since_start;
  181. wait_jiffies = next_jiffies_since_start - jiffies_since_start;
  182. schedule_timeout_interruptible(wait_jiffies ? wait_jiffies : 1);
  183. }
  184. dprintk(dev, 1, "SDR Capture Thread End\n");
  185. return 0;
  186. }
  187. static int sdr_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  188. unsigned *nbuffers, unsigned *nplanes,
  189. unsigned sizes[], void *alloc_ctxs[])
  190. {
  191. /* 2 = max 16-bit sample returned */
  192. sizes[0] = SDR_CAP_SAMPLES_PER_BUF * 2;
  193. *nplanes = 1;
  194. return 0;
  195. }
  196. static int sdr_cap_buf_prepare(struct vb2_buffer *vb)
  197. {
  198. struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  199. unsigned size = SDR_CAP_SAMPLES_PER_BUF * 2;
  200. dprintk(dev, 1, "%s\n", __func__);
  201. if (dev->buf_prepare_error) {
  202. /*
  203. * Error injection: test what happens if buf_prepare() returns
  204. * an error.
  205. */
  206. dev->buf_prepare_error = false;
  207. return -EINVAL;
  208. }
  209. if (vb2_plane_size(vb, 0) < size) {
  210. dprintk(dev, 1, "%s data will not fit into plane (%lu < %u)\n",
  211. __func__, vb2_plane_size(vb, 0), size);
  212. return -EINVAL;
  213. }
  214. vb2_set_plane_payload(vb, 0, size);
  215. return 0;
  216. }
  217. static void sdr_cap_buf_queue(struct vb2_buffer *vb)
  218. {
  219. struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  220. struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
  221. dprintk(dev, 1, "%s\n", __func__);
  222. spin_lock(&dev->slock);
  223. list_add_tail(&buf->list, &dev->sdr_cap_active);
  224. spin_unlock(&dev->slock);
  225. }
  226. static int sdr_cap_start_streaming(struct vb2_queue *vq, unsigned count)
  227. {
  228. struct vivid_dev *dev = vb2_get_drv_priv(vq);
  229. int err = 0;
  230. dprintk(dev, 1, "%s\n", __func__);
  231. dev->sdr_cap_seq_count = 0;
  232. if (dev->start_streaming_error) {
  233. dev->start_streaming_error = false;
  234. err = -EINVAL;
  235. } else if (dev->kthread_sdr_cap == NULL) {
  236. dev->kthread_sdr_cap = kthread_run(vivid_thread_sdr_cap, dev,
  237. "%s-sdr-cap", dev->v4l2_dev.name);
  238. if (IS_ERR(dev->kthread_sdr_cap)) {
  239. v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n");
  240. err = PTR_ERR(dev->kthread_sdr_cap);
  241. dev->kthread_sdr_cap = NULL;
  242. }
  243. }
  244. if (err) {
  245. struct vivid_buffer *buf, *tmp;
  246. list_for_each_entry_safe(buf, tmp, &dev->sdr_cap_active, list) {
  247. list_del(&buf->list);
  248. vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
  249. }
  250. }
  251. return err;
  252. }
  253. /* abort streaming and wait for last buffer */
  254. static void sdr_cap_stop_streaming(struct vb2_queue *vq)
  255. {
  256. struct vivid_dev *dev = vb2_get_drv_priv(vq);
  257. if (dev->kthread_sdr_cap == NULL)
  258. return;
  259. while (!list_empty(&dev->sdr_cap_active)) {
  260. struct vivid_buffer *buf;
  261. buf = list_entry(dev->sdr_cap_active.next, struct vivid_buffer, list);
  262. list_del(&buf->list);
  263. vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  264. }
  265. /* shutdown control thread */
  266. mutex_unlock(&dev->mutex);
  267. kthread_stop(dev->kthread_sdr_cap);
  268. dev->kthread_sdr_cap = NULL;
  269. mutex_lock(&dev->mutex);
  270. }
  271. const struct vb2_ops vivid_sdr_cap_qops = {
  272. .queue_setup = sdr_cap_queue_setup,
  273. .buf_prepare = sdr_cap_buf_prepare,
  274. .buf_queue = sdr_cap_buf_queue,
  275. .start_streaming = sdr_cap_start_streaming,
  276. .stop_streaming = sdr_cap_stop_streaming,
  277. .wait_prepare = vb2_ops_wait_prepare,
  278. .wait_finish = vb2_ops_wait_finish,
  279. };
  280. int vivid_sdr_enum_freq_bands(struct file *file, void *fh, struct v4l2_frequency_band *band)
  281. {
  282. switch (band->tuner) {
  283. case 0:
  284. if (band->index >= ARRAY_SIZE(bands_adc))
  285. return -EINVAL;
  286. *band = bands_adc[band->index];
  287. return 0;
  288. case 1:
  289. if (band->index >= ARRAY_SIZE(bands_fm))
  290. return -EINVAL;
  291. *band = bands_fm[band->index];
  292. return 0;
  293. default:
  294. return -EINVAL;
  295. }
  296. }
  297. int vivid_sdr_g_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
  298. {
  299. struct vivid_dev *dev = video_drvdata(file);
  300. switch (vf->tuner) {
  301. case 0:
  302. vf->frequency = dev->sdr_adc_freq;
  303. vf->type = V4L2_TUNER_ADC;
  304. return 0;
  305. case 1:
  306. vf->frequency = dev->sdr_fm_freq;
  307. vf->type = V4L2_TUNER_RF;
  308. return 0;
  309. default:
  310. return -EINVAL;
  311. }
  312. }
  313. int vivid_sdr_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf)
  314. {
  315. struct vivid_dev *dev = video_drvdata(file);
  316. unsigned freq = vf->frequency;
  317. unsigned band;
  318. switch (vf->tuner) {
  319. case 0:
  320. if (vf->type != V4L2_TUNER_ADC)
  321. return -EINVAL;
  322. if (freq < BAND_ADC_0)
  323. band = 0;
  324. else if (freq < BAND_ADC_1)
  325. band = 1;
  326. else
  327. band = 2;
  328. freq = clamp_t(unsigned, freq,
  329. bands_adc[band].rangelow,
  330. bands_adc[band].rangehigh);
  331. if (vb2_is_streaming(&dev->vb_sdr_cap_q) &&
  332. freq != dev->sdr_adc_freq) {
  333. /* resync the thread's timings */
  334. dev->sdr_cap_seq_resync = true;
  335. }
  336. dev->sdr_adc_freq = freq;
  337. return 0;
  338. case 1:
  339. if (vf->type != V4L2_TUNER_RF)
  340. return -EINVAL;
  341. dev->sdr_fm_freq = clamp_t(unsigned, freq,
  342. bands_fm[0].rangelow,
  343. bands_fm[0].rangehigh);
  344. return 0;
  345. default:
  346. return -EINVAL;
  347. }
  348. }
  349. int vivid_sdr_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
  350. {
  351. switch (vt->index) {
  352. case 0:
  353. strlcpy(vt->name, "ADC", sizeof(vt->name));
  354. vt->type = V4L2_TUNER_ADC;
  355. vt->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
  356. vt->rangelow = bands_adc[0].rangelow;
  357. vt->rangehigh = bands_adc[2].rangehigh;
  358. return 0;
  359. case 1:
  360. strlcpy(vt->name, "RF", sizeof(vt->name));
  361. vt->type = V4L2_TUNER_RF;
  362. vt->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
  363. vt->rangelow = bands_fm[0].rangelow;
  364. vt->rangehigh = bands_fm[0].rangehigh;
  365. return 0;
  366. default:
  367. return -EINVAL;
  368. }
  369. }
  370. int vivid_sdr_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt)
  371. {
  372. if (vt->index > 1)
  373. return -EINVAL;
  374. return 0;
  375. }
  376. int vidioc_enum_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
  377. {
  378. if (f->index >= ARRAY_SIZE(formats))
  379. return -EINVAL;
  380. f->pixelformat = formats[f->index].pixelformat;
  381. return 0;
  382. }
  383. int vidioc_g_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
  384. {
  385. struct vivid_dev *dev = video_drvdata(file);
  386. f->fmt.sdr.pixelformat = dev->sdr_pixelformat;
  387. f->fmt.sdr.buffersize = dev->sdr_buffersize;
  388. memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
  389. return 0;
  390. }
  391. int vidioc_s_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
  392. {
  393. struct vivid_dev *dev = video_drvdata(file);
  394. struct vb2_queue *q = &dev->vb_sdr_cap_q;
  395. int i;
  396. if (vb2_is_busy(q))
  397. return -EBUSY;
  398. memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
  399. for (i = 0; i < ARRAY_SIZE(formats); i++) {
  400. if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
  401. dev->sdr_pixelformat = formats[i].pixelformat;
  402. dev->sdr_buffersize = formats[i].buffersize;
  403. f->fmt.sdr.buffersize = formats[i].buffersize;
  404. return 0;
  405. }
  406. }
  407. dev->sdr_pixelformat = formats[0].pixelformat;
  408. dev->sdr_buffersize = formats[0].buffersize;
  409. f->fmt.sdr.pixelformat = formats[0].pixelformat;
  410. f->fmt.sdr.buffersize = formats[0].buffersize;
  411. return 0;
  412. }
  413. int vidioc_try_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
  414. {
  415. int i;
  416. memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
  417. for (i = 0; i < ARRAY_SIZE(formats); i++) {
  418. if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
  419. f->fmt.sdr.buffersize = formats[i].buffersize;
  420. return 0;
  421. }
  422. }
  423. f->fmt.sdr.pixelformat = formats[0].pixelformat;
  424. f->fmt.sdr.buffersize = formats[0].buffersize;
  425. return 0;
  426. }
  427. #define FIXP_N (15)
  428. #define FIXP_FRAC (1 << FIXP_N)
  429. #define FIXP_2PI ((int)(2 * 3.141592653589 * FIXP_FRAC))
  430. void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
  431. {
  432. u8 *vbuf = vb2_plane_vaddr(&buf->vb, 0);
  433. unsigned long i;
  434. unsigned long plane_size = vb2_plane_size(&buf->vb, 0);
  435. s32 src_phase_step;
  436. s32 mod_phase_step;
  437. s32 fixp_i;
  438. s32 fixp_q;
  439. /*
  440. * TODO: Generated beep tone goes very crackly when sample rate is
  441. * increased to ~1Msps or more. That is because of huge rounding error
  442. * of phase angle caused by used cosine implementation.
  443. */
  444. /* calculate phase step */
  445. #define BEEP_FREQ 1000 /* 1kHz beep */
  446. src_phase_step = DIV_ROUND_CLOSEST(FIXP_2PI * BEEP_FREQ,
  447. dev->sdr_adc_freq);
  448. for (i = 0; i < plane_size; i += 2) {
  449. mod_phase_step = fixp_cos32_rad(dev->sdr_fixp_src_phase,
  450. FIXP_2PI) >> (31 - FIXP_N);
  451. dev->sdr_fixp_src_phase += src_phase_step;
  452. dev->sdr_fixp_mod_phase += mod_phase_step / 4;
  453. /*
  454. * Transfer phases to [0 / 2xPI] in order to avoid variable
  455. * overflow and make it suitable for cosine implementation
  456. * used, which does not support negative angles.
  457. */
  458. while (dev->sdr_fixp_mod_phase < FIXP_2PI)
  459. dev->sdr_fixp_mod_phase += FIXP_2PI;
  460. while (dev->sdr_fixp_mod_phase > FIXP_2PI)
  461. dev->sdr_fixp_mod_phase -= FIXP_2PI;
  462. while (dev->sdr_fixp_src_phase > FIXP_2PI)
  463. dev->sdr_fixp_src_phase -= FIXP_2PI;
  464. fixp_i = fixp_cos32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI);
  465. fixp_q = fixp_sin32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI);
  466. /* Normalize fraction values represented with 32 bit precision
  467. * to fixed point representation with FIXP_N bits */
  468. fixp_i >>= (31 - FIXP_N);
  469. fixp_q >>= (31 - FIXP_N);
  470. switch (dev->sdr_pixelformat) {
  471. case V4L2_SDR_FMT_CU8:
  472. /* convert 'fixp float' to u8 */
  473. /* u8 = X * 127.5 + 127.5; X is float [-1.0, +1.0] */
  474. fixp_i = fixp_i * 1275 + FIXP_FRAC * 1275;
  475. fixp_q = fixp_q * 1275 + FIXP_FRAC * 1275;
  476. *vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10);
  477. *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10);
  478. break;
  479. case V4L2_SDR_FMT_CS8:
  480. /* convert 'fixp float' to s8 */
  481. fixp_i = fixp_i * 1275;
  482. fixp_q = fixp_q * 1275;
  483. *vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10);
  484. *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10);
  485. break;
  486. default:
  487. break;
  488. }
  489. }
  490. }