zoran_procfs.c 5.4 KB

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