zoran_procfs.c 5.2 KB

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