Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp493268lqb; Wed, 29 May 2024 01:41:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUbjCC5dlSDmao7TCbk/+YUfk3tZrDfecc0nVljWCy0O5gIM/41F2ZJfwTmOOXwGrthEJV06ixEpn9vplu7zpg4xyk4cuxS1yerIiMwAg== X-Google-Smtp-Source: AGHT+IE/Z/ZnnJs8xzKu5gmBKl1bfVEkCebt1jo/bnTOtY8SRflH0Q0Iq1/cKn10uDzcbd7JY4Me X-Received: by 2002:a05:6a20:321b:b0:1af:af86:ce47 with SMTP id adf61e73a8af0-1b259a4d868mr1992003637.14.1716972086840; Wed, 29 May 2024 01:41:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716972086; cv=pass; d=google.com; s=arc-20160816; b=nKWgXRKTj+TqsV5yUlSaht6aWesDUI6ZVQk8EFZm9VAj9UKRQzBcrSVzXk0JebUqEx bkwPczhtogUe3LpnWZkCW03VEl/kfowOjFoeGVBCAW0ZpxAZZEMobNMUaJt+uHca/XWp eDd7AtzywpNT1hRTTy1csfTX2zhbCZWORrGHhqlh0ve8Ltx+mmlW8mtnfPunq4NHoYrF 4fbJieqW1i/2vKmIzL78ZM08HcH7M5vtw/CYBprVBuT4pJHIlBLGuyESziQtUZ76GEr4 S//6NJrbV00ZNtc/RTcI66MPpk1qNaHMVve50+GLjhGPYYv9Tc5WRkRCIMBhqTItwgSH x9fQ== 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=a/JqdadxOtCgPk5Z92J6Iz23Jf3+Y16joj23RLu5HX0=; fh=OyDmguPyLiF3XvVbJVHccolgcUzxcygiaS/bQl8GzoM=; b=GPPnj9VQ8iNdjaw6mXvgCeE5PK06jFiFryPvRDW8nBYQ4xs1+3dRshYoy0fCIVSFKN ijvYYNTfj55NVhnLlRbZE6xynJnvxpFga8p/k5KpEmrj250XqUFflp54n/bYK7V4yPRJ kMcR3AkPQ6wYJTgDMb4ZZ6XV/odSVkt0lq1TGqH2lLgyoi3Nu1Ga1eT7gONEFHoldtxi G1Z/9QOnW8qH77osE15G0/6sGITkA7nUzm4orsDMcnTV0CBf1REzgFDbeKSwSrcNmgxT 901LHTil92TWbEKd9x6IfUwymCttWZpiCZkKdPvOrRZSC/ls3g5PLVCiDnkbKMfoMCI0 nu1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UEqCNGs+; 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-193698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-68221b73bcesi9719134a12.90.2024.05.29.01.41.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 01:41:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UEqCNGs+; 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-193698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193698-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CB0BBB2997E for ; Wed, 29 May 2024 08:18:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F3BD181324; Wed, 29 May 2024 08:08:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UEqCNGs+" Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 750D018131C for ; Wed, 29 May 2024 08:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716970124; cv=none; b=BApt6IYjhCBp3VnT4mu8LMPDr1dMywrMLeP2rav8hyYEi7zCreCZMUXIRrmMUQj8qoBdgUs/zEND+68SPq8d3Yw6PPOM+goIk/29/ekVjGUdDhEx81LmB8UPLfdLPCOnaqylbDXOpFNBqH6EYgQ4pzkkOwitYPWvRbfsx0KstiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716970124; c=relaxed/simple; bh=T3LsNDsQjui6zBSWsbGtzYkzQN8h8gfwvEMkMXJ//Qw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ovJuhBXIKKtP1smQhKj/MdX4aphQ7qx8IXAuKXDZ9EZUDLKqnOhiO57AWYlPU9vlY7XoHjNChjNpiDt1d+h19xz5flSq+Nne7sZ5if/vb0DGJi8Nwf2XdcN58wb64XpCLmOLr4Z60v0iA5+f6KoVDpYtyQPAzsWCd6gCFU9VGAA= 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=UEqCNGs+; arc=none smtp.client-ip=209.85.128.52 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-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42108739ed8so21231905e9.0 for ; Wed, 29 May 2024 01:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716970121; x=1717574921; 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=a/JqdadxOtCgPk5Z92J6Iz23Jf3+Y16joj23RLu5HX0=; b=UEqCNGs+fNHoYv50zpSrTx/PiSv4obl+HDUKrrSNy4QdgzTjjO2e7nGSFuzJfkxQni sQtcbBmcwYQvL2Kd0uwlR3YggHK/S1eouMJ6a/vkgJdjc2QQVxVhaMcpxuR2keWz5gkM 4VuqMiXAmfO/hsvoA0Tk3rTSV+DA/O6pSzypolQT/wi99XnRs/xjYcS9cVFIw56oOG0Q WvxsKzby+xQKRyD8C5oQWzoFMk9vbcvWpRH0YEEEkVezx9U/ldTn5Pi8r8xuGZDeiR2v +161X7nuHqgGEy5L3vlLqQUsfuo42cxHzVI6w7TKe9unRrIaRm8vnLgyFnVuRNi9/2x8 iCRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716970121; x=1717574921; 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=a/JqdadxOtCgPk5Z92J6Iz23Jf3+Y16joj23RLu5HX0=; b=BMM2QLNHzGpxhxA77EUkv7ao/90ktxGoSRnIXm2wmJ3MkXaR4Xx8qQDlHUIOL+F228 DKRNUcVjfonepV+2+cnb2ltwFCY+ExF3UHJ6HLBThn+JKMrYWSj6PSZA6p+Oha29449A RfmYG58yZpLQ0Bj3Ev2JXWWzUBwS0LnvRXjHKDSdBPyBaMwuWo4hFJ0grsOJ+1VDPyhL Titd5wsqV4b+qP5Sz7oMKYg3SDEaprZxRPOHh8xYIzMnpVbzvq1e3pDLLDIFUkLI90+M A6PhTuq5SgFignQGYqvP8jh+ow3S6pdyCDfRNnkUnwzx9nq6VGqJtrKhB5O76k4Gdqzw raaw== X-Forwarded-Encrypted: i=1; AJvYcCWGlVa3zBLgGasMDX56RodUcWwQXswzh9oHdeO5YLR3qASO1x8SaJ6RwJY8Kti/UXcMRZadSxFhvYGQkaut1D2TQDa4Fzk2DxNuYZ4F X-Gm-Message-State: AOJu0YyKpGWxWrlX84zm9vICWigH6LCASGMWpMPFJlWQlARDZX/NZzO4 WLNFE9HDeJGJfWkTL8jqWerAu6AnC/ajwNvARzFs0YuTsA/6LVs/nZNmH2T4vnU= X-Received: by 2002:a05:600c:5354:b0:420:f8:23d6 with SMTP id 5b1f17b1804b1-42108aa7589mr151469755e9.36.1716970120703; Wed, 29 May 2024 01:08:40 -0700 (PDT) Received: from [192.168.0.3] ([176.61.106.227]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a090366sm13891799f8f.56.2024.05.29.01.08.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 May 2024 01:08:40 -0700 (PDT) Message-ID: <0f337380-4e43-4ed4-aa05-0c7072ecd112@linaro.org> Date: Wed, 29 May 2024 09:08:38 +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 2/6] platform: arm64: add Lenovo Yoga C630 WOS EC driver To: Dmitry Baryshkov Cc: 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 , 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-2-4fa8dfaae7b6@linaro.org> <2b76f27e-f223-4ff9-880e-9e232ce9ddc6@linaro.org> <3gbjbuav5l2td5xrfj46krhgdew42medhfrnkd47iahdv4fm3x@qv6jadf6tkol> Content-Language: en-US From: Bryan O'Donoghue In-Reply-To: <3gbjbuav5l2td5xrfj46krhgdew42medhfrnkd47iahdv4fm3x@qv6jadf6tkol> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 29/05/2024 00:56, Dmitry Baryshkov wrote: > On Wed, May 29, 2024 at 12:51:04AM +0100, Bryan O'Donoghue wrote: >> On 28/05/2024 21:44, Dmitry Baryshkov wrote: >>> Lenovo Yoga C630 WOS is a laptop using Snapdragon 850 SoC. Like many >>> laptops it uses embedded controller (EC) to perform various platform >> >> an embedded controller >> >>> operations, including, but not limited, to Type-C port control or power >>> supply handlng. >>> >>> Add the driver for the EC, that creates devices for UCSI and power >>> supply devices. >>> >>> Signed-off-by: Dmitry Baryshkov >>> --- >>> drivers/platform/arm64/Kconfig | 14 ++ >>> drivers/platform/arm64/Makefile | 1 + >>> drivers/platform/arm64/lenovo-yoga-c630.c | 279 +++++++++++++++++++++++++ >>> include/linux/platform_data/lenovo-yoga-c630.h | 42 ++++ >>> 4 files changed, 336 insertions(+) >>> >>> diff --git a/drivers/platform/arm64/Kconfig b/drivers/platform/arm64/Kconfig >>> index 8fdca0f8e909..8c103b3150d1 100644 >>> --- a/drivers/platform/arm64/Kconfig >>> +++ b/drivers/platform/arm64/Kconfig >>> @@ -32,4 +32,18 @@ config EC_ACER_ASPIRE1 >>> laptop where this information is not properly exposed via the >>> standard ACPI devices. >>> +config EC_LENOVO_YOGA_C630 >>> + tristate "Lenovo Yoga C630 Embedded Controller driver" >>> + depends on I2C >>> + help >>> + Driver for the Embedded Controller in the Qualcomm Snapdragon-based >>> + Lenovo Yoga C630, which provides battery and power adapter >>> + information. >>> + >>> + This driver provides battery and AC status support for the mentioned >>> + laptop where this information is not properly exposed via the >>> + standard ACPI devices. >>> + >>> + Say M or Y here to include this support. >>> + >>> endif # ARM64_PLATFORM_DEVICES >>> diff --git a/drivers/platform/arm64/Makefile b/drivers/platform/arm64/Makefile >>> index 4fcc9855579b..b2ae9114fdd8 100644 >>> --- a/drivers/platform/arm64/Makefile >>> +++ b/drivers/platform/arm64/Makefile >>> @@ -6,3 +6,4 @@ >>> # >>> obj-$(CONFIG_EC_ACER_ASPIRE1) += acer-aspire1-ec.o >>> +obj-$(CONFIG_EC_LENOVO_YOGA_C630) += lenovo-yoga-c630.o >>> diff --git a/drivers/platform/arm64/lenovo-yoga-c630.c b/drivers/platform/arm64/lenovo-yoga-c630.c >>> new file mode 100644 >>> index 000000000000..3d1d5acde807 >>> --- /dev/null >>> +++ b/drivers/platform/arm64/lenovo-yoga-c630.c >>> @@ -0,0 +1,279 @@ >>> +// SPDX-License-Identifier: GPL-2.0-only >>> +/* >>> + * Copyright (c) 2022-2024, Linaro Ltd >>> + * Authors: >>> + * Bjorn Andersson >>> + * Dmitry Baryshkov >>> + */ >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> + >>> +#define LENOVO_EC_RESPONSE_REG 0x01 >>> +#define LENOVO_EC_REQUEST_REG 0x02 >>> + >>> +#define LENOVO_EC_UCSI_WRITE 0x20 >>> +#define LENOVO_EC_UCSI_READ 0x21 >>> + >>> +#define LENOVO_EC_READ_REG 0xb0 >>> +#define LENOVO_EC_REQUEST_NEXT_EVENT 0x84 >>> + >>> +struct yoga_c630_ec { >>> + struct i2c_client *client; >>> + struct mutex lock; >>> + struct blocking_notifier_head notifier_list; >>> +}; >>> + >>> +static int yoga_c630_ec_request(struct yoga_c630_ec *ec, u8 *req, size_t req_len, >>> + u8 *resp, size_t resp_len) >>> +{ >>> + int ret; >>> + >>> + WARN_ON(!mutex_is_locked(&ec->lock)); >>> + >>> + ret = i2c_smbus_write_i2c_block_data(ec->client, LENOVO_EC_REQUEST_REG, >>> + req_len, req); >>> + if (ret < 0) >>> + return ret; >>> + >>> + return i2c_smbus_read_i2c_block_data(ec->client, LENOVO_EC_RESPONSE_REG, >>> + resp_len, resp); >>> +} >>> + >>> +int yoga_c630_ec_read8(struct yoga_c630_ec *ec, u8 addr) >>> +{ >>> + u8 req[2] = { LENOVO_EC_READ_REG, }; >>> + int ret; >>> + u8 val; >>> + >>> + mutex_lock(&ec->lock); >>> + req[1] = addr; >>> + ret = yoga_c630_ec_request(ec, req, sizeof(req), &val, 1); >>> + mutex_unlock(&ec->lock); >>> + >>> + return ret < 0 ? ret : val; >>> +} >>> +EXPORT_SYMBOL_GPL(yoga_c630_ec_read8); >>> + >>> +int yoga_c630_ec_read16(struct yoga_c630_ec *ec, u8 addr) >>> +{ >>> + u8 req[2] = { LENOVO_EC_READ_REG, }; >>> + int ret; >>> + u8 msb; >>> + u8 lsb; >>> + >>> + mutex_lock(&ec->lock); >>> + >>> + req[1] = addr; >>> + ret = yoga_c630_ec_request(ec, req, sizeof(req), &lsb, 1); >>> + if (ret < 0) >>> + goto out; >>> + >>> + req[1] = addr + 1; >>> + ret = yoga_c630_ec_request(ec, req, sizeof(req), &msb, 1); >>> + >>> +out: >>> + mutex_unlock(&ec->lock); >>> + >>> + return ret < 0 ? ret : msb << 8 | lsb; >>> +} >>> +EXPORT_SYMBOL_GPL(yoga_c630_ec_read16); >>> + >>> +u16 yoga_c630_ec_ucsi_get_version(struct yoga_c630_ec *ec) >>> +{ >>> + u8 req[3] = { 0xb3, 0xf2, 0x20}; >> >> You have a define above for the read_reg and write_reg commands, could you >> not define 0xb3 as LENOVO_EC_GET_VERSION ? >> >> All of the other commands here seem to have a named define. > > Because unlike other registers it is not clear what other use cases does > 0xb3 support > >> >>> + int ret; >>> + u8 msb; >>> + u8 lsb; >>> + >>> + mutex_lock(&ec->lock); >>> + ret = yoga_c630_ec_request(ec, req, sizeof(req), &lsb, 1); >>> + if (ret < 0) >>> + goto out; >>> + >>> + req[2]++; >> >> why not set reg[2] = 0x21; > > ack > >> >> also is req[2] some kind of address ? > > Unfortunately no idea. This is totally based on the AML code in DSDT. I > have no documentation on the EC or its programming interface. > >> >>> + ret = yoga_c630_ec_request(ec, req, sizeof(req), &msb, 1); >>> + >>> +out: >>> + mutex_unlock(&ec->lock); >>> + >>> + return ret < 0 ? ret : msb << 8 | lsb; >>> +} >>> +EXPORT_SYMBOL_GPL(yoga_c630_ec_ucsi_get_version); >>> + >>> +int yoga_c630_ec_ucsi_write(struct yoga_c630_ec *ec, >>> + const u8 req[YOGA_C630_UCSI_WRITE_SIZE]) >>> +{ >>> + int ret; >>> + >>> + mutex_lock(&ec->lock); >>> + ret = i2c_smbus_write_i2c_block_data(ec->client, LENOVO_EC_UCSI_WRITE, >>> + YOGA_C630_UCSI_WRITE_SIZE, req); >>> + mutex_unlock(&ec->lock); >>> + >>> + return ret < 0 ? ret : 0; >>> +} >>> +EXPORT_SYMBOL_GPL(yoga_c630_ec_ucsi_write); >>> + >>> +int yoga_c630_ec_ucsi_read(struct yoga_c630_ec *ec, >>> + u8 resp[YOGA_C630_UCSI_READ_SIZE]) >>> +{ >>> + int ret; >>> + >>> + mutex_lock(&ec->lock); >>> + ret = i2c_smbus_read_i2c_block_data(ec->client, LENOVO_EC_UCSI_READ, >>> + YOGA_C630_UCSI_READ_SIZE, resp); >>> + mutex_unlock(&ec->lock); >>> + >>> + return ret < 0 ? ret : 0; >>> +} >>> +EXPORT_SYMBOL_GPL(yoga_c630_ec_ucsi_read); >>> + >>> +static irqreturn_t yoga_c630_ec_intr(int irq, void *data) >>> +{ >>> + u8 req[] = { LENOVO_EC_REQUEST_NEXT_EVENT }; >>> + struct yoga_c630_ec *ec = data; >>> + u8 event; >>> + int ret; >>> + >>> + mutex_lock(&ec->lock); >>> + ret = yoga_c630_ec_request(ec, req, sizeof(req), &event, 1); >>> + mutex_unlock(&ec->lock); >>> + if (ret < 0) >>> + return IRQ_HANDLED; >>> + >>> + pr_info("NOTIFY %x\n", event); >> >> why not dev_info() ? > > Argh, debugging code. I should drop it. > Assuming you do all of that in v5 Reviewed-by: Bryan O'Donoghue