在 x86_64 上添加 i2c 客户端设备 [英] adding i2c client devices on x86_64
问题描述
在我的 x86_64 板上,有来自 MFD 设备的 i2c 总线.此 i2c 总线上有设备.我能够使用 i2cdetect 程序检测这些设备.
On my x86_64 board, there is i2c-bus coming out of a MFD device. There are devices on to this i2c-bus. I am able to detect these devices using i2cdetect program.
# i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- 4c -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
我需要内核自动检测这些设备,所以,我尝试按照下面给出的代码编写 i2c_board_info,但是,内核仍然无法自动检测这些设备.
I need the kernel to detect these devices automatically, So, I tried writing i2c_board_info as in given below code, But still, the kernel is not able to detect these devices automatically.
#include <linux/init.h>
#include <linux/i2c.h>
#define BUS_NUMBER 0
static struct __init i2c_board_info tst_i2c0_board_info[] = {
{
I2C_BOARD_INFO("ltc2990", 0x4c),
},
{
I2C_BOARD_INFO("24c128", 0x57),
},
};
static int tst_i2c_board_setup(void)
{
int ret=-1;
ret = i2c_register_board_info(BUS_NUMBER, tst_i2c0_board_info, ARRAY_SIZE(tst_i2c0_board_info));
return ret;
}
device_initcall(tst_i2c_board_setup);
有关如何解决此问题的任何建议?
Any suggestions on how can I solve this ?
推荐答案
由于您拥有支持 ACPI 的平台,因此最好的方法是提供给定设备的 ASL 摘录.
Since you have an ACPI-enabled platform the best approach is to provide the ASL excerpts for given devices.
由于采用了面向 IoT 的 Intel Galileo 平台,Atmel 24 系列 EEPROM 拥有自己的 ACPI ID,摘录将很简单:
Because of Intel Galileo platform for IoT the Atmel 24 series EEPROM has got its own ACPI ID and an excerpt will be simple:
DefinitionBlock ("at24.aml", "SSDT", 5, "", "AT24", 1)
{
External (_SB_.PCI0.I2C2, DeviceObj)
Scope (\_SB.PCI0.I2C2)
{
Device (EEP0) {
Name (_HID, "INT3499")
Name (_DDN, "Atmel AT24 compatible EEPROM")
Name (_CRS, ResourceTemplate () {
I2cSerialBusV2 (
0x0057, // I2C Slave Address
ControllerInitiated,
400000, // Bus speed
AddressingMode7Bit,
"\_SB.PCI0.I2C2", // Link to ACPI I2C host controller
0
)
})
Name (_DSD, Package () {
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"size", 1024},
Package () {"pagesize", 32},
}
})
}
}
}
注意,size 属性被添加到 待定补丁 系列(补丁添加eeprom大小"属性和添加支持获取eeprom设备属性大小").
Note, the size property is being added in a pending patch series (patches add eeprom "size" property and add support to fetch eeprom device property "size").
请注意,地址宽度目前为 8 位硬编码.如果您需要 16 位,则需要创建与上述类似的补丁.
Note, the address width is 8-bit as hard coded for now. In case you need to have 16-bit you need to create a similar patches as mentioned above.
对于 LTC2990 电源监视器,您需要以下摘录:
For LTC2990 power monitor you need the following excerpt:
DefinitionBlock ("ltc2990.aml", "SSDT", 5, "", "PMON", 1)
{
External (\_SB_.PCI0.I2C2, DeviceObj)
Scope (\_SB.PCI0.I2C2)
{
Device (PMON)
{
Name (_HID, "PRP0001")
Name (_DDN, "Linear Technology LTC2990 power monitor")
Name (_CRS, ResourceTemplate () {
I2cSerialBus (
0x4c, // Bus address
ControllerInitiated, // Don't care
400000, // Fast mode (400 kHz)
AddressingMode7Bit, // 7-bit addressing
"\_SB.PCI0.I2C2", // I2C host controller
0 // Must be 0
)
})
Name (_DSD, Package () {
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"compatible", "lltc,ltc2990"},
}
})
}
}
}
请注意,很遗憾,驱动程序中没有兼容字符串,因此,需要像 它在这里完成.
Note, unfortunately there is no compatible string in the driver, so, one needs to add it like it's done here.
在上面的示例中,\_SB.PCI0.I2C2
是 I2C 主机控制器的绝对路径.
In the examples above \_SB.PCI0.I2C2
is an absolute path to the I2C host controller.
如何应用这些文件:
- 首先,创建一个文件夹
mkdir -p kernel/firmware/acpi
- 将文件保存在该文件夹中
DefinitionBlock()
宏中提到的名称下 - 创建未压缩的 cpio 存档并将原始 initrd 连接到顶部:
find kernel | cpio -H newc --create > /boot/instrumented_initrd
cat /boot/initrd >> /boot/instrumented_initrd
更多详细信息可在 SSDT Overlays 中找到.
可以在 meta-acpi GitHub 页面上找到其他示例和背后想法的描述
The other examples and description of the idea behind can be found on meta-acpi GitHub page, some materials from which are copied here.
这篇关于在 x86_64 上添加 i2c 客户端设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!