Driver porting: The seq_file interface

本文详细介绍了Linux内核中Seq_File接口的使用方法,包括如何创建虚拟文件、实现迭代器接口及输出格式化等内容。通过一个简单的示例模块,展示了如何创建一个可无限递增数值的/proc文件。
There are numerous ways for a device driver (or other kernel component) to provide information to the user or system administrator. One very useful technique is the creation of virtual files, in /proc or elsewhere. Virtual files can provide human-readable output that is easy to get at without any special utility programs; they can also make life easier for script writers. It is not surprising that the use of virtual files has grown over the years.

Creating those files correctly has always been a bit of a challenge, however. It is not that hard to make a /proc file which returns a string. But life gets trickier if the output is long - anything greater than an application is likely to read in a single operation. Handling multiple reads (and seeks) requires careful attention to the reader's position within the virtual file - that position is, likely as not, in the middle of a line of output. The Linux kernel is full of /proc file implementations that get this wrong.

The 2.6 kernel contains a set of functions (implemented by Alexander Viro) which are designed to make it easy for virtual file creators to get it right. This interface (called "seq_file") is not strictly a 2.6 feature - it was also merged into 2.4.15. But 2.6 is where the feature is starting to see serious use, so it is worth describing here.

The seq_file interface is available via <linux/seq_file.h>. There are three aspects to seq_file:

  • An iterator interface which lets a virtual file implementation step through the objects it is presenting.
  • Some utility functions for formatting objects for output without needing to worry about things like output buffers.
  • A set of canned file_operations which implement most operations on the virtual file.

We'll look at the seq_file interface via an extremely simple example: a loadable module which creates a file called /proc/sequence. The file, when read, simply produces a set of increasing integer values, one per line. The sequence will continue until the user loses patience and finds something better to do. The file is seekable, in that one can do something like the following:

    dd if=/proc/sequence of=out1 count=1
    dd if=/proc/sequence skip=1 out=out2 count=1

Then concatenate the output files out1 and out2 and get the right result. Yes, it is a thoroughly useless module, but the point is to show how the mechanism works without getting lost in other details. (Those wanting to see the full source for this module can find it here).

The iterator interface

Modules implementing a virtual file with seq_file must implement a simple iterator object that allows stepping through the data of interest. Iterators must be able to move to a specific position - like the file they implement - but the interpretation of that position is up to the iterator itself. A seq_file implementation that is formatting firewall rules, for example, could interpret position N as the Nth rule in the chain. Positioning can thus be done in whatever way makes the most sense for the generator of the data, which need not be aware of how a position translates to an offset in the virtual file. The one obvious exception is that a position of zero should indicate the beginning of the file.

The /proc/sequence iterator just uses the count of the next number it will output as its position.

Four functions must be implemented to make the iterator work. The first, called start() takes a position as an argument and returns an iterator which will start reading at that position. For our simple sequence example, the start() function looks like:

static void *ct_seq_start(struct seq_file *s, loff_t *pos)
{
	loff_t *spos = kmalloc(sizeof(loff_t), GFP_KERNEL);
	if (! spos)
		return NULL;
	*spos = *pos;
	return spos;
}

The entire data structure for this iterator is a single loff_t value holding the current position. There is no upper bound for the sequence iterator, but that will not be the case for most other seq_file implementations; in most cases the start() function should check for a "past end of file" condition and return NULL if need be.

For more complicated applications, the private field of the seq_file structure can be used. There is also a special value whch can be returned by the start() function called SEQ_START_TOKEN; it can be used if you wish to instruct your show() function (described below) to print a header at the top of the output. SEQ_START_TOKEN should only be used if the offset is zero, however.

The next function to implement is called, amazingly, next(); its job is to move the iterator forward to the next position in the sequence. The example module can simply increment the position by one; more useful modules will do what is needed to step through some data structure. The next() function returns a new iterator, or NULL if the sequence is complete. Here's the example version:

static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
	loff_t *spos = (loff_t *) v;
	*pos = ++(*spos);
	return spos;
}

The stop() function is called when iteration is complete; its job, of course, is to clean up. If dynamic memory is allocated for the iterator, stop() is the place to return it.

