fbdev: move FBIO_WAITFORVSYNC to linux/fb.h
[safe/jmp/linux-2.6] / include / linux / device.h
index 4e14fad..0713e10 100644 (file)
@@ -2,7 +2,8 @@
  * device.h - generic, centralized driver model
  *
  * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
- * Copyright (c) 2004-2007 Greg Kroah-Hartman <gregkh@suse.de>
+ * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
+ * Copyright (c) 2008-2009 Novell Inc.
  *
  * This file is released under the GPLv2
  *
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/semaphore.h>
 #include <asm/atomic.h>
 #include <asm/device.h>
 
-#define BUS_ID_SIZE            20
-
 struct device;
+struct device_private;
 struct device_driver;
 struct driver_private;
 struct class;
 struct class_private;
 struct bus_type;
 struct bus_type_private;
+struct device_node;
 
 struct bus_attribute {
        struct attribute        attr;
@@ -61,11 +61,9 @@ struct bus_type {
        void (*shutdown)(struct device *dev);
 
        int (*suspend)(struct device *dev, pm_message_t state);
-       int (*suspend_late)(struct device *dev, pm_message_t state);
-       int (*resume_early)(struct device *dev);
        int (*resume)(struct device *dev);
 
-       struct dev_pm_ops *pm;
+       const struct dev_pm_ops *pm;
 
        struct bus_type_private *p;
 };
@@ -108,13 +106,15 @@ extern int bus_unregister_notifier(struct bus_type *bus,
 
 /* All 4 notifers below get called with the target struct device *
  * as an argument. Note that those functions are likely to be called
- * with the device semaphore held in the core, so be careful.
+ * with the device lock held in the core, so be careful.
  */
 #define BUS_NOTIFY_ADD_DEVICE          0x00000001 /* device added */
 #define BUS_NOTIFY_DEL_DEVICE          0x00000002 /* device removed */
 #define BUS_NOTIFY_BOUND_DRIVER                0x00000003 /* driver bound to device */
 #define BUS_NOTIFY_UNBIND_DRIVER       0x00000004 /* driver about to be
                                                      unbound */
+#define BUS_NOTIFY_UNBOUND_DRIVER      0x00000005 /* driver is unbound
+                                                     from the device */
 
 extern struct kset *bus_get_kset(struct bus_type *bus);
 extern struct klist *bus_get_device_klist(struct bus_type *bus);
@@ -124,16 +124,22 @@ struct device_driver {
        struct bus_type         *bus;
 
        struct module           *owner;
-       const char              *mod_name;      /* used for built-in modules */
+       const char              *mod_name;      /* used for built-in modules */
+
+       bool suppress_bind_attrs;       /* disables bind/unbind via sysfs */
+
+#if defined(CONFIG_OF)
+       const struct of_device_id       *of_match_table;
+#endif
 
        int (*probe) (struct device *dev);
        int (*remove) (struct device *dev);
        void (*shutdown) (struct device *dev);
        int (*suspend) (struct device *dev, pm_message_t state);
        int (*resume) (struct device *dev);
-       struct attribute_group **groups;
+       const struct attribute_group **groups;
 
-       struct dev_pm_ops *pm;
+       const struct dev_pm_ops *pm;
 
        struct driver_private *p;
 };
@@ -147,6 +153,8 @@ extern void put_driver(struct device_driver *drv);
 extern struct device_driver *driver_find(const char *name,
                                         struct bus_type *bus);
 extern int driver_probe_done(void);
+extern void wait_for_device_probe(void);
+
 
 /* sysfs interface for exporting driver attributes */
 
@@ -162,9 +170,9 @@ struct driver_attribute driver_attr_##_name =               \
        __ATTR(_name, _mode, _show, _store)
 
 extern int __must_check driver_create_file(struct device_driver *driver,
-                                          struct driver_attribute *attr);
+                                       const struct driver_attribute *attr);
 extern void driver_remove_file(struct device_driver *driver,
-                              struct driver_attribute *attr);
+                              const struct driver_attribute *attr);
 
 extern int __must_check driver_add_kobj(struct device_driver *drv,
                                        struct kobject *kobj,
@@ -191,6 +199,7 @@ struct class {
        struct kobject                  *dev_kobj;
 
        int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
+       char *(*devnode)(struct device *dev, mode_t *mode);
 
        void (*class_release)(struct class *class);
        void (*dev_release)(struct device *dev);
@@ -198,7 +207,11 @@ struct class {
        int (*suspend)(struct device *dev, pm_message_t state);
        int (*resume)(struct device *dev);
 
-       struct dev_pm_ops *pm;
+       const struct kobj_ns_type_operations *ns_type;
+       const void *(*namespace)(struct device *dev);
+
+       const struct dev_pm_ops *pm;
+
        struct class_private *p;
 };
 
@@ -221,6 +234,14 @@ extern void class_unregister(struct class *class);
        __class_register(class, &__key);        \
 })
 
