From patchwork Fri Jun 12 08:19:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 49816 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 902C620C81 for ; Fri, 12 Jun 2015 08:20:22 +0000 (UTC) Received: by wizw5 with SMTP id w5sf2876413wiz.2 for ; Fri, 12 Jun 2015 01:20:21 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=akA6DGs9gPOT1RvNVVaU0Z4vknlLEiTq4PRtu22IT18=; b=fApri0QqQlpJoFuqgDQGjecCrsnE+f+qBUohSxW4tlbxwrkNA2eDOrPESNMjOpprYR 6zPE8PcVhlk1s+vuQ49LiTpdALqAE4vlBXejkzCXyM4/ZAr1JS4Ldm/TQDg0uYFq+M0q HJKhUCwgqgPpVgDYAidqytiXSZzf1uBovHO6vsjlsLXZe5bx91fmGxuDiMJCm8us0Wla SEEVGq9SvXscxFcPtjSSjnhaAh4kORejJwfb05eXE3yC5VlDonPwElme8Yz75b/MNn9x QrI7vSuJmVqxH15n9rw1D5/9P5YGKxthXR8OPQOXW9g2xxNHOmhkaGzzMefQZHPbK/SC sGPQ== X-Gm-Message-State: ALoCoQnjMWSy4Ey0hh0c+uCyaNUtVaqgSQlS6N1yjWyyXFcBe/+50h6WN72FM7TI4nubiLZ0Uj6C X-Received: by 10.194.5.229 with SMTP id v5mr13141262wjv.0.1434097221886; Fri, 12 Jun 2015 01:20:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.163.65 with SMTP id yg1ls485320lab.26.gmail; Fri, 12 Jun 2015 01:20:21 -0700 (PDT) X-Received: by 10.112.48.68 with SMTP id j4mr13750794lbn.60.1434097221727; Fri, 12 Jun 2015 01:20:21 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id t7si2781509lat.105.2015.06.12.01.20.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 01:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbcue7 with SMTP id ue7so15788431lbc.0 for ; Fri, 12 Jun 2015 01:20:21 -0700 (PDT) X-Received: by 10.112.182.4 with SMTP id ea4mr14197347lbc.35.1434097221273; Fri, 12 Jun 2015 01:20:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp372464lbb; Fri, 12 Jun 2015 01:20:20 -0700 (PDT) X-Received: by 10.70.43.225 with SMTP id z1mr21163402pdl.45.1434097219562; Fri, 12 Jun 2015 01:20:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ek10si4329457pdb.228.2015.06.12.01.20.18; Fri, 12 Jun 2015 01:20:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751170AbbFLIUR (ORCPT + 2 others); Fri, 12 Jun 2015 04:20:17 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:33207 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbbFLIUN (ORCPT ); Fri, 12 Jun 2015 04:20:13 -0400 Received: by pdjn11 with SMTP id n11so20194024pdj.0 for ; Fri, 12 Jun 2015 01:20:13 -0700 (PDT) X-Received: by 10.66.157.71 with SMTP id wk7mr21080066pab.99.1434097213166; Fri, 12 Jun 2015 01:20:13 -0700 (PDT) Received: from localhost.localdomain ([107.6.117.179]) by mx.google.com with ESMTPSA id ld1sm2830591pbc.26.2015.06.12.01.20.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 01:20:11 -0700 (PDT) From: Jun Nie To: linus.walleij@linaro.org, linux-gpio@vger.kernel.org Cc: shawn.guo@linaro.org, wan.zhijun@zte.com.cn, jason.liu@linaro.org, Jun Nie Subject: [PATCH] pinctrl: single: support GPIO for bits pinctrl Date: Fri, 12 Jun 2015 16:19:45 +0800 Message-Id: <1434097185-16464-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-gpio-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-gpio@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: jun.nie@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.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Support GPIO for one register control multiple pins case with calculating register offset first, then bit offset. Signed-off-by: Jun Nie --- drivers/pinctrl/pinctrl-single.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 13b45f2..bd69d9a 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -494,7 +494,7 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev, struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); struct pcs_gpiofunc_range *frange = NULL; struct list_head *pos, *tmp; - int mux_bytes = 0; + int offset, mux_bytes = 0; unsigned data; /* If function mask is null, return directly. */ @@ -507,9 +507,23 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev, || pin < frange->offset) continue; mux_bytes = pcs->width / BITS_PER_BYTE; - data = pcs->read(pcs->base + pin * mux_bytes) & ~pcs->fmask; - data |= frange->gpiofunc; - pcs->write(data, pcs->base + pin * mux_bytes); + if (pcs->bits_per_mux) { + int pin_pos, byte_num, num_pins_in_register; + + num_pins_in_register = pcs->width / pcs->bits_per_pin; + byte_num = (pcs->bits_per_pin * pin) / BITS_PER_BYTE; + offset = (byte_num / mux_bytes) * mux_bytes; + pin_pos = pin % num_pins_in_register; + pin_pos *= pcs->bits_per_pin; + data = pcs->read(pcs->base + offset) & + ~(pcs->fmask << pin_pos); + data |= frange->gpiofunc << pin_pos; + } else { + offset = pin * mux_bytes; + data = pcs->read(pcs->base + offset) & ~pcs->fmask; + data |= frange->gpiofunc; + } + pcs->write(data, pcs->base + offset); break; } return 0;