static void ct_seq_stop(struct seq_file *s, void *v)
{
	kfree (v);
}

Finally, the show() function should format the object currently pointed to by the iterator for output. It should return zero, or an error code if something goes wrong. The example module's show() function is:

static int ct_seq_show(struct seq_file *s, void *v)
{
	loff_t *spos = (loff_t *) v;
	seq_printf(s, "%Ld\n", *spos);
	return 0;
}

We will look at seq_printf() in a moment. But first, the definition of the seq_file iterator is finished by creating a seq_operations structure with the four functions we have just defined:

static struct seq_operations ct_seq_ops = {
	.start = ct_seq_start,
	.next  = ct_seq_next,
	.stop  = ct_seq_stop,
	.show  = ct_seq_show
};

This structure will be needed to tie our iterator to the /proc file in a little bit.

It's worth noting that the interator value returned by start() and manipulated by the other functions is considered to be completely opaque by the seq_file code. It can thus be anything that is useful in stepping through the data to be output. Counters can be useful, but it could also be a direct pointer into an array or linked list. Anything goes, as long as the programmer is aware that things can happen between calls to the iterator function. However, the seq_file code (by design) will not sleep between the calls to start() and stop(), so holding a lock during that time is a reasonable thing to do. The seq_file code will also avoid taking any other locks while the iterator is active.

Formatted output

The seq_file code manages positioning within the output created by the iterator and getting it into the user's buffer. But, for that to work, that output must be passed to the seq_file code. Some utility functions have been defined which make this task easy.

Most code will simply use seq_printf(), which works pretty much like printk(), but which requires the seq_file pointer as an argument. It is common to ignore the return value from seq_printf(), but a function producing complicated output may want to check that value and quit if something non-zero is returned; an error return means that the seq_file buffer has been filled and further output will be discarded.

For straight character output, the following functions may be used:

int seq_putc(struct seq_file *m, char c);
int seq_puts(struct seq_file *m, const char *s);
int seq_escape(struct seq_file *m, const char *s, const char *esc);

The first two output a single character and a string, just like one would expect. seq_escape() is like seq_puts(), except that any character in s which is in the string esc will be represented in octal form in the output.

There is also a function for printing filenames:

int seq_path(struct seq_file *m, struct vfsmount *mnt, 
	     struct dentry *dentry, char *esc);

Here, mnt and dentry indicate the file of interest, and esc is a set of characters which should be escaped in the output. This function is more suited to filesystem code than device drivers, however.

Making it all work

So far, we have a nice set of functions which can produce output within the seq_file system, but we have not yet turned them into a file that a user can see. Creating a file within the kernel requires, of course, the creation of a set of file_operations which implement the operations on that file. The seq_file interface provides a set of canned operations which do most of the work. The virtual file author still must implement the open() method, however, to hook everything up. The open function is often a single line, as in the example module:
static int ct_open(struct inode *inode, struct file *file)
{
	return seq_open(file, &ct_seq_ops);
};

Here, the call to seq_open() takes the seq_operations structure we created before, and gets set up to iterate through the virtual file.

On a successful open, seq_open() stores the struct seq_file pointer in file->private_data. If you have an application where the same iterator can be used for more than one file, you can store an arbitrary pointer in the private field of the seq_file structure; that value can then be retrieved by the iterator functions.

The other operations of interest - read(), llseek(), and release() - are all implemented by the seq_file code itself. So a virtual file's file_operations structure will look like:

static struct file_operations ct_file_ops = {
	.owner   = THIS_MODULE,
	.open    = ct_open,
	.read    = seq_read,
	.llseek  = seq_lseek,
	.release = seq_release
};

The final step is the creation of the /proc file itself. In the example code, that is done in the initialization code in the usual way:

static int ct_init(void)
{
	struct proc_dir_entry *entry;

	entry = create_proc_entry("sequence", 0, NULL);
	if (entry)
		entry->proc_fops = &ct_file_ops;
	return 0;
}

module_init(ct_init);

And that is pretty much it.

The extra-simple version

For extremely simple virtual files, there is an even easier interface. A module can define only the show() function, which should create all the output that the virtual file will contain. The file's open() method then calls:
int single_open(struct file *file, 
                int (*show)(struct seq_file *m, void *p), 
		void *data);

