From patchwork Thu Apr 15 11:12:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alessandro Rubini X-Patchwork-Id: 71758 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: wd@gemini.denx.de Delivered-To: wd@gemini.denx.de Received: from diddl.denx.de (diddl.denx.de [10.0.0.6]) by gemini.denx.de (Postfix) with ESMTP id 1006DEEE8D8 for ; Thu, 15 Apr 2010 13:13:41 +0200 (CEST) Received: from diddl.denx.de (localhost.localdomain [127.0.0.1]) by diddl.denx.de (Postfix) with ESMTP id 02AC3C913130 for ; Thu, 15 Apr 2010 13:13:41 +0200 (CEST) Received: from pop.mnet-online.de by diddl.denx.de with POP3 (fetchmail-6.3.9) for (single-drop); Thu, 15 Apr 2010 13:13:41 +0200 (CEST) Received: from murder (svr19.m-online.net [192.168.3.147]) by backend2 (Cyrus v2.2.12) with LMTPA; Thu, 15 Apr 2010 13:13:24 +0200 X-Sieve: CMU Sieve 2.2 Received: from mail.m-online.net (localhost [127.0.0.1]) by frontend3.pop.m-online.net (Cyrus v2.2.13) with LMTPA; Thu, 15 Apr 2010 13:13:23 +0200 Received: from scanner-1.m-online.net (unknown [192.168.8.165]) by mail.m-online.net (Postfix) with ESMTP id 39347200088; Thu, 15 Apr 2010 13:13:23 +0200 (CEST) Received: from mxin-2.m-online.net ([192.168.1.21]) by scanner-1.m-online.net (scanner-1.m-online.net [192.168.8.165]) (amavisd-new, port 10026) with ESMTP id 24902-03-8; Thu, 15 Apr 2010 13:13:21 +0200 (CEST) Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by mxin-2.m-online.net (Postfix) with ESMTP id 79D5B46C0A7; Thu, 15 Apr 2010 13:13:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 66107280CB; Thu, 15 Apr 2010 13:12:45 +0200 (CEST) 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 sZybcgh-0bQe; Thu, 15 Apr 2010 13:12:45 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BF93E280D2; Thu, 15 Apr 2010 13:12:38 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 91FC02808C for ; Thu, 15 Apr 2010 13:12:36 +0200 (CEST) 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 R43QfWHKV6Eb for ; Thu, 15 Apr 2010 13:12:36 +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.gnudd.com (mail2.gnudd.com [213.203.150.91]) by theia.denx.de (Postfix) with ESMTPS id 0251C280D4 for ; Thu, 15 Apr 2010 13:12:30 +0200 (CEST) Received: from mail.gnudd.com (localhost [127.0.0.1]) by mail.gnudd.com (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id o3FBCRPf029175; Thu, 15 Apr 2010 13:12:27 +0200 Received: (from rubini@localhost) by mail.gnudd.com (8.14.3/8.14.3/Submit) id o3FBCRku029174; Thu, 15 Apr 2010 13:12:27 +0200 Date: Thu, 15 Apr 2010 13:12:27 +0200 From: Alessandro Rubini To: u-boot@lists.denx.de Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Face: #Q; A)@_4.#>0+_%y]7aBr:c"ndLp&#+2?]J; lkse\^)FP^Lr5@O0{)J; 'nny4%74.fM'n)M >ISCj.KmsL/HTxz!:Ju'pnj'Gz&. Organization: GnuDD, Device Drivers, Embedded Systems, Courses References: In-Reply-To: Cc: STEricsson_nomadik_linux@list.st.com, andrea.gallo@stericsson.com Subject: [U-Boot] [PATCH 4/7] nhk8815: added keypad X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Virus-Scanned: by amavisd-new at m-online.net From: Alessandro Rubini This patch adds keypad support for the nhk8815 board, based on the stmpe2401 driver. The keypad hosts 16 keys, so each of them sends a string instead of a single key. The provided keymap is only an example and must be customized according to the use case. Signed-off-by: Alessandro Rubini Acked-by: Andrea Gallo --- board/st/nhk8815/Makefile | 5 ++- board/st/nhk8815/keypad.c | 99 ++++++++++++++++++++++++++++++++++++ board/st/nhk8815/nhk8815-devices.h | 7 +++ board/st/nhk8815/nhk8815.c | 4 ++ include/configs/nhk8815.h | 3 + 5 files changed, 117 insertions(+), 1 deletions(-) create mode 100644 board/st/nhk8815/keypad.c create mode 100644 board/st/nhk8815/nhk8815-devices.h diff --git a/board/st/nhk8815/Makefile b/board/st/nhk8815/Makefile index b37fe53..1bb1d2c 100644 --- a/board/st/nhk8815/Makefile +++ b/board/st/nhk8815/Makefile @@ -29,7 +29,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(BOARD).a -COBJS := nhk8815.o +COBJS-y := nhk8815.o +COBJS-$(CONFIG_NHK8815_KEYPAD) += keypad.o + +COBJS := $(COBJS-y) SOBJS := platform.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/board/st/nhk8815/keypad.c b/board/st/nhk8815/keypad.c new file mode 100644 index 0000000..4bbcce6 --- /dev/null +++ b/board/st/nhk8815/keypad.c @@ -0,0 +1,99 @@ +/* + * board/st/nhk8815/keypad.c: keypad on nhk8815 board, based on STMPE2401 + * + * Copyright 2009 Alessandro Rubini + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ +#include +#include +#include +#include + +/* + * Keymap for our 4x4 matrix: since we have just + * a few keys, use a string for each of the keys. + */ +static char *keymap[4][4] = { + {"", "back", "ffw", "left"}, + {"", "tvout", "playpause", "right"}, + {"vol-", "lock", "rew", "up"}, + {"vol+", "start", "ok", "down"} +}; + +/* this keeps track of the string being returned */ +static char *nextchar = ""; + +/* This getc can return failure, not permitted in the caller */ +static int __nhk8815_getc(void) +{ + int row, col, res; + + res = pe_kpc_getkey(STMPE0, &row, &col); + if (res < 0) + return res; /* invalid */ + nextchar = keymap[row][col]; + return 0; +} + +/* This is low level: may not report a valid key (a release, for example) */ +static int __nhk8815_tstc(void) +{ + /* the interrupt is active low */ + int gpio = nmk_gpio_get(76); + return !gpio; +} + +/* This is the one that is being called, it reads the pending string */ +static int nhk8815_tstc(void) +{ + if (*nextchar) /* there's already data */ + return 1; + if (!__nhk8815_tstc()) /* no new data? */ + return 0; + __nhk8815_getc(); /* get (or not) new data */ + return (nextchar[0] != '\0'); +} + +/* So this is only called when there is data in the currenct string */ +static int nhk8815_getc(void) +{ + return *(nextchar++); +} + +/* called from late init */ +int nhk8815_keypad_init(void) +{ + struct stdio_dev dev; + + /* The keypad is on EXP0, columns 0..3, rows 0..3 */ + pe_kpc_init(STMPE0, 0x0f, 0x0f, 30 /* ms */); + + /* Keypad interrupt: GPIO76 */ + nmk_gpio_af(76, GPIO_GPIO); + nmk_gpio_dir(76, 0); + + memset (&dev, 0, sizeof (dev)); + dev.flags = DEV_FLAGS_INPUT; + dev.getc = nhk8815_getc; + dev.tstc = nhk8815_tstc; + strcpy(dev.name, "keypad"); + stdio_register(&dev); + return 0; +} diff --git a/board/st/nhk8815/nhk8815-devices.h b/board/st/nhk8815/nhk8815-devices.h new file mode 100644 index 0000000..78252ed --- /dev/null +++ b/board/st/nhk8815/nhk8815-devices.h @@ -0,0 +1,7 @@ +#ifndef __NHK8815_DEVICES__ +#define __NHK8815_DEVICES__ + +/* Prototypes for functions exported by device files in this directory */ +extern int nhk8815_keypad_init(void); /* ./keypad.c */ + +#endif /* __NHK8815_DEVICES__ */ diff --git a/board/st/nhk8815/nhk8815.c b/board/st/nhk8815/nhk8815.c index eadce40..fbabd15 100644 --- a/board/st/nhk8815/nhk8815.c +++ b/board/st/nhk8815/nhk8815.c @@ -29,6 +29,7 @@ #include #include #include +#include "nhk8815-devices.h" DECLARE_GLOBAL_DATA_PTR; @@ -109,6 +110,9 @@ int board_eth_init(bd_t *bis) /* Initialization callback, from lib_arm/board.c */ int board_late_init(void) { +#ifdef CONFIG_NHK8815_KEYPAD + nhk8815_keypad_init(); +#endif return 0; } diff --git a/include/configs/nhk8815.h b/include/configs/nhk8815.h index fcb1b20..5eb3cbc 100644 --- a/include/configs/nhk8815.h +++ b/include/configs/nhk8815.h @@ -130,6 +130,9 @@ #define STMPE0 0x43 #define STMPE1 0x44 +/* Keypad using stmpe2401 */ +#define CONFIG_NHK8815_KEYPAD + /* Ethernet */ #define PCI_MEMORY_VADDR 0xe8000000 #define PCI_IO_VADDR 0xee000000