armada_debugfs.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 <drm/drm_print.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 = drm_to_armada_dev(dev);
  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_crtc_reg_show(struct seq_file *m, void *data)
  28. {
  29. struct armada_crtc *dcrtc = m->private;
  30. int i;
  31. for (i = 0x84; i <= 0x1c4; i += 4) {
  32. u32 v = readl_relaxed(dcrtc->base + i);
  33. seq_printf(m, "0x%04x: 0x%08x\n", i, v);
  34. }
  35. return 0;
  36. }
  37. static int armada_debugfs_crtc_reg_open(struct inode *inode, struct file *file)
  38. {
  39. return single_open(file, armada_debugfs_crtc_reg_show,
  40. inode->i_private);
  41. }
  42. static int armada_debugfs_crtc_reg_write(struct file *file,
  43. const char __user *ptr, size_t len, loff_t *off)
  44. {
  45. struct armada_crtc *dcrtc;
  46. unsigned long reg, mask, val;
  47. char buf[32];
  48. int ret;
  49. u32 v;
  50. if (*off != 0)
  51. return 0;
  52. if (len > sizeof(buf) - 1)
  53. len = sizeof(buf) - 1;
  54. ret = strncpy_from_user(buf, ptr, len);
  55. if (ret < 0)
  56. return ret;
  57. buf[len] = '\0';
  58. if (sscanf(buf, "%lx %lx %lx", &reg, &mask, &val) != 3)
  59. return -EINVAL;
  60. if (reg < 0x84 || reg > 0x1c4 || reg & 3)
  61. return -ERANGE;
  62. dcrtc = ((struct seq_file *)file->private_data)->private;
  63. v = readl(dcrtc->base + reg);
  64. v &= ~mask;
  65. v |= val & mask;
  66. writel(v, dcrtc->base + reg);
  67. return len;
  68. }
  69. static const struct file_operations armada_debugfs_crtc_reg_fops = {
  70. .owner = THIS_MODULE,
  71. .open = armada_debugfs_crtc_reg_open,
  72. .read = seq_read,
  73. .write = armada_debugfs_crtc_reg_write,
  74. .llseek = seq_lseek,
  75. .release = single_release,
  76. };
  77. void armada_drm_crtc_debugfs_init(struct armada_crtc *dcrtc)
  78. {
  79. debugfs_create_file("armada-regs", 0600, dcrtc->crtc.debugfs_entry,
  80. dcrtc, &armada_debugfs_crtc_reg_fops);
  81. }
  82. static struct drm_info_list armada_debugfs_list[] = {
  83. { "gem_linear", armada_debugfs_gem_linear_show, 0 },
  84. };
  85. #define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)
  86. int armada_drm_debugfs_init(struct drm_minor *minor)
  87. {
  88. drm_debugfs_create_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
  89. minor->debugfs_root, minor);
  90. return 0;
  91. }