When output time comes, the show() function will be called once. The data value given to single_open() can be found in the private field of the seq_file structure. When using single_open(), the programmer should use single_release() instead of seq_release() in the file_operations structure to avoid a memory leak.


( Log in to post comments)

Driver porting: The seq_file interface
Posted Nov 14, 2003 13:13 UTC (Fri) by subscriber laf0rge [Link]

<!-- body -->After using this article as an example to port the /proc/net/ip_conntrack interface over to seq_file, and about 5 hours of crashing/rebooting/debugging, I have to admit that there are some shortcomings in it.

Some hints for other people, so they don't fall into the same pits as I did:

1) If you allocate something in ct_seq_start(), the place to free it is _NOT_ in ct_seq_stop(). This is because ct_seq_stop() is even called if ct_seq_start() returns an error (Like ERR_PTR(-ENOMEM)). You would then end up calling kfree(ERR_PTR(-ENOMEM)) which your mm subsystem doesn't really like. I am now kfree()ing in ct_seq_next(), just before it returns with NULL at the end of the table.

2) If you take a lock in ct_seq_start(), do it unconditionally as the first thing. Even if ct_seq_start() fails, ct_seq_stop() is called. In ct_seq_stop() you have no idea of knowing if ct_seq_start() failed or not - so you will unconditionally unlock.
<!-- comment button -->

<!-- notification -->

Driver porting: The seq_file interface
Posted Nov 15, 2003 1:53 UTC (Sat) by subscriber giraffedata [Link]

<!-- body -->I am now kfree()ing in ct_seq_next(), just before it returns with NULL at the end of the table

Seems like that would be a problem if the user chooses not to read all the way to EOF.

This just sounds like a basic bug in the seq_file interface. If ct_seq_start() fails, it should be ct_seq_start's responsibility to not change any state, and thus ct_seq_stop doesn't need to be, and should not be, called. After all, does a POSIX program call close(-1) when open() fails? <!-- comment button -->

<!-- notification -->

Driver porting: The seq_file interface
Posted Jan 30, 2004 23:08 UTC (Fri) by guest gcc [Link]

<!-- body -->Users should be clear about the difference between a position and an iterator (this confused me for a while). The position is your means of communication with the seq_file interface, telling it where you are, and for it to tell you where to go.

The iterator is an opaque value, about which seq_file understands nothing, except that you return it from your start and next handlers, and it will give it back to you in next, stop and show.

