From patchwork Fri Apr 15 00:32:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12814161 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 E9520192 for ; Fri, 15 Apr 2022 00:32:56 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id s14so5996734plk.8 for ; Thu, 14 Apr 2022 17:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C5t3e+cZTj4xwdAITByfx8113SkQvPNyKKAsLc7zHFM=; b=Sre7yJqjWog5IzWlAJouxhJIxDudi3P7KD3fupciGkuyrvofNEAvI6ORbO60O9ZAZl Ijh9lYeRczXJ1Vvrwlg9LZ0q5AjBBmPg0zqi98nw8R+2XJEJE/dy5VprhT6XO7G34/6y /5tfZ9uQuwRXXUQRMhjzq7HEs4yCBtKp7QfMU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C5t3e+cZTj4xwdAITByfx8113SkQvPNyKKAsLc7zHFM=; b=zlU5jWNb/Kfg1COfjgttw6sibgkHuplVZA/Luo4FnNcXvsf4K4IcWlipvOk0hcWjrq XxuHg4oDufIY90EWUlW0DK3ZAtNsyapB7TzbiR3XzeV9rRtBuz3dVj5lvdk84g0gd8et X+0IVp5l90EiLG9Br0JJjqukOijzgifRK/xsflc5hXs6zTsdLfohXMq+8iKSMqzhhoMo ijF5fA4QPpsvanNTcUjsA0fDczn2Oh5q//ymRJE2343CS8RzAH97KtJMxkOLLlRVsIzH YXysIMMYwZkCfNrLVRXQNqm6JzJAmLksQFPbLzEOrTbfsP5zc/sN7LV4d7hx/rm+4T0z OWlg== X-Gm-Message-State: AOAM533+/ADDpw+NJkao61avSGTZSqMY2Op9Sjiupd7iq2h10deIY3f0 g5fRyxBbC0PLWYHhqhQAGMblgg== X-Google-Smtp-Source: ABdhPJyX/cNKS4BBDlZhUfNXn3R48lgEEQXevRhtV5J7S7Guj8PpbEYGPvwnRdf6ljVjJ3e+Vg2vtA== X-Received: by 2002:a17:902:bd06:b0:158:8973:b16b with SMTP id p6-20020a170902bd0600b001588973b16bmr15242969pls.129.1649982776334; Thu, 14 Apr 2022 17:32:56 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:e3e0:734:f81a:d2c1]) by smtp.gmail.com with ESMTPSA id p12-20020a63ab0c000000b00381f7577a5csm2830187pgf.17.2022.04.14.17.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 17:32:56 -0700 (PDT) From: Stephen Boyd To: Benson Leung Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, Lee Jones , Daisuke Nojiri , Guenter Roeck , chrome-platform@lists.linux.dev Subject: [PATCH 1/3] platform/chrome: cros_ec_proto: Add peripheral charger count API Date: Thu, 14 Apr 2022 17:32:51 -0700 Message-Id: <20220415003253.1973106-2-swboyd@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220415003253.1973106-1-swboyd@chromium.org> References: <20220415003253.1973106-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a peripheral charger count API similar to the one implemented in the ChromeOS PCHG driver so we can use it to decide whether or not to register the PCHG device in the cros_ec MFD driver. Cc: Lee Jones Cc: Daisuke Nojiri Cc: Benson Leung Cc: Guenter Roeck Cc: Signed-off-by: Stephen Boyd Reviewed-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_proto.c | 31 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 1 + 2 files changed, 32 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index c4caf2e2de82..42269703ca6c 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -832,6 +832,37 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature) } EXPORT_SYMBOL_GPL(cros_ec_check_features); +/** + * cros_ec_pchg_port_count() - Return the number of peripheral charger ports. + * @ec: EC device. + * + * Return: Number of peripheral charger ports, or 0 in case of error. + */ +unsigned int cros_ec_pchg_port_count(struct cros_ec_dev *ec) +{ + struct cros_ec_command *msg; + const struct ec_response_pchg_count *rsp; + struct cros_ec_device *ec_dev = ec->ec_dev; + int ret, count = 0; + + msg = kzalloc(sizeof(*msg) + sizeof(*rsp), GFP_KERNEL); + if (!msg) + return 0; + + msg->command = EC_CMD_PCHG_COUNT + ec->cmd_offset; + msg->insize = sizeof(*rsp); + + ret = cros_ec_cmd_xfer_status(ec_dev, msg); + if (ret >= 0) { + rsp = (const struct ec_response_pchg_count *)msg->data; + count = rsp->port_count; + } + kfree(msg); + + return count; +} +EXPORT_SYMBOL_GPL(cros_ec_pchg_port_count); + /** * cros_ec_get_sensor_count() - Return the number of MEMS sensors supported. * diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h index df3c78c92ca2..8f5781bc2d7a 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -230,6 +230,7 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); bool cros_ec_check_features(struct cros_ec_dev *ec, int feature); int cros_ec_get_sensor_count(struct cros_ec_dev *ec); +unsigned int cros_ec_pchg_port_count(struct cros_ec_dev *ec); int cros_ec_command(struct cros_ec_device *ec_dev, unsigned int version, int command, void *outdata, int outsize, void *indata, int insize); From patchwork Fri Apr 15 00:32:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12814162 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 08D8518D for ; Fri, 15 Apr 2022 00:32:57 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id cw11so6210859pfb.1 for ; Thu, 14 Apr 2022 17:32:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jkz+K46qtkIknicoqbLXEwCJgWhY8AVoAaPBkdZve2U=; b=UGyg9hR+s/RnQZqDAT16Gq3HREy8egyTdio40vc9b2DXdzEhoR+syVUHMO6ACrN4si o5m2LO78SdlXKcFz2Y0unk1Rz3+ZYTNxIHyrEe7jYqw6KMm3qFBqzIGFfHfUbweV5EJK gYd2QE8lr4c2DhEP5HnJxUIOQSOD9VOv1Wm0Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jkz+K46qtkIknicoqbLXEwCJgWhY8AVoAaPBkdZve2U=; b=1xGLMa8KOKxJ/UK1Iv/2Kb+ABCu8vg/v3D4DibOu4PxYRyfpnKf/W6b1OL2294O25d j19q9rRfP7Syoilf+yjP18Z+1xX8YkJCl3Y8Fgun/wOOSv+Jb//k0G6wsTBSkoH49+wt qNZcIg0U6gZE0yBv8i9XibEWIkmQ8Bkn07D9Uu9LLk8uQl4iDpcSJUj4pN8VYy2Jl8tw DE1YfVsWVJxB1gugjqZOeTbo+xQrJSOEosjX3fjP07YIxQiTHp7D0IuLwDLO2BuOZLJ7 q3GVR/sU04R4qvNp3+BLsZ4m9h24zZq7zJOE0AL0XpZ5/oCP5XI4HK+OVqtFdi0+VCqu +qRQ== X-Gm-Message-State: AOAM5307xOuf+VNS/bccOIDlowmUUsA5vCaqxLtdlyy66d47K8St9VYr bRLAhzz5MRbNK1orRKX2FaWUag== X-Google-Smtp-Source: ABdhPJxvYhjYZJVkJb/YqcuxXe04uZW1OYgYUoLiRnxUGlY1oCtRAnvQQVyvmC3kzKaWPTQk6Qd8GA== X-Received: by 2002:a05:6a00:cc3:b0:505:c82b:f4f8 with SMTP id b3-20020a056a000cc300b00505c82bf4f8mr6363580pfv.59.1649982777538; Thu, 14 Apr 2022 17:32:57 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:e3e0:734:f81a:d2c1]) by smtp.gmail.com with ESMTPSA id p12-20020a63ab0c000000b00381f7577a5csm2830187pgf.17.2022.04.14.17.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 17:32:57 -0700 (PDT) From: Stephen Boyd To: Benson Leung Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, Lee Jones , Daisuke Nojiri , Guenter Roeck , chrome-platform@lists.linux.dev Subject: [PATCH 2/3] mfd: cros_ec_dev: Only register PCHG device if present Date: Thu, 14 Apr 2022 17:32:52 -0700 Message-Id: <20220415003253.1973106-3-swboyd@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220415003253.1973106-1-swboyd@chromium.org> References: <20220415003253.1973106-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Don't create a device for the peripheral charger (PCHG) if there aren't any peripheral charger ports. This removes a device on most ChromeOS systems, because the peripheral charger functionality isn't always present. Cc: Lee Jones Cc: Daisuke Nojiri Cc: Benson Leung Cc: Guenter Roeck Cc: Signed-off-by: Stephen Boyd Reviewed-by: Tzung-Bi Shih --- drivers/mfd/cros_ec_dev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index 546feef851ab..d2ba6a1fbc1d 100644 --- a/drivers/mfd/cros_ec_dev.c +++ b/drivers/mfd/cros_ec_dev.c @@ -114,6 +114,9 @@ static const struct mfd_cell cros_ec_platform_cells[] = { { .name = "cros-ec-chardev", }, { .name = "cros-ec-debugfs", }, { .name = "cros-ec-sysfs", }, +}; + +static const struct mfd_cell cros_ec_pchg_cells[] = { { .name = "cros-ec-pchg", }, }; @@ -242,6 +245,19 @@ static int ec_device_probe(struct platform_device *pdev) } } + /* + * The PCHG device cannot be detected by sending EC_FEATURE_GET_CMD, but + * it can be detected by querying the number of peripheral chargers. + */ + if (cros_ec_pchg_port_count(ec)) { + retval = mfd_add_hotplug_devices(ec->dev, + cros_ec_pchg_cells, + ARRAY_SIZE(cros_ec_pchg_cells)); + if (retval) + dev_warn(ec->dev, "failed to add pchg: %d\n", + retval); + } + /* * The following subdevices cannot be detected by sending the * EC_FEATURE_GET_CMD to the Embedded Controller device. From patchwork Fri Apr 15 00:32:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12814163 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.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 1FA8618E for ; Fri, 15 Apr 2022 00:32:59 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id e8-20020a17090a118800b001cb13402ea2so7207461pja.0 for ; Thu, 14 Apr 2022 17:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u5uNblHgSOrswPeO9jURL3NSLbtduvbh6ZJ+Qdg6lQI=; b=FL9PZa7rqg/FQc24DKxyR99Opmvgy6c3zIdZDaBfP4n8HTZ/yB2BYuvSBSFQXOcAZd uEHYiNbQmPVoRnkfuIxaz3XeEJ8J6ZPZ3z2WRzpYo7g5KAzE2lyNiu7Fr89hF9l8lZTG /4B9a+qm1khvB+hDLkK+xXPYs9ZguwZPEysNw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u5uNblHgSOrswPeO9jURL3NSLbtduvbh6ZJ+Qdg6lQI=; b=mce0193hyaD7B7wuk3P2aGLxFXQ/9XaLyQMxNBnNI4BdfmXti8N9qQ9xTS5+qfMdRA iNdRHoa5ih4dsLKdl83Tb6Ilif92FJtQGOjcXzHkATg0aLCEWr83evB4UemgZH5zCezM V1+bOfb8n5g/+B1AMpGrjV9qVlivhTzMv9qnNe664yGxqq/cLnfPt3Sv5GZ83fABjirz BfluqHV/Jw6pIYB/G72QJbsi5VIQI0rxcWlIqMaHd3DwvqOtTDKRImsCv++iTakRYGfE Eq1EnNxGLSBfAGcRMDOqC2h4lxeuSlkpFPYWKOekQUf0mzPnIYwGBVPR14qdNdSCH7o+ GfXQ== X-Gm-Message-State: AOAM531a0aMsTArH8IJtuQHv9n3kwcWW1P1scNsBTIFiNne2PU11cD6z 07GXHdA1UZcTI6K3NjWrAerm0g== X-Google-Smtp-Source: ABdhPJy092wIOMpHMCaiCRG/f784cDQMvZyv6Zy3Qf2VuKU9u3jvUIyk6bF/0bpYWpLFKq3UGLiVqA== X-Received: by 2002:a17:902:b941:b0:14d:af72:3f23 with SMTP id h1-20020a170902b94100b0014daf723f23mr50652474pls.6.1649982778661; Thu, 14 Apr 2022 17:32:58 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:e3e0:734:f81a:d2c1]) by smtp.gmail.com with ESMTPSA id p12-20020a63ab0c000000b00381f7577a5csm2830187pgf.17.2022.04.14.17.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 17:32:58 -0700 (PDT) From: Stephen Boyd To: Benson Leung Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, Lee Jones , Daisuke Nojiri , Guenter Roeck , chrome-platform@lists.linux.dev Subject: [PATCH 3/3] power: supply: PCHG: Use cros_ec_pchg_port_count() Date: Thu, 14 Apr 2022 17:32:53 -0700 Message-Id: <20220415003253.1973106-4-swboyd@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220415003253.1973106-1-swboyd@chromium.org> References: <20220415003253.1973106-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the common function cros_ec_pchg_port_count() now that we only register this device when there are a non-zero number of peripheral charger ports. Cc: Lee Jones Cc: Daisuke Nojiri Cc: Benson Leung Cc: Guenter Roeck Cc: Signed-off-by: Stephen Boyd Reviewed-by: Tzung-Bi Shih --- .../power/supply/cros_peripheral_charger.c | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c index 9fe6d826148d..98cae6580eed 100644 --- a/drivers/power/supply/cros_peripheral_charger.c +++ b/drivers/power/supply/cros_peripheral_charger.c @@ -104,22 +104,6 @@ static bool cros_pchg_cmd_ver_check(const struct charger_data *charger) return !!(rsp.version_mask & BIT(pchg_cmd_version)); } -static int cros_pchg_port_count(const struct charger_data *charger) -{ - struct ec_response_pchg_count rsp; - int ret; - - ret = cros_pchg_ec_command(charger, 0, EC_CMD_PCHG_COUNT, - NULL, 0, &rsp, sizeof(rsp)); - if (ret < 0) { - dev_warn(charger->dev, - "Unable to get number or ports (err:%d)\n", ret); - return ret; - } - - return rsp.port_count; -} - static int cros_pchg_get_status(struct port_data *port) { struct charger_data *charger = port->charger; @@ -281,24 +265,13 @@ static int cros_pchg_probe(struct platform_device *pdev) charger->ec_dev = ec_dev; charger->ec_device = ec_device; - ret = cros_pchg_port_count(charger); - if (ret <= 0) { - /* - * This feature is enabled by the EC and the kernel driver is - * included by default for CrOS devices. Don't need to be loud - * since this error can be normal. - */ - dev_info(dev, "No peripheral charge ports (err:%d)\n", ret); - return -ENODEV; - } - if (!cros_pchg_cmd_ver_check(charger)) { dev_err(dev, "EC_CMD_PCHG version %d isn't available.\n", pchg_cmd_version); return -EOPNOTSUPP; } - num_ports = ret; + num_ports = cros_ec_pchg_port_count(ec_dev); if (num_ports > EC_PCHG_MAX_PORTS) { dev_err(dev, "Too many peripheral charge ports (%d)\n", num_ports);