Received: by 10.223.185.116 with SMTP id b49csp3123386wrg; Mon, 5 Mar 2018 14:40:47 -0800 (PST) X-Google-Smtp-Source: AG47ELuHIcnE6DCMQ6zjC9bDczrzNAsso//ujobA0+IQ/W1u22j6doF2SNvWQaBnuU8CGfA452cq X-Received: by 2002:a17:902:aa5:: with SMTP id 34-v6mr14761459plp.429.1520289647122; Mon, 05 Mar 2018 14:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520289647; cv=none; d=google.com; s=arc-20160816; b=iezUM37zJ1vBcgzoIsTrgLvtiLfq5fcCTKUVVzRa+kE/GoMPCsRJsSmHKpxyBPtVg9 365jvoANzV9Dmv7f85xgP4rf+NKX0K5EKBwiNJvPBpLuR1sjkq4s+LzBQ6uE6s+URkrc 6wm/rgq1q2lrX+PB7v50eb7xP6NXtTDjRMF0WaFgXTOsGEHGEy+WOgdCUTsQJRznMnB9 eGlr/KK7Ua/TWnbfrtcDtz8Je90xFvfEKmdqktRwgoHLJRWN87eQF2KZaboKdao2BCWV K7szLspJjkUNCCco6//j+ioP/1h1cuCqZ3rBtGjqK+COAHE+SqleYBfihE0yZ+8JQT5n YNsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=/HLAsu+A7dBidrrBRcOyUNWthdAz2nCAhqUXsXh9M94=; b=z0w/MzD52LG+MkQ3u9sUcr3CmIo1/hBjJxf1yY9BxM7Ycq6xVlAzJwexGFPzD63Rvi fIGXEaAYmyatx4XuAeIAK96h8gECFIaMLFI+tGismA4DhwFu8zlBLtxLqVFLa7OBqvXS GyxdT477TbnqkjBEY7XtOqQGLEXGj5HJOKky/mXwRkemJjXQpbKTYB29LBvHPNcludKt Mq4o7Jv+KH/ifYgRp9m+8m04OZ+jP4k/PxAjC4pOjfeDdRmKgqJs66CdACpvA24Gu5Ba 5C0/BrlxrHgI5SfG/LOwLO3GbQckatHEc70ptoMslu47HpQXvlMoXoc3PESRRY3OvxEG 0j/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=KeRGjAGS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si9825308plz.300.2018.03.05.14.40.32; Mon, 05 Mar 2018 14:40:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=KeRGjAGS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932634AbeCEWjb (ORCPT + 99 others); Mon, 5 Mar 2018 17:39:31 -0500 Received: from vern.gendns.com ([206.190.152.46]:42540 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932069AbeCEWj2 (ORCPT ); Mon, 5 Mar 2018 17:39:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/HLAsu+A7dBidrrBRcOyUNWthdAz2nCAhqUXsXh9M94=; b=KeRGjAGS2TmbjzefsTccz9RusP 3OJlpUFV+8yGSq11J69ekQ4ibB5ubBZKolWyau248NVBcxI3UREJbyXvnyQeboMZQU3dwSSNsopeB OTKPOuyl4M76V9ZrCDeB/ILDcqEi2alP80x16nWzp/pmge2oyGaR1h6ckaEUcAAMuCPqFWbc6/zdn Bf5Zex0dA5LvHPFR7CgslqBFL/SUEsvjUEdUnmuj2fK78QIQa/0sU13fb4KSj82oWZ7OvXHIL0h7J +L83UD+2sS+Axtd+HOGXAcqu5mnVJpHFgpAvhNd+XJ4afMII9n1m/tpd3e0CskwFO9tDlCJZPfowC 7pItzMSA==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:52754 helo=[192.168.0.134]) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1esyjo-003YPf-Tk; Mon, 05 Mar 2018 17:37:45 -0500 Subject: Re: [PATCH v2] pinctrl: pinctrl-single: Fix pcs_request_gpio() when bits_per_mux != 0 To: Andy Shevchenko Cc: linux-arm Mailing List , Linux OMAP Mailing List , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Tony Lindgren , Haojian Zhuang , Linus Walleij References: <1519077427-30165-1-git-send-email-david@lechnology.com> From: David Lechner Message-ID: <6f8d2656-476c-81b6-6109-b26b98f15d31@lechnology.com> Date: Mon, 5 Mar 2018 16:39:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/20/2018 06:56 AM, Andy Shevchenko wrote: > On Mon, Feb 19, 2018 at 11:57 PM, David Lechner wrote: >> This fixes pcs_request_gpio() in the pinctrl-single driver when >> bits_per_mux != 0. It appears this was overlooked when the multiple >> pins per register feature was added. >> >> Fixes: 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure multiple pins of different modules") >> Signed-off-by: David Lechner >> --- >> >> v2 changes: >> - don't wrap Fixes: line in commit message since it is a special machine- >> readable line. >> >> There was some discussion in v1 about using DIV_ROUND_UP(), etc. macros, but >> the consensus was to leave it as-is since it matches existing code and that >> macros can be introduced in another patch. >> >> drivers/pinctrl/pinctrl-single.c | 22 +++++++++++++++++++--- >> 1 file changed, 19 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c >> index cec7537..a7c5eb3 100644 >> --- a/drivers/pinctrl/pinctrl-single.c >> +++ b/drivers/pinctrl/pinctrl-single.c >> @@ -391,9 +391,25 @@ 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 byte_num, offset, pin_shift; >> + >> + byte_num = (pcs->bits_per_pin * pin) / BITS_PER_BYTE; >> + offset = (byte_num / mux_bytes) * mux_bytes; >> + pin_shift = pin % (pcs->width / pcs->bits_per_pin) * >> + pcs->bits_per_pin; >> + >> + data = pcs->read(pcs->base + offset); >> + data &= ~(pcs->fmask << pin_shift); >> + data |= frange->gpiofunc << pin_shift; >> + pcs->write(data, pcs->base + offset); >> + } else { > >> + data = pcs->read(pcs->base + pin * mux_bytes); >> + data &= ~pcs->fmask; >> + data |= frange->gpiofunc; >> + pcs->write(data, pcs->base + pin * mux_bytes); > > Just an idea, you may leave this almost untouched and do calculate > pin_shift and offset in condition, like > > if (...) { > pin_shift = ... > offset = ... > } else { > pin_shift = 0; > offset = pin * mux_bytes; > } > > data = pcs->read(pcs->base + offset); > data &= ~(pcs->fmask << pin_shift); > data |= frange->gpiofunc << pin_shift; > pcs->write(data, pcs->base + offset); > > It's also possible to split to two changes, where first introduces > that variables and their default values (see 'else' branch) and second > one introduces an if branch override. > >> + } >> break; > Yes, there are many ways this could be done. However, I would like to just leave it as it is since it matches the patterns used elsewhere in this file.