Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp105465ybv; Tue, 18 Feb 2020 18:50:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxTYKXpNAi68Eb8hgrFJulozKHiJwRdZ8G9nAhRngybGUFju8n6ibk6Cij1y4NCCZ+ThNuR X-Received: by 2002:aca:c692:: with SMTP id w140mr3489780oif.139.1582080639106; Tue, 18 Feb 2020 18:50:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582080639; cv=none; d=google.com; s=arc-20160816; b=Wr9Vn1yX/MnB0sxqWScgqBnZhV1B/KgnLeXVOGlEilmejsncdaHvGNeNEYKfr3rf1k /biBE7imWMmoSs4+nazy8c6N5K0YeN2V+TkmDbYV7Qr2mtWu9o8YA6CH7nftBA2uz+JQ UPBwW+57svhE5RG0oheqsQiGZmAVDmXP8OjN4IbBCH6BQhIr7thkJAbw0BDOmPhs+fAM XKduqXuyAMQV05u6KaOF4NIcWF7/hw0diw+2iP3wv6bpBUUkmh1nldzJgWcc5iri2lzx K7r3UXT1W3hP/5jxN4lliL0LmclfGi2rL/yiyMiZ6c6ZveRdUbGkMN/6l9u/AJAoCaUC Fj6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=3YO1Y1VDHcP44ZD0tS0W7OVzzWFpRpsczECwzMV+qhw=; b=eejlO4roYSYkMxINrNj0rwJ7j5Kz1Uk3ShJAMir0SQj9AJyF+YbBbpZ0SnmzkLSyLn E9TITGNocO5icEVHK9/phcP4/XsMXH+V5LLciW6IjeMOyCSCCJfcYX+BZjCHAElbuB8c svMndaWHnn00OqA5tN5U8N5A/G5QgB+wuw+q9vyTDiOd/GwwjysSNTg5NZmmLCekBZte cd6l3SWbRhZ5I8/yxJXTxS51vX4V+r2KeyVzXUqMRRuhorzlTDXT9NZdmOsSTC/kiGls iFrOJkUa7SnYorDn0npvgE2tLLC9Ql84+nnG0KG0HhiAogKuswiE4kthUNt8Foi02k+j nRAw== ARC-Authentication-Results: i=1; mx.google.com; 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 f14si393784oto.46.2020.02.18.18.50.27; Tue, 18 Feb 2020 18:50:39 -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; 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 S1728273AbgBSCte (ORCPT + 99 others); Tue, 18 Feb 2020 21:49:34 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:33001 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728027AbgBSCtd (ORCPT ); Tue, 18 Feb 2020 21:49:33 -0500 Received: by mail-ed1-f67.google.com with SMTP id r21so27341866edq.0 for ; Tue, 18 Feb 2020 18:49:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3YO1Y1VDHcP44ZD0tS0W7OVzzWFpRpsczECwzMV+qhw=; b=CrBOaYK+8ZFUbKAjS+HBKCOj9fgPjewapiaTXGOH9d/STNXon++xluzfqNnhY4BxQe PsZz3lmyrz0PBV8wmwpPgvQDg1M/YS7Jx6KH3i3kKVGXKd58Gf6vbnO4I/UdNpXzihjL av0eoo5+nxADlidddr7cb/wFMKp4eX7TL3HKa+jbM5AxXCE8BQQNCBL/d35+bhqlX2x2 eKAjIfWLc/nUmGZ0K74dBTKL0YQ8DZUSOPKpbT3wvyvfDwG60LRuEETnb26GNQ7j+KjI SJMyEvYVnGhIM2VzcCG2z+0dLAerB2lGZ58fjQQiGW2J0WhMd06knY4DhkQYlPGHxwqL nBcg== X-Gm-Message-State: APjAAAWMyiiIlEhgDOZebXm6eBCUhOcMjTtW8yfNe58BWxbwEDGIJ5E7 B6NCKJGISL1QjX5K2kcSjhnzi7pzucA= X-Received: by 2002:a17:906:f14e:: with SMTP id gw14mr834201ejb.217.1582080571088; Tue, 18 Feb 2020 18:49:31 -0800 (PST) Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com. [209.85.221.51]) by smtp.gmail.com with ESMTPSA id d8sm24849edn.52.2020.02.18.18.49.30 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Feb 2020 18:49:30 -0800 (PST) Received: by mail-wr1-f51.google.com with SMTP id y11so26363948wrt.6 for ; Tue, 18 Feb 2020 18:49:30 -0800 (PST) X-Received: by 2002:a5d:640d:: with SMTP id z13mr31363099wru.181.1582080570098; Tue, 18 Feb 2020 18:49:30 -0800 (PST) MIME-Version: 1.0 References: <20200219010951.395599-1-megous@megous.com> In-Reply-To: <20200219010951.395599-1-megous@megous.com> From: Chen-Yu Tsai Date: Wed, 19 Feb 2020 10:49:18 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] bus: sunxi-rsb: Return correct data when mixing 16-bit and 8-bit reads To: Ondrej Jirman Cc: linux-sunxi , Maxime Ripard , Samuel Holland , Stephen Boyd , "moderated list:ARM/Allwinner sunXi SoC support" , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 9:10 AM Ondrej Jirman wrote: > > When doing a 16-bit read that returns data in the MSB byte, the > RSB_DATA register will keep the MSB byte unchanged when doing > the following 8-bit read. sunxi_rsb_read() will then return > a result that contains high byte from 16-bit read mixed with > the 8-bit result. > > The consequence is that after this happens the PMIC's regmap will > look like this: (0x33 is the high byte from the 16-bit read) > > % cat /sys/kernel/debug/regmap/sunxi-rsb-3a3/registers > 00: 33 > 01: 33 > 02: 33 > 03: 33 > 04: 33 > 05: 33 > 06: 33 > 07: 33 > 08: 33 > 09: 33 > 0a: 33 > 0b: 33 > 0c: 33 > 0d: 33 > 0e: 33 > [snip] > > Fix this by masking the result of the read with the correct mask > based on the size of the read. There are no 16-bit users in the > mainline kernel, so this doesn't need to get into the stable tree. > > Signed-off-by: Ondrej Jirman Acked-by: Chen-Yu Tsai for the fix, however it's not entirely clear to me how the MSB 0x33 value got into the regmap. Looks like I expected the regmap core to handle any overflows, or didn't expect the lingering MSB from 16-bit reads, as I didn't have any 16-bit register devices back when I wrote this. ChenYu > --- > drivers/bus/sunxi-rsb.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/bus/sunxi-rsb.c b/drivers/bus/sunxi-rsb.c > index b8043b58568ac..8ab6a3865f569 100644 > --- a/drivers/bus/sunxi-rsb.c > +++ b/drivers/bus/sunxi-rsb.c > @@ -316,6 +316,7 @@ static int sunxi_rsb_read(struct sunxi_rsb *rsb, u8 rtaddr, u8 addr, > { > u32 cmd; > int ret; > + u32 mask; > > if (!buf) > return -EINVAL; > @@ -323,12 +324,15 @@ static int sunxi_rsb_read(struct sunxi_rsb *rsb, u8 rtaddr, u8 addr, > switch (len) { > case 1: > cmd = RSB_CMD_RD8; > + mask = 0xffu; > break; > case 2: > cmd = RSB_CMD_RD16; > + mask = 0xffffu; > break; > case 4: > cmd = RSB_CMD_RD32; > + mask = 0xffffffffu; > break; > default: > dev_err(rsb->dev, "Invalid access width: %zd\n", len); > @@ -345,7 +349,7 @@ static int sunxi_rsb_read(struct sunxi_rsb *rsb, u8 rtaddr, u8 addr, > if (ret) > goto unlock; > > - *buf = readl(rsb->regs + RSB_DATA); > + *buf = readl(rsb->regs + RSB_DATA) & mask; > > unlock: > mutex_unlock(&rsb->lock); > -- > 2.25.1 >