Source-Changes-HG archive

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

[src/trunk]: src/sys Remove duplicate register definitions and merge them all...



details:   https://anonhg.NetBSD.org/src/rev/8ed834adb3e4
branches:  trunk
changeset: 342657:8ed834adb3e4
user:      jdc <jdc%NetBSD.org@localhost>
date:      Sun Jan 03 17:32:17 2016 +0000

description:
Remove duplicate register definitions and merge them all into pcf8584reg.h.
No functional change.

diffstat:

 sys/arch/sparc64/dev/pcfiic_ebus.c |  15 +++--
 sys/dev/ic/pcf8584.c               |  99 ++++++++++++++-----------------------
 sys/dev/ic/pcf8584reg.h            |  10 ++-
 sys/dev/ic/pcf8584var.h            |  15 +-----
 4 files changed, 54 insertions(+), 85 deletions(-)

diffs (truncated from 319 to 300 lines):

diff -r 2787a0355439 -r 8ed834adb3e4 sys/arch/sparc64/dev/pcfiic_ebus.c
--- a/sys/arch/sparc64/dev/pcfiic_ebus.c        Sun Jan 03 17:29:25 2016 +0000
+++ b/sys/arch/sparc64/dev/pcfiic_ebus.c        Sun Jan 03 17:32:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcfiic_ebus.c,v 1.4 2013/02/03 17:46:28 jdc Exp $      */
+/*     $NetBSD: pcfiic_ebus.c,v 1.5 2016/01/03 17:32:17 jdc Exp $      */
 /*     $OpenBSD: pcfiic_ebus.c,v 1.13 2008/06/08 03:07:40 deraadt Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus.c,v 1.4 2013/02/03 17:46:28 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus.c,v 1.5 2016/01/03 17:32:17 jdc Exp $");
 
 /*
  * Device specific driver for the EBus i2c devices found on some sun4u
@@ -42,6 +42,7 @@
 #include <dev/i2c/i2cvar.h>
 
 #include <dev/ic/pcf8584var.h>
+#include <dev/ic/pcf8584reg.h>
 
 int    pcfiic_ebus_match(device_t, struct cfdata *, void *);
 void   pcfiic_ebus_attach(device_t, device_t, void *);
@@ -94,7 +95,7 @@
        struct ebus_attach_args         *ea = aux;
        char                            compat[32];
        u_int64_t                       addr;
-       u_int8_t                        clock = PCF_CLOCK_12 | PCF_FREQ_90;
+       u_int8_t                        clock = PCF8584_CLK_12 | PCF8584_SCL_90;
        int                             swapregs = 0;
 
        if (ea->ea_nreg < 1 || ea->ea_nreg > 2) {
@@ -113,9 +114,9 @@
                int clk = prom_getpropint(findroot(), "clock-frequency", 0);
 
                if (clk < 105000000)
-                       clock = PCF_CLOCK_3 | PCF_FREQ_90;
+                       clock = PCF8584_CLK_3 | PCF8584_SCL_90;
                else if (clk < 160000000)
-                       clock = PCF_CLOCK_4_43 | PCF_FREQ_90;
+                       clock = PCF8584_CLK_4_43 | PCF8584_SCL_90;
                swapregs = 1;
        }
 
@@ -161,10 +162,10 @@
 
        if (strcmp(ea->ea_name, "SUNW,envctrl") == 0) {
                envctrl_props(create_dict(self), ea->ea_node);
-               pcfiic_attach(sc, 0x55, PCF_CLOCK_12 | PCF_FREQ_45, 0);
+               pcfiic_attach(sc, 0x55, PCF8584_CLK_12 | PCF8584_SCL_45, 0);
        } else if (strcmp(ea->ea_name, "SUNW,envctrltwo") == 0) {
                envctrltwo_props(create_dict(self), ea->ea_node);
-               pcfiic_attach(sc, 0x55, PCF_CLOCK_12 | PCF_FREQ_45, 0);
+               pcfiic_attach(sc, 0x55, PCF8584_CLK_12 | PCF8584_SCL_45, 0);
        } else
                pcfiic_attach(sc, (i2c_addr_t)(addr >> 1), clock, swapregs);
 }
diff -r 2787a0355439 -r 8ed834adb3e4 sys/dev/ic/pcf8584.c
--- a/sys/dev/ic/pcf8584.c      Sun Jan 03 17:29:25 2016 +0000
+++ b/sys/dev/ic/pcf8584.c      Sun Jan 03 17:32:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcf8584.c,v 1.12 2015/12/16 08:04:58 jdc Exp $ */
+/*     $NetBSD: pcf8584.c,v 1.13 2016/01/03 17:32:17 jdc Exp $ */
 /*     $OpenBSD: pcf8584.c,v 1.9 2007/10/20 18:46:21 kettenis Exp $ */
 
 /*
@@ -29,36 +29,13 @@
 #include <dev/i2c/i2cvar.h>
 
 #include <dev/ic/pcf8584var.h>
-
-#define PCF_S0                 0x00
-#define PCF_S1                 0x01
-#define PCF_S2                 0x02
-#define PCF_S3                 0x03
-
-#define PCF_CTRL_ACK           (1<<0)
-#define PCF_CTRL_STO           (1<<1)
-#define PCF_CTRL_STA           (1<<2)
-#define PCF_CTRL_ENI           (1<<3)
-#define PCF_CTRL_ES2           (1<<4)
-#define PCF_CTRL_ES1           (1<<5)
-#define PCF_CTRL_ESO           (1<<6)
-#define PCF_CTRL_PIN           (1<<7)
+#include <dev/ic/pcf8584reg.h>
 
-#define PCF_CTRL_START         (PCF_CTRL_PIN | PCF_CTRL_ESO | \
-    PCF_CTRL_STA | PCF_CTRL_ACK)
-#define PCF_CTRL_STOP          (PCF_CTRL_PIN | PCF_CTRL_ESO | \
-    PCF_CTRL_STO | PCF_CTRL_ACK)
-#define PCF_CTRL_REPSTART      (PCF_CTRL_ESO | PCF_CTRL_STA | PCF_CTRL_ACK)
-#define PCF_CTRL_IDLE          (PCF_CTRL_PIN | PCF_CTRL_ESO | PCF_CTRL_ACK)
-
-#define PCF_STAT_nBB           (1<<0)
-#define PCF_STAT_LAB           (1<<1)
-#define PCF_STAT_AAS           (1<<2)
-#define PCF_STAT_AD0           (1<<3)
-#define PCF_STAT_LRB           (1<<3)
-#define PCF_STAT_BER           (1<<4)
-#define PCF_STAT_STS           (1<<5)
-#define PCF_STAT_PIN           (1<<7)
+/* Internal egisters */
+#define PCF8584_S0             0x00
+#define PCF8584_S1             0x01
+#define PCF8584_S2             0x02
+#define PCF8584_S3             0x03
 
 void           pcfiic_init(struct pcfiic_softc *);
 int            pcfiic_i2c_acquire_bus(void *, int);
