从Linux内核模块访问串行端口 [英] Accessing a serial port from a linux kernel module

查看:125
本文介绍了从Linux内核模块访问串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Linux内核驱动程序大师!

Hello Linux Kernel Driver Gurus!

我正在为使用串行接口进行配置的摄像机编写v4l2驱动程序.我希望驱动程序配置摄像头,因为它可以使客户端代码在各个摄像头型号之间保持一致.问题是:从驱动程序模块访问相机的串行接口的最佳方法是什么?

I'm writing a v4l2 driver for a camera that uses a serial interface for configuration. I'd like the driver to configure the camera, as it keeps the client code consistent across camera models. The question is: what's the best way to access the camera's serial interface from the driver module?

据我所知,从内核驱动程序访问文件是一个很大的禁忌,但这是可以做到的.因此,我目前正在使用以下代码段,但感觉像是黑客.

From what I hear, accessing files from a kernel driver is a big no-no, but it can be done. As such, I'm currently using the following code snippet, but it feels like a hack.

oldfs = get_fs();
set_fs(KERNEL_DS);

fd->f_pos=0;
fd->f_op->write(fd, data, data_len, &fd->f_pos);

set_fs(oldfs);

我的问题确实是:执行此操作的正确方法是什么?

My question is really: what's the right way to do this?

推荐答案

我认为,由于涉及串行端口,因此它一定是某种嵌入式系统.毕竟,甚至没有多少PC具有串行端口.我还假定至少从用户的角度来看,可以将串行端口视为永久连接.如果这是真的,那么您实际上就不需要TTY设备.您想作为私有UART访问设备.

I presume that since a serial port is involved, this must be some kind of embedded system. After all, not many PCs even have serial ports. I also assume that the serial port can be considered a permanent connection, at least from the user's perspective. If that is all true, then you don't really want a TTY device. You want to access the device as a private UART.

如果您查看Wolfson音频编解码器(sound/soc/wm * .c),将看到一个设备示例,这些设备主要通过I2S进行通信,但具有用于配置的辅助I2C接口.我相信,从概念上讲,这就是您想要的.该驱动程序为软件提供了统一的界面,并向适当的硬件发出命令.显然,这比将硬件实现的详细信息公开给用户空间要干净得多.

If you have a look at the Wolfson audio codecs (sound/soc/wm*.c) you will see an example of devices that primarily communicate over I2S but have an auxiliary I2C interface for configuration. This is conceptually what you want, I believe. The driver presents a unified interface to software, and issues commands to whatever hardware is appropriate. Obviously this is much cleaner than having to expose hardware implementation details to userspace.

我找不到在内核中以这种方式工作的UART驱动程序的好示例,但希望我已经描述了要寻找的内容.从实用性而非技术上的角度来看,最好是从内核执行文件I/O.

I couldn't find a good example of a UART driver in the kernel that works this way, but hopefully I've described what to look for. From a practical rather than technical purity point of view, it might just be better to do file I/O from the kernel.

这篇关于从Linux内核模块访问串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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