123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218 |
- From 973bf943acca4abdd932b5fdff032de0af07f96e Mon Sep 17 00:00:00 2001
- From: Maximilian Luz <luzmaximilian@gmail.com>
- Date: Sun, 22 Oct 2023 14:57:11 +0200
- Subject: [PATCH] platform/surface: aggregator_registry: Add support for
- Surface Laptop Go 3
- Add SAM client device nodes for the Surface Laptop Go 3. It seems to use
- the same SAM client devices as the Surface Laptop Go 1 and 2, so re-use
- their node group.
- Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
- Patchset: surface-sam
- ---
- drivers/platform/surface/surface_aggregator_registry.c | 3 +++
- 1 file changed, 3 insertions(+)
- diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
- index aeb3feae40ff..2bc4977037fc 100644
- --- a/drivers/platform/surface/surface_aggregator_registry.c
- +++ b/drivers/platform/surface/surface_aggregator_registry.c
- @@ -367,6 +367,9 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
- /* Surface Laptop Go 2 */
- { "MSHW0290", (unsigned long)ssam_node_group_slg1 },
-
- + /* Surface Laptop Go 3 */
- + { "MSHW0440", (unsigned long)ssam_node_group_slg1 },
- +
- /* Surface Laptop Studio */
- { "MSHW0123", (unsigned long)ssam_node_group_sls },
-
- --
- 2.44.0
- From 7dedc84364f9c1fb73d271c859dce19b4a9644d6 Mon Sep 17 00:00:00 2001
- From: Maximilian Luz <luzmaximilian@gmail.com>
- Date: Mon, 20 Nov 2023 19:47:00 +0100
- Subject: [PATCH] platform/surface: aggregator_registry: Add support for
- Surface Laptop Studio 2
- Add SAM client device nodes for the Surface Laptop Studio 2 (SLS2). The
- SLS2 is quite similar to the SLS1, but it does not provide the touchpad
- as a SAM-HID device. Therefore, add a new node group for the SLS2 and
- update the comments accordingly
- Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
- Patchset: surface-sam
- ---
- .../surface/surface_aggregator_registry.c | 25 ++++++++++++++++---
- 1 file changed, 21 insertions(+), 4 deletions(-)
- diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
- index 2bc4977037fc..26cb6229ad16 100644
- --- a/drivers/platform/surface/surface_aggregator_registry.c
- +++ b/drivers/platform/surface/surface_aggregator_registry.c
- @@ -247,8 +247,8 @@ static const struct software_node *ssam_node_group_sl5[] = {
- NULL,
- };
-
- -/* Devices for Surface Laptop Studio. */
- -static const struct software_node *ssam_node_group_sls[] = {
- +/* Devices for Surface Laptop Studio 1. */
- +static const struct software_node *ssam_node_group_sls1[] = {
- &ssam_node_root,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- @@ -263,6 +263,20 @@ static const struct software_node *ssam_node_group_sls[] = {
- NULL,
- };
-
- +/* Devices for Surface Laptop Studio 2. */
- +static const struct software_node *ssam_node_group_sls2[] = {
- + &ssam_node_root,
- + &ssam_node_bat_ac,
- + &ssam_node_bat_main,
- + &ssam_node_tmp_pprof,
- + &ssam_node_pos_tablet_switch,
- + &ssam_node_hid_sam_keyboard,
- + &ssam_node_hid_sam_penstash,
- + &ssam_node_hid_sam_sensors,
- + &ssam_node_hid_sam_ucm_ucsi,
- + NULL,
- +};
- +
- /* Devices for Surface Laptop Go. */
- static const struct software_node *ssam_node_group_slg1[] = {
- &ssam_node_root,
- @@ -370,8 +384,11 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
- /* Surface Laptop Go 3 */
- { "MSHW0440", (unsigned long)ssam_node_group_slg1 },
-
- - /* Surface Laptop Studio */
- - { "MSHW0123", (unsigned long)ssam_node_group_sls },
- + /* Surface Laptop Studio 1 */
- + { "MSHW0123", (unsigned long)ssam_node_group_sls1 },
- +
- + /* Surface Laptop Studio 2 */
- + { "MSHW0360", (unsigned long)ssam_node_group_sls2 },
-
- { },
- };
- --
- 2.44.0
- From 96a7b3dd527f3e1b97e2d089a727c16cd5045aa5 Mon Sep 17 00:00:00 2001
- From: Ivor Wanders <ivor@iwanders.net>
- Date: Mon, 18 Dec 2023 19:21:32 -0500
- Subject: [PATCH] platform/surface: aggregator_registry: add entry for fan
- speed
- Add an entry for the fan speed function.
- Add this new entry to the Surface Pro 9 group.
- Signed-off-by: Ivor Wanders <ivor@iwanders.net>
- Link: https://github.com/linux-surface/kernel/pull/144
- Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com>
- Patchset: surface-sam
- ---
- drivers/platform/surface/surface_aggregator_registry.c | 7 +++++++
- 1 file changed, 7 insertions(+)
- diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
- index 26cb6229ad16..f02a933160ff 100644
- --- a/drivers/platform/surface/surface_aggregator_registry.c
- +++ b/drivers/platform/surface/surface_aggregator_registry.c
- @@ -74,6 +74,12 @@ static const struct software_node ssam_node_tmp_pprof = {
- .parent = &ssam_node_root,
- };
-
- +/* Fan speed function. */
- +static const struct software_node ssam_node_fan_speed = {
- + .name = "ssam:01:05:01:01:01",
- + .parent = &ssam_node_root,
- +};
- +
- /* Tablet-mode switch via KIP subsystem. */
- static const struct software_node ssam_node_kip_tablet_switch = {
- .name = "ssam:01:0e:01:00:01",
- @@ -319,6 +325,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- &ssam_node_tmp_pprof,
- + &ssam_node_fan_speed,
- &ssam_node_pos_tablet_switch,
- &ssam_node_hid_kip_keyboard,
- &ssam_node_hid_kip_penstash,
- --
- 2.44.0
- From b4eb65349df9859f65aa9990c24c5036d35382da Mon Sep 17 00:00:00 2001
- From: Ivor Wanders <ivor@iwanders.net>
- Date: Thu, 30 Nov 2023 20:20:24 -0500
- Subject: [PATCH] hwmon: add fan speed monitoring driver for Surface devices
- Adds a driver that provides read only access to the fan speed for Microsoft
- Surface Pro devices. The fan speed is always regulated by the EC and cannot
- be influenced directly.
- Signed-off-by: Ivor Wanders <ivor@iwanders.net>
- Link: https://github.com/linux-surface/kernel/pull/144
- Patchset: surface-sam
- ---
- Documentation/hwmon/index.rst | 1 +
- Documentation/hwmon/surface_fan.rst | 25 ++++++++
- MAINTAINERS | 8 +++
- drivers/hwmon/Kconfig | 13 ++++
- drivers/hwmon/Makefile | 1 +
- drivers/hwmon/surface_fan.c | 93 +++++++++++++++++++++++++++++
- 6 files changed, 141 insertions(+)
- create mode 100644 Documentation/hwmon/surface_fan.rst
- create mode 100644 drivers/hwmon/surface_fan.c
- diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
- index c7ed1f73ac06..58be92e94a8d 100644
- --- a/Documentation/hwmon/index.rst
- +++ b/Documentation/hwmon/index.rst
- @@ -208,6 +208,7 @@ Hardware Monitoring Kernel Drivers
- smsc47m1
- sparx5-temp
- stpddc60
- + surface_fan
- sy7636a-hwmon
- tc654
- tc74
- diff --git a/Documentation/hwmon/surface_fan.rst b/Documentation/hwmon/surface_fan.rst
- new file mode 100644
- index 000000000000..07942574c4f0
- --- /dev/null
- +++ b/Documentation/hwmon/surface_fan.rst
- @@ -0,0 +1,25 @@
- +.. SPDX-License-Identifier: GPL-2.0-or-later
- +
- +Kernel driver surface_fan
- +=========================
- +
- +Supported Devices:
- +
- + * Microsoft Surface Pro 9
- +
- +Author: Ivor Wanders <ivor@iwanders.net>
- +
- +Description
- +-----------
- +
- +This provides monitoring of the fan found in some Microsoft Surface Pro devices,
- +like the Surface Pro 9. The fan is always controlled by the onboard controller.
- +
- +Sysfs interface
- +---------------
- +
- +======================= ======= =========================================
- +Name Perm Description
- +======================= ======= =========================================
- +``fan1_input`` RO Current fan speed in RPM.
- +======================= ======= =========================================
- diff --git a/MAINTAINERS b/MAINTAINERS
- index 1aabf1c15bb3..b6416cf3f022 100644
- --- a/MAINTAINERS
- +++ b/MAINTAINERS
- @@ -14576,6 +14576,14 @@ F: Documentation/driver-api/surface_aggregator/clients/dtx.rst
- F: drivers/platform/surface/surface_dtx.c
- F: include/uapi/linux/surface_aggregator/dtx.h
-
- +MICROSOFT SURFACE SENSOR FAN DRIVER
- +M: Maximilian Luz <luzmaximilian@gmail.com>
- +M: Ivor Wanders <ivor@iwanders.net>
- +L: linux-hwmon@vger.kernel.org
- +S: Maintained
- +F: Documentation/hwmon/surface_fan.rst
- +F: drivers/hwmon/surface_fan.c
- +
- MICROSOFT SURFACE GPE LID SUPPORT DRIVER
- M: Maximilian Luz <luzmaximilian@gmail.com>
- L: platform-driver-x86@vger.kernel.org
- diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
- index a608264da87d..e762f6138970 100644
- --- a/drivers/hwmon/Kconfig
- +++ b/drivers/hwmon/Kconfig
- @@ -1994,6 +1994,19 @@ config SENSORS_SFCTEMP
- This driver can also be built as a module. If so, the module
- will be called sfctemp.
-
- +config SENSORS_SURFACE_FAN
- + tristate "Surface Fan Driver"
- + depends on SURFACE_AGGREGATOR
- + help
- + Driver that provides monitoring of the fan on Surface Pro devices that
- + have a fan, like the Surface Pro 9.
- +
- + This makes the fan's current speed accessible through the hwmon
- + system. It does not provide control over the fan, the firmware is
- + responsible for that, this driver merely provides monitoring.
- +
- + Select M or Y here, if you want to be able to read the fan's speed.
- +
- config SENSORS_ADC128D818
- tristate "Texas Instruments ADC128D818"
- depends on I2C
- diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
- index 47be39af5c03..30cc90f40844 100644
- --- a/drivers/hwmon/Makefile
- +++ b/drivers/hwmon/Makefile
- @@ -201,6 +201,7 @@ obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
- obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
- obj-$(CONFIG_SENSORS_SPARX5) += sparx5-temp.o
- obj-$(CONFIG_SENSORS_STTS751) += stts751.o
- +obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o
- obj-$(CONFIG_SENSORS_SY7636A) += sy7636a-hwmon.o
- obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o
- obj-$(CONFIG_SENSORS_TC74) += tc74.o
- diff --git a/drivers/hwmon/surface_fan.c b/drivers/hwmon/surface_fan.c
- new file mode 100644
- index 000000000000..7c2e3ae3eb40
- --- /dev/null
- +++ b/drivers/hwmon/surface_fan.c
- @@ -0,0 +1,93 @@
- +// SPDX-License-Identifier: GPL-2.0+
- +/*
- + * Surface Fan driver for Surface System Aggregator Module. It provides access
- + * to the fan's rpm through the hwmon system.
- + *
- + * Copyright (C) 2023 Ivor Wanders <ivor@iwanders.net>
- + */
- +
- +#include <linux/hwmon.h>
- +#include <linux/kernel.h>
- +#include <linux/module.h>
- +#include <linux/surface_aggregator/device.h>
- +#include <linux/types.h>
- +
- +// SSAM
- +SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_fan_rpm_get, __le16, {
- + .target_category = SSAM_SSH_TC_FAN,
- + .command_id = 0x01,
- +});
- +
- +// hwmon
- +umode_t surface_fan_hwmon_is_visible(const void *drvdata,
- + enum hwmon_sensor_types type, u32 attr,
- + int channel)
- +{
- + return 0444;
- +}
- +
- +static int surface_fan_hwmon_read(struct device *dev,
- + enum hwmon_sensor_types type, u32 attr,
- + int channel, long *val)
- +{
- + struct ssam_device *sdev = dev_get_drvdata(dev);
- + int ret;
- + __le16 value;
- +
- + ret = __ssam_fan_rpm_get(sdev, &value);
- + if (ret)
- + return ret;
- +
- + *val = le16_to_cpu(value);
- +
- + return ret;
- +}
- +
- +static const struct hwmon_channel_info *const surface_fan_info[] = {
- + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
- + NULL
- +};
- +
- +static const struct hwmon_ops surface_fan_hwmon_ops = {
- + .is_visible = surface_fan_hwmon_is_visible,
- + .read = surface_fan_hwmon_read,
- +};
- +
- +static const struct hwmon_chip_info surface_fan_chip_info = {
- + .ops = &surface_fan_hwmon_ops,
- + .info = surface_fan_info,
- +};
- +
- +static int surface_fan_probe(struct ssam_device *sdev)
- +{
- + struct device *hdev;
- +
- + hdev = devm_hwmon_device_register_with_info(&sdev->dev,
- + "surface_fan", sdev,
- + &surface_fan_chip_info,
- + NULL);
- + if (IS_ERR(hdev))
- + return PTR_ERR(hdev);
- +
- + return 0;
- +}
- +
- +static const struct ssam_device_id ssam_fan_match[] = {
- + { SSAM_SDEV(FAN, SAM, 0x01, 0x01) },
- + {},
- +};
- +MODULE_DEVICE_TABLE(ssam, ssam_fan_match);
- +
- +static struct ssam_device_driver surface_fan = {
- + .probe = surface_fan_probe,
- + .match_table = ssam_fan_match,
- + .driver = {
- + .name = "surface_fan",
- + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
- + },
- +};
- +module_ssam_device_driver(surface_fan);
- +
- +MODULE_AUTHOR("Ivor Wanders <ivor@iwanders.net>");
- +MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
- +MODULE_LICENSE("GPL");
- --
- 2.44.0
- From 5c18bed9c7ad073b61e3c3686dc4bc1858f958dc Mon Sep 17 00:00:00 2001
- From: Maximilian Luz <luzmaximilian@gmail.com>
- Date: Sat, 30 Dec 2023 18:07:54 +0100
- Subject: [PATCH] hwmon: Add thermal sensor driver for Surface Aggregator
- Module
- Some of the newer Microsoft Surface devices (such as the Surface Book
- 3 and Pro 9) have thermal sensors connected via the Surface Aggregator
- Module (the embedded controller on those devices). Add a basic driver
- to read out the temperature values of those sensors.
- Link: https://github.com/linux-surface/surface-aggregator-module/issues/59
- Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
- Patchset: surface-sam
- ---
- drivers/hwmon/Kconfig | 10 +++
- drivers/hwmon/Makefile | 1 +
- drivers/hwmon/surface_temp.c | 165 +++++++++++++++++++++++++++++++++++
- 3 files changed, 176 insertions(+)
- create mode 100644 drivers/hwmon/surface_temp.c
- diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
- index e762f6138970..41261b49f8be 100644
- --- a/drivers/hwmon/Kconfig
- +++ b/drivers/hwmon/Kconfig
- @@ -2007,6 +2007,16 @@ config SENSORS_SURFACE_FAN
-
- Select M or Y here, if you want to be able to read the fan's speed.
-
- +config SENSORS_SURFACE_TEMP
- + tristate "Microsoft Surface Thermal Sensor Driver"
- + depends on SURFACE_AGGREGATOR
- + help
- + Driver for monitoring thermal sensors connected via the Surface
- + Aggregator Module (embedded controller) on Microsoft Surface devices.
- +
- + This driver can also be built as a module. If so, the module
- + will be called surface_temp.
- +
- config SENSORS_ADC128D818
- tristate "Texas Instruments ADC128D818"
- depends on I2C
- diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
- index 30cc90f40844..6644fd4598a4 100644
- --- a/drivers/hwmon/Makefile
- +++ b/drivers/hwmon/Makefile
- @@ -202,6 +202,7 @@ obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
- obj-$(CONFIG_SENSORS_SPARX5) += sparx5-temp.o
- obj-$(CONFIG_SENSORS_STTS751) += stts751.o
- obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o
- +obj-$(CONFIG_SENSORS_SURFACE_TEMP)+= surface_temp.o
- obj-$(CONFIG_SENSORS_SY7636A) += sy7636a-hwmon.o
- obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o
- obj-$(CONFIG_SENSORS_TC74) += tc74.o
- diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c
- new file mode 100644
- index 000000000000..48c3e826713f
- --- /dev/null
- +++ b/drivers/hwmon/surface_temp.c
- @@ -0,0 +1,165 @@
- +// SPDX-License-Identifier: GPL-2.0+
- +/*
- + * Thermal sensor subsystem driver for Surface System Aggregator Module (SSAM).
- + *
- + * Copyright (C) 2022-2023 Maximilian Luz <luzmaximilian@gmail.com>
- + */
- +
- +#include <linux/bitops.h>
- +#include <linux/hwmon.h>
- +#include <linux/kernel.h>
- +#include <linux/module.h>
- +#include <linux/types.h>
- +
- +#include <linux/surface_aggregator/controller.h>
- +#include <linux/surface_aggregator/device.h>
- +
- +
- +/* -- SAM interface. -------------------------------------------------------- */
- +
- +SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, {
- + .target_category = SSAM_SSH_TC_TMP,
- + .command_id = 0x04,
- +});
- +
- +SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_temperature, __le16, {
- + .target_category = SSAM_SSH_TC_TMP,
- + .command_id = 0x01,
- +});
- +
- +static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors)
- +{
- + __le16 sensors_le;
- + int status;
- +
- + status = __ssam_tmp_get_available_sensors(sdev, &sensors_le);
- + if (status)
- + return status;
- +
- + *sensors = le16_to_cpu(sensors_le);
- + return 0;
- +}
- +
- +static int ssam_tmp_get_temperature(struct ssam_device *sdev, u8 iid, long *temperature)
- +{
- + __le16 temp_le;
- + int status;
- +
- + status = __ssam_tmp_get_temperature(sdev->ctrl, sdev->uid.target, iid, &temp_le);
- + if (status)
- + return status;
- +
- + /* Convert 1/10 °K to 1/1000 °C */
- + *temperature = (le16_to_cpu(temp_le) - 2731) * 100L;
- + return 0;
- +}
- +
- +
- +/* -- Driver.---------------------------------------------------------------- */
- +
- +struct ssam_temp {
- + struct ssam_device *sdev;
- + s16 sensors;
- +};
- +
- +static umode_t ssam_temp_hwmon_is_visible(const void *data,
- + enum hwmon_sensor_types type,
- + u32 attr, int channel)
- +{
- + const struct ssam_temp *ssam_temp = data;
- +
- + if (!(ssam_temp->sensors & BIT(channel)))
- + return 0;
- +
- + return 0444;
- +}
- +
- +static int ssam_temp_hwmon_read(struct device *dev,
- + enum hwmon_sensor_types type,
- + u32 attr, int channel, long *value)
- +{
- + const struct ssam_temp *ssam_temp = dev_get_drvdata(dev);
- +
- + return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value);
- +}
- +
- +static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = {
- + HWMON_CHANNEL_INFO(chip,
- + HWMON_C_REGISTER_TZ),
- + /* We have at most 16 thermal sensor channels. */
- + HWMON_CHANNEL_INFO(temp,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT,
- + HWMON_T_INPUT),
- + NULL
- +};
- +
- +static const struct hwmon_ops ssam_temp_hwmon_ops = {
- + .is_visible = ssam_temp_hwmon_is_visible,
- + .read = ssam_temp_hwmon_read,
- +};
- +
- +static const struct hwmon_chip_info ssam_temp_hwmon_chip_info = {
- + .ops = &ssam_temp_hwmon_ops,
- + .info = ssam_temp_hwmon_info,
- +};
- +
- +static int ssam_temp_probe(struct ssam_device *sdev)
- +{
- + struct ssam_temp *ssam_temp;
- + struct device *hwmon_dev;
- + s16 sensors;
- + int status;
- +
- + status = ssam_tmp_get_available_sensors(sdev, &sensors);
- + if (status)
- + return status;
- +
- + ssam_temp = devm_kzalloc(&sdev->dev, sizeof(*ssam_temp), GFP_KERNEL);
- + if (!ssam_temp)
- + return -ENOMEM;
- +
- + ssam_temp->sdev = sdev;
- + ssam_temp->sensors = sensors;
- +
- + hwmon_dev = devm_hwmon_device_register_with_info(&sdev->dev,
- + "surface_thermal", ssam_temp, &ssam_temp_hwmon_chip_info,
- + NULL);
- + if (IS_ERR(hwmon_dev))
- + return PTR_ERR(hwmon_dev);
- +
- + return 0;
- +}
- +
- +static const struct ssam_device_id ssam_temp_match[] = {
- + { SSAM_SDEV(TMP, SAM, 0x00, 0x02) },
- + { },
- +};
- +MODULE_DEVICE_TABLE(ssam, ssam_temp_match);
- +
- +static struct ssam_device_driver ssam_temp = {
- + .probe = ssam_temp_probe,
- + .match_table = ssam_temp_match,
- + .driver = {
- + .name = "surface_temp",
- + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
- + },
- +};
- +module_ssam_device_driver(ssam_temp);
- +
- +MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
- +MODULE_DESCRIPTION("Thermal sensor subsystem driver for Surface System Aggregator Module");
- +MODULE_LICENSE("GPL");
- --
- 2.44.0
- From 8b1e37ad9423a6fdf8a8b3bfb1e15aadefe136de Mon Sep 17 00:00:00 2001
- From: Maximilian Luz <luzmaximilian@gmail.com>
- Date: Sat, 30 Dec 2023 18:12:23 +0100
- Subject: [PATCH] hwmon: surface_temp: Add support for sensor names
- The thermal subsystem of the Surface Aggregator Module allows us to
- query the names of the respective thermal sensors. Forward those to
- userspace.
- Signed-off-by: Ivor Wanders <ivor@iwanders.net>
- Co-Developed-by: Maximilian Luz <luzmaximilian@gmail.com>
- Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
- Patchset: surface-sam
- ---
- drivers/hwmon/surface_temp.c | 113 +++++++++++++++++++++++++++++------
- 1 file changed, 96 insertions(+), 17 deletions(-)
- diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c
- index 48c3e826713f..4c08926139db 100644
- --- a/drivers/hwmon/surface_temp.c
- +++ b/drivers/hwmon/surface_temp.c
- @@ -17,6 +17,27 @@
-
- /* -- SAM interface. -------------------------------------------------------- */
-
- +/*
- + * Available sensors are indicated by a 16-bit bitfield, where a 1 marks the
- + * presence of a sensor. So we have at most 16 possible sensors/channels.
- + */
- +#define SSAM_TMP_SENSOR_MAX_COUNT 16
- +
- +/*
- + * All names observed so far are 6 characters long, but there's only
- + * zeros after the name, so perhaps they can be longer. This number reflects
- + * the maximum zero-padded space observed in the returned buffer.
- + */
- +#define SSAM_TMP_SENSOR_NAME_LENGTH 18
- +
- +struct ssam_tmp_get_name_rsp {
- + __le16 unknown1;
- + char unknown2;
- + char name[SSAM_TMP_SENSOR_NAME_LENGTH];
- +} __packed;
- +
- +static_assert(sizeof(struct ssam_tmp_get_name_rsp) == 21);
- +
- SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, {
- .target_category = SSAM_SSH_TC_TMP,
- .command_id = 0x04,
- @@ -27,6 +48,11 @@ SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_temperature, __le16, {
- .command_id = 0x01,
- });
-
- +SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_name, struct ssam_tmp_get_name_rsp, {
- + .target_category = SSAM_SSH_TC_TMP,
- + .command_id = 0x0e,
- +});
- +
- static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors)
- {
- __le16 sensors_le;
- @@ -54,12 +80,37 @@ static int ssam_tmp_get_temperature(struct ssam_device *sdev, u8 iid, long *temp
- return 0;
- }
-
- +static int ssam_tmp_get_name(struct ssam_device *sdev, u8 iid, char *buf, size_t buf_len)
- +{
- + struct ssam_tmp_get_name_rsp name_rsp;
- + int status;
- +
- + status = __ssam_tmp_get_name(sdev->ctrl, sdev->uid.target, iid, &name_rsp);
- + if (status)
- + return status;
- +
- + /*
- + * This should not fail unless the name in the returned struct is not
- + * null-terminated or someone changed something in the struct
- + * definitions above, since our buffer and struct have the same
- + * capacity by design. So if this fails blow this up with a warning.
- + * Since the more likely cause is that the returned string isn't
- + * null-terminated, we might have received garbage (as opposed to just
- + * an incomplete string), so also fail the function.
- + */
- + status = strscpy(buf, name_rsp.name, buf_len);
- + WARN_ON(status < 0);
- +
- + return status < 0 ? status : 0;
- +}
- +
-
- /* -- Driver.---------------------------------------------------------------- */
-
- struct ssam_temp {
- struct ssam_device *sdev;
- s16 sensors;
- + char names[SSAM_TMP_SENSOR_MAX_COUNT][SSAM_TMP_SENSOR_NAME_LENGTH];
- };
-
- static umode_t ssam_temp_hwmon_is_visible(const void *data,
- @@ -83,33 +134,47 @@ static int ssam_temp_hwmon_read(struct device *dev,
- return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value);
- }
-
- +static int ssam_temp_hwmon_read_string(struct device *dev,
- + enum hwmon_sensor_types type,
- + u32 attr, int channel, const char **str)
- +{
- + const struct ssam_temp *ssam_temp = dev_get_drvdata(dev);
- +
- + *str = ssam_temp->names[channel];
- + return 0;
- +}
- +
- static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = {
- HWMON_CHANNEL_INFO(chip,
- HWMON_C_REGISTER_TZ),
- - /* We have at most 16 thermal sensor channels. */
- + /*
- + * We have at most SSAM_TMP_SENSOR_MAX_COUNT = 16 thermal sensor
- + * channels.
- + */
- HWMON_CHANNEL_INFO(temp,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT,
- - HWMON_T_INPUT),
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL,
- + HWMON_T_INPUT | HWMON_T_LABEL),
- NULL
- };
-
- static const struct hwmon_ops ssam_temp_hwmon_ops = {
- .is_visible = ssam_temp_hwmon_is_visible,
- .read = ssam_temp_hwmon_read,
- + .read_string = ssam_temp_hwmon_read_string,
- };
-
- static const struct hwmon_chip_info ssam_temp_hwmon_chip_info = {
- @@ -122,6 +187,7 @@ static int ssam_temp_probe(struct ssam_device *sdev)
- struct ssam_temp *ssam_temp;
- struct device *hwmon_dev;
- s16 sensors;
- + int channel;
- int status;
-
- status = ssam_tmp_get_available_sensors(sdev, &sensors);
- @@ -135,6 +201,19 @@ static int ssam_temp_probe(struct ssam_device *sdev)
- ssam_temp->sdev = sdev;
- ssam_temp->sensors = sensors;
-
- + /* Retrieve the name for each available sensor. */
- + for (channel = 0; channel < SSAM_TMP_SENSOR_MAX_COUNT; channel++)
- + {
- + if (!(sensors & BIT(channel)))
- + continue;
- +
- + status = ssam_tmp_get_name(sdev, channel + 1,
- + ssam_temp->names[channel],
- + SSAM_TMP_SENSOR_NAME_LENGTH);
- + if (status)
- + return status;
- + }
- +
- hwmon_dev = devm_hwmon_device_register_with_info(&sdev->dev,
- "surface_thermal", ssam_temp, &ssam_temp_hwmon_chip_info,
- NULL);
- --
- 2.44.0
- From 9b490a17f59518e59cf3c77c103bf5ddc52041a3 Mon Sep 17 00:00:00 2001
- From: Maximilian Luz <luzmaximilian@gmail.com>
- Date: Sat, 30 Dec 2023 18:21:12 +0100
- Subject: [PATCH] platform/surface: aggregator_registry: Add support for
- thermal sensors on the Surface Pro 9
- The Surface Pro 9 has thermal sensors connected via the Surface
- Aggregator Module. Add a device node to support those.
- Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
- Patchset: surface-sam
- ---
- drivers/platform/surface/surface_aggregator_registry.c | 7 +++++++
- 1 file changed, 7 insertions(+)
- diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
- index f02a933160ff..67686042e009 100644
- --- a/drivers/platform/surface/surface_aggregator_registry.c
- +++ b/drivers/platform/surface/surface_aggregator_registry.c
- @@ -74,6 +74,12 @@ static const struct software_node ssam_node_tmp_pprof = {
- .parent = &ssam_node_root,
- };
-
- +/* Thermal sensors. */
- +static const struct software_node ssam_node_tmp_sensors = {
- + .name = "ssam:01:03:01:00:02",
- + .parent = &ssam_node_root,
- +};
- +
- /* Fan speed function. */
- static const struct software_node ssam_node_fan_speed = {
- .name = "ssam:01:05:01:01:01",
- @@ -325,6 +331,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- &ssam_node_tmp_pprof,
- + &ssam_node_tmp_sensors,
- &ssam_node_fan_speed,
- &ssam_node_pos_tablet_switch,
- &ssam_node_hid_kip_keyboard,
- --
- 2.44.0
- From ec0b680c0ce36ef6bffd682e10589cf5d8d467ae Mon Sep 17 00:00:00 2001
- From: Ivor Wanders <ivor@iwanders.net>
- Date: Sat, 16 Dec 2023 15:56:39 -0500
- Subject: [PATCH] platform/surface: platform_profile: add fan profile switching
- Change naming from tmp to platform profile to clarify the module may
- interact with both the TMP and FAN subystems. Add functionality that
- switches the fan profile when the platform profile is changed.
- Signed-off-by: Ivor Wanders <ivor@iwanders.net>
- Patchset: surface-sam
- ---
- .../surface/surface_aggregator_registry.c | 38 +++++---
- .../surface/surface_platform_profile.c | 86 ++++++++++++++++---
- 2 files changed, 100 insertions(+), 24 deletions(-)
- diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
- index 67686042e009..058b6654a91a 100644
- --- a/drivers/platform/surface/surface_aggregator_registry.c
- +++ b/drivers/platform/surface/surface_aggregator_registry.c
- @@ -68,8 +68,8 @@ static const struct software_node ssam_node_bat_sb3base = {
- .parent = &ssam_node_hub_base,
- };
-
- -/* Platform profile / performance-mode device. */
- -static const struct software_node ssam_node_tmp_pprof = {
- +/* Platform profile / performance-mode device without a fan. */
- +static const struct software_node ssam_node_tmp_perf_profile = {
- .name = "ssam:01:03:01:00:01",
- .parent = &ssam_node_root,
- };
- @@ -86,6 +86,20 @@ static const struct software_node ssam_node_fan_speed = {
- .parent = &ssam_node_root,
- };
-
- +/* Platform profile / performance-mode device with a fan, such that
- + * the fan controller profile can also be switched.
- + */
- +static const struct property_entry ssam_node_tmp_perf_profile_has_fan[] = {
- + PROPERTY_ENTRY_BOOL("has_fan"),
- + { }
- +};
- +
- +static const struct software_node ssam_node_tmp_perf_profile_with_fan = {
- + .name = "ssam:01:03:01:00:01",
- + .parent = &ssam_node_root,
- + .properties = ssam_node_tmp_perf_profile_has_fan,
- +};
- +
- /* Tablet-mode switch via KIP subsystem. */
- static const struct software_node ssam_node_kip_tablet_switch = {
- .name = "ssam:01:0e:01:00:01",
- @@ -214,7 +228,7 @@ static const struct software_node ssam_node_pos_tablet_switch = {
- */
- static const struct software_node *ssam_node_group_gen5[] = {
- &ssam_node_root,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- NULL,
- };
-
- @@ -225,7 +239,7 @@ static const struct software_node *ssam_node_group_sb3[] = {
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- &ssam_node_bat_sb3base,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- &ssam_node_bas_dtx,
- &ssam_node_hid_base_keyboard,
- &ssam_node_hid_base_touchpad,
- @@ -239,7 +253,7 @@ static const struct software_node *ssam_node_group_sl3[] = {
- &ssam_node_root,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- &ssam_node_hid_main_keyboard,
- &ssam_node_hid_main_touchpad,
- &ssam_node_hid_main_iid5,
- @@ -251,7 +265,7 @@ static const struct software_node *ssam_node_group_sl5[] = {
- &ssam_node_root,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- &ssam_node_hid_main_keyboard,
- &ssam_node_hid_main_touchpad,
- &ssam_node_hid_main_iid5,
- @@ -264,7 +278,7 @@ static const struct software_node *ssam_node_group_sls1[] = {
- &ssam_node_root,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- &ssam_node_pos_tablet_switch,
- &ssam_node_hid_sam_keyboard,
- &ssam_node_hid_sam_penstash,
- @@ -280,7 +294,7 @@ static const struct software_node *ssam_node_group_sls2[] = {
- &ssam_node_root,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- &ssam_node_pos_tablet_switch,
- &ssam_node_hid_sam_keyboard,
- &ssam_node_hid_sam_penstash,
- @@ -294,7 +308,7 @@ static const struct software_node *ssam_node_group_slg1[] = {
- &ssam_node_root,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- NULL,
- };
-
- @@ -303,7 +317,7 @@ static const struct software_node *ssam_node_group_sp7[] = {
- &ssam_node_root,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- NULL,
- };
-
- @@ -313,7 +327,7 @@ static const struct software_node *ssam_node_group_sp8[] = {
- &ssam_node_hub_kip,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile,
- &ssam_node_kip_tablet_switch,
- &ssam_node_hid_kip_keyboard,
- &ssam_node_hid_kip_penstash,
- @@ -330,7 +344,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
- &ssam_node_hub_kip,
- &ssam_node_bat_ac,
- &ssam_node_bat_main,
- - &ssam_node_tmp_pprof,
- + &ssam_node_tmp_perf_profile_with_fan,
- &ssam_node_tmp_sensors,
- &ssam_node_fan_speed,
- &ssam_node_pos_tablet_switch,
- diff --git a/drivers/platform/surface/surface_platform_profile.c b/drivers/platform/surface/surface_platform_profile.c
- index a5a3941b3f43..e54d0a8f7daa 100644
- --- a/drivers/platform/surface/surface_platform_profile.c
- +++ b/drivers/platform/surface/surface_platform_profile.c
- @@ -1,7 +1,7 @@
- // SPDX-License-Identifier: GPL-2.0+
- /*
- * Surface Platform Profile / Performance Mode driver for Surface System
- - * Aggregator Module (thermal subsystem).
- + * Aggregator Module (thermal and fan subsystem).
- *
- * Copyright (C) 2021-2022 Maximilian Luz <luzmaximilian@gmail.com>
- */
- @@ -14,6 +14,7 @@
-
- #include <linux/surface_aggregator/device.h>
-
- +// Enum for the platform performance profile sent to the TMP module.
- enum ssam_tmp_profile {
- SSAM_TMP_PROFILE_NORMAL = 1,
- SSAM_TMP_PROFILE_BATTERY_SAVER = 2,
- @@ -21,15 +22,26 @@ enum ssam_tmp_profile {
- SSAM_TMP_PROFILE_BEST_PERFORMANCE = 4,
- };
-
- +// Enum for the fan profile sent to the FAN module. This fan profile is
- +// only sent to the EC if the 'has_fan' property is set. The integers are
- +// not a typo, they differ from the performance profile indices.
- +enum ssam_fan_profile {
- + SSAM_FAN_PROFILE_NORMAL = 2,
- + SSAM_FAN_PROFILE_BATTERY_SAVER = 1,
- + SSAM_FAN_PROFILE_BETTER_PERFORMANCE = 3,
- + SSAM_FAN_PROFILE_BEST_PERFORMANCE = 4,
- +};
- +
- struct ssam_tmp_profile_info {
- __le32 profile;
- __le16 unknown1;
- __le16 unknown2;
- } __packed;
-
- -struct ssam_tmp_profile_device {
- +struct ssam_platform_profile_device {
- struct ssam_device *sdev;
- struct platform_profile_handler handler;
- + bool has_fan;
- };
-
- SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_profile_get, struct ssam_tmp_profile_info, {
- @@ -42,6 +54,13 @@ SSAM_DEFINE_SYNC_REQUEST_CL_W(__ssam_tmp_profile_set, __le32, {
- .command_id = 0x03,
- });
-
- +SSAM_DEFINE_SYNC_REQUEST_W(__ssam_fan_profile_set, char, {
- + .target_category = SSAM_SSH_TC_FAN,
- + .target_id = SSAM_SSH_TID_SAM,
- + .command_id = 0x0e,
- + .instance_id = 0x01,
- +});
- +
- static int ssam_tmp_profile_get(struct ssam_device *sdev, enum ssam_tmp_profile *p)
- {
- struct ssam_tmp_profile_info info;
- @@ -62,7 +81,14 @@ static int ssam_tmp_profile_set(struct ssam_device *sdev, enum ssam_tmp_profile
- return ssam_retry(__ssam_tmp_profile_set, sdev, &profile_le);
- }
-
- -static int convert_ssam_to_profile(struct ssam_device *sdev, enum ssam_tmp_profile p)
- +static int ssam_fan_profile_set(struct ssam_device *sdev, enum ssam_fan_profile p)
- +{
- + char profile = p;
- +
- + return ssam_retry(__ssam_fan_profile_set, sdev->ctrl, &profile);
- +}
- +
- +static int convert_ssam_tmp_to_profile(struct ssam_device *sdev, enum ssam_tmp_profile p)
- {
- switch (p) {
- case SSAM_TMP_PROFILE_NORMAL:
- @@ -83,7 +109,8 @@ static int convert_ssam_to_profile(struct ssam_device *sdev, enum ssam_tmp_profi
- }
- }
-
- -static int convert_profile_to_ssam(struct ssam_device *sdev, enum platform_profile_option p)
- +
- +static int convert_profile_to_ssam_tmp(struct ssam_device *sdev, enum platform_profile_option p)
- {
- switch (p) {
- case PLATFORM_PROFILE_LOW_POWER:
- @@ -105,20 +132,42 @@ static int convert_profile_to_ssam(struct ssam_device *sdev, enum platform_profi
- }
- }
-
- +static int convert_profile_to_ssam_fan(struct ssam_device *sdev, enum platform_profile_option p)
- +{
- + switch (p) {
- + case PLATFORM_PROFILE_LOW_POWER:
- + return SSAM_FAN_PROFILE_BATTERY_SAVER;
- +
- + case PLATFORM_PROFILE_BALANCED:
- + return SSAM_FAN_PROFILE_NORMAL;
- +
- + case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
- + return SSAM_FAN_PROFILE_BETTER_PERFORMANCE;
- +
- + case PLATFORM_PROFILE_PERFORMANCE:
- + return SSAM_FAN_PROFILE_BEST_PERFORMANCE;
- +
- + default:
- + /* This should have already been caught by platform_profile_store(). */
- + WARN(true, "unsupported platform profile");
- + return -EOPNOTSUPP;
- + }
- +}
- +
- static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
- enum platform_profile_option *profile)
- {
- - struct ssam_tmp_profile_device *tpd;
- + struct ssam_platform_profile_device *tpd;
- enum ssam_tmp_profile tp;
- int status;
-
- - tpd = container_of(pprof, struct ssam_tmp_profile_device, handler);
- + tpd = container_of(pprof, struct ssam_platform_profile_device, handler);
-
- status = ssam_tmp_profile_get(tpd->sdev, &tp);
- if (status)
- return status;
-
- - status = convert_ssam_to_profile(tpd->sdev, tp);
- + status = convert_ssam_tmp_to_profile(tpd->sdev, tp);
- if (status < 0)
- return status;
-
- @@ -129,21 +178,32 @@ static int ssam_platform_profile_get(struct platform_profile_handler *pprof,
- static int ssam_platform_profile_set(struct platform_profile_handler *pprof,
- enum platform_profile_option profile)
- {
- - struct ssam_tmp_profile_device *tpd;
- + struct ssam_platform_profile_device *tpd;
- int tp;
-
- - tpd = container_of(pprof, struct ssam_tmp_profile_device, handler);
- + tpd = container_of(pprof, struct ssam_platform_profile_device, handler);
- +
- + tp = convert_profile_to_ssam_tmp(tpd->sdev, profile);
- + if (tp < 0)
- + return tp;
-
- - tp = convert_profile_to_ssam(tpd->sdev, profile);
- + tp = ssam_tmp_profile_set(tpd->sdev, tp);
- if (tp < 0)
- return tp;
-
- - return ssam_tmp_profile_set(tpd->sdev, tp);
- + if (tpd->has_fan) {
- + tp = convert_profile_to_ssam_fan(tpd->sdev, profile);
- + if (tp < 0)
- + return tp;
- + tp = ssam_fan_profile_set(tpd->sdev, tp);
- + }
- +
- + return tp;
- }
-
- static int surface_platform_profile_probe(struct ssam_device *sdev)
- {
- - struct ssam_tmp_profile_device *tpd;
- + struct ssam_platform_profile_device *tpd;
-
- tpd = devm_kzalloc(&sdev->dev, sizeof(*tpd), GFP_KERNEL);
- if (!tpd)
- @@ -154,6 +214,8 @@ static int surface_platform_profile_probe(struct ssam_device *sdev)
- tpd->handler.profile_get = ssam_platform_profile_get;
- tpd->handler.profile_set = ssam_platform_profile_set;
-
- + tpd->has_fan = device_property_read_bool(&sdev->dev, "has_fan");
- +
- set_bit(PLATFORM_PROFILE_LOW_POWER, tpd->handler.choices);
- set_bit(PLATFORM_PROFILE_BALANCED, tpd->handler.choices);
- set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, tpd->handler.choices);
- --
- 2.44.0
- From 63781a056a0f06d5cc38d7755e0753c7ec08c51c Mon Sep 17 00:00:00 2001
- From: Maximilian Luz <luzmaximilian@gmail.com>
- Date: Fri, 19 Apr 2024 20:41:47 +0200
- Subject: [PATCH] platform/surface: aggregator: Fix warning when controller is
- destroyed in probe
- There is a small window in ssam_serial_hub_probe() where the controller
- is initialized but has not been started yet. Specifically, between
- ssam_controller_init() and ssam_controller_start(). Any failure in this
- window, for example caused by a failure of serdev_device_open(),
- currently results in an incorrect warning being emitted.
- In particular, any failure in this window results in the controller
- being destroyed via ssam_controller_destroy(). This function checks the
- state of the controller and, in an attempt to validate that the
- controller has been cleanly shut down before we try and deallocate any
- resources, emits a warning if that state is not SSAM_CONTROLLER_STOPPED.
- However, since we have only just initialized the controller and have not
- yet started it, its state is SSAM_CONTROLLER_INITIALIZED. Note that this
- is the only point at which the controller has this state, as it will
- change after we start the controller with ssam_controller_start() and
- never revert back. Further, at this point no communication has taken
- place and the sender and receiver threads have not been started yet (and
- we may not even have an open serdev device either).
- Therefore, it is perfectly safe to call ssam_controller_destroy() with a
- state of SSAM_CONTROLLER_INITIALIZED. This, however, means that the
- warning currently being emitted is incorrect. Fix it by extending the
- check.
- Fixes: c167b9c7e3d6 ("platform/surface: Add Surface Aggregator subsystem")
- Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
- ---
- drivers/platform/surface/aggregator/controller.c | 3 ++-
- 1 file changed, 2 insertions(+), 1 deletion(-)
- diff --git a/drivers/platform/surface/aggregator/controller.c b/drivers/platform/surface/aggregator/controller.c
- index 7fc602e01487..7e89f547999b 100644
- --- a/drivers/platform/surface/aggregator/controller.c
- +++ b/drivers/platform/surface/aggregator/controller.c
- @@ -1354,7 +1354,8 @@ void ssam_controller_destroy(struct ssam_controller *ctrl)
- if (ctrl->state == SSAM_CONTROLLER_UNINITIALIZED)
- return;
-
- - WARN_ON(ctrl->state != SSAM_CONTROLLER_STOPPED);
- + WARN_ON(ctrl->state != SSAM_CONTROLLER_STOPPED &&
- + ctrl->state != SSAM_CONTROLLER_INITIALIZED);
-
- /*
- * Note: New events could still have been received after the previous
- --
- 2.44.0
|