Linux-3.6.6 transplantation based on S3C2440 -- LCD Backlight Control

Source: Internet
Author: User

 

On my Development Board, you can use the S3C2440 gpg4 pin to control the LCD backlight. That is, when the LCD is set to 1, the LCD will be switched on and off when the LCD is cleared.

 

In Linux, LCD backlights are defined as led platform devices. In the Mach-zhaocj2440.c file, it is defined:

Static struct s3c24xx_led_platdata zhaocj2440_led_backlight_pdata = {

. Name = "Backlight ",

. Gpio = s3c2410_gpg (4 ),

. Def_trigger = "Backlight ",

};

 

Static struct platform_device zhaocj2440_led_backlight = {

. Name = "s3c24xx_led ",

. ID = 5,

. Dev = {

. Platform_data = & zhaocj2440_led_backlight_pdata,

},

};

 

To add the LCD backlight control function to the system, you only need to add a "B" field (B indicates the backlight) to the zhaocj2440_features_str array. That is:

Static char zhaocj2440_features_str [12] _ initdata = "4 TB ";

 

The system uses the zhaocj2440_parse_features function to add the devices in the zhaocj2440_features_str array to the features structure one by one, and then adds the above devices to the platform bus using the following statement in the zhaocj2440:

If (features. Count)/* the optional features */

Platform_add_devices (features. Optional, features. Count );

 

Because the system regards the LCD backlight as an LED Device, its platform driver is the same as that of the LED platform driver, that is:

Static struct platform_driver s3c24xx_led_driver = {

. Probe = s3c24xx_led_probe,

. Remove = s3c24xx_led_remove,

. Driver = {

. Name = "s3c24xx_led ",

. Owner = this_module,

},

};

 

I have introduced the LED driver in detail in the previous article. I will not go into details here.

 

Note that during system initialization, the pin settings for the control LEDs are low, so the LEDs are not bright after the system starts. Similarly, the gpg4 pin that controls the backlight is also low by default, so the LCD is not bright when the system is started. This setting has nothing to do with LEDs, but it is not suitable for LCD. Therefore, we need to change the default settings for the backlight pin to a high level. To implement the above functions, you only need to add the following statement in the proper position (approximately in the attachment of row 107th) in the s3c24xx_led_probe function in the Leds-s3c24xx.c file (under the drivers/LEDs directory:

If (pdata-> name = "Backlight ")

Gpio_set_value (pdata-> gpio, 1 );

 

Next we will write an application to control the backlight of the LCD:

/****************

* *** Backlight. c ****

*****************/

# Include <stdint. h>

# Include <string. h>

# Include <fcntl. h>

# Include <unistd. h>

# Include <stdio. h>

# Include <Linux/input. h>

# Include <unistd. h>

 

Int main (INT argc, char * argv [])

{

Int FD;

 

FD = open ("/sys/class/LEDs/backlight/brightness", o_rdwr );

If (FD <0)

{

Printf ("can not open file. \ n ");

Return-1;

}

 

If (! Strcmp (argv [1], "on "))

Write (FD, "1", 1 );

Else if (! Strcmp (argv [1], "off "))

Write (FD, "0", 1 );

 

Close (FD );

Return 0;

}

 

Compile the program, download it to the temp directory, and run:

[Root @ zhaocj/temp] #./Backlight on

Enable backlight and LCD display

 

[Root @ zhaocj/temp] #./backlight off

Turn off the backlight and the LCD cannot be displayed

 

 

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.