zoran_procfs.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #include <linux/config.h>
  2. #include <linux/ctype.h>
  3. struct procfs_params_zr36067 {
  4. char *name;
  5. short reg;
  6. u32 mask;
  7. short bit;
  8. };
  9. static struct procfs_params_zr36067 zr67[] = {
  10. {"HSPol", 0x000, 1, 30},
  11. {"HStart", 0x000, 0x3ff, 10},
  12. {"HEnd", 0x000, 0x3ff, 0},
  13. {"VSPol", 0x004, 1, 30},
  14. {"VStart", 0x004, 0x3ff, 10},
  15. {"VEnd", 0x004, 0x3ff, 0},
  16. {"ExtFl", 0x008, 1, 26},
  17. {"TopField", 0x008, 1, 25},
  18. {"VCLKPol", 0x008, 1, 24},
  19. {"DupFld", 0x008, 1, 20},
  20. {"LittleEndian", 0x008, 1, 0},
  21. {"HsyncStart", 0x10c, 0xffff, 16},
  22. {"LineTot", 0x10c, 0xffff, 0},
  23. {"NAX", 0x110, 0xffff, 16},
  24. {"PAX", 0x110, 0xffff, 0},
  25. {"NAY", 0x114, 0xffff, 16},
  26. {"PAY", 0x114, 0xffff, 0},
  27. /*    {"",,,}, */
  28. {NULL, 0, 0, 0},
  29. };
  30. static void setparam(struct zoran *zr, char *name, char *sval)
  31. {
  32. int i, reg0, reg, val;
  33. i = 0;
  34. while (zr67[i].name != NULL) {
  35. if (!strncmp(name, zr67[i].name, strlen(zr67[i].name))) {
  36. reg = reg0 = btread(zr67[i].reg);
  37. reg &= ~(zr67[i].mask << zr67[i].bit);
  38. if (!isdigit(sval[0]))
  39. break;
  40. val = simple_strtoul(sval, NULL, 0);
  41. if ((val & ~zr67[i].mask))
  42. break;
  43. reg |= (val & zr67[i].mask) << zr67[i].bit;
  44. printk(KERN_INFO "%s: setparam: setting ZR36067 register 0x%03x: 0x%08x=>0x%08x %s=%dn",
  45.        zr->name, zr67[i].reg, reg0, reg, zr67[i].name, val);
  46. btwrite(reg, zr67[i].reg);
  47. break;
  48. }
  49. i++;
  50. }
  51. }
  52. /* This macro was stolen from /usr/src/drivers/char/nvram.c and modified */
  53. #define PRINT_PROC(args...)
  54. do {
  55. if (begin + len > offset + size) {
  56. *eof = 0;                               
  57.                         break;         
  58. }                                               
  59.                 len += sprintf( buffer+len, ##args );         
  60. if (begin + len < offset) {
  61. begin += len;
  62. len = 0;
  63. }
  64. } while(0)
  65. static int zoran_read_proc(char *buffer, char **start, off_t offset, int size, int *eof, void *data)
  66. {
  67. #ifdef CONFIG_PROC_FS
  68. int len = 0;
  69. off_t begin = 0;
  70. int i;
  71. struct zoran *zr;
  72. zr = (struct zoran *) data;
  73. DEBUG2(printk(KERN_INFO "%s: read_proc: buffer=%x, offset=%d, size=%d, data=%xn", zr->name, (int) buffer, (int) offset, size, (int) data));
  74. *eof = 1;
  75. PRINT_PROC("ZR36067 registers:");
  76. for (i = 0; i < 0x130; i += 4) {
  77. if (!(i % 16)) {
  78. PRINT_PROC("n%03X", i);
  79. }
  80. PRINT_PROC(" %08X ", btread(i));
  81. }
  82. PRINT_PROC("n");
  83. if (offset >= len + begin) {
  84. return 0;
  85. }
  86. *start = buffer + begin - offset;
  87. return ((size < begin + len - offset) ? size : begin + len - offset);
  88. #endif
  89. return 0;
  90. }
  91. static int zoran_write_proc(struct file *file, const char *buffer, unsigned long count, void *data)
  92. {
  93. #ifdef CONFIG_PROC_FS
  94. char *string, *sp;
  95. char *line, *ldelim, *varname, *svar, *tdelim;
  96. struct zoran *zr;
  97. zr = (struct zoran *) data;
  98. if(count > 32768) /* Stupidity filter */
  99. count = 32768;
  100. string = sp = vmalloc(count + 1);
  101. if (!string) {
  102. printk(KERN_ERR "%s: write_proc: can not allocate memoryn", zr->name);
  103. return -ENOMEM;
  104. }
  105. memcpy(string, buffer, count);
  106. string[count] = 0;
  107. DEBUG2(printk(KERN_INFO "%s: write_proc: name=%s count=%lu data=%xn", zr->name, file->f_dentry->d_name.name, count, (int) data));
  108. ldelim = " tn";
  109. tdelim = "=";
  110. line = strpbrk(sp, ldelim);
  111. while (line) {
  112. *line = 0;
  113. svar = strpbrk(sp, tdelim);
  114. if (svar) {
  115. *svar = 0;
  116. varname = sp;
  117. svar++;
  118. setparam(zr, varname, svar);
  119. }
  120. sp = line + 1;
  121. line = strpbrk(sp, ldelim);
  122. }
  123. vfree(string);
  124. #endif
  125. return count;
  126. }
  127. static int zoran_proc_init(int i)
  128. {
  129. #ifdef CONFIG_PROC_FS
  130. char name[8];
  131. sprintf(name, "zoran%d", i);
  132. if ((zoran[i].zoran_proc = create_proc_entry(name, 0, 0))) {
  133. zoran[i].zoran_proc->read_proc = zoran_read_proc;
  134. zoran[i].zoran_proc->write_proc = zoran_write_proc;
  135. zoran[i].zoran_proc->data = &zoran[i];
  136. printk(KERN_INFO "%s: procfs entry /proc/%s allocated. data=%xn", zoran[i].name, name, (int) zoran[i].zoran_proc->data);
  137. } else {
  138. printk(KERN_ERR "%s: Unable to initialise /proc/%sn", zoran[i].name, name);
  139. return 1;
  140. }
  141. #endif
  142. return 0;
  143. }
  144. static void zoran_proc_cleanup(int i)
  145. {
  146. #ifdef CONFIG_PROC_FS
  147. char name[8];
  148. sprintf(name, "zoran%d", i);
  149. if (zoran[i].zoran_proc) {
  150. remove_proc_entry(name, 0);
  151. }
  152. zoran[i].zoran_proc = NULL;
  153. #endif
  154. }