user2654735
user2654735

Reputation: 323

Creating Linux device driver. Can't get driver to detect device and call probe function

I have a couple of questions. Firstly, I'm trying to create a SPI driver for a RTC that I have but am having trouble getting the driver's probe function to get called. It seems that the device is not being detected and/or not being associated with the driver correctly.

1.) Is there a way, in Linux 2.6.35.14, to list HW devices that have no driver associated with them?

2.) Is it correct that Linux will discover the SPI RTC hardware's name/bus # automatically? Then all that would need to be done is match the driver name with this name? example:

 static struct spi_driver ds1305_driver = {
      .driver.name    = "ds1343", 
 ...
 }

3.) My probe function is not being called. I don't know how to trace why the device is not being detected. There are no dmesg errors that I can find. The RTC is a DS1343, if that helps at all. I'm basing it on the DS1305/DS1306

For the sake of brevity, I have skipped a lot of the functions that are not interesting for my purpose.

 #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");

Upvotes: 1

Views: 1714

Answers (1)

0andriy
0andriy

Reputation: 4674

First of all you have to understand base concept of the platform in Linux. The hardware platform is a set of devices including certain CPU and peripherals. Linux (kernel) has somehow to know on which platform it's run. In older times we used to have board files and hardcoded platform configurations which was awful. Nowadays this problem is solved by using ACPI or OF (DeviceTree) firmware mechanisms. The SPI unlike PCI can't be enumerated automatically, thus you have provide the information about devices either through ACPI (DSDT table), or DeviceTree, or unlikely via board file. You also can't list devices behind the bus, even for I2C it's unreliable and often may lead to a bus crash.

P.S. Why do you not extend existing driver? Is there too many differences to any of similar drivers in upstream?

Upvotes: 2

Related Questions