Source-Changes-HG archive

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

[src/trunk]: src/sys Cleanup i2c bus acquire / release, centralizing all of t...



details:   https://anonhg.NetBSD.org/src/rev/8a190653e5c3
branches:  trunk
changeset: 847434:8a190653e5c3
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Dec 22 23:23:29 2019 +0000

description:
Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus().  "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().

diffstat:

 sys/arch/alpha/pci/tsciic.c                |  29 +---------
 sys/arch/alpha/pci/tsvar.h                 |   3 +-
 sys/arch/arm/at91/at91twi.c                |  40 +-------------
 sys/arch/arm/at91/at91twivar.h             |   5 +-
 sys/arch/arm/iomd/iomdiic.c                |  40 +-------------
 sys/arch/arm/omap/omap3_i2c.c              |  35 +-----------
 sys/arch/arm/omap/ti_iic.c                 |  33 +----------
 sys/arch/arm/rockchip/rk_i2c.c             |  32 +----------
 sys/arch/arm/sunxi/sunxi_hdmi.c            |  46 +++------------
 sys/arch/arm/sunxi/sunxi_rsb.c             |  61 ++++++---------------
 sys/arch/arm/xscale/i80312_i2c.c           |   6 +-
 sys/arch/arm/xscale/i80321_i2c.c           |   6 +-
 sys/arch/arm/xscale/iopi2c.c               |  35 +-----------
 sys/arch/arm/xscale/iopi2cvar.h            |   3 +-
 sys/arch/evbarm/armadillo/armadillo9_iic.c |  36 +-----------
 sys/arch/evbarm/gumstix/gxiic.c            |  16 +----
 sys/arch/evbarm/nslu2/nslu2_iic.c          |  32 +----------
 sys/arch/hpcarm/dev/nbpiic.c               |  44 ++++-----------
 sys/arch/i386/pci/viapcib.c                |  37 +------------
 sys/arch/macppc/dev/cuda.c                 |  33 +----------
 sys/arch/macppc/dev/ki2c.c                 |  30 +----------
 sys/arch/macppc/dev/pmu.c                  |  34 +-----------
 sys/arch/macppc/dev/smu.c                  |  33 +-----------
 sys/arch/macppc/macppc/memory.c            |  22 +------
 sys/arch/mips/alchemy/dev/ausmbus_psc.c    |  10 +--
 sys/arch/mips/ingenic/jziic.c              |  34 +----------
 sys/arch/mips/ralink/ralink_i2c.c          |  27 +--------
 sys/arch/mmeye/dev/rtciic.c                |  24 +-------
 sys/arch/powerpc/ibm4xx/dev/gpiic_opb.c    |  34 +-----------
 sys/arch/sgimips/dev/crmfb.c               |  26 +--------
 sys/arch/sparc64/dev/ffb.c                 |  23 +-------
 sys/arch/sparc64/dev/jbus-i2c.c            |  29 +---------
 sys/arch/x86/pci/imcsmb/imcsmb.c           |  13 +---
 sys/arch/zaurus/dev/ziic.c                 |  13 +--
 sys/dev/acpi/smbus_acpi.c                  |  31 +---------
 sys/dev/gpio/gpioiic.c                     |  37 +-----------
 sys/dev/i2c/gttwsi_core.c                  |  38 +------------
 sys/dev/i2c/i2c.c                          |   8 +--
 sys/dev/i2c/i2c_exec.c                     |  83 ++++++++++++++++++++++++++++-
 sys/dev/i2c/i2cvar.h                       |  17 +++--
 sys/dev/i2c/motoi2c.c                      |  19 ++----
 sys/dev/i2c/motoi2cvar.h                   |   3 +-
 sys/dev/ic/dw_hdmi.c                       |  29 +---------
 sys/dev/ic/dw_hdmi.h                       |   3 +-
 sys/dev/ic/dwiic.c                         |  33 +----------
 sys/dev/ic/pca9564.c                       |  12 +---
 sys/dev/ic/pca9564var.h                    |   3 +-
 sys/dev/ic/pcf8584.c                       |  24 +-------
 sys/dev/ic/pcf8584var.h                    |   3 +-
 sys/dev/pci/alipm.c                        |  26 +--------
 sys/dev/pci/amdpm_smbus.c                  |  32 +----------
 sys/dev/pci/amdpmvar.h                     |   3 +-
 sys/dev/pci/coram.c                        |  43 +--------------
 sys/dev/pci/cxdtv.c                        |  33 +----------
 sys/dev/pci/ichsmb.c                       |  37 +-----------
 sys/dev/pci/if_tl.c                        |  24 +-------
 sys/dev/pci/igma.c                         |  27 +--------
 sys/dev/pci/ismt.c                         |  32 +----------
 sys/dev/pci/nfsmb.c                        |  35 +-----------
 sys/dev/pci/piixpm.c                       |  14 +---
 sys/dev/pci/pm2fb.c                        |  23 +-------
 sys/dev/pci/pm3fb.c                        |  18 +------
 sys/dev/pci/radeonfb_i2c.c                 |   3 +-
 sys/dev/pci/voodoofb.c                     |  23 +-------
 sys/dev/pci/voyager.c                      |   8 +-
 sys/dev/usb/auvitek_i2c.c                  |  40 +-------------
 sys/dev/usb/emdtv_i2c.c                    |  30 +---------
 67 files changed, 308 insertions(+), 1410 deletions(-)

