| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 1 | #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 |  | 
| Grant Likely | efb2e01 | 2010-04-13 16:12:27 -0700 | [diff] [blame] | 14 | #ifdef CONFIG_OF_DEVICE | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 15 | #include <linux/device.h> | 
 | 16 | #include <linux/mod_devicetable.h> | 
 | 17 | #include <linux/pm.h> | 
 | 18 | #include <linux/of_device.h> | 
| Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 19 | #include <linux/platform_device.h> | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 20 |  | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 21 | /** | 
| Grant Likely | 15c3597 | 2011-06-21 10:59:35 -0600 | [diff] [blame] | 22 |  * struct of_dev_auxdata - lookup table entry for device names & platform_data | 
 | 23 |  * @compatible: compatible value of node to match against node | 
 | 24 |  * @phys_addr: Start address of registers to match against node | 
 | 25 |  * @name: Name to assign for matching nodes | 
 | 26 |  * @platform_data: platform_data to assign for matching nodes | 
 | 27 |  * | 
 | 28 |  * This lookup table allows the caller of of_platform_populate() to override | 
 | 29 |  * the names of devices when creating devices from the device tree.  The table | 
 | 30 |  * should be terminated with an empty entry.  It also allows the platform_data | 
 | 31 |  * pointer to be set. | 
 | 32 |  * | 
 | 33 |  * The reason for this functionality is that some Linux infrastructure uses | 
 | 34 |  * the device name to look up a specific device, but the Linux-specific names | 
 | 35 |  * are not encoded into the device tree, so the kernel needs to provide specific | 
 | 36 |  * values. | 
 | 37 |  * | 
 | 38 |  * Note: Using an auxdata lookup table should be considered a last resort when | 
 | 39 |  * converting a platform to use the DT.  Normally the automatically generated | 
 | 40 |  * device name will not matter, and drivers should obtain data from the device | 
 | 41 |  * node instead of from an anonymouns platform_data pointer. | 
 | 42 |  */ | 
 | 43 | struct of_dev_auxdata { | 
 | 44 | 	char *compatible; | 
 | 45 | 	resource_size_t phys_addr; | 
 | 46 | 	char *name; | 
 | 47 | 	void *platform_data; | 
 | 48 | }; | 
 | 49 |  | 
 | 50 | /* Macro to simplify populating a lookup table */ | 
 | 51 | #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \ | 
 | 52 | 	{ .compatible = _compat, .phys_addr = _phys, .name = _name, \ | 
 | 53 | 	  .platform_data = _pdata } | 
 | 54 |  | 
 | 55 | /** | 
| Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 56 |  * of_platform_driver - Legacy of-aware driver for platform devices. | 
 | 57 |  * | 
 | 58 |  * An of_platform_driver driver is attached to a basic platform_device on | 
| Grant Likely | d714d19 | 2011-02-22 20:22:44 -0700 | [diff] [blame] | 59 |  * the ibm ebus (ibmebus_bus_type). | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 60 |  */ | 
 | 61 | struct of_platform_driver | 
 | 62 | { | 
| Grant Likely | 94a0cb1 | 2010-07-22 13:59:23 -0600 | [diff] [blame] | 63 | 	int	(*probe)(struct platform_device* dev, | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 64 | 			 const struct of_device_id *match); | 
| Grant Likely | 94a0cb1 | 2010-07-22 13:59:23 -0600 | [diff] [blame] | 65 | 	int	(*remove)(struct platform_device* dev); | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 66 |  | 
| Grant Likely | 94a0cb1 | 2010-07-22 13:59:23 -0600 | [diff] [blame] | 67 | 	int	(*suspend)(struct platform_device* dev, pm_message_t state); | 
 | 68 | 	int	(*resume)(struct platform_device* dev); | 
 | 69 | 	int	(*shutdown)(struct platform_device* dev); | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 70 |  | 
 | 71 | 	struct device_driver	driver; | 
 | 72 | }; | 
 | 73 | #define	to_of_platform_driver(drv) \ | 
 | 74 | 	container_of(drv,struct of_platform_driver, driver) | 
 | 75 |  | 
