From owner-svn-src-head@freebsd.org Wed Dec 12 22:05:09 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D23FD1327AD9; Wed, 12 Dec 2018 22:05:08 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 75D0E83F21; Wed, 12 Dec 2018 22:05:08 +0000 (UTC) (envelope-from manu@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 56A97E4B8; Wed, 12 Dec 2018 22:05:08 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBCM58Iu009956; Wed, 12 Dec 2018 22:05:08 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBCM57lG009952; Wed, 12 Dec 2018 22:05:07 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201812122205.wBCM57lG009952@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Wed, 12 Dec 2018 22:05:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342015 - in head/sys: conf dev/iicbus/twsi X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: in head/sys: conf dev/iicbus/twsi X-SVN-Commit-Revision: 342015 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 75D0E83F21 X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-1.33 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.82)[-0.825,0]; NEURAL_HAM_SHORT(-0.51)[-0.506,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2018 22:05:09 -0000 Author: manu Date: Wed Dec 12 22:05:07 2018 New Revision: 342015 URL: https://svnweb.freebsd.org/changeset/base/342015 Log: twsi: Clean up marvell part and add support for Marvell 7k/8k Sponsored by: Rubicon Communications, LLC ("Netgate") Modified: head/sys/conf/files.arm64 head/sys/dev/iicbus/twsi/mv_twsi.c head/sys/dev/iicbus/twsi/twsi.c head/sys/dev/iicbus/twsi/twsi.h Modified: head/sys/conf/files.arm64 ============================================================================== --- head/sys/conf/files.arm64 Wed Dec 12 22:04:21 2018 (r342014) +++ head/sys/conf/files.arm64 Wed Dec 12 22:05:07 2018 (r342015) @@ -201,6 +201,7 @@ dev/axgbe/xgbe-dev.c optional axgbe dev/axgbe/xgbe-drv.c optional axgbe dev/axgbe/xgbe-mdio.c optional axgbe dev/cpufreq/cpufreq_dt.c optional cpufreq fdt +dev/iicbus/twsi/mv_twsi.c optional twsi fdt dev/iicbus/twsi/a10_twsi.c optional twsi fdt dev/iicbus/twsi/twsi.c optional twsi fdt dev/hwpmc/hwpmc_arm64.c optional hwpmc Modified: head/sys/dev/iicbus/twsi/mv_twsi.c ============================================================================== --- head/sys/dev/iicbus/twsi/mv_twsi.c Wed Dec 12 22:04:21 2018 (r342014) +++ head/sys/dev/iicbus/twsi/mv_twsi.c Wed Dec 12 22:05:07 2018 (r342015) @@ -61,6 +61,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -98,6 +100,7 @@ static int mv_twsi_attach(device_t); static struct ofw_compat_data compat_data[] = { { "mrvl,twsi", true }, { "marvell,mv64xxx-i2c", true }, + { "marvell,mv78230-i2c", true }, { NULL, false } }; @@ -141,29 +144,27 @@ mv_twsi_probe(device_t dev) if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) return (ENXIO); - sc->reg_data = TWSI_DATA; - sc->reg_slave_addr = TWSI_ADDR; - sc->reg_slave_ext_addr = TWSI_XADDR; - sc->reg_control = TWSI_CNTR; - sc->reg_status = TWSI_STAT; - sc->reg_baud_rate = TWSI_BAUD_RATE; - sc->reg_soft_reset = TWSI_SRST; - device_set_desc(dev, "Marvell Integrated I2C Bus Controller"); return (BUS_PROBE_DEFAULT); } #define ABSSUB(a,b) (((a) > (b)) ? (a) - (b) : (b) - (a)) static void -mv_twsi_cal_baud_rate(const uint32_t target, struct twsi_baud_rate *rate) +mv_twsi_cal_baud_rate(struct twsi_softc *sc, const uint32_t target, + struct twsi_baud_rate *rate) { - uint32_t clk, cur, diff, diff0; + uint64_t clk; + uint32_t cur, diff, diff0; int m, n, m0, n0; /* Calculate baud rate. */ m0 = n0 = 4; /* Default values on reset */ diff0 = 0xffffffff; +#ifdef __aarch64__ + clk_get_freq(sc->clk_core, &clk); +#else clk = get_tclk(); +#endif for (n = 0; n < 8; n++) { for (m = 0; m < 16; m++) { @@ -186,17 +187,37 @@ static int mv_twsi_attach(device_t dev) { struct twsi_softc *sc; - phandle_t child, iicbusnode; - device_t childdev; - struct iicbus_ivar *devi; - char dname[32]; /* 32 is taken from struct u_device */ - uint32_t paddr; - int len, error, ret; +#ifdef __aarch64__ + int error; +#endif sc = device_get_softc(dev); + sc->dev = dev; - mv_twsi_cal_baud_rate(TWSI_BAUD_RATE_SLOW, &sc->baud_rate[IIC_SLOW]); - mv_twsi_cal_baud_rate(TWSI_BAUD_RATE_FAST, &sc->baud_rate[IIC_FAST]); +#ifdef __aarch64__ + /* Activate clock */ + error = clk_get_by_ofw_index(dev, 0, 0, &sc->clk_core); + if (error != 0) { + device_printf(dev, "could not find core clock\n"); + return (error); + } + error = clk_enable(sc->clk_core); + if (error != 0) { + device_printf(dev, "could not enable core clock\n"); + return (error); + } + + if (clk_get_by_ofw_index(dev, 0, 1, &sc->clk_reg) == 0) { + error = clk_enable(sc->clk_reg); + if (error != 0) { + device_printf(dev, "could not enable core clock\n"); + return (error); + } + } +#endif + + mv_twsi_cal_baud_rate(sc, TWSI_BAUD_RATE_SLOW, &sc->baud_rate[IIC_SLOW]); + mv_twsi_cal_baud_rate(sc, TWSI_BAUD_RATE_FAST, &sc->baud_rate[IIC_FAST]); if (bootverbose) device_printf(dev, "calculated baud rates are:\n" " %" PRIu32 " kHz (M=%d, N=%d) for slow,\n" @@ -208,56 +229,13 @@ mv_twsi_attach(device_t dev) sc->baud_rate[IIC_FAST].m, sc->baud_rate[IIC_FAST].n); + sc->reg_data = TWSI_DATA; + sc->reg_slave_addr = TWSI_ADDR; + sc->reg_slave_ext_addr = TWSI_XADDR; + sc->reg_control = TWSI_CNTR; + sc->reg_status = TWSI_STAT; + sc->reg_baud_rate = TWSI_BAUD_RATE; + sc->reg_soft_reset = TWSI_SRST; - ret = twsi_attach(dev); - if (ret != 0) - return (ret); - - iicbusnode = 0; - /* Find iicbus as the child devices in the device tree. */ - for (child = OF_child(ofw_bus_get_node(dev)); child != 0; - child = OF_peer(child)) { - len = OF_getproplen(child, "model"); - if (len <= 0 || len > sizeof(dname)) - continue; - error = OF_getprop(child, "model", &dname, len); - if (error == -1) - continue; - len = strlen(dname); - if (len == strlen(IICBUS_DEVNAME) && - strncasecmp(dname, IICBUS_DEVNAME, len) == 0) { - iicbusnode = child; - break; - } - } - if (iicbusnode == 0) - goto attach_end; - - /* Attach child devices onto iicbus. */ - for (child = OF_child(iicbusnode); child != 0; child = OF_peer(child)) { - /* Get slave address. */ - error = OF_getencprop(child, "i2c-address", &paddr, sizeof(paddr)); - if (error == -1) - error = OF_getencprop(child, "reg", &paddr, sizeof(paddr)); - if (error == -1) - continue; - - /* Get device driver name. */ - len = OF_getproplen(child, "model"); - if (len <= 0 || len > sizeof(dname)) - continue; - OF_getprop(child, "model", &dname, len); - - if (bootverbose) - device_printf(dev, "adding a device %s at %d.\n", - dname, paddr); - childdev = BUS_ADD_CHILD(sc->iicbus, 0, dname, -1); - devi = IICBUS_IVAR(childdev); - devi->addr = paddr; - } - -attach_end: - bus_generic_attach(sc->iicbus); - - return (0); + return (twsi_attach(dev)); } Modified: head/sys/dev/iicbus/twsi/twsi.c ============================================================================== --- head/sys/dev/iicbus/twsi/twsi.c Wed Dec 12 22:04:21 2018 (r342014) +++ head/sys/dev/iicbus/twsi/twsi.c Wed Dec 12 22:05:07 2018 (r342015) @@ -440,6 +440,7 @@ twsi_detach(device_t dev) int rv; sc = device_get_softc(dev); + debugf(""); if ((rv = bus_generic_detach(dev)) != 0) return (rv); Modified: head/sys/dev/iicbus/twsi/twsi.h ============================================================================== --- head/sys/dev/iicbus/twsi/twsi.h Wed Dec 12 22:04:21 2018 (r342014) +++ head/sys/dev/iicbus/twsi/twsi.h Wed Dec 12 22:05:07 2018 (r342015) @@ -34,6 +34,8 @@ #ifndef _TWSI_H_ #define _TWSI_H_ +#include + struct twsi_baud_rate { uint32_t raw; int param; @@ -46,6 +48,8 @@ struct twsi_softc { struct resource *res[1]; /* SYS_RES_MEMORY */ struct mtx mutex; device_t iicbus; + clk_t clk_core; + clk_t clk_reg; bus_size_t reg_data; bus_size_t reg_slave_addr;