From owner-svn-src-head@freebsd.org Wed Aug 17 10:20:37 2016 Return-Path: Delivered-To: svn-src-head@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 51BF8BBC2CB; Wed, 17 Aug 2016 10:20:37 +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 mx1.freebsd.org (Postfix) with ESMTPS id 2C54114A3; Wed, 17 Aug 2016 10:20:37 +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 u7HAKaU4071990; Wed, 17 Aug 2016 10:20:36 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7HAKaki071989; Wed, 17 Aug 2016 10:20:36 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201608171020.u7HAKaki071989@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Wed, 17 Aug 2016 10:20:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304289 - head/sys/arm/allwinner X-SVN-Group: head 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.22 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, 17 Aug 2016 10:20:37 -0000 Author: manu Date: Wed Aug 17 10:20:36 2016 New Revision: 304289 URL: https://svnweb.freebsd.org/changeset/base/304289 Log: a10_gpio_get_function now returns the whole function not only GPIO_INPUT/GPIO_OUTPUT. a10_gpio_get_pud now returns the whole pud not only PULLDOWN/PULLUP. Add a10_gpio_get_drv to get the current drive strenght. During fdt pin configure, avoid setting function/drive/pud if it's already in the correct value. Tested on Allwinner H3 and A20 MFC after: 1 week Modified: head/sys/arm/allwinner/a10_gpio.c Modified: head/sys/arm/allwinner/a10_gpio.c ============================================================================== --- head/sys/arm/allwinner/a10_gpio.c Wed Aug 17 10:20:05 2016 (r304288) +++ head/sys/arm/allwinner/a10_gpio.c Wed Aug 17 10:20:36 2016 (r304289) @@ -210,14 +210,8 @@ a10_gpio_get_function(struct a10_gpio_so offset = ((pin & 0x07) << 2); func = A10_GPIO_READ(sc, A10_GPIO_GP_CFG(bank, pin >> 3)); - switch ((func >> offset) & 0x7) { - case A10_GPIO_INPUT: - return (GPIO_PIN_INPUT); - case A10_GPIO_OUTPUT: - return (GPIO_PIN_OUTPUT); - } - return (0); + return ((func >> offset) & 0x7); } static int @@ -257,14 +251,8 @@ a10_gpio_get_pud(struct a10_gpio_softc * offset = ((pin & 0x0f) << 1); val = A10_GPIO_READ(sc, A10_GPIO_GP_PUL(bank, pin >> 4)); - switch ((val >> offset) & 0x3) { - case A10_GPIO_PULLDOWN: - return (GPIO_PIN_PULLDOWN); - case A10_GPIO_PULLUP: - return (GPIO_PIN_PULLUP); - } - return (0); + return ((val >> offset) & AW_GPIO_PUD_MASK); } static void @@ -285,6 +273,23 @@ a10_gpio_set_pud(struct a10_gpio_softc * A10_GPIO_WRITE(sc, A10_GPIO_GP_PUL(bank, pin >> 4), val); } +static uint32_t +a10_gpio_get_drv(struct a10_gpio_softc *sc, uint32_t pin) +{ + uint32_t bank, offset, val; + + /* Must be called with lock held. */ + A10_GPIO_LOCK_ASSERT(sc); + + bank = sc->padconf->pins[pin].port; + pin = sc->padconf->pins[pin].pin; + offset = ((pin & 0x0f) << 1); + + val = A10_GPIO_READ(sc, A10_GPIO_GP_DRV(bank, pin >> 4)); + + return ((val >> offset) & AW_GPIO_DRV_MASK); +} + static void a10_gpio_set_drv(struct a10_gpio_softc *sc, uint32_t pin, uint32_t drive) { @@ -373,14 +378,39 @@ static int a10_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) { struct a10_gpio_softc *sc; + uint32_t func; + uint32_t pud; sc = device_get_softc(dev); if (pin >= sc->padconf->npins) return (EINVAL); A10_GPIO_LOCK(sc); - *flags = a10_gpio_get_function(sc, pin); - *flags |= a10_gpio_get_pud(sc, pin); + func = a10_gpio_get_function(sc, pin); + switch (func) { + case A10_GPIO_INPUT: + *flags = GPIO_PIN_INPUT; + break; + case A10_GPIO_OUTPUT: + *flags = GPIO_PIN_OUTPUT; + break; + default: + *flags = 0; + break; + } + + pud = a10_gpio_get_pud(sc, pin); + switch (pud) { + case A10_GPIO_PULLDOWN: + *flags |= GPIO_PIN_PULLDOWN; + break; + case A10_GPIO_PULLUP: + *flags |= GPIO_PIN_PULLUP; + break; + default: + break; + } + A10_GPIO_UNLOCK(sc); return (0); @@ -564,9 +594,13 @@ aw_fdt_configure_pins(device_t dev, phan } A10_GPIO_LOCK(sc); - a10_gpio_set_function(sc, pin_num, pin_func); - a10_gpio_set_drv(sc, pin_num, pin_drive); - a10_gpio_set_pud(sc, pin_num, pin_pull); + + if (a10_gpio_get_function(sc, pin_num) != pin_func) + a10_gpio_set_function(sc, pin_num, pin_func); + if (a10_gpio_get_drv(sc, pin_num) != pin_drive) + a10_gpio_set_drv(sc, pin_num, pin_drive); + if (a10_gpio_get_pud(sc, pin_num) != pin_pull) + a10_gpio_set_pud(sc, pin_num, pin_pull); A10_GPIO_UNLOCK(sc); }