我有几个问题。首先,我正在尝试为我拥有的 RTC 创建一个 SPI 驱动程序,但在调用驱动程序的探测函数时遇到了问题。设备似乎未被检测到和/或未与驱动程序正确关联。
1.) 在 Linux 2.6.35.14 中,有没有办法列出没有关联驱动程序的硬件设备?
2.) Linux 会自动发现 SPI RTC 硬件的名称/总线#是否正确?那么所有需要做的就是将驱动程序名称与这个名称匹配?示例:
static struct spi_driver ds1305_driver = {
.driver.name = "ds1343",
...
}
3.) 我的探测函数没有被调用。我不知道如何追踪未检测到设备的原因。我找不到任何 dmesg 错误。如果有帮助的话,RTC 是 DS1343。我基于 DS1305/DS1306
为了简洁起见,我跳过了很多对我来说不感兴趣的函数。
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/bcd.h>
#include <linux/slab.h>
#include <linux/rtc.h>
#include <linux/workqueue.h>
#include <linux/spi/spi.h>
#include <linux/spi/ds1343.h>
...
static int __devinit ds1305_probe(struct spi_device *spi)
{
....
}
.....
static struct spi_driver ds1305_driver = {
.driver.name = "ds1343",
.driver.owner = THIS_MODULE,
.probe = ds1305_probe,
.remove = __devexit_p(ds1305_remove),
/* REVISIT add suspend/resume */
};
static int __init ds1305_init(void)
{
return spi_register_driver(&ds1305_driver);
}
module_init(ds1305_init);
static void __exit ds1305_exit(void)
{
spi_unregister_driver(&ds1305_driver);
}
module_exit(ds1305_exit);
MODULE_DESCRIPTION("RTC driver for DS1305 and DS1306 chips");
MODULE_LICENSE("GPL");
MODULE_ALIAS("spi:rtc-ds1343");
最佳答案
首先,您必须了解 Linux 平台的基本概念。硬件平台是一组设备,包括一定的CPU和外设。 Linux(内核)不知何故知道它在哪个平台上运行。在过去,我们曾经拥有非常糟糕的板文件和硬编码平台配置。现在这个问题通过使用 ACPI 或 OF (DeviceTree) 固件机制来解决。与 PCI 不同,SPI 无法自动枚举,因此您可以通过 ACPI(DSDT 表)或 DeviceTree 提供有关设备的信息,或者不太可能通过板文件提供。您也不能列出总线后面的设备,即使对于 I2C 也是不可靠的,并且经常可能导致总线崩溃。
附言为什么不扩展现有的驱动程序?与上游的任何类似驱动程序是否存在太多差异?
关于创建 Linux 设备驱动程序。无法让驱动程序检测设备并调用探测功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32054211/