Lines Matching refs:solo_enc

93 static int solo_is_motion_on(struct solo_enc_dev *solo_enc)  in solo_is_motion_on()  argument
95 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_is_motion_on()
97 return (solo_dev->motion_mask >> solo_enc->ch) & 1; in solo_is_motion_on()
100 static int solo_motion_detected(struct solo_enc_dev *solo_enc) in solo_motion_detected() argument
102 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_motion_detected()
104 u32 ch_mask = 1 << solo_enc->ch; in solo_motion_detected()
107 spin_lock_irqsave(&solo_enc->motion_lock, flags); in solo_motion_detected()
112 spin_unlock_irqrestore(&solo_enc->motion_lock, flags); in solo_motion_detected()
117 static void solo_motion_toggle(struct solo_enc_dev *solo_enc, int on) in solo_motion_toggle() argument
119 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_motion_toggle()
120 u32 mask = 1 << solo_enc->ch; in solo_motion_toggle()
123 spin_lock_irqsave(&solo_enc->motion_lock, flags); in solo_motion_toggle()
136 spin_unlock_irqrestore(&solo_enc->motion_lock, flags); in solo_motion_toggle()
139 void solo_update_mode(struct solo_enc_dev *solo_enc) in solo_update_mode() argument
141 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_update_mode()
145 solo_enc->interlaced = (solo_enc->mode & 0x08) ? 1 : 0; in solo_update_mode()
146 solo_enc->bw_weight = max(solo_dev->fps / solo_enc->interval, 1); in solo_update_mode()
148 if (solo_enc->mode == SOLO_ENC_MODE_CIF) { in solo_update_mode()
149 solo_enc->width = solo_dev->video_hsize >> 1; in solo_update_mode()
150 solo_enc->height = solo_dev->video_vsize; in solo_update_mode()
169 solo_enc->width = solo_dev->video_hsize; in solo_update_mode()
170 solo_enc->height = solo_dev->video_vsize << 1; in solo_update_mode()
171 solo_enc->bw_weight <<= 2; in solo_update_mode()
191 memcpy(solo_enc->vop, vop, vop_len); in solo_update_mode()
196 u16 interval = solo_enc->interval * 1000; in solo_update_mode()
198 vop = solo_enc->vop; in solo_update_mode()
208 solo_enc->vop_len = vop_len; in solo_update_mode()
211 vop = solo_enc->jpeg_header; in solo_update_mode()
212 vop[SOF0_START + 5] = 0xff & (solo_enc->height >> 8); in solo_update_mode()
213 vop[SOF0_START + 6] = 0xff & solo_enc->height; in solo_update_mode()
214 vop[SOF0_START + 7] = 0xff & (solo_enc->width >> 8); in solo_update_mode()
215 vop[SOF0_START + 8] = 0xff & solo_enc->width; in solo_update_mode()
218 jpeg_dqt[solo_g_jpeg_qp(solo_dev, solo_enc->ch)], DQT_LEN); in solo_update_mode()
221 static int solo_enc_on(struct solo_enc_dev *solo_enc) in solo_enc_on() argument
223 u8 ch = solo_enc->ch; in solo_enc_on()
224 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enc_on()
227 solo_update_mode(solo_enc); in solo_enc_on()
230 if (solo_enc->bw_weight > solo_dev->enc_bw_remain) in solo_enc_on()
232 solo_enc->sequence = 0; in solo_enc_on()
233 solo_dev->enc_bw_remain -= solo_enc->bw_weight; in solo_enc_on()
235 if (solo_enc->type == SOLO_ENC_TYPE_EXT) in solo_enc_on()
243 solo_enc->interlaced ? 1 : 0); in solo_enc_on()
245 if (solo_enc->interlaced) in solo_enc_on()
246 interval = solo_enc->interval - 1; in solo_enc_on()
248 interval = solo_enc->interval; in solo_enc_on()
251 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(ch), solo_enc->gop); in solo_enc_on()
252 solo_reg_write(solo_dev, SOLO_VE_CH_QP(ch), solo_enc->qp); in solo_enc_on()
256 solo_reg_write(solo_dev, SOLO_VE_CH_GOP_E(ch), solo_enc->gop); in solo_enc_on()
257 solo_reg_write(solo_dev, SOLO_VE_CH_QP_E(ch), solo_enc->qp); in solo_enc_on()
261 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(ch), solo_enc->mode); in solo_enc_on()
266 static void solo_enc_off(struct solo_enc_dev *solo_enc) in solo_enc_off() argument
268 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enc_off()
270 solo_dev->enc_bw_remain += solo_enc->bw_weight; in solo_enc_off()
272 solo_reg_write(solo_dev, SOLO_CAP_CH_SCALE(solo_enc->ch), 0); in solo_enc_off()
273 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(solo_enc->ch), 0); in solo_enc_off()
308 static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip, in solo_send_desc() argument
312 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_send_desc()
320 solo_enc->desc_count = 1; in solo_send_desc()
328 desc = &solo_enc->desc_items[solo_enc->desc_count++]; in solo_send_desc()
364 solo_enc->desc_count--; in solo_send_desc()
376 if (solo_enc->desc_count >= (solo_enc->desc_nelts - 1)) { in solo_send_desc()
377 ret = solo_p2m_dma_desc(solo_dev, solo_enc->desc_items, in solo_send_desc()
378 solo_enc->desc_dma, in solo_send_desc()
379 solo_enc->desc_count - 1); in solo_send_desc()
382 solo_enc->desc_count = 1; in solo_send_desc()
386 if (solo_enc->desc_count <= 1) in solo_send_desc()
389 return solo_p2m_dma_desc(solo_dev, solo_enc->desc_items, in solo_send_desc()
390 solo_enc->desc_dma, solo_enc->desc_count - 1); in solo_send_desc()
449 static int solo_fill_jpeg(struct solo_enc_dev *solo_enc, in solo_fill_jpeg() argument
453 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_fill_jpeg()
459 if (vb2_plane_size(vb, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len) in solo_fill_jpeg()
462 frame_size = ALIGN(vop_jpeg_size(vh) + solo_enc->jpeg_len, DMA_ALIGN); in solo_fill_jpeg()
463 vb2_set_plane_payload(vb, 0, vop_jpeg_size(vh) + solo_enc->jpeg_len); in solo_fill_jpeg()
465 return solo_send_desc(solo_enc, solo_enc->jpeg_len, sgt, in solo_fill_jpeg()
471 static int solo_fill_mpeg(struct solo_enc_dev *solo_enc, in solo_fill_mpeg() argument
475 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_fill_mpeg()
487 skip = solo_enc->vop_len; in solo_fill_mpeg()
490 solo_enc->vop_len); in solo_fill_mpeg()
501 return solo_send_desc(solo_enc, skip, sgt, frame_off, frame_size, in solo_fill_mpeg()
506 static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc, in solo_enc_fillbuf() argument
513 switch (solo_enc->fmt) { in solo_enc_fillbuf()
516 ret = solo_fill_mpeg(solo_enc, vb, vh); in solo_enc_fillbuf()
519 ret = solo_fill_jpeg(solo_enc, vb, vh); in solo_enc_fillbuf()
524 vbuf->sequence = solo_enc->sequence++; in solo_enc_fillbuf()
528 if (solo_is_motion_on(solo_enc) && enc_buf->motion) { in solo_enc_fillbuf()
539 v4l2_event_queue(solo_enc->vfd, &ev); in solo_enc_fillbuf()
548 static void solo_enc_handle_one(struct solo_enc_dev *solo_enc, in solo_enc_handle_one() argument
554 mutex_lock(&solo_enc->lock); in solo_enc_handle_one()
555 if (solo_enc->type != enc_buf->type) in solo_enc_handle_one()
558 spin_lock_irqsave(&solo_enc->av_lock, flags); in solo_enc_handle_one()
559 if (list_empty(&solo_enc->vidq_active)) { in solo_enc_handle_one()
560 spin_unlock_irqrestore(&solo_enc->av_lock, flags); in solo_enc_handle_one()
563 vb = list_first_entry(&solo_enc->vidq_active, struct solo_vb2_buf, in solo_enc_handle_one()
566 spin_unlock_irqrestore(&solo_enc->av_lock, flags); in solo_enc_handle_one()
568 solo_enc_fillbuf(solo_enc, &vb->vb.vb2_buf, enc_buf); in solo_enc_handle_one()
570 mutex_unlock(&solo_enc->lock); in solo_enc_handle_one()
581 struct solo_enc_dev *solo_enc; in solo_handle_ring() local
605 solo_enc = solo_dev->v4l2_enc[ch]; in solo_handle_ring()
606 if (solo_enc == NULL) { in solo_handle_ring()
624 if (solo_motion_detected(solo_enc)) in solo_handle_ring()
629 solo_enc_handle_one(solo_enc, &enc_buf); in solo_handle_ring()
673 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vq); in solo_enc_buf_queue() local
677 spin_lock(&solo_enc->av_lock); in solo_enc_buf_queue()
678 list_add_tail(&solo_vb->list, &solo_enc->vidq_active); in solo_enc_buf_queue()
679 spin_unlock(&solo_enc->av_lock); in solo_enc_buf_queue()
710 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q); in solo_enc_start_streaming() local
712 return solo_enc_on(solo_enc); in solo_enc_start_streaming()
717 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q); in solo_enc_stop_streaming() local
720 spin_lock_irqsave(&solo_enc->av_lock, flags); in solo_enc_stop_streaming()
721 solo_enc_off(solo_enc); in solo_enc_stop_streaming()
722 while (!list_empty(&solo_enc->vidq_active)) { in solo_enc_stop_streaming()
724 solo_enc->vidq_active.next, in solo_enc_stop_streaming()
730 spin_unlock_irqrestore(&solo_enc->av_lock, flags); in solo_enc_stop_streaming()
736 struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vb->vb2_queue); in solo_enc_buf_finish() local
739 switch (solo_enc->fmt) { in solo_enc_buf_finish()
744 solo_enc->vop, solo_enc->vop_len); in solo_enc_buf_finish()
748 solo_enc->jpeg_header, solo_enc->jpeg_len); in solo_enc_buf_finish()
766 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_querycap() local
770 solo_enc->ch); in solo_enc_querycap()
777 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_enum_input() local
778 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enc_enum_input()
784 solo_enc->ch + 1); in solo_enc_enum_input()
786 input->std = solo_enc->vfd->tvnorms; in solo_enc_enum_input()
788 if (!tw28_get_video_status(solo_dev, solo_enc->ch)) in solo_enc_enum_input()
814 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_enum_fmt_cap() local
815 int dev_type = solo_enc->solo_dev->type; in solo_enc_enum_fmt_cap()
847 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_try_fmt_cap() local
848 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enc_try_fmt_cap()
886 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_set_fmt_cap() local
887 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enc_set_fmt_cap()
891 if (vb2_is_busy(&solo_enc->vidq)) in solo_enc_set_fmt_cap()
899 solo_enc->mode = SOLO_ENC_MODE_D1; in solo_enc_set_fmt_cap()
901 solo_enc->mode = SOLO_ENC_MODE_CIF; in solo_enc_set_fmt_cap()
904 solo_enc->fmt = pix->pixelformat; in solo_enc_set_fmt_cap()
916 solo_update_mode(solo_enc); in solo_enc_set_fmt_cap()
923 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_get_fmt_cap() local
926 pix->width = solo_enc->width; in solo_enc_get_fmt_cap()
927 pix->height = solo_enc->height; in solo_enc_get_fmt_cap()
928 pix->pixelformat = solo_enc->fmt; in solo_enc_get_fmt_cap()
929 pix->field = solo_enc->interlaced ? V4L2_FIELD_INTERLACED : in solo_enc_get_fmt_cap()
939 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_g_std() local
940 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enc_g_std()
951 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enc_s_std() local
953 return solo_set_video_type(solo_enc->solo_dev, std & V4L2_STD_625_50); in solo_enc_s_std()
959 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enum_framesizes() local
960 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enum_framesizes()
986 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_enum_frameintervals() local
987 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_enum_frameintervals()
1016 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_g_parm() local
1020 cp->timeperframe.numerator = solo_enc->interval; in solo_g_parm()
1021 cp->timeperframe.denominator = solo_enc->solo_dev->fps; in solo_g_parm()
1042 struct solo_enc_dev *solo_enc = video_drvdata(file); in solo_s_parm() local
1044 u8 fps = solo_enc->solo_dev->fps; in solo_s_parm()
1046 if (vb2_is_streaming(&solo_enc->vidq)) in solo_s_parm()
1049 solo_enc->interval = calc_interval(fps, t->numerator, t->denominator); in solo_s_parm()
1050 solo_update_mode(solo_enc); in solo_s_parm()
1056 struct solo_enc_dev *solo_enc = in solo_s_ctrl() local
1058 struct solo_dev *solo_dev = solo_enc->solo_dev; in solo_s_ctrl()
1067 return tw28_set_ctrl_val(solo_dev, ctrl->id, solo_enc->ch, in solo_s_ctrl()
1070 solo_enc->gop = ctrl->val; in solo_s_ctrl()
1071 solo_reg_write(solo_dev, SOLO_VE_CH_GOP(solo_enc->ch), solo_enc->gop); in solo_s_ctrl()
1072 solo_reg_write(solo_dev, SOLO_VE_CH_GOP_E(solo_enc->ch), solo_enc->gop); in solo_s_ctrl()
1075 solo_enc->qp = ctrl->val; in solo_s_ctrl()
1076 solo_reg_write(solo_dev, SOLO_VE_CH_QP(solo_enc->ch), solo_enc->qp); in solo_s_ctrl()
1077 solo_reg_write(solo_dev, SOLO_VE_CH_QP_E(solo_enc->ch), solo_enc->qp); in solo_s_ctrl()
1080 solo_enc->motion_thresh = ctrl->val << 8; in solo_s_ctrl()
1081 if (!solo_enc->motion_global || !solo_enc->motion_enabled) in solo_s_ctrl()
1083 return solo_set_motion_threshold(solo_dev, solo_enc->ch, in solo_s_ctrl()
1084 solo_enc->motion_thresh); in solo_s_ctrl()
1086 solo_enc->motion_global = ctrl->val == V4L2_DETECT_MD_MODE_GLOBAL; in solo_s_ctrl()
1087 solo_enc->motion_enabled = ctrl->val > V4L2_DETECT_MD_MODE_DISABLED; in solo_s_ctrl()
1089 if (solo_enc->motion_global) in solo_s_ctrl()
1090 err = solo_set_motion_threshold(solo_dev, solo_enc->ch, in solo_s_ctrl()
1091 solo_enc->motion_thresh); in solo_s_ctrl()
1093 err = solo_set_motion_block(solo_dev, solo_enc->ch, in solo_s_ctrl()
1094 solo_enc->md_thresholds->p_cur.p_u16); in solo_s_ctrl()
1098 solo_motion_toggle(solo_enc, ctrl->val); in solo_s_ctrl()
1101 if (solo_enc->motion_enabled && !solo_enc->motion_global) in solo_s_ctrl()
1102 return solo_set_motion_block(solo_dev, solo_enc->ch, in solo_s_ctrl()
1103 solo_enc->md_thresholds->p_new.p_u16); in solo_s_ctrl()
1106 strscpy(solo_enc->osd_text, ctrl->p_new.p_char, in solo_s_ctrl()
1107 sizeof(solo_enc->osd_text)); in solo_s_ctrl()
1108 return solo_osd_print(solo_enc); in solo_s_ctrl()
1209 struct solo_enc_dev *solo_enc; in solo_enc_alloc() local
1213 solo_enc = kzalloc(sizeof(*solo_enc), GFP_KERNEL); in solo_enc_alloc()
1214 if (!solo_enc) in solo_enc_alloc()
1217 hdl = &solo_enc->hdl; in solo_enc_alloc()
1242 solo_enc->md_thresholds = in solo_enc_alloc()
1249 solo_enc->solo_dev = solo_dev; in solo_enc_alloc()
1250 solo_enc->ch = ch; in solo_enc_alloc()
1251 mutex_init(&solo_enc->lock); in solo_enc_alloc()
1252 spin_lock_init(&solo_enc->av_lock); in solo_enc_alloc()
1253 INIT_LIST_HEAD(&solo_enc->vidq_active); in solo_enc_alloc()
1254 solo_enc->fmt = (solo_dev->type == SOLO_DEV_6010) ? in solo_enc_alloc()
1256 solo_enc->type = SOLO_ENC_TYPE_STD; in solo_enc_alloc()
1258 solo_enc->qp = SOLO_DEFAULT_QP; in solo_enc_alloc()
1259 solo_enc->gop = solo_dev->fps; in solo_enc_alloc()
1260 solo_enc->interval = 1; in solo_enc_alloc()
1261 solo_enc->mode = SOLO_ENC_MODE_CIF; in solo_enc_alloc()
1262 solo_enc->motion_global = true; in solo_enc_alloc()
1263 solo_enc->motion_thresh = SOLO_DEF_MOT_THRESH; in solo_enc_alloc()
1264 solo_enc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in solo_enc_alloc()
1265 solo_enc->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; in solo_enc_alloc()
1266 solo_enc->vidq.ops = &solo_enc_video_qops; in solo_enc_alloc()
1267 solo_enc->vidq.mem_ops = &vb2_dma_sg_memops; in solo_enc_alloc()
1268 solo_enc->vidq.drv_priv = solo_enc; in solo_enc_alloc()
1269 solo_enc->vidq.gfp_flags = __GFP_DMA32 | __GFP_KSWAPD_RECLAIM; in solo_enc_alloc()
1270 solo_enc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in solo_enc_alloc()
1271 solo_enc->vidq.buf_struct_size = sizeof(struct solo_vb2_buf); in solo_enc_alloc()
1272 solo_enc->vidq.lock = &solo_enc->lock; in solo_enc_alloc()
1273 solo_enc->vidq.dev = &solo_dev->pdev->dev; in solo_enc_alloc()
1274 ret = vb2_queue_init(&solo_enc->vidq); in solo_enc_alloc()
1277 solo_update_mode(solo_enc); in solo_enc_alloc()
1279 spin_lock_init(&solo_enc->motion_lock); in solo_enc_alloc()
1282 solo_enc->jpeg_len = sizeof(jpeg_header); in solo_enc_alloc()
1283 memcpy(solo_enc->jpeg_header, jpeg_header, solo_enc->jpeg_len); in solo_enc_alloc()
1285 solo_enc->desc_nelts = 32; in solo_enc_alloc()
1286 solo_enc->desc_items = dma_alloc_coherent(&solo_dev->pdev->dev, in solo_enc_alloc()
1288 solo_enc->desc_nelts, in solo_enc_alloc()
1289 &solo_enc->desc_dma, in solo_enc_alloc()
1292 if (solo_enc->desc_items == NULL) in solo_enc_alloc()
1295 solo_enc->vfd = video_device_alloc(); in solo_enc_alloc()
1296 if (!solo_enc->vfd) in solo_enc_alloc()
1299 *solo_enc->vfd = solo_enc_template; in solo_enc_alloc()
1300 solo_enc->vfd->v4l2_dev = &solo_dev->v4l2_dev; in solo_enc_alloc()
1301 solo_enc->vfd->ctrl_handler = hdl; in solo_enc_alloc()
1302 solo_enc->vfd->queue = &solo_enc->vidq; in solo_enc_alloc()
1303 solo_enc->vfd->lock = &solo_enc->lock; in solo_enc_alloc()
1304 video_set_drvdata(solo_enc->vfd, solo_enc); in solo_enc_alloc()
1305 ret = video_register_device(solo_enc->vfd, VFL_TYPE_VIDEO, nr); in solo_enc_alloc()
1309 snprintf(solo_enc->vfd->name, sizeof(solo_enc->vfd->name), in solo_enc_alloc()
1311 solo_enc->vfd->num); in solo_enc_alloc()
1313 return solo_enc; in solo_enc_alloc()
1316 video_device_release(solo_enc->vfd); in solo_enc_alloc()
1318 dma_free_coherent(&solo_enc->solo_dev->pdev->dev, in solo_enc_alloc()
1319 sizeof(struct solo_p2m_desc) * solo_enc->desc_nelts, in solo_enc_alloc()
1320 solo_enc->desc_items, solo_enc->desc_dma); in solo_enc_alloc()
1323 kfree(solo_enc); in solo_enc_alloc()
1327 static void solo_enc_free(struct solo_enc_dev *solo_enc) in solo_enc_free() argument
1329 if (solo_enc == NULL) in solo_enc_free()
1332 dma_free_coherent(&solo_enc->solo_dev->pdev->dev, in solo_enc_free()
1333 sizeof(struct solo_p2m_desc) * solo_enc->desc_nelts, in solo_enc_free()
1334 solo_enc->desc_items, solo_enc->desc_dma); in solo_enc_free()
1335 video_unregister_device(solo_enc->vfd); in solo_enc_free()
1336 v4l2_ctrl_handler_free(&solo_enc->hdl); in solo_enc_free()
1337 kfree(solo_enc); in solo_enc_free()