您的位置:首页 > 移动开发 > Android开发

android miscdevice(混杂设备)驱动编写注意

2013-09-22 09:39 302 查看

miscdevice说明

miscdevice:混杂设备,是linux字符设备驱动中的一种,主要变量和函数有

struct miscdevice、misc_register、misc_deregister

miscdevice结构体定义如下:

struct miscdevice  {
int minor;
const char *name;
const struct file_operations *fops;
struct list_head list;
struct device *parent;
struct device *this_device;
const char *nodename;
mode_t mode;
};


主要用到的成员有minor name fops。minor变量取值有宏定义:

#define PSMOUSE_MINOR		1
#define MS_BUSMOUSE_MINOR	2
#define ATIXL_BUSMOUSE_MINOR	3
/*#define AMIGAMOUSE_MINOR	4	FIXME OBSOLETE */
#define ATARIMOUSE_MINOR	5
#define SUN_MOUSE_MINOR		6
#define APOLLO_MOUSE_MINOR	7
#define PC110PAD_MINOR		9
/*#define ADB_MOUSE_MINOR	10	FIXME OBSOLETE */
#define WATCHDOG_MINOR		130	/* Watchdog timer     */
#define TEMP_MINOR		131	/* Temperature Sensor */
#define RTC_MINOR		135
#define EFI_RTC_MINOR		136	/* EFI Time services */
#define SUN_OPENPROM_MINOR	139
#define DMAPI_MINOR		140	/* DMAPI */
#define NVRAM_MINOR		144
#define SGI_MMTIMER		153
#define STORE_QUEUE_MINOR	155
#define I2O_MINOR		166
#define MICROCODE_MINOR		184
#define TUN_MINOR		200
#define MWAVE_MINOR		219	/* ACP/Mwave Modem */
#define MPT_MINOR		220
#define MPT2SAS_MINOR		221
#define UINPUT_MINOR		223
#define HPET_MINOR		228
#define FUSE_MINOR		229
#define KVM_MINOR		232
#define BTRFS_MINOR		234
#define AUTOFS_MINOR		235
#define MAPPER_CTRL_MINOR	236
#define MISC_DYNAMIC_MINOR	255


看最后一个MISC_DYNAMIC_NIMOR,minor赋值该宏时,表示该设备的次设备号由系统动态分配。

与linux内核驱动比较

在标准linux内核中misc驱动注册misc设备时,需要提供miscdevice结构体变量,这一点安卓也一样。但标准linux所需提供的miscdevice变量中成员minor若未赋值,默认为MISC_DYNAMIC_MINOR,但在android中,需显式赋值,否则misc_register会注册失败。这一点我在写misc驱动时纳闷了半天,怎么linux上加载好好的驱动,跑到android上就提示加载失败。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: