platform_set_drvdata和platform_get_drvdata

1、platform_set_drvdata

kernel\linux-3.10.y\include\linux\platform_device.h:

static inline void platform_set_drvdata(struct platform_device *pdev, void *data)
{
	dev_set_drvdata(&pdev->dev, data);
}

kernel\linux-3.10.y\drivers\base\dd.c:
int dev_set_drvdata(struct device *dev, void *data)
{
	int error;

	if (!dev->p) {
	error = device_private_init(dev);
	if (error)
	return error;
	}
	dev->p->driver_data = data;
	return 0;
}

2、platform_get_drvdata

static inline void *platform_get_drvdata(const struct platform_device *pdev)
{
	return dev_get_drvdata(&pdev->dev);
}

void *dev_get_drvdata(const struct device *dev)
{
	if (dev && dev->p)
		return dev->p->driver_data;
	return NULL;
}

kernel\linux-3.10.y\include\linux\device.h:

struct device {
	struct device  *parent;

	struct device_private *p;

	struct kobject kobj;
	const char  *init_name; /* initial name of the device */
	const struct device_type *type;

	struct mutex  mutex; /* mutex to synchronize calls to
	  * its driver.
	  */

	struct bus_type *bus;  /* type of bus device is on */
	struct device_driver *driver; /* which driver has allocated this  device */
	void  *platform_data; /* Platform specific data, device core doesn't touch it */
	struct dev_pm_info power;
	struct dev_pm_domain *pm_domain;

	#ifdef CONFIG_PINCTRL
	struct dev_pin_info *pins;
	#endif

	#ifdef CONFIG_NUMA
	int  numa_node; /* NUMA node this device is close to */
	#endif
	u64  *dma_mask; /* dma mask (if dma'able device) */
	u64  coherent_dma_mask;/* Like dma_mask, but for
		  alloc_coherent mappings as
		  not all hardware supports
		  64 bit addresses for consistent
		  allocations such descriptors. */

	struct device_dma_parameters *dma_parms;

	struct list_head dma_pools; /* dma pools (if dma'ble) */

	struct dma_coherent_mem *dma_mem; /* internal for coherent mem
		  override */
	#ifdef CONFIG_DMA_CMA
	struct cma *cma_area;  /* contiguous memory area for dma
		allocations */
	#endif
	/* arch specific additions */
	struct dev_archdata archdata;

	struct device_node *of_node; /* associated device tree node */
	struct acpi_dev_node acpi_node; /* associated ACPI device node */

	dev_t   devt; /* dev_t, creates the sysfs "dev" */
	u32   id; /* device instance */

	spinlock_t  devres_lock;
	struct list_head devres_head;

	struct klist_node knode_class;
	struct class  *class;
	const struct attribute_group **groups; /* optional groups */

	void (*release)(struct device *dev);
	struct iommu_group *iommu_group;
};

kernel\linux-3.10.y\drivers\base\base.h:

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;
	struct device *device;
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值