forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/armada/armada_debugfs.c
....@@ -1,16 +1,17 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2012 Russell King
34 * 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.
85 */
6
+
97 #include <linux/ctype.h>
10
-#include <linux/debugfs.h>
118 #include <linux/module.h>
129 #include <linux/seq_file.h>
13
-#include <drm/drmP.h>
10
+#include <linux/uaccess.h>
11
+
12
+#include <drm/drm_debugfs.h>
13
+#include <drm/drm_file.h>
14
+
1415 #include "armada_crtc.h"
1516 #include "armada_drm.h"
1617
....@@ -18,7 +19,7 @@
1819 {
1920 struct drm_info_node *node = m->private;
2021 struct drm_device *dev = node->minor->dev;
21
- struct armada_private *priv = dev->dev_private;
22
+ struct armada_private *priv = drm_to_armada_dev(dev);
2223 struct drm_printer p = drm_seq_file_printer(m);
2324
2425 mutex_lock(&priv->linear_lock);
....@@ -28,50 +29,33 @@
2829 return 0;
2930 }
3031
31
-static int armada_debugfs_reg_show(struct seq_file *m, void *data)
32
+static int armada_debugfs_crtc_reg_show(struct seq_file *m, void *data)
3233 {
33
- struct drm_device *dev = m->private;
34
- struct armada_private *priv = dev->dev_private;
35
- int n, i;
34
+ struct armada_crtc *dcrtc = m->private;
35
+ int i;
3636
37
- if (priv) {
38
- for (n = 0; n < ARRAY_SIZE(priv->dcrtc); n++) {
39
- struct armada_crtc *dcrtc = priv->dcrtc[n];
40
- if (!dcrtc)
41
- continue;
42
-
43
- for (i = 0x84; i <= 0x1c4; i += 4) {
44
- uint32_t v = readl_relaxed(dcrtc->base + i);
45
- seq_printf(m, "%u: 0x%04x: 0x%08x\n", n, i, v);
46
- }
47
- }
37
+ for (i = 0x84; i <= 0x1c4; i += 4) {
38
+ u32 v = readl_relaxed(dcrtc->base + i);
39
+ seq_printf(m, "0x%04x: 0x%08x\n", i, v);
4840 }
4941
5042 return 0;
5143 }
5244
53
-static int armada_debugfs_reg_r_open(struct inode *inode, struct file *file)
45
+static int armada_debugfs_crtc_reg_open(struct inode *inode, struct file *file)
5446 {
55
- return single_open(file, armada_debugfs_reg_show, inode->i_private);
47
+ return single_open(file, armada_debugfs_crtc_reg_show,
48
+ inode->i_private);
5649 }
5750
58
-static const struct file_operations fops_reg_r = {
59
- .owner = THIS_MODULE,
60
- .open = armada_debugfs_reg_r_open,
61
- .read = seq_read,
62
- .llseek = seq_lseek,
63
- .release = single_release,
64
-};
65
-
66
-static int armada_debugfs_write(struct file *file, const char __user *ptr,
67
- size_t len, loff_t *off)
51
+static int armada_debugfs_crtc_reg_write(struct file *file,
52
+ const char __user *ptr, size_t len, loff_t *off)
6853 {
69
- struct drm_device *dev = file->private_data;
70
- struct armada_private *priv = dev->dev_private;
71
- struct armada_crtc *dcrtc = priv->dcrtc[0];
72
- char buf[32], *p;
73
- uint32_t reg, val;
54
+ struct armada_crtc *dcrtc;
55
+ unsigned long reg, mask, val;
56
+ char buf[32];
7457 int ret;
58
+ u32 v;
7559
7660 if (*off != 0)
7761 return 0;
....@@ -84,23 +68,34 @@
8468 return ret;
8569 buf[len] = '\0';
8670
87
- reg = simple_strtoul(buf, &p, 16);
88
- if (!isspace(*p))
71
+ if (sscanf(buf, "%lx %lx %lx", &reg, &mask, &val) != 3)
8972 return -EINVAL;
90
- val = simple_strtoul(p + 1, NULL, 16);
73
+ if (reg < 0x84 || reg > 0x1c4 || reg & 3)
74
+ return -ERANGE;
9175
92
- if (reg >= 0x84 && reg <= 0x1c4)
93
- writel(val, dcrtc->base + reg);
76
+ dcrtc = ((struct seq_file *)file->private_data)->private;
77
+ v = readl(dcrtc->base + reg);
78
+ v &= ~mask;
79
+ v |= val & mask;
80
+ writel(v, dcrtc->base + reg);
9481
9582 return len;
9683 }
9784
98
-static const struct file_operations fops_reg_w = {
85
+static const struct file_operations armada_debugfs_crtc_reg_fops = {
9986 .owner = THIS_MODULE,
100
- .open = simple_open,
101
- .write = armada_debugfs_write,
102
- .llseek = noop_llseek,
87
+ .open = armada_debugfs_crtc_reg_open,
88
+ .read = seq_read,
89
+ .write = armada_debugfs_crtc_reg_write,
90
+ .llseek = seq_lseek,
91
+ .release = single_release,
10392 };
93
+
94
+void armada_drm_crtc_debugfs_init(struct armada_crtc *dcrtc)
95
+{
96
+ debugfs_create_file("armada-regs", 0600, dcrtc->crtc.debugfs_entry,
97
+ dcrtc, &armada_debugfs_crtc_reg_fops);
98
+}
10499
105100 static struct drm_info_list armada_debugfs_list[] = {
106101 { "gem_linear", armada_debugfs_gem_linear_show, 0 },
....@@ -109,24 +104,8 @@
109104
110105 int armada_drm_debugfs_init(struct drm_minor *minor)
111106 {
112
- struct dentry *de;
113
- int ret;
114
-
115
- ret = drm_debugfs_create_files(armada_debugfs_list,
116
- ARMADA_DEBUGFS_ENTRIES,
117
- minor->debugfs_root, minor);
118
- if (ret)
119
- return ret;
120
-
121
- de = debugfs_create_file("reg", S_IFREG | S_IRUSR,
122
- minor->debugfs_root, minor->dev, &fops_reg_r);
123
- if (!de)
124
- return -ENOMEM;
125
-
126
- de = debugfs_create_file("reg_wr", S_IFREG | S_IWUSR,
127
- minor->debugfs_root, minor->dev, &fops_reg_w);
128
- if (!de)
129
- return -ENOMEM;
107
+ drm_debugfs_create_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
108
+ minor->debugfs_root, minor);
130109
131110 return 0;
132111 }