xref: /freebsd/share/man/man9/ofw_bus_is_compatible.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1f510c340SOleksandr Tymoshenko.\" -*- nroff -*-
2f510c340SOleksandr Tymoshenko.\"
3f510c340SOleksandr Tymoshenko.\" Copyright (c) 2018 Oleksandr Tymoshenko
4f510c340SOleksandr Tymoshenko.\"
5f510c340SOleksandr Tymoshenko.\" All rights reserved.
6f510c340SOleksandr Tymoshenko.\"
7f510c340SOleksandr Tymoshenko.\" This program is free software.
8f510c340SOleksandr Tymoshenko.\"
9f510c340SOleksandr Tymoshenko.\" Redistribution and use in source and binary forms, with or without
10f510c340SOleksandr Tymoshenko.\" modification, are permitted provided that the following conditions
11f510c340SOleksandr Tymoshenko.\" are met:
12f510c340SOleksandr Tymoshenko.\" 1. Redistributions of source code must retain the above copyright
13f510c340SOleksandr Tymoshenko.\"    notice, this list of conditions and the following disclaimer.
14f510c340SOleksandr Tymoshenko.\" 2. Redistributions in binary form must reproduce the above copyright
15f510c340SOleksandr Tymoshenko.\"    notice, this list of conditions and the following disclaimer in the
16f510c340SOleksandr Tymoshenko.\"    documentation and/or other materials provided with the distribution.
17f510c340SOleksandr Tymoshenko.\"
18f510c340SOleksandr Tymoshenko.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19f510c340SOleksandr Tymoshenko.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20f510c340SOleksandr Tymoshenko.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21f510c340SOleksandr Tymoshenko.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22f510c340SOleksandr Tymoshenko.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23f510c340SOleksandr Tymoshenko.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24f510c340SOleksandr Tymoshenko.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25f510c340SOleksandr Tymoshenko.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26f510c340SOleksandr Tymoshenko.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27f510c340SOleksandr Tymoshenko.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28f510c340SOleksandr Tymoshenko.\"
29f510c340SOleksandr Tymoshenko.Dd April 8, 2018
30f510c340SOleksandr Tymoshenko.Dt ofw_bus_is_compatible 9
31f510c340SOleksandr Tymoshenko.Os
32f510c340SOleksandr Tymoshenko.Sh NAME
33*8bf0ef84SGordon Bergling.Nm ofw_bus_is_compatible ,
34*8bf0ef84SGordon Bergling.Nm ofw_bus_is_compatible_strict ,
35*8bf0ef84SGordon Bergling.Nm ofw_bus_node_is_compatible ,
36f510c340SOleksandr Tymoshenko.Nm ofw_bus_search_compatible
37f510c340SOleksandr Tymoshenko.Nd check device tree nodes for compatibility with drivers
38f510c340SOleksandr Tymoshenko.Sh SYNOPSIS
39f510c340SOleksandr Tymoshenko.In dev/ofw/openfirm.h
40f510c340SOleksandr Tymoshenko.In dev/ofw/ofw_bus.h
41f510c340SOleksandr Tymoshenko.In dev/ofw/ofw_bus_subr.h
42f510c340SOleksandr Tymoshenko.Ft int
43f510c340SOleksandr Tymoshenko.Fn ofw_bus_is_compatible "device_t dev" "const char *compatstr"
44f510c340SOleksandr Tymoshenko.Ft int
45f510c340SOleksandr Tymoshenko.Fn ofw_bus_is_compatible_strict "device_t dev" "const char *compatstr"
46f510c340SOleksandr Tymoshenko.Ft int
47f510c340SOleksandr Tymoshenko.Fn ofw_bus_node_is_compatible "phandle_t node" "const char *compatstr"
48f510c340SOleksandr Tymoshenko.Ft const struct ofw_compat_data *
49f510c340SOleksandr Tymoshenko.Fn ofw_bus_search_compatible "device_t dev" "const struct ofw_compat_data *compat"
50f510c340SOleksandr Tymoshenko.Sh DESCRIPTION
51f510c340SOleksandr TymoshenkoThe "compatible" property of the device tree node is used to
52f510c340SOleksandr Tymoshenkoidentify the type of the device the node represents.
53f510c340SOleksandr TymoshenkoThe property is a list of one or more strings that represent
54f510c340SOleksandr Tymoshenkohardware types the device is compatible with.
55f510c340SOleksandr TymoshenkoThe common format for such strings is "vendor,hardware"
56f510c340SOleksandr Tymoshenkowhere "vendor" is an abbreviated name of the manufacturer
57f510c340SOleksandr Tymoshenkoand "hardware" is a device identifier, for instance, "fsl"
58f510c340SOleksandr Tymoshenkofor "Freescale" and "imx6ul-i2c" for the I2C controller.
59f510c340SOleksandr TymoshenkoMore than one string is required for compatibility with
60f510c340SOleksandr Tymoshenkoolder revisions of the driver.
61f510c340SOleksandr TymoshenkoIf hardware revision B is backward compatible with revision
62f510c340SOleksandr TymoshenkoA device tree node can signal this compatibility by
63f510c340SOleksandr Tymoshenkoproviding both "vndr,hrdwrA" and "vndr,hrdwrB" strings in
64f510c340SOleksandr Tymoshenkothe "compatibile" property value.
65f510c340SOleksandr TymoshenkoThis way older driver can use features available only in
66f510c340SOleksandr Tymoshenkorevision A, and the new version of the driver can take
67f510c340SOleksandr Tymoshenkoadvantage of revision B feature set.
68f510c340SOleksandr Tymoshenko.Pp
69f510c340SOleksandr Tymoshenko.Fn ofw_bus_is_compatible
70f510c340SOleksandr Tymoshenkoreturns 1 if the
71f510c340SOleksandr Tymoshenko.Fa compatstr
72f510c340SOleksandr Tymoshenkovalue occurs in the "compatible" property list of the device
73f510c340SOleksandr Tymoshenkotree node associated with the device
74f510c340SOleksandr Tymoshenko.Fa dev ,
75f510c340SOleksandr Tymoshenkoand 0 otherwise.
76f510c340SOleksandr Tymoshenko.Pp
77f510c340SOleksandr Tymoshenko.Fn ofw_bus_is_compatible_strict
78f510c340SOleksandr Tymoshenkoreturn 1 if the "compatible"
79f510c340SOleksandr Tymoshenkoproperty of the device tree node associated with the device
80f510c340SOleksandr Tymoshenko.Fa dev
81f510c340SOleksandr Tymoshenkoconsists of only one string and this string is equal to
82f510c340SOleksandr Tymoshenko.Fa compatstr ,
83f510c340SOleksandr Tymoshenkoand 0 otherwise.
84f510c340SOleksandr Tymoshenko.Pp
85f510c340SOleksandr Tymoshenko.Fn ofw_bus_node_is_compatible
86f510c340SOleksandr Tymoshenkoreturns 1 if the
87f510c340SOleksandr Tymoshenko.Fa compatstr
88f510c340SOleksandr Tymoshenkovalue occurs in the "compatible" property list of the device
89f510c340SOleksandr Tymoshenkotree node
90f510c340SOleksandr Tymoshenko.Fa node ,
91f510c340SOleksandr Tymoshenkoand 0 otherwise.
92f510c340SOleksandr Tymoshenko.Pp
93f510c340SOleksandr Tymoshenko.Fn ofw_bus_search_compatible
94f510c340SOleksandr Tymoshenkoreturns pointer to the first entry of the
95f510c340SOleksandr Tymoshenko.Fa compat
96f510c340SOleksandr Tymoshenkotable whose ocd_str field occurs in "compatible" property of
97f510c340SOleksandr Tymoshenkothe device tree node associated with the device
98f510c340SOleksandr Tymoshenko.Fa dev .
99f510c340SOleksandr TymoshenkoThe
100f510c340SOleksandr Tymoshenko.Fa compat
101f510c340SOleksandr Tymoshenkotable is an array of struct ofw_compat_data elements defined as follows:
102f510c340SOleksandr Tymoshenko.Bd -literal -offset indent
103f510c340SOleksandr Tymoshenkostruct ofw_compat_data {
104f510c340SOleksandr Tymoshenko	const char *ocd_str;
105f510c340SOleksandr Tymoshenko	uintptr_t  ocd_data;
106f510c340SOleksandr Tymoshenko};
107f510c340SOleksandr Tymoshenko.Ed
108f510c340SOleksandr TymoshenkoThe
109f510c340SOleksandr Tymoshenko.Fa compat
110f510c340SOleksandr Tymoshenkotable must be terminated by the entry with ocd_str set to NULL.
111f510c340SOleksandr TymoshenkoIf the device tree node is not compatible with any of
112f510c340SOleksandr Tymoshenkothe entries, the function returns the pointer to the
113f510c340SOleksandr Tymoshenkoterminating entry.
114f510c340SOleksandr Tymoshenko.Sh EXAMPLES
115f510c340SOleksandr Tymoshenko.Bd -literal -offset indent
116f510c340SOleksandr Tymoshenkostatic struct ofw_compat_data compat_data[] = {
117f510c340SOleksandr Tymoshenko	{"arm,hrdwrA",		FEATURE_A},
118f510c340SOleksandr Tymoshenko	{"arm,hrdwrB",		FEATURE_A | FEATURE_B},
119f510c340SOleksandr Tymoshenko	{NULL,			0}
120f510c340SOleksandr Tymoshenko};
121f510c340SOleksandr Tymoshenko
122f510c340SOleksandr Tymoshenkostatic int
123f510c340SOleksandr Tymoshenkohrdwr_probe(device_t dev)
124f510c340SOleksandr Tymoshenko{
125f510c340SOleksandr Tymoshenko	...
126f510c340SOleksandr Tymoshenko	if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data)
127f510c340SOleksandr Tymoshenko		return (ENXIO);
128f510c340SOleksandr Tymoshenko	...
129f510c340SOleksandr Tymoshenko}
130f510c340SOleksandr Tymoshenko
131f510c340SOleksandr Tymoshenkostatic int
132f510c340SOleksandr Tymoshenkohrdwr_attach(device_t dev)
133f510c340SOleksandr Tymoshenko{
134f510c340SOleksandr Tymoshenko	...
135f510c340SOleksandr Tymoshenko	sc = device_get_softc(dev);
136f510c340SOleksandr Tymoshenko	sc->sc_features = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
137f510c340SOleksandr Tymoshenko	...
138f510c340SOleksandr Tymoshenko}
139f510c340SOleksandr Tymoshenko.Ed
140f510c340SOleksandr Tymoshenko.Sh SEE ALSO
141f510c340SOleksandr Tymoshenko.Xr ofw_bus_find_compatible 9
142f510c340SOleksandr Tymoshenko.Sh AUTHORS
143f510c340SOleksandr TymoshenkoThis manual page was written by
144f510c340SOleksandr Tymoshenko.An Oleksandr Tymoshenko .
145