From owner-svn-src-all@freebsd.org Fri May 6 05:22:27 2016 Return-Path: Delivered-To: svn-src-all@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 1D335B2E10F; Fri, 6 May 2016 05:22:27 +0000 (UTC) (envelope-from sgalabov@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 EDE121833; Fri, 6 May 2016 05:22:26 +0000 (UTC) (envelope-from sgalabov@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u465MQ94019978; Fri, 6 May 2016 05:22:26 GMT (envelope-from sgalabov@FreeBSD.org) Received: (from sgalabov@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u465MQUW019976; Fri, 6 May 2016 05:22:26 GMT (envelope-from sgalabov@FreeBSD.org) Message-Id: <201605060522.u465MQUW019976@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sgalabov set sender to sgalabov@FreeBSD.org using -f From: Stanislav Galabov Date: Fri, 6 May 2016 05:22:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299154 - head/sys/mips/mediatek X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2016 05:22:27 -0000 Author: sgalabov Date: Fri May 6 05:22:25 2016 New Revision: 299154 URL: https://svnweb.freebsd.org/changeset/base/299154 Log: mtk_gpio fixes Allow output pins to be read and input pins to be set. Fix bugs where we were trying to access the gpio softc before doing device_get_softc. Approved by: adrian (mentor) Sponsored by: Smartcom - Bulgaria AD Differential Revision: https://reviews.freebsd.org/D6222 Modified: head/sys/mips/mediatek/mtk_gpio_v1.c head/sys/mips/mediatek/mtk_gpio_v2.c Modified: head/sys/mips/mediatek/mtk_gpio_v1.c ============================================================================== --- head/sys/mips/mediatek/mtk_gpio_v1.c Fri May 6 05:16:42 2016 (r299153) +++ head/sys/mips/mediatek/mtk_gpio_v1.c Fri May 6 05:22:25 2016 (r299154) @@ -290,7 +290,7 @@ mtk_gpio_attach(device_t dev) else sc->num_pins = MTK_GPIO_PINS; - for (i = 0; i < num_pins; i++) { + for (i = 0; i < sc->num_pins; i++) { sc->pins[i].pin_caps |= GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | GPIO_PIN_INVIN | GPIO_PIN_INVOUT; sc->pins[i].intr_polarity = INTR_POLARITY_HIGH; @@ -444,18 +444,12 @@ mtk_gpio_pin_set(device_t dev, uint32_t return (EINVAL); MTK_GPIO_LOCK(sc); - if(!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { - ret = EINVAL; - goto out; - } - if (value) MTK_WRITE_4(sc, GPIO_PIOSET, (1u << pin)); else MTK_WRITE_4(sc, GPIO_PIORESET, (1u << pin)); - -out: MTK_GPIO_UNLOCK(sc); + return (ret); } @@ -473,15 +467,10 @@ mtk_gpio_pin_get(device_t dev, uint32_t return (EINVAL); MTK_GPIO_LOCK(sc); - if(!(sc->pins[pin].pin_flags & GPIO_PIN_INPUT)) { - ret = EINVAL; - goto out; - } data = MTK_READ_4(sc, GPIO_PIODATA); *val = (data & (1u << pin)) ? 1 : 0; - -out: MTK_GPIO_UNLOCK(sc); + return (ret); } @@ -491,12 +480,12 @@ mtk_gpio_pin_toggle(device_t dev, uint32 struct mtk_gpio_softc *sc; int ret; - if (pin >= sc->num_pins) - return (EINVAL); - sc = device_get_softc(dev); ret = 0; + if (pin >= sc->num_pins) + return (EINVAL); + MTK_GPIO_LOCK(sc); if (!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { ret = EINVAL; Modified: head/sys/mips/mediatek/mtk_gpio_v2.c ============================================================================== --- head/sys/mips/mediatek/mtk_gpio_v2.c Fri May 6 05:16:42 2016 (r299153) +++ head/sys/mips/mediatek/mtk_gpio_v2.c Fri May 6 05:22:25 2016 (r299154) @@ -428,23 +428,17 @@ mtk_gpio_pin_set(device_t dev, uint32_t struct mtk_gpio_softc *sc; int ret; - if (pin >= sc->num_pins) - return (EINVAL); - sc = device_get_softc(dev); ret = 0; + if (pin >= sc->num_pins) + return (EINVAL); + MTK_GPIO_LOCK(sc); - if (!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { - ret = EINVAL; - goto out; - } if (value) MTK_WRITE_4(sc, GPIO_PIOSET(sc), (1u << pin)); else MTK_WRITE_4(sc, GPIO_PIORESET(sc), (1u << pin)); - -out: MTK_GPIO_UNLOCK(sc); return (ret); @@ -457,22 +451,17 @@ mtk_gpio_pin_get(device_t dev, uint32_t uint32_t data; int ret; - if (pin >= sc->num_pins) - return (EINVAL); - sc = device_get_softc(dev); ret = 0; + if (pin >= sc->num_pins) + return (EINVAL); + MTK_GPIO_LOCK(sc); - if (!(sc->pins[pin].pin_flags & GPIO_PIN_INPUT)) { - ret = EINVAL; - goto out; - } data = MTK_READ_4(sc, GPIO_PIODATA(sc)); *val = (data & (1u << pin)) ? 1 : 0; - -out: MTK_GPIO_UNLOCK(sc); + return (ret); } @@ -483,12 +472,12 @@ mtk_gpio_pin_toggle(device_t dev, uint32 uint32_t val; int ret; - if (pin >= sc->num_pins) - return (EINVAL); - sc = device_get_softc(dev); ret = 0; + if (pin >= sc->num_pins) + return (EINVAL); + MTK_GPIO_LOCK(sc); if(!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { ret = EINVAL;