From patchwork Sat Sep 28 03:24:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Otavio Salvador X-Patchwork-Id: 278706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 1E3CC2C0335 for ; Sat, 28 Sep 2013 13:32:56 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B53384A080; Sat, 28 Sep 2013 05:32:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c8o4uz3tIS9G; Sat, 28 Sep 2013 05:32:54 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9EF5F4A088; Sat, 28 Sep 2013 05:32:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0BB4A4A092 for ; Sat, 28 Sep 2013 05:32:45 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mlPcTZB1lBom for ; Sat, 28 Sep 2013 05:32:38 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-yh0-f47.google.com (mail-yh0-f47.google.com [209.85.213.47]) by theia.denx.de (Postfix) with ESMTPS id 72E574A08F for ; Sat, 28 Sep 2013 05:32:17 +0200 (CEST) Received: by mail-yh0-f47.google.com with SMTP id l109so1268153yhq.20 for ; Fri, 27 Sep 2013 20:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :organization; bh=pxN3hycyWlSA41ER89edpWrFMQfKPHVIdnmJWbjwXaw=; b=sQDpHxqlfhd0K4fJeuwNYlwqibtCw0DHdqm+tkqTJRlYX7rf1ZVwGhrRmky8cLiwKz utIDhjxN+FVheQoKnAAzgVFu/B3kauHbXupj7j7MeaF756tIZdPPyzD38dVm3IhXBEF8 Y7W8IjPiR+AYtypGWPi7J3Q2QS3GvINR7Q/BG2Guf9AEMZmZXQvMEW9tc0W8GK5Nri4u IslzRe8y7xS6+H4nxKOY/RFIV7G7+VN5AlmabnwJGmpEgp+T+sNRHWTe/kpODL7caM+B ETIxonYHAi8gdxeqAb3txheHIuBSAKWuvXZgXpyypuAy0m5RN192XNDcvmOXBxpJPwv4 kZjQ== X-Received: by 10.236.32.3 with SMTP id n3mr10270943yha.25.1380338686183; Fri, 27 Sep 2013 20:24:46 -0700 (PDT) Received: from nano.lab.ossystems.com.br ([177.194.209.11]) by mx.google.com with ESMTPSA id v45sm15980678yha.2.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Sep 2013 20:24:45 -0700 (PDT) From: Otavio Salvador To: U-Boot Mailing List Date: Sat, 28 Sep 2013 00:24:17 -0300 Message-Id: <1380338659-7896-6-git-send-email-otavio@ossystems.com.br> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1380338659-7896-1-git-send-email-otavio@ossystems.com.br> References: <1380338659-7896-1-git-send-email-otavio@ossystems.com.br> Organization: O.S. Systems Software LTDA. Cc: Otavio Salvador Subject: [U-Boot] [PATCH 6/7] status_led: Add support for inverted LEDs X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de There're cases we want to use active-low LEDs and the 'inverted' logic needs to be added. This includes it using the STATUS_LED_INVERT macro. Signed-off-by: Otavio Salvador --- doc/README.LED | 2 ++ drivers/misc/status_led.c | 21 ++++++++++++++++++--- include/status_led.h | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/doc/README.LED b/doc/README.LED index c3bcb3a..c14555a 100644 --- a/doc/README.LED +++ b/doc/README.LED @@ -43,6 +43,8 @@ STATUS_LED_RED is the red LED. It is used signal errors. This must be a valid STATUS_LED_BIT value. Other similar color LED's are STATUS_LED_YELLOW and STATUS_LED_BLUE. +STATUS_LED_INVERT and STATUS_LED_INVERT to use active-low LEDs. + These board must define these functions __led_init is called once to initialize the LED to STATUS_LED_STATE. One time diff --git a/drivers/misc/status_led.c b/drivers/misc/status_led.c index 6b71ad4..5878d15 100644 --- a/drivers/misc/status_led.c +++ b/drivers/misc/status_led.c @@ -23,19 +23,22 @@ typedef struct { led_id_t mask; int state; int period; + int invert; int cnt; } led_dev_t; -led_dev_t led_dev[] = { +static led_dev_t led_dev[] = { { STATUS_LED_BIT, STATUS_LED_STATE, STATUS_LED_PERIOD, + STATUS_LED_INVERT, 0, }, #if defined(STATUS_LED_BIT1) { STATUS_LED_BIT1, STATUS_LED_STATE1, STATUS_LED_PERIOD1, + STATUS_LED_INVERT1, 0, }, #endif @@ -43,6 +46,7 @@ led_dev_t led_dev[] = { { STATUS_LED_BIT2, STATUS_LED_STATE2, STATUS_LED_PERIOD2, + STATUS_LED_INVERT2, 0, }, #endif @@ -50,6 +54,7 @@ led_dev_t led_dev[] = { { STATUS_LED_BIT3, STATUS_LED_STATE3, STATUS_LED_PERIOD3, + STATUS_LED_INVERT3, 0, }, #endif @@ -64,9 +69,11 @@ static void status_led_init (void) led_dev_t *ld; int i; - for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) - __led_init (ld->mask, ld->state); + /* Avoid join in a call loop */ status_led_init_done = 1; + + for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) + status_led_set (i, ld->state); } void status_led_tick (ulong timestamp) @@ -107,5 +114,13 @@ void status_led_set (int led, int state) ld->cnt = 0; /* always start with full period */ state = STATUS_LED_ON; /* always start with LED _ON_ */ } + + if (ld->invert) { + if (state == STATUS_LED_ON) + state = STATUS_LED_OFF; + else + state = STATUS_LED_ON; + } + __led_set (ld->mask, state); } diff --git a/include/status_led.h b/include/status_led.h index ecff60d..0da3fda 100644 --- a/include/status_led.h +++ b/include/status_led.h @@ -288,6 +288,20 @@ extern void __led_set (led_id_t mask, int state); #else # error Status LED configuration missing #endif + +#ifndef STATUS_LED_INVERT +#define STATUS_LED_INVERT 0 +#endif +#ifndef STATUS_LED_INVERT1 +#define STATUS_LED_INVERT1 0 +#endif +#ifndef STATUS_LED_INVERT2 +#define STATUS_LED_INVERT2 0 +#endif +#ifndef STATUS_LED_INVERT3 +#define STATUS_LED_INVERT3 0 +#endif + /************************************************************************/ #ifndef CONFIG_BOARD_SPECIFIC_LED