27 #include <linux/types.h>
28 #include <linux/kernel.h>
29 #include <linux/module.h>
33 #include <linux/videodev2.h>
37 #include <linux/pci.h>
42 #include <linux/i2c.h>
51 #define DRV_NAME "sta2x11_vip"
52 #define DRV_VERSION "1.3"
54 #ifndef PCI_DEVICE_ID_STMICRO_VIP
55 #define PCI_DEVICE_ID_STMICRO_VIP 0xCC0D
72 #define DVP_HLFLN 0xA8
77 #define DVP_CTL_ENA 0x00000001
78 #define DVP_CTL_RST 0x80000000
79 #define DVP_CTL_DIS (~0x00040001)
81 #define DVP_IT_VSB 0x00000008
82 #define DVP_IT_VST 0x00000010
83 #define DVP_IT_FIFO 0x00000020
85 #define DVP_HLFLN_SD 0x00000001
87 #define REG_WRITE(vip, reg, value) iowrite32((value), (vip->iomem)+(reg))
88 #define REG_READ(vip, reg) ioread32((vip->iomem)+(reg))
150 static const unsigned int registers_to_save[
AUX_COUNT] = {
160 .bytesperline = 720 * 2,
161 .sizeimage = 720 * 2 * 576,
168 .bytesperline = 720 * 2,
169 .sizeimage = 720 * 2 * 288,
176 .bytesperline = 720 * 2,
177 .sizeimage = 720 * 2 * 288,
188 .bytesperline = 720 * 2,
189 .sizeimage = 720 * 2 * 480,
196 .bytesperline = 720 * 2,
197 .sizeimage = 720 * 2 * 240,
204 .bytesperline = 720 * 2,
205 .sizeimage = 720 * 2 * 240,
302 switch (vip->
format.field) {
305 ((vip->
format.height / 2 - 1) << 16) |
306 (2 * vip->
format.width - 1));
308 (2 * vip->
format.width - 1));
315 ((vip->
format.height - 1) << 16) |
316 (2 * vip->
format.width - 1));
318 (2 * vip->
format.width - 1));
325 (2 * vip->
format.width - 1));
327 ((vip->
format.height) << 16) |
328 (2 * vip->
format.width - 1));
374 static int vip_open(
struct file *
file)
382 if (vip->
users > 1) {
431 static int vip_close(
struct file *file)
439 spin_lock_irq(&vip->
slock);
449 spin_unlock_irq(&vip->
slock);
473 static ssize_t vip_read(
struct file *file,
char __user *
data,
474 size_t count, loff_t *ppos)
492 static int vip_mmap(
struct file *file,
struct vm_area_struct *vma)
527 static int vidioc_querycap(
struct file *file,
void *
priv,
538 pci_name(vip->
pdev));
559 static int vidioc_s_std(
struct file *file,
void *priv,
v4l2_std_id *
std)
573 *std = vip->
std = newstd;
574 if (oldstd != *std) {
576 vip->
format = formats_60[0];
578 vip->
format = formats_50[0];
583 if (oldstd != *std) {
585 vip->
format = formats_60[0];
587 vip->
format = formats_50[0];
603 static int vidioc_g_std(
struct file *file,
void *priv,
v4l2_std_id *std)
622 static int vidioc_querystd(
struct file *file,
void *priv,
v4l2_std_id *std)
640 static int vidioc_queryctrl(
struct file *file,
void *priv,
658 static int vidioc_g_ctrl(
struct file *file,
void *priv,
676 static int vidioc_s_ctrl(
struct file *file,
void *priv,
697 static int vidioc_enum_input(
struct file *file,
void *priv,
722 static int vidioc_s_input(
struct file *file,
void *priv,
unsigned int i)
748 static int vidioc_g_input(
struct file *file,
void *priv,
unsigned int *i)
768 static int vidioc_enum_fmt_vid_cap(
struct file *file,
void *priv,
797 static int vidioc_try_fmt_vid_cap(
struct file *file,
void *priv,
812 switch (f->
fmt.
pix.field) {
814 if (interlace_lim < f->
fmt.pix.height)
821 if (interlace_lim < f->
fmt.pix.height)
822 f->
fmt.
pix.height = interlace_lim;
831 if (2 * interlace_lim < f->
fmt.pix.height)
832 f->
fmt.
pix.height = 2 * interlace_lim;
833 if (200 > f->
fmt.
pix.height)
854 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *priv,
861 ret = vidioc_try_fmt_vid_cap(file, priv, f);
879 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *priv,
897 static int vidioc_reqbufs(
struct file *file,
void *priv,
915 static int vidioc_querybuf(
struct file *file,
void *priv,
struct v4l2_buffer *
p)
931 static int vidioc_qbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
p)
947 static int vidioc_dqbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
p)
964 static int vidioc_streamon(
struct file *file,
void *priv,
982 static int vidioc_streamoff(
struct file *file,
void *priv,
994 .release = vip_close,
1028 .ioctl_ops = &vip_ioctl_ops,
1050 unsigned long flags;
1069 if ((DVP_IT_VSB | DVP_IT_VST) == (status & (DVP_IT_VST | DVP_IT_VSB))) {
1078 pr_info(
"VIP: fifo overflow\n");
1084 if (status & DVP_IT_VSB)
1092 vip->
active->field_count++;
1098 if (list_empty(&vip->
capture))
1111 switch (vip->
format.field) {
1129 spin_unlock_irqrestore(&vip->
slock, flags);
1141 static int vip_gpio_reserve(
struct device *dev,
int pin,
int dir,
1151 dev_err(dev,
"Failed to allocate pin %d (%s)\n", pin, name);
1157 dev_err(dev,
"Failed to set direction for pin %d (%s)\n",
1163 ret = gpio_export(pin,
false);
1165 dev_err(dev,
"Failed to export pin %d (%s)\n", pin, name);
1180 static void vip_gpio_release(
struct device *dev,
int pin,
const char *name)
1183 dev_dbg(dev,
"releasing pin %d (%s)\n", pin, name);
1219 config = dev_get_platdata(&pdev->
dev);
1226 ret = vip_gpio_reserve(&pdev->
dev, config->
pwr_pin, 0,
1232 ret = vip_gpio_reserve(&pdev->
dev, config->
reset_pin, 0,
1235 vip_gpio_release(&pdev->
dev, config->
pwr_pin,
1262 vip->
format = formats_50[0];
1268 dev_dbg(&pdev->
dev,
"BAR #0 at 0x%lx 0x%lx irq %d\n",
1278 vip->
iomem = pci_iomap(pdev, 0, 0x100);
1284 pci_enable_msi(pdev);
1286 INIT_LIST_HEAD(&vip->
capture);
1317 dev_err(&pdev->
dev,
"no I2C adapter found\n");
1322 "adv7180", vip->
config->i2c_addr,
1334 pr_info(
"STA2X11 Video Input Port (VIP) loaded\n");
1340 if (video_is_registered(vip->
video_dev))
1381 struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1396 vip_gpio_release(&pdev->
dev, vip->
config->pwr_pin,
1398 vip_gpio_release(&pdev->
dev, vip->
config->reset_pin,
1399 vip->
config->reset_name);
1425 struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1428 unsigned long flags;
1440 REG_READ(vip, registers_to_save[i]);
1441 spin_unlock_irqrestore(&vip->
slock, flags);
1467 static int sta2x11_vip_resume(
struct pci_dev *pdev)
1469 struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1472 unsigned long flags;
1506 spin_unlock_irqrestore(&vip->
slock, flags);
1517 static struct pci_driver sta2x11_vip_driver = {
1519 .probe = sta2x11_vip_init_one,
1521 .id_table = sta2x11_vip_pci_tbl,
1523 .suspend = sta2x11_vip_suspend,
1524 .resume = sta2x11_vip_resume,
1528 static int __init sta2x11_vip_init_module(
void)
1530 return pci_register_driver(&sta2x11_vip_driver);
1533 static void __exit sta2x11_vip_exit_module(
void)