2019-06-04 10:11:33 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2012-08-15 13:59:49 +01:00
/*
* Copyright ( C ) 2012 Russell King
* Rewritten from the dovefb driver , and Armada510 manuals .
*/
2019-08-04 11:41:31 +02:00
2012-08-15 13:59:49 +01:00
# include <linux/ctype.h>
# include <linux/module.h>
# include <linux/seq_file.h>
2019-08-04 11:41:31 +02:00
# include <linux/uaccess.h>
# include <drm/drm_debugfs.h>
# include <drm/drm_file.h>
2012-08-15 13:59:49 +01:00
# include "armada_crtc.h"
# include "armada_drm.h"
static int armada_debugfs_gem_linear_show ( struct seq_file * m , void * data )
{
struct drm_info_node * node = m - > private ;
struct drm_device * dev = node - > minor - > dev ;
2020-09-04 16:39:19 +02:00
struct armada_private * priv = drm_to_armada_dev ( dev ) ;
2016-12-29 12:09:24 +01:00
struct drm_printer p = drm_seq_file_printer ( m ) ;
2012-08-15 13:59:49 +01:00
2015-11-24 10:00:36 +01:00
mutex_lock ( & priv - > linear_lock ) ;
2016-12-30 14:55:10 +00:00
drm_mm_print ( & priv - > linear , & p ) ;
2015-11-24 10:00:36 +01:00
mutex_unlock ( & priv - > linear_lock ) ;
2012-08-15 13:59:49 +01:00
2016-12-29 12:09:24 +01:00
return 0 ;
2012-08-15 13:59:49 +01:00
}
2018-07-07 16:53:39 +01:00
static int armada_debugfs_crtc_reg_show ( struct seq_file * m , void * data )
2012-08-15 13:59:49 +01:00
{
2018-07-07 16:53:39 +01:00
struct armada_crtc * dcrtc = m - > private ;
int i ;
for ( i = 0x84 ; i < = 0x1c4 ; i + = 4 ) {
u32 v = readl_relaxed ( dcrtc - > base + i ) ;
seq_printf ( m , " 0x%04x: 0x%08x \n " , i , v ) ;
2012-08-15 13:59:49 +01:00
}
return 0 ;
}
2018-07-07 16:53:39 +01:00
static int armada_debugfs_crtc_reg_open ( struct inode * inode , struct file * file )
2012-08-15 13:59:49 +01:00
{
2018-07-07 16:53:39 +01:00
return single_open ( file , armada_debugfs_crtc_reg_show ,
inode - > i_private ) ;
2012-08-15 13:59:49 +01:00
}
2018-07-07 16:53:39 +01:00
static int armada_debugfs_crtc_reg_write ( struct file * file ,
const char __user * ptr , size_t len , loff_t * off )
2012-08-15 13:59:49 +01:00
{
2018-07-07 16:53:39 +01:00
struct armada_crtc * dcrtc ;
unsigned long reg , mask , val ;
char buf [ 32 ] ;
2012-08-15 13:59:49 +01:00
int ret ;
2018-07-07 16:53:39 +01:00
u32 v ;
2012-08-15 13:59:49 +01:00
if ( * off ! = 0 )
return 0 ;
if ( len > sizeof ( buf ) - 1 )
len = sizeof ( buf ) - 1 ;
ret = strncpy_from_user ( buf , ptr , len ) ;
if ( ret < 0 )
return ret ;
buf [ len ] = ' \0 ' ;
2018-07-07 16:53:39 +01:00
if ( sscanf ( buf , " %lx %lx %lx " , & reg , & mask , & val ) ! = 3 )
2012-08-15 13:59:49 +01:00
return - EINVAL ;
2018-07-07 16:53:39 +01:00
if ( reg < 0x84 | | reg > 0x1c4 | | reg & 3 )
return - ERANGE ;
2012-08-15 13:59:49 +01:00
2018-07-07 16:53:39 +01:00
dcrtc = ( ( struct seq_file * ) file - > private_data ) - > private ;
v = readl ( dcrtc - > base + reg ) ;
v & = ~ mask ;
v | = val & mask ;
writel ( v , dcrtc - > base + reg ) ;
2012-08-15 13:59:49 +01:00
return len ;
}
2018-07-07 16:53:39 +01:00
static const struct file_operations armada_debugfs_crtc_reg_fops = {
2012-08-15 13:59:49 +01:00
. owner = THIS_MODULE ,
2018-07-07 16:53:39 +01:00
. open = armada_debugfs_crtc_reg_open ,
. read = seq_read ,
. write = armada_debugfs_crtc_reg_write ,
. llseek = seq_lseek ,
. release = single_release ,
2012-08-15 13:59:49 +01:00
} ;
2018-07-07 16:53:39 +01:00
void armada_drm_crtc_debugfs_init ( struct armada_crtc * dcrtc )
{
debugfs_create_file ( " armada-regs " , 0600 , dcrtc - > crtc . debugfs_entry ,
dcrtc , & armada_debugfs_crtc_reg_fops ) ;
}
2012-08-15 13:59:49 +01:00
static struct drm_info_list armada_debugfs_list [ ] = {
{ " gem_linear " , armada_debugfs_gem_linear_show , 0 } ,
} ;
# define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)
int armada_drm_debugfs_init ( struct drm_minor * minor )
{
2018-07-07 16:53:39 +01:00
drm_debugfs_create_files ( armada_debugfs_list , ARMADA_DEBUGFS_ENTRIES ,
minor - > debugfs_root , minor ) ;
2012-08-15 13:59:49 +01:00
2017-01-26 23:56:07 +01:00
return 0 ;
2012-08-15 13:59:49 +01:00
}