c - spi驱动中的基本设备操作

标签 c linux linux-kernel linux-device-driver spi

我需要从头开始为 omap4 编写一个 spi 驱动程序。 我指的是 http://lxr.free-electrons.com/source/drivers/spi/spi-omap2-mcspi.c 驱动程序代码。 但是,我无法理解此驱动程序代码中如何处理基本设备操作。 例如,字符驱动程序具有结构

struct file_operations scull_fops = {
.owner = THIS_MODULE,
.llseek = scull_llseek,
.read = scull_read,
.write = scull_write,
.ioctl = scull_ioctl,
.open = scull_open,
.release = scull_release,
};

包含指向基本功能的指针,如打开、读取、写入等...

我没有找到这些函数 http://lxr.free-electrons.com/source/drivers/spi/spi-omap2-mcspi.c

有人请帮助我确定设备打开、读取和写入是如何在 spi-omap2-mcspi.c 代码中提供的。

最佳答案

如果您查看帖子中链接的文件底部,您将看到基本平台驱动程序操作的处理。

static const struct dev_pm_ops omap2_mcspi_pm_ops = {
        .resume = omap2_mcspi_resume,
        .runtime_resume = omap_mcspi_runtime_resume,
};

static struct platform_driver omap2_mcspi_driver = {
       .driver = {
                .name =         "omap2_mcspi",
                .owner =        THIS_MODULE,
                .pm =           &omap2_mcspi_pm_ops,
                .of_match_table = omap_mcspi_of_match,
       },
       .probe =        omap2_mcspi_probe,
       .remove =       omap2_mcspi_remove,
};

probe 操作中,您可以看到此驱动程序的 spi 特定操作的设置:

     /* the spi->mode bits understood by this driver: */
     master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
     master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
     master->setup = omap2_mcspi_setup;
     master->auto_runtime_pm = true;
     master->transfer_one_message = omap2_mcspi_transfer_one_message;
     master->cleanup = omap2_mcspi_cleanup;
     master->dev.of_node = node;

关于c - spi驱动中的基本设备操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22706570/

相关文章:

c - 获取 ext2 镜像中的特定 inode (C)

c++ - Newton Raphson 中的波动值

c - 带符号的补码算法

python - PyQt Web 浏览器 : Focus on the webpage without a mouse click

c - GCC/C 如何隐藏控制台窗口?

linux - Yocto - Linux 图像生成 - 删除 qemu 支持

linux - 限制对端口 8000 的访问(使用 Apache)- Ubuntu 14.04 Lts

linux-kernel - 从 FIQ 处理程序调用 Linux C 代码时出现问题

linux - Systemtap 不显示内核函数中的所有局部变量

python - Linux 内核调试 : "Python Exception <class ' gdb. 错误'> 没有名为 module_core 的成员。"在 gdb 中尝试使用帮助脚本时