1 // SPDX-License-Identifier: GPL-2.0+
3 * Surface System Aggregator Module (SSAM) client device registry.
5 * Registry for non-platform/non-ACPI SSAM client devices, i.e. devices that
6 * cannot be auto-detected. Provides device-hubs and performs instantiation
9 * Copyright (C) 2020-2022 Maximilian Luz <luzmaximilian@gmail.com>
12 #include <linux/acpi.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/property.h>
18 #include <linux/types.h>
20 #include <linux/surface_aggregator/device.h>
23 /* -- Device registry. ------------------------------------------------------ */
26 * SSAM device names follow the SSAM module alias, meaning they are prefixed
27 * with 'ssam:', followed by domain, category, target ID, instance ID, and
28 * function, each encoded as two-digit hexadecimal, separated by ':'. In other
29 * words, it follows the scheme
33 * Where, 'dd', 'cc', 'tt', 'ii', and 'ff' are the two-digit hexadecimal
34 * values mentioned above, respectively.
38 static const struct software_node ssam_node_root
= {
39 .name
= "ssam_platform_hub",
42 /* KIP device hub (connects keyboard cover devices on Surface Pro 8). */
43 static const struct software_node ssam_node_hub_kip
= {
44 .name
= "ssam:00:00:01:0e:00",
45 .parent
= &ssam_node_root
,
48 /* Base device hub (devices attached to Surface Book 3 base). */
49 static const struct software_node ssam_node_hub_base
= {
50 .name
= "ssam:00:00:01:11:00",
51 .parent
= &ssam_node_root
,
55 static const struct software_node ssam_node_bat_ac
= {
56 .name
= "ssam:01:02:01:01:01",
57 .parent
= &ssam_node_root
,
60 /* Primary battery. */
61 static const struct software_node ssam_node_bat_main
= {
62 .name
= "ssam:01:02:01:01:00",
63 .parent
= &ssam_node_root
,
66 /* Secondary battery (Surface Book 3). */
67 static const struct software_node ssam_node_bat_sb3base
= {
68 .name
= "ssam:01:02:02:01:00",
69 .parent
= &ssam_node_hub_base
,
72 /* Platform profile / performance-mode device without a fan. */
73 static const struct software_node ssam_node_tmp_perf_profile
= {
74 .name
= "ssam:01:03:01:00:01",
75 .parent
= &ssam_node_root
,
78 /* Platform profile / performance-mode device with a fan, such that
79 * the fan controller profile can also be switched.
81 static const struct property_entry ssam_node_tmp_perf_profile_has_fan
[] = {
82 PROPERTY_ENTRY_BOOL("has_fan"),
86 static const struct software_node ssam_node_tmp_perf_profile_with_fan
= {
87 .name
= "ssam:01:03:01:00:01",
88 .parent
= &ssam_node_root
,
89 .properties
= ssam_node_tmp_perf_profile_has_fan
,
92 /* Thermal sensors. */
93 static const struct software_node ssam_node_tmp_sensors
= {
94 .name
= "ssam:01:03:01:00:02",
95 .parent
= &ssam_node_root
,
98 /* Fan speed function. */
99 static const struct software_node ssam_node_fan_speed
= {
100 .name
= "ssam:01:05:01:01:01",
101 .parent
= &ssam_node_root
,
104 /* Tablet-mode switch via KIP subsystem. */
105 static const struct software_node ssam_node_kip_tablet_switch
= {
106 .name
= "ssam:01:0e:01:00:01",
107 .parent
= &ssam_node_root
,
110 /* DTX / detachment-system device (Surface Book 3). */
111 static const struct software_node ssam_node_bas_dtx
= {
112 .name
= "ssam:01:11:01:00:00",
113 .parent
= &ssam_node_root
,
116 /* HID keyboard (SAM, TID=1). */
117 static const struct software_node ssam_node_hid_sam_keyboard
= {
118 .name
= "ssam:01:15:01:01:00",
119 .parent
= &ssam_node_root
,
122 /* HID pen stash (SAM, TID=1; pen taken / stashed away evens). */
123 static const struct software_node ssam_node_hid_sam_penstash
= {
124 .name
= "ssam:01:15:01:02:00",
125 .parent
= &ssam_node_root
,
128 /* HID touchpad (SAM, TID=1). */
129 static const struct software_node ssam_node_hid_sam_touchpad
= {
130 .name
= "ssam:01:15:01:03:00",
131 .parent
= &ssam_node_root
,
134 /* HID device instance 6 (SAM, TID=1, HID sensor collection). */
135 static const struct software_node ssam_node_hid_sam_sensors
= {
136 .name
= "ssam:01:15:01:06:00",
137 .parent
= &ssam_node_root
,
140 /* HID device instance 7 (SAM, TID=1, UCM UCSI HID client). */
141 static const struct software_node ssam_node_hid_sam_ucm_ucsi
= {
142 .name
= "ssam:01:15:01:07:00",
143 .parent
= &ssam_node_root
,
146 /* HID system controls (SAM, TID=1). */
147 static const struct software_node ssam_node_hid_sam_sysctrl
= {
148 .name
= "ssam:01:15:01:08:00",
149 .parent
= &ssam_node_root
,
153 static const struct software_node ssam_node_hid_main_keyboard
= {
154 .name
= "ssam:01:15:02:01:00",
155 .parent
= &ssam_node_root
,
159 static const struct software_node ssam_node_hid_main_touchpad
= {
160 .name
= "ssam:01:15:02:03:00",
161 .parent
= &ssam_node_root
,
164 /* HID device instance 5 (unknown HID device). */
165 static const struct software_node ssam_node_hid_main_iid5
= {
166 .name
= "ssam:01:15:02:05:00",
167 .parent
= &ssam_node_root
,
170 /* HID keyboard (base hub). */
171 static const struct software_node ssam_node_hid_base_keyboard
= {
172 .name
= "ssam:01:15:02:01:00",
173 .parent
= &ssam_node_hub_base
,
176 /* HID touchpad (base hub). */
177 static const struct software_node ssam_node_hid_base_touchpad
= {
178 .name
= "ssam:01:15:02:03:00",
179 .parent
= &ssam_node_hub_base
,
182 /* HID device instance 5 (unknown HID device, base hub). */
183 static const struct software_node ssam_node_hid_base_iid5
= {
184 .name
= "ssam:01:15:02:05:00",
185 .parent
= &ssam_node_hub_base
,
188 /* HID device instance 6 (unknown HID device, base hub). */
189 static const struct software_node ssam_node_hid_base_iid6
= {
190 .name
= "ssam:01:15:02:06:00",
191 .parent
= &ssam_node_hub_base
,
194 /* HID keyboard (KIP hub). */
195 static const struct software_node ssam_node_hid_kip_keyboard
= {
196 .name
= "ssam:01:15:02:01:00",
197 .parent
= &ssam_node_hub_kip
,
200 /* HID pen stash (KIP hub; pen taken / stashed away evens). */
201 static const struct software_node ssam_node_hid_kip_penstash
= {
202 .name
= "ssam:01:15:02:02:00",
203 .parent
= &ssam_node_hub_kip
,
206 /* HID touchpad (KIP hub). */
207 static const struct software_node ssam_node_hid_kip_touchpad
= {
208 .name
= "ssam:01:15:02:03:00",
209 .parent
= &ssam_node_hub_kip
,
212 /* HID device instance 5 (KIP hub, type-cover firmware update). */
213 static const struct software_node ssam_node_hid_kip_fwupd
= {
214 .name
= "ssam:01:15:02:05:00",
215 .parent
= &ssam_node_hub_kip
,
218 /* Tablet-mode switch via POS subsystem. */
219 static const struct software_node ssam_node_pos_tablet_switch
= {
220 .name
= "ssam:01:26:01:00:01",
221 .parent
= &ssam_node_root
,
225 * Devices for 5th- and 6th-generations models:
227 * - Surface Laptop 1 and 2,
228 * - Surface Pro 5 and 6.
230 static const struct software_node
*ssam_node_group_gen5
[] = {
232 &ssam_node_tmp_perf_profile
,
236 /* Devices for Surface Book 3. */
237 static const struct software_node
*ssam_node_group_sb3
[] = {
242 &ssam_node_bat_sb3base
,
243 &ssam_node_tmp_perf_profile
,
245 &ssam_node_hid_base_keyboard
,
246 &ssam_node_hid_base_touchpad
,
247 &ssam_node_hid_base_iid5
,
248 &ssam_node_hid_base_iid6
,
252 /* Devices for Surface Laptop 3 and 4. */
253 static const struct software_node
*ssam_node_group_sl3
[] = {
257 &ssam_node_tmp_perf_profile
,
258 &ssam_node_hid_main_keyboard
,
259 &ssam_node_hid_main_touchpad
,
260 &ssam_node_hid_main_iid5
,
264 /* Devices for Surface Laptop 5. */
265 static const struct software_node
*ssam_node_group_sl5
[] = {
269 &ssam_node_tmp_perf_profile_with_fan
,
270 &ssam_node_tmp_sensors
,
271 &ssam_node_fan_speed
,
272 &ssam_node_hid_main_keyboard
,
273 &ssam_node_hid_main_touchpad
,
274 &ssam_node_hid_main_iid5
,
275 &ssam_node_hid_sam_ucm_ucsi
,
279 /* Devices for Surface Laptop 6. */
280 static const struct software_node
*ssam_node_group_sl6
[] = {
284 &ssam_node_tmp_perf_profile_with_fan
,
285 &ssam_node_tmp_sensors
,
286 &ssam_node_fan_speed
,
287 &ssam_node_hid_main_keyboard
,
288 &ssam_node_hid_main_touchpad
,
289 &ssam_node_hid_main_iid5
,
290 &ssam_node_hid_sam_sensors
,
291 &ssam_node_hid_sam_ucm_ucsi
,
295 /* Devices for Surface Laptop 7. */
296 static const struct software_node
*ssam_node_group_sl7
[] = {
300 &ssam_node_tmp_perf_profile_with_fan
,
301 &ssam_node_fan_speed
,
302 &ssam_node_hid_sam_keyboard
,
303 /* TODO: evaluate thermal sensors devices when we get a driver for that */
307 /* Devices for Surface Laptop Studio 1. */
308 static const struct software_node
*ssam_node_group_sls1
[] = {
312 &ssam_node_tmp_perf_profile
,
313 &ssam_node_pos_tablet_switch
,
314 &ssam_node_hid_sam_keyboard
,
315 &ssam_node_hid_sam_penstash
,
316 &ssam_node_hid_sam_touchpad
,
317 &ssam_node_hid_sam_sensors
,
318 &ssam_node_hid_sam_ucm_ucsi
,
319 &ssam_node_hid_sam_sysctrl
,
323 /* Devices for Surface Laptop Studio 2. */
324 static const struct software_node
*ssam_node_group_sls2
[] = {
328 &ssam_node_tmp_perf_profile_with_fan
,
329 &ssam_node_tmp_sensors
,
330 &ssam_node_fan_speed
,
331 &ssam_node_pos_tablet_switch
,
332 &ssam_node_hid_sam_keyboard
,
333 &ssam_node_hid_sam_penstash
,
334 &ssam_node_hid_sam_sensors
,
335 &ssam_node_hid_sam_ucm_ucsi
,
339 /* Devices for Surface Laptop Go. */
340 static const struct software_node
*ssam_node_group_slg1
[] = {
344 &ssam_node_tmp_perf_profile
,
348 /* Devices for Surface Pro 7 and Surface Pro 7+. */
349 static const struct software_node
*ssam_node_group_sp7
[] = {
353 &ssam_node_tmp_perf_profile
,
357 /* Devices for Surface Pro 8 */
358 static const struct software_node
*ssam_node_group_sp8
[] = {
363 &ssam_node_tmp_perf_profile
,
364 &ssam_node_kip_tablet_switch
,
365 &ssam_node_hid_kip_keyboard
,
366 &ssam_node_hid_kip_penstash
,
367 &ssam_node_hid_kip_touchpad
,
368 &ssam_node_hid_kip_fwupd
,
369 &ssam_node_hid_sam_sensors
,
370 &ssam_node_hid_sam_ucm_ucsi
,
374 /* Devices for Surface Pro 9 (Intel/x86) and 10 */
375 static const struct software_node
*ssam_node_group_sp9
[] = {
380 &ssam_node_tmp_perf_profile_with_fan
,
381 &ssam_node_tmp_sensors
,
382 &ssam_node_fan_speed
,
383 &ssam_node_pos_tablet_switch
,
384 &ssam_node_hid_kip_keyboard
,
385 &ssam_node_hid_kip_penstash
,
386 &ssam_node_hid_kip_touchpad
,
387 &ssam_node_hid_kip_fwupd
,
388 &ssam_node_hid_sam_sensors
,
389 &ssam_node_hid_sam_ucm_ucsi
,
393 /* Devices for Surface Pro 9 5G (ARM/QCOM) */
394 static const struct software_node
*ssam_node_group_sp9_5g
[] = {
399 &ssam_node_tmp_sensors
,
400 &ssam_node_hid_kip_keyboard
,
401 &ssam_node_hid_kip_penstash
,
402 &ssam_node_hid_kip_touchpad
,
403 &ssam_node_hid_kip_fwupd
,
404 &ssam_node_hid_sam_sensors
,
405 &ssam_node_kip_tablet_switch
,
409 /* -- SSAM platform/meta-hub driver. ---------------------------------------- */
411 static const struct acpi_device_id ssam_platform_hub_acpi_match
[] = {
412 /* Surface Pro 4, 5, and 6 (OMBR < 0x10) */
413 { "MSHW0081", (unsigned long)ssam_node_group_gen5
},
415 /* Surface Pro 6 (OMBR >= 0x10) */
416 { "MSHW0111", (unsigned long)ssam_node_group_gen5
},
419 { "MSHW0116", (unsigned long)ssam_node_group_sp7
},
422 { "MSHW0119", (unsigned long)ssam_node_group_sp7
},
425 { "MSHW0263", (unsigned long)ssam_node_group_sp8
},
428 { "MSHW0343", (unsigned long)ssam_node_group_sp9
},
431 { "MSHW0510", (unsigned long)ssam_node_group_sp9
},
434 { "MSHW0107", (unsigned long)ssam_node_group_gen5
},
437 { "MSHW0117", (unsigned long)ssam_node_group_sb3
},
439 /* Surface Laptop 1 */
440 { "MSHW0086", (unsigned long)ssam_node_group_gen5
},
442 /* Surface Laptop 2 */
443 { "MSHW0112", (unsigned long)ssam_node_group_gen5
},
445 /* Surface Laptop 3 (13", Intel) */
446 { "MSHW0114", (unsigned long)ssam_node_group_sl3
},
448 /* Surface Laptop 3 (15", AMD) and 4 (15", AMD) */
449 { "MSHW0110", (unsigned long)ssam_node_group_sl3
},
451 /* Surface Laptop 4 (13", Intel) */
452 { "MSHW0250", (unsigned long)ssam_node_group_sl3
},
454 /* Surface Laptop 5 */
455 { "MSHW0350", (unsigned long)ssam_node_group_sl5
},
457 /* Surface Laptop 6 */
458 { "MSHW0530", (unsigned long)ssam_node_group_sl6
},
460 /* Surface Laptop Go 1 */
461 { "MSHW0118", (unsigned long)ssam_node_group_slg1
},
463 /* Surface Laptop Go 2 */
464 { "MSHW0290", (unsigned long)ssam_node_group_slg1
},
466 /* Surface Laptop Go 3 */
467 { "MSHW0440", (unsigned long)ssam_node_group_slg1
},
469 /* Surface Laptop Studio 1 */
470 { "MSHW0123", (unsigned long)ssam_node_group_sls1
},
472 /* Surface Laptop Studio 2 */
473 { "MSHW0360", (unsigned long)ssam_node_group_sls2
},
477 MODULE_DEVICE_TABLE(acpi
, ssam_platform_hub_acpi_match
);
479 static const struct of_device_id ssam_platform_hub_of_match
[] __maybe_unused
= {
480 /* Surface Pro 9 5G (ARM/QCOM) */
481 { .compatible
= "microsoft,arcata", (void *)ssam_node_group_sp9_5g
},
482 /* Surface Laptop 7 */
483 { .compatible
= "microsoft,romulus13", (void *)ssam_node_group_sl7
},
484 { .compatible
= "microsoft,romulus15", (void *)ssam_node_group_sl7
},
488 static int ssam_platform_hub_probe(struct platform_device
*pdev
)
490 const struct software_node
**nodes
;
491 const struct of_device_id
*match
;
492 struct device_node
*fdt_root
;
493 struct ssam_controller
*ctrl
;
494 struct fwnode_handle
*root
;
497 nodes
= (const struct software_node
**)acpi_device_get_match_data(&pdev
->dev
);
499 fdt_root
= of_find_node_by_path("/");
503 match
= of_match_node(ssam_platform_hub_of_match
, fdt_root
);
504 of_node_put(fdt_root
);
508 nodes
= (const struct software_node
**)match
->data
;
514 * As we're adding the SSAM client devices as children under this device
515 * and not the SSAM controller, we need to add a device link to the
516 * controller to ensure that we remove all of our devices before the
517 * controller is removed. This also guarantees proper ordering for
518 * suspend/resume of the devices on this hub.
520 ctrl
= ssam_client_bind(&pdev
->dev
);
522 return PTR_ERR(ctrl
) == -ENODEV
? -EPROBE_DEFER
: PTR_ERR(ctrl
);
524 status
= software_node_register_node_group(nodes
);
528 root
= software_node_fwnode(&ssam_node_root
);
530 software_node_unregister_node_group(nodes
);
534 set_secondary_fwnode(&pdev
->dev
, root
);
536 status
= __ssam_register_clients(&pdev
->dev
, ctrl
, root
);
538 set_secondary_fwnode(&pdev
->dev
, NULL
);
539 software_node_unregister_node_group(nodes
);
542 platform_set_drvdata(pdev
, nodes
);
546 static void ssam_platform_hub_remove(struct platform_device
*pdev
)
548 const struct software_node
**nodes
= platform_get_drvdata(pdev
);
550 ssam_remove_clients(&pdev
->dev
);
551 set_secondary_fwnode(&pdev
->dev
, NULL
);
552 software_node_unregister_node_group(nodes
);
555 static struct platform_driver ssam_platform_hub_driver
= {
556 .probe
= ssam_platform_hub_probe
,
557 .remove_new
= ssam_platform_hub_remove
,
559 .name
= "surface_aggregator_platform_hub",
560 .acpi_match_table
= ssam_platform_hub_acpi_match
,
561 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
564 module_platform_driver(ssam_platform_hub_driver
);
566 MODULE_ALIAS("platform:surface_aggregator_platform_hub");
567 MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
568 MODULE_DESCRIPTION("Device-registry for Surface System Aggregator Module");
569 MODULE_LICENSE("GPL");