天嵌 ARM开发社区

 找回密码
 注册
12
返回列表 发新帖
楼主: DonyChen

驱动初始化成功,但是打开设备失败是什么原因

[复制链接]
 楼主| DonyChen 发表于 2012-4-22 18:03:09 | 显示全部楼层
本帖最后由 DonyChen 于 2012-4-22 18:04 编辑
亚瑟王 发表于 2012-4-21 13:31
亲,光盘里面的2.6.25.8的内核和2.6.30.4的内核中的LED灯的驱动没有实质的区别。最大的不同是注册设备是的 ...

我也这么认为的,可事实上就是有差别咧~~
亚瑟王 发表于 2012-4-23 09:56:10 | 显示全部楼层
DonyChen 发表于 2012-4-22 18:03
我也这么认为的,可事实上就是有差别咧~~

把你写的驱动的实际内容贴出来吧。
 楼主| DonyChen 发表于 2012-4-23 22:23:44 | 显示全部楼层
光盘附带的驱动
/*************************************

NAME:EmbedSky_hello.c
COPYRIGHT:www.embedsky.net

*************************************/

#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>


#define DEVICE_NAME "EmbedSky_leds"

/* 搴旂敤绋嬪簭鎵ц?ioctl(fd, cmd, arg)鏃剁殑绗?涓?弬鏁?*/
#define IOCTL_GPIO_ON        1
#define IOCTL_GPIO_OFF        0

/* 鐢ㄦ潵鎸囧畾LED鎵
 楼主| DonyChen 发表于 2012-4-23 22:25:25 | 显示全部楼层
我写的驱动

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/device.h>

#define DEVICE_NAME "EmbedSky_leds"
#define LED_MAJOR 231

#define IOCTL_LED_ON 1
#define IOCTL_LED_OFF 0

static unsigned long led_table[]=
{
        S3C2410_GPB5,
        S3C2410_GPB6,
        S3C2410_GPB7,
        S3C2410_GPB8,
};

static unsigned int led_cfg_table[]=
{
        S3C2410_GPB5_OUTP,
        S3C2410_GPB6_OUTP,
        S3C2410_GPB7_OUTP,
        S3C2410_GPB8_OUTP,

};


static int EmbedSky_leds_open(struct inode *inode, struct file *file)
{
        int i;

        for(i=0; i<4; i++)
        {
                s3c2410_gpio_cfgpin(led_table[i],led_cfg_table[i]);
        }
        return 0;
}

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

        switch(cmd)
        {
                case IOCTL_LED_ON:
                        s3c2410_gpio_setpin(led_table[arg],0);
                        return 0;

                case IOCTL_LED_OFF:
                        s3c2410_gpio_setpin(led_table[arg],1);
                        return 0;

                default:
                        return -EINVAL;
        }
}

static struct file_operations EmbedSky_leds_fops =
{
        .owner = THIS_MODULE,
        .open = EmbedSky_leds_open,
        .ioctl = EmbedSky_leds_ioctl,
};

static char __initdata  banner[]="TQ2440/SKY2440 ";
static struct class *led_class;

static int __init EmbedSky_leds_init(void)
{
        int ret;
        printk(banner);

        ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &EmbedSky_leds_fops);
        if(ret<0)
        {
                printk(DEVICE_NAME"can't register major number\n");
                return ret;
        }
        led_class = class_create(THIS_MODULE, DEVICE_NAME);
        if(IS_ERR(led_class))
        {
                printk("Err: failed in EmbedSky-leds class.\n");
                return -1;
        }

        device_create(led_class, NULL, MKDEV(LED_MAJOR,0),NULL,DEVICE_NAME);
        printk(DEVICE_NAME" initialized\n");
        return 0;
}

static void __exit EmbedSky_leds_exit(void)
{
        unregister_chrdev(LED_MAJOR, DEVICE_NAME);
        device_destroy(led_class, MKDEV(LED_MAJOR,0));
        class_destroy(led_class);
}

module_init(EmbedSky_leds_init);
module_exit(EmbedSky_leds_exit);
 楼主| DonyChen 发表于 2012-4-23 22:26:40 | 显示全部楼层
请管理员指教呀
 楼主| DonyChen 发表于 2012-4-28 13:42:12 | 显示全部楼层
亚瑟王???指点一下??
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-10-7 02:40 , Processed in 1.040079 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表