diff options
Diffstat (limited to 'include/linux/device.h')
-rw-r--r-- | include/linux/device.h | 146 |
1 files changed, 71 insertions, 75 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index 06e5d42f2c7b..17cbc6db67b4 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -28,19 +28,6 @@ | |||
28 | #define BUS_ID_SIZE KOBJ_NAME_LEN | 28 | #define BUS_ID_SIZE KOBJ_NAME_LEN |
29 | 29 | ||
30 | 30 | ||
31 | enum { | ||
32 | SUSPEND_NOTIFY, | ||
33 | SUSPEND_SAVE_STATE, | ||
34 | SUSPEND_DISABLE, | ||
35 | SUSPEND_POWER_DOWN, | ||
36 | }; | ||
37 | |||
38 | enum { | ||
39 | RESUME_POWER_ON, | ||
40 | RESUME_RESTORE_STATE, | ||
41 | RESUME_ENABLE, | ||
42 | }; | ||
43 | |||
44 | struct device; | 31 | struct device; |
45 | struct device_driver; | 32 | struct device_driver; |
46 | struct class; | 33 | struct class; |
@@ -115,8 +102,8 @@ struct device_driver { | |||
115 | int (*probe) (struct device * dev); | 102 | int (*probe) (struct device * dev); |
116 | int (*remove) (struct device * dev); | 103 | int (*remove) (struct device * dev); |
117 | void (*shutdown) (struct device * dev); | 104 | void (*shutdown) (struct device * dev); |
118 | int (*suspend) (struct device * dev, pm_message_t state, u32 level); | 105 | int (*suspend) (struct device * dev, pm_message_t state); |
119 | int (*resume) (struct device * dev, u32 level); | 106 | int (*resume) (struct device * dev); |
120 | }; | 107 | }; |
121 | 108 | ||
122 | 109 | ||
@@ -190,7 +177,43 @@ struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store) | |||
190 | extern int class_create_file(struct class *, const struct class_attribute *); | 177 | extern int class_create_file(struct class *, const struct class_attribute *); |
191 | extern void class_remove_file(struct class *, const struct class_attribute *); | 178 | extern void class_remove_file(struct class *, const struct class_attribute *); |
192 | 179 | ||
180 | struct class_device_attribute { | ||
181 | struct attribute attr; | ||
182 | ssize_t (*show)(struct class_device *, char * buf); | ||
183 | ssize_t (*store)(struct class_device *, const char * buf, size_t count); | ||
184 | }; | ||
185 | |||
186 | #define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \ | ||
187 | struct class_device_attribute class_device_attr_##_name = \ | ||
188 | __ATTR(_name,_mode,_show,_store) | ||
193 | 189 | ||
190 | extern int class_device_create_file(struct class_device *, | ||
191 | const struct class_device_attribute *); | ||
192 | |||
193 | /** | ||
194 | * struct class_device - class devices | ||
195 | * @class: pointer to the parent class for this class device. This is required. | ||
196 | * @devt: for internal use by the driver core only. | ||
197 | * @node: for internal use by the driver core only. | ||
198 | * @kobj: for internal use by the driver core only. | ||
199 | * @devt_attr: for internal use by the driver core only. | ||
200 | * @dev: if set, a symlink to the struct device is created in the sysfs | ||
201 | * directory for this struct class device. | ||
202 | * @class_data: pointer to whatever you want to store here for this struct | ||
203 | * class_device. Use class_get_devdata() and class_set_devdata() to get and | ||
204 | * set this pointer. | ||
205 | * @parent: pointer to a struct class_device that is the parent of this struct | ||
206 | * class_device. If NULL, this class_device will show up at the root of the | ||
207 | * struct class in sysfs (which is probably what you want to have happen.) | ||
208 | * @release: pointer to a release function for this struct class_device. If | ||
209 | * set, this will be called instead of the class specific release function. | ||
210 | * Only use this if you want to override the default release function, like | ||
211 | * when you are nesting class_device structures. | ||
212 | * @hotplug: pointer to a hotplug function for this struct class_device. If | ||
213 | * set, this will be called instead of the class specific hotplug function. | ||
214 | * Only use this if you want to override the default hotplug function, like | ||
215 | * when you are nesting class_device structures. | ||
216 | */ | ||
194 | struct class_device { | 217 | struct class_device { |
195 | struct list_head node; | 218 | struct list_head node; |
196 | 219 | ||
@@ -198,9 +221,14 @@ struct class_device { | |||
198 | struct class * class; /* required */ | 221 | struct class * class; /* required */ |
199 | dev_t devt; /* dev_t, creates the sysfs "dev" */ | 222 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
200 | struct class_device_attribute *devt_attr; | 223 | struct class_device_attribute *devt_attr; |
224 | struct class_device_attribute uevent_attr; | ||
201 | struct device * dev; /* not necessary, but nice to have */ | 225 | struct device * dev; /* not necessary, but nice to have */ |
202 | void * class_data; /* class-specific data */ | 226 | void * class_data; /* class-specific data */ |
227 | struct class_device *parent; /* parent of this child device, if there is one */ | ||
203 | 228 | ||
229 | void (*release)(struct class_device *dev); | ||
230 | int (*hotplug)(struct class_device *dev, char **envp, | ||
231 | int num_envp, char *buffer, int buffer_size); | ||
204 | char class_id[BUS_ID_SIZE]; /* unique to this class */ | 232 | char class_id[BUS_ID_SIZE]; /* unique to this class */ |
205 | }; | 233 | }; |
206 | 234 | ||
@@ -228,18 +256,6 @@ extern int class_device_rename(struct class_device *, char *); | |||
228 | extern struct class_device * class_device_get(struct class_device *); | 256 | extern struct class_device * class_device_get(struct class_device *); |
229 | extern void class_device_put(struct class_device *); | 257 | extern void class_device_put(struct class_device *); |
230 | 258 | ||
231 | struct class_device_attribute { | ||
232 | struct attribute attr; | ||
233 | ssize_t (*show)(struct class_device *, char * buf); | ||
234 | ssize_t (*store)(struct class_device *, const char * buf, size_t count); | ||
235 | }; | ||
236 | |||
237 | #define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \ | ||
238 | struct class_device_attribute class_device_attr_##_name = \ | ||
239 | __ATTR(_name,_mode,_show,_store) | ||
240 | |||
241 | extern int class_device_create_file(struct class_device *, | ||
242 | const struct class_device_attribute *); | ||
243 | extern void class_device_remove_file(struct class_device *, | 259 | extern void class_device_remove_file(struct class_device *, |
244 | const struct class_device_attribute *); | 260 | const struct class_device_attribute *); |
245 | extern int class_device_create_bin_file(struct class_device *, | 261 | extern int class_device_create_bin_file(struct class_device *, |
@@ -251,8 +267,8 @@ struct class_interface { | |||
251 | struct list_head node; | 267 | struct list_head node; |
252 | struct class *class; | 268 | struct class *class; |
253 | 269 | ||
254 | int (*add) (struct class_device *); | 270 | int (*add) (struct class_device *, struct class_interface *); |
255 | void (*remove) (struct class_device *); | 271 | void (*remove) (struct class_device *, struct class_interface *); |
256 | }; | 272 | }; |
257 | 273 | ||
258 | extern int class_interface_register(struct class_interface *); | 274 | extern int class_interface_register(struct class_interface *); |
@@ -260,12 +276,29 @@ extern void class_interface_unregister(struct class_interface *); | |||
260 | 276 | ||
261 | extern struct class *class_create(struct module *owner, char *name); | 277 | extern struct class *class_create(struct module *owner, char *name); |
262 | extern void class_destroy(struct class *cls); | 278 | extern void class_destroy(struct class *cls); |
263 | extern struct class_device *class_device_create(struct class *cls, dev_t devt, | 279 | extern struct class_device *class_device_create(struct class *cls, |
264 | struct device *device, char *fmt, ...) | 280 | struct class_device *parent, |
265 | __attribute__((format(printf,4,5))); | 281 | dev_t devt, |
282 | struct device *device, | ||
283 | char *fmt, ...) | ||
284 | __attribute__((format(printf,5,6))); | ||
266 | extern void class_device_destroy(struct class *cls, dev_t devt); | 285 | extern void class_device_destroy(struct class *cls, dev_t devt); |
267 | 286 | ||
268 | 287 | ||
288 | /* interface for exporting device attributes */ | ||
289 | struct device_attribute { | ||
290 | struct attribute attr; | ||
291 | ssize_t (*show)(struct device *dev, struct device_attribute *attr, | ||
292 | char *buf); | ||
293 | ssize_t (*store)(struct device *dev, struct device_attribute *attr, | ||
294 | const char *buf, size_t count); | ||
295 | }; | ||
296 | |||
297 | #define DEVICE_ATTR(_name,_mode,_show,_store) \ | ||
298 | struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store) | ||
299 | |||
300 | extern int device_create_file(struct device *device, struct device_attribute * entry); | ||
301 | extern void device_remove_file(struct device * dev, struct device_attribute * attr); | ||
269 | struct device { | 302 | struct device { |
270 | struct klist klist_children; | 303 | struct klist klist_children; |
271 | struct klist_node knode_parent; /* node in sibling list */ | 304 | struct klist_node knode_parent; /* node in sibling list */ |
@@ -275,6 +308,7 @@ struct device { | |||
275 | 308 | ||
276 | struct kobject kobj; | 309 | struct kobject kobj; |
277 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ | 310 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ |
311 | struct device_attribute uevent_attr; | ||
278 | 312 | ||
279 | struct semaphore sem; /* semaphore to synchronize calls to | 313 | struct semaphore sem; /* semaphore to synchronize calls to |
280 | * its driver. | 314 | * its driver. |
@@ -317,6 +351,11 @@ dev_set_drvdata (struct device *dev, void *data) | |||
317 | dev->driver_data = data; | 351 | dev->driver_data = data; |
318 | } | 352 | } |
319 | 353 | ||
354 | static inline int device_is_registered(struct device *dev) | ||
355 | { | ||
356 | return klist_node_attached(&dev->knode_bus); | ||
357 | } | ||
358 | |||
320 | /* | 359 | /* |
321 | * High level routines for use by the bus drivers | 360 | * High level routines for use by the bus drivers |
322 | */ | 361 | */ |
@@ -338,23 +377,6 @@ extern int device_attach(struct device * dev); | |||
338 | extern void driver_attach(struct device_driver * drv); | 377 | extern void driver_attach(struct device_driver * drv); |
339 | 378 | ||
340 | 379 | ||
341 | /* driverfs interface for exporting device attributes */ | ||
342 | |||
343 | struct device_attribute { | ||
344 | struct attribute attr; | ||
345 | ssize_t (*show)(struct device *dev, struct device_attribute *attr, | ||
346 | char *buf); | ||
347 | ssize_t (*store)(struct device *dev, struct device_attribute *attr, | ||
348 | const char *buf, size_t count); | ||
349 | }; | ||
350 | |||
351 | #define DEVICE_ATTR(_name,_mode,_show,_store) \ | ||
352 | struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store) | ||
353 | |||
354 | |||
355 | extern int device_create_file(struct device *device, struct device_attribute * entry); | ||
356 | extern void device_remove_file(struct device * dev, struct device_attribute * attr); | ||
357 | |||
358 | /* | 380 | /* |
359 | * Platform "fixup" functions - allow the platform to have their say | 381 | * Platform "fixup" functions - allow the platform to have their say |
360 | * about devices and actions that the general device layer doesn't | 382 | * about devices and actions that the general device layer doesn't |
@@ -374,32 +396,6 @@ extern struct device * get_device(struct device * dev); | |||
374 | extern void put_device(struct device * dev); | 396 | extern void put_device(struct device * dev); |
375 | 397 | ||
376 | 398 | ||
377 | /* drivers/base/platform.c */ | ||
378 | |||
379 | struct platform_device { | ||
380 | const char * name; | ||
381 | u32 id; | ||
382 | struct device dev; | ||
383 | u32 num_resources; | ||
384 | struct resource * resource; | ||
385 | }; | ||
386 | |||
387 | #define to_platform_device(x) container_of((x), struct platform_device, dev) | ||
388 | |||
389 | extern int platform_device_register(struct platform_device *); | ||
390 | extern void platform_device_unregister(struct platform_device *); | ||
391 | |||
392 | extern struct bus_type platform_bus_type; | ||
393 | extern struct device platform_bus; | ||
394 | |||
395 | extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int); | ||
396 | extern int platform_get_irq(struct platform_device *, unsigned int); | ||
397 | extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, char *); | ||
398 | extern int platform_get_irq_byname(struct platform_device *, char *); | ||
399 | extern int platform_add_devices(struct platform_device **, int); | ||
400 | |||
401 | extern struct platform_device *platform_device_register_simple(char *, unsigned int, struct resource *, unsigned int); | ||
402 | |||
403 | /* drivers/base/power.c */ | 399 | /* drivers/base/power.c */ |
404 | extern void device_shutdown(void); | 400 | extern void device_shutdown(void); |
405 | 401 | ||