2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-06-27 09:37:19 +00:00
|
|
|
/*
|
|
|
|
* drivers/mfd/mfd-core.c
|
|
|
|
*
|
|
|
|
* core MFD support
|
|
|
|
* Copyright (c) 2006 Ian Molton
|
|
|
|
* Copyright (c) 2007,2008 Dmitry Baryshkov
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
2010-02-19 10:07:59 +00:00
|
|
|
#include <linux/acpi.h>
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
#include <linux/list.h>
|
2015-11-30 15:11:40 +00:00
|
|
|
#include <linux/property.h>
|
2008-06-27 09:37:19 +00:00
|
|
|
#include <linux/mfd/core.h>
|
2010-11-26 17:19:34 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2011-07-03 19:13:27 +00:00
|
|
|
#include <linux/module.h>
|
2012-06-29 17:01:03 +00:00
|
|
|
#include <linux/irqdomain.h>
|
|
|
|
#include <linux/of.h>
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
#include <linux/of_address.h>
|
2013-10-15 19:14:21 +00:00
|
|
|
#include <linux/regulator/consumer.h>
|
2008-06-27 09:37:19 +00:00
|
|
|
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
static LIST_HEAD(mfd_of_node_list);
|
|
|
|
|
|
|
|
struct mfd_of_node_entry {
|
|
|
|
struct list_head list;
|
|
|
|
struct device *dev;
|
|
|
|
struct device_node *np;
|
|
|
|
};
|
|
|
|
|
2012-11-09 16:15:28 +00:00
|
|
|
static struct device_type mfd_dev_type = {
|
|
|
|
.name = "mfd_device",
|
|
|
|
};
|
|
|
|
|
2011-03-03 17:51:58 +00:00
|
|
|
int mfd_cell_enable(struct platform_device *pdev)
|
2011-02-18 03:07:34 +00:00
|
|
|
{
|
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
|
|
|
|
2019-10-21 09:16:34 +00:00
|
|
|
if (!cell->enable) {
|
|
|
|
dev_dbg(&pdev->dev, "No .enable() call-back registered\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-21 09:47:37 +00:00
|
|
|
return cell->enable(pdev);
|
2011-02-18 03:07:34 +00:00
|
|
|
}
|
2011-03-03 17:51:58 +00:00
|
|
|
EXPORT_SYMBOL(mfd_cell_enable);
|
2011-02-18 03:07:34 +00:00
|
|
|
|
2011-03-03 17:51:58 +00:00
|
|
|
int mfd_cell_disable(struct platform_device *pdev)
|
2011-02-18 03:07:34 +00:00
|
|
|
{
|
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
|
|
|
|
2019-10-21 09:16:34 +00:00
|
|
|
if (!cell->disable) {
|
|
|
|
dev_dbg(&pdev->dev, "No .disable() call-back registered\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-21 09:47:37 +00:00
|
|
|
return cell->disable(pdev);
|
2011-02-18 03:07:34 +00:00
|
|
|
}
|
2011-03-03 17:51:58 +00:00
|
|
|
EXPORT_SYMBOL(mfd_cell_disable);
|
2011-02-18 03:07:34 +00:00
|
|
|
|
2014-09-16 11:52:36 +00:00
|
|
|
#if IS_ENABLED(CONFIG_ACPI)
|
|
|
|
static void mfd_acpi_add_device(const struct mfd_cell *cell,
|
|
|
|
struct platform_device *pdev)
|
|
|
|
{
|
2015-10-23 09:16:41 +00:00
|
|
|
const struct mfd_cell_acpi_match *match = cell->acpi_match;
|
|
|
|
struct acpi_device *parent, *child;
|
2014-09-16 11:52:36 +00:00
|
|
|
struct acpi_device *adev;
|
|
|
|
|
2015-10-23 09:16:41 +00:00
|
|
|
parent = ACPI_COMPANION(pdev->dev.parent);
|
|
|
|
if (!parent)
|
2014-09-16 11:52:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2015-10-23 09:16:41 +00:00
|
|
|
* MFD child device gets its ACPI handle either from the ACPI device
|
|
|
|
* directly under the parent that matches the either _HID or _CID, or
|
|
|
|
* _ADR or it will use the parent handle if is no ID is given.
|
|
|
|
*
|
|
|
|
* Note that use of _ADR is a grey area in the ACPI specification,
|
|
|
|
* though Intel Galileo Gen2 is using it to distinguish the children
|
|
|
|
* devices.
|
2014-09-16 11:52:36 +00:00
|
|
|
*/
|
2015-10-23 09:16:41 +00:00
|
|
|
adev = parent;
|
|
|
|
if (match) {
|
|
|
|
if (match->pnpid) {
|
|
|
|
struct acpi_device_id ids[2] = {};
|
|
|
|
|
|
|
|
strlcpy(ids[0].id, match->pnpid, sizeof(ids[0].id));
|
|
|
|
list_for_each_entry(child, &parent->children, node) {
|
2016-03-13 01:02:58 +00:00
|
|
|
if (!acpi_match_device_ids(child, ids)) {
|
2015-10-23 09:16:41 +00:00
|
|
|
adev = child;
|
|
|
|
break;
|
|
|
|
}
|
2014-09-16 11:52:36 +00:00
|
|
|
}
|
2015-10-23 09:16:41 +00:00
|
|
|
} else {
|
|
|
|
unsigned long long adr;
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
list_for_each_entry(child, &parent->children, node) {
|
|
|
|
status = acpi_evaluate_integer(child->handle,
|
|
|
|
"_ADR", NULL,
|
|
|
|
&adr);
|
|
|
|
if (ACPI_SUCCESS(status) && match->adr == adr) {
|
|
|
|
adev = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-16 11:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_COMPANION_SET(&pdev->dev, adev);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void mfd_acpi_add_device(const struct mfd_cell *cell,
|
|
|
|
struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
static int mfd_match_of_node_to_dev(struct platform_device *pdev,
|
|
|
|
struct device_node *np,
|
|
|
|
const struct mfd_cell *cell)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_OF)
|
|
|
|
struct mfd_of_node_entry *of_entry;
|
|
|
|
const __be32 *reg;
|
|
|
|
u64 of_node_addr;
|
|
|
|
|
|
|
|
/* Skip if OF node has previously been allocated to a device */
|
|
|
|
list_for_each_entry(of_entry, &mfd_of_node_list, list)
|
|
|
|
if (of_entry->np == np)
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
if (!cell->use_of_reg)
|
|
|
|
/* No of_reg defined - allocate first free compatible match */
|
|
|
|
goto allocate_of_node;
|
|
|
|
|
|
|
|
/* We only care about each node's first defined address */
|
|
|
|
reg = of_get_address(np, 0, NULL, NULL);
|
|
|
|
if (!reg)
|
|
|
|
/* OF node does not contatin a 'reg' property to match to */
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
of_node_addr = of_read_number(reg, of_n_addr_cells(np));
|
|
|
|
|
|
|
|
if (cell->of_reg != of_node_addr)
|
|
|
|
/* No match */
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
allocate_of_node:
|
|
|
|
of_entry = kzalloc(sizeof(*of_entry), GFP_KERNEL);
|
|
|
|
if (!of_entry)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
of_entry->dev = &pdev->dev;
|
|
|
|
of_entry->np = np;
|
|
|
|
list_add_tail(&of_entry->list, &mfd_of_node_list);
|
|
|
|
|
|
|
|
pdev->dev.of_node = np;
|
|
|
|
pdev->dev.fwnode = &np->fwnode;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-28 23:30:26 +00:00
|
|
|
static int mfd_add_device(struct device *parent, int id,
|
2019-10-21 09:47:37 +00:00
|
|
|
const struct mfd_cell *cell,
|
2008-07-28 16:29:09 +00:00
|
|
|
struct resource *mem_base,
|
2012-09-11 07:16:36 +00:00
|
|
|
int irq_base, struct irq_domain *domain)
|
2008-06-27 09:37:19 +00:00
|
|
|
{
|
2008-07-25 21:59:29 +00:00
|
|
|
struct resource *res;
|
2008-06-27 09:37:19 +00:00
|
|
|
struct platform_device *pdev;
|
2012-06-29 17:01:03 +00:00
|
|
|
struct device_node *np = NULL;
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
struct mfd_of_node_entry *of_entry, *tmp;
|
2008-06-27 09:37:19 +00:00
|
|
|
int ret = -ENOMEM;
|
2014-09-26 10:55:33 +00:00
|
|
|
int platform_id;
|
2008-06-27 09:37:19 +00:00
|
|
|
int r;
|
|
|
|
|
2015-03-25 11:07:05 +00:00
|
|
|
if (id == PLATFORM_DEVID_AUTO)
|
2014-09-26 10:55:33 +00:00
|
|
|
platform_id = id;
|
|
|
|
else
|
|
|
|
platform_id = id + cell->id;
|
|
|
|
|
|
|
|
pdev = platform_device_alloc(cell->name, platform_id);
|
2008-06-27 09:37:19 +00:00
|
|
|
if (!pdev)
|
|
|
|
goto fail_alloc;
|
|
|
|
|
2019-10-21 09:55:23 +00:00
|
|
|
pdev->mfd_cell = kmemdup(cell, sizeof(*cell), GFP_KERNEL);
|
|
|
|
if (!pdev->mfd_cell)
|
|
|
|
goto fail_device;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 21:03:40 +00:00
|
|
|
res = kcalloc(cell->num_resources, sizeof(*res), GFP_KERNEL);
|
2008-07-25 21:59:29 +00:00
|
|
|
if (!res)
|
|
|
|
goto fail_device;
|
|
|
|
|
2008-07-28 23:30:26 +00:00
|
|
|
pdev->dev.parent = parent;
|
2012-11-09 16:15:28 +00:00
|
|
|
pdev->dev.type = &mfd_dev_type;
|
2013-08-13 09:08:38 +00:00
|
|
|
pdev->dev.dma_mask = parent->dma_mask;
|
|
|
|
pdev->dev.dma_parms = parent->dma_parms;
|
2014-09-22 19:37:55 +00:00
|
|
|
pdev->dev.coherent_dma_mask = parent->coherent_dma_mask;
|
2008-06-27 09:37:19 +00:00
|
|
|
|
2014-04-24 17:27:25 +00:00
|
|
|
ret = regulator_bulk_register_supply_alias(
|
2013-10-15 19:14:21 +00:00
|
|
|
&pdev->dev, cell->parent_supplies,
|
|
|
|
parent, cell->parent_supplies,
|
|
|
|
cell->num_parent_supplies);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail_res;
|
|
|
|
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
if (IS_ENABLED(CONFIG_OF) && parent->of_node && cell->of_compatible) {
|
2012-06-29 17:01:03 +00:00
|
|
|
for_each_child_of_node(parent->of_node, np) {
|
|
|
|
if (of_device_is_compatible(np, cell->of_compatible)) {
|
2020-08-19 08:16:50 +00:00
|
|
|
/* Ignore 'disabled' devices error free */
|
|
|
|
if (!of_device_is_available(np)) {
|
|
|
|
ret = 0;
|
|
|
|
goto fail_alias;
|
|
|
|
}
|
|
|
|
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
ret = mfd_match_of_node_to_dev(pdev, np, cell);
|
|
|
|
if (ret == -EAGAIN)
|
|
|
|
continue;
|
|
|
|
if (ret)
|
2019-11-07 11:19:50 +00:00
|
|
|
goto fail_alias;
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
|
2012-06-29 17:01:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
|
|
|
|
if (!pdev->dev.of_node)
|
|
|
|
pr_warn("%s: Failed to locate of_node [id: %d]\n",
|
|
|
|
cell->name, platform_id);
|
2012-06-29 17:01:03 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 11:52:36 +00:00
|
|
|
mfd_acpi_add_device(cell, pdev);
|
|
|
|
|
2011-04-06 14:52:52 +00:00
|
|
|
if (cell->pdata_size) {
|
|
|
|
ret = platform_device_add_data(pdev,
|
|
|
|
cell->platform_data, cell->pdata_size);
|
|
|
|
if (ret)
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
goto fail_of_entry;
|
2011-04-06 14:52:52 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 11:52:23 +00:00
|
|
|
if (cell->properties) {
|
|
|
|
ret = platform_device_add_properties(pdev, cell->properties);
|
2015-11-30 15:11:40 +00:00
|
|
|
if (ret)
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
goto fail_of_entry;
|
2015-11-30 15:11:40 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 14:42:19 +00:00
|
|
|
if (cell->swnode) {
|
|
|
|
ret = device_add_software_node(&pdev->dev, cell->swnode);
|
|
|
|
if (ret)
|
|
|
|
goto fail_of_entry;
|
|
|
|
}
|
|
|
|
|
2008-06-27 09:37:19 +00:00
|
|
|
for (r = 0; r < cell->num_resources; r++) {
|
|
|
|
res[r].name = cell->resources[r].name;
|
|
|
|
res[r].flags = cell->resources[r].flags;
|
|
|
|
|
|
|
|
/* Find out base to use */
|
2010-03-26 00:09:04 +00:00
|
|
|
if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) {
|
2008-06-27 09:37:19 +00:00
|
|
|
res[r].parent = mem_base;
|
|
|
|
res[r].start = mem_base->start +
|
|
|
|
cell->resources[r].start;
|
|
|
|
res[r].end = mem_base->start +
|
|
|
|
cell->resources[r].end;
|
|
|
|
} else if (cell->resources[r].flags & IORESOURCE_IRQ) {
|
2012-06-29 17:01:03 +00:00
|
|
|
if (domain) {
|
|
|
|
/* Unable to create mappings for IRQ ranges. */
|
|
|
|
WARN_ON(cell->resources[r].start !=
|
|
|
|
cell->resources[r].end);
|
|
|
|
res[r].start = res[r].end = irq_create_mapping(
|
|
|
|
domain, cell->resources[r].start);
|
|
|
|
} else {
|
|
|
|
res[r].start = irq_base +
|
|
|
|
cell->resources[r].start;
|
|
|
|
res[r].end = irq_base +
|
|
|
|
cell->resources[r].end;
|
|
|
|
}
|
2008-06-27 09:37:19 +00:00
|
|
|
} else {
|
|
|
|
res[r].parent = cell->resources[r].parent;
|
|
|
|
res[r].start = cell->resources[r].start;
|
|
|
|
res[r].end = cell->resources[r].end;
|
|
|
|
}
|
2010-02-19 10:07:59 +00:00
|
|
|
|
2010-09-30 20:55:36 +00:00
|
|
|
if (!cell->ignore_resource_conflicts) {
|
2015-05-01 09:41:10 +00:00
|
|
|
if (has_acpi_companion(&pdev->dev)) {
|
|
|
|
ret = acpi_check_resource_conflict(&res[r]);
|
|
|
|
if (ret)
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
goto fail_of_entry;
|
2015-05-01 09:41:10 +00:00
|
|
|
}
|
2010-09-30 20:55:36 +00:00
|
|
|
}
|
2008-06-27 09:37:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-31 09:30:55 +00:00
|
|
|
ret = platform_device_add_resources(pdev, res, cell->num_resources);
|
|
|
|
if (ret)
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
goto fail_of_entry;
|
2008-06-27 09:37:19 +00:00
|
|
|
|
|
|
|
ret = platform_device_add(pdev);
|
|
|
|
if (ret)
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
goto fail_of_entry;
|
2008-07-25 21:59:29 +00:00
|
|
|
|
2010-11-26 17:19:34 +00:00
|
|
|
if (cell->pm_runtime_no_callbacks)
|
|
|
|
pm_runtime_no_callbacks(&pdev->dev);
|
|
|
|
|
2008-07-25 21:59:29 +00:00
|
|
|
kfree(res);
|
2008-06-27 09:37:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
mfd: core: Make a best effort attempt to match devices with the correct of_nodes
Currently, when a child platform device (sometimes referred to as a
sub-device) is registered via the Multi-Functional Device (MFD) API,
the framework attempts to match the newly registered platform device
with its associated Device Tree (OF) node. Until now, the device has
been allocated the first node found with an identical OF compatible
string. Unfortunately, if there are, say for example '3' devices
which are to be handled by the same driver and therefore have the same
compatible string, each of them will be allocated a pointer to the
*first* node.
An example Device Tree entry might look like this:
mfd_of_test {
compatible = "mfd,of-test-parent";
#address-cells = <0x02>;
#size-cells = <0x02>;
child@aaaaaaaaaaaaaaaa {
compatible = "mfd,of-test-child";
reg = <0xaaaaaaaa 0xaaaaaaaa 0 0x11>,
<0xbbbbbbbb 0xbbbbbbbb 0 0x22>;
};
child@cccccccc {
compatible = "mfd,of-test-child";
reg = <0x00000000 0xcccccccc 0 0x33>;
};
child@dddddddd00000000 {
compatible = "mfd,of-test-child";
reg = <0xdddddddd 0x00000000 0 0x44>;
};
};
When used with example sub-device registration like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 0, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child")
};
... the current implementation will result in all devices being allocated
the first OF node found containing a matching compatible string:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@aaaaaaaaaaaaaaaa
After this patch each device will be allocated a unique OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@cccccccc
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@dddddddd00000000
Which is fine if all OF nodes are identical. However if we wish to
apply an attribute to particular device, we really need to ensure the
correct OF node will be associated with the device containing the
correct address. We accomplish this by matching the device's address
expressed in DT with one provided during sub-device registration.
Like this:
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child", 0xdddddddd00000000),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
This will ensure a specific device (designated here using the
platform_ids; 1, 2 and 3) is matched with a particular OF node:
[0.712511] mfd-of-test-child mfd-of-test-child.0: Probing platform device: 0
[0.712710] mfd-of-test-child mfd-of-test-child.0: Using OF node: child@dddddddd00000000
[0.713033] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.713381] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.713691] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.713889] mfd-of-test-child mfd-of-test-child.2: Using OF node: child@cccccccc
This implementation is still not infallible, hence the mention of
"best effort" in the commit subject. Since we have not *insisted* on
the existence of 'reg' properties (in some scenarios they just do not
make sense) and no device currently uses the new 'of_reg' attribute,
we have to make an on-the-fly judgement call whether to associate the
OF node anyway. Which we do in cases where parent drivers haven't
specified a particular OF node to match to. So there is a *slight*
possibility of the following result (note: the implementation here is
convoluted, but it shows you one means by which this process can
still break):
/*
* First entry will match to the first OF node with matching compatible
* Second will fail, since the first took its OF node and is no longer available
* Third will succeed
*/
static const struct mfd_cell mfd_of_test_cell[] = {
OF_MFD_CELL("mfd-of-test-child", NULL, NULL, 0, 1, "mfd,of-test-child"),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 2, "mfd,of-test-child", 0xaaaaaaaaaaaaaaaa),
OF_MFD_CELL_REG("mfd-of-test-child", NULL, NULL, 0, 3, "mfd,of-test-child", 0x00000000cccccccc)
};
The result:
[0.753869] mfd-of-test-parent mfd_of_test: Registering 3 devices
[0.756597] mfd-of-test-child: Failed to locate of_node [id: 2]
[0.759999] mfd-of-test-child mfd-of-test-child.1: Probing platform device: 1
[0.760314] mfd-of-test-child mfd-of-test-child.1: Using OF node: child@aaaaaaaaaaaaaaaa
[0.760908] mfd-of-test-child mfd-of-test-child.2: Probing platform device: 2
[0.761183] mfd-of-test-child mfd-of-test-child.2: No OF node associated with this device
[0.761621] mfd-of-test-child mfd-of-test-child.3: Probing platform device: 3
[0.761899] mfd-of-test-child mfd-of-test-child.3: Using OF node: child@cccccccc
We could code around this with some pre-parsing semantics, but the
added complexity required to cover each and every corner-case is not
justified. Merely patching the current failing (via this patch) is
already working with some pretty small corner-cases. Other issues
should be patched in the parent drivers which can be achieved simply
by implementing OF_MFD_CELL_REG().
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2020-06-11 06:35:33 +00:00
|
|
|
fail_of_entry:
|
|
|
|
list_for_each_entry_safe(of_entry, tmp, &mfd_of_node_list, list)
|
|
|
|
if (of_entry->dev == &pdev->dev) {
|
|
|
|
list_del(&of_entry->list);
|
|
|
|
kfree(of_entry);
|
|
|
|
}
|
2021-03-01 14:42:19 +00:00
|
|
|
device_remove_software_node(&pdev->dev);
|
2013-10-15 19:14:21 +00:00
|
|
|
fail_alias:
|
2014-04-24 17:27:25 +00:00
|
|
|
regulator_bulk_unregister_supply_alias(&pdev->dev,
|
|
|
|
cell->parent_supplies,
|
|
|
|
cell->num_parent_supplies);
|
2008-07-25 21:59:29 +00:00
|
|
|
fail_res:
|
|
|
|
kfree(res);
|
2008-06-27 09:37:19 +00:00
|
|
|
fail_device:
|
|
|
|
platform_device_put(pdev);
|
|
|
|
fail_alloc:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-23 09:04:45 +00:00
|
|
|
/**
|
|
|
|
* mfd_add_devices - register child devices
|
|
|
|
*
|
|
|
|
* @parent: Pointer to parent device.
|
|
|
|
* @id: Can be PLATFORM_DEVID_AUTO to let the Platform API take care
|
|
|
|
* of device numbering, or will be added to a device's cell_id.
|
|
|
|
* @cells: Array of (struct mfd_cell)s describing child devices.
|
|
|
|
* @n_devs: Number of child devices to register.
|
|
|
|
* @mem_base: Parent register range resource for child devices.
|
|
|
|
* @irq_base: Base of the range of virtual interrupt numbers allocated for
|
|
|
|
* this MFD device. Unused if @domain is specified.
|
|
|
|
* @domain: Interrupt domain to create mappings for hardware interrupts.
|
|
|
|
*/
|
2008-07-28 23:30:26 +00:00
|
|
|
int mfd_add_devices(struct device *parent, int id,
|
2013-10-29 09:03:04 +00:00
|
|
|
const struct mfd_cell *cells, int n_devs,
|
2008-07-28 16:29:09 +00:00
|
|
|
struct resource *mem_base,
|
2012-09-11 07:16:36 +00:00
|
|
|
int irq_base, struct irq_domain *domain)
|
2008-06-27 09:37:19 +00:00
|
|
|
{
|
|
|
|
int i;
|
2013-10-29 14:47:22 +00:00
|
|
|
int ret;
|
2008-06-27 09:37:19 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_devs; i++) {
|
2019-10-21 09:47:37 +00:00
|
|
|
ret = mfd_add_device(parent, id, cells + i, mem_base,
|
2012-09-11 07:16:36 +00:00
|
|
|
irq_base, domain);
|
2008-06-27 09:37:19 +00:00
|
|
|
if (ret)
|
2013-10-29 14:47:22 +00:00
|
|
|
goto fail;
|
2008-06-27 09:37:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 14:47:22 +00:00
|
|
|
return 0;
|
2008-06-27 09:37:19 +00:00
|
|
|
|
2013-10-29 14:47:22 +00:00
|
|
|
fail:
|
|
|
|
if (i)
|
|
|
|
mfd_remove_devices(parent);
|
2019-10-21 09:47:37 +00:00
|
|
|
|
2008-06-27 09:37:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mfd_add_devices);
|
|
|
|
|
2019-10-21 09:47:37 +00:00
|
|
|
static int mfd_remove_devices_fn(struct device *dev, void *data)
|
2008-06-27 09:37:19 +00:00
|
|
|
{
|
2012-11-09 16:15:28 +00:00
|
|
|
struct platform_device *pdev;
|
|
|
|
const struct mfd_cell *cell;
|
2020-07-23 10:54:58 +00:00
|
|
|
int *level = data;
|
2011-02-18 03:07:34 +00:00
|
|
|
|
2012-11-09 16:15:28 +00:00
|
|
|
if (dev->type != &mfd_dev_type)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pdev = to_platform_device(dev);
|
|
|
|
cell = mfd_get_cell(pdev);
|
|
|
|
|
2020-07-23 10:54:58 +00:00
|
|
|
if (level && cell->level > *level)
|
|
|
|
return 0;
|
|
|
|
|
2014-04-24 17:27:25 +00:00
|
|
|
regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies,
|
|
|
|
cell->num_parent_supplies);
|
|
|
|
|
2021-03-01 14:42:19 +00:00
|
|
|
device_remove_software_node(&pdev->dev);
|
|
|
|
|
2011-02-18 03:07:34 +00:00
|
|
|
platform_device_unregister(pdev);
|
2008-06-27 09:37:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-23 10:54:58 +00:00
|
|
|
void mfd_remove_devices_late(struct device *parent)
|
|
|
|
{
|
|
|
|
int level = MFD_DEP_LEVEL_HIGH;
|
|
|
|
|
|
|
|
device_for_each_child_reverse(parent, &level, mfd_remove_devices_fn);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mfd_remove_devices_late);
|
|
|
|
|
2008-07-28 23:30:26 +00:00
|
|
|
void mfd_remove_devices(struct device *parent)
|
2008-06-27 09:37:19 +00:00
|
|
|
{
|
2020-07-23 10:54:58 +00:00
|
|
|
int level = MFD_DEP_LEVEL_NORMAL;
|
|
|
|
|
|
|
|
device_for_each_child_reverse(parent, &level, mfd_remove_devices_fn);
|
2008-06-27 09:37:19 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mfd_remove_devices);
|
|
|
|
|
2016-04-07 18:42:55 +00:00
|
|
|
static void devm_mfd_dev_release(struct device *dev, void *res)
|
|
|
|
{
|
|
|
|
mfd_remove_devices(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* devm_mfd_add_devices - Resource managed version of mfd_add_devices()
|
|
|
|
*
|
|
|
|
* Returns 0 on success or an appropriate negative error number on failure.
|
|
|
|
* All child-devices of the MFD will automatically be removed when it gets
|
|
|
|
* unbinded.
|
2020-06-23 14:51:28 +00:00
|
|
|
*
|
|
|
|
* @dev: Pointer to parent device.
|
|
|
|
* @id: Can be PLATFORM_DEVID_AUTO to let the Platform API take care
|
|
|
|
* of device numbering, or will be added to a device's cell_id.
|
|
|
|
* @cells: Array of (struct mfd_cell)s describing child devices.
|
|
|
|
* @n_devs: Number of child devices to register.
|
|
|
|
* @mem_base: Parent register range resource for child devices.
|
|
|
|
* @irq_base: Base of the range of virtual interrupt numbers allocated for
|
|
|
|
* this MFD device. Unused if @domain is specified.
|
|
|
|
* @domain: Interrupt domain to create mappings for hardware interrupts.
|
2016-04-07 18:42:55 +00:00
|
|
|
*/
|
|
|
|
int devm_mfd_add_devices(struct device *dev, int id,
|
|
|
|
const struct mfd_cell *cells, int n_devs,
|
|
|
|
struct resource *mem_base,
|
|
|
|
int irq_base, struct irq_domain *domain)
|
|
|
|
{
|
|
|
|
struct device **ptr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ptr = devres_alloc(devm_mfd_dev_release, sizeof(*ptr), GFP_KERNEL);
|
|
|
|
if (!ptr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = mfd_add_devices(dev, id, cells, n_devs, mem_base,
|
|
|
|
irq_base, domain);
|
|
|
|
if (ret < 0) {
|
|
|
|
devres_free(ptr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr = dev;
|
|
|
|
devres_add(dev, ptr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(devm_mfd_add_devices);
|
|
|
|
|
2008-06-27 09:37:19 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov");
|