@@ -74,22 +51,22 @@
 u_int8_t       pcfiic_read(struct pcfiic_softc *, bus_size_t);
 void           pcfiic_write(struct pcfiic_softc *, bus_size_t, u_int8_t);
 void           pcfiic_choose_bus(struct pcfiic_softc *, u_int8_t);
-int            pcfiic_wait_nBB(struct pcfiic_softc *);
+int            pcfiic_wait_BBN(struct pcfiic_softc *);
 int            pcfiic_wait_pin(struct pcfiic_softc *, volatile u_int8_t *);
 
 void
 pcfiic_init(struct pcfiic_softc *sc)
 {
        /* init S1 */
-       pcfiic_write(sc, PCF_S1, PCF_CTRL_PIN);
+       pcfiic_write(sc, PCF8584_S1, PCF8584_CTRL_PIN);
        /* own address */
-       pcfiic_write(sc, PCF_S0, sc->sc_addr);
+       pcfiic_write(sc, PCF8584_S0, sc->sc_addr);
 
        /* select clock reg */
-       pcfiic_write(sc, PCF_S1, PCF_CTRL_PIN|PCF_CTRL_ES1);
-       pcfiic_write(sc, PCF_S0, sc->sc_clock);
+       pcfiic_write(sc, PCF8584_S1, PCF8584_CTRL_PIN | PCF8584_CTRL_ES1);
+       pcfiic_write(sc, PCF8584_S0, sc->sc_clock);
 
-       pcfiic_write(sc, PCF_S1, PCF_CTRL_IDLE);
+       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_IDLE);
 
        delay(200000);  /* Multi-Master mode, wait for longest i2c message */
 }
