The problem summary of the LCD 10-minute auto-shutdown under Linux

Source: Internet
Author: User

LCD driver under Linux will automatically turn off the screen after 10 minutes, we can modify the code so that it does not automatically turn off the screen

There is a drivers/char/vt.c file in which there is a variable (blankinterval) that can be set to modify the auto-off time, or it can be returned directly at the beginning of the function (blank_screen_t) , so that the screen will never be turned off.


When the LCD is displayed, it is found that the LCD is no longer working for 10 minutes. Indeed, the value of a parameter Blankinterval under Linux is 10*60*hz.

It determines that the LCD is only displayed for 10 minutes, and then the LCD controller is switched off.

Please refer to http://blog.csdn.net/dongliqiang2006/article/details/4262950 for specific details.

However, the last program given in this article is not available, there is a mistake, in the write that line should be, the original is/0.

#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
int main (int argc, char *argv[])
{
int F0;
F0 = open ("/dev/tty0", O_RDWR);
Write (F0, "\033[9;0]", 8);
Close (F0);
return 0;
}

1. The program is stored as DISPLAY_TIME.C2 cross-compiled arm-linux-gcc-o display_time display_time.c3.display_time copied to the root directory under 4 run./display_ Time if you want to boot automatically, after copying to the root directory, in the/etc/init.d/rcs add a sentence/display_time. See the next blog post for Linux drivers and applications start-up.


