xref: /OK3568_Linux_fs/kernel/include/linux/of_platform.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */
2*4882a593Smuzhiyun #ifndef _LINUX_OF_PLATFORM_H
3*4882a593Smuzhiyun #define _LINUX_OF_PLATFORM_H
4*4882a593Smuzhiyun /*
5*4882a593Smuzhiyun  *    Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
6*4882a593Smuzhiyun  *			 <benh@kernel.crashing.org>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/device.h>
10*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
11*4882a593Smuzhiyun #include <linux/pm.h>
12*4882a593Smuzhiyun #include <linux/of_device.h>
13*4882a593Smuzhiyun #include <linux/platform_device.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /**
16*4882a593Smuzhiyun  * struct of_dev_auxdata - lookup table entry for device names & platform_data
17*4882a593Smuzhiyun  * @compatible: compatible value of node to match against node
18*4882a593Smuzhiyun  * @phys_addr: Start address of registers to match against node
19*4882a593Smuzhiyun  * @name: Name to assign for matching nodes
20*4882a593Smuzhiyun  * @platform_data: platform_data to assign for matching nodes
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * This lookup table allows the caller of of_platform_populate() to override
23*4882a593Smuzhiyun  * the names of devices when creating devices from the device tree.  The table
24*4882a593Smuzhiyun  * should be terminated with an empty entry.  It also allows the platform_data
25*4882a593Smuzhiyun  * pointer to be set.
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * The reason for this functionality is that some Linux infrastructure uses
28*4882a593Smuzhiyun  * the device name to look up a specific device, but the Linux-specific names
29*4882a593Smuzhiyun  * are not encoded into the device tree, so the kernel needs to provide specific
30*4882a593Smuzhiyun  * values.
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * Note: Using an auxdata lookup table should be considered a last resort when
33*4882a593Smuzhiyun  * converting a platform to use the DT.  Normally the automatically generated
34*4882a593Smuzhiyun  * device name will not matter, and drivers should obtain data from the device
35*4882a593Smuzhiyun  * node instead of from an anonymous platform_data pointer.
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun struct of_dev_auxdata {
38*4882a593Smuzhiyun 	char *compatible;
39*4882a593Smuzhiyun 	resource_size_t phys_addr;
40*4882a593Smuzhiyun 	char *name;
41*4882a593Smuzhiyun 	void *platform_data;
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /* Macro to simplify populating a lookup table */
45*4882a593Smuzhiyun #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
46*4882a593Smuzhiyun 	{ .compatible = _compat, .phys_addr = _phys, .name = _name, \
47*4882a593Smuzhiyun 	  .platform_data = _pdata }
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun extern const struct of_device_id of_default_bus_match_table[];
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /* Platform drivers register/unregister */
52*4882a593Smuzhiyun extern struct platform_device *of_device_alloc(struct device_node *np,
53*4882a593Smuzhiyun 					 const char *bus_id,
54*4882a593Smuzhiyun 					 struct device *parent);
55*4882a593Smuzhiyun #ifdef CONFIG_OF
56*4882a593Smuzhiyun extern struct platform_device *of_find_device_by_node(struct device_node *np);
57*4882a593Smuzhiyun #else
of_find_device_by_node(struct device_node * np)58*4882a593Smuzhiyun static inline struct platform_device *of_find_device_by_node(struct device_node *np)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun 	return NULL;
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun #endif
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /* Platform devices and busses creation */
65*4882a593Smuzhiyun extern struct platform_device *of_platform_device_create(struct device_node *np,
66*4882a593Smuzhiyun 						   const char *bus_id,
67*4882a593Smuzhiyun 						   struct device *parent);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun extern int of_platform_device_destroy(struct device *dev, void *data);
70*4882a593Smuzhiyun extern int of_platform_bus_probe(struct device_node *root,
71*4882a593Smuzhiyun 				 const struct of_device_id *matches,
72*4882a593Smuzhiyun 				 struct device *parent);
73*4882a593Smuzhiyun #ifdef CONFIG_OF_ADDRESS
74*4882a593Smuzhiyun extern int of_platform_populate(struct device_node *root,
75*4882a593Smuzhiyun 				const struct of_device_id *matches,
76*4882a593Smuzhiyun 				const struct of_dev_auxdata *lookup,
77*4882a593Smuzhiyun 				struct device *parent);
78*4882a593Smuzhiyun extern int of_platform_default_populate(struct device_node *root,
79*4882a593Smuzhiyun 					const struct of_dev_auxdata *lookup,
80*4882a593Smuzhiyun 					struct device *parent);
81*4882a593Smuzhiyun extern void of_platform_depopulate(struct device *parent);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun extern int devm_of_platform_populate(struct device *dev);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun extern void devm_of_platform_depopulate(struct device *dev);
86*4882a593Smuzhiyun #else
of_platform_populate(struct device_node * root,const struct of_device_id * matches,const struct of_dev_auxdata * lookup,struct device * parent)87*4882a593Smuzhiyun static inline int of_platform_populate(struct device_node *root,
88*4882a593Smuzhiyun 					const struct of_device_id *matches,
89*4882a593Smuzhiyun 					const struct of_dev_auxdata *lookup,
90*4882a593Smuzhiyun 					struct device *parent)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun 	return -ENODEV;
93*4882a593Smuzhiyun }
of_platform_default_populate(struct device_node * root,const struct of_dev_auxdata * lookup,struct device * parent)94*4882a593Smuzhiyun static inline int of_platform_default_populate(struct device_node *root,
95*4882a593Smuzhiyun 					       const struct of_dev_auxdata *lookup,
96*4882a593Smuzhiyun 					       struct device *parent)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	return -ENODEV;
99*4882a593Smuzhiyun }
of_platform_depopulate(struct device * parent)100*4882a593Smuzhiyun static inline void of_platform_depopulate(struct device *parent) { }
101*4882a593Smuzhiyun 
devm_of_platform_populate(struct device * dev)102*4882a593Smuzhiyun static inline int devm_of_platform_populate(struct device *dev)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun 	return -ENODEV;
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun 
devm_of_platform_depopulate(struct device * dev)107*4882a593Smuzhiyun static inline void devm_of_platform_depopulate(struct device *dev) { }
108*4882a593Smuzhiyun #endif
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
111*4882a593Smuzhiyun extern void of_platform_register_reconfig_notifier(void);
112*4882a593Smuzhiyun #else
of_platform_register_reconfig_notifier(void)113*4882a593Smuzhiyun static inline void of_platform_register_reconfig_notifier(void) { }
114*4882a593Smuzhiyun #endif
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun #endif	/* _LINUX_OF_PLATFORM_H */
117