Linux 如何访问 i2c 设备驱动程序节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6057726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access i2c device driver node
提问by Farrukh Arshad
Situation 1:
情况一:
I have an i2c chip driver as part of linux kernel. I can verify the i2c chip driver is in the kernel from kernel boot messages (my chip driver is mma8450)
我有一个 i2c 芯片驱动程序作为 linux 内核的一部分。我可以通过内核启动消息验证 i2c 芯片驱动程序是否在内核中(我的芯片驱动程序是 mma8450)
dmesg:
留言:
mma8450 0-001c: uevent
I can also see this driver in (0x1c is i2c address of chip)
我也可以在(0x1c是芯片的i2c地址)中看到这个驱动程序
cat /sys/bus/i2c/devices/0-001c/name
mma8450
I can not see this driver node in /dev interface. My question is how can I create node of this device in /dev so that I can access this device in a user program ?
我在 /dev 界面中看不到这个驱动程序节点。我的问题是如何在 /dev 中创建此设备的节点,以便我可以在用户程序中访问此设备?
Situation 2:
情况二:
I create the module of the same chip driver and does not make it a part of kernel. I can load this module using insmod mma8450, how can I create a node of this device as I don't have its major / minor numbers ? (I can not see major & minor numbers assigned to this driver in mma8450 source code)
我创建了相同芯片驱动程序的模块,并且不使其成为内核的一部分。我可以使用 insmod mma8450 加载这个模块,我如何创建这个设备的节点,因为我没有它的主要/次要号码?(我在 mma8450 源代码中看不到分配给此驱动程序的主要和次要编号)
Any help is appreciated
任何帮助表示赞赏
Regards
问候
回答by austinmarton
Find the major/minor numbers for your device:
查找设备的主要/次要编号:
cat /proc/devices
You should see a device for the i2c bus and one for the i2c device itself.
您应该看到一个用于 i2c 总线的设备和一个用于 i2c 设备本身的设备。
Create the device node for the i2c device driver:
为 i2c 设备驱动程序创建设备节点:
mknod /dev/[device name] [type] [major] [minor]
回答by bernard
Load the kernel module:
加载内核模块:
modprobe i2c-dev
modprobe i2c-dev
ls /dev/i2*
/dev/i2c-0
/dev/i2c-10
/dev/i2c-12
/dev/i2c-14
/dev/i2c-3
/dev/i2c-5
/dev/i2c-7
/dev/i2c-9
/dev/i2c-1
/dev/i2c-11
/dev/i2c-13
/dev/i2c-2
/dev/i2c-4
/dev/i2c-6
/dev/i2c-8
回答by Dra?en G.
This is 3-Axis Accelerometer. Linux registers it as a driver for input_polled_dev
type.
这是三轴加速度计。Linux 将其注册为input_polled_dev
类型的驱动程序。
You can uaccess it using /dev/i2c-x bus (controller) device node, but there is no much sense using it that way directly from userspace.
您可以使用 /dev/i2c-x 总线(控制器)设备节点来访问它,但是直接从用户空间使用它没有多大意义。
I2C clients are not meant to be used using /dev device nodes. They should be registered to Kernel I2C framework and used through higher layers API.
I2C 客户端不打算使用 /dev 设备节点。它们应该注册到内核 I2C 框架并通过更高层的 API 使用。
There is sample program for reading similar MMA7455L x,y,z registers from userspace using /dev/i2c-X bus device node.
有使用 /dev/i2c-X 总线设备节点从用户空间读取类似 MMA7455L x,y,z 寄存器的示例程序。