blob: 3863a4dbdf1888c51ff9d4ae94057a31e5118034 [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
Grant Likelyefb2e012010-04-13 16:12:27 -070014#ifdef CONFIG_OF_DEVICE
Stephen Rothwellb41912c2007-05-01 16:12:57 +100015#include <linux/device.h>
16#include <linux/mod_devicetable.h>
17#include <linux/pm.h>
18#include <linux/of_device.h>
Grant Likelyeca39302010-06-08 07:48:21 -060019#include <linux/platform_device.h>
Stephen Rothwellb41912c2007-05-01 16:12:57 +100020
Grant Likely2dc11582010-08-06 09:25:50 -060021/**
Grant Likely15c35972011-06-21 10:59:35 -060022 * 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 */
43struct 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 Likely2dc11582010-08-06 09:25:50 -060056 * 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 Likelyd714d192011-02-22 20:22:44 -070059 * the ibm ebus (ibmebus_bus_type).
Stephen Rothwellb41912c2007-05-01 16:12:57 +100060 */
61struct of_platform_driver
62{
Grant Likely94a0cb12010-07-22 13:59:23 -060063 int (*probe)(struct platform_device* dev,
Stephen Rothwellb41912c2007-05-01 16:12:57 +100064 const struct of_device_id *match);
Grant Likely94a0cb12010-07-22 13:59:23 -060065 int (*remove)(struct platform_device* dev);
Stephen Rothwellb41912c2007-05-01 16:12:57 +100066
Grant Likely94a0cb12010-07-22 13:59:23 -060067 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 Rothwellb41912c2007-05-01 16:12:57 +100070
71 struct device_driver driver;
72};
73#define to_of_platform_driver(drv) \
74 container_of(drv,struct of_platform_driver, driver)
75
Grant Likelycbb49c22011-06-21 10:59:34 -060076extern const struct of_device_id of_default_bus_match_table[];
77
Grant Likely0763ed22009-04-30 15:08:50 -070078/* Platform drivers register/unregister */
Grant Likely94a0cb12010-07-22 13:59:23 -060079extern struct platform_device *of_device_alloc(struct device_node *np,
Grant Likely94c09312010-06-08 07:48:14 -060080 const char *bus_id,
81 struct device *parent);
Grant Likely94a0cb12010-07-22 13:59:23 -060082extern struct platform_device *of_find_device_by_node(struct device_node *np);
Stephen Rothwellb41912c2007-05-01 16:12:57 +100083
Grant Likely964dba22012-02-24 14:58:34 -070084#ifdef CONFIG_OF_ADDRESS /* device reg helpers depend on OF_ADDRESS */
Grant Likely5fd200f2010-06-08 07:48:13 -060085/* Platform devices and busses creation */
Grant Likely94a0cb12010-07-22 13:59:23 -060086extern struct platform_device *of_platform_device_create(struct device_node *np,
Grant Likely5fd200f2010-06-08 07:48:13 -060087 const char *bus_id,
88 struct device *parent);
89
Grant Likely5fd200f2010-06-08 07:48:13 -060090extern int of_platform_bus_probe(struct device_node *root,
91 const struct of_device_id *matches,
92 struct device *parent);
Grant Likely29d4f8a2011-06-21 10:59:34 -060093extern int of_platform_populate(struct device_node *root,
94 const struct of_device_id *matches,
Grant Likely15c35972011-06-21 10:59:35 -060095 const struct of_dev_auxdata *lookup,
Grant Likely29d4f8a2011-06-21 10:59:34 -060096 struct device *parent);
Grant Likelye7cc3ac2012-03-02 21:05:31 -070097#endif /* CONFIG_OF_ADDRESS */
98
99#endif /* CONFIG_OF_DEVICE */
100
101#if !defined(CONFIG_OF_ADDRESS)
102struct of_dev_auxdata;
Jonas Gorskiab286982012-12-19 09:10:09 -0600103struct device;
Grant Likely964dba22012-02-24 14:58:34 -0700104static inline int of_platform_populate(struct device_node *root,
105 const struct of_device_id *matches,
106 const struct of_dev_auxdata *lookup,
107 struct device *parent)
108{
109 return -ENODEV;
110}
111#endif /* !CONFIG_OF_ADDRESS */
Grant Likely5fd200f2010-06-08 07:48:13 -0600112
Stephen Rothwellb41912c2007-05-01 16:12:57 +1000113#endif /* _LINUX_OF_PLATFORM_H */