1 #include <linux/config.h>
2 #include <linux/ctype.h>
4 struct procfs_params_zr36067 {
11 static struct procfs_params_zr36067 zr67[] = {
12 {"HSPol", 0x000, 1, 30},
13 {"HStart", 0x000, 0x3ff, 10},
14 {"HEnd", 0x000, 0x3ff, 0},
16 {"VSPol", 0x004, 1, 30},
17 {"VStart", 0x004, 0x3ff, 10},
18 {"VEnd", 0x004, 0x3ff, 0},
20 {"ExtFl", 0x008, 1, 26},
21 {"TopField", 0x008, 1, 25},
22 {"VCLKPol", 0x008, 1, 24},
23 {"DupFld", 0x008, 1, 20},
24 {"LittleEndian", 0x008, 1, 0},
26 {"HsyncStart", 0x10c, 0xffff, 16},
27 {"LineTot", 0x10c, 0xffff, 0},
29 {"NAX", 0x110, 0xffff, 16},
30 {"PAX", 0x110, 0xffff, 0},
32 {"NAY", 0x114, 0xffff, 16},
33 {"PAY", 0x114, 0xffff, 0},
39 static void setparam(struct zoran *zr, char *name, char *sval)
41 int i, reg0, reg, val;
43 while (zr67[i].name != NULL) {
44 if (!strncmp(name, zr67[i].name, strlen(zr67[i].name))) {
45 reg = reg0 = btread(zr67[i].reg);
46 reg &= ~(zr67[i].mask << zr67[i].bit);
47 if (!isdigit(sval[0]))
49 val = simple_strtoul(sval, NULL, 0);
50 if ((val & ~zr67[i].mask))
52 reg |= (val & zr67[i].mask) << zr67[i].bit;
53 printk(KERN_INFO "%s: setparam: setting ZR36067 register 0x%03x: 0x%08x=>0x%08x %s=%d\n",
54 zr->name, zr67[i].reg, reg0, reg, zr67[i].name, val);
55 btwrite(reg, zr67[i].reg);
62 /* This macro was stolen from /usr/src/drivers/char/nvram.c and modified */
63 #define PRINT_PROC(args...) \
65 if (begin + len > offset + size) { \
69 len += sprintf( buffer+len, ##args ); \
70 if (begin + len < offset) { \
76 static int zoran_read_proc(char *buffer, char **start, off_t offset, int size, int *eof, void *data)
85 zr = (struct zoran *) data;
86 DEBUG2(printk(KERN_INFO "%s: read_proc: buffer=%x, offset=%d, size=%d, data=%x\n", zr->name, (int) buffer, (int) offset, size, (int) data));
88 PRINT_PROC("ZR36067 registers:");
89 for (i = 0; i < 0x130; i += 4) {
91 PRINT_PROC("\n%03X", i);
93 PRINT_PROC(" %08X ", btread(i));
96 if (offset >= len + begin) {
99 *start = buffer + begin - offset;
100 return ((size < begin + len - offset) ? size : begin + len - offset);
105 static int zoran_write_proc(struct file *file, const char *buffer, unsigned long count, void *data)
107 #ifdef CONFIG_PROC_FS
109 char *line, *ldelim, *varname, *svar, *tdelim;
112 zr = (struct zoran *) data;
114 if(count > 32768) /* Stupidity filter */
117 string = sp = vmalloc(count + 1);
119 printk(KERN_ERR "%s: write_proc: can not allocate memory\n", zr->name);
122 if(copy_from_user(string, buffer, count))
128 DEBUG2(printk(KERN_INFO "%s: write_proc: name=%s count=%lu data=%x\n", zr->name, file->f_dentry->d_name.name, count, (int) data));
131 line = strpbrk(sp, ldelim);
134 svar = strpbrk(sp, tdelim);
139 setparam(zr, varname, svar);
142 line = strpbrk(sp, ldelim);
149 static int zoran_proc_init(int i)
151 #ifdef CONFIG_PROC_FS
153 sprintf(name, "zoran%d", i);
154 if ((zoran[i].zoran_proc = create_proc_entry(name, 0, 0))) {
155 zoran[i].zoran_proc->read_proc = zoran_read_proc;
156 zoran[i].zoran_proc->write_proc = zoran_write_proc;
157 zoran[i].zoran_proc->data = &zoran[i];
158 printk(KERN_INFO "%s: procfs entry /proc/%s allocated. data=%x\n", zoran[i].name, name, (int) zoran[i].zoran_proc->data);
160 printk(KERN_ERR "%s: Unable to initialise /proc/%s\n", zoran[i].name, name);
167 static void zoran_proc_cleanup(int i)
169 #ifdef CONFIG_PROC_FS
171 sprintf(name, "zoran%d", i);
172 if (zoran[i].zoran_proc) {
173 remove_proc_entry(name, 0);
175 zoran[i].zoran_proc = NULL;