linux4.9内核PCIe的一个问题

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index f30ca75b5b6c…d87876fb8f90 100644
— a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c

@@ -197,7 +197,8 @@ static void __dev_sort_resources(struct pci_dev *dev,
 
        /* Don't touch classless devices or host bridges or ioapics.  */
        if (class == PCI_CLASS_NOT_DEFINED || class == PCI_CLASS_BRIDGE_HOST)
-               return;
+               if (dev->vendor != 0x1234)
+                       return;

如果pcie板卡没有定义class id,lspci显示没有分到地址空间.

以下是一个基于Linux 4.9内核的AHT20 IIC驱动的代码: ``` #include <linux/i2c.h> #include <linux/init.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/kernel.h> // AHT20 I2C Address #define AHT20_I2C_ADDR 0x38 // AHT20 Commands #define AHT20_CMD_INIT 0b1110001 #define AHT20_CMD_MEASURE 0b10101100 #define AHT20_CMD_SOFT_RESET 0b10111010 static int aht20_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; u8 buf[3]; // Initialize AHT20 buf[0] = AHT20_CMD_INIT; ret = i2c_master_send(client, buf, 1); if (ret < 0) { dev_err(&client->dev, "Failed to send AHT20 initialization command\n"); return ret; } msleep(20); // Soft reset AHT20 buf[0] = AHT20_CMD_SOFT_RESET; ret = i2c_master_send(client, buf, 1); if (ret < 0) { dev_err(&client->dev, "Failed to send AHT20 soft reset command\n"); return ret; } msleep(20); return 0; } static int aht20_read_measurement(struct i2c_client *client, u16 *humidity, u16 *temperature) { int ret; u8 buf[6]; // Send measure command to AHT20 buf[0] = AHT20_CMD_MEASURE; ret = i2c_master_send(client, buf, 1); if (ret < 0) { dev_err(&client->dev, "Failed to send AHT20 measure command\n"); return ret; } msleep(80); // Read measurement data from AHT20 ret = i2c_master_recv(client, buf, sizeof(buf)); if (ret < 0) { dev_err(&client->dev, "Failed to read AHT20 measurement data\n"); return ret; } // Convert measurement data to humidity and temperature values *humidity = (buf[1] << 12) | (buf[2] << 4) | (buf[3] >> 4); *temperature = ((buf[3] & 0x0F) << 16) | (buf[4] << 8) | buf[5]; return 0; } static const struct i2c_device_id aht20_id[] = { { "aht20", 0 }, { } }; MODULE_DEVICE_TABLE(i2c, aht20_id); static struct i2c_driver aht20_driver = { .driver = { .name = "aht20", }, .probe = aht20_probe, .id_table = aht20_id, }; module_i2c_driver(aht20_driver); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("AHT20 IIC Driver"); MODULE_LICENSE("GPL"); ``` 请注意,这只是一个示例代码,并且可能需要根据您的具体需求进行修改和调整。在实际使用中,请务必小心谨慎,以确保您的设备和数据的安全。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值