1、snd_soc_codec_get_drvdata
./include/sound/soc.h
static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
{
return dev_get_drvdata(codec->dev);
}
調用dev_get_drvdata函數,
函數dev_get_drvdata(), 是用來返回driver的私有數據的,其函數實現如下。
drivers/base/dd.c
/*
* These exports can't be _GPL due to .h files using this within them, and it
* might break something that was previously working...
*/
void *dev_get_drvdata(const struct device *dev)
{
if (dev && dev->p)
return dev->p->driver_data;
return NULL;
}
EXPORT_SYMBOL(dev_get_drvdata);
我們可以看到此函數主要是返回了device->p->driver_data指針。那麼,我們下面來看一下,Kernel中比較重要的Device結構體,它其實是對內核中所有設備的抽象表示。 所有的設備都有一個device實例與之對應,而且Device結構體的主要用法爲將其嵌入到其他的設備結構體中,如platform_device等。同時,Device結構體也負責作爲子系統之間交互的統一參數
include/linux/device.h
struct device {
struct device *parent;
struct device_private *p; //負責保存driver核心部分的數據
struct kobject kobj;
const char *init_name;
.......
struct device_driver *driver;
#ifdef CONFIG_PINCTRL
struct dev_pin_info *pins;
#endfi
.......
struct device_node *of_node; //負責保存device_tree中相應的node地址
.......
const struct attribute_group **groups;
......
}
struct device_private {
struct klist klist_children;
struct klist_node knode_parent;
struct klist_node knode_driver;
struct klist_node knode_bus;
struct list_head deferred_probe;
void *driver_data; //負責保存driver中相應的driver_data
struct device *device;
}