Lines Matching full:cam
127 #define sensor_call(cam, optype, func, args...) \ argument
128 v4l2_subdev_call(cam->sensor, optype, func, ##args)
133 #define cam_err(cam, fmt, arg...) \ argument
134 dev_err(&(cam)->platdev->dev, fmt, ##arg)
135 #define cam_warn(cam, fmt, arg...) \ argument
136 dev_warn(&(cam)->platdev->dev, fmt, ##arg)
137 #define cam_dbg(cam, fmt, arg...) \ argument
138 dev_dbg(&(cam)->platdev->dev, fmt, ##arg)
180 static int via_sensor_power_setup(struct via_camera *cam) in via_sensor_power_setup() argument
182 struct device *dev = &cam->platdev->dev; in via_sensor_power_setup()
184 cam->power_gpio = devm_gpiod_get(dev, "VGPIO3", GPIOD_OUT_LOW); in via_sensor_power_setup()
185 if (IS_ERR(cam->power_gpio)) in via_sensor_power_setup()
186 return dev_err_probe(dev, PTR_ERR(cam->power_gpio), in via_sensor_power_setup()
190 cam->reset_gpio = devm_gpiod_get(dev, "VGPIO2", GPIOD_OUT_HIGH); in via_sensor_power_setup()
191 if (IS_ERR(cam->reset_gpio)) in via_sensor_power_setup()
192 return dev_err_probe(dev, PTR_ERR(cam->reset_gpio), in via_sensor_power_setup()
201 static void via_sensor_power_up(struct via_camera *cam) in via_sensor_power_up() argument
203 gpiod_set_value(cam->power_gpio, 1); in via_sensor_power_up()
204 gpiod_set_value(cam->reset_gpio, 1); in via_sensor_power_up()
206 gpiod_set_value(cam->reset_gpio, 0); in via_sensor_power_up()
210 static void via_sensor_power_down(struct via_camera *cam) in via_sensor_power_down() argument
212 gpiod_set_value(cam->power_gpio, 0); in via_sensor_power_down()
213 gpiod_set_value(cam->reset_gpio, 1); in via_sensor_power_down()
217 static void via_sensor_power_release(struct via_camera *cam) in via_sensor_power_release() argument
219 via_sensor_power_down(cam); in via_sensor_power_release()
228 static int viacam_set_flip(struct via_camera *cam) in viacam_set_flip() argument
235 return v4l2_s_ctrl(NULL, cam->sensor->ctrl_handler, &ctrl); in viacam_set_flip()
242 static int viacam_configure_sensor(struct via_camera *cam) in viacam_configure_sensor() argument
249 v4l2_fill_mbus_format(&format.format, &cam->sensor_format, cam->mbus_code); in viacam_configure_sensor()
250 ret = sensor_call(cam, core, init, 0); in viacam_configure_sensor()
252 ret = sensor_call(cam, pad, set_fmt, NULL, &format); in viacam_configure_sensor()
257 ret = viacam_set_flip(cam); in viacam_configure_sensor()
271 static inline void viacam_write_reg(struct via_camera *cam, in viacam_write_reg() argument
274 iowrite32(value, cam->mmio + reg); in viacam_write_reg()
277 static inline int viacam_read_reg(struct via_camera *cam, int reg) in viacam_read_reg() argument
279 return ioread32(cam->mmio + reg); in viacam_read_reg()
282 static inline void viacam_write_reg_mask(struct via_camera *cam, in viacam_write_reg_mask() argument
285 int tmp = viacam_read_reg(cam, reg); in viacam_write_reg_mask()
288 viacam_write_reg(cam, reg, tmp); in viacam_write_reg_mask()
297 struct via_camera *cam = data; in viacam_quick_irq() local
305 spin_lock(&cam->viadev->reg_lock); in viacam_quick_irq()
306 icv = viacam_read_reg(cam, VCR_INTCTRL); in viacam_quick_irq()
309 viacam_write_reg(cam, VCR_INTCTRL, icv); in viacam_quick_irq()
312 spin_unlock(&cam->viadev->reg_lock); in viacam_quick_irq()
319 static struct via_buffer *viacam_next_buffer(struct via_camera *cam) in viacam_next_buffer() argument
321 if (cam->opstate != S_RUNNING) in viacam_next_buffer()
323 if (list_empty(&cam->buffer_queue)) in viacam_next_buffer()
325 return list_entry(cam->buffer_queue.next, struct via_buffer, queue); in viacam_next_buffer()
333 struct via_camera *cam = data; in viacam_irq() local
338 mutex_lock(&cam->lock); in viacam_irq()
343 vb = viacam_next_buffer(cam); in viacam_irq()
349 bufn = (viacam_read_reg(cam, VCR_INTCTRL) & VCR_IC_ACTBUF) >> 3; in viacam_irq()
352 bufn = cam->n_cap_bufs - 1; in viacam_irq()
358 viafb_dma_copy_out_sg(cam->cb_offsets[bufn], sgt->sgl, sgt->nents); in viacam_irq()
359 vb->vbuf.sequence = cam->sequence++; in viacam_irq()
364 mutex_unlock(&cam->lock); in viacam_irq()
376 static void viacam_int_enable(struct via_camera *cam) in viacam_int_enable() argument
378 viacam_write_reg(cam, VCR_INTCTRL, in viacam_int_enable()
383 static void viacam_int_disable(struct via_camera *cam) in viacam_int_disable() argument
386 viacam_write_reg(cam, VCR_INTCTRL, 0); in viacam_int_disable()
397 static int viacam_ctlr_cbufs(struct via_camera *cam) in viacam_ctlr_cbufs() argument
399 int nbuf = cam->viadev->camera_fbmem_size/cam->sensor_format.sizeimage; in viacam_ctlr_cbufs()
407 cam->n_cap_bufs = 3; in viacam_ctlr_cbufs()
408 viacam_write_reg_mask(cam, VCR_CAPINTC, VCR_CI_3BUFS, in viacam_ctlr_cbufs()
411 cam->n_cap_bufs = 2; in viacam_ctlr_cbufs()
412 viacam_write_reg_mask(cam, VCR_CAPINTC, 0, VCR_CI_3BUFS); in viacam_ctlr_cbufs()
414 cam_warn(cam, "Insufficient frame buffer memory\n"); in viacam_ctlr_cbufs()
420 offset = cam->fb_offset; in viacam_ctlr_cbufs()
421 for (i = 0; i < cam->n_cap_bufs; i++) { in viacam_ctlr_cbufs()
422 cam->cb_offsets[i] = offset; in viacam_ctlr_cbufs()
423 cam->cb_addrs[i] = cam->fbmem + offset; in viacam_ctlr_cbufs()
424 viacam_write_reg(cam, VCR_VBUF1 + i*4, offset & VCR_VBUF_MASK); in viacam_ctlr_cbufs()
425 offset += cam->sensor_format.sizeimage; in viacam_ctlr_cbufs()
447 static void viacam_set_scale(struct via_camera *cam) in viacam_set_scale() argument
452 if (cam->user_format.width == VGA_WIDTH) in viacam_set_scale()
455 sf = (cam->user_format.width*2048)/VGA_WIDTH; in viacam_set_scale()
458 if (cam->user_format.height < VGA_HEIGHT) { in viacam_set_scale()
459 sf = (1024*cam->user_format.height)/VGA_HEIGHT; in viacam_set_scale()
462 viacam_write_reg(cam, VCR_AVSCALE, avscale); in viacam_set_scale()
469 static void viacam_ctlr_image(struct via_camera *cam) in viacam_ctlr_image() argument
477 viacam_write_reg(cam, VCR_CAPINTC, ~(VCR_CI_ENABLE|VCR_CI_CLKEN)); in viacam_ctlr_image()
482 viacam_write_reg(cam, VCR_HORRANGE, 0x06200120); in viacam_ctlr_image()
483 viacam_write_reg(cam, VCR_VERTRANGE, 0x01de0000); in viacam_ctlr_image()
484 viacam_set_scale(cam); in viacam_ctlr_image()
488 viacam_write_reg(cam, VCR_MAXDATA, in viacam_ctlr_image()
489 (cam->sensor_format.height << 16) | in viacam_ctlr_image()
490 (cam->sensor_format.bytesperline >> 3)); in viacam_ctlr_image()
491 viacam_write_reg(cam, VCR_MAXVBI, 0); in viacam_ctlr_image()
492 viacam_write_reg(cam, VCR_VSTRIDE, in viacam_ctlr_image()
493 cam->user_format.bytesperline & VCR_VS_STRIDE); in viacam_ctlr_image()
507 if (cam->n_cap_bufs == 3) in viacam_ctlr_image()
512 if (cam->user_format.pixelformat == V4L2_PIX_FMT_YUYV) in viacam_ctlr_image()
516 viacam_write_reg(cam, VCR_CAPINTC, cicreg); in viacam_ctlr_image()
520 static int viacam_config_controller(struct via_camera *cam) in viacam_config_controller() argument
525 spin_lock_irqsave(&cam->viadev->reg_lock, flags); in viacam_config_controller()
526 ret = viacam_ctlr_cbufs(cam); in viacam_config_controller()
528 viacam_ctlr_image(cam); in viacam_config_controller()
529 spin_unlock_irqrestore(&cam->viadev->reg_lock, flags); in viacam_config_controller()
530 clear_bit(CF_CONFIG_NEEDED, &cam->flags); in viacam_config_controller()
537 static void viacam_start_engine(struct via_camera *cam) in viacam_start_engine() argument
539 spin_lock_irq(&cam->viadev->reg_lock); in viacam_start_engine()
540 viacam_write_reg_mask(cam, VCR_CAPINTC, VCR_CI_ENABLE, VCR_CI_ENABLE); in viacam_start_engine()
541 viacam_int_enable(cam); in viacam_start_engine()
542 (void) viacam_read_reg(cam, VCR_CAPINTC); /* Force post */ in viacam_start_engine()
543 cam->opstate = S_RUNNING; in viacam_start_engine()
544 spin_unlock_irq(&cam->viadev->reg_lock); in viacam_start_engine()
548 static void viacam_stop_engine(struct via_camera *cam) in viacam_stop_engine() argument
550 spin_lock_irq(&cam->viadev->reg_lock); in viacam_stop_engine()
551 viacam_int_disable(cam); in viacam_stop_engine()
552 viacam_write_reg_mask(cam, VCR_CAPINTC, 0, VCR_CI_ENABLE); in viacam_stop_engine()
553 (void) viacam_read_reg(cam, VCR_CAPINTC); /* Force post */ in viacam_stop_engine()
554 cam->opstate = S_IDLE; in viacam_stop_engine()
555 spin_unlock_irq(&cam->viadev->reg_lock); in viacam_stop_engine()
571 struct via_camera *cam = vb2_get_drv_priv(vb->vb2_queue); in viacam_vb2_queue() local
574 list_add_tail(&via->queue, &cam->buffer_queue); in viacam_vb2_queue()
579 struct via_camera *cam = vb2_get_drv_priv(vb->vb2_queue); in viacam_vb2_prepare() local
581 if (vb2_plane_size(vb, 0) < cam->user_format.sizeimage) { in viacam_vb2_prepare()
582 cam_dbg(cam, in viacam_vb2_prepare()
585 cam->user_format.sizeimage); in viacam_vb2_prepare()
589 vb2_set_plane_payload(vb, 0, cam->user_format.sizeimage); in viacam_vb2_prepare()
599 struct via_camera *cam = vb2_get_drv_priv(vq); in viacam_vb2_queue_setup() local
600 int size = cam->user_format.sizeimage; in viacam_vb2_queue_setup()
612 struct via_camera *cam = vb2_get_drv_priv(vq); in viacam_vb2_start_streaming() local
616 if (cam->opstate != S_IDLE) { in viacam_vb2_start_streaming()
623 if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { in viacam_vb2_start_streaming()
624 ret = viacam_configure_sensor(cam); in viacam_vb2_start_streaming()
627 ret = viacam_config_controller(cam); in viacam_vb2_start_streaming()
631 cam->sequence = 0; in viacam_vb2_start_streaming()
638 cpu_latency_qos_add_request(&cam->qos_request, 50); in viacam_vb2_start_streaming()
639 viacam_start_engine(cam); in viacam_vb2_start_streaming()
642 list_for_each_entry_safe(buf, tmp, &cam->buffer_queue, queue) { in viacam_vb2_start_streaming()
651 struct via_camera *cam = vb2_get_drv_priv(vq); in viacam_vb2_stop_streaming() local
654 cpu_latency_qos_remove_request(&cam->qos_request); in viacam_vb2_stop_streaming()
655 viacam_stop_engine(cam); in viacam_vb2_stop_streaming()
657 list_for_each_entry_safe(buf, tmp, &cam->buffer_queue, queue) { in viacam_vb2_stop_streaming()
678 struct via_camera *cam = video_drvdata(filp); in viacam_open() local
685 mutex_lock(&cam->lock); in viacam_open()
696 via_sensor_power_up(cam); in viacam_open()
697 set_bit(CF_CONFIG_NEEDED, &cam->flags); in viacam_open()
700 mutex_unlock(&cam->lock); in viacam_open()
706 struct via_camera *cam = video_drvdata(filp); in viacam_release() local
709 mutex_lock(&cam->lock); in viacam_release()
716 via_sensor_power_down(cam); in viacam_release()
719 mutex_unlock(&cam->lock); in viacam_release()
831 static int viacam_do_try_fmt(struct via_camera *cam, in viacam_do_try_fmt() argument
847 ret = sensor_call(cam, pad, set_fmt, &pad_state, &format); in viacam_do_try_fmt()
858 struct via_camera *cam = video_drvdata(filp); in viacam_try_fmt_vid_cap() local
861 return viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); in viacam_try_fmt_vid_cap()
868 struct via_camera *cam = video_drvdata(filp); in viacam_g_fmt_vid_cap() local
870 fmt->fmt.pix = cam->user_format; in viacam_g_fmt_vid_cap()
877 struct via_camera *cam = video_drvdata(filp); in viacam_s_fmt_vid_cap() local
886 if (cam->opstate != S_IDLE) in viacam_s_fmt_vid_cap()
892 ret = viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); in viacam_s_fmt_vid_cap()
898 cam->user_format = fmt->fmt.pix; in viacam_s_fmt_vid_cap()
899 cam->sensor_format = sfmt.fmt.pix; in viacam_s_fmt_vid_cap()
900 cam->mbus_code = f->mbus_code; in viacam_s_fmt_vid_cap()
901 ret = viacam_configure_sensor(cam); in viacam_s_fmt_vid_cap()
903 ret = viacam_config_controller(cam); in viacam_s_fmt_vid_cap()
921 struct via_camera *cam = video_drvdata(filp); in viacam_g_parm() local
923 return v4l2_g_parm_cap(video_devdata(filp), cam->sensor, parm); in viacam_g_parm()
929 struct via_camera *cam = video_drvdata(filp); in viacam_s_parm() local
931 return v4l2_s_parm_cap(video_devdata(filp), cam->sensor, parm); in viacam_s_parm()
958 struct via_camera *cam = video_drvdata(filp); in viacam_enum_frameintervals() local
961 .code = cam->mbus_code, in viacam_enum_frameintervals()
962 .width = cam->sensor_format.width, in viacam_enum_frameintervals()
963 .height = cam->sensor_format.height, in viacam_enum_frameintervals()
977 ret = sensor_call(cam, pad, enum_frame_interval, NULL, &fie); in viacam_enum_frameintervals()
1020 struct via_camera *cam = priv; in viacam_suspend() local
1021 enum viacam_opstate state = cam->opstate; in viacam_suspend()
1023 if (cam->opstate != S_IDLE) { in viacam_suspend()
1024 viacam_stop_engine(cam); in viacam_suspend()
1025 cam->opstate = state; /* So resume restarts */ in viacam_suspend()
1033 struct via_camera *cam = priv; in viacam_resume() local
1041 viacam_int_disable(cam); in viacam_resume()
1042 set_bit(CF_CONFIG_NEEDED, &cam->flags); in viacam_resume()
1046 if (!list_empty(&cam->vdev.fh_list)) in viacam_resume()
1047 via_sensor_power_up(cam); in viacam_resume()
1049 via_sensor_power_down(cam); in viacam_resume()
1053 if (cam->opstate != S_IDLE) { in viacam_resume()
1054 mutex_lock(&cam->lock); in viacam_resume()
1055 ret = viacam_configure_sensor(cam); in viacam_resume()
1057 ret = viacam_config_controller(cam); in viacam_resume()
1058 mutex_unlock(&cam->lock); in viacam_resume()
1060 viacam_start_engine(cam); in viacam_resume()
1144 struct via_camera *cam; in viacam_probe() local
1169 cam = kzalloc (sizeof(struct via_camera), GFP_KERNEL); in viacam_probe()
1170 if (cam == NULL) in viacam_probe()
1172 via_cam_info = cam; in viacam_probe()
1173 cam->platdev = pdev; in viacam_probe()
1174 cam->viadev = viadev; in viacam_probe()
1175 cam->opstate = S_IDLE; in viacam_probe()
1176 cam->user_format = cam->sensor_format = viacam_def_pix_format; in viacam_probe()
1177 mutex_init(&cam->lock); in viacam_probe()
1178 INIT_LIST_HEAD(&cam->buffer_queue); in viacam_probe()
1179 cam->mmio = viadev->engine_mmio; in viacam_probe()
1180 cam->fbmem = viadev->fbmem; in viacam_probe()
1181 cam->fb_offset = viadev->camera_fbmem_offset; in viacam_probe()
1182 cam->flags = 1 << CF_CONFIG_NEEDED; in viacam_probe()
1183 cam->mbus_code = via_def_mbus_code; in viacam_probe()
1187 ret = v4l2_device_register(&pdev->dev, &cam->v4l2_dev); in viacam_probe()
1192 ret = v4l2_ctrl_handler_init(&cam->ctrl_handler, 10); in viacam_probe()
1195 cam->v4l2_dev.ctrl_handler = &cam->ctrl_handler; in viacam_probe()
1212 ret = via_sensor_power_setup(cam); in viacam_probe()
1215 via_sensor_power_up(cam); in viacam_probe()
1222 cam->sensor = v4l2_i2c_new_subdev_board(&cam->v4l2_dev, sensor_adapter, in viacam_probe()
1224 if (cam->sensor == NULL) { in viacam_probe()
1232 viacam_int_disable(cam); in viacam_probe()
1234 viacam_irq, IRQF_SHARED, "via-camera", cam); in viacam_probe()
1238 vq = &cam->vq; in viacam_probe()
1241 vq->drv_priv = cam; in viacam_probe()
1244 vq->dev = cam->v4l2_dev.dev; in viacam_probe()
1248 vq->lock = &cam->lock; in viacam_probe()
1254 cam->vdev = viacam_v4l_template; in viacam_probe()
1255 cam->vdev.v4l2_dev = &cam->v4l2_dev; in viacam_probe()
1256 cam->vdev.lock = &cam->lock; in viacam_probe()
1257 cam->vdev.queue = vq; in viacam_probe()
1258 video_set_drvdata(&cam->vdev, cam); in viacam_probe()
1259 ret = video_register_device(&cam->vdev, VFL_TYPE_VIDEO, -1); in viacam_probe()
1267 viacam_pm_hooks.private = cam; in viacam_probe()
1272 via_sensor_power_down(cam); in viacam_probe()
1276 free_irq(viadev->pdev->irq, cam); in viacam_probe()
1278 via_sensor_power_release(cam); in viacam_probe()
1280 v4l2_ctrl_handler_free(&cam->ctrl_handler); in viacam_probe()
1282 v4l2_device_unregister(&cam->v4l2_dev); in viacam_probe()
1284 kfree(cam); in viacam_probe()
1290 struct via_camera *cam = via_cam_info; in viacam_remove() local
1293 video_unregister_device(&cam->vdev); in viacam_remove()
1294 v4l2_device_unregister(&cam->v4l2_dev); in viacam_remove()
1298 free_irq(viadev->pdev->irq, cam); in viacam_remove()
1299 via_sensor_power_release(cam); in viacam_remove()
1300 v4l2_ctrl_handler_free(&cam->ctrl_handler); in viacam_remove()
1301 kfree(cam); in viacam_remove()