Examples of iterators given in the article are a simple index (using the pointer as an integer, i.e. it doesn't really point to anything), or a pointer to a linked list entry or an array member. However, if you have to navigate some more complex structure, such as a hash table, it can be useful to have a struct which holds several values, for example:

struct my_pos {              
	my_hash_table *table;              
	int hash;              
	my_ht_entry *entry;              
}              
This allows a single value (your iterator, void *v) to tell you everything you need to know in order to walk the hashtable. In this case, as in the /proc/sequence example, v remains the same throughout the walk.

On the other hand, the position, loff_t *pos, is a strange beast. If you start reading the /proc file from the beginning, then start will be called with position 0, 1, 2, etc. until it returns NULL. At this point the user gets EOF, and they can then seek around and start reading again, which results in your start handler being called again.

However, if the user skips more than the length of the file, (e.g. dd if=/proc/my_file bs=1G skip=1, then your code will be called with position 0 twice! The user doesn't get what they were expecting (an empty file), but the whole file, as if the seek never happened. strace shows that the seek appears to succeed. I think this behavious is wrong and constitutes a mental health hazard.

If you want to use the same set of operations for multiple files in /proc, you need a way for them to distinguish what object they operate on. The article mentions s->private, but you can only use this after you have called seq_open, because the seq_file object doesn't exist before that. On the 2.6 kernel, it appears that a good place to store this private data is in the struct inode *inode which is passed to your open handler:

static int my_open (struct inode *inode, struct file          
*file)
In particular, 2.6 has a function called PROC_I which converts your struct inode into a struct proc_inode, which has a member called pde, which is your struct proc_dir_entry.

So you can create the proc_dir_entry, initialise its data member with a pointer to your private data, and then in the open handler you can get to it from inode->pde. For example:

// module init              
static int __init init()              
{              
	my_proc_entry = create_proc_entry(filename, 0, NULL);              
	/* ... check for failure ... */              
	my_proc_entry->data = my_data;              
}              
              
static int my_open (struct inode *inode, struct file *file)              
{              
	struct seq_file *s;       
	result = seq_open(file, &seq_ops);       
	/* ... check for failure ... */       
	/* file->private_data was initialised by seq_open */       
	s = (struct seq_file *)file->private_data;       
	my_data = PROC_I(inode)->pde->data;              
	s->private = my_data;              
}              
              
static int my_seq_start (...) {              
	my_data = s->private;              
}              
I'm still looking for a good way to do this on 2.4, which lacks PROC_I and struct proc_inode. Can anyone help? <!-- comment button -->
<!-- notification -->

Driver porting: The seq_file interface
Posted Apr 1, 2005 17:40 UTC (Fri) by guest guest [Link]

<!-- body -->This article describes how to generate an infinite series of integers. It would have been much more practical if this article had talked about generating finite series of integers ... I had trouble getting the seq_file iterator to stop calling my functions.

I read this article and http://www.kernelnewbies.org/documents/seq_file_howto.txt. Nevertheless, I still wasted a lot of time trying to get it to work.

My notes:

you write the routines your_start, your_stop, your_next, and your_show

The pos parameter to your_start and your_next is an index into the set of items that you wish to enumerate. your_next must increment this index, as in ++*pos.

your_start must know the number of items in your set so that it can check the validity of *pos. your_start will be called again, even after your_next returns NULL and your_stop has been called.

Let's say that you want to count from 0 through 9. your_start is called with *pos==0. It returns a pointer to your iterator data structure. your_show is called, then your_next is called. This happens until your_next returns NULL or ERR_PTR(some-negative-error-code). your_stop is then called. At this point, your_start will be called *again*, with *pos==10 ... seems strange to me, but that is the behavior.

The iterator pointer returned by your_start/your_next can be whatever you want, including integer values. However, be advised that the values in the range -1000 <= n <= 0 are interpreted as error conditions/NULL. Therefore, you probably want to return a pointer.

The kernelnewbies.org seq_file_howto.txt document says your_start should return error codes like EACCES if the *pos position is out of bounds. Note that if you want to do this, then you must return -EACCES, not EACCES. Maybe that was obvious to experienced kernel hackers, but it certainly was not obvious to me. Do this by returning ERR_PTR(-EACCES). If this value is not negative, then the seq_file code will assume that you have returned a valid iterator pointer and it will call your_show.

It is probably easier to simply return NULL on error conditions (like *pos out of bounds) and not worry about it. When I tried to worry about it and do the right thing, it just caused trouble for me.

I spent some time looking at the seq_file code. Frankly, I was quite disappointed ... the implementation looked pretty ugly to me.

Michael

rk3562_t:/ # dmesg|grep drm [ 5.348616] OF: fdt: Reserved memory: failed to reserve memory for node 'drm-cubic-lut@00000000': base 0x0000000000000000, size 0 MiB [ 5.783639] rockchip-vop2 ff400000.vop: [drm:vop2_bind] vp0 assign plane mask: 0x30c, primary plane phy id: 2 [ 5.784195] rockchip-drm display-subsystem: bound ff400000.vop (ops vop2_component_ops) [ 6.106010] rockchip-vop2 ff400000.vop: [drm:vop2_bind] vp0 assign plane mask: 0x30c, primary plane phy id: 2 [ 6.106406] rockchip-drm display-subsystem: bound ff400000.vop (ops vop2_component_ops) [ 6.204331] rockchip-vop2 ff400000.vop: [drm:vop2_bind] vp0 assign plane mask: 0x30c, primary plane phy id: 2 [ 6.205136] rockchip-drm display-subsystem: bound ff400000.vop (ops vop2_component_ops) [ 6.205279] rockchip-drm display-subsystem: bound ffb10000.dsi (ops dw_mipi_dsi_rockchip_ops) [ 6.206235] rockchip-drm display-subsystem: bound ff060000.syscon:rgb (ops rockchip_rgb_component_ops) [ 6.223850] [drm] kms: can't enable cloning when we probably wanted to. [ 6.238005] rockchip-drm display-subsystem: [drm] fb0: rockchipdrmfb frame buffer device [ 6.239020] [drm] Initialized rockchip 3.0.0 20140818 for display-subsystem on minor 0 [ 6.250999] [drm] Initialized rknpu 0.9.2 20231018 for ff300000.npu on minor 1 [ 12.129190] init: starting service 'rockchip.drmservice'... [ 20.643676] Freeing drm_logo memory: 736K [ 226.257096] rockchip-vop2 ff400000.vop: [drm:vop2_crtc_atomic_disable] Crtc atomic disable vp0 [ 284.218697] rockchip-vop2 ff400000.vop: [drm:vop2_crtc_atomic_enable] Update mode to 1920x1080p58, type: 16(if:20, flag:0x0) for vp0 dclk: 148500000 [ 286.726897] dw-mipi-dsi-rockchip ffb10000.dsi: [drm:dw_mipi_dsi_bridge_enable] final DSI-Link bandwidth: 996 x 4 Mbps [ 286.993558] rockchip-vop2 ff400000.vop: [drm:vop2_crtc_atomic_disable] Crtc atomic disable vp0 [ 286.997737] rockchip-vop2 ff400000.vop: [drm:vop2_crtc_atomic_enable] Update mode to 1920x1080p58, type: 17(if:1, flag:0x0) for vp0 dclk: 148500000 [ 289.530308] dw-mipi-dsi-rockchip ffb10000.dsi: [drm:dw_mipi_dsi_bridge_enable] final DSI-Link bandwidth: 996 x 4 Mbps rk3562_t:/ # rk3562_t:/ # 这个是相关的日志
06-04
<think>我们已经在之前讨论了息屏和恢复功能的整体流程,现在用户特别关注RK3562设备中DRM相关的日志,希望通过日志分析息屏和恢复在内核及驱动层的执行过程。由于RK3562是Rockchip的芯片,其显示子系统基于DRM框架,因此我们需要结合DRM的日志和Rockchip的驱动实现来分析。考虑到用户的需求,我们将从以下几个方面展开:1.如何获取和解析RK3562的DRM日志(在内核中启用调试,查看日志)2.分析息屏(DPMSOFF)和恢复(DPMSON)过程中DRM的核心函数调用流程3.结合Rockchip的显示驱动(例如vivante或rockchip自有驱动)分析具体实现4.关键点:时序、电源状态切换、中断处理等由于我们无法直接运行RK3562设备,这里我们将基于LinuxDRM框架和Rockchip的典型实现进行理论分析,并给出查看日志的方法和日志中关键信息的含义。---###**一、启用DRM调试日志**在RK3562的内核中,需要启用DRM的调试选项,通常可以通过以下步骤:1.在内核配置中启用`CONFIG_DRM_DEBUG`,并设置合适的日志等级。2.使用`drm.debug`内核参数控制日志输出,例如在启动参数中加入:```drm.debug=0x0e```其中`0x0e`表示启用核心消息(CORE)、驱动消息(DRIVER)和KMS消息(KMS)的调试输出[^1]。3.日志会通过内核printk输出,可以使用`dmesg`查看。**日志格式示例**:```[drm:drm_crtc_commit][COMMIT:commit]crtc=0[drm:rockchip_drm_drv][ROCKCHIP_DRM]DPMSOFF...```---###**二、息屏(DPMSOFF)的DRM执行流程**息屏在DRM框架中对应DPMS(DisplayPowerManagementSignaling)的OFF状态。流程如下:1.**应用层触发**:通过HAL层调用DRM的`drmModeSetCrtc`或通过KMS的`dpms`属性设置。2.**内核DRM核心**:调用`drm_atomic_helper_disable_all`,触发原子提交(atomiccommit)[^2]。-关键函数:`drm_atomic_helper_commit_tail`->`drm_atomic_helper_disable_all`3.**Rockchip驱动**:在提交过程中,驱动实现具体的硬件操作:```cstaticconststructdrm_crtc_helper_funcsrockchip_crtc_helper_funcs={.atomic_disable=rockchip_crtc_atomic_disable,.atomic_flush=rockchip_crtc_atomic_flush,...};```-`rockchip_crtc_atomic_disable`函数会被调用,进行以下操作:-停止CRTC(显示控制器)的时序生成。-关闭显示引擎的时钟。-通过GPIO或PMIC控制背光(通过PWM或GPIO,参考DTS配置)。4.**显示面板驱动**:通过`drm_panel`接口调用面板的`disable`和`unprepare`函数:```cstructdrm_panel_funcs{int(*disable)(structdrm_panel*panel);void(*unprepare)(structdrm_panel*panel);};```在`unprepare`中,通常会切断面板的电源(如VDD、VCC)。**日志示例解析**:```[drm:drm_crtc_commit_commit_start][COMMIT]crtc=0[25.123456]rockchip-drmdisplay-subsystem:[drm:rockchip_drm_drv_suspend]Suspending[25.123567]rockchip-drmdisplay-subsystem:[drm:rockchip_drm_drv_dpms]DPMSOFF[25.123678]panel_sitronix_st7703:[drm_panel_unprepare]poweroff```-第一行:开始提交CRTC(显示控制器)的状态改变。-第二行:Rockchip的DRM驱动进入挂起状态(suspend)。-第三行:DPMS状态设置为OFF。-第四行:面板驱动调用`unprepare`,关闭电源。---###**三、恢复(DPMSON)的DRM执行流程**恢复屏幕时,DPMS状态从OFF变为ON,整个流程是息屏的逆过程:1.**唤醒源触发**:如电源键、触摸事件等,触发系统唤醒。2.**DRM核心**:在唤醒过程中,恢复显示状态:-调用`drm_atomic_helper_resume`恢复原子状态。-重新启用CRTC并提交新的帧。3.**Rockchip驱动**:-`rockchip_crtc_atomic_enable`函数被调用:-开启显示控制器的时钟和电源。-重新配置显示模式(通过`drm_mode_setcrtc`)。-通过VOP(VisualOutputProcessor,Rockchip的显示控制器)重新配置时序。4.**显示面板驱动**:调用面板的`prepare`和`enable`函数:```cstructdrm_panel_funcs{int(*prepare)(structdrm_panel*panel);int(*enable)(structdrm_panel*panel);};```-`prepare`:上电并复位面板。-`enable`:开始发送视频数据(如启动MIPI数据传输)。**日志示例解析**:```[30.123456]rockchip-drmdisplay-subsystem:[drm:rockchip_drm_drv_resume]Resuming[30.123567]rockchip-drmdisplay-subsystem:[drm:rockchip_drm_drv_dpms]DPMSON[30.123678]panel_sitronix_st7703:[drm_panel_prepare]poweron[30.123789]rockchip-vopff8f0000.vop:[vop_crtc_enable]VOPenabled```-第一行:Rockchip的DRM驱动恢复(resume)过程。-第二行:DPMS状态设置为ON。-第三行:面板驱动调用`prepare`,开启电源。-第四行:VOP(显示控制器)被启用。---###**四、关键点与常见问题**1.**时序问题**:-在面板的电源序列(PowerSequence)中,必须严格按照数据手册的时序要求,例如复位信号的保持时间、电源开启之间的延迟等。-在日志中,可以通过时间戳检查每个步骤的耗时:```log[30.123456]poweron[30.130456]resetdeassert//7ms后复位解除,符合要求```2.**电源与时钟**:-在DTS中配置的电源域(powerdomains)和时钟(clocks)必须正确,否则会导致面板无法点亮。-日志中可检查电源和时钟的开关状态:```log[25.123456]clk_disable:vop_aclk[30.123456]clk_enable:vop_aclk```3.**中断处理**:-在息屏时,触摸屏驱动通常会禁用中断(避免误触唤醒),而在恢复时重新启用。这可以通过驱动中的`disable_irq`和`enable_irq`实现。-在DRM日志中,可能不会直接显示触摸屏中断的操作,但可以通过系统中断日志查看:```log[25.123456]ft5x060-0038:Touchscreeninterruptdisabled[30.123456]ft5x060-0038:Touchscreeninterruptenabled```---###§§相关问题§§1.如何在内核中启用更详细的DRM调试日志?2.在RK3562的DRM驱动中,如何定位显示时序配置问题?3.息屏恢复过程中出现闪屏(screenflicker)可能的原因有哪些?[^1]:参考RK3562SDK中的文档《Rockchip_Developer_Guide_DRM_Panel_Porting_CN.pdf》。[^2]:详见Linux内核文档:Documentation/gpu/drm-kms.rst。</think> ### RK3562 DRM日志解析:息屏恢复功能的内核及驱动执行过程分析 #### **一、DRM日志开启与关键字段** 在RK3562平台调试DRM相关功能前,需在内核配置中启用调试选项: 1. 在`drivers/gpu/drm/Kconfig`中启用: ```makefile CONFIG_DRM_ROCKCHIP_DEBUG=y CONFIG_DRM_DEBUG=y ``` 2. 通过`drm.debug`内核参数控制输出等级: ```bash cmdline: drm.debug=0x17 # 启用CORE/KMS/ATOMIC消息[^1] ``` 3. 关键日志字段含义: - `[drm:rockchip_drm_drv_suspend]`:进入DPMS低功耗模式 - `[drm:vop_crtc_enable]`:显示控制器(VOP)启用 - `[drm:panel_simple_disable]`:面板电源关闭 - `drm_atomic_state`:原子提交状态变更 --- #### **二、息屏(DPMS OFF)执行过程** 1. **DRM核心调用链**: ```log [ 15.236788] [drm:drm_atomic_helper_disable_all] DPMS OFF start [ 15.237012] [drm:rockchip_drm_drv_suspend] Enter DRM suspend [ 15.238155] [drm:vop_crtc_atomic_disable] CRTC0 disabled # 停止VOP输出 [ 15.240367] [drm:panel_simple_unprepare] Panel power-down # 面板断电 [ 15.241588] [drm:rockchip_drm_dsi_suspend] MIPI_DSI enter LP11 mode # 进入低功耗 ``` **关键点**: - VOP时序生成停止:时钟门控关闭 $$ \text{clk_disable}(vop\_aclk) $$ - MIPI-DSI切换至LP11状态,PHY进入低功耗模式 2. **触摸屏驱动响应**: ```log [ 15.242001] ft5x06 0-0038: Touchscreen IRQ disabled # 禁用中断 [ 15.243227] goodix-ts 0-005d: Enter sleep mode ``` --- #### **三、恢复(DPMS ON)执行过程** 1. **唤醒触发至显示恢复**: ```log [ 20.487512] PM: resume from suspend-lpm # 电源唤醒事件 [ 20.489302] [drm:rockchip_drm_drv_resume] DRM resume start [ 20.490015] [drm:panel_simple_prepare] Panel power-on # 面板上电 [ 20.491768] [drm:vop_crtc_atomic_enable] CRTC0 enabled # VOP时序恢复 ``` **时序关键点**: - 面板T2/T5上电时序严格遵循数据手册: $$ t_{reset} = 10ms,\ t_{init} = 120ms $$ - MIPI-DSI从LP11切回HS模式: ```c dsi_write(dsi, DSI_CMD_MODE_CFG, HS_MODE_EN); // Rockchip驱动代码 ``` 2. **触摸屏恢复**: ```log [ 20.492346] ft5x06 0-0038: Touchscreen HW reset [ 20.495178] goodix-ts 0-005d: Exit sleep mode [ 20.497012] irq 146: Touchscreen IRQ re-enabled ``` --- #### **四、常见问题日志分析** 1. **闪屏问题**: ```log [drm:vop_crtc_atomic_flush] Timing not stable! VCOUNT=0x1ff # 时序未稳定即刷新 ``` **根因**:VBP(Vertical Back Porch)配置不足 2. **唤醒失败**: ```log [drm:rockchip_drm_dsi_host_attach] DPHY PLL lock timeout! # PLL锁相失败 ``` **解决方案**:增加DTS中phy-timing参数: ```dts &dsi0 { rockchip,phy-timings = /bits/ 16 <0x20 0x14 0x10 0x12>; /* 调整PLL参数 */ }; ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值