@@ -101,11 +78,11 @@
        struct i2cbus_attach_args               iba;
 
        if (swapregs) {
-               sc->sc_regmap[PCF_S1] = PCF_S0;
-               sc->sc_regmap[PCF_S0] = PCF_S1;
+               sc->sc_regmap[PCF8584_S1] = PCF8584_S0;
+               sc->sc_regmap[PCF8584_S0] = PCF8584_S1;
        } else {
-               sc->sc_regmap[PCF_S0] = PCF_S0;
-               sc->sc_regmap[PCF_S1] = PCF_S1;
+               sc->sc_regmap[PCF8584_S0] = PCF8584_S0;
+               sc->sc_regmap[PCF8584_S1] = PCF8584_S1;
        }
        sc->sc_clock = clock;
        sc->sc_addr = addr;
@@ -208,27 +185,27 @@
        int                     i, err = 0;
        volatile u_int8_t       r;
 
-       if (pcfiic_wait_nBB(sc) != 0)
+       if (pcfiic_wait_BBN(sc) != 0)
                return (1);
 
-       pcfiic_write(sc, PCF_S0, addr << 1);
-       pcfiic_write(sc, PCF_S1, PCF_CTRL_START);
+       pcfiic_write(sc, PCF8584_S0, addr << 1);
+       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_START);
 
        for (i = 0; i <= len; i++) {
                if (pcfiic_wait_pin(sc, &r) != 0) {
-                       pcfiic_write(sc, PCF_S1, PCF_CTRL_STOP);
+                       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_STOP);
                        return (1);
                }
 
-               if (r & PCF_STAT_LRB) {
+               if (r & PCF8584_STATUS_LRB) {
                        err = 1;
                        break;
                }
 
                if (i < len)
-                       pcfiic_write(sc, PCF_S0, buf[i]);
+                       pcfiic_write(sc, PCF8584_S0, buf[i]);
        }
-       pcfiic_write(sc, PCF_S1, PCF_CTRL_STOP);
+       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_STOP);
        return (err);
 }
 
@@ -238,30 +215,30 @@
        int                     i = 0, err = 0;
        volatile u_int8_t       r;
 
-       if (pcfiic_wait_nBB(sc) != 0)
+       if (pcfiic_wait_BBN(sc) != 0)
                return (1);
 
-       pcfiic_write(sc, PCF_S0, (addr << 1) | 0x01);
-       pcfiic_write(sc, PCF_S1, PCF_CTRL_START);
+       pcfiic_write(sc, PCF8584_S0, (addr << 1) | 0x01);
+       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_START);
 
        for (i = 0; i <= len; i++) {
                if (pcfiic_wait_pin(sc, &r) != 0) {
-                       pcfiic_write(sc, PCF_S1, PCF_CTRL_STOP);
+                       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_STOP);
                        return (1);
                }
 
-               if ((i != len) && (r & PCF_STAT_LRB)) {
-                       pcfiic_write(sc, PCF_S1, PCF_CTRL_STOP);
+               if ((i != len) && (r & PCF8584_STATUS_LRB)) {
+                       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_STOP);
                        return (1);
                }
 
                if (i == len - 1) {
-                       pcfiic_write(sc, PCF_S1, PCF_CTRL_ESO);
+                       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_NAK);
                } else if (i == len) {
-                       pcfiic_write(sc, PCF_S1, PCF_CTRL_STOP);
+                       pcfiic_write(sc, PCF8584_S1, PCF8584_CMD_STOP);
                }
 
