Linux-2.6.32 porting LCD backlight control on mini2440 development board

Publisher:psi33Latest update time:2024-06-18 Source: elecfansKeywords:linux  mini2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Editor: LCD backlight control is actually an I/O port driver, which is exactly the same as LED control, or even simpler, because it usually controls several LEDs at the same time. This is a standard entry-level driver. I won't say much about this, just follow the manual. The I/O port here is GPG4.

1 LCD backlight control principle
In the mini2440/micro2440 development board, the LCD backlight is controlled by the LCD_PWR pin of the CPU. As can be seen from the schematic diagram, it corresponds to GPG4. When the LCD_PWR output is a high level "1", the backlight will be turned on; when the output is a low level "0", the backlight will be turned off (Note: here it only turns the backlight on and off, and does not adjust the backlight brightness).

2 Adding backlight driver to the kernel
Now, we need to add a simple backlight driver so that the backlight can be easily turned on and off by software. Our goal is to turn off the backlight by sending an even number such as "0" to the backlight device in the command terminal, and turn on the backlight by sending an odd number such as "1". This makes it much more convenient to use without the need for a dedicated application to control it, as described in the user manual (2.5.10 Controlling LCD backlight):
Tip: LCD backlight device file: /dev/backlight
Enter in the command line: echo 0 > /dev/backlight to turn off the LCD backlight.
Enter in the command line: echo 1 > /dev/backlight to turn on the LCD backlight.
To achieve this, we add a mini2440_backlight.c file in the linux-2.6.32.2/drivers/video directory
with the following content:

;The following header files may not be required for every one of them, but the redundant ones will not affect the content of the driver
#include
#include
#include #include <
linux/slab.h> #include

#include
#include #include <
linux/delay.h> #include <
linux/clk.h> #include
#include <
linux/gpio.h > #include <
asm/io.h> #include

#include
#include
#include
#include
#include
#undef DEBUG
//#define DEBUG
#ifdef DEBUG

#define DPRINTK(x...) {printk(__FUNCTION__"(%d): ",__LINE__);printk(##x);}
#else
#define DPRINTK(x...) (void)(0)
#endif
;Define the name of the backlight driver as backligh, which will appear in /dev/backlight
#define DEVICE_NAME "backlight"
;Define the backlight variable bl_state to record the on/off state of the backlight
static unsigned int bl_state;
;Set the function of the backlight switch, mainly to flip the backlight variable bl_state
static inline void set_bl(int state)
{
bl_state = !!state; //Flip the bl_state variable
s3c2410_gpio_setpin(S3C2410_GPG(4), bl_state); //Write the result to the register GPG4 used by the backlight
}
;Get the backlight state
static inline unsigned int get_bl(void)
{
return bl_state;
}
;Read parameters from the application and pass them to the kernel
static ssize_t dev_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
{
unsigned char ch;
int ret;
if (count == 0) {
return count;
}
;Use copy_from_user function to read parameters from the user layer/application layer
ret = copy_from_user(&ch, buffer, sizeof ch) ? -EFAULT : 0;
if (ret) {
return ret;
}
ch &= 0x01; //Judge whether it is an odd or even number

set_bl(ch); //Set backlight status
return count;
}
;Pass kernel parameters to the read function of user layer/application layer
static ssize_t dev_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
int ret;
unsigned char str[] = {'0', '1' };
if (count == 0) {
return 0;
}
;Use copy_to_user function to pass kernel parameters to user layer/application layer
ret = copy_to_user(buffer, str + get_bl(), sizeof(unsigned char) ) ? -EFAULT : 0;
if (ret) {
return ret;
}
return sizeof(unsigned char);
}
;Device operation set
static struct file_operations dev_fops = {
owner: THIS_MODULE,
read:dev_read,
write: dev_write,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};
;Device initialization, effective when the kernel starts
static int __init dev_init(void)

{
int ret;
ret = misc_register(&misc);
printk (DEVICE_NAME"tinitializedn");
;Initialize the backlight port GPG4 as output
s3c2410_gpio_cfgpin(S3C2410_GPG(4), S3C2410_GPIO_OUTPUT);
;Turn on the backlight when starting the kernel
set_bl(1);
return ret;
}
static void __exit dev_exit(void)
{
misc_deregister(&misc);
}
module_init(dev_init); //Register backlight driver module
module_exit(dev_exit); //Uninstall backlight driver module
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM Inc.");

MODULE_AUTHOR("FriendlyARM Inc.");


Then add the backlight configuration option to the kernel configuration menu, open linux-2.6.32.2/drivers/video/Kconfig, and add it in the following location:

config FB_S3C2410_DEBUG
bool "S3C2410 lcd debug messages"
depends on FB_S3C2410
help
Turn on debugging messages. Note that you can set/unset at run time
through sysfs
#Add the backlight driver configuration of MINI2440 here
config BACKLIGHT_MINI2440
tristate "Backlight support for mini2440 from FriendlyARM"
depends on MACH_MINI2440 && FB_S3C2410
help
backlight driver for MINI2440 from FriendlyARM

