Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8363753ybl; Thu, 16 Jan 2020 15:23:55 -0800 (PST) X-Google-Smtp-Source: APXvYqyQA1CLyKhMNZGSwb2DE5pn5SHWYgrnuJYOsA/es2fwZIHyx5X7ua9mHVsuV5ViyM29ozgk X-Received: by 2002:aca:1309:: with SMTP id e9mr1325148oii.7.1579217035047; Thu, 16 Jan 2020 15:23:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579217035; cv=none; d=google.com; s=arc-20160816; b=n4M8xMykKVQZypTLS8zoiu2qhx/plrJynmy4eOJvKXSti9nvacA/W/FOa9CvjK3Ub0 7rPjegKPa3RaXXdD+QQpfWdCtqkG1lyYr+AUrSdvazY8Nac7aPKhRMaEBCWmQV8Jgz+A BfRndzrBD5QJUPs3Vh5dsgmPfpMRdA+ahmIazWTo6wxMuBRT5DJtS/erHR4jhDB5JTaQ klhiT/+TsgwTGt3Sfj2yI9+2pg0GIA7ch8uXwfucmFPhNssoVb5u13e9JzCSNRX5gwXy hF2t6XhnyrJexQp/e+K2fEBo4Yotzauueh8qQJprXnb3CaI10ZLQGIY72Lgmkw9kQ2Gr ArBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wu+I8aE11hoRgbOsBs0FtKqpK+C2bZSgRMmLwWFZIRw=; b=Qtk67ZVWO/D5ji15ltNRBC6vwhN+jsUBcuKb6nCzhJihTv8RbVX0kh9M10mKwzr3lL tuyeLxnDub9ml+OdhODFF2BhcrNhrfvEJq66g8RKNrviq54TFimHkaKBCDLr/mHMS2QX b9SAy1cVnN7usuOH+sXGFpJXJeEWDU+B6QkAP9bjDzr+kiuQhu690RgEMOEZcpBWkmrU PXi+GD916cT75kL3LpLRC9D2InXKFjg7iXbNv60YxUwCa0oyfAbzMJyZb6psgX2AsaML P42HFcKuSaPZNl8nCkDpsG5PNB/zz/8z6URDbrm9LPc1BmE/96EhVGqRX2iNwvHphvhr //rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="r5O/F1al"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si12308532oic.40.2020.01.16.15.23.43; Thu, 16 Jan 2020 15:23:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="r5O/F1al"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730698AbgAPTvh (ORCPT + 99 others); Thu, 16 Jan 2020 14:51:37 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43329 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730652AbgAPTvg (ORCPT ); Thu, 16 Jan 2020 14:51:36 -0500 Received: by mail-pf1-f194.google.com with SMTP id x6so10731904pfo.10 for ; Thu, 16 Jan 2020 11:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wu+I8aE11hoRgbOsBs0FtKqpK+C2bZSgRMmLwWFZIRw=; b=r5O/F1alUl7CBjpQdp0GZXx4v1NXnzhtUe6P/VPfC6ZasmBJRUUI09knkDD2oHGrn/ yDxzA0e1yhYyussa/w9yGeprzDlaMXL1WC7B6ynovLgsxvz54xfg0W+uQ3uAJqIpYz9o H9zlD+evVptsKTVKN7F3TO68ts/QGrat3Mli3A3+SXkpnWE+REq+0ECXE3Nkr4el/kRR 4Ueap7wvqXdOnA6Lfmq11MsnSifCVJtw+zUhQcQAL4uiQrdqDz9UKWEuevnVt17CJhJF Kem/H9vhlG7mlYV+0z02Yx1R3DirrPYgE8uwzF0VeYq4FZXyxEFu4gtbbaqzEpKkCevG pSGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wu+I8aE11hoRgbOsBs0FtKqpK+C2bZSgRMmLwWFZIRw=; b=G/MAcn4ZKyNPtWIFV2VguX6semDLeXCHYRomUF/lb72QOmBMDSpmLNeo3ae8FYE4JQ 9esQH5BOCZcMW5jaeuVfvLMsaGnZQtX56VlTVy2jZLyQi4jweGRuAV6xJAK+HD4YodrC fESAsAXr1OauPGlsbzWV52yUirBL1xNT0ieneRGGes63v9UnLX0HziiLeJTf3h1V+7Ds rfRL2J3au2RcRgEGz64SBPuIRluiJec2he9XPMaFLFZpD9o75FAxviJnqDKR2JHQHlNc I0LNQPX/Jtg3UCsSMCDn4+QVj3Vy+57qJXo6l9MZxsN8UMGrxRBCFwWKoJz/LIm/DUpY r0zg== X-Gm-Message-State: APjAAAU28+ljDs39JjHoMd6jOq10GBzLeowUgmOjb1kKMOBFAKoe3C+B e4chRWxU/v/WorAJ+KoDrQ1Ygg== X-Received: by 2002:a63:3e03:: with SMTP id l3mr41344370pga.118.1579204295555; Thu, 16 Jan 2020 11:51:35 -0800 (PST) Received: from google.com ([2620:15c:202:201:bc61:d85d:eb16:9036]) by smtp.gmail.com with ESMTPSA id fa21sm4571804pjb.17.2020.01.16.11.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 11:51:34 -0800 (PST) Date: Thu, 16 Jan 2020 11:51:29 -0800 From: Benson Leung To: Prashant Malani Cc: enric.balletbo@collabora.com, groeck@chromium.org, bleung@chromium.org, lee.jones@linaro.org, sre@kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jon Flatley , Gwendal Grignou Subject: Re: [PATCH v6 1/3] platform: chrome: Add cros-usbpd-notify driver Message-ID: <20200116195129.GD208460@google.com> References: <20200114232219.93171-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="osDK9TLjxFScVI/L" Content-Disposition: inline In-Reply-To: <20200114232219.93171-1-pmalani@chromium.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --osDK9TLjxFScVI/L Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 14, 2020 at 03:22:18PM -0800, Prashant Malani wrote: > From: Jon Flatley >=20 > ChromiumOS uses ACPI device with HID "GOOG0003" for power delivery > related events. The existing cros-usbpd-charger driver relies on these > events without ever actually receiving them on ACPI platforms. This is > because in the ChromeOS kernel trees, the GOOG0003 device is owned by an > ACPI driver that offers firmware updates to USB-C chargers. >=20 > Introduce a new platform driver under cros-ec, the ChromeOS embedded > controller, that handles these PD events and dispatches them > appropriately over a notifier chain to all drivers that use them. >=20 > On platforms that don't have the ACPI device defined, the driver gets > instantiated for ECs which support the EC_FEATURE_USB_PD feature bit, > and the notification events will get delivered using the MKBP event > handling mechanism. >=20 > Co-Developed-by: Prashant Malani > Reviewed-by: Gwendal Grignou > Signed-off-by: Jon Flatley > Signed-off-by: Prashant Malani Minor nit, otherwise, Reviewed-by: Benson Leung > --- >=20 > Changes in v6(pmalani@chromium.org): > - Fix build error from typo in cros_usbpd_notify_acpi_device_ids > variable name. >=20 > Changes in v5(pmalani@chromium.org): > - Split the driver into platform and ACPI variants, each enclosed by > CONFIG_OF and CONFIG_ACPI #ifdefs respectively. > - Updated the copyright year to 2020. > - Reworded the commit message and Kconfig description to incorporate > the modified driver structure. >=20 > Changes in v4(pmalani@chromium.org): > - No code changes, but added new version so that versioning is > consistent with the next patch in the series. >=20 > Changes in v3 (pmalani@chromium.org): > - Renamed driver and files from "cros_ec_pd_notify" to > "cros_usbpd_notify" to be more consistent with other naming. > - Moved the change to include cros-usbpd-notify in the charger MFD > into a separate follow-on patch. >=20 > Changes in v2 (pmalani@chromium.org): > - Removed dependency on DT entry; instead, we will instantiate > the driver on detecting EC_FEATURE_USB_PD for non-ACPI platforms. > - Modified the cros-ec-pd-notify device to be an mfd_cell under > usbpdcharger for non-ACPI platforms. Altered the platform_probe() call > to derive the cros EC structs appropriately. > - Replaced "usbpd_notify" with "pd_notify" in functions and structures. > - Addressed comments from upstream maintainer. >=20 > drivers/platform/chrome/Kconfig | 10 ++ > drivers/platform/chrome/Makefile | 1 + > drivers/platform/chrome/cros_usbpd_notify.c | 153 ++++++++++++++++++ > .../linux/platform_data/cros_usbpd_notify.h | 17 ++ > 4 files changed, 181 insertions(+) > create mode 100644 drivers/platform/chrome/cros_usbpd_notify.c > create mode 100644 include/linux/platform_data/cros_usbpd_notify.h >=20 > diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kc= onfig > index 5f57282a28da0..89df6c991089d 100644 > --- a/drivers/platform/chrome/Kconfig > +++ b/drivers/platform/chrome/Kconfig > @@ -226,6 +226,16 @@ config CROS_USBPD_LOGGER > To compile this driver as a module, choose M here: the > module will be called cros_usbpd_logger. > =20 > +config CROS_USBPD_NOTIFY > + tristate "ChromeOS Type-C power delivery event notifier" > + depends on CROS_EC > + help > + If you say Y here, you get support for Type-C PD event notifications > + from the ChromeOS EC. On ACPI platorms this driver will bind to the > + GOOG0003 ACPI device, and on platforms which don't have this device it > + will get initialized on ECs which support the feature > + EC_FEATURE_USB_PD. > + > source "drivers/platform/chrome/wilco_ec/Kconfig" > =20 > endif # CHROMEOS_PLATFORMS > diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/M= akefile > index aacd5920d8a18..f6465f8ef0b5e 100644 > --- a/drivers/platform/chrome/Makefile > +++ b/drivers/platform/chrome/Makefile > @@ -22,5 +22,6 @@ obj-$(CONFIG_CROS_EC_DEBUGFS) +=3D cros_ec_debugfs.o > obj-$(CONFIG_CROS_EC_SENSORHUB) +=3D cros_ec_sensorhub.o > obj-$(CONFIG_CROS_EC_SYSFS) +=3D cros_ec_sysfs.o > obj-$(CONFIG_CROS_USBPD_LOGGER) +=3D cros_usbpd_logger.o > +obj-$(CONFIG_CROS_USBPD_NOTIFY) +=3D cros_usbpd_notify.o > =20 > obj-$(CONFIG_WILCO_EC) +=3D wilco_ec/ > diff --git a/drivers/platform/chrome/cros_usbpd_notify.c b/drivers/platfo= rm/chrome/cros_usbpd_notify.c > new file mode 100644 > index 0000000000000..858e494995843 > --- /dev/null > +++ b/drivers/platform/chrome/cros_usbpd_notify.c > @@ -0,0 +1,153 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright 2020 Google LLC > + * > + * This driver serves as the receiver of cros_ec PD host events. > + */ > + > +#include > +#include > +#include > +#include > +#include Same nit as other: Alphabetize #include list. > +#include > +#include > + > +#define DRV_NAME "cros-usbpd-notify" > +#define ACPI_DRV_NAME "GOOG0003" > + > +static BLOCKING_NOTIFIER_HEAD(cros_usbpd_notifier_list); > + > +/** > + * cros_usbpd_register_notify - Register a notifier callback for PD even= ts. > + * @nb: Notifier block pointer to register > + * > + * On ACPI platforms this corresponds to host events on the ECPD > + * "GOOG0003" ACPI device. On non-ACPI platforms this will filter mkbp e= vents > + * for USB PD events. > + * > + * Return: 0 on success or negative error code. > + */ > +int cros_usbpd_register_notify(struct notifier_block *nb) > +{ > + return blocking_notifier_chain_register( > + &cros_usbpd_notifier_list, nb); > +} > +EXPORT_SYMBOL_GPL(cros_usbpd_register_notify); > + > + > +/** > + * cros_usbpd_unregister_notify - Unregister notifier callback for PD ev= ents. > + * @nb: Notifier block pointer to unregister > + * > + * Unregister a notifier callback that was previously registered with > + * cros_usbpd_register_notify(). > + */ > +void cros_usbpd_unregister_notify(struct notifier_block *nb) > +{ > + blocking_notifier_chain_unregister(&cros_usbpd_notifier_list, nb); > +} > +EXPORT_SYMBOL_GPL(cros_usbpd_unregister_notify); > + > +#ifdef CONFIG_ACPI > + > +static int cros_usbpd_notify_add_acpi(struct acpi_device *adev) > +{ > + return 0; > +} > + > +static void cros_usbpd_notify_acpi(struct acpi_device *adev, u32 event) > +{ > + blocking_notifier_call_chain(&cros_usbpd_notifier_list, event, NULL); > +} > + > +static const struct acpi_device_id cros_usbpd_notify_acpi_device_ids[] = =3D { > + { ACPI_DRV_NAME, 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(acpi, cros_usbpd_notify_acpi_device_ids); > + > +static struct acpi_driver cros_usbpd_notify_acpi_driver =3D { > + .name =3D DRV_NAME, > + .class =3D DRV_NAME, > + .ids =3D cros_usbpd_notify_acpi_device_ids, > + .ops =3D { > + .add =3D cros_usbpd_notify_add_acpi, > + .notify =3D cros_usbpd_notify_acpi, > + }, > +}; > +module_acpi_driver(cros_usbpd_notify_acpi_driver); > + > +#endif /* CONFIG_ACPI */ > + > +#ifdef CONFIG_OF > + > +static int cros_usbpd_notify_plat(struct notifier_block *nb, > + unsigned long queued_during_suspend, void *data) > +{ > + struct cros_ec_device *ec_dev =3D (struct cros_ec_device *)data; > + u32 host_event =3D cros_ec_get_host_event(ec_dev); > + > + if (!host_event) > + return NOTIFY_BAD; > + > + if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_PD_MCU)) { > + blocking_notifier_call_chain(&cros_usbpd_notifier_list, > + host_event, NULL); > + return NOTIFY_OK; > + } > + return NOTIFY_DONE; > +} > + > +static int cros_usbpd_notify_probe_plat(struct platform_device *pdev) > +{ > + struct device *dev =3D &pdev->dev; > + struct cros_ec_dev *ecdev =3D dev_get_drvdata(dev->parent); > + struct notifier_block *nb; > + int ret; > + > + nb =3D devm_kzalloc(dev, sizeof(*nb), GFP_KERNEL); > + if (!nb) > + return -ENOMEM; > + > + nb->notifier_call =3D cros_usbpd_notify_plat; > + dev_set_drvdata(dev, nb); > + > + ret =3D blocking_notifier_chain_register(&ecdev->ec_dev->event_notifier, > + nb); > + if (ret < 0) { > + dev_err(dev, "Failed to register notifier\n"); > + return ret; > + } > + > + return 0; > +} > + > +static int cros_usbpd_notify_remove_plat(struct platform_device *pdev) > +{ > + struct device *dev =3D &pdev->dev; > + struct cros_ec_dev *ecdev =3D dev_get_drvdata(dev->parent); > + struct notifier_block *nb =3D > + (struct notifier_block *)dev_get_drvdata(dev); > + > + blocking_notifier_chain_unregister(&ecdev->ec_dev->event_notifier, > + nb); > + > + return 0; > +} > + > +static struct platform_driver cros_usbpd_notify_plat_driver =3D { > + .driver =3D { > + .name =3D DRV_NAME, > + }, > + .probe =3D cros_usbpd_notify_probe_plat, > + .remove =3D cros_usbpd_notify_remove_plat, > +}; > +module_platform_driver(cros_usbpd_notify_plat_driver); > + > +#endif /* CONFIG_OF */ > + > +MODULE_LICENSE("GPL"); > +MODULE_DESCRIPTION("ChromeOS power delivery notifier device"); > +MODULE_AUTHOR("Jon Flatley "); > +MODULE_ALIAS("platform:" DRV_NAME); > diff --git a/include/linux/platform_data/cros_usbpd_notify.h b/include/li= nux/platform_data/cros_usbpd_notify.h > new file mode 100644 > index 0000000000000..4f2791722b6d3 > --- /dev/null > +++ b/include/linux/platform_data/cros_usbpd_notify.h > @@ -0,0 +1,17 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * ChromeOS EC Power Delivery Notifier Driver > + * > + * Copyright 2020 Google LLC > + */ > + > +#ifndef __LINUX_PLATFORM_DATA_CROS_USBPD_NOTIFY_H > +#define __LINUX_PLATFORM_DATA_CROS_USBPD_NOTIFY_H > + > +#include > + > +int cros_usbpd_register_notify(struct notifier_block *nb); > + > +void cros_usbpd_unregister_notify(struct notifier_block *nb); > + > +#endif /* __LINUX_PLATFORM_DATA_CROS_USBPD_NOTIFY_H */ > --=20 > 2.25.0.341.g760bfbb309-goog >=20 --=20 Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. bleung@google.com Chromium OS Project bleung@chromium.org --osDK9TLjxFScVI/L Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQCtZK6p/AktxXfkOlzbaomhzOwwgUCXiC+wQAKCRBzbaomhzOw wuN3AQDB4Q1NmuP+t8X4OizjnyRzUk9VBJVkoynrO5XKn7/SqgD/YZ3TvXxhLxNq d7qveRMcSkrAreryhqfg9GlJQJRagA8= =gH1s -----END PGP SIGNATURE----- --osDK9TLjxFScVI/L--