Re: [PATCH 2/2] power: supply: Add AC driver for Surface Aggregator Module
Hi, On 4/5/21 5:47 PM, Sebastian Reichel wrote: Hi, On Tue, Mar 09, 2021 at 01:05:30AM +0100, Maximilian Luz wrote: On newer Microsoft Surface models (specifically 7th-generation, i.e. Surface Pro 7, Surface Book 3, Surface Laptop 3, and Surface Laptop Go), battery and AC status/information is no longer handled via standard ACPI devices, but instead directly via the Surface System Aggregator Module (SSAM), i.e. the embedded controller on those devices. While on previous generation models, AC status is also handled via SSAM, an ACPI shim was present to translate the standard ACPI AC interface to SSAM requests. The SSAM interface itself, which is modeled closely after the ACPI interface, has not changed. This commit introduces a new SSAM client device driver to support AC status/information via the aforementioned interface on said Surface models. Signed-off-by: Maximilian Luz --- Note: This patch depends on the platform/surface: Add Surface Aggregator device registry series. More specifically patch platform/surface: Set up Surface Aggregator device registry The full series has been merged into the for-next branch of the platform-drivers-x86 tree [1]. The commit in question can be found at [2]. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=for-next [2]: https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/commit/?h=for-next&id=fc622b3d36e6d91330fb21506b9ad1e3206a4dde --- MAINTAINERS| 1 + drivers/power/supply/Kconfig | 16 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/surface_charger.c | 296 + 4 files changed, 314 insertions(+) create mode 100644 drivers/power/supply/surface_charger.c diff --git a/MAINTAINERS b/MAINTAINERS index f44521abe8bf..d6651ba93997 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11867,6 +11867,7 @@ L: linux...@vger.kernel.org L:platform-driver-...@vger.kernel.org S:Maintained F:drivers/power/supply/surface_battery.c +F: drivers/power/supply/surface_charger.c MICROSOFT SURFACE GPE LID SUPPORT DRIVER M:Maximilian Luz diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index cebeff10d543..91f7cf425ac9 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -817,4 +817,20 @@ config BATTERY_SURFACE Microsoft Surface devices, i.e. Surface Pro 7, Surface Laptop 3, Surface Book 3, and Surface Laptop Go. +config CHARGER_SURFACE + tristate "AC driver for 7th-generation Microsoft Surface devices" + depends on SURFACE_AGGREGATOR_REGISTRY + help + Driver for AC devices connected via/managed by the Surface System + Aggregator Module (SSAM). + + This driver provides AC-information and -status support for Surface + devices where said data is not exposed via the standard ACPI devices. + On those models (7th-generation), AC-information is instead handled + directly via a SSAM client device and this driver. + + Say M or Y here to include AC status support for 7th-generation + Microsoft Surface devices, i.e. Surface Pro 7, Surface Laptop 3, + Surface Book 3, and Surface Laptop Go. + endif # POWER_SUPPLY diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index 134041538d2c..a7309a3d1a47 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -102,3 +102,4 @@ obj-$(CONFIG_CHARGER_WILCO) += wilco-charger.o obj-$(CONFIG_RN5T618_POWER) += rn5t618_power.o obj-$(CONFIG_BATTERY_ACER_A500) += acer_a500_battery.o obj-$(CONFIG_BATTERY_SURFACE) += surface_battery.o +obj-$(CONFIG_CHARGER_SURFACE) += surface_charger.o diff --git a/drivers/power/supply/surface_charger.c b/drivers/power/supply/surface_charger.c new file mode 100644 index ..fe484523a2c2 --- /dev/null +++ b/drivers/power/supply/surface_charger.c @@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * AC driver for 7th-generation Microsoft Surface devices via Surface System + * Aggregator Module (SSAM). + * + * Copyright (C) 2019-2021 Maximilian Luz + */ + +#include +#include +#include +#include +#include +#include + +#include + + +/* -- SAM interface. */ + +enum sam_event_cid_bat { + SAM_EVENT_CID_BAT_ADP = 0x17, +}; + +enum sam_battery_sta { + SAM_BATTERY_STA_OK = 0x0f, + SAM_BATTERY_STA_PRESENT = 0x10, +}; + +/* Get battery status (_STA). */ +SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_sta, __le32, { + .target_category = SSAM_SSH_TC_BAT, + .command_id = 0x01, +}); + +/* Get platform power source for battery (_PSR / DPTF PSRC). */ +SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_psrc, __le32, { + .target_category = SSAM_SSH_TC_BAT, + .command_id = 0x0d, +}); + +
Re: [PATCH 2/2] power: supply: Add AC driver for Surface Aggregator Module
Hi, On Tue, Mar 09, 2021 at 01:05:30AM +0100, Maximilian Luz wrote: > On newer Microsoft Surface models (specifically 7th-generation, i.e. > Surface Pro 7, Surface Book 3, Surface Laptop 3, and Surface Laptop Go), > battery and AC status/information is no longer handled via standard ACPI > devices, but instead directly via the Surface System Aggregator Module > (SSAM), i.e. the embedded controller on those devices. > > While on previous generation models, AC status is also handled via SSAM, > an ACPI shim was present to translate the standard ACPI AC interface to > SSAM requests. The SSAM interface itself, which is modeled closely after > the ACPI interface, has not changed. > > This commit introduces a new SSAM client device driver to support AC > status/information via the aforementioned interface on said Surface > models. > > Signed-off-by: Maximilian Luz > --- > > Note: This patch depends on the > > platform/surface: Add Surface Aggregator device registry > > series. More specifically patch > > platform/surface: Set up Surface Aggregator device registry > > The full series has been merged into the for-next branch of the > platform-drivers-x86 tree [1]. The commit in question can be found at > [2]. > > [1]: > https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=for-next > [2]: > https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/commit/?h=for-next&id=fc622b3d36e6d91330fb21506b9ad1e3206a4dde > > --- > MAINTAINERS| 1 + > drivers/power/supply/Kconfig | 16 ++ > drivers/power/supply/Makefile | 1 + > drivers/power/supply/surface_charger.c | 296 + > 4 files changed, 314 insertions(+) > create mode 100644 drivers/power/supply/surface_charger.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index f44521abe8bf..d6651ba93997 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -11867,6 +11867,7 @@ L:linux...@vger.kernel.org > L: platform-driver-...@vger.kernel.org > S: Maintained > F: drivers/power/supply/surface_battery.c > +F: drivers/power/supply/surface_charger.c > > MICROSOFT SURFACE GPE LID SUPPORT DRIVER > M: Maximilian Luz > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > index cebeff10d543..91f7cf425ac9 100644 > --- a/drivers/power/supply/Kconfig > +++ b/drivers/power/supply/Kconfig > @@ -817,4 +817,20 @@ config BATTERY_SURFACE > Microsoft Surface devices, i.e. Surface Pro 7, Surface Laptop 3, > Surface Book 3, and Surface Laptop Go. > > +config CHARGER_SURFACE > + tristate "AC driver for 7th-generation Microsoft Surface devices" > + depends on SURFACE_AGGREGATOR_REGISTRY > + help > + Driver for AC devices connected via/managed by the Surface System > + Aggregator Module (SSAM). > + > + This driver provides AC-information and -status support for Surface > + devices where said data is not exposed via the standard ACPI devices. > + On those models (7th-generation), AC-information is instead handled > + directly via a SSAM client device and this driver. > + > + Say M or Y here to include AC status support for 7th-generation > + Microsoft Surface devices, i.e. Surface Pro 7, Surface Laptop 3, > + Surface Book 3, and Surface Laptop Go. > + > endif # POWER_SUPPLY > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > index 134041538d2c..a7309a3d1a47 100644 > --- a/drivers/power/supply/Makefile > +++ b/drivers/power/supply/Makefile > @@ -102,3 +102,4 @@ obj-$(CONFIG_CHARGER_WILCO) += wilco-charger.o > obj-$(CONFIG_RN5T618_POWER) += rn5t618_power.o > obj-$(CONFIG_BATTERY_ACER_A500) += acer_a500_battery.o > obj-$(CONFIG_BATTERY_SURFACE)+= surface_battery.o > +obj-$(CONFIG_CHARGER_SURFACE)+= surface_charger.o > diff --git a/drivers/power/supply/surface_charger.c > b/drivers/power/supply/surface_charger.c > new file mode 100644 > index ..fe484523a2c2 > --- /dev/null > +++ b/drivers/power/supply/surface_charger.c > @@ -0,0 +1,296 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * AC driver for 7th-generation Microsoft Surface devices via Surface System > + * Aggregator Module (SSAM). > + * > + * Copyright (C) 2019-2021 Maximilian Luz > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > + > +/* -- SAM interface. > */ > + > +enum sam_event_cid_bat { > + SAM_EVENT_CID_BAT_ADP = 0x17, > +}; > + > +enum sam_battery_sta { > + SAM_BATTERY_STA_OK = 0x0f, > + SAM_BATTERY_STA_PRESENT = 0x10, > +}; > + > +/* Get battery status (_STA). */ > +SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_sta, __le32, { > + .target_category = SSAM_SSH_TC_BAT, > + .command_id = 0x01, > +}); > + > +/* Get platform power source for battery (_PS