Merge tag 'pm-6.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-block.git] / include / linux / of_platform.h
CommitLineData
af6074fc 1/* SPDX-License-Identifier: GPL-2.0+ */
b41912ca
SR
2#ifndef _LINUX_OF_PLATFORM_H
3#define _LINUX_OF_PLATFORM_H
4/*
5 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
6 * <benh@kernel.crashing.org>
b41912ca
SR
7 */
8
b41912ca 9#include <linux/mod_devicetable.h>
b41912ca 10
2e8fff66 11struct device;
ef175b29 12struct device_node;
2e8fff66 13struct of_device_id;
ef175b29 14struct platform_device;
2e8fff66 15
15c3597d
GL
16/**
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
22 *
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
26 * pointer to be set.
27 *
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
31 * values.
32 *
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
8c1eb253 36 * node instead of from an anonymous platform_data pointer.
15c3597d
GL
37 */
38struct of_dev_auxdata {
39 char *compatible;
40 resource_size_t phys_addr;
41 char *name;
42 void *platform_data;
43};
44
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 }
49
0763ed23 50/* Platform drivers register/unregister */
94a0cb1f 51extern struct platform_device *of_device_alloc(struct device_node *np,
94c09319
GL
52 const char *bus_id,
53 struct device *parent);
4c32fb7d
RH
54
55extern int of_device_add(struct platform_device *pdev);
56extern int of_device_register(struct platform_device *ofdev);
57extern void of_device_unregister(struct platform_device *ofdev);
58
aa767cfb 59#ifdef CONFIG_OF
94a0cb1f 60extern struct platform_device *of_find_device_by_node(struct device_node *np);
aa767cfb
AB
61#else
62static inline struct platform_device *of_find_device_by_node(struct device_node *np)
63{
64 return NULL;
65}
66#endif
b41912ca 67
620e8e8b
MK
68extern int of_platform_bus_probe(struct device_node *root,
69 const struct of_device_id *matches,
70 struct device *parent);
71
72#ifdef CONFIG_OF_ADDRESS
5fd200f3 73/* Platform devices and busses creation */
94a0cb1f 74extern struct platform_device *of_platform_device_create(struct device_node *np,
5fd200f3
GL
75 const char *bus_id,
76 struct device *parent);
77
c2372c20 78extern int of_platform_device_destroy(struct device *dev, void *data);
620e8e8b 79
29d4f8a4
GL
80extern int of_platform_populate(struct device_node *root,
81 const struct of_device_id *matches,
15c3597d 82 const struct of_dev_auxdata *lookup,
29d4f8a4 83 struct device *parent);
43443ad6
HM
84extern int of_platform_default_populate(struct device_node *root,
85 const struct of_dev_auxdata *lookup,
86 struct device *parent);
75f353b6 87extern void of_platform_depopulate(struct device *parent);
38b0b219
BG
88
89extern int devm_of_platform_populate(struct device *dev);
90
91extern void devm_of_platform_depopulate(struct device *dev);
8a46f4f7 92#else
620e8e8b
MK
93/* Platform devices and busses creation */
94static inline struct platform_device *of_platform_device_create(struct device_node *np,
95 const char *bus_id,
96 struct device *parent)
97{
98 return NULL;
99}
100static inline int of_platform_device_destroy(struct device *dev, void *data)
101{
102 return -ENODEV;
103}
104
964dba28
GL
105static inline int of_platform_populate(struct device_node *root,
106 const struct of_device_id *matches,
107 const struct of_dev_auxdata *lookup,
108 struct device *parent)
109{
110 return -ENODEV;
111}
43443ad6
HM
112static inline int of_platform_default_populate(struct device_node *root,
113 const struct of_dev_auxdata *lookup,
114 struct device *parent)
115{
116 return -ENODEV;
117}
75f353b6 118static inline void of_platform_depopulate(struct device *parent) { }
38b0b219
BG
119
120static inline int devm_of_platform_populate(struct device *dev)
121{
122 return -ENODEV;
123}
124
125static inline void devm_of_platform_depopulate(struct device *dev) { }
8a46f4f7 126#endif
5fd200f3 127
b41912ca 128#endif /* _LINUX_OF_PLATFORM_H */