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:02: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. */
72 static const struct software_node ssam_node_tmp_pprof = {
73 .name = "ssam:01:03:01:00:01",
74 .parent = &ssam_node_root,
77 /* Tablet-mode switch via KIP subsystem. */
78 static const struct software_node ssam_node_kip_tablet_switch = {
79 .name = "ssam:01:0e:01:00:01",
80 .parent = &ssam_node_root,
83 /* DTX / detachment-system device (Surface Book 3). */
84 static const struct software_node ssam_node_bas_dtx = {
85 .name = "ssam:01:11:01:00:00",
86 .parent = &ssam_node_root,
89 /* HID keyboard (SAM, TID=1). */
90 static const struct software_node ssam_node_hid_sam_keyboard = {
91 .name = "ssam:01:15:01:01:00",
92 .parent = &ssam_node_root,
95 /* HID pen stash (SAM, TID=1; pen taken / stashed away evens). */
96 static const struct software_node ssam_node_hid_sam_penstash = {
97 .name = "ssam:01:15:01:02:00",
98 .parent = &ssam_node_root,
101 /* HID touchpad (SAM, TID=1). */
102 static const struct software_node ssam_node_hid_sam_touchpad = {
103 .name = "ssam:01:15:01:03:00",
104 .parent = &ssam_node_root,
107 /* HID device instance 6 (SAM, TID=1, HID sensor collection). */
108 static const struct software_node ssam_node_hid_sam_sensors = {
109 .name = "ssam:01:15:01:06:00",
110 .parent = &ssam_node_root,
113 /* HID device instance 7 (SAM, TID=1, UCM UCSI HID client). */
114 static const struct software_node ssam_node_hid_sam_ucm_ucsi = {
115 .name = "ssam:01:15:01:07:00",
116 .parent = &ssam_node_root,
119 /* HID system controls (SAM, TID=1). */
120 static const struct software_node ssam_node_hid_sam_sysctrl = {
121 .name = "ssam:01:15:01:08:00",
122 .parent = &ssam_node_root,
126 static const struct software_node ssam_node_hid_main_keyboard = {
127 .name = "ssam:01:15:02:01:00",
128 .parent = &ssam_node_root,
132 static const struct software_node ssam_node_hid_main_touchpad = {
133 .name = "ssam:01:15:02:03:00",
134 .parent = &ssam_node_root,
137 /* HID device instance 5 (unknown HID device). */
138 static const struct software_node ssam_node_hid_main_iid5 = {
139 .name = "ssam:01:15:02:05:00",
140 .parent = &ssam_node_root,
143 /* HID keyboard (base hub). */
144 static const struct software_node ssam_node_hid_base_keyboard = {
145 .name = "ssam:01:15:02:01:00",
146 .parent = &ssam_node_hub_base,
149 /* HID touchpad (base hub). */
150 static const struct software_node ssam_node_hid_base_touchpad = {
151 .name = "ssam:01:15:02:03:00",
152 .parent = &ssam_node_hub_base,
155 /* HID device instance 5 (unknown HID device, base hub). */
156 static const struct software_node ssam_node_hid_base_iid5 = {
157 .name = "ssam:01:15:02:05:00",
158 .parent = &ssam_node_hub_base,
161 /* HID device instance 6 (unknown HID device, base hub). */
162 static const struct software_node ssam_node_hid_base_iid6 = {
163 .name = "ssam:01:15:02:06:00",
164 .parent = &ssam_node_hub_base,
167 /* HID keyboard (KIP hub). */
168 static const struct software_node ssam_node_hid_kip_keyboard = {
169 .name = "ssam:01:15:02:01:00",
170 .parent = &ssam_node_hub_kip,
173 /* HID pen stash (KIP hub; pen taken / stashed away evens). */
174 static const struct software_node ssam_node_hid_kip_penstash = {
175 .name = "ssam:01:15:02:02:00",
176 .parent = &ssam_node_hub_kip,
179 /* HID touchpad (KIP hub). */
180 static const struct software_node ssam_node_hid_kip_touchpad = {
181 .name = "ssam:01:15:02:03:00",
182 .parent = &ssam_node_hub_kip,
185 /* HID device instance 5 (KIP hub, type-cover firmware update). */
186 static const struct software_node ssam_node_hid_kip_fwupd = {
187 .name = "ssam:01:15:02:05:00",
188 .parent = &ssam_node_hub_kip,
191 /* Tablet-mode switch via POS subsystem. */
192 static const struct software_node ssam_node_pos_tablet_switch = {
193 .name = "ssam:01:26:01:00:01",
194 .parent = &ssam_node_root,
198 * Devices for 5th- and 6th-generations models:
200 * - Surface Laptop 1 and 2,
201 * - Surface Pro 5 and 6.
203 static const struct software_node *ssam_node_group_gen5[] = {
205 &ssam_node_tmp_pprof,
209 /* Devices for Surface Book 3. */
210 static const struct software_node *ssam_node_group_sb3[] = {
215 &ssam_node_bat_sb3base,
216 &ssam_node_tmp_pprof,
218 &ssam_node_hid_base_keyboard,
219 &ssam_node_hid_base_touchpad,
220 &ssam_node_hid_base_iid5,
221 &ssam_node_hid_base_iid6,
225 /* Devices for Surface Laptop 3 and 4. */
226 static const struct software_node *ssam_node_group_sl3[] = {
230 &ssam_node_tmp_pprof,
231 &ssam_node_hid_main_keyboard,
232 &ssam_node_hid_main_touchpad,
233 &ssam_node_hid_main_iid5,
237 /* Devices for Surface Laptop Studio. */
238 static const struct software_node *ssam_node_group_sls[] = {
242 &ssam_node_tmp_pprof,
243 &ssam_node_pos_tablet_switch,
244 &ssam_node_hid_sam_keyboard,
245 &ssam_node_hid_sam_penstash,
246 &ssam_node_hid_sam_touchpad,
247 &ssam_node_hid_sam_sensors,
248 &ssam_node_hid_sam_ucm_ucsi,
249 &ssam_node_hid_sam_sysctrl,
253 /* Devices for Surface Laptop Go. */
254 static const struct software_node *ssam_node_group_slg1[] = {
258 &ssam_node_tmp_pprof,
262 /* Devices for Surface Pro 7 and Surface Pro 7+. */
263 static const struct software_node *ssam_node_group_sp7[] = {
267 &ssam_node_tmp_pprof,
271 static const struct software_node *ssam_node_group_sp8[] = {
276 &ssam_node_tmp_pprof,
277 &ssam_node_kip_tablet_switch,
278 &ssam_node_hid_kip_keyboard,
279 &ssam_node_hid_kip_penstash,
280 &ssam_node_hid_kip_touchpad,
281 &ssam_node_hid_kip_fwupd,
282 &ssam_node_hid_sam_sensors,
283 &ssam_node_hid_sam_ucm_ucsi,
288 /* -- SSAM platform/meta-hub driver. ---------------------------------------- */
290 static const struct acpi_device_id ssam_platform_hub_match[] = {
291 /* Surface Pro 4, 5, and 6 (OMBR < 0x10) */
292 { "MSHW0081", (unsigned long)ssam_node_group_gen5 },
294 /* Surface Pro 6 (OMBR >= 0x10) */
295 { "MSHW0111", (unsigned long)ssam_node_group_gen5 },
298 { "MSHW0116", (unsigned long)ssam_node_group_sp7 },
301 { "MSHW0119", (unsigned long)ssam_node_group_sp7 },
304 { "MSHW0263", (unsigned long)ssam_node_group_sp8 },
307 { "MSHW0107", (unsigned long)ssam_node_group_gen5 },
310 { "MSHW0117", (unsigned long)ssam_node_group_sb3 },
312 /* Surface Laptop 1 */
313 { "MSHW0086", (unsigned long)ssam_node_group_gen5 },
315 /* Surface Laptop 2 */
316 { "MSHW0112", (unsigned long)ssam_node_group_gen5 },
318 /* Surface Laptop 3 (13", Intel) */
319 { "MSHW0114", (unsigned long)ssam_node_group_sl3 },
321 /* Surface Laptop 3 (15", AMD) and 4 (15", AMD) */
322 { "MSHW0110", (unsigned long)ssam_node_group_sl3 },
324 /* Surface Laptop 4 (13", Intel) */
325 { "MSHW0250", (unsigned long)ssam_node_group_sl3 },
327 /* Surface Laptop Go 1 */
328 { "MSHW0118", (unsigned long)ssam_node_group_slg1 },
330 /* Surface Laptop Go 2 */
331 { "MSHW0290", (unsigned long)ssam_node_group_slg1 },
333 /* Surface Laptop Studio */
334 { "MSHW0123", (unsigned long)ssam_node_group_sls },
338 MODULE_DEVICE_TABLE(acpi, ssam_platform_hub_match);
340 static int ssam_platform_hub_probe(struct platform_device *pdev)
342 const struct software_node **nodes;
343 struct ssam_controller *ctrl;
344 struct fwnode_handle *root;
347 nodes = (const struct software_node **)acpi_device_get_match_data(&pdev->dev);
352 * As we're adding the SSAM client devices as children under this device
353 * and not the SSAM controller, we need to add a device link to the
354 * controller to ensure that we remove all of our devices before the
355 * controller is removed. This also guarantees proper ordering for
356 * suspend/resume of the devices on this hub.
358 ctrl = ssam_client_bind(&pdev->dev);
360 return PTR_ERR(ctrl) == -ENODEV ? -EPROBE_DEFER : PTR_ERR(ctrl);
362 status = software_node_register_node_group(nodes);
366 root = software_node_fwnode(&ssam_node_root);
368 software_node_unregister_node_group(nodes);
372 set_secondary_fwnode(&pdev->dev, root);
374 status = __ssam_register_clients(&pdev->dev, ctrl, root);
376 set_secondary_fwnode(&pdev->dev, NULL);
377 software_node_unregister_node_group(nodes);
380 platform_set_drvdata(pdev, nodes);
384 static int ssam_platform_hub_remove(struct platform_device *pdev)
386 const struct software_node **nodes = platform_get_drvdata(pdev);
388 ssam_remove_clients(&pdev->dev);
389 set_secondary_fwnode(&pdev->dev, NULL);
390 software_node_unregister_node_group(nodes);
394 static struct platform_driver ssam_platform_hub_driver = {
395 .probe = ssam_platform_hub_probe,
396 .remove = ssam_platform_hub_remove,
398 .name = "surface_aggregator_platform_hub",
399 .acpi_match_table = ssam_platform_hub_match,
400 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
403 module_platform_driver(ssam_platform_hub_driver);
406 MODULE_DESCRIPTION("Device-registry for Surface System Aggregator Module");
407 MODULE_LICENSE("GPL");