Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5407645ybi; Wed, 12 Jun 2019 01:55:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOB5ugbubTvpeZpiiQp39F0tNiIjkVfihYnjpxoJHBWVFEic0XEeNalRNWk2attNl5pVks X-Received: by 2002:a17:90a:9a95:: with SMTP id e21mr30689891pjp.98.1560329742242; Wed, 12 Jun 2019 01:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560329742; cv=none; d=google.com; s=arc-20160816; b=T/4Z4ED7e2uhyelXbGp0nrMa8Ug8KwIwvD+cAbv9dW8enIkwsxZMwvstmy/Glygj7U MmV3bpmY0Nvkm81wH6FQUrtIF2zYjiTi//L82+2G6VPvotZOguC4ICA5z9+p/8BMJ/TW S5KDfKZd4bBnpPaR3/RSuTqbn3RkPRmAUWDy6Iv9oWoHZYQ7FxR2q2Z121Njt9FPcK97 3zBCdVHN07WEsNyN0ntR1l9be65mHcePl/mJmr1IeiBC9VRMTQ8IrEKTmlP7dndwGMXa 4RdXlLyVkb41wKYUZyoMVMqy1f7tqd+vyyRGuEdLl2K2BaPxflEOXfFYwaw/JSQmbbK5 Otjw== 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=LVdZCLFy6QEDGvyvStVGqispy/JrU6lkx44tS0r6TYo=; b=rkG8a460eknyC3XTs/t4CrayUIlvvk/uhrH3/b2sZaYicolqRmQkB6Jg110ibtmZPq VhXGNiBUeKLg20x5YQ5RtP8FlOnt5T3mpPHvelaB7BK8XqMqMs2SMY/kT0kZegbjrVVF ce0XPnpETomnYtaiaUXQFy1g5+e6sVFVMgrn08Xa0F4OovrgrNweuPfZIXPf2gnzcsds ZRldW6GYc1CLAyJ1UZmerIz2iRpBa95cIUKW23IfB0q7N5pVgJw7efWkWZmDy4T9gO+V eP1ualUyKuwouGGUQ3L118aEyhaWDqTggxu1zENNupqqPdLeFnESw3ozhcsgvSI5BOpH EYNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ebH+e+yR; 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 q18si6270577pgv.456.2019.06.12.01.55.26; Wed, 12 Jun 2019 01:55:42 -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=ebH+e+yR; 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 S1731247AbfFLIeB (ORCPT + 99 others); Wed, 12 Jun 2019 04:34:01 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36232 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437239AbfFLIdP (ORCPT ); Wed, 12 Jun 2019 04:33:15 -0400 Received: by mail-pf1-f195.google.com with SMTP id r7so3335564pfl.3 for ; Wed, 12 Jun 2019 01:33:14 -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=LVdZCLFy6QEDGvyvStVGqispy/JrU6lkx44tS0r6TYo=; b=ebH+e+yRL03RD84DE66s1KelaR+9leWYSMIwRIAWYA5aXrQAAkVvL2oCcizYNskH02 MIL5/ZHmccqPa/hYl2SfmClEogn4UxqAKKoOdJ/Y+dUjX+xGRD7r9jViQDAMPkCadeUi xsx07/ikMU88hRqRIuygDMj3xWF/S7eBmhkptKjJvSnhEoInIc9Reh1QpdM25KXHVfja XGaBSoWYfRtxQopXIjLMdqz3es4WwYhkrsBtfCPtyZCLpBoS3/qVaz+JvybH9syeFOzV HfZ0vKVBOP/dvWqH8Jd7nm/arv+NBZ8SJLEG53JUu6MiBqXBEjO4Qm/bmR6o/HH0zVvw lcoA== 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=LVdZCLFy6QEDGvyvStVGqispy/JrU6lkx44tS0r6TYo=; b=E7tMyo+Q3c02GOdm5lr9MGGHjM4Y3PxtEHvhGEszIyuqZATLNL+k5viuMIvIn2Q8bp 378WsVwMkg0N05oY6TgtB2HBSTJgFwg3moEWTzr/7EFzQHWhqUw8JD/YxJkyAc1FH30L b+hOty2BZtT1uPU5s9VRxxT8dUdo0ZH8SXJUdqDr2Rf0eDjwGv9cDmMgw3xPZV3KIElV rMaXVAUHJHKzIzBX+jryQLTqVTmQlUXIj6KlredadJOLB9U+BSRAtaBQOiMNAukBPI0g KL85I5Iri5qJ+/VmX7xuirJu49Lye0fttn4kFLl4Ybzb3oVPh6UbinPPJmF0fZwPH5Js ZVRQ== X-Gm-Message-State: APjAAAVCUbtnRN39iXGt4h8qgKB59B140XoliFTICbn1nTWCie/8dqSb f3PINN30ERi+mTUq0T7EZcA= X-Received: by 2002:a62:7d13:: with SMTP id y19mr26901449pfc.62.1560328394213; Wed, 12 Jun 2019 01:33:14 -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 d21sm18845991pfr.162.2019.06.12.01.33.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 12 Jun 2019 01:33:13 -0700 (PDT) From: Andrey Smirnov To: dri-devel@lists.freedesktop.org Cc: Andrey Smirnov , Andrzej Hajda , Laurent Pinchart , Tomi Valkeinen , Andrey Gusakov , Philipp Zabel , Cory Tusar , Chris Healy , Lucas Stach , linux-kernel@vger.kernel.org Subject: [PATCH v5 06/15] drm/bridge: tc358767: Simplify AUX data read Date: Wed, 12 Jun 2019 01:32:43 -0700 Message-Id: <20190612083252.15321-7-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190612083252.15321-1-andrew.smirnov@gmail.com> References: <20190612083252.15321-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 function that does two things: 1. Fetch data from up to 4 32-bit registers from the chip 2. Copy read data into user provided array. Signed-off-by: Andrey Smirnov Reviewed-by: Andrzej Hajda 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 | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c index 7b15caec2ce5..7152b44db8a3 100644 --- a/drivers/gpu/drm/bridge/tc358767.c +++ b/drivers/gpu/drm/bridge/tc358767.c @@ -321,6 +321,20 @@ 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, count = ALIGN(size, sizeof(u32)); + + ret = regmap_raw_read(tc->regmap, DP0_AUXRDATA(0), auxrdata, count); + if (ret) + return ret; + + 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 +393,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