From patchwork Mon Jun 2 08:46:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanjay Singh Rawat X-Patchwork-Id: 31262 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 67FEF203C2 for ; Mon, 2 Jun 2014 08:46:55 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id uo5sf18652177pbc.0 for ; Mon, 02 Jun 2014 01:46:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=/T+FMu9E01XVm8B6edjs+6LfXhtVz4kYvxingCkfecA=; b=UysbirnG827d8EXEMHqcgVG2F3gb7rbNAsdJCWc3WeVP4/O+CZjETsz93FrDJY4D5S 613veNe5GTonypOZYp1yoN/1NNGF17hmUR5vyhI/XRmehXi+092eh3SWov8ZhaHYYdOL Osj2Tiqn7UnevwpIzsYTqQox7oKAfL3DIONJ2Gw1MUWYWeg8qgKqlMww0N3eXxmF+fgU D0dypsf4cDVWWTB9vxTrnLOCLQkjJFN5ucZHbxJ68Aahcqet9Y1aV6AzbUPF3p3FBF7Y DpohbgmsUurew9NLO17tbZbJ8a3yDSgvh8RrAHohTfdkEyJkde7CU4TXAFBlFmI9JSV3 d9wA== X-Gm-Message-State: ALoCoQkzl36pMYNVVRYSK6FHIf2p50RSQ/NutWn/1gRSyBFZfSh0sTJoTR1lCNXgmDUOzIDsyzeh X-Received: by 10.66.137.2 with SMTP id qe2mr5984241pab.43.1401698814897; Mon, 02 Jun 2014 01:46:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.234 with SMTP id a97ls1826538qgf.51.gmail; Mon, 02 Jun 2014 01:46:54 -0700 (PDT) X-Received: by 10.220.163.3 with SMTP id y3mr29002502vcx.7.1401698814790; Mon, 02 Jun 2014 01:46:54 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id ht8si7544762vdb.61.2014.06.02.01.46.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 01:46:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db11so4790591veb.36 for ; Mon, 02 Jun 2014 01:46:54 -0700 (PDT) X-Received: by 10.52.164.237 with SMTP id yt13mr24669990vdb.18.1401698814633; Mon, 02 Jun 2014 01:46:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp81523vcb; Mon, 2 Jun 2014 01:46:54 -0700 (PDT) X-Received: by 10.68.132.42 with SMTP id or10mr38791176pbb.80.1401698813931; Mon, 02 Jun 2014 01:46:53 -0700 (PDT) Received: from mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45]) by mx.google.com with ESMTPS id vu1si4327121pbc.156.2014.06.02.01.46.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 01:46:53 -0700 (PDT) Received-SPF: pass (google.com: domain of sanjay.rawat@linaro.org designates 209.85.160.45 as permitted sender) client-ip=209.85.160.45; Received: by mail-pb0-f45.google.com with SMTP id um1so3993181pbc.4 for ; Mon, 02 Jun 2014 01:46:53 -0700 (PDT) X-Received: by 10.66.139.73 with SMTP id qw9mr38593633pab.123.1401698813501; Mon, 02 Jun 2014 01:46:53 -0700 (PDT) Received: from srawat-Latitude-E6420.LGE.NET ([203.247.149.152]) by mx.google.com with ESMTPSA id gg3sm19269218pbc.34.2014.06.02.01.46.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Jun 2014 01:46:53 -0700 (PDT) From: Sanjay Singh Rawat To: linaro-dev@lists.linaro.org Cc: Sanjay Singh Rawat Subject: [PATCH POWERDEBUG] gpio: expose free gpios to user Date: Mon, 2 Jun 2014 14:16:48 +0530 Message-Id: <1401698808-31421-1-git-send-email-sanjay.rawat@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sanjay.rawat@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , - GPIOs in the SoC will be free/used state, this patch make free gpios accessible to the user by exporting them. - bug 1229658 Signed-off-by: Sanjay Singh Rawat --- gpio.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/gpio.c b/gpio.c index 4a42cb7..39480b0 100644 --- a/gpio.c +++ b/gpio.c @@ -320,10 +320,10 @@ static struct display_ops gpio_ops = { .change = gpio_change, }; -void export_gpios(void) +void export_free_gpios(void) { FILE *fgpio, *fgpio_export; - int gpio[256], num = 0; + int i, gpio_max = 0; char *line = NULL; ssize_t read, len; @@ -340,15 +340,18 @@ void export_gpios(void) } /* export the gpios */ - while (read = getline(&line, &len, fgpio) != -1) { - char *str; - - if (strstr(line, "gpio-")) { - str = strtok(line, " "); - sscanf(str, "gpio-%d", &gpio[num]); - fprintf(fgpio_export, "%d", gpio[num]); - num++; - } + while ((read = getline(&line, &len, fgpio)) != -1) { + if (strstr(line, "GPIOs")) + sscanf(line, "%*[^-]-%d%*", &gpio_max); + } + + printf("log: total gpios = %d\n", gpio_max); + for (i = 0 ; i <= gpio_max ; i++) { + char command[50] = ""; + + sprintf(command, "echo %d > /sys/class/gpio/export", i); + if (system(command) < 0) + printf("error: failed to export gpio-%d\n", i); } out: return; @@ -368,7 +371,7 @@ int gpio_init(void) if (access(SYSFS_GPIO, F_OK)) gpio_error = true; /* set the flag */ - export_gpios(); + export_free_gpios(); gpio_tree = tree_load(SYSFS_GPIO, gpio_filter_cb, false); if (!gpio_tree)