-
//dev_get_platdata和dev_get_drvdata获取的对象是不同的。
-
//dev_get_platdata获取的是device结构体成员变量的void * platform_data。
-
dev_get_drvdata获取的是device结构体void * driver_data。
-
另外有与dev_get_drvdata相对应的set函数dev_set_drvdata
-
只能直接给该platform_data赋值。
dev_get_drvdata(dev)用法1
-
struct synaptics_rmi4_data *rmi4_data1 = dev_get_drvdata(dev);调用的如下函数
-
static inline void *dev_get_drvdata(const struct device *dev)
{
return dev->driver_data;
} -
在这之前首先调用的如下函数进行设置的
-
static int synaptics_rmi4_probe(struct platform_device *pdev)
{
rmi4_data = kzalloc(sizeof(*rmi4_data), GFP_KERNEL);
platform_set_drvdata(pdev, rmi4_data);
-
...................................................
-
static inline void platform_set_drvdata(struct platform_device *pdev,
void *data)
{
dev_set_drvdata(&pdev->dev, data);
}调用的如下函数 -
static inline void dev_set_drvdata(struct device *dev, void *data)
{
dev->driver_data = data;
}
dev_get_drvdata(dev)用法2
struct led_classdev *led_cdev = dev_get_drvdata(dev);
-
在这之前首先调用的如下函数进行设置的
-
int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
{
char name[64];
int ret;ret = led_classdev_next_name(led_cdev->name, name, sizeof(name));
if (ret < 0)
return ret;led_cdev->dev = device_create_with_groups(leds_class, parent, 0,
led_cdev, led_cdev->groups, "%s", name); -
............................................................
-
struct device *device_create_with_groups(struct class *class,
struct device *parent, dev_t devt,
void *drvdata,
const struct attribute_group **groups,
const char *fmt, ...)
{
va_list vargs;
struct device *dev;va_start(vargs, fmt);
dev = device_create_groups_vargs(class, parent, devt, drvdata, groups,
fmt, vargs);
va_end(vargs);
return dev;
}
EXPORT_SYMBOL_GPL(device_create_with_groups); -
static struct device *device_create_groups_vargs(struct class *class, struct device *parent,
dev_t devt, void *drvdata,
const struct attribute_group **groups,
const char *fmt, va_list args)
{
struct device *dev = NULL;
int retval = -ENODEV;if (class == NULL || IS_ERR(class))
goto error;dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) {
retval = -ENOMEM;
goto error;
}device_initialize(dev);
dev->devt = devt;
dev->class = class;
dev->parent = parent;
dev->groups = groups;
dev->release = device_create_release;
dev_set_drvdata(dev, drvdata);retval = kobject_set_name_vargs(&dev->kobj, fmt, args);
if (retval)
goto error;retval = device_add(dev);
if (retval)
goto error;return dev;
error:
put_device(dev);
return ERR_PTR(retval);
} -
-