blob: dc8224ae28d5d9e6106dc0d06a8a9bc2eb85fd0a [file] [log] [blame]
Stephen Rothwellb41912c2007-05-01 16:12:57 +10001#ifndef _LINUX_OF_PLATFORM_H
2#define _LINUX_OF_PLATFORM_H
3/*
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
5 * <benh@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
Stephen Rothwellb41912c2007-05-01 16:12:57 +100014#include <linux/device.h>
15#include <linux/mod_devicetable.h>
16#include <linux/pm.h>
17#include <linux/of_device.h>
Grant Likelyeca39302010-06-08 07:48:21 -060018#include <linux/platform_device.h>
Stephen Rothwellb41912c2007-05-01 16:12:57 +100019
Grant Likely2dc11582010-08-06 09:25:50 -060020/**
Grant Likely15c35972011-06-21 10:59:35 -060021 * struct of_dev_auxdata - lookup table entry for device names & platform_data
22 * @compatible: compatible value of node to match against node
23 * @phys_addr: Start address of registers to match against node
24 * @name: Name to assign for matching nodes
25 * @platform_data: platform_data to assign for matching nodes
26 *
27 * This lookup table allows the caller of of_platform_populate() to override
28 * the names of devices when creating devices from the device tree. The table
29 * should be terminated with an empty entry. It also allows the platform_data
30 * pointer to be set.
31 *
32 * The reason for this functionality is that some Linux infrastructure uses
33 * the device name to look up a specific device, but the Linux-specific names
34 * are not encoded into the device tree, so the kernel needs to provide specific
35 * values.
36 *
37 * Note: Using an auxdata lookup table should be considered a last resort when
38 * converting a platform to use the DT. Normally the automatically generated
39 * device name will not matter, and drivers should obtain data from the device
Geert Uytterhoeven8c1eb252014-03-11 11:23:50 +010040 * node instead of from an anonymous platform_data pointer.
Grant Likely15c35972011-06-21 10:59:35 -060041 */
42struct of_dev_auxdata {
43 char *compatible;
44 resource_size_t phys_addr;
45 char *name;
46 void *platform_data;
47};
48
49/* Macro to simplify populating a lookup table */
50#define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
51 { .compatible = _compat, .phys_addr = _phys, .name = _name, \
52 .platform_data = _pdata }
53
Grant Likelycbb49c22011-06-21 10:59:34 -060054extern const struct of_device_id of_default_bus_match_table[];
55
Grant Likely0763ed22009-04-30 15:08:50 -070056/* Platform drivers register/unregister */
Grant Likely94a0cb12010-07-22 13:59:23 -060057extern struct platform_device *of_device_alloc(struct device_node *np,
Grant Likely94c09312010-06-08 07:48:14 -060058 const char *bus_id,
59 struct device *parent);
Grant Likely94a0cb12010-07-22 13:59:23 -060060extern struct platform_device *of_find_device_by_node(struct device_node *np);
Stephen Rothwellb41912c2007-05-01 16:12:57 +100061
Grant Likely5fd200f2010-06-08 07:48:13 -060062/* Platform devices and busses creation */
Grant Likely94a0cb12010-07-22 13:59:23 -060063extern struct platform_device *of_platform_device_create(struct device_node *np,
Grant Likely5fd200f2010-06-08 07:48:13 -060064 const char *bus_id,
65 struct device *parent);
66
Grant Likely5fd200f2010-06-08 07:48:13 -060067extern int of_platform_bus_probe(struct device_node *root,
68 const struct of_device_id *matches,
69 struct device *parent);
Arnd Bergmann8a46f4f2013-06-01 00:22:52 +020070#ifdef CONFIG_OF_ADDRESS
Grant Likely29d4f8a2011-06-21 10:59:34 -060071extern int of_platform_populate(struct device_node *root,
72 const struct of_device_id *matches,
Grant Likely15c35972011-06-21 10:59:35 -060073 const struct of_dev_auxdata *lookup,
Grant Likely29d4f8a2011-06-21 10:59:34 -060074 struct device *parent);
Hauke Mehrtens43443ad2015-08-02 19:44:43 +020075extern int of_platform_default_populate(struct device_node *root,
76 const struct of_dev_auxdata *lookup,
77 struct device *parent);
Grant Likely75f353b2014-06-24 16:13:47 +010078extern void of_platform_depopulate(struct device *parent);
Benjamin Gaignard38b0b212017-02-24 17:14:33 +010079
80extern int devm_of_platform_populate(struct device *dev);
81
82extern void devm_of_platform_depopulate(struct device *dev);
Arnd Bergmann8a46f4f2013-06-01 00:22:52 +020083#else
Grant Likely964dba22012-02-24 14:58:34 -070084static inline int of_platform_populate(struct device_node *root,
85 const struct of_device_id *matches,
86 const struct of_dev_auxdata *lookup,
87 struct device *parent)
88{
89 return -ENODEV;
90}
Hauke Mehrtens43443ad2015-08-02 19:44:43 +020091static inline int of_platform_default_populate(struct device_node *root,
92 const struct of_dev_auxdata *lookup,
93 struct device *parent)
94{
95 return -ENODEV;
96}
Grant Likely75f353b2014-06-24 16:13:47 +010097static inline void of_platform_depopulate(struct device *parent) { }
Benjamin Gaignard38b0b212017-02-24 17:14:33 +010098
99static inline int devm_of_platform_populate(struct device *dev)
100{
101 return -ENODEV;
102}
103
104static inline void devm_of_platform_depopulate(struct device *dev) { }
Arnd Bergmann8a46f4f2013-06-01 00:22:52 +0200105#endif
Grant Likely5fd200f2010-06-08 07:48:13 -0600106
Guenter Roecka697c2e2015-03-10 20:31:04 -0700107#if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
Pantelis Antoniou801d7282014-10-28 22:36:01 +0200108extern void of_platform_register_reconfig_notifier(void);
109#else
110static inline void of_platform_register_reconfig_notifier(void) { }
111#endif
112
Stephen Rothwellb41912c2007-05-01 16:12:57 +1000113#endif /* _LINUX_OF_PLATFORM_H */