diffs (truncated from 4434 to 300 lines):

diff -r 681ba40f983c -r 8a190653e5c3 sys/arch/alpha/pci/tsciic.c
--- a/sys/arch/alpha/pci/tsciic.c       Sun Dec 22 22:24:37 2019 +0000
+++ b/sys/arch/alpha/pci/tsciic.c       Sun Dec 22 23:23:29 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tsciic.c,v 1.1 2014/02/21 12:23:30 jdc Exp $   */
+/*     $NetBSD: tsciic.c,v 1.2 2019/12/22 23:23:29 thorpej Exp $       */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: tsciic.c,v 1.1 2014/02/21 12:23:30 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsciic.c,v 1.2 2019/12/22 23:23:29 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -45,8 +45,6 @@
 #include <dev/i2c/ddcvar.h>
 
 /* I2C glue */
-static int tsciic_acquire_bus(void *, int);
-static void tsciic_release_bus(void *, int);
 static int tsciic_send_start(void *, int);
 static int tsciic_send_stop(void *, int);
 static int tsciic_initiate_xfer(void *, i2c_addr_t, int);
@@ -77,17 +75,13 @@
        struct tsciic_softc *sc = device_private(self);
        struct i2cbus_attach_args iba;
 
-       mutex_init(&sc->sc_buslock, MUTEX_DEFAULT, IPL_NONE);
-
+       iic_tag_init(&sc->sc_i2c);
        sc->sc_i2c.ic_cookie = sc;
-       sc->sc_i2c.ic_acquire_bus = tsciic_acquire_bus;
-       sc->sc_i2c.ic_release_bus = tsciic_release_bus;
        sc->sc_i2c.ic_send_start = tsciic_send_start;
        sc->sc_i2c.ic_send_stop = tsciic_send_stop;
        sc->sc_i2c.ic_initiate_xfer = tsciic_initiate_xfer;
        sc->sc_i2c.ic_read_byte = tsciic_read_byte;
        sc->sc_i2c.ic_write_byte = tsciic_write_byte;
-       sc->sc_i2c.ic_exec = NULL;
 
        memset(&iba, 0, sizeof(iba));
        iba.iba_tag = &sc->sc_i2c;
@@ -129,23 +123,6 @@
 
 /* higher level I2C stuff */
 static int
-tsciic_acquire_bus(void *cookie, int flags)
-{
-       struct tsciic_softc *sc = cookie;
-
-       mutex_enter(&sc->sc_buslock);
-       return 0;
-}
-
-static void
-tsciic_release_bus(void *cookie, int flags)
-{
-       struct tsciic_softc *sc = cookie;
-
-       mutex_exit(&sc->sc_buslock);
-}
-
-static int
 tsciic_send_start(void *cookie, int flags)
 {
        return (i2c_bitbang_send_start(cookie, flags, &tsciicbb_ops));
diff -r 681ba40f983c -r 8a190653e5c3 sys/arch/alpha/pci/tsvar.h
--- a/sys/arch/alpha/pci/tsvar.h        Sun Dec 22 22:24:37 2019 +0000
+++ b/sys/arch/alpha/pci/tsvar.h        Sun Dec 22 23:23:29 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tsvar.h,v 1.12 2014/02/21 12:23:30 jdc Exp $ */
+/* $NetBSD: tsvar.h,v 1.13 2019/12/22 23:23:29 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
@@ -72,7 +72,6 @@
 struct tsciic_softc {
        device_t        sc_dev;
        struct          i2c_controller sc_i2c;
-       kmutex_t        sc_buslock;
 };
 
 struct tsciic_attach_args {
diff -r 681ba40f983c -r 8a190653e5c3 sys/arch/arm/at91/at91twi.c
--- a/sys/arch/arm/at91/at91twi.c       Sun Dec 22 22:24:37 2019 +0000
+++ b/sys/arch/arm/at91/at91twi.c       Sun Dec 22 23:23:29 2019 +0000
@@ -1,5 +1,5 @@
-/*     $Id: at91twi.c,v 1.7 2016/02/14 19:54:20 chs Exp $      */
-/*     $NetBSD: at91twi.c,v 1.7 2016/02/14 19:54:20 chs Exp $  */
+/*     $Id: at91twi.c,v 1.8 2019/12/22 23:23:29 thorpej Exp $  */
+/*     $NetBSD: at91twi.c,v 1.8 2019/12/22 23:23:29 thorpej Exp $      */
 
 /*-
  * Copyright (c) 2007 Embedtronics Oy. All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at91twi.c,v 1.7 2016/02/14 19:54:20 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at91twi.c,v 1.8 2019/12/22 23:23:29 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -58,8 +58,6 @@
 int at91twi_write(struct at91twi_softc *, int, void *, int, int);
 
 /* I2C glue */
-static int at91twi_i2c_acquire_bus(void *, int);
-static void at91twi_i2c_release_bus(void *, int);
 static int at91twi_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
                    void *, size_t, int);
 
