【问题标题】:How to add a new device to board init code linux kernel如何将新设备添加到板初始化代码 linux 内核
【发布时间】:2020-09-09 14:51:05
【问题描述】:

您好,我正在使用 2.22.19 版本自定义 linux 内核,它不支持设备树。所以我必须使用板初始化代码来描述外围设备。我已经检查了板初始化代码中的“spi 节点”,如下所示:

   static struct resource c300v2evm_spi0_resources[] = {
    {
        .start  = COMCERTO_SPI0_BASE,
        .end    = COMCERTO_SPI0_BASE + SZ_4K - 1,
        .flags  = IORESOURCE_MEM,
    },
    {
        .start  = IRQ_SPI0,
        .flags  = IORESOURCE_IRQ,
    },
};
static struct platform_device c300v2evm_spi0 = {
    .name = "comcerto_spi",
    .id = 0,
    .num_resources = ARRAY_SIZE(c300v2evm_spi0_resources),
    .resource = c300v2evm_spi0_resources,
};

且spi总线与控制器驱动匹配:

static int __init comcerto_spi_probe(struct platform_device *pdev)
{
...// probe function code
}
static struct platform_driver comcerto_spi_driver = {
    .driver = {
        .name   = "comcerto_spi",
        .owner  = THIS_MODULE,
    },
    .probe  = comcerto_spi_probe,
    .remove = __devexit_p(comcerto_spi_remove),
};

现在我有了设备的协议驱动程序(spi 总线上的 eeprom):

static int at25_probe(struct spi_device *spi)
{
... // probe function code
}
static struct spi_driver at25_driver = {
    .driver = {
        .name       = "at25",
        .owner      = THIS_MODULE,
    },
    .probe      = at25_probe,
    .remove     = __devexit_p(at25_remove),
};

static int __init at25_init(void)
{
    return spi_register_driver(&at25_driver);
}

我检查了日志,发现协议已通过 init 函数加载到内核,但我不知道如何在板卡初始化代码中添加节点以匹配协议驱动程序探测函数。

【问题讨论】:

  • 我不禁觉得这不是这个问题的正确论坛。我还怀疑您不会找到一个论坛,人们会在这样一个古老的 Linux 内核上帮助您解决问题(除了可能,如果您愿意付钱给他们,并且付给他们很多钱) .

标签: c linux kernel driver porting


【解决方案1】:

我已通过以下操作解决了该问题: 首先,我在板子初始化代码文件中定义了一个描述我的 spi 设备的结构:

static struct legerity_platform_data c300v2evm_legerity0_platform_data = {
.type = 5,
.dummy = 0,
};

static struct spi_board_info spi0_info[] = {
{
    .modalias = "spi0",
    .chip_select = 1,
    .max_speed_hz = 1000*1000,
    .bus_num = 0,
    .irq = -1,
    .mode = SPI_MODE_3,
    .platform_data = &c300v2evm_legerity0_platform_data,
    },
};

使用字段“.bus_num = 0”,内核会理解这个spi设备属于spi0总线,它有“id = 0”。 然后我使用这个函数向内核注册设备:

spi_register_board_info(spi0_info, 1);

我已经用我的板子和我的设备匹配的协议驱动程序进行了测试,“探针”功能被调用。此方法是在 linux 内核版本 2.x.x 中注册新设备的基本方法,我已检查是否可以在较新版本中使用此方法。 希望这对必须使用旧版本 linux 内核的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 2016-10-08
    • 2016-08-02
    • 2014-10-07
    • 1970-01-01
    相关资源
    最近更新 更多