Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 #ifndef _LINUX_OF_PLATFORM_H
0003 #define _LINUX_OF_PLATFORM_H
0004 /*
0005  *    Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
0006  *           <benh@kernel.crashing.org>
0007  */
0008 
0009 #include <linux/device.h>
0010 #include <linux/mod_devicetable.h>
0011 #include <linux/pm.h>
0012 #include <linux/of_device.h>
0013 #include <linux/platform_device.h>
0014 
0015 /**
0016  * struct of_dev_auxdata - lookup table entry for device names & platform_data
0017  * @compatible: compatible value of node to match against node
0018  * @phys_addr: Start address of registers to match against node
0019  * @name: Name to assign for matching nodes
0020  * @platform_data: platform_data to assign for matching nodes
0021  *
0022  * This lookup table allows the caller of of_platform_populate() to override
0023  * the names of devices when creating devices from the device tree.  The table
0024  * should be terminated with an empty entry.  It also allows the platform_data
0025  * pointer to be set.
0026  *
0027  * The reason for this functionality is that some Linux infrastructure uses
0028  * the device name to look up a specific device, but the Linux-specific names
0029  * are not encoded into the device tree, so the kernel needs to provide specific
0030  * values.
0031  *
0032  * Note: Using an auxdata lookup table should be considered a last resort when
0033  * converting a platform to use the DT.  Normally the automatically generated
0034  * device name will not matter, and drivers should obtain data from the device
0035  * node instead of from an anonymous platform_data pointer.
0036  */
0037 struct of_dev_auxdata {
0038     char *compatible;
0039     resource_size_t phys_addr;
0040     char *name;
0041     void *platform_data;
0042 };
0043 
0044 /* Macro to simplify populating a lookup table */
0045 #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
0046     { .compatible = _compat, .phys_addr = _phys, .name = _name, \
0047       .platform_data = _pdata }
0048 
0049 extern const struct of_device_id of_default_bus_match_table[];
0050 
0051 /* Platform drivers register/unregister */
0052 extern struct platform_device *of_device_alloc(struct device_node *np,
0053                      const char *bus_id,
0054                      struct device *parent);
0055 #ifdef CONFIG_OF
0056 extern struct platform_device *of_find_device_by_node(struct device_node *np);
0057 #else
0058 static inline struct platform_device *of_find_device_by_node(struct device_node *np)
0059 {
0060     return NULL;
0061 }
0062 #endif
0063 
0064 extern int of_platform_bus_probe(struct device_node *root,
0065                  const struct of_device_id *matches,
0066                  struct device *parent);
0067 
0068 #ifdef CONFIG_OF_ADDRESS
0069 /* Platform devices and busses creation */
0070 extern struct platform_device *of_platform_device_create(struct device_node *np,
0071                            const char *bus_id,
0072                            struct device *parent);
0073 
0074 extern int of_platform_device_destroy(struct device *dev, void *data);
0075 
0076 extern int of_platform_populate(struct device_node *root,
0077                 const struct of_device_id *matches,
0078                 const struct of_dev_auxdata *lookup,
0079                 struct device *parent);
0080 extern int of_platform_default_populate(struct device_node *root,
0081                     const struct of_dev_auxdata *lookup,
0082                     struct device *parent);
0083 extern void of_platform_depopulate(struct device *parent);
0084 
0085 extern int devm_of_platform_populate(struct device *dev);
0086 
0087 extern void devm_of_platform_depopulate(struct device *dev);
0088 #else
0089 /* Platform devices and busses creation */
0090 static inline struct platform_device *of_platform_device_create(struct device_node *np,
0091                                 const char *bus_id,
0092                                 struct device *parent)
0093 {
0094     return NULL;
0095 }
0096 static inline int of_platform_device_destroy(struct device *dev, void *data)
0097 {
0098     return -ENODEV;
0099 }
0100 
0101 static inline int of_platform_populate(struct device_node *root,
0102                     const struct of_device_id *matches,
0103                     const struct of_dev_auxdata *lookup,
0104                     struct device *parent)
0105 {
0106     return -ENODEV;
0107 }
0108 static inline int of_platform_default_populate(struct device_node *root,
0109                            const struct of_dev_auxdata *lookup,
0110                            struct device *parent)
0111 {
0112     return -ENODEV;
0113 }
0114 static inline void of_platform_depopulate(struct device *parent) { }
0115 
0116 static inline int devm_of_platform_populate(struct device *dev)
0117 {
0118     return -ENODEV;
0119 }
0120 
0121 static inline void devm_of_platform_depopulate(struct device *dev) { }
0122 #endif
0123 
0124 #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
0125 extern void of_platform_register_reconfig_notifier(void);
0126 #else
0127 static inline void of_platform_register_reconfig_notifier(void) { }
0128 #endif
0129 
0130 #endif  /* _LINUX_OF_PLATFORM_H */