From owner-svn-src-head@freebsd.org Thu Jun 14 20:37:26 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 82B5F10030C6; Thu, 14 Jun 2018 20:37:26 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 38C7380D69; Thu, 14 Jun 2018 20:37:26 +0000 (UTC) (envelope-from kevans@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 19F2D5B2B; Thu, 14 Jun 2018 20:37:26 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5EKbPB8096777; Thu, 14 Jun 2018 20:37:25 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5EKbP6S096772; Thu, 14 Jun 2018 20:37:25 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201806142037.w5EKbP6S096772@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 14 Jun 2018 20:37:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335173 - head/sys/dev/extres/regulator X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/dev/extres/regulator X-SVN-Commit-Revision: 335173 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 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: Thu, 14 Jun 2018 20:37:26 -0000 Author: kevans Date: Thu Jun 14 20:37:25 2018 New Revision: 335173 URL: https://svnweb.freebsd.org/changeset/base/335173 Log: extres/regulator: Properly refcount gpio regulators regnode::enable_cnt is generally used to refcount regulator nodes. For GPIOs, the refcount was done on the gpio_entry since more than one regulator can share a GPIO. GPIO regulators were not taking part in the node refcount, since they had their own mechanism. This caused some fallout after manu started disabling everybody's unused regulators in r331989. Refcount it. Glanced over by: manu Modified: head/sys/dev/extres/regulator/regulator.c head/sys/dev/extres/regulator/regulator.h head/sys/dev/extres/regulator/regulator_fixed.c Modified: head/sys/dev/extres/regulator/regulator.c ============================================================================== --- head/sys/dev/extres/regulator/regulator.c Thu Jun 14 20:36:55 2018 (r335172) +++ head/sys/dev/extres/regulator/regulator.c Thu Jun 14 20:37:25 2018 (r335173) @@ -507,6 +507,20 @@ struct regnode_std_param *regnode_get_stdparam(struct return (®node->std_param); } +void +regnode_enable_cnt_inc(struct regnode *regnode) +{ + + regnode->enable_cnt++; +} + +void +regnode_enable_cnt_dec(struct regnode *regnode) +{ + + regnode->enable_cnt--; +} + void regnode_topo_unlock(void) { Modified: head/sys/dev/extres/regulator/regulator.h ============================================================================== --- head/sys/dev/extres/regulator/regulator.h Thu Jun 14 20:36:55 2018 (r335172) +++ head/sys/dev/extres/regulator/regulator.h Thu Jun 14 20:37:25 2018 (r335173) @@ -106,6 +106,8 @@ int regnode_get_flags(struct regnode *regnode); void *regnode_get_softc(struct regnode *regnode); device_t regnode_get_device(struct regnode *regnode); struct regnode_std_param *regnode_get_stdparam(struct regnode *regnode); +void regnode_enable_cnt_inc(struct regnode *regnode); +void regnode_enable_cnt_dec(struct regnode *regnode); void regnode_topo_unlock(void); void regnode_topo_xlock(void); void regnode_topo_slock(void); Modified: head/sys/dev/extres/regulator/regulator_fixed.c ============================================================================== --- head/sys/dev/extres/regulator/regulator_fixed.c Thu Jun 14 20:36:55 2018 (r335172) +++ head/sys/dev/extres/regulator/regulator_fixed.c Thu Jun 14 20:37:25 2018 (r335173) @@ -156,6 +156,8 @@ regnode_fixed_init(struct regnode *regnode) if (sc->gpio_open_drain) flags |= GPIO_PIN_OPENDRAIN; enable = sc->param->boot_on || sc->param->always_on; + if (enable) + regnode_enable_cnt_inc(regnode); if (!sc->param->enable_active_high) enable = !enable; rv = GPIO_PIN_SET(pin->dev, pin->pin, enable); @@ -194,12 +196,14 @@ regnode_fixed_enable(struct regnode *regnode, bool ena return (0); pin = &sc->gpio_entry->gpio_pin; if (enable) { + regnode_enable_cnt_inc(regnode); sc->gpio_entry->enable_cnt++; if (sc->gpio_entry->enable_cnt > 1) return (0); } else { KASSERT(sc->gpio_entry->enable_cnt > 0, ("Invalid enable count")); + regnode_enable_cnt_dec(regnode); sc->gpio_entry->enable_cnt--; if (sc->gpio_entry->enable_cnt >= 1) return (0);