@@ -119,19 +117,12 @@
 //#endif
 
        /* initialize rest */
-       mutex_init(&sc->sc_buslock, MUTEX_DEFAULT, IPL_NONE);
        sc->sc_ih = at91_intr_establish(sc->sc_pid, IPL_SERIAL, INTR_HIGH_LEVEL,
                                        at91twi_intr, sc);
 
        /* fill in the i2c tag */
+       iic_tag_init(&sc->sc_i2c);
        sc->sc_i2c.ic_cookie = sc;
-       sc->sc_i2c.ic_acquire_bus = at91twi_i2c_acquire_bus;
-       sc->sc_i2c.ic_release_bus = at91twi_i2c_release_bus;
-       sc->sc_i2c.ic_send_start = NULL;
-       sc->sc_i2c.ic_send_stop = NULL;
-       sc->sc_i2c.ic_initiate_xfer = NULL;
-       sc->sc_i2c.ic_read_byte = NULL;
-       sc->sc_i2c.ic_write_byte = NULL;
        sc->sc_i2c.ic_exec = at91twi_i2c_exec;
 
        memset(&iba, 0, sizeof(iba));
@@ -294,29 +285,6 @@
        return at91twi_start(sc, addr, data, len, flags);
 }
 
-static int
-at91twi_i2c_acquire_bus(void *cookie, int flags)
-{
-       struct at91twi_softc *sc = cookie;
-
-       if (flags & I2C_F_POLL)
-               return 0;
-
-       mutex_enter(&sc->sc_buslock);
-       return 0;
-}
-
-static void
-at91twi_i2c_release_bus(void *cookie, int flags)
-{
-       struct at91twi_softc *sc = cookie;
-
-       if (flags & I2C_F_POLL)
-               return;
-
-       mutex_exit(&sc->sc_buslock);
-}
-
 int
 at91twi_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *vcmd,
     size_t cmdlen, void *vbuf, size_t buflen, int flags)
diff -r 681ba40f983c -r 8a190653e5c3 sys/arch/arm/at91/at91twivar.h
--- a/sys/arch/arm/at91/at91twivar.h    Sun Dec 22 22:24:37 2019 +0000
+++ b/sys/arch/arm/at91/at91twivar.h    Sun Dec 22 23:23:29 2019 +0000
@@ -1,5 +1,5 @@
-/*     $Id: at91twivar.h,v 1.2 2008/07/03 01:15:39 matt Exp $  */
-/*     $NetBSD: at91twivar.h,v 1.2 2008/07/03 01:15:39 matt Exp $      */
+/*     $Id: at91twivar.h,v 1.3 2019/12/22 23:23:29 thorpej Exp $       */
+/*     $NetBSD: at91twivar.h,v 1.3 2019/12/22 23:23:29 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2007 Embedtronics Oy. All rights reserved.
@@ -40,7 +40,6 @@
 
        int                     sc_pid;         /* peripheral id        */
        struct i2c_controller   sc_i2c;         /* I2C device desc      */
-       kmutex_t                sc_buslock;     /* bus lock             */
 
        void                    *sc_ih;         /* interrupt handle     */
 
