From: Kory Maincent <kory.maincent@bootlin.com>
To: u-boot@lists.denx.de
Subject: [PATCH v5 06/10] w1: replace dt detection by automatic detection
Date: Tue, 4 May 2021 19:31:26 +0200 [thread overview]
Message-ID: <20210504173130.22869-7-kory.maincent@bootlin.com> (raw)
In-Reply-To: <20210504173130.22869-1-kory.maincent@bootlin.com>
This patch changes the functioning of the detection of w1 devices.
The old way was a comparison between detected w1 and the ones described in
the device tree. Now it will just look for the driver matching the family
id of the w1 detected.
The patch is inspired from Maxime Ripard code.
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
Reviewed-by: Maxime Ripard <maxime@cerno.tech>
---
Change since v2:
- drop the remove action of devicetree match in the W1 EEPROMs drivers.
- move the w1_device_register function to w1-uclass.
- update the w1_device_register function to be compatible with automatic
detection and devicetree detection. I will not bind the device if it as
been found in the devicetree.
- update the w1 device driver list to have only two parameters in the
U_BOOT_W1_DEVICE function.
drivers/w1-eeprom/ds24xxx.c | 7 +++
drivers/w1-eeprom/ds2502.c | 6 +++
drivers/w1-eeprom/w1-eeprom-uclass.c | 31 ------------
drivers/w1/w1-uclass.c | 76 +++++++++++++++++++++++++++-
include/w1-eeprom.h | 2 -
include/w1.h | 17 +++++++
6 files changed, 104 insertions(+), 35 deletions(-)
diff --git a/drivers/w1-eeprom/ds24xxx.c b/drivers/w1-eeprom/ds24xxx.c
index d12fd5754e..4be378b43d 100644
--- a/drivers/w1-eeprom/ds24xxx.c
+++ b/drivers/w1-eeprom/ds24xxx.c
@@ -53,3 +53,10 @@ U_BOOT_DRIVER(ds24xxx) = {
.ops = &ds24xxx_ops,
.probe = ds24xxx_probe,
};
+
+u8 family_supported[] = {
+ W1_FAMILY_DS24B33,
+ W1_FAMILY_DS2431,
+};
+
+U_BOOT_W1_DEVICE(ds24xxx, family_supported);
diff --git a/drivers/w1-eeprom/ds2502.c b/drivers/w1-eeprom/ds2502.c
index b3d68d7f05..a67f5edd0f 100644
--- a/drivers/w1-eeprom/ds2502.c
+++ b/drivers/w1-eeprom/ds2502.c
@@ -243,3 +243,9 @@ U_BOOT_DRIVER(ds2502) = {
.ops = &ds2502_ops,
.probe = ds2502_probe,
};
+
+u8 family_supported[] = {
+ W1_FAMILY_DS2502,
+};
+
+U_BOOT_W1_DEVICE(ds2502, family_supported);
diff --git a/drivers/w1-eeprom/w1-eeprom-uclass.c b/drivers/w1-eeprom/w1-eeprom-uclass.c
index 97a9d43b03..7a02af3dd6 100644
--- a/drivers/w1-eeprom/w1-eeprom-uclass.c
+++ b/drivers/w1-eeprom/w1-eeprom-uclass.c
@@ -37,37 +37,6 @@ int w1_eeprom_read_buf(struct udevice *dev, unsigned int offset,
return ops->read_buf(dev, offset, buf, count);
}
-int w1_eeprom_register_new_device(u64 id)
-{
- u8 family = id & 0xff;
- int ret;
- struct udevice *dev;
-
- for (ret = uclass_first_device(UCLASS_W1_EEPROM, &dev);
- !ret && dev;
- uclass_next_device(&dev)) {
- if (ret || !dev) {
- debug("cannot find w1 eeprom dev\n");
- return ret;
- }
- if (dev_get_driver_data(dev) == family) {
- struct w1_device *w1;
-
- w1 = dev_get_parent_plat(dev);
- if (w1->id) /* device already in use */
- continue;
- w1->id = id;
- debug("%s: Match found: %s:%s %llx\n", __func__,
- dev->name, dev->driver->name, id);
- return 0;
- }
- }
-
- debug("%s: No matches found: error %d\n", __func__, ret);
-
- return ret;
-}
-
int w1_eeprom_get_id(struct udevice *dev, u64 *id)
{
struct w1_device *w1 = dev_get_parent_plat(dev);
diff --git a/drivers/w1/w1-uclass.c b/drivers/w1/w1-uclass.c
index 8bc6cb13f4..16aeeb6303 100644
--- a/drivers/w1/w1-uclass.c
+++ b/drivers/w1/w1-uclass.c
@@ -4,9 +4,11 @@
* Copyright (c) 2015 Free Electrons
* Copyright (c) 2015 NextThing Co.
* Copyright (c) 2018 Microchip Technology, Inc.
+ * Copyright (c) 2021 Bootlin
*
* Maxime Ripard <maxime.ripard@free-electrons.com>
* Eugen Hristev <eugen.hristev@microchip.com>
+ * Kory Maincent <kory.maincent@bootlin.com>
*
*/
@@ -26,6 +28,76 @@ struct w1_bus {
u64 search_id;
};
+int w1_bus_find_dev(const struct udevice *bus, u64 id, struct udevice
+**devp)
+{
+ struct udevice *dev;
+ u8 family = id & 0xff;
+ int ret;
+
+ for (ret = uclass_first_device(UCLASS_W1_EEPROM, &dev);
+ !ret && dev;
+ uclass_next_device(&dev)) {
+ if (ret || !dev) {
+ debug("cannot find w1 eeprom dev\n");
+ return -ENODEV;
+ }
+
+ if (dev_get_driver_data(dev) == family) {
+ *devp = dev;
+ return 0;
+ }
+ }
+
+ return -ENODEV;
+}
+
+int w1_register_new_device(u64 id, struct udevice *bus)
+{
+ u8 family = id & 0xff;
+ int n_ents, ret;
+ struct udevice *dev;
+
+ struct w1_driver_entry *start, *entry;
+
+ start = ll_entry_start(struct w1_driver_entry, w1_driver_entry);
+ n_ents = ll_entry_count(struct w1_driver_entry, w1_driver_entry);
+
+ for (entry = start; entry != start + n_ents; entry++) {
+ const u8 *match_family;
+ const struct driver *drv;
+ struct w1_device *w1;
+
+ for (match_family = entry->family; match_family;
+ match_family++) {
+ if (*match_family != family)
+ continue;
+
+ ret = w1_bus_find_dev(bus, id, &dev);
+
+ /* If nothing in the device tree, bind a device */
+ if (ret == -ENODEV) {
+ drv = entry->driver;
+ ret = device_bind(bus, drv, drv->name,
+ NULL, ofnode_null(), &dev);
+ if (ret)
+ return ret;
+ }
+
+ device_probe(dev);
+
+ w1 = dev_get_parent_plat(dev);
+ w1->id = id;
+
+ return 0;
+ }
+ }
+
+ debug("%s: No matches found: error %d\n", __func__, ret);
+
+ return ret;
+}
+
static int w1_enumerate(struct udevice *bus)
{
const struct w1_ops *ops = device_get_ops(bus);
@@ -97,8 +169,8 @@ static int w1_enumerate(struct udevice *bus)
debug("%s: Detected new device 0x%llx (family 0x%x)\n",
bus->name, rn, (u8)(rn & 0xff));
- /* attempt to register as w1-eeprom device */
- w1_eeprom_register_new_device(rn);
+ /* attempt to register as w1 device */
+ w1_register_new_device(rn, bus);
}
}
diff --git a/include/w1-eeprom.h b/include/w1-eeprom.h
index 22337368b4..b3cf77a81e 100644
--- a/include/w1-eeprom.h
+++ b/include/w1-eeprom.h
@@ -27,7 +27,5 @@ int w1_eeprom_read_buf(struct udevice *dev, unsigned int offset,
int w1_eeprom_dm_init(void);
-int w1_eeprom_register_new_device(u64 id);
-
int w1_eeprom_get_id(struct udevice *dev, u64 *id);
#endif
diff --git a/include/w1.h b/include/w1.h
index 77f439e587..b18078ba15 100644
--- a/include/w1.h
+++ b/include/w1.h
@@ -15,6 +15,23 @@ struct udevice;
#define W1_FAMILY_DS2502 0x09
#define W1_FAMILY_EEP_SANDBOX 0xfe
+struct w1_driver_entry {
+ struct driver *driver;
+ u8 *family;
+};
+
+/* U_BOOT_W1_DEVICE() tells U-Boot to create a one-wire device.
+ *
+ * @__name: Device name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
+ * @__driver: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
+ * @__family: Family code number of the one-wire
+ */
+#define U_BOOT_W1_DEVICE(__name, __family) \
+ ll_entry_declare(struct w1_driver_entry, __name, w1_driver_entry) = { \
+ .driver = llsym(struct driver, __name, driver), \
+ .family = __family, \
+ }
+
struct w1_device {
u64 id;
};
--
2.17.1
next prev parent reply other threads:[~2021-05-04 17:31 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-04 17:31 [PATCH v5 00/10] Add support for extension boards detection and DT overlays application Kory Maincent
2021-05-04 17:31 ` [PATCH v5 01/10] fdt_support: move fdt_valid from cmd_fdt.c to fdt_support.c Kory Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` [PATCH v5 02/10] cmd: add support for a new "extension" command Kory Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` [PATCH v5 03/10] pytest: add sandbox test for " Kory Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` [PATCH v5 04/10] ti/common: add support for extension_scan_board function Kory Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` [PATCH v5 05/10] am57xx: add support for cape detect functionality Kory Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` Kory Maincent [this message]
2021-05-13 19:06 ` [PATCH v5 06/10] w1: replace dt detection by automatic detection Tom Rini
2021-05-04 17:31 ` [PATCH v5 07/10] arm: sunxi: add support for DIP detection to CHIP board Kory Maincent
2021-05-13 11:01 ` Andre Przywara
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` [PATCH v5 08/10] configs: CHIP: add support for DIP detect functionality Kory Maincent
2021-05-13 11:03 ` Andre Przywara
2021-05-17 10:19 ` Köry Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` [PATCH v5 09/10] arm: am335x: add support for i2c2 bus Kory Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-04 17:31 ` [PATCH v5 10/10] am335x: add support for cape detect functionality Kory Maincent
2021-05-13 19:06 ` Tom Rini
2021-05-12 20:37 ` [PATCH v5 00/10] Add support for extension boards detection and DT overlays application Thomas Petazzoni
2021-05-13 12:18 ` Tom Rini
2021-05-13 12:29 ` Thomas Petazzoni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210504173130.22869-7-kory.maincent@bootlin.com \
--to=kory.maincent@bootlin.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox