Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6402873ybi; Wed, 5 Jun 2019 00:09:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyboMutVTGtT1BhiKLo93DGPtZbdlxwrbnn0K8Iojw3ISR+PaSsng+64m6bx2qM+XVrpQcX X-Received: by 2002:a63:2b96:: with SMTP id r144mr2517464pgr.314.1559718573913; Wed, 05 Jun 2019 00:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559718573; cv=none; d=google.com; s=arc-20160816; b=UVhNJIEcTnfNutp6nPWdxDyj7E5P7LGj+EX2qd2cmzQUmvd93n97WgN/BB/F9WK7HW TBLlblNhrJPVBBAZFnrz4ZMsA0CABnCd1teZyb5G2zzxxSOn26ul1UFmitPKPYJGqnYl ebi0f8qiJHAKnzAPSDt+nG4ng8TLvw++4Hx+x0stIP1f9AEqb/vg21rkF9Wul6B8WC8M lh3MkeAW4K2LbxrPXnxjw5bA4/ySXclEQfXR0TABTrQ9J7DxGWI+2T62tpnFHP0sViBE 503bQ50zG2BfezL6OMxuDnqXcltjomlBgJPXLBzH6qix1K2Tt2DGxGpd+G8pvB9XXT6k 49Jw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RWa3xMhIG7h2ZDJedBrnEPzMrydSyBPoX1txGwYk6+U=; b=jYB9j0JIxunLJHzC6SumKz/s/5yZr94wi6x7pXAzj4zHXcGoRwyjJLwni9x0IdxoKr cltfEDC2t2t5G1w8a12WZoVAUtRH0hsIt/AQZQywFud/l6e184VJR6R8ieefgpR7/vme ckzbAGmHIteKzSb6+U2A/UPoPdp8LCTFE8DeM/cqL/w76GOQQw2TP73gavEv2Jf38nud UyE5mpGB2MJlRfCn9qhjSONIx2Qzbi4ibMWazPgr3kYby8MEIBUr3kNefESg/owvzWfw iiRS3OT8D+M19YVXWq47r6Xu8zoizwMgk8BQuhAAlD4jfjWOet8BYIeOKmZsa9TpWChi nXSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="pjTQEQM/"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q3si24131146plr.75.2019.06.05.00.09.16; Wed, 05 Jun 2019 00:09:33 -0700 (PDT) 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=pass header.i=@gmail.com header.s=20161025 header.b="pjTQEQM/"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726779AbfFEHFd (ORCPT + 99 others); Wed, 5 Jun 2019 03:05:33 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40086 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbfFEHFc (ORCPT ); Wed, 5 Jun 2019 03:05:32 -0400 Received: by mail-pg1-f193.google.com with SMTP id d30so11865466pgm.7 for ; Wed, 05 Jun 2019 00:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RWa3xMhIG7h2ZDJedBrnEPzMrydSyBPoX1txGwYk6+U=; b=pjTQEQM/NCzvm3rKIdA/jf1ynZxiZDf1SDBIDA4M3O+FwsyScIvnbcO2uajRBeDUtB H8KwDgjBWXNTr778cITsLegfEbxsGpzdjdTK2zo6F2G4Iy0xZDr9X2D9/0I3P5O51IiJ ITp6L+msYtdfxpBb5c+q+0dWFCgZTqojOjEjocVxnPZGZzwE5BHpVOVZZskAAsXR2Ij1 l5iMa1GGT5zjOTltNAP63i3RWMc2hHDu1xt1opU8JDqDW9EXuaOdOCj9fKVJLzDZ5lPK l/CFuL1ntsYHcdvBYjgg5CfcnQaSxnTuzQcLJr9XizuEUxe0QIMS44IbHJkiTP5KDtxV QHLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RWa3xMhIG7h2ZDJedBrnEPzMrydSyBPoX1txGwYk6+U=; b=aZH3m3RQTzqKyyO9pWyJsHeZ/FAq+sklAIqFkTBgWjTnFQk3G6bt5N7zJSTDakuVUy pfH+WjZwRXKPc04PhQfB6j4z/a+HvLzhYgFfF7n0Ysgd9VdgUDVfgS5QCsa72nAx/ACK gGU2AyJCoIqcpI3UWm15JCmiFXvx9tmtls/QfVp5RHTlumk2iQOy66GR7fAeLerhki+O G4Qo1SeB4DGcAB5eruR8M4SBflzBWLBoCRJ7VCEAUCjTcbxTEQaRuNOAKqAQRFBhfoBE M+3sAJNTeIRKJGO17rq2O5MzIQ6GGbSSe4p53Iy4pQa5OLaYDjTncXGKv+fbedkNWdrY BzHQ== X-Gm-Message-State: APjAAAU/C4jZG7cgXTOF/FMMdCLKH9N3TsLBVPngQ8dbl5FRUpBNRc+H tC+iE7hP8Sd3g00ld/0XAgo= X-Received: by 2002:a17:90a:ae10:: with SMTP id t16mr42228780pjq.51.1559718331351; Wed, 05 Jun 2019 00:05:31 -0700 (PDT) Received: from localhost.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id d132sm6527348pfd.61.2019.06.05.00.05.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2019 00:05:30 -0700 (PDT) From: Andrey Smirnov To: dri-devel@lists.freedesktop.org Cc: Andrey Smirnov , Archit Taneja , Andrzej Hajda , Laurent Pinchart , Tomi Valkeinen , Andrey Gusakov , Philipp Zabel , Cory Tusar , Chris Healy , Lucas Stach , linux-kernel@vger.kernel.org Subject: [PATCH v3 06/15] drm/bridge: tc358767: Simplify AUX data read Date: Wed, 5 Jun 2019 00:04:58 -0700 Message-Id: <20190605070507.11417-7-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190605070507.11417-1-andrew.smirnov@gmail.com> References: <20190605070507.11417-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify AUX data read by removing index arithmetic and shifting with a helper functions that does three things: 1. Fetch data from up to 4 32-bit registers from the chip 2. Optionally fix data endianness (not needed on LE hosts) 3. Copy read data into user provided array. Signed-off-by: Andrey Smirnov Cc: Archit Taneja Cc: Andrzej Hajda Cc: Laurent Pinchart Cc: Tomi Valkeinen Cc: Andrey Gusakov Cc: Philipp Zabel Cc: Cory Tusar Cc: Chris Healy Cc: Lucas Stach Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org --- drivers/gpu/drm/bridge/tc358767.c | 40 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c index e197ce0fb166..da47d81e7109 100644 --- a/drivers/gpu/drm/bridge/tc358767.c +++ b/drivers/gpu/drm/bridge/tc358767.c @@ -321,6 +321,29 @@ static int tc_aux_get_status(struct tc_data *tc, u8 *reply) return 0; } +static int tc_aux_read_data(struct tc_data *tc, void *data, size_t size) +{ + u32 auxrdata[DP_AUX_MAX_PAYLOAD_BYTES / sizeof(u32)]; + int ret, i, count = DIV_ROUND_UP(size, sizeof(u32)); + + ret = regmap_bulk_read(tc->regmap, DP0_AUXRDATA(0), auxrdata, count); + if (ret) + return ret; + + for (i = 0; i < count; i++) { + /* + * Our regmap is configured as LE for register data, + * so we need undo any byte swapping that might have + * happened to preserve original byte order. + */ + le32_to_cpus(&auxrdata[i]); + } + + memcpy(data, auxrdata, size); + + return size; +} + static ssize_t tc_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) { @@ -379,19 +402,10 @@ static ssize_t tc_aux_transfer(struct drm_dp_aux *aux, if (ret) return ret; - if (request == DP_AUX_I2C_READ || request == DP_AUX_NATIVE_READ) { - /* Read data */ - while (i < size) { - if ((i % 4) == 0) { - ret = regmap_read(tc->regmap, - DP0_AUXRDATA(i >> 2), &tmp); - if (ret) - return ret; - } - buf[i] = tmp & 0xff; - tmp = tmp >> 8; - i++; - } + switch (request) { + case DP_AUX_NATIVE_READ: + case DP_AUX_I2C_READ: + return tc_aux_read_data(tc, msg->buffer, size); } return size; -- 2.21.0