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