blob: c67cc676bbd2dce0df300b9336ffdb6f6cfbe5aa [file] [log] [blame]
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +02001.. SPDX-License-Identifier: GPL-2.0
2
3=========================
Pantelis Antoniou7518b5892014-10-28 22:35:58 +02004Device Tree Overlay Notes
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +02005=========================
Pantelis Antoniou7518b5892014-10-28 22:35:58 +02006
7This document describes the implementation of the in-kernel
8device tree overlay functionality residing in drivers/of/overlay.c and is a
Mauro Carvalho Chehab26853a22020-04-15 16:45:20 +02009companion document to Documentation/devicetree/dynamic-resolution-notes.rst[1]
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020010
11How overlays work
12-----------------
13
14A Device Tree's overlay purpose is to modify the kernel's live tree, and
Masanari Iidaac3e8ea2015-01-02 22:54:39 +090015have the modification affecting the state of the kernel in a way that
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020016is reflecting the changes.
17Since the kernel mainly deals with devices, any new device node that result
18in an active device should have it created while if the device node is either
19disabled or removed all together, the affected device should be deregistered.
20
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020021Lets take an example where we have a foo board with the following base tree::
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020022
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020023 ---- foo.dts ---------------------------------------------------------------
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020024 /* FOO platform */
Frank Rowand9ae85782020-01-27 18:37:18 -060025 /dts-v1/;
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020026 / {
27 compatible = "corp,foo";
28
29 /* shared resources */
30 res: res {
31 };
32
33 /* On chip peripherals */
34 ocp: ocp {
35 /* peripherals that are always instantiated */
36 peripheral1 { ... };
Frank Rowand9ae85782020-01-27 18:37:18 -060037 };
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020038 };
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020039 ---- foo.dts ---------------------------------------------------------------
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020040
Frank Rowand9ae85782020-01-27 18:37:18 -060041The overlay bar.dts,
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020042::
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020043
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020044 ---- bar.dts - overlay target location by label ----------------------------
Frank Rowand9ae85782020-01-27 18:37:18 -060045 /dts-v1/;
46 /plugin/;
47 &ocp {
48 /* bar peripheral */
49 bar {
50 compatible = "corp,bar";
51 ... /* various properties and child nodes */
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020052 };
53 };
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020054 ---- bar.dts ---------------------------------------------------------------
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020055
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020056when loaded (and resolved as described in [1]) should result in foo+bar.dts::
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020057
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020058 ---- foo+bar.dts -----------------------------------------------------------
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020059 /* FOO platform + bar peripheral */
60 / {
61 compatible = "corp,foo";
62
63 /* shared resources */
64 res: res {
65 };
66
67 /* On chip peripherals */
68 ocp: ocp {
69 /* peripherals that are always instantiated */
70 peripheral1 { ... };
71
72 /* bar peripheral */
73 bar {
74 compatible = "corp,bar";
75 ... /* various properties and child nodes */
Frank Rowand9ae85782020-01-27 18:37:18 -060076 };
77 };
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020078 };
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020079 ---- foo+bar.dts -----------------------------------------------------------
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020080
Masanari Iidaac3e8ea2015-01-02 22:54:39 +090081As a result of the overlay, a new device node (bar) has been created
Pantelis Antoniou7518b5892014-10-28 22:35:58 +020082so a bar platform device will be registered and if a matching device driver
83is loaded the device will be created as expected.
84
Frank Rowand9ae85782020-01-27 18:37:18 -060085If the base DT was not compiled with the -@ option then the "&ocp" label
86will not be available to resolve the overlay node(s) to the proper location
87in the base DT. In this case, the target path can be provided. The target
88location by label syntax is preferred because the overlay can be applied to
89any base DT containing the label, no matter where the label occurs in the DT.
90
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020091The above bar.dts example modified to use target path syntax is::
Frank Rowand9ae85782020-01-27 18:37:18 -060092
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +020093 ---- bar.dts - overlay target location by explicit path --------------------
Frank Rowand9ae85782020-01-27 18:37:18 -060094 /dts-v1/;
95 /plugin/;
96 &{/ocp} {
97 /* bar peripheral */
98 bar {
99 compatible = "corp,bar";
100 ... /* various properties and child nodes */
101 }
102 };
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +0200103 ---- bar.dts ---------------------------------------------------------------
Frank Rowand9ae85782020-01-27 18:37:18 -0600104
105
Pantelis Antoniou7518b5892014-10-28 22:35:58 +0200106Overlay in-kernel API
107--------------------------------
108
109The API is quite easy to use.
110
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +02001111) Call of_overlay_fdt_apply() to create and apply an overlay changeset. The
112 return value is an error or a cookie identifying this overlay.
Pantelis Antoniou7518b5892014-10-28 22:35:58 +0200113
Mauro Carvalho Chehab642e6e5c2020-04-15 16:45:22 +02001142) Call of_overlay_remove() to remove and cleanup the overlay changeset
115 previously created via the call to of_overlay_fdt_apply(). Removal of an
116 overlay changeset that is stacked by another will not be permitted.
Pantelis Antoniou7518b5892014-10-28 22:35:58 +0200117
118Finally, if you need to remove all overlays in one-go, just call
Frank Rowand0290c4c2017-10-17 16:36:23 -0700119of_overlay_remove_all() which will remove every single one in the correct
Pantelis Antoniou7518b5892014-10-28 22:35:58 +0200120order.
121
Jan Kiszka83ef4772018-04-26 13:00:30 +0200122In addition, there is the option to register notifiers that get called on
123overlay operations. See of_overlay_notifier_register/unregister and
124enum of_overlay_notify_action for details.
125
126Note that a notifier callback is not supposed to store pointers to a device
127tree node or its content beyond OF_OVERLAY_POST_REMOVE corresponding to the
128respective node it received.