全志A33驱动开发 之 LED操作
一、整体说明
本次使用的开发板是锐尔威视RERVISION的vstar2。开发板如下图所示。本例使用平台设备的probe函数来注册一个misc设备。从面在/dev/目录下形成Jay_leds的设备文件。通过ioctl函数操作。打开关闭LED灯。
二、注意事项
1、GPIO 在fex文件中的配置说明:
GPIO配置脚本的使用:
Port:端口+组内序号<功能分配><内部电阻状态><驱动能力><输出电平状态>
2、sys_config.fex中的配置:
;----------------------------------------------------------------------------------
;leds config parameters
;leds_used 0:uboot charging, 1:android charging
;----------------------------------------------------------------------------------
[leds_para]
leds_used = 0
red_led = port:PB02<1><0>
3、获取sys_config.fex中的配置:(详细的看驱动文件)
type = script_get_item(“leds_para”, “red_led”, &led_val);
4、内核配置:
因为a33提供的开发包是用脚本编译的,buildroot自带生成编译工具。在linux kernel也没有明确 的指定编译工具跟架构。
这里要设置如下两项配置:(去掉原来的配置)
#ARCH ?= $(SUBARCH)
#CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
ARCH ?= arm
CROSS_COMPILE ?= /home/mydocuments/linux_kernel/a33/dragonboard/out/sun8iw5p1/dragonboard/common/buildroot/external-toolchain/bin/arm-linux-gnueabi-
5、编译测试程序:
/home/mydocument/arm-gcc/arm-2009q3/bin/arm-none-linux-gnueabi-gcc led.c -o leds_test
三、实现led驱动
1、源文件
/**************************************************START OF FILE*****************************************************/
/* ------------------------------------------------------------------------------------------------------------------
包含头文件
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <mach/gpio.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <asm/io.h>
#include <linux/regulator/consumer.h>
#include <linux/delay.h>
#include <mach/hardware.h>
#include <mach/platform.h>
#include <mach/sys_config.h>
#include <linux/gpio.h>
/* ------------------------------------------------------------------------------------------------------------------
宏定义
*/
//配置是否开启打印信息
#define DEBUG 1
#ifdef DEBUG
#define dprintk( argc, argv... ) printk( argc, ##argv )
#else
#define dprintk( argc, argv... )
#endif
//platform device相关函数
static int leds_probe(struct platform_device *pdev);
static int leds_remove (struct platform_device *pdev);
static int leds_suspend (struct platform_device *pdev, pm_message_t state);
static int leds_resume (struct platform_device *pdev);
//misc driver 相关函数
int leds_release(struct inode *inode,struct file *filp);
int leds_open(struct inode *inode,struct file *filp);
long leds_ioctl(struct file *filp,unsigned int cmd,unsigned long arg);
/* ------------------