armada_debugfs.c 2.6 KB

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