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
12 #include <linux/acpi.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/property.h>
17 #include <linux/types.h>
19 #include <linux/surface_aggregator/device.h>
22 /* -- Device registry. ------------------------------------------------------ */
25 * SSAM device names follow the SSAM module alias, meaning they are prefixed
26 * with 'ssam:', followed by domain, category, target ID, instance ID, and
27 * function, each encoded as two-digit hexadecimal, separated by ':'. In other
28 * words, it follows the scheme
32 * Where, 'dd', 'cc', 'tt', 'ii', and 'ff' are the two-digit hexadecimal
33 * values mentioned above, respectively.
37 static const struct software_node ssam_node_root = {
38 .name = "ssam_platform_hub",
41 /* KIP device hub (connects keyboard cover devices on Surface Pro 8). */
42 static const struct software_node ssam_node_hub_kip = {
43 .name = "ssam:00:00:01:0e:00",
44 .parent = &ssam_node_root,
47 /* Base device hub (devices attached to Surface Book 3 base). */
48 static const struct software_node ssam_node_hub_base = {
49 .name = "ssam:00:00:01:11:00",
50 .parent = &ssam_node_root,
54 static const struct software_node ssam_node_bat_ac = {
55 .name = "ssam:01:02:01:01:01",
56 .parent = &ssam_node_root,
59 /* Primary battery. */
60 static const struct software_node ssam_node_bat_main = {
61 .name = "ssam:01:02:01:01:00",
62 .parent = &ssam_node_root,
65 /* Secondary battery (Surface Book 3). */
66 static const struct software_node ssam_node_bat_sb3base = {
67 .name = "ssam:01:02:02:01:00",
68 .parent = &ssam_node_hub_base,
71 /* Platform profile / performance-mode device without a fan. */
72 static const struct software_node ssam_node_tmp_perf_profile = {
73 .name = "ssam:01:03:01:00:01",
74 .parent = &ssam_node_root,
77 /* Platform profile / performance-mode device with a fan, such that
78 * the fan controller profile can also be switched.
80 static const struct property_entry ssam_node_tmp_perf_profile_has_fan[] = {
81 PROPERTY_ENTRY_BOOL("has_fan"),
85 static const struct software_node ssam_node_tmp_perf_profile_with_fan = {
86 .name = "ssam:01:03:01:00:01",
87 .parent = &ssam_node_root,
88 .properties = ssam_node_tmp_perf_profile_has_fan,
91 /* Thermal sensors. */
92 static const struct software_node ssam_node_tmp_sensors = {
93 .name = "ssam:01:03:01:00:02",
94 .parent = &ssam_node_root,
97 /* Fan speed function. */
98 static const struct software_node ssam_node_fan_speed = {
99 .name = "ssam:01:05:01:01:01",
100 .parent = &ssam_node_root,
103 /* Tablet-mode switch via KIP subsystem. */
104 static const struct software_node ssam_node_kip_tablet_switch = {
105 .name = "ssam:01:0e:01:00:01",
106 .parent = &ssam_node_root,
109 /* DTX / detachment-system device (Surface Book 3). */
110 static const struct software_node ssam_node_bas_dtx = {
111 .name = "ssam:01:11:01:00:00",
112 .parent = &ssam_node_root,
115 /* HID keyboard (SAM, TID=1). */
116 static const struct software_node ssam_node_hid_sam_keyboard = {
117 .name = "ssam:01:15:01:01:00",
118 .parent = &ssam_node_root,
121 /* HID pen stash (SAM, TID=1; pen taken / stashed away evens). */
122 static const struct software_node ssam_node_hid_sam_penstash = {
123 .name = "ssam:01:15:01:02:00",
124 .parent = &ssam_node_root,
127 /* HID touchpad (SAM, TID=1). */
128 static const struct software_node ssam_node_hid_sam_touchpad = {
129 .name = "ssam:01:15:01:03:00",
130 .parent = &ssam_node_root,
133 /* HID device instance 6 (SAM, TID=1, HID sensor collection). */
134 static const struct software_node ssam_node_hid_sam_sensors = {
135 .name = "ssam:01:15:01:06:00",
136 .parent = &ssam_node_root,
139 /* HID device instance 7 (SAM, TID=1, UCM UCSI HID client). */
140 static const struct software_node ssam_node_hid_sam_ucm_ucsi = {
141 .name = "ssam:01:15:01:07:00",
142 .parent = &ssam_node_root,
145 /* HID system controls (SAM, TID=1). */
146 static const struct software_node ssam_node_hid_sam_sysctrl = {
147 .name = "ssam:01:15:01:08:00",
148 .parent = &ssam_node_root,
152 static const struct software_node ssam_node_hid_main_keyboard = {
153 .name = "ssam:01:15:02:01:00",
154 .parent = &ssam_node_root,
158 static const struct software_node ssam_node_hid_main_touchpad = {
159 .name = "ssam:01:15:02:03:00",
160 .parent = &ssam_node_root,
163 /* HID device instance 5 (unknown HID device). */
164 static const struct software_node ssam_node_hid_main_iid5 = {
165 .name = "ssam:01:15:02:05:00",
166 .parent = &ssam_node_root,
169 /* HID keyboard (base hub). */
170 static const struct software_node ssam_node_hid_base_keyboard = {
171 .name = "ssam:01:15:02:01:00",
172 .parent = &ssam_node_hub_base,
175 /* HID touchpad (base hub). */
176 static const struct software_node ssam_node_hid_base_touchpad = {
177 .name = "ssam:01:15:02:03:00",
178 .parent = &ssam_node_hub_base,
181 /* HID device instance 5 (unknown HID device, base hub). */
182 static const struct software_node ssam_node_hid_base_iid5 = {
183 .name = "ssam:01:15:02:05:00",
184 .parent = &ssam_node_hub_base,
187 /* HID device instance 6 (unknown HID device, base hub). */
188 static const struct software_node ssam_node_hid_base_iid6 = {
189 .name = "ssam:01:15:02:06:00",
190 .parent = &ssam_node_hub_base,
193 /* HID keyboard (KIP hub). */
194 static const struct software_node ssam_node_hid_kip_keyboard = {
195 .name = "ssam:01:15:02:01:00",
196 .parent = &ssam_node_hub_kip,
199 /* HID pen stash (KIP hub; pen taken / stashed away evens). */
200 static const struct software_node ssam_node_hid_kip_penstash = {
201 .name = "ssam:01:15:02:02:00",
202 .parent = &ssam_node_hub_kip,
205 /* HID touchpad (KIP hub). */
206 static const struct software_node ssam_node_hid_kip_touchpad = {
207 .name = "ssam:01:15:02:03:00",
208 .parent = &ssam_node_hub_kip,
211 /* HID device instance 5 (KIP hub, type-cover firmware update). */
212 static const struct software_node ssam_node_hid_kip_fwupd = {
213 .name = "ssam:01:15:02:05:00",
214 .parent = &ssam_node_hub_kip,
217 /* Tablet-mode switch via POS subsystem. */
218 static const struct software_node ssam_node_pos_tablet_switch = {
219 .name = "ssam:01:26:01:00:01",
220 .parent = &ssam_node_root,
224 * Devices for 5th- and 6th-generations models:
226 * - Surface Laptop 1 and 2,
227 * - Surface Pro 5 and 6.
229 static const struct software_node *ssam_node_group_gen5[] = {
231 &ssam_node_tmp_perf_profile,
235 /* Devices for Surface Book 3. */
236 static const struct software_node *ssam_node_group_sb3[] = {
241 &ssam_node_bat_sb3base,
242 &ssam_node_tmp_perf_profile,
244 &ssam_node_hid_base_keyboard,
245 &ssam_node_hid_base_touchpad,
246 &ssam_node_hid_base_iid5,
247 &ssam_node_hid_base_iid6,
251 /* Devices for Surface Laptop 3 and 4. */
252 static const struct software_node *ssam_node_group_sl3[] = {
256 &ssam_node_tmp_perf_profile,
257 &ssam_node_hid_main_keyboard,
258 &ssam_node_hid_main_touchpad,
259 &ssam_node_hid_main_iid5,
263 /* Devices for Surface Laptop 5. */
264 static const struct software_node *ssam_node_group_sl5[] = {
268 &ssam_node_tmp_perf_profile,
269 &ssam_node_hid_main_keyboard,
270 &ssam_node_hid_main_touchpad,
271 &ssam_node_hid_main_iid5,
272 &ssam_node_hid_sam_ucm_ucsi,
276 /* Devices for Surface Laptop Studio. */
277 static const struct software_node *ssam_node_group_sls[] = {
281 &ssam_node_tmp_perf_profile,
282 &ssam_node_pos_tablet_switch,
283 &ssam_node_hid_sam_keyboard,
284 &ssam_node_hid_sam_penstash,
285 &ssam_node_hid_sam_touchpad,
286 &ssam_node_hid_sam_sensors,
287 &ssam_node_hid_sam_ucm_ucsi,
288 &ssam_node_hid_sam_sysctrl,
292 /* Devices for Surface Laptop Go. */
293 static const struct software_node *ssam_node_group_slg1[] = {
297 &ssam_node_tmp_perf_profile,
301 /* Devices for Surface Pro 7 and Surface Pro 7+. */
302 static const struct software_node *ssam_node_group_sp7[] = {
306 &ssam_node_tmp_perf_profile,
310 /* Devices for Surface Pro 8 */
311 static const struct software_node *ssam_node_group_sp8[] = {
316 &ssam_node_tmp_perf_profile,
317 &ssam_node_kip_tablet_switch,
318 &ssam_node_hid_kip_keyboard,
319 &ssam_node_hid_kip_penstash,
320 &ssam_node_hid_kip_touchpad,
321 &ssam_node_hid_kip_fwupd,
322 &ssam_node_hid_sam_sensors,
323 &ssam_node_hid_sam_ucm_ucsi,
327 /* Devices for Surface Pro 9 */
328 static const struct software_node *ssam_node_group_sp9[] = {
333 &ssam_node_tmp_perf_profile_with_fan,
334 &ssam_node_tmp_sensors,
335 &ssam_node_fan_speed,
336 &ssam_node_pos_tablet_switch,
337 &ssam_node_hid_kip_keyboard,
338 &ssam_node_hid_kip_penstash,
339 &ssam_node_hid_kip_touchpad,
340 &ssam_node_hid_kip_fwupd,
341 &ssam_node_hid_sam_sensors,
342 &ssam_node_hid_sam_ucm_ucsi,
347 /* -- SSAM platform/meta-hub driver. ---------------------------------------- */
349 static const struct acpi_device_id ssam_platform_hub_match[] = {
350 /* Surface Pro 4, 5, and 6 (OMBR < 0x10) */
351 { "MSHW0081", (unsigned long)ssam_node_group_gen5 },
353 /* Surface Pro 6 (OMBR >= 0x10) */
354 { "MSHW0111", (unsigned long)ssam_node_group_gen5 },
357 { "MSHW0116", (unsigned long)ssam_node_group_sp7 },
360 { "MSHW0119", (unsigned long)ssam_node_group_sp7 },
363 { "MSHW0263", (unsigned long)ssam_node_group_sp8 },
366 { "MSHW0343", (unsigned long)ssam_node_group_sp9 },
369 { "MSHW0107", (unsigned long)ssam_node_group_gen5 },
372 { "MSHW0117", (unsigned long)ssam_node_group_sb3 },
374 /* Surface Laptop 1 */
375 { "MSHW0086", (unsigned long)ssam_node_group_gen5 },
377 /* Surface Laptop 2 */
378 { "MSHW0112", (unsigned long)ssam_node_group_gen5 },
380 /* Surface Laptop 3 (13", Intel) */
381 { "MSHW0114", (unsigned long)ssam_node_group_sl3 },
383 /* Surface Laptop 3 (15", AMD) and 4 (15", AMD) */
384 { "MSHW0110", (unsigned long)ssam_node_group_sl3 },
386 /* Surface Laptop 4 (13", Intel) */
387 { "MSHW0250", (unsigned long)ssam_node_group_sl3 },
389 /* Surface Laptop 5 */
390 { "MSHW0350", (unsigned long)ssam_node_group_sl5 },
392 /* Surface Laptop Go 1 */
393 { "MSHW0118", (unsigned long)ssam_node_group_slg1 },
395 /* Surface Laptop Go 2 */
396 { "MSHW0290", (unsigned long)ssam_node_group_slg1 },
398 /* Surface Laptop Studio */
399 { "MSHW0123", (unsigned long)ssam_node_group_sls },
403 MODULE_DEVICE_TABLE(acpi, ssam_platform_hub_match);
405 static int ssam_platform_hub_probe(struct platform_device *pdev)
407 const struct software_node **nodes;
408 struct ssam_controller *ctrl;
409 struct fwnode_handle *root;
412 nodes = (const struct software_node **)acpi_device_get_match_data(&pdev->dev);
417 * As we're adding the SSAM client devices as children under this device
418 * and not the SSAM controller, we need to add a device link to the
419 * controller to ensure that we remove all of our devices before the
420 * controller is removed. This also guarantees proper ordering for
421 * suspend/resume of the devices on this hub.
423 ctrl = ssam_client_bind(&pdev->dev);
425 return PTR_ERR(ctrl) == -ENODEV ? -EPROBE_DEFER : PTR_ERR(ctrl);
427 status = software_node_register_node_group(nodes);
431 root = software_node_fwnode(&ssam_node_root);
433 software_node_unregister_node_group(nodes);
437 set_secondary_fwnode(&pdev->dev, root);
439 status = __ssam_register_clients(&pdev->dev, ctrl, root);
441 set_secondary_fwnode(&pdev->dev, NULL);
442 software_node_unregister_node_group(nodes);
445 platform_set_drvdata(pdev, nodes);
449 static void ssam_platform_hub_remove(struct platform_device *pdev)
451 const struct software_node **nodes = platform_get_drvdata(pdev);
453 ssam_remove_clients(&pdev->dev);
454 set_secondary_fwnode(&pdev->dev, NULL);
455 software_node_unregister_node_group(nodes);
458 static struct platform_driver ssam_platform_hub_driver = {
459 .probe = ssam_platform_hub_probe,
460 .remove_new = ssam_platform_hub_remove,
462 .name = "surface_aggregator_platform_hub",
463 .acpi_match_table = ssam_platform_hub_match,
464 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
467 module_platform_driver(ssam_platform_hub_driver);
470 MODULE_DESCRIPTION("Device-registry for Surface System Aggregator Module");
471 MODULE_LICENSE("GPL");