上一篇的pwm 驱动,加上第一篇的led灯控制,合起来就是背光设备的驱动!
背光设备定位于仅仅对于lcd的背光进行控制,其中主要控制背光开关脚(GPIO),背光调节脚(PWM)!
由于很类似,在这里就不做赘述
显而易见,pwm的配置和上一篇一样,具体代码如下:
/*
* linux/drivers/char/smart210_pwm.c
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/fb.h>
#include <linux/backlight.h>
#include <linux/err.h>
#include <linux/pwm.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <mach/gpio.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h>
#define DEVICE_NAME "pwm-backlight"
#define PWM_IOCTL_SET_BL_POWER 0
#define PWM_IOCTL_SET_BL_FREQ 1
#define PWM_IOCTL_SET_BL_DUTY 2
#define NS_IN_1HZ (1000000000UL)
#define BACKLIGHT_PWM_ID 1
#define BACKLIGHT_PWM_GPIO S5PV210_GPD0(1)
#define BACKLIGHT_CON_GPIO S5PV210_GPH1(2)
#define _BL_ON 1
#define _BL_OFF 0
struct backlight_data{
unsigned char bl_power;//backlight power pin state
unsigned char bl_duty;//backlight con for brightness
unsigned int bl_freq;//backlight con for freq
};
static struct pwm_device *pwm1backlight;
static struct semaphore lock;
//default setting for backlight ,backlight power on,bl bri is 90,bl freq is 1000hz
static struct backlight_data smart210_bl ={
.bl_power = _BL_ON,
.bl_duty = 90,
.bl_freq = 1000,
};
static void bl_set_power(unsigned char blpower) {
smart210_bl.bl_power = blpower;
if (gpio_request(BACKLIGHT_CON_GPIO, "BacklightPower")) {
printk("request GPIO %d for bl power failed\n", BACKLIGHT_CON_GPIO);
return;
}
gpio_set_value(BACKLIGHT_CON_GPIO, blpower);
s3c_gpio_cfgpin(BACKLIGHT_CON_GPIO, S3C_GPIO_OUTPUT);
gpio_free(BACKLIGHT_CON_GPIO);
}
static