通常,会在驱动的probe函数中获取device的相关信息,然后使用 platform_set_drvdata进行保存。在其他函数中要用到时(比如remove),通过platform_get_drvdata来获取。 内核中的定义为: #define platform_get_drvdata(_dev)dev_get_drvdata(&(_dev)->dev) #define platform_set_drvdata(_dev,data)dev_set_drvdata...
struct ads7846 *ts = dev_get_drvdata(dev); return sprintf(buf, "%u\n", ts->pendown); } static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL); static ssize_t ads7846_disable_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ads7846 *ts ...
if (!dev_name(dev)) { //设置device的name域,如果设置失败退出。 error = -EINVAL; goto name_error; } pr_debug("device: '%s': %s\n", dev_name(dev), __func__); parent = get_device(dev->parent); //增加设备parent的引用计数 kobj = get_device_parent(dev, parent); //设置设备paren...
}staticDEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show,NULL);staticssize_tads7846_disable_show(structdevice *dev,structdevice_attribute *attr,char*buf){structads7846*ts=dev_get_drvdata(dev);returnsprintf(buf,"%u\n", ts->disabled); }staticssize_tads7846_disable_store(structdevice *...
/* /drivers/base/dd.c */intdev_set_drvdata(struct device*dev,void*data){int error;if(!dev->p){error=device_private_init(dev);if(error)returnerror;}dev->p->driver_data=data;return0;} /* /linux/device.h */struct device{struct device*parent;struct device_private*p;struct kobject ko...
struct miscdevice *c = dev_get_drvdata(dev); if (mode && c->mode) *mode = c->mode; if (c->nodename) return kstrdup(c->nodename, GFP_KERNEL); return NULL; } static int __init misc_init(void) { int err; #ifdef CONFIG_PROC_FS ...
struct m25p *flash = dev_get_drvdata(&spi->dev); int status; /* Clean up MTD stuff. */ status = mtd_device_unregister(&flash->mtd); if (status == 0) { kfree(flash->command); kfree(flash); } return 0; } static struct spi_driver m25p80_driver = { ...
dev_tdev,void*drvdata,constchar*fmt,...);voiddevice_destroy(structclass*class,dev_tdevt);...
mousedev_connect在/drivers/input/mousedev.c中 static int mousedev_connect(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id) { struct mousedev *mousedev; int minor; int error; //历遍mousedev_table数组,寻找一个为空的位置 ...
mtd->dev.type = &mtd_devtype; mtd->dev.class = &mtd_class; mtd->dev.devt = MTD_DEVT(i); //设置mtd设备名 dev_set_name(&mtd->dev, "mtd%d", i); //设置mtd设备信息mtd_info dev_set_drvdata(&mtd->dev, mtd); //注册设备 ...