WIP FPC-III support
[linux/fpc-iii.git] / drivers / media / pci / cx23885 / cx23885-ioctl.c
bloba8ccad07cf50303895a14e29751b39a8c365fa17
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Driver for the Conexant CX23885/7/8 PCIe bridge
5 * Various common ioctl() support functions
7 * Copyright (c) 2009 Andy Walls <awalls@md.metrocast.net>
8 */
10 #include "cx23885.h"
11 #include "cx23885-ioctl.h"
13 #ifdef CONFIG_VIDEO_ADV_DEBUG
14 int cx23885_g_chip_info(struct file *file, void *fh,
15 struct v4l2_dbg_chip_info *chip)
17 struct cx23885_dev *dev = video_drvdata(file);
19 if (chip->match.addr > 1)
20 return -EINVAL;
21 if (chip->match.addr == 1) {
22 if (dev->v4l_device == NULL)
23 return -EINVAL;
24 strscpy(chip->name, "cx23417", sizeof(chip->name));
25 } else {
26 strscpy(chip->name, dev->v4l2_dev.name, sizeof(chip->name));
28 return 0;
31 static int cx23417_g_register(struct cx23885_dev *dev,
32 struct v4l2_dbg_register *reg)
34 u32 value;
36 if (dev->v4l_device == NULL)
37 return -EINVAL;
39 if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
40 return -EINVAL;
42 if (mc417_register_read(dev, (u16) reg->reg, &value))
43 return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
45 reg->size = 4;
46 reg->val = value;
47 return 0;
50 int cx23885_g_register(struct file *file, void *fh,
51 struct v4l2_dbg_register *reg)
53 struct cx23885_dev *dev = video_drvdata(file);
55 if (reg->match.addr > 1)
56 return -EINVAL;
57 if (reg->match.addr)
58 return cx23417_g_register(dev, reg);
60 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
61 return -EINVAL;
63 reg->size = 4;
64 reg->val = cx_read(reg->reg);
65 return 0;
68 static int cx23417_s_register(struct cx23885_dev *dev,
69 const struct v4l2_dbg_register *reg)
71 if (dev->v4l_device == NULL)
72 return -EINVAL;
74 if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
75 return -EINVAL;
77 if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
78 return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
79 return 0;
82 int cx23885_s_register(struct file *file, void *fh,
83 const struct v4l2_dbg_register *reg)
85 struct cx23885_dev *dev = video_drvdata(file);
87 if (reg->match.addr > 1)
88 return -EINVAL;
89 if (reg->match.addr)
90 return cx23417_s_register(dev, reg);
92 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
93 return -EINVAL;
95 cx_write(reg->reg, reg->val);
96 return 0;
98 #endif