linux驱动开发:背光设备

上一篇的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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值