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