| Grant Likely | cbb49c2 | 2011-06-21 10:59:34 -0600 | [diff] [blame] | 76 | extern const struct of_device_id of_default_bus_match_table[]; | 
 | 77 |  | 
| Grant Likely | 0763ed2 | 2009-04-30 15:08:50 -0700 | [diff] [blame] | 78 | /* Platform drivers register/unregister */ | 
| Grant Likely | 94a0cb1 | 2010-07-22 13:59:23 -0600 | [diff] [blame] | 79 | extern struct platform_device *of_device_alloc(struct device_node *np, | 
| Grant Likely | 94c0931 | 2010-06-08 07:48:14 -0600 | [diff] [blame] | 80 | 					 const char *bus_id, | 
 | 81 | 					 struct device *parent); | 
| Grant Likely | 94a0cb1 | 2010-07-22 13:59:23 -0600 | [diff] [blame] | 82 | extern struct platform_device *of_find_device_by_node(struct device_node *np); | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 83 |  | 
| Grant Likely | 964dba2 | 2012-02-24 14:58:34 -0700 | [diff] [blame] | 84 | #ifdef CONFIG_OF_ADDRESS /* device reg helpers depend on OF_ADDRESS */ | 
| Grant Likely | 5fd200f | 2010-06-08 07:48:13 -0600 | [diff] [blame] | 85 | /* Platform devices and busses creation */ | 
| Grant Likely | 94a0cb1 | 2010-07-22 13:59:23 -0600 | [diff] [blame] | 86 | extern struct platform_device *of_platform_device_create(struct device_node *np, | 
| Grant Likely | 5fd200f | 2010-06-08 07:48:13 -0600 | [diff] [blame] | 87 | 						   const char *bus_id, | 
 | 88 | 						   struct device *parent); | 
 | 89 |  | 
| Grant Likely | 5fd200f | 2010-06-08 07:48:13 -0600 | [diff] [blame] | 90 | extern int of_platform_bus_probe(struct device_node *root, | 
 | 91 | 				 const struct of_device_id *matches, | 
 | 92 | 				 struct device *parent); | 
| Grant Likely | 29d4f8a | 2011-06-21 10:59:34 -0600 | [diff] [blame] | 93 | extern int of_platform_populate(struct device_node *root, | 
 | 94 | 				const struct of_device_id *matches, | 
| Grant Likely | 15c3597 | 2011-06-21 10:59:35 -0600 | [diff] [blame] | 95 | 				const struct of_dev_auxdata *lookup, | 
| Grant Likely | 29d4f8a | 2011-06-21 10:59:34 -0600 | [diff] [blame] | 96 | 				struct device *parent); | 
| Grant Likely | e7cc3ac | 2012-03-02 21:05:31 -0700 | [diff] [blame] | 97 | #endif /* CONFIG_OF_ADDRESS */ | 
 | 98 |  | 
 | 99 | #endif /* CONFIG_OF_DEVICE */ | 
 | 100 |  | 
 | 101 | #if !defined(CONFIG_OF_ADDRESS) | 
 | 102 | struct of_dev_auxdata; | 
| Grant Likely | 964dba2 | 2012-02-24 14:58:34 -0700 | [diff] [blame] | 103 | static inline int of_platform_populate(struct device_node *root, | 
 | 104 | 					const struct of_device_id *matches, | 
 | 105 | 					const struct of_dev_auxdata *lookup, | 
 | 106 | 					struct device *parent) | 
 | 107 | { | 
 | 108 | 	return -ENODEV; | 
 | 109 | } | 
 | 110 | #endif /* !CONFIG_OF_ADDRESS */ | 
| Grant Likely | 5fd200f | 2010-06-08 07:48:13 -0600 | [diff] [blame] | 111 |  | 
| Stephen Rothwell | b41912c | 2007-05-01 16:12:57 +1000 | [diff] [blame] | 112 | #endif	/* _LINUX_OF_PLATFORM_H */ |