Subversion Repositories shark

Rev

Rev 422 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
847 giacomo 1
/*
2
 * device.h - generic, centralized driver model
3
 *
4
 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
5
 *
6
 * This file is released under the GPLv2
7
 *
8
 * See Documentation/driver-model/ for more information.
9
 */
10
 
11
#ifndef _DEVICE_H_
12
#define _DEVICE_H_
13
 
14
#include <linux/config.h>
15
#include <linux/ioport.h>
16
#include <linux/kobject.h>
17
#include <linux/list.h>
18
#include <linux/spinlock.h>
19
#include <linux/types.h>
20
#include <linux/ioport.h>
21
#include <linux/module.h>
22
#include <linux/pm.h>
23
#include <asm/semaphore.h>
24
#include <asm/atomic.h>
25
 
26
#define DEVICE_NAME_SIZE        50
27
#define DEVICE_NAME_HALF        __stringify(20) /* Less than half to accommodate slop */
28
#define DEVICE_ID_SIZE          32
29
#define BUS_ID_SIZE             KOBJ_NAME_LEN
30
 
31
 
32
enum {
33
        SUSPEND_NOTIFY,
34
        SUSPEND_SAVE_STATE,
35
        SUSPEND_DISABLE,
36
        SUSPEND_POWER_DOWN,
37
};
38
 
39
enum {
40
        RESUME_POWER_ON,
41
        RESUME_RESTORE_STATE,
42
        RESUME_ENABLE,
43
};
44
 
45
struct device;
46
struct device_driver;
47
struct class;
48
struct class_device;
49
 
50
struct bus_type {
51
        char                    * name;
52
 
53
        struct subsystem        subsys;
54
        struct kset             drivers;
55
        struct kset             devices;
56
 
57
        int             (*match)(struct device * dev, struct device_driver * drv);
58
        struct device * (*add)  (struct device * parent, char * bus_id);
59
        int             (*hotplug) (struct device *dev, char **envp,
60
                                    int num_envp, char *buffer, int buffer_size);
61
        int             (*suspend)(struct device * dev, u32 state);
62
        int             (*resume)(struct device * dev);
63
};
64
 
65
extern int bus_register(struct bus_type * bus);
66
extern void bus_unregister(struct bus_type * bus);
67
 
68
extern int bus_rescan_devices(struct bus_type * bus);
69
 
70
extern struct bus_type * get_bus(struct bus_type * bus);
71
extern void put_bus(struct bus_type * bus);
72
 
73
extern struct bus_type * find_bus(char * name);
74
 
75
/* iterator helpers for buses */
76
 
77
int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
78
                     int (*fn)(struct device *, void *));
79
 
80
int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
81
                     void * data, int (*fn)(struct device_driver *, void *));
82
 
83
 
84
/* driverfs interface for exporting bus attributes */
85
 
86
struct bus_attribute {
87
        struct attribute        attr;
88
        ssize_t (*show)(struct bus_type *, char * buf);
89
        ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
90
};
91
 
92
#define BUS_ATTR(_name,_mode,_show,_store)      \
93
struct bus_attribute bus_attr_##_name = {               \
94
        .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
95
        .show   = _show,                                \
96
        .store  = _store,                               \
97
};
98
 
99
extern int bus_create_file(struct bus_type *, struct bus_attribute *);
100
extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
101
 
102
struct device_driver {
103
        char                    * name;
104
        struct bus_type         * bus;
105
 
106
        struct semaphore        unload_sem;
107
        struct kobject          kobj;
108
        struct list_head        devices;
109
 
110
        int     (*probe)        (struct device * dev);
111
        int     (*remove)       (struct device * dev);
112
        void    (*shutdown)     (struct device * dev);
113
        int     (*suspend)      (struct device * dev, u32 state, u32 level);
114
        int     (*resume)       (struct device * dev, u32 level);
115
};
116
 
117
 
118
extern int driver_register(struct device_driver * drv);
119
extern void driver_unregister(struct device_driver * drv);
120
 
121
extern struct device_driver * get_driver(struct device_driver * drv);
122
extern void put_driver(struct device_driver * drv);
123
 
124
 
125
/* driverfs interface for exporting driver attributes */
126
 
127
struct driver_attribute {
128
        struct attribute        attr;
129
        ssize_t (*show)(struct device_driver *, char * buf);
130
        ssize_t (*store)(struct device_driver *, const char * buf, size_t count);
131
};
132
 
133
#define DRIVER_ATTR(_name,_mode,_show,_store)   \
134
struct driver_attribute driver_attr_##_name = {                 \
135
        .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
136
        .show   = _show,                                \
137
        .store  = _store,                               \
138
};
139
 
