alps\mediatek\kernel\drivers\Makefile 加一行
obj-y += emd_ctl/
obj-y += scandriver/obj-y += hello/
alps\mediatek\kernel\drivers\scandriver\Makefile 加一行
obj-y += demo1.o
alps\mediatek\kernel\drivers\scandriver\test.h
#ifndef TEST_H
#define TEST_H
#define test1_MAGIC 'w' //定义幻数为 w
#define test1_POWER_ON _IOWR(test1_MAGIC, 0, int)
#define test1_POWER_OFF _IOWR(test1_MAGIC, 1, int)
#define test1_TRIG_LOW _IOWR(test1_MAGIC, 3, int)
#define test1_TRIG_HIGH _IOWR(test1_MAGIC, 4, int)
#define test1_MAXNR 5
#define TEST1_CMD1 _IO(test1_MAGIC,0x1a)
#define TEST1_CMD2 _IO(test1_MAGIC,0x1b)
#endif
alps\mediatek\kernel\drivers\scandriver\test.c
#include <linux/init.h>
#include <linux/slab.h>
#include <asm/errno.h>
#include <asm/delay.h>
#include <linux/mm.h>
#include <linux/poll.h>
#include <linux/module.h>
#include <linux/cdev.h>
#include <linux/wait.h>
#include <linux/timer.h>
//#include <mach/gpio.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include "test.h"
#include <mach/mt_gpio.h>
#include <mach/mt_sleep.h>
#include <mach/mt_pm_ldo.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#define FLASH_LIGHT_GPIO GPIO126
//#define GPIO_ModeSetup(pin, mode) mt_set_gpio_mode(pin, mode)
//#define GPIO_InitIO(dir, pin) mt_set_gpio_dir(pin, dir)
//#define GPIO_WriteIO(out, pin) mt_set_gpio_out(pin, out)
//#define GPIO_ReadIO(pin) mt_get_gpio_in(pin)
void flash_light_set_low(void)
{
mt_set_gpio_mode(FLASH_LIGHT_GPIO, 0);
mt_set_gpio_dir(FLASH_LIGHT_GPIO, 1);
mt_set_gpio_out(FLASH_LIGHT_GPIO, 0);
}
void flash_light_set_high(void)
{
mt_set_gpio_mode(FLASH_LIGHT_GPIO, 0);
mt_set_gpio_dir(FLASH_LIGHT_GPIO, 1);
mt_set_gpio_out(FLASH_LIGHT_GPIO, 1);
}
void flash_light_poweron(void)
{
flash_light_set_high();
// hwPowerDown(MT6323_POWER_LDO_VGP2, "TP");
// hwPowerOn(MT6323_POWER_LDO_VGP2, VOL_1800, "TP");
// hwPowerDown(MT6323_POWER_LDO_VGP1, "TP");
// hwPowerOn(MT6323_POWER_LDO_VGP1, VOL_3300, "TP");
}
void flash_light_poweroff(void)
{
flash_light_set_low();
}
#define test1_MAJOR 184
#define test1_MINOR 0
#define INVALID_NO -1
static unsigned char DEV_NAME[10] = "test_flash_light_gpio";
static struct cdev test1Dev;
static int test1_open(struct inode* inode, struct file* filp)
{
flash_light_poweron();
return 0;
}
//static int test1_ioctl(struct inode *i, struct file *f, unsigned int cmd, unsigned long arg)
static long test1_ioctl(struct file *f, unsigned int cmd,
unsigned long arg)
{
int err = 0;
int retval = 0;
if(_IOC_TYPE(cmd) != test1_MAGIC){ //如果幻数不相同则返回错误
printk("cmd is not equal test1_MAGIC\n");
return -ENOTTY;
}
// if(_IOC_NR(cmd) > FLASH_LIGHT_POWER_ON){ //如果序数大于最大值,则返回错误
// printk("the number of cmd max FLASH_LIGHT_POWER_ON\n");
// return -ENOTTY;
// }
//检查指向的用户空间是否合法
//if(_IOC_DIR(cmd) & _IOC_READ)
//err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd)); //_IOC_SIZE(cmd) 是字节数
//else if(_IOC_DIR(cmd) & _IOC_WRITE)
//err = !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd)); //读取用户空间的内存区是否合法
*arg是用户空间的地址
//if(err)
//return -EFAULT;
switch(cmd)
{
case test1_POWER_ON:
flash_light_poweron();
printk("FLASH_LIGHT_POWER_ON!\n");
break;
case test1_POWER_OFF:
flash_light_poweroff();
printk("FLASH_LIGHT_POWER_OFF!\n");
break;
default:
break;
}
return 0;
}
static int test1_release(struct inode* i,struct file* f)
{
return 0;
}
struct file_operations test1_fops =
{
.owner= THIS_MODULE,
.open= test1_open,
.unlocked_ioctl= test1_ioctl,
.release= test1_release,
};
static struct miscdevice test1 = {
.minor = MISC_DYNAMIC_MINOR,
.name = "test_flash_light_gpio",
.fops = &test1_fops
};
static int __init test1_reg(void)
{
misc_register(&test1);
printk("test1 driver initilization Success\n");
return 0;
}
static void __exit test1_exit(void)
{
cdev_del(&test1Dev);
unregister_chrdev_region(MKDEV(test1_MAJOR, 0), 1);
return;
}
module_init(test1_reg)
module_exit(test1_exit)