Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/macppc overhaul SMU i2c handling:



details:   https://anonhg.NetBSD.org/src/rev/eaecd7f49e42
branches:  trunk
changeset: 322167:eaecd7f49e42
user:      macallan <macallan%NetBSD.org@localhost>
date:      Fri Apr 20 18:22:50 2018 +0000

description:
overhaul SMU i2c handling:
- get rid of the special smuiicbus, use generic i2cbus
- use shifted i2c addresses like everyone else
- use direct config
with this generic i2c drivers should work on the smu's i2c bus.

diffstat:

 sys/arch/macppc/conf/files.macppc |   7 +--
 sys/arch/macppc/dev/smu.c         |  52 +++++++++++++++++++++++++++--
 sys/arch/macppc/dev/smuiic.c      |  66 +++++++++++++++++++++-----------------
 sys/arch/macppc/dev/smusat.c      |  32 +++++++++++-------
 4 files changed, 105 insertions(+), 52 deletions(-)

diffs (270 lines):

diff -r dc556ae80e11 -r eaecd7f49e42 sys/arch/macppc/conf/files.macppc
--- a/sys/arch/macppc/conf/files.macppc Fri Apr 20 18:07:40 2018 +0000
+++ b/sys/arch/macppc/conf/files.macppc Fri Apr 20 18:22:50 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.macppc,v 1.108 2018/03/04 15:51:15 christos Exp $
+#      $NetBSD: files.macppc,v 1.109 2018/04/20 18:22:50 macallan Exp $
 #
 # macppc-specific configuration info
 
@@ -181,13 +181,12 @@
 file arch/macppc/dev/smu.c                     smu needs-flag
 defflag        opt_smu.h       SMU_DEBUG
 
-define smuiic {}
-device smuiic: smuiic, i2cbus
+device smuiic: i2cbus
 attach smuiic at smu
 file arch/macppc/dev/smuiic.c                  smuiic
 
 device smusat
-attach smusat at smuiic
+attach smusat at iic
 file arch/macppc/dev/smusat.c                  smusat
 defflag        opt_smusat.h    SMUSAT_DEBUG
 
diff -r dc556ae80e11 -r eaecd7f49e42 sys/arch/macppc/dev/smu.c
--- a/sys/arch/macppc/dev/smu.c Fri Apr 20 18:07:40 2018 +0000
+++ b/sys/arch/macppc/dev/smu.c Fri Apr 20 18:22:50 2018 +0000
@@ -131,6 +131,19 @@
 #define SMU_CMD_RTC    0x8e
 #define SMU_CMD_I2C    0x9a
 #define SMU_CMD_POWER  0xaa
+#define SMU_ADC                0xd8
+#define SMU_MISC       0xee
+#define  SMU_MISC_GET_DATA     0x02
+#define  SMU_MISC_LED_CTRL     0x04
+
+#define SMU_CPUTEMP_CAL 0x18
+#define SMU_CPUVOLT_CAL        0x21
+#define SMU_SLOTPW_CAL 0x78
+
+#define SMU_PARTITION          0x3e
+#define SMU_PARTITION_LATEST   0x01
+#define SMU_PARTITION_BASE     0x02
+#define SMU_PARTITION_UPDATE   0x03
 
 #ifdef SMU_DEBUG
 #define DPRINTF printf
@@ -166,6 +179,8 @@
 static bool is_drive_sensor(const envsys_data_t *);
 static bool is_slots_sensor(const envsys_data_t *);
 
+int smu_get_datablock(int, uint8_t *, size_t);
+
 CFATTACH_DECL_NEW(smu, sizeof(struct smu_softc),
     smu_match, smu_attach, NULL, NULL);
 
@@ -191,6 +206,9 @@
        sc->sc_dev = self;
        sc->sc_node = ca->ca_node;
 
