]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/dm/device.h
dm: Allow drivers to be marked 'before relocation'
[karo-tx-uboot.git] / include / dm / device.h
1 /*
2  * Copyright (c) 2013 Google, Inc
3  *
4  * (C) Copyright 2012
5  * Pavel Herrmann <morpheus.ibis@gmail.com>
6  * Marek Vasut <marex@denx.de>
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 #ifndef _DM_DEVICE_H
12 #define _DM_DEVICE_H
13
14 #include <dm/uclass-id.h>
15 #include <linker_lists.h>
16 #include <linux/list.h>
17
18 struct driver_info;
19
20 /* Driver is active (probed). Cleared when it is removed */
21 #define DM_FLAG_ACTIVATED       (1 << 0)
22
23 /* DM is responsible for allocating and freeing platdata */
24 #define DM_FLAG_ALLOC_PDATA     (1 << 1)
25
26 /* DM should init this device prior to relocation */
27 #define DM_FLAG_PRE_RELOC       (1 << 2)
28
29 /**
30  * struct udevice - An instance of a driver
31  *
32  * This holds information about a device, which is a driver bound to a
33  * particular port or peripheral (essentially a driver instance).
34  *
35  * A device will come into existence through a 'bind' call, either due to
36  * a U_BOOT_DEVICE() macro (in which case platdata is non-NULL) or a node
37  * in the device tree (in which case of_offset is >= 0). In the latter case
38  * we translate the device tree information into platdata in a function
39  * implemented by the driver ofdata_to_platdata method (called just before the
40  * probe method if the device has a device tree node.
41  *
42  * All three of platdata, priv and uclass_priv can be allocated by the
43  * driver, or you can use the auto_alloc_size members of struct driver and
44  * struct uclass_driver to have driver model do this automatically.
45  *
46  * @driver: The driver used by this device
47  * @name: Name of device, typically the FDT node name
48  * @platdata: Configuration data for this device
49  * @of_offset: Device tree node offset for this device (- for none)
50  * @parent: Parent of this device, or NULL for the top level device
51  * @priv: Private data for this device
52  * @uclass: Pointer to uclass for this device
53  * @uclass_priv: The uclass's private data for this device
54  * @uclass_node: Used by uclass to link its devices
55  * @child_head: List of children of this device
56  * @sibling_node: Next device in list of all devices
57  * @flags: Flags for this device DM_FLAG_...
58  */
59 struct udevice {
60         struct driver *driver;
61         const char *name;
62         void *platdata;
63         int of_offset;
64         struct udevice *parent;
65         void *priv;
66         struct uclass *uclass;
67         void *uclass_priv;
68         struct list_head uclass_node;
69         struct list_head child_head;
70         struct list_head sibling_node;
71         uint32_t flags;
72 };
73
74 /* Returns the operations for a device */
75 #define device_get_ops(dev)     (dev->driver->ops)
76
77 /* Returns non-zero if the device is active (probed and not removed) */
78 #define device_active(dev)      ((dev)->flags & DM_FLAG_ACTIVATED)
79
80 /**
81  * struct udevice_id - Lists the compatible strings supported by a driver
82  * @compatible: Compatible string
83  * @data: Data for this compatible string
84  */
85 struct udevice_id {
86         const char *compatible;
87         ulong data;
88 };
89
90 /**
91  * struct driver - A driver for a feature or peripheral
92  *
93  * This holds methods for setting up a new device, and also removing it.
94  * The device needs information to set itself up - this is provided either
95  * by platdata or a device tree node (which we find by looking up
96  * matching compatible strings with of_match).
97  *
98  * Drivers all belong to a uclass, representing a class of devices of the
99  * same type. Common elements of the drivers can be implemented in the uclass,
100  * or the uclass can provide a consistent interface to the drivers within
101  * it.
102  *
103  * @name: Device name
104  * @id: Identiies the uclass we belong to
105  * @of_match: List of compatible strings to match, and any identifying data
106  * for each.
107  * @bind: Called to bind a device to its driver
108  * @probe: Called to probe a device, i.e. activate it
109  * @remove: Called to remove a device, i.e. de-activate it
110  * @unbind: Called to unbind a device from its driver
111  * @ofdata_to_platdata: Called before probe to decode device tree data
112  * @priv_auto_alloc_size: If non-zero this is the size of the private data
113  * to be allocated in the device's ->priv pointer. If zero, then the driver
114  * is responsible for allocating any data required.
115  * @platdata_auto_alloc_size: If non-zero this is the size of the
116  * platform data to be allocated in the device's ->platdata pointer.
117  * This is typically only useful for device-tree-aware drivers (those with
118  * an of_match), since drivers which use platdata will have the data
119  * provided in the U_BOOT_DEVICE() instantiation.
120  * ops: Driver-specific operations. This is typically a list of function
121  * pointers defined by the driver, to implement driver functions required by
122  * the uclass.
123  * @flags: driver flags - see DM_FLAGS_...
124  */
125 struct driver {
126         char *name;
127         enum uclass_id id;
128         const struct udevice_id *of_match;
129         int (*bind)(struct udevice *dev);
130         int (*probe)(struct udevice *dev);
131         int (*remove)(struct udevice *dev);
132         int (*unbind)(struct udevice *dev);
133         int (*ofdata_to_platdata)(struct udevice *dev);
134         int priv_auto_alloc_size;
135         int platdata_auto_alloc_size;
136         const void *ops;        /* driver-specific operations */
137         uint32_t flags;
138 };
139
140 /* Declare a new U-Boot driver */
141 #define U_BOOT_DRIVER(__name)                                           \
142         ll_entry_declare(struct driver, __name, driver)
143
144 /**
145  * dev_get_platdata() - Get the platform data for a device
146  *
147  * This checks that dev is not NULL, but no other checks for now
148  *
149  * @dev         Device to check
150  * @return platform data, or NULL if none
151  */
152 void *dev_get_platdata(struct udevice *dev);
153
154 /**
155  * dev_get_priv() - Get the private data for a device
156  *
157  * This checks that dev is not NULL, but no other checks for now
158  *
159  * @dev         Device to check
160  * @return private data, or NULL if none
161  */
162 void *dev_get_priv(struct udevice *dev);
163
164 #endif