Skip to content

Commit a6fde5a

Browse files
qzedStollD
authored andcommittedJul 23, 2023
platform/surface: aggregator: Enforce use of target-ID enum in device ID macros
Similar to the target category (TC), the target ID (TID) can be one value out of a small number of choices, given in enum ssam_ssh_tid. In the device ID macros, SSAM_SDEV() and SSAM_VDEV() we already use text expansion to, both, remove some textual clutter for the target category values and enforce that the value belongs to the known set. Now that we know the names for the target IDs, use the same trick for them as well. Also rename the SSAM_ANY_x macros to SSAM_SSH_x_ANY to better fit in. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20221202223327.690880-9-luzmaximilian@gmail.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Patchset: surface-sam
1 parent 6357e47 commit a6fde5a

File tree

8 files changed

+35
-35
lines changed

8 files changed

+35
-35
lines changed
 

‎drivers/hid/surface-hid/surface_hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void surface_hid_remove(struct ssam_device *sdev)
230230
}
231231

232232
static const struct ssam_device_id surface_hid_match[] = {
233-
{ SSAM_SDEV(HID, SSAM_ANY_TID, SSAM_ANY_IID, 0x00) },
233+
{ SSAM_SDEV(HID, ANY, SSAM_SSH_IID_ANY, 0x00) },
234234
{ },
235235
};
236236
MODULE_DEVICE_TABLE(ssam, surface_hid_match);

‎drivers/platform/surface/surface_aggregator_hub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ static const struct ssam_hub_desc kip_hub = {
348348
/* -- Driver registration. -------------------------------------------------- */
349349

350350
static const struct ssam_device_id ssam_hub_match[] = {
351-
{ SSAM_VDEV(HUB, 0x01, SSAM_SSH_TC_KIP, 0x00), (unsigned long)&kip_hub },
352-
{ SSAM_VDEV(HUB, 0x02, SSAM_SSH_TC_BAS, 0x00), (unsigned long)&base_hub },
351+
{ SSAM_VDEV(HUB, SAM, SSAM_SSH_TC_KIP, 0x00), (unsigned long)&kip_hub },
352+
{ SSAM_VDEV(HUB, KIP, SSAM_SSH_TC_BAS, 0x00), (unsigned long)&base_hub },
353353
{ }
354354
};
355355
MODULE_DEVICE_TABLE(ssam, ssam_hub_match);

‎drivers/platform/surface/surface_aggregator_tabletsw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ static const struct ssam_tablet_sw_desc ssam_pos_sw_desc = {
515515
/* -- Driver registration. -------------------------------------------------- */
516516

517517
static const struct ssam_device_id ssam_tablet_sw_match[] = {
518-
{ SSAM_SDEV(KIP, 0x01, 0x00, 0x01), (unsigned long)&ssam_kip_sw_desc },
519-
{ SSAM_SDEV(POS, 0x01, 0x00, 0x01), (unsigned long)&ssam_pos_sw_desc },
518+
{ SSAM_SDEV(KIP, SAM, 0x00, 0x01), (unsigned long)&ssam_kip_sw_desc },
519+
{ SSAM_SDEV(POS, SAM, 0x00, 0x01), (unsigned long)&ssam_pos_sw_desc },
520520
{ },
521521
};
522522
MODULE_DEVICE_TABLE(ssam, ssam_tablet_sw_match);

‎drivers/platform/surface/surface_dtx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ static void surface_dtx_ssam_remove(struct ssam_device *sdev)
12141214
}
12151215

12161216
static const struct ssam_device_id surface_dtx_ssam_match[] = {
1217-
{ SSAM_SDEV(BAS, 0x01, 0x00, 0x00) },
1217+
{ SSAM_SDEV(BAS, SAM, 0x00, 0x00) },
12181218
{ },
12191219
};
12201220
MODULE_DEVICE_TABLE(ssam, surface_dtx_ssam_match);

‎drivers/platform/surface/surface_platform_profile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void surface_platform_profile_remove(struct ssam_device *sdev)
169169
}
170170

171171
static const struct ssam_device_id ssam_platform_profile_match[] = {
172-
{ SSAM_SDEV(TMP, 0x01, 0x00, 0x01) },
172+
{ SSAM_SDEV(TMP, SAM, 0x00, 0x01) },
173173
{ },
174174
};
175175
MODULE_DEVICE_TABLE(ssam, ssam_platform_profile_match);

