Skip to contentSkip to conversation

board: turris: Find atsha device by atsha driver

PATCH In review Pali Rohár 2 participants 4 messages May 19, 2022 – Jul 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board: turris: Find atsha device by atsha driver

It does not matter what is DT node name of atsha device. So find it via atsha driver and not by DT node name.

---
 board/CZ.NIC/turris_atsha_otp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
board/CZ.NIC/turris_atsha_otp.c +4 -1
index 8c39f5e52414..e62b7ee2a49a 100644
@@ -6,6 +6,7 @@
 
 #include <env.h>
 #include <net.h>
+#include <dm/device.h>
 #include <dm/uclass.h>
 #include <atsha204a-i2c.h>
 
@@ -16,12 +17,14 @@
 #define TURRIS_ATSHA_OTP_MAC0		3
 #define TURRIS_ATSHA_OTP_MAC1		4
 
+extern U_BOOT_DRIVER(atsha204);
+
 static struct udevice *get_atsha204a_dev(void)
 {
 	/* Cannot be static because BSS does not have to be ready at this early stage */
 	struct udevice *dev;
 
-	if (uclass_get_device_by_name(UCLASS_MISC, "crypto@64", &dev)) {
+	if (uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(atsha204), &dev)) {
 		puts("Cannot find ATSHA204A on I2C bus!\n");
 		dev = NULL;
 	}
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Pali Rohár

It does not matter what is DT node name of atsha device. So find it via atsha driver and not by DT node name.

Just curious: What exactly does this patch fix? Is there a turris board with a differently named atsha DT entry?

Still:

Thanks,
Stefan

Quoted 22 lines
---
  board/CZ.NIC/turris_atsha_otp.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
board/CZ.NIC/turris_atsha_otp.c +3 -0
index 8c39f5e52414..e62b7ee2a49a 100644
@@ -6,6 +6,7 @@
 
  #include <env.h>
  #include <net.h>
+#include <dm/device.h>
  #include <dm/uclass.h>
  #include <atsha204a-i2c.h>
 
@@ -16,12 +17,14 @@
  #define TURRIS_ATSHA_OTP_MAC0		3
  #define TURRIS_ATSHA_OTP_MAC1		4
 
+extern U_BOOT_DRIVER(atsha204);
+

board/CZ.NIC/turris_atsha_otp.c line 30

Quoted 10 lines
board/CZ.NIC/turris_atsha_otp.c +1 -1
  static struct udevice *get_atsha204a_dev(void)
  {
  	/* Cannot be static because BSS does not have to be ready at this early stage */
  	struct udevice *dev;
 
-	if (uclass_get_device_by_name(UCLASS_MISC, "crypto@64", &dev)) {
+	if (uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(atsha204), &dev)) {
  		puts("Cannot find ATSHA204A on I2C bus!\n");
  		dev = NULL;
  	}

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#2 lore raw
Quoted 8 lines · On Friday 20 May 2022 07:05:50 Stefan Roese wrote:
Quoted 4 lines · Pali Rohár

It does not matter what is DT node name of atsha device. So find it via atsha driver and not by DT node name.

Just curious: What exactly does this patch fix? Is there a turris board with a differently named atsha DT entry?

Currently is not. In patch for Turris 1.x support I use same "crypto@64" node name, so code would work correctly:
https://lore.kernel.org/u-boot/[email protected]/#Z31arch:powerpc:dts:turris1x-u-boot.dtsi

But I think that U-Boot code should be independent of the node names and this file calls functions exported from atsha204 driver. So it is better to find udevice based on driver which export those functions than DTS node name.

Quoted 43 lines

Still:

Thanks,
Stefan

Quoted 18 lines
---
  board/CZ.NIC/turris_atsha_otp.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
board/CZ.NIC/turris_atsha_otp.c +2 -0
index 8c39f5e52414..e62b7ee2a49a 100644
@@ -6,6 +6,7 @@
  #include <env.h>
  #include <net.h>
+#include <dm/device.h>
  #include <dm/uclass.h>
  #include <atsha204a-i2c.h>
@@ -16,12 +17,14 @@
  #define TURRIS_ATSHA_OTP_MAC0		3
  #define TURRIS_ATSHA_OTP_MAC1		4
+extern U_BOOT_DRIVER(atsha204);

board/CZ.NIC/turris_atsha_otp.c line 28

Quoted 10 lines
board/CZ.NIC/turris_atsha_otp.c +2 -1
+
  static struct udevice *get_atsha204a_dev(void)
  {
  	/* Cannot be static because BSS does not have to be ready at this early stage */
  	struct udevice *dev;
-	if (uclass_get_device_by_name(UCLASS_MISC, "crypto@64", &dev)) {
+	if (uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(atsha204), &dev)) {
  		puts("Cannot find ATSHA204A on I2C bus!\n");
  		dev = NULL;
  	}

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#3 lore raw
In reply to Pali Rohár
Quoted 4 lines · Pali Rohár

It does not matter what is DT node name of atsha device. So find it via atsha driver and not by DT node name.

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 22 lines
---
  board/CZ.NIC/turris_atsha_otp.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
board/CZ.NIC/turris_atsha_otp.c +3 -0
index 8c39f5e52414..e62b7ee2a49a 100644
@@ -6,6 +6,7 @@
 
  #include <env.h>
  #include <net.h>
+#include <dm/device.h>
  #include <dm/uclass.h>
  #include <atsha204a-i2c.h>
 
@@ -16,12 +17,14 @@
  #define TURRIS_ATSHA_OTP_MAC0		3
  #define TURRIS_ATSHA_OTP_MAC1		4
 
+extern U_BOOT_DRIVER(atsha204);
+

board/CZ.NIC/turris_atsha_otp.c line 30

Quoted 10 lines
board/CZ.NIC/turris_atsha_otp.c +1 -1
  static struct udevice *get_atsha204a_dev(void)
  {
  	/* Cannot be static because BSS does not have to be ready at this early stage */
  	struct udevice *dev;
 
-	if (uclass_get_device_by_name(UCLASS_MISC, "crypto@64", &dev)) {
+	if (uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(atsha204), &dev)) {
  		puts("Cannot find ATSHA204A on I2C bus!\n");
  		dev = NULL;
  	}

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]