love_ic 2014-07-25 00:42 采纳率: 0%
浏览 11447

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


*/

  • 写回答

2条回答 默认 最新

  • m0_73227129 2023-03-25 06:16
    关注

    这是什么设备,要找出虚拟硬盘的话,可以fdisk -l

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试