armada_debugfs.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012 Russell King
  4. * Rewritten from the dovefb driver, and Armada510 manuals.
  5. */
  6. #include <linux/ctype.h>
  7. #include <linux/debugfs.h>
  8. #include <linux/module.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/uaccess.h>
  11. #include <drm/drm_debugfs.h>
  12. #include <drm/drm_file.h>
  13. #include "armada_crtc.h"
  14. #include "armada_drm.h"
  15. static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data)
  16. {
  17. struct drm_info_node *node = m->private;
  18. struct drm_device *dev = node->minor->dev;
  19. struct armada_private *priv = drm_to_armada_dev(dev);
  20. struct drm_printer p = drm_seq_file_printer(m);
  21. mutex_lock(&priv->linear_lock);
  22. drm_mm_print(&priv->linear, &p);
  23. mutex_unlock(&priv->linear_lock);
  24. return 0;
  25. }
  26. static int armada_debugfs_crtc_reg_show(struct seq_file *m, void *data)
  27. {
  28. struct armada_crtc *dcrtc = m->private;
  29. int i;
  30. for (i = 0x84; i <= 0x1c4; i += 4) {
  31. u32 v = readl_relaxed(dcrtc->base + i);
  32. seq_printf(m, "0x%04x: 0x%08x\n", i, v);
  33. }
  34. return 0;
  35. }
  36. static int armada_debugfs_crtc_reg_open(struct inode *inode, struct file *file)
  37. {
  38. return single_open(file, armada_debugfs_crtc_reg_show,
  39. inode->i_private);
  40. }
  41. static int armada_debugfs_crtc_reg_write(struct file *file,
  42. const char __user *ptr, size_t len, loff_t *off)
  43. {
  44. struct armada_crtc *dcrtc;
  45. unsigned long reg, mask, val;
  46. char buf[32];
  47. int ret;
  48. u32 v;
  49. if (*off != 0)
  50. return 0;
  51. if (len > sizeof(buf) - 1)
  52. len = sizeof(buf) - 1;
  53. ret = strncpy_from_user(buf, ptr, len);
  54. if (ret < 0)
  55. return ret;
  56. buf[len] = '\0';
  57. if (sscanf(buf, "%lx %lx %lx", &reg, &mask, &val) != 3)
  58. return -EINVAL;
  59. if (reg < 0x84 || reg > 0x1c4 || reg & 3)
  60. return -ERANGE;
  61. dcrtc = ((struct seq_file *)file->private_data)->private;
  62. v = readl(dcrtc->base + reg);
  63. v &= ~mask;
  64. v |= val & mask;
  65. writel(v, dcrtc->base + reg);
  66. return len;
  67. }
  68. static const struct file_operations armada_debugfs_crtc_reg_fops = {
  69. .owner = THIS_MODULE,
  70. .open = armada_debugfs_crtc_reg_open,
  71. .read = seq_read,
  72. .write = armada_debugfs_crtc_reg_write,
  73. .llseek = seq_lseek,
  74. .release = single_release,
  75. };
  76. void armada_drm_crtc_debugfs_init(struct armada_crtc *dcrtc)
  77. {
  78. debugfs_create_file("armada-regs", 0600, dcrtc->crtc.debugfs_entry,
  79. dcrtc, &armada_debugfs_crtc_reg_fops);
  80. }
  81. static struct drm_info_list armada_debugfs_list[] = {
  82. { "gem_linear", armada_debugfs_gem_linear_show, 0 },
  83. };
  84. #define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)
  85. int armada_drm_debugfs_init(struct drm_minor *minor)
  86. {
  87. drm_debugfs_create_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
  88. minor->debugfs_root, minor);
  89. return 0;
  90. }