Lines Matching +full:pd +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2006-2010 by Marin Mitov *
14 #include <media/v4l2-dev.h>
15 #include <media/v4l2-ioctl.h>
16 #include <media/v4l2-common.h>
17 #include <media/videobuf2-dma-contig.h>
24 * read_i2c_reg - reads an internal i2c register
43 return -EIO; /* error: NEW_CYCLE not cleared */ in read_i2c_reg()
48 return -EIO; /* error: DIRECT_ABORT set */ in read_i2c_reg()
55 * write_i2c_reg - writes to an internal i2c register
73 return -EIO; /* error: NEW_CYCLE not cleared */ in write_i2c_reg()
77 return -EIO; /* error: DIRECT_ABORT set */ in write_i2c_reg()
83 * write_i2c_reg_nowait - writes to an internal i2c register
100 * wait_i2c_reg - waits the read/write to finish
113 return -EIO; /* error: NEW_CYCLE not cleared */ in wait_i2c_reg()
117 return -EIO; /* error: DIRECT_ABORT set */ in wait_i2c_reg()
128 struct dt3155_priv *pd = vb2_get_drv_priv(vq); in dt3155_queue_setup() local
129 unsigned size = pd->width * pd->height; in dt3155_queue_setup()
132 return sizes[0] < size ? -EINVAL : 0; in dt3155_queue_setup()
140 struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue); in dt3155_buf_prepare() local
142 vb2_set_plane_payload(vb, 0, pd->width * pd->height); in dt3155_buf_prepare()
148 struct dt3155_priv *pd = vb2_get_drv_priv(q); in dt3155_start_streaming() local
149 struct vb2_buffer *vb = &pd->curr_buf->vb2_buf; in dt3155_start_streaming()
152 pd->sequence = 0; in dt3155_start_streaming()
154 iowrite32(dma_addr, pd->regs + EVEN_DMA_START); in dt3155_start_streaming()
155 iowrite32(dma_addr + pd->width, pd->regs + ODD_DMA_START); in dt3155_start_streaming()
156 iowrite32(pd->width, pd->regs + EVEN_DMA_STRIDE); in dt3155_start_streaming()
157 iowrite32(pd->width, pd->regs + ODD_DMA_STRIDE); in dt3155_start_streaming()
160 FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR); in dt3155_start_streaming()
163 pd->regs + CSR1); in dt3155_start_streaming()
164 wait_i2c_reg(pd->regs); in dt3155_start_streaming()
165 write_i2c_reg(pd->regs, CONFIG, pd->config); in dt3155_start_streaming()
166 write_i2c_reg(pd->regs, EVEN_CSR, CSR_ERROR | CSR_DONE); in dt3155_start_streaming()
167 write_i2c_reg(pd->regs, ODD_CSR, CSR_ERROR | CSR_DONE); in dt3155_start_streaming()
170 write_i2c_reg(pd->regs, CSR2, pd->csr2 | BUSY_EVEN | BUSY_ODD); in dt3155_start_streaming()
176 struct dt3155_priv *pd = vb2_get_drv_priv(q); in dt3155_stop_streaming() local
179 spin_lock_irq(&pd->lock); in dt3155_stop_streaming()
181 write_i2c_reg_nowait(pd->regs, CSR2, pd->csr2); in dt3155_stop_streaming()
183 FLD_DN_ODD | FLD_DN_EVEN, pd->regs + CSR1); in dt3155_stop_streaming()
184 /* disable interrupts, clear all irq flags */ in dt3155_stop_streaming()
185 iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR); in dt3155_stop_streaming()
186 spin_unlock_irq(&pd->lock); in dt3155_stop_streaming()
195 spin_lock_irq(&pd->lock); in dt3155_stop_streaming()
196 if (pd->curr_buf) { in dt3155_stop_streaming()
197 vb2_buffer_done(&pd->curr_buf->vb2_buf, VB2_BUF_STATE_ERROR); in dt3155_stop_streaming()
198 pd->curr_buf = NULL; in dt3155_stop_streaming()
201 while (!list_empty(&pd->dmaq)) { in dt3155_stop_streaming()
202 vb = list_first_entry(&pd->dmaq, typeof(*vb), done_entry); in dt3155_stop_streaming()
203 list_del(&vb->done_entry); in dt3155_stop_streaming()
206 spin_unlock_irq(&pd->lock); in dt3155_stop_streaming()
212 struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue); in dt3155_buf_queue() local
214 /* pd->vidq.streaming = 1 when dt3155_buf_queue() is invoked */ in dt3155_buf_queue()
215 spin_lock_irq(&pd->lock); in dt3155_buf_queue()
216 if (pd->curr_buf) in dt3155_buf_queue()
217 list_add_tail(&vb->done_entry, &pd->dmaq); in dt3155_buf_queue()
219 pd->curr_buf = vbuf; in dt3155_buf_queue()
220 spin_unlock_irq(&pd->lock); in dt3155_buf_queue()
240 tmp = ioread32(ipd->regs + INT_CSR) & (FLD_START | FLD_END_ODD); in dt3155_irq_handler_even()
245 ipd->regs + INT_CSR); in dt3155_irq_handler_even()
248 tmp = ioread32(ipd->regs + CSR1) & (FLD_CRPT_EVEN | FLD_CRPT_ODD); in dt3155_irq_handler_even()
253 ipd->regs + CSR1); in dt3155_irq_handler_even()
256 spin_lock(&ipd->lock); in dt3155_irq_handler_even()
257 if (ipd->curr_buf && !list_empty(&ipd->dmaq)) { in dt3155_irq_handler_even()
258 ipd->curr_buf->vb2_buf.timestamp = ktime_get_ns(); in dt3155_irq_handler_even()
259 ipd->curr_buf->sequence = ipd->sequence++; in dt3155_irq_handler_even()
260 ipd->curr_buf->field = V4L2_FIELD_NONE; in dt3155_irq_handler_even()
261 vb2_buffer_done(&ipd->curr_buf->vb2_buf, VB2_BUF_STATE_DONE); in dt3155_irq_handler_even()
263 ivb = list_first_entry(&ipd->dmaq, typeof(*ivb), done_entry); in dt3155_irq_handler_even()
264 list_del(&ivb->done_entry); in dt3155_irq_handler_even()
265 ipd->curr_buf = to_vb2_v4l2_buffer(ivb); in dt3155_irq_handler_even()
267 iowrite32(dma_addr, ipd->regs + EVEN_DMA_START); in dt3155_irq_handler_even()
268 iowrite32(dma_addr + ipd->width, ipd->regs + ODD_DMA_START); in dt3155_irq_handler_even()
269 iowrite32(ipd->width, ipd->regs + EVEN_DMA_STRIDE); in dt3155_irq_handler_even()
270 iowrite32(ipd->width, ipd->regs + ODD_DMA_STRIDE); in dt3155_irq_handler_even()
275 FLD_END_EVEN | FLD_END_ODD, ipd->regs + INT_CSR); in dt3155_irq_handler_even()
276 spin_unlock(&ipd->lock); in dt3155_irq_handler_even()
293 strscpy(cap->driver, DT3155_NAME, sizeof(cap->driver)); in dt3155_querycap()
294 strscpy(cap->card, DT3155_NAME " frame grabber", sizeof(cap->card)); in dt3155_querycap()
301 if (f->index) in dt3155_enum_fmt_vid_cap()
302 return -EINVAL; in dt3155_enum_fmt_vid_cap()
303 f->pixelformat = V4L2_PIX_FMT_GREY; in dt3155_enum_fmt_vid_cap()
309 struct dt3155_priv *pd = video_drvdata(filp); in dt3155_fmt_vid_cap() local
311 f->fmt.pix.width = pd->width; in dt3155_fmt_vid_cap()
312 f->fmt.pix.height = pd->height; in dt3155_fmt_vid_cap()
313 f->fmt.pix.pixelformat = V4L2_PIX_FMT_GREY; in dt3155_fmt_vid_cap()
314 f->fmt.pix.field = V4L2_FIELD_NONE; in dt3155_fmt_vid_cap()
315 f->fmt.pix.bytesperline = f->fmt.pix.width; in dt3155_fmt_vid_cap()
316 f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height; in dt3155_fmt_vid_cap()
317 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in dt3155_fmt_vid_cap()
323 struct dt3155_priv *pd = video_drvdata(filp); in dt3155_g_std() local
325 *norm = pd->std; in dt3155_g_std()
331 struct dt3155_priv *pd = video_drvdata(filp); in dt3155_s_std() local
333 if (pd->std == norm) in dt3155_s_std()
335 if (vb2_is_busy(&pd->vidq)) in dt3155_s_std()
336 return -EBUSY; in dt3155_s_std()
337 pd->std = norm; in dt3155_s_std()
338 if (pd->std & V4L2_STD_525_60) { in dt3155_s_std()
339 pd->csr2 = VT_60HZ; in dt3155_s_std()
340 pd->width = 640; in dt3155_s_std()
341 pd->height = 480; in dt3155_s_std()
343 pd->csr2 = VT_50HZ; in dt3155_s_std()
344 pd->width = 768; in dt3155_s_std()
345 pd->height = 576; in dt3155_s_std()
353 if (input->index > 3) in dt3155_enum_input()
354 return -EINVAL; in dt3155_enum_input()
355 if (input->index) in dt3155_enum_input()
356 snprintf(input->name, sizeof(input->name), "VID%d", in dt3155_enum_input()
357 input->index); in dt3155_enum_input()
359 strscpy(input->name, "J2/VID0", sizeof(input->name)); in dt3155_enum_input()
360 input->type = V4L2_INPUT_TYPE_CAMERA; in dt3155_enum_input()
361 input->std = V4L2_STD_ALL; in dt3155_enum_input()
362 input->status = 0; in dt3155_enum_input()
368 struct dt3155_priv *pd = video_drvdata(filp); in dt3155_g_input() local
370 *i = pd->input; in dt3155_g_input()
376 struct dt3155_priv *pd = video_drvdata(filp); in dt3155_s_input() local
379 return -EINVAL; in dt3155_s_input()
380 pd->input = i; in dt3155_s_input()
381 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG); in dt3155_s_input()
382 write_i2c_reg(pd->regs, AD_CMD, (i << 6) | (i << 4) | SYNC_LVL_3); in dt3155_s_input()
407 static int dt3155_init_board(struct dt3155_priv *pd) in dt3155_init_board() argument
409 struct pci_dev *pdev = pd->pdev; in dt3155_init_board()
417 FLD_DN_ODD | FLD_DN_EVEN, pd->regs + CSR1); in dt3155_init_board()
421 iowrite32(FIFO_EN | SRST, pd->regs + CSR1); in dt3155_init_board()
422 iowrite32(0xEEEEEE01, pd->regs + EVEN_PIXEL_FMT); in dt3155_init_board()
423 iowrite32(0xEEEEEE01, pd->regs + ODD_PIXEL_FMT); in dt3155_init_board()
424 iowrite32(0x00000020, pd->regs + FIFO_TRIGGER); in dt3155_init_board()
425 iowrite32(0x00000103, pd->regs + XFER_MODE); in dt3155_init_board()
426 iowrite32(0, pd->regs + RETRY_WAIT_CNT); in dt3155_init_board()
427 iowrite32(0, pd->regs + INT_CSR); in dt3155_init_board()
428 iowrite32(1, pd->regs + EVEN_FLD_MASK); in dt3155_init_board()
429 iowrite32(1, pd->regs + ODD_FLD_MASK); in dt3155_init_board()
430 iowrite32(0, pd->regs + MASK_LENGTH); in dt3155_init_board()
431 iowrite32(0x0005007C, pd->regs + FIFO_FLAG_CNT); in dt3155_init_board()
432 iowrite32(0x01010101, pd->regs + IIC_CLK_DUR); in dt3155_init_board()
435 read_i2c_reg(pd->regs, DT_ID, &tmp); in dt3155_init_board()
437 return -ENODEV; in dt3155_init_board()
440 write_i2c_reg(pd->regs, AD_ADDR, 0); in dt3155_init_board()
442 write_i2c_reg(pd->regs, AD_LUT, i); in dt3155_init_board()
446 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG); in dt3155_init_board()
447 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3); in dt3155_init_board()
448 write_i2c_reg(pd->regs, AD_ADDR, AD_POS_REF); in dt3155_init_board()
449 write_i2c_reg(pd->regs, AD_CMD, 34); in dt3155_init_board()
450 write_i2c_reg(pd->regs, AD_ADDR, AD_NEG_REF); in dt3155_init_board()
451 write_i2c_reg(pd->regs, AD_CMD, 0); in dt3155_init_board()
454 write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM); in dt3155_init_board()
456 write_i2c_reg(pd->regs, PM_LUT_ADDR, i); in dt3155_init_board()
457 write_i2c_reg(pd->regs, PM_LUT_DATA, i); in dt3155_init_board()
459 write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM | PM_LUT_SEL); in dt3155_init_board()
461 write_i2c_reg(pd->regs, PM_LUT_ADDR, i); in dt3155_init_board()
462 write_i2c_reg(pd->regs, PM_LUT_DATA, i); in dt3155_init_board()
464 write_i2c_reg(pd->regs, CONFIG, pd->config); /* ACQ_MODE_EVEN */ in dt3155_init_board()
467 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG); in dt3155_init_board()
468 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3); in dt3155_init_board()
470 /* disable all irqs, clear all irq flags */ in dt3155_init_board()
472 pd->regs + INT_CSR); in dt3155_init_board()
481 .minor = -1,
491 struct dt3155_priv *pd; in dt3155_probe() local
493 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); in dt3155_probe()
495 return -ENODEV; in dt3155_probe()
496 pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL); in dt3155_probe()
497 if (!pd) in dt3155_probe()
498 return -ENOMEM; in dt3155_probe()
500 err = v4l2_device_register(&pdev->dev, &pd->v4l2_dev); in dt3155_probe()
503 pd->vdev = dt3155_vdev; in dt3155_probe()
504 pd->vdev.v4l2_dev = &pd->v4l2_dev; in dt3155_probe()
505 video_set_drvdata(&pd->vdev, pd); /* for use in video_fops */ in dt3155_probe()
506 pd->pdev = pdev; in dt3155_probe()
507 pd->std = V4L2_STD_625_50; in dt3155_probe()
508 pd->csr2 = VT_50HZ; in dt3155_probe()
509 pd->width = 768; in dt3155_probe()
510 pd->height = 576; in dt3155_probe()
511 INIT_LIST_HEAD(&pd->dmaq); in dt3155_probe()
512 mutex_init(&pd->mux); in dt3155_probe()
513 pd->vdev.lock = &pd->mux; /* for locking v4l2_file_operations */ in dt3155_probe()
514 pd->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in dt3155_probe()
515 pd->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in dt3155_probe()
516 pd->vidq.io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ; in dt3155_probe()
517 pd->vidq.ops = &q_ops; in dt3155_probe()
518 pd->vidq.mem_ops = &vb2_dma_contig_memops; in dt3155_probe()
519 pd->vidq.drv_priv = pd; in dt3155_probe()
520 pd->vidq.min_queued_buffers = 2; in dt3155_probe()
521 pd->vidq.gfp_flags = GFP_DMA32; in dt3155_probe()
522 pd->vidq.lock = &pd->mux; /* for locking v4l2_file_operations */ in dt3155_probe()
523 pd->vidq.dev = &pdev->dev; in dt3155_probe()
524 pd->vdev.queue = &pd->vidq; in dt3155_probe()
525 err = vb2_queue_init(&pd->vidq); in dt3155_probe()
528 spin_lock_init(&pd->lock); in dt3155_probe()
529 pd->config = ACQ_MODE_EVEN; in dt3155_probe()
536 pd->regs = pci_iomap(pdev, 0, pci_resource_len(pd->pdev, 0)); in dt3155_probe()
537 if (!pd->regs) { in dt3155_probe()
538 err = -ENOMEM; in dt3155_probe()
541 err = dt3155_init_board(pd); in dt3155_probe()
544 err = request_irq(pd->pdev->irq, dt3155_irq_handler_even, in dt3155_probe()
545 IRQF_SHARED, DT3155_NAME, pd); in dt3155_probe()
548 err = video_register_device(&pd->vdev, VFL_TYPE_VIDEO, -1); in dt3155_probe()
551 dev_info(&pdev->dev, "/dev/video%i is ready\n", pd->vdev.minor); in dt3155_probe()
555 free_irq(pd->pdev->irq, pd); in dt3155_probe()
557 pci_iounmap(pdev, pd->regs); in dt3155_probe()
563 v4l2_device_unregister(&pd->v4l2_dev); in dt3155_probe()
570 struct dt3155_priv *pd = container_of(v4l2_dev, struct dt3155_priv, in dt3155_remove() local
573 vb2_video_unregister_device(&pd->vdev); in dt3155_remove()
574 free_irq(pd->pdev->irq, pd); in dt3155_remove()
575 v4l2_device_unregister(&pd->v4l2_dev); in dt3155_remove()
576 pci_iounmap(pdev, pd->regs); in dt3155_remove()
596 MODULE_DESCRIPTION("video4linux pci-driver for dt3155 frame grabber");