aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Walls <awalls@radix.net>2009-09-26 21:50:44 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-12-05 15:40:16 -0500
commit74618244003a5a9e11240af8c5795ae747d9a2e0 (patch)
tree20021195d0e5b841808e4e5dfb6b1d40c16f3f9e
parentf56db93cef5d368b4fa5db49b68bc4ab0b20c4fd (diff)
V4L/DVB (13085): cx23885: Fix support for v4l2-dbg access to CX2388[578] and CX23417 regs
This changes corrects the ioctl() operations for both the CX2388[578] analog video and MPEG video device nodes to properly and consistently support VIDIOC_G_CHIP_IDENT, VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER ioctl()s. This caused some ioctl() support routines to be broken out into a separate source file. Now v4l2-dbg can be used to manipulate CX2388[578] and CX23417 registers including the CX2388[57] functions handled by the cx25840 module. This was done in anticipation of developing a new v4l2_subdev for the integrated IR controller of the CX23888. Signed-off-by: Andy Walls <awalls@radix.net> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/cx23885/Makefile1
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c10
-rw-r--r--drivers/media/video/cx23885/cx23885-ioctl.c197
-rw-r--r--drivers/media/video/cx23885/cx23885-ioctl.h39
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c34
-rw-r--r--drivers/media/video/cx23885/cx23885.h4
6 files changed, 253 insertions, 32 deletions
diff --git a/drivers/media/video/cx23885/Makefile b/drivers/media/video/cx23885/Makefile
index ab8ea35c9bfb..93a954c23f42 100644
--- a/drivers/media/video/cx23885/Makefile
+++ b/drivers/media/video/cx23885/Makefile
@@ -1,5 +1,6 @@
1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o \ 1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o \
2 cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o \ 2 cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o \
3 cx23885-ioctl.o \
3 netup-init.o cimax2.o netup-eeprom.o 4 netup-init.o cimax2.o netup-eeprom.o
4 5
5obj-$(CONFIG_VIDEO_CX23885) += cx23885.o 6obj-$(CONFIG_VIDEO_CX23885) += cx23885.o
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
index 6c3b51ce3372..0eed852c61e9 100644
--- a/drivers/media/video/cx23885/cx23885-417.c
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -37,6 +37,7 @@
37#include <media/cx2341x.h> 37#include <media/cx2341x.h>
38 38
39#include "cx23885.h" 39#include "cx23885.h"
40#include "cx23885-ioctl.h"
40 41
41#define CX23885_FIRM_IMAGE_SIZE 376836 42#define CX23885_FIRM_IMAGE_SIZE 376836
42#define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw" 43#define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw"
@@ -318,7 +319,7 @@ static int mc417_wait_ready(struct cx23885_dev *dev)
318 } 319 }
319} 320}
320 321
321static int mc417_register_write(struct cx23885_dev *dev, u16 address, u32 value) 322int mc417_register_write(struct cx23885_dev *dev, u16 address, u32 value)
322{ 323{
323 u32 regval; 324 u32 regval;
324 325
@@ -382,7 +383,7 @@ static int mc417_register_write(struct cx23885_dev *dev, u16 address, u32 value)
382 return mc417_wait_ready(dev); 383 return mc417_wait_ready(dev);
383} 384}
384 385
385static int mc417_register_read(struct cx23885_dev *dev, u16 address, u32 *value) 386int mc417_register_read(struct cx23885_dev *dev, u16 address, u32 *value)
386{ 387{
387 int retval; 388 int retval;
388 u32 regval; 389 u32 regval;
@@ -1724,6 +1725,11 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1724 .vidioc_log_status = vidioc_log_status, 1725 .vidioc_log_status = vidioc_log_status,
1725 .vidioc_querymenu = vidioc_querymenu, 1726 .vidioc_querymenu = vidioc_querymenu,
1726 .vidioc_queryctrl = vidioc_queryctrl, 1727 .vidioc_queryctrl = vidioc_queryctrl,
1728 .vidioc_g_chip_ident = cx23885_g_chip_ident,
1729#ifdef CONFIG_VIDEO_ADV_DEBUG
1730 .vidioc_g_register = cx23885_g_register,
1731 .vidioc_s_register = cx23885_s_register,
1732#endif
1727}; 1733};
1728 1734
1729static struct video_device cx23885_mpeg_template = { 1735static struct video_device cx23885_mpeg_template = {
diff --git a/drivers/media/video/cx23885/cx23885-ioctl.c b/drivers/media/video/cx23885/cx23885-ioctl.c
new file mode 100644
index 000000000000..3a497b6c4fd7
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-ioctl.c
@@ -0,0 +1,197 @@
1/*
2 * Driver for the Conexant CX23885/7/8 PCIe bridge
3 *
4 * Various common ioctl() support functions
5 *
6 * Copyright (c) 2009 Andy Walls <awalls@radix.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 *
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include "cx23885.h"
25#include <media/v4l2-chip-ident.h>
26
27int cx23885_g_chip_ident(struct file *file, void *fh,
28 struct v4l2_dbg_chip_ident *chip)
29{
30 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
31 int err = 0;
32 u8 rev;
33
34 chip->ident = V4L2_IDENT_NONE;
35 chip->revision = 0;
36 switch (chip->match.type) {
37 case V4L2_CHIP_MATCH_HOST:
38 switch (chip->match.addr) {
39 case 0:
40 rev = cx_read(RDR_CFG2) & 0xff;
41 switch (dev->pci->device) {
42 case 0x8852:
43 /* rev 0x04 could be '885 or '888. Pick '888. */
44 if (rev == 0x04)
45 chip->ident = V4L2_IDENT_CX23888;
46 else
47 chip->ident = V4L2_IDENT_CX23885;
48 break;
49 case 0x8880:
50 if (rev == 0x0e || rev == 0x0f)
51 chip->ident = V4L2_IDENT_CX23887;
52 else
53 chip->ident = V4L2_IDENT_CX23888;
54 break;
55 default:
56 chip->ident = V4L2_IDENT_UNKNOWN;
57 break;
58 }
59 chip->revision = (dev->pci->device << 16) | (rev << 8) |
60 (dev->hwrevision & 0xff);
61 break;
62 case 1:
63 if (dev->v4l_device != NULL) {
64 chip->ident = V4L2_IDENT_CX23417;
65 chip->revision = 0;
66 }
67 break;
68 default:
69 err = -EINVAL; /* per V4L2 spec */
70 break;
71 }
72 break;
73 case V4L2_CHIP_MATCH_I2C_DRIVER:
74 /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
75 call_all(dev, core, g_chip_ident, chip);
76 break;
77 case V4L2_CHIP_MATCH_I2C_ADDR:
78 /*
79 * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
80 * to look if a chip is at the address with no driver. That's a
81 * dangerous thing to do with EEPROMs anyway.
82 */
83 call_all(dev, core, g_chip_ident, chip);
84 break;
85 default:
86 err = -EINVAL;
87 break;
88 }
89 return err;
90}
91
92#ifdef CONFIG_VIDEO_ADV_DEBUG
93static int cx23885_g_host_register(struct cx23885_dev *dev,
94 struct v4l2_dbg_register *reg)
95{
96 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
97 return -EINVAL;
98
99 reg->size = 4;
100 reg->val = cx_read(reg->reg);
101 return 0;
102}
103
104static int cx23417_g_register(struct cx23885_dev *dev,
105 struct v4l2_dbg_register *reg)
106{
107 u32 value;
108
109 if (dev->v4l_device == NULL)
110 return -EINVAL;
111
112 if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
113 return -EINVAL;
114
115 if (mc417_register_read(dev, (u16) reg->reg, &value))
116 return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
117
118 reg->size = 4;
119 reg->val = value;
120 return 0;
121}
122
123int cx23885_g_register(struct file *file, void *fh,
124 struct v4l2_dbg_register *reg)
125{
126 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
127
128 if (!capable(CAP_SYS_ADMIN))
129 return -EPERM;
130
131 if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
132 switch (reg->match.addr) {
133 case 0:
134 return cx23885_g_host_register(dev, reg);
135 case 1:
136 return cx23417_g_register(dev, reg);
137 default:
138 break;
139 }
140 }
141
142 /* FIXME - any error returns should not be ignored */
143 call_all(dev, core, g_register, reg);
144 return 0;
145}
146
147static int cx23885_s_host_register(struct cx23885_dev *dev,
148 struct v4l2_dbg_register *reg)
149{
150 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
151 return -EINVAL;
152
153 reg->size = 4;
154 cx_write(reg->reg, reg->val);
155 return 0;
156}
157
158static int cx23417_s_register(struct cx23885_dev *dev,
159 struct v4l2_dbg_register *reg)
160{
161 if (dev->v4l_device == NULL)
162 return -EINVAL;
163
164 if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
165 return -EINVAL;
166
167 if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
168 return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
169
170 reg->size = 4;
171 return 0;
172}
173
174int cx23885_s_register(struct file *file, void *fh,
175 struct v4l2_dbg_register *reg)
176{
177 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
178
179 if (!capable(CAP_SYS_ADMIN))
180 return -EPERM;
181
182 if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
183 switch (reg->match.addr) {
184 case 0:
185 return cx23885_s_host_register(dev, reg);
186 case 1:
187 return cx23417_s_register(dev, reg);
188 default:
189 break;
190 }
191 }
192
193 /* FIXME - any error returns should not be ignored */
194 call_all(dev, core, s_register, reg);
195 return 0;
196}
197#endif
diff --git a/drivers/media/video/cx23885/cx23885-ioctl.h b/drivers/media/video/cx23885/cx23885-ioctl.h
new file mode 100644
index 000000000000..80b0f4923c6a
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-ioctl.h
@@ -0,0 +1,39 @@
1/*
2 * Driver for the Conexant CX23885/7/8 PCIe bridge
3 *
4 * Various common ioctl() support functions
5 *
6 * Copyright (c) 2009 Andy Walls <awalls@radix.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 *
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef _CX23885_IOCTL_H_
25#define _CX23885_IOCTL_H_
26
27int cx23885_g_chip_ident(struct file *file, void *fh,
28 struct v4l2_dbg_chip_ident *chip);
29
30#ifdef CONFIG_VIDEO_ADV_DEBUG
31int cx23885_g_register(struct file *file, void *fh,
32 struct v4l2_dbg_register *reg);
33
34
35int cx23885_s_register(struct file *file, void *fh,
36 struct v4l2_dbg_register *reg);
37
38#endif
39#endif
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 654cc253cd50..3f1d07e6490a 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -35,6 +35,7 @@
35#include "cx23885.h" 35#include "cx23885.h"
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include "cx23885-ioctl.h"
38 39
39MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards"); 40MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
40MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); 41MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
@@ -1312,34 +1313,6 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1312 cx23885_set_freq(dev, f); 1313 cx23885_set_freq(dev, f);
1313} 1314}
1314 1315
1315#ifdef CONFIG_VIDEO_ADV_DEBUG
1316static int vidioc_g_register(struct file *file, void *fh,
1317 struct v4l2_dbg_register *reg)
1318{
1319 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1320
1321 if (!v4l2_chip_match_host(&reg->match))
1322 return -EINVAL;
1323
1324 call_all(dev, core, g_register, reg);
1325
1326 return 0;
1327}
1328
1329static int vidioc_s_register(struct file *file, void *fh,
1330 struct v4l2_dbg_register *reg)
1331{
1332 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
1333
1334 if (!v4l2_chip_match_host(&reg->match))
1335 return -EINVAL;
1336
1337 call_all(dev, core, s_register, reg);
1338
1339 return 0;
1340}
1341#endif
1342
1343/* ----------------------------------------------------------- */ 1316/* ----------------------------------------------------------- */
1344 1317
1345static void cx23885_vid_timeout(unsigned long data) 1318static void cx23885_vid_timeout(unsigned long data)
@@ -1449,9 +1422,10 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1449 .vidioc_s_tuner = vidioc_s_tuner, 1422 .vidioc_s_tuner = vidioc_s_tuner,
1450 .vidioc_g_frequency = vidioc_g_frequency, 1423 .vidioc_g_frequency = vidioc_g_frequency,
1451 .vidioc_s_frequency = vidioc_s_frequency, 1424 .vidioc_s_frequency = vidioc_s_frequency,
1425 .vidioc_g_chip_ident = cx23885_g_chip_ident,
1452#ifdef CONFIG_VIDEO_ADV_DEBUG 1426#ifdef CONFIG_VIDEO_ADV_DEBUG
1453 .vidioc_g_register = vidioc_g_register, 1427 .vidioc_g_register = cx23885_g_register,
1454 .vidioc_s_register = vidioc_s_register, 1428 .vidioc_s_register = cx23885_s_register,
1455#endif 1429#endif
1456}; 1430};
1457 1431
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index cc7a165561ff..f4c4108f23f3 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -515,6 +515,10 @@ extern void cx23885_417_check_encoder(struct cx23885_dev *dev);
515extern void cx23885_mc417_init(struct cx23885_dev *dev); 515extern void cx23885_mc417_init(struct cx23885_dev *dev);
516extern int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value); 516extern int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value);
517extern int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value); 517extern int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value);
518extern int mc417_register_read(struct cx23885_dev *dev,
519 u16 address, u32 *value);
520extern int mc417_register_write(struct cx23885_dev *dev,
521 u16 address, u32 value);
518extern void mc417_gpio_set(struct cx23885_dev *dev, u32 mask); 522extern void mc417_gpio_set(struct cx23885_dev *dev, u32 mask);
519extern void mc417_gpio_clear(struct cx23885_dev *dev, u32 mask); 523extern void mc417_gpio_clear(struct cx23885_dev *dev, u32 mask);
520extern void mc417_gpio_enable(struct cx23885_dev *dev, u32 mask, int asoutput); 524extern void mc417_gpio_enable(struct cx23885_dev *dev, u32 mask, int asoutput);