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