LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 05-23-2018, 09:45 AM   #1
mrigendra
LQ Newbie
 
Registered: Dec 2014
Posts: 22

Rep: Reputation: Disabled
What is the use of of_device_id and i2c_device_id?


was understanding an I2C driver for adxl34x sensor. If I only keep of_device_id, my probe does not gets called, but if I include i2c_device_id probe gets called. I checked for some explanation but I get to know that i2c_device_id is used for legacy purpose or board file matching. Here I am using device tree. How is it possible that i2c_device_id is making the device recognised? Is there a dependency in I2C drivers to use both i2c_Device_id and of_device_id?? here is my understanding on this top id_table is used for legacy i2c devices. See in this code

Code:
static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
                        const struct i2c_client *client)
{
    while (id->name[0]) {
        if (strcmp(client->name, id->name) == 0)
            return id;
        id++;
    }
    return NULL;
}
There is no device id table reference, while of_device_id

Code:
/**
 * of_match_device - Tell if a struct device matches an of_device_id list
 * @ids: array of of device match structures to search in
 * @dev: the of device structure to match against
 *
 * Used by a driver to check whether an platform_device present in the
 * system is in its list of supported devices.
 */
const struct of_device_id *of_match_device(const struct of_device_id *matches,
                       const struct device *dev)
{
    if ((!matches) || (!dev->of_node))
        return NULL;
    return of_match_node(matches, dev->of_node);
}
Uses dev->of_node

So its safe to say both mechanism are isolated and does not depend on each other. Then why my driver is not getting probed by only using this,

Code:
/*
 static const struct i2c_device_id adxl34x_id[] = {
    { "adxl345", 0 },
    { }
};

MODULE_DEVICE_TABLE(i2c, adxl34x_id);
*/

#ifdef CONFIG_OF
static const struct of_device_id adxl34x_of_id[] = {
    /*
     * The ADXL346 is backward-compatible with the ADXL345. Differences are
     * handled by runtime detection of the device model, there's thus no
     * need for listing the "adi,adxl346" compatible value explicitly.
     */
    { .compatible = "adi,adxl345", },
    /*
     * Deprecated, DT nodes should use one or more of the device-specific
     * compatible values "adi,adxl345" and "adi,adxl346".
     */
    { .compatible = "adi,adxl34x", },
    { }
};

MODULE_DEVICE_TABLE(of, adxl34x_of_id);
#endif

static struct i2c_driver adxl34x_driver = {
    .driver = {
        .name = "adxl34x",
        //.pm = &adxl34x_i2c_pm,
        .of_match_table = of_match_ptr(adxl34x_of_id),
    },
    .probe    = adxl34x_i2c_probe,
    .remove   = adxl34x_i2c_remove,
    //.id_table = adxl34x_id, /*commented i2c_device_id*/
};
Here are some links that I have gone through in order to get some understanding

https://patches.linaro.org/patch/16873/

https://lists.ozlabs.org/pipermail/l...ly/131965.html

https://i2c.wiki.kernel.org/index.php/OF_Modalias

I understood that first of_* style match will happen, then i2c_device_id type match.

In my case, then how of_* is not able to bind then?

Why i2c_device_table is needed if its legacy thing?

Last edited by mrigendra; 05-23-2018 at 09:51 AM.
 
Old 05-25-2018, 08:40 AM   #2
ltkenbo
LQ Newbie
 
Registered: May 2006
Posts: 8

Rep: Reputation: 0
Can you please post your device tree file or at least the entry you made for this device?
 
  


Reply

Tags
device tree, linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 10:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration