blob: 5a6f458a4bb745c0ab4058448a5c2c4834cf809d [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/module.h>
16#include <linux/device.h>
17#include <linux/mod_devicetable.h>
18#include <linux/pm.h>
19#include <linux/of_device.h>
Grant Likelyeca39302010-06-08 07:48:21 -060020#include <linux/platform_device.h>
Stephen Rothwellb41912c2007-05-01 16:12:57 +100021
Grant Likely2dc11582010-08-06 09:25:50 -060022/**
Grant Likely15c35972011-06-21 10:59:35 -060023 * struct of_dev_auxdata - lookup table entry for device names & platform_data
24 * @compatible: compatible value of node to match against node
25 * @phys_addr: Start address of registers to match against node
26 * @name: Name to assign for matching nodes
27 * @platform_data: platform_data to assign for matching nodes
28 *
29 * This lookup table allows the caller of of_platform_populate() to override
30 * the names of devices when creating devices from the device tree. The table
31 * should be terminated with an empty entry. It also allows the platform_data
32 * pointer to be set.
33 *
34 * The reason for this functionality is that some Linux infrastructure uses
35 * the device name to look up a specific device, but the Linux-specific names
36 * are not encoded into the device tree, so the kernel needs to provide specific
37 * values.
38 *
39 * Note: Using an auxdata lookup table should be considered a last resort when
40 * converting a platform to use the DT. Normally the automatically generated
41 * device name will not matter, and drivers should obtain data from the device
42 * node instead of from an anonymouns platform_data pointer.
43 */
44struct of_dev_auxdata {
45 char *compatible;
46 resource_size_t phys_addr;
47 char *name;
48 void *platform_data;
49};
50
51/* Macro to simplify populating a lookup table */
52#define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
53 { .compatible = _compat, .phys_addr = _phys, .name = _name, \
54 .platform_data = _pdata }
55
56/**
Grant Likely2dc11582010-08-06 09:25:50 -060057 * of_platform_driver - Legacy of-aware driver for platform devices.
58 *
59 * An of_platform_driver driver is attached to a basic platform_device on
Grant Likelyd714d192011-02-22 20:22:44 -070060 * the ibm ebus (ibmebus_bus_type).
Stephen Rothwellb41912c2007-05-01 16:12:57 +100061 */
62struct of_platform_driver
63{
Grant Likely94a0cb12010-07-22 13:59:23 -060064 int (*probe)(struct platform_device* dev,
Stephen Rothwellb41912c2007-05-01 16:12:57 +100065 const struct of_device_id *match);
Grant Likely94a0cb12010-07-22 13:59:23 -060066 int (*remove)(struct platform_device* dev);
Stephen Rothwellb41912c2007-05-01 16:12:57 +100067
Grant Likely94a0cb12010-07-22 13:59:23 -060068 int (*suspend)(struct platform_device* dev, pm_message_t state);
69 int (*resume)(struct platform_device* dev);
70 int (*shutdown)(struct platform_device* dev);
Stephen Rothwellb41912c2007-05-01 16:12:57 +100071
72 struct device_driver driver;
73};
74#define to_of_platform_driver(drv) \
75 container_of(drv,struct of_platform_driver, driver)
76
Grant Likelycbb49c22011-06-21 10:59:34 -060077extern const struct of_device_id of_default_bus_match_table[];
78
Grant Likely0763ed22009-04-30 15:08:50 -070079/* Platform drivers register/unregister */
Grant Likely94a0cb12010-07-22 13:59:23 -060080extern struct platform_device *of_device_alloc(struct device_node *np,
Grant Likely94c09312010-06-08 07:48:14 -060081 const char *bus_id,
82 struct device *parent);
Grant Likely94a0cb12010-07-22 13:59:23 -060083extern struct platform_device *of_find_device_by_node(struct device_node *np);
Stephen Rothwellb41912c2007-05-01 16:12:57 +100084
Grant Likely5fd200f2010-06-08 07:48:13 -060085#if !defined(CONFIG_SPARC) /* SPARC has its own device registration method */
86/* Platform devices and busses creation */
Grant Likely94a0cb12010-07-22 13:59:23 -060087extern struct platform_device *of_platform_device_create(struct device_node *np,
Grant Likely5fd200f2010-06-08 07:48:13 -060088 const char *bus_id,
89 struct device *parent);
90
Grant Likely5fd200f2010-06-08 07:48:13 -060091extern int of_platform_bus_probe(struct device_node *root,
92 const struct of_device_id *matches,
93 struct device *parent);
Grant Likely29d4f8a2011-06-21 10:59:34 -060094extern int of_platform_populate(struct device_node *root,
95 const struct of_device_id *matches,
Grant Likely15c35972011-06-21 10:59:35 -060096 const struct of_dev_auxdata *lookup,
Grant Likely29d4f8a2011-06-21 10:59:34 -060097 struct device *parent);
Grant Likely5fd200f2010-06-08 07:48:13 -060098#endif /* !CONFIG_SPARC */
99
Grant Likelyefb2e012010-04-13 16:12:27 -0700100#endif /* CONFIG_OF_DEVICE */
Stephen Rothwell3f23de12007-05-03 02:38:57 +1000101
Stephen Rothwellb41912c2007-05-01 16:12:57 +1000102#endif /* _LINUX_OF_PLATFORM_H */