Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/thorpej-i2c-spi-conf]: src/sys/dev/i2c SPD stands for "Serial Presence D...



details:   https://anonhg.NetBSD.org/src/rev/911fe55895dc
branches:  thorpej-i2c-spi-conf
changeset: 378783:911fe55895dc
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun May 16 05:16:21 2021 +0000

description:
SPD stands for "Serial Presence Detect".  This implies that
if we're using direct configuration that we should treat
that as a *hint*... it's entirely possible that a device
tree lists locations where SPD memory can be found, not
necessarily where memory is known to be present.

Accordingly, if we get a direct configuration match based
on compatible data or device name, we still check to see
if the device is there.

diffstat:

 sys/dev/i2c/spdmem_i2c.c |  55 +++++++++++++++++++++++++++++------------------
 1 files changed, 34 insertions(+), 21 deletions(-)

diffs (91 lines):

diff -r 2a1b3c94a2b6 -r 911fe55895dc sys/dev/i2c/spdmem_i2c.c
--- a/sys/dev/i2c/spdmem_i2c.c  Sun May 16 04:40:08 2021 +0000
+++ b/sys/dev/i2c/spdmem_i2c.c  Sun May 16 05:16:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -185,31 +185,45 @@ spdmem_i2c_match(device_t parent, cfdata
        struct spdmem_i2c_softc sc;
        int match_result;
 
-       if (iic_use_direct_match(ia, match, compat_data, &match_result))
-               return match_result;
+       /*
+        * SPD stands for "Serial Presence Detect".  This implies that
+        * if we're using direct configuration that we should treat
+        * that as a *hint*... it's entirely possible that a device
+        * tree lists locations where SPD memory can be found, not
+        * necessarily where memory is known to be present.
+        *
+        * Accordingly, if we get a direct configuration match based
+        * on compatible data or device name, we still check to see
+        * if the device is there.
+        */
 
-       /*
-        * XXXJRT
-        * Should do this with "compatible" strings.  There are also
-        * other problems with this "match" routine.  Specifically, if
-        * we are doing direct-config, we know the device is already
-        * there aren't do need to probe.  I'll leave the logic for
-        * now and let someone who knows better clean it later.
-        */
+       if (iic_use_direct_match(ia, match, compat_data, &match_result)) {
+               if (match_result != 0) {
+                       goto do_probe;
+               }
+               return 0;
+       }
 
        if (ia->ia_name) {
                /* add other names as we find more firmware variations */
-               if (strcmp(ia->ia_name, "dimm-spd") &&
-                   strcmp(ia->ia_name, "dimm"))
-                       return 0;
+               if (strcmp(ia->ia_name, "dimm-spd") == 0 ||
+                   strcmp(ia->ia_name, "dimm") == 0) {
+                       match_result = I2C_MATCH_DIRECT_SPECIFIC;
+                       goto do_probe;
+               }
+               return 0;
        }
 
-       /* only do this lame test when not using direct config */
-       if (ia->ia_name == NULL) {
-               if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) != SPDMEM_I2C_ADDR)
-                       return 0;
+       /* As a last resort, filter out invalid addresses. */
+       if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) == SPDMEM_I2C_ADDR) {
+               match_result = I2C_MATCH_ADDRESS_AND_PROBE;
+               goto do_probe;
        }
+       
+       /* Not a candidate address. */
+       return 0;
 
+ do_probe:
        sc.sc_tag = ia->ia_tag;
        sc.sc_addr = ia->ia_addr;
        sc.sc_page0 = SPDCTL_SPA0;
@@ -221,8 +235,7 @@ spdmem_i2c_match(device_t parent, cfdata
                return 0;
 
        if (spdmem_common_probe(&sc.sc_base)) {
-               return ia->ia_name ? I2C_MATCH_DIRECT_SPECIFIC
-                                  : I2C_MATCH_ADDRESS_AND_PROBE;
+               return match_result;
        }
        return 0;
 }



Home | Main Index | Thread Index | Old Index