Lines Matching full:camif
3 * s3c24xx/s3c64xx SoC series Camera Interface (CAMIF) driver
37 #include "camif-core.h"
38 #include "camif-regs.h"
43 /* Locking: called with vp->camif->slock spinlock held */
64 /* Locking: called with camif->slock spinlock held */
65 static int s3c_camif_hw_init(struct camif_dev *camif, struct camif_vp *vp) in s3c_camif_hw_init() argument
67 const struct s3c_camif_variant *variant = camif->variant; in s3c_camif_hw_init()
69 if (camif->sensor.sd == NULL || vp->out_fmt == NULL) in s3c_camif_hw_init()
74 camif_hw_set_camera_bus(camif); in s3c_camif_hw_init()
75 camif_hw_set_source_format(camif); in s3c_camif_hw_init()
76 camif_hw_set_camera_crop(camif); in s3c_camif_hw_init()
77 camif_hw_set_test_pattern(camif, camif->test_pattern); in s3c_camif_hw_init()
79 camif_hw_set_effect(camif, camif->colorfx, in s3c_camif_hw_init()
80 camif->colorfx_cr, camif->colorfx_cb); in s3c_camif_hw_init()
93 * Locking: called with camif->slock spinlock held.
95 static int s3c_camif_hw_vp_init(struct camif_dev *camif, struct camif_vp *vp) in s3c_camif_hw_vp_init() argument
97 unsigned int ip_rev = camif->variant->ip_revision; in s3c_camif_hw_vp_init()
110 static int sensor_set_power(struct camif_dev *camif, int on) in sensor_set_power() argument
112 struct cam_sensor *sensor = &camif->sensor; in sensor_set_power()
115 if (camif->sensor.power_count == !on) in sensor_set_power()
128 static int sensor_set_streaming(struct camif_dev *camif, int on) in sensor_set_streaming() argument
130 struct cam_sensor *sensor = &camif->sensor; in sensor_set_streaming()
133 if (camif->sensor.stream_count == !on) in sensor_set_streaming()
146 * Return any buffers to vb2, perform CAMIF software reset and
151 struct camif_dev *camif = vp->camif; in camif_reinitialize() local
156 spin_lock_irqsave(&camif->slock, flags); in camif_reinitialize()
174 spin_unlock_irqrestore(&camif->slock, flags); in camif_reinitialize()
179 return sensor_set_streaming(camif, 0); in camif_reinitialize()
184 struct camif_dev *camif = vp->camif; in s3c_vp_active() local
188 spin_lock_irqsave(&camif->slock, flags); in s3c_vp_active()
190 spin_unlock_irqrestore(&camif->slock, flags); in s3c_vp_active()
195 static bool camif_is_streaming(struct camif_dev *camif) in camif_is_streaming() argument
200 spin_lock_irqsave(&camif->slock, flags); in camif_is_streaming()
201 status = camif->stream_count > 0; in camif_is_streaming()
202 spin_unlock_irqrestore(&camif->slock, flags); in camif_is_streaming()
209 struct camif_dev *camif = vp->camif; in camif_stop_capture() local
216 spin_lock_irqsave(&camif->slock, flags); in camif_stop_capture()
219 spin_unlock_irqrestore(&camif->slock, flags); in camif_stop_capture()
225 spin_lock_irqsave(&camif->slock, flags); in camif_stop_capture()
236 spin_unlock_irqrestore(&camif->slock, flags); in camif_stop_capture()
291 struct camif_dev *camif = vp->camif; in s3c_camif_irq_handler() local
292 unsigned int ip_rev = camif->variant->ip_revision; in s3c_camif_irq_handler()
295 spin_lock(&camif->slock); in s3c_camif_irq_handler()
360 camif_hw_set_camera_crop(camif); in s3c_camif_irq_handler()
363 camif_hw_set_test_pattern(camif, camif->test_pattern); in s3c_camif_irq_handler()
364 if (camif->variant->has_img_effect) in s3c_camif_irq_handler()
365 camif_hw_set_effect(camif, camif->colorfx, in s3c_camif_irq_handler()
366 camif->colorfx_cr, camif->colorfx_cb); in s3c_camif_irq_handler()
370 spin_unlock(&camif->slock); in s3c_camif_irq_handler()
377 struct camif_dev *camif = vp->camif; in start_streaming() local
385 * a need for CAMIF software reset. in start_streaming()
387 spin_lock_irqsave(&camif->slock, flags); in start_streaming()
389 if (camif->stream_count == 0) { in start_streaming()
390 camif_hw_reset(camif); in start_streaming()
391 ret = s3c_camif_hw_init(camif, vp); in start_streaming()
393 ret = s3c_camif_hw_vp_init(camif, vp); in start_streaming()
395 spin_unlock_irqrestore(&camif->slock, flags); in start_streaming()
402 spin_lock_irqsave(&camif->slock, flags); in start_streaming()
416 spin_unlock_irqrestore(&camif->slock, flags); in start_streaming()
417 ret = sensor_set_streaming(camif, 1); in start_streaming()
421 camif_hw_dump_regs(camif, __func__); in start_streaming()
427 spin_unlock_irqrestore(&camif->slock, flags); in start_streaming()
483 struct camif_dev *camif = vp->camif; in buffer_queue() local
486 spin_lock_irqsave(&camif->slock, flags); in buffer_queue()
508 spin_unlock_irqrestore(&camif->slock, flags); in buffer_queue()
511 if (sensor_set_streaming(camif, 1) == 0) in buffer_queue()
517 camif_hw_dump_regs(camif, __func__); in buffer_queue()
521 spin_unlock_irqrestore(&camif->slock, flags); in buffer_queue()
537 struct camif_dev *camif = vp->camif; in s3c_camif_open() local
543 if (mutex_lock_interruptible(&camif->lock)) in s3c_camif_open()
550 ret = pm_runtime_get_sync(camif->dev); in s3c_camif_open()
554 ret = sensor_set_power(camif, 1); in s3c_camif_open()
558 pm_runtime_put(camif->dev); in s3c_camif_open()
562 mutex_unlock(&camif->lock); in s3c_camif_open()
569 struct camif_dev *camif = vp->camif; in s3c_camif_close() local
575 mutex_lock(&camif->lock); in s3c_camif_close()
583 sensor_set_power(camif, 0); in s3c_camif_close()
585 pm_runtime_put(camif->dev); in s3c_camif_close()
588 mutex_unlock(&camif->lock); in s3c_camif_close()
596 struct camif_dev *camif = vp->camif; in s3c_camif_poll() local
599 mutex_lock(&camif->lock); in s3c_camif_poll()
605 mutex_unlock(&camif->lock); in s3c_camif_poll()
643 dev_name(vp->camif->dev), vp->id); in s3c_camif_vidioc_querycap()
651 struct v4l2_subdev *sensor = vp->camif->sensor.sd; in s3c_camif_vidioc_enum_input()
712 struct camif_dev *camif = vp->camif; in __camif_video_try_format() local
713 struct v4l2_rect *crop = &camif->camif_crop; in __camif_video_try_format()
726 pix_lim = &camif->variant->vp_pix_limits[vp->id]; in __camif_video_try_format()
806 /* Only check pixel formats at the sensor and the camif subdev pads */
807 static int camif_pipeline_validate(struct camif_dev *camif) in camif_pipeline_validate() argument
814 pad = media_entity_remote_pad(&camif->pads[0]); in camif_pipeline_validate()
820 ret = v4l2_subdev_call(camif->sensor.sd, pad, get_fmt, NULL, &src_fmt); in camif_pipeline_validate()
824 if (src_fmt.format.width != camif->mbus_fmt.width || in camif_pipeline_validate()
825 src_fmt.format.height != camif->mbus_fmt.height || in camif_pipeline_validate()
826 src_fmt.format.code != camif->mbus_fmt.code) in camif_pipeline_validate()
836 struct camif_dev *camif = vp->camif; in s3c_camif_streamon() local
837 struct media_entity *sensor = &camif->sensor.sd->entity; in s3c_camif_streamon()
851 ret = media_pipeline_start(sensor, camif->m_pipeline); in s3c_camif_streamon()
855 ret = camif_pipeline_validate(camif); in s3c_camif_streamon()
868 struct camif_dev *camif = vp->camif; in s3c_camif_streamoff() local
881 media_pipeline_stop(&camif->sensor.sd->entity); in s3c_camif_streamoff()
1002 static void __camif_try_compose(struct camif_dev *camif, struct camif_vp *vp, in __camif_try_compose() argument
1006 if (camif->variant->ip_revision == S3C244X_CAMIF_IP_REV) { in __camif_try_compose()
1018 struct camif_dev *camif = vp->camif; in s3c_camif_s_selection() local
1026 __camif_try_compose(camif, vp, &rect); in s3c_camif_s_selection()
1029 spin_lock_irqsave(&camif->slock, flags); in s3c_camif_s_selection()
1032 spin_unlock_irqrestore(&camif->slock, flags); in s3c_camif_s_selection()
1071 struct camif_dev *camif = vp->camif; in s3c_camif_video_s_ctrl() local
1077 spin_lock_irqsave(&camif->slock, flags); in s3c_camif_video_s_ctrl()
1090 spin_unlock_irqrestore(&camif->slock, flags); in s3c_camif_video_s_ctrl()
1099 int s3c_camif_register_video_node(struct camif_dev *camif, int idx) in s3c_camif_register_video_node() argument
1101 struct camif_vp *vp = &camif->vp[idx]; in s3c_camif_register_video_node()
1108 snprintf(vfd->name, sizeof(vfd->name), "camif-%s", in s3c_camif_register_video_node()
1113 vfd->v4l2_dev = &camif->v4l2_dev; in s3c_camif_register_video_node()
1116 vfd->lock = &camif->lock; in s3c_camif_register_video_node()
1130 q->lock = &vp->camif->lock; in s3c_camif_register_video_node()
1131 q->dev = camif->v4l2_dev.dev; in s3c_camif_register_video_node()
1165 v4l2_info(&camif->v4l2_dev, "registered %s as /dev/%s\n", in s3c_camif_register_video_node()
1176 void s3c_camif_unregister_video_node(struct camif_dev *camif, int idx) in s3c_camif_unregister_video_node() argument
1178 struct video_device *vfd = &camif->vp[idx].vdev; in s3c_camif_unregister_video_node()
1187 /* Media bus pixel formats supported at the camif input */
1214 struct camif_dev *camif = v4l2_get_subdevdata(sd); in s3c_camif_subdev_get_fmt() local
1223 mutex_lock(&camif->lock); in s3c_camif_subdev_get_fmt()
1228 *mf = camif->mbus_fmt; in s3c_camif_subdev_get_fmt()
1233 mf->width = camif->camif_crop.width; in s3c_camif_subdev_get_fmt()
1234 mf->height = camif->camif_crop.height; in s3c_camif_subdev_get_fmt()
1235 mf->code = camif->mbus_fmt.code; in s3c_camif_subdev_get_fmt()
1239 mutex_unlock(&camif->lock); in s3c_camif_subdev_get_fmt()
1245 static void __camif_subdev_try_format(struct camif_dev *camif, in __camif_subdev_try_format() argument
1248 const struct s3c_camif_variant *variant = camif->variant; in __camif_subdev_try_format()
1268 struct v4l2_rect *crop = &camif->camif_crop; in __camif_subdev_try_format()
1275 v4l2_dbg(1, debug, &camif->subdev, "%ux%u\n", mf->width, mf->height); in __camif_subdev_try_format()
1282 struct camif_dev *camif = v4l2_get_subdevdata(sd); in s3c_camif_subdev_set_fmt() local
1284 struct v4l2_rect *crop = &camif->camif_crop; in s3c_camif_subdev_set_fmt()
1292 mutex_lock(&camif->lock); in s3c_camif_subdev_set_fmt()
1298 if (vb2_is_busy(&camif->vp[VP_CODEC].vb_queue) || in s3c_camif_subdev_set_fmt()
1299 vb2_is_busy(&camif->vp[VP_PREVIEW].vb_queue)) { in s3c_camif_subdev_set_fmt()
1300 mutex_unlock(&camif->lock); in s3c_camif_subdev_set_fmt()
1304 __camif_subdev_try_format(camif, mf, fmt->pad); in s3c_camif_subdev_set_fmt()
1309 mutex_unlock(&camif->lock); in s3c_camif_subdev_set_fmt()
1315 camif->mbus_fmt = *mf; in s3c_camif_subdev_set_fmt()
1322 * Reset source format (the camif's crop rectangle) in s3c_camif_subdev_set_fmt()
1326 struct camif_frame *frame = &camif->vp[i].out_frame; in s3c_camif_subdev_set_fmt()
1335 mf->code = camif->mbus_fmt.code; in s3c_camif_subdev_set_fmt()
1341 mutex_unlock(&camif->lock); in s3c_camif_subdev_set_fmt()
1349 struct camif_dev *camif = v4l2_get_subdevdata(sd); in s3c_camif_subdev_get_selection() local
1350 struct v4l2_rect *crop = &camif->camif_crop; in s3c_camif_subdev_get_selection()
1351 struct v4l2_mbus_framefmt *mf = &camif->mbus_fmt; in s3c_camif_subdev_get_selection()
1363 mutex_lock(&camif->lock); in s3c_camif_subdev_get_selection()
1374 mutex_unlock(&camif->lock); in s3c_camif_subdev_get_selection()
1383 static void __camif_try_crop(struct camif_dev *camif, struct v4l2_rect *r) in __camif_try_crop() argument
1385 struct v4l2_mbus_framefmt *mf = &camif->mbus_fmt; in __camif_try_crop()
1386 const struct camif_pix_limits *pix_lim = &camif->variant->pix_limits; in __camif_try_crop()
1414 if (camif->variant->ip_revision == S3C244X_CAMIF_IP_REV && in __camif_try_crop()
1415 camif_is_streaming(camif)) { in __camif_try_crop()
1419 struct v4l2_rect *or = &camif->vp[i].out_frame.rect; in __camif_try_crop()
1422 *r = camif->camif_crop; in __camif_try_crop()
1428 v4l2_dbg(1, debug, &camif->v4l2_dev, "crop: (%d,%d)/%dx%d, fmt: %ux%u\n", in __camif_try_crop()
1436 struct camif_dev *camif = v4l2_get_subdevdata(sd); in s3c_camif_subdev_set_selection() local
1437 struct v4l2_rect *crop = &camif->camif_crop; in s3c_camif_subdev_set_selection()
1443 mutex_lock(&camif->lock); in s3c_camif_subdev_set_selection()
1444 __camif_try_crop(camif, &sel->r); in s3c_camif_subdev_set_selection()
1452 spin_lock_irqsave(&camif->slock, flags); in s3c_camif_subdev_set_selection()
1456 struct camif_vp *vp = &camif->vp[i]; in s3c_camif_subdev_set_selection()
1464 spin_unlock_irqrestore(&camif->slock, flags); in s3c_camif_subdev_set_selection()
1466 mutex_unlock(&camif->lock); in s3c_camif_subdev_set_selection()
1470 camif->mbus_fmt.width, camif->mbus_fmt.height); in s3c_camif_subdev_set_selection()
1489 struct camif_dev *camif = container_of(ctrl->handler, struct camif_dev, in s3c_camif_subdev_s_ctrl() local
1493 spin_lock_irqsave(&camif->slock, flags); in s3c_camif_subdev_s_ctrl()
1497 camif->colorfx = camif->ctrl_colorfx->val; in s3c_camif_subdev_s_ctrl()
1501 camif->colorfx_cb = 115; in s3c_camif_subdev_s_ctrl()
1502 camif->colorfx_cr = 145; in s3c_camif_subdev_s_ctrl()
1505 camif->colorfx_cb = camif->ctrl_colorfx_cbcr->val >> 8; in s3c_camif_subdev_s_ctrl()
1506 camif->colorfx_cr = camif->ctrl_colorfx_cbcr->val & 0xff; in s3c_camif_subdev_s_ctrl()
1510 camif->colorfx_cb = 128; in s3c_camif_subdev_s_ctrl()
1511 camif->colorfx_cr = 128; in s3c_camif_subdev_s_ctrl()
1515 camif->test_pattern = camif->ctrl_test_pattern->val; in s3c_camif_subdev_s_ctrl()
1521 camif->vp[VP_CODEC].state |= ST_VP_CONFIG; in s3c_camif_subdev_s_ctrl()
1522 camif->vp[VP_PREVIEW].state |= ST_VP_CONFIG; in s3c_camif_subdev_s_ctrl()
1523 spin_unlock_irqrestore(&camif->slock, flags); in s3c_camif_subdev_s_ctrl()
1539 int s3c_camif_create_subdev(struct camif_dev *camif) in s3c_camif_create_subdev() argument
1541 struct v4l2_ctrl_handler *handler = &camif->ctrl_handler; in s3c_camif_create_subdev()
1542 struct v4l2_subdev *sd = &camif->subdev; in s3c_camif_create_subdev()
1547 strscpy(sd->name, "S3C-CAMIF", sizeof(sd->name)); in s3c_camif_create_subdev()
1549 camif->pads[CAMIF_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK; in s3c_camif_create_subdev()
1550 camif->pads[CAMIF_SD_PAD_SOURCE_C].flags = MEDIA_PAD_FL_SOURCE; in s3c_camif_create_subdev()
1551 camif->pads[CAMIF_SD_PAD_SOURCE_P].flags = MEDIA_PAD_FL_SOURCE; in s3c_camif_create_subdev()
1554 camif->pads); in s3c_camif_create_subdev()
1559 camif->ctrl_test_pattern = v4l2_ctrl_new_std_menu_items(handler, in s3c_camif_create_subdev()
1564 if (camif->variant->has_img_effect) { in s3c_camif_create_subdev()
1565 camif->ctrl_colorfx = v4l2_ctrl_new_std_menu(handler, in s3c_camif_create_subdev()
1570 camif->ctrl_colorfx_cbcr = v4l2_ctrl_new_std(handler, in s3c_camif_create_subdev()
1581 if (camif->variant->has_img_effect) in s3c_camif_create_subdev()
1582 v4l2_ctrl_auto_cluster(2, &camif->ctrl_colorfx, in s3c_camif_create_subdev()
1586 v4l2_set_subdevdata(sd, camif); in s3c_camif_create_subdev()
1591 void s3c_camif_unregister_subdev(struct camif_dev *camif) in s3c_camif_unregister_subdev() argument
1593 struct v4l2_subdev *sd = &camif->subdev; in s3c_camif_unregister_subdev()
1601 v4l2_ctrl_handler_free(&camif->ctrl_handler); in s3c_camif_unregister_subdev()
1605 int s3c_camif_set_defaults(struct camif_dev *camif) in s3c_camif_set_defaults() argument
1607 unsigned int ip_rev = camif->variant->ip_revision; in s3c_camif_set_defaults()
1611 struct camif_vp *vp = &camif->vp[i]; in s3c_camif_set_defaults()
1614 vp->camif = camif; in s3c_camif_set_defaults()
1616 vp->offset = camif->variant->vp_offset; in s3c_camif_set_defaults()
1640 memset(&camif->mbus_fmt, 0, sizeof(camif->mbus_fmt)); in s3c_camif_set_defaults()
1641 camif->mbus_fmt.width = CAMIF_DEF_WIDTH; in s3c_camif_set_defaults()
1642 camif->mbus_fmt.height = CAMIF_DEF_HEIGHT; in s3c_camif_set_defaults()
1643 camif->mbus_fmt.code = camif_mbus_formats[0]; in s3c_camif_set_defaults()
1645 memset(&camif->camif_crop, 0, sizeof(camif->camif_crop)); in s3c_camif_set_defaults()
1646 camif->camif_crop.width = CAMIF_DEF_WIDTH; in s3c_camif_set_defaults()
1647 camif->camif_crop.height = CAMIF_DEF_HEIGHT; in s3c_camif_set_defaults()