Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp707226imp; Wed, 20 Feb 2019 07:39:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbTVyDcdhz+JqpULxh4pKrivEZGoSORMIe1Wnol9SNY8mm01SehCtLJ2l3ugImmNI35BMpa X-Received: by 2002:a62:5003:: with SMTP id e3mr36245348pfb.23.1550677153581; Wed, 20 Feb 2019 07:39:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677153; cv=none; d=google.com; s=arc-20160816; b=q7Ngl1qC9cF9R0ZAkpAM73tvFUDIshrT3hBi0q7C9z5jHqyOMNq3MtleG7IyXgEayB HDSnS14MBlpTth8FltjMK84/fCjxsX+9G4eMBFKwzjcShGvgT+HKGajNYEhuBhHVu7np U8aK4rhOCbnejkFa8qkyCFkE4v+kEADRsdSw3zpgUU5kDT+dhwIP8Iq/kPDoL0CaPHjP yt52BYYQJeCcIXvt2YYH89SXZnvoIx/bEgs9S/6rI7IZ5RLsEAXmf+L8dACDdoHmUxiV Gpq5vQtaXHwqsuuPN2z6oQxjgSFPnyM8aVtTNBmiYIDgnSN6owa7SIx81Njm+7Z7PYjA vXQw== 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:references:cc:to:from:subject:dkim-signature; bh=4XRMCSi0LdzN7adsNjimSKKZZBAP1rV9ioFDU46+zRA=; b=y+GMQDue2+0VL5B4ZrEhGdezSZQw4zrt4XoPD5+5UK0rf++iv/xbG/e44eouNeBRhC Cu7dabbvysj9pvq9BLqxQ2zVIGZFZWIahXKBGMSX8KcxhSq6zlm/qa+L9OH25Hzfc/jN xoNzqMGosKWPXbxQQAl4ixGogMjOhE4xP6lvTF/vyTyWc7EEf6yD0OveLrvBFjC2kV2q LsVjH992OsVb5deUSB4hojBz0u24VKtcFQ5ef1b1J5xQcSeUt4va1ea3d3TdLbPIGUXV BsdYZPHiIjuX/AVADWfpbvMYC3rRpX5kG5WnSt+IVD5uFPPJmv3k1KPu35hRNvr1W3GH mGvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Iu2HxyDb; 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 q17si8142990pll.343.2019.02.20.07.38.57; Wed, 20 Feb 2019 07:39:13 -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=Iu2HxyDb; 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 S1727554AbfBTPg1 (ORCPT + 99 others); Wed, 20 Feb 2019 10:36:27 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37507 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725865AbfBTPg0 (ORCPT ); Wed, 20 Feb 2019 10:36:26 -0500 Received: by mail-pg1-f195.google.com with SMTP id q206so12052675pgq.4; Wed, 20 Feb 2019 07:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=4XRMCSi0LdzN7adsNjimSKKZZBAP1rV9ioFDU46+zRA=; b=Iu2HxyDbS+NZCUPuNRzhT5m7pBT2y9XBoytp47BCOZRNmY9gOTjsqwzH3aXCqDIiKp VN67ziAfi5BIyQjyDzUrYe0bi0bm86Dffdg+N2k1Kzm4hcrzw8QANdMydNnlN9zRF7Y9 VCIdyemIdbfGAo3ZJGd2R6RtOqhl/WPDrytg2NSTkktNEKh1f69Yo5DD0bijbP2fgmDQ B23BSsHuoeiJ5t7iz65ESpVmscUAXTcsT417LX7qtQPZP11EUF/thcul8U21Y/GhYpyz Nn36i9sHITdKMzcGqy+6o6HaU69nx1mRTodLD0Or9K+gVcpOsGJqdpn7v5jnd/qrCR6u /chg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:references:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4XRMCSi0LdzN7adsNjimSKKZZBAP1rV9ioFDU46+zRA=; b=AYPF9iXE7WD+6gUMDtfqiP6IhYXNtjl7un4FnP3DCiX4Z9oZIRbc/Nfu2pALFgthD7 eVxbZOzTesHo6bXU/URSizMJBDvw0/KheH/LdL5LCYDfinhuOjgQCx9WVa2QqwP89Ci0 MqDBDpS+J116OESdobx/TAPkA0ibQBVqteeR2qFpSlshq0ZhYslILcPSOP4IVnQyKDuZ Jjaa9Dr/4LPO7oPe/z4mLOH3dVbqDZiZz/MN4kJyC4NalSwKwAPq1RZuQ3ARyKqaPCuF XvR8rUGJXlAZWrqt5UZsvzhqB6LfviB5Em5+JttyqGZDPTYnTZ4RZiOI9hiuGEbtMxyS tLLw== X-Gm-Message-State: AHQUAubh5nqIJlWTU2/jTN3HQcRuN0QTo755P+SYPYF0jOCeblLvg10a 91BB+JyVpqc8ddw4UMWeSawiA0/0 X-Received: by 2002:a63:c503:: with SMTP id f3mr29177919pgd.431.1550676985646; Wed, 20 Feb 2019 07:36:25 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id l12sm21625830pgp.54.2019.02.20.07.36.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Feb 2019 07:36:25 -0800 (PST) Subject: Re: [PATCHv3] usb: typec: tps6598x: handle block writes separately with plain-I2C adapters From: Guenter Roeck 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> <8dc1a931-c9f7-a46a-42dc-fdcd2274343b@roeck-us.net> Message-ID: Date: Wed, 20 Feb 2019 07:36:23 -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: <8dc1a931-c9f7-a46a-42dc-fdcd2274343b@roeck-us.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/20/19 7:35 AM, Guenter Roeck wrote: > 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. > Clarification: That would be a separate patch. Guenter > 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; >>       } >> >