From owner-svn-src-stable@freebsd.org Mon Sep 11 15:31:30 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6B737E11FAF; Mon, 11 Sep 2017 15:31:30 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4494965488; Mon, 11 Sep 2017 15:31:30 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BFVTJK095132; Mon, 11 Sep 2017 15:31:29 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BFVT5N095131; Mon, 11 Sep 2017 15:31:29 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709111531.v8BFVT5N095131@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 15:31:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323440 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323440 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 15:31:30 -0000 Author: ian Date: Mon Sep 11 15:31:29 2017 New Revision: 323440 URL: https://svnweb.freebsd.org/changeset/base/323440 Log: MFC r321586: Add a debug sysctl that lets you see i2c bus traffic through this device. Modified: stable/11/sys/arm/freescale/imx/imx_i2c.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx_i2c.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_i2c.c Mon Sep 11 15:18:43 2017 (r323439) +++ stable/11/sys/arm/freescale/imx/imx_i2c.c Mon Sep 11 15:31:29 2017 (r323440) @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -139,8 +140,18 @@ struct i2c_softc { int rb_pinctl_idx; gpio_pin_t rb_sclpin; gpio_pin_t rb_sdapin; + u_int debug; + u_int slave; }; +#define DEVICE_DEBUGF(sc, lvl, fmt, args...) \ + if ((lvl) <= (sc)->debug) \ + device_printf((sc)->dev, fmt, ##args) + +#define DEBUGF(sc, lvl, fmt, args...) \ + if ((lvl) <= (sc)->debug) \ + printf(fmt, ##args) + static phandle_t i2c_get_node(device_t, device_t); static int i2c_probe(device_t); static int i2c_attach(device_t); @@ -384,6 +395,12 @@ i2c_attach(device_t dev) return (ENXIO); } + /* Set up debug-enable sysctl. */ + SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), + OID_AUTO, "debug", CTLFLAG_RWTUN, &sc->debug, 0, + "Enable debug; 1=reads/writes, 2=add starts/stops"); + /* * Set up for bus recovery using gpio pins, if the pinctrl and gpio * properties are present. This is optional. If all the config data is @@ -451,6 +468,8 @@ i2c_repeated_start(device_t dev, u_char slave, int tim DELAY(1); i2c_write_reg(sc, I2C_STATUS_REG, 0x0); i2c_write_reg(sc, I2C_DATA_REG, slave); + sc->slave = slave; + DEVICE_DEBUGF(sc, 2, "rstart 0x%02x\n", sc->slave); error = wait_for_xfer(sc, true); return (i2c_error_handler(sc, error)); } @@ -473,6 +492,8 @@ i2c_start_ll(device_t dev, u_char slave, int timeout) return (i2c_error_handler(sc, error)); i2c_write_reg(sc, I2C_STATUS_REG, 0); i2c_write_reg(sc, I2C_DATA_REG, slave); + sc->slave = slave; + DEVICE_DEBUGF(sc, 2, "start 0x%02x\n", sc->slave); error = wait_for_xfer(sc, true); return (i2c_error_handler(sc, error)); } @@ -512,6 +533,7 @@ i2c_stop(device_t dev) i2c_write_reg(sc, I2C_CONTROL_REG, I2CCR_MEN); wait_for_busbusy(sc, false); i2c_write_reg(sc, I2C_CONTROL_REG, 0); + DEVICE_DEBUGF(sc, 2, "stop 0x%02x\n", sc->slave); return (IIC_NOERR); } @@ -523,6 +545,8 @@ i2c_reset(device_t dev, u_char speed, u_char addr, u_c sc = device_get_softc(dev); + DEVICE_DEBUGF(sc, 1, "reset\n"); + /* * Look up the divisor that gives the nearest speed that doesn't exceed * the configured value for the bus. @@ -568,6 +592,7 @@ i2c_read(device_t dev, char *buf, int len, int *read, sc = device_get_softc(dev); *read = 0; + DEVICE_DEBUGF(sc, 1, "read 0x%02x len %d: ", sc->slave, len); if (len) { if (len == 1) i2c_write_reg(sc, I2C_CONTROL_REG, I2CCR_MEN | @@ -599,9 +624,11 @@ i2c_read(device_t dev, char *buf, int len, int *read, } } reg = i2c_read_reg(sc, I2C_DATA_REG); + DEBUGF(sc, 1, "0x%02x ", reg); *buf++ = reg; (*read)++; } + DEBUGF(sc, 1, "\n"); return (i2c_error_handler(sc, error)); } @@ -616,13 +643,15 @@ i2c_write(device_t dev, const char *buf, int len, int error = 0; *sent = 0; + DEVICE_DEBUGF(sc, 1, "write 0x%02x len %d: ", sc->slave, len); while (*sent < len) { + DEBUGF(sc, 1, "0x%02x ", *buf); i2c_write_reg(sc, I2C_STATUS_REG, 0x0); i2c_write_reg(sc, I2C_DATA_REG, *buf++); if ((error = wait_for_xfer(sc, true)) != IIC_NOERR) break; (*sent)++; } - + DEBUGF(sc, 1, "\n"); return (i2c_error_handler(sc, error)); }