xref: /linux-6.15/include/linux/of_platform.h (revision 3c48780d)
1af6074fcSRob Herring /* SPDX-License-Identifier: GPL-2.0+ */
2b41912caSStephen Rothwell #ifndef _LINUX_OF_PLATFORM_H
3b41912caSStephen Rothwell #define _LINUX_OF_PLATFORM_H
4b41912caSStephen Rothwell /*
5b41912caSStephen Rothwell  *    Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
6b41912caSStephen Rothwell  *			 <[email protected]>
7b41912caSStephen Rothwell  */
8b41912caSStephen Rothwell 
9b41912caSStephen Rothwell #include <linux/mod_devicetable.h>
10b41912caSStephen Rothwell 
112e8fff66SRob Herring struct device;
12*ef175b29SRob Herring struct device_node;
132e8fff66SRob Herring struct of_device_id;
14*ef175b29SRob Herring struct platform_device;
152e8fff66SRob Herring 
162dc11581SGrant Likely /**
1715c3597dSGrant Likely  * struct of_dev_auxdata - lookup table entry for device names & platform_data
1815c3597dSGrant Likely  * @compatible: compatible value of node to match against node
1915c3597dSGrant Likely  * @phys_addr: Start address of registers to match against node
2015c3597dSGrant Likely  * @name: Name to assign for matching nodes
2115c3597dSGrant Likely  * @platform_data: platform_data to assign for matching nodes
2215c3597dSGrant Likely  *
2315c3597dSGrant Likely  * This lookup table allows the caller of of_platform_populate() to override
2415c3597dSGrant Likely  * the names of devices when creating devices from the device tree.  The table
2515c3597dSGrant Likely  * should be terminated with an empty entry.  It also allows the platform_data
2615c3597dSGrant Likely  * pointer to be set.
2715c3597dSGrant Likely  *
2815c3597dSGrant Likely  * The reason for this functionality is that some Linux infrastructure uses
2915c3597dSGrant Likely  * the device name to look up a specific device, but the Linux-specific names
3015c3597dSGrant Likely  * are not encoded into the device tree, so the kernel needs to provide specific
3115c3597dSGrant Likely  * values.
3215c3597dSGrant Likely  *
3315c3597dSGrant Likely  * Note: Using an auxdata lookup table should be considered a last resort when
3415c3597dSGrant Likely  * converting a platform to use the DT.  Normally the automatically generated
3515c3597dSGrant Likely  * device name will not matter, and drivers should obtain data from the device
368c1eb253SGeert Uytterhoeven  * node instead of from an anonymous platform_data pointer.
3715c3597dSGrant Likely  */
3815c3597dSGrant Likely struct of_dev_auxdata {
3915c3597dSGrant Likely 	char *compatible;
4015c3597dSGrant Likely 	resource_size_t phys_addr;
4115c3597dSGrant Likely 	char *name;
4215c3597dSGrant Likely 	void *platform_data;
4315c3597dSGrant Likely };
4415c3597dSGrant Likely 
4515c3597dSGrant Likely /* Macro to simplify populating a lookup table */
4615c3597dSGrant Likely #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
4715c3597dSGrant Likely 	{ .compatible = _compat, .phys_addr = _phys, .name = _name, \
4815c3597dSGrant Likely 	  .platform_data = _pdata }
4915c3597dSGrant Likely 
500763ed23SGrant Likely /* Platform drivers register/unregister */
5194a0cb1fSGrant Likely extern struct platform_device *of_device_alloc(struct device_node *np,
5294c09319SGrant Likely 					 const char *bus_id,
5394c09319SGrant Likely 					 struct device *parent);
544c32fb7dSRob Herring 
554c32fb7dSRob Herring extern int of_device_add(struct platform_device *pdev);
564c32fb7dSRob Herring extern int of_device_register(struct platform_device *ofdev);
574c32fb7dSRob Herring extern void of_device_unregister(struct platform_device *ofdev);
584c32fb7dSRob Herring 
59aa767cfbSArnd Bergmann #ifdef CONFIG_OF
6094a0cb1fSGrant Likely extern struct platform_device *of_find_device_by_node(struct device_node *np);
61aa767cfbSArnd Bergmann #else
of_find_device_by_node(struct device_node * np)62aa767cfbSArnd Bergmann static inline struct platform_device *of_find_device_by_node(struct device_node *np)
63aa767cfbSArnd Bergmann {
64aa767cfbSArnd Bergmann 	return NULL;
65aa767cfbSArnd Bergmann }
66aa767cfbSArnd Bergmann #endif
67b41912caSStephen Rothwell 
68620e8e8bSMatthias Kaehlcke extern int of_platform_bus_probe(struct device_node *root,
69620e8e8bSMatthias Kaehlcke 				 const struct of_device_id *matches,
70620e8e8bSMatthias Kaehlcke 				 struct device *parent);
71620e8e8bSMatthias Kaehlcke 
72620e8e8bSMatthias Kaehlcke #ifdef CONFIG_OF_ADDRESS
735fd200f3SGrant Likely /* Platform devices and busses creation */
7494a0cb1fSGrant Likely extern struct platform_device *of_platform_device_create(struct device_node *np,
755fd200f3SGrant Likely 						   const char *bus_id,
765fd200f3SGrant Likely 						   struct device *parent);
775fd200f3SGrant Likely 
78c2372c20SJan Glauber extern int of_platform_device_destroy(struct device *dev, void *data);
79620e8e8bSMatthias Kaehlcke 
8029d4f8a4SGrant Likely extern int of_platform_populate(struct device_node *root,
8129d4f8a4SGrant Likely 				const struct of_device_id *matches,
8215c3597dSGrant Likely 				const struct of_dev_auxdata *lookup,
8329d4f8a4SGrant Likely 				struct device *parent);
8443443ad6SHauke Mehrtens extern int of_platform_default_populate(struct device_node *root,
8543443ad6SHauke Mehrtens 					const struct of_dev_auxdata *lookup,
8643443ad6SHauke Mehrtens 					struct device *parent);
8775f353b6SGrant Likely extern void of_platform_depopulate(struct device *parent);
8838b0b219SBenjamin Gaignard 
8938b0b219SBenjamin Gaignard extern int devm_of_platform_populate(struct device *dev);
9038b0b219SBenjamin Gaignard 
9138b0b219SBenjamin Gaignard extern void devm_of_platform_depopulate(struct device *dev);
928a46f4f7SArnd Bergmann #else
93620e8e8bSMatthias Kaehlcke /* Platform devices and busses creation */
of_platform_device_create(struct device_node * np,const char * bus_id,struct device * parent)94620e8e8bSMatthias Kaehlcke static inline struct platform_device *of_platform_device_create(struct device_node *np,
95620e8e8bSMatthias Kaehlcke 								const char *bus_id,
96620e8e8bSMatthias Kaehlcke 								struct device *parent)
97620e8e8bSMatthias Kaehlcke {
98620e8e8bSMatthias Kaehlcke 	return NULL;
99620e8e8bSMatthias Kaehlcke }
of_platform_device_destroy(struct device * dev,void * data)100620e8e8bSMatthias Kaehlcke static inline int of_platform_device_destroy(struct device *dev, void *data)
101620e8e8bSMatthias Kaehlcke {
102620e8e8bSMatthias Kaehlcke 	return -ENODEV;
103620e8e8bSMatthias Kaehlcke }
104620e8e8bSMatthias Kaehlcke 
of_platform_populate(struct device_node * root,const struct of_device_id * matches,const struct of_dev_auxdata * lookup,struct device * parent)105964dba28SGrant Likely static inline int of_platform_populate(struct device_node *root,
106964dba28SGrant Likely 					const struct of_device_id *matches,
107964dba28SGrant Likely 					const struct of_dev_auxdata *lookup,
108964dba28SGrant Likely 					struct device *parent)
109964dba28SGrant Likely {
110964dba28SGrant Likely 	return -ENODEV;
111964dba28SGrant Likely }
of_platform_default_populate(struct device_node * root,const struct of_dev_auxdata * lookup,struct device * parent)11243443ad6SHauke Mehrtens static inline int of_platform_default_populate(struct device_node *root,
11343443ad6SHauke Mehrtens 					       const struct of_dev_auxdata *lookup,
11443443ad6SHauke Mehrtens 					       struct device *parent)
11543443ad6SHauke Mehrtens {
11643443ad6SHauke Mehrtens 	return -ENODEV;
11743443ad6SHauke Mehrtens }
of_platform_depopulate(struct device * parent)11875f353b6SGrant Likely static inline void of_platform_depopulate(struct device *parent) { }
11938b0b219SBenjamin Gaignard 
devm_of_platform_populate(struct device * dev)12038b0b219SBenjamin Gaignard static inline int devm_of_platform_populate(struct device *dev)
12138b0b219SBenjamin Gaignard {
12238b0b219SBenjamin Gaignard 	return -ENODEV;
12338b0b219SBenjamin Gaignard }
12438b0b219SBenjamin Gaignard 
devm_of_platform_depopulate(struct device * dev)12538b0b219SBenjamin Gaignard static inline void devm_of_platform_depopulate(struct device *dev) { }
1268a46f4f7SArnd Bergmann #endif
1275fd200f3SGrant Likely 
128b41912caSStephen Rothwell #endif	/* _LINUX_OF_PLATFORM_H */
129