1 /* SPDX-License-Identifier: GPL-2.0+ */
2 #ifndef _LINUX_OF_PLATFORM_H
3 #define _LINUX_OF_PLATFORM_H
5 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
6 * <benh@kernel.crashing.org>
9 #include <linux/mod_devicetable.h>
10 #include <linux/of_device.h>
11 #include <linux/platform_device.h>
17 * struct of_dev_auxdata - lookup table entry for device names & platform_data
18 * @compatible: compatible value of node to match against node
19 * @phys_addr: Start address of registers to match against node
20 * @name: Name to assign for matching nodes
21 * @platform_data: platform_data to assign for matching nodes
23 * This lookup table allows the caller of of_platform_populate() to override
24 * the names of devices when creating devices from the device tree. The table
25 * should be terminated with an empty entry. It also allows the platform_data
28 * The reason for this functionality is that some Linux infrastructure uses
29 * the device name to look up a specific device, but the Linux-specific names
30 * are not encoded into the device tree, so the kernel needs to provide specific
33 * Note: Using an auxdata lookup table should be considered a last resort when
34 * converting a platform to use the DT. Normally the automatically generated
35 * device name will not matter, and drivers should obtain data from the device
36 * node instead of from an anonymous platform_data pointer.
38 struct of_dev_auxdata {
40 resource_size_t phys_addr;
45 /* Macro to simplify populating a lookup table */
46 #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
47 { .compatible = _compat, .phys_addr = _phys, .name = _name, \
48 .platform_data = _pdata }
50 extern const struct of_device_id of_default_bus_match_table[];
52 /* Platform drivers register/unregister */
53 extern struct platform_device *of_device_alloc(struct device_node *np,
55 struct device *parent);
57 extern int of_device_add(struct platform_device *pdev);
58 extern int of_device_register(struct platform_device *ofdev);
59 extern void of_device_unregister(struct platform_device *ofdev);
62 extern struct platform_device *of_find_device_by_node(struct device_node *np);
64 static inline struct platform_device *of_find_device_by_node(struct device_node *np)
70 extern int of_platform_bus_probe(struct device_node *root,
71 const struct of_device_id *matches,
72 struct device *parent);
74 #ifdef CONFIG_OF_ADDRESS
75 /* Platform devices and busses creation */
76 extern struct platform_device *of_platform_device_create(struct device_node *np,
78 struct device *parent);
80 extern int of_platform_device_destroy(struct device *dev, void *data);
82 extern int of_platform_populate(struct device_node *root,
83 const struct of_device_id *matches,
84 const struct of_dev_auxdata *lookup,
85 struct device *parent);
86 extern int of_platform_default_populate(struct device_node *root,
87 const struct of_dev_auxdata *lookup,
88 struct device *parent);
89 extern void of_platform_depopulate(struct device *parent);
91 extern int devm_of_platform_populate(struct device *dev);
93 extern void devm_of_platform_depopulate(struct device *dev);
95 /* Platform devices and busses creation */
96 static inline struct platform_device *of_platform_device_create(struct device_node *np,
98 struct device *parent)
102 static inline int of_platform_device_destroy(struct device *dev, void *data)
107 static inline int of_platform_populate(struct device_node *root,
108 const struct of_device_id *matches,
109 const struct of_dev_auxdata *lookup,
110 struct device *parent)
114 static inline int of_platform_default_populate(struct device_node *root,
115 const struct of_dev_auxdata *lookup,
116 struct device *parent)
120 static inline void of_platform_depopulate(struct device *parent) { }
122 static inline int devm_of_platform_populate(struct device *dev)
127 static inline void devm_of_platform_depopulate(struct device *dev) { }
130 #endif /* _LINUX_OF_PLATFORM_H */