2 love ic love_ic 于 2014.07.25 08:42 提问

linux驱动加载后能找到设备,但是/dev下不能找到设备文件

linux驱动加载后能找到设备,但是/dev下不能找到设备文件,我用的是动态分配设备号,insmod也能通过,但是/dev下就是找不到设备文件,加载后也不能通过测试程序我基本上直接用的板子例程,静态动态我都试了,就是不行,日志文件里面也什么都没有,板子是2410的,主机是红帽的,希望大神能够指点迷津
/*
****************************************Copyright (c)**************************************************
** Guangzhou Zhiyuan Electronic Co.,LTD.
** graduate school
** http://www.zyinside.com
**
**------------------------------------- File Info ------------------------------------------------------
** File name: magic-leds.c
** Last modified Date: 2005-12-28
** Last Version: 1.0
** Descriptions: Driver for LEDs and BEEP on MagicARM2410.
** Based on Linux 2.4.18.
**------------------------------------------------------------------------------------------------------
** Created by: Chenxibing
** Created date: 2005-12-27
** Version: 1.0
** Descriptions: Preliminary version.
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**


*/

#ifndef KERNEL
#define KERNEL
#endif

#ifndef MODULE
#define MODULE
#endif

#include
#include
#include
#include
#include
#include
//#include
//#include
//#include
//#include
//#include
#include

#define DEVICE_NAME "magic-leds"
#define LED_MAJOR 231 //can be 231~239 or 240~254

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Guangzhou Zhiyuan Electronic Co.,LTD.\ngraduate school\nhttp://www.zyinside.com");
MODULE_SUPPORTED_DEVICE("Linux 2.4.18 & MagicARM2410");
MODULE_AUTHOR("Chenxibing");

/*


** LEDs' informations.


*/
static unsigned long leds_table[] =
{
GPIO_E11,
GPIO_E12,
GPIO_H4,
GPIO_H6,
GPIO_H10,
};

/*


** Function name: magic_leds_ioctl()
** Descriptions : IO control function
** Input:
** inode : information of device
** filp : pointer of file
** cmd : command
** arg : additive parameter
** Output:
** 0 : OK
** other : not OK
** Created by : Chenxibing
** Created Date : 2005-12-27
**-----------------------------------------------------------------------------------------------------
** Modified by :
** Modified Date:
**-----------------------------------------------------------------------------------------------------


*/
static int magic_leds_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
if (arg > 4) return -EINVAL;

switch(cmd) 
{
    case 0:
    case 1:
        write_gpio_bit(leds_table[arg], cmd);
    default:
        return -EINVAL;
}

}

/*


** Function name: magic_leds_open()
** Descriptions : open leds
** Input:
** inode : information of device
** filp : pointer of file
** Output:
** 0 : OK
** other : not OK
** Created by : Chenxibing
** Created Date : 2005-12-27
**-----------------------------------------------------------------------------------------------------
** Modified by :
** Modified Date:
**-----------------------------------------------------------------------------------------------------


*/
static int magic_leds_open(struct inode *inode, struct file *filp)
{
int i;

for (i = 0; i < 5; i++)
{
    set_gpio_ctrl(leds_table[i] | GPIO_PULLUP_EN | GPIO_MODE_OUT);
    write_gpio_bit(leds_table[i], 1);
}

MOD_INC_USE_COUNT;
printk(KERN_INFO DEVICE_NAME ": opened.\n");
return 0;

}

/*


** Function name: magic_leds_release()
** Descriptions : release leds
** Input:
** inode : information of device
** filp : pointer of file
** Output:
** 0 : OK
** other : not OK
** Created by : Chenxibing
** Created Date : 2005-12-27
**-----------------------------------------------------------------------------------------------------
** Modified by :
** Modified Date:
**-----------------------------------------------------------------------------------------------------


*/
static int magic_leds_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
printk(KERN_INFO DEVICE_NAME ": released.\n");
return 0;
}

/*


** operations of the driver


*/
static struct file_operations magic_leds_fops =
{
owner: THIS_MODULE,
ioctl: magic_leds_ioctl,
open: magic_leds_open,
release: magic_leds_release,
};

/*


** Function name: magic_leds_init()
** Descriptions : register driver
** Input:
** : NONE
** Output:
** 0 : OK
** other : not OK
** Created by : Chenxibing
** Created Date : 2005-12-27
**-----------------------------------------------------------------------------------------------------
** Modified by :
** Modified Date:
**-----------------------------------------------------------------------------------------------------


*/
static devfs_handle_t devfs_handle;
static int __init magic_leds_init(void)
{
int result;
printk("""leds dev\n");

result = register_chrdev(LED_MAJOR, DEVICE_NAME, &magic_leds_fops);
if (result < 0)
{
printk(KERN_ERR DEVICE_NAME ": Failed to register major.\n");
return result;
}
// devfs_handle = devfs_register(NULL, DEVICE_NAME, DEVFS_FL_AUTO_DEVNUM,
// 0, 0, S_IFCHR | S_IRUSR | S_IWUSR, &magic_leds_fops, NULL);

// printk(KERN_INFO DEVICE_NAME ": Initialize OK.\n");
// return 0;
}

/*


** Function name: magic_leds_exit()
** Descriptions : unregister driver
** Input:
** : NONE
** Output:
** 0 : OK
** other : not OK
** Created by : Chenxibing
** Created Date : 2005-12-27
**-----------------------------------------------------------------------------------------------------
** Modified by :
** Modified Date:
**-----------------------------------------------------------------------------------------------------


*/

static void __exit magic_leds_exit(void)
{
// devfs_unregister(devfs_handle);
unregister_chrdev(LED_MAJOR, DEVICE_NAME);
}

module_init(magic_leds_init);
module_exit(magic_leds_exit);
/*


** End of File


*/

1个回答

city_of_the_sky
city_of_the_sky   2014.12.06 12:13

注册完设备文件可以在/proc/devices下看到设备名,还要建立设备节点...在/dev下看到的就是

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!