-               r = pcfiic_read(sc, PCF_S0);
+               r = pcfiic_read(sc, PCF8584_S0);
                if (i > 0)
                        buf[i - 1] = r;
        }
@@ -280,7 +257,7 @@
 pcfiic_write(struct pcfiic_softc *sc, bus_size_t r, u_int8_t v)
 {
        bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_regmap[r], v);
-       (void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, PCF_S1);
+       (void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, PCF8584_S1);
 }
 
 void
@@ -292,12 +269,12 @@
 }
 
 int
-pcfiic_wait_nBB(struct pcfiic_softc *sc)
+pcfiic_wait_BBN(struct pcfiic_softc *sc)
 {
        int             i;
 
        for (i = 0; i < 1000; i++) {
-               if (pcfiic_read(sc, PCF_S1) & PCF_STAT_nBB)
+               if (pcfiic_read(sc, PCF8584_S1) & PCF8584_STATUS_BBN)
                        return (0);
                delay(1000);
        }
@@ -310,8 +287,8 @@
        int             i;
 
        for (i = 0; i < 1000; i++) {
-               *r = pcfiic_read(sc, PCF_S1);
-               if ((*r & PCF_STAT_PIN) == 0)
+               *r = pcfiic_read(sc, PCF8584_S1);
+               if ((*r & PCF8584_STATUS_PIN) == 0)
                        return (0);
                delay(1000);
        }
diff -r 2787a0355439 -r 8ed834adb3e4 sys/dev/ic/pcf8584reg.h
--- a/sys/dev/ic/pcf8584reg.h   Sun Jan 03 17:29:25 2016 +0000
+++ b/sys/dev/ic/pcf8584reg.h   Sun Jan 03 17:32:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcf8584reg.h,v 1.1 2007/04/14 19:33:30 tnn Exp $ */
+/*     $NetBSD: pcf8584reg.h,v 1.2 2016/01/03 17:32:17 jdc Exp $ */
 
 /* Written by Tobias Nygren. Released into the public domain. */
 
@@ -39,8 +39,12 @@
 #define        PCF8584_REG_S2          PCF8584_CTRL_ES1        /* clock register */
 #define        PCF8584_REG_S3          PCF8584_CTRL_ES2        /* Interrupt vector */
 
-#define PCF8584_CMD_START (PCF8584_CTRL_PIN | PCF8584_CTRL_ESO | \
+#define PCF8584_CMD_START      (PCF8584_CTRL_PIN | PCF8584_CTRL_ESO | \
     PCF8584_CTRL_STA | PCF8584_CTRL_ACK)
-#define PCF8584_CMD_STOP (PCF8584_CTRL_PIN | PCF8584_CTRL_ESO | \
+#define PCF8584_CMD_STOP       (PCF8584_CTRL_PIN | PCF8584_CTRL_ESO | \
     PCF8584_CTRL_STO | PCF8584_CTRL_ACK)
+#define PCF8584_CMD_REPSTART    (PCF8584_CTRL_ESO | PCF8584_CTRL_STA | \
+    PCF8584_CTRL_ACK)
+#define PCF8584_CMD_IDLE        (PCF8584_CTRL_PIN | PCF8584_CTRL_ESO | \
+    PCF8584_CTRL_ACK)
 #define PCF8584_CMD_NAK (PCF8584_CTRL_ESO)
diff -r 2787a0355439 -r 8ed834adb3e4 sys/dev/ic/pcf8584var.h
--- a/sys/dev/ic/pcf8584var.h   Sun Jan 03 17:29:25 2016 +0000
+++ b/sys/dev/ic/pcf8584var.h   Sun Jan 03 17:32:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcf8584var.h,v 1.4 2010/02/28 11:47:28 martin Exp $    */
+/*     $NetBSD: pcf8584var.h,v 1.5 2016/01/03 17:32:17 jdc Exp $       */
 /*     $OpenBSD: pcf8584var.h,v 1.5 2007/10/20 18:46:21 kettenis Exp $ */
 
 /*



Home | Main Index | Thread Index | Old Index