通常,会在驱动的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...
static ssize_t ads7846_pen_down_show(struct device *dev, struct device_attribute *attr, char *buf) { 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 ads...
struct gpio_drvdata { struct gpio_platform_data *pdata; bool gpio_state; }; static ssize_t ctrl_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gpio_drvdata *ddata = dev_get_drvdata(dev); int ret; if (ddata->gpio_state) ret = snprintf(buf, PAGE_SI...
fw_priv = dev_get_drvdata(f_dev);/*从设备结构中得到私有数据结构*/ fw_priv->fw = fw; retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data);/*在sysfs中创建可执行文件*/ ……//省略出错保护 retval = device_create_file(f_dev, &dev_attr_loading);/*在sysfs中创建一般...
struct spi_device *spi = dev_get_drvdata(dev); u8 addr = RTC_CLCK_BURST << 1 | RTC_CMD_READ; u8 buf[RTC_CLCK_LEN - 1]; int status; //spi读取时间 status = spi_write_then_read(spi, &addr, sizeof(addr), buf, sizeof(buf)); ...
driver_data :同上,驱动层可通过dev_set/get_drvdata函数来获取该成员; class :指向了该设备对应类,开篇我们提到的触摸,鼠标以及键盘等设备,对于计算机而言,他们都具有相同的功能,都归属于输入设备。我们可以在/sys/class目录下对应的类找到该设备,如input、leds、pwm等目录; dev :dev_t类型变量,字符设备章节提及...
/* /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...
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); //注册设备 if (device_register(&mtd->dev) != 0) ...
device */void*platform_data;/* Platform specific data, device core doesn't touch it */void*driver_data;/* Driver data, set and get with dev_set/get_drvdata */struct dev_pm_info power;struct dev_pm_domain*pm_domain;#ifdefCONFIG_PINCTRLstruct dev_pin_info*pins;#endif ...
* @devt: the dev_t for the char device to be added * @drvdata: the data to be added to the device for callbacks * @fmt: string for the device's name * * This function can be used by char device classes. A struct device