From owner-svn-src-all@FreeBSD.ORG Tue Feb 17 20:37:22 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1733CFDC; Tue, 17 Feb 2015 20:37:22 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 02699F70; Tue, 17 Feb 2015 20:37:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1HKbLqP021932; Tue, 17 Feb 2015 20:37:21 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1HKbLTE021931; Tue, 17 Feb 2015 20:37:21 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201502172037.t1HKbLTE021931@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Tue, 17 Feb 2015 20:37:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278919 - head/sys/arm/broadcom/bcm2835 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.18-1 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: Tue, 17 Feb 2015 20:37:22 -0000 Author: loos Date: Tue Feb 17 20:37:21 2015 New Revision: 278919 URL: https://svnweb.freebsd.org/changeset/base/278919 Log: Make use of the newly introduced macros. Update the copyright. Modified: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c Modified: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c ============================================================================== --- head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c Tue Feb 17 20:29:42 2015 (r278918) +++ head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c Tue Feb 17 20:37:21 2015 (r278919) @@ -1,6 +1,6 @@ /*- - * Copyright (c) 2012 Oleksandr Tymoshenko - * Copyright (c) 2012 Luiz Otavio O Souza. + * Copyright (c) 2012 Oleksandr Tymoshenko + * Copyright (c) 2012-2015 Luiz Otavio O Souza * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -251,16 +251,14 @@ bcm_gpio_set_function(struct bcm_gpio_so static void bcm_gpio_set_pud(struct bcm_gpio_softc *sc, uint32_t pin, uint32_t state) { - uint32_t bank, offset; + uint32_t bank; /* Must be called with lock held. */ BCM_GPIO_LOCK_ASSERT(sc); - bank = pin / 32; - offset = pin - 32 * bank; - + bank = BCM_GPIO_BANK(pin); BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), state); - BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), (1 << offset)); + BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), BCM_GPIO_MASK(pin)); BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), 0); BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), 0); } @@ -438,29 +436,25 @@ static int bcm_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) { struct bcm_gpio_softc *sc = device_get_softc(dev); - uint32_t bank, offset; + uint32_t bank, reg; int i; for (i = 0; i < sc->sc_gpio_npins; i++) { if (sc->sc_gpio_pins[i].gp_pin == pin) break; } - if (i >= sc->sc_gpio_npins) return (EINVAL); - /* We never write to read-only/reserved pins. */ if (bcm_gpio_pin_is_ro(sc, pin)) return (EINVAL); - - bank = pin / 32; - offset = pin - 32 * bank; - BCM_GPIO_LOCK(sc); + bank = BCM_GPIO_BANK(pin); if (value) - BCM_GPIO_WRITE(sc, BCM_GPIO_GPSET(bank), (1 << offset)); + reg = BCM_GPIO_GPSET(bank); else - BCM_GPIO_WRITE(sc, BCM_GPIO_GPCLR(bank), (1 << offset)); + reg = BCM_GPIO_GPCLR(bank); + BCM_GPIO_WRITE(sc, reg, BCM_GPIO_MASK(pin)); BCM_GPIO_UNLOCK(sc); return (0); @@ -470,24 +464,20 @@ static int bcm_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) { struct bcm_gpio_softc *sc = device_get_softc(dev); - uint32_t bank, offset, reg_data; + uint32_t bank, reg_data; int i; for (i = 0; i < sc->sc_gpio_npins; i++) { if (sc->sc_gpio_pins[i].gp_pin == pin) break; } - if (i >= sc->sc_gpio_npins) return (EINVAL); - - bank = pin / 32; - offset = pin - 32 * bank; - + bank = BCM_GPIO_BANK(pin); BCM_GPIO_LOCK(sc); reg_data = BCM_GPIO_READ(sc, BCM_GPIO_GPLEV(bank)); BCM_GPIO_UNLOCK(sc); - *val = (reg_data & (1 << offset)) ? 1 : 0; + *val = (reg_data & BCM_GPIO_MASK(pin)) ? 1 : 0; return (0); } @@ -496,30 +486,26 @@ static int bcm_gpio_pin_toggle(device_t dev, uint32_t pin) { struct bcm_gpio_softc *sc = device_get_softc(dev); - uint32_t bank, data, offset; + uint32_t bank, data, reg; int i; for (i = 0; i < sc->sc_gpio_npins; i++) { if (sc->sc_gpio_pins[i].gp_pin == pin) break; } - if (i >= sc->sc_gpio_npins) return (EINVAL); - /* We never write to read-only/reserved pins. */ if (bcm_gpio_pin_is_ro(sc, pin)) return (EINVAL); - - bank = pin / 32; - offset = pin - 32 * bank; - BCM_GPIO_LOCK(sc); + bank = BCM_GPIO_BANK(pin); data = BCM_GPIO_READ(sc, BCM_GPIO_GPLEV(bank)); - if (data & (1 << offset)) - BCM_GPIO_WRITE(sc, BCM_GPIO_GPCLR(bank), (1 << offset)); + if (data & BCM_GPIO_MASK(pin)) + reg = BCM_GPIO_GPCLR(bank); else - BCM_GPIO_WRITE(sc, BCM_GPIO_GPSET(bank), (1 << offset)); + reg = BCM_GPIO_GPSET(bank); + BCM_GPIO_WRITE(sc, reg, BCM_GPIO_MASK(pin)); BCM_GPIO_UNLOCK(sc); return (0);