140
extern int driver_create_file(struct device_driver *, struct driver_attribute *);
141
extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
142
 
143
 
144
/*
145
 * device classes
146
 */
147
struct class {
148
        char                    * name;
149
 
150
        struct subsystem        subsys;
151
        struct list_head        children;
152
        struct list_head        interfaces;
153
 
154
        int     (*hotplug)(struct class_device *dev, char **envp,
155
                           int num_envp, char *buffer, int buffer_size);
156
 
157
        void    (*release)(struct class_device *dev);
158
};
159
 
160
extern int class_register(struct class *);
161
extern void class_unregister(struct class *);
162
 
163
extern struct class * class_get(struct class *);
164
extern void class_put(struct class *);
165
 
166
 
167
struct class_attribute {
168
        struct attribute        attr;
169
        ssize_t (*show)(struct class *, char * buf);
170
        ssize_t (*store)(struct class *, const char * buf, size_t count);
171
};
172
 
173
#define CLASS_ATTR(_name,_mode,_show,_store)                    \
174
struct class_attribute class_attr_##_name = {                   \
175
        .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
176
        .show   = _show,                                        \
177
        .store  = _store,                                       \
178
};
179
 
180
extern int class_create_file(struct class *, const struct class_attribute *);
181
extern void class_remove_file(struct class *, const struct class_attribute *);
182
 
183
 
184
struct class_device {
185
        struct list_head        node;
186
 
187
        struct kobject          kobj;
188
        struct class            * class;        /* required */
189
        struct device           * dev;          /* not necessary, but nice to have */
190
        void                    * class_data;   /* class-specific data */
191
 
192
        char    class_id[BUS_ID_SIZE];  /* unique to this class */
193
};
194
 
195
static inline void *
196
class_get_devdata (struct class_device *dev)
197
{
198
        return dev->class_data;
199
}
200
 
201
static inline void
202
class_set_devdata (struct class_device *dev, void *data)
203
{
204
        dev->class_data = data;
205
}
206
 
207
 
208
extern int class_device_register(struct class_device *);
209
extern void class_device_unregister(struct class_device *);
210
extern void class_device_initialize(struct class_device *);
211
extern int class_device_add(struct class_device *);
212
extern void class_device_del(struct class_device *);
213
 
214
extern int class_device_rename(struct class_device *, char *);
215
 
216
extern struct class_device * class_device_get(struct class_device *);
217
extern void class_device_put(struct class_device *);
218
 
219
struct class_device_attribute {
220
        struct attribute        attr;
221
        ssize_t (*show)(struct class_device *, char * buf);
222
        ssize_t (*store)(struct class_device *, const char * buf, size_t count);
223
};
224
 
225
#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store)             \
226
struct class_device_attribute class_device_attr_##_name = {     \
227
        .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
228
        .show   = _show,                                        \
229
        .store  = _store,                                       \
230
};
231
 
232
extern int class_device_create_file(struct class_device *,
233
                                    const struct class_device_attribute *);
234
extern void class_device_remove_file(struct class_device *,
235
                                     const struct class_device_attribute *);
236
 
237
 
238
struct class_interface {
239
        struct list_head        node;
240
        struct class            *class;
241
 
242
        int (*add)      (struct class_device *);
243
        void (*remove)  (struct class_device *);
244
};
245
 
246
extern int class_interface_register(struct class_interface *);
247
extern void class_interface_unregister(struct class_interface *);
248
 
249
 
250
struct device {
251
        struct list_head node;          /* node in sibling list */
252
        struct list_head bus_list;      /* node in bus's list */
253
        struct list_head driver_list;
254
        struct list_head children;
255
        struct device   * parent;
256
 
257
        struct completion * complete;   /* Notification for freeing device. */
258
        struct kobject kobj;
259
        char    bus_id[BUS_ID_SIZE];    /* position on parent bus */
260
 
261
        struct bus_type * bus;          /* type of bus device is on */
262
        struct device_driver *driver;   /* which driver has allocated this
263
                                           device */
264
        void            *driver_data;   /* data private to the driver */
265
        void            *platform_data; /* Platform specific data (e.g. ACPI,
266
                                           BIOS data relevant to device) */
267
        struct dev_pm_info      power;
268
        u32             power_state;    /* Current operating state. In
269
                                           ACPI-speak, this is D0-D3, D0
270
                                           being fully functional, and D3
271
                                           being off. */
272
 
273
        unsigned char *saved_state;     /* saved device state */
274
        u32             detach_state;   /* State to enter when device is
275
                                           detached from its driver. */
276
 
277
        u64             *dma_mask;      /* dma mask (if dma'able device) */
278
 
279
        void    (*release)(struct device * dev);
280
};
281
 
