mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-25 14:10:43 +00:00
dm: core: Add a flag to control sequence numbering
At present we try to use the 'reg' property and device tree aliases to give devices a sequence number. The 'reg' property is often actually a memory address, so the sequence numbers thus-obtained are not useful. It would be better if the devices were just sequentially numbered in that case. In fact neither I2C nor SPI use this feature, so drop it. Some devices need us to look up an alias to number them within the uclass. Add a flag to control this, so it is not done unless it is needed. Adjust the tests to test this new behaviour. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
This commit is contained in:
parent
b367053102
commit
9cc36a2b89
9 changed files with 58 additions and 59 deletions
|
@ -388,12 +388,12 @@ Device Sequence Numbers
|
|||
U-Boot numbers devices from 0 in many situations, such as in the command
|
||||
line for I2C and SPI buses, and the device names for serial ports (serial0,
|
||||
serial1, ...). Driver model supports this numbering and permits devices
|
||||
to be locating by their 'sequence'. This numbering unique identifies a
|
||||
to be locating by their 'sequence'. This numbering uniquely identifies a
|
||||
device in its uclass, so no two devices within a particular uclass can have
|
||||
the same sequence number.
|
||||
|
||||
Sequence numbers start from 0 but gaps are permitted. For example, a board
|
||||
may have I2C buses 0, 1, 4, 5 but no 2 or 3. The choice of how devices are
|
||||
may have I2C buses 1, 4, 5 but no 0, 2 or 3. The choice of how devices are
|
||||
numbered is up to a particular board, and may be set by the SoC in some
|
||||
cases. While it might be tempting to automatically renumber the devices
|
||||
where there are gaps in the sequence, this can lead to confusion and is
|
||||
|
@ -403,7 +403,7 @@ Each device can request a sequence number. If none is required then the
|
|||
device will be automatically allocated the next available sequence number.
|
||||
|
||||
To specify the sequence number in the device tree an alias is typically
|
||||
used.
|
||||
used. Make sure that the uclass has the DM_UC_FLAG_SEQ_ALIAS flag set.
|
||||
|
||||
aliases {
|
||||
serial2 = "/serial@22230000";
|
||||
|
@ -413,43 +413,18 @@ This indicates that in the uclass called "serial", the named node
|
|||
("/serial@22230000") will be given sequence number 2. Any command or driver
|
||||
which requests serial device 2 will obtain this device.
|
||||
|
||||
Some devices represent buses where the devices on the bus are numbered or
|
||||
addressed. For example, SPI typically numbers its slaves from 0, and I2C
|
||||
uses a 7-bit address. In these cases the 'reg' property of the subnode is
|
||||
used, for example:
|
||||
More commonly you can use node references, which expand to the full path:
|
||||
|
||||
{
|
||||
aliases {
|
||||
spi2 = "/spi@22300000";
|
||||
};
|
||||
aliases {
|
||||
serial2 = &serial_2;
|
||||
};
|
||||
...
|
||||
serial_2: serial@22230000 {
|
||||
...
|
||||
};
|
||||
|
||||
spi@22300000 {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
spi-flash@0 {
|
||||
reg = <0>;
|
||||
...
|
||||
}
|
||||
eeprom@1 {
|
||||
reg = <1>;
|
||||
};
|
||||
};
|
||||
|
||||
In this case we have a SPI bus with two slaves at 0 and 1. The SPI bus
|
||||
itself is numbered 2. So we might access the SPI flash with:
|
||||
|
||||
sf probe 2:0
|
||||
|
||||
and the eeprom with
|
||||
|
||||
sspi 2:1 32 ef
|
||||
|
||||
These commands simply need to look up the 2nd device in the SPI uclass to
|
||||
find the right SPI bus. Then, they look at the children of that bus for the
|
||||
right sequence number (0 or 1 in this case).
|
||||
|
||||
Typically the alias method is used for top-level nodes and the 'reg' method
|
||||
is used only for buses.
|
||||
The alias resolves to the same string in this case, but this version is
|
||||
easier to read.
|
||||
|
||||
Device sequence numbers are resolved when a device is probed. Before then
|
||||
the sequence number is only a request which may or may not be honoured,
|
||||
|
|
|
@ -53,24 +53,22 @@ int device_bind(struct udevice *parent, struct driver *drv, const char *name,
|
|||
dev->driver = drv;
|
||||
dev->uclass = uc;
|
||||
|
||||
/*
|
||||
* For some devices, such as a SPI or I2C bus, the 'reg' property
|
||||
* is a reasonable indicator of the sequence number. But if there is
|
||||
* an alias, we use that in preference. In any case, this is just
|
||||
* a 'requested' sequence, and will be resolved (and ->seq updated)
|
||||
* when the device is probed.
|
||||
*/
|
||||
dev->seq = -1;
|
||||
#ifdef CONFIG_OF_CONTROL
|
||||
dev->req_seq = fdtdec_get_int(gd->fdt_blob, of_offset, "reg", -1);
|
||||
if (!IS_ERR_VALUE(dev->req_seq))
|
||||
dev->req_seq &= INT_MAX;
|
||||
if (uc->uc_drv->name && of_offset != -1) {
|
||||
fdtdec_get_alias_seq(gd->fdt_blob, uc->uc_drv->name, of_offset,
|
||||
&dev->req_seq);
|
||||
}
|
||||
#else
|
||||
dev->req_seq = -1;
|
||||
#ifdef CONFIG_OF_CONTROL
|
||||
/*
|
||||
* Some devices, such as a SPI bus, I2C bus and serial ports are
|
||||
* numbered using aliases.
|
||||
*
|
||||
* This is just a 'requested' sequence, and will be
|
||||
* resolved (and ->seq updated) when the device is probed.
|
||||
*/
|
||||
if (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS) {
|
||||
if (uc->uc_drv->name && of_offset != -1) {
|
||||
fdtdec_get_alias_seq(gd->fdt_blob, uc->uc_drv->name,
|
||||
of_offset, &dev->req_seq);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!dev->platdata && drv->platdata_auto_alloc_size) {
|
||||
dev->flags |= DM_FLAG_ALLOC_PDATA;
|
||||
|
|
|
@ -453,6 +453,7 @@ int i2c_post_bind(struct udevice *dev)
|
|||
UCLASS_DRIVER(i2c) = {
|
||||
.id = UCLASS_I2C,
|
||||
.name = "i2c",
|
||||
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
||||
.per_device_auto_alloc_size = sizeof(struct dm_i2c_bus),
|
||||
.post_bind = i2c_post_bind,
|
||||
.post_probe = i2c_post_probe,
|
||||
|
|
|
@ -297,6 +297,7 @@ static int serial_pre_remove(struct udevice *dev)
|
|||
UCLASS_DRIVER(serial) = {
|
||||
.id = UCLASS_SERIAL,
|
||||
.name = "serial",
|
||||
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
||||
.post_probe = serial_post_probe,
|
||||
.pre_remove = serial_pre_remove,
|
||||
.per_device_auto_alloc_size = sizeof(struct serial_dev_priv),
|
||||
|
|
|
@ -344,6 +344,7 @@ int spi_ofdata_to_platdata(const void *blob, int node,
|
|||
UCLASS_DRIVER(spi) = {
|
||||
.id = UCLASS_SPI,
|
||||
.name = "spi",
|
||||
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
||||
.post_bind = spi_post_bind,
|
||||
.post_probe = spi_post_probe,
|
||||
.per_device_auto_alloc_size = sizeof(struct dm_spi_bus),
|
||||
|
|
|
@ -40,6 +40,9 @@ struct uclass {
|
|||
|
||||
struct udevice;
|
||||
|
||||
/* Members of this uclass sequence themselves with aliases */
|
||||
#define DM_UC_FLAG_SEQ_ALIAS (1 << 0)
|
||||
|
||||
/**
|
||||
* struct uclass_driver - Driver for the uclass
|
||||
*
|
||||
|
@ -66,6 +69,7 @@ struct udevice;
|
|||
* a falback if this member is 0 in the driver.
|
||||
* @ops: Uclass operations, providing the consistent interface to devices
|
||||
* within the uclass.
|
||||
* @flags: Flags for this uclass (DM_UC_...)
|
||||
*/
|
||||
struct uclass_driver {
|
||||
const char *name;
|
||||
|
@ -80,6 +84,7 @@ struct uclass_driver {
|
|||
int per_device_auto_alloc_size;
|
||||
int per_child_platdata_auto_alloc_size;
|
||||
const void *ops;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
/* Declare a new uclass_driver */
|
||||
|
|
|
@ -88,12 +88,13 @@ U_BOOT_DRIVER(testbus_drv) = {
|
|||
UCLASS_DRIVER(testbus) = {
|
||||
.name = "testbus",
|
||||
.id = UCLASS_TEST_BUS,
|
||||
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
||||
};
|
||||
|
||||
/* Test that we can probe for children */
|
||||
static int dm_test_bus_children(struct dm_test_state *dms)
|
||||
{
|
||||
int num_devices = 4;
|
||||
int num_devices = 6;
|
||||
struct udevice *bus;
|
||||
struct uclass *uc;
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
|
|||
UCLASS_DRIVER(testfdt) = {
|
||||
.name = "testfdt",
|
||||
.id = UCLASS_TEST_FDT,
|
||||
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
||||
};
|
||||
|
||||
int dm_check_devices(struct dm_test_state *dms, int num_devices)
|
||||
|
@ -128,7 +129,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices)
|
|||
/* Test that FDT-based binding works correctly */
|
||||
static int dm_test_fdt(struct dm_test_state *dms)
|
||||
{
|
||||
const int num_devices = 4;
|
||||
const int num_devices = 6;
|
||||
struct udevice *dev;
|
||||
struct uclass *uc;
|
||||
int ret;
|
||||
|
@ -184,7 +185,7 @@ static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)
|
|||
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, true, &dev));
|
||||
ut_asserteq_str("b-test", dev->name);
|
||||
|
||||
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 0, true, &dev));
|
||||
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, true, &dev));
|
||||
ut_asserteq_str("a-test", dev->name);
|
||||
|
||||
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 5,
|
||||
|
@ -220,11 +221,11 @@ static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)
|
|||
ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_TEST_FDT, 1,
|
||||
&dev));
|
||||
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
|
||||
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 1, &dev));
|
||||
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 4, &dev));
|
||||
|
||||
/* But now that it is probed, we can find it */
|
||||
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 1, &dev));
|
||||
ut_asserteq_str("a-test", dev->name);
|
||||
ut_asserteq_str("f-test", dev->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,15 @@
|
|||
|
||||
aliases {
|
||||
console = &uart0;
|
||||
i2c0 = "/i2c@0";
|
||||
spi0 = "/spi@0";
|
||||
testfdt6 = "/e-test";
|
||||
testbus3 = "/some-bus";
|
||||
testfdt0 = "/some-bus/c-test@0";
|
||||
testfdt1 = "/some-bus/c-test@1";
|
||||
testfdt3 = "/b-test";
|
||||
testfdt5 = "/some-bus/c-test@5";
|
||||
testfdt8 = "/a-test";
|
||||
};
|
||||
|
||||
uart0: serial {
|
||||
|
@ -86,6 +94,14 @@
|
|||
compatible = "google,another-fdt-test";
|
||||
};
|
||||
|
||||
f-test {
|
||||
compatible = "denx,u-boot-fdt-test";
|
||||
};
|
||||
|
||||
g-test {
|
||||
compatible = "denx,u-boot-fdt-test";
|
||||
};
|
||||
|
||||
gpio_a: base-gpios {
|
||||
compatible = "sandbox,gpio";
|
||||
gpio-controller;
|
||||
|
|
Loading…
Reference in a new issue