config FB_SM501
tristate "Silicon Motion SM501 framebuffer support"
depends on FB && MFD_SM501
select FB_CFB_FILLRECT
select FB_CFB_COPYAREA
select FB_CFB_IMAGEBLIT

Then open linux-2.6.32.2/drivers/video/Makefile and add the driver target file according to the configuration definition, as shown in the figure:
# the test framebuffer is last
obj-$(CONFIG_FB_VIRTUAL) += vfb.o
#video output switch sysfs driver
obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
obj-$(CONFIG_BACKLIGHT_MINI2440) += mini2440_backlight.o

In this way, we have transplanted the mini2440 backlight driver into the kernel. In the kernel source code root directory, execute:
make menuconfig, and select the following submenus in turn:
Device Drivers --->
Graphics support --->
< *> Support for frame buffer devices --->

<*>backlight support for mini2440 from Friendlyarm

Here, press the space bar to select the mini2440 configuration item we just added, then exit and save the kernel configuration menu. Execute in the command line: make zImage
will generate arch/arm/boot/zImage, use supervivi's "k" function to burn it into the development board, and you can see the penguin image as shown in the figure at startup, which means that we have turned on the backlight, but there are still some problems with the LCD driver. In the next section, we will introduce in detail how to port the LCD driver.

The added device file node is shown in the figure:


Keywords:linux  mini2440 Reference address:Linux-2.6.32 porting LCD backlight control on mini2440 development board

Previous article:Linux-2.6.32 transplanted on mini2440 development board - RTC transplanted
Next article:Linux-2.6.32 transplanted on mini2440 development board - W35 LCD driver transplanted

Recommended ReadingLatest update time:2024-11-16 10:33

S3C2440 Linux driver transplantation——LED heartbeat
Development board: TQ2440 Kernel: Linux 2.6.32 PC OS:Ubuntu 11.04     This article will explain the transplantation of LED drivers. The LED in this article is used to realize heartbeat, that is, after the system is started, the LED will flash at a fixed frequency like a human heart. Unless the system freezes, the LE
[Microcontroller]
S3C2440 Linux driver transplantation——LED heartbeat
Porting FFmpeg video recording on mini2440
Recently I wanted to plug a camera into my board and record some videos. After two or three days of work, I was able to use the ffmpeg program to record videos on my board, and then save the files in .avi format to my PC. The process was a bit tortuous, but it was a bit of a hassle. (1) Compile x264. Downlo
[Microcontroller]
Porting FFmpeg video recording on mini2440
Summary of Linux 2.6.32 porting
(I) Modify the machine code Open mach-test2440.c, find the last MACHINE_START macro, For example, the line MACHINE_START(TEST2440, "TEST2440"), The second parameter doesn't matter, the important thing is the first parameter. When gcc compiles this mach-test2440.c, TEST2440 will be matched to "#define MACH_TYPE_T
[Microcontroller]
A brief introduction to the FriendlyArm mini2440
I bought a second-hand mini2440 development board on Taobao a long time ago. I was busy with my graduation project and had no time to play with it. These days, I took it out to study while waiting for the PCB to be printed. The first step is to configure the development environment: The cross compiler I used was a
[Microcontroller]
Analysis of mini2440 key driver
First, let's explain how the buttons are connected to the S3C2440 chip: KEY1 ---- EINT8 ---- GPG0 KEY2 ---- EINT11 ---- GPG3 KEY3 ---- EINT13 ---- GPG5 KEY4 ---- EINT14 ---- GPG6 KEY5 ---- EINT15 ---- GPG7 KEY6 ---- EINT19 ---- GPG11 The driver source code is as follows: (drivers/char/mini2440_buttons.c) #include
[Microcontroller]
Problems encountered by Java in Embedded Linux under Friendly Arm Micro2440
I recently used the FriendlyArm Micro2440 in a project where the system used Embedded Linux. I encountered a problem: the program ran very slowly. At first I thought it was a problem with reading and writing files, so I tried writing the data to Excel, sqlite database, and csv file, but the results were all uns
[Microcontroller]
arm-linux-gcc & A rather low-level error
Today I used Linux + arm-linux tools to port some bare metal programs written on Windows ADS to TQ2440. I got stuck just after I got the first LED working. main.c without any modification #define rGPBCON    (*(volatile unsigned *)0x56000010)    //Port B control #define rGPBDAT    (*(volatile unsigned *)
[Microcontroller]
Linux bootloader full explanation (ARM S3C2410)
Preface: This article is very detailed. The main reference is the successful process. If you want to transplant the bootloader, you should find a ready-made source code, at least that's what I think, although I haven't transplanted it yet.  There are many articles about Linux BOOTLOADER on the Internet, but most of th
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号