免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1742 | 回复: 4
打印 上一主题 下一主题

关于并口驱动的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-28 10:47 |只看该作者 |倒序浏览
小弟想写个并口输出试试,设置vmware把并口输出到文件,但是怎么试,输出文件也没内容,但往/dev/lp中写数据可以看到。

下面是我的代码,初始化都没有返回任何错误,请高手帮忙!

#include <linux/init.h>
#include <linux/types.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <asm/io.h>
#include <linux/ioport.h>
#include <asm/system.h>

#define DEV_NUM 3
#define DEV_NAME "pio"

#define PORT 0x378
#define PORT_NUM 1

dev_t dev_num;
struct resource *p_res;


struct pio_data {
    struct cdev mdev;
};

struct file_operations pio_ops = {
    .owner = THIS_MODULE,
};

struct pio_data pio_devs[DEV_NUM];

int __init pio_init() {
    int ret = 0;
    int i = 0;
    dev_t dnum;

    printk(KERN_ALERT"pio init\n");
        ret = alloc_chrdev_region(&dev_num, 0, DEV_NUM, DEV_NAME);
   
        if (ret < 0) {
            printk(KERN_ALERT"pio: can not alloc major number\n");
            return ret;
        }

    for (i = 0; i < DEV_NUM; i++) {
        dnum = MKDEV(MAJOR(dev_num), i);
        cdev_init(&(pio_devs.mdev), &pio_ops);
        pio_devs.mdev.owner = THIS_MODULE;
        ret = cdev_add(&(pio_devs.mdev), dnum, 1);

        if (ret < 0) {
            printk(KERN_ALERT"pio: can not create device: %d:%d\n", MAJOR(dev_num), i);
            return ret;
        }
    }

    p_res = request_region(PORT, PORT_NUM, DEV_NAME);
   
    if (p_res == NULL) {
        printk(KERN_ALERT"pio: request i/o ports error.\n");
        return ret;
    }

    for (i = 0; i < 10; i++) {
        outb('a' + i, PORT);
        wmb();
    }

    return 0;
}

void __exit pio_exit() {
    int i = 0;
    printk("pio exit\n");

    release_region(PORT, PORT_NUM);

    for (i = 0; i < DEV_NUM; i++) {
        cdev_del(&(pio_devs.mdev));
    }

    unregister_chrdev_region(dev_num, DEV_NUM);
}

module_init(pio_init);
module_exit(pio_exit);

论坛徽章:
0
2 [报告]
发表于 2009-12-29 00:42 |只看该作者
LINUX自带的并口驱动卸载了没有?

论坛徽章:
0
3 [报告]
发表于 2009-12-29 09:19 |只看该作者

回复 #2 accessory 的帖子

卸载了,插入模块,端口申请什么的都没有问题。

论坛徽章:
0
4 [报告]
发表于 2009-12-29 17:44 |只看该作者
看看能不能把并口换回了。

要不然你就在驱动中加一些调试代码

论坛徽章:
0
5 [报告]
发表于 2009-12-29 18:59 |只看该作者
驱动调试很麻烦,感慨一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP