Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp704803imp; Wed, 20 Feb 2019 07:36:45 -0800 (PST) X-Google-Smtp-Source: AHgI3IaGGt1yqpZbJXZ/PQIcmV1vlB9XxWpFgDZd9Rz1JIA9VtF5YXAch+g5ZGRbjh86JwrMzqvN X-Received: by 2002:a63:e950:: with SMTP id q16mr29916886pgj.138.1550677005149; Wed, 20 Feb 2019 07:36:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677005; cv=none; d=google.com; s=arc-20160816; b=gZtgdBYW3xw34WBsMBT8qnsUif3aflPVQ/oyd+bHlmbTEnGru3C2lF9mbXBvBZybgF FrlsU+a2MiPItM9cidwGpE7OC7sSt8ZdpkTg7u3wnzmVZzfECLYKc/e6DtLH6j79TnqD ubE7YKgJ+gn2F+K47B6bWPUiRL9iq1QUwDh504A+JIETWR/OBiex45+NbYl2ra3RPOl7 gCNIItsMOacBBTdd30aePTay0zA+/8DBlxZy4l7sSZkBCE47mliCjW1peF6vJO0Mf8fK uA6vAFiN5iVM7/a8hkdL7RSQ+uPCUzLuIa/DUSAVcYPAv3ld7yD2I8EU9tI4ErP3Sbtq iNOg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=WmAAGsSCPamxS6QsYyp6MZrdJ8c46CKOqUNG+Yp75Gc=; b=h7LZw9Kg4dz3zD0E8Sc6jeOdgBKQ9kbzVCVXlw+JZdfAZlyigBjKJtO+AOw9WlB491 //pim+AdCHQESLSnOArzSoW17BOmvn4yyyic4WHOFDdnorJY6l5xsvnPO3fwrP8D4AHD 9Uhg8iD0+ld/xRyea6avFz3j2UrXtiFauuWl+AoP/WN5J3Uyq0v+EtfMF1wdfCTecwVT RaSGv+FkVhRTGuEglgmTn31Yqq6NJgjXt9X0ywPmTR/dT7EAuzCOl2UzJq7Qw7JzpqyX rqANFq+mkXOAMhxVRFrxDffehR+SrboAUHY5Vw9iKO3+cRFxgSY0pRKaMLjyLp1UsSLI Vpzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XDkVLYh7; 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 101si20777230pld.22.2019.02.20.07.36.29; Wed, 20 Feb 2019 07:36:45 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XDkVLYh7; 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 S1727275AbfBTPfa (ORCPT + 99 others); Wed, 20 Feb 2019 10:35:30 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35594 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbfBTPfa (ORCPT ); Wed, 20 Feb 2019 10:35:30 -0500 Received: by mail-pg1-f194.google.com with SMTP id s198so12054054pgs.2; Wed, 20 Feb 2019 07:35:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=WmAAGsSCPamxS6QsYyp6MZrdJ8c46CKOqUNG+Yp75Gc=; b=XDkVLYh7DQl04ReMszpW+QSQAypNERQT268eUtkAnB4PerqFqZkYQZmjTHp6rYKquJ AXN+8rgrL63ZJPUjGJQ9MgIYkM9n5g1EJuOEMXZUyCIAfrhmqLJRLJj8i4lCtnKj5EFy WSHp+rfJau1XAbPSRNM+OV4N8YUcou5gWl7UB8VF5dGPTOOXA9DhWOMP5fMLgXkSV3C2 xHNPu635NcFY66QfNcrP7VjLZ5KIM3pn28iWnvWgZaGore4Xf2faAJcTZIlzVAntHD6u d/yp3XEUbWznY1SvUqscfur90mWOFrX6hD1yU6jrMpXNAKXfFvbiLk+dhNbfSKKxKzcw JVYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WmAAGsSCPamxS6QsYyp6MZrdJ8c46CKOqUNG+Yp75Gc=; b=LQ2+Lww+oN60y9mx1ZNLUoUvB74jOSCexMFRC3l9Pihs3Yaqs/JjejorWPHNVh0cC4 YXAa75dIUzHlG0NDFMNkp/SouhiH2fGTto7caTOMXxQYnjOjRLQY/lxxqWfzIAJmMzr9 z1qFmyx06MX4TmFHw4HcbRmlaHUYb3SypQkRzJBGscfFBhBsH5WspgK4Mq1IAt8Xrncp bz64y4FdLE/FaO013bYpdM27VLKy3Bu+AniEbbfdTIg5J3jELYb1r25xhEPdbC09lDcd U6iZKNYOkMR8M3D9MdoX+Ea1ErCttIVCdpAiTY1bvYEGYZgZ1wvSsevimQOwzBOx1fuK uE/g== X-Gm-Message-State: AHQUAuZgeJKKt3Ap1J8rifU43l08ls8kbVDVFh3ZEyGi3xvOQJaQ9D15 D0jMo5b9LYkwlRtPe4ve5T0= X-Received: by 2002:a63:cc15:: with SMTP id x21mr6565927pgf.380.1550676929247; Wed, 20 Feb 2019 07:35:29 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id w4sm40282408pgk.16.2019.02.20.07.35.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Feb 2019 07:35:27 -0800 (PST) Subject: Re: [PATCHv3] usb: typec: tps6598x: handle block writes separately with plain-I2C adapters To: Nikolaus Voss , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Nikolaus Voss References: <20190220110017.BFA344CE86@mail.steuer-voss.de> <20190220151138.12332-1-nv@vosn.de> From: Guenter Roeck Message-ID: <8dc1a931-c9f7-a46a-42dc-fdcd2274343b@roeck-us.net> Date: Wed, 20 Feb 2019 07:35:25 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190220151138.12332-1-nv@vosn.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/20/19 7:11 AM, Nikolaus Voss wrote: > From: Nikolaus Voss > > Commit 1a2f474d328f handles block _reads_ separately with plain-I2C > adapters, but the problem described with regmap-i2c not handling > SMBus block transfers (i.e. read and writes) correctly also exists > with writes. > > As workaround, this patch adds a block write function the same way > 1a2f474d328f adds a block read function. > > Fixes: 1a2f474d328f ("usb: typec: tps6598x: handle block reads separately with plain-I2C adapters") > Fixes: 0a4c005bd171 ("usb: typec: driver for TI TPS6598x USB Power Delivery controllers") > Signed-off-by: Nikolaus Voss Reviewed-by: Guenter Roeck Note that tps6598x_exec_cmd() is only called with in_len == out_len == 0 and NULL data pointers. It might make sense to simplify the function and drop the unused parameters as well as the associated code. Guenter > --- > v2: fix tps6598x_exec_cmd also > v3: use fixed length for stack buffer > --- > drivers/usb/typec/tps6598x.c | 26 ++++++++++++++++++++------ > 1 file changed, 20 insertions(+), 6 deletions(-) > > diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c > index c84c8c189e90..eb8046f87a54 100644 > --- a/drivers/usb/typec/tps6598x.c > +++ b/drivers/usb/typec/tps6598x.c > @@ -110,6 +110,20 @@ tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len) > return 0; > } > > +static int tps6598x_block_write(struct tps6598x *tps, u8 reg, > + void *val, size_t len) > +{ > + u8 data[TPS_MAX_LEN + 1]; > + > + if (!tps->i2c_protocol) > + return regmap_raw_write(tps->regmap, reg, val, len); > + > + data[0] = len; > + memcpy(&data[1], val, len); > + > + return regmap_raw_write(tps->regmap, reg, data, sizeof(data)); > +} > + > static inline int tps6598x_read16(struct tps6598x *tps, u8 reg, u16 *val) > { > return tps6598x_block_read(tps, reg, val, sizeof(u16)); > @@ -127,23 +141,23 @@ static inline int tps6598x_read64(struct tps6598x *tps, u8 reg, u64 *val) > > static inline int tps6598x_write16(struct tps6598x *tps, u8 reg, u16 val) > { > - return regmap_raw_write(tps->regmap, reg, &val, sizeof(u16)); > + return tps6598x_block_write(tps, reg, &val, sizeof(u16)); > } > > static inline int tps6598x_write32(struct tps6598x *tps, u8 reg, u32 val) > { > - return regmap_raw_write(tps->regmap, reg, &val, sizeof(u32)); > + return tps6598x_block_write(tps, reg, &val, sizeof(u32)); > } > > static inline int tps6598x_write64(struct tps6598x *tps, u8 reg, u64 val) > { > - return regmap_raw_write(tps->regmap, reg, &val, sizeof(u64)); > + return tps6598x_block_write(tps, reg, &val, sizeof(u64)); > } > > static inline int > tps6598x_write_4cc(struct tps6598x *tps, u8 reg, const char *val) > { > - return regmap_raw_write(tps->regmap, reg, &val, sizeof(u32)); > + return tps6598x_block_write(tps, reg, &val, sizeof(u32)); > } > > static int tps6598x_read_partner_identity(struct tps6598x *tps) > @@ -229,8 +243,8 @@ static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, > return -EBUSY; > > if (in_len) { > - ret = regmap_raw_write(tps->regmap, TPS_REG_DATA1, > - in_data, in_len); > + ret = tps6598x_block_write(tps, TPS_REG_DATA1, > + in_data, in_len); > if (ret) > return ret; > } >