在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.
由于用于物联网的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 属性已添加到 dt绑定:添加eeprom大小"属性和).
Note, the size property is being added in a pending patch series series (patches dt-bindings: add eeprom "size" property and eeprom: at24: 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连接到顶部:
- save files under names mentioned in the
DefinitionBlock()
macro in that folder - create the uncompressed cpio archive and concatenate the original initrd on top:
find kernel | cpio -H newc --create > /boot/instrumented_initrd
cat /boot/initrd >> /boot/instrumented_initrd
更多详细信息,请参见 ssdt- overlays.txt .
More details are available in ssdt-overlays.txt.
可以在 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屋!