+       if (smu0 == NULL)
+               smu0 = sc;
+
        sysctl_createv(NULL, 0, NULL, (void *) &sc->sc_sysctl_me,
            CTLFLAG_READWRITE,
            CTLTYPE_NODE, device_xname(sc->sc_dev), NULL,
@@ -212,9 +230,6 @@
 
        smu_setup_sme(sc);
 
-       if (smu0 == NULL)
-               smu0 = sc;
-
        printf("\n");
        smu_setup_zones(sc);
 }
@@ -793,10 +808,10 @@
        cmd.len = 9 + recv_len;
        cmd.data[0] = iicbus->reg;
        cmd.data[1] = I2C_OP_READ_P(op) ? 0x02 : 0x00;
-       cmd.data[2] = addr;
+       cmd.data[2] = addr << 1;
        cmd.data[3] = send_len;
        memcpy(&cmd.data[4], send, send_len);
-       cmd.data[7] = addr;
+       cmd.data[7] = addr << 1;
        if (I2C_OP_READ_P(op))
                cmd.data[7] |= 0x01;
        cmd.data[8] = recv_len;
@@ -1007,3 +1022,30 @@
                return TRUE;
        return false;
 }
+
+int
+smu_get_datablock(int id, uint8_t *buf, size_t len)
+{
+       struct smu_cmd cmd;
+
+       cmd.cmd = SMU_PARTITION;
+       cmd.len = 2;
+       cmd.data[0] = SMU_PARTITION_LATEST;
+       cmd.data[1] = id;
+       smu_do_cmd(smu0, &cmd, 100);
+
+       cmd.data[4] = cmd.data[0];
+       cmd.data[5] = cmd.data[1];
+
+       cmd.cmd = SMU_MISC;
+       cmd.len = 7;
+       cmd.data[0] = SMU_MISC_GET_DATA;
+       cmd.data[1] = 4;
+       cmd.data[2] = 0;
+       cmd.data[3] = 0;
+       cmd.data[6] = len;
+       smu_do_cmd(smu0, &cmd, 100);
+
+       memcpy(buf, cmd.data, len);
+       return 0;
+}
diff -r dc556ae80e11 -r eaecd7f49e42 sys/arch/macppc/dev/smuiic.c
--- a/sys/arch/macppc/dev/smuiic.c      Fri Apr 20 18:07:40 2018 +0000
+++ b/sys/arch/macppc/dev/smuiic.c      Fri Apr 20 18:22:50 2018 +0000
@@ -49,7 +49,6 @@
 
 static int smuiic_match(device_t, struct cfdata *, void *);
 static void smuiic_attach(device_t, device_t, void *);
-static int smuiic_print(void *, const char *);
 
 CFATTACH_DECL_NEW(smuiic, sizeof(struct smuiic_softc),
     smuiic_match, smuiic_attach, NULL, NULL);
@@ -71,8 +70,13 @@
        struct smu_iicbus_confargs *ca = aux;
        struct smuiic_softc *sc = device_private(self);
        struct i2cbus_attach_args iba;
-       struct smuiic_confargs sca;
-       int node, reg;
+       prop_dictionary_t dict = device_properties(self);
+       int devs;
+       uint32_t addr;
+       char compat[256];
+       prop_array_t cfg;
+       prop_dictionary_t dev;
+       prop_data_t data;
        char name[32];
 
        sc->sc_dev = self;
@@ -80,34 +84,36 @@
        sc->sc_i2c = ca->ca_tag;
        printf("\n");
 
