Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp632555iob; Wed, 18 May 2022 09:30:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+ZzkTJuTvdBrUiB+78hGysuFPd1Jt9+8M7e0Phbn7Hojd/2GdsQ7kqargNltx8gAf+ZVO X-Received: by 2002:a17:903:324e:b0:161:385a:c141 with SMTP id ji14-20020a170903324e00b00161385ac141mr491008plb.154.1652891414383; Wed, 18 May 2022 09:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652891414; cv=none; d=google.com; s=arc-20160816; b=aWSOzpWEi/sUfeRrdQXdlo7Dxc8/CvCN32fzEcXEOuxVQ5t0jGg7jPUCzT06efR7SW fbmlzy027Ol1WucGwxxN8jdfDP8w56J0u8qvbpvSvjEoqSV28GROMtfiZYb1j9Xtyv8D cSX9UswCY6FZjMsR46boFhQe3RaShkd/epEkmjhR0rCzfAaB6ADHfaMXyVai+inJRi4h aeCou7F54tYTNfLj6EpuU+EubYzxcNjtmAGX3p8tdy0oBlAFNf7tEKLrHCUvHwRcfxym 9h5kYow93pHJXLk5BkXdB4Il8DQCXpz4kJYqQI/g9witlnRu8EIiqXn2TeWOi6XWCKHi cznA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OT9eEBFMeKZroeDVOBWrAfjCYcqI+X5VChXxs9BlrXg=; b=HgzgproT+420QsR90xSOIlG83CDEdTIlld++3ovmgwPVSVGBsYS+XEMf0tEjk25Ywn IwQp5ZirkWy/BJLTuoiju9HFpYFDCob9ToYtWEv1lEworNoR6xmuu2TZrPnpFIVRqxdU ELe4LMb75oJk+H64vWrrbFQJCg+/XPbCoRsq7aQkUWc/6i/klYc5upUZ2HdzQXbYOYoG c75WtnusY3+AliwZVuwzhVmV2j37zQopa08KPobM7OhOeWgEWtRGPX2jOmRS4/NaIaxx TbUXFQ98wuR3PJX09iwPRMyAZffS3Rl/p8u5qERTaMFwR76+SFghz9Ne6GxzN7/CGQl5 oDpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gsl7VPQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r30-20020a63441e000000b003c62121f239si3131039pga.808.2022.05.18.09.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 09:30:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gsl7VPQ9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B6B071A08; Wed, 18 May 2022 09:26:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240098AbiERQ0f (ORCPT + 99 others); Wed, 18 May 2022 12:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240182AbiERQ02 (ORCPT ); Wed, 18 May 2022 12:26:28 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A65D50E20 for ; Wed, 18 May 2022 09:26:26 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id c12so3677498eds.10 for ; Wed, 18 May 2022 09:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OT9eEBFMeKZroeDVOBWrAfjCYcqI+X5VChXxs9BlrXg=; b=Gsl7VPQ9FyK0s5sL1fpz/EjhUZoQKGnGlpYrkZXH8BfbxKlvO5GUZPMlOfQz+y5b0t /3+JhrFXrolcoO2X5Onss7j27Lxsb9Ew1AC0L6/7HCsHCwgPBRwWU3FHfyMoIdbMeeqf YIDfQCWhi1TCO6M/Sdn6KoljmmkQjNNDN5fst0xkAjc9nj3OHmM4BRHkMKyxlFpU6a1S Gaf/zuL0mhBX5ySZz1xCfh6QXNOLHJJONgeNBlxRY3irGcwfekbX9znijLdKWdEU9hBj vLdo5SsbDeV1WlQxwvEg6rU9in5kF2p6DcdSMCKg3DNrL3zc/9SKETvhllh/zgiLQ+Zg zkNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OT9eEBFMeKZroeDVOBWrAfjCYcqI+X5VChXxs9BlrXg=; b=W7Wpljn7o/LxvPBM1TkqMENpQM7X1uZAKDZETsMMUUv25FMntTxE9XeuL94aoDRVnc PSB0pi6jNTEQ44U9kJxpkjQCk2AAHTZyXLCeWlmVBI9i9jzyLCsTK9zz+PgR0F5Boj6t ZkkBQ+FaNtJCCw6R/wdnJTJ4t9gGd0MQsamEJAksTIxn55X67Q+yyNALHoblTjGVF3oj QDg9LmPgy5xWNnbLPJJ7VcR9Tm/nmir1uKma87A6+pmIlv8kyTRm9i05PGO5eW0sqq83 4VgD55jVESW8a80buT4UFYq5zbfpSbMc5xHYFNysgkEqrC4bL3hLds7YMknhyGEQE0pP rAKg== X-Gm-Message-State: AOAM5300O79a/tj+IHYw9xNmHI5EBBYV9lSPTaiyIaibicBiRzgSB//6 dlvBRZMIWzytyU5PpvJKrB+euqVloGdAd33fUokf/g== X-Received: by 2002:a05:6402:2709:b0:428:3ed9:abe3 with SMTP id y9-20020a056402270900b004283ed9abe3mr593155edd.51.1652891184623; Wed, 18 May 2022 09:26:24 -0700 (PDT) MIME-Version: 1.0 References: <20220518091814.2028579-1-tzungbi@kernel.org> <20220518091814.2028579-3-tzungbi@kernel.org> In-Reply-To: <20220518091814.2028579-3-tzungbi@kernel.org> From: Guenter Roeck Date: Wed, 18 May 2022 09:26:13 -0700 Message-ID: Subject: Re: [PATCH 2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx() To: Tzung-Bi Shih Cc: Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel , Doug Anderson Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 18, 2022 at 2:18 AM Tzung-Bi Shih wrote: > > cros_ec_prepare_tx() mixed the code for both versions. To be neat and to > make it clear, factor the legacy part out as a separate function, rename > the function, and update the comments. > > Specifically, > - prepare_tx(), for current protocol version (i.e. 3). > - prepare_tx_legacy(), for protocol version <= 2. > > Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck > --- > drivers/platform/chrome/cros_ec_proto.c | 51 ++++++++++++++----------- > 1 file changed, 28 insertions(+), 23 deletions(-) > > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c > index ff767dccdf0f..01ab58b3269b 100644 > --- a/drivers/platform/chrome/cros_ec_proto.c > +++ b/drivers/platform/chrome/cros_ec_proto.c > @@ -52,8 +52,8 @@ static int cros_ec_map_error(uint32_t result) > return ret; > } > > -static int prepare_packet(struct cros_ec_device *ec_dev, > - struct cros_ec_command *msg) > +static int prepare_tx(struct cros_ec_device *ec_dev, > + struct cros_ec_command *msg) > { > struct ec_host_request *request; > u8 *out; > @@ -85,6 +85,28 @@ static int prepare_packet(struct cros_ec_device *ec_dev, > return sizeof(*request) + msg->outsize; > } > > +static int prepare_tx_legacy(struct cros_ec_device *ec_dev, > + struct cros_ec_command *msg) > +{ > + u8 *out; > + u8 csum; > + int i; > + > + if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE) > + return -EINVAL; > + > + out = ec_dev->dout; > + out[0] = EC_CMD_VERSION0 + msg->version; > + out[1] = msg->command; > + out[2] = msg->outsize; > + csum = out[0] + out[1] + out[2]; > + for (i = 0; i < msg->outsize; i++) > + csum += out[EC_MSG_TX_HEADER_BYTES + i] = msg->data[i]; > + out[EC_MSG_TX_HEADER_BYTES + msg->outsize] = csum; > + > + return EC_MSG_TX_PROTO_BYTES + msg->outsize; > +} > + > static int send_command(struct cros_ec_device *ec_dev, > struct cros_ec_command *msg) > { > @@ -161,35 +183,18 @@ static int send_command(struct cros_ec_device *ec_dev, > * @ec_dev: Device to register. > * @msg: Message to write. > * > - * This is intended to be used by all ChromeOS EC drivers, but at present > - * only SPI uses it. Once LPC uses the same protocol it can start using it. > - * I2C could use it now, with a refactor of the existing code. > + * This is used by all ChromeOS EC drivers to prepare the outgoing message > + * according to different protocol versions. > * > * Return: number of prepared bytes on success or negative error code. > */ > int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, > struct cros_ec_command *msg) > { > - u8 *out; > - u8 csum; > - int i; > - > if (ec_dev->proto_version > 2) > - return prepare_packet(ec_dev, msg); > - > - if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE) > - return -EINVAL; > - > - out = ec_dev->dout; > - out[0] = EC_CMD_VERSION0 + msg->version; > - out[1] = msg->command; > - out[2] = msg->outsize; > - csum = out[0] + out[1] + out[2]; > - for (i = 0; i < msg->outsize; i++) > - csum += out[EC_MSG_TX_HEADER_BYTES + i] = msg->data[i]; > - out[EC_MSG_TX_HEADER_BYTES + msg->outsize] = csum; > + return prepare_tx(ec_dev, msg); > > - return EC_MSG_TX_PROTO_BYTES + msg->outsize; > + return prepare_tx_legacy(ec_dev, msg); > } > EXPORT_SYMBOL(cros_ec_prepare_tx); > > -- > 2.36.0.550.gb090851708-goog >