After Linux boots, the LCD will automatically turn off (black screen, display slowly disappear, etc.) as long as the keyboard is fixed for a period of time (the keyboard with IO extension on the Development Board), it can be restored by pressing the keyboard.   It took me a whole day to get this problem. In fact, if it is a handheld device, so there is nothing. But the product of our company is to show things all the time, must solve this problem. I have seen a lot of forums, many people have encountered this problem, but I was a search, the keyword is wrong, always find the right answer. If you encounter the same problem, and do not want to see my three-legged cat analysis, then on Baidu search "Blankinterval", "Setterm-blank 0" and so on, you can find a simple solution.   This problem is easy to think about screen saver and power management. Indeed, this is a power management. However, you cannot solve this problem from the power management of the Linux kernel option. We step by step.   First, I measured that the PCLK clock on the LCD disappeared, which means the kernel switched the LCD controller off. So, start with the LCD driver. I use s3c2440, this is the 2410 upgrade version, but the LCD controller is the same, in the Development Board I got the manufacturer gave me a good driver of the kernel, the driving position in the/DRIVERS/VIDEO/S3C2410FB.C. Why is there a fb behind it? This is framebuffer abbreviation, under Baidu you can find a lot of explanation about it. Framebuffer is the device interface for hardware operation of all Linux GUI programs, located in/dev, typically fb0. A function similar to S3c2410_disable_controller () can be found in s3c2410fb.c, and my driver is called Pxafb_disable_controller (), which shows that the driver is changed from the PXA processor. Of course, the manufacturers are not the same name also called different. There is a __raw_writel like this (Fbi->reg.lcdcon1 & ~s3c2410_lcdcon1_envid, S3c2410_lcdcon1), and the LCD will not be turned off by deleting the phrase. This is the first level and I have seen someone do it. However, there is a problem, after pressing the keyboard to restore something that was originally displayed on the screen if you do not redraw will disappear, even if you re-draw, you will see some parts of the screen first black, and then restored. Of course, if you can accept it, then that's it.   Then, it's natural to think of who called this function to get rid of the problem from the source. But that's not the case. I searched for this function name and found aA set_ctrlr_state () function called pxafb_disable_controller (), searched for Set_ctrlr_state (), found a pxafb_task () called Set_ctrlr_state (), But to Pxafb_task () there is no way to go up again, because this is a task provided to the kernel to pass the function entry with the pointer. I understand the kernel is not enough, spent a lot of time to read a lot of articles on the forum, I found/drivers/char/vt.c this file. Vt.c I feel it should be the combination of the 2.4 kernel console.c and vt.c, which should be integrated with the console basically all function functions, the IOCTL in the VT_IOCTL.C this file. The primary role of this file is to manage the console, such as the console's pattern (graphics, characters), output to the console, and so on. which can find some functions such as Do_blank_screen (), blank_screen_t (), that is, these functions turn off the LCD controller, modify any one can work. One solution on the web is to turn blank_screen_t () into an empty function, but I have not tried this, and I feel that I have come to the root of the problem and should be able to solve it fundamentally.   Let's look at the real cause of the screen shutdown problem, see this console initialization function static int __init con_init (void)
{
const char *DISPLAY_DESC = NULL;
struct Vc_data *VC;
unsigned int currcons = 0; Acquire_console_sem (); if (CONSWITCHP)
Display_desc = Conswitchp->con_startup ();
if (!DISPLAY_DESC) {
Fg_console = 0;
Release_console_sem ();
return 0;
}Init_timer (&console_timer);
Console_timer.function = blank_screen_t;
if (blankinterval) {
Blank_state = blank_normal_wait;
Mod_timer (&console_timer, jiffies + blankinterval);
}//This is the initialization of the console timer, and the Timer event function is connected to the blank_screen_t ()/*
* Kmalloc is not running yet-we use the Bootmem allocator.
*/
for (currcons = 0; currcons < min_nr_consoles; currcons++) {
VC_CONS[CURRCONS].D = VC = alloc_bootmem (sizeof (struct vc_data));
Visual_init (VC, currcons, 1);
Vc->vc_screenbuf = (unsigned short *) Alloc_bootmem (vc->vc_screenbuf_size);
vc->vc_kmalloced = 0;
Vc_init (VC, Vc->vc_rows, Vc->vc_cols,
currcons | | !vc->vc_sw->con_save_screen);
}
currcons = Fg_console = 0;
MASTER_DISPLAY_FG = VC = VC_CONS[CURRCONS].D;
Set_origin (VC);
Save_screen (VC);
Gotoxy (VC, vc->vc_x, vc->vc_y);
Csi_j (VC, 0);
Update_screen (VC);
PRINTK ("Console:%s%s%dx%d",
Vc->vc_can_do_color? "Colour": "Mono",
Display_desc, Vc->vc_cols, vc->vc_rows);
printable = 1;
PRINTK ("/n"); Release_console_sem (); #ifdef Config_vt_console
Register_console (&vt_console_driver);
#endif
return 0;
}
Which refers to a global variable called Blankinterval and a console_time, I do not know how the kernel timer is exactly how to work, but this code is already very obvious. This timer and power management macro Pm_config have no relationship, it is part of the console. Look again at the blank_screen_t (): static void blank_screen_t (unsigned long dummy)
{
blank_timer_expired = 1;
Schedule_work (&console_work);
You can find the macro beginning with vt.c, static declare_work (Console_work, Console_callback, NULL), and found the Console_callback () function: static void Console_callback (void *ignored)
{
Acquire_console_sem (); if (want_console >= 0) {
if (want_console! = Fg_console &&
Vc_cons_allocated (Want_console)) {
Hide_cursor (VC_CONS[FG_CONSOLE].D);
Change_console (VC_CONS[WANT_CONSOLE].D);
/* We only changed when the console had already
been allocated-a new console is not created
In an interrupt routine */
}
Want_console =-1;
}
if (do_poke_blanked_console) {/* Don't unblank for a LED change */
Do_poke_blanked_console = 0;
Poke_blanked_console ();
}
if (Scrollback_delta) {
struct Vc_data *VC = vc_cons[fg_console].d;
Clear_selection ();
if (Vc->vc_mode = = Kd_text)
Vc->vc_sw->con_scrolldelta (VC, Scrollback_delta);
Scrollback_delta = 0;
}
if (blank_timer_expired) {
Do_blank_screen (0);
blank_timer_expired = 0;
}Release_console_sem ();
Then look at Do_blank_screen (), as the struct vc_data with the FoPs similar pointer tracking down, you can find the driver inside the corresponding code. It's too much trouble to write, let me slack off. Small summary, in fact, there is a timer inside the console, it is responsible for a certain time after the display is closed, regardless of whether the power management function is turned on. So what does this have to do with framebuffer? I explained from a very retarded point of view that the kernel had just started out with this output: Console:colour dummy device 80x30 after initializing the LCD controller (Framebuffer), there is an output: console:switching To colour frame buffer device 80x30 I understand: At this time, the kernel to the console (also do not know whether the console or TTY) to switch to the framebuffer, prawns quickly jump out to criticize me, hehe. Back to the point, from the code can be found that the fundamental solution is to let Blankinterval = 0,blank_state will not be blank_off outside the value, will not turn off the screen. But the problem here is still not completely solved, if the user program wants to change Blankinterval to implement Screensavers (of course, not on my system); In addition, some programs change the Blankinterval, after the program exits, the screen will be closed after a period of time. How to solve this problem in the user program, which took me a lot of time. In the process of tracing the code, I took a detour, I think the mode of modifying the console can not let the black screen phenomenon, but later found that this may make the console no way to draw, do not know right. Ignore detours, direct positive solution. Isn't there a lot of functions in the vt.c that operate the console? See who changed the Blankinterval. So search blankinterval, found Setterm_command () modified it, and then search Setterm_command, found the Do_con_trol () function, search Do_con_trol, found Do_con_write () function, search Do_con_write, finally finally boss appeared: Con_write () function. Why is it the ultimate boss? Look at this paragraph: static struct tty_operations con_ops = {
. open = Con_open,
. Close = Con_close,
. write = Con_write,
. Write_room = Con_write_room,
. Put_char = Con_put_char,
. Flush_chars = Con_flush_chars,
. Chars_in_buffer = Con_chars_in_buffer,
. IOCTL = Vt_ioctl,
. Stop = Con_stop,
. Start = Con_start,
. Throttle = Con_throttle,
. Unthrottle = Con_unthrottle,
}; If you are familiar with FoPs, you can see that this is the table for the TTY device's file manipulation function. In other words, in the user program, the Open function opens/dev/tty, and then the write function can be modified blankinterval. The principle is found, in practice there is great difficulty, then multiple function calls, and then see Do_con_trol () inside the switch statement, normal people are dizzy. Fortunately, the great Baidu provides us with a lot of information: under the command line, you can use the Setterm-blank 0 instruction to set the Blankinterval. Haha, the Savior came, quickly look at the source code of Setterm. Setterm belongs to Util-linux package, search is easy to find. In the Perform_sequence () function, there is a paragraph:/*-blank [0-60]. */
if (Opt_blank && vcterm)
printf ("/033[9;%d]", opt_bl_min); Really amazing ah, with a printf can be in the user program to solve the problem, originally I was going to just say with printf to solve, see the principle I think will be more comfortable, moreover, in my system with printf is not possible. But! The problem is not complete, often in our system, the LCD Virtual Console and console TTY is not the same device, that is, if the simple printf in the program is not possible! This only modifies the blankinterval of the TTY you are using, and you are using a text-only device that does not have a black screen problem. So, you need to carefully compare/dev/console,/dev/tty,/dev/ttyn device number, in my system, the user program/dev/console and/dev/tty are 5, indicating they are a thing,/dev/ttyn is 4, This is the Virtual Console on FB. But/dev/ttyn is not a TTY in use, so how about printf? Had to use the write function to solve. Write a code like this: #include <fcntl.h> #include <stdio.h> #include <sys/ioctl.h> void some_function () {int f; f = Open ("/dev/tty0", O_RDWR); Write (F, "/033[9;0]", 8); Close (f);} The problem has finally been solved. In conclusion, the second problem has many solutions: 1. Modify the LCD driver to turn off the function of the LCD controller to null (not recommended) 2. Modify the blank_screen_t () function in vt.c, Leave it blank (recommended when the system does not need to use the Turn off display feature) 3. Modify the Blankinterval in the vt.c to 0 (the system may need to use the Turn off display function, and you want the system not to turn off the display when the power is up) 4. Modify the user program and add the code that sets the Blankinterval ( Recommended

The problem summary of the LCD 10-minute auto-shutdown under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.