Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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]) |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/types.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | |
| 35 | #include <linux/proc_fs.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/i2c.h> |
| 38 | #include <linux/i2c-algo-bit.h> |
| 39 | #include <linux/videodev.h> |
| 40 | #include <linux/spinlock.h> |
| 41 | #include <linux/sem.h> |
| 42 | #include <linux/seq_file.h> |
| 43 | |
| 44 | #include <linux/ctype.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 45 | #include <linux/poll.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/io.h> |
| 47 | |
| 48 | #include "videocodec.h" |
| 49 | #include "zoran.h" |
| 50 | #include "zoran_procfs.h" |
Jean Delvare | 18b548c | 2007-07-17 18:29:41 -0300 | [diff] [blame] | 51 | #include "zoran_card.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #ifdef CONFIG_PROC_FS |
| 54 | struct procfs_params_zr36067 { |
| 55 | char *name; |
| 56 | short reg; |
| 57 | u32 mask; |
| 58 | short bit; |
| 59 | }; |
| 60 | |
| 61 | static const struct procfs_params_zr36067 zr67[] = { |
| 62 | {"HSPol", 0x000, 1, 30}, |
| 63 | {"HStart", 0x000, 0x3ff, 10}, |
| 64 | {"HEnd", 0x000, 0x3ff, 0}, |
| 65 | |
| 66 | {"VSPol", 0x004, 1, 30}, |
| 67 | {"VStart", 0x004, 0x3ff, 10}, |
| 68 | {"VEnd", 0x004, 0x3ff, 0}, |
| 69 | |
| 70 | {"ExtFl", 0x008, 1, 26}, |
| 71 | {"TopField", 0x008, 1, 25}, |
| 72 | {"VCLKPol", 0x008, 1, 24}, |
| 73 | {"DupFld", 0x008, 1, 20}, |
| 74 | {"LittleEndian", 0x008, 1, 0}, |
| 75 | |
| 76 | {"HsyncStart", 0x10c, 0xffff, 16}, |
| 77 | {"LineTot", 0x10c, 0xffff, 0}, |
| 78 | |
| 79 | {"NAX", 0x110, 0xffff, 16}, |
| 80 | {"PAX", 0x110, 0xffff, 0}, |
| 81 | |
| 82 | {"NAY", 0x114, 0xffff, 16}, |
| 83 | {"PAY", 0x114, 0xffff, 0}, |
| 84 | |
| 85 | /* {"",,,}, */ |
| 86 | |
| 87 | {NULL, 0, 0, 0}, |
| 88 | }; |
| 89 | |
| 90 | static void |
| 91 | setparam (struct zoran *zr, |
| 92 | char *name, |
| 93 | char *sval) |
| 94 | { |
| 95 | int i = 0, reg0, reg, val; |
| 96 | |
| 97 | while (zr67[i].name != NULL) { |
| 98 | if (!strncmp(name, zr67[i].name, strlen(zr67[i].name))) { |
| 99 | reg = reg0 = btread(zr67[i].reg); |
| 100 | reg &= ~(zr67[i].mask << zr67[i].bit); |
| 101 | if (!isdigit(sval[0])) |
| 102 | break; |
| 103 | val = simple_strtoul(sval, NULL, 0); |
| 104 | if ((val & ~zr67[i].mask)) |
| 105 | break; |
| 106 | reg |= (val & zr67[i].mask) << zr67[i].bit; |
| 107 | dprintk(4, |
| 108 | KERN_INFO |
| 109 | "%s: setparam: setting ZR36067 register 0x%03x: 0x%08x=>0x%08x %s=%d\n", |
| 110 | ZR_DEVNAME(zr), zr67[i].reg, reg0, reg, |
| 111 | zr67[i].name, val); |
| 112 | btwrite(reg, zr67[i].reg); |
| 113 | break; |
| 114 | } |
| 115 | i++; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | static int zoran_show(struct seq_file *p, void *v) |
| 120 | { |
| 121 | struct zoran *zr = p->private; |
| 122 | int i; |
| 123 | |
| 124 | seq_printf(p, "ZR36067 registers:\n"); |
| 125 | for (i = 0; i < 0x130; i += 16) |
| 126 | seq_printf(p, "%03X %08X %08X %08X %08X \n", i, |
| 127 | btread(i), btread(i+4), btread(i+8), btread(i+12)); |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | static int zoran_open(struct inode *inode, struct file *file) |
| 132 | { |
| 133 | struct zoran *data = PDE(inode)->data; |
| 134 | return single_open(file, zoran_show, data); |
| 135 | } |
| 136 | |
| 137 | static ssize_t zoran_write(struct file *file, const char __user *buffer, |
| 138 | size_t count, loff_t *ppos) |
| 139 | { |
Josef Sipek | 723731b | 2006-12-08 02:37:47 -0800 | [diff] [blame] | 140 | struct zoran *zr = PDE(file->f_path.dentry->d_inode)->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | char *string, *sp; |
| 142 | char *line, *ldelim, *varname, *svar, *tdelim; |
| 143 | |
| 144 | if (count > 32768) /* Stupidity filter */ |
| 145 | return -EINVAL; |
| 146 | |
| 147 | string = sp = vmalloc(count + 1); |
| 148 | if (!string) { |
| 149 | dprintk(1, |
| 150 | KERN_ERR |
| 151 | "%s: write_proc: can not allocate memory\n", |
| 152 | ZR_DEVNAME(zr)); |
| 153 | return -ENOMEM; |
| 154 | } |
| 155 | if (copy_from_user(string, buffer, count)) { |
| 156 | vfree (string); |
| 157 | return -EFAULT; |
| 158 | } |
| 159 | string[count] = 0; |
| 160 | dprintk(4, KERN_INFO "%s: write_proc: name=%s count=%zu zr=%p\n", |
Josef Sipek | 723731b | 2006-12-08 02:37:47 -0800 | [diff] [blame] | 161 | ZR_DEVNAME(zr), file->f_path.dentry->d_name.name, count, zr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | ldelim = " \t\n"; |
| 163 | tdelim = "="; |
| 164 | line = strpbrk(sp, ldelim); |
| 165 | while (line) { |
| 166 | *line = 0; |
| 167 | svar = strpbrk(sp, tdelim); |
| 168 | if (svar) { |
| 169 | *svar = 0; |
| 170 | varname = sp; |
| 171 | svar++; |
| 172 | setparam(zr, varname, svar); |
| 173 | } |
| 174 | sp = line + 1; |
| 175 | line = strpbrk(sp, ldelim); |
| 176 | } |
| 177 | vfree(string); |
| 178 | |
| 179 | return count; |
| 180 | } |
| 181 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 182 | static const struct file_operations zoran_operations = { |
Denis V. Lunev | c7705f344 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 183 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | .open = zoran_open, |
| 185 | .read = seq_read, |
| 186 | .write = zoran_write, |
| 187 | .llseek = seq_lseek, |
| 188 | .release = single_release, |
| 189 | }; |
| 190 | #endif |
| 191 | |
| 192 | int |
| 193 | zoran_proc_init (struct zoran *zr) |
| 194 | { |
| 195 | #ifdef CONFIG_PROC_FS |
| 196 | char name[8]; |
| 197 | |
| 198 | snprintf(name, 7, "zoran%d", zr->id); |
Denis V. Lunev | c7705f344 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 199 | zr->zoran_proc = proc_create_data(name, 0, NULL, &zoran_operations, zr); |
| 200 | if (zr->zoran_proc != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | dprintk(2, |
| 202 | KERN_INFO |
| 203 | "%s: procfs entry /proc/%s allocated. data=%p\n", |
| 204 | ZR_DEVNAME(zr), name, zr->zoran_proc->data); |
| 205 | } else { |
| 206 | dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n", |
| 207 | ZR_DEVNAME(zr), name); |
| 208 | return 1; |
| 209 | } |
| 210 | #endif |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | void |
| 215 | zoran_proc_cleanup (struct zoran *zr) |
| 216 | { |
| 217 | #ifdef CONFIG_PROC_FS |
| 218 | char name[8]; |
| 219 | |
| 220 | snprintf(name, 7, "zoran%d", zr->id); |
| 221 | if (zr->zoran_proc) |
| 222 | remove_proc_entry(name, NULL); |
| 223 | zr->zoran_proc = NULL; |
| 224 | #endif |
| 225 | } |