Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Support direct config.



details:   https://anonhg.NetBSD.org/src/rev/ac2c3e47c484
branches:  trunk
changeset: 342235:ac2c3e47c484
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Dec 13 17:15:06 2015 +0000

description:
Support direct config.

diffstat:

 sys/dev/i2c/as3722.c  |  29 +++++++++++++++++++----------
 sys/dev/i2c/at24cxx.c |  23 +++++++++++++++++++++--
 sys/dev/i2c/titemp.c  |  29 +++++++++++++++++++----------
 3 files changed, 59 insertions(+), 22 deletions(-)

diffs (179 lines):

diff -r 3d814591cc9f -r ac2c3e47c484 sys/dev/i2c/as3722.c
--- a/sys/dev/i2c/as3722.c      Sun Dec 13 17:14:56 2015 +0000
+++ b/sys/dev/i2c/as3722.c      Sun Dec 13 17:15:06 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: as3722.c,v 1.3 2015/11/21 12:19:47 jmcneill Exp $ */
+/* $NetBSD: as3722.c,v 1.4 2015/12/13 17:15:06 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.3 2015/11/21 12:19:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.4 2015/12/13 17:15:06 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -93,6 +93,11 @@
 CFATTACH_DECL_NEW(as3722pmic, sizeof(struct as3722_softc),
     as3722_match, as3722_attach, NULL, NULL);
 
+static const char * as3722_compats[] = {
+       "ams,as3722",
+       NULL
+};
+
 static int
 as3722_match(device_t parent, cfdata_t match, void *aux)
 {
@@ -100,16 +105,20 @@
        uint8_t reg, id1;
        int error;
 
-       iic_acquire_bus(ia->ia_tag, I2C_F_POLL);
-       reg = AS3722_ASIC_ID1_REG;
-       error = iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP, ia->ia_addr,
-           &reg, 1, &id1, 1, I2C_F_POLL);
-       iic_release_bus(ia->ia_tag, I2C_F_POLL);
+       if (ia->ia_name == NULL) {
+               iic_acquire_bus(ia->ia_tag, I2C_F_POLL);
+               reg = AS3722_ASIC_ID1_REG;
+               error = iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP, ia->ia_addr,
+                   &reg, 1, &id1, 1, I2C_F_POLL);
+               iic_release_bus(ia->ia_tag, I2C_F_POLL);
 
-       if (error == 0 && id1 == 0x0c)
-               return 1;
+               if (error == 0 && id1 == 0x0c)
+                       return 1;
 
-       return 0;
+               return 0;
+       } else {
+               return iic_compat_match(ia, as3722_compats);
+       }
 }
 
 static void
diff -r 3d814591cc9f -r ac2c3e47c484 sys/dev/i2c/at24cxx.c
--- a/sys/dev/i2c/at24cxx.c     Sun Dec 13 17:14:56 2015 +0000
+++ b/sys/dev/i2c/at24cxx.c     Sun Dec 13 17:15:06 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: at24cxx.c,v 1.20 2015/09/27 13:02:21 phx Exp $ */
+/*     $NetBSD: at24cxx.c,v 1.21 2015/12/13 17:15:06 jmcneill Exp $    */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.20 2015/09/27 13:02:21 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at24cxx.c,v 1.21 2015/12/13 17:15:06 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -113,9 +113,17 @@
 static const char * seeprom_compats[] = {
        "i2c-at24c64",
        "i2c-at34c02",
+       "atmel,24c02",
        NULL
 };
 
+static const struct seeprom_size {
+       const char *name;
+       int size;
+} seeprom_sizes[] = {
+       { "atmel,24c02", 256 },
+};
+
 static int
 seeprom_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -142,6 +150,7 @@
 {
        struct seeprom_softc *sc = device_private(self);
        struct i2c_attach_args *ia = aux;
+       u_int n;
 
        sc->sc_tag = ia->ia_tag;
        sc->sc_address = ia->ia_addr;
@@ -173,6 +182,16 @@
                sc->sc_size = (device_cfdata(self)->cf_flags << 7);
        else
                sc->sc_size = ia->ia_size;
+
+       if (sc->sc_size == 0 && ia->ia_ncompat > 0) {
+               for (n = 0; n < __arraycount(seeprom_sizes); n++) {
+                       if (!strcmp(seeprom_sizes[n].name, ia->ia_compat[n])) {
+                               sc->sc_size = seeprom_sizes[n].size;
+                               break;
+                       }
+               }
+       }
+
        switch (sc->sc_size) {
        case 128:               /* 1Kbit */
        case 256:               /* 2Kbit */
diff -r 3d814591cc9f -r ac2c3e47c484 sys/dev/i2c/titemp.c
--- a/sys/dev/i2c/titemp.c      Sun Dec 13 17:14:56 2015 +0000
+++ b/sys/dev/i2c/titemp.c      Sun Dec 13 17:15:06 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: titemp.c,v 1.1 2015/05/12 20:54:08 jmcneill Exp $ */
+/* $NetBSD: titemp.c,v 1.2 2015/12/13 17:15:06 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: titemp.c,v 1.1 2015/05/12 20:54:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: titemp.c,v 1.2 2015/12/13 17:15:06 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -84,6 +84,11 @@
 CFATTACH_DECL_NEW(titemp, sizeof(struct titemp_softc),
     titemp_match, titemp_attach, NULL, NULL);
 
+static const char * titemp_compats[] = {
+       "ti,tmp451",
+       NULL
+};
+
 static int
 titemp_match(device_t parent, cfdata_t match, void *aux)
 {
@@ -91,16 +96,20 @@
        uint8_t mfid;
        int error;
 
-       if (iic_acquire_bus(ia->ia_tag, I2C_F_POLL) != 0)
-               return 0;
-       error = iic_smbus_read_byte(ia->ia_tag, ia->ia_addr,
-           TITEMP_MFID_REG, &mfid, I2C_F_POLL);
-       iic_release_bus(ia->ia_tag, I2C_F_POLL);
+       if (ia->ia_name == NULL) {
+               if (iic_acquire_bus(ia->ia_tag, I2C_F_POLL) != 0)
+                       return 0;
+               error = iic_smbus_read_byte(ia->ia_tag, ia->ia_addr,
+                   TITEMP_MFID_REG, &mfid, I2C_F_POLL);
+               iic_release_bus(ia->ia_tag, I2C_F_POLL);
 
-       if (error || mfid != TITEMP_MFID_TMP451)
-               return 0;
+               if (error || mfid != TITEMP_MFID_TMP451)
+                       return 0;
 
-       return 1;
+               return 1;
+       } else {
+               return iic_compat_match(ia, titemp_compats);
+       }
 }
 
 static void



Home | Main Index | Thread Index | Old Index