1.MTK中添加一个驱动。
代码位置:mediatek/platform/mt6573/kernel/driver/要添加的目录/
2.进入目录添加:slide.c 和 Makefile
其中Makefile的内容如下:obj-$(CONFIG_MTK_SLIDE) := slide.o
3.再进入目录:mediatek/config/viroyal73_wg/autoconfig/Kconfig/
在project里添加一行:
CONFIG_MTK_SLIDE=y
4.进入目录mediatek/platform/mt6573/kernel/config/
在Drivers里面添加:
config MTK_SLIDE
bool "mediatek slide driver"
default y
即已经完整的将驱动添加到工程。
其中slide.c的详细代码如下:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/input.h>
#include <linux/workqueue.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <linux/earlysuspend.h>
#include <asm/atomic.h>
#include <asm/uaccess.h>
#include <asm/tcm.h>
#include <mach/mt6573_reg_base.h>
#include <mt6573_kpd.h>
#include <mach/irqs.h>
#include <mach/mt6573_eint.h>
#include <linux/delay.h>
#include <mach/mt6573_gpio.h>
#include <linux/list.h>
#include <linux/string.h>
#include <linux/leds-mt65xx.h>
#define SLID_NAME "slid_switch"
#define PIN_PUPD0 (0xF7000000+0x26094)
static struct input_dev *slide_input_dev;
static u8 slide_state = !KPD_SLIDE_POLARITY;
static void slide_eint_handler(unsigned long data);
static DECLARE_TASKLET(slide_tasklet, slide_eint_handler, 0);
void slide_eint_handler(unsigned long data)
{
bool slid;
u8 old_state = slide_state;
u32 temp;
mt65xx_eint_mask(KPD_SLIDE_EINT);
slide_state = !slide_state;
slid = (slide_state == !KPD_SLIDE_POLARITY);
input_report_switch(slide_input_dev, SW_LID, !slid);
printk("[slide] slide = %s \n", slid ? "opened" : "closed");
#if defined(CUSTOM_KERNEL_DUALSCREEN)
if(slid)
{
printk("========= open slid ==========\n");
mt_set_gpio_mode(GPIO106, GPIO_MODE_00);
mt_set_gpio_dir(GPIO106, GPIO_DIR_OUT);
mt_set_gpio_out(GPIO106, GPIO_OUT_ONE);
mt65xx_leds_brightness_set(6, 160);
}
else
{
printk("========= close slid ==========\n");
mt_set_gpio_mode(GPIO106, GPIO_MODE_00);
mt_set_gpio_dir(GPIO106, GPIO_DIR_OUT);
mt_set_gpio_out(GPIO106, GPIO_OUT_ZERO);
mt65xx_leds_brightness_set(6, 160);
}
#endif
if(old_state==0)
{
temp = *(volatile u32 *)PIN_PUPD0;
temp |= (0x1<<20);
temp &=~(0x1<<28);
*(volatile u32 *)PIN_PUPD0 = (u32)temp;
}
else
{
temp = *(volatile u32 *)PIN_PUPD0;
temp &=~(0x1<<20);
temp |=(0x1<<28);
*(volatile u32 *)PIN_PUPD0 = (u32)temp;
}
/* for detecting the return to old_state */
mt65xx_eint_set_polarity(KPD_SLIDE_EINT, old_state);
mdelay(10); //modify by zhangmin 2012.8.7 mdelay(60);
mt65xx_eint_unmask(KPD_SLIDE_EINT);
}
static void switch_slide_eint_handler(void)
{
tasklet_schedule(&slide_tasklet);
}
static int slid_pdrv_probe(struct platform_device *pdev)
{
slide_input_dev = input_allocate_device();
if (!slide_input_dev)
return -ENOMEM;
int tmp;
tmp = *(volatile u32 *)PIN_PUPD0;
tmp &= ~(0x1 << 20);
tmp |= (0x1 << 28);
*(volatile u32 *)PIN_PUPD0;
mt65xx_eint_set_sens(KPD_SLIDE_EINT, KPD_SLIDE_SENSITIVE);
mt65xx_eint_set_hw_debounce(KPD_SLIDE_EINT, 5);
mt65xx_eint_registration(KPD_SLIDE_EINT, true, KPD_SLIDE_POLARITY,
switch_slide_eint_handler, false);
__set_bit(EV_SW, slide_input_dev->evbit);
__set_bit(SW_LID, slide_input_dev->swbit);
__set_bit(SW_LID, slide_input_dev->sw);
return 0;
}
static int slid_pdrv_remove(struct platform_device *pdev)
{
return 0;
}
static struct platform_device slid_pdev = {
.name = SLID_NAME,
.id = -1,
};
static struct platform_driver slid_pdrv = {
.probe = slid_pdrv_probe,
.remove = slid_pdrv_remove,
.driver = {
.name = SLID_NAME,
.owner= THIS_MODULE,
},
};
static int __init slid_mod_init(void)
{
platform_device_register(&slid_pdev);
platform_driver_register(&slid_pdrv);
return 0;
}
static void __exit slid_mod_exit(void)
{
platform_device_unregister(&slid_pdev);
platform_driver_unregister(&slid_pdrv);
}
module_init(slid_mod_init);
module_exit(slid_mod_exit);
MODULE_LICENSE("GPL");