Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4624167pxj; Wed, 12 May 2021 09:28:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVsPxYRng/+ksRTdjxmnx/u7goNrtaIPXr5U16ZN50C8Ajqi2DM2PIxOOtd65q2BtYm7rX X-Received: by 2002:a17:906:b5b:: with SMTP id v27mr38531795ejg.40.1620836923940; Wed, 12 May 2021 09:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836923; cv=none; d=google.com; s=arc-20160816; b=Gg6Bv95okZmm2ltXVcVxerXecZkw1S8lMYgl/lfazJG0kU7PhYRT2Dk7VlFN7SiLL4 ANjToEy8l021oR1PsNiqEHFsLCm9OQ9cTWSGCxJyDwogtVY1w0tF5ZV3LkDgDGqe+sYW 9QiI8+dpEUInh2mRQOZn6mpEGgJkJORL7pV9kP19FMDmz6ddosa69hlXDsstRtd3x9DL pwr6+sor17RuPyumXUzuHSPhIPQtEv27VXon+evEtYVMZjUUxH2Xoy+Hf9loNBCs5saf E0+crRtwyYgFxAlbJsag8M2mRgRn22w+z2Yn1ynSqKDPfRHBGx2hV4ZdSluoaqiAUBJm pKAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C9M9ft/1rYFjL5Kt6lXTzC1yNTURGboAqiQKQGQ/e9M=; b=uvKEXONLGcnovufOuMczDO5usI++dHbdopmpbav95o/Yy2r8l4j71ew5wL4Hhf5eaC IAKC6bDNC53eS8/qOGHIWP6OK03hj7qJ1BBvLO7p8qT/1VFElNhBmaH30hst9SxmNLZj PZ/XkJa3hM0ACCeNyo8dv9dNFBueeb9YtwYeVriRoHAoOksztxZ4xRwu6yJiNfJij2EP tGn9I8OVIGYpzmZ6aWdLkmBzZnnDXvf8I5YZ3nC2wVtaaXr7ZjlYvtISHmX8qE1A9KnH 1gZKbcGJbp5q8g0Rni36bgYRKnOql+YaVRuGesh0BKk4hAIyaqvYzcwDwJ0/Iwg0gMZv SXkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A24NHkhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si101384edr.479.2021.05.12.09.28.19; Wed, 12 May 2021 09:28:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A24NHkhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237123AbhELQYR (ORCPT + 99 others); Wed, 12 May 2021 12:24:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:57044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236210AbhELPhU (ORCPT ); Wed, 12 May 2021 11:37:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 071FF61C50; Wed, 12 May 2021 15:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832722; bh=eAikVfT7g1iI26ky+W7FRy9jZDn+90ZjTe7RKbYCq3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A24NHkhjx1Cy8t7HFhpuB//gU6siXbYnzVoqfNF/D3I/7BP5MymbDeiZSB6rBr639 mvPp5JJm4jWLOag3lgs5r4WOtC+8rnHihk+Zc5+xTTTeOvBvSjylZ2swjawIoZhg5j TsZgmPca+kfUa2XJqNaOHD6WcJHRlXpQRgL5H5aY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hanna Hawa , Andy Shevchenko , Tony Lindgren , Drew Fustini , Linus Walleij , Sasha Levin Subject: [PATCH 5.10 369/530] pinctrl: pinctrl-single: fix pcs_pin_dbg_show() when bits_per_mux is not zero Date: Wed, 12 May 2021 16:47:59 +0200 Message-Id: <20210512144831.911811816@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hanna Hawa [ Upstream commit bd85125ea88513f637a62a72e8949c579c5c0a87 ] A System Error (SError, followed by kernel panic) 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 is not zero. In addition move offset calculation and pin offset in register to common function. Fixes: 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure multiple pins of different modules") Signed-off-by: Hanna Hawa Reviewed-by: Andy Shevchenko Reviewed-by: Tony Lindgren Reviewed-by: Drew Fustini Link: https://lore.kernel.org/r/20210319152133.28705-4-hhhawa@amazon.com Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/pinctrl-single.c | 55 ++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 539543898c89..12cc4eb18637 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -270,20 +270,44 @@ 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 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; + return (pin_offset_bytes / mux_bytes) * mux_bytes; + } + + return pin * mux_bytes; +} + +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; + offset = pcs_pin_reg_offset_get(pcs, pin); val = pcs->read(pcs->base + offset); + + if (pcs->bits_per_mux) + val &= pcs->fmask << pcs_pin_shift_reg_get(pcs, pin); + pa = pcs->res->start + offset; seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME); @@ -384,7 +408,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 +415,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; } @@ -726,14 +747,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); -- 2.30.2