+       cfg = prop_array_create();
+       prop_dictionary_set(dict, "i2c-child-devices", cfg);
+       prop_object_release(cfg);
+
+       /* look for i2c devices */
+       devs = OF_child(sc->sc_node);
+       while (devs != 0) {
+               if (OF_getprop(devs, "name", name, 256) <= 0)
+                       goto skip;
+               if (OF_getprop(devs, "compatible",
+                   compat, 256) <= 0)
+                       goto skip;
+               if (OF_getprop(devs, "reg", &addr, 4) <= 0)
+                       goto skip;
+               addr = (addr & 0xff) >> 1;
+               dev = prop_dictionary_create();
+               prop_dictionary_set_cstring(dev, "name", name);
+               data = prop_data_create_data(compat, strlen(compat)+1);
+               prop_dictionary_set(dev, "compatible", data);
+               prop_object_release(data);
+               prop_dictionary_set_uint32(dev, "addr", addr);
+               prop_dictionary_set_uint64(dev, "cookie", devs);
+               prop_array_add(cfg, dev);
+               prop_object_release(dev);
+       skip:
+               devs = OF_peer(devs);
+       }
+
+       memset(&iba, 0, sizeof(iba));
        iba.iba_tag = sc->sc_i2c;
 
        config_found_ia(sc->sc_dev, "i2cbus", &iba, iicbus_print);
-
-       for (node = OF_child(sc->sc_node); node != 0; node = OF_peer(node)) {
-               memset(name, 0, sizeof(name));
-               OF_getprop(node, "name", name, sizeof(name));
-
-               if (OF_getprop(node, "reg", &reg, sizeof(reg)) <= 0)
-                       continue;
-
-               sca.ca_name = name;
-               sca.ca_node = node;
-               sca.ca_addr = reg & 0xfe;
-               sca.ca_tag = sc->sc_i2c;
-               config_found_ia(sc->sc_dev, "smuiic", &sca, smuiic_print);
-       }
 }
-
-static int
-smuiic_print(void *aux, const char *smuiic)
-{
-       struct smuiic_confargs *ca = aux;
-
-       if (smuiic) {
-               aprint_normal("%s at %s", ca->ca_name, smuiic);
-               aprint_normal(" address 0x%x", ca->ca_addr);
-       }
-
-       return UNCONF;
-}
diff -r dc556ae80e11 -r eaecd7f49e42 sys/arch/macppc/dev/smusat.c
--- a/sys/arch/macppc/dev/smusat.c      Fri Apr 20 18:07:40 2018 +0000
+++ b/sys/arch/macppc/dev/smusat.c      Fri Apr 20 18:22:50 2018 +0000
@@ -105,25 +105,31 @@
 CFATTACH_DECL_NEW(smusat, sizeof(struct smusat_softc),
     smusat_match, smusat_attach, NULL, NULL);
 
+static const char * smusat_compats[] = {
+       "sat",  
+       "smu-sat",
+       NULL
+};
+
 static int
 smusat_match(device_t parent, struct cfdata *cf, void *aux)
 {
-       struct smuiic_confargs *ca = aux;
-       char compat[32];
+       struct i2c_attach_args *ia = aux;
 
-       memset(compat, 0, sizeof(compat));
-       OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
-
-       if (strcmp(compat, "smu-sat") == 0)
-               return 5;
-       
-       return 0;
+       if (ia->ia_name == NULL) {
+               /* no ID registers on this chip */
+               if (ia->ia_addr == 0x58)
+                       return 1;
+               return 0;
+       } else {
+               return iic_compat_match(ia, smusat_compats);
+       }
 }
 
 static void
 smusat_attach(device_t parent, device_t self, void *aux)
 {
-       struct smuiic_confargs *ca = aux;
+       struct i2c_attach_args *ia = aux;
        struct smusat_softc *sc = device_private(self);
        struct smusat_sensor *sensor;
        struct sysctlnode *sysctl_sensors, *sysctl_sensor, *sysctl_node;
@@ -131,9 +137,9 @@
        int node, i, j;
 
        sc->sc_dev = self;
-       sc->sc_node = ca->ca_node;
-       sc->sc_addr = ca->ca_addr & 0xfe;
-       sc->sc_i2c = ca->ca_tag;
+       sc->sc_node = ia->ia_cookie;
+       sc->sc_addr = ia->ia_addr;
+       sc->sc_i2c = ia->ia_tag;
 
        sysctl_createv(NULL, 0, NULL, (void *) &sc->sc_sysctl_me,
            CTLFLAG_READWRITE,



Home | Main Index | Thread Index | Old Index