使用设备树中的信息注册平台设备 [英] Registering Platform Device with info from Device Tree

查看:548
本文介绍了使用设备树中的信息注册平台设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Petalinux用于Xilinx Zynq应用程序,并且是内核驱动程序开发的新手.

I am using Petalinux for a Xilinx Zynq application, and I am new to kernel driver development.

我为AXI FIFO接口的平台驱动程序创建了一个内核模块.似乎可以使用.of_match_table从设备树中识别设备,因为我可以看到cat /proc/iomem保留的正确内存空间.

I created a kernel module for a platform driver for an AXI FIFO interface. The devices seems to be recognised from the device tree using the .of_match_table, since I can see the correct memory space reserved with cat /proc/iomem .

如果我搜索驱动程序名称xxx,我会得到

If I search for the driver name xxx I get

./lib/modules/4.4.0-xilinx/extra/xxx.ko
./sys/bus/platform/drivers/xxx
./sys/module/xxx
./sys/module/xxx/drivers/platform:xxx

我在/sys/bus/platform/devices/43c00000.axi_xxxx下找到了该设备,但仍然无法访问它或在/dev/下看到了该设备.

I found the device under /sys/bus/platform/devices/43c00000.axi_xxxx but still can't access it or see it under /dev/.

  • 如何注册设备,以便可以从用户空间应用程序中打开它?

  • How do I register device so that I can open it from my user space app?.

我是否需要为其分配内存,然后使用platform_device_register(pdev)注册新设备?

Do I need to allocate memory for it and then register a new device using platform_device_register(pdev)?

谢谢

推荐答案

您需要在框架中注册设备才能创建设备文件.

You need to register your device in a framework to get a device file created.

我建议在您的情况下注册其他设备.它只是注册一个字符设备.

I would suggest registering a miscdevice in your case. It simply registers a character device.

static struct miscdevice miscdev;

static ssize_t myaxi_read(struct file *file, char __user *buf,
                 size_t sz, loff_t *ppos)
{
    // Do something

}

static ssize_t myaxi_write(struct file *file, const char __user *buf,
                  size_t sz, loff_t *ppos)
{
    // Do something
}

static const struct file_operations myaxi_fops = {
    .owner = THIS_MODULE,
    .write = myaxi_write,
    .read = myaxi_read,
};

在您的探针中:

miscdev.minor = MISC_DYNAMIC_MINOR;
miscdev.name = "myaxi";
miscdev.fops = &myaxi_fops;
misc_register(&miscdev);

您可以在 http://free-electrons.com/doc/training/linux-kernel/linux-kernel-slides.pdf

这篇关于使用设备树中的信息注册平台设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