0007-surface-sam.patch 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. From 17af44bcfe971e7b9dddad3735fad70bbda3fbf9 Mon Sep 17 00:00:00 2001
  2. From: Maximilian Luz <luzmaximilian@gmail.com>
  3. Date: Fri, 19 Apr 2024 20:41:47 +0200
  4. Subject: [PATCH] platform/surface: aggregator: Fix warning when controller is
  5. destroyed in probe
  6. There is a small window in ssam_serial_hub_probe() where the controller
  7. is initialized but has not been started yet. Specifically, between
  8. ssam_controller_init() and ssam_controller_start(). Any failure in this
  9. window, for example caused by a failure of serdev_device_open(),
  10. currently results in an incorrect warning being emitted.
  11. In particular, any failure in this window results in the controller
  12. being destroyed via ssam_controller_destroy(). This function checks the
  13. state of the controller and, in an attempt to validate that the
  14. controller has been cleanly shut down before we try and deallocate any
  15. resources, emits a warning if that state is not SSAM_CONTROLLER_STOPPED.
  16. However, since we have only just initialized the controller and have not
  17. yet started it, its state is SSAM_CONTROLLER_INITIALIZED. Note that this
  18. is the only point at which the controller has this state, as it will
  19. change after we start the controller with ssam_controller_start() and
  20. never revert back. Further, at this point no communication has taken
  21. place and the sender and receiver threads have not been started yet (and
  22. we may not even have an open serdev device either).
  23. Therefore, it is perfectly safe to call ssam_controller_destroy() with a
  24. state of SSAM_CONTROLLER_INITIALIZED. This, however, means that the
  25. warning currently being emitted is incorrect. Fix it by extending the
  26. check.
  27. Fixes: c167b9c7e3d6 ("platform/surface: Add Surface Aggregator subsystem")
  28. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  29. Patchset: surface-sam
  30. ---
  31. drivers/platform/surface/aggregator/controller.c | 3 ++-
  32. 1 file changed, 2 insertions(+), 1 deletion(-)
  33. diff --git a/drivers/platform/surface/aggregator/controller.c b/drivers/platform/surface/aggregator/controller.c
  34. index 7fc602e01487..7e89f547999b 100644
  35. --- a/drivers/platform/surface/aggregator/controller.c
  36. +++ b/drivers/platform/surface/aggregator/controller.c
  37. @@ -1354,7 +1354,8 @@ void ssam_controller_destroy(struct ssam_controller *ctrl)
  38. if (ctrl->state == SSAM_CONTROLLER_UNINITIALIZED)
  39. return;
  40. - WARN_ON(ctrl->state != SSAM_CONTROLLER_STOPPED);
  41. + WARN_ON(ctrl->state != SSAM_CONTROLLER_STOPPED &&
  42. + ctrl->state != SSAM_CONTROLLER_INITIALIZED);
  43. /*
  44. * Note: New events could still have been received after the previous
  45. --
  46. 2.46.0
  47. From 00b833401e8060eb50db269e0681383454a74848 Mon Sep 17 00:00:00 2001
  48. From: Maximilian Luz <luzmaximilian@gmail.com>
  49. Date: Sun, 22 Oct 2023 14:57:11 +0200
  50. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  51. Surface Laptop Go 3
  52. Add SAM client device nodes for the Surface Laptop Go 3. It seems to use
  53. the same SAM client devices as the Surface Laptop Go 1 and 2, so re-use
  54. their node group.
  55. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  56. Patchset: surface-sam
  57. ---
  58. drivers/platform/surface/surface_aggregator_registry.c | 3 +++
  59. 1 file changed, 3 insertions(+)
  60. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  61. index 1c4d74db08c9..f826489dc69d 100644
  62. --- a/drivers/platform/surface/surface_aggregator_registry.c
  63. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  64. @@ -395,6 +395,9 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
  65. /* Surface Laptop Go 2 */
  66. { "MSHW0290", (unsigned long)ssam_node_group_slg1 },
  67. + /* Surface Laptop Go 3 */
  68. + { "MSHW0440", (unsigned long)ssam_node_group_slg1 },
  69. +
  70. /* Surface Laptop Studio */
  71. { "MSHW0123", (unsigned long)ssam_node_group_sls },
  72. --
  73. 2.46.0
  74. From 9e13165394bf1898d05c7d5a4a5adb1767d2307e Mon Sep 17 00:00:00 2001
  75. From: Maximilian Luz <luzmaximilian@gmail.com>
  76. Date: Mon, 20 Nov 2023 19:47:00 +0100
  77. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  78. Surface Laptop Studio 2
  79. Add SAM client device nodes for the Surface Laptop Studio 2 (SLS2). The
  80. SLS2 is quite similar to the SLS1, but it does not provide the touchpad
  81. as a SAM-HID device. Therefore, add a new node group for the SLS2 and
  82. update the comments accordingly
  83. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  84. Patchset: surface-sam
  85. ---
  86. .../surface/surface_aggregator_registry.c | 25 ++++++++++++++++---
  87. 1 file changed, 21 insertions(+), 4 deletions(-)
  88. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  89. index f826489dc69d..ef59a7b66667 100644
  90. --- a/drivers/platform/surface/surface_aggregator_registry.c
  91. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  92. @@ -273,8 +273,8 @@ static const struct software_node *ssam_node_group_sl5[] = {
  93. NULL,
  94. };
  95. -/* Devices for Surface Laptop Studio. */
  96. -static const struct software_node *ssam_node_group_sls[] = {
  97. +/* Devices for Surface Laptop Studio 1. */
  98. +static const struct software_node *ssam_node_group_sls1[] = {
  99. &ssam_node_root,
  100. &ssam_node_bat_ac,
  101. &ssam_node_bat_main,
  102. @@ -289,6 +289,20 @@ static const struct software_node *ssam_node_group_sls[] = {
  103. NULL,
  104. };
  105. +/* Devices for Surface Laptop Studio 2. */
  106. +static const struct software_node *ssam_node_group_sls2[] = {
  107. + &ssam_node_root,
  108. + &ssam_node_bat_ac,
  109. + &ssam_node_bat_main,
  110. + &ssam_node_tmp_pprof,
  111. + &ssam_node_pos_tablet_switch,
  112. + &ssam_node_hid_sam_keyboard,
  113. + &ssam_node_hid_sam_penstash,
  114. + &ssam_node_hid_sam_sensors,
  115. + &ssam_node_hid_sam_ucm_ucsi,
  116. + NULL,
  117. +};
  118. +
  119. /* Devices for Surface Laptop Go. */
  120. static const struct software_node *ssam_node_group_slg1[] = {
  121. &ssam_node_root,
  122. @@ -398,8 +412,11 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
  123. /* Surface Laptop Go 3 */
  124. { "MSHW0440", (unsigned long)ssam_node_group_slg1 },
  125. - /* Surface Laptop Studio */
  126. - { "MSHW0123", (unsigned long)ssam_node_group_sls },
  127. + /* Surface Laptop Studio 1 */
  128. + { "MSHW0123", (unsigned long)ssam_node_group_sls1 },
  129. +
  130. + /* Surface Laptop Studio 2 */
  131. + { "MSHW0360", (unsigned long)ssam_node_group_sls2 },
  132. { },
  133. };
  134. --
  135. 2.46.0
  136. From 83719d2cd70ad6ac1df993782e757ded15e881cc Mon Sep 17 00:00:00 2001
  137. From: Maximilian Luz <luzmaximilian@gmail.com>
  138. Date: Sun, 9 Jun 2024 20:05:57 +0200
  139. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  140. Surface Laptop 6
  141. Add SAM client device nodes for the Surface Laptop Studio 6 (SL6). The
  142. SL6 is similar to the SL5, with the typical battery/AC, platform
  143. profile, and HID nodes. It also has support for the newly supported fan
  144. interface.
  145. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  146. Patchset: surface-sam
  147. ---
  148. .../surface/surface_aggregator_registry.c | 19 +++++++++++++++++++
  149. 1 file changed, 19 insertions(+)
  150. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  151. index ef59a7b66667..70a2ea5a1957 100644
  152. --- a/drivers/platform/surface/surface_aggregator_registry.c
  153. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  154. @@ -273,6 +273,22 @@ static const struct software_node *ssam_node_group_sl5[] = {
  155. NULL,
  156. };
  157. +/* Devices for Surface Laptop 6. */
  158. +static const struct software_node *ssam_node_group_sl6[] = {
  159. + &ssam_node_root,
  160. + &ssam_node_bat_ac,
  161. + &ssam_node_bat_main,
  162. + &ssam_node_tmp_perf_profile_with_fan,
  163. + &ssam_node_tmp_sensors,
  164. + &ssam_node_fan_speed,
  165. + &ssam_node_hid_main_keyboard,
  166. + &ssam_node_hid_main_touchpad,
  167. + &ssam_node_hid_main_iid5,
  168. + &ssam_node_hid_sam_sensors,
  169. + &ssam_node_hid_sam_ucm_ucsi,
  170. + NULL,
  171. +};
  172. +
  173. /* Devices for Surface Laptop Studio 1. */
  174. static const struct software_node *ssam_node_group_sls1[] = {
  175. &ssam_node_root,
  176. @@ -403,6 +419,9 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
  177. /* Surface Laptop 5 */
  178. { "MSHW0350", (unsigned long)ssam_node_group_sl5 },
  179. + /* Surface Laptop 6 */
  180. + { "MSHW0530", (unsigned long)ssam_node_group_sl5 },
  181. +
  182. /* Surface Laptop Go 1 */
  183. { "MSHW0118", (unsigned long)ssam_node_group_slg1 },
  184. --
  185. 2.46.0
  186. From c188646846cc6e9db1134eb62208d088ce615312 Mon Sep 17 00:00:00 2001
  187. From: Maximilian Luz <luzmaximilian@gmail.com>
  188. Date: Sat, 30 Dec 2023 18:07:54 +0100
  189. Subject: [PATCH] hwmon: Add thermal sensor driver for Surface Aggregator
  190. Module
  191. Some of the newer Microsoft Surface devices (such as the Surface Book
  192. 3 and Pro 9) have thermal sensors connected via the Surface Aggregator
  193. Module (the embedded controller on those devices). Add a basic driver
  194. to read out the temperature values of those sensors.
  195. Link: https://github.com/linux-surface/surface-aggregator-module/issues/59
  196. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  197. Patchset: surface-sam
  198. ---
  199. drivers/hwmon/Kconfig | 10 +++
  200. drivers/hwmon/Makefile | 1 +
  201. drivers/hwmon/surface_temp.c | 165 +++++++++++++++++++++++++++++++++++
  202. 3 files changed, 176 insertions(+)
  203. create mode 100644 drivers/hwmon/surface_temp.c
  204. diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
  205. index e14ae18a973b..76eabe3e4435 100644
  206. --- a/drivers/hwmon/Kconfig
  207. +++ b/drivers/hwmon/Kconfig
  208. @@ -2093,6 +2093,16 @@ config SENSORS_SURFACE_FAN
  209. Select M or Y here, if you want to be able to read the fan's speed.
  210. +config SENSORS_SURFACE_TEMP
  211. + tristate "Microsoft Surface Thermal Sensor Driver"
  212. + depends on SURFACE_AGGREGATOR
  213. + help
  214. + Driver for monitoring thermal sensors connected via the Surface
  215. + Aggregator Module (embedded controller) on Microsoft Surface devices.
  216. +
  217. + This driver can also be built as a module. If so, the module
  218. + will be called surface_temp.
  219. +
  220. config SENSORS_ADC128D818
  221. tristate "Texas Instruments ADC128D818"
  222. depends on I2C
  223. diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
  224. index e3f25475d1f0..eff74ab7f720 100644
  225. --- a/drivers/hwmon/Makefile
  226. +++ b/drivers/hwmon/Makefile
  227. @@ -209,6 +209,7 @@ obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
  228. obj-$(CONFIG_SENSORS_SPARX5) += sparx5-temp.o
  229. obj-$(CONFIG_SENSORS_STTS751) += stts751.o
  230. obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o
  231. +obj-$(CONFIG_SENSORS_SURFACE_TEMP)+= surface_temp.o
  232. obj-$(CONFIG_SENSORS_SY7636A) += sy7636a-hwmon.o
  233. obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o
  234. obj-$(CONFIG_SENSORS_TC74) += tc74.o
  235. diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c
  236. new file mode 100644
  237. index 000000000000..48c3e826713f
  238. --- /dev/null
  239. +++ b/drivers/hwmon/surface_temp.c
  240. @@ -0,0 +1,165 @@
  241. +// SPDX-License-Identifier: GPL-2.0+
  242. +/*
  243. + * Thermal sensor subsystem driver for Surface System Aggregator Module (SSAM).
  244. + *
  245. + * Copyright (C) 2022-2023 Maximilian Luz <luzmaximilian@gmail.com>
  246. + */
  247. +
  248. +#include <linux/bitops.h>
  249. +#include <linux/hwmon.h>
  250. +#include <linux/kernel.h>
  251. +#include <linux/module.h>
  252. +#include <linux/types.h>
  253. +
  254. +#include <linux/surface_aggregator/controller.h>
  255. +#include <linux/surface_aggregator/device.h>
  256. +
  257. +
  258. +/* -- SAM interface. -------------------------------------------------------- */
  259. +
  260. +SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, {
  261. + .target_category = SSAM_SSH_TC_TMP,
  262. + .command_id = 0x04,
  263. +});
  264. +
  265. +SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_temperature, __le16, {
  266. + .target_category = SSAM_SSH_TC_TMP,
  267. + .command_id = 0x01,
  268. +});
  269. +
  270. +static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors)
  271. +{
  272. + __le16 sensors_le;
  273. + int status;
  274. +
  275. + status = __ssam_tmp_get_available_sensors(sdev, &sensors_le);
  276. + if (status)
  277. + return status;
  278. +
  279. + *sensors = le16_to_cpu(sensors_le);
  280. + return 0;
  281. +}
  282. +
  283. +static int ssam_tmp_get_temperature(struct ssam_device *sdev, u8 iid, long *temperature)
  284. +{
  285. + __le16 temp_le;
  286. + int status;
  287. +
  288. + status = __ssam_tmp_get_temperature(sdev->ctrl, sdev->uid.target, iid, &temp_le);
  289. + if (status)
  290. + return status;
  291. +
  292. + /* Convert 1/10 °K to 1/1000 °C */
  293. + *temperature = (le16_to_cpu(temp_le) - 2731) * 100L;
  294. + return 0;
  295. +}
  296. +
  297. +
  298. +/* -- Driver.---------------------------------------------------------------- */
  299. +
  300. +struct ssam_temp {
  301. + struct ssam_device *sdev;
  302. + s16 sensors;
  303. +};
  304. +
  305. +static umode_t ssam_temp_hwmon_is_visible(const void *data,
  306. + enum hwmon_sensor_types type,
  307. + u32 attr, int channel)
  308. +{
  309. + const struct ssam_temp *ssam_temp = data;
  310. +
  311. + if (!(ssam_temp->sensors & BIT(channel)))
  312. + return 0;
  313. +
  314. + return 0444;
  315. +}
  316. +
  317. +static int ssam_temp_hwmon_read(struct device *dev,
  318. + enum hwmon_sensor_types type,
  319. + u32 attr, int channel, long *value)
  320. +{
  321. + const struct ssam_temp *ssam_temp = dev_get_drvdata(dev);
  322. +
  323. + return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value);
  324. +}
  325. +
  326. +static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = {
  327. + HWMON_CHANNEL_INFO(chip,
  328. + HWMON_C_REGISTER_TZ),
  329. + /* We have at most 16 thermal sensor channels. */
  330. + HWMON_CHANNEL_INFO(temp,
  331. + HWMON_T_INPUT,
  332. + HWMON_T_INPUT,
  333. + HWMON_T_INPUT,
  334. + HWMON_T_INPUT,
  335. + HWMON_T_INPUT,
  336. + HWMON_T_INPUT,
  337. + HWMON_T_INPUT,
  338. + HWMON_T_INPUT,
  339. + HWMON_T_INPUT,
  340. + HWMON_T_INPUT,
  341. + HWMON_T_INPUT,
  342. + HWMON_T_INPUT,
  343. + HWMON_T_INPUT,
  344. + HWMON_T_INPUT,
  345. + HWMON_T_INPUT,
  346. + HWMON_T_INPUT),
  347. + NULL
  348. +};
  349. +
  350. +static const struct hwmon_ops ssam_temp_hwmon_ops = {
  351. + .is_visible = ssam_temp_hwmon_is_visible,
  352. + .read = ssam_temp_hwmon_read,
  353. +};
  354. +
  355. +static const struct hwmon_chip_info ssam_temp_hwmon_chip_info = {
  356. + .ops = &ssam_temp_hwmon_ops,
  357. + .info = ssam_temp_hwmon_info,
  358. +};
  359. +
  360. +static int ssam_temp_probe(struct ssam_device *sdev)
  361. +{
  362. + struct ssam_temp *ssam_temp;
  363. + struct device *hwmon_dev;
  364. + s16 sensors;
  365. + int status;
  366. +
  367. + status = ssam_tmp_get_available_sensors(sdev, &sensors);
  368. + if (status)
  369. + return status;
  370. +
  371. + ssam_temp = devm_kzalloc(&sdev->dev, sizeof(*ssam_temp), GFP_KERNEL);
  372. + if (!ssam_temp)
  373. + return -ENOMEM;
  374. +
  375. + ssam_temp->sdev = sdev;
  376. + ssam_temp->sensors = sensors;
  377. +
  378. + hwmon_dev = devm_hwmon_device_register_with_info(&sdev->dev,
  379. + "surface_thermal", ssam_temp, &ssam_temp_hwmon_chip_info,
  380. + NULL);
  381. + if (IS_ERR(hwmon_dev))
  382. + return PTR_ERR(hwmon_dev);
  383. +
  384. + return 0;
  385. +}
  386. +
  387. +static const struct ssam_device_id ssam_temp_match[] = {
  388. + { SSAM_SDEV(TMP, SAM, 0x00, 0x02) },
  389. + { },
  390. +};
  391. +MODULE_DEVICE_TABLE(ssam, ssam_temp_match);
  392. +
  393. +static struct ssam_device_driver ssam_temp = {
  394. + .probe = ssam_temp_probe,
  395. + .match_table = ssam_temp_match,
  396. + .driver = {
  397. + .name = "surface_temp",
  398. + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  399. + },
  400. +};
  401. +module_ssam_device_driver(ssam_temp);
  402. +
  403. +MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
  404. +MODULE_DESCRIPTION("Thermal sensor subsystem driver for Surface System Aggregator Module");
  405. +MODULE_LICENSE("GPL");
  406. --
  407. 2.46.0
  408. From 31d334453ebc65b7868bf33b1963553586e64fa3 Mon Sep 17 00:00:00 2001
  409. From: Maximilian Luz <luzmaximilian@gmail.com>
  410. Date: Sat, 30 Dec 2023 18:12:23 +0100
  411. Subject: [PATCH] hwmon: surface_temp: Add support for sensor names
  412. The thermal subsystem of the Surface Aggregator Module allows us to
  413. query the names of the respective thermal sensors. Forward those to
  414. userspace.
  415. Signed-off-by: Ivor Wanders <ivor@iwanders.net>
  416. Co-Developed-by: Maximilian Luz <luzmaximilian@gmail.com>
  417. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  418. Patchset: surface-sam
  419. ---
  420. drivers/hwmon/surface_temp.c | 113 +++++++++++++++++++++++++++++------
  421. 1 file changed, 96 insertions(+), 17 deletions(-)
  422. diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c
  423. index 48c3e826713f..4c08926139db 100644
  424. --- a/drivers/hwmon/surface_temp.c
  425. +++ b/drivers/hwmon/surface_temp.c
  426. @@ -17,6 +17,27 @@
  427. /* -- SAM interface. -------------------------------------------------------- */
  428. +/*
  429. + * Available sensors are indicated by a 16-bit bitfield, where a 1 marks the
  430. + * presence of a sensor. So we have at most 16 possible sensors/channels.
  431. + */
  432. +#define SSAM_TMP_SENSOR_MAX_COUNT 16
  433. +
  434. +/*
  435. + * All names observed so far are 6 characters long, but there's only
  436. + * zeros after the name, so perhaps they can be longer. This number reflects
  437. + * the maximum zero-padded space observed in the returned buffer.
  438. + */
  439. +#define SSAM_TMP_SENSOR_NAME_LENGTH 18
  440. +
  441. +struct ssam_tmp_get_name_rsp {
  442. + __le16 unknown1;
  443. + char unknown2;
  444. + char name[SSAM_TMP_SENSOR_NAME_LENGTH];
  445. +} __packed;
  446. +
  447. +static_assert(sizeof(struct ssam_tmp_get_name_rsp) == 21);
  448. +
  449. SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, {
  450. .target_category = SSAM_SSH_TC_TMP,
  451. .command_id = 0x04,
  452. @@ -27,6 +48,11 @@ SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_temperature, __le16, {
  453. .command_id = 0x01,
  454. });
  455. +SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_name, struct ssam_tmp_get_name_rsp, {
  456. + .target_category = SSAM_SSH_TC_TMP,
  457. + .command_id = 0x0e,
  458. +});
  459. +
  460. static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors)
  461. {
  462. __le16 sensors_le;
  463. @@ -54,12 +80,37 @@ static int ssam_tmp_get_temperature(struct ssam_device *sdev, u8 iid, long *temp
  464. return 0;
  465. }
  466. +static int ssam_tmp_get_name(struct ssam_device *sdev, u8 iid, char *buf, size_t buf_len)
  467. +{
  468. + struct ssam_tmp_get_name_rsp name_rsp;
  469. + int status;
  470. +
  471. + status = __ssam_tmp_get_name(sdev->ctrl, sdev->uid.target, iid, &name_rsp);
  472. + if (status)
  473. + return status;
  474. +
  475. + /*
  476. + * This should not fail unless the name in the returned struct is not
  477. + * null-terminated or someone changed something in the struct
  478. + * definitions above, since our buffer and struct have the same
  479. + * capacity by design. So if this fails blow this up with a warning.
  480. + * Since the more likely cause is that the returned string isn't
  481. + * null-terminated, we might have received garbage (as opposed to just
  482. + * an incomplete string), so also fail the function.
  483. + */
  484. + status = strscpy(buf, name_rsp.name, buf_len);
  485. + WARN_ON(status < 0);
  486. +
  487. + return status < 0 ? status : 0;
  488. +}
  489. +
  490. /* -- Driver.---------------------------------------------------------------- */
  491. struct ssam_temp {
  492. struct ssam_device *sdev;
  493. s16 sensors;
  494. + char names[SSAM_TMP_SENSOR_MAX_COUNT][SSAM_TMP_SENSOR_NAME_LENGTH];
  495. };
  496. static umode_t ssam_temp_hwmon_is_visible(const void *data,
  497. @@ -83,33 +134,47 @@ static int ssam_temp_hwmon_read(struct device *dev,
  498. return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value);
  499. }
  500. +static int ssam_temp_hwmon_read_string(struct device *dev,
  501. + enum hwmon_sensor_types type,
  502. + u32 attr, int channel, const char **str)
  503. +{
  504. + const struct ssam_temp *ssam_temp = dev_get_drvdata(dev);
  505. +
  506. + *str = ssam_temp->names[channel];
  507. + return 0;
  508. +}
  509. +
  510. static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = {
  511. HWMON_CHANNEL_INFO(chip,
  512. HWMON_C_REGISTER_TZ),
  513. - /* We have at most 16 thermal sensor channels. */
  514. + /*
  515. + * We have at most SSAM_TMP_SENSOR_MAX_COUNT = 16 thermal sensor
  516. + * channels.
  517. + */
  518. HWMON_CHANNEL_INFO(temp,
  519. - HWMON_T_INPUT,
  520. - HWMON_T_INPUT,
  521. - HWMON_T_INPUT,
  522. - HWMON_T_INPUT,
  523. - HWMON_T_INPUT,
  524. - HWMON_T_INPUT,
  525. - HWMON_T_INPUT,
  526. - HWMON_T_INPUT,
  527. - HWMON_T_INPUT,
  528. - HWMON_T_INPUT,
  529. - HWMON_T_INPUT,
  530. - HWMON_T_INPUT,
  531. - HWMON_T_INPUT,
  532. - HWMON_T_INPUT,
  533. - HWMON_T_INPUT,
  534. - HWMON_T_INPUT),
  535. + HWMON_T_INPUT | HWMON_T_LABEL,
  536. + HWMON_T_INPUT | HWMON_T_LABEL,
  537. + HWMON_T_INPUT | HWMON_T_LABEL,
  538. + HWMON_T_INPUT | HWMON_T_LABEL,
  539. + HWMON_T_INPUT | HWMON_T_LABEL,
  540. + HWMON_T_INPUT | HWMON_T_LABEL,
  541. + HWMON_T_INPUT | HWMON_T_LABEL,
  542. + HWMON_T_INPUT | HWMON_T_LABEL,
  543. + HWMON_T_INPUT | HWMON_T_LABEL,
  544. + HWMON_T_INPUT | HWMON_T_LABEL,
  545. + HWMON_T_INPUT | HWMON_T_LABEL,
  546. + HWMON_T_INPUT | HWMON_T_LABEL,
  547. + HWMON_T_INPUT | HWMON_T_LABEL,
  548. + HWMON_T_INPUT | HWMON_T_LABEL,
  549. + HWMON_T_INPUT | HWMON_T_LABEL,
  550. + HWMON_T_INPUT | HWMON_T_LABEL),
  551. NULL
  552. };
  553. static const struct hwmon_ops ssam_temp_hwmon_ops = {
  554. .is_visible = ssam_temp_hwmon_is_visible,
  555. .read = ssam_temp_hwmon_read,
  556. + .read_string = ssam_temp_hwmon_read_string,
  557. };
  558. static const struct hwmon_chip_info ssam_temp_hwmon_chip_info = {
  559. @@ -122,6 +187,7 @@ static int ssam_temp_probe(struct ssam_device *sdev)
  560. struct ssam_temp *ssam_temp;
  561. struct device *hwmon_dev;
  562. s16 sensors;
  563. + int channel;
  564. int status;
  565. status = ssam_tmp_get_available_sensors(sdev, &sensors);
  566. @@ -135,6 +201,19 @@ static int ssam_temp_probe(struct ssam_device *sdev)
  567. ssam_temp->sdev = sdev;
  568. ssam_temp->sensors = sensors;
  569. + /* Retrieve the name for each available sensor. */
  570. + for (channel = 0; channel < SSAM_TMP_SENSOR_MAX_COUNT; channel++)
  571. + {
  572. + if (!(sensors & BIT(channel)))
  573. + continue;
  574. +
  575. + status = ssam_tmp_get_name(sdev, channel + 1,
  576. + ssam_temp->names[channel],
  577. + SSAM_TMP_SENSOR_NAME_LENGTH);
  578. + if (status)
  579. + return status;
  580. + }
  581. +
  582. hwmon_dev = devm_hwmon_device_register_with_info(&sdev->dev,
  583. "surface_thermal", ssam_temp, &ssam_temp_hwmon_chip_info,
  584. NULL);
  585. --
  586. 2.46.0
  587. From 36174000616d130e9b4655d69eb3bd5b07adbecb Mon Sep 17 00:00:00 2001
  588. From: Maximilian Luz <luzmaximilian@gmail.com>
  589. Date: Mon, 10 Jun 2024 21:47:47 +0200
  590. Subject: [PATCH] platform/surface: aggregator_registry: Add fan and thermal
  591. sensor support for Surface Laptop 5
  592. Patchset: surface-sam
  593. ---
  594. drivers/platform/surface/surface_aggregator_registry.c | 4 +++-
  595. 1 file changed, 3 insertions(+), 1 deletion(-)
  596. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  597. index 70a2ea5a1957..6b568804f70b 100644
  598. --- a/drivers/platform/surface/surface_aggregator_registry.c
  599. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  600. @@ -265,7 +265,9 @@ static const struct software_node *ssam_node_group_sl5[] = {
  601. &ssam_node_root,
  602. &ssam_node_bat_ac,
  603. &ssam_node_bat_main,
  604. - &ssam_node_tmp_perf_profile,
  605. + &ssam_node_tmp_perf_profile_with_fan,
  606. + &ssam_node_tmp_sensors,
  607. + &ssam_node_fan_speed,
  608. &ssam_node_hid_main_keyboard,
  609. &ssam_node_hid_main_touchpad,
  610. &ssam_node_hid_main_iid5,
  611. --
  612. 2.46.0
  613. From e32f317be4ad620fb6683b62ad9e883f37e17f57 Mon Sep 17 00:00:00 2001
  614. From: Maximilian Luz <luzmaximilian@gmail.com>
  615. Date: Mon, 10 Jun 2024 21:48:02 +0200
  616. Subject: [PATCH] platform/surface: aggregator_registry: Add fan and thermal
  617. sensor support for Surface Laptop Studio 2
  618. Patchset: surface-sam
  619. ---
  620. drivers/platform/surface/surface_aggregator_registry.c | 4 +++-
  621. 1 file changed, 3 insertions(+), 1 deletion(-)
  622. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  623. index 6b568804f70b..9046df95c043 100644
  624. --- a/drivers/platform/surface/surface_aggregator_registry.c
  625. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  626. @@ -312,7 +312,9 @@ static const struct software_node *ssam_node_group_sls2[] = {
  627. &ssam_node_root,
  628. &ssam_node_bat_ac,
  629. &ssam_node_bat_main,
  630. - &ssam_node_tmp_pprof,
  631. + &ssam_node_tmp_perf_profile_with_fan,
  632. + &ssam_node_tmp_sensors,
  633. + &ssam_node_fan_speed,
  634. &ssam_node_pos_tablet_switch,
  635. &ssam_node_hid_sam_keyboard,
  636. &ssam_node_hid_sam_penstash,
  637. --
  638. 2.46.0
  639. From ebf64f6dcf1bdf0dbe80b5ec5e3d4b8a6cfab41e Mon Sep 17 00:00:00 2001
  640. From: Maximilian Luz <luzmaximilian@gmail.com>
  641. Date: Fri, 28 Jun 2024 22:31:37 +0200
  642. Subject: [PATCH] platform/surface: aggregator_registry: Add Support for
  643. Surface Pro 10
  644. Patchset: surface-sam
  645. ---
  646. .../surface/surface_aggregator_registry.c | 22 +++++++++++++++++++
  647. 1 file changed, 22 insertions(+)
  648. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  649. index 9046df95c043..058f4edd8b66 100644
  650. --- a/drivers/platform/surface/surface_aggregator_registry.c
  651. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  652. @@ -377,6 +377,25 @@ static const struct software_node *ssam_node_group_sp9[] = {
  653. NULL,
  654. };
  655. +/* Devices for Surface Pro 10 */
  656. +static const struct software_node *ssam_node_group_sp10[] = {
  657. + &ssam_node_root,
  658. + &ssam_node_hub_kip,
  659. + &ssam_node_bat_ac,
  660. + &ssam_node_bat_main,
  661. + &ssam_node_tmp_perf_profile_with_fan,
  662. + &ssam_node_tmp_sensors,
  663. + &ssam_node_fan_speed,
  664. + &ssam_node_pos_tablet_switch,
  665. + &ssam_node_hid_kip_keyboard,
  666. + &ssam_node_hid_kip_penstash,
  667. + &ssam_node_hid_kip_touchpad,
  668. + &ssam_node_hid_kip_fwupd,
  669. + &ssam_node_hid_sam_sensors,
  670. + &ssam_node_hid_sam_ucm_ucsi,
  671. + NULL,
  672. +};
  673. +
  674. /* -- SSAM platform/meta-hub driver. ---------------------------------------- */
  675. @@ -399,6 +418,9 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
  676. /* Surface Pro 9 */
  677. { "MSHW0343", (unsigned long)ssam_node_group_sp9 },
  678. + /* Surface Pro 10 */
  679. + { "MSHW0510", (unsigned long)ssam_node_group_sp10 },
  680. +
  681. /* Surface Book 2 */
  682. { "MSHW0107", (unsigned long)ssam_node_group_gen5 },
  683. --
  684. 2.46.0