armada_debugfs.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2012 Russell King
  3. * Rewritten from the dovefb driver, and Armada510 manuals.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/ctype.h>
  10. #include <linux/debugfs.h>
  11. #include <linux/module.h>
  12. #include <linux/seq_file.h>
  13. #include <drm/drmP.h>
  14. #include "armada_crtc.h"
  15. #include "armada_drm.h"
  16. static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data)
  17. {
  18. struct drm_info_node *node = m->private;
  19. struct drm_device *dev = node->minor->dev;
  20. struct armada_private *priv = dev->dev_private;
  21. struct drm_printer p = drm_seq_file_printer(m);
  22. mutex_lock(&priv->linear_lock);
  23. drm_mm_print(&priv->linear, &p);
  24. mutex_unlock(&priv->linear_lock);
  25. return 0;
  26. }
  27. static int armada_debugfs_reg_show(struct seq_file *m, void *data)
  28. {
  29. struct drm_device *dev = m->private;
  30. struct armada_private *priv = dev->dev_private;
  31. int n, i;
  32. if (priv) {
  33. for (n = 0; n < ARRAY_SIZE(priv->dcrtc); n++) {
  34. struct armada_crtc *dcrtc = priv->dcrtc[n];
  35. if (!dcrtc)
  36. continue;
  37. for (i = 0x84; i <= 0x1c4; i += 4) {
  38. uint32_t v = readl_relaxed(dcrtc->base + i);
  39. seq_printf(m, "%u: 0x%04x: 0x%08x\n", n, i, v);
  40. }
  41. }
  42. }
  43. return 0;
  44. }
  45. static int armada_debugfs_reg_r_open(struct inode *inode, struct file *file)
  46. {
  47. return single_open(file, armada_debugfs_reg_show, inode->i_private);
  48. }
  49. static const struct file_operations fops_reg_r = {
  50. .owner = THIS_MODULE,
  51. .open = armada_debugfs_reg_r_open,
  52. .read = seq_read,
  53. .llseek = seq_lseek,
  54. .release = single_release,
  55. };
  56. static int armada_debugfs_write(struct file *file, const char __user *ptr,
  57. size_t len, loff_t *off)
  58. {
  59. struct drm_device *dev = file->private_data;
  60. struct armada_private *priv = dev->dev_private;
  61. struct armada_crtc *dcrtc = priv->dcrtc[0];
  62. char buf[32], *p;
  63. uint32_t reg, val;
  64. int ret;
  65. if (*off != 0)
  66. return 0;
  67. if (len > sizeof(buf) - 1)
  68. len = sizeof(buf) - 1;
  69. ret = strncpy_from_user(buf, ptr, len);
  70. if (ret < 0)
  71. return ret;
  72. buf[len] = '\0';
  73. reg = simple_strtoul(buf, &p, 16);
  74. if (!isspace(*p))
  75. return -EINVAL;
  76. val = simple_strtoul(p + 1, NULL, 16);
  77. if (reg >= 0x84 && reg <= 0x1c4)
  78. writel(val, dcrtc->base + reg);
  79. return len;
  80. }
  81. static const struct file_operations fops_reg_w = {
  82. .owner = THIS_MODULE,
  83. .open = simple_open,
  84. .write = armada_debugfs_write,
  85. .llseek = noop_llseek,
  86. };
  87. static struct drm_info_list armada_debugfs_list[] = {
  88. { "gem_linear", armada_debugfs_gem_linear_show, 0 },
  89. };
  90. #define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)
  91. int armada_drm_debugfs_init(struct drm_minor *minor)
  92. {
  93. struct dentry *de;
  94. int ret;
  95. ret = drm_debugfs_create_files(armada_debugfs_list,
  96. ARMADA_DEBUGFS_ENTRIES,
  97. minor->debugfs_root, minor);
  98. if (ret)
  99. return ret;
  100. de = debugfs_create_file("reg", S_IFREG | S_IRUSR,
  101. minor->debugfs_root, minor->dev, &fops_reg_r);
  102. if (!de)
  103. return -ENOMEM;
  104. de = debugfs_create_file("reg_wr", S_IFREG | S_IWUSR,
  105. minor->debugfs_root, minor->dev, &fops_reg_w);
  106. if (!de)
  107. return -ENOMEM;
  108. return 0;
  109. }