aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/driver-model
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /Documentation/driver-model
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'Documentation/driver-model')
-rw-r--r--Documentation/driver-model/binding.txt4
-rw-r--r--Documentation/driver-model/device.txt65
-rw-r--r--Documentation/driver-model/devres.txt22
3 files changed, 37 insertions, 54 deletions
diff --git a/Documentation/driver-model/binding.txt b/Documentation/driver-model/binding.txt
index abfc8e290d5..f7ec9d625bf 100644
--- a/Documentation/driver-model/binding.txt
+++ b/Documentation/driver-model/binding.txt
@@ -48,6 +48,10 @@ devclass_add_device is called to enumerate the device within the class
48and actually register it with the class, which happens with the 48and actually register it with the class, which happens with the
49class's register_dev callback. 49class's register_dev callback.
50 50
51NOTE: The device class structures and core routines to manipulate them
52are not in the mainline kernel, so the discussion is still a bit
53speculative.
54
51 55
52Driver 56Driver
53~~~~~~ 57~~~~~~
diff --git a/Documentation/driver-model/device.txt b/Documentation/driver-model/device.txt
index 1e70220d20f..bdefe728a73 100644
--- a/Documentation/driver-model/device.txt
+++ b/Documentation/driver-model/device.txt
@@ -45,52 +45,33 @@ struct device_attribute {
45 const char *buf, size_t count); 45 const char *buf, size_t count);
46}; 46};
47 47
48Attributes of devices can be exported by a device driver through sysfs. 48Attributes of devices can be exported via drivers using a simple
49procfs-like interface.
49 50
50Please see Documentation/filesystems/sysfs.txt for more information 51Please see Documentation/filesystems/sysfs.txt for more information
51on how sysfs works. 52on how sysfs works.
52 53
53As explained in Documentation/kobject.txt, device attributes must be be
54created before the KOBJ_ADD uevent is generated. The only way to realize
55that is by defining an attribute group.
56
57Attributes are declared using a macro called DEVICE_ATTR: 54Attributes are declared using a macro called DEVICE_ATTR:
58 55
59#define DEVICE_ATTR(name,mode,show,store) 56#define DEVICE_ATTR(name,mode,show,store)
60 57
61Example: 58Example:
62 59
63static DEVICE_ATTR(type, 0444, show_type, NULL); 60DEVICE_ATTR(power,0644,show_power,store_power);
64static DEVICE_ATTR(power, 0644, show_power, store_power);
65
66This declares two structures of type struct device_attribute with respective
67names 'dev_attr_type' and 'dev_attr_power'. These two attributes can be
68organized as follows into a group:
69 61
70static struct attribute *dev_attrs[] = { 62This declares a structure of type struct device_attribute named
71 &dev_attr_type.attr, 63'dev_attr_power'. This can then be added and removed to the device's
72 &dev_attr_power.attr, 64directory using:
73 NULL,
74};
75
76static struct attribute_group dev_attr_group = {
77 .attrs = dev_attrs,
78};
79 65
80static const struct attribute_group *dev_attr_groups[] = { 66int device_create_file(struct device *device, struct device_attribute * entry);
81 &dev_attr_group, 67void device_remove_file(struct device * dev, struct device_attribute * attr);
82 NULL,
83};
84 68
85This array of groups can then be associated with a device by setting the 69Example:
86group pointer in struct device before device_register() is invoked:
87 70
88 dev->groups = dev_attr_groups; 71device_create_file(dev,&dev_attr_power);
89 device_register(dev); 72device_remove_file(dev,&dev_attr_power);
90 73
91The device_register() function will use the 'groups' pointer to create the 74The file name will be 'power' with a mode of 0644 (-rw-r--r--).
92device attributes and the device_unregister() function will use this pointer
93to remove the device attributes.
94 75
95Word of warning: While the kernel allows device_create_file() and 76Word of warning: While the kernel allows device_create_file() and
96device_remove_file() to be called on a device at any time, userspace has 77device_remove_file() to be called on a device at any time, userspace has
@@ -103,4 +84,24 @@ not know about the new attributes.
103This is important for device driver that need to publish additional 84This is important for device driver that need to publish additional
104attributes for a device at driver probe time. If the device driver simply 85attributes for a device at driver probe time. If the device driver simply
105calls device_create_file() on the device structure passed to it, then 86calls device_create_file() on the device structure passed to it, then
106userspace will never be notified of the new attributes. 87userspace will never be notified of the new attributes. Instead, it should
88probably use class_create() and class->dev_attrs to set up a list of
89desired attributes in the modules_init function, and then in the .probe()
90hook, and then use device_create() to create a new device as a child
91of the probed device. The new device will generate a new uevent and
92properly advertise the new attributes to userspace.
93
94For example, if a driver wanted to add the following attributes:
95struct device_attribute mydriver_attribs[] = {
96 __ATTR(port_count, 0444, port_count_show),
97 __ATTR(serial_number, 0444, serial_number_show),
98 NULL
99};
100
101Then in the module init function is would do:
102 mydriver_class = class_create(THIS_MODULE, "my_attrs");
103 mydriver_class.dev_attr = mydriver_attribs;
104
105And assuming 'dev' is the struct device passed into the probe hook, the driver
106probe function would do something like:
107 device_create(&mydriver_class, dev, chrdev, &private_data, "my_name");
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index 43cff70465a..d79aead9418 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -233,10 +233,6 @@ certainly invest a bit more effort into libata core layer).
233 6. List of managed interfaces 233 6. List of managed interfaces
234 ----------------------------- 234 -----------------------------
235 235
236MEM
237 devm_kzalloc()
238 devm_kfree()
239
240IO region 236IO region
241 devm_request_region() 237 devm_request_region()
242 devm_request_mem_region() 238 devm_request_mem_region()
@@ -266,25 +262,7 @@ IOMAP
266 devm_ioremap() 262 devm_ioremap()
267 devm_ioremap_nocache() 263 devm_ioremap_nocache()
268 devm_iounmap() 264 devm_iounmap()
269 devm_request_and_ioremap() : checks resource, requests region, ioremaps
270 pcim_iomap() 265 pcim_iomap()
271 pcim_iounmap() 266 pcim_iounmap()
272 pcim_iomap_table() : array of mapped addresses indexed by BAR 267 pcim_iomap_table() : array of mapped addresses indexed by BAR
273 pcim_iomap_regions() : do request_region() and iomap() on multiple BARs 268 pcim_iomap_regions() : do request_region() and iomap() on multiple BARs
274
275REGULATOR
276 devm_regulator_get()
277 devm_regulator_put()
278 devm_regulator_bulk_get()
279
280CLOCK
281 devm_clk_get()
282 devm_clk_put()
283
284PINCTRL
285 devm_pinctrl_get()
286 devm_pinctrl_put()
287
288PWM
289 devm_pwm_get()
290 devm_pwm_put()