282
static inline struct device *
283
list_to_dev(struct list_head *node)
284
{
285
        return list_entry(node, struct device, node);
286
}
287
 
288
static inline void *
289
dev_get_drvdata (struct device *dev)
290
{
291
        return dev->driver_data;
292
}
293
 
294
static inline void
295
dev_set_drvdata (struct device *dev, void *data)
296
{
297
        dev->driver_data = data;
298
}
299
 
300
/*
301
 * High level routines for use by the bus drivers
302
 */
303
extern int device_register(struct device * dev);
304
extern void device_unregister(struct device * dev);
305
extern void device_unregister_wait(struct device * dev);
306
extern void device_initialize(struct device * dev);
307
extern int device_add(struct device * dev);
308
extern void device_del(struct device * dev);
309
extern int device_for_each_child(struct device *, void *,
310
                     int (*fn)(struct device *, void *));
311
 
312
/*
313
 * Manual binding of a device to driver. See drivers/base/bus.c
314
 * for information on use.
315
 */
316
extern void device_bind_driver(struct device * dev);
317
extern void device_release_driver(struct device * dev);
318
extern void driver_attach(struct device_driver * drv);
319
 
320
 
321
/* driverfs interface for exporting device attributes */
322
 
323
struct device_attribute {
324
        struct attribute        attr;
325
        ssize_t (*show)(struct device * dev, char * buf);
326
        ssize_t (*store)(struct device * dev, const char * buf, size_t count);
327
};
328
 
329
#define DEVICE_ATTR(_name,_mode,_show,_store) \
330
struct device_attribute dev_attr_##_name = {            \
331
        .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
332
        .show   = _show,                                \
333
        .store  = _store,                               \
334
};
335
 
336
 
337
extern int device_create_file(struct device *device, struct device_attribute * entry);
338
extern void device_remove_file(struct device * dev, struct device_attribute * attr);
339
 
340
/*
341
 * Platform "fixup" functions - allow the platform to have their say
342
 * about devices and actions that the general device layer doesn't
343
 * know about.
344
 */
345
/* Notify platform of device discovery */
346
extern int (*platform_notify)(struct device * dev);
347
 
348
extern int (*platform_notify_remove)(struct device * dev);
349
 
350
 
351
/**
352
 * get_device - atomically increment the reference count for the device.
353
 *
354
 */
355
extern struct device * get_device(struct device * dev);
356
extern void put_device(struct device * dev);
357
 
358
 
359
/* drivers/base/platform.c */
360
 
361
struct platform_device {
362
        char            * name;
363
        u32             id;
364
        struct device   dev;
365
        u32             num_resources;
366
        struct resource * resource;
367
};
368
 
369
#define to_platform_device(x) container_of((x), struct platform_device, dev)
370
 
371
extern int platform_device_register(struct platform_device *);
372
extern void platform_device_unregister(struct platform_device *);
373
 
374
extern struct bus_type platform_bus_type;
375
extern struct device legacy_bus;
376
 
377
/* drivers/base/power.c */
378
extern void device_shutdown(void);
379
 
380
 
381
/* drivers/base/firmware.c */
382
extern int firmware_register(struct subsystem *);
383
extern void firmware_unregister(struct subsystem *);
384
 
385
/* debugging and troubleshooting/diagnostic helpers. */
386
#define dev_printk(level, dev, format, arg...)  \
387
        printk(level "%s %s: " format , (dev)->driver->name , (dev)->bus_id , ## arg)
388
 
389
#ifdef DEBUG
390
#define dev_dbg(dev, format, arg...)            \
391
        dev_printk(KERN_DEBUG , dev , format , ## arg)
392
#else
393
#define dev_dbg(dev, format, arg...) do {} while (0)
394
#endif
395
 
396
#ifdef DEBUG //** for shark usb 
397
 
398
#define dev_err(dev, format, arg...)            \
399
        dev_printk(KERN_ERR , dev , format , ## arg)
400
#define dev_info(dev, format, arg...)           \
401
        dev_printk(KERN_INFO , dev , format , ## arg)
402
#define dev_warn(dev, format, arg...)           \
403
        dev_printk(KERN_WARNING , dev , format , ## arg)
404
 
405
#else
406
 
407
#define dev_err(dev, format, arg...)
408
#define dev_info(dev, format, arg...)
409
#define dev_warn(dev, format, arg...)
410
 
411
#endif
412
 
413
/* Create alias, so I can be autoloaded. */
414
#define MODULE_ALIAS_CHARDEV(major,minor) \
415
        MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
416
#define MODULE_ALIAS_CHARDEV_MAJOR(major) \
417
        MODULE_ALIAS("char-major-" __stringify(major) "-*")
418
#endif /* _DEVICE_H_ */