通常,会在驱动的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 ...
rockchip->hcd = dev_get_drvdata(&rockchip->dwc->xhci->dev) // 处理extcon属性 dwc3_rockchip_get_extcon_dev // 判断usbdrd3_0节点中是否有extcon属性 device_property_read_bool(dev, "extcon") extcon_get_edev_by_phandle // 通过引用的设备树节点获取struct extcon_dev // 设置通知的回调函数 ...
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 ...
staticssize_tads7846_pen_down_show(structdevice *dev,structdevice_attribute *attr,char*buf){structads7846*ts=dev_get_drvdata(dev);returnsprintf(buf,"%u\n", ts->pendown); }staticDEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show,NULL);staticssize_tads7846_disable_show(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...
static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *time) { struct spi_device *spi = dev_get_drvdata(dev); u8 buf[1 + RTC_CLCK_LEN]; u8 *bp; int status; /* Enable writing */ bp = buf; *bp++ = RTC_ADDR_CTRL << 1 | RTC_CMD_WRITE; ...
#define platform_get_drvdata(_dev) dev_get_drvdata(&(_dev)->dev) #define platform_set_drvdata(_dev,data) dev_set_drvdata(&(_dev)->dev, (data)) #endif /* _PLATFORM_DEVICE_H_ */ 1. 2. 3. 4. 5. 6. 7. 8. 9.
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); //注册设备 ...