Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp285073img; Thu, 21 Mar 2019 20:31:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyd06kdOoFpACZzp5Jrgu3QOEg+yuV20Qz1JnimOB0W19yAT34QSroSztQ7DGTU3bS/fYiL X-Received: by 2002:a62:ab13:: with SMTP id p19mr6800128pff.131.1553225517508; Thu, 21 Mar 2019 20:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553225517; cv=none; d=google.com; s=arc-20160816; b=lS/kREeUlTu7Kqibpmw2D+LZtLJh7KIiKJBDAFWyCkACX7GplDL6J0Bm2bw2+Tk+re M9w5MEJQIkVNfKbrj+xKAUHVlJJc6/1B8ojBsd5uekt20XZZ+vvCBRbKSifm+vNF5Dey PfMbV2f4OOvlb8iIf/6g6TowPBWKP+ziJfO1yZohYHvBtVv9HDTYijtayw9j/kE8xkHg BLtTHA3GRK8pULLac/Ht8qyfE09f+GifzubGm1NDmUC37K7aF5nrcKGr6NB8vB3f7DzK a9dnjY5BIDA8zZXaaztlCA3QqB3X6mCmOBlNyDhTZrY0udDlZBNcSHVqRHrpz3gDMbN6 hCiA== 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=sN+UVi1xXiDD03PDbdwofs9lsLwAu0xcW30rFoQcclA=; b=mgkEkYAFLJcatTur0CR6WuRmd1ynLC8ybn7m0fVNqrD2A8XiYL4nlYPrAytjk35x9U cW7gSgYt4VZ+8SnvWIDo3qV9G485PgG8+D7efp0gKcJS+6M7OuXwyEF7urmS8qJhAAmD meszYqvfvS3Hs2BDrwi/JAeAzz64PSwNMNihCPDHgeUw/FtCABac8PnYJ49/2w8qmTgF unv8J9xiYPGqPzIdgL8ucOKarwEQ8MLcJcTyzWLY5chj9CTLbNg3mRoVjMBJyLEgF4ty j/emBVH8OOHVBI9grbNZvWOZor0ufjo19cSMnPk1Sz9EWa6eoPmzR9x+N3y8g4nTPRg/ ACzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ofq/VCA/"; 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 g10si2180897pll.374.2019.03.21.20.31.42; Thu, 21 Mar 2019 20:31:57 -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="ofq/VCA/"; 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 S1727703AbfCVD31 (ORCPT + 99 others); Thu, 21 Mar 2019 23:29:27 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36560 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727671AbfCVD3Z (ORCPT ); Thu, 21 Mar 2019 23:29:25 -0400 Received: by mail-pg1-f196.google.com with SMTP id r124so508999pgr.3 for ; Thu, 21 Mar 2019 20:29:24 -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=sN+UVi1xXiDD03PDbdwofs9lsLwAu0xcW30rFoQcclA=; b=ofq/VCA/8//9wm+Cmv96RWNS5f+TSNVAoC14wrGBvAI8QClu6xdbqkCn3GC3/hp2UJ GU83eWJ7bhlfofRMJZD49zHp/2gV1z5LzIEqcpMSNbVDDv8p5YOX8H4kuWK02IhqBCHi O8ihvdQ6sHzvr31AtwuMwz0oYLMM42Leo+o3QduVMmSEJobf2PnrbUPGOYG/seA6zbpT WhRtdnGg4/UBZbB4DZYNE8V84O8XStDGkXqcl2FyX48inq5633ENWQ0qc5O2QT2GMMG/ KLyL62F/xFJ/YzkUcX5Rgpwbk7cf/y/m+9SF62ORV6THTwc7zX66W19/fsVNT8uAR1/4 QOgA== 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=sN+UVi1xXiDD03PDbdwofs9lsLwAu0xcW30rFoQcclA=; b=aphiZOr74Asai7/rZorOqUsa1LRAu0PaSb31m5W0Lt/V1TWA1LCJVYwt3uTv12+fSM uG1slW5kx7T8Pvl98WKUCXmd5qsr+bGuBorWNULh9NRo2fhuevoeX/V9p3VVrozheRue 6dEXvcNAg82JEPiFE6c4C3XhKQ69PdbaJJvumC1y5OYi6qiueHuitv8h+qQOvi9e2tTB YxkecU2MGC1GuALqZOckuGxQnitAsZ5shMASMBFl5UR91YjLI7mgDNr8c4sj1CfAw+IZ CIyOynCa/M3bzA/xTCU6z2V6JiTV+7/esPhjNk5sjV0LTpPOpEFWbXjomixGaj2VS3qc A7Qg== X-Gm-Message-State: APjAAAVBlApYYa+HJ8RF6bSknRZ2qn74zsEvJzFm3454dMFvIczxxSq7 iZrVCKRd7Porf2ClrcbRLZJcEcreSZI= X-Received: by 2002:a17:902:586:: with SMTP id f6mr7048149plf.68.1553225363743; Thu, 21 Mar 2019 20:29:23 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id o76sm16154476pfa.156.2019.03.21.20.29.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Mar 2019 20:29:23 -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 , Chris Healy , Lucas Stach , linux-kernel@vger.kernel.org Subject: [PATCH v2 07/15] drm/bridge: tc358767: Simplify AUX data write Date: Thu, 21 Mar 2019 20:28:53 -0700 Message-Id: <20190322032901.12045-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190322032901.12045-1-andrew.smirnov@gmail.com> References: <20190322032901.12045-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 write by dropping index arithmetic and shifting and replacing it with a call to a helper function that does three things: 1. Copies user-provided data into a write buffer 2. Optionally fixes the endianness of the write buffer (not needed on LE hosts) 3. Transfers contenst of the write buffer to up to 4 32-bit registers on the chip Note that separate data endianness fix: tmp = (tmp << 8) | buf[i]; that was reserved for DP_AUX_I2C_WRITE looks really strange, since it will place data differently depending on the passed user-data size. E.g. for a write of 1 byte, data transferred to the chip would look like: [byte0] [dummy1] [dummy2] [dummy3] whereas for a write of 4 bytes we'd get: [byte3] [byte2] [byte1] [byte0] Since there's no indication in the datasheet that I2C write buffer should be treated differently than AUX write buffer and no comment in the original code explaining why it was done this way, that special I2C write buffer transformation was dropped in this patch. Signed-off-by: Andrey Smirnov Cc: Archit Taneja Cc: Andrzej Hajda Cc: Laurent Pinchart Cc: Tomi Valkeinen Cc: Andrey Gusakov Cc: Philipp Zabel Cc: Chris Healy Cc: Lucas Stach Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org --- drivers/gpu/drm/bridge/tc358767.c | 58 +++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c index 81c10a5d8106..21374565585d 100644 --- a/drivers/gpu/drm/bridge/tc358767.c +++ b/drivers/gpu/drm/bridge/tc358767.c @@ -307,6 +307,31 @@ static int tc_aux_get_status(struct tc_data *tc, u8 *reply) return 0; } +static int tc_aux_write_data(struct tc_data *tc, const void *data, + size_t size) +{ + u32 auxwdata[DP_AUX_MAX_PAYLOAD_BYTES / sizeof(u32)] = { 0 }; + int ret, i, count = DIV_ROUND_UP(size, 4); + + memcpy(auxwdata, data, size); + + for (i = 0; i < count; i++) { + ret = regmap_write(tc->regmap, DP0_AUXWDATA(i), + /* + * Our regmap is configured as LE + * for register data, so we need + * undo any byte swapping that will + * happened to preserve original + * byte order. + */ + cpu_to_le32(auxwdata[i])); + if (ret) + return ret; + } + + return size; +} + static int tc_aux_read_data(struct tc_data *tc, void *data, size_t size) { u32 auxrdata[DP_AUX_MAX_PAYLOAD_BYTES / sizeof(u32)]; @@ -335,9 +360,6 @@ static ssize_t tc_aux_transfer(struct drm_dp_aux *aux, struct tc_data *tc = aux_to_tc(aux); size_t size = min_t(size_t, 8, msg->size); u8 request = msg->request & ~DP_AUX_I2C_MOT; - u8 *buf = msg->buffer; - u32 tmp = 0; - int i = 0; int ret; if (size == 0) @@ -347,25 +369,17 @@ static ssize_t tc_aux_transfer(struct drm_dp_aux *aux, if (ret) return ret; - if (request == DP_AUX_I2C_WRITE || request == DP_AUX_NATIVE_WRITE) { - /* Store data */ - while (i < size) { - if (request == DP_AUX_NATIVE_WRITE) - tmp = tmp | (buf[i] << (8 * (i & 0x3))); - else - tmp = (tmp << 8) | buf[i]; - i++; - if (((i % 4) == 0) || (i == size)) { - ret = regmap_write(tc->regmap, - DP0_AUXWDATA((i - 1) >> 2), - tmp); - if (ret) - return ret; - tmp = 0; - } - } - } else if (request != DP_AUX_I2C_READ && - request != DP_AUX_NATIVE_READ) { + switch (request) { + case DP_AUX_NATIVE_READ: + case DP_AUX_I2C_READ: + break; + case DP_AUX_NATIVE_WRITE: + case DP_AUX_I2C_WRITE: + ret = tc_aux_write_data(tc, msg->buffer, size); + if (ret < 0) + return ret; + break; + default: return -EINVAL; } -- 2.20.1