Android LEDs simple code Summary

Source: Internet
Author: User

Linux LEDs

 

[Source code: linux-3.2-rc7]

I was asked a question about led two days ago. Here is a summary.

 

This is a relatively simple module for all of us, and of course it is also a good entry point for learning.

For more information about the analysis driver, see makefile & kconfig.

# Led core

OBJ-$ (config_new_leds) + = led-core.o

OBJ-$ (config_leds_class) + = led-class.o

OBJ-$ (config_leds_triggers) + = led-triggers.o

 

# Led platform drivers

OBJ-$ (config_leds_88pm860x) + = leds-88pm860x.o

OBJ-$ (config_leds_atmel_pwm) + = leds-atmel-pwm.o

OBJ-$ (config_leds_s3c24xx) + = leds-s3c24xx.o

............

# Led SPI drivers

OBJ-$ (config_leds_dac124s085) + = leds-dac124s085.o

 

# Led triggers

OBJ-$ (config_leds_trigger_heartbeat) + = ledtrig-heartbeat.o

OBJ-$ (config_leds_trigger_backlight) + = ledtrig-backlight.o

.........

 

Let's take a look at kconfig's definition of these macros.

First look at new_leds

Bool "led support"

Help

Say y to enable Linux led support. This allows control of supported

LEDs from both userspace and optionally, bykernel events (triggers ).

 

This is not related to standard keyboard ledswhich are controlled

Via the input system.

Configleds_class

Bool "led class support"

Help

This option enables the LED sysfs class in/sys/class/LEDs. You'll

Need this to do anything useful withleds. If unsure, say n.

Configleds_triggers

Bool "led trigger support"

Dependson leds_class

Help

This option enables trigger support for theleds class.

These triggers allow kernel events to drivethe LEDs and can

Be configured via sysfs. If unsure, say y.

After reading the above explanation, everyone has a basic understanding. Here we will use the 2410 example to explain it.

Definition in makefile

OBJ-$ (config_leds_s3c24xx) + = leds-s3c24xx.o

Definition in kconfig

Config leds_s3c24xx

Tristate "led support for Samsung s3c24xx gpio LEDs"

Dependson leds_class

Dependson arch_s3c2410

Help

This option enables support for ledsconnected to gpio lines

On Samsung s3c24xx series CPUs, such as thes3c2410 and S3C2440.

In kconfig, we noticed that using the leds-s3c24xx.c requires opening leds_class and relies on arch S3C2410.

 

 

The following code is analyzed:

Code path linux-3.2-rc7/Drivers/LEDs/leds-s3c24xx.c

 

Static inline struct s3c24xx_gpio_led * pdev_to_gpio (struct platform_device * Dev)

 

Static inline struct s3c24xx_gpio_led * to_gpio (struct led_classdev * led_cdev)

 

Static void s3c24xx_led_set (structled_classdev * led_cdev,

Enum led_brightness value)

 

Static int s3c24xx_led_remove (structplatform_device * Dev)

 

Static int s3c24xx_led_probe (structplatform_device * Dev)

{

Structs3c24xx_led_platdata * pdata = Dev-> Dev. platform_data;

Structs3c24xx_gpio_led * led;

Intret;

 

Led = kzarloc (sizeof (struct s3c24xx_gpio_led), gfp_kernel );

If (LED = NULL ){

Dev_err (& Dev-> Dev, "no memory for device \ n ");

Return-enomem;

}

 

Platform_set_drvdata (Dev, LED );

 

LED-> cdev. brightness_set = s3c24xx_led_set;

LED-> cdev. default_trigger = pdata-> def_trigger;

LED-> cdev. Name = pdata-> name;

LED-> cdev. Flags | = led_core_suspendresume;

 

LED-> pdata = pdata;

 

/* No point in having a pull-up if we are always driving */

 

If (pdata-> flags & s3c24xx_ledf_tristate ){

S3c2410_gpio_setpin (pdata-> gpio, 0 );

S3c2410_gpio_cfgpin (pdata-> gpio, s3c2410_gpio_input );

} Else {

S3c2410_gpio_pullup (pdata-> gpio, 0 );

S3c2410_gpio_setpin (pdata-> gpio, 0 );

S3c2410_gpio_cfgpin (pdata-> gpio, s3c2410_gpio_output );

}

 

/* Register our new LED Device */

 

Ret = led_classdev_register (& Dev-> Dev, & LED-> cdev );

If (Ret <0 ){

Dev_err (& Dev-> Dev, "led_classdev_register failed \ n ");

Kfree (LED );

Returnret;

}

 

Return0;

}

 

Static struct platform_drivers3c24xx_led_driver = {

. Probe = s3c24xx_led_probe,

. Remove = s3c24xx_led_remove,

. Driver = {

. Name = "s3c24xx_led ",

. Owner = this_module,

},

};

 

Static int _ init s3c24xx_led_init (void)

{

Returnplatform_driver_register (& s3c24xx_led_driver );

}

 

Static void _ exit s3c24xx_led_exit (void)

{

Platform_driver_unregister (& s3c24xx_led_driver );

}

 

Here we can see that the entire driver is a simple device registration process, but here the registration method such as led_classdev_register appears during led registration.

The simple description of leds-class.txt is as follows:

In its simplest form, the LED class justallows control of LEDs from

Userspace. LEDs appear in/sys/class/LEDs /.

 

The basic framework of Android is as follows:

The above distribution can be seen on Android phones.

R, G, and B LEDs, button-backlight, keyboard-backlight, LCD-backlight, and torch-flash. The spotlight here depends on your peripherals.

Have fun!

Related Article

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.