Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2012 Russell King
0004  *  Rewritten from the dovefb driver, and Armada510 manuals.
0005  */
0006 
0007 #include <linux/ctype.h>
0008 #include <linux/module.h>
0009 #include <linux/seq_file.h>
0010 #include <linux/uaccess.h>
0011 
0012 #include <drm/drm_debugfs.h>
0013 #include <drm/drm_file.h>
0014 
0015 #include "armada_crtc.h"
0016 #include "armada_drm.h"
0017 
0018 static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data)
0019 {
0020     struct drm_info_node *node = m->private;
0021     struct drm_device *dev = node->minor->dev;
0022     struct armada_private *priv = drm_to_armada_dev(dev);
0023     struct drm_printer p = drm_seq_file_printer(m);
0024 
0025     mutex_lock(&priv->linear_lock);
0026     drm_mm_print(&priv->linear, &p);
0027     mutex_unlock(&priv->linear_lock);
0028 
0029     return 0;
0030 }
0031 
0032 static int armada_debugfs_crtc_reg_show(struct seq_file *m, void *data)
0033 {
0034     struct armada_crtc *dcrtc = m->private;
0035     int i;
0036 
0037     for (i = 0x84; i <= 0x1c4; i += 4) {
0038         u32 v = readl_relaxed(dcrtc->base + i);
0039         seq_printf(m, "0x%04x: 0x%08x\n", i, v);
0040     }
0041 
0042     return 0;
0043 }
0044 
0045 static int armada_debugfs_crtc_reg_open(struct inode *inode, struct file *file)
0046 {
0047     return single_open(file, armada_debugfs_crtc_reg_show,
0048                inode->i_private);
0049 }
0050 
0051 static int armada_debugfs_crtc_reg_write(struct file *file,
0052     const char __user *ptr, size_t len, loff_t *off)
0053 {
0054     struct armada_crtc *dcrtc;
0055     unsigned long reg, mask, val;
0056     char buf[32];
0057     int ret;
0058     u32 v;
0059 
0060     if (*off != 0)
0061         return 0;
0062 
0063     if (len > sizeof(buf) - 1)
0064         len = sizeof(buf) - 1;
0065 
0066     ret = strncpy_from_user(buf, ptr, len);
0067     if (ret < 0)
0068         return ret;
0069     buf[len] = '\0';
0070 
0071     if (sscanf(buf, "%lx %lx %lx", &reg, &mask, &val) != 3)
0072         return -EINVAL;
0073     if (reg < 0x84 || reg > 0x1c4 || reg & 3)
0074         return -ERANGE;
0075 
0076     dcrtc = ((struct seq_file *)file->private_data)->private;
0077     v = readl(dcrtc->base + reg);
0078     v &= ~mask;
0079     v |= val & mask;
0080     writel(v, dcrtc->base + reg);
0081 
0082     return len;
0083 }
0084 
0085 static const struct file_operations armada_debugfs_crtc_reg_fops = {
0086     .owner = THIS_MODULE,
0087     .open = armada_debugfs_crtc_reg_open,
0088     .read = seq_read,
0089     .write = armada_debugfs_crtc_reg_write,
0090     .llseek = seq_lseek,
0091     .release = single_release,
0092 };
0093 
0094 void armada_drm_crtc_debugfs_init(struct armada_crtc *dcrtc)
0095 {
0096     debugfs_create_file("armada-regs", 0600, dcrtc->crtc.debugfs_entry,
0097                 dcrtc, &armada_debugfs_crtc_reg_fops);
0098 }
0099 
0100 static struct drm_info_list armada_debugfs_list[] = {
0101     { "gem_linear", armada_debugfs_gem_linear_show, 0 },
0102 };
0103 #define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)
0104 
0105 int armada_drm_debugfs_init(struct drm_minor *minor)
0106 {
0107     drm_debugfs_create_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
0108                  minor->debugfs_root, minor);
0109 
0110     return 0;
0111 }