diff -r 681ba40f983c -r 8a190653e5c3 sys/arch/arm/iomd/iomdiic.c
--- a/sys/arch/arm/iomd/iomdiic.c       Sun Dec 22 22:24:37 2019 +0000
+++ b/sys/arch/arm/iomd/iomdiic.c       Sun Dec 22 23:23:29 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iomdiic.c,v 1.8 2016/02/14 19:54:20 chs Exp $  */
+/*     $NetBSD: iomdiic.c,v 1.9 2019/12/22 23:23:29 thorpej Exp $      */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -57,7 +57,6 @@
        bus_space_handle_t sc_sh;
 
        struct i2c_controller sc_i2c;
-       kmutex_t sc_buslock;
 
        /*
         * The SDA pin is open-drain, so we make it an input by
@@ -66,9 +65,6 @@
        uint8_t sc_iomd_iocr;
 };
 
-static int     iomdiic_acquire_bus(void *, int);
-static void    iomdiic_release_bus(void *, int);
-
 static int     iomdiic_send_start(void *, int);
 static int     iomdiic_send_stop(void *, int);
 static int     iomdiic_initiate_xfer(void *, i2c_addr_t, int);
@@ -136,11 +132,8 @@
 
        sc->sc_dev = self;
 
-       mutex_init(&sc->sc_buslock, MUTEX_DEFAULT, IPL_NONE);
-
+       iic_tag_init(&sc->sc_i2c);
        sc->sc_i2c.ic_cookie = sc;
-       sc->sc_i2c.ic_acquire_bus = iomdiic_acquire_bus;
-       sc->sc_i2c.ic_release_bus = iomdiic_release_bus;
        sc->sc_i2c.ic_send_start = iomdiic_send_start;
        sc->sc_i2c.ic_send_stop = iomdiic_send_stop;
        sc->sc_i2c.ic_initiate_xfer = iomdiic_initiate_xfer;
@@ -165,9 +158,9 @@
        strcpy(dev.dv_xname, "iomdiicboot");
 
        sc.sc_dev = &dev;
+
+       iic_tag_init(&sc.sc_i2c);
        sc.sc_i2c.ic_cookie = &sc;
-       sc.sc_i2c.ic_acquire_bus = iomdiic_acquire_bus;
-       sc.sc_i2c.ic_release_bus = iomdiic_release_bus;
        sc.sc_i2c.ic_send_start = iomdiic_send_start;
        sc.sc_i2c.ic_send_stop = iomdiic_send_stop;
        sc.sc_i2c.ic_initiate_xfer = iomdiic_initiate_xfer;
@@ -178,31 +171,6 @@
 }
 
 static int
-iomdiic_acquire_bus(void *cookie, int flags)
-{
-       struct iomdiic_softc *sc = cookie;
-
-       /* XXX What should we do for the polling case? */
-       if (flags & I2C_F_POLL)
-               return (0);
-
-       mutex_enter(&sc->sc_buslock);
-       return (0);
-}
-
-static void
-iomdiic_release_bus(void *cookie, int flags)
-{
-       struct iomdiic_softc *sc = cookie;
-
-       /* XXX See above. */
-       if (flags & I2C_F_POLL)
-               return;
-
-       mutex_exit(&sc->sc_buslock);
-}
-
-static int
 iomdiic_send_start(void *cookie, int flags)
 {
        
diff -r 681ba40f983c -r 8a190653e5c3 sys/arch/arm/omap/omap3_i2c.c
--- a/sys/arch/arm/omap/omap3_i2c.c     Sun Dec 22 22:24:37 2019 +0000
+++ b/sys/arch/arm/omap/omap3_i2c.c     Sun Dec 22 23:23:29 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: omap3_i2c.c,v 1.3 2013/03/13 03:08:17 khorben Exp $ */
+/* $NetBSD: omap3_i2c.c,v 1.4 2019/12/22 23:23:29 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2012 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: omap3_i2c.c,v 1.3 2013/03/13 03:08:17 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omap3_i2c.c,v 1.4 2019/12/22 23:23:29 thorpej Exp $");
 
 #include "opt_omap.h"
 
@@ -53,7 +53,6 @@
 struct omap3_i2c_softc {
        device_t                sc_dev;
        struct i2c_controller   sc_ic;
-       kmutex_t                sc_lock;
        device_t                sc_i2cdev;
 
        bus_space_tag_t         sc_iot;
@@ -74,8 +73,6 @@
 static int     omap3_i2c_rescan(device_t, const char *, const int *);
 static void    omap3_i2c_childdet(device_t, device_t);
 



Home | Main Index | Thread Index | Old Index