aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/driver-api/driver-model/device.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/driver-api/driver-model/device.rst')
-rw-r--r--Documentation/driver-api/driver-model/device.rst27
1 files changed, 19 insertions, 8 deletions
diff --git a/Documentation/driver-api/driver-model/device.rst b/Documentation/driver-api/driver-model/device.rst
index 2b868d49d349..0833be568b06 100644
--- a/Documentation/driver-api/driver-model/device.rst
+++ b/Documentation/driver-api/driver-model/device.rst
@@ -50,10 +50,10 @@ Attributes
Attributes of devices can be exported by a device driver through sysfs.
-Please see Documentation/filesystems/sysfs.txt for more information
+Please see Documentation/filesystems/sysfs.rst for more information
on how sysfs works.
-As explained in Documentation/kobject.txt, device attributes must be
+As explained in Documentation/core-api/kobject.rst, device attributes must be
created before the KOBJ_ADD uevent is generated. The only way to realize
that is by defining an attribute group.
@@ -63,8 +63,14 @@ Attributes are declared using a macro called DEVICE_ATTR::
Example:::
- static DEVICE_ATTR(type, 0444, show_type, NULL);
- static DEVICE_ATTR(power, 0644, show_power, store_power);
+ static DEVICE_ATTR(type, 0444, type_show, NULL);
+ static DEVICE_ATTR(power, 0644, power_show, power_store);
+
+Helper macros are available for common values of mode, so the above examples
+can be simplified to:::
+
+ static DEVICE_ATTR_RO(type);
+ static DEVICE_ATTR_RW(power);
This declares two structures of type struct device_attribute with respective
names 'dev_attr_type' and 'dev_attr_power'. These two attributes can be
@@ -76,19 +82,24 @@ organized as follows into a group::
NULL,
};
- static struct attribute_group dev_attr_group = {
+ static struct attribute_group dev_group = {
.attrs = dev_attrs,
};
- static const struct attribute_group *dev_attr_groups[] = {
- &dev_attr_group,
+ static const struct attribute_group *dev_groups[] = {
+ &dev_group,
NULL,
};
+A helper macro is available for the common case of a single group, so the
+above two structures can be declared using:::
+
+ ATTRIBUTE_GROUPS(dev);
+
This array of groups can then be associated with a device by setting the
group pointer in struct device before device_register() is invoked::
- dev->groups = dev_attr_groups;
+ dev->groups = dev_groups;
device_register(dev);
The device_register() function will use the 'groups' pointer to create the