From patchwork Wed Jun 17 01:56:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 49965 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3EB2F228F8 for ; Wed, 17 Jun 2015 01:56:54 +0000 (UTC) Received: by wgfj7 with SMTP id j7sf5572302wgf.1 for ; Tue, 16 Jun 2015 18:56:53 -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=YW+Hw9SSGR2qP/VUCJRNddewlJWOAO9GGLZp0ZcTaSZycROWWbhmZ0pL/6FRQmG+rp 91V6nZzcrxUYbJwWwNEx+PoAXFe1LsCD3IeSsWNNOX9tXF26VNtHQhYBNKOqRknbFjY7 rFuRh3EnE/AX8+xy844D+0NtRV4fFt1hdq3VMsL2XvBSa9X0Z2Vk4hXD6g+JHA2y85gd oYHxo6Ly9yaGIA/gYQqq+REhJ4lfb4kNBWz0re6JsFBSNIMlkvS1ZO2umbV96wpiUkiw a7oaqmAYM9oEJ2NKTS84aaMrRqmNKJHQjoz53PqD6QmMPc//man0/Wmz9IxSkC42zmIw fq4w== X-Gm-Message-State: ALoCoQl8s+4z52oMW4yrThj9ogdmhk/zNAWsYZRmLsJixYYT76HoNIq6tBkAfZVlRCHpnOoSS7y9 X-Received: by 10.194.236.230 with SMTP id ux6mr546190wjc.5.1434506213569; Tue, 16 Jun 2015 18:56:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.133 with SMTP id kq5ls222971lac.102.gmail; Tue, 16 Jun 2015 18:56:53 -0700 (PDT) X-Received: by 10.152.37.37 with SMTP id v5mr5095023laj.11.1434506213411; Tue, 16 Jun 2015 18:56:53 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id i6si2127909laa.144.2015.06.16.18.56.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jun 2015 18:56:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbwc1 with SMTP id wc1so22066558lbb.2 for ; Tue, 16 Jun 2015 18:56:53 -0700 (PDT) X-Received: by 10.112.219.37 with SMTP id pl5mr1335428lbc.35.1434506213211; Tue, 16 Jun 2015 18:56:53 -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 hn6csp128184lbb; Tue, 16 Jun 2015 18:56:52 -0700 (PDT) X-Received: by 10.70.48.141 with SMTP id l13mr5774944pdn.101.1434506211361; Tue, 16 Jun 2015 18:56:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nn5si3826995pbc.21.2015.06.16.18.56.50; Tue, 16 Jun 2015 18:56:51 -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 S1754262AbbFQB4t (ORCPT + 2 others); Tue, 16 Jun 2015 21:56:49 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:32997 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752529AbbFQB4t (ORCPT ); Tue, 16 Jun 2015 21:56:49 -0400 Received: by padev16 with SMTP id ev16so23740835pad.0 for ; Tue, 16 Jun 2015 18:56:48 -0700 (PDT) X-Received: by 10.66.229.65 with SMTP id so1mr5913301pac.92.1434506208729; Tue, 16 Jun 2015 18:56:48 -0700 (PDT) Received: from localhost.localdomain ([107.6.117.179]) by mx.google.com with ESMTPSA id v9sm2693421pdr.96.2015.06.16.18.56.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Jun 2015 18:56:47 -0700 (PDT) From: Jun Nie To: tony@atomide.com, haojian.zhuang@linaro.org, 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: Wed, 17 Jun 2015 09:56:12 +0800 Message-Id: <1434506172-4401-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.170 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 Reviewed-by: Haojian Zhuang --- 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;