Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Russell King |
| 3 | * 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. |
| 8 | */ |
| 9 | #include <linux/ctype.h> |
| 10 | #include <linux/debugfs.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/seq_file.h> |
| 13 | #include <drm/drmP.h> |
| 14 | #include "armada_crtc.h" |
| 15 | #include "armada_drm.h" |
| 16 | |
| 17 | static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data) |
| 18 | { |
| 19 | struct drm_info_node *node = m->private; |
| 20 | struct drm_device *dev = node->minor->dev; |
| 21 | struct armada_private *priv = dev->dev_private; |
Daniel Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 22 | struct drm_printer p = drm_seq_file_printer(m); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 23 | |
Daniel Vetter | 0b8ebea | 2015-11-24 10:00:36 +0100 | [diff] [blame] | 24 | mutex_lock(&priv->linear_lock); |
Chris Wilson | 433e404 | 2016-12-30 14:55:10 +0000 | [diff] [blame] | 25 | drm_mm_print(&priv->linear, &p); |
Daniel Vetter | 0b8ebea | 2015-11-24 10:00:36 +0100 | [diff] [blame] | 26 | mutex_unlock(&priv->linear_lock); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 27 | |
Daniel Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 28 | return 0; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static int armada_debugfs_reg_show(struct seq_file *m, void *data) |
| 32 | { |
| 33 | struct drm_device *dev = m->private; |
| 34 | struct armada_private *priv = dev->dev_private; |
| 35 | int n, i; |
| 36 | |
| 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 | } |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int armada_debugfs_reg_r_open(struct inode *inode, struct file *file) |
| 54 | { |
| 55 | return single_open(file, armada_debugfs_reg_show, inode->i_private); |
| 56 | } |
| 57 | |
| 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) |
| 68 | { |
| 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; |
| 74 | int ret; |
| 75 | |
| 76 | if (*off != 0) |
| 77 | return 0; |
| 78 | |
| 79 | if (len > sizeof(buf) - 1) |
| 80 | len = sizeof(buf) - 1; |
| 81 | |
| 82 | ret = strncpy_from_user(buf, ptr, len); |
| 83 | if (ret < 0) |
| 84 | return ret; |
| 85 | buf[len] = '\0'; |
| 86 | |
| 87 | reg = simple_strtoul(buf, &p, 16); |
| 88 | if (!isspace(*p)) |
| 89 | return -EINVAL; |
| 90 | val = simple_strtoul(p + 1, NULL, 16); |
| 91 | |
| 92 | if (reg >= 0x84 && reg <= 0x1c4) |
| 93 | writel(val, dcrtc->base + reg); |
| 94 | |
| 95 | return len; |
| 96 | } |
| 97 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 98 | static const struct file_operations fops_reg_w = { |
| 99 | .owner = THIS_MODULE, |
Duan Jiong | a276d6c | 2013-11-01 13:45:05 +0800 | [diff] [blame] | 100 | .open = simple_open, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 101 | .write = armada_debugfs_write, |
| 102 | .llseek = noop_llseek, |
| 103 | }; |
| 104 | |
| 105 | static struct drm_info_list armada_debugfs_list[] = { |
| 106 | { "gem_linear", armada_debugfs_gem_linear_show, 0 }, |
| 107 | }; |
| 108 | #define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list) |
| 109 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 110 | int armada_drm_debugfs_init(struct drm_minor *minor) |
| 111 | { |
Noralf Trønnes | b516a6c | 2017-01-26 23:56:07 +0100 | [diff] [blame] | 112 | struct dentry *de; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 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 | |
Noralf Trønnes | b516a6c | 2017-01-26 23:56:07 +0100 | [diff] [blame] | 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; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 125 | |
Noralf Trønnes | b516a6c | 2017-01-26 23:56:07 +0100 | [diff] [blame] | 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; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 130 | |
Noralf Trønnes | b516a6c | 2017-01-26 23:56:07 +0100 | [diff] [blame] | 131 | return 0; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 132 | } |