aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/device.h')
-rw-r--r--include/linux/device.h136
1 files changed, 105 insertions, 31 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 182192892d45..6a8276f683b6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -22,7 +22,6 @@
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/pm.h> 24#include <linux/pm.h>
25#include <linux/semaphore.h>
26#include <asm/atomic.h> 25#include <asm/atomic.h>
27#include <asm/device.h> 26#include <asm/device.h>
28 27
@@ -34,6 +33,7 @@ struct class;
34struct class_private; 33struct class_private;
35struct bus_type; 34struct bus_type;
36struct bus_type_private; 35struct bus_type_private;
36struct device_node;
37 37
38struct bus_attribute { 38struct bus_attribute {
39 struct attribute attr; 39 struct attribute attr;
@@ -128,6 +128,10 @@ struct device_driver {
128 128
129 bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ 129 bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
130 130
131#if defined(CONFIG_OF)
132 const struct of_device_id *of_match_table;
133#endif
134
131 int (*probe) (struct device *dev); 135 int (*probe) (struct device *dev);
132 int (*remove) (struct device *dev); 136 int (*remove) (struct device *dev);
133 void (*shutdown) (struct device *dev); 137 void (*shutdown) (struct device *dev);
@@ -203,6 +207,9 @@ struct class {
203 int (*suspend)(struct device *dev, pm_message_t state); 207 int (*suspend)(struct device *dev, pm_message_t state);
204 int (*resume)(struct device *dev); 208 int (*resume)(struct device *dev);
205 209
210 const struct kobj_ns_type_operations *ns_type;
211 const void *(*namespace)(struct device *dev);
212
206 const struct dev_pm_ops *pm; 213 const struct dev_pm_ops *pm;
207 214
208 struct class_private *p; 215 struct class_private *p;
@@ -404,7 +411,7 @@ struct device {
404 const char *init_name; /* initial name of the device */ 411 const char *init_name; /* initial name of the device */
405 struct device_type *type; 412 struct device_type *type;
406 413
407 struct semaphore sem; /* semaphore to synchronize calls to 414 struct mutex mutex; /* mutex to synchronize calls to
408 * its driver. 415 * its driver.
409 */ 416 */
410 417
@@ -433,6 +440,9 @@ struct device {
433 override */ 440 override */
434 /* arch specific additions */ 441 /* arch specific additions */
435 struct dev_archdata archdata; 442 struct dev_archdata archdata;
443#ifdef CONFIG_OF
444 struct device_node *of_node;
445#endif
436 446
437 dev_t devt; /* dev_t, creates the sysfs "dev" */ 447 dev_t devt; /* dev_t, creates the sysfs "dev" */
438 448
@@ -451,6 +461,10 @@ struct device {
451 461
452static inline const char *dev_name(const struct device *dev) 462static inline const char *dev_name(const struct device *dev)
453{ 463{
464 /* Use the init name until the kobject becomes available */
465 if (dev->init_name)
466 return dev->init_name;
467
454 return kobject_name(&dev->kobj); 468 return kobject_name(&dev->kobj);
455} 469}
456 470
@@ -510,17 +524,17 @@ static inline bool device_async_suspend_enabled(struct device *dev)
510 524
511static inline void device_lock(struct device *dev) 525static inline void device_lock(struct device *dev)
512{ 526{
513 down(&dev->sem); 527 mutex_lock(&dev->mutex);
514} 528}
515 529
516static inline int device_trylock(struct device *dev) 530static inline int device_trylock(struct device *dev)
517{ 531{
518 return down_trylock(&dev->sem); 532 return mutex_trylock(&dev->mutex);
519} 533}
520 534
521static inline void device_unlock(struct device *dev) 535static inline void device_unlock(struct device *dev)
522{ 536{
523 up(&dev->sem); 537 mutex_unlock(&dev->mutex);
524} 538}
525 539
526void driver_init(void); 540void driver_init(void);
@@ -624,43 +638,103 @@ extern void sysdev_shutdown(void);
624 638
625/* debugging and troubleshooting/diagnostic helpers. */ 639/* debugging and troubleshooting/diagnostic helpers. */
626extern const char *dev_driver_string(const struct device *dev); 640extern const char *dev_driver_string(const struct device *dev);
627#define dev_printk(level, dev, format, arg...) \ 641
628 printk(level "%s %s: " format , dev_driver_string(dev) , \ 642
629 dev_name(dev) , ## arg) 643#ifdef CONFIG_PRINTK
630 644
631#define dev_emerg(dev, format, arg...) \ 645extern int dev_printk(const char *level, const struct device *dev,
632 dev_printk(KERN_EMERG , dev , format , ## arg) 646 const char *fmt, ...)
633#define dev_alert(dev, format, arg...) \ 647 __attribute__ ((format (printf, 3, 4)));
634 dev_printk(KERN_ALERT , dev , format , ## arg) 648extern int dev_emerg(const struct device *dev, const char *fmt, ...)
635#define dev_crit(dev, format, arg...) \ 649 __attribute__ ((format (printf, 2, 3)));
636 dev_printk(KERN_CRIT , dev , format , ## arg) 650extern int dev_alert(const struct device *dev, const char *fmt, ...)
637#define dev_err(dev, format, arg...) \ 651 __attribute__ ((format (printf, 2, 3)));
638 dev_printk(KERN_ERR , dev , format , ## arg) 652extern int dev_crit(const struct device *dev, const char *fmt, ...)
639#define dev_warn(dev, format, arg...) \ 653 __attribute__ ((format (printf, 2, 3)));
640 dev_printk(KERN_WARNING , dev , format , ## arg) 654extern int dev_err(const struct device *dev, const char *fmt, ...)
641#define dev_notice(dev, format, arg...) \ 655 __attribute__ ((format (printf, 2, 3)));
642 dev_printk(KERN_NOTICE , dev , format , ## arg) 656extern int dev_warn(const struct device *dev, const char *fmt, ...)
643#define dev_info(dev, format, arg...) \ 657 __attribute__ ((format (printf, 2, 3)));
644 dev_printk(KERN_INFO , dev , format , ## arg) 658extern int dev_notice(const struct device *dev, const char *fmt, ...)
659 __attribute__ ((format (printf, 2, 3)));
660extern int _dev_info(const struct device *dev, const char *fmt, ...)
661 __attribute__ ((format (printf, 2, 3)));
662
663#else
664
665static inline int dev_printk(const char *level, const struct device *dev,
666 const char *fmt, ...)
667 __attribute__ ((format (printf, 3, 4)));
668static inline int dev_printk(const char *level, const struct device *dev,
669 const char *fmt, ...)
670 { return 0; }
671
672static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
673 __attribute__ ((format (printf, 2, 3)));
674static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
675 { return 0; }
676static inline int dev_crit(const struct device *dev, const char *fmt, ...)
677 __attribute__ ((format (printf, 2, 3)));
678static inline int dev_crit(const struct device *dev, const char *fmt, ...)
679 { return 0; }
680static inline int dev_alert(const struct device *dev, const char *fmt, ...)
681 __attribute__ ((format (printf, 2, 3)));
682static inline int dev_alert(const struct device *dev, const char *fmt, ...)
683 { return 0; }
684static inline int dev_err(const struct device *dev, const char *fmt, ...)
685 __attribute__ ((format (printf, 2, 3)));
686static inline int dev_err(const struct device *dev, const char *fmt, ...)
687 { return 0; }
688static inline int dev_warn(const struct device *dev, const char *fmt, ...)
689 __attribute__ ((format (printf, 2, 3)));
690static inline int dev_warn(const struct device *dev, const char *fmt, ...)
691 { return 0; }
692static inline int dev_notice(const struct device *dev, const char *fmt, ...)
693 __attribute__ ((format (printf, 2, 3)));
694static inline int dev_notice(const struct device *dev, const char *fmt, ...)
695 { return 0; }
696static inline int _dev_info(const struct device *dev, const char *fmt, ...)
697 __attribute__ ((format (printf, 2, 3)));
698static inline int _dev_info(const struct device *dev, const char *fmt, ...)
699 { return 0; }
700
701#endif
702
703/*
704 * Stupid hackaround for existing uses of non-printk uses dev_info
705 *
706 * Note that the definition of dev_info below is actually _dev_info
707 * and a macro is used to avoid redefining dev_info
708 */
709
710#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
645 711
646#if defined(DEBUG) 712#if defined(DEBUG)
647#define dev_dbg(dev, format, arg...) \ 713#define dev_dbg(dev, format, arg...) \
648 dev_printk(KERN_DEBUG , dev , format , ## arg) 714 dev_printk(KERN_DEBUG, dev, format, ##arg)
649#elif defined(CONFIG_DYNAMIC_DEBUG) 715#elif defined(CONFIG_DYNAMIC_DEBUG)
650#define dev_dbg(dev, format, ...) do { \ 716#define dev_dbg(dev, format, ...) \
717do { \
651 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ 718 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
652 } while (0) 719} while (0)
653#else 720#else
654#define dev_dbg(dev, format, arg...) \ 721#define dev_dbg(dev, format, arg...) \
655 ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) 722({ \
723 if (0) \
724 dev_printk(KERN_DEBUG, dev, format, ##arg); \
725 0; \
726})
656#endif 727#endif
657 728
658#ifdef VERBOSE_DEBUG 729#ifdef VERBOSE_DEBUG
659#define dev_vdbg dev_dbg 730#define dev_vdbg dev_dbg
660#else 731#else
661 732#define dev_vdbg(dev, format, arg...) \
662#define dev_vdbg(dev, format, arg...) \ 733({ \
663 ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) 734 if (0) \
735 dev_printk(KERN_DEBUG, dev, format, ##arg); \
736 0; \
737})
664#endif 738#endif
665 739
666/* 740/*