tvin_debug.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * TVIN attribute debug
  3. *
  4. * Author: Bobby Yang <bo.yang@amlogic.com>
  5. *
  6. * Copyright (C) 2010 Amlogic Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. /* Standard Linux Headers */
  13. #include <linux/string.h>
  14. #include <linux/kernel.h>
  15. /* Amlogic Headers */
  16. #include <mach/am_regs.h>
  17. /* Local Headers */
  18. #include "tvin_debug.h"
  19. static void tvin_dbg_usage(void)
  20. {
  21. pr_info("Usage: rc address or wc address value\n");
  22. pr_info("Notes: address in hexadecimal and prefix 0x\n");
  23. return;
  24. }
  25. /*
  26. * rc 0x12345678
  27. * rw 0x12345678 1234
  28. * adress must be hexadecimal and prefix with ox.
  29. */
  30. ssize_t vdin_dbg_store(struct device *dev,
  31. struct device_attribute *attr, const char *buf, size_t count)
  32. {
  33. char strcmd[16];
  34. char straddr[10];
  35. char strval[32];
  36. int i = 0;
  37. int j = 0;
  38. unsigned long addr;
  39. unsigned int value=0;
  40. unsigned int retval;
  41. /* get parameter command string */
  42. j = 0;
  43. while( (i < count) && (buf[i]) && (buf[i] != ',') && (buf[i] != ' ') && (buf[i] != 10)){
  44. strcmd[j] = buf[i];
  45. i++;
  46. j++;
  47. }
  48. strcmd[j] = '\0';
  49. /* ignore */
  50. while( (i < count) && (buf[i]) && ((buf[i] ==',') || (buf[i] == ' ') || (buf[i] == 10))){
  51. i++;
  52. }
  53. /* check address */
  54. if (strncmp(&buf[i], "0x", 2) != 0){
  55. pr_info("invalid parameter address\n");
  56. tvin_dbg_usage();
  57. return 32;
  58. }
  59. /* get parameter address string */
  60. j = 0;
  61. while( (i < count) && (buf[i]) && (buf[i] != ',') && (buf[i] != ' ' && (buf[i] != 10))){
  62. straddr[j] = buf[i];
  63. i++;
  64. j++;
  65. }
  66. straddr[j] = 0;
  67. addr = simple_strtoul(straddr, NULL, 16); //hex data
  68. /* rc read cbus */
  69. if (strncmp(strcmd, "rc", 2) == 0){
  70. retval = READ_CBUS_REG(addr);
  71. pr_info("%s: 0x%x --> 0x%x\n", strcmd, addr, retval);
  72. return 32;
  73. }
  74. /* rp read apb */
  75. else if (strncmp(strcmd, "rp", 2) == 0){
  76. retval = READ_APB_REG(addr);
  77. pr_info("%s: 0x%x --> 0x%x\n", strcmd, addr, retval);
  78. return 32;
  79. }
  80. /* wc write cbus */
  81. else if (strncmp(strcmd, "wc", 2) == 0){
  82. /* get parameter value string*/
  83. /* ignore */
  84. while( (i < count) && (buf[i]) && ((buf[i] ==',') || (buf[i] == ' ') || (buf[i] == 10))){
  85. i++;
  86. }
  87. if (!buf[i]){
  88. pr_info("no parameter value\n");
  89. tvin_dbg_usage();
  90. return 32;
  91. }
  92. j = 0;
  93. while( (i < count) && (buf[i]) && (buf[i] != ',') && (buf[i] != ' ')&& (buf[i] != 10)){
  94. strval[j] = buf[i];
  95. i++;
  96. j++;
  97. }
  98. strval[j] = '\0';
  99. value = simple_strtol(strval, NULL, 16); //hex data
  100. WRITE_CBUS_REG(addr, value);
  101. pr_info("%s: 0x%x <-- 0x%x\n", strcmd, addr, value);
  102. return 32;
  103. }
  104. /* wp write apb */
  105. else if (strncmp(strcmd, "wp", 2) == 0){
  106. /* get parameter value string*/
  107. /* ignore */
  108. while( (i < count) && (buf[i]) && ((buf[i] ==',') || (buf[i] == ' ') || (buf[i] == 10))){
  109. i++;
  110. }
  111. if (!buf[i]){
  112. pr_info("no parameter value\n");
  113. tvin_dbg_usage();
  114. return 32;
  115. }
  116. j = 0;
  117. while( (i < count) && (buf[i]) && (buf[i] != ',') && (buf[i] != ' ')&& (buf[i] != 10)){
  118. strval[j] = buf[i];
  119. i++;
  120. j++;
  121. }
  122. strval[j] = '\0';
  123. value = simple_strtol(strval, NULL, 16); //hex data
  124. WRITE_APB_REG(addr, value);
  125. pr_info("%s: 0x%x <-- 0x%x\n", strcmd, addr, value);
  126. return 32;
  127. }
  128. else{
  129. pr_info("invalid parameter\n");
  130. tvin_dbg_usage();
  131. return 32;
  132. }
  133. return 32;
  134. }