V4L/DVB (4068): Removed all references to kernel stuff from videodev.h and videodev2.h
[linux-2.6] / drivers / media / video / zoran_procfs.c
1 /*
2  * Zoran zr36057/zr36067 PCI controller driver, for the
3  * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
4  * Media Labs LML33/LML33R10.
5  *
6  * This part handles the procFS entries (/proc/ZORAN[%d])
7  *
8  * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9  *
10  * Currently maintained by:
11  *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
12  *   Laurent Pinchart <laurent.pinchart@skynet.be>
13  *   Mailinglist      <mjpeg-users@lists.sf.net>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28  */
29
30 #include <linux/config.h>
31 #include <linux/types.h>
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/vmalloc.h>
35
36 #include <linux/proc_fs.h>
37 #include <linux/pci.h>
38 #include <linux/i2c.h>
39 #include <linux/i2c-algo-bit.h>
40 #include <linux/videodev.h>
41 #include <linux/spinlock.h>
42 #include <linux/sem.h>
43 #include <linux/seq_file.h>
44
45 #include <linux/ctype.h>
46 #include <linux/poll.h>
47 #include <asm/io.h>
48
49 #include "videocodec.h"
50 #include "zoran.h"
51 #include "zoran_procfs.h"
52
53 extern int *zr_debug;
54
55 #define dprintk(num, format, args...) \
56         do { \
57                 if (*zr_debug >= num) \
58                         printk(format, ##args); \
59         } while (0)
60
61 #ifdef CONFIG_PROC_FS
62 struct procfs_params_zr36067 {
63         char *name;
64         short reg;
65         u32 mask;
66         short bit;
67 };
68
69 static const struct procfs_params_zr36067 zr67[] = {
70         {"HSPol", 0x000, 1, 30},
71         {"HStart", 0x000, 0x3ff, 10},
72         {"HEnd", 0x000, 0x3ff, 0},
73
74         {"VSPol", 0x004, 1, 30},
75         {"VStart", 0x004, 0x3ff, 10},
76         {"VEnd", 0x004, 0x3ff, 0},
77
78         {"ExtFl", 0x008, 1, 26},
79         {"TopField", 0x008, 1, 25},
80         {"VCLKPol", 0x008, 1, 24},
81         {"DupFld", 0x008, 1, 20},
82         {"LittleEndian", 0x008, 1, 0},
83
84         {"HsyncStart", 0x10c, 0xffff, 16},
85         {"LineTot", 0x10c, 0xffff, 0},
86
87         {"NAX", 0x110, 0xffff, 16},
88         {"PAX", 0x110, 0xffff, 0},
89
90         {"NAY", 0x114, 0xffff, 16},
91         {"PAY", 0x114, 0xffff, 0},
92
93         /* {"",,,}, */
94
95         {NULL, 0, 0, 0},
96 };
97
98 static void
99 setparam (struct zoran *zr,
100           char         *name,
101           char         *sval)
102 {
103         int i = 0, reg0, reg, val;
104
105         while (zr67[i].name != NULL) {
106                 if (!strncmp(name, zr67[i].name, strlen(zr67[i].name))) {
107                         reg = reg0 = btread(zr67[i].reg);
108                         reg &= ~(zr67[i].mask << zr67[i].bit);
109                         if (!isdigit(sval[0]))
110                                 break;
111                         val = simple_strtoul(sval, NULL, 0);
112                         if ((val & ~zr67[i].mask))
113                                 break;
114                         reg |= (val & zr67[i].mask) << zr67[i].bit;
115                         dprintk(4,
116                                 KERN_INFO
117                                 "%s: setparam: setting ZR36067 register 0x%03x: 0x%08x=>0x%08x %s=%d\n",
118                                 ZR_DEVNAME(zr), zr67[i].reg, reg0, reg,
119                                 zr67[i].name, val);
120                         btwrite(reg, zr67[i].reg);
121                         break;
122                 }
123                 i++;
124         }
125 }
126
127 static int zoran_show(struct seq_file *p, void *v)
128 {
129         struct zoran *zr = p->private;
130         int i;
131
132         seq_printf(p, "ZR36067 registers:\n");
133         for (i = 0; i < 0x130; i += 16)
134                 seq_printf(p, "%03X %08X  %08X  %08X  %08X \n", i,
135                            btread(i), btread(i+4), btread(i+8), btread(i+12));
136         return 0;
137 }
138
139 static int zoran_open(struct inode *inode, struct file *file)
140 {
141         struct zoran *data = PDE(inode)->data;
142         return single_open(file, zoran_show, data);
143 }
144
145 static ssize_t zoran_write(struct file *file, const char __user *buffer,
146                         size_t count, loff_t *ppos)
147 {
148         struct zoran *zr = PDE(file->f_dentry->d_inode)->data;
149         char *string, *sp;
150         char *line, *ldelim, *varname, *svar, *tdelim;
151
152         if (count > 32768)      /* Stupidity filter */
153                 return -EINVAL;
154
155         string = sp = vmalloc(count + 1);
156         if (!string) {
157                 dprintk(1,
158                         KERN_ERR
159                         "%s: write_proc: can not allocate memory\n",
160                         ZR_DEVNAME(zr));
161                 return -ENOMEM;
162         }
163         if (copy_from_user(string, buffer, count)) {
164                 vfree (string);
165                 return -EFAULT;
166         }
167         string[count] = 0;
168         dprintk(4, KERN_INFO "%s: write_proc: name=%s count=%zu zr=%p\n",
169                 ZR_DEVNAME(zr), file->f_dentry->d_name.name, count, zr);
170         ldelim = " \t\n";
171         tdelim = "=";
172         line = strpbrk(sp, ldelim);
173         while (line) {
174                 *line = 0;
175                 svar = strpbrk(sp, tdelim);
176                 if (svar) {
177                         *svar = 0;
178                         varname = sp;
179                         svar++;
180                         setparam(zr, varname, svar);
181                 }
182                 sp = line + 1;
183                 line = strpbrk(sp, ldelim);
184         }
185         vfree(string);
186
187         return count;
188 }
189
190 static struct file_operations zoran_operations = {
191         .open           = zoran_open,
192         .read           = seq_read,
193         .write          = zoran_write,
194         .llseek         = seq_lseek,
195         .release        = single_release,
196 };
197 #endif
198
199 int
200 zoran_proc_init (struct zoran *zr)
201 {
202 #ifdef CONFIG_PROC_FS
203         char name[8];
204
205         snprintf(name, 7, "zoran%d", zr->id);
206         if ((zr->zoran_proc = create_proc_entry(name, 0, NULL))) {
207                 zr->zoran_proc->data = zr;
208                 zr->zoran_proc->owner = THIS_MODULE;
209                 zr->zoran_proc->proc_fops = &zoran_operations;
210                 dprintk(2,
211                         KERN_INFO
212                         "%s: procfs entry /proc/%s allocated. data=%p\n",
213                         ZR_DEVNAME(zr), name, zr->zoran_proc->data);
214         } else {
215                 dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n",
216                         ZR_DEVNAME(zr), name);
217                 return 1;
218         }
219 #endif
220         return 0;
221 }
222
223 void
224 zoran_proc_cleanup (struct zoran *zr)
225 {
226 #ifdef CONFIG_PROC_FS
227         char name[8];
228
229         snprintf(name, 7, "zoran%d", zr->id);
230         if (zr->zoran_proc)
231                 remove_proc_entry(name, NULL);
232         zr->zoran_proc = NULL;
233 #endif
234 }