From patchwork Mon Nov 18 09:33:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sung-Chi Li X-Patchwork-Id: 13878324 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 E309A191F79 for ; Mon, 18 Nov 2024 09:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731922448; cv=none; b=hYEygHQ3IeDocJJfnb/r79xcpOo09UKJe1CG/D5+eLuE1/NqgJVzV4L4iUXgxXgmTQD+LJ8J3e19CapIalrXMUdTXm05Xv4cX4vu8vbQOWONC7bQ7gSlX4hBn5fzDGHi/R7ncGP7ZBROy7jH0MxEaVaDC+9k+rOsy/JPowIpOuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731922448; c=relaxed/simple; bh=mr78STc32F6NVAyA04kXqtWn3/4JDgdZRTo0Intr1/Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fAsx0wtzbYim4SiJqeycYs0azl/4p70mzOTJ4+ZZYw3HwADKlKHRg9/26/kAn204z0+0MeHh0Xs8aEXhjUCvydzLZOfWAl9WPrCfo9gY6IJpSuL26AqT3vcui0tnvDaf6oF/ikch1t2ucwtuq2RgHAltDUCK+QpLCjiP9RxIuIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=mKeu0jMZ; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mKeu0jMZ" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7ea9739647bso2827712a12.0 for ; Mon, 18 Nov 2024 01:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731922445; x=1732527245; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ks7+zAh8GlNof48UsfJ+LdfKrIBWbtjlmTnt6P9ZM8Q=; b=mKeu0jMZ1wblrKZrypb3iS2fXqQXha8uAyco7ZexeZ5V/Zec8c2bfOMHrppt/gt3kq 4sfsZrYWTY4p+eAcZd20GqupJk17GgvbssbhJsiO4XUY/qKyZRWc0BCw5m4IDXVQcOTb 5S56JAIe6rwED9HF/W3VheNWbp/1FzWAbynP8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731922445; x=1732527245; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ks7+zAh8GlNof48UsfJ+LdfKrIBWbtjlmTnt6P9ZM8Q=; b=Azxras+V6JdyBCMBC77maripS7CCk45Hx+UNSNLpKOrggD7suEO0CCNUpBtN+as3pO XXx6dkGyf274GSkXPQd2b8+R+rvnvlJtuFBsmBU1pGZsBuKvhawrmP5c4pbFMzz6sDA4 B9Bpq9MLRmT0EktXn7wE9/y/bCGOciz7TpTabc6ychk3c4xosWNRERL6GnvDxLBhTCtY 4pvAPB4QnlyhOAqv0Ww+aQ/1bS18Z34ik2rEiu/5iCyN2UiYx1V7Q/8g5/KnyMUbk1th po3RN63qrStuTzZ2CTo1J6iJxLS5IlPuW/xn7xa6lJYsB5XrgS3ZbLoStBK8jV+zhXGS cftw== X-Forwarded-Encrypted: i=1; AJvYcCVCt8GhIGI7k5uZj6sCeg2AYh4O9Oi3lsbEj7MqPhRTIhEhmIBfttiCO7ovULopp8/hKTVddVMtF0B5yMgS/eQ=@lists.linux.dev X-Gm-Message-State: AOJu0Yz1unQyOhJWDyHFIJ7wXSocEquW3U/XlIqvDSGdTMwIocsoALIY lzWBwYlu1lTlnd1CxG5zsbFgGN+axrxQwsIJ3RYdtBmw2v7tYyXhVG0oU9D8kw== X-Google-Smtp-Source: AGHT+IEJfWkT4rx6TA0lmY/3l1SbBZlpAFbZZ+EhIEzl62OAA3Oe1rd4uNwXlwBQvP/WP4bn+OmVHg== X-Received: by 2002:a05:6a20:c896:b0:1dc:bdbd:9017 with SMTP id adf61e73a8af0-1dcbdbd91f4mr150236637.40.1731922445334; Mon, 18 Nov 2024 01:34:05 -0800 (PST) Received: from lschyi-p920.tpe.corp.google.com ([2401:fa00:1:10:e40d:fa29:75db:2caa]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9f1e24ce4sm8333500a91.0.2024.11.18.01.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 01:34:04 -0800 (PST) From: "Sung-Chi, Li" Date: Mon, 18 Nov 2024 17:33:46 +0800 Subject: [PATCH 1/3] platform/chrome: cros_ec_charge_state: add new driver to control charge Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241118-add_charger_state-v1-1-94997079f35a@chromium.org> References: <20241118-add_charger_state-v1-0-94997079f35a@chromium.org> In-Reply-To: <20241118-add_charger_state-v1-0-94997079f35a@chromium.org> To: Benson Leung , Tzung-Bi Shih , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lee Jones Cc: linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731922439; l=8745; i=lschyi@chromium.org; s=20241113; h=from:subject:message-id; bh=mr78STc32F6NVAyA04kXqtWn3/4JDgdZRTo0Intr1/Y=; b=6ULQoZs/+Ku8qgFPy2ll+3sbBufLGITxaWVjTEpjxIL63t2VI1Y0t3aFvm4E40JZQBd1AtoeV eG9syX/9SIPApVJKwygVB32YxlGxhGybsHb1hEf1sacGf5LwTgWwJGU X-Developer-Key: i=lschyi@chromium.org; a=ed25519; pk=nE3PJlqSK35GdWfB4oVLOwi4njfaUZRhM66HGos9P6o= Implement the new platform driver cros_ec_charge_state to have low finer control over the charge current flow through the charge chip connected on ChromeOS Embedded Controller (EC). The driver reads configured charge chip configurations from the device tree, and register these chip controls as thermal zone devices, so they are controllable from the thermal subsystem. As such, corresponding DTS changes are needed, and here is a sample DTS configuration: ``` &cros_ec { charge-chip-battery { compatible = "google,cros-ec-charge-state"; type = "charge"; min-milliamp = <150>; max-milliamp = <5000>; }; }; ``` Signed-off-by: Sung-Chi, Li --- drivers/platform/chrome/Kconfig | 11 ++ drivers/platform/chrome/Makefile | 1 + drivers/platform/chrome/cros_ec_charge_state.c | 215 +++++++++++++++++++++++++ 3 files changed, 227 insertions(+) diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 7dbeb786352a..34d00d8823cb 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -297,6 +297,17 @@ config CROS_TYPEC_SWITCH To compile this driver as a module, choose M here: the module will be called cros_typec_switch. +config CROS_CHARGE_STATE + tristate "ChromeOS EC Charger Chip Control" + depends on MFD_CROS_EC_DEV + default MFD_CROS_EC_DEV + help + If you say Y here, you get support for configuring the battery + charging and system input current. + + To compile this driver as a module, choose M here: the module will be + called cros-ec-charge-state. + source "drivers/platform/chrome/wilco_ec/Kconfig" # Kunit test cases diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index 2dcc6ccc2302..01c7154ae119 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_CROS_EC_SYSFS) += cros_ec_sysfs.o obj-$(CONFIG_CROS_HPS_I2C) += cros_hps_i2c.o obj-$(CONFIG_CROS_USBPD_LOGGER) += cros_usbpd_logger.o obj-$(CONFIG_CROS_USBPD_NOTIFY) += cros_usbpd_notify.o +obj-$(CONFIG_CROS_CHARGE_STATE) += cros_ec_charge_state.o obj-$(CONFIG_WILCO_EC) += wilco_ec/ diff --git a/drivers/platform/chrome/cros_ec_charge_state.c b/drivers/platform/chrome/cros_ec_charge_state.c new file mode 100644 index 000000000000..3fed5b48bc92 --- /dev/null +++ b/drivers/platform/chrome/cros_ec_charge_state.c @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Charge state driver for ChromeOS Embedded Controller + * + * Copyright 2024 Google LLC + * + * This driver exports the low level control over charge chip connected to EC + * which allows to manipulate the current used to charge the battery, and also + * manipulate the current input to the whole system. + * This driver also registers that charge chip as a thermal cooling device. + */ + +#include +#include +#include +#include +#include + +#define DRV_NAME "cros-ec-charge-state" +#define CHARGE_TYPE_CHARGE "charge" +#define CHARGE_TYPE_INPUT "input" + +struct cros_ec_charge_state_data { + struct cros_ec_device *ec_dev; + struct device *dev; + enum charge_state_params charge_type; + uint32_t min_milliamp; + uint32_t max_milliamp; +}; + +static int +cros_ec_charge_state_get_current_limit(struct cros_ec_device *ec_dev, + enum charge_state_params charge_type, + uint32_t *limit) +{ + struct ec_params_charge_state param; + struct ec_response_charge_state state; + int ret; + + param.cmd = CHARGE_STATE_CMD_GET_PARAM; + param.get_param.param = charge_type; + ret = cros_ec_cmd(ec_dev, 0, EC_CMD_CHARGE_STATE, ¶m, sizeof(param), + &state, sizeof(state)); + if (ret < 0) + return ret; + + *limit = cpu_to_le32(state.get_param.value); + return 0; +} + +static int +cros_ec_charge_state_set_current_limit(struct cros_ec_device *ec_dev, + enum charge_state_params charge_type, + uint32_t limit) +{ + struct ec_params_charge_state param; + int ret; + + param.cmd = CHARGE_STATE_CMD_SET_PARAM; + param.set_param.param = charge_type; + param.set_param.value = cpu_to_le32(limit); + ret = cros_ec_cmd(ec_dev, 0, EC_CMD_CHARGE_STATE, ¶m, sizeof(param), + NULL, 0); + return (ret < 0) ? ret : 0; +} + +static int +cros_ec_charge_state_get_max_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct cros_ec_charge_state_data *data = cdev->devdata; + *state = data->max_milliamp; + return 0; +} + +static int +cros_ec_charge_state_get_cur_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct cros_ec_charge_state_data *data = cdev->devdata; + uint32_t limit; + int ret; + + ret = cros_ec_charge_state_get_current_limit(data->ec_dev, + data->charge_type, &limit); + if (ret) { + dev_err(data->dev, "failed to get current state: %d", ret); + return ret; + } + + *state = data->max_milliamp - limit; + return 0; +} + +static int +cros_ec_charge_state_set_cur_state(struct thermal_cooling_device *cdev, + unsigned long state) +{ + struct cros_ec_charge_state_data *data = cdev->devdata; + uint32_t limit = data->max_milliamp - state; + + if (limit < data->min_milliamp) { + dev_warn( + data->dev, + "failed to set current %u lower than minimum %d; set to minimum", + limit, data->min_milliamp); + limit = data->min_milliamp; + } + + state = data->max_milliamp - limit; + return cros_ec_charge_state_set_current_limit( + data->ec_dev, data->charge_type, (uint32_t)state); +} + +static const struct thermal_cooling_device_ops + cros_ec_charge_state_cooling_device_ops = { + .get_max_state = cros_ec_charge_state_get_max_state, + .get_cur_state = cros_ec_charge_state_get_cur_state, + .set_cur_state = cros_ec_charge_state_set_cur_state, + }; + +static int +cros_ec_charge_state_register_charge_chip(struct device *dev, + struct device_node *node, + struct cros_ec_device *cros_ec) +{ + struct cros_ec_charge_state_data *data; + struct thermal_cooling_device *cdev; + const char *type_val = NULL; + int ret; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret = of_property_read_string(node, "type", &type_val); + if (ret) { + dev_err(dev, "failed to get charge type: %d", ret); + return ret; + } + + if (!strcmp(type_val, CHARGE_TYPE_CHARGE)) { + data->charge_type = CS_PARAM_CHG_CURRENT; + } else if (!strcmp(type_val, CHARGE_TYPE_INPUT)) { + data->charge_type = CS_PARAM_CHG_INPUT_CURRENT; + } else { + dev_err(dev, "unknown charge type: %s", type_val); + return -1; + } + + ret = of_property_read_u32(node, "min-milliamp", &data->min_milliamp); + if (ret) { + dev_err(dev, "failed to get min-milliamp data: %d", ret); + return ret; + } + + ret = of_property_read_u32(node, "max-milliamp", &data->max_milliamp); + if (ret) { + dev_err(dev, "failed to get max-milliamp data: %d", ret); + return ret; + } + + data->ec_dev = cros_ec; + data->dev = dev; + + cdev = devm_thermal_of_cooling_device_register( + dev, node, node->name, data, + &cros_ec_charge_state_cooling_device_ops); + if (IS_ERR_VALUE(cdev)) { + dev_err(dev, + "failed to register charge chip %s as cooling device: %pe", + node->name, cdev); + return PTR_ERR(cdev); + } + + return 0; +} + +static int cros_ec_charge_state_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent); + struct cros_ec_device *cros_ec = ec_dev->ec_dev; + struct device_node *child; + + for_each_available_child_of_node(cros_ec->dev->of_node, child) { + if (!of_device_is_compatible(child, + "google,cros-ec-charge-state")) + continue; + if (cros_ec_charge_state_register_charge_chip(dev, child, + cros_ec)) + continue; + } + + return 0; +} + +static const struct platform_device_id cros_ec_charge_state_id[] = { + { DRV_NAME, 0 }, + {} +}; + +static struct platform_driver cros_ec_chargedev_driver = { + .driver = { + .name = DRV_NAME, + }, + .probe = cros_ec_charge_state_probe, +}; + +module_platform_driver(cros_ec_chargedev_driver); + +MODULE_DEVICE_TABLE(platform, cros_ec_charge_state_id); +MODULE_DESCRIPTION("ChromeOS EC Charge State Driver"); +MODULE_AUTHOR("Sung-Chi, Li "); +MODULE_LICENSE("GPL"); From patchwork Mon Nov 18 09:33:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sung-Chi Li X-Patchwork-Id: 13878325 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 211F71925B3 for ; Mon, 18 Nov 2024 09:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731922450; cv=none; b=jx/xIvtLthtGxsuggNlPDGa4n9UOeH3SuBI1E5jAXBzX+Sp5LzkXfrDsUTMPSrlJ6kxIWhXat7AWAsrBueCyBRTZyN2+WlmLsC4evywduaGnUkNfvvQcwMRETkDO9SHst+ejxcd09+MdtgqN9KTO+GJYu8Evgv3ro30Nuz/0Q8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731922450; c=relaxed/simple; bh=oQBa+arFToImvygLUmykUiqwBnm+r3Jm6b2xiExq89A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iHo+AuzYZ4vxYUc4gJqIYG5mUN8/RBZmIylUN3V6rCq7Krmqwj36YXUTRP+SI76BBRjUUxaEjSL3QbeNQtFiOmaBz5atwszkNiqM9RyaxR80O0qy7Y0enbyzNLw/3pIirzGyqVBJAuk8m1Jc0v/E1J9woqtZZWtVzShhVraD+NQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=XL2tdxzv; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XL2tdxzv" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-71e52582cf8so1105679b3a.2 for ; Mon, 18 Nov 2024 01:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731922448; x=1732527248; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UHXQE/YkSfeFGTAAqcokg2A23ODQxbzC48wuYHeeOsM=; b=XL2tdxzvq5U3dgI8ngGJtUMpvNkBuLZjnh8TTO2A7Jj1GLcVaDRWsXDb59WWE0qBQ9 6yBgWNLb33BzpuFEnbWoyZUPi26ax1+5ofNl5c/QGNjtb9CJp81Qm1VBwBWvVhlB+ZaV 8af2E4GiXtz8fOFS8pxXTp89X53WUZxskOwNs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731922448; x=1732527248; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UHXQE/YkSfeFGTAAqcokg2A23ODQxbzC48wuYHeeOsM=; b=gn5eaiv7uBn74O/1kBaXO9TJULY4LRX1aMx1hCpcC4w28+ZYX0/dnv/pzIl1ijDmuq 2RqDFSWbp//Fa+sXWUvzcJG0uyZ2dvEa3HVzUstdimNlXMyaikFgsQkLJV9aFcsbq/yv pyiVbOa+xfdZp4wzzf4HE0EVzj76KC75ZF/8gi+S/DdUnKuY9kojMEedb39ZKs1Irr8u PMmOR0f6iGdqZQrEI/Ccq49L7FJroMENtzEOCc32lDnxOQEePEfRQMFxnB93gISJNVvw B3aMWo3IU9lSA5M2Kq8hSxVwuvOaoapU9cRV7kjGiscCbt/iklWMryTSEdUg8WCHfr1H VY2A== X-Forwarded-Encrypted: i=1; AJvYcCUBaEurWRDZjfPTQ8YccOPxy15aoh/c3CmnqzzktYephVUTjNRY5bR1rfopaJ+BNLdM7TcYXnl099c5bKPfQ3Q=@lists.linux.dev X-Gm-Message-State: AOJu0Yw/dT6x89R+XWF/pmgQ3gtOEj1d1tm4Ks3tLBs76oqpemAd3U31 6D5kJojsi6VjdLWp7BnxPOfY4iwiXtbL27tqf2IGc0XAkIoy5oM54lMhXkE/QQ== X-Google-Smtp-Source: AGHT+IG2sOF9mqpA9kM4EzBZ19VjQrlcYkQ8SMGZKqRzx8/+WwzPqwYlg+wjyo1LmGg63cIPu7qorQ== X-Received: by 2002:a05:6a20:7fa9:b0:1db:e9bc:1b1c with SMTP id adf61e73a8af0-1dc90bb3866mr15806642637.28.1731922447589; Mon, 18 Nov 2024 01:34:07 -0800 (PST) Received: from lschyi-p920.tpe.corp.google.com ([2401:fa00:1:10:e40d:fa29:75db:2caa]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9f1e24ce4sm8333500a91.0.2024.11.18.01.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 01:34:07 -0800 (PST) From: "Sung-Chi, Li" Date: Mon, 18 Nov 2024 17:33:47 +0800 Subject: [PATCH 2/3] dt-bindings: chrome: add new binding google,cros-ec-chrage-state Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241118-add_charger_state-v1-2-94997079f35a@chromium.org> References: <20241118-add_charger_state-v1-0-94997079f35a@chromium.org> In-Reply-To: <20241118-add_charger_state-v1-0-94997079f35a@chromium.org> To: Benson Leung , Tzung-Bi Shih , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lee Jones Cc: linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731922439; l=3165; i=lschyi@chromium.org; s=20241113; h=from:subject:message-id; bh=oQBa+arFToImvygLUmykUiqwBnm+r3Jm6b2xiExq89A=; b=0hwa6pWnShfMj5+1Y8nbF73R9eB01LMvqC0LFFyIM02SGd4i0fyCG/90SbVomYPRHIFQIKrSq W9v3H7Xh9w7DOhL9VIqxgvkH4oSz1CMwyOOjNMwi0Y9hSDb15MCQCZw X-Developer-Key: i=lschyi@chromium.org; a=ed25519; pk=nE3PJlqSK35GdWfB4oVLOwi4njfaUZRhM66HGos9P6o= Add new dt bindings for charge chip control. The charge chip control dt configuration is used by the driver 'cros-ec-charge-state', which is added in the commit "platform/chrome: cros_ec_charge_state: add new driver to control charge". As these charge chip controls are connected under the ChromeOS Embedded Controller (EC), also add the patternProperties to the mfd/google,cros-ec bindings. Signed-off-by: Sung-Chi, Li --- .../bindings/chrome/google,cros-charge-state.yaml | 62 ++++++++++++++++++++++ .../devicetree/bindings/mfd/google,cros-ec.yaml | 4 ++ 2 files changed, 66 insertions(+) diff --git a/Documentation/devicetree/bindings/chrome/google,cros-charge-state.yaml b/Documentation/devicetree/bindings/chrome/google,cros-charge-state.yaml new file mode 100644 index 000000000000..40e8f6988769 --- /dev/null +++ b/Documentation/devicetree/bindings/chrome/google,cros-charge-state.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/chrome/google,cros-charge-state.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google Chrome OS EC(Embedded Controller) charge state driver. + +maintainers: + - Sung-Chi, Li + +description: + Chrome OS devices have an Embedded Controller(EC) which has access to + battery charger IC. This node is intended to allow the host to read and + control the charger current. The node for this device should be under a + cros-ec node like google,cros-ec-spi. + +properties: + compatible: + const: google,cros-ec-charge-state + + min-milliamp: + description: min current in milliamp. + $ref: /schemas/types.yaml#/definitions/uint32 + + max-milliamp: + description: max current in milliamp. + $ref: /schemas/types.yaml#/definitions/uint32 + + type: + description: current limit type. + enum: + - charge + - input + +required: + - compatible + - min-milliamp + - man-milliamp + - type + +additionalProperties: false + +examples: + - |+ + spi { + #address-cells = <1>; + #size-cells = <0>; + + cros_ec: ec@0 { + compatible = "google,cros-ec-spi"; + reg = <0>; + interrupts = <35 0>; + + charge_chip_battery_current: charge-chip-battery { + compatible = "google,cros-ec-charge"; + type = "charge"; + min-milliamp = <150>; + max-milliamp = <5000>; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml index aac8819bd00b..3db4a48d5176 100644 --- a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +++ b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml @@ -166,6 +166,10 @@ patternProperties: type: object $ref: /schemas/extcon/extcon-usbc-cros-ec.yaml# + "^charge-chip-*": + type: object + $ref: /schemas/chrome/google,cros-charge-state.yaml# + required: - compatible From patchwork Mon Nov 18 09:33:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sung-Chi Li X-Patchwork-Id: 13878326 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 7699B192D9C for ; Mon, 18 Nov 2024 09:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731922452; cv=none; b=R0ITRjiioBPwGCBG7E4aIf2f/JW9jmynNaTS7BMD8XRWuuRWi+VdcnD5om2TdgdyT9HPtpEAXRCikiQOgbX9ko0mkUiIME/omR3wXB8yrGhaBQ0QF3FUDUBSRn8PMsyOelFolOWbdL+Xt/YEE7LhLxW7vm6YVTbg6e30Dp/Fvvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731922452; c=relaxed/simple; bh=uAG+q77If4uu42qh15gAWVauifcVeZPLI5R8Z0hp1us=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MN29G0JxbwpKsWV7F7CvROdomeT5v0i4608jbomCPBsk28CTApfvbQydUmk9s8E+Mt3pfmkzas4toJ4kUiuNWSx3HAaEOVuwf14RV4P9vT9jdrRXU5hrco+3S4L3VnrhhniI/5OK7XWM4bmEzcXbWHeJNyQiiOGodbg7MUv7xYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=YAVmSwKk; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YAVmSwKk" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2ea1e5fc65bso1126310a91.3 for ; Mon, 18 Nov 2024 01:34:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731922451; x=1732527251; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=B1gi99T1COw3fo/A7RXmsrRNqipSiwXe7IPFAyxh3nQ=; b=YAVmSwKkfNy2/ioYXBym1WIgdfd24AiQs9TQ2YkPDutYrFIfAc2EOxPkbmvBwBW3K6 2s9xM0i7g4T6SmVs/oO0K3xl2iy8f74hD7us4iKDlK055wapd+PwFTPS4wL8+SHwdk2L g31gXaJqmxK/hNz7uwOPUGFbhXwVCHcHeQ/CQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731922451; x=1732527251; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B1gi99T1COw3fo/A7RXmsrRNqipSiwXe7IPFAyxh3nQ=; b=oDdozq3gLhyDDi3i/v9Dytp/hZeMh5tZ3vwTFR4vUuFLdwNhTrJQzzcA2q4tLfrOd4 eJaRPsmMmK2jFE8uZh30vhPTnizUu69WRNHG02ZacTX/J0GoJXp7uUfiVrat1+gCgsS7 BYWqUR2WsN64e0QJd3vO8cxwATtWxjGwA/DtF+aBqaEA25dv5RhotdVxma/1zgudZqJo wcUQgS/bsN/hFEEk/L3dds7xiGOkyV4vPwQzqo0lW7AAtYh0ewYuF6j5jLIwNKTMCi9B 9Z4zXdu9iJs7Vmf+KaSoNns9Ve5ElRye+gRztZAbbc0UTV1nYPgdssFxQHZhqm4Cddz0 qyEg== X-Forwarded-Encrypted: i=1; AJvYcCUQzKbnkFd01xjH/3d4nYkFEpfRrgRDRY/U9aqNDy2vpS/oehyUhgRG2/WhwwPfgS6oltNtC8cp6Tk4ZY2kmHs=@lists.linux.dev X-Gm-Message-State: AOJu0Yw60ooXDDgosVY/AHhlaHZoT9TTlCim6MyK+QHu4zT0CyXpnX8w nFiwd2RBtCSA0U6ARboDqRIQmokFNZRghTMnP2Qu8YqftsZheuDOXZBVeBGIpA== X-Google-Smtp-Source: AGHT+IGXhjKQWR0KaYkQWRGmrJux1znHSMqcGsFKjVw/B9Ofkc26uXXYB4L/tgF/ZNdQ+bFvpHZU2w== X-Received: by 2002:a17:90b:3a91:b0:2ea:7cd5:4ade with SMTP id 98e67ed59e1d1-2ea7cd54b4cmr2877384a91.30.1731922450867; Mon, 18 Nov 2024 01:34:10 -0800 (PST) Received: from lschyi-p920.tpe.corp.google.com ([2401:fa00:1:10:e40d:fa29:75db:2caa]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9f1e24ce4sm8333500a91.0.2024.11.18.01.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 01:34:10 -0800 (PST) From: "Sung-Chi, Li" Date: Mon, 18 Nov 2024 17:33:48 +0800 Subject: [PATCH 3/3] mfd: cros_ec: Add charge state control cell Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241118-add_charger_state-v1-3-94997079f35a@chromium.org> References: <20241118-add_charger_state-v1-0-94997079f35a@chromium.org> In-Reply-To: <20241118-add_charger_state-v1-0-94997079f35a@chromium.org> To: Benson Leung , Tzung-Bi Shih , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lee Jones Cc: linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, devicetree@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731922439; l=1453; i=lschyi@chromium.org; s=20241113; h=from:subject:message-id; bh=uAG+q77If4uu42qh15gAWVauifcVeZPLI5R8Z0hp1us=; b=w4UcQxVgEZXHMCl9ZfUByBz4hpcE6oLHmGnYGMAyCfy29Q31/pkyHjtwS/WdcFDy/n4DbMxgt UgelA/S3WGbAYMdCVwNS8dtLFkYxQjx3GC2nRh8IwDJIXPMf5LFCzXB X-Developer-Key: i=lschyi@chromium.org; a=ed25519; pk=nE3PJlqSK35GdWfB4oVLOwi4njfaUZRhM66HGos9P6o= The driver of controlling the charge chip connected on the ChromeOS Embedded Controller (EC) is added in the commit "platform/chrome: cros_ec_charge_state: add new driver to control charge". To register the charge state sub-devices, add mfd cells in the cros-ec-dev mfd driver, and register charge state sub-devices based on whether the EC supports battery feature. Signed-off-by: Sung-Chi, Li --- drivers/mfd/cros_ec_dev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index 9f84a52b48d6..fcb4deac3bf3 100644 --- a/drivers/mfd/cros_ec_dev.c +++ b/drivers/mfd/cros_ec_dev.c @@ -112,6 +112,10 @@ static const struct mfd_cell cros_ec_ucsi_cells[] = { { .name = "cros_ec_ucsi", }, }; +static const struct mfd_cell cros_ec_charge_state_cells[] = { + { .name = "cros-ec-charge-state", }, +}; + static const struct cros_feature_to_cells cros_subdevices[] = { { .id = EC_FEATURE_CEC, @@ -148,6 +152,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_ec_keyboard_leds_cells, .num_cells = ARRAY_SIZE(cros_ec_keyboard_leds_cells), }, + { + .id = EC_FEATURE_BATTERY, + .mfd_cells = cros_ec_charge_state_cells, + .num_cells = ARRAY_SIZE(cros_ec_charge_state_cells), + }, }; static const struct mfd_cell cros_ec_platform_cells[] = {