smi_debug.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include <linux/uaccess.h>
  2. #include <linux/module.h>
  3. #include <linux/fs.h>
  4. #include <linux/platform_device.h>
  5. #include <linux/cdev.h>
  6. #include <linux/interrupt.h>
  7. #include <asm/io.h>
  8. #include <linux/sched.h>
  9. #include <linux/wait.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/delay.h>
  12. #include <linux/mm.h>
  13. #include <linux/vmalloc.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/slab.h>
  16. #include <aee.h>
  17. #include <linux/timer.h>
  18. /* #include <asm/system.h> */
  19. #include <asm-generic/irq_regs.h>
  20. /* #include <asm/mach/map.h> */
  21. #include <sync_write.h>
  22. /*#include <mach/irqs.h>*/
  23. #include <asm/cacheflush.h>
  24. #include <linux/string.h>
  25. #include <linux/time.h>
  26. #include <linux/fb.h>
  27. #include <linux/debugfs.h>
  28. #include <m4u.h>
  29. #include <mt_smi.h>
  30. #include "smi_common.h"
  31. #include "smi_reg.h"
  32. #define SMI_LOG_TAG "smi"
  33. static char debug_buffer[4096];
  34. static void process_dbg_opt(const char *opt)
  35. {
  36. unsigned long addr = 0;
  37. int ret = 0;
  38. if (0 == strncmp(opt, "set_reg:", 8)) {
  39. unsigned long val = 0;
  40. char *p = (char *)opt + 8;
  41. ret = kstrtoul(p, 16, &addr);
  42. p++;
  43. ret = kstrtoul(p, 16, &val);
  44. SMIMSG("set register: 0x%lx = 0x%x\n", addr, (unsigned int)val);
  45. COM_WriteReg32(addr, val);
  46. }
  47. if (0 == strncmp(opt, "get_reg:", 8)) {
  48. char *p = (char *)opt + 8;
  49. ret = kstrtoul(p, 16, &addr);
  50. SMIMSG("get register: 0x%lx = 0x%x\n", addr, COM_ReadReg32(addr));
  51. }
  52. }
  53. static void process_dbg_cmd(char *cmd)
  54. {
  55. char *tok;
  56. while ((tok = strsep(&cmd, " ")) != NULL)
  57. process_dbg_opt(tok);
  58. }
  59. /* --------------------------------------------------------------------------- */
  60. /* Debug FileSystem Routines */
  61. /* --------------------------------------------------------------------------- */
  62. struct dentry *smi_dbgfs = NULL;
  63. static int debug_open(struct inode *inode, struct file *file)
  64. {
  65. file->private_data = inode->i_private;
  66. return 0;
  67. }
  68. static ssize_t debug_read(struct file *file, char __user *ubuf, size_t count, loff_t *ppos)
  69. {
  70. int n = 0;
  71. return simple_read_from_buffer(ubuf, count, ppos, debug_buffer, n);
  72. }
  73. static ssize_t debug_write(struct file *file, const char __user *ubuf, size_t count, loff_t *ppos)
  74. {
  75. const int debug_bufmax = sizeof(debug_buffer) - 1;
  76. size_t ret;
  77. ret = count;
  78. if (count > debug_bufmax)
  79. count = debug_bufmax;
  80. if (copy_from_user(&debug_buffer, ubuf, count))
  81. return -EFAULT;
  82. debug_buffer[count] = 0;
  83. process_dbg_cmd(debug_buffer);
  84. return ret;
  85. }
  86. static const struct file_operations debug_fops = {
  87. .read = debug_read,
  88. .write = debug_write,
  89. .open = debug_open,
  90. };
  91. void SMI_DBG_Init(void)
  92. {
  93. smi_dbgfs = debugfs_create_file("smi", S_IFREG | S_IRUGO, NULL, (void *)0, &debug_fops);
  94. }
  95. void SMI_DBG_Deinit(void)
  96. {
  97. debugfs_remove(smi_dbgfs);
  98. }