zoran_procfs.c 5.0 KB

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