0006-surface-sam.patch 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956
  1. From b485239f375af4576846cfeb3d3de9338d7c7fca Mon Sep 17 00:00:00 2001
  2. From: Maximilian Luz <luzmaximilian@gmail.com>
  3. Date: Fri, 2 Dec 2022 23:33:20 +0100
  4. Subject: [PATCH] platform/surface: aggregator: Improve documentation and
  5. handling of message target and source IDs
  6. The `tid_in` and `tid_out` fields of the serial hub protocol command
  7. struct (struct ssh_command) are actually source and target IDs,
  8. indicating the peer from which the message originated and the peer for
  9. which it is intended.
  10. Change the naming of those fields accordingly and improve the protocol
  11. documentation. Additionally, introduce an enum containing all currently
  12. known peers, i.e. targets and sources.
  13. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  14. Link: https://lore.kernel.org/r/20221202223327.690880-3-luzmaximilian@gmail.com
  15. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  16. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  17. Patchset: surface-sam
  18. ---
  19. .../driver-api/surface_aggregator/client.rst | 4 +-
  20. .../driver-api/surface_aggregator/ssh.rst | 36 +++++++++--------
  21. .../platform/surface/aggregator/controller.c | 12 +++---
  22. .../platform/surface/aggregator/ssh_msgb.h | 4 +-
  23. .../surface/aggregator/ssh_request_layer.c | 11 ++---
  24. include/linux/surface_aggregator/controller.h | 4 +-
  25. include/linux/surface_aggregator/serial_hub.h | 40 +++++++++++++------
  26. 7 files changed, 64 insertions(+), 47 deletions(-)
  27. diff --git a/Documentation/driver-api/surface_aggregator/client.rst b/Documentation/driver-api/surface_aggregator/client.rst
  28. index 27f95abdbe997..9d7411223a848 100644
  29. --- a/Documentation/driver-api/surface_aggregator/client.rst
  30. +++ b/Documentation/driver-api/surface_aggregator/client.rst
  31. @@ -191,7 +191,7 @@ data received from it is converted from little-endian to host endianness.
  32. * they do not correspond to an actual SAM/EC request.
  33. */
  34. rqst.target_category = SSAM_SSH_TC_SAM;
  35. - rqst.target_id = 0x01;
  36. + rqst.target_id = SSAM_SSH_TID_SAM;
  37. rqst.command_id = 0x02;
  38. rqst.instance_id = 0x03;
  39. rqst.flags = SSAM_REQUEST_HAS_RESPONSE;
  40. @@ -241,7 +241,7 @@ one of the generator macros, for example via:
  41. SSAM_DEFINE_SYNC_REQUEST_W(__ssam_tmp_perf_mode_set, __le32, {
  42. .target_category = SSAM_SSH_TC_TMP,
  43. - .target_id = 0x01,
  44. + .target_id = SSAM_SSH_TID_SAM,
  45. .command_id = 0x03,
  46. .instance_id = 0x00,
  47. });
  48. diff --git a/Documentation/driver-api/surface_aggregator/ssh.rst b/Documentation/driver-api/surface_aggregator/ssh.rst
  49. index bf007d6c98732..18fd0f0aee84b 100644
  50. --- a/Documentation/driver-api/surface_aggregator/ssh.rst
  51. +++ b/Documentation/driver-api/surface_aggregator/ssh.rst
  52. @@ -13,6 +13,7 @@
  53. .. |DATA_NSQ| replace:: ``DATA_NSQ``
  54. .. |TC| replace:: ``TC``
  55. .. |TID| replace:: ``TID``
  56. +.. |SID| replace:: ``SID``
  57. .. |IID| replace:: ``IID``
  58. .. |RQID| replace:: ``RQID``
  59. .. |CID| replace:: ``CID``
  60. @@ -219,13 +220,13 @@ following fields, packed together and in order:
  61. - |u8|
  62. - Target category.
  63. - * - |TID| (out)
  64. + * - |TID|
  65. - |u8|
  66. - - Target ID for outgoing (host to EC) commands.
  67. + - Target ID for commands/messages.
  68. - * - |TID| (in)
  69. + * - |SID|
  70. - |u8|
  71. - - Target ID for incoming (EC to host) commands.
  72. + - Source ID for commands/messages.
  73. * - |IID|
  74. - |u8|
  75. @@ -286,19 +287,20 @@ general, however, a single target category should map to a single reserved
  76. event request ID.
  77. Furthermore, requests, responses, and events have an associated target ID
  78. -(``TID``). This target ID is split into output (host to EC) and input (EC to
  79. -host) fields, with the respecting other field (e.g. output field on incoming
  80. -messages) set to zero. Two ``TID`` values are known: Primary (``0x01``) and
  81. -secondary (``0x02``). In general, the response to a request should have the
  82. -same ``TID`` value, however, the field (output vs. input) should be used in
  83. -accordance to the direction in which the response is sent (i.e. on the input
  84. -field, as responses are generally sent from the EC to the host).
  85. -
  86. -Note that, even though requests and events should be uniquely identifiable
  87. -by target category and command ID alone, the EC may require specific
  88. -target ID and instance ID values to accept a command. A command that is
  89. -accepted for ``TID=1``, for example, may not be accepted for ``TID=2``
  90. -and vice versa.
  91. +(``TID``) and source ID (``SID``). These two fields indicate where a message
  92. +originates from (``SID``) and what the intended target of the message is
  93. +(``TID``). Note that a response to a specific request therefore has the source
  94. +and target IDs swapped when compared to the original request (i.e. the request
  95. +target is the response source and the request source is the response target).
  96. +See (:c:type:`enum ssh_request_id <ssh_request_id>`) for possible values of
  97. +both.
  98. +
  99. +Note that, even though requests and events should be uniquely identifiable by
  100. +target category and command ID alone, the EC may require specific target ID and
  101. +instance ID values to accept a command. A command that is accepted for
  102. +``TID=1``, for example, may not be accepted for ``TID=2`` and vice versa. While
  103. +this may not always hold in reality, you can think of different target/source
  104. +IDs indicating different physical ECs with potentially different feature sets.
  105. Limitations and Observations
  106. diff --git a/drivers/platform/surface/aggregator/controller.c b/drivers/platform/surface/aggregator/controller.c
  107. index 30cea324ff95f..cb86760622762 100644
  108. --- a/drivers/platform/surface/aggregator/controller.c
  109. +++ b/drivers/platform/surface/aggregator/controller.c
  110. @@ -994,7 +994,7 @@ static void ssam_handle_event(struct ssh_rtl *rtl,
  111. item->rqid = get_unaligned_le16(&cmd->rqid);
  112. item->event.target_category = cmd->tc;
  113. - item->event.target_id = cmd->tid_in;
  114. + item->event.target_id = cmd->sid;
  115. item->event.command_id = cmd->cid;
  116. item->event.instance_id = cmd->iid;
  117. memcpy(&item->event.data[0], data->ptr, data->len);
  118. @@ -1779,35 +1779,35 @@ EXPORT_SYMBOL_GPL(ssam_request_sync_with_buffer);
  119. SSAM_DEFINE_SYNC_REQUEST_R(ssam_ssh_get_firmware_version, __le32, {
  120. .target_category = SSAM_SSH_TC_SAM,
  121. - .target_id = 0x01,
  122. + .target_id = SSAM_SSH_TID_SAM,
  123. .command_id = 0x13,
  124. .instance_id = 0x00,
  125. });
  126. SSAM_DEFINE_SYNC_REQUEST_R(ssam_ssh_notif_display_off, u8, {
  127. .target_category = SSAM_SSH_TC_SAM,
  128. - .target_id = 0x01,
  129. + .target_id = SSAM_SSH_TID_SAM,
  130. .command_id = 0x15,
  131. .instance_id = 0x00,
  132. });
  133. SSAM_DEFINE_SYNC_REQUEST_R(ssam_ssh_notif_display_on, u8, {
  134. .target_category = SSAM_SSH_TC_SAM,
  135. - .target_id = 0x01,
  136. + .target_id = SSAM_SSH_TID_SAM,
  137. .command_id = 0x16,
  138. .instance_id = 0x00,
  139. });
  140. SSAM_DEFINE_SYNC_REQUEST_R(ssam_ssh_notif_d0_exit, u8, {
  141. .target_category = SSAM_SSH_TC_SAM,
  142. - .target_id = 0x01,
  143. + .target_id = SSAM_SSH_TID_SAM,
  144. .command_id = 0x33,
  145. .instance_id = 0x00,
  146. });
  147. SSAM_DEFINE_SYNC_REQUEST_R(ssam_ssh_notif_d0_entry, u8, {
  148. .target_category = SSAM_SSH_TC_SAM,
  149. - .target_id = 0x01,
  150. + .target_id = SSAM_SSH_TID_SAM,
  151. .command_id = 0x34,
  152. .instance_id = 0x00,
  153. });
  154. diff --git a/drivers/platform/surface/aggregator/ssh_msgb.h b/drivers/platform/surface/aggregator/ssh_msgb.h
  155. index f3ecad92eefd8..438873e060986 100644
  156. --- a/drivers/platform/surface/aggregator/ssh_msgb.h
  157. +++ b/drivers/platform/surface/aggregator/ssh_msgb.h
  158. @@ -189,8 +189,8 @@ static inline void msgb_push_cmd(struct msgbuf *msgb, u8 seq, u16 rqid,
  159. __msgb_push_u8(msgb, SSH_PLD_TYPE_CMD); /* Payload type. */
  160. __msgb_push_u8(msgb, rqst->target_category); /* Target category. */
  161. - __msgb_push_u8(msgb, rqst->target_id); /* Target ID (out). */
  162. - __msgb_push_u8(msgb, 0x00); /* Target ID (in). */
  163. + __msgb_push_u8(msgb, rqst->target_id); /* Target ID. */
  164. + __msgb_push_u8(msgb, SSAM_SSH_TID_HOST); /* Source ID. */
  165. __msgb_push_u8(msgb, rqst->instance_id); /* Instance ID. */
  166. __msgb_push_u16(msgb, rqid); /* Request ID. */
  167. __msgb_push_u8(msgb, rqst->command_id); /* Command ID. */
  168. diff --git a/drivers/platform/surface/aggregator/ssh_request_layer.c b/drivers/platform/surface/aggregator/ssh_request_layer.c
  169. index 69132976d297e..90634dcacabf2 100644
  170. --- a/drivers/platform/surface/aggregator/ssh_request_layer.c
  171. +++ b/drivers/platform/surface/aggregator/ssh_request_layer.c
  172. @@ -920,13 +920,14 @@ static void ssh_rtl_rx_command(struct ssh_ptl *p, const struct ssam_span *data)
  173. * Check if the message was intended for us. If not, drop it.
  174. *
  175. * Note: We will need to change this to handle debug messages. On newer
  176. - * generation devices, these seem to be sent to tid_out=0x03. We as
  177. - * host can still receive them as they can be forwarded via an override
  178. - * option on SAM, but doing so does not change tid_out=0x00.
  179. + * generation devices, these seem to be sent to SSAM_SSH_TID_DEBUG. We
  180. + * as host can still receive them as they can be forwarded via an
  181. + * override option on SAM, but doing so does not change the target ID
  182. + * to SSAM_SSH_TID_HOST.
  183. */
  184. - if (command->tid_out != 0x00) {
  185. + if (command->tid != SSAM_SSH_TID_HOST) {
  186. rtl_warn(rtl, "rtl: dropping message not intended for us (tid = %#04x)\n",
  187. - command->tid_out);
  188. + command->tid);
  189. return;
  190. }
  191. diff --git a/include/linux/surface_aggregator/controller.h b/include/linux/surface_aggregator/controller.h
  192. index d11a1c6e3186a..8932bc0bae187 100644
  193. --- a/include/linux/surface_aggregator/controller.h
  194. +++ b/include/linux/surface_aggregator/controller.h
  195. @@ -912,10 +912,10 @@ enum ssam_event_mask {
  196. })
  197. #define SSAM_EVENT_REGISTRY_SAM \
  198. - SSAM_EVENT_REGISTRY(SSAM_SSH_TC_SAM, 0x01, 0x0b, 0x0c)
  199. + SSAM_EVENT_REGISTRY(SSAM_SSH_TC_SAM, SSAM_SSH_TID_SAM, 0x0b, 0x0c)
  200. #define SSAM_EVENT_REGISTRY_KIP \
  201. - SSAM_EVENT_REGISTRY(SSAM_SSH_TC_KIP, 0x02, 0x27, 0x28)
  202. + SSAM_EVENT_REGISTRY(SSAM_SSH_TC_KIP, SSAM_SSH_TID_KIP, 0x27, 0x28)
  203. #define SSAM_EVENT_REGISTRY_REG(tid)\
  204. SSAM_EVENT_REGISTRY(SSAM_SSH_TC_REG, tid, 0x01, 0x02)
  205. diff --git a/include/linux/surface_aggregator/serial_hub.h b/include/linux/surface_aggregator/serial_hub.h
  206. index 45501b6e54e8a..5c4ae1a261831 100644
  207. --- a/include/linux/surface_aggregator/serial_hub.h
  208. +++ b/include/linux/surface_aggregator/serial_hub.h
  209. @@ -83,23 +83,21 @@ enum ssh_payload_type {
  210. /**
  211. * struct ssh_command - Payload of a command-type frame.
  212. - * @type: The type of the payload. See &enum ssh_payload_type. Should be
  213. - * SSH_PLD_TYPE_CMD for this struct.
  214. - * @tc: Command target category.
  215. - * @tid_out: Output target ID. Should be zero if this an incoming (EC to host)
  216. - * message.
  217. - * @tid_in: Input target ID. Should be zero if this is an outgoing (host to
  218. - * EC) message.
  219. - * @iid: Instance ID.
  220. - * @rqid: Request ID. Used to match requests with responses and differentiate
  221. - * between responses and events.
  222. - * @cid: Command ID.
  223. + * @type: The type of the payload. See &enum ssh_payload_type. Should be
  224. + * SSH_PLD_TYPE_CMD for this struct.
  225. + * @tc: Command target category.
  226. + * @tid: Target ID. Indicates the target of the message.
  227. + * @sid: Source ID. Indicates the source of the message.
  228. + * @iid: Instance ID.
  229. + * @rqid: Request ID. Used to match requests with responses and differentiate
  230. + * between responses and events.
  231. + * @cid: Command ID.
  232. */
  233. struct ssh_command {
  234. u8 type;
  235. u8 tc;
  236. - u8 tid_out;
  237. - u8 tid_in;
  238. + u8 tid;
  239. + u8 sid;
  240. u8 iid;
  241. __le16 rqid;
  242. u8 cid;
  243. @@ -280,6 +278,22 @@ struct ssam_span {
  244. size_t len;
  245. };
  246. +/**
  247. + * enum ssam_ssh_tid - Target/source IDs for Serial Hub messages.
  248. + * @SSAM_SSH_TID_HOST: We as the kernel Serial Hub driver.
  249. + * @SSAM_SSH_TID_SAM: The Surface Aggregator EC.
  250. + * @SSAM_SSH_TID_KIP: Keyboard and perihperal controller.
  251. + * @SSAM_SSH_TID_DEBUG: Debug connector.
  252. + * @SSAM_SSH_TID_SURFLINK: SurfLink connector.
  253. + */
  254. +enum ssam_ssh_tid {
  255. + SSAM_SSH_TID_HOST = 0x00,
  256. + SSAM_SSH_TID_SAM = 0x01,
  257. + SSAM_SSH_TID_KIP = 0x02,
  258. + SSAM_SSH_TID_DEBUG = 0x03,
  259. + SSAM_SSH_TID_SURFLINK = 0x04,
  260. +};
  261. +
  262. /*
  263. * Known SSH/EC target categories.
  264. *
  265. --
  266. 2.43.0
  267. From 69c2a8e68aca66851c845903701871b9f71aa97c Mon Sep 17 00:00:00 2001
  268. From: Maximilian Luz <luzmaximilian@gmail.com>
  269. Date: Fri, 2 Dec 2022 23:33:21 +0100
  270. Subject: [PATCH] platform/surface: aggregator: Add target and source IDs to
  271. command trace events
  272. Add command source and target IDs to trace events.
  273. Tracing support for the Surface Aggregator driver was originally
  274. implemented at a time when only two peers were known: Host and SAM. We
  275. now know that there are at least five, with three actively being used
  276. (Host, SAM, KIP; four with Debug if you want to count manually enabling
  277. that interface). So it makes sense to also explicitly name the peers
  278. involved when tracing.
  279. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  280. Link: https://lore.kernel.org/r/20221202223327.690880-4-luzmaximilian@gmail.com
  281. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  282. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  283. Patchset: surface-sam
  284. ---
  285. drivers/platform/surface/aggregator/trace.h | 73 +++++++++++++++++++--
  286. 1 file changed, 67 insertions(+), 6 deletions(-)
  287. diff --git a/drivers/platform/surface/aggregator/trace.h b/drivers/platform/surface/aggregator/trace.h
  288. index 2a2c17771d014..55cc61bba1da6 100644
  289. --- a/drivers/platform/surface/aggregator/trace.h
  290. +++ b/drivers/platform/surface/aggregator/trace.h
  291. @@ -96,6 +96,7 @@ TRACE_DEFINE_ENUM(SSAM_SSH_TC_POS);
  292. #define SSAM_SEQ_NOT_APPLICABLE ((u16)-1)
  293. #define SSAM_RQID_NOT_APPLICABLE ((u32)-1)
  294. #define SSAM_SSH_TC_NOT_APPLICABLE 0
  295. +#define SSAM_SSH_TID_NOT_APPLICABLE ((u8)-1)
  296. #ifndef _SURFACE_AGGREGATOR_TRACE_HELPERS
  297. #define _SURFACE_AGGREGATOR_TRACE_HELPERS
  298. @@ -150,12 +151,44 @@ static inline u32 ssam_trace_get_request_id(const struct ssh_packet *p)
  299. return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(rqid)]);
  300. }
  301. +/**
  302. + * ssam_trace_get_request_tid() - Read the packet's request target ID.
  303. + * @p: The packet.
  304. + *
  305. + * Return: Returns the packet's request target ID (TID) field if the packet
  306. + * represents a request with command data, or %SSAM_SSH_TID_NOT_APPLICABLE
  307. + * if not (e.g. flush request, control packet).
  308. + */
  309. +static inline u32 ssam_trace_get_request_tid(const struct ssh_packet *p)
  310. +{
  311. + if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
  312. + return SSAM_SSH_TID_NOT_APPLICABLE;
  313. +
  314. + return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(tid)]);
  315. +}
  316. +
  317. +/**
  318. + * ssam_trace_get_request_sid() - Read the packet's request source ID.
  319. + * @p: The packet.
  320. + *
  321. + * Return: Returns the packet's request source ID (SID) field if the packet
  322. + * represents a request with command data, or %SSAM_SSH_TID_NOT_APPLICABLE
  323. + * if not (e.g. flush request, control packet).
  324. + */
  325. +static inline u32 ssam_trace_get_request_sid(const struct ssh_packet *p)
  326. +{
  327. + if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
  328. + return SSAM_SSH_TID_NOT_APPLICABLE;
  329. +
  330. + return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(sid)]);
  331. +}
  332. +
  333. /**
  334. * ssam_trace_get_request_tc() - Read the packet's request target category.
  335. * @p: The packet.
  336. *
  337. * Return: Returns the packet's request target category (TC) field if the
  338. - * packet represents a request with command data, or %SSAM_TC_NOT_APPLICABLE
  339. + * packet represents a request with command data, or %SSAM_SSH_TC_NOT_APPLICABLE
  340. * if not (e.g. flush request, control packet).
  341. */
  342. static inline u32 ssam_trace_get_request_tc(const struct ssh_packet *p)
  343. @@ -232,8 +265,18 @@ static inline u32 ssam_trace_get_request_tc(const struct ssh_packet *p)
  344. { SSAM_RQID_NOT_APPLICABLE, "N/A" } \
  345. )
  346. -#define ssam_show_ssh_tc(rqid) \
  347. - __print_symbolic(rqid, \
  348. +#define ssam_show_ssh_tid(tid) \
  349. + __print_symbolic(tid, \
  350. + { SSAM_SSH_TID_NOT_APPLICABLE, "N/A" }, \
  351. + { SSAM_SSH_TID_HOST, "Host" }, \
  352. + { SSAM_SSH_TID_SAM, "SAM" }, \
  353. + { SSAM_SSH_TID_KIP, "KIP" }, \
  354. + { SSAM_SSH_TID_DEBUG, "Debug" }, \
  355. + { SSAM_SSH_TID_SURFLINK, "SurfLink" } \
  356. + )
  357. +
  358. +#define ssam_show_ssh_tc(tc) \
  359. + __print_symbolic(tc, \
  360. { SSAM_SSH_TC_NOT_APPLICABLE, "N/A" }, \
  361. { SSAM_SSH_TC_SAM, "SAM" }, \
  362. { SSAM_SSH_TC_BAT, "BAT" }, \
  363. @@ -313,6 +356,8 @@ DECLARE_EVENT_CLASS(ssam_command_class,
  364. TP_STRUCT__entry(
  365. __field(u16, rqid)
  366. __field(u16, len)
  367. + __field(u8, tid)
  368. + __field(u8, sid)
  369. __field(u8, tc)
  370. __field(u8, cid)
  371. __field(u8, iid)
  372. @@ -320,14 +365,18 @@ DECLARE_EVENT_CLASS(ssam_command_class,
  373. TP_fast_assign(
  374. __entry->rqid = get_unaligned_le16(&cmd->rqid);
  375. + __entry->tid = cmd->tid;
  376. + __entry->sid = cmd->sid;
  377. __entry->tc = cmd->tc;
  378. __entry->cid = cmd->cid;
  379. __entry->iid = cmd->iid;
  380. __entry->len = len;
  381. ),
  382. - TP_printk("rqid=%#06x, tc=%s, cid=%#04x, iid=%#04x, len=%u",
  383. + TP_printk("rqid=%#06x, tid=%s, sid=%s, tc=%s, cid=%#04x, iid=%#04x, len=%u",
  384. __entry->rqid,
  385. + ssam_show_ssh_tid(__entry->tid),
  386. + ssam_show_ssh_tid(__entry->sid),
  387. ssam_show_ssh_tc(__entry->tc),
  388. __entry->cid,
  389. __entry->iid,
  390. @@ -430,6 +479,8 @@ DECLARE_EVENT_CLASS(ssam_request_class,
  391. __field(u8, tc)
  392. __field(u16, cid)
  393. __field(u16, iid)
  394. + __field(u8, tid)
  395. + __field(u8, sid)
  396. ),
  397. TP_fast_assign(
  398. @@ -439,16 +490,20 @@ DECLARE_EVENT_CLASS(ssam_request_class,
  399. __entry->state = READ_ONCE(request->state);
  400. __entry->rqid = ssam_trace_get_request_id(p);
  401. ssam_trace_ptr_uid(p, __entry->uid);
  402. + __entry->tid = ssam_trace_get_request_tid(p);
  403. + __entry->sid = ssam_trace_get_request_sid(p);
  404. __entry->tc = ssam_trace_get_request_tc(p);
  405. __entry->cid = ssam_trace_get_command_field_u8(p, cid);
  406. __entry->iid = ssam_trace_get_command_field_u8(p, iid);
  407. ),
  408. - TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tc=%s, cid=%s, iid=%s",
  409. + TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tid=%s, sid=%s, tc=%s, cid=%s, iid=%s",
  410. __entry->uid,
  411. ssam_show_request_id(__entry->rqid),
  412. ssam_show_request_type(__entry->state),
  413. ssam_show_request_state(__entry->state),
  414. + ssam_show_ssh_tid(__entry->tid),
  415. + ssam_show_ssh_tid(__entry->sid),
  416. ssam_show_ssh_tc(__entry->tc),
  417. ssam_show_generic_u8_field(__entry->cid),
  418. ssam_show_generic_u8_field(__entry->iid)
  419. @@ -474,6 +529,8 @@ DECLARE_EVENT_CLASS(ssam_request_status_class,
  420. __field(u8, tc)
  421. __field(u16, cid)
  422. __field(u16, iid)
  423. + __field(u8, tid)
  424. + __field(u8, sid)
  425. ),
  426. TP_fast_assign(
  427. @@ -484,16 +541,20 @@ DECLARE_EVENT_CLASS(ssam_request_status_class,
  428. __entry->rqid = ssam_trace_get_request_id(p);
  429. __entry->status = status;
  430. ssam_trace_ptr_uid(p, __entry->uid);
  431. + __entry->tid = ssam_trace_get_request_tid(p);
  432. + __entry->sid = ssam_trace_get_request_sid(p);
  433. __entry->tc = ssam_trace_get_request_tc(p);
  434. __entry->cid = ssam_trace_get_command_field_u8(p, cid);
  435. __entry->iid = ssam_trace_get_command_field_u8(p, iid);
  436. ),
  437. - TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tc=%s, cid=%s, iid=%s, status=%d",
  438. + TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tid=%s, sid=%s, tc=%s, cid=%s, iid=%s, status=%d",
  439. __entry->uid,
  440. ssam_show_request_id(__entry->rqid),
  441. ssam_show_request_type(__entry->state),
  442. ssam_show_request_state(__entry->state),
  443. + ssam_show_ssh_tid(__entry->tid),
  444. + ssam_show_ssh_tid(__entry->sid),
  445. ssam_show_ssh_tc(__entry->tc),
  446. ssam_show_generic_u8_field(__entry->cid),
  447. ssam_show_generic_u8_field(__entry->iid),
  448. --
  449. 2.43.0
  450. From 2c39117451ac4ff8c8cfbf8145d75476bb2049da Mon Sep 17 00:00:00 2001
  451. From: Maximilian Luz <luzmaximilian@gmail.com>
  452. Date: Fri, 2 Dec 2022 23:33:22 +0100
  453. Subject: [PATCH] platform/surface: aggregator_hub: Use target-ID enum instead
  454. of hard-coding values
  455. Instead of hard-coding the target ID, use the respective enum
  456. ssam_ssh_tid value.
  457. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  458. Link: https://lore.kernel.org/r/20221202223327.690880-5-luzmaximilian@gmail.com
  459. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  460. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  461. Patchset: surface-sam
  462. ---
  463. drivers/platform/surface/surface_aggregator_hub.c | 4 ++--
  464. 1 file changed, 2 insertions(+), 2 deletions(-)
  465. diff --git a/drivers/platform/surface/surface_aggregator_hub.c b/drivers/platform/surface/surface_aggregator_hub.c
  466. index 43061514be382..62f27cdb6ca8f 100644
  467. --- a/drivers/platform/surface/surface_aggregator_hub.c
  468. +++ b/drivers/platform/surface/surface_aggregator_hub.c
  469. @@ -214,7 +214,7 @@ static void ssam_hub_remove(struct ssam_device *sdev)
  470. SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_query_opmode, u8, {
  471. .target_category = SSAM_SSH_TC_BAS,
  472. - .target_id = 0x01,
  473. + .target_id = SSAM_SSH_TID_SAM,
  474. .command_id = 0x0d,
  475. .instance_id = 0x00,
  476. });
  477. @@ -292,7 +292,7 @@ static const struct ssam_hub_desc base_hub = {
  478. SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_query_state, u8, {
  479. .target_category = SSAM_SSH_TC_KIP,
  480. - .target_id = 0x01,
  481. + .target_id = SSAM_SSH_TID_SAM,
  482. .command_id = 0x2c,
  483. .instance_id = 0x00,
  484. });
  485. --
  486. 2.43.0
  487. From 557688c8fb79ccab9336084de3e42256bc0bba71 Mon Sep 17 00:00:00 2001
  488. From: Maximilian Luz <luzmaximilian@gmail.com>
  489. Date: Fri, 2 Dec 2022 23:33:23 +0100
  490. Subject: [PATCH] platform/surface: aggregator_tabletsw: Use target-ID enum
  491. instead of hard-coding values
  492. Instead of hard-coding the target ID, use the respective enum
  493. ssam_ssh_tid value.
  494. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  495. Link: https://lore.kernel.org/r/20221202223327.690880-6-luzmaximilian@gmail.com
  496. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  497. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  498. Patchset: surface-sam
  499. ---
  500. drivers/platform/surface/surface_aggregator_tabletsw.c | 6 +++---
  501. 1 file changed, 3 insertions(+), 3 deletions(-)
  502. diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c
  503. index af8b547cffdc6..c8ecbdbb516c5 100644
  504. --- a/drivers/platform/surface/surface_aggregator_tabletsw.c
  505. +++ b/drivers/platform/surface/surface_aggregator_tabletsw.c
  506. @@ -252,7 +252,7 @@ static bool ssam_kip_cover_state_is_tablet_mode(struct ssam_tablet_sw *sw, u32 s
  507. SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_get_cover_state, u8, {
  508. .target_category = SSAM_SSH_TC_KIP,
  509. - .target_id = 0x01,
  510. + .target_id = SSAM_SSH_TID_SAM,
  511. .command_id = 0x1d,
  512. .instance_id = 0x00,
  513. });
  514. @@ -376,7 +376,7 @@ static int ssam_pos_get_sources_list(struct ssam_tablet_sw *sw, struct ssam_sour
  515. int status;
  516. rqst.target_category = SSAM_SSH_TC_POS;
  517. - rqst.target_id = 0x01;
  518. + rqst.target_id = SSAM_SSH_TID_SAM;
  519. rqst.command_id = 0x01;
  520. rqst.instance_id = 0x00;
  521. rqst.flags = SSAM_REQUEST_HAS_RESPONSE;
  522. @@ -435,7 +435,7 @@ static int ssam_pos_get_source(struct ssam_tablet_sw *sw, u32 *source_id)
  523. SSAM_DEFINE_SYNC_REQUEST_WR(__ssam_pos_get_posture_for_source, __le32, __le32, {
  524. .target_category = SSAM_SSH_TC_POS,
  525. - .target_id = 0x01,
  526. + .target_id = SSAM_SSH_TID_SAM,
  527. .command_id = 0x02,
  528. .instance_id = 0x00,
  529. });
  530. --
  531. 2.43.0
  532. From fde3b7b3d4239a851fcbd2f0c6bf2cc52d8f8b0f Mon Sep 17 00:00:00 2001
  533. From: Maximilian Luz <luzmaximilian@gmail.com>
  534. Date: Fri, 2 Dec 2022 23:33:24 +0100
  535. Subject: [PATCH] platform/surface: dtx: Use target-ID enum instead of
  536. hard-coding values
  537. Instead of hard-coding the target ID, use the respective enum
  538. ssam_ssh_tid value.
  539. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  540. Link: https://lore.kernel.org/r/20221202223327.690880-7-luzmaximilian@gmail.com
  541. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  542. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  543. Patchset: surface-sam
  544. ---
  545. drivers/platform/surface/surface_dtx.c | 18 +++++++++---------
  546. 1 file changed, 9 insertions(+), 9 deletions(-)
  547. diff --git a/drivers/platform/surface/surface_dtx.c b/drivers/platform/surface/surface_dtx.c
  548. index ed36944467f9f..0de76a784a35f 100644
  549. --- a/drivers/platform/surface/surface_dtx.c
  550. +++ b/drivers/platform/surface/surface_dtx.c
  551. @@ -71,63 +71,63 @@ static_assert(sizeof(struct ssam_bas_base_info) == 2);
  552. SSAM_DEFINE_SYNC_REQUEST_N(ssam_bas_latch_lock, {
  553. .target_category = SSAM_SSH_TC_BAS,
  554. - .target_id = 0x01,
  555. + .target_id = SSAM_SSH_TID_SAM,
  556. .command_id = 0x06,
  557. .instance_id = 0x00,
  558. });
  559. SSAM_DEFINE_SYNC_REQUEST_N(ssam_bas_latch_unlock, {
  560. .target_category = SSAM_SSH_TC_BAS,
  561. - .target_id = 0x01,
  562. + .target_id = SSAM_SSH_TID_SAM,
  563. .command_id = 0x07,
  564. .instance_id = 0x00,
  565. });
  566. SSAM_DEFINE_SYNC_REQUEST_N(ssam_bas_latch_request, {
  567. .target_category = SSAM_SSH_TC_BAS,
  568. - .target_id = 0x01,
  569. + .target_id = SSAM_SSH_TID_SAM,
  570. .command_id = 0x08,
  571. .instance_id = 0x00,
  572. });
  573. SSAM_DEFINE_SYNC_REQUEST_N(ssam_bas_latch_confirm, {
  574. .target_category = SSAM_SSH_TC_BAS,
  575. - .target_id = 0x01,
  576. + .target_id = SSAM_SSH_TID_SAM,
  577. .command_id = 0x09,
  578. .instance_id = 0x00,
  579. });
  580. SSAM_DEFINE_SYNC_REQUEST_N(ssam_bas_latch_heartbeat, {
  581. .target_category = SSAM_SSH_TC_BAS,
  582. - .target_id = 0x01,
  583. + .target_id = SSAM_SSH_TID_SAM,
  584. .command_id = 0x0a,
  585. .instance_id = 0x00,
  586. });
  587. SSAM_DEFINE_SYNC_REQUEST_N(ssam_bas_latch_cancel, {
  588. .target_category = SSAM_SSH_TC_BAS,
  589. - .target_id = 0x01,
  590. + .target_id = SSAM_SSH_TID_SAM,
  591. .command_id = 0x0b,
  592. .instance_id = 0x00,
  593. });
  594. SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_get_base, struct ssam_bas_base_info, {
  595. .target_category = SSAM_SSH_TC_BAS,
  596. - .target_id = 0x01,
  597. + .target_id = SSAM_SSH_TID_SAM,
  598. .command_id = 0x0c,
  599. .instance_id = 0x00,
  600. });
  601. SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_get_device_mode, u8, {
  602. .target_category = SSAM_SSH_TC_BAS,
  603. - .target_id = 0x01,
  604. + .target_id = SSAM_SSH_TID_SAM,
  605. .command_id = 0x0d,
  606. .instance_id = 0x00,
  607. });
  608. SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_get_latch_status, u8, {
  609. .target_category = SSAM_SSH_TC_BAS,
  610. - .target_id = 0x01,
  611. + .target_id = SSAM_SSH_TID_SAM,
  612. .command_id = 0x11,
  613. .instance_id = 0x00,
  614. });
  615. --
  616. 2.43.0
  617. From 62cba06b475782a9d876e239b7a4a9e7320fabda Mon Sep 17 00:00:00 2001
  618. From: Maximilian Luz <luzmaximilian@gmail.com>
  619. Date: Fri, 2 Dec 2022 23:33:25 +0100
  620. Subject: [PATCH] HID: surface-hid: Use target-ID enum instead of hard-coding
  621. values
  622. Instead of hard-coding the target ID, use the respective enum
  623. ssam_ssh_tid value.
  624. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  625. Link: https://lore.kernel.org/r/20221202223327.690880-8-luzmaximilian@gmail.com
  626. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  627. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  628. Patchset: surface-sam
  629. ---
  630. drivers/hid/surface-hid/surface_kbd.c | 2 +-
  631. 1 file changed, 1 insertion(+), 1 deletion(-)
  632. diff --git a/drivers/hid/surface-hid/surface_kbd.c b/drivers/hid/surface-hid/surface_kbd.c
  633. index 0635341bc5174..42933bf3e925f 100644
  634. --- a/drivers/hid/surface-hid/surface_kbd.c
  635. +++ b/drivers/hid/surface-hid/surface_kbd.c
  636. @@ -250,7 +250,7 @@ static int surface_kbd_probe(struct platform_device *pdev)
  637. shid->uid.domain = SSAM_DOMAIN_SERIALHUB;
  638. shid->uid.category = SSAM_SSH_TC_KBD;
  639. - shid->uid.target = 2;
  640. + shid->uid.target = SSAM_SSH_TID_KIP;
  641. shid->uid.instance = 0;
  642. shid->uid.function = 0;
  643. --
  644. 2.43.0
  645. From b652f52830fed086d0d8c1a16d7aa8e48743188d Mon Sep 17 00:00:00 2001
  646. From: Maximilian Luz <luzmaximilian@gmail.com>
  647. Date: Fri, 2 Dec 2022 23:33:26 +0100
  648. Subject: [PATCH] platform/surface: aggregator: Enforce use of target-ID enum
  649. in device ID macros
  650. Similar to the target category (TC), the target ID (TID) can be one
  651. value out of a small number of choices, given in enum ssam_ssh_tid.
  652. In the device ID macros, SSAM_SDEV() and SSAM_VDEV() we already use text
  653. expansion to, both, remove some textual clutter for the target category
  654. values and enforce that the value belongs to the known set. Now that we
  655. know the names for the target IDs, use the same trick for them as well.
  656. Also rename the SSAM_ANY_x macros to SSAM_SSH_x_ANY to better fit in.
  657. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  658. Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
  659. Link: https://lore.kernel.org/r/20221202223327.690880-9-luzmaximilian@gmail.com
  660. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  661. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  662. Patchset: surface-sam
  663. ---
  664. drivers/hid/surface-hid/surface_hid.c | 2 +-
  665. .../platform/surface/surface_aggregator_hub.c | 4 +-
  666. .../surface/surface_aggregator_tabletsw.c | 4 +-
  667. drivers/platform/surface/surface_dtx.c | 2 +-
  668. .../surface/surface_platform_profile.c | 2 +-
  669. drivers/power/supply/surface_battery.c | 4 +-
  670. drivers/power/supply/surface_charger.c | 2 +-
  671. include/linux/surface_aggregator/device.h | 50 +++++++++----------
  672. 8 files changed, 35 insertions(+), 35 deletions(-)
  673. diff --git a/drivers/hid/surface-hid/surface_hid.c b/drivers/hid/surface-hid/surface_hid.c
  674. index d4aa8c81903ae..aa80d83a83d1b 100644
  675. --- a/drivers/hid/surface-hid/surface_hid.c
  676. +++ b/drivers/hid/surface-hid/surface_hid.c
  677. @@ -230,7 +230,7 @@ static void surface_hid_remove(struct ssam_device *sdev)
  678. }
  679. static const struct ssam_device_id surface_hid_match[] = {
  680. - { SSAM_SDEV(HID, SSAM_ANY_TID, SSAM_ANY_IID, 0x00) },
  681. + { SSAM_SDEV(HID, ANY, SSAM_SSH_IID_ANY, 0x00) },
  682. { },
  683. };
  684. MODULE_DEVICE_TABLE(ssam, surface_hid_match);
  685. diff --git a/drivers/platform/surface/surface_aggregator_hub.c b/drivers/platform/surface/surface_aggregator_hub.c
  686. index 62f27cdb6ca8f..6abd1efe20883 100644
  687. --- a/drivers/platform/surface/surface_aggregator_hub.c
  688. +++ b/drivers/platform/surface/surface_aggregator_hub.c
  689. @@ -348,8 +348,8 @@ static const struct ssam_hub_desc kip_hub = {
  690. /* -- Driver registration. -------------------------------------------------- */
  691. static const struct ssam_device_id ssam_hub_match[] = {
  692. - { SSAM_VDEV(HUB, 0x01, SSAM_SSH_TC_KIP, 0x00), (unsigned long)&kip_hub },
  693. - { SSAM_VDEV(HUB, 0x02, SSAM_SSH_TC_BAS, 0x00), (unsigned long)&base_hub },
  694. + { SSAM_VDEV(HUB, SAM, SSAM_SSH_TC_KIP, 0x00), (unsigned long)&kip_hub },
  695. + { SSAM_VDEV(HUB, KIP, SSAM_SSH_TC_BAS, 0x00), (unsigned long)&base_hub },
  696. { }
  697. };
  698. MODULE_DEVICE_TABLE(ssam, ssam_hub_match);
  699. diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c
  700. index c8ecbdbb516c5..6917e86062bc8 100644
  701. --- a/drivers/platform/surface/surface_aggregator_tabletsw.c
  702. +++ b/drivers/platform/surface/surface_aggregator_tabletsw.c
  703. @@ -515,8 +515,8 @@ static const struct ssam_tablet_sw_desc ssam_pos_sw_desc = {
  704. /* -- Driver registration. -------------------------------------------------- */
  705. static const struct ssam_device_id ssam_tablet_sw_match[] = {
  706. - { SSAM_SDEV(KIP, 0x01, 0x00, 0x01), (unsigned long)&ssam_kip_sw_desc },
  707. - { SSAM_SDEV(POS, 0x01, 0x00, 0x01), (unsigned long)&ssam_pos_sw_desc },
  708. + { SSAM_SDEV(KIP, SAM, 0x00, 0x01), (unsigned long)&ssam_kip_sw_desc },
  709. + { SSAM_SDEV(POS, SAM, 0x00, 0x01), (unsigned long)&ssam_pos_sw_desc },
  710. { },
  711. };
  712. MODULE_DEVICE_TABLE(ssam, ssam_tablet_sw_match);
  713. diff --git a/drivers/platform/surface/surface_dtx.c b/drivers/platform/surface/surface_dtx.c
  714. index 0de76a784a35f..30cbde278c599 100644
  715. --- a/drivers/platform/surface/surface_dtx.c
  716. +++ b/drivers/platform/surface/surface_dtx.c
  717. @@ -1214,7 +1214,7 @@ static void surface_dtx_ssam_remove(struct ssam_device *sdev)
  718. }
  719. static const struct ssam_device_id surface_dtx_ssam_match[] = {
  720. - { SSAM_SDEV(BAS, 0x01, 0x00, 0x00) },
  721. + { SSAM_SDEV(BAS, SAM, 0x00, 0x00) },
  722. { },
  723. };
  724. MODULE_DEVICE_TABLE(ssam, surface_dtx_ssam_match);
  725. diff --git a/drivers/platform/surface/surface_platform_profile.c b/drivers/platform/surface/surface_platform_profile.c
  726. index 37c761f577149..a5a3941b3f43a 100644
  727. --- a/drivers/platform/surface/surface_platform_profile.c
  728. +++ b/drivers/platform/surface/surface_platform_profile.c
  729. @@ -168,7 +168,7 @@ static void surface_platform_profile_remove(struct ssam_device *sdev)
  730. }
  731. static const struct ssam_device_id ssam_platform_profile_match[] = {
  732. - { SSAM_SDEV(TMP, 0x01, 0x00, 0x01) },
  733. + { SSAM_SDEV(TMP, SAM, 0x00, 0x01) },
  734. { },
  735. };
  736. MODULE_DEVICE_TABLE(ssam, ssam_platform_profile_match);
  737. diff --git a/drivers/power/supply/surface_battery.c b/drivers/power/supply/surface_battery.c
  738. index 540707882bb0a..19d2f8834e56d 100644
  739. --- a/drivers/power/supply/surface_battery.c
  740. +++ b/drivers/power/supply/surface_battery.c
  741. @@ -852,8 +852,8 @@ static const struct spwr_psy_properties spwr_psy_props_bat2_sb3 = {
  742. };
  743. static const struct ssam_device_id surface_battery_match[] = {
  744. - { SSAM_SDEV(BAT, 0x01, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat1 },
  745. - { SSAM_SDEV(BAT, 0x02, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat2_sb3 },
  746. + { SSAM_SDEV(BAT, SAM, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat1 },
  747. + { SSAM_SDEV(BAT, KIP, 0x01, 0x00), (unsigned long)&spwr_psy_props_bat2_sb3 },
  748. { },
  749. };
  750. MODULE_DEVICE_TABLE(ssam, surface_battery_match);
  751. diff --git a/drivers/power/supply/surface_charger.c b/drivers/power/supply/surface_charger.c
  752. index 59182d55742d0..cabdd8da12d08 100644
  753. --- a/drivers/power/supply/surface_charger.c
  754. +++ b/drivers/power/supply/surface_charger.c
  755. @@ -260,7 +260,7 @@ static const struct spwr_psy_properties spwr_psy_props_adp1 = {
  756. };
  757. static const struct ssam_device_id surface_ac_match[] = {
  758. - { SSAM_SDEV(BAT, 0x01, 0x01, 0x01), (unsigned long)&spwr_psy_props_adp1 },
  759. + { SSAM_SDEV(BAT, SAM, 0x01, 0x01), (unsigned long)&spwr_psy_props_adp1 },
  760. { },
  761. };
  762. MODULE_DEVICE_TABLE(ssam, surface_ac_match);
  763. diff --git a/include/linux/surface_aggregator/device.h b/include/linux/surface_aggregator/device.h
  764. index 46c45d1b63682..4da20b7a0ee5e 100644
  765. --- a/include/linux/surface_aggregator/device.h
  766. +++ b/include/linux/surface_aggregator/device.h
  767. @@ -68,9 +68,9 @@ struct ssam_device_uid {
  768. * match_flags member of the device ID structure. Do not use them directly
  769. * with struct ssam_device_id or struct ssam_device_uid.
  770. */
  771. -#define SSAM_ANY_TID 0xffff
  772. -#define SSAM_ANY_IID 0xffff
  773. -#define SSAM_ANY_FUN 0xffff
  774. +#define SSAM_SSH_TID_ANY 0xffff
  775. +#define SSAM_SSH_IID_ANY 0xffff
  776. +#define SSAM_SSH_FUN_ANY 0xffff
  777. /**
  778. * SSAM_DEVICE() - Initialize a &struct ssam_device_id with the given
  779. @@ -83,25 +83,25 @@ struct ssam_device_uid {
  780. *
  781. * Initializes a &struct ssam_device_id with the given parameters. See &struct
  782. * ssam_device_uid for details regarding the parameters. The special values
  783. - * %SSAM_ANY_TID, %SSAM_ANY_IID, and %SSAM_ANY_FUN can be used to specify that
  784. + * %SSAM_SSH_TID_ANY, %SSAM_SSH_IID_ANY, and %SSAM_SSH_FUN_ANY can be used to specify that
  785. * matching should ignore target ID, instance ID, and/or sub-function,
  786. * respectively. This macro initializes the ``match_flags`` field based on the
  787. * given parameters.
  788. *
  789. * Note: The parameters @d and @cat must be valid &u8 values, the parameters
  790. - * @tid, @iid, and @fun must be either valid &u8 values or %SSAM_ANY_TID,
  791. - * %SSAM_ANY_IID, or %SSAM_ANY_FUN, respectively. Other non-&u8 values are not
  792. + * @tid, @iid, and @fun must be either valid &u8 values or %SSAM_SSH_TID_ANY,
  793. + * %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values are not
  794. * allowed.
  795. */
  796. #define SSAM_DEVICE(d, cat, tid, iid, fun) \
  797. - .match_flags = (((tid) != SSAM_ANY_TID) ? SSAM_MATCH_TARGET : 0) \
  798. - | (((iid) != SSAM_ANY_IID) ? SSAM_MATCH_INSTANCE : 0) \
  799. - | (((fun) != SSAM_ANY_FUN) ? SSAM_MATCH_FUNCTION : 0), \
  800. + .match_flags = (((tid) != SSAM_SSH_TID_ANY) ? SSAM_MATCH_TARGET : 0) \
  801. + | (((iid) != SSAM_SSH_IID_ANY) ? SSAM_MATCH_INSTANCE : 0) \
  802. + | (((fun) != SSAM_SSH_FUN_ANY) ? SSAM_MATCH_FUNCTION : 0), \
  803. .domain = d, \
  804. .category = cat, \
  805. - .target = __builtin_choose_expr((tid) != SSAM_ANY_TID, (tid), 0), \
  806. - .instance = __builtin_choose_expr((iid) != SSAM_ANY_IID, (iid), 0), \
  807. - .function = __builtin_choose_expr((fun) != SSAM_ANY_FUN, (fun), 0)
  808. + .target = __builtin_choose_expr((tid) != SSAM_SSH_TID_ANY, (tid), 0), \
  809. + .instance = __builtin_choose_expr((iid) != SSAM_SSH_IID_ANY, (iid), 0), \
  810. + .function = __builtin_choose_expr((fun) != SSAM_SSH_FUN_ANY, (fun), 0)
  811. /**
  812. * SSAM_VDEV() - Initialize a &struct ssam_device_id as virtual device with
  813. @@ -113,18 +113,18 @@ struct ssam_device_uid {
  814. *
  815. * Initializes a &struct ssam_device_id with the given parameters in the
  816. * virtual domain. See &struct ssam_device_uid for details regarding the
  817. - * parameters. The special values %SSAM_ANY_TID, %SSAM_ANY_IID, and
  818. - * %SSAM_ANY_FUN can be used to specify that matching should ignore target ID,
  819. + * parameters. The special values %SSAM_SSH_TID_ANY, %SSAM_SSH_IID_ANY, and
  820. + * %SSAM_SSH_FUN_ANY can be used to specify that matching should ignore target ID,
  821. * instance ID, and/or sub-function, respectively. This macro initializes the
  822. * ``match_flags`` field based on the given parameters.
  823. *
  824. * Note: The parameter @cat must be a valid &u8 value, the parameters @tid,
  825. - * @iid, and @fun must be either valid &u8 values or %SSAM_ANY_TID,
  826. - * %SSAM_ANY_IID, or %SSAM_ANY_FUN, respectively. Other non-&u8 values are not
  827. + * @iid, and @fun must be either valid &u8 values or %SSAM_SSH_TID_ANY,
  828. + * %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values are not
  829. * allowed.
  830. */
  831. #define SSAM_VDEV(cat, tid, iid, fun) \
  832. - SSAM_DEVICE(SSAM_DOMAIN_VIRTUAL, SSAM_VIRTUAL_TC_##cat, tid, iid, fun)
  833. + SSAM_DEVICE(SSAM_DOMAIN_VIRTUAL, SSAM_VIRTUAL_TC_##cat, SSAM_SSH_TID_##tid, iid, fun)
  834. /**
  835. * SSAM_SDEV() - Initialize a &struct ssam_device_id as physical SSH device
  836. @@ -136,18 +136,18 @@ struct ssam_device_uid {
  837. *
  838. * Initializes a &struct ssam_device_id with the given parameters in the SSH
  839. * domain. See &struct ssam_device_uid for details regarding the parameters.
  840. - * The special values %SSAM_ANY_TID, %SSAM_ANY_IID, and %SSAM_ANY_FUN can be
  841. - * used to specify that matching should ignore target ID, instance ID, and/or
  842. - * sub-function, respectively. This macro initializes the ``match_flags``
  843. - * field based on the given parameters.
  844. + * The special values %SSAM_SSH_TID_ANY, %SSAM_SSH_IID_ANY, and
  845. + * %SSAM_SSH_FUN_ANY can be used to specify that matching should ignore target
  846. + * ID, instance ID, and/or sub-function, respectively. This macro initializes
  847. + * the ``match_flags`` field based on the given parameters.
  848. *
  849. * Note: The parameter @cat must be a valid &u8 value, the parameters @tid,
  850. - * @iid, and @fun must be either valid &u8 values or %SSAM_ANY_TID,
  851. - * %SSAM_ANY_IID, or %SSAM_ANY_FUN, respectively. Other non-&u8 values are not
  852. - * allowed.
  853. + * @iid, and @fun must be either valid &u8 values or %SSAM_SSH_TID_ANY,
  854. + * %SSAM_SSH_IID_ANY, or %SSAM_SSH_FUN_ANY, respectively. Other non-&u8 values
  855. + * are not allowed.
  856. */
  857. #define SSAM_SDEV(cat, tid, iid, fun) \
  858. - SSAM_DEVICE(SSAM_DOMAIN_SERIALHUB, SSAM_SSH_TC_##cat, tid, iid, fun)
  859. + SSAM_DEVICE(SSAM_DOMAIN_SERIALHUB, SSAM_SSH_TC_##cat, SSAM_SSH_TID_##tid, iid, fun)
  860. /*
  861. * enum ssam_device_flags - Flags for SSAM client devices.
  862. --
  863. 2.43.0
  864. From b16cc48e61fb290cbc81fd7e45d2a66770459e6a Mon Sep 17 00:00:00 2001
  865. From: Maximilian Luz <luzmaximilian@gmail.com>
  866. Date: Fri, 2 Dec 2022 23:33:27 +0100
  867. Subject: [PATCH] platform/surface: aggregator_registry: Fix target-ID of
  868. base-hub
  869. The target ID of the base hub is currently set to KIP (keyboard/
  870. peripherals). However, even though it manages such devices with the KIP
  871. target ID, the base hub itself is actually accessed via the SAM target
  872. ID. So set it accordingly.
  873. Note that the target ID of the hub can be chosen arbitrarily and does
  874. not directly correspond to any physical or virtual component of the EC.
  875. This change is only a code improvement intended for consistency and
  876. clarity, it does not fix an actual bug.
  877. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  878. Link: https://lore.kernel.org/r/20221202223327.690880-10-luzmaximilian@gmail.com
  879. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  880. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  881. Patchset: surface-sam
  882. ---
  883. drivers/platform/surface/surface_aggregator_hub.c | 2 +-
  884. drivers/platform/surface/surface_aggregator_registry.c | 2 +-
  885. 2 files changed, 2 insertions(+), 2 deletions(-)
  886. diff --git a/drivers/platform/surface/surface_aggregator_hub.c b/drivers/platform/surface/surface_aggregator_hub.c
  887. index 6abd1efe20883..8b8b80228c147 100644
  888. --- a/drivers/platform/surface/surface_aggregator_hub.c
  889. +++ b/drivers/platform/surface/surface_aggregator_hub.c
  890. @@ -349,7 +349,7 @@ static const struct ssam_hub_desc kip_hub = {
  891. static const struct ssam_device_id ssam_hub_match[] = {
  892. { SSAM_VDEV(HUB, SAM, SSAM_SSH_TC_KIP, 0x00), (unsigned long)&kip_hub },
  893. - { SSAM_VDEV(HUB, KIP, SSAM_SSH_TC_BAS, 0x00), (unsigned long)&base_hub },
  894. + { SSAM_VDEV(HUB, SAM, SSAM_SSH_TC_BAS, 0x00), (unsigned long)&base_hub },
  895. { }
  896. };
  897. MODULE_DEVICE_TABLE(ssam, ssam_hub_match);
  898. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  899. index 023f126121d7d..296f72d52e6a6 100644
  900. --- a/drivers/platform/surface/surface_aggregator_registry.c
  901. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  902. @@ -46,7 +46,7 @@ static const struct software_node ssam_node_hub_kip = {
  903. /* Base device hub (devices attached to Surface Book 3 base). */
  904. static const struct software_node ssam_node_hub_base = {
  905. - .name = "ssam:00:00:02:11:00",
  906. + .name = "ssam:00:00:01:11:00",
  907. .parent = &ssam_node_root,
  908. };
  909. --
  910. 2.43.0
  911. From f7eb5245e8e253df7ec399d45b5c44d47904c01b Mon Sep 17 00:00:00 2001
  912. From: Maximilian Luz <luzmaximilian@gmail.com>
  913. Date: Tue, 20 Dec 2022 18:56:08 +0100
  914. Subject: [PATCH] platform/surface: aggregator: Rename top-level request
  915. functions to avoid ambiguities
  916. We currently have a struct ssam_request_sync and a function
  917. ssam_request_sync(). While this is valid C, there are some downsides to
  918. it.
  919. One of these is that current Sphinx versions (>= 3.0) cannot
  920. disambiguate between the two (see disucssion and pull request linked
  921. below). It instead emits a "WARNING: Duplicate C declaration" and links
  922. for the struct and function in the resulting documentation link to the
  923. same entry (i.e. both to either function or struct documentation)
  924. instead of their respective own entries.
  925. While we could just ignore that and wait for a fix, there's also a point
  926. to be made that the current naming can be somewhat confusing when
  927. searching (e.g. via grep) or trying to understand the levels of
  928. abstraction at play:
  929. We currently have struct ssam_request_sync and associated functions
  930. ssam_request_sync_[alloc|free|init|wait|...]() operating on this struct.
  931. However, function ssam_request_sync() is one abstraction level above
  932. this. Similarly, ssam_request_sync_with_buffer() is not a function
  933. operating on struct ssam_request_sync, but rather a sibling to
  934. ssam_request_sync(), both using the struct under the hood.
  935. Therefore, rename the top level request functions:
  936. ssam_request_sync() -> ssam_request_do_sync()
  937. ssam_request_sync_with_buffer() -> ssam_request_do_sync_with_buffer()
  938. ssam_request_sync_onstack() -> ssam_request_do_sync_onstack()
  939. Link: https://lore.kernel.org/all/085e0ada65c11da9303d07e70c510dc45f21315b.1656756450.git.mchehab@kernel.org/
  940. Link: https://github.com/sphinx-doc/sphinx/pull/8313
  941. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  942. Link: https://lore.kernel.org/r/20221220175608.1436273-2-luzmaximilian@gmail.com
  943. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  944. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  945. Patchset: surface-sam
  946. ---
  947. .../driver-api/surface_aggregator/client.rst | 8 +--
  948. drivers/hid/surface-hid/surface_hid.c | 6 +-
  949. drivers/hid/surface-hid/surface_kbd.c | 6 +-
  950. drivers/platform/surface/aggregator/bus.c | 6 +-
  951. .../platform/surface/aggregator/controller.c | 32 +++++------
  952. .../platform/surface/surface_acpi_notify.c | 2 +-
  953. .../surface/surface_aggregator_cdev.c | 6 +-
  954. .../surface/surface_aggregator_tabletsw.c | 2 +-
  955. include/linux/surface_aggregator/controller.h | 56 +++++++++----------
  956. include/linux/surface_aggregator/device.h | 8 +--
  957. 10 files changed, 66 insertions(+), 66 deletions(-)
  958. diff --git a/Documentation/driver-api/surface_aggregator/client.rst b/Documentation/driver-api/surface_aggregator/client.rst
  959. index 9d7411223a848..e100ab0a24cc4 100644
  960. --- a/Documentation/driver-api/surface_aggregator/client.rst
  961. +++ b/Documentation/driver-api/surface_aggregator/client.rst
  962. @@ -19,7 +19,7 @@
  963. .. |ssam_notifier_unregister| replace:: :c:func:`ssam_notifier_unregister`
  964. .. |ssam_device_notifier_register| replace:: :c:func:`ssam_device_notifier_register`
  965. .. |ssam_device_notifier_unregister| replace:: :c:func:`ssam_device_notifier_unregister`
  966. -.. |ssam_request_sync| replace:: :c:func:`ssam_request_sync`
  967. +.. |ssam_request_do_sync| replace:: :c:func:`ssam_request_do_sync`
  968. .. |ssam_event_mask| replace:: :c:type:`enum ssam_event_mask <ssam_event_mask>`
  969. @@ -209,12 +209,12 @@ data received from it is converted from little-endian to host endianness.
  970. * with the SSAM_REQUEST_HAS_RESPONSE flag set in the specification
  971. * above.
  972. */
  973. - status = ssam_request_sync(ctrl, &rqst, &resp);
  974. + status = ssam_request_do_sync(ctrl, &rqst, &resp);
  975. /*
  976. * Alternatively use
  977. *
  978. - * ssam_request_sync_onstack(ctrl, &rqst, &resp, sizeof(arg_le));
  979. + * ssam_request_do_sync_onstack(ctrl, &rqst, &resp, sizeof(arg_le));
  980. *
  981. * to perform the request, allocating the message buffer directly
  982. * on the stack as opposed to allocation via kzalloc().
  983. @@ -230,7 +230,7 @@ data received from it is converted from little-endian to host endianness.
  984. return status;
  985. }
  986. -Note that |ssam_request_sync| in its essence is a wrapper over lower-level
  987. +Note that |ssam_request_do_sync| in its essence is a wrapper over lower-level
  988. request primitives, which may also be used to perform requests. Refer to its
  989. implementation and documentation for more details.
  990. diff --git a/drivers/hid/surface-hid/surface_hid.c b/drivers/hid/surface-hid/surface_hid.c
  991. index aa80d83a83d1b..61e5814b0ad7d 100644
  992. --- a/drivers/hid/surface-hid/surface_hid.c
  993. +++ b/drivers/hid/surface-hid/surface_hid.c
  994. @@ -80,7 +80,7 @@ static int ssam_hid_get_descriptor(struct surface_hid_device *shid, u8 entry, u8
  995. rsp.length = 0;
  996. - status = ssam_retry(ssam_request_sync_onstack, shid->ctrl, &rqst, &rsp,
  997. + status = ssam_retry(ssam_request_do_sync_onstack, shid->ctrl, &rqst, &rsp,
  998. sizeof(*slice));
  999. if (status)
  1000. return status;
  1001. @@ -131,7 +131,7 @@ static int ssam_hid_set_raw_report(struct surface_hid_device *shid, u8 rprt_id,
  1002. buf[0] = rprt_id;
  1003. - return ssam_retry(ssam_request_sync, shid->ctrl, &rqst, NULL);
  1004. + return ssam_retry(ssam_request_do_sync, shid->ctrl, &rqst, NULL);
  1005. }
  1006. static int ssam_hid_get_raw_report(struct surface_hid_device *shid, u8 rprt_id, u8 *buf, size_t len)
  1007. @@ -151,7 +151,7 @@ static int ssam_hid_get_raw_report(struct surface_hid_device *shid, u8 rprt_id,
  1008. rsp.length = 0;
  1009. rsp.pointer = buf;
  1010. - return ssam_retry(ssam_request_sync_onstack, shid->ctrl, &rqst, &rsp, sizeof(rprt_id));
  1011. + return ssam_retry(ssam_request_do_sync_onstack, shid->ctrl, &rqst, &rsp, sizeof(rprt_id));
  1012. }
  1013. static u32 ssam_hid_event_fn(struct ssam_event_notifier *nf, const struct ssam_event *event)
  1014. diff --git a/drivers/hid/surface-hid/surface_kbd.c b/drivers/hid/surface-hid/surface_kbd.c
  1015. index 42933bf3e925f..4fbce201db6a1 100644
  1016. --- a/drivers/hid/surface-hid/surface_kbd.c
  1017. +++ b/drivers/hid/surface-hid/surface_kbd.c
  1018. @@ -49,7 +49,7 @@ static int ssam_kbd_get_descriptor(struct surface_hid_device *shid, u8 entry, u8
  1019. rsp.length = 0;
  1020. rsp.pointer = buf;
  1021. - status = ssam_retry(ssam_request_sync_onstack, shid->ctrl, &rqst, &rsp, sizeof(entry));
  1022. + status = ssam_retry(ssam_request_do_sync_onstack, shid->ctrl, &rqst, &rsp, sizeof(entry));
  1023. if (status)
  1024. return status;
  1025. @@ -75,7 +75,7 @@ static int ssam_kbd_set_caps_led(struct surface_hid_device *shid, bool value)
  1026. rqst.length = sizeof(value_u8);
  1027. rqst.payload = &value_u8;
  1028. - return ssam_retry(ssam_request_sync_onstack, shid->ctrl, &rqst, NULL, sizeof(value_u8));
  1029. + return ssam_retry(ssam_request_do_sync_onstack, shid->ctrl, &rqst, NULL, sizeof(value_u8));
  1030. }
  1031. static int ssam_kbd_get_feature_report(struct surface_hid_device *shid, u8 *buf, size_t len)
  1032. @@ -97,7 +97,7 @@ static int ssam_kbd_get_feature_report(struct surface_hid_device *shid, u8 *buf,
  1033. rsp.length = 0;
  1034. rsp.pointer = buf;
  1035. - status = ssam_retry(ssam_request_sync_onstack, shid->ctrl, &rqst, &rsp, sizeof(payload));
  1036. + status = ssam_retry(ssam_request_do_sync_onstack, shid->ctrl, &rqst, &rsp, sizeof(payload));
  1037. if (status)
  1038. return status;
  1039. diff --git a/drivers/platform/surface/aggregator/bus.c b/drivers/platform/surface/aggregator/bus.c
  1040. index b501a79f2a08a..da0baba5ed51f 100644
  1041. --- a/drivers/platform/surface/aggregator/bus.c
  1042. +++ b/drivers/platform/surface/aggregator/bus.c
  1043. @@ -136,9 +136,9 @@ int ssam_device_add(struct ssam_device *sdev)
  1044. * is always valid and can be used for requests as long as the client
  1045. * device we add here is registered as child under it. This essentially
  1046. * guarantees that the client driver can always expect the preconditions
  1047. - * for functions like ssam_request_sync (controller has to be started
  1048. - * and is not suspended) to hold and thus does not have to check for
  1049. - * them.
  1050. + * for functions like ssam_request_do_sync() (controller has to be
  1051. + * started and is not suspended) to hold and thus does not have to check
  1052. + * for them.
  1053. *
  1054. * Note that for this to work, the controller has to be a parent device.
  1055. * If it is not a direct parent, care has to be taken that the device is
  1056. diff --git a/drivers/platform/surface/aggregator/controller.c b/drivers/platform/surface/aggregator/controller.c
  1057. index cb86760622762..7fc602e01487d 100644
  1058. --- a/drivers/platform/surface/aggregator/controller.c
  1059. +++ b/drivers/platform/surface/aggregator/controller.c
  1060. @@ -1674,7 +1674,7 @@ int ssam_request_sync_submit(struct ssam_controller *ctrl,
  1061. EXPORT_SYMBOL_GPL(ssam_request_sync_submit);
  1062. /**
  1063. - * ssam_request_sync() - Execute a synchronous request.
  1064. + * ssam_request_do_sync() - Execute a synchronous request.
  1065. * @ctrl: The controller via which the request will be submitted.
  1066. * @spec: The request specification and payload.
  1067. * @rsp: The response buffer.
  1068. @@ -1686,9 +1686,9 @@ EXPORT_SYMBOL_GPL(ssam_request_sync_submit);
  1069. *
  1070. * Return: Returns the status of the request or any failure during setup.
  1071. */
  1072. -int ssam_request_sync(struct ssam_controller *ctrl,
  1073. - const struct ssam_request *spec,
  1074. - struct ssam_response *rsp)
  1075. +int ssam_request_do_sync(struct ssam_controller *ctrl,
  1076. + const struct ssam_request *spec,
  1077. + struct ssam_response *rsp)
  1078. {
  1079. struct ssam_request_sync *rqst;
  1080. struct ssam_span buf;
  1081. @@ -1722,10 +1722,10 @@ int ssam_request_sync(struct ssam_controller *ctrl,
  1082. ssam_request_sync_free(rqst);
  1083. return status;
  1084. }
  1085. -EXPORT_SYMBOL_GPL(ssam_request_sync);
  1086. +EXPORT_SYMBOL_GPL(ssam_request_do_sync);
  1087. /**
  1088. - * ssam_request_sync_with_buffer() - Execute a synchronous request with the
  1089. + * ssam_request_do_sync_with_buffer() - Execute a synchronous request with the
  1090. * provided buffer as back-end for the message buffer.
  1091. * @ctrl: The controller via which the request will be submitted.
  1092. * @spec: The request specification and payload.
  1093. @@ -1738,17 +1738,17 @@ EXPORT_SYMBOL_GPL(ssam_request_sync);
  1094. * SSH_COMMAND_MESSAGE_LENGTH() macro can be used to compute the required
  1095. * message buffer size.
  1096. *
  1097. - * This function does essentially the same as ssam_request_sync(), but instead
  1098. - * of dynamically allocating the request and message data buffer, it uses the
  1099. - * provided message data buffer and stores the (small) request struct on the
  1100. - * heap.
  1101. + * This function does essentially the same as ssam_request_do_sync(), but
  1102. + * instead of dynamically allocating the request and message data buffer, it
  1103. + * uses the provided message data buffer and stores the (small) request struct
  1104. + * on the heap.
  1105. *
  1106. * Return: Returns the status of the request or any failure during setup.
  1107. */
  1108. -int ssam_request_sync_with_buffer(struct ssam_controller *ctrl,
  1109. - const struct ssam_request *spec,
  1110. - struct ssam_response *rsp,
  1111. - struct ssam_span *buf)
  1112. +int ssam_request_do_sync_with_buffer(struct ssam_controller *ctrl,
  1113. + const struct ssam_request *spec,
  1114. + struct ssam_response *rsp,
  1115. + struct ssam_span *buf)
  1116. {
  1117. struct ssam_request_sync rqst;
  1118. ssize_t len;
  1119. @@ -1772,7 +1772,7 @@ int ssam_request_sync_with_buffer(struct ssam_controller *ctrl,
  1120. return status;
  1121. }
  1122. -EXPORT_SYMBOL_GPL(ssam_request_sync_with_buffer);
  1123. +EXPORT_SYMBOL_GPL(ssam_request_do_sync_with_buffer);
  1124. /* -- Internal SAM requests. ------------------------------------------------ */
  1125. @@ -1864,7 +1864,7 @@ static int __ssam_ssh_event_request(struct ssam_controller *ctrl,
  1126. result.length = 0;
  1127. result.pointer = &buf;
  1128. - status = ssam_retry(ssam_request_sync_onstack, ctrl, &rqst, &result,
  1129. + status = ssam_retry(ssam_request_do_sync_onstack, ctrl, &rqst, &result,
  1130. sizeof(params));
  1131. return status < 0 ? status : buf;
  1132. diff --git a/drivers/platform/surface/surface_acpi_notify.c b/drivers/platform/surface/surface_acpi_notify.c
  1133. index 50500e562963d..897cdd9c3aae8 100644
  1134. --- a/drivers/platform/surface/surface_acpi_notify.c
  1135. +++ b/drivers/platform/surface/surface_acpi_notify.c
  1136. @@ -590,7 +590,7 @@ static acpi_status san_rqst(struct san_data *d, struct gsb_buffer *buffer)
  1137. return san_rqst_fixup_suspended(d, &rqst, buffer);
  1138. }
  1139. - status = __ssam_retry(ssam_request_sync_onstack, SAN_REQUEST_NUM_TRIES,
  1140. + status = __ssam_retry(ssam_request_do_sync_onstack, SAN_REQUEST_NUM_TRIES,
  1141. d->ctrl, &rqst, &rsp, SAN_GSB_MAX_RQSX_PAYLOAD);
  1142. if (!status) {
  1143. diff --git a/drivers/platform/surface/surface_aggregator_cdev.c b/drivers/platform/surface/surface_aggregator_cdev.c
  1144. index 492c82e691827..07f0ed658369b 100644
  1145. --- a/drivers/platform/surface/surface_aggregator_cdev.c
  1146. +++ b/drivers/platform/surface/surface_aggregator_cdev.c
  1147. @@ -302,8 +302,8 @@ static long ssam_cdev_request(struct ssam_cdev_client *client, struct ssam_cdev_
  1148. * theoretical maximum (SSH_COMMAND_MAX_PAYLOAD_SIZE) of the
  1149. * underlying protocol (note that nothing remotely this size
  1150. * should ever be allocated in any normal case). This size is
  1151. - * validated later in ssam_request_sync(), for allocation the
  1152. - * bound imposed by u16 should be enough.
  1153. + * validated later in ssam_request_do_sync(), for allocation
  1154. + * the bound imposed by u16 should be enough.
  1155. */
  1156. spec.payload = kzalloc(spec.length, GFP_KERNEL);
  1157. if (!spec.payload) {
  1158. @@ -342,7 +342,7 @@ static long ssam_cdev_request(struct ssam_cdev_client *client, struct ssam_cdev_
  1159. }
  1160. /* Perform request. */
  1161. - status = ssam_request_sync(client->cdev->ctrl, &spec, &rsp);
  1162. + status = ssam_request_do_sync(client->cdev->ctrl, &spec, &rsp);
  1163. if (status)
  1164. goto out;
  1165. diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1166. index 6917e86062bc8..a18e9fc7896b3 100644
  1167. --- a/drivers/platform/surface/surface_aggregator_tabletsw.c
  1168. +++ b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1169. @@ -387,7 +387,7 @@ static int ssam_pos_get_sources_list(struct ssam_tablet_sw *sw, struct ssam_sour
  1170. rsp.length = 0;
  1171. rsp.pointer = (u8 *)sources;
  1172. - status = ssam_retry(ssam_request_sync_onstack, sw->sdev->ctrl, &rqst, &rsp, 0);
  1173. + status = ssam_retry(ssam_request_do_sync_onstack, sw->sdev->ctrl, &rqst, &rsp, 0);
  1174. if (status)
  1175. return status;
  1176. diff --git a/include/linux/surface_aggregator/controller.h b/include/linux/surface_aggregator/controller.h
  1177. index 8932bc0bae187..cb7980805920a 100644
  1178. --- a/include/linux/surface_aggregator/controller.h
  1179. +++ b/include/linux/surface_aggregator/controller.h
  1180. @@ -207,17 +207,17 @@ static inline int ssam_request_sync_wait(struct ssam_request_sync *rqst)
  1181. return rqst->status;
  1182. }
  1183. -int ssam_request_sync(struct ssam_controller *ctrl,
  1184. - const struct ssam_request *spec,
  1185. - struct ssam_response *rsp);
  1186. +int ssam_request_do_sync(struct ssam_controller *ctrl,
  1187. + const struct ssam_request *spec,
  1188. + struct ssam_response *rsp);
  1189. -int ssam_request_sync_with_buffer(struct ssam_controller *ctrl,
  1190. - const struct ssam_request *spec,
  1191. - struct ssam_response *rsp,
  1192. - struct ssam_span *buf);
  1193. +int ssam_request_do_sync_with_buffer(struct ssam_controller *ctrl,
  1194. + const struct ssam_request *spec,
  1195. + struct ssam_response *rsp,
  1196. + struct ssam_span *buf);
  1197. /**
  1198. - * ssam_request_sync_onstack - Execute a synchronous request on the stack.
  1199. + * ssam_request_do_sync_onstack - Execute a synchronous request on the stack.
  1200. * @ctrl: The controller via which the request is submitted.
  1201. * @rqst: The request specification.
  1202. * @rsp: The response buffer.
  1203. @@ -227,7 +227,7 @@ int ssam_request_sync_with_buffer(struct ssam_controller *ctrl,
  1204. * fully initializes it via the provided request specification, submits it,
  1205. * and finally waits for its completion before returning its status. This
  1206. * helper macro essentially allocates the request message buffer on the stack
  1207. - * and then calls ssam_request_sync_with_buffer().
  1208. + * and then calls ssam_request_do_sync_with_buffer().
  1209. *
  1210. * Note: The @payload_len parameter specifies the maximum payload length, used
  1211. * for buffer allocation. The actual payload length may be smaller.
  1212. @@ -235,12 +235,12 @@ int ssam_request_sync_with_buffer(struct ssam_controller *ctrl,
  1213. * Return: Returns the status of the request or any failure during setup, i.e.
  1214. * zero on success and a negative value on failure.
  1215. */
  1216. -#define ssam_request_sync_onstack(ctrl, rqst, rsp, payload_len) \
  1217. +#define ssam_request_do_sync_onstack(ctrl, rqst, rsp, payload_len) \
  1218. ({ \
  1219. u8 __data[SSH_COMMAND_MESSAGE_LENGTH(payload_len)]; \
  1220. struct ssam_span __buf = { &__data[0], ARRAY_SIZE(__data) }; \
  1221. \
  1222. - ssam_request_sync_with_buffer(ctrl, rqst, rsp, &__buf); \
  1223. + ssam_request_do_sync_with_buffer(ctrl, rqst, rsp, &__buf); \
  1224. })
  1225. /**
  1226. @@ -349,7 +349,7 @@ struct ssam_request_spec_md {
  1227. * zero on success and negative on failure. The ``ctrl`` parameter is the
  1228. * controller via which the request is being sent.
  1229. *
  1230. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1231. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1232. * the generated function.
  1233. */
  1234. #define SSAM_DEFINE_SYNC_REQUEST_N(name, spec...) \
  1235. @@ -366,7 +366,7 @@ struct ssam_request_spec_md {
  1236. rqst.length = 0; \
  1237. rqst.payload = NULL; \
  1238. \
  1239. - return ssam_request_sync_onstack(ctrl, &rqst, NULL, 0); \
  1240. + return ssam_request_do_sync_onstack(ctrl, &rqst, NULL, 0); \
  1241. }
  1242. /**
  1243. @@ -389,7 +389,7 @@ struct ssam_request_spec_md {
  1244. * parameter is the controller via which the request is sent. The request
  1245. * argument is specified via the ``arg`` pointer.
  1246. *
  1247. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1248. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1249. * the generated function.
  1250. */
  1251. #define SSAM_DEFINE_SYNC_REQUEST_W(name, atype, spec...) \
  1252. @@ -406,8 +406,8 @@ struct ssam_request_spec_md {
  1253. rqst.length = sizeof(atype); \
  1254. rqst.payload = (u8 *)arg; \
  1255. \
  1256. - return ssam_request_sync_onstack(ctrl, &rqst, NULL, \
  1257. - sizeof(atype)); \
  1258. + return ssam_request_do_sync_onstack(ctrl, &rqst, NULL, \
  1259. + sizeof(atype)); \
  1260. }
  1261. /**
  1262. @@ -430,7 +430,7 @@ struct ssam_request_spec_md {
  1263. * the controller via which the request is sent. The request's return value is
  1264. * written to the memory pointed to by the ``ret`` parameter.
  1265. *
  1266. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1267. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1268. * the generated function.
  1269. */
  1270. #define SSAM_DEFINE_SYNC_REQUEST_R(name, rtype, spec...) \
  1271. @@ -453,7 +453,7 @@ struct ssam_request_spec_md {
  1272. rsp.length = 0; \
  1273. rsp.pointer = (u8 *)ret; \
  1274. \
  1275. - status = ssam_request_sync_onstack(ctrl, &rqst, &rsp, 0); \
  1276. + status = ssam_request_do_sync_onstack(ctrl, &rqst, &rsp, 0); \
  1277. if (status) \
  1278. return status; \
  1279. \
  1280. @@ -491,7 +491,7 @@ struct ssam_request_spec_md {
  1281. * request argument is specified via the ``arg`` pointer. The request's return
  1282. * value is written to the memory pointed to by the ``ret`` parameter.
  1283. *
  1284. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1285. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1286. * the generated function.
  1287. */
  1288. #define SSAM_DEFINE_SYNC_REQUEST_WR(name, atype, rtype, spec...) \
  1289. @@ -514,7 +514,7 @@ struct ssam_request_spec_md {
  1290. rsp.length = 0; \
  1291. rsp.pointer = (u8 *)ret; \
  1292. \
  1293. - status = ssam_request_sync_onstack(ctrl, &rqst, &rsp, sizeof(atype)); \
  1294. + status = ssam_request_do_sync_onstack(ctrl, &rqst, &rsp, sizeof(atype)); \
  1295. if (status) \
  1296. return status; \
  1297. \
  1298. @@ -550,7 +550,7 @@ struct ssam_request_spec_md {
  1299. * parameter is the controller via which the request is sent, ``tid`` the
  1300. * target ID for the request, and ``iid`` the instance ID.
  1301. *
  1302. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1303. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1304. * the generated function.
  1305. */
  1306. #define SSAM_DEFINE_SYNC_REQUEST_MD_N(name, spec...) \
  1307. @@ -567,7 +567,7 @@ struct ssam_request_spec_md {
  1308. rqst.length = 0; \
  1309. rqst.payload = NULL; \
  1310. \
  1311. - return ssam_request_sync_onstack(ctrl, &rqst, NULL, 0); \
  1312. + return ssam_request_do_sync_onstack(ctrl, &rqst, NULL, 0); \
  1313. }
  1314. /**
  1315. @@ -592,7 +592,7 @@ struct ssam_request_spec_md {
  1316. * ``tid`` the target ID for the request, and ``iid`` the instance ID. The
  1317. * request argument is specified via the ``arg`` pointer.
  1318. *
  1319. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1320. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1321. * the generated function.
  1322. */
  1323. #define SSAM_DEFINE_SYNC_REQUEST_MD_W(name, atype, spec...) \
  1324. @@ -609,7 +609,7 @@ struct ssam_request_spec_md {
  1325. rqst.length = sizeof(atype); \
  1326. rqst.payload = (u8 *)arg; \
  1327. \
  1328. - return ssam_request_sync_onstack(ctrl, &rqst, NULL, \
  1329. + return ssam_request_do_sync_onstack(ctrl, &rqst, NULL, \
  1330. sizeof(atype)); \
  1331. }
  1332. @@ -635,7 +635,7 @@ struct ssam_request_spec_md {
  1333. * the target ID for the request, and ``iid`` the instance ID. The request's
  1334. * return value is written to the memory pointed to by the ``ret`` parameter.
  1335. *
  1336. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1337. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1338. * the generated function.
  1339. */
  1340. #define SSAM_DEFINE_SYNC_REQUEST_MD_R(name, rtype, spec...) \
  1341. @@ -658,7 +658,7 @@ struct ssam_request_spec_md {
  1342. rsp.length = 0; \
  1343. rsp.pointer = (u8 *)ret; \
  1344. \
  1345. - status = ssam_request_sync_onstack(ctrl, &rqst, &rsp, 0); \
  1346. + status = ssam_request_do_sync_onstack(ctrl, &rqst, &rsp, 0); \
  1347. if (status) \
  1348. return status; \
  1349. \
  1350. @@ -698,7 +698,7 @@ struct ssam_request_spec_md {
  1351. * The request argument is specified via the ``arg`` pointer. The request's
  1352. * return value is written to the memory pointed to by the ``ret`` parameter.
  1353. *
  1354. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1355. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1356. * the generated function.
  1357. */
  1358. #define SSAM_DEFINE_SYNC_REQUEST_MD_WR(name, atype, rtype, spec...) \
  1359. @@ -722,7 +722,7 @@ struct ssam_request_spec_md {
  1360. rsp.length = 0; \
  1361. rsp.pointer = (u8 *)ret; \
  1362. \
  1363. - status = ssam_request_sync_onstack(ctrl, &rqst, &rsp, sizeof(atype)); \
  1364. + status = ssam_request_do_sync_onstack(ctrl, &rqst, &rsp, sizeof(atype)); \
  1365. if (status) \
  1366. return status; \
  1367. \
  1368. diff --git a/include/linux/surface_aggregator/device.h b/include/linux/surface_aggregator/device.h
  1369. index 4da20b7a0ee5e..1545e5567b152 100644
  1370. --- a/include/linux/surface_aggregator/device.h
  1371. +++ b/include/linux/surface_aggregator/device.h
  1372. @@ -456,7 +456,7 @@ static inline int ssam_device_register_clients(struct ssam_device *sdev)
  1373. * device of the request and by association the controller via which the
  1374. * request is sent.
  1375. *
  1376. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1377. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1378. * the generated function.
  1379. */
  1380. #define SSAM_DEFINE_SYNC_REQUEST_CL_N(name, spec...) \
  1381. @@ -490,7 +490,7 @@ static inline int ssam_device_register_clients(struct ssam_device *sdev)
  1382. * which the request is sent. The request's argument is specified via the
  1383. * ``arg`` pointer.
  1384. *
  1385. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1386. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1387. * the generated function.
  1388. */
  1389. #define SSAM_DEFINE_SYNC_REQUEST_CL_W(name, atype, spec...) \
  1390. @@ -524,7 +524,7 @@ static inline int ssam_device_register_clients(struct ssam_device *sdev)
  1391. * the request is sent. The request's return value is written to the memory
  1392. * pointed to by the ``ret`` parameter.
  1393. *
  1394. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1395. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1396. * the generated function.
  1397. */
  1398. #define SSAM_DEFINE_SYNC_REQUEST_CL_R(name, rtype, spec...) \
  1399. @@ -560,7 +560,7 @@ static inline int ssam_device_register_clients(struct ssam_device *sdev)
  1400. * specified via the ``arg`` pointer. The request's return value is written to
  1401. * the memory pointed to by the ``ret`` parameter.
  1402. *
  1403. - * Refer to ssam_request_sync_onstack() for more details on the behavior of
  1404. + * Refer to ssam_request_do_sync_onstack() for more details on the behavior of
  1405. * the generated function.
  1406. */
  1407. #define SSAM_DEFINE_SYNC_REQUEST_CL_WR(name, atype, rtype, spec...) \
  1408. --
  1409. 2.43.0
  1410. From 7b63e1f2a5cfa18d867a206b08e6cd0cbf321e8d Mon Sep 17 00:00:00 2001
  1411. From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  1412. Date: Wed, 18 Jan 2023 11:38:23 +0200
  1413. Subject: [PATCH] platform/surface: Switch to use acpi_evaluate_dsm_typed()
  1414. The acpi_evaluate_dsm_typed() provides a way to check the type of the
  1415. object evaluated by _DSM call. Use it instead of open coded variant.
  1416. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  1417. Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com>
  1418. Link: https://lore.kernel.org/r/20230118093823.39679-1-andriy.shevchenko@linux.intel.com
  1419. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  1420. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  1421. Patchset: surface-sam
  1422. ---
  1423. drivers/platform/surface/surface_hotplug.c | 13 +++----------
  1424. 1 file changed, 3 insertions(+), 10 deletions(-)
  1425. diff --git a/drivers/platform/surface/surface_hotplug.c b/drivers/platform/surface/surface_hotplug.c
  1426. index f004a24952013..7b6d887dccdbf 100644
  1427. --- a/drivers/platform/surface/surface_hotplug.c
  1428. +++ b/drivers/platform/surface/surface_hotplug.c
  1429. @@ -101,18 +101,12 @@ static void shps_dsm_notify_irq(struct platform_device *pdev, enum shps_irq_type
  1430. param.type = ACPI_TYPE_INTEGER;
  1431. param.integer.value = value;
  1432. - result = acpi_evaluate_dsm(handle, &shps_dsm_guid, SHPS_DSM_REVISION,
  1433. - shps_dsm_fn_for_irq(type), &param);
  1434. -
  1435. + result = acpi_evaluate_dsm_typed(handle, &shps_dsm_guid, SHPS_DSM_REVISION,
  1436. + shps_dsm_fn_for_irq(type), &param, ACPI_TYPE_BUFFER);
  1437. if (!result) {
  1438. dev_err(&pdev->dev, "IRQ notification via DSM failed (irq=%d, gpio=%d)\n",
  1439. type, value);
  1440. - } else if (result->type != ACPI_TYPE_BUFFER) {
  1441. - dev_err(&pdev->dev,
  1442. - "IRQ notification via DSM failed: unexpected result type (irq=%d, gpio=%d)\n",
  1443. - type, value);
  1444. -
  1445. } else if (result->buffer.length != 1 || result->buffer.pointer[0] != 0) {
  1446. dev_err(&pdev->dev,
  1447. "IRQ notification via DSM failed: unexpected result value (irq=%d, gpio=%d)\n",
  1448. @@ -121,8 +115,7 @@ static void shps_dsm_notify_irq(struct platform_device *pdev, enum shps_irq_type
  1449. mutex_unlock(&sdev->lock[type]);
  1450. - if (result)
  1451. - ACPI_FREE(result);
  1452. + ACPI_FREE(result);
  1453. }
  1454. static irqreturn_t shps_handle_irq(int irq, void *data)
  1455. --
  1456. 2.43.0
  1457. From 0f5c1efd939ca9d0d7442aedb1b067bdfd701107 Mon Sep 17 00:00:00 2001
  1458. From: Maximilian Luz <luzmaximilian@gmail.com>
  1459. Date: Sat, 4 Mar 2023 20:09:36 +0100
  1460. Subject: [PATCH] platform/surface: aggregator_tabletsw: Properly handle
  1461. different posture source IDs
  1462. The device posture subsystem (POS) can provide different posture
  1463. sources. Different sources can provide different posture states and
  1464. sources can be identified by their ID.
  1465. For example, screen posture of the Surface Laptop Studio (SLS), which is
  1466. currently the only supported source, uses a source ID of 0x03. The
  1467. Surface Pro 9 uses the same subsystem for its Type-Cover, however,
  1468. provides different states for that under the ID 0x00.
  1469. To eventually support the Surface Pro 9 and potential future devices, we
  1470. need to properly disambiguate between source IDs. Therefore, add the
  1471. source ID to the state we carry and determine the tablet-mode state (as
  1472. well as state names) based on that.
  1473. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1474. Patchset: surface-sam
  1475. ---
  1476. .../surface/surface_aggregator_tabletsw.c | 123 ++++++++++++------
  1477. 1 file changed, 84 insertions(+), 39 deletions(-)
  1478. diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1479. index a18e9fc7896b3..f9a58db6afde4 100644
  1480. --- a/drivers/platform/surface/surface_aggregator_tabletsw.c
  1481. +++ b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1482. @@ -20,16 +20,23 @@
  1483. struct ssam_tablet_sw;
  1484. +struct ssam_tablet_sw_state {
  1485. + u32 source;
  1486. + u32 state;
  1487. +};
  1488. +
  1489. struct ssam_tablet_sw_ops {
  1490. - int (*get_state)(struct ssam_tablet_sw *sw, u32 *state);
  1491. - const char *(*state_name)(struct ssam_tablet_sw *sw, u32 state);
  1492. - bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw, u32 state);
  1493. + int (*get_state)(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state);
  1494. + const char *(*state_name)(struct ssam_tablet_sw *sw,
  1495. + const struct ssam_tablet_sw_state *state);
  1496. + bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw,
  1497. + const struct ssam_tablet_sw_state *state);
  1498. };
  1499. struct ssam_tablet_sw {
  1500. struct ssam_device *sdev;
  1501. - u32 state;
  1502. + struct ssam_tablet_sw_state state;
  1503. struct work_struct update_work;
  1504. struct input_dev *mode_switch;
  1505. @@ -45,9 +52,11 @@ struct ssam_tablet_sw_desc {
  1506. struct {
  1507. u32 (*notify)(struct ssam_event_notifier *nf, const struct ssam_event *event);
  1508. - int (*get_state)(struct ssam_tablet_sw *sw, u32 *state);
  1509. - const char *(*state_name)(struct ssam_tablet_sw *sw, u32 state);
  1510. - bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw, u32 state);
  1511. + int (*get_state)(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state);
  1512. + const char *(*state_name)(struct ssam_tablet_sw *sw,
  1513. + const struct ssam_tablet_sw_state *state);
  1514. + bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw,
  1515. + const struct ssam_tablet_sw_state *state);
  1516. } ops;
  1517. struct {
  1518. @@ -61,7 +70,7 @@ struct ssam_tablet_sw_desc {
  1519. static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf)
  1520. {
  1521. struct ssam_tablet_sw *sw = dev_get_drvdata(dev);
  1522. - const char *state = sw->ops.state_name(sw, sw->state);
  1523. + const char *state = sw->ops.state_name(sw, &sw->state);
  1524. return sysfs_emit(buf, "%s\n", state);
  1525. }
  1526. @@ -79,19 +88,19 @@ static const struct attribute_group ssam_tablet_sw_group = {
  1527. static void ssam_tablet_sw_update_workfn(struct work_struct *work)
  1528. {
  1529. struct ssam_tablet_sw *sw = container_of(work, struct ssam_tablet_sw, update_work);
  1530. + struct ssam_tablet_sw_state state;
  1531. int tablet, status;
  1532. - u32 state;
  1533. status = sw->ops.get_state(sw, &state);
  1534. if (status)
  1535. return;
  1536. - if (sw->state == state)
  1537. + if (sw->state.source == state.source && sw->state.state == state.state)
  1538. return;
  1539. sw->state = state;
  1540. /* Send SW_TABLET_MODE event. */
  1541. - tablet = sw->ops.state_is_tablet_mode(sw, state);
  1542. + tablet = sw->ops.state_is_tablet_mode(sw, &state);
  1543. input_report_switch(sw->mode_switch, SW_TABLET_MODE, tablet);
  1544. input_sync(sw->mode_switch);
  1545. }
  1546. @@ -146,7 +155,7 @@ static int ssam_tablet_sw_probe(struct ssam_device *sdev)
  1547. sw->mode_switch->id.bustype = BUS_HOST;
  1548. sw->mode_switch->dev.parent = &sdev->dev;
  1549. - tablet = sw->ops.state_is_tablet_mode(sw, sw->state);
  1550. + tablet = sw->ops.state_is_tablet_mode(sw, &sw->state);
  1551. input_set_capability(sw->mode_switch, EV_SW, SW_TABLET_MODE);
  1552. input_report_switch(sw->mode_switch, SW_TABLET_MODE, tablet);
  1553. @@ -204,9 +213,10 @@ enum ssam_kip_cover_state {
  1554. SSAM_KIP_COVER_STATE_BOOK = 0x06,
  1555. };
  1556. -static const char *ssam_kip_cover_state_name(struct ssam_tablet_sw *sw, u32 state)
  1557. +static const char *ssam_kip_cover_state_name(struct ssam_tablet_sw *sw,
  1558. + const struct ssam_tablet_sw_state *state)
  1559. {
  1560. - switch (state) {
  1561. + switch (state->state) {
  1562. case SSAM_KIP_COVER_STATE_DISCONNECTED:
  1563. return "disconnected";
  1564. @@ -226,14 +236,15 @@ static const char *ssam_kip_cover_state_name(struct ssam_tablet_sw *sw, u32 stat
  1565. return "book";
  1566. default:
  1567. - dev_warn(&sw->sdev->dev, "unknown KIP cover state: %u\n", state);
  1568. + dev_warn(&sw->sdev->dev, "unknown KIP cover state: %u\n", state->state);
  1569. return "<unknown>";
  1570. }
  1571. }
  1572. -static bool ssam_kip_cover_state_is_tablet_mode(struct ssam_tablet_sw *sw, u32 state)
  1573. +static bool ssam_kip_cover_state_is_tablet_mode(struct ssam_tablet_sw *sw,
  1574. + const struct ssam_tablet_sw_state *state)
  1575. {
  1576. - switch (state) {
  1577. + switch (state->state) {
  1578. case SSAM_KIP_COVER_STATE_DISCONNECTED:
  1579. case SSAM_KIP_COVER_STATE_FOLDED_CANVAS:
  1580. case SSAM_KIP_COVER_STATE_FOLDED_BACK:
  1581. @@ -245,7 +256,7 @@ static bool ssam_kip_cover_state_is_tablet_mode(struct ssam_tablet_sw *sw, u32 s
  1582. return false;
  1583. default:
  1584. - dev_warn(&sw->sdev->dev, "unknown KIP cover state: %d\n", sw->state);
  1585. + dev_warn(&sw->sdev->dev, "unknown KIP cover state: %d\n", state->state);
  1586. return true;
  1587. }
  1588. }
  1589. @@ -257,7 +268,7 @@ SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_get_cover_state, u8, {
  1590. .instance_id = 0x00,
  1591. });
  1592. -static int ssam_kip_get_cover_state(struct ssam_tablet_sw *sw, u32 *state)
  1593. +static int ssam_kip_get_cover_state(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state)
  1594. {
  1595. int status;
  1596. u8 raw;
  1597. @@ -268,7 +279,8 @@ static int ssam_kip_get_cover_state(struct ssam_tablet_sw *sw, u32 *state)
  1598. return status;
  1599. }
  1600. - *state = raw;
  1601. + state->source = 0; /* Unused for KIP switch. */
  1602. + state->state = raw;
  1603. return 0;
  1604. }
  1605. @@ -317,11 +329,15 @@ MODULE_PARM_DESC(tablet_mode_in_slate_state, "Enable tablet mode in slate device
  1606. #define SSAM_EVENT_POS_CID_POSTURE_CHANGED 0x03
  1607. #define SSAM_POS_MAX_SOURCES 4
  1608. -enum ssam_pos_state {
  1609. - SSAM_POS_POSTURE_LID_CLOSED = 0x00,
  1610. - SSAM_POS_POSTURE_LAPTOP = 0x01,
  1611. - SSAM_POS_POSTURE_SLATE = 0x02,
  1612. - SSAM_POS_POSTURE_TABLET = 0x03,
  1613. +enum ssam_pos_source_id {
  1614. + SSAM_POS_SOURCE_SLS = 0x03,
  1615. +};
  1616. +
  1617. +enum ssam_pos_state_sls {
  1618. + SSAM_POS_SLS_LID_CLOSED = 0x00,
  1619. + SSAM_POS_SLS_LAPTOP = 0x01,
  1620. + SSAM_POS_SLS_SLATE = 0x02,
  1621. + SSAM_POS_SLS_TABLET = 0x03,
  1622. };
  1623. struct ssam_sources_list {
  1624. @@ -329,42 +345,68 @@ struct ssam_sources_list {
  1625. __le32 id[SSAM_POS_MAX_SOURCES];
  1626. } __packed;
  1627. -static const char *ssam_pos_state_name(struct ssam_tablet_sw *sw, u32 state)
  1628. +static const char *ssam_pos_state_name_sls(struct ssam_tablet_sw *sw, u32 state)
  1629. {
  1630. switch (state) {
  1631. - case SSAM_POS_POSTURE_LID_CLOSED:
  1632. + case SSAM_POS_SLS_LID_CLOSED:
  1633. return "closed";
  1634. - case SSAM_POS_POSTURE_LAPTOP:
  1635. + case SSAM_POS_SLS_LAPTOP:
  1636. return "laptop";
  1637. - case SSAM_POS_POSTURE_SLATE:
  1638. + case SSAM_POS_SLS_SLATE:
  1639. return "slate";
  1640. - case SSAM_POS_POSTURE_TABLET:
  1641. + case SSAM_POS_SLS_TABLET:
  1642. return "tablet";
  1643. default:
  1644. - dev_warn(&sw->sdev->dev, "unknown device posture: %u\n", state);
  1645. + dev_warn(&sw->sdev->dev, "unknown device posture for SLS: %u\n", state);
  1646. return "<unknown>";
  1647. }
  1648. }
  1649. -static bool ssam_pos_state_is_tablet_mode(struct ssam_tablet_sw *sw, u32 state)
  1650. +static const char *ssam_pos_state_name(struct ssam_tablet_sw *sw,
  1651. + const struct ssam_tablet_sw_state *state)
  1652. +{
  1653. + switch (state->source) {
  1654. + case SSAM_POS_SOURCE_SLS:
  1655. + return ssam_pos_state_name_sls(sw, state->state);
  1656. +
  1657. + default:
  1658. + dev_warn(&sw->sdev->dev, "unknown device posture source: %u\n", state->source);
  1659. + return "<unknown>";
  1660. + }
  1661. +}
  1662. +
  1663. +static bool ssam_pos_state_is_tablet_mode_sls(struct ssam_tablet_sw *sw, u32 state)
  1664. {
  1665. switch (state) {
  1666. - case SSAM_POS_POSTURE_LAPTOP:
  1667. - case SSAM_POS_POSTURE_LID_CLOSED:
  1668. + case SSAM_POS_SLS_LAPTOP:
  1669. + case SSAM_POS_SLS_LID_CLOSED:
  1670. return false;
  1671. - case SSAM_POS_POSTURE_SLATE:
  1672. + case SSAM_POS_SLS_SLATE:
  1673. return tablet_mode_in_slate_state;
  1674. - case SSAM_POS_POSTURE_TABLET:
  1675. + case SSAM_POS_SLS_TABLET:
  1676. return true;
  1677. default:
  1678. - dev_warn(&sw->sdev->dev, "unknown device posture: %u\n", state);
  1679. + dev_warn(&sw->sdev->dev, "unknown device posture for SLS: %u\n", state);
  1680. + return true;
  1681. + }
  1682. +}
  1683. +
  1684. +static bool ssam_pos_state_is_tablet_mode(struct ssam_tablet_sw *sw,
  1685. + const struct ssam_tablet_sw_state *state)
  1686. +{
  1687. + switch (state->source) {
  1688. + case SSAM_POS_SOURCE_SLS:
  1689. + return ssam_pos_state_is_tablet_mode_sls(sw, state->state);
  1690. +
  1691. + default:
  1692. + dev_warn(&sw->sdev->dev, "unknown device posture source: %u\n", state->source);
  1693. return true;
  1694. }
  1695. }
  1696. @@ -455,9 +497,10 @@ static int ssam_pos_get_posture_for_source(struct ssam_tablet_sw *sw, u32 source
  1697. return 0;
  1698. }
  1699. -static int ssam_pos_get_posture(struct ssam_tablet_sw *sw, u32 *state)
  1700. +static int ssam_pos_get_posture(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state)
  1701. {
  1702. u32 source_id;
  1703. + u32 source_state;
  1704. int status;
  1705. status = ssam_pos_get_source(sw, &source_id);
  1706. @@ -466,13 +509,15 @@ static int ssam_pos_get_posture(struct ssam_tablet_sw *sw, u32 *state)
  1707. return status;
  1708. }
  1709. - status = ssam_pos_get_posture_for_source(sw, source_id, state);
  1710. + status = ssam_pos_get_posture_for_source(sw, source_id, &source_state);
  1711. if (status) {
  1712. dev_err(&sw->sdev->dev, "failed to get posture value for source %u: %d\n",
  1713. source_id, status);
  1714. return status;
  1715. }
  1716. + state->source = source_id;
  1717. + state->state = source_state;
  1718. return 0;
  1719. }
  1720. --
  1721. 2.43.0
  1722. From 89dc1d5972b9c2001086ca9aa1982fd669258763 Mon Sep 17 00:00:00 2001
  1723. From: Maximilian Luz <luzmaximilian@gmail.com>
  1724. Date: Sun, 19 Feb 2023 23:33:43 +0100
  1725. Subject: [PATCH] platform/surface: aggregator_tabletsw: Add support for
  1726. Type-Cover posture source
  1727. Implement support for the Type-Cover posture source (ID 0x00), found on
  1728. the Surface Pro 9.
  1729. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1730. Patchset: surface-sam
  1731. ---
  1732. .../surface/surface_aggregator_tabletsw.c | 57 +++++++++++++++++++
  1733. 1 file changed, 57 insertions(+)
  1734. diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1735. index f9a58db6afde4..4a029f5db20a9 100644
  1736. --- a/drivers/platform/surface/surface_aggregator_tabletsw.c
  1737. +++ b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1738. @@ -330,9 +330,18 @@ MODULE_PARM_DESC(tablet_mode_in_slate_state, "Enable tablet mode in slate device
  1739. #define SSAM_POS_MAX_SOURCES 4
  1740. enum ssam_pos_source_id {
  1741. + SSAM_POS_SOURCE_COVER = 0x00,
  1742. SSAM_POS_SOURCE_SLS = 0x03,
  1743. };
  1744. +enum ssam_pos_state_cover {
  1745. + SSAM_POS_COVER_DISCONNECTED = 0x01,
  1746. + SSAM_POS_COVER_CLOSED = 0x02,
  1747. + SSAM_POS_COVER_LAPTOP = 0x03,
  1748. + SSAM_POS_COVER_FOLDED_CANVAS = 0x04,
  1749. + SSAM_POS_COVER_FOLDED_BACK = 0x05,
  1750. +};
  1751. +
  1752. enum ssam_pos_state_sls {
  1753. SSAM_POS_SLS_LID_CLOSED = 0x00,
  1754. SSAM_POS_SLS_LAPTOP = 0x01,
  1755. @@ -345,6 +354,30 @@ struct ssam_sources_list {
  1756. __le32 id[SSAM_POS_MAX_SOURCES];
  1757. } __packed;
  1758. +static const char *ssam_pos_state_name_cover(struct ssam_tablet_sw *sw, u32 state)
  1759. +{
  1760. + switch (state) {
  1761. + case SSAM_POS_COVER_DISCONNECTED:
  1762. + return "disconnected";
  1763. +
  1764. + case SSAM_POS_COVER_CLOSED:
  1765. + return "closed";
  1766. +
  1767. + case SSAM_POS_COVER_LAPTOP:
  1768. + return "laptop";
  1769. +
  1770. + case SSAM_POS_COVER_FOLDED_CANVAS:
  1771. + return "folded-canvas";
  1772. +
  1773. + case SSAM_POS_COVER_FOLDED_BACK:
  1774. + return "folded-back";
  1775. +
  1776. + default:
  1777. + dev_warn(&sw->sdev->dev, "unknown device posture for type-cover: %u\n", state);
  1778. + return "<unknown>";
  1779. + }
  1780. +}
  1781. +
  1782. static const char *ssam_pos_state_name_sls(struct ssam_tablet_sw *sw, u32 state)
  1783. {
  1784. switch (state) {
  1785. @@ -370,6 +403,9 @@ static const char *ssam_pos_state_name(struct ssam_tablet_sw *sw,
  1786. const struct ssam_tablet_sw_state *state)
  1787. {
  1788. switch (state->source) {
  1789. + case SSAM_POS_SOURCE_COVER:
  1790. + return ssam_pos_state_name_cover(sw, state->state);
  1791. +
  1792. case SSAM_POS_SOURCE_SLS:
  1793. return ssam_pos_state_name_sls(sw, state->state);
  1794. @@ -379,6 +415,24 @@ static const char *ssam_pos_state_name(struct ssam_tablet_sw *sw,
  1795. }
  1796. }
  1797. +static bool ssam_pos_state_is_tablet_mode_cover(struct ssam_tablet_sw *sw, u32 state)
  1798. +{
  1799. + switch (state) {
  1800. + case SSAM_POS_COVER_DISCONNECTED:
  1801. + case SSAM_POS_COVER_FOLDED_CANVAS:
  1802. + case SSAM_POS_COVER_FOLDED_BACK:
  1803. + return true;
  1804. +
  1805. + case SSAM_POS_COVER_CLOSED:
  1806. + case SSAM_POS_COVER_LAPTOP:
  1807. + return false;
  1808. +
  1809. + default:
  1810. + dev_warn(&sw->sdev->dev, "unknown device posture for type-cover: %u\n", state);
  1811. + return true;
  1812. + }
  1813. +}
  1814. +
  1815. static bool ssam_pos_state_is_tablet_mode_sls(struct ssam_tablet_sw *sw, u32 state)
  1816. {
  1817. switch (state) {
  1818. @@ -402,6 +456,9 @@ static bool ssam_pos_state_is_tablet_mode(struct ssam_tablet_sw *sw,
  1819. const struct ssam_tablet_sw_state *state)
  1820. {
  1821. switch (state->source) {
  1822. + case SSAM_POS_SOURCE_COVER:
  1823. + return ssam_pos_state_is_tablet_mode_cover(sw, state->state);
  1824. +
  1825. case SSAM_POS_SOURCE_SLS:
  1826. return ssam_pos_state_is_tablet_mode_sls(sw, state->state);
  1827. --
  1828. 2.43.0
  1829. From 0ef185523ee176cfa2fd105fcc89d3f2f617eeaf Mon Sep 17 00:00:00 2001
  1830. From: Maximilian Luz <luzmaximilian@gmail.com>
  1831. Date: Thu, 18 May 2023 22:57:17 +0200
  1832. Subject: [PATCH] platform/surface: aggregator_tabletsw: Add support for book
  1833. mode in POS subsystem
  1834. Devices with a type-cover have an additional "book" mode, deactivating
  1835. type-cover input and turning off its backlight. This is currently
  1836. unsupported, leading to the warning
  1837. surface_aggregator_tablet_mode_switch 01:26:01:00:01: unknown device posture for type-cover: 6
  1838. Therefore, add support for this state and map it to enable tablet-mode.
  1839. Fixes: 37ff64cd81ff ("platform/surface: aggregator_tabletsw: Add support for Type-Cover posture source")
  1840. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1841. Patchset: surface-sam
  1842. ---
  1843. drivers/platform/surface/surface_aggregator_tabletsw.c | 5 +++++
  1844. 1 file changed, 5 insertions(+)
  1845. diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1846. index 4a029f5db20a9..c0a1a5869246e 100644
  1847. --- a/drivers/platform/surface/surface_aggregator_tabletsw.c
  1848. +++ b/drivers/platform/surface/surface_aggregator_tabletsw.c
  1849. @@ -340,6 +340,7 @@ enum ssam_pos_state_cover {
  1850. SSAM_POS_COVER_LAPTOP = 0x03,
  1851. SSAM_POS_COVER_FOLDED_CANVAS = 0x04,
  1852. SSAM_POS_COVER_FOLDED_BACK = 0x05,
  1853. + SSAM_POS_COVER_BOOK = 0x06,
  1854. };
  1855. enum ssam_pos_state_sls {
  1856. @@ -372,6 +373,9 @@ static const char *ssam_pos_state_name_cover(struct ssam_tablet_sw *sw, u32 stat
  1857. case SSAM_POS_COVER_FOLDED_BACK:
  1858. return "folded-back";
  1859. + case SSAM_POS_COVER_BOOK:
  1860. + return "book";
  1861. +
  1862. default:
  1863. dev_warn(&sw->sdev->dev, "unknown device posture for type-cover: %u\n", state);
  1864. return "<unknown>";
  1865. @@ -421,6 +425,7 @@ static bool ssam_pos_state_is_tablet_mode_cover(struct ssam_tablet_sw *sw, u32 s
  1866. case SSAM_POS_COVER_DISCONNECTED:
  1867. case SSAM_POS_COVER_FOLDED_CANVAS:
  1868. case SSAM_POS_COVER_FOLDED_BACK:
  1869. + case SSAM_POS_COVER_BOOK:
  1870. return true;
  1871. case SSAM_POS_COVER_CLOSED:
  1872. --
  1873. 2.43.0
  1874. From dcb71bedc807baae6102c9a8d2534d0477af51cd Mon Sep 17 00:00:00 2001
  1875. From: Maximilian Luz <luzmaximilian@gmail.com>
  1876. Date: Sun, 19 Feb 2023 23:41:18 +0100
  1877. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  1878. tablet-mode switch on Surface Pro 9
  1879. Add support for the POS-subsystem tablet-mode switch used on the Surface
  1880. Pro 9.
  1881. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1882. Patchset: surface-sam
  1883. ---
  1884. drivers/platform/surface/surface_aggregator_registry.c | 2 +-
  1885. 1 file changed, 1 insertion(+), 1 deletion(-)
  1886. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  1887. index 296f72d52e6a6..0fe5be5396525 100644
  1888. --- a/drivers/platform/surface/surface_aggregator_registry.c
  1889. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  1890. @@ -305,7 +305,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
  1891. &ssam_node_bat_ac,
  1892. &ssam_node_bat_main,
  1893. &ssam_node_tmp_pprof,
  1894. - /* TODO: Tablet mode switch (via POS subsystem) */
  1895. + &ssam_node_pos_tablet_switch,
  1896. &ssam_node_hid_kip_keyboard,
  1897. &ssam_node_hid_kip_penstash,
  1898. &ssam_node_hid_kip_touchpad,
  1899. --
  1900. 2.43.0
  1901. From 776b9d87b6b47f6e83688766418965349b9e75fc Mon Sep 17 00:00:00 2001
  1902. From: Maximilian Luz <luzmaximilian@gmail.com>
  1903. Date: Sun, 22 Oct 2023 14:57:11 +0200
  1904. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  1905. Surface Laptop Go 3
  1906. Add SAM client device nodes for the Surface Laptop Go 3. It seems to use
  1907. the same SAM client devices as the Surface Laptop Go 1 and 2, so re-use
  1908. their node group.
  1909. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1910. Patchset: surface-sam
  1911. ---
  1912. drivers/platform/surface/surface_aggregator_registry.c | 3 +++
  1913. 1 file changed, 3 insertions(+)
  1914. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  1915. index 0fe5be5396525..0d8c8395c5886 100644
  1916. --- a/drivers/platform/surface/surface_aggregator_registry.c
  1917. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  1918. @@ -367,6 +367,9 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
  1919. /* Surface Laptop Go 2 */
  1920. { "MSHW0290", (unsigned long)ssam_node_group_slg1 },
  1921. + /* Surface Laptop Go 3 */
  1922. + { "MSHW0440", (unsigned long)ssam_node_group_slg1 },
  1923. +
  1924. /* Surface Laptop Studio */
  1925. { "MSHW0123", (unsigned long)ssam_node_group_sls },
  1926. --
  1927. 2.43.0
  1928. From c650a4d3042c1cb708251d910fbf048c84f40682 Mon Sep 17 00:00:00 2001
  1929. From: Maximilian Luz <luzmaximilian@gmail.com>
  1930. Date: Mon, 20 Nov 2023 19:47:00 +0100
  1931. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  1932. Surface Laptop Studio 2
  1933. Add SAM client device nodes for the Surface Laptop Studio 2 (SLS2). The
  1934. SLS2 is quite similar to the SLS1, but it does not provide the touchpad
  1935. as a SAM-HID device. Therefore, add a new node group for the SLS2 and
  1936. update the comments accordingly
  1937. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  1938. Patchset: surface-sam
  1939. ---
  1940. .../surface/surface_aggregator_registry.c | 25 ++++++++++++++++---
  1941. 1 file changed, 21 insertions(+), 4 deletions(-)
  1942. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  1943. index 0d8c8395c5886..530db4db71aba 100644
  1944. --- a/drivers/platform/surface/surface_aggregator_registry.c
  1945. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  1946. @@ -247,8 +247,8 @@ static const struct software_node *ssam_node_group_sl5[] = {
  1947. NULL,
  1948. };
  1949. -/* Devices for Surface Laptop Studio. */
  1950. -static const struct software_node *ssam_node_group_sls[] = {
  1951. +/* Devices for Surface Laptop Studio 1. */
  1952. +static const struct software_node *ssam_node_group_sls1[] = {
  1953. &ssam_node_root,
  1954. &ssam_node_bat_ac,
  1955. &ssam_node_bat_main,
  1956. @@ -263,6 +263,20 @@ static const struct software_node *ssam_node_group_sls[] = {
  1957. NULL,
  1958. };
  1959. +/* Devices for Surface Laptop Studio 2. */
  1960. +static const struct software_node *ssam_node_group_sls2[] = {
  1961. + &ssam_node_root,
  1962. + &ssam_node_bat_ac,
  1963. + &ssam_node_bat_main,
  1964. + &ssam_node_tmp_pprof,
  1965. + &ssam_node_pos_tablet_switch,
  1966. + &ssam_node_hid_sam_keyboard,
  1967. + &ssam_node_hid_sam_penstash,
  1968. + &ssam_node_hid_sam_sensors,
  1969. + &ssam_node_hid_sam_ucm_ucsi,
  1970. + NULL,
  1971. +};
  1972. +
  1973. /* Devices for Surface Laptop Go. */
  1974. static const struct software_node *ssam_node_group_slg1[] = {
  1975. &ssam_node_root,
  1976. @@ -370,8 +384,11 @@ static const struct acpi_device_id ssam_platform_hub_match[] = {
  1977. /* Surface Laptop Go 3 */
  1978. { "MSHW0440", (unsigned long)ssam_node_group_slg1 },
  1979. - /* Surface Laptop Studio */
  1980. - { "MSHW0123", (unsigned long)ssam_node_group_sls },
  1981. + /* Surface Laptop Studio 1 */
  1982. + { "MSHW0123", (unsigned long)ssam_node_group_sls1 },
  1983. +
  1984. + /* Surface Laptop Studio 2 */
  1985. + { "MSHW0360", (unsigned long)ssam_node_group_sls2 },
  1986. { },
  1987. };
  1988. --
  1989. 2.43.0
  1990. From ee3c245f0f101a020ec8df9f961cc0354b21ef64 Mon Sep 17 00:00:00 2001
  1991. From: Ivor Wanders <ivor@iwanders.net>
  1992. Date: Mon, 18 Dec 2023 19:21:32 -0500
  1993. Subject: [PATCH] platform/surface: aggregator_registry: add entry for fan
  1994. speed
  1995. Add an entry for the fan speed function.
  1996. Add this new entry to the Surface Pro 9 group.
  1997. Signed-off-by: Ivor Wanders <ivor@iwanders.net>
  1998. Link: https://github.com/linux-surface/kernel/pull/144
  1999. Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com>
  2000. Patchset: surface-sam
  2001. ---
  2002. drivers/platform/surface/surface_aggregator_registry.c | 7 +++++++
  2003. 1 file changed, 7 insertions(+)
  2004. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  2005. index 530db4db71aba..b0db25886c996 100644
  2006. --- a/drivers/platform/surface/surface_aggregator_registry.c
  2007. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  2008. @@ -74,6 +74,12 @@ static const struct software_node ssam_node_tmp_pprof = {
  2009. .parent = &ssam_node_root,
  2010. };
  2011. +/* Fan speed function. */
  2012. +static const struct software_node ssam_node_fan_speed = {
  2013. + .name = "ssam:01:05:01:01:01",
  2014. + .parent = &ssam_node_root,
  2015. +};
  2016. +
  2017. /* Tablet-mode switch via KIP subsystem. */
  2018. static const struct software_node ssam_node_kip_tablet_switch = {
  2019. .name = "ssam:01:0e:01:00:01",
  2020. @@ -319,6 +325,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
  2021. &ssam_node_bat_ac,
  2022. &ssam_node_bat_main,
  2023. &ssam_node_tmp_pprof,
  2024. + &ssam_node_fan_speed,
  2025. &ssam_node_pos_tablet_switch,
  2026. &ssam_node_hid_kip_keyboard,
  2027. &ssam_node_hid_kip_penstash,
  2028. --
  2029. 2.43.0
  2030. From 0aecdee1605a40edddb894fa823a9bc568f05f3c Mon Sep 17 00:00:00 2001
  2031. From: Ivor Wanders <ivor@iwanders.net>
  2032. Date: Thu, 30 Nov 2023 20:20:24 -0500
  2033. Subject: [PATCH] hwmon: add fan speed monitoring driver for Surface devices
  2034. Adds a driver that provides read only access to the fan speed for Microsoft
  2035. Surface Pro devices. The fan speed is always regulated by the EC and cannot
  2036. be influenced directly.
  2037. Signed-off-by: Ivor Wanders <ivor@iwanders.net>
  2038. Link: https://github.com/linux-surface/kernel/pull/144
  2039. Patchset: surface-sam
  2040. ---
  2041. Documentation/hwmon/index.rst | 1 +
  2042. Documentation/hwmon/surface_fan.rst | 25 ++++++++
  2043. MAINTAINERS | 8 +++
  2044. drivers/hwmon/Kconfig | 13 ++++
  2045. drivers/hwmon/Makefile | 1 +
  2046. drivers/hwmon/surface_fan.c | 93 +++++++++++++++++++++++++++++
  2047. 6 files changed, 141 insertions(+)
  2048. create mode 100644 Documentation/hwmon/surface_fan.rst
  2049. create mode 100644 drivers/hwmon/surface_fan.c
  2050. diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
  2051. index c1d11cf13eef1..0e52bb60dc6d0 100644
  2052. --- a/Documentation/hwmon/index.rst
  2053. +++ b/Documentation/hwmon/index.rst
  2054. @@ -192,6 +192,7 @@ Hardware Monitoring Kernel Drivers
  2055. smsc47m1
  2056. sparx5-temp
  2057. stpddc60
  2058. + surface_fan
  2059. sy7636a-hwmon
  2060. tc654
  2061. tc74
  2062. diff --git a/Documentation/hwmon/surface_fan.rst b/Documentation/hwmon/surface_fan.rst
  2063. new file mode 100644
  2064. index 0000000000000..07942574c4f0c
  2065. --- /dev/null
  2066. +++ b/Documentation/hwmon/surface_fan.rst
  2067. @@ -0,0 +1,25 @@
  2068. +.. SPDX-License-Identifier: GPL-2.0-or-later
  2069. +
  2070. +Kernel driver surface_fan
  2071. +=========================
  2072. +
  2073. +Supported Devices:
  2074. +
  2075. + * Microsoft Surface Pro 9
  2076. +
  2077. +Author: Ivor Wanders <ivor@iwanders.net>
  2078. +
  2079. +Description
  2080. +-----------
  2081. +
  2082. +This provides monitoring of the fan found in some Microsoft Surface Pro devices,
  2083. +like the Surface Pro 9. The fan is always controlled by the onboard controller.
  2084. +
  2085. +Sysfs interface
  2086. +---------------
  2087. +
  2088. +======================= ======= =========================================
  2089. +Name Perm Description
  2090. +======================= ======= =========================================
  2091. +``fan1_input`` RO Current fan speed in RPM.
  2092. +======================= ======= =========================================
  2093. diff --git a/MAINTAINERS b/MAINTAINERS
  2094. index 13d1078808bb5..9f7702a82842d 100644
  2095. --- a/MAINTAINERS
  2096. +++ b/MAINTAINERS
  2097. @@ -13700,6 +13700,14 @@ F: Documentation/driver-api/surface_aggregator/clients/dtx.rst
  2098. F: drivers/platform/surface/surface_dtx.c
  2099. F: include/uapi/linux/surface_aggregator/dtx.h
  2100. +MICROSOFT SURFACE SENSOR FAN DRIVER
  2101. +M: Maximilian Luz <luzmaximilian@gmail.com>
  2102. +M: Ivor Wanders <ivor@iwanders.net>
  2103. +L: linux-hwmon@vger.kernel.org
  2104. +S: Maintained
  2105. +F: Documentation/hwmon/surface_fan.rst
  2106. +F: drivers/hwmon/surface_fan.c
  2107. +
  2108. MICROSOFT SURFACE GPE LID SUPPORT DRIVER
  2109. M: Maximilian Luz <luzmaximilian@gmail.com>
  2110. L: platform-driver-x86@vger.kernel.org
  2111. diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
  2112. index a5143d01b95f8..4a5f0ffd13e7a 100644
  2113. --- a/drivers/hwmon/Kconfig
  2114. +++ b/drivers/hwmon/Kconfig
  2115. @@ -1925,6 +1925,19 @@ config SENSORS_SMM665
  2116. This driver can also be built as a module. If so, the module will
  2117. be called smm665.
  2118. +config SENSORS_SURFACE_FAN
  2119. + tristate "Surface Fan Driver"
  2120. + depends on SURFACE_AGGREGATOR
  2121. + help
  2122. + Driver that provides monitoring of the fan on Surface Pro devices that
  2123. + have a fan, like the Surface Pro 9.
  2124. +
  2125. + This makes the fan's current speed accessible through the hwmon
  2126. + system. It does not provide control over the fan, the firmware is
  2127. + responsible for that, this driver merely provides monitoring.
  2128. +
  2129. + Select M or Y here, if you want to be able to read the fan's speed.
  2130. +
  2131. config SENSORS_ADC128D818
  2132. tristate "Texas Instruments ADC128D818"
  2133. depends on I2C
  2134. diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
  2135. index 11d076cad8a2d..4481011816074 100644
  2136. --- a/drivers/hwmon/Makefile
  2137. +++ b/drivers/hwmon/Makefile
  2138. @@ -192,6 +192,7 @@ obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
  2139. obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
  2140. obj-$(CONFIG_SENSORS_SPARX5) += sparx5-temp.o
  2141. obj-$(CONFIG_SENSORS_STTS751) += stts751.o
  2142. +obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o
  2143. obj-$(CONFIG_SENSORS_SY7636A) += sy7636a-hwmon.o
  2144. obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o
  2145. obj-$(CONFIG_SENSORS_TC74) += tc74.o
  2146. diff --git a/drivers/hwmon/surface_fan.c b/drivers/hwmon/surface_fan.c
  2147. new file mode 100644
  2148. index 0000000000000..7c2e3ae3eb40e
  2149. --- /dev/null
  2150. +++ b/drivers/hwmon/surface_fan.c
  2151. @@ -0,0 +1,93 @@
  2152. +// SPDX-License-Identifier: GPL-2.0+
  2153. +/*
  2154. + * Surface Fan driver for Surface System Aggregator Module. It provides access
  2155. + * to the fan's rpm through the hwmon system.
  2156. + *
  2157. + * Copyright (C) 2023 Ivor Wanders <ivor@iwanders.net>
  2158. + */
  2159. +
  2160. +#include <linux/hwmon.h>
  2161. +#include <linux/kernel.h>
  2162. +#include <linux/module.h>
  2163. +#include <linux/surface_aggregator/device.h>
  2164. +#include <linux/types.h>
  2165. +
  2166. +// SSAM
  2167. +SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_fan_rpm_get, __le16, {
  2168. + .target_category = SSAM_SSH_TC_FAN,
  2169. + .command_id = 0x01,
  2170. +});
  2171. +
  2172. +// hwmon
  2173. +umode_t surface_fan_hwmon_is_visible(const void *drvdata,
  2174. + enum hwmon_sensor_types type, u32 attr,
  2175. + int channel)
  2176. +{
  2177. + return 0444;
  2178. +}
  2179. +
  2180. +static int surface_fan_hwmon_read(struct device *dev,
  2181. + enum hwmon_sensor_types type, u32 attr,
  2182. + int channel, long *val)
  2183. +{
  2184. + struct ssam_device *sdev = dev_get_drvdata(dev);
  2185. + int ret;
  2186. + __le16 value;
  2187. +
  2188. + ret = __ssam_fan_rpm_get(sdev, &value);
  2189. + if (ret)
  2190. + return ret;
  2191. +
  2192. + *val = le16_to_cpu(value);
  2193. +
  2194. + return ret;
  2195. +}
  2196. +
  2197. +static const struct hwmon_channel_info *const surface_fan_info[] = {
  2198. + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
  2199. + NULL
  2200. +};
  2201. +
  2202. +static const struct hwmon_ops surface_fan_hwmon_ops = {
  2203. + .is_visible = surface_fan_hwmon_is_visible,
  2204. + .read = surface_fan_hwmon_read,
  2205. +};
  2206. +
  2207. +static const struct hwmon_chip_info surface_fan_chip_info = {
  2208. + .ops = &surface_fan_hwmon_ops,
  2209. + .info = surface_fan_info,
  2210. +};
  2211. +
  2212. +static int surface_fan_probe(struct ssam_device *sdev)
  2213. +{
  2214. + struct device *hdev;
  2215. +
  2216. + hdev = devm_hwmon_device_register_with_info(&sdev->dev,
  2217. + "surface_fan", sdev,
  2218. + &surface_fan_chip_info,
  2219. + NULL);
  2220. + if (IS_ERR(hdev))
  2221. + return PTR_ERR(hdev);
  2222. +
  2223. + return 0;
  2224. +}
  2225. +
  2226. +static const struct ssam_device_id ssam_fan_match[] = {
  2227. + { SSAM_SDEV(FAN, SAM, 0x01, 0x01) },
  2228. + {},
  2229. +};
  2230. +MODULE_DEVICE_TABLE(ssam, ssam_fan_match);
  2231. +
  2232. +static struct ssam_device_driver surface_fan = {
  2233. + .probe = surface_fan_probe,
  2234. + .match_table = ssam_fan_match,
  2235. + .driver = {
  2236. + .name = "surface_fan",
  2237. + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  2238. + },
  2239. +};
  2240. +module_ssam_device_driver(surface_fan);
  2241. +
  2242. +MODULE_AUTHOR("Ivor Wanders <ivor@iwanders.net>");
  2243. +MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
  2244. +MODULE_LICENSE("GPL");
  2245. --
  2246. 2.43.0
  2247. From 75ed426ff1c6b08c6198be537e9b22724a86fc5d Mon Sep 17 00:00:00 2001
  2248. From: Maximilian Luz <luzmaximilian@gmail.com>
  2249. Date: Sat, 30 Dec 2023 18:07:54 +0100
  2250. Subject: [PATCH] hwmon: Add thermal sensor driver for Surface Aggregator
  2251. Module
  2252. Some of the newer Microsoft Surface devices (such as the Surface Book
  2253. 3 and Pro 9) have thermal sensors connected via the Surface Aggregator
  2254. Module (the embedded controller on those devices). Add a basic driver
  2255. to read out the temperature values of those sensors.
  2256. Link: https://github.com/linux-surface/surface-aggregator-module/issues/59
  2257. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  2258. Patchset: surface-sam
  2259. ---
  2260. drivers/hwmon/Kconfig | 10 +++
  2261. drivers/hwmon/Makefile | 1 +
  2262. drivers/hwmon/surface_temp.c | 165 +++++++++++++++++++++++++++++++++++
  2263. 3 files changed, 176 insertions(+)
  2264. create mode 100644 drivers/hwmon/surface_temp.c
  2265. diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
  2266. index 4a5f0ffd13e7a..be7243e7ccb23 100644
  2267. --- a/drivers/hwmon/Kconfig
  2268. +++ b/drivers/hwmon/Kconfig
  2269. @@ -1938,6 +1938,16 @@ config SENSORS_SURFACE_FAN
  2270. Select M or Y here, if you want to be able to read the fan's speed.
  2271. +config SENSORS_SURFACE_TEMP
  2272. + tristate "Microsoft Surface Thermal Sensor Driver"
  2273. + depends on SURFACE_AGGREGATOR
  2274. + help
  2275. + Driver for monitoring thermal sensors connected via the Surface
  2276. + Aggregator Module (embedded controller) on Microsoft Surface devices.
  2277. +
  2278. + This driver can also be built as a module. If so, the module
  2279. + will be called surface_temp.
  2280. +
  2281. config SENSORS_ADC128D818
  2282. tristate "Texas Instruments ADC128D818"
  2283. depends on I2C
  2284. diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
  2285. index 4481011816074..c22cfad4ca112 100644
  2286. --- a/drivers/hwmon/Makefile
  2287. +++ b/drivers/hwmon/Makefile
  2288. @@ -193,6 +193,7 @@ obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
  2289. obj-$(CONFIG_SENSORS_SPARX5) += sparx5-temp.o
  2290. obj-$(CONFIG_SENSORS_STTS751) += stts751.o
  2291. obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o
  2292. +obj-$(CONFIG_SENSORS_SURFACE_TEMP)+= surface_temp.o
  2293. obj-$(CONFIG_SENSORS_SY7636A) += sy7636a-hwmon.o
  2294. obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o
  2295. obj-$(CONFIG_SENSORS_TC74) += tc74.o
  2296. diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c
  2297. new file mode 100644
  2298. index 0000000000000..48c3e826713f6
  2299. --- /dev/null
  2300. +++ b/drivers/hwmon/surface_temp.c
  2301. @@ -0,0 +1,165 @@
  2302. +// SPDX-License-Identifier: GPL-2.0+
  2303. +/*
  2304. + * Thermal sensor subsystem driver for Surface System Aggregator Module (SSAM).
  2305. + *
  2306. + * Copyright (C) 2022-2023 Maximilian Luz <luzmaximilian@gmail.com>
  2307. + */
  2308. +
  2309. +#include <linux/bitops.h>
  2310. +#include <linux/hwmon.h>
  2311. +#include <linux/kernel.h>
  2312. +#include <linux/module.h>
  2313. +#include <linux/types.h>
  2314. +
  2315. +#include <linux/surface_aggregator/controller.h>
  2316. +#include <linux/surface_aggregator/device.h>
  2317. +
  2318. +
  2319. +/* -- SAM interface. -------------------------------------------------------- */
  2320. +
  2321. +SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, {
  2322. + .target_category = SSAM_SSH_TC_TMP,
  2323. + .command_id = 0x04,
  2324. +});
  2325. +
  2326. +SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_temperature, __le16, {
  2327. + .target_category = SSAM_SSH_TC_TMP,
  2328. + .command_id = 0x01,
  2329. +});
  2330. +
  2331. +static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors)
  2332. +{
  2333. + __le16 sensors_le;
  2334. + int status;
  2335. +
  2336. + status = __ssam_tmp_get_available_sensors(sdev, &sensors_le);
  2337. + if (status)
  2338. + return status;
  2339. +
  2340. + *sensors = le16_to_cpu(sensors_le);
  2341. + return 0;
  2342. +}
  2343. +
  2344. +static int ssam_tmp_get_temperature(struct ssam_device *sdev, u8 iid, long *temperature)
  2345. +{
  2346. + __le16 temp_le;
  2347. + int status;
  2348. +
  2349. + status = __ssam_tmp_get_temperature(sdev->ctrl, sdev->uid.target, iid, &temp_le);
  2350. + if (status)
  2351. + return status;
  2352. +
  2353. + /* Convert 1/10 °K to 1/1000 °C */
  2354. + *temperature = (le16_to_cpu(temp_le) - 2731) * 100L;
  2355. + return 0;
  2356. +}
  2357. +
  2358. +
  2359. +/* -- Driver.---------------------------------------------------------------- */
  2360. +
  2361. +struct ssam_temp {
  2362. + struct ssam_device *sdev;
  2363. + s16 sensors;
  2364. +};
  2365. +
  2366. +static umode_t ssam_temp_hwmon_is_visible(const void *data,
  2367. + enum hwmon_sensor_types type,
  2368. + u32 attr, int channel)
  2369. +{
  2370. + const struct ssam_temp *ssam_temp = data;
  2371. +
  2372. + if (!(ssam_temp->sensors & BIT(channel)))
  2373. + return 0;
  2374. +
  2375. + return 0444;
  2376. +}
  2377. +
  2378. +static int ssam_temp_hwmon_read(struct device *dev,
  2379. + enum hwmon_sensor_types type,
  2380. + u32 attr, int channel, long *value)
  2381. +{
  2382. + const struct ssam_temp *ssam_temp = dev_get_drvdata(dev);
  2383. +
  2384. + return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value);
  2385. +}
  2386. +
  2387. +static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = {
  2388. + HWMON_CHANNEL_INFO(chip,
  2389. + HWMON_C_REGISTER_TZ),
  2390. + /* We have at most 16 thermal sensor channels. */
  2391. + HWMON_CHANNEL_INFO(temp,
  2392. + HWMON_T_INPUT,
  2393. + HWMON_T_INPUT,
  2394. + HWMON_T_INPUT,
  2395. + HWMON_T_INPUT,
  2396. + HWMON_T_INPUT,
  2397. + HWMON_T_INPUT,
  2398. + HWMON_T_INPUT,
  2399. + HWMON_T_INPUT,
  2400. + HWMON_T_INPUT,
  2401. + HWMON_T_INPUT,
  2402. + HWMON_T_INPUT,
  2403. + HWMON_T_INPUT,
  2404. + HWMON_T_INPUT,
  2405. + HWMON_T_INPUT,
  2406. + HWMON_T_INPUT,
  2407. + HWMON_T_INPUT),
  2408. + NULL
  2409. +};
  2410. +
  2411. +static const struct hwmon_ops ssam_temp_hwmon_ops = {
  2412. + .is_visible = ssam_temp_hwmon_is_visible,
  2413. + .read = ssam_temp_hwmon_read,
  2414. +};
  2415. +
  2416. +static const struct hwmon_chip_info ssam_temp_hwmon_chip_info = {
  2417. + .ops = &ssam_temp_hwmon_ops,
  2418. + .info = ssam_temp_hwmon_info,
  2419. +};
  2420. +
  2421. +static int ssam_temp_probe(struct ssam_device *sdev)
  2422. +{
  2423. + struct ssam_temp *ssam_temp;
  2424. + struct device *hwmon_dev;
  2425. + s16 sensors;
  2426. + int status;
  2427. +
  2428. + status = ssam_tmp_get_available_sensors(sdev, &sensors);
  2429. + if (status)
  2430. + return status;
  2431. +
  2432. + ssam_temp = devm_kzalloc(&sdev->dev, sizeof(*ssam_temp), GFP_KERNEL);
  2433. + if (!ssam_temp)
  2434. + return -ENOMEM;
  2435. +
  2436. + ssam_temp->sdev = sdev;
  2437. + ssam_temp->sensors = sensors;
  2438. +
  2439. + hwmon_dev = devm_hwmon_device_register_with_info(&sdev->dev,
  2440. + "surface_thermal", ssam_temp, &ssam_temp_hwmon_chip_info,
  2441. + NULL);
  2442. + if (IS_ERR(hwmon_dev))
  2443. + return PTR_ERR(hwmon_dev);
  2444. +
  2445. + return 0;
  2446. +}
  2447. +
  2448. +static const struct ssam_device_id ssam_temp_match[] = {
  2449. + { SSAM_SDEV(TMP, SAM, 0x00, 0x02) },
  2450. + { },
  2451. +};
  2452. +MODULE_DEVICE_TABLE(ssam, ssam_temp_match);
  2453. +
  2454. +static struct ssam_device_driver ssam_temp = {
  2455. + .probe = ssam_temp_probe,
  2456. + .match_table = ssam_temp_match,
  2457. + .driver = {
  2458. + .name = "surface_temp",
  2459. + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  2460. + },
  2461. +};
  2462. +module_ssam_device_driver(ssam_temp);
  2463. +
  2464. +MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
  2465. +MODULE_DESCRIPTION("Thermal sensor subsystem driver for Surface System Aggregator Module");
  2466. +MODULE_LICENSE("GPL");
  2467. --
  2468. 2.43.0
  2469. From aef610f92f0370d3b11472e302da555edca811dd Mon Sep 17 00:00:00 2001
  2470. From: Maximilian Luz <luzmaximilian@gmail.com>
  2471. Date: Sat, 30 Dec 2023 18:12:23 +0100
  2472. Subject: [PATCH] hwmon: surface_temp: Add support for sensor names
  2473. The thermal subsystem of the Surface Aggregator Module allows us to
  2474. query the names of the respective thermal sensors. Forward those to
  2475. userspace.
  2476. Signed-off-by: Ivor Wanders <ivor@iwanders.net>
  2477. Co-Developed-by: Maximilian Luz <luzmaximilian@gmail.com>
  2478. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  2479. Patchset: surface-sam
  2480. ---
  2481. drivers/hwmon/surface_temp.c | 113 +++++++++++++++++++++++++++++------
  2482. 1 file changed, 96 insertions(+), 17 deletions(-)
  2483. diff --git a/drivers/hwmon/surface_temp.c b/drivers/hwmon/surface_temp.c
  2484. index 48c3e826713f6..4c08926139dbf 100644
  2485. --- a/drivers/hwmon/surface_temp.c
  2486. +++ b/drivers/hwmon/surface_temp.c
  2487. @@ -17,6 +17,27 @@
  2488. /* -- SAM interface. -------------------------------------------------------- */
  2489. +/*
  2490. + * Available sensors are indicated by a 16-bit bitfield, where a 1 marks the
  2491. + * presence of a sensor. So we have at most 16 possible sensors/channels.
  2492. + */
  2493. +#define SSAM_TMP_SENSOR_MAX_COUNT 16
  2494. +
  2495. +/*
  2496. + * All names observed so far are 6 characters long, but there's only
  2497. + * zeros after the name, so perhaps they can be longer. This number reflects
  2498. + * the maximum zero-padded space observed in the returned buffer.
  2499. + */
  2500. +#define SSAM_TMP_SENSOR_NAME_LENGTH 18
  2501. +
  2502. +struct ssam_tmp_get_name_rsp {
  2503. + __le16 unknown1;
  2504. + char unknown2;
  2505. + char name[SSAM_TMP_SENSOR_NAME_LENGTH];
  2506. +} __packed;
  2507. +
  2508. +static_assert(sizeof(struct ssam_tmp_get_name_rsp) == 21);
  2509. +
  2510. SSAM_DEFINE_SYNC_REQUEST_CL_R(__ssam_tmp_get_available_sensors, __le16, {
  2511. .target_category = SSAM_SSH_TC_TMP,
  2512. .command_id = 0x04,
  2513. @@ -27,6 +48,11 @@ SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_temperature, __le16, {
  2514. .command_id = 0x01,
  2515. });
  2516. +SSAM_DEFINE_SYNC_REQUEST_MD_R(__ssam_tmp_get_name, struct ssam_tmp_get_name_rsp, {
  2517. + .target_category = SSAM_SSH_TC_TMP,
  2518. + .command_id = 0x0e,
  2519. +});
  2520. +
  2521. static int ssam_tmp_get_available_sensors(struct ssam_device *sdev, s16 *sensors)
  2522. {
  2523. __le16 sensors_le;
  2524. @@ -54,12 +80,37 @@ static int ssam_tmp_get_temperature(struct ssam_device *sdev, u8 iid, long *temp
  2525. return 0;
  2526. }
  2527. +static int ssam_tmp_get_name(struct ssam_device *sdev, u8 iid, char *buf, size_t buf_len)
  2528. +{
  2529. + struct ssam_tmp_get_name_rsp name_rsp;
  2530. + int status;
  2531. +
  2532. + status = __ssam_tmp_get_name(sdev->ctrl, sdev->uid.target, iid, &name_rsp);
  2533. + if (status)
  2534. + return status;
  2535. +
  2536. + /*
  2537. + * This should not fail unless the name in the returned struct is not
  2538. + * null-terminated or someone changed something in the struct
  2539. + * definitions above, since our buffer and struct have the same
  2540. + * capacity by design. So if this fails blow this up with a warning.
  2541. + * Since the more likely cause is that the returned string isn't
  2542. + * null-terminated, we might have received garbage (as opposed to just
  2543. + * an incomplete string), so also fail the function.
  2544. + */
  2545. + status = strscpy(buf, name_rsp.name, buf_len);
  2546. + WARN_ON(status < 0);
  2547. +
  2548. + return status < 0 ? status : 0;
  2549. +}
  2550. +
  2551. /* -- Driver.---------------------------------------------------------------- */
  2552. struct ssam_temp {
  2553. struct ssam_device *sdev;
  2554. s16 sensors;
  2555. + char names[SSAM_TMP_SENSOR_MAX_COUNT][SSAM_TMP_SENSOR_NAME_LENGTH];
  2556. };
  2557. static umode_t ssam_temp_hwmon_is_visible(const void *data,
  2558. @@ -83,33 +134,47 @@ static int ssam_temp_hwmon_read(struct device *dev,
  2559. return ssam_tmp_get_temperature(ssam_temp->sdev, channel + 1, value);
  2560. }
  2561. +static int ssam_temp_hwmon_read_string(struct device *dev,
  2562. + enum hwmon_sensor_types type,
  2563. + u32 attr, int channel, const char **str)
  2564. +{
  2565. + const struct ssam_temp *ssam_temp = dev_get_drvdata(dev);
  2566. +
  2567. + *str = ssam_temp->names[channel];
  2568. + return 0;
  2569. +}
  2570. +
  2571. static const struct hwmon_channel_info * const ssam_temp_hwmon_info[] = {
  2572. HWMON_CHANNEL_INFO(chip,
  2573. HWMON_C_REGISTER_TZ),
  2574. - /* We have at most 16 thermal sensor channels. */
  2575. + /*
  2576. + * We have at most SSAM_TMP_SENSOR_MAX_COUNT = 16 thermal sensor
  2577. + * channels.
  2578. + */
  2579. HWMON_CHANNEL_INFO(temp,
  2580. - HWMON_T_INPUT,
  2581. - HWMON_T_INPUT,
  2582. - HWMON_T_INPUT,
  2583. - HWMON_T_INPUT,
  2584. - HWMON_T_INPUT,
  2585. - HWMON_T_INPUT,
  2586. - HWMON_T_INPUT,
  2587. - HWMON_T_INPUT,
  2588. - HWMON_T_INPUT,
  2589. - HWMON_T_INPUT,
  2590. - HWMON_T_INPUT,
  2591. - HWMON_T_INPUT,
  2592. - HWMON_T_INPUT,
  2593. - HWMON_T_INPUT,
  2594. - HWMON_T_INPUT,
  2595. - HWMON_T_INPUT),
  2596. + HWMON_T_INPUT | HWMON_T_LABEL,
  2597. + HWMON_T_INPUT | HWMON_T_LABEL,
  2598. + HWMON_T_INPUT | HWMON_T_LABEL,
  2599. + HWMON_T_INPUT | HWMON_T_LABEL,
  2600. + HWMON_T_INPUT | HWMON_T_LABEL,
  2601. + HWMON_T_INPUT | HWMON_T_LABEL,
  2602. + HWMON_T_INPUT | HWMON_T_LABEL,
  2603. + HWMON_T_INPUT | HWMON_T_LABEL,
  2604. + HWMON_T_INPUT | HWMON_T_LABEL,
  2605. + HWMON_T_INPUT | HWMON_T_LABEL,
  2606. + HWMON_T_INPUT | HWMON_T_LABEL,
  2607. + HWMON_T_INPUT | HWMON_T_LABEL,
  2608. + HWMON_T_INPUT | HWMON_T_LABEL,
  2609. + HWMON_T_INPUT | HWMON_T_LABEL,
  2610. + HWMON_T_INPUT | HWMON_T_LABEL,
  2611. + HWMON_T_INPUT | HWMON_T_LABEL),
  2612. NULL
  2613. };
  2614. static const struct hwmon_ops ssam_temp_hwmon_ops = {
  2615. .is_visible = ssam_temp_hwmon_is_visible,
  2616. .read = ssam_temp_hwmon_read,
  2617. + .read_string = ssam_temp_hwmon_read_string,
  2618. };
  2619. static const struct hwmon_chip_info ssam_temp_hwmon_chip_info = {
  2620. @@ -122,6 +187,7 @@ static int ssam_temp_probe(struct ssam_device *sdev)
  2621. struct ssam_temp *ssam_temp;
  2622. struct device *hwmon_dev;
  2623. s16 sensors;
  2624. + int channel;
  2625. int status;
  2626. status = ssam_tmp_get_available_sensors(sdev, &sensors);
  2627. @@ -135,6 +201,19 @@ static int ssam_temp_probe(struct ssam_device *sdev)
  2628. ssam_temp->sdev = sdev;
  2629. ssam_temp->sensors = sensors;
  2630. + /* Retrieve the name for each available sensor. */
  2631. + for (channel = 0; channel < SSAM_TMP_SENSOR_MAX_COUNT; channel++)
  2632. + {
  2633. + if (!(sensors & BIT(channel)))
  2634. + continue;
  2635. +
  2636. + status = ssam_tmp_get_name(sdev, channel + 1,
  2637. + ssam_temp->names[channel],
  2638. + SSAM_TMP_SENSOR_NAME_LENGTH);
  2639. + if (status)
  2640. + return status;
  2641. + }
  2642. +
  2643. hwmon_dev = devm_hwmon_device_register_with_info(&sdev->dev,
  2644. "surface_thermal", ssam_temp, &ssam_temp_hwmon_chip_info,
  2645. NULL);
  2646. --
  2647. 2.43.0
  2648. From e2cecbfd921d8e15791f549b26465aef5dabc001 Mon Sep 17 00:00:00 2001
  2649. From: Maximilian Luz <luzmaximilian@gmail.com>
  2650. Date: Sat, 30 Dec 2023 18:21:12 +0100
  2651. Subject: [PATCH] platform/surface: aggregator_registry: Add support for
  2652. thermal sensors on the Surface Pro 9
  2653. The Surface Pro 9 has thermal sensors connected via the Surface
  2654. Aggregator Module. Add a device node to support those.
  2655. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  2656. Patchset: surface-sam
  2657. ---
  2658. drivers/platform/surface/surface_aggregator_registry.c | 7 +++++++
  2659. 1 file changed, 7 insertions(+)
  2660. diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
  2661. index b0db25886c996..797802d16f319 100644
  2662. --- a/drivers/platform/surface/surface_aggregator_registry.c
  2663. +++ b/drivers/platform/surface/surface_aggregator_registry.c
  2664. @@ -74,6 +74,12 @@ static const struct software_node ssam_node_tmp_pprof = {
  2665. .parent = &ssam_node_root,
  2666. };
  2667. +/* Thermal sensors. */
  2668. +static const struct software_node ssam_node_tmp_sensors = {
  2669. + .name = "ssam:01:03:01:00:02",
  2670. + .parent = &ssam_node_root,
  2671. +};
  2672. +
  2673. /* Fan speed function. */
  2674. static const struct software_node ssam_node_fan_speed = {
  2675. .name = "ssam:01:05:01:01:01",
  2676. @@ -325,6 +331,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
  2677. &ssam_node_bat_ac,
  2678. &ssam_node_bat_main,
  2679. &ssam_node_tmp_pprof,
  2680. + &ssam_node_tmp_sensors,
  2681. &ssam_node_fan_speed,
  2682. &ssam_node_pos_tablet_switch,
  2683. &ssam_node_hid_kip_keyboard,
  2684. --
  2685. 2.43.0