Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp721691lqb; Wed, 29 May 2024 08:42:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVU/JlJfk03bQzcQP5CmchS6I72LdYH2doBvHvyNb5uf9KXFEtN6QxKdFX9O/6aHl66yoBmHanSTpmITFXdfDdR4IrsY4BLustBwI7Shw== X-Google-Smtp-Source: AGHT+IHFfDdIJJE/zlj3OVLzr2oGGVfuLy0Dur34oL5CKjTfMTb42gZx1eyd4ChTolcOnKg6d8BV X-Received: by 2002:a17:90a:db17:b0:2c0:29d5:3515 with SMTP id 98e67ed59e1d1-2c029d53638mr2907955a91.3.1716997334241; Wed, 29 May 2024 08:42:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716997334; cv=pass; d=google.com; s=arc-20160816; b=fnpmjwre/0zjRp5Nj6WlEaGDUEXqWPoxqNLVC/75G8F08d3+u39uGX/IKY128f3/WL qrTGuaDZBoZLcNfkOMp6jCNSo9pie9blm9TCbW9HFS3XM9WoNBI1X/ft50Fc9RdrZq56 uTC92Cs0dsA4JydH9T/mVlGjm2Tbkoe8BOLuLsY3afJLDQmoBydfV3aM6cyzwf6hrRzv L6wbMGoDGVqql0mXWXx/WCv9GI1BNvtWmtlhAojFArYksHKNSHX2yaX/j8rNvrFTsBNE PhLIRn4o+QdV4BVS+rtLzRf22xZtTzcMp7Vf+R7QX0lMfN5cyVExq0JSrrXz5XJfWTB4 vyog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=b4HbbIwVhQ8OurjkPgt7eXPYfY1OZfSmqAUwwAgEnTI=; fh=5YjtBB6LhqA2XTMdeSBMbh1T8GOfqb/ovhtcBI77Oec=; b=z2s9Vop2tMheim54dz7ZRi2Uw9Nw9cTjkuSjeI3Ow6rBWGh9hhf+tgzur8KSnDwa44 VZnczSwS947I2zS9Ju/ESynJLrcakugl5VmS0124ygn+mfywuAbjTzJ+ZdqOTLX1+eqn 3P9nhGPnw/egfUvpdNb9cPPHNC/zxNwypzYm37UP7WrQackjyPFWW97n0LiR0UEjZpjE 91Abcl5BO+Das7uekWaiRbTIaJDiR0Ux+NqzOjylXFoxmsOl6CenRU74jX3qPinISr3o 5hQHYOyWhXWgaBL4/N72C4O/o5KFABU2dweEfdyCNpJ5TxTjuclElvb0CRGrMPG9IxIH 59Tg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xPLZa1jp; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-194375-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194375-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bff4595a46si4716261a91.163.2024.05.29.08.42.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 08:42:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194375-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xPLZa1jp; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-194375-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194375-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BA1202876CE for ; Wed, 29 May 2024 15:42:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 154BE181D15; Wed, 29 May 2024 15:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xPLZa1jp" Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B5BB181334 for ; Wed, 29 May 2024 15:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716997307; cv=none; b=QeQhqUZ2i0sBY2jp5RVd9PV2RvMOxtTxwdny8PD4ShQ4a6qI0QPK7QoTKKrUceZQsnX2QpH0TehzFl8inYUHc3jpPaO9WHyO8Ms5yxjQII1bgHJa1enPwuD+MUDWrEoBjeGAIsxaF8Yd23fekwKqw34O4S81TtzKHZrJ6IWAjkE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716997307; c=relaxed/simple; bh=6y1oCo4DKqnvTKrWAni22CK+MS7HQ51Og7J50Sv/9XA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dRpecLln5iCG4CzfIBXipHU3cSq8Ti9rSYoWkqADBHTREjmggC1T1bvktD9QpLz2PoUComyr18TFb5fC82zBouRJTV1Z4JQ9+mBOkf9Cji050GW5Y68wh/RIXV5tkuQtM2+PFH15Y3+ljpHGK9+3gqLV8xFlBI6TIZvs+OM27LA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=xPLZa1jp; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3550134ef25so2149335f8f.1 for ; Wed, 29 May 2024 08:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716997303; x=1717602103; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=b4HbbIwVhQ8OurjkPgt7eXPYfY1OZfSmqAUwwAgEnTI=; b=xPLZa1jpZnbDDLPJXbcxOcZnFG9NrtGT36cYfiBfCJ7RQMrRGjNdeLIXXpzeITYu5K d+VHBNzphr3I8toFvHS7jYFijG7fSxRFFlu52OhYk/OyM1GujpSZDF2LqQU1FfVv2060 QmjI5ZbMdvei0svyl/xDbFvKCoCngyMq2JD+g55zRvVnn9tGptUy/A562k6qwCYy/7Ek X1+fC2omcAC6JOGosfdntSxbnJePpPm+8gXF9QVGPo5jgDh+98n3fXjg4CM2h9ROVWtb GuYBPLMCtWvj4y+haNIzbtpIYD4V9nMT/v5pUeGVLmlVvgO8AvAM06fQ6Cbru62/QVqx 83Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716997303; x=1717602103; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=b4HbbIwVhQ8OurjkPgt7eXPYfY1OZfSmqAUwwAgEnTI=; b=w4VRxOE9unG4k+u9qHYcAOQs2UgIFEKx07GzssZxVJ8M0GGYYTH2RTmBZvfIOj08lO udPWG/bVPFqZ2I8HvuZ3lQ6aKHXu9di6EGRvOhNWWa6Y2wSlaq31VOvI7bpkbby9bpfY seNqHT3ye4exh0k2Vu2pPtLNzIn2DfQHCSaq+H3ypk9e/s9lWNgIKficrXmdotNIiOTF /tGiFYv2qfgVexbP+IFGeIKkJBT8JWqPbd3I/3YMtx337vCPk0PAKEZzUc3AURn/VQRs XVH/CQ7OU1vplRQQYScDrXqnnQm5lre+psSwptfhKsv8e3MVemFu0Ca17FVqCgl+Pr0f W2Ug== X-Forwarded-Encrypted: i=1; AJvYcCVVUSHFS6ccfJES3naclrQLZx6fxGgJ7GTXDLZzYxp8zpLWN2AdjN3fdhxCGmm1eKMrAgr8J5N20dRjYhSPhR0QVuNnubBXaUTTjXWK X-Gm-Message-State: AOJu0Ywv8kXnZVvBlhFUftbAFjNZ/DSlPmu2jhh7J61g517EUGHaJ+Pq r9RdYvLnVPOvGVNF7ix7uouuXHQC0uUk9Q1zyY0cQ5lMeuCDM9LgyzCuQgteDtY= X-Received: by 2002:a5d:518a:0:b0:354:f4e6:f9cd with SMTP id ffacd0b85a97d-35526c34337mr12265772f8f.17.1716997302847; Wed, 29 May 2024 08:41:42 -0700 (PDT) Received: from [192.168.0.3] ([176.61.106.227]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a1c9303sm15266075f8f.88.2024.05.29.08.41.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 May 2024 08:41:42 -0700 (PDT) Message-ID: Date: Wed, 29 May 2024 16:41:40 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/6] usb: typec: ucsi: add Lenovo Yoga C630 glue driver To: Dmitry Baryshkov , Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Hans de Goede , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , Heikki Krogerus , Greg Kroah-Hartman , Konrad Dybcio Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org, Nikita Travkin References: <20240528-yoga-ec-driver-v4-0-4fa8dfaae7b6@linaro.org> <20240528-yoga-ec-driver-v4-3-4fa8dfaae7b6@linaro.org> Content-Language: en-US From: Bryan O'Donoghue In-Reply-To: <20240528-yoga-ec-driver-v4-3-4fa8dfaae7b6@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 28/05/2024 21:44, Dmitry Baryshkov wrote: > The Lenovo Yoga C630 WOS laptop provides implements UCSI interface in > the onboard EC. Add glue driver to interface the platform's UCSI > implementation. > > Signed-off-by: Dmitry Baryshkov > --- > drivers/usb/typec/ucsi/Kconfig | 9 ++ > drivers/usb/typec/ucsi/Makefile | 1 + > drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 189 ++++++++++++++++++++++++++++++++ > 3 files changed, 199 insertions(+) > > diff --git a/drivers/usb/typec/ucsi/Kconfig b/drivers/usb/typec/ucsi/Kconfig > index bdcb1764cfae..680e1b87b152 100644 > --- a/drivers/usb/typec/ucsi/Kconfig > +++ b/drivers/usb/typec/ucsi/Kconfig > @@ -69,4 +69,13 @@ config UCSI_PMIC_GLINK > To compile the driver as a module, choose M here: the module will be > called ucsi_glink. > > +config UCSI_LENOVO_YOGA_C630 > + tristate "UCSI Interface Driver for Lenovo Yoga C630" > + depends on EC_LENOVO_YOGA_C630 > + help > + This driver enables UCSI support on the Lenovo Yoga C630 laptop. > + > + To compile the driver as a module, choose M here: the module will be > + called ucsi_yoga_c630. > + > endif > diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile > index b4679f94696b..aed41d23887b 100644 > --- a/drivers/usb/typec/ucsi/Makefile > +++ b/drivers/usb/typec/ucsi/Makefile > @@ -21,3 +21,4 @@ obj-$(CONFIG_UCSI_ACPI) += ucsi_acpi.o > obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o > obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o > obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o > +obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o > diff --git a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c > new file mode 100644 > index 000000000000..ca1ab5c81b87 > --- /dev/null > +++ b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c > @@ -0,0 +1,189 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2022-2024, Linaro Ltd > + * Authors: > + * Bjorn Andersson > + * Dmitry Baryshkov > + */ > +#include > +#include > +#include > + > +#include "ucsi.h" > + > +struct yoga_c630_ucsi { > + struct yoga_c630_ec *ec; > + struct ucsi *ucsi; > + struct notifier_block nb; > + struct completion complete; > + unsigned long flags; > +#define UCSI_C630_COMMAND_PENDING 0 > +#define UCSI_C630_ACK_PENDING 1 > + u16 version; > +}; > + > +static int yoga_c630_ucsi_read(struct ucsi *ucsi, unsigned int offset, > + void *val, size_t val_len) > +{ > + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); > + u8 buf[YOGA_C630_UCSI_READ_SIZE]; > + int ret; > + > + ret = yoga_c630_ec_ucsi_read(uec->ec, buf); > + if (ret) > + return ret; > + > + if (offset == UCSI_VERSION) { > + memcpy(val, &uec->version, min(val_len, sizeof(uec->version))); > + return 0; > + } > + > + if (offset == UCSI_CCI) > + memcpy(val, buf, > + min(val_len, YOGA_C630_UCSI_CCI_SIZE)); > + else if (offset == UCSI_MESSAGE_IN) > + memcpy(val, buf + YOGA_C630_UCSI_CCI_SIZE, > + min(val_len, YOGA_C630_UCSI_DATA_SIZE)); For some reason I believe multi-lines like this, including function calls that are split over lines should be encapsulated with {} else if(x) { memcpy(x,y, z); } If checkpatch doesn't complain about it feel free not to do that though. > + else > + return -EINVAL; > + > + return 0; > +} > + > +static int yoga_c630_ucsi_async_write(struct ucsi *ucsi, unsigned int offset, > + const void *val, size_t val_len) > +{ > + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); > + > + if (offset != UCSI_CONTROL || > + val_len != YOGA_C630_UCSI_WRITE_SIZE) > + return -EINVAL; > + > + return yoga_c630_ec_ucsi_write(uec->ec, val); > +} > + > +static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, > + const void *val, size_t val_len) > +{ > + struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); > + bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; > + int ret; > + > + if (ack) > + set_bit(UCSI_C630_ACK_PENDING, &uec->flags); > + else > + set_bit(UCSI_C630_COMMAND_PENDING, &uec->flags); > + > + reinit_completion(&uec->complete); > + > + ret = yoga_c630_ucsi_async_write(ucsi, offset, val, val_len); > + if (ret) > + goto out_clear_bit; > + > + if (!wait_for_completion_timeout(&uec->complete, 5 * HZ)) > + ret = -ETIMEDOUT; > + > +out_clear_bit: > + if (ack) > + clear_bit(UCSI_C630_ACK_PENDING, &uec->flags); > + else > + clear_bit(UCSI_C630_COMMAND_PENDING, &uec->flags); > + > + return ret; > +} > + > +const struct ucsi_operations yoga_c630_ucsi_ops = { > + .read = yoga_c630_ucsi_read, > + .sync_write = yoga_c630_ucsi_sync_write, > + .async_write = yoga_c630_ucsi_async_write, > +}; > + > +static int yoga_c630_ucsi_notify(struct notifier_block *nb, > + unsigned long action, void *data) > +{ > + struct yoga_c630_ucsi *uec = container_of(nb, struct yoga_c630_ucsi, nb); > + u32 cci; > + int ret; > + > + if (action == LENOVO_EC_EVENT_USB || action == LENOVO_EC_EVENT_HPD) { > + ucsi_connector_change(uec->ucsi, 1); > + return NOTIFY_OK; > + } > + > + if (action != LENOVO_EC_EVENT_UCSI) > + return NOTIFY_DONE; Is this disjunction on action a good candidate for a switch(){} > + > + ret = uec->ucsi->ops->read(uec->ucsi, UCSI_CCI, &cci, sizeof(cci)); > + if (ret) > + return NOTIFY_DONE; > + > + if (UCSI_CCI_CONNECTOR(cci)) > + ucsi_connector_change(uec->ucsi, UCSI_CCI_CONNECTOR(cci)); > + > + if (cci & UCSI_CCI_ACK_COMPLETE && > + test_bit(UCSI_C630_ACK_PENDING, &uec->flags)) > + complete(&uec->complete); > + if (cci & UCSI_CCI_COMMAND_COMPLETE && > + test_bit(UCSI_C630_COMMAND_PENDING, &uec->flags)) > + complete(&uec->complete); IMO these multi-line clauses should end up with a {} around the complete even though its not required. Emphasis on the O. Reviewed-by: Bryan O'Donoghue