+struct class_compat;
+struct class_compat *class_compat_register(const char *name);
+void class_compat_unregister(struct class_compat *cls);
+int class_compat_create_link(struct class_compat *cls, struct device *dev,
+                            struct device *device_link);
+void class_compat_remove_link(struct class_compat *cls, struct device *dev,
+                             struct device *device_link);
+
 extern void class_dev_iter_init(struct class_dev_iter *iter,
                                struct class *class,
                                struct device *start,
@@ -237,8 +258,10 @@ extern struct device *class_find_device(struct class *class,
 
 struct class_attribute {
        struct attribute attr;
-       ssize_t (*show)(struct class *class, char *buf);
-       ssize_t (*store)(struct class *class, const char *buf, size_t count);
+       ssize_t (*show)(struct class *class, struct class_attribute *attr,
+                       char *buf);
+       ssize_t (*store)(struct class *class, struct class_attribute *attr,
+                       const char *buf, size_t count);
 };
 
 #define CLASS_ATTR(_name, _mode, _show, _store)                        \
@@ -249,6 +272,23 @@ extern int __must_check class_create_file(struct class *class,
 extern void class_remove_file(struct class *class,
                              const struct class_attribute *attr);
 
+/* Simple class attribute that is just a static string */
+
+struct class_attribute_string {
+       struct class_attribute attr;
+       char *str;
+};
+
+/* Currently read-only only */
+#define _CLASS_ATTR_STRING(_name, _mode, _str) \
+       { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
+#define CLASS_ATTR_STRING(_name, _mode, _str) \
+       struct class_attribute_string class_attr_##_name = \
+               _CLASS_ATTR_STRING(_name, _mode, _str)
+
+extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
+                        char *buf);
+
 struct class_interface {
        struct list_head        node;
        struct class            *class;
@@ -284,14 +324,12 @@ extern void class_destroy(struct class *cls);
  */
 struct device_type {
        const char *name;
-       struct attribute_group **groups;
+       const struct attribute_group **groups;
        int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
+       char *(*devnode)(struct device *dev, mode_t *mode);
        void (*release)(struct device *dev);
 
-       int (*suspend)(struct device *dev, pm_message_t state);
-       int (*resume)(struct device *dev);
-
-       struct dev_pm_ops *pm;
+       const struct dev_pm_ops *pm;
 };
 
 /* interface for exporting device attributes */
@@ -307,13 +345,13 @@ struct device_attribute {
 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
 
 extern int __must_check device_create_file(struct device *device,
-                                          struct device_attribute *entry);
+                                       const struct device_attribute *entry);
 extern void device_remove_file(struct device *dev,
-                              struct device_attribute *attr);
+                              const struct device_attribute *attr);
 extern int __must_check device_create_bin_file(struct device *dev,
-                                              struct bin_attribute *attr);
+                                       const struct bin_attribute *attr);
 extern void device_remove_bin_file(struct device *dev,
-                                  struct bin_attribute *attr);
+                                  const struct bin_attribute *attr);
 extern int device_schedule_callback_owner(struct device *dev,
                void (*func)(struct device *dev), struct module *owner);
 
@@ -365,26 +403,21 @@ struct device_dma_parameters {
 };
 
 struct device {
-       struct klist            klist_children;
-       struct klist_node       knode_parent;   /* node in sibling list */
-       struct klist_node       knode_driver;
-       struct klist_node       knode_bus;
        struct device           *parent;
 
+       struct device_private   *p;
+
        struct kobject kobj;
-       char    bus_id[BUS_ID_SIZE];    /* position on parent bus */
-       unsigned                uevent_suppress:1;
        const char              *init_name; /* initial name of the device */
        struct device_type      *type;
 
-       struct semaphore        sem;    /* semaphore to synchronize calls to
+       struct mutex            mutex;  /* mutex to synchronize calls to
                                         * its driver.
                                         */
 
        struct bus_type *bus;           /* type of bus device is on */
        struct device_driver *driver;   /* which driver has allocated this
                                           device */
-       void            *driver_data;   /* data private to the driver */
        void            *platform_data; /* Platform specific data, device
                                           core doesn't touch it */
        struct dev_pm_info      power;
@@ -407,6 +440,9 @@ struct device {
                                             override */
        /* arch specific additions */
        struct dev_archdata     archdata;
+#ifdef CONFIG_OF
+       struct device_node      *of_node;
+#endif
 
        dev_t                   devt;   /* dev_t, creates the sysfs "dev" */
 
@@ -415,7 +451,7 @@ struct device {
 
        struct klist_node       knode_class;
        struct class            *class;
-       struct attribute_group  **groups;       /* optional groups */
+       const struct attribute_group **groups;  /* optional groups */
 
        void    (*release)(struct device *dev);
 };
@@ -425,8 +461,11 @@ struct device {
 
 static inline const char *dev_name(const struct device *dev)
 {
-       /* will be changed into kobject_name(&dev->kobj) in the near future */
-       return dev->bus_id;
+       /* Use the init name until the kobject becomes available */
+       if (dev->init_name)
+               return dev->init_name;
+
+       return kobject_name(&dev->kobj);
 }
 
 extern int dev_set_name(struct device *dev, const char *name, ...)
@@ -451,14 +490,14 @@ static inline void set_dev_node(struct device *dev, int node)
 }
 #endif
 
-static inline void *dev_get_drvdata(const struct device *dev)
+static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
 {
-       return dev->driver_data;
+       return dev->kobj.uevent_suppress;
 }
 
-static inline void dev_set_drvdata(struct device *dev, void *data)
+static inline void dev_set_uevent_suppress(struct device *dev, int val)
 {
-       dev->driver_data = data;
+       dev->kobj.uevent_suppress = val;
 }
 
 static inline int device_is_registered(struct device *dev)
@@ -466,6 +505,38 @@ static inline int device_is_registered(struct device *dev)
        return dev->kobj.state_in_sysfs;
 }
 
+static inline void device_enable_async_suspend(struct device *dev)
+{
+       if (dev->power.status == DPM_ON)
+               dev->power.async_suspend = true;
+}
+
+static inline void device_disable_async_suspend(struct device *dev)
+{
+       if (dev->power.status == DPM_ON)
+               dev->power.async_suspend = false;
+}
+
+static inline bool device_async_suspend_enabled(struct device *dev)
+{
+       return !!dev->power.async_suspend;
+}
+
+static inline void device_lock(struct device *dev)
+{
+       mutex_lock(&dev->mutex);
+}
+
+static inline int device_trylock(struct device *dev)
+{
+       return mutex_trylock(&dev->mutex);
+}
+
+static inline void device_unlock(struct device *dev)
+{
+       mutex_unlock(&dev->mutex);
+}
+
 void driver_init(void);
 
 /*
@@ -481,7 +552,28 @@ extern int device_for_each_child(struct device *dev, void *data,
 extern struct device *device_find_child(struct device *dev, void *data,
                                int (*match)(struct device *dev, void *data));
 extern int device_rename(struct device *dev, char *new_name);
-extern int device_move(struct device *dev, struct device *new_parent);
+extern int device_move(struct device *dev, struct device *new_parent,
+                      enum dpm_order dpm_order);
+extern const char *device_get_devnode(struct device *dev,
+                                     mode_t *mode, const char **tmp);
+extern void *dev_get_drvdata(const struct device *dev);
+extern void dev_set_drvdata(struct device *dev, void *data);
+
+/*
+ * Root device objects for grouping under /sys/devices
+ */
+extern struct device *__root_device_register(const char *name,
+                                            struct module *owner);
+static inline struct device *root_device_register(const char *name)
+{
+       return __root_device_register(name, THIS_MODULE);
+}
+extern void root_device_unregister(struct device *root);
+
+static inline void *dev_get_platdata(const struct device *dev)
+{
+       return dev->platform_data;
+}
 
 /*
  * Manual binding of a device to driver. See drivers/base/bus.c
@@ -526,6 +618,17 @@ extern int (*platform_notify_remove)(struct device *dev);
 extern struct device *get_device(struct device *dev);
 extern void put_device(struct device *dev);
 
+extern void wait_for_device_probe(void);
+
+#ifdef CONFIG_DEVTMPFS
+extern int devtmpfs_create_node(struct device *dev);
+extern int devtmpfs_delete_node(struct device *dev);
+extern int devtmpfs_mount(const char *mntdir);
+#else
+static inline int devtmpfs_create_node(struct device *dev) { return 0; }
+static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
+static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
+#endif
 
 /* drivers/base/power/shutdown.c */
 extern void device_shutdown(void);
@@ -554,13 +657,13 @@ extern const char *dev_driver_string(const struct device *dev);
 #define dev_info(dev, format, arg...)          \
        dev_printk(KERN_INFO , dev , format , ## arg)
 
-#if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
+#if defined(DEBUG)
+#define dev_dbg(dev, format, arg...)           \
+       dev_printk(KERN_DEBUG , dev , format , ## arg)
+#elif defined(CONFIG_DYNAMIC_DEBUG)
 #define dev_dbg(dev, format, ...) do { \
        dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
        } while (0)
-#elif defined(DEBUG)
-#define dev_dbg(dev, format, arg...)           \
-       dev_printk(KERN_DEBUG , dev , format , ## arg)
 #else
 #define dev_dbg(dev, format, arg...)           \
        ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; })