‎drivers/power/supply/surface_battery.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,8 @@ static const struct spwr_psy_properties spwr_psy_props_bat2_sb3 = {
852852
};
853853

854854
static const struct ssam_device_id surface_battery_match[] = {
855-
{ SSAM_SDEV(BAT, 0x01, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat1 },
856-
{ SSAM_SDEV(BAT, 0x02, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat2_sb3 },
855+
{ SSAM_SDEV(BAT, SAM, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat1 },
856+
{ SSAM_SDEV(BAT, KIP, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat2_sb3 },
857857
{ },
858858
};
859859
MODULE_DEVICE_TABLE(ssam, surface_battery_match);

‎drivers/power/supply/surface_charger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static const struct spwr_psy_properties spwr_psy_props_adp1 = {
260260
};
261261

262262
static const struct ssam_device_id surface_ac_match[] = {
263-
{ SSAM_SDEV(BAT, 0x01, 0x01, 0x01), (unsigned long)&spwr_psy_props_adp1 },
263+
{ SSAM_SDEV(BAT, SAM, 0x01, 0x01), (unsigned long)&spwr_psy_props_adp1 },
264264
{ },
265265
};
266266
MODULE_DEVICE_TABLE(ssam, surface_ac_match);

‎include/linux/surface_aggregator/device.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ struct ssam_device_uid {
6868
* match_flags member of the device ID structure. Do not use them directly
6969
* with struct ssam_device_id or struct ssam_device_uid.
7070
*/
71-
#define SSAM_ANY_TID 0xffff
72-
#define SSAM_ANY_IID 0xffff
73-
#define SSAM_ANY_FUN 0xffff
71+
#define SSAM_SSH_TID_ANY 0xffff
72+
#define SSAM_SSH_IID_ANY 0xffff
73+
#define SSAM_SSH_FUN_ANY 0xffff
7474

7575
/**
7676
* SSAM_DEVICE() - Initialize a &struct ssam_device_id with the given
@@ -83,25 +83,25 @@ struct ssam_device_uid {
8383
*
8484
* Initializes a &struct ssam_device_id with the given parameters. See &struct
8585
* ssam_device_uid for details regarding the parameters. The special values
86-
* %SSAM_ANY_TID, %SSAM_ANY_IID, and %SSAM_ANY_FUN can be used to specify that
86+
* %SSAM_SSH_TID_ANY, %SSAM_SSH_IID_ANY, and %SSAM_SSH_FUN_ANY can be used to specify that
8787
* matching should ignore target ID, instance ID, and/or sub-function,
8888
* respectively. This macro initializes the ``match_flags`` field based on the
8989
* given parameters.
9090
*
9191
* Note: The parameters @d and @cat must be valid &u8 values, the parameters
92-
* @tid, @iid, and @fun must be either valid &u8 values or %SSAM_ANY_TID,
93-
* %SSAM_ANY_IID, or %SSAM_ANY_FUN, respectively. Other non-&u8 values are not
92+
* @tid, @iid, and @fun must be either valid &u8 values or %SSAM_SSH_TID_ANY,
93+
* %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values are not
9494
* allowed.
9595
*/
9696
#define SSAM_DEVICE(d, cat, tid, iid, fun) \
97-
.match_flags = (((tid) != SSAM_ANY_TID) ? SSAM_MATCH_TARGET : 0) \
98-
| (((iid) != SSAM_ANY_IID) ? SSAM_MATCH_INSTANCE : 0) \
99-
| (((fun) != SSAM_ANY_FUN) ? SSAM_MATCH_FUNCTION : 0), \
97+
.match_flags = (((tid) != SSAM_SSH_TID_ANY) ? SSAM_MATCH_TARGET : 0) \
98+
| (((iid) != SSAM_SSH_IID_ANY) ? SSAM_MATCH_INSTANCE : 0) \
99+
| (((fun) != SSAM_SSH_FUN_ANY) ? SSAM_MATCH_FUNCTION : 0), \
100100
.domain = d, \
101101
.category = cat, \
102-
.target = __builtin_choose_expr((tid) != SSAM_ANY_TID, (tid), 0), \
103-
.instance = __builtin_choose_expr((iid) != SSAM_ANY_IID, (iid), 0), \
104-
.function = __builtin_choose_expr((fun) != SSAM_ANY_FUN, (fun), 0)
102+
.target = __builtin_choose_expr((tid) != SSAM_SSH_TID_ANY, (tid), 0), \
103+
.instance = __builtin_choose_expr((iid) != SSAM_SSH_IID_ANY, (iid), 0), \
104+
.function = __builtin_choose_expr((fun) != SSAM_SSH_FUN_ANY, (fun), 0)
105105

106106
/**
107107
* SSAM_VDEV() - Initialize a &struct ssam_device_id as virtual device with
@@ -113,18 +113,18 @@ struct ssam_device_uid {
113113
*
114114
* Initializes a &struct ssam_device_id with the given parameters in the
115115
* virtual domain. See &struct ssam_device_uid for details regarding the
116-
* parameters. The special values %SSAM_ANY_TID, %SSAM_ANY_IID, and
117-
* %SSAM_ANY_FUN can be used to specify that matching should ignore target ID,
116+
* parameters. The special values %SSAM_SSH_TID_ANY, %SSAM_SSH_IID_ANY, and
117+
* %SSAM_SSH_FUN_ANY can be used to specify that matching should ignore target ID,
118118
* instance ID, and/or sub-function, respectively. This macro initializes the
119119
* ``match_flags`` field based on the given parameters.
120120
*
121121
* Note: The parameter @cat must be a valid &u8 value, the parameters @tid,
122-
* @iid, and @fun must be either valid &u8 values or %SSAM_ANY_TID,
123-
* %SSAM_ANY_IID, or %SSAM_ANY_FUN, respectively. Other non-&u8 values are not
122+
* @iid, and @fun must be either valid &u8 values or %SSAM_SSH_TID_ANY,
123+
* %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values are not
124124
* allowed.
125125
*/
126126
#define SSAM_VDEV(cat, tid, iid, fun) \
127-
SSAM_DEVICE(SSAM_DOMAIN_VIRTUAL, SSAM_VIRTUAL_TC_##cat, tid, iid, fun)
127+
SSAM_DEVICE(SSAM_DOMAIN_VIRTUAL, SSAM_VIRTUAL_TC_##cat, SSAM_SSH_TID_##tid, iid, fun)
128128

129129
/**
130130
* SSAM_SDEV() - Initialize a &struct ssam_device_id as physical SSH device
@@ -136,18 +136,18 @@ struct ssam_device_uid {
136136
*
137137
* Initializes a &struct ssam_device_id with the given parameters in the SSH
138138
* domain. See &struct ssam_device_uid for details regarding the parameters.
139-
* The special values %SSAM_ANY_TID, %SSAM_ANY_IID, and %SSAM_ANY_FUN can be
140-
* used to specify that matching should ignore target ID, instance ID, and/or
141-
* sub-function, respectively. This macro initializes the ``match_flags``
142-
* field based on the given parameters.
139+
* The special values %SSAM_SSH_TID_ANY, %SSAM_SSH_IID_ANY, and
140+
* %SSAM_SSH_FUN_ANY can be used to specify that matching should ignore target
141+
* ID, instance ID, and/or sub-function, respectively. This macro initializes
142+
* the ``match_flags`` field based on the given parameters.
143143
*
144144
* Note: The parameter @cat must be a valid &u8 value, the parameters @tid,
145-
* @iid, and @fun must be either valid &u8 values or %SSAM_ANY_TID,
146-
* %SSAM_ANY_IID, or %SSAM_ANY_FUN, respectively. Other non-&u8 values are not
147-
* allowed.
145+
* @iid, and @fun must be either valid &u8 values or %SSAM_SSH_TID_ANY,
146+
* %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values
147+
* are not allowed.
148148
*/
149149
#define SSAM_SDEV(cat, tid, iid, fun) \
150-
SSAM_DEVICE(SSAM_DOMAIN_SERIALHUB, SSAM_SSH_TC_##cat, tid, iid, fun)
150+
SSAM_DEVICE(SSAM_DOMAIN_SERIALHUB, SSAM_SSH_TC_##cat, SSAM_SSH_TID_##tid, iid, fun)
151151

152152
/*
153153
* enum ssam_device_flags - Flags for SSAM client devices.

0 commit comments

Comments
 (0)