sysfs: Add sysfs_add/remove_files utility functions
[deliverable/linux.git] / include / linux / sysdev.h
CommitLineData
1da177e4
LT
1/**
2 * System devices follow a slightly different driver model.
3 * They don't need to do dynammic driver binding, can't be probed,
4 * and don't reside on any type of peripheral bus.
5 * So, we represent and treat them a little differently.
6 *
7 * We still have a notion of a driver for a system device, because we still
8 * want to perform basic operations on these devices.
9 *
10 * We also support auxillary drivers binding to devices of a certain class.
11 *
12 * This allows configurable drivers to register themselves for devices of
13 * a certain type. And, it allows class definitions to reside in generic
14 * code while arch-specific code can register specific drivers.
15 *
16 * Auxillary drivers registered with a NULL cls are registered as drivers
17 * for all system devices, and get notification calls for each device.
18 */
19
20
21#ifndef _SYSDEV_H_
22#define _SYSDEV_H_
23
24#include <linux/kobject.h>
3367b994 25#include <linux/module.h>
438510f6 26#include <linux/pm.h>
1da177e4
LT
27
28
29struct sys_device;
30
31struct sysdev_class {
af5ca3f4 32 const char *name;
1da177e4
LT
33 struct list_head drivers;
34
35 /* Default operations for these types of devices */
36 int (*shutdown)(struct sys_device *);
438510f6 37 int (*suspend)(struct sys_device *, pm_message_t state);
1da177e4
LT
38 int (*resume)(struct sys_device *);
39 struct kset kset;
40};
41
670dd90d
SL
42struct sysdev_class_attribute {
43 struct attribute attr;
c9be0a36
AK
44 ssize_t (*show)(struct sysdev_class *, struct sysdev_class_attribute *,
45 char *);
46 ssize_t (*store)(struct sysdev_class *, struct sysdev_class_attribute *,
47 const char *, size_t);
670dd90d
SL
48};
49
9d1fe323
MT
50#define _SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \
51{ \
670dd90d
SL
52 .attr = {.name = __stringify(_name), .mode = _mode }, \
53 .show = _show, \
54 .store = _store, \
9d1fe323
MT
55}
56
57#define SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \
58 struct sysdev_class_attribute attr_##_name = \
59 _SYSDEV_CLASS_ATTR(_name,_mode,_show,_store)
670dd90d 60
1da177e4
LT
61
62extern int sysdev_class_register(struct sysdev_class *);
63extern void sysdev_class_unregister(struct sysdev_class *);
64
670dd90d
SL
65extern int sysdev_class_create_file(struct sysdev_class *,
66 struct sysdev_class_attribute *);
67extern void sysdev_class_remove_file(struct sysdev_class *,
68 struct sysdev_class_attribute *);
1da177e4
LT
69/**
70 * Auxillary system device drivers.
71 */
72
73struct sysdev_driver {
74 struct list_head entry;
75 int (*add)(struct sys_device *);
76 int (*remove)(struct sys_device *);
77 int (*shutdown)(struct sys_device *);
438510f6 78 int (*suspend)(struct sys_device *, pm_message_t state);
1da177e4
LT
79 int (*resume)(struct sys_device *);
80};
81
82
83extern int sysdev_driver_register(struct sysdev_class *, struct sysdev_driver *);
84extern void sysdev_driver_unregister(struct sysdev_class *, struct sysdev_driver *);
85
86
87/**
88 * sys_devices can be simplified a lot from regular devices, because they're
89 * simply not as versatile.
90 */
91
92struct sys_device {
93 u32 id;
94 struct sysdev_class * cls;
95 struct kobject kobj;
96};
97
98extern int sysdev_register(struct sys_device *);
99extern void sysdev_unregister(struct sys_device *);
100
101
102struct sysdev_attribute {
103 struct attribute attr;
4a0b2b4d
AK
104 ssize_t (*show)(struct sys_device *, struct sysdev_attribute *, char *);
105 ssize_t (*store)(struct sys_device *, struct sysdev_attribute *,
106 const char *, size_t);
1da177e4
LT
107};
108
109
9d1fe323 110#define _SYSDEV_ATTR(_name, _mode, _show, _store) \
7583b6e4 111{ \
7b595756 112 .attr = { .name = __stringify(_name), .mode = _mode }, \
1da177e4
LT
113 .show = _show, \
114 .store = _store, \
7583b6e4
OJ
115}
116
9d1fe323
MT
117#define SYSDEV_ATTR(_name, _mode, _show, _store) \
118 struct sysdev_attribute attr_##_name = \
119 _SYSDEV_ATTR(_name, _mode, _show, _store);
1da177e4
LT
120
121extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *);
122extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *);
123
9800794a
AK
124struct sysdev_ext_attribute {
125 struct sysdev_attribute attr;
126 void *var;
127};
128
129/*
130 * Support for simple variable sysdev attributes.
131 * The pointer to the variable is stored in a sysdev_ext_attribute
132 */
133
134/* Add more types as needed */
135
136extern ssize_t sysdev_show_ulong(struct sys_device *, struct sysdev_attribute *,
137 char *);
138extern ssize_t sysdev_store_ulong(struct sys_device *,
139 struct sysdev_attribute *, const char *, size_t);
140extern ssize_t sysdev_show_int(struct sys_device *, struct sysdev_attribute *,
141 char *);
142extern ssize_t sysdev_store_int(struct sys_device *,
143 struct sysdev_attribute *, const char *, size_t);
144
145#define _SYSDEV_ULONG_ATTR(_name, _mode, _var) \
146 { _SYSDEV_ATTR(_name, _mode, sysdev_show_ulong, sysdev_store_ulong), \
147 &(_var) }
148#define SYSDEV_ULONG_ATTR(_name, _mode, _var) \
149 struct sysdev_ext_attribute attr_##_name = \
150 _SYSDEV_ULONG_ATTR(_name, _mode, _var);
151#define _SYSDEV_INT_ATTR(_name, _mode, _var) \
152 { _SYSDEV_ATTR(_name, _mode, sysdev_show_int, sysdev_store_int), \
153 &(_var) }
154#define SYSDEV_INT_ATTR(_name, _mode, _var) \
155 struct sysdev_ext_attribute attr_##_name = \
156 _SYSDEV_INT_ATTR(_name, _mode, _var);
157
1da177e4 158#endif /* _SYSDEV_H_ */
This page took 0.854995 seconds and 5 git commands to generate.