源码init.3rdparty.rc:(\3rdparty\lcm3d\lcm3d_drv\special\init.3rdparty.rc)
on init
device /dev/lcm3d 777 system system
on boot
insmod /system/sps/lcm3d_drv/ko/lcm3d_drv.ko
源码Makefile:(\3rdparty\lcm3d\lcm3d_drv\special\driver\Makefile)
obj-m:=lcm3d_drv.o
源码lcm3d_drv.c:(\3rdparty\lcm3d\lcm3d_drv\special\driver\lcm3d_drv.c)
#include <linux/module.h> // For module specific items
#include <linux/moduleparam.h> // For new moduleparam's
#include <linux/types.h> // For standard types (like size_t)
#include <linux/errno.h> // For the -ENODEV/... values
#include <linux/kernel.h> // For printk/panic/...
#include <linux/fs.h> // For file operations
#include <linux/ioport.h> // For io-port access
#include <linux/platform_device.h> // For platform_driver framework
#include <linux/init.h> // For __init/__exit/...
#include <linux/uaccess.h> // For copy_to_user/put_user/...
#include <linux/io.h> // For inb/outb/...
#include <linux/gpio.h> // GPIO
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/slab.h> //kamlloc
#include <linux/string.h>
#include <linux/mutex.h>
#include <linux/kmod.h>
#include <linux/mm.h>
#include <asm/system.h>
static int lcm3d_major = 252; // lcm3d_major = 0;
#define LCM3D_ON 0x4800
#define LCM3D_OFF 0x4801
void lcm3d_off( void )
{
//在这里调用
//gpio_set_value( XXX,0);
printk("set lcm3d off\n");
}
void lcm3d_on( void )
{
//在这里调用
//gpio_set_value( XXX,1);
printk("set lcm3d on\n");
}
static int lcm3d_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
switch ( cmd ) {
case LCM3D_ON:{
lcm3d_on();break;
}
case LCM3D_OFF:{
lcm3d_off();break;
}
default:{
break;
}
}
return 0;
}
int lcm3d_open (struct inode *inode, struct file *filp)
{
return 0;
}
ssize_t lcm3d_read(struct file *file, char __user *buff, size_t count, loff_t *offp)
{
return 0;
}
ssize_t lcm3d_write(struct file *file, const char __user *buff, size_t count, loff_t *offp)
{
return 0;
}
static int lcm3d_release(struct inode *node, struct file *file)
{
return 0;
}
static struct file_operations lcm3d_remap_ops = {
.owner = THIS_MODULE,
.open = lcm3d_open,
.release = lcm3d_release,
.read = lcm3d_read,
.write = lcm3d_write,
.ioctl = lcm3d_ioctl,
};
static struct cdev lcm3dDevs;
static void lcm3d_setup_cdev(struct cdev *dev, int minor,
struct file_operations *fops)
{
int err;
int devno = MKDEV(lcm3d_major, minor);
cdev_init(dev, fops);
dev->owner = THIS_MODULE;
dev->ops = fops;
err = cdev_add (dev, devno, 1);
if (err)
printk (KERN_NOTICE "Error %d adding lcm3d %d", err, minor);
}
static struct class *my_class;
static int lcm3d_init(void)
{
int result;
dev_t dev = MKDEV(lcm3d_major, 0);
if (lcm3d_major)
result = register_chrdev_region(dev, 1, "lcm3d");
else {
result = alloc_chrdev_region(&dev, 0, 1, "lcm3d");
lcm3d_major = MAJOR(dev);
}
if (result < 0) {
printk(KERN_WARNING "lcm3d: unable to get major %d\n", lcm3d_major);
return result;
}
if (lcm3d_major == 0)
lcm3d_major = result;
lcm3d_setup_cdev(&lcm3dDevs, 0, &lcm3d_remap_ops);
printk("lcm3d device installed, with major %d\n", lcm3d_major);
my_class= class_create(THIS_MODULE, "lcm3d");
device_create(my_class, NULL, MKDEV(lcm3d_major, 0),
NULL, "lcm3d");
return 0;
}
static void lcm3d_cleanup(void)
{
cdev_del(&lcm3dDevs);
unregister_chrdev_region(MKDEV(lcm3d_major, 0), 1);
device_destroy(my_class,MKDEV(lcm3d_major,0));
printk("lcm3d device uninstalled\n");
}
module_init(lcm3d_init);
module_exit(lcm3d_cleanup);
module_param(lcm3d_major, int, 0);
MODULE_AUTHOR("estar.cn");
MODULE_LICENSE("Dual BSD/GPL");
注:
1)展讯8810平台下结构
修改customize/make/XXX.mak
最后一行加入
3RDPARTY_LCM3D = lcm3d_drv
2)#cat proc/devices看是否有字符设备lcm3d
#lsmod //查看是否加载上了 lcm3d_drv.ko