From patchwork Tue Mar 16 20:24:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hawa, Hanna" X-Patchwork-Id: 12143841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9782C433E0 for ; Tue, 16 Mar 2021 20:27:17 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6322B64EED for ; Tue, 16 Mar 2021 20:27:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6322B64EED Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9+L+0dUT3CPXRv4hu9nL06zIZpjXzH+61R2u5MQZTSY=; b=D6Wbq3lRKwMbf0oGGF7O1e68L Q+n/iCukSd9o6XJagGd2Ys7njOVF7yZoEUaIzV6yXPQgLLpJkUCRu7Xv9u7Zv9PF3nwWdItKHGhRM epvLRinNBevMpGnw0RhobfoULC+qyD7lOVg1s46cnJREZNVCi/K4FxfBJX/5bwaa94X+cUAcqkBPL qV4zJFT6b6Qj7JFScYvrcCiogXykGp1Q3CCtqdB8Ox+jyqJ7jdu4fTEliGoAyVKgJ12lEO4eRC70V ByPEiK7DLL6vHOjl/pZuUW3+bKjZkSR1ShdyV+gJQ2v6C6laozkDSJ4YkHjUE9xWzbv7vA1DLCF8b 6T2YCV0sw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lMGGB-001nZ8-UC; Tue, 16 Mar 2021 20:25:48 +0000 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lMGFn-001nUC-D2 for linux-arm-kernel@lists.infradead.org; Tue, 16 Mar 2021 20:25:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1615926324; x=1647462324; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=xPHHLCf7ZvBUG+y5LNfWWLREmAHRu22m1USDWCJuPBU=; b=NaQ40W9/stOPVdgD2Ny/rSWSasSEoStEMiZp5hMj7jWGhWo+zuA8V0zI QgfLFdGOm9rLeT9ABltumdtojxLhCh1kb8nbswDvfkq9Mo6fl7HXuJeNR hMcQWGZcEkKc/WOxorGLIqgtrjhERksAbE3Om+uY16w8ulK3o/kDR3CSX M=; X-IronPort-AV: E=Sophos;i="5.81,254,1610409600"; d="scan'208";a="99356089" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-53356bf6.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 16 Mar 2021 20:25:16 +0000 Received: from EX13D19EUB003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2a-53356bf6.us-west-2.amazon.com (Postfix) with ESMTPS id 1BB2AA1C59; Tue, 16 Mar 2021 20:25:15 +0000 (UTC) Received: from u8a88181e7b2355.ant.amazon.com (10.43.160.48) by EX13D19EUB003.ant.amazon.com (10.43.166.69) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 16 Mar 2021 20:25:08 +0000 From: Hanna Hawa To: , , CC: , , , , , , , , , , , Subject: [PATCH v2 3/3] pinctrl: pinctrl-single: fix pcs_pin_dbg_show() when bits_per_mux != 0 Date: Tue, 16 Mar 2021 22:24:34 +0200 Message-ID: <20210316202434.27555-4-hhhawa@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210316202434.27555-1-hhhawa@amazon.com> References: <20210316202434.27555-1-hhhawa@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.160.48] X-ClientProxiedBy: EX13D02UWB003.ant.amazon.com (10.43.161.48) To EX13D19EUB003.ant.amazon.com (10.43.166.69) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210316_202523_906863_C32A2776 X-CRM114-Status: GOOD ( 18.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org An SError was detected when trying to print the supported pins in a pinctrl device which supports multiple pins per register. This change fixes the pcs_pin_dbg_show() in pinctrl-single driver when bits_per_mux != 0. In addition move offset calculation and pin offset in register to common function. Signed-off-by: Hanna Hawa --- drivers/pinctrl/pinctrl-single.c | 66 ++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index f3394517cb2e..434f90c8b1b3 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -270,20 +270,53 @@ static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) writel(val, reg); } +static unsigned int pcs_pin_reg_offset_get(struct pcs_device *pcs, + unsigned int pin) +{ + unsigned int offset, mux_bytes; + + mux_bytes = pcs->width / BITS_PER_BYTE; + + if (pcs->bits_per_mux) { + unsigned int pin_offset_bytes; + + pin_offset_bytes = (pcs->bits_per_pin * pin) / BITS_PER_BYTE; + offset = (pin_offset_bytes / mux_bytes) * mux_bytes; + } else { + offset = pin * mux_bytes; + } + + return offset; +} + +static unsigned int pcs_pin_shift_reg_get(struct pcs_device *pcs, + unsigned int pin) +{ + return ((pin % (pcs->width / pcs->bits_per_pin)) * pcs->bits_per_pin); +} + static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, unsigned pin) { struct pcs_device *pcs; - unsigned val, mux_bytes; + unsigned int val; unsigned long offset; size_t pa; pcs = pinctrl_dev_get_drvdata(pctldev); - mux_bytes = pcs->width / BITS_PER_BYTE; - offset = pin * mux_bytes; - val = pcs->read(pcs->base + offset); + offset = pcs_pin_reg_offset_get(pcs, pin); + + if (pcs->bits_per_mux) { + unsigned int pin_shift_in_reg = pcs_pin_shift_reg_get(pcs, pin); + + val = pcs->read(pcs->base + offset) + & (pcs->fmask << pin_shift_in_reg); + } else { + val = pcs->read(pcs->base + offset); + } + pa = pcs->res->start + offset; seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME); @@ -384,7 +417,6 @@ 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; unsigned data; /* If function mask is null, return directly. */ @@ -392,29 +424,27 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev, return -ENOTSUPP; list_for_each_safe(pos, tmp, &pcs->gpiofuncs) { + u32 offset; + frange = list_entry(pos, struct pcs_gpiofunc_range, node); if (pin >= frange->offset + frange->npins || pin < frange->offset) continue; - mux_bytes = pcs->width / BITS_PER_BYTE; - if (pcs->bits_per_mux) { - int byte_num, offset, pin_shift; + offset = pcs_pin_reg_offset_get(pcs, pin); - 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; + if (pcs->bits_per_mux) { + int pin_shift = pcs_pin_shift_reg_get(pcs, 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->read(pcs->base + offset); data &= ~pcs->fmask; data |= frange->gpiofunc; - pcs->write(data, pcs->base + pin * mux_bytes); + pcs->write(data, pcs->base + offset); } break; } @@ -724,14 +754,8 @@ static int pcs_allocate_pin_table(struct pcs_device *pcs) for (i = 0; i < pcs->desc.npins; i++) { unsigned offset; int res; - int byte_num; - if (pcs->bits_per_mux) { - byte_num = (pcs->bits_per_pin * i) / BITS_PER_BYTE; - offset = (byte_num / mux_bytes) * mux_bytes; - } else { - offset = i * mux_bytes; - } + offset = pcs_pin_reg_offset_get(pcs, i); res = pcs_add_pin(pcs, offset); if (res < 0) { dev_err(pcs->dev, "error adding pins: %i\n", res);