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;
}