blob: 84a966623e78d446c5aebf7d61c1af3401f32709 [file] [log] [blame]
Rob Herringaf6074f2017-12-27 12:55:14 -06001/* SPDX-License-Identifier: GPL-2.0+ */
Stephen Rothwellb41912c2007-05-01 16:12:57 +10002#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>
Stephen Rothwellb41912c2007-05-01 16:12:57 +10007 */
8
Stephen Rothwellb41912c2007-05-01 16:12:57 +10009#include <linux/device.h>
10#include <linux/mod_devicetable.h>
11#include <linux/pm.h>
12#include <linux/of_device.h>
Grant Likelyeca39302010-06-08 07:48:21 -060013#include <linux/platform_device.h>
Stephen Rothwellb41912c2007-05-01 16:12:57 +100014
Grant Likely2dc11582010-08-06 09:25:50 -060015/**
Grant Likely15c35972011-06-21 10:59:35 -060016 * struct of_dev_auxdata - lookup table entry for device names & platform_data
17 * @compatible: compatible value of node to match against node
18 * @phys_addr: Start address of registers to match against node
19 * @name: Name to assign for matching nodes
20 * @platform_data: platform_data to assign for matching nodes
21 *
22 * This lookup table allows the caller of of_platform_populate() to override
23 * the names of devices when creating devices from the device tree. The table
24 * should be terminated with an empty entry. It also allows the platform_data
25 * pointer to be set.
26 *
27 * The reason for this functionality is that some Linux infrastructure uses
28 * the device name to look up a specific device, but the Linux-specific names
29 * are not encoded into the device tree, so the kernel needs to provide specific
30 * values.
31 *
32 * Note: Using an auxdata lookup table should be considered a last resort when
33 * converting a platform to use the DT. Normally the automatically generated
34 * device name will not matter, and drivers should obtain data from the device
Geert Uytterhoeven8c1eb252014-03-11 11:23:50 +010035 * node instead of from an anonymous platform_data pointer.
Grant Likely15c35972011-06-21 10:59:35 -060036 */
37struct of_dev_auxdata {
38 char *compatible;
39 resource_size_t phys_addr;
40 char *name;
41 void *platform_data;
42};
43
44/* Macro to simplify populating a lookup table */
45#define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
46 { .compatible = _compat, .phys_addr = _phys, .name = _name, \
47 .platform_data = _pdata }
48
Grant Likelycbb49c22011-06-21 10:59:34 -060049extern const struct of_device_id of_default_bus_match_table[];
50
Grant Likely0763ed22009-04-30 15:08:50 -070051/* Platform drivers register/unregister */
Grant Likely94a0cb12010-07-22 13:59:23 -060052extern struct platform_device *of_device_alloc(struct device_node *np,
Grant Likely94c09312010-06-08 07:48:14 -060053 const char *bus_id,
54 struct device *parent);
Arnd Bergmannaa767cf2017-09-11 22:07:50 +020055#ifdef CONFIG_OF
Grant Likely94a0cb12010-07-22 13:59:23 -060056extern struct platform_device *of_find_device_by_node(struct device_node *np);
Arnd Bergmannaa767cf2017-09-11 22:07:50 +020057#else
58static inline struct platform_device *of_find_device_by_node(struct device_node *np)
59{
60 return NULL;
61}
62#endif
Stephen Rothwellb41912c2007-05-01 16:12:57 +100063
Grant Likely5fd200f2010-06-08 07:48:13 -060064/* Platform devices and busses creation */
Grant Likely94a0cb12010-07-22 13:59:23 -060065extern struct platform_device *of_platform_device_create(struct device_node *np,
Grant Likely5fd200f2010-06-08 07:48:13 -060066 const char *bus_id,
67 struct device *parent);
68
Jan Glauberc2372c22017-05-22 13:09:20 +020069extern int of_platform_device_destroy(struct device *dev, void *data);
Grant Likely5fd200f2010-06-08 07:48:13 -060070extern int of_platform_bus_probe(struct device_node *root,
71 const struct of_device_id *matches,
72 struct device *parent);
Arnd Bergmann8a46f4f2013-06-01 00:22:52 +020073#ifdef CONFIG_OF_ADDRESS
Grant Likely29d4f8a2011-06-21 10:59:34 -060074extern int of_platform_populate(struct device_node *root,
75 const struct of_device_id *matches,
Grant Likely15c35972011-06-21 10:59:35 -060076 const struct of_dev_auxdata *lookup,
Grant Likely29d4f8a2011-06-21 10:59:34 -060077 struct device *parent);
Hauke Mehrtens43443ad2015-08-02 19:44:43 +020078extern int of_platform_default_populate(struct device_node *root,
79 const struct of_dev_auxdata *lookup,
80 struct device *parent);
Grant Likely75f353b2014-06-24 16:13:47 +010081extern void of_platform_depopulate(struct device *parent);
Benjamin Gaignard38b0b212017-02-24 17:14:33 +010082
83extern int devm_of_platform_populate(struct device *dev);
84
85extern void devm_of_platform_depopulate(struct device *dev);
Arnd Bergmann8a46f4f2013-06-01 00:22:52 +020086#else
Grant Likely964dba22012-02-24 14:58:34 -070087static inline int of_platform_populate(struct device_node *root,
88 const struct of_device_id *matches,
89 const struct of_dev_auxdata *lookup,
90 struct device *parent)
91{
92 return -ENODEV;
93}
Hauke Mehrtens43443ad2015-08-02 19:44:43 +020094static inline int of_platform_default_populate(struct device_node *root,
95 const struct of_dev_auxdata *lookup,
96 struct device *parent)
97{
98 return -ENODEV;
99}
Grant Likely75f353b2014-06-24 16:13:47 +0100100static inline void of_platform_depopulate(struct device *parent) { }
Benjamin Gaignard38b0b212017-02-24 17:14:33 +0100101
102static inline int devm_of_platform_populate(struct device *dev)
103{
104 return -ENODEV;
105}
106
107static inline void devm_of_platform_depopulate(struct device *dev) { }
Arnd Bergmann8a46f4f2013-06-01 00:22:52 +0200108#endif
Grant Likely5fd200f2010-06-08 07:48:13 -0600109
Guenter Roecka697c2e2015-03-10 20:31:04 -0700110#if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
Pantelis Antoniou801d7282014-10-28 22:36:01 +0200111extern void of_platform_register_reconfig_notifier(void);
112#else
113static inline void of_platform_register_reconfig_notifier(void) { }
114#endif
115
Stephen Rothwellb41912c2007-05-01 16:12:57 +1000116#endif /* _